Adding a carent in the scrim
> Caret is only visible when the accessibility is enabled
> It is visible in NOTMAL and OVERVIEW state and moves out of the
scrim along with the scrim.
> Acts as an accessible target for various options
Bug: 78172350
Bug: 79215734
Change-Id: I8a968b67e36901859649546295f6491d49cc9ce9
diff --git a/src/com/android/launcher3/Launcher.java b/src/com/android/launcher3/Launcher.java
index d8bb90a..333df05 100644
--- a/src/com/android/launcher3/Launcher.java
+++ b/src/com/android/launcher3/Launcher.java
@@ -194,7 +194,6 @@
private final int[] mTmpAddItemCellCoordinates = new int[2];
@Thunk Hotseat mHotseat;
- private View mDragHandleIndicator;
@Nullable private View mHotseatSearchBox;
private DropTargetBar mDropTargetBar;
@@ -920,7 +919,6 @@
mOverviewPanel = findViewById(R.id.overview_panel);
mOverviewPanelContainer = findViewById(R.id.overview_panel_container);
mHotseat = findViewById(R.id.hotseat);
- mDragHandleIndicator = findViewById(R.id.drag_indicator);
mHotseatSearchBox = findViewById(R.id.search_container_hotseat);
mLauncherView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
@@ -1181,10 +1179,6 @@
return mHotseat;
}
- public View getDragHandleIndicator() {
- return mDragHandleIndicator;
- }
-
public View getHotseatSearchBox() {
return mHotseatSearchBox;
}
diff --git a/src/com/android/launcher3/LauncherState.java b/src/com/android/launcher3/LauncherState.java
index f548095..a47d7f4 100644
--- a/src/com/android/launcher3/LauncherState.java
+++ b/src/com/android/launcher3/LauncherState.java
@@ -50,7 +50,6 @@
public static final int ALL_APPS_HEADER = 1 << 2;
public static final int ALL_APPS_HEADER_EXTRA = 1 << 3; // e.g. app predictions
public static final int ALL_APPS_CONTENT = 1 << 4;
- public static final int DRAG_HANDLE_INDICATOR = 1 << 5;
protected static final int FLAG_MULTI_PAGE = 1 << 0;
protected static final int FLAG_DISABLE_ACCESSIBILITY = 1 << 1;
@@ -194,9 +193,9 @@
public int getVisibleElements(Launcher launcher) {
if (launcher.getDeviceProfile().isVerticalBarLayout()) {
- return HOTSEAT_ICONS | DRAG_HANDLE_INDICATOR;
+ return HOTSEAT_ICONS;
}
- return HOTSEAT_ICONS | DRAG_HANDLE_INDICATOR | HOTSEAT_SEARCH_BOX;
+ return HOTSEAT_ICONS | HOTSEAT_SEARCH_BOX;
}
/**
diff --git a/src/com/android/launcher3/WorkspaceStateTransitionAnimation.java b/src/com/android/launcher3/WorkspaceStateTransitionAnimation.java
index 8d3d459..157dc1b 100644
--- a/src/com/android/launcher3/WorkspaceStateTransitionAnimation.java
+++ b/src/com/android/launcher3/WorkspaceStateTransitionAnimation.java
@@ -18,7 +18,6 @@
import static com.android.launcher3.LauncherAnimUtils.DRAWABLE_ALPHA;
import static com.android.launcher3.LauncherAnimUtils.SCALE_PROPERTY;
-import static com.android.launcher3.LauncherState.DRAG_HANDLE_INDICATOR;
import static com.android.launcher3.LauncherState.HOTSEAT_ICONS;
import static com.android.launcher3.LauncherState.HOTSEAT_SEARCH_BOX;
import static com.android.launcher3.anim.PropertySetter.NO_ANIM_PROPERTY_SETTER;
@@ -90,10 +89,6 @@
(elements & HOTSEAT_SEARCH_BOX) != 0 ? 1 : 0,
pageAlphaProvider.interpolator);
- propertySetter.setViewAlpha(mLauncher.getDragHandleIndicator(),
- (elements & DRAG_HANDLE_INDICATOR) != 0 ? 1 : 0,
- pageAlphaProvider.interpolator);
-
// Set scrim
propertySetter.setFloat(ViewScrim.get(mWorkspace), ViewScrim.PROGRESS,
state.getWorkspaceScrimAlpha(mLauncher), Interpolators.LINEAR);
diff --git a/src/com/android/launcher3/allapps/AllAppsTransitionController.java b/src/com/android/launcher3/allapps/AllAppsTransitionController.java
index 6d70a08..93514e2 100644
--- a/src/com/android/launcher3/allapps/AllAppsTransitionController.java
+++ b/src/com/android/launcher3/allapps/AllAppsTransitionController.java
@@ -101,7 +101,6 @@
mAppsView.setAlpha(1);
mLauncher.getHotseat().setTranslationY(0);
mLauncher.getWorkspace().getPageIndicator().setTranslationY(0);
- mLauncher.getDragHandleIndicator().setTranslationY(0);
}
}
@@ -125,7 +124,6 @@
if (!mIsVerticalLayout) {
mLauncher.getHotseat().setTranslationY(hotseatTranslation);
mLauncher.getWorkspace().getPageIndicator().setTranslationY(hotseatTranslation);
- mLauncher.getDragHandleIndicator().setTranslationY(hotseatTranslation);
}
// Use a light system UI (dark icons) if all apps is behind at least half of the
diff --git a/src/com/android/launcher3/views/LauncherDragIndicator.java b/src/com/android/launcher3/views/LauncherDragIndicator.java
deleted file mode 100644
index 986e4be..0000000
--- a/src/com/android/launcher3/views/LauncherDragIndicator.java
+++ /dev/null
@@ -1,129 +0,0 @@
-/*
- * Copyright (C) 2018 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.views;
-
-import static com.android.launcher3.LauncherState.ALL_APPS;
-
-import android.content.Context;
-import android.graphics.Rect;
-import android.os.Bundle;
-import android.util.AttributeSet;
-import android.view.Gravity;
-import android.view.View;
-import android.view.View.OnClickListener;
-import android.view.accessibility.AccessibilityNodeInfo;
-import android.view.accessibility.AccessibilityNodeInfo.AccessibilityAction;
-import android.widget.FrameLayout;
-import android.widget.ImageView;
-
-import com.android.launcher3.DeviceProfile;
-import com.android.launcher3.Insettable;
-import com.android.launcher3.Launcher;
-import com.android.launcher3.R;
-import com.android.launcher3.Utilities;
-import com.android.launcher3.userevent.nano.LauncherLogProto.Action;
-import com.android.launcher3.userevent.nano.LauncherLogProto.ControlType;
-
-public class LauncherDragIndicator extends ImageView implements Insettable, OnClickListener {
-
- 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;
-
- protected final Launcher mLauncher;
-
- public LauncherDragIndicator(Context context) {
- this(context, null);
- }
-
- public LauncherDragIndicator(Context context, AttributeSet attrs) {
- this(context, attrs, 0);
- }
-
- public LauncherDragIndicator(Context context, AttributeSet attrs, int defStyleAttr) {
- super(context, attrs, defStyleAttr);
- mLauncher = Launcher.getLauncher(context);
- setOnClickListener(this);
- }
-
- @Override
- public void setInsets(Rect insets) {
- DeviceProfile grid = mLauncher.getDeviceProfile();
- FrameLayout.LayoutParams lp = (FrameLayout.LayoutParams) getLayoutParams();
-
- if (grid.isVerticalBarLayout()) {
- if (grid.isSeascape()) {
- lp.leftMargin = grid.hotseatBarSidePaddingPx;
- lp.rightMargin = insets.right;
- lp.gravity = Gravity.RIGHT | Gravity.BOTTOM;
- } else {
- lp.leftMargin = insets.left;
- lp.rightMargin = grid.hotseatBarSidePaddingPx;
- lp.gravity = Gravity.LEFT | Gravity.BOTTOM;
- }
- lp.bottomMargin = grid.workspacePadding.bottom;
- setImageResource(R.drawable.all_apps_handle_landscape);
- } else {
- lp.leftMargin = lp.rightMargin = 0;
- lp.gravity = Gravity.CENTER_HORIZONTAL | Gravity.BOTTOM;
- lp.bottomMargin = getPortraitBottomMargin(grid, insets);
- setImageResource(R.drawable.ic_drag_indicator);
- }
-
- lp.width = lp.height = grid.pageIndicatorSizePx;
- setLayoutParams(lp);
- }
-
- protected int getPortraitBottomMargin(DeviceProfile grid, Rect insets) {
- return grid.hotseatBarSizePx + insets.bottom - grid.pageIndicatorSizePx;
- }
-
- @Override
- public void onInitializeAccessibilityNodeInfo(AccessibilityNodeInfo info) {
- super.onInitializeAccessibilityNodeInfo(info);
- initCustomActions(info);
- }
-
- protected void initCustomActions(AccessibilityNodeInfo info) {
- Context context = getContext();
- if (Utilities.isWallpaperAllowed(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(int action, Bundle arguments) {
- if (action == WALLPAPERS) {
- return OptionsPopupView.startWallpaperPicker(this);
- } else if (action == WIDGETS) {
- return OptionsPopupView.onWidgetsClicked(this);
- } else if (action == SETTINGS) {
- return OptionsPopupView.startSettings(this);
- }
- return super.performAccessibilityAction(action, arguments);
- }
-
- @Override
- public void onClick(View view) {
- if (!mLauncher.isInState(ALL_APPS)) {
- mLauncher.getUserEventDispatcher().logActionOnControl(
- Action.Touch.TAP, ControlType.ALL_APPS_BUTTON);
- mLauncher.getStateManager().goToState(ALL_APPS);
- }
- }
-}
diff --git a/src/com/android/launcher3/views/ScrimView.java b/src/com/android/launcher3/views/ScrimView.java
index b49b565..28602f5 100644
--- a/src/com/android/launcher3/views/ScrimView.java
+++ b/src/com/android/launcher3/views/ScrimView.java
@@ -15,28 +15,63 @@
*/
package com.android.launcher3.views;
+import static android.content.Context.ACCESSIBILITY_SERVICE;
import static android.support.v4.graphics.ColorUtils.compositeColors;
import static android.support.v4.graphics.ColorUtils.setAlphaComponent;
+import static com.android.launcher3.LauncherState.ALL_APPS;
+import static com.android.launcher3.LauncherState.NORMAL;
+
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Rect;
+import android.graphics.drawable.Drawable;
+import android.os.Bundle;
+import android.support.annotation.Nullable;
+import android.support.v4.view.ViewCompat;
+import android.support.v4.view.accessibility.AccessibilityNodeInfoCompat;
+import android.support.v4.view.accessibility.AccessibilityNodeInfoCompat.AccessibilityActionCompat;
+import android.support.v4.widget.ExploreByTouchHelper;
import android.util.AttributeSet;
+import android.view.KeyEvent;
+import android.view.MotionEvent;
import android.view.View;
+import android.view.accessibility.AccessibilityManager;
+import android.view.accessibility.AccessibilityManager.AccessibilityStateChangeListener;
+import com.android.launcher3.DeviceProfile;
import com.android.launcher3.Insettable;
+import com.android.launcher3.Launcher;
+import com.android.launcher3.LauncherState;
+import com.android.launcher3.LauncherStateManager;
+import com.android.launcher3.LauncherStateManager.StateListener;
import com.android.launcher3.R;
+import com.android.launcher3.Utilities;
import com.android.launcher3.uioverrides.WallpaperColorInfo;
import com.android.launcher3.uioverrides.WallpaperColorInfo.OnChangeListener;
+import com.android.launcher3.userevent.nano.LauncherLogProto.Action;
+import com.android.launcher3.userevent.nano.LauncherLogProto.ControlType;
import com.android.launcher3.util.Themes;
+import java.util.List;
+
/**
* Simple scrim which draws a flat color
*/
-public class ScrimView extends View implements Insettable, OnChangeListener {
+public class ScrimView extends View implements Insettable, OnChangeListener,
+ AccessibilityStateChangeListener, StateListener {
+ 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;
+
+ private final Rect mTempRect = new Rect();
+ private final int[] mTempPos = new int[2];
+
+ protected final Launcher mLauncher;
private final WallpaperColorInfo mWallpaperColorInfo;
+ private final AccessibilityManager mAM;
protected final int mEndScrim;
protected float mMaxScrimAlpha;
@@ -48,28 +83,56 @@
protected int mEndFlatColor;
protected int mEndFlatColorAlpha;
+ protected final int mDragHandleSize;
+ private final Rect mDragHandleBounds;
+ private final AccessibilityHelper mAccessibilityHelper;
+ @Nullable
+ protected Drawable mDragHandle;
+
public ScrimView(Context context, AttributeSet attrs) {
super(context, attrs);
+ mLauncher = Launcher.getLauncher(context);
mWallpaperColorInfo = WallpaperColorInfo.getInstance(context);
mEndScrim = Themes.getAttrColor(context, R.attr.allAppsScrimColor);
mMaxScrimAlpha = 0.7f;
+
+ mDragHandleSize = context.getResources()
+ .getDimensionPixelSize(R.dimen.vertical_drag_handle_size);
+ mDragHandleBounds = new Rect(0, 0, mDragHandleSize, mDragHandleSize);
+
+ mAccessibilityHelper = new AccessibilityHelper();
+ ViewCompat.setAccessibilityDelegate(this, mAccessibilityHelper);
+
+ mAM = (AccessibilityManager) context.getSystemService(ACCESSIBILITY_SERVICE);
}
@Override
- public void setInsets(Rect insets) { }
+ public void setInsets(Rect insets) {
+ updateDragHandleBounds();
+ }
+
+ @Override
+ protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
+ super.onMeasure(widthMeasureSpec, heightMeasureSpec);
+ updateDragHandleBounds();
+ }
@Override
protected void onAttachedToWindow() {
super.onAttachedToWindow();
mWallpaperColorInfo.addOnChangeListener(this);
onExtractedColorsChanged(mWallpaperColorInfo);
+
+ mAM.addAccessibilityStateChangeListener(this);
+ onAccessibilityStateChanged(mAM.isEnabled());
}
@Override
protected void onDetachedFromWindow() {
super.onDetachedFromWindow();
mWallpaperColorInfo.removeOnChangeListener(this);
+ mAM.removeAccessibilityStateChangeListener(this);
}
@Override
@@ -91,6 +154,7 @@
if (mProgress != progress) {
mProgress = progress;
updateColors();
+ updateDragHandleAlpha();
invalidate();
}
}
@@ -102,10 +166,158 @@
mEndFlatColor, Math.round((1 - mProgress) * mEndFlatColorAlpha));
}
+ protected void updateDragHandleAlpha() {
+ if (mDragHandle != null) {
+ mDragHandle.setAlpha(Math.round(255 * Utilities.boundToRange(mProgress, 0, 1)));
+ }
+ }
+
@Override
protected void onDraw(Canvas canvas) {
if (mCurrentFlatColor != 0) {
canvas.drawColor(mCurrentFlatColor);
}
}
+
+ protected void updateDragHandleBounds() {
+ DeviceProfile grid = mLauncher.getDeviceProfile();
+ final int left;
+ final int width = getMeasuredWidth();
+ final int top = getMeasuredHeight() - mDragHandleSize - grid.getInsets().bottom;
+ final int topMargin;
+
+ if (grid.isVerticalBarLayout()) {
+ topMargin = grid.workspacePadding.bottom;
+ if (grid.isSeascape()) {
+ left = width - grid.getInsets().right - mDragHandleSize;
+ } else {
+ left = mDragHandleSize + grid.getInsets().left;
+ }
+ } else {
+ left = (width - mDragHandleSize) / 2;
+ topMargin = grid.hotseatBarSizePx;
+ }
+ mDragHandleBounds.offsetTo(left, top - topMargin);
+
+ if (mDragHandle != null) {
+ mDragHandle.setBounds(mDragHandleBounds);
+ }
+ }
+
+ @Override
+ public void onAccessibilityStateChanged(boolean enabled) {
+ LauncherStateManager stateManager = mLauncher.getStateManager();
+ stateManager.removeStateListener(this);
+
+ if (enabled) {
+ mDragHandle = mLauncher.getDrawable(R.drawable.drag_handle_indicator);
+ mDragHandle.setBounds(mDragHandleBounds);
+
+ stateManager.addStateListener(this);
+ onStateSetImmediately(mLauncher.getStateManager().getState());
+
+ updateDragHandleAlpha();
+ } else {
+ mDragHandle = null;
+ }
+ invalidate();
+ }
+
+ @Override
+ public boolean dispatchHoverEvent(MotionEvent event) {
+ return mAccessibilityHelper.dispatchHoverEvent(event) || super.dispatchHoverEvent(event);
+ }
+
+ @Override
+ public boolean dispatchKeyEvent(KeyEvent event) {
+ return mAccessibilityHelper.dispatchKeyEvent(event) || super.dispatchKeyEvent(event);
+ }
+
+ @Override
+ public void onFocusChanged(boolean gainFocus, int direction,
+ Rect previouslyFocusedRect) {
+ super.onFocusChanged(gainFocus, direction, previouslyFocusedRect);
+ mAccessibilityHelper.onFocusChanged(gainFocus, direction, previouslyFocusedRect);
+ }
+
+ @Override
+ public void onStateTransitionStart(LauncherState toState) {}
+
+ @Override
+ public void onStateTransitionComplete(LauncherState finalState) {
+ onStateSetImmediately(finalState);
+ }
+
+ @Override
+ public void onStateSetImmediately(LauncherState state) {
+ setImportantForAccessibility(state == ALL_APPS
+ ? IMPORTANT_FOR_ACCESSIBILITY_NO_HIDE_DESCENDANTS
+ : IMPORTANT_FOR_ACCESSIBILITY_AUTO);
+ }
+
+ private class AccessibilityHelper extends ExploreByTouchHelper {
+
+ private static final int DRAG_HANDLE_ID = 1;
+
+ public AccessibilityHelper() {
+ super(ScrimView.this);
+ }
+
+ @Override
+ protected int getVirtualViewAt(float x, float y) {
+ return mDragHandleBounds.contains((int) x, (int) y)
+ ? DRAG_HANDLE_ID : INVALID_ID;
+ }
+
+ @Override
+ protected void getVisibleVirtualViews(List<Integer> virtualViewIds) {
+ virtualViewIds.add(DRAG_HANDLE_ID);
+ }
+
+ @Override
+ protected void onPopulateNodeForVirtualView(int virtualViewId,
+ AccessibilityNodeInfoCompat node) {
+ node.setContentDescription(getContext().getString(R.string.all_apps_button_label));
+ node.setBoundsInParent(mDragHandleBounds);
+
+ getLocationOnScreen(mTempPos);
+ mTempRect.set(mDragHandleBounds);
+ mTempRect.offset(mTempPos[0], mTempPos[1]);
+ node.setBoundsInScreen(mTempRect);
+
+ node.addAction(AccessibilityNodeInfoCompat.ACTION_CLICK);
+ node.setClickable(true);
+ node.setFocusable(true);
+
+ if (mLauncher.isInState(NORMAL)) {
+ Context context = getContext();
+ if (Utilities.isWallpaperAllowed(context)) {
+ node.addAction(
+ new AccessibilityActionCompat(WALLPAPERS, context.getText(WALLPAPERS)));
+ }
+ node.addAction(new AccessibilityActionCompat(WIDGETS, context.getText(WIDGETS)));
+ node.addAction(new AccessibilityActionCompat(SETTINGS, context.getText(SETTINGS)));
+ }
+ }
+
+ @Override
+ protected boolean onPerformActionForVirtualView(
+ int virtualViewId, int action, Bundle arguments) {
+ if (action == AccessibilityNodeInfoCompat.ACTION_CLICK) {
+ mLauncher.getUserEventDispatcher().logActionOnControl(
+ Action.Touch.TAP, ControlType.ALL_APPS_BUTTON,
+ mLauncher.getStateManager().getState().containerType);
+ mLauncher.getStateManager().goToState(ALL_APPS);
+ return true;
+ } else if (action == WALLPAPERS) {
+ return OptionsPopupView.startWallpaperPicker(ScrimView.this);
+ } else if (action == WIDGETS) {
+ return OptionsPopupView.onWidgetsClicked(ScrimView.this);
+ } else if (action == SETTINGS) {
+ return OptionsPopupView.startSettings(ScrimView.this);
+ }
+
+ return false;
+ }
+ }
}