diff --git a/quickstep/res/layout/taskbar.xml b/quickstep/res/layout/taskbar.xml index c0e0862588..b4c168c8a0 100644 --- a/quickstep/res/layout/taskbar.xml +++ b/quickstep/res/layout/taskbar.xml @@ -65,13 +65,12 @@ android:layout_gravity="end"/> - diff --git a/quickstep/res/values/colors.xml b/quickstep/res/values/colors.xml index 2f24441c2c..17980f0eeb 100644 --- a/quickstep/res/values/colors.xml +++ b/quickstep/res/values/colors.xml @@ -28,4 +28,7 @@ @color/overview_scrim_dark #E0E0E0 + + #EBffffff + #99000000 \ No newline at end of file diff --git a/quickstep/src/com/android/launcher3/taskbar/StashedHandleView.java b/quickstep/src/com/android/launcher3/taskbar/StashedHandleView.java new file mode 100644 index 0000000000..0224bc4a5b --- /dev/null +++ b/quickstep/src/com/android/launcher3/taskbar/StashedHandleView.java @@ -0,0 +1,70 @@ +/* + * Copyright (C) 2021 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.taskbar; + +import android.content.Context; +import android.graphics.Rect; +import android.util.AttributeSet; +import android.view.View; + +import androidx.annotation.ColorInt; +import androidx.core.content.ContextCompat; + +import com.android.launcher3.R; + +public class StashedHandleView extends View { + + private final @ColorInt int mStashedHandleLightColor; + private final @ColorInt int mStashedHandleDarkColor; + private final Rect mSampledRegion = new Rect(); + private final int[] mTmpArr = new int[2]; + + public StashedHandleView(Context context) { + this(context, null); + } + + public StashedHandleView(Context context, AttributeSet attrs) { + this(context, attrs, 0); + } + + public StashedHandleView(Context context, AttributeSet attrs, int defStyleAttr) { + this(context, attrs, defStyleAttr, 0); + } + + public StashedHandleView(Context context, AttributeSet attrs, int defStyleAttr, + int defStyleRes) { + super(context, attrs, defStyleAttr, defStyleRes); + + mStashedHandleLightColor = ContextCompat.getColor(context, + R.color.taskbar_stashed_handle_light_color); + mStashedHandleDarkColor = ContextCompat.getColor(context, + R.color.taskbar_stashed_handle_dark_color); + } + + public void updateSampledRegion() { + getLocationOnScreen(mTmpArr); + mSampledRegion.set(mTmpArr[0], mTmpArr[1], mTmpArr[0] + getWidth(), + mTmpArr[1] + getHeight()); + } + + public Rect getSampledRegion() { + return mSampledRegion; + } + + public void updateHandleColor(boolean isRegionDark) { + setBackgroundColor(isRegionDark ? mStashedHandleLightColor : mStashedHandleDarkColor); + } +} diff --git a/quickstep/src/com/android/launcher3/taskbar/StashedHandleViewController.java b/quickstep/src/com/android/launcher3/taskbar/StashedHandleViewController.java index df37261c8a..2858d7c38e 100644 --- a/quickstep/src/com/android/launcher3/taskbar/StashedHandleViewController.java +++ b/quickstep/src/com/android/launcher3/taskbar/StashedHandleViewController.java @@ -16,6 +16,7 @@ package com.android.launcher3.taskbar; import android.animation.Animator; +import android.content.SharedPreferences; import android.content.res.Resources; import android.graphics.Outline; import android.graphics.Rect; @@ -25,19 +26,30 @@ import android.view.ViewOutlineProvider; import androidx.annotation.Nullable; import com.android.launcher3.R; +import com.android.launcher3.Utilities; import com.android.launcher3.anim.RevealOutlineAnimation; import com.android.launcher3.anim.RoundedRectRevealOutlineProvider; +import com.android.launcher3.util.Executors; import com.android.quickstep.AnimatedFloat; +import com.android.systemui.shared.navigationbar.RegionSamplingHelper; /** * Handles properties/data collection, then passes the results to our stashed handle View to render. */ public class StashedHandleViewController { + /** + * The SharedPreferences key for whether the stashed handle region is dark. + */ + private static final String SHARED_PREFS_STASHED_HANDLE_REGION_DARK_KEY = + "stashed_handle_region_is_dark"; + private final TaskbarActivityContext mActivity; - private final View mStashedHandleView; + private final SharedPreferences mPrefs; + private final StashedHandleView mStashedHandleView; private final int mStashedHandleWidth; private final int mStashedHandleHeight; + private final RegionSamplingHelper mRegionSamplingHelper; private final AnimatedFloat mTaskbarStashedHandleAlpha = new AnimatedFloat( this::updateStashedHandleAlpha); private final AnimatedFloat mTaskbarStashedHandleHintScale = new AnimatedFloat( @@ -52,13 +64,31 @@ public class StashedHandleViewController { private boolean mIsAtStashedRevealBounds = true; - public StashedHandleViewController(TaskbarActivityContext activity, View stashedHandleView) { + public StashedHandleViewController(TaskbarActivityContext activity, + StashedHandleView stashedHandleView) { mActivity = activity; + mPrefs = Utilities.getPrefs(mActivity); mStashedHandleView = stashedHandleView; + mStashedHandleView.updateHandleColor( + mPrefs.getBoolean(SHARED_PREFS_STASHED_HANDLE_REGION_DARK_KEY, false)); final Resources resources = mActivity.getResources(); mStashedHandleWidth = resources.getDimensionPixelSize(R.dimen.taskbar_stashed_handle_width); mStashedHandleHeight = resources.getDimensionPixelSize( R.dimen.taskbar_stashed_handle_height); + mRegionSamplingHelper = new RegionSamplingHelper(mStashedHandleView, + new RegionSamplingHelper.SamplingCallback() { + @Override + public void onRegionDarknessChanged(boolean isRegionDark) { + mStashedHandleView.updateHandleColor(isRegionDark); + mPrefs.edit().putBoolean(SHARED_PREFS_STASHED_HANDLE_REGION_DARK_KEY, + isRegionDark).apply(); + } + + @Override + public Rect getSampledRegion(View sampledView) { + return mStashedHandleView.getSampledRegion(); + } + }, Executors.UI_HELPER_EXECUTOR); } public void init(TaskbarControllers controllers) { @@ -93,6 +123,10 @@ public class StashedHandleViewController { }); } + public void onDestroy() { + mRegionSamplingHelper.stopAndDestroy(); + } + public AnimatedFloat getStashedHandleAlpha() { return mTaskbarStashedHandleAlpha; } @@ -117,6 +151,16 @@ public class StashedHandleViewController { return handleRevealProvider.createRevealAnimator(mStashedHandleView, !isStashed); } + public void onIsStashed(boolean isStashed) { + mRegionSamplingHelper.setWindowVisible(isStashed); + if (isStashed) { + mStashedHandleView.updateSampledRegion(); + mRegionSamplingHelper.start(mStashedHandleView.getSampledRegion()); + } else { + mRegionSamplingHelper.stop(); + } + } + protected void updateStashedHandleAlpha() { mStashedHandleView.setAlpha(mTaskbarStashedHandleAlpha.value); } diff --git a/quickstep/src/com/android/launcher3/taskbar/TaskbarActivityContext.java b/quickstep/src/com/android/launcher3/taskbar/TaskbarActivityContext.java index a90f17d227..5b9bd31922 100644 --- a/quickstep/src/com/android/launcher3/taskbar/TaskbarActivityContext.java +++ b/quickstep/src/com/android/launcher3/taskbar/TaskbarActivityContext.java @@ -117,7 +117,7 @@ public class TaskbarActivityContext extends ContextThemeWrapper implements Activ R.layout.taskbar, null, false); TaskbarView taskbarView = mDragLayer.findViewById(R.id.taskbar_view); FrameLayout navButtonsView = mDragLayer.findViewById(R.id.navbuttons_view); - View stashedHandleView = mDragLayer.findViewById(R.id.stashed_handle); + StashedHandleView stashedHandleView = mDragLayer.findViewById(R.id.stashed_handle); // Construct controllers. mControllers = new TaskbarControllers(this, diff --git a/quickstep/src/com/android/launcher3/taskbar/TaskbarControllers.java b/quickstep/src/com/android/launcher3/taskbar/TaskbarControllers.java index 2927a6321e..b32a41e987 100644 --- a/quickstep/src/com/android/launcher3/taskbar/TaskbarControllers.java +++ b/quickstep/src/com/android/launcher3/taskbar/TaskbarControllers.java @@ -89,5 +89,6 @@ public class TaskbarControllers { taskbarDragLayerController.onDestroy(); taskbarKeyguardController.onDestroy(); taskbarViewController.onDestroy(); + stashedHandleViewController.onDestroy(); } } diff --git a/quickstep/src/com/android/launcher3/taskbar/TaskbarStashController.java b/quickstep/src/com/android/launcher3/taskbar/TaskbarStashController.java index 949df8233a..1f5ff02721 100644 --- a/quickstep/src/com/android/launcher3/taskbar/TaskbarStashController.java +++ b/quickstep/src/com/android/launcher3/taskbar/TaskbarStashController.java @@ -285,6 +285,7 @@ public class TaskbarStashController { @Override public void onAnimationStart(Animator animation) { mIsStashed = isStashed; + onIsStashed(mIsStashed); } @Override @@ -326,4 +327,8 @@ public class TaskbarStashController { animateForward ? UNSTASHED_TASKBAR_HANDLE_HINT_SCALE : 1) .setDuration(TASKBAR_HINT_STASH_DURATION).start(); } + + private void onIsStashed(boolean isStashed) { + mControllers.stashedHandleViewController.onIsStashed(isStashed); + } }