mirror of
https://github.com/LawnchairLauncher/lawnchair.git
synced 2026-02-28 15:56:49 +00:00
Merge "Tint task bar based on sampling of colors in the area" into sc-v2-dev
This commit is contained in:
@@ -65,13 +65,12 @@
|
||||
android:layout_gravity="end"/>
|
||||
</FrameLayout>
|
||||
|
||||
<View
|
||||
<com.android.launcher3.taskbar.StashedHandleView
|
||||
android:id="@+id/stashed_handle"
|
||||
tools:comment1="The actual size and shape will be set as a ViewOutlineProvider at runtime"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
tools:comment2="TODO: Tint dynamically"
|
||||
android:background="?android:attr/textColorPrimary"
|
||||
android:background="@color/taskbar_stashed_handle_dark_color"
|
||||
android:clipToOutline="true"
|
||||
android:layout_gravity="bottom"/>
|
||||
|
||||
|
||||
@@ -28,4 +28,7 @@
|
||||
<!-- Taskbar -->
|
||||
<color name="taskbar_background">@color/overview_scrim_dark</color>
|
||||
<color name="taskbar_icon_selection_ripple">#E0E0E0</color>
|
||||
|
||||
<color name="taskbar_stashed_handle_light_color">#EBffffff</color>
|
||||
<color name="taskbar_stashed_handle_dark_color">#99000000</color>
|
||||
</resources>
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -89,5 +89,6 @@ public class TaskbarControllers {
|
||||
taskbarDragLayerController.onDestroy();
|
||||
taskbarKeyguardController.onDestroy();
|
||||
taskbarViewController.onDestroy();
|
||||
stashedHandleViewController.onDestroy();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user