Merge "Multiple shortcut menu for android R (1/n)"

This commit is contained in:
PETER LIANG
2019-12-27 01:59:05 +00:00
committed by Android (Google) Code Review
6 changed files with 47 additions and 170 deletions

View File

@@ -15,28 +15,26 @@
*/
package com.android.internal.app;
import static android.view.WindowManagerPolicyConstants.NAV_BAR_MODE_GESTURAL;
import android.accessibilityservice.AccessibilityServiceInfo;
import android.annotation.NonNull;
import android.annotation.Nullable;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.provider.Settings;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.view.accessibility.AccessibilityManager;
import android.widget.BaseAdapter;
import android.widget.GridView;
import android.widget.ImageView;
import android.widget.TextView;
import com.android.internal.R;
import com.android.internal.widget.ResolverDrawerLayout;
import java.util.ArrayList;
import java.util.Collections;
@@ -54,66 +52,43 @@ public class AccessibilityButtonChooserActivity extends Activity {
private List<AccessibilityButtonTarget> mTargets = null;
private AlertDialog mAlertDialog;
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.accessibility_button_chooser);
final ResolverDrawerLayout rdl = findViewById(R.id.contentPanel);
if (rdl != null) {
rdl.setOnDismissedListener(this::finish);
}
String component = Settings.Secure.getString(getContentResolver(),
Settings.Secure.ACCESSIBILITY_BUTTON_TARGET_COMPONENT);
if (isGestureNavigateEnabled()) {
TextView promptPrologue = findViewById(R.id.accessibility_button_prompt_prologue);
promptPrologue.setText(isTouchExploreOn()
? R.string.accessibility_gesture_3finger_prompt_text
: R.string.accessibility_gesture_prompt_text);
}
if (TextUtils.isEmpty(component)) {
TextView prompt = findViewById(R.id.accessibility_button_prompt);
if (isGestureNavigateEnabled()) {
prompt.setText(isTouchExploreOn()
? R.string.accessibility_gesture_3finger_instructional_text
: R.string.accessibility_gesture_instructional_text);
}
prompt.setVisibility(View.VISIBLE);
final TypedArray theme = getTheme().obtainStyledAttributes(android.R.styleable.Theme);
if (!theme.getBoolean(android.R.styleable.Theme_windowNoTitle, /* defValue= */false)) {
requestWindowFeature(Window.FEATURE_NO_TITLE);
}
// TODO(b/146815874): Will replace it with white list services
mMagnificationTarget = new AccessibilityButtonTarget(this, MAGNIFICATION_COMPONENT_ID,
R.string.accessibility_magnification_chooser_text,
R.drawable.ic_accessibility_magnification);
// TODO(b/146815544): Will use shortcut type or button type to get the corresponding
// services
mTargets = getServiceAccessibilityButtonTargets(this);
if (Settings.Secure.getInt(getContentResolver(),
Settings.Secure.ACCESSIBILITY_DISPLAY_MAGNIFICATION_NAVBAR_ENABLED, 0) == 1) {
mTargets.add(mMagnificationTarget);
}
if (mTargets.size() < 2) {
// Why are we here?
finish();
}
GridView gridview = findViewById(R.id.accessibility_button_chooser_grid);
gridview.setAdapter(new TargetAdapter());
gridview.setOnItemClickListener((parent, view, position, id) -> {
onTargetSelected(mTargets.get(position));
});
// TODO(b/146815548): Will add title to separate which one type
mAlertDialog = new AlertDialog.Builder(this)
.setAdapter(new TargetAdapter(),
(dialog, position) -> onTargetSelected(mTargets.get(position)))
.setOnDismissListener(dialog -> finish())
.create();
mAlertDialog.show();
}
private boolean isGestureNavigateEnabled() {
return NAV_BAR_MODE_GESTURAL == getResources().getInteger(
com.android.internal.R.integer.config_navBarInteractionMode);
}
private boolean isTouchExploreOn() {
return ((AccessibilityManager) getSystemService(Context.ACCESSIBILITY_SERVICE))
.isTouchExplorationEnabled();
@Override
protected void onDestroy() {
mAlertDialog.dismiss();
super.onDestroy();
}
private static List<AccessibilityButtonTarget> getServiceAccessibilityButtonTargets(
@@ -167,6 +142,8 @@ public class AccessibilityButtonChooserActivity extends Activity {
TextView labelView = root.findViewById(R.id.accessibility_button_target_label);
iconView.setImageDrawable(target.getDrawable());
labelView.setText(target.getLabel());
// TODO(b/146815874): Need to get every service status to update UI
return root;
}
}
@@ -175,7 +152,7 @@ public class AccessibilityButtonChooserActivity extends Activity {
public String mId;
public CharSequence mLabel;
public Drawable mDrawable;
// TODO(b/146815874): Will add fragment type and related functions
public AccessibilityButtonTarget(@NonNull Context context,
@NonNull AccessibilityServiceInfo serviceInfo) {
this.mId = serviceInfo.getComponentName().flattenToString();

View File

@@ -4777,7 +4777,7 @@
</activity>
<activity android:name="com.android.internal.app.AccessibilityButtonChooserActivity"
android:exported="false"
android:theme="@style/Theme.DeviceDefault.Resolver"
android:theme="@style/Theme.DeviceDefault.Dialog.Alert.DayNight"
android:finishOnCloseSystemDialogs="true"
android:excludeFromRecents="true"
android:documentLaunchMode="never"

View File

@@ -1,73 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
/*
* Copyright 2017, The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-->
<com.android.internal.widget.ResolverDrawerLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:maxWidth="@dimen/resolver_max_width"
android:maxCollapsedHeight="256dp"
android:maxCollapsedHeightSmall="56dp"
android:id="@id/contentPanel">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alwaysShow="true"
android:orientation="vertical"
android:background="?attr/colorBackground"
android:paddingTop="8dp"
android:paddingBottom="8dp"
android:paddingStart="?attr/dialogPreferredPadding"
android:paddingEnd="?attr/dialogPreferredPadding">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:minHeight="56dp"
android:id="@+id/accessibility_button_prompt_prologue"
android:textAppearance="?attr/textAppearanceMedium"
android:text="@string/accessibility_button_prompt_text"
android:gravity="start|center_vertical"
android:layout_alignParentStart="true"
android:paddingTop="8dp"
android:paddingBottom="8dp"/>
<GridView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/accessibility_button_chooser_grid"
android:columnWidth="90dp"
android:numColumns="auto_fit"
android:verticalSpacing="10dp"
android:horizontalSpacing="10dp"
android:stretchMode="columnWidth"
android:gravity="center"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/accessibility_button_prompt"
android:textAppearance="?attr/textAppearanceMedium"
android:text="@string/accessibility_button_instructional_text"
android:gravity="start|center_vertical"
android:paddingTop="8dp"
android:paddingBottom="8dp"
android:visibility="gone"/>
</LinearLayout>
</com.android.internal.widget.ResolverDrawerLayout>

View File

@@ -16,37 +16,28 @@
** limitations under the License.
*/
-->
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:minWidth="80dp"
android:gravity="center"
android:paddingTop="8dp"
android:paddingBottom="8dp"
android:background="?attr/selectableItemBackgroundBorderless">
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:paddingBottom="12dp"
android:paddingEnd="16dp"
android:paddingStart="16dp"
android:paddingTop="12dp">
<ImageView android:id="@+id/accessibility_button_target_icon"
android:layout_width="48dp"
android:layout_height="48dp"
android:layout_marginLeft="3dp"
android:layout_marginRight="3dp"
android:layout_marginBottom="3dp"
android:scaleType="fitCenter"/>
<ImageView
android:id="@+id/accessibility_button_target_icon"
android:layout_width="48dp"
android:layout_height="48dp"
android:scaleType="fitCenter"/>
<TextView android:id="@+id/accessibility_button_target_label"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:layout_marginLeft="4dp"
android:layout_marginRight="4dp"
android:textAppearance="?attr/textAppearanceSmall"
android:textColor="?attr/textColorPrimary"
android:textSize="12sp"
android:fontFamily="sans-serif-condensed"
android:gravity="top|center_horizontal"
android:minLines="2"
android:maxLines="2"
android:ellipsize="marquee"/>
<TextView
android:id="@+id/accessibility_button_target_label"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_weight="1"
android:textColor="?attr/textColorPrimary"/>
</LinearLayout>

View File

@@ -4383,20 +4383,6 @@
<string name="accessibility_shortcut_spoken_feedback">Press and hold both volume keys for three seconds to use
<xliff:g id="service_name" example="TalkBack">%1$s</xliff:g></string>
<!-- Text appearing in a prompt at the top of UI allowing the user to select a target service or feature to be assigned to the Accessibility button in the navigation bar. -->
<string name="accessibility_button_prompt_text">Choose a service to use when you tap the accessibility button:</string>
<!-- Text appearing in a prompt at the top of UI allowing the user to select a target service or feature to be assigned to the Accessibility button when gesture navigation is enabled [CHAR LIMIT=none] -->
<string name="accessibility_gesture_prompt_text">Choose a service to use with the accessibility gesture (swipe up from the bottom of the screen with two fingers):</string>
<!-- Text appearing in a prompt at the top of UI allowing the user to select a target service or feature to be assigned to the Accessibility button when gesture navigation and TalkBack is enabled [CHAR LIMIT=none] -->
<string name="accessibility_gesture_3finger_prompt_text">Choose a service to use with the accessibility gesture (swipe up from the bottom of the screen with three fingers):</string>
<!-- Text describing how to display UI allowing a user to select a target service or feature to be assigned to the Accessibility button in the navigation bar. -->
<string name="accessibility_button_instructional_text">To switch between services, touch &amp; hold the accessibility button.</string>
<!-- Text describing how to display UI allowing a user to select a target service or feature to be assigned to the Accessibility button when gesture navigation is enabled. [CHAR LIMIT=none] -->
<string name="accessibility_gesture_instructional_text">To switch between services, swipe up with two fingers and hold.</string>
<!-- Text describing how to display UI allowing a user to select a target service or feature to be assigned to the Accessibility button when gesture navigation and TalkBack is enabled. [CHAR LIMIT=none] -->
<string name="accessibility_gesture_3finger_instructional_text">To switch between services, swipe up with three fingers and hold.</string>
<!-- Text used to describe system navigation features, shown within a UI allowing a user to assign system magnification features to the Accessibility button in the navigation bar. -->
<string name="accessibility_magnification_chooser_text">Magnification</string>

View File

@@ -3204,11 +3204,7 @@
<java-symbol type="string" name="accessibility_shortcut_spoken_feedback" />
<!-- Accessibility Button -->
<java-symbol type="layout" name="accessibility_button_chooser" />
<java-symbol type="layout" name="accessibility_button_chooser_item" />
<java-symbol type="id" name="accessibility_button_chooser_grid" />
<java-symbol type="id" name="accessibility_button_prompt" />
<java-symbol type="id" name="accessibility_button_prompt_prologue" />
<java-symbol type="id" name="accessibility_button_target_icon" />
<java-symbol type="id" name="accessibility_button_target_label" />
<java-symbol type="string" name="accessibility_magnification_chooser_text" />