diff options
17 files changed, 254 insertions, 316 deletions
diff --git a/quickstep/res/layout/drag_handle_indicator.xml b/quickstep/res/layout/drag_handle_indicator.xml deleted file mode 100644 index 9ee05d5ad..000000000 --- a/quickstep/res/layout/drag_handle_indicator.xml +++ /dev/null @@ -1,23 +0,0 @@ -<?xml version="1.0" encoding="utf-8"?> -<!-- 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. ---> -<com.android.quickstep.views.QuickstepDragIndicator - xmlns:android="http://schemas.android.com/apk/res/android" - android:id="@+id/drag_indicator" - android:layout_width="wrap_content" - android:layout_height="wrap_content" - android:contentDescription="@string/accessibility_desc_recent_apps" - android:scaleType="centerInside" - android:tint="?attr/workspaceTextColor" /> diff --git a/quickstep/res/values/dimens.xml b/quickstep/res/values/dimens.xml index 9e4d60c5e..225f564a0 100644 --- a/quickstep/res/values/dimens.xml +++ b/quickstep/res/values/dimens.xml @@ -50,5 +50,4 @@ <dimen name="clear_all_container_width">168dp</dimen> <dimen name="shelf_surface_radius">16dp</dimen> - <dimen name="shelf_surface_top_padding">4dp</dimen> </resources> diff --git a/quickstep/src/com/android/launcher3/uioverrides/OverviewState.java b/quickstep/src/com/android/launcher3/uioverrides/OverviewState.java index 91e1e7faa..a01e18482 100644 --- a/quickstep/src/com/android/launcher3/uioverrides/OverviewState.java +++ b/quickstep/src/com/android/launcher3/uioverrides/OverviewState.java @@ -92,9 +92,9 @@ public class OverviewState extends LauncherState { @Override public int getVisibleElements(Launcher launcher) { if (launcher.getDeviceProfile().isVerticalBarLayout()) { - return DRAG_HANDLE_INDICATOR; + return 0; } else { - return HOTSEAT_SEARCH_BOX | DRAG_HANDLE_INDICATOR | + return HOTSEAT_SEARCH_BOX | (launcher.getAppsView().getFloatingHeaderView().hasVisibleContent() ? ALL_APPS_HEADER_EXTRA : HOTSEAT_ICONS); } diff --git a/quickstep/src/com/android/quickstep/util/LayoutUtils.java b/quickstep/src/com/android/quickstep/util/LayoutUtils.java index b1fa5e2b8..2ff70dde4 100644 --- a/quickstep/src/com/android/quickstep/util/LayoutUtils.java +++ b/quickstep/src/com/android/quickstep/util/LayoutUtils.java @@ -43,8 +43,7 @@ public class LayoutUtils { extraSpace = 0; } else { Resources res = context.getResources(); - extraSpace = dp.hotseatBarSizePx + res.getDimension(R.dimen.shelf_surface_top_padding) - + res.getDimension(R.dimen.shelf_surface_radius); + extraSpace = dp.hotseatBarSizePx + res.getDimension(R.dimen.vertical_drag_handle_size); } calculateTaskSize(context, dp, extraSpace, MULTI_WINDOW_STRATEGY_HALF_SCREEN, outRect); } diff --git a/quickstep/src/com/android/quickstep/views/QuickstepDragIndicator.java b/quickstep/src/com/android/quickstep/views/QuickstepDragIndicator.java deleted file mode 100644 index 5e9cd6e4f..000000000 --- a/quickstep/src/com/android/quickstep/views/QuickstepDragIndicator.java +++ /dev/null @@ -1,70 +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.quickstep.views; - -import static com.android.launcher3.LauncherState.ALL_APPS; -import static com.android.launcher3.LauncherState.OVERVIEW; - -import android.content.Context; -import android.util.AttributeSet; -import android.view.View; -import android.view.accessibility.AccessibilityNodeInfo; - -import com.android.launcher3.R; -import com.android.launcher3.userevent.nano.LauncherLogProto.Action; -import com.android.launcher3.userevent.nano.LauncherLogProto.ContainerType; -import com.android.launcher3.userevent.nano.LauncherLogProto.ControlType; -import com.android.launcher3.views.LauncherDragIndicator; - -public class QuickstepDragIndicator extends LauncherDragIndicator { - - public QuickstepDragIndicator(Context context) { - super(context); - } - - public QuickstepDragIndicator(Context context, AttributeSet attrs) { - super(context, attrs); - } - - public QuickstepDragIndicator(Context context, AttributeSet attrs, int defStyleAttr) { - super(context, attrs, defStyleAttr); - } - - private boolean isInOverview() { - return mLauncher.isInState(OVERVIEW); - } - - @Override - public void onInitializeAccessibilityNodeInfo(AccessibilityNodeInfo info) { - super.onInitializeAccessibilityNodeInfo(info); - info.setContentDescription(getContext().getString(R.string.all_apps_button_label)); - } - - @Override - protected void initCustomActions(AccessibilityNodeInfo info) { - if (!isInOverview()) { - super.initCustomActions(info); - } - } - - @Override - public void onClick(View view) { - mLauncher.getUserEventDispatcher().logActionOnControl(Action.Touch.TAP, - ControlType.ALL_APPS_BUTTON, - isInOverview() ? ContainerType.TASKSWITCHER : ContainerType.WORKSPACE); - mLauncher.getStateManager().goToState(ALL_APPS); - } -} diff --git a/quickstep/src/com/android/quickstep/views/ShelfScrimView.java b/quickstep/src/com/android/quickstep/views/ShelfScrimView.java index aa0467211..b47af2d3a 100644 --- a/quickstep/src/com/android/quickstep/views/ShelfScrimView.java +++ b/quickstep/src/com/android/quickstep/views/ShelfScrimView.java @@ -31,7 +31,6 @@ import android.graphics.Path.Op; import android.util.AttributeSet; import com.android.launcher3.DeviceProfile; -import com.android.launcher3.Launcher; import com.android.launcher3.R; import com.android.launcher3.uioverrides.OverviewState; import com.android.launcher3.util.Themes; @@ -49,8 +48,6 @@ public class ShelfScrimView extends ScrimView { private static final int THRESHOLD_ALPHA_DARK = 102; private static final int THRESHOLD_ALPHA_LIGHT = 46; - private final Launcher mLauncher; - // In transposed layout, we simply draw a flat color. private boolean mDrawingFlatColor; @@ -58,7 +55,6 @@ public class ShelfScrimView extends ScrimView { private final int mEndAlpha; private final int mThresholdAlpha; private final float mRadius; - private final float mTopPadding; private final float mMaxScrimAlpha; private final Paint mPaint; @@ -77,15 +73,12 @@ public class ShelfScrimView extends ScrimView { public ShelfScrimView(Context context, AttributeSet attrs) { super(context, attrs); - - mLauncher = Launcher.getLauncher(context); mMaxScrimAlpha = OVERVIEW.getWorkspaceScrimAlpha(mLauncher); mEndAlpha = Color.alpha(mEndScrim); mThresholdAlpha = Themes.getAttrBoolean(mLauncher, R.attr.isMainColorDark) ? THRESHOLD_ALPHA_DARK : THRESHOLD_ALPHA_LIGHT; mRadius = mLauncher.getResources().getDimension(R.dimen.shelf_surface_radius); - mTopPadding = mLauncher.getResources().getDimension(R.dimen.shelf_surface_top_padding); mPaint = new Paint(Paint.ANTI_ALIAS_FLAG); // Just assume the easiest UI for now, until we have the proper layout information. @@ -110,10 +103,10 @@ public class ShelfScrimView extends ScrimView { mRemainingScreenPathValid = false; updateColors(); } + updateDragHandleAlpha(); invalidate(); } - @Override public void updateColors() { super.updateColors(); @@ -131,6 +124,7 @@ public class ShelfScrimView extends ScrimView { (1 - mProgress) / (1 - mMoveThreshold))); mShelfColor = setAlphaComponent(mEndScrim, alpha); } + mRemainingScreenColor = 0; } else if (mProgress <= 0) { mScrimMoveFactor = 0; @@ -150,23 +144,42 @@ public class ShelfScrimView extends ScrimView { } @Override + protected void updateDragHandleAlpha() { + if (mDrawingFlatColor) { + super.updateDragHandleAlpha(); + } else if (mDragHandle != null) { + mDragHandle.setAlpha(255); + } + } + + @Override protected void onDraw(Canvas canvas) { + float translate = drawBackground(canvas); + + if (mDragHandle != null) { + canvas.translate(0, -translate); + mDragHandle.draw(canvas); + canvas.translate(0, translate); + } + } + + private float drawBackground(Canvas canvas) { if (mDrawingFlatColor) { if (mCurrentFlatColor != 0) { canvas.drawColor(mCurrentFlatColor); } - return; + return 0; } if (mShelfColor == 0) { - return; + return 0; } else if (mScrimMoveFactor <= 0) { canvas.drawColor(mShelfColor); - return; + return getHeight(); } float minTop = getHeight() - mMinSize; - float top = minTop * mScrimMoveFactor - mTopPadding - mRadius; + float top = minTop * mScrimMoveFactor - mDragHandleSize; // Draw the scrim over the remaining screen if needed. if (mRemainingScreenColor != 0) { @@ -192,5 +205,6 @@ public class ShelfScrimView extends ScrimView { mPaint.setColor(mShelfColor); canvas.drawRoundRect(0, top, getWidth(), getHeight() + mRadius, mRadius, mRadius, mPaint); + return minTop - mDragHandleSize - top; } } diff --git a/res/drawable/all_apps_handle_landscape.xml b/res/drawable/drag_handle_indicator.xml index 15518ffaa..b01b84ab8 100644 --- a/res/drawable/all_apps_handle_landscape.xml +++ b/res/drawable/drag_handle_indicator.xml @@ -15,25 +15,25 @@ --> <vector xmlns:android="http://schemas.android.com/apk/res/android" - android:width="@dimen/dynamic_grid_min_page_indicator_size" - android:height="@dimen/dynamic_grid_min_page_indicator_size" - android:viewportWidth="48.0" - android:viewportHeight="48.0" > + android:width="@dimen/vertical_drag_handle_size" + android:height="@dimen/vertical_drag_handle_size" + android:viewportWidth="36.0" + android:viewportHeight="36.0" > <group - android:translateX="17.5" - android:translateY="17.5"> + android:translateX="11.5" + android:translateY="11.5"> <path android:pathData="M2 8.5L6.5 4L11 8.5" android:strokeColor="?attr/workspaceAmbientShadowColor" - android:strokeWidth="4" + android:strokeWidth="3.6" android:strokeLineCap="round" android:strokeLineJoin="round" /> <path android:pathData="M2 8.5L6.5 4L11 8.5" android:strokeColor="?attr/workspaceTextColor" - android:strokeWidth="2" + android:strokeWidth="1.8" android:strokeLineCap="round" android:strokeLineJoin="round" /> </group> diff --git a/res/drawable/ic_drag_indicator.xml b/res/drawable/ic_drag_indicator.xml deleted file mode 100644 index d50bdd3fd..000000000 --- a/res/drawable/ic_drag_indicator.xml +++ /dev/null @@ -1,25 +0,0 @@ -<?xml version="1.0" encoding="utf-8"?> -<!-- 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. ---> - -<vector xmlns:android="http://schemas.android.com/apk/res/android" - android:height="2dp" - android:width="16dp" - android:viewportHeight="2.0" - android:viewportWidth="16.0"> - <path - android:fillColor="@android:color/white" - android:pathData="M1,0h14c0.55,0,1,0.45,1,1s-0.45,1-1,1H1C0.45,2,0,1.55,0,1S0.45,0,1,0z"/> -</vector>
\ No newline at end of file diff --git a/res/layout/drag_handle_indicator.xml b/res/layout/drag_handle_indicator.xml deleted file mode 100644 index d5a7b8a03..000000000 --- a/res/layout/drag_handle_indicator.xml +++ /dev/null @@ -1,23 +0,0 @@ -<?xml version="1.0" encoding="utf-8"?> -<!-- 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. ---> -<com.android.launcher3.views.LauncherDragIndicator - xmlns:android="http://schemas.android.com/apk/res/android" - android:id="@+id/drag_indicator" - android:layout_width="wrap_content" - android:layout_height="wrap_content" - android:contentDescription="@string/all_apps_button_label" - android:scaleType="centerInside" - android:tint="?attr/workspaceTextColor" /> diff --git a/res/layout/launcher.xml b/res/layout/launcher.xml index cd8a4253b..ec8bd5c6f 100644 --- a/res/layout/launcher.xml +++ b/res/layout/launcher.xml @@ -67,9 +67,6 @@ android:layout_height="match_parent" android:visibility="invisible" /> - <include android:id="@+id/drag_indicator" - layout="@layout/drag_handle_indicator" /> - <!-- DO NOT CHANGE THE ID --> <include android:id="@+id/hotseat" diff --git a/res/values/dimens.xml b/res/values/dimens.xml index b1ad11ef0..cd050e88a 100644 --- a/res/values/dimens.xml +++ b/res/values/dimens.xml @@ -42,6 +42,7 @@ <dimen name="all_apps_scrim_radius">8dp</dimen> <dimen name="all_apps_scrim_margin">8dp</dimen> <dimen name="all_apps_scrim_blur">4dp</dimen> + <dimen name="vertical_drag_handle_size">24dp</dimen> <!-- Drop target bar --> <dimen name="dynamic_grid_drop_target_size">48dp</dimen> diff --git a/src/com/android/launcher3/Launcher.java b/src/com/android/launcher3/Launcher.java index d8bb90a71..333df05f6 100644 --- a/src/com/android/launcher3/Launcher.java +++ b/src/com/android/launcher3/Launcher.java @@ -194,7 +194,6 @@ public class Launcher extends BaseDraggingActivity private final int[] mTmpAddItemCellCoordinates = new int[2]; @Thunk Hotseat mHotseat; - private View mDragHandleIndicator; @Nullable private View mHotseatSearchBox; private DropTargetBar mDropTargetBar; @@ -920,7 +919,6 @@ public class Launcher extends BaseDraggingActivity 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 @@ public class Launcher extends BaseDraggingActivity 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 f548095ef..a47d7f468 100644 --- a/src/com/android/launcher3/LauncherState.java +++ b/src/com/android/launcher3/LauncherState.java @@ -50,7 +50,6 @@ public class LauncherState { 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 class LauncherState { 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 8d3d459cc..157dc1bf3 100644 --- a/src/com/android/launcher3/WorkspaceStateTransitionAnimation.java +++ b/src/com/android/launcher3/WorkspaceStateTransitionAnimation.java @@ -18,7 +18,6 @@ package com.android.launcher3; 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 @@ public class WorkspaceStateTransitionAnimation { (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 6d70a08bd..93514e23d 100644 --- a/src/com/android/launcher3/allapps/AllAppsTransitionController.java +++ b/src/com/android/launcher3/allapps/AllAppsTransitionController.java @@ -101,7 +101,6 @@ public class AllAppsTransitionController implements StateHandler, OnDeviceProfil mAppsView.setAlpha(1); mLauncher.getHotseat().setTranslationY(0); mLauncher.getWorkspace().getPageIndicator().setTranslationY(0); - mLauncher.getDragHandleIndicator().setTranslationY(0); } } @@ -125,7 +124,6 @@ public class AllAppsTransitionController implements StateHandler, OnDeviceProfil 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 986e4bee3..000000000 --- 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 b49b56568..28602f557 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 @@ public class ScrimView extends View implements Insettable, OnChangeListener { 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 @@ public class ScrimView extends View implements Insettable, OnChangeListener { if (mProgress != progress) { mProgress = progress; updateColors(); + updateDragHandleAlpha(); invalidate(); } } @@ -102,10 +166,158 @@ public class ScrimView extends View implements Insettable, OnChangeListener { 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; + } + } } |