Implement the work scheduler view and update colors of FAB

Update colors of the FAB to spec: https://www.figma.com/design/uMzPkNMZpb7EyfHDo8usIa/V-%E2%80%A2-Toast-Butter?node-id=3784-112229&node-type=instance&m=dev
Exported the brief case icon from figma since it is not available on go/icons.
Color of the brief case icon is onPrimary.
Have place holder string in launcher but implement the actual string in NL.

bug:361589193
Test - manual: video: https://drive.google.com/file/d/1CIs8qdtV1jUvbq57CcgAXDBPPHHX5CKJ/view?usp=sharing
Flag: com.android.launcher3.work_scheduler_in_work_profile

Change-Id: Ia98e9c4394f6ddfa7009653034929f9afbfeac8c
This commit is contained in:
Brandon Dayauon committed 2024-11-06 09:48:26 -08:00
1 parent 4674c3bb2b
commit bfd02bb36a
17 files changed
+246 -94

No files matched your search

@@ -726,7 +726,7 @@ public class ActivityAllAppsContainerView<T extends Context & ActivityContext>
post(() -> mAH.get(AdapterHolder.WORK).applyPadding());
} else {
mWorkManager.detachWorkModeSwitch();
mWorkManager.detachWorkUtilityViews();
mViewPager = null;
}
@@ -1257,8 +1257,8 @@ public class ActivityAllAppsContainerView<T extends Context & ActivityContext>
/** Called in Launcher#bindStringCache() to update the UI when cache is updated. */
public void updateWorkUI() {
setDeviceManagementResources();
if (mWorkManager.getWorkModeSwitch() != null) {
mWorkManager.getWorkModeSwitch().updateStringFromCache();
if (mWorkManager.getWorkUtilityView() != null) {
mWorkManager.getWorkUtilityView().updateStringFromCache();
}
inflateWorkCardsIfNeeded();
}
@@ -1581,8 +1581,8 @@ public class ActivityAllAppsContainerView<T extends Context & ActivityContext>
void applyPadding() {
if (mRecyclerView != null) {
int bottomOffset = 0;
if (isWork() && mWorkManager.getWorkModeSwitch() != null) {
bottomOffset = mInsets.bottom + mWorkManager.getWorkModeSwitch().getHeight();
if (isWork() && mWorkManager.getWorkUtilityView() != null) {
bottomOffset = mInsets.bottom + mWorkManager.getWorkUtilityView().getHeight();
} else if (isMain() && mPrivateProfileManager != null) {
Optional<AdapterItem> privateSpaceHeaderItem = mAppsList.getAdapterItems()
.stream()
@@ -58,7 +58,7 @@ public class WorkProfileManager extends UserProfileManager
implements PersonalWorkSlidingTabStrip.OnActivePageChangedListener {
private static final String TAG = "WorkProfileManager";
private final ActivityAllAppsContainerView<?> mAllApps;
private WorkModeSwitch mWorkModeSwitch;
private WorkUtilityView mWorkUtilityView;
private final Predicate<UserHandle> mWorkProfileMatcher;
public WorkProfileManager(
@@ -79,15 +79,15 @@ public class WorkProfileManager extends UserProfileManager
@Override
public void onActivePageChanged(int page) {
updateWorkFAB(page);
updateWorkUtilityViews(page);
}
private void updateWorkFAB(int page) {
if (mWorkModeSwitch != null) {
private void updateWorkUtilityViews(int page) {
if (mWorkUtilityView != null) {
if (page == MAIN || page == SEARCH) {
mWorkModeSwitch.animateVisibility(false);
mWorkUtilityView.animateVisibility(false);
} else if (page == WORK && getCurrentState() == STATE_ENABLED) {
mWorkModeSwitch.animateVisibility(true);
mWorkUtilityView.animateVisibility(true);
}
}
}
@@ -104,10 +104,10 @@ public class WorkProfileManager extends UserProfileManager
}
boolean isEnabled = !mAllApps.getAppsStore().hasModelFlag(quietModeFlag);
updateCurrentState(isEnabled ? STATE_ENABLED : STATE_DISABLED);
if (mWorkModeSwitch != null) {
if (mWorkUtilityView != null) {
// reset the position of the button and clear IME insets.
mWorkModeSwitch.getImeInsets().setEmpty();
mWorkModeSwitch.updateTranslationY();
mWorkUtilityView.getImeInsets().setEmpty();
mWorkUtilityView.updateTranslationY();
}
}
@@ -116,54 +116,54 @@ public class WorkProfileManager extends UserProfileManager
if (getAH() != null) {
getAH().mAppsList.updateAdapterItems();
}
if (mWorkModeSwitch != null) {
updateWorkFAB(mAllApps.getCurrentPage());
if (mWorkUtilityView != null) {
updateWorkUtilityViews(mAllApps.getCurrentPage());
}
if (getCurrentState() == STATE_ENABLED) {
attachWorkModeSwitch();
attachWorkUtilityViews();
} else if (getCurrentState() == STATE_DISABLED) {
detachWorkModeSwitch();
detachWorkUtilityViews();
}
}
/**
* Creates and attaches for profile toggle button to {@link ActivityAllAppsContainerView}
*/
public boolean attachWorkModeSwitch() {
public boolean attachWorkUtilityViews() {
if (!mAllApps.getAppsStore().hasModelFlag(
FLAG_HAS_SHORTCUT_PERMISSION | FLAG_QUIET_MODE_CHANGE_PERMISSION)) {
Log.e(TAG, "unable to attach work mode switch; Missing required permissions");
return false;
}
if (mWorkModeSwitch == null) {
mWorkModeSwitch = (WorkModeSwitch) mAllApps.getLayoutInflater().inflate(
R.layout.work_mode_fab, mAllApps, false);
if (mWorkUtilityView == null) {
mWorkUtilityView = (WorkUtilityView) mAllApps.getLayoutInflater().inflate(
R.layout.work_mode_utility_view, mAllApps, false);
}
if (mWorkModeSwitch.getParent() == null) {
mAllApps.addView(mWorkModeSwitch);
if (mWorkUtilityView.getParent() == null) {
mAllApps.addView(mWorkUtilityView);
}
if (mAllApps.getCurrentPage() != WORK) {
mWorkModeSwitch.animateVisibility(false);
mWorkUtilityView.animateVisibility(false);
}
if (getAH() != null) {
getAH().applyPadding();
}
mWorkModeSwitch.setOnClickListener(this::onWorkFabClicked);
mWorkUtilityView.setOnClickListener(this::onWorkFabClicked);
return true;
}
/**
* Removes work profile toggle button from {@link ActivityAllAppsContainerView}
*/
public void detachWorkModeSwitch() {
if (mWorkModeSwitch != null && mWorkModeSwitch.getParent() == mAllApps) {
mAllApps.removeView(mWorkModeSwitch);
public void detachWorkUtilityViews() {
if (mWorkUtilityView != null && mWorkUtilityView.getParent() == mAllApps) {
mAllApps.removeView(mWorkUtilityView);
}
mWorkModeSwitch = null;
mWorkUtilityView = null;
}
@Nullable
public WorkModeSwitch getWorkModeSwitch() {
return mWorkModeSwitch;
public WorkUtilityView getWorkUtilityView() {
return mWorkUtilityView;
}
private ActivityAllAppsContainerView.AdapterHolder getAH() {
@@ -199,7 +199,7 @@ public class WorkProfileManager extends UserProfileManager
}
private void onWorkFabClicked(View view) {
if (getCurrentState() == STATE_ENABLED && mWorkModeSwitch.isEnabled()) {
if (getCurrentState() == STATE_ENABLED && mWorkUtilityView.isEnabled()) {
logEvents(LAUNCHER_TURN_OFF_WORK_APPS_TAP);
setWorkProfileEnabled(false);
}
@@ -216,7 +216,7 @@ public class WorkProfileManager extends UserProfileManager
}
@Override
public void onScrolled(@NonNull RecyclerView recyclerView, int dx, int dy) {
WorkModeSwitch fab = getWorkModeSwitch();
WorkUtilityView fab = getWorkUtilityView();
if (fab == null){
return;
}
@@ -21,11 +21,13 @@ import android.animation.AnimatorSet;
import android.animation.ObjectAnimator;
import android.animation.ValueAnimator;
import android.content.Context;
import android.content.Intent;
import android.graphics.Rect;
import android.text.TextUtils;
import android.util.AttributeSet;
import android.view.ViewGroup;
import android.view.WindowInsets;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
@@ -36,6 +38,7 @@ import androidx.core.view.WindowInsetsCompat;
import com.android.app.animation.Interpolators;
import com.android.launcher3.DeviceProfile;
import com.android.launcher3.Flags;
import com.android.launcher3.Insettable;
import com.android.launcher3.R;
import com.android.launcher3.Utilities;
@@ -43,10 +46,13 @@ import com.android.launcher3.anim.AnimatedPropertySetter;
import com.android.launcher3.anim.KeyboardInsetAnimationCallback;
import com.android.launcher3.model.StringCache;
import com.android.launcher3.views.ActivityContext;
import java.util.ArrayList;
/**
* Work profile toggle switch shown at the bottom of AllApps work tab
* Work profile utility ViewGroup that is shown at the bottom of AllApps work tab
*/
public class WorkModeSwitch extends LinearLayout implements Insettable,
public class WorkUtilityView extends LinearLayout implements Insettable,
KeyboardInsetAnimationCallback.KeyboardInsetListener {
private static final int TEXT_EXPAND_OPACITY_DURATION = 300;
@@ -54,10 +60,14 @@ public class WorkModeSwitch extends LinearLayout implements Insettable,
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;
private static final int WORK_SCHEDULER_OPACITY_DURATION =
(int) (EXPAND_COLLAPSE_DURATION * 0.75f);
private static final int FLAG_FADE_ONGOING = 1 << 1;
private static final int FLAG_TRANSLATION_ONGOING = 1 << 2;
private static final int FLAG_IS_EXPAND = 1 << 3;
private static final int SCROLL_THRESHOLD_DP = 10;
private static final float WORK_SCHEDULER_SCALE_MIN = 0.25f;
private static final float WORK_SCHEDULER_SCALE_MAX = 1f;
private final Rect mInsets = new Rect();
private final Rect mImeInsets = new Rect();
@@ -67,22 +77,25 @@ public class WorkModeSwitch extends LinearLayout implements Insettable,
private final int mTextMarginStart;
private final int mTextMarginEnd;
private final int mIconMarginStart;
private final String mWorkSchedulerIntentAction;
// Threshold when user scrolls up/down to determine when should button extend/collapse
private final int mScrollThreshold;
private TextView mTextView;
private ImageView mIcon;
private ValueAnimator mPauseFABAnim;
private TextView mPauseText;
private ImageView mWorkIcon;
private ImageButton mSchedulerButton;
public WorkModeSwitch(@NonNull Context context) {
public WorkUtilityView(@NonNull Context context) {
this(context, null, 0);
}
public WorkModeSwitch(@NonNull Context context, @NonNull AttributeSet attrs) {
public WorkUtilityView(@NonNull Context context, @NonNull AttributeSet attrs) {
this(context, attrs, 0);
}
public WorkModeSwitch(@NonNull Context context, @NonNull AttributeSet attrs, int defStyleAttr) {
public WorkUtilityView(@NonNull Context context, @NonNull AttributeSet attrs,
int defStyleAttr) {
super(context, attrs, defStyleAttr);
mContext = context;
mScrollThreshold = Utilities.dpToPx(SCROLL_THRESHOLD_DP);
@@ -93,14 +106,17 @@ public class WorkModeSwitch extends LinearLayout implements Insettable,
R.dimen.work_fab_text_end_margin);
mIconMarginStart = mContext.getResources().getDimensionPixelSize(
R.dimen.work_fab_icon_start_margin_expanded);
mWorkSchedulerIntentAction = mContext.getResources().getString(
R.string.work_profile_scheduler_intent);
}
@Override
protected void onFinishInflate() {
super.onFinishInflate();
mTextView = findViewById(R.id.pause_text);
mIcon = findViewById(R.id.work_icon);
mPauseText = findViewById(R.id.pause_text);
mWorkIcon = findViewById(R.id.work_icon);
mSchedulerButton = findViewById(R.id.work_scheduler);
setSelected(true);
KeyboardInsetAnimationCallback keyboardInsetAnimationCallback =
new KeyboardInsetAnimationCallback(this);
@@ -109,6 +125,12 @@ public class WorkModeSwitch extends LinearLayout implements Insettable,
addFlag(FLAG_IS_EXPAND);
setInsets(mActivityContext.getDeviceProfile().getInsets());
updateStringFromCache();
mSchedulerButton.setVisibility(GONE);
if (shouldUseScheduler()) {
mSchedulerButton.setVisibility(VISIBLE);
mSchedulerButton.setOnClickListener(view ->
mContext.startActivity(new Intent(mWorkSchedulerIntentAction)));
}
}
@Override
@@ -183,15 +205,63 @@ public class WorkModeSwitch extends LinearLayout implements Insettable,
super.setTranslationY(Math.min(translationY, -mInsets.bottom));
}
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);
}
}
private void animatePillTransition(boolean isExpanding) {
@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;
}
private void animateWorkUtilityViews(boolean isExpanding) {
if (!shouldAnimate(isExpanding)) {
return;
}
AnimatorSet animatorSet = new AnimatedPropertySetter().buildAnim();
mTextView.measure(0,0);
int currentWidth = mTextView.getWidth();
int fullWidth = mTextView.getMeasuredWidth();
mPauseText.measure(0,0);
int currentWidth = mPauseText.getWidth();
int fullWidth = mPauseText.getMeasuredWidth();
float from = isExpanding ? 0 : currentWidth;
float to = isExpanding ? fullWidth : 0;
mPauseFABAnim = ObjectAnimator.ofFloat(from, to);
@@ -203,15 +273,15 @@ public class WorkModeSwitch extends LinearLayout implements Insettable,
float translation = (float) valueAnimator.getAnimatedValue();
float translationFraction = translation / fullWidth;
ViewGroup.MarginLayoutParams textViewLayoutParams =
(ViewGroup.MarginLayoutParams) mTextView.getLayoutParams();
(ViewGroup.MarginLayoutParams) mPauseText.getLayoutParams();
textViewLayoutParams.width = (int) translation;
textViewLayoutParams.setMarginStart((int) (mTextMarginStart * translationFraction));
textViewLayoutParams.setMarginEnd((int) (mTextMarginEnd * translationFraction));
mTextView.setLayoutParams(textViewLayoutParams);
mPauseText.setLayoutParams(textViewLayoutParams);
ViewGroup.MarginLayoutParams iconLayoutParams =
(ViewGroup.MarginLayoutParams) mIcon.getLayoutParams();
(ViewGroup.MarginLayoutParams) mWorkIcon.getLayoutParams();
iconLayoutParams.setMarginStart((int) (mIconMarginStart * translationFraction));
mIcon.setLayoutParams(iconLayoutParams);
mWorkIcon.setLayoutParams(iconLayoutParams);
}
});
mPauseFABAnim.addListener(new AnimatorListenerAdapter() {
@@ -220,21 +290,28 @@ public class WorkModeSwitch extends LinearLayout implements Insettable,
if (isExpanding) {
addFlag(FLAG_IS_EXPAND);
} else {
mTextView.setVisibility(GONE);
mPauseText.setVisibility(GONE);
removeFlag(FLAG_IS_EXPAND);
}
mTextView.setHorizontallyScrolling(false);
mTextView.setEllipsize(TextUtils.TruncateAt.END);
mPauseText.setHorizontallyScrolling(false);
mPauseText.setEllipsize(TextUtils.TruncateAt.END);
}
@Override
public void onAnimationStart(Animator animator) {
mTextView.setHorizontallyScrolling(true);
mTextView.setVisibility(VISIBLE);
mTextView.setEllipsize(null);
mPauseText.setHorizontallyScrolling(true);
mPauseText.setVisibility(VISIBLE);
mPauseText.setEllipsize(null);
}
});
animatorSet.playTogether(mPauseFABAnim, updatePauseTextAlpha(isExpanding));
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);
animatorSet.start();
}
@@ -250,7 +327,7 @@ public class WorkModeSwitch extends LinearLayout implements Insettable,
alphaAnim.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
@Override
public void onAnimationUpdate(ValueAnimator valueAnimator) {
mTextView.setAlpha((float) valueAnimator.getAnimatedValue());
mPauseText.setAlpha((float) valueAnimator.getAnimatedValue());
}
});
return alphaAnim;
@@ -287,11 +364,11 @@ public class WorkModeSwitch extends LinearLayout implements Insettable,
}
public void extend() {
animatePillTransition(true);
animateWorkUtilityViews(true);
}
public void shrink(){
animatePillTransition(false);
public void shrink() {
animateWorkUtilityViews(false);
}
/**
@@ -310,7 +387,11 @@ public class WorkModeSwitch extends LinearLayout implements Insettable,
public void updateStringFromCache(){
StringCache cache = mActivityContext.getStringCache();
if (cache != null) {
mTextView.setText(cache.workProfilePauseButton);
mPauseText.setText(cache.workProfilePauseButton);
}
}
private boolean shouldUseScheduler() {
return Flags.workSchedulerInWorkProfile() && !mWorkSchedulerIntentAction.isEmpty();
}
}