Merge remote-tracking branch 'aosp/android12L-release' into 12.1-dev
This commit is contained in:
commit
11e1a2fdc8
825 files changed
+38322
-29268
No files matched your search
@@ -16,30 +16,24 @@
|
||||
package com.android.launcher3.allapps;
|
||||
|
||||
import static com.android.launcher3.logging.StatsLogManager.LauncherEvent.LAUNCHER_TURN_OFF_WORK_APPS_TAP;
|
||||
import static com.android.launcher3.util.Executors.UI_HELPER_EXECUTOR;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.res.ColorStateList;
|
||||
import android.graphics.Insets;
|
||||
import android.graphics.Rect;
|
||||
import android.os.Build;
|
||||
import android.os.Process;
|
||||
import android.os.UserHandle;
|
||||
import android.os.UserManager;
|
||||
import android.util.AttributeSet;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.view.WindowInsets;
|
||||
import android.widget.Button;
|
||||
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.annotation.RequiresApi;
|
||||
|
||||
import com.android.launcher3.BaseDraggingActivity;
|
||||
import com.android.launcher3.DeviceProfile;
|
||||
import com.android.launcher3.Insettable;
|
||||
import com.android.launcher3.Launcher;
|
||||
import com.android.launcher3.Utilities;
|
||||
import com.android.launcher3.anim.KeyboardInsetAnimationCallback;
|
||||
import com.android.launcher3.pm.UserCache;
|
||||
import com.android.launcher3.workprofile.PersonalWorkSlidingTabStrip;
|
||||
|
||||
import app.lawnchair.font.FontManager;
|
||||
import app.lawnchair.theme.color.ColorStateListTokens;
|
||||
@@ -48,15 +42,20 @@ import app.lawnchair.theme.drawable.DrawableTokens;
|
||||
/**
|
||||
* Work profile toggle switch shown at the bottom of AllApps work tab
|
||||
*/
|
||||
public class WorkModeSwitch extends Button implements Insettable, View.OnClickListener {
|
||||
public class WorkModeSwitch extends Button implements Insettable, View.OnClickListener,
|
||||
KeyboardInsetAnimationCallback.KeyboardInsetListener,
|
||||
PersonalWorkSlidingTabStrip.OnActivePageChangedListener {
|
||||
|
||||
private Rect mInsets = new Rect();
|
||||
private static final int FLAG_FADE_ONGOING = 1 << 1;
|
||||
private static final int FLAG_TRANSLATION_ONGOING = 1 << 2;
|
||||
private static final int FLAG_PROFILE_TOGGLE_ONGOING = 1 << 3;
|
||||
|
||||
private final Rect mInsets = new Rect();
|
||||
private int mFlags;
|
||||
private boolean mWorkEnabled;
|
||||
private boolean mOnWorkTab;
|
||||
|
||||
|
||||
@Nullable
|
||||
private KeyboardInsetAnimationCallback mKeyboardInsetAnimationCallback;
|
||||
|
||||
public WorkModeSwitch(Context context) {
|
||||
this(context, null, 0);
|
||||
}
|
||||
@@ -77,14 +76,17 @@ public class WorkModeSwitch extends Button implements Insettable, View.OnClickLi
|
||||
setSelected(true);
|
||||
setOnClickListener(this);
|
||||
if (Utilities.ATLEAST_R) {
|
||||
mKeyboardInsetAnimationCallback = new KeyboardInsetAnimationCallback(this);
|
||||
setWindowInsetsAnimationCallback(mKeyboardInsetAnimationCallback);
|
||||
KeyboardInsetAnimationCallback keyboardInsetAnimationCallback =
|
||||
new KeyboardInsetAnimationCallback(this);
|
||||
setWindowInsetsAnimationCallback(keyboardInsetAnimationCallback);
|
||||
}
|
||||
|
||||
setBackground(DrawableTokens.WorkAppsToggleBackground.resolve(getContext()));
|
||||
ColorStateList textColor = ColorStateListTokens.AllAppsTabText.resolve(getContext());
|
||||
setTextColor(textColor);
|
||||
setCompoundDrawableTintList(textColor);
|
||||
DeviceProfile grid = BaseDraggingActivity.fromContext(getContext()).getDeviceProfile();
|
||||
setInsets(grid.getInsets());
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -98,58 +100,58 @@ public class WorkModeSwitch extends Button implements Insettable, View.OnClickLi
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Animates in/out work profile toggle panel based on the tab user is on
|
||||
*/
|
||||
public void setWorkTabVisible(boolean workTabVisible) {
|
||||
clearAnimation();
|
||||
if (workTabVisible) {
|
||||
setEnabled(true);
|
||||
if (mWorkEnabled) {
|
||||
setVisibility(VISIBLE);
|
||||
}
|
||||
setAlpha(0);
|
||||
animate().alpha(1).start();
|
||||
} else {
|
||||
animate().alpha(0).withEndAction(() -> this.setVisibility(GONE)).start();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onActivePageChanged(int page) {
|
||||
mOnWorkTab = page == AllAppsContainerView.AdapterHolder.WORK;
|
||||
updateVisibility();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
if (Utilities.ATLEAST_P) {
|
||||
setEnabled(false);
|
||||
Launcher.fromContext(getContext()).getStatsLogManager().logger().log(
|
||||
LAUNCHER_TURN_OFF_WORK_APPS_TAP);
|
||||
UI_HELPER_EXECUTOR.post(() -> setWorkProfileEnabled(getContext(), false));
|
||||
if (Utilities.ATLEAST_P && isEnabled()) {
|
||||
setFlag(FLAG_PROFILE_TOGGLE_ONGOING);
|
||||
Launcher launcher = Launcher.getLauncher(getContext());
|
||||
launcher.getStatsLogManager().logger().log(LAUNCHER_TURN_OFF_WORK_APPS_TAP);
|
||||
launcher.getAppsView().getWorkManager().setWorkProfileEnabled(false);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEnabled() {
|
||||
return super.isEnabled() && getVisibility() == VISIBLE && mFlags == 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the enabled or disabled state of the button
|
||||
*/
|
||||
public void updateCurrentState(boolean active) {
|
||||
mWorkEnabled = active;
|
||||
setEnabled(true);
|
||||
setVisibility(active ? VISIBLE : GONE);
|
||||
public void updateCurrentState(boolean isEnabled) {
|
||||
removeFlag(FLAG_PROFILE_TOGGLE_ONGOING);
|
||||
if (mWorkEnabled != isEnabled) {
|
||||
mWorkEnabled = isEnabled;
|
||||
updateVisibility();
|
||||
}
|
||||
}
|
||||
|
||||
@RequiresApi(Build.VERSION_CODES.P)
|
||||
public static Boolean setWorkProfileEnabled(Context context, boolean enabled) {
|
||||
UserManager userManager = context.getSystemService(UserManager.class);
|
||||
boolean showConfirm = false;
|
||||
for (UserHandle userProfile : UserCache.INSTANCE.get(context).getUserProfiles()) {
|
||||
if (Process.myUserHandle().equals(userProfile)) {
|
||||
continue;
|
||||
}
|
||||
showConfirm |= !userManager.requestQuietModeEnabled(!enabled, userProfile);
|
||||
|
||||
private void updateVisibility() {
|
||||
clearAnimation();
|
||||
if (mWorkEnabled && mOnWorkTab) {
|
||||
setFlag(FLAG_FADE_ONGOING);
|
||||
setVisibility(VISIBLE);
|
||||
animate().alpha(1).withEndAction(() -> removeFlag(FLAG_FADE_ONGOING)).start();
|
||||
} else if (getVisibility() != GONE) {
|
||||
setFlag(FLAG_FADE_ONGOING);
|
||||
animate().alpha(0).withEndAction(() -> {
|
||||
removeFlag(FLAG_FADE_ONGOING);
|
||||
this.setVisibility(GONE);
|
||||
}).start();
|
||||
}
|
||||
return showConfirm;
|
||||
}
|
||||
|
||||
@Override
|
||||
public WindowInsets onApplyWindowInsets(WindowInsets insets) {
|
||||
if (Utilities.ATLEAST_R) {
|
||||
if (Utilities.ATLEAST_R && isEnabled()) {
|
||||
setTranslationY(0);
|
||||
if (insets.isVisible(WindowInsets.Type.ime())) {
|
||||
Insets keyboardInsets = insets.getInsets(WindowInsets.Type.ime());
|
||||
@@ -158,4 +160,22 @@ public class WorkModeSwitch extends Button implements Insettable, View.OnClickLi
|
||||
}
|
||||
return insets;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onTranslationStart() {
|
||||
setFlag(FLAG_TRANSLATION_ONGOING);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onTranslationEnd() {
|
||||
removeFlag(FLAG_TRANSLATION_ONGOING);
|
||||
}
|
||||
|
||||
private void setFlag(int flag) {
|
||||
mFlags |= flag;
|
||||
}
|
||||
|
||||
private void removeFlag(int flag) {
|
||||
mFlags &= ~flag;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user