Added Settings page for AccessibilityMenu
Bug: 261252772 Test: Install apk, then navigate to AccessibilityMenu settings. Change-Id: I89c792819a0fbadc899db5585295f0ddf8d0083b
This commit is contained in:
@@ -24,6 +24,7 @@ android_app {
|
||||
static_libs: [
|
||||
"androidx.coordinatorlayout_coordinatorlayout",
|
||||
"androidx.core_core",
|
||||
"androidx.preference_preference",
|
||||
"androidx.viewpager_viewpager",
|
||||
"SettingsLibDisplayUtils",
|
||||
],
|
||||
|
||||
@@ -33,5 +33,27 @@
|
||||
android:name="android.accessibilityservice"
|
||||
android:resource="@xml/accessibilitymenu_service"/>
|
||||
</service>
|
||||
|
||||
<!-- Accessibility Menu Settings -->
|
||||
<activity
|
||||
android:name="com.android.systemui.accessibility.accessibilitymenu.activity.A11yMenuSettingsActivity"
|
||||
android:exported="true"
|
||||
android:label="@string/accessibility_menu_settings_name"
|
||||
android:launchMode="singleTop"
|
||||
android:theme="@style/AccessibilityMenuSettings">
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.MAIN"/>
|
||||
|
||||
<category android:name="android.accessibilityservice.SERVICE_SETTINGS"/>
|
||||
</intent-filter>
|
||||
</activity>
|
||||
</application>
|
||||
|
||||
<queries>
|
||||
<intent>
|
||||
<action android:name="android.intent.action.VIEW" />
|
||||
<category android:name="android.intent.category.BROWSABLE" />
|
||||
<data android:scheme="https" />
|
||||
</intent>
|
||||
</queries>
|
||||
</manifest>
|
||||
@@ -1,11 +1,5 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<resources>
|
||||
<!-- user customized shortcuts preference -->
|
||||
<string name="pref_user_shortcuts">accessibility_menu_user_shortcuts</string>
|
||||
<!-- key for user customized shortcuts -->
|
||||
<string name="pref_user_shortcuts_key">pref_user_shortcuts_key</string>
|
||||
<!-- value for empty shortcut -->
|
||||
<string name="pref_user_shortcuts_value_empty">[]</string>
|
||||
<!-- empty string for shortcut label -->
|
||||
<string name="empty_content"></string>
|
||||
|
||||
@@ -14,4 +8,6 @@
|
||||
<!-- key for Help&feedback settings [CHAR_LIMIT=NONE] -->
|
||||
<string name="pref_help">pref_help</string>
|
||||
|
||||
<!-- url for help page -->
|
||||
<string name="help_url">https://support.google.com/accessibility/android/answer/9078941</string>
|
||||
</resources>
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
|
||||
<resources>
|
||||
<!--The theme is for preference CollapsingToolbarBaseActivity settings-->
|
||||
<style name="AccessibilityMenuSettings" parent="android:Theme.DeviceDefault.Light" />
|
||||
<style name="AccessibilityMenuSettings" parent="android:Theme.DeviceDefault.DayNight" />
|
||||
|
||||
<!--Adds the theme to support SnackBar component and user configurable theme. -->
|
||||
<style name="ServiceTheme" parent="android:Theme.DeviceDefault.Light">
|
||||
|
||||
@@ -0,0 +1,33 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!--
|
||||
~ Copyright (C) 2023 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.
|
||||
-->
|
||||
|
||||
<androidx.preference.PreferenceScreen
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto">
|
||||
|
||||
<SwitchPreference
|
||||
android:defaultValue="false"
|
||||
android:key="@string/pref_large_buttons"
|
||||
android:persistent="true"
|
||||
android:summary="@string/accessibility_menu_large_buttons_summary"
|
||||
android:title="@string/accessibility_menu_large_buttons_title"/>
|
||||
|
||||
<Preference
|
||||
android:key="@string/pref_help"
|
||||
android:title="@string/pref_help_and_feedback_title"/>
|
||||
|
||||
</androidx.preference.PreferenceScreen>
|
||||
@@ -21,4 +21,5 @@
|
||||
android:intro="@string/accessibility_menu_intro"
|
||||
android:animatedImageDrawable="@drawable/a11ymenu_intro"
|
||||
android:isAccessibilityTool="true"
|
||||
android:settingsActivity="com.android.systemui.accessibility.accessibilitymenu.activity.A11yMenuSettingsActivity"
|
||||
/>
|
||||
@@ -22,6 +22,8 @@ import android.content.BroadcastReceiver;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.IntentFilter;
|
||||
import android.content.SharedPreferences;
|
||||
import android.content.SharedPreferences.OnSharedPreferenceChangeListener;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.content.pm.ResolveInfo;
|
||||
import android.content.res.Configuration;
|
||||
@@ -38,6 +40,8 @@ import android.view.MotionEvent;
|
||||
import android.view.View;
|
||||
import android.view.accessibility.AccessibilityEvent;
|
||||
|
||||
import androidx.preference.PreferenceManager;
|
||||
|
||||
import com.android.settingslib.display.BrightnessUtils;
|
||||
import com.android.systemui.accessibility.accessibilitymenu.model.A11yMenuShortcut.ShortcutId;
|
||||
import com.android.systemui.accessibility.accessibilitymenu.view.A11yMenuOverlayLayout;
|
||||
@@ -62,6 +66,7 @@ public class AccessibilityMenuService extends AccessibilityService
|
||||
public static final long BUTTON_CLICK_TIMEOUT = 200;
|
||||
|
||||
private A11yMenuOverlayLayout mA11yMenuLayout;
|
||||
private SharedPreferences mPrefs;
|
||||
|
||||
private static boolean sInitialized = false;
|
||||
|
||||
@@ -90,6 +95,25 @@ public class AccessibilityMenuService extends AccessibilityService
|
||||
}
|
||||
};
|
||||
|
||||
final BroadcastReceiver mBroadcastReceiver = new BroadcastReceiver() {
|
||||
@Override
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
mA11yMenuLayout.hideMenu();
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Update a11y menu layout when large button setting is changed.
|
||||
*/
|
||||
private final OnSharedPreferenceChangeListener mSharedPreferenceChangeListener =
|
||||
(SharedPreferences prefs, String key) -> {
|
||||
{
|
||||
if (key.equals(getString(R.string.pref_large_buttons))) {
|
||||
mA11yMenuLayout.configureLayout();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
// Update layout.
|
||||
private final Handler mHandler = new Handler(Looper.getMainLooper());
|
||||
private final Runnable mOnConfigChangedRunnable = new Runnable() {
|
||||
@@ -147,12 +171,11 @@ public class AccessibilityMenuService extends AccessibilityService
|
||||
protected void onServiceConnected() {
|
||||
mA11yMenuLayout = new A11yMenuOverlayLayout(this);
|
||||
|
||||
registerReceiver(new BroadcastReceiver() {
|
||||
@Override
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
mA11yMenuLayout.hideMenu();
|
||||
}}, new IntentFilter(Intent.ACTION_SCREEN_OFF)
|
||||
);
|
||||
registerReceiver(mBroadcastReceiver, new IntentFilter(Intent.ACTION_SCREEN_OFF));
|
||||
|
||||
mPrefs = PreferenceManager.getDefaultSharedPreferences(this);
|
||||
mPrefs.registerOnSharedPreferenceChangeListener(mSharedPreferenceChangeListener);
|
||||
|
||||
|
||||
mDisplayManager = getSystemService(DisplayManager.class);
|
||||
mDisplayManager.registerDisplayListener(mDisplayListener, null);
|
||||
@@ -285,6 +308,14 @@ public class AccessibilityMenuService extends AccessibilityService
|
||||
public void onInterrupt() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onUnbind(Intent intent) {
|
||||
unregisterReceiver(mBroadcastReceiver);
|
||||
mPrefs.unregisterOnSharedPreferenceChangeListener(mSharedPreferenceChangeListener);
|
||||
sInitialized = false;
|
||||
return super.onUnbind(intent);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean onKeyEvent(KeyEvent event) {
|
||||
if (event.getKeyCode() == KeyEvent.KEYCODE_BACK) {
|
||||
|
||||
@@ -0,0 +1,97 @@
|
||||
/*
|
||||
* Copyright (C) 2023 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.
|
||||
*/
|
||||
|
||||
package com.android.systemui.accessibility.accessibilitymenu.activity;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.SharedPreferences;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.net.Uri;
|
||||
import android.os.Bundle;
|
||||
import android.provider.Browser;
|
||||
import android.provider.Settings;
|
||||
|
||||
import androidx.fragment.app.FragmentActivity;
|
||||
import androidx.preference.Preference;
|
||||
import androidx.preference.PreferenceFragmentCompat;
|
||||
import androidx.preference.PreferenceManager;
|
||||
|
||||
import com.android.systemui.accessibility.accessibilitymenu.R;
|
||||
|
||||
/**
|
||||
* Settings activity for AccessibilityMenu.
|
||||
*/
|
||||
public class A11yMenuSettingsActivity extends FragmentActivity {
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
getSupportFragmentManager()
|
||||
.beginTransaction()
|
||||
.replace(android.R.id.content, new A11yMenuPreferenceFragment())
|
||||
.commit();
|
||||
}
|
||||
|
||||
/**
|
||||
* Settings/preferences fragment for AccessibilityMenu.
|
||||
*/
|
||||
public static class A11yMenuPreferenceFragment extends PreferenceFragmentCompat {
|
||||
@Override
|
||||
public void onCreatePreferences(Bundle bundle, String s) {
|
||||
setPreferencesFromResource(R.xml.accessibilitymenu_preferences, s);
|
||||
initializeHelpAndFeedbackPreference();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns large buttons settings state.
|
||||
*
|
||||
* @param context The parent context
|
||||
* @return {@code true} large button is enabled; {@code false} large button is disabled
|
||||
*/
|
||||
public static boolean isLargeButtonsEnabled(Context context) {
|
||||
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
|
||||
String key = context.getResources().getString(R.string.pref_large_buttons);
|
||||
return prefs.getBoolean(key, false);
|
||||
}
|
||||
|
||||
private void initializeHelpAndFeedbackPreference() {
|
||||
final Preference prefHelp = findPreference(getString(R.string.pref_help));
|
||||
if (prefHelp != null) {
|
||||
prefHelp.setTitle(R.string.pref_help_title);
|
||||
|
||||
// Do not allow access to web during setup.
|
||||
if (Settings.Secure.getInt(
|
||||
getContext().getContentResolver(),
|
||||
Settings.Secure.USER_SETUP_COMPLETE, 0) != 1) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Configure preference to open the help page in the default web browser.
|
||||
// If the system has no browser, hide the preference.
|
||||
Uri uri = Uri.parse(getResources().getString(R.string.help_url));
|
||||
Intent intent = new Intent(Intent.ACTION_VIEW, uri);
|
||||
intent.putExtra(Browser.EXTRA_APPLICATION_ID, getContext().getPackageName());
|
||||
if (getActivity().getPackageManager().queryIntentActivities(
|
||||
intent, PackageManager.ResolveInfoFlags.of(0)).isEmpty()) {
|
||||
prefHelp.setVisible(false);
|
||||
return;
|
||||
}
|
||||
prefHelp.setIntent(intent);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -27,6 +27,7 @@ import android.widget.TextView;
|
||||
|
||||
import com.android.systemui.accessibility.accessibilitymenu.AccessibilityMenuService;
|
||||
import com.android.systemui.accessibility.accessibilitymenu.R;
|
||||
import com.android.systemui.accessibility.accessibilitymenu.activity.A11yMenuSettingsActivity.A11yMenuPreferenceFragment;
|
||||
import com.android.systemui.accessibility.accessibilitymenu.model.A11yMenuShortcut;
|
||||
import com.android.systemui.accessibility.accessibilitymenu.utils.ShortcutDrawableUtils;
|
||||
|
||||
@@ -124,7 +125,12 @@ public class A11yMenuAdapter extends BaseAdapter {
|
||||
ImageButton shortcutIconButton = convertView.findViewById(R.id.shortcutIconBtn);
|
||||
TextView shortcutLabel = convertView.findViewById(R.id.shortcutLabel);
|
||||
|
||||
// TODO: Enlarge shortcut icon & label when large button setting is on.
|
||||
if (A11yMenuPreferenceFragment.isLargeButtonsEnabled(mService)) {
|
||||
ViewGroup.LayoutParams params = shortcutIconButton.getLayoutParams();
|
||||
params.width = (int) (params.width * LARGE_BUTTON_SCALE);
|
||||
params.height = (int) (params.height * LARGE_BUTTON_SCALE);
|
||||
shortcutLabel.setTextSize(android.util.TypedValue.COMPLEX_UNIT_PX, mLargeTextSize);
|
||||
}
|
||||
|
||||
if (shortcutItem.getId() == A11yMenuShortcut.ShortcutId.UNSPECIFIED_ID_VALUE.ordinal()) {
|
||||
// Sets empty shortcut icon and label when the shortcut is ADD_ITEM.
|
||||
|
||||
@@ -43,6 +43,7 @@ import androidx.annotation.NonNull;
|
||||
|
||||
import com.android.systemui.accessibility.accessibilitymenu.AccessibilityMenuService;
|
||||
import com.android.systemui.accessibility.accessibilitymenu.R;
|
||||
import com.android.systemui.accessibility.accessibilitymenu.activity.A11yMenuSettingsActivity.A11yMenuPreferenceFragment;
|
||||
import com.android.systemui.accessibility.accessibilitymenu.model.A11yMenuShortcut;
|
||||
|
||||
import java.util.ArrayList;
|
||||
@@ -71,6 +72,24 @@ public class A11yMenuOverlayLayout {
|
||||
A11yMenuShortcut.ShortcutId.ID_SCREENSHOT_VALUE.ordinal()
|
||||
};
|
||||
|
||||
/** Predefined default shortcuts when large button setting is on. */
|
||||
private static final int[] LARGE_SHORTCUT_LIST_DEFAULT = {
|
||||
A11yMenuShortcut.ShortcutId.ID_ASSISTANT_VALUE.ordinal(),
|
||||
A11yMenuShortcut.ShortcutId.ID_A11YSETTING_VALUE.ordinal(),
|
||||
A11yMenuShortcut.ShortcutId.ID_POWER_VALUE.ordinal(),
|
||||
A11yMenuShortcut.ShortcutId.ID_RECENT_VALUE.ordinal(),
|
||||
A11yMenuShortcut.ShortcutId.ID_VOLUME_DOWN_VALUE.ordinal(),
|
||||
A11yMenuShortcut.ShortcutId.ID_VOLUME_UP_VALUE.ordinal(),
|
||||
A11yMenuShortcut.ShortcutId.ID_BRIGHTNESS_DOWN_VALUE.ordinal(),
|
||||
A11yMenuShortcut.ShortcutId.ID_BRIGHTNESS_UP_VALUE.ordinal(),
|
||||
A11yMenuShortcut.ShortcutId.ID_LOCKSCREEN_VALUE.ordinal(),
|
||||
A11yMenuShortcut.ShortcutId.ID_QUICKSETTING_VALUE.ordinal(),
|
||||
A11yMenuShortcut.ShortcutId.ID_NOTIFICATION_VALUE.ordinal(),
|
||||
A11yMenuShortcut.ShortcutId.ID_SCREENSHOT_VALUE.ordinal()
|
||||
};
|
||||
|
||||
|
||||
|
||||
private final AccessibilityMenuService mService;
|
||||
private final WindowManager mWindowManager;
|
||||
private ViewGroup mLayout;
|
||||
@@ -153,7 +172,10 @@ public class A11yMenuOverlayLayout {
|
||||
*/
|
||||
private List<A11yMenuShortcut> createShortcutList() {
|
||||
List<A11yMenuShortcut> shortcutList = new ArrayList<>();
|
||||
for (int shortcutId : SHORTCUT_LIST_DEFAULT) {
|
||||
|
||||
for (int shortcutId :
|
||||
(A11yMenuPreferenceFragment.isLargeButtonsEnabled(mService)
|
||||
? LARGE_SHORTCUT_LIST_DEFAULT : SHORTCUT_LIST_DEFAULT)) {
|
||||
shortcutList.add(new A11yMenuShortcut(shortcutId));
|
||||
}
|
||||
return shortcutList;
|
||||
|
||||
@@ -33,6 +33,7 @@ import androidx.viewpager.widget.ViewPager;
|
||||
|
||||
import com.android.systemui.accessibility.accessibilitymenu.AccessibilityMenuService;
|
||||
import com.android.systemui.accessibility.accessibilitymenu.R;
|
||||
import com.android.systemui.accessibility.accessibilitymenu.activity.A11yMenuSettingsActivity.A11yMenuPreferenceFragment;
|
||||
import com.android.systemui.accessibility.accessibilitymenu.model.A11yMenuShortcut;
|
||||
import com.android.systemui.accessibility.accessibilitymenu.view.A11yMenuFooter.A11yMenuFooterCallBack;
|
||||
|
||||
@@ -65,9 +66,6 @@ public class A11yMenuViewPager {
|
||||
/** The number of columns in the grid view when large button settings is on. */
|
||||
public static final int LARGE_GRID_COLUMN_COUNT = 2;
|
||||
|
||||
/** Temporary measure to test both item types. */
|
||||
private static final boolean USE_LARGE_ITEMS = false;
|
||||
|
||||
/**
|
||||
* Returns the number of items in the grid view.
|
||||
*
|
||||
@@ -75,7 +73,7 @@ public class A11yMenuViewPager {
|
||||
* @return Grid item count
|
||||
*/
|
||||
public static int getGridItemCount(Context context) {
|
||||
return USE_LARGE_ITEMS
|
||||
return A11yMenuPreferenceFragment.isLargeButtonsEnabled(context)
|
||||
? LARGE_GRID_ITEM_COUNT
|
||||
: GRID_ITEM_COUNT;
|
||||
}
|
||||
@@ -87,7 +85,7 @@ public class A11yMenuViewPager {
|
||||
* @return Grid column count
|
||||
*/
|
||||
public static int getGridColumnCount(Context context) {
|
||||
return USE_LARGE_ITEMS
|
||||
return A11yMenuPreferenceFragment.isLargeButtonsEnabled(context)
|
||||
? LARGE_GRID_COLUMN_COUNT
|
||||
: GRID_COLUMN_COUNT;
|
||||
}
|
||||
@@ -99,7 +97,7 @@ public class A11yMenuViewPager {
|
||||
* @return Grid row count
|
||||
*/
|
||||
public static int getGridRowCount(Context context) {
|
||||
return USE_LARGE_ITEMS
|
||||
return A11yMenuPreferenceFragment.isLargeButtonsEnabled(context)
|
||||
? (LARGE_GRID_ITEM_COUNT / LARGE_GRID_COLUMN_COUNT)
|
||||
: (GRID_ITEM_COUNT / GRID_COLUMN_COUNT);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user