Adding Private Space views to Launcher.
This CL adds the following: * Static View Elements to be added to AllApps recycler View * View Controller to load the above elements dynamically * Private Space Section Decorator * PrivateProfile Manager containing the logic related to Private Space * Abstract UserProfileManager as the super class of Work/Private ProfileManager Private Space Views Figma [link](https://www.figma.com/file/K6bIIcG882EiJNjxvSWsFT/V%E2%80%A2-Private-Space?type=design&node-id=14535-111985&mode=design&t=JLz9W0O551TpzQYH-0) Flag: ACONFIG com.android.launcher3.Flags.enable_private_space DEVELOPMENT Bug: 289223923 Test: Ran Launcher3 tests Change-Id: I8aa4247c78064a551e5e0d0b46d3fc033873f99d
This commit is contained in:
@@ -26,18 +26,14 @@ import static com.android.launcher3.model.BgDataModel.Callbacks.FLAG_HAS_SHORTCU
|
||||
import static com.android.launcher3.model.BgDataModel.Callbacks.FLAG_QUIET_MODE_CHANGE_PERMISSION;
|
||||
import static com.android.launcher3.model.BgDataModel.Callbacks.FLAG_QUIET_MODE_ENABLED;
|
||||
import static com.android.launcher3.model.BgDataModel.Callbacks.FLAG_WORK_PROFILE_QUIET_MODE_ENABLED;
|
||||
import static com.android.launcher3.util.Executors.UI_HELPER_EXECUTOR;
|
||||
|
||||
import android.os.Build;
|
||||
import android.os.UserHandle;
|
||||
import android.os.UserManager;
|
||||
import android.util.Log;
|
||||
import android.view.View;
|
||||
|
||||
import androidx.annotation.IntDef;
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.annotation.RequiresApi;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
import com.android.launcher3.Flags;
|
||||
@@ -46,12 +42,9 @@ import com.android.launcher3.R;
|
||||
import com.android.launcher3.Utilities;
|
||||
import com.android.launcher3.allapps.BaseAllAppsAdapter.AdapterItem;
|
||||
import com.android.launcher3.logging.StatsLogManager;
|
||||
import com.android.launcher3.model.data.ItemInfo;
|
||||
import com.android.launcher3.pm.UserCache;
|
||||
import com.android.launcher3.workprofile.PersonalWorkSlidingTabStrip;
|
||||
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.util.ArrayList;
|
||||
import java.util.function.Predicate;
|
||||
import java.util.stream.Stream;
|
||||
@@ -59,62 +52,29 @@ import java.util.stream.Stream;
|
||||
/**
|
||||
* Companion class for {@link ActivityAllAppsContainerView} to manage work tab and personal tab
|
||||
* related
|
||||
* logic based on {@link WorkProfileState}?
|
||||
* logic based on {@link UserProfileState}?
|
||||
*/
|
||||
public class WorkProfileManager implements PersonalWorkSlidingTabStrip.OnActivePageChangedListener {
|
||||
public class WorkProfileManager extends UserProfileManager
|
||||
implements PersonalWorkSlidingTabStrip.OnActivePageChangedListener {
|
||||
private static final String TAG = "WorkProfileManager";
|
||||
|
||||
public static final int STATE_ENABLED = 1;
|
||||
public static final int STATE_DISABLED = 2;
|
||||
public static final int STATE_TRANSITION = 3;
|
||||
|
||||
/**
|
||||
* Work profile manager states
|
||||
*/
|
||||
@IntDef(value = {
|
||||
STATE_ENABLED,
|
||||
STATE_DISABLED,
|
||||
STATE_TRANSITION
|
||||
})
|
||||
@Retention(RetentionPolicy.SOURCE)
|
||||
public @interface WorkProfileState { }
|
||||
|
||||
private final UserManager mUserManager;
|
||||
private final ActivityAllAppsContainerView<?> mAllApps;
|
||||
private final Predicate<ItemInfo> mMatcher;
|
||||
private final StatsLogManager mStatsLogManager;
|
||||
|
||||
private WorkModeSwitch mWorkModeSwitch;
|
||||
|
||||
private final UserCache mUserCache;
|
||||
|
||||
@WorkProfileState
|
||||
private int mCurrentState;
|
||||
private final Predicate<UserHandle> mWorkProfileMatcher;
|
||||
|
||||
public WorkProfileManager(
|
||||
UserManager userManager, ActivityAllAppsContainerView allApps,
|
||||
StatsLogManager statsLogManager, UserCache userCache) {
|
||||
mUserManager = userManager;
|
||||
super(userManager, statsLogManager, userCache);
|
||||
mAllApps = allApps;
|
||||
mStatsLogManager = statsLogManager;
|
||||
mUserCache = userCache;
|
||||
mMatcher = info -> info != null && mUserCache.getUserInfo(info.user).isWork();
|
||||
mWorkProfileMatcher = (user) -> userCache.getUserInfo(user).isWork();
|
||||
}
|
||||
|
||||
/**
|
||||
* Posts quite mode enable/disable call for work profile user
|
||||
*/
|
||||
@RequiresApi(Build.VERSION_CODES.P)
|
||||
public void setWorkProfileEnabled(boolean enabled) {
|
||||
updateCurrentState(STATE_TRANSITION);
|
||||
UI_HELPER_EXECUTOR.post(() -> {
|
||||
for (UserHandle userProfile : mUserCache.getUserProfiles()) {
|
||||
if (mUserCache.getUserInfo(userProfile).isWork()) {
|
||||
mUserManager.requestQuietModeEnabled(!enabled, userProfile);
|
||||
break;
|
||||
}
|
||||
}
|
||||
});
|
||||
setCurrentState(STATE_TRANSITION);
|
||||
setQuietMode(!enabled);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -126,7 +86,7 @@ public class WorkProfileManager implements PersonalWorkSlidingTabStrip.OnActiveP
|
||||
if (mWorkModeSwitch != null) {
|
||||
if (page == MAIN || page == SEARCH) {
|
||||
mWorkModeSwitch.animateVisibility(false);
|
||||
} else if (page == WORK && mCurrentState == STATE_ENABLED) {
|
||||
} else if (page == WORK && getCurrentState() == STATE_ENABLED) {
|
||||
mWorkModeSwitch.animateVisibility(true);
|
||||
}
|
||||
}
|
||||
@@ -151,17 +111,17 @@ public class WorkProfileManager implements PersonalWorkSlidingTabStrip.OnActiveP
|
||||
}
|
||||
}
|
||||
|
||||
private void updateCurrentState(@WorkProfileState int currentState) {
|
||||
mCurrentState = currentState;
|
||||
private void updateCurrentState(@UserProfileState int currentState) {
|
||||
setCurrentState(currentState);
|
||||
if (getAH() != null) {
|
||||
getAH().mAppsList.updateAdapterItems();
|
||||
}
|
||||
if (mWorkModeSwitch != null) {
|
||||
updateWorkFAB(mAllApps.getCurrentPage());
|
||||
}
|
||||
if (mCurrentState == STATE_ENABLED) {
|
||||
if (getCurrentState() == STATE_ENABLED) {
|
||||
attachWorkModeSwitch();
|
||||
} else if (mCurrentState == STATE_DISABLED) {
|
||||
} else if (getCurrentState() == STATE_DISABLED) {
|
||||
detachWorkModeSwitch();
|
||||
}
|
||||
}
|
||||
@@ -201,10 +161,6 @@ public class WorkProfileManager implements PersonalWorkSlidingTabStrip.OnActiveP
|
||||
mWorkModeSwitch = null;
|
||||
}
|
||||
|
||||
public Predicate<ItemInfo> getMatcher() {
|
||||
return mMatcher;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public WorkModeSwitch getWorkModeSwitch() {
|
||||
return mWorkModeSwitch;
|
||||
@@ -214,29 +170,25 @@ public class WorkProfileManager implements PersonalWorkSlidingTabStrip.OnActiveP
|
||||
return mAllApps.mAH.get(WORK);
|
||||
}
|
||||
|
||||
public int getCurrentState() {
|
||||
return mCurrentState;
|
||||
}
|
||||
|
||||
/**
|
||||
* returns whether or not work apps should be visible in work tab.
|
||||
*/
|
||||
public boolean shouldShowWorkApps() {
|
||||
return mCurrentState != WorkProfileManager.STATE_DISABLED;
|
||||
return getCurrentState() != WorkProfileManager.STATE_DISABLED;
|
||||
}
|
||||
|
||||
public boolean hasWorkApps() {
|
||||
return Stream.of(mAllApps.getAppsStore().getApps()).anyMatch(mMatcher);
|
||||
return Stream.of(mAllApps.getAppsStore().getApps()).anyMatch(getItemInfoMatcher());
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds work profile specific adapter items to adapterItems and returns number of items added
|
||||
*/
|
||||
public int addWorkItems(ArrayList<AdapterItem> adapterItems) {
|
||||
if (mCurrentState == WorkProfileManager.STATE_DISABLED) {
|
||||
if (getCurrentState() == WorkProfileManager.STATE_DISABLED) {
|
||||
//add disabled card here.
|
||||
adapterItems.add(new AdapterItem(VIEW_TYPE_WORK_DISABLED_CARD));
|
||||
} else if (mCurrentState == WorkProfileManager.STATE_ENABLED && !isEduSeen()) {
|
||||
} else if (getCurrentState() == WorkProfileManager.STATE_ENABLED && !isEduSeen()) {
|
||||
adapterItems.add(new AdapterItem(VIEW_TYPE_WORK_EDU_CARD));
|
||||
}
|
||||
return adapterItems.size();
|
||||
@@ -247,8 +199,9 @@ public class WorkProfileManager implements PersonalWorkSlidingTabStrip.OnActiveP
|
||||
}
|
||||
|
||||
private void onWorkFabClicked(View view) {
|
||||
if (Utilities.ATLEAST_P && mCurrentState == STATE_ENABLED && mWorkModeSwitch.isEnabled()) {
|
||||
mStatsLogManager.logger().log(LAUNCHER_TURN_OFF_WORK_APPS_TAP);
|
||||
if (Utilities.ATLEAST_P && getCurrentState() == STATE_ENABLED
|
||||
&& mWorkModeSwitch.isEnabled()) {
|
||||
logEvents(LAUNCHER_TURN_OFF_WORK_APPS_TAP);
|
||||
setWorkProfileEnabled(false);
|
||||
}
|
||||
}
|
||||
@@ -279,4 +232,9 @@ public class WorkProfileManager implements PersonalWorkSlidingTabStrip.OnActiveP
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
public Predicate<UserHandle> getUserMatcher() {
|
||||
return mWorkProfileMatcher;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user