2021-06-01 16:54:07 -07:00
|
|
|
/*
|
|
|
|
|
* 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.animation.Animator;
|
2021-08-17 16:07:22 -07:00
|
|
|
import android.content.SharedPreferences;
|
2021-06-01 16:54:07 -07:00
|
|
|
import android.content.res.Resources;
|
|
|
|
|
import android.graphics.Outline;
|
|
|
|
|
import android.graphics.Rect;
|
|
|
|
|
import android.view.View;
|
|
|
|
|
import android.view.ViewOutlineProvider;
|
|
|
|
|
|
|
|
|
|
import androidx.annotation.Nullable;
|
|
|
|
|
|
|
|
|
|
import com.android.launcher3.R;
|
2021-08-17 16:07:22 -07:00
|
|
|
import com.android.launcher3.Utilities;
|
2021-06-01 16:54:07 -07:00
|
|
|
import com.android.launcher3.anim.RevealOutlineAnimation;
|
|
|
|
|
import com.android.launcher3.anim.RoundedRectRevealOutlineProvider;
|
2021-08-17 16:07:22 -07:00
|
|
|
import com.android.launcher3.util.Executors;
|
2021-09-28 15:09:25 -07:00
|
|
|
import com.android.launcher3.util.MultiValueAlpha;
|
2021-06-01 16:54:07 -07:00
|
|
|
import com.android.quickstep.AnimatedFloat;
|
2021-08-17 16:07:22 -07:00
|
|
|
import com.android.systemui.shared.navigationbar.RegionSamplingHelper;
|
2021-06-01 16:54:07 -07:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Handles properties/data collection, then passes the results to our stashed handle View to render.
|
|
|
|
|
*/
|
|
|
|
|
public class StashedHandleViewController {
|
|
|
|
|
|
2021-09-28 15:09:25 -07:00
|
|
|
public static final int ALPHA_INDEX_STASHED = 0;
|
|
|
|
|
public static final int ALPHA_INDEX_HOME_DISABLED = 1;
|
|
|
|
|
private static final int NUM_ALPHA_CHANNELS = 2;
|
|
|
|
|
|
2021-08-17 16:07:22 -07:00
|
|
|
/**
|
|
|
|
|
* 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";
|
|
|
|
|
|
2021-06-01 16:54:07 -07:00
|
|
|
private final TaskbarActivityContext mActivity;
|
2021-08-17 16:07:22 -07:00
|
|
|
private final SharedPreferences mPrefs;
|
|
|
|
|
private final StashedHandleView mStashedHandleView;
|
2021-06-01 16:54:07 -07:00
|
|
|
private final int mStashedHandleWidth;
|
|
|
|
|
private final int mStashedHandleHeight;
|
2021-08-17 16:07:22 -07:00
|
|
|
private final RegionSamplingHelper mRegionSamplingHelper;
|
2021-09-28 15:09:25 -07:00
|
|
|
private final MultiValueAlpha mTaskbarStashedHandleAlpha;
|
2021-07-16 12:15:35 -10:00
|
|
|
private final AnimatedFloat mTaskbarStashedHandleHintScale = new AnimatedFloat(
|
|
|
|
|
this::updateStashedHandleHintScale);
|
2021-06-01 16:54:07 -07:00
|
|
|
|
|
|
|
|
// Initialized in init.
|
|
|
|
|
private TaskbarControllers mControllers;
|
|
|
|
|
|
|
|
|
|
// The bounds we want to clip to in the settled state when showing the stashed handle.
|
|
|
|
|
private final Rect mStashedHandleBounds = new Rect();
|
|
|
|
|
private float mStashedHandleRadius;
|
|
|
|
|
|
|
|
|
|
private boolean mIsAtStashedRevealBounds = true;
|
|
|
|
|
|
2021-08-17 16:07:22 -07:00
|
|
|
public StashedHandleViewController(TaskbarActivityContext activity,
|
|
|
|
|
StashedHandleView stashedHandleView) {
|
2021-06-01 16:54:07 -07:00
|
|
|
mActivity = activity;
|
2021-08-17 16:07:22 -07:00
|
|
|
mPrefs = Utilities.getPrefs(mActivity);
|
2021-06-01 16:54:07 -07:00
|
|
|
mStashedHandleView = stashedHandleView;
|
2021-09-28 15:09:25 -07:00
|
|
|
mTaskbarStashedHandleAlpha = new MultiValueAlpha(mStashedHandleView, NUM_ALPHA_CHANNELS);
|
|
|
|
|
mTaskbarStashedHandleAlpha.setUpdateVisibility(true);
|
2021-08-17 16:07:22 -07:00
|
|
|
mStashedHandleView.updateHandleColor(
|
2021-09-29 16:16:43 -07:00
|
|
|
mPrefs.getBoolean(SHARED_PREFS_STASHED_HANDLE_REGION_DARK_KEY, false),
|
|
|
|
|
false /* animate */);
|
2021-06-01 16:54:07 -07:00
|
|
|
final Resources resources = mActivity.getResources();
|
|
|
|
|
mStashedHandleWidth = resources.getDimensionPixelSize(R.dimen.taskbar_stashed_handle_width);
|
|
|
|
|
mStashedHandleHeight = resources.getDimensionPixelSize(
|
|
|
|
|
R.dimen.taskbar_stashed_handle_height);
|
2021-08-17 16:07:22 -07:00
|
|
|
mRegionSamplingHelper = new RegionSamplingHelper(mStashedHandleView,
|
|
|
|
|
new RegionSamplingHelper.SamplingCallback() {
|
|
|
|
|
@Override
|
|
|
|
|
public void onRegionDarknessChanged(boolean isRegionDark) {
|
2021-09-29 16:16:43 -07:00
|
|
|
mStashedHandleView.updateHandleColor(isRegionDark, true /* animate */);
|
2021-08-17 16:07:22 -07:00
|
|
|
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);
|
2021-06-01 16:54:07 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void init(TaskbarControllers controllers) {
|
|
|
|
|
mControllers = controllers;
|
|
|
|
|
mStashedHandleView.getLayoutParams().height = mActivity.getDeviceProfile().taskbarSize;
|
|
|
|
|
|
2021-09-28 15:09:25 -07:00
|
|
|
mTaskbarStashedHandleAlpha.getProperty(ALPHA_INDEX_STASHED).setValue(0);
|
2021-07-16 12:15:35 -10:00
|
|
|
mTaskbarStashedHandleHintScale.updateValue(1f);
|
2021-06-01 16:54:07 -07:00
|
|
|
|
|
|
|
|
final int stashedTaskbarHeight = mControllers.taskbarStashController.getStashedHeight();
|
|
|
|
|
mStashedHandleView.setOutlineProvider(new ViewOutlineProvider() {
|
|
|
|
|
@Override
|
|
|
|
|
public void getOutline(View view, Outline outline) {
|
|
|
|
|
final int stashedCenterX = view.getWidth() / 2;
|
|
|
|
|
final int stashedCenterY = view.getHeight() - stashedTaskbarHeight / 2;
|
|
|
|
|
mStashedHandleBounds.set(
|
|
|
|
|
stashedCenterX - mStashedHandleWidth / 2,
|
|
|
|
|
stashedCenterY - mStashedHandleHeight / 2,
|
|
|
|
|
stashedCenterX + mStashedHandleWidth / 2,
|
|
|
|
|
stashedCenterY + mStashedHandleHeight / 2);
|
2021-09-29 15:41:08 -07:00
|
|
|
mStashedHandleView.updateSampledRegion(mStashedHandleBounds);
|
2021-06-01 16:54:07 -07:00
|
|
|
mStashedHandleRadius = view.getHeight() / 2f;
|
|
|
|
|
outline.setRoundRect(mStashedHandleBounds, mStashedHandleRadius);
|
|
|
|
|
}
|
|
|
|
|
});
|
2021-07-16 12:15:35 -10:00
|
|
|
|
|
|
|
|
mStashedHandleView.addOnLayoutChangeListener((view, i, i1, i2, i3, i4, i5, i6, i7) -> {
|
|
|
|
|
final int stashedCenterX = view.getWidth() / 2;
|
|
|
|
|
final int stashedCenterY = view.getHeight() - stashedTaskbarHeight / 2;
|
|
|
|
|
|
|
|
|
|
view.setPivotX(stashedCenterX);
|
|
|
|
|
view.setPivotY(stashedCenterY);
|
|
|
|
|
});
|
2021-06-01 16:54:07 -07:00
|
|
|
}
|
|
|
|
|
|
2021-08-17 16:07:22 -07:00
|
|
|
public void onDestroy() {
|
|
|
|
|
mRegionSamplingHelper.stopAndDestroy();
|
|
|
|
|
}
|
|
|
|
|
|
2021-09-28 15:09:25 -07:00
|
|
|
public MultiValueAlpha getStashedHandleAlpha() {
|
2021-06-01 16:54:07 -07:00
|
|
|
return mTaskbarStashedHandleAlpha;
|
|
|
|
|
}
|
|
|
|
|
|
2021-07-16 12:15:35 -10:00
|
|
|
public AnimatedFloat getStashedHandleHintScale() {
|
|
|
|
|
return mTaskbarStashedHandleHintScale;
|
|
|
|
|
}
|
|
|
|
|
|
2021-06-01 16:54:07 -07:00
|
|
|
/**
|
|
|
|
|
* Creates and returns a {@link RevealOutlineAnimation} Animator that updates the stashed handle
|
|
|
|
|
* shape and size. When stashed, the shape is a thin rounded pill. When unstashed, the shape
|
|
|
|
|
* morphs into the size of where the taskbar icons will be.
|
|
|
|
|
*/
|
|
|
|
|
public @Nullable Animator createRevealAnimToIsStashed(boolean isStashed) {
|
|
|
|
|
if (mIsAtStashedRevealBounds == isStashed) {
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
mIsAtStashedRevealBounds = isStashed;
|
|
|
|
|
final RevealOutlineAnimation handleRevealProvider = new RoundedRectRevealOutlineProvider(
|
|
|
|
|
mStashedHandleRadius, mStashedHandleRadius,
|
|
|
|
|
mControllers.taskbarViewController.getIconLayoutBounds(), mStashedHandleBounds);
|
|
|
|
|
return handleRevealProvider.createRevealAnimator(mStashedHandleView, !isStashed);
|
|
|
|
|
}
|
|
|
|
|
|
2021-08-17 16:07:22 -07:00
|
|
|
public void onIsStashed(boolean isStashed) {
|
|
|
|
|
mRegionSamplingHelper.setWindowVisible(isStashed);
|
|
|
|
|
if (isStashed) {
|
2021-09-29 15:41:08 -07:00
|
|
|
mStashedHandleView.updateSampledRegion(mStashedHandleBounds);
|
2021-08-17 16:07:22 -07:00
|
|
|
mRegionSamplingHelper.start(mStashedHandleView.getSampledRegion());
|
|
|
|
|
} else {
|
|
|
|
|
mRegionSamplingHelper.stop();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-07-16 12:15:35 -10:00
|
|
|
protected void updateStashedHandleHintScale() {
|
|
|
|
|
mStashedHandleView.setScaleX(mTaskbarStashedHandleHintScale.value);
|
|
|
|
|
mStashedHandleView.setScaleY(mTaskbarStashedHandleHintScale.value);
|
|
|
|
|
}
|
2021-09-28 15:09:25 -07:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Should be called when the home button is disabled, so we can hide this handle as well.
|
|
|
|
|
*/
|
|
|
|
|
public void setIsHomeButtonDisabled(boolean homeDisabled) {
|
|
|
|
|
mTaskbarStashedHandleAlpha.getProperty(ALPHA_INDEX_HOME_DISABLED).setValue(
|
|
|
|
|
homeDisabled ? 0 : 1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public boolean isStashedHandleVisible() {
|
|
|
|
|
return mStashedHandleView.getVisibility() == View.VISIBLE;
|
|
|
|
|
}
|
2021-06-01 16:54:07 -07:00
|
|
|
}
|