From d0a6ae7f645e6ba564aebb50316c53fa2e119459 Mon Sep 17 00:00:00 2001 From: Sunny Goyal Date: Thu, 16 Jun 2016 12:29:03 -0700 Subject: Accessibility fixes and updates > Adding custom actions on the page indicator to go to overview mode > Disabling custom actions on the first page > Disabling 'move page left' on the second page Change-Id: Ib8154f70cb3f93e663a881357c6c46c33253887f --- src/com/android/launcher3/Launcher.java | 16 ++--- src/com/android/launcher3/PagedView.java | 37 ++--------- src/com/android/launcher3/Workspace.java | 61 +++++++----------- .../OverviewAccessibilityDelegate.java | 72 ++++++++++++++++++++++ .../OverviewScreenAccessibilityDelegate.java | 5 +- .../android/launcher3/folder/FolderPagedView.java | 1 + 6 files changed, 110 insertions(+), 82 deletions(-) create mode 100644 src/com/android/launcher3/accessibility/OverviewAccessibilityDelegate.java (limited to 'src') diff --git a/src/com/android/launcher3/Launcher.java b/src/com/android/launcher3/Launcher.java index ae1b6b8fa..da1e4790e 100644 --- a/src/com/android/launcher3/Launcher.java +++ b/src/com/android/launcher3/Launcher.java @@ -234,7 +234,6 @@ public class Launcher extends Activity @Thunk Workspace mWorkspace; private View mLauncherView; - private PageIndicator mPageIndicator; @Thunk DragLayer mDragLayer; private DragController mDragController; @@ -509,9 +508,7 @@ public class Launcher extends Activity if (mExtractedColors != null && Utilities.isNycOrAbove()) { mExtractedColors.load(this); mHotseat.updateColor(mExtractedColors, !mPaused); - if (mPageIndicator != null) { - mPageIndicator.updateColor(mExtractedColors); - } + mWorkspace.getPageIndicator().updateColor(mExtractedColors); } } @@ -1325,9 +1322,8 @@ public class Launcher extends Activity mLauncherView = findViewById(R.id.launcher); mDragLayer = (DragLayer) findViewById(R.id.drag_layer); mFocusHandler = mDragLayer.getFocusIndicatorHelper(); - mWorkspace = (Workspace) mDragLayer.findViewById(R.id.workspace); - mPageIndicator = (PageIndicator) mDragLayer.findViewById(R.id.page_indicator); + mWorkspace.initParentViews(mDragLayer); mLauncherView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION @@ -2680,7 +2676,7 @@ public class Launcher extends Activity * Event handler for the (Add) Widgets button that appears after a long press * on the home screen. */ - protected void onClickAddWidgetButton(View view) { + public void onClickAddWidgetButton(View view) { if (LOGD) Log.d(TAG, "onClickAddWidgetButton"); if (mIsSafeModeEnabled) { Toast.makeText(this, R.string.safemode_widget_error, Toast.LENGTH_SHORT).show(); @@ -2693,7 +2689,7 @@ public class Launcher extends Activity * Event handler for the wallpaper picker button that appears after a long press * on the home screen. */ - protected void onClickWallpaperPicker(View v) { + public void onClickWallpaperPicker(View v) { if (!Utilities.isWallapaperAllowed(this)) { Toast.makeText(this, R.string.msg_disabled_by_admin, Toast.LENGTH_SHORT).show(); return; @@ -2716,7 +2712,7 @@ public class Launcher extends Activity * Event handler for a click on the settings button that appears after a long press * on the home screen. */ - private void onClickSettingsButton(View v) { + public void onClickSettingsButton(View v) { if (LOGD) Log.d(TAG, "onClickSettingsButton"); startActivity(new Intent(Utilities.ACTION_APPLICATION_PREFERENCES) .setPackage(getPackageName())); @@ -3250,7 +3246,7 @@ public class Launcher extends Activity /** * Shows the overview button. */ - void showOverviewMode(boolean animated) { + public void showOverviewMode(boolean animated) { showOverviewMode(animated, false); } diff --git a/src/com/android/launcher3/PagedView.java b/src/com/android/launcher3/PagedView.java index 926679314..5ac3f0bab 100644 --- a/src/com/android/launcher3/PagedView.java +++ b/src/com/android/launcher3/PagedView.java @@ -154,7 +154,7 @@ public abstract class PagedView extends ViewGroup implements ViewGroup.OnHierarc // Page Indicator @Thunk int mPageIndicatorViewId; - @Thunk PageIndicator mPageIndicator; + protected PageIndicator mPageIndicator; // The viewport whether the pages are to be contained (the actual view may be larger than the // viewport) @ViewDebug.ExportedProperty(category = "launcher") @@ -247,39 +247,14 @@ public abstract class PagedView extends ViewGroup implements ViewGroup.OnHierarc mScroller.setInterpolator(mDefaultInterpolator); } - protected void onAttachedToWindow() { - super.onAttachedToWindow(); - - // Hook up the page indicator - ViewGroup parent = (ViewGroup) getParent(); - ViewGroup grandParent = (ViewGroup) parent.getParent(); - if (mPageIndicator == null && mPageIndicatorViewId > -1) { - mPageIndicator = (PageIndicator) grandParent.findViewById(mPageIndicatorViewId); + public void initParentViews(View parent) { + if (mPageIndicatorViewId > -1) { + mPageIndicator = (PageIndicator) parent.findViewById(mPageIndicatorViewId); mPageIndicator.setMarkersCount(getChildCount()); - - OnClickListener listener = getPageIndicatorClickListener(); - if (listener != null) { - mPageIndicator.setOnClickListener(listener); - } - mPageIndicator.setContentDescription(getPageIndicatorDescription()); + mPageIndicator.setContentDescription(getCurrentPageDescription()); } } - protected String getPageIndicatorDescription() { - return getCurrentPageDescription(); - } - - protected OnClickListener getPageIndicatorClickListener() { - return null; - } - - @Override - protected void onDetachedFromWindow() { - super.onDetachedFromWindow(); - // Unhook the page indicator - mPageIndicator = null; - } - // Convenience methods to map points from self to parent and vice versa private float[] mapPointFromViewToParent(View v, float x, float y) { sTmpPoint[0] = x; @@ -467,7 +442,7 @@ public abstract class PagedView extends ViewGroup implements ViewGroup.OnHierarc private void updatePageIndicator() { // Update the page indicator (when we aren't reordering) if (mPageIndicator != null) { - mPageIndicator.setContentDescription(getPageIndicatorDescription()); + mPageIndicator.setContentDescription(getCurrentPageDescription()); if (!isReordering(false)) { mPageIndicator.setActiveMarker(getNextPage()); } diff --git a/src/com/android/launcher3/Workspace.java b/src/com/android/launcher3/Workspace.java index 24736d48e..50bddddde 100644 --- a/src/com/android/launcher3/Workspace.java +++ b/src/com/android/launcher3/Workspace.java @@ -61,6 +61,7 @@ import com.android.launcher3.Launcher.LauncherOverlay; import com.android.launcher3.UninstallDropTarget.DropTargetSource; import com.android.launcher3.accessibility.LauncherAccessibilityDelegate; import com.android.launcher3.accessibility.LauncherAccessibilityDelegate.AccessibilityDragSource; +import com.android.launcher3.accessibility.OverviewAccessibilityDelegate; import com.android.launcher3.accessibility.OverviewScreenAccessibilityDelegate; import com.android.launcher3.accessibility.WorkspaceAccessibilityHelper; import com.android.launcher3.compat.AppWidgetManagerCompat; @@ -458,6 +459,12 @@ public class Workspace extends PagedView setEdgeGlowColor(getResources().getColor(R.color.workspace_edge_effect_color)); } + @Override + public void initParentViews(View parent) { + super.initParentViews(parent); + mPageIndicator.setAccessibilityDelegate(new OverviewAccessibilityDelegate()); + } + private int getDefaultPage() { return numCustomPages(); } @@ -1445,10 +1452,9 @@ public class Workspace extends PagedView mHotseatAlpha[direction.ordinal()] = alpha; float finalAlpha = mHotseatAlpha[0] * mHotseatAlpha[1]; - View pageIndicator = getPageIndicator(); - if (pageIndicator != null) { - property.set(pageIndicator, translation); - pageIndicator.setAlpha(finalAlpha); + if (mPageIndicator != null) { + property.set(mPageIndicator, translation); + mPageIndicator.setAlpha(alpha); } property.set(mLauncher.getHotseat(), translation); @@ -1647,8 +1653,8 @@ public class Workspace extends PagedView mLauncher.getHotseat().setTranslationX(translationX); } - if (getPageIndicator() != null) { - getPageIndicator().setTranslationX(translationX); + if (mPageIndicator != null) { + mPageIndicator.setTranslationX(translationX); } if (mCustomContentCallbacks != null) { @@ -1656,21 +1662,6 @@ public class Workspace extends PagedView } } - @Override - protected OnClickListener getPageIndicatorClickListener() { - AccessibilityManager am = (AccessibilityManager) - getContext().getSystemService(Context.ACCESSIBILITY_SERVICE); - if (!am.isTouchExplorationEnabled()) { - return null; - } - return new OnClickListener() { - @Override - public void onClick(View arg0) { - mLauncher.showOverviewMode(true); - } - }; - } - @Override protected void screenScrolled(int screenCenter) { updatePageAlphaValues(screenCenter); @@ -1692,15 +1683,6 @@ public class Workspace extends PagedView } protected void onResume() { - if (getPageIndicator() != null) { - // In case accessibility state has changed, we need to perform this on every - // attach to window - OnClickListener listener = getPageIndicatorClickListener(); - if (listener != null) { - getPageIndicator().setOnClickListener(listener); - } - } - // Update wallpaper dimensions if they were changed since last onResume // (we also always set the wallpaper dimensions in the constructor) if (LauncherAppState.getInstance().hasWallpaperChangedSinceLastCheck()) { @@ -2086,10 +2068,13 @@ public class Workspace extends PagedView IMPORTANT_FOR_ACCESSIBILITY_NO_HIDE_DESCENDANTS); page.setContentDescription(getPageDescription(pageNo)); - if (mPagesAccessibilityDelegate == null) { - mPagesAccessibilityDelegate = new OverviewScreenAccessibilityDelegate(this); + // No custom action for the first page. + if (!FeatureFlags.QSB_ON_FIRST_SCREEN || pageNo > 0) { + if (mPagesAccessibilityDelegate == null) { + mPagesAccessibilityDelegate = new OverviewScreenAccessibilityDelegate(this); + } + page.setAccessibilityDelegate(mPagesAccessibilityDelegate); } - page.setAccessibilityDelegate(mPagesAccessibilityDelegate); } else { int accessible = mState == State.NORMAL ? IMPORTANT_FOR_ACCESSIBILITY_AUTO : @@ -2118,7 +2103,7 @@ public class Workspace extends PagedView @Override public void onLauncherTransitionStart(Launcher l, boolean animated, boolean toWorkspace) { - if (mPageIndicator instanceof PageIndicator) { + if (mPageIndicator != null) { boolean isNewStateSpringLoaded = mState == State.SPRING_LOADED; mPageIndicator.setShouldAutoHide(!isNewStateSpringLoaded); if (isNewStateSpringLoaded) { @@ -4195,7 +4180,7 @@ public class Workspace extends PagedView public interface ItemOperator { /** - * Process the next itemInfo, possibly with side-effect on {@link ItemOperator#value}. + * Process the next itemInfo, possibly with side-effect on the next item. * * @param info info for the shortcut * @param view view for the shortcut @@ -4379,11 +4364,7 @@ public class Workspace extends PagedView exitWidgetResizeMode(); } - protected String getPageIndicatorDescription() { - String settings = getResources().getString(R.string.settings_button_text); - return getCurrentPageDescription() + ", " + settings; - } - + @Override protected String getCurrentPageDescription() { if (hasCustomContent() && getNextPage() == 0) { return mCustomContentDescription; diff --git a/src/com/android/launcher3/accessibility/OverviewAccessibilityDelegate.java b/src/com/android/launcher3/accessibility/OverviewAccessibilityDelegate.java new file mode 100644 index 000000000..64559f2ec --- /dev/null +++ b/src/com/android/launcher3/accessibility/OverviewAccessibilityDelegate.java @@ -0,0 +1,72 @@ +/* + * Copyright (C) 2016 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.launcher3.accessibility; + +import android.content.Context; +import android.os.Bundle; +import android.view.View; +import android.view.View.AccessibilityDelegate; +import android.view.accessibility.AccessibilityNodeInfo; +import android.view.accessibility.AccessibilityNodeInfo.AccessibilityAction; + +import com.android.launcher3.Launcher; +import com.android.launcher3.R; +import com.android.launcher3.Utilities; + +/** + * Accessibility delegate with actions pointing to various Overview entry points. + */ +public class OverviewAccessibilityDelegate extends AccessibilityDelegate { + + private static final int OVERVIEW = R.string.accessibility_action_overview; + private static final int WALLPAPERS = R.string.wallpaper_button_text; + private static final int WIDGETS = R.string.widget_button_text; + private static final int SETTINGS = R.string.settings_button_text; + + @Override + public void onInitializeAccessibilityNodeInfo(View host, AccessibilityNodeInfo info) { + super.onInitializeAccessibilityNodeInfo(host, info); + + Context context = host.getContext(); + info.addAction(new AccessibilityAction(OVERVIEW, context.getText(OVERVIEW))); + + if (Utilities.isWallapaperAllowed(context)) { + info.addAction(new AccessibilityAction(WALLPAPERS, context.getText(WALLPAPERS))); + } + info.addAction(new AccessibilityAction(WIDGETS, context.getText(WIDGETS))); + info.addAction(new AccessibilityAction(SETTINGS, context.getText(SETTINGS))); + } + + @Override + public boolean performAccessibilityAction(View host, int action, Bundle args) { + Launcher launcher = (Launcher) host.getContext(); + if (action == OVERVIEW) { + launcher.showOverviewMode(true); + return true; + } else if (action == WALLPAPERS) { + launcher.onClickWallpaperPicker(host); + return true; + } else if (action == WIDGETS) { + launcher.onClickAddWidgetButton(host); + return true; + } else if (action == SETTINGS) { + launcher.onClickSettingsButton(host); + return true; + } + return super.performAccessibilityAction(host, action, args); + } +} diff --git a/src/com/android/launcher3/accessibility/OverviewScreenAccessibilityDelegate.java b/src/com/android/launcher3/accessibility/OverviewScreenAccessibilityDelegate.java index c5b52de72..5f68f90b1 100644 --- a/src/com/android/launcher3/accessibility/OverviewScreenAccessibilityDelegate.java +++ b/src/com/android/launcher3/accessibility/OverviewScreenAccessibilityDelegate.java @@ -28,6 +28,7 @@ import android.view.accessibility.AccessibilityNodeInfo.AccessibilityAction; import com.android.launcher3.R; import com.android.launcher3.Utilities; import com.android.launcher3.Workspace; +import com.android.launcher3.config.FeatureFlags; @TargetApi(Build.VERSION_CODES.LOLLIPOP) public class OverviewScreenAccessibilityDelegate extends AccessibilityDelegate { @@ -88,7 +89,9 @@ public class OverviewScreenAccessibilityDelegate extends AccessibilityDelegate { if (index < mWorkspace.getChildCount() - 1) { info.addAction(mActions.get(MOVE_FORWARD)); } - if (index > mWorkspace.numCustomPages()) { + + int startIndex = mWorkspace.numCustomPages() + (FeatureFlags.QSB_ON_FIRST_SCREEN ? 1 : 0); + if (index > startIndex) { info.addAction(mActions.get(MOVE_BACKWARD)); } } diff --git a/src/com/android/launcher3/folder/FolderPagedView.java b/src/com/android/launcher3/folder/FolderPagedView.java index c56e4e5f9..c6fc4cb63 100644 --- a/src/com/android/launcher3/folder/FolderPagedView.java +++ b/src/com/android/launcher3/folder/FolderPagedView.java @@ -120,6 +120,7 @@ public class FolderPagedView extends PagedView { mFolder = folder; mKeyListener = new PagedFolderKeyEventListener(folder); mPageIndicator = (PageIndicator) folder.findViewById(R.id.folder_page_indicator); + initParentViews(folder); } /** -- cgit v1.2.3