Work toggle improvements

Bug:141289979
Test:Manual
Change-Id: If96845c0220816f9ffd5a5c86ec33b2674d15d1d
This commit is contained in:
Samuel Fufa
2020-01-21 09:58:14 -08:00
parent 766a5d1337
commit 8f6d141d84
14 changed files with 245 additions and 102 deletions

View File

@@ -15,6 +15,9 @@
*/
package com.android.launcher3.allapps;
import static android.view.View.MeasureSpec.EXACTLY;
import static android.view.View.MeasureSpec.makeMeasureSpec;
import android.animation.ValueAnimator;
import android.content.Context;
import android.graphics.Canvas;
@@ -51,6 +54,7 @@ import com.android.launcher3.ItemInfo;
import com.android.launcher3.R;
import com.android.launcher3.Utilities;
import com.android.launcher3.keyboard.FocusedItemDecorator;
import com.android.launcher3.pm.UserCache;
import com.android.launcher3.userevent.nano.LauncherLogProto.ContainerType;
import com.android.launcher3.userevent.nano.LauncherLogProto.Target;
import com.android.launcher3.util.ItemInfoMatcher;
@@ -59,6 +63,7 @@ import com.android.launcher3.util.MultiValueAlpha.AlphaProperty;
import com.android.launcher3.util.Themes;
import com.android.launcher3.views.RecyclerViewFastScroller;
import com.android.launcher3.views.SpringRelativeLayout;
import com.android.launcher3.views.WorkFooterContainer;
/**
* The all apps view container.
@@ -83,7 +88,10 @@ public class AllAppsContainerView extends SpringRelativeLayout implements DragSo
protected SearchUiManager mSearchUiManager;
private View mSearchContainer;
private AllAppsPagedView mViewPager;
private FloatingHeaderView mHeader;
private WorkFooterContainer mWorkFooterContainer;
private SpannableStringBuilder mSearchQueryBuilder = null;
@@ -173,6 +181,15 @@ public class AllAppsContainerView extends SpringRelativeLayout implements DragSo
}
}
rebindAdapters(hasWorkApps);
if (hasWorkApps) {
resetWorkProfile();
}
}
private void resetWorkProfile() {
mWorkFooterContainer.refresh();
mAH[AdapterHolder.WORK].setupOverlay();
mAH[AdapterHolder.WORK].applyPadding();
}
/**
@@ -311,6 +328,7 @@ public class AllAppsContainerView extends SpringRelativeLayout implements DragSo
mAH[i].padding.bottom = insets.bottom;
mAH[i].padding.left = mAH[i].padding.right = leftRightPadding;
mAH[i].applyPadding();
mAH[i].setupOverlay();
}
ViewGroup.MarginLayoutParams mlp = (MarginLayoutParams) getLayoutParams();
@@ -368,12 +386,17 @@ public class AllAppsContainerView extends SpringRelativeLayout implements DragSo
mAllAppsStore.unregisterIconContainer(mAH[AdapterHolder.WORK].recyclerView);
if (mUsingTabs) {
setupWorkToggle();
mAH[AdapterHolder.MAIN].setup(mViewPager.getChildAt(0), mPersonalMatcher);
mAH[AdapterHolder.WORK].setup(mViewPager.getChildAt(1), mWorkMatcher);
onTabChanged(mViewPager.getNextPage());
} else {
mAH[AdapterHolder.MAIN].setup(findViewById(R.id.apps_list_view), null);
mAH[AdapterHolder.WORK].recyclerView = null;
if (mWorkFooterContainer != null) {
((ViewGroup) mWorkFooterContainer.getParent()).removeView(mWorkFooterContainer);
mWorkFooterContainer = null;
}
}
setupHeader();
@@ -381,6 +404,16 @@ public class AllAppsContainerView extends SpringRelativeLayout implements DragSo
mAllAppsStore.registerIconContainer(mAH[AdapterHolder.WORK].recyclerView);
}
private void setupWorkToggle() {
mWorkFooterContainer = (WorkFooterContainer) mLauncher.getLayoutInflater().inflate(
R.layout.work_tab_footer, findViewById(R.id.work_toggle_container));
mWorkFooterContainer.setLayoutParams(
new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
ViewGroup.LayoutParams.WRAP_CONTENT));
this.addView(mWorkFooterContainer);
mWorkFooterContainer.post(() -> mAH[AdapterHolder.WORK].applyPadding());
}
private void replaceRVContainer(boolean showTabs) {
for (int i = 0; i < mAH.length; i++) {
if (mAH[i].recyclerView != null) {
@@ -417,6 +450,9 @@ public class AllAppsContainerView extends SpringRelativeLayout implements DragSo
findViewById(R.id.tab_work)
.setOnClickListener((View view) -> mViewPager.snapToPage(AdapterHolder.WORK));
}
if (mWorkFooterContainer != null) {
mWorkFooterContainer.setWorkTabVisible(pos == AdapterHolder.WORK);
}
}
// Used by tests only
@@ -562,6 +598,7 @@ public class AllAppsContainerView extends SpringRelativeLayout implements DragSo
public static final int MAIN = 0;
public static final int WORK = 1;
private final boolean mIsWork;
public final AllAppsGridAdapter adapter;
final LinearLayoutManager layoutManager;
final AlphabeticalAppsList appsList;
@@ -569,7 +606,10 @@ public class AllAppsContainerView extends SpringRelativeLayout implements DragSo
AllAppsRecyclerView recyclerView;
boolean verticalFadingEdge;
boolean mWorkDisabled;
AdapterHolder(boolean isWork) {
mIsWork = isWork;
appsList = new AlphabeticalAppsList(mLauncher, mAllAppsStore, isWork);
adapter = new AllAppsGridAdapter(mLauncher, appsList);
appsList.setAdapter(adapter);
@@ -591,11 +631,36 @@ public class AllAppsContainerView extends SpringRelativeLayout implements DragSo
adapter.setIconFocusListener(focusedItemDecorator.getFocusListener());
applyVerticalFadingEdgeEnabled(verticalFadingEdge);
applyPadding();
setupOverlay();
}
void setupOverlay() {
if (!mIsWork || recyclerView == null) return;
boolean workDisabled = UserCache.INSTANCE.get(mLauncher).isAnyProfileQuietModeEnabled();
recyclerView.getOverlay().clear();
if (workDisabled) {
View pausedOverlay = mLauncher.getLayoutInflater().inflate(
R.layout.work_apps_paused, null);
recyclerView.post(() -> {
int width = recyclerView.getWidth();
int height = recyclerView.getHeight();
pausedOverlay.measure(makeMeasureSpec(width, EXACTLY),
makeMeasureSpec(height, EXACTLY));
pausedOverlay.layout(0, 0, width, height);
applyPadding();
});
recyclerView.getOverlay().add(pausedOverlay);
}
mWorkDisabled = workDisabled;
}
void applyPadding() {
if (recyclerView != null) {
recyclerView.setPadding(padding.left, padding.top, padding.right, padding.bottom);
int bottomOffset =
mWorkFooterContainer != null && mIsWork ? mWorkFooterContainer.getHeight()
: 0;
recyclerView.setPadding(padding.left, padding.top, padding.right,
padding.bottom + bottomOffset);
}
}