2018-01-03 14:41:31 +00:00
|
|
|
/*
|
2020-03-19 16:34:24 -07:00
|
|
|
* Copyright (C) 2020 The Android Open Source Project
|
2018-01-03 14:41:31 +00:00
|
|
|
*
|
|
|
|
|
* 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.allapps;
|
|
|
|
|
|
2024-09-16 15:46:04 -07:00
|
|
|
import android.animation.Animator;
|
|
|
|
|
import android.animation.AnimatorListenerAdapter;
|
|
|
|
|
import android.animation.AnimatorSet;
|
|
|
|
|
import android.animation.ObjectAnimator;
|
|
|
|
|
import android.animation.ValueAnimator;
|
2018-01-03 14:41:31 +00:00
|
|
|
import android.content.Context;
|
2024-09-20 14:50:55 -07:00
|
|
|
import android.content.Intent;
|
2020-03-19 16:34:24 -07:00
|
|
|
import android.graphics.Rect;
|
2024-09-16 15:46:04 -07:00
|
|
|
import android.text.TextUtils;
|
2018-01-03 14:41:31 +00:00
|
|
|
import android.util.AttributeSet;
|
2024-09-16 15:46:04 -07:00
|
|
|
import android.view.ViewGroup;
|
2021-06-16 09:46:25 -05:00
|
|
|
import android.view.WindowInsets;
|
2024-09-20 14:50:55 -07:00
|
|
|
import android.widget.ImageButton;
|
2024-09-16 15:46:04 -07:00
|
|
|
import android.widget.ImageView;
|
2022-11-21 16:30:28 -08:00
|
|
|
import android.widget.LinearLayout;
|
|
|
|
|
import android.widget.TextView;
|
2021-05-25 19:21:37 -05:00
|
|
|
|
2022-11-21 16:30:28 -08:00
|
|
|
import androidx.annotation.NonNull;
|
2024-11-25 13:51:33 -08:00
|
|
|
import androidx.annotation.VisibleForTesting;
|
2022-11-18 00:36:08 -08:00
|
|
|
import androidx.core.graphics.Insets;
|
|
|
|
|
import androidx.core.view.WindowInsetsCompat;
|
|
|
|
|
|
2024-09-16 15:46:04 -07:00
|
|
|
import com.android.app.animation.Interpolators;
|
2021-08-31 20:24:33 -07:00
|
|
|
import com.android.launcher3.DeviceProfile;
|
2024-09-20 14:50:55 -07:00
|
|
|
import com.android.launcher3.Flags;
|
2020-03-19 16:34:24 -07:00
|
|
|
import com.android.launcher3.Insettable;
|
2022-06-22 13:34:23 -07:00
|
|
|
import com.android.launcher3.R;
|
2019-12-10 12:19:13 -08:00
|
|
|
import com.android.launcher3.Utilities;
|
2024-09-16 15:46:04 -07:00
|
|
|
import com.android.launcher3.anim.AnimatedPropertySetter;
|
2021-06-16 09:46:25 -05:00
|
|
|
import com.android.launcher3.anim.KeyboardInsetAnimationCallback;
|
2021-12-20 16:47:38 +00:00
|
|
|
import com.android.launcher3.model.StringCache;
|
2022-01-14 23:15:47 -05:00
|
|
|
import com.android.launcher3.views.ActivityContext;
|
2024-09-20 14:50:55 -07:00
|
|
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
|
|
2020-03-19 16:34:24 -07:00
|
|
|
/**
|
2024-09-20 14:50:55 -07:00
|
|
|
* Work profile utility ViewGroup that is shown at the bottom of AllApps work tab
|
2020-03-19 16:34:24 -07:00
|
|
|
*/
|
2024-09-20 14:50:55 -07:00
|
|
|
public class WorkUtilityView extends LinearLayout implements Insettable,
|
2022-11-21 16:30:28 -08:00
|
|
|
KeyboardInsetAnimationCallback.KeyboardInsetListener {
|
2020-03-19 16:34:24 -07:00
|
|
|
|
2024-09-16 15:46:04 -07:00
|
|
|
private static final int TEXT_EXPAND_OPACITY_DURATION = 300;
|
|
|
|
|
private static final int TEXT_COLLAPSE_OPACITY_DURATION = 50;
|
|
|
|
|
private static final int EXPAND_COLLAPSE_DURATION = 300;
|
|
|
|
|
private static final int TEXT_ALPHA_EXPAND_DELAY = 80;
|
|
|
|
|
private static final int TEXT_ALPHA_COLLAPSE_DELAY = 0;
|
2024-09-20 14:50:55 -07:00
|
|
|
private static final int WORK_SCHEDULER_OPACITY_DURATION =
|
|
|
|
|
(int) (EXPAND_COLLAPSE_DURATION * 0.75f);
|
2021-08-31 20:24:33 -07:00
|
|
|
private static final int FLAG_FADE_ONGOING = 1 << 1;
|
|
|
|
|
private static final int FLAG_TRANSLATION_ONGOING = 1 << 2;
|
2024-09-16 15:46:04 -07:00
|
|
|
private static final int FLAG_IS_EXPAND = 1 << 3;
|
2022-11-21 16:30:28 -08:00
|
|
|
private static final int SCROLL_THRESHOLD_DP = 10;
|
2024-09-20 14:50:55 -07:00
|
|
|
private static final float WORK_SCHEDULER_SCALE_MIN = 0.25f;
|
|
|
|
|
private static final float WORK_SCHEDULER_SCALE_MAX = 1f;
|
2020-04-13 16:47:47 -07:00
|
|
|
|
2021-08-31 20:24:33 -07:00
|
|
|
private final Rect mInsets = new Rect();
|
2022-11-18 00:36:08 -08:00
|
|
|
private final Rect mImeInsets = new Rect();
|
2021-08-31 20:24:33 -07:00
|
|
|
private int mFlags;
|
2022-11-21 16:30:28 -08:00
|
|
|
private final ActivityContext mActivityContext;
|
2024-04-16 13:36:18 -07:00
|
|
|
private final Context mContext;
|
2024-09-16 15:46:04 -07:00
|
|
|
private final int mTextMarginStart;
|
|
|
|
|
private final int mTextMarginEnd;
|
|
|
|
|
private final int mIconMarginStart;
|
2024-09-20 14:50:55 -07:00
|
|
|
private final String mWorkSchedulerIntentAction;
|
2022-11-21 16:30:28 -08:00
|
|
|
|
|
|
|
|
// Threshold when user scrolls up/down to determine when should button extend/collapse
|
|
|
|
|
private final int mScrollThreshold;
|
2024-09-16 15:46:04 -07:00
|
|
|
private ValueAnimator mPauseFABAnim;
|
2024-09-20 14:50:55 -07:00
|
|
|
private TextView mPauseText;
|
|
|
|
|
private ImageView mWorkIcon;
|
|
|
|
|
private ImageButton mSchedulerButton;
|
2021-06-16 09:46:25 -05:00
|
|
|
|
2024-09-20 14:50:55 -07:00
|
|
|
public WorkUtilityView(@NonNull Context context) {
|
2021-05-25 19:21:37 -05:00
|
|
|
this(context, null, 0);
|
2018-01-03 14:41:31 +00:00
|
|
|
}
|
|
|
|
|
|
2024-09-20 14:50:55 -07:00
|
|
|
public WorkUtilityView(@NonNull Context context, @NonNull AttributeSet attrs) {
|
2021-05-25 19:21:37 -05:00
|
|
|
this(context, attrs, 0);
|
2018-01-03 14:41:31 +00:00
|
|
|
}
|
|
|
|
|
|
2024-09-20 14:50:55 -07:00
|
|
|
public WorkUtilityView(@NonNull Context context, @NonNull AttributeSet attrs,
|
|
|
|
|
int defStyleAttr) {
|
2018-01-03 14:41:31 +00:00
|
|
|
super(context, attrs, defStyleAttr);
|
2024-04-16 13:36:18 -07:00
|
|
|
mContext = context;
|
2022-11-21 16:30:28 -08:00
|
|
|
mScrollThreshold = Utilities.dpToPx(SCROLL_THRESHOLD_DP);
|
|
|
|
|
mActivityContext = ActivityContext.lookupContext(getContext());
|
2024-09-16 15:46:04 -07:00
|
|
|
mTextMarginStart = mContext.getResources().getDimensionPixelSize(
|
|
|
|
|
R.dimen.work_fab_text_start_margin);
|
|
|
|
|
mTextMarginEnd = mContext.getResources().getDimensionPixelSize(
|
|
|
|
|
R.dimen.work_fab_text_end_margin);
|
|
|
|
|
mIconMarginStart = mContext.getResources().getDimensionPixelSize(
|
|
|
|
|
R.dimen.work_fab_icon_start_margin_expanded);
|
2024-09-20 14:50:55 -07:00
|
|
|
mWorkSchedulerIntentAction = mContext.getResources().getString(
|
|
|
|
|
R.string.work_profile_scheduler_intent);
|
2018-01-03 14:41:31 +00:00
|
|
|
}
|
|
|
|
|
|
2020-04-13 16:47:47 -07:00
|
|
|
@Override
|
2021-05-25 19:21:37 -05:00
|
|
|
protected void onFinishInflate() {
|
|
|
|
|
super.onFinishInflate();
|
2022-11-21 16:30:28 -08:00
|
|
|
|
2024-09-20 14:50:55 -07:00
|
|
|
mPauseText = findViewById(R.id.pause_text);
|
|
|
|
|
mWorkIcon = findViewById(R.id.work_icon);
|
|
|
|
|
mSchedulerButton = findViewById(R.id.work_scheduler);
|
2021-06-17 11:34:20 -05:00
|
|
|
setSelected(true);
|
2024-01-24 14:38:48 -08:00
|
|
|
KeyboardInsetAnimationCallback keyboardInsetAnimationCallback =
|
|
|
|
|
new KeyboardInsetAnimationCallback(this);
|
|
|
|
|
setWindowInsetsAnimationCallback(keyboardInsetAnimationCallback);
|
2024-09-16 15:46:04 -07:00
|
|
|
// Expand is the default state upon initialization.
|
|
|
|
|
addFlag(FLAG_IS_EXPAND);
|
2022-11-21 16:30:28 -08:00
|
|
|
setInsets(mActivityContext.getDeviceProfile().getInsets());
|
2023-06-08 13:52:06 -07:00
|
|
|
updateStringFromCache();
|
2024-09-20 14:50:55 -07:00
|
|
|
mSchedulerButton.setVisibility(GONE);
|
2024-11-25 13:51:33 -08:00
|
|
|
mSchedulerButton.setOnClickListener(null);
|
2024-09-20 14:50:55 -07:00
|
|
|
if (shouldUseScheduler()) {
|
|
|
|
|
mSchedulerButton.setVisibility(VISIBLE);
|
|
|
|
|
mSchedulerButton.setOnClickListener(view ->
|
|
|
|
|
mContext.startActivity(new Intent(mWorkSchedulerIntentAction)));
|
|
|
|
|
}
|
2018-08-02 16:30:51 -07:00
|
|
|
}
|
|
|
|
|
|
2020-03-19 16:34:24 -07:00
|
|
|
@Override
|
|
|
|
|
public void setInsets(Rect insets) {
|
|
|
|
|
mInsets.set(insets);
|
2022-11-18 00:36:08 -08:00
|
|
|
updateTranslationY();
|
2022-06-22 13:34:23 -07:00
|
|
|
MarginLayoutParams lp = (MarginLayoutParams) getLayoutParams();
|
|
|
|
|
if (lp != null) {
|
|
|
|
|
int bottomMargin = getResources().getDimensionPixelSize(R.dimen.work_fab_margin_bottom);
|
2022-08-01 17:46:12 +01:00
|
|
|
DeviceProfile dp = ActivityContext.lookupContext(getContext()).getDeviceProfile();
|
Put the "floating" in ENABLE_FLOATING_SEARCH_BAR.
This means adding the search view to the drag layer, so it can
persist and animate across Launcher states (i.e. Home, All Apps,
Overview, Overview from App).
Some high level things:
- LauncherState now has a flag indicating if the floating
search bar should be visible, as well as a method indicating
how high it should rest when the keyboard is not showing. By
default the height is set negative if the flag is not present,
so the search bar will rest off screen in that state.
- LauncherState also has a new method indicating if the search
bar should show as a pill when not focused. Currently this is
done in phone portrait mode in all apps and overview.
- SearchUiManager now has a method for gestures to hint that
the search bar will be focused or unfocused soon, e.g. for
the app -> overview case, we hint that it will be focused
when crossing the threshold, and unfocused if retracting.
This allows the search bar to animate during the gesture
and take or release focus after the state change completes.
- AllAppsTransitionController lets the apps panel translate in
from the bottom of the screen, for example when coming from
an app and we don't want to pop it in halfway up the screen.
Instead it can slide in gracefully from behind the keyboard
and floating search bar.
- KeyboardInsetAnimationCallback can now notify listeners of
keyboard alpha changes during controlled animations. And
StateAnimationConfig has a new animation type to control
the keyboard alpha during the all apps transition.
- This new ANIM_ALL_APPS_KEYBOARD_FADE is used to pop the
keyboard in at the threshold for going from an app to all apps.
Note that its position moves linearly before this, so the
search bar starts moving up accordingly before the keyboard
alpha is non-0.
Fix: 266761289
Fix: 268845147
Fix: 267683921
Fix: 265849321
Fix: 266446733
Fix: 269301440
Bug: 275635606
Bug: 259619990
Bug: 261866704
Test: Manual with all the state transitions on phone and tablet
(also folding/unfolding foldable).
Flag: ENABLE_FLOATING_SEARCH_BAR, ENABLE_ALL_APPS_FROM_OVERVIEW
(latter just for the background app interpolator changes).
Change-Id: I6f06552e95747348a62260279626cf407bf145b0
2023-05-30 21:46:24 -07:00
|
|
|
if (mActivityContext.getAppsView().isSearchBarFloating()) {
|
2022-08-01 17:46:12 +01:00
|
|
|
bottomMargin += dp.hotseatQsbHeight;
|
2022-06-22 13:34:23 -07:00
|
|
|
}
|
|
|
|
|
|
2022-09-21 10:03:47 -07:00
|
|
|
if (!dp.isGestureMode && dp.isTaskbarPresent) {
|
2023-03-23 21:38:49 -07:00
|
|
|
bottomMargin += dp.taskbarHeight;
|
2022-06-22 13:34:23 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
lp.bottomMargin = bottomMargin;
|
2021-05-25 19:21:37 -05:00
|
|
|
}
|
2020-03-19 16:34:24 -07:00
|
|
|
}
|
|
|
|
|
|
2022-07-11 11:03:54 -07:00
|
|
|
@Override
|
|
|
|
|
protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
|
|
|
|
|
super.onLayout(changed, left, top, right, bottom);
|
2023-10-30 12:24:05 +00:00
|
|
|
boolean isRtl = Utilities.isRtl(getResources());
|
2024-04-16 13:36:18 -07:00
|
|
|
int shift = mActivityContext.getDeviceProfile().getAllAppsIconStartMargin(mContext);
|
2023-10-30 12:24:05 +00:00
|
|
|
setTranslationX(isRtl ? shift : -shift);
|
2022-07-11 11:03:54 -07:00
|
|
|
}
|
|
|
|
|
|
2021-08-31 20:24:33 -07:00
|
|
|
@Override
|
|
|
|
|
public boolean isEnabled() {
|
2024-09-16 15:46:04 -07:00
|
|
|
return super.isEnabled() && getVisibility() == VISIBLE;
|
2021-08-31 20:24:33 -07:00
|
|
|
}
|
|
|
|
|
|
2022-11-21 16:30:28 -08:00
|
|
|
public void animateVisibility(boolean visible) {
|
2021-08-31 20:24:33 -07:00
|
|
|
clearAnimation();
|
2022-11-21 16:30:28 -08:00
|
|
|
if (visible) {
|
2024-09-16 15:46:04 -07:00
|
|
|
addFlag(FLAG_FADE_ONGOING);
|
2021-08-31 20:24:33 -07:00
|
|
|
setVisibility(VISIBLE);
|
2022-11-21 16:30:28 -08:00
|
|
|
extend();
|
2021-08-31 20:24:33 -07:00
|
|
|
animate().alpha(1).withEndAction(() -> removeFlag(FLAG_FADE_ONGOING)).start();
|
|
|
|
|
} else if (getVisibility() != GONE) {
|
2024-09-16 15:46:04 -07:00
|
|
|
addFlag(FLAG_FADE_ONGOING);
|
2021-08-31 20:24:33 -07:00
|
|
|
animate().alpha(0).withEndAction(() -> {
|
|
|
|
|
removeFlag(FLAG_FADE_ONGOING);
|
2022-11-21 16:30:28 -08:00
|
|
|
setVisibility(GONE);
|
2021-08-31 20:24:33 -07:00
|
|
|
}).start();
|
2020-03-31 03:54:50 -07:00
|
|
|
}
|
|
|
|
|
}
|
2021-06-16 09:46:25 -05:00
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public WindowInsets onApplyWindowInsets(WindowInsets insets) {
|
2022-11-18 00:36:08 -08:00
|
|
|
WindowInsetsCompat windowInsetsCompat =
|
|
|
|
|
WindowInsetsCompat.toWindowInsetsCompat(insets, this);
|
|
|
|
|
if (windowInsetsCompat.isVisible(WindowInsetsCompat.Type.ime())) {
|
|
|
|
|
setInsets(mImeInsets, windowInsetsCompat.getInsets(WindowInsetsCompat.Type.ime()));
|
2024-11-01 13:27:48 -07:00
|
|
|
shrink();
|
2022-09-09 15:04:42 -07:00
|
|
|
} else {
|
2022-11-18 00:36:08 -08:00
|
|
|
mImeInsets.setEmpty();
|
2024-11-01 13:27:48 -07:00
|
|
|
extend();
|
2021-06-16 09:46:25 -05:00
|
|
|
}
|
2022-11-18 00:36:08 -08:00
|
|
|
updateTranslationY();
|
|
|
|
|
return super.onApplyWindowInsets(insets);
|
|
|
|
|
}
|
|
|
|
|
|
2023-05-30 10:53:51 -07:00
|
|
|
void updateTranslationY() {
|
2022-11-18 00:36:08 -08:00
|
|
|
setTranslationY(-mImeInsets.bottom);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void setTranslationY(float translationY) {
|
|
|
|
|
// Always translate at least enough for nav bar insets.
|
|
|
|
|
super.setTranslationY(Math.min(translationY, -mInsets.bottom));
|
|
|
|
|
}
|
|
|
|
|
|
2024-09-20 14:50:55 -07:00
|
|
|
private ValueAnimator animateSchedulerScale(boolean isExpanding) {
|
|
|
|
|
float scaleFrom = isExpanding ? WORK_SCHEDULER_SCALE_MIN : WORK_SCHEDULER_SCALE_MAX;
|
|
|
|
|
float scaleTo = isExpanding ? WORK_SCHEDULER_SCALE_MAX : WORK_SCHEDULER_SCALE_MIN;
|
|
|
|
|
ValueAnimator schedulerScaleAnim = ObjectAnimator.ofFloat(scaleFrom, scaleTo);
|
|
|
|
|
schedulerScaleAnim.setDuration(EXPAND_COLLAPSE_DURATION);
|
|
|
|
|
schedulerScaleAnim.setInterpolator(Interpolators.STANDARD);
|
|
|
|
|
schedulerScaleAnim.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
|
|
|
|
|
@Override
|
|
|
|
|
public void onAnimationUpdate(ValueAnimator valueAnimator) {
|
|
|
|
|
float scale = (float) valueAnimator.getAnimatedValue();
|
|
|
|
|
mSchedulerButton.setScaleX(scale);
|
|
|
|
|
mSchedulerButton.setScaleY(scale);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
schedulerScaleAnim.addListener(new AnimatorListenerAdapter() {
|
|
|
|
|
@Override
|
|
|
|
|
public void onAnimationStart(Animator animation) {
|
|
|
|
|
if (isExpanding) {
|
|
|
|
|
mSchedulerButton.setVisibility(VISIBLE);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void onAnimationEnd(Animator animation) {
|
|
|
|
|
if (!isExpanding) {
|
|
|
|
|
mSchedulerButton.setVisibility(GONE);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
return schedulerScaleAnim;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private ValueAnimator animateSchedulerAlpha(boolean isExpanding) {
|
|
|
|
|
float alphaFrom = isExpanding ? 0 : 1;
|
|
|
|
|
float alphaTo = isExpanding ? 1 : 0;
|
|
|
|
|
ValueAnimator schedulerAlphaAnim = ObjectAnimator.ofFloat(alphaFrom, alphaTo);
|
|
|
|
|
schedulerAlphaAnim.setDuration(WORK_SCHEDULER_OPACITY_DURATION);
|
|
|
|
|
schedulerAlphaAnim.setStartDelay(isExpanding ? 0 :
|
|
|
|
|
EXPAND_COLLAPSE_DURATION - WORK_SCHEDULER_OPACITY_DURATION);
|
|
|
|
|
schedulerAlphaAnim.setInterpolator(Interpolators.STANDARD);
|
|
|
|
|
schedulerAlphaAnim.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
|
|
|
|
|
@Override
|
|
|
|
|
public void onAnimationUpdate(ValueAnimator valueAnimator) {
|
|
|
|
|
mSchedulerButton.setAlpha((float) valueAnimator.getAnimatedValue());
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
return schedulerAlphaAnim;
|
|
|
|
|
}
|
2024-09-16 15:46:04 -07:00
|
|
|
|
2024-09-20 14:50:55 -07:00
|
|
|
private void animateWorkUtilityViews(boolean isExpanding) {
|
2024-09-16 15:46:04 -07:00
|
|
|
if (!shouldAnimate(isExpanding)) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
AnimatorSet animatorSet = new AnimatedPropertySetter().buildAnim();
|
2024-09-20 14:50:55 -07:00
|
|
|
mPauseText.measure(0,0);
|
|
|
|
|
int currentWidth = mPauseText.getWidth();
|
|
|
|
|
int fullWidth = mPauseText.getMeasuredWidth();
|
2024-09-16 15:46:04 -07:00
|
|
|
float from = isExpanding ? 0 : currentWidth;
|
|
|
|
|
float to = isExpanding ? fullWidth : 0;
|
|
|
|
|
mPauseFABAnim = ObjectAnimator.ofFloat(from, to);
|
|
|
|
|
mPauseFABAnim.setDuration(EXPAND_COLLAPSE_DURATION);
|
|
|
|
|
mPauseFABAnim.setInterpolator(Interpolators.STANDARD);
|
|
|
|
|
mPauseFABAnim.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
|
|
|
|
|
@Override
|
|
|
|
|
public void onAnimationUpdate(ValueAnimator valueAnimator) {
|
|
|
|
|
float translation = (float) valueAnimator.getAnimatedValue();
|
|
|
|
|
float translationFraction = translation / fullWidth;
|
|
|
|
|
ViewGroup.MarginLayoutParams textViewLayoutParams =
|
2024-09-20 14:50:55 -07:00
|
|
|
(ViewGroup.MarginLayoutParams) mPauseText.getLayoutParams();
|
2024-09-16 15:46:04 -07:00
|
|
|
textViewLayoutParams.width = (int) translation;
|
|
|
|
|
textViewLayoutParams.setMarginStart((int) (mTextMarginStart * translationFraction));
|
|
|
|
|
textViewLayoutParams.setMarginEnd((int) (mTextMarginEnd * translationFraction));
|
2024-09-20 14:50:55 -07:00
|
|
|
mPauseText.setLayoutParams(textViewLayoutParams);
|
2024-09-16 15:46:04 -07:00
|
|
|
ViewGroup.MarginLayoutParams iconLayoutParams =
|
2024-09-20 14:50:55 -07:00
|
|
|
(ViewGroup.MarginLayoutParams) mWorkIcon.getLayoutParams();
|
2024-09-16 15:46:04 -07:00
|
|
|
iconLayoutParams.setMarginStart((int) (mIconMarginStart * translationFraction));
|
2024-09-20 14:50:55 -07:00
|
|
|
mWorkIcon.setLayoutParams(iconLayoutParams);
|
2024-09-16 15:46:04 -07:00
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
mPauseFABAnim.addListener(new AnimatorListenerAdapter() {
|
|
|
|
|
@Override
|
|
|
|
|
public void onAnimationEnd(Animator animator) {
|
|
|
|
|
if (isExpanding) {
|
|
|
|
|
addFlag(FLAG_IS_EXPAND);
|
|
|
|
|
} else {
|
2024-09-20 14:50:55 -07:00
|
|
|
mPauseText.setVisibility(GONE);
|
2024-09-16 15:46:04 -07:00
|
|
|
removeFlag(FLAG_IS_EXPAND);
|
|
|
|
|
}
|
2024-09-20 14:50:55 -07:00
|
|
|
mPauseText.setHorizontallyScrolling(false);
|
|
|
|
|
mPauseText.setEllipsize(TextUtils.TruncateAt.END);
|
2024-09-16 15:46:04 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void onAnimationStart(Animator animator) {
|
2024-09-20 14:50:55 -07:00
|
|
|
mPauseText.setHorizontallyScrolling(true);
|
|
|
|
|
mPauseText.setVisibility(VISIBLE);
|
|
|
|
|
mPauseText.setEllipsize(null);
|
2024-09-16 15:46:04 -07:00
|
|
|
}
|
|
|
|
|
});
|
2024-09-20 14:50:55 -07:00
|
|
|
ArrayList<Animator> animatorList = new ArrayList<>();
|
|
|
|
|
animatorList.add(mPauseFABAnim);
|
|
|
|
|
animatorList.add(updatePauseTextAlpha(isExpanding));
|
|
|
|
|
if (shouldUseScheduler()) {
|
|
|
|
|
animatorList.add(animateSchedulerScale(isExpanding));
|
|
|
|
|
animatorList.add(animateSchedulerAlpha(isExpanding));
|
|
|
|
|
}
|
|
|
|
|
animatorSet.playTogether(animatorList);
|
2024-09-16 15:46:04 -07:00
|
|
|
animatorSet.start();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private ValueAnimator updatePauseTextAlpha(boolean expand) {
|
|
|
|
|
float from = expand ? 0 : 1;
|
|
|
|
|
float to = expand ? 1 : 0;
|
|
|
|
|
ValueAnimator alphaAnim = ObjectAnimator.ofFloat(from, to);
|
|
|
|
|
alphaAnim.setDuration(expand ? TEXT_EXPAND_OPACITY_DURATION
|
|
|
|
|
: TEXT_COLLAPSE_OPACITY_DURATION);
|
|
|
|
|
alphaAnim.setStartDelay(expand ? TEXT_ALPHA_EXPAND_DELAY : TEXT_ALPHA_COLLAPSE_DELAY);
|
|
|
|
|
alphaAnim.setInterpolator(Interpolators.LINEAR);
|
|
|
|
|
alphaAnim.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
|
|
|
|
|
@Override
|
|
|
|
|
public void onAnimationUpdate(ValueAnimator valueAnimator) {
|
2024-09-20 14:50:55 -07:00
|
|
|
mPauseText.setAlpha((float) valueAnimator.getAnimatedValue());
|
2024-09-16 15:46:04 -07:00
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
return alphaAnim;
|
|
|
|
|
}
|
|
|
|
|
|
2022-11-18 00:36:08 -08:00
|
|
|
private void setInsets(Rect rect, Insets insets) {
|
|
|
|
|
rect.set(insets.left, insets.top, insets.right, insets.bottom);
|
2021-06-16 09:46:25 -05:00
|
|
|
}
|
2021-08-31 20:24:33 -07:00
|
|
|
|
2023-05-30 10:53:51 -07:00
|
|
|
public Rect getImeInsets() {
|
|
|
|
|
return mImeInsets;
|
|
|
|
|
}
|
|
|
|
|
|
2021-08-31 20:24:33 -07:00
|
|
|
@Override
|
|
|
|
|
public void onTranslationStart() {
|
2024-09-16 15:46:04 -07:00
|
|
|
addFlag(FLAG_TRANSLATION_ONGOING);
|
2021-08-31 20:24:33 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void onTranslationEnd() {
|
|
|
|
|
removeFlag(FLAG_TRANSLATION_ONGOING);
|
|
|
|
|
}
|
|
|
|
|
|
2024-09-16 15:46:04 -07:00
|
|
|
private void addFlag(int flag) {
|
2021-08-31 20:24:33 -07:00
|
|
|
mFlags |= flag;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void removeFlag(int flag) {
|
|
|
|
|
mFlags &= ~flag;
|
|
|
|
|
}
|
2022-11-21 16:30:28 -08:00
|
|
|
|
2024-09-16 15:46:04 -07:00
|
|
|
private boolean containsFlag(int flag) {
|
|
|
|
|
return (mFlags & flag) == flag;
|
|
|
|
|
}
|
|
|
|
|
|
2022-11-21 16:30:28 -08:00
|
|
|
public void extend() {
|
2024-09-20 14:50:55 -07:00
|
|
|
animateWorkUtilityViews(true);
|
2022-11-21 16:30:28 -08:00
|
|
|
}
|
|
|
|
|
|
2024-09-20 14:50:55 -07:00
|
|
|
public void shrink() {
|
|
|
|
|
animateWorkUtilityViews(false);
|
2024-09-16 15:46:04 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Determines if the button should animate based on current state. It should animate the button
|
|
|
|
|
* only if it is not in the same state it is animating to.
|
|
|
|
|
*/
|
|
|
|
|
private boolean shouldAnimate(boolean expanding) {
|
|
|
|
|
return expanding != containsFlag(FLAG_IS_EXPAND)
|
|
|
|
|
&& (mPauseFABAnim == null || !mPauseFABAnim.isRunning());
|
2022-11-21 16:30:28 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public int getScrollThreshold() {
|
|
|
|
|
return mScrollThreshold;
|
|
|
|
|
}
|
2023-06-08 13:52:06 -07:00
|
|
|
|
|
|
|
|
public void updateStringFromCache(){
|
|
|
|
|
StringCache cache = mActivityContext.getStringCache();
|
|
|
|
|
if (cache != null) {
|
2024-09-20 14:50:55 -07:00
|
|
|
mPauseText.setText(cache.workProfilePauseButton);
|
2023-06-08 13:52:06 -07:00
|
|
|
}
|
|
|
|
|
}
|
2024-09-20 14:50:55 -07:00
|
|
|
|
2024-11-25 13:51:33 -08:00
|
|
|
@VisibleForTesting
|
|
|
|
|
boolean shouldUseScheduler() {
|
2024-09-20 14:50:55 -07:00
|
|
|
return Flags.workSchedulerInWorkProfile() && !mWorkSchedulerIntentAction.isEmpty();
|
|
|
|
|
}
|
2024-11-25 13:51:33 -08:00
|
|
|
|
|
|
|
|
@VisibleForTesting
|
|
|
|
|
ImageButton getSchedulerButton() {
|
|
|
|
|
return mSchedulerButton;
|
|
|
|
|
}
|
2018-01-03 14:41:31 +00:00
|
|
|
}
|