Extend/shrink work button when scrolling

most of the change was from this CL: ag/19223926
moved scroll listener definition to WorkProfileManager.java
Added feature flag

bug: 194188980
test: Video - https://drive.google.com/file/d/18UM7UDNQz-Z8Q2Sh8VEKHm9LXRVJaWFM/view?usp=sharing
Change-Id: Ib80784e0f5108b28658141ca5e495a27fab34a3c
This commit is contained in:
Brandon Dayauon
2022-11-21 16:30:28 -08:00
parent dcafe99d42
commit c9672b9002
6 changed files with 152 additions and 77 deletions
@@ -17,6 +17,10 @@ package com.android.launcher3.allapps;
import static com.android.launcher3.allapps.BaseAllAppsAdapter.VIEW_TYPE_WORK_DISABLED_CARD;
import static com.android.launcher3.allapps.BaseAllAppsAdapter.VIEW_TYPE_WORK_EDU_CARD;
import static com.android.launcher3.allapps.BaseAllAppsContainerView.AdapterHolder.MAIN;
import static com.android.launcher3.allapps.BaseAllAppsContainerView.AdapterHolder.SEARCH;
import static com.android.launcher3.allapps.BaseAllAppsContainerView.AdapterHolder.WORK;
import static com.android.launcher3.logging.StatsLogManager.LauncherEvent.LAUNCHER_TURN_OFF_WORK_APPS_TAP;
import static com.android.launcher3.model.BgDataModel.Callbacks.FLAG_HAS_SHORTCUT_PERMISSION;
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;
@@ -28,14 +32,19 @@ import android.os.Process;
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.R;
import com.android.launcher3.Utilities;
import com.android.launcher3.allapps.BaseAllAppsAdapter.AdapterItem;
import com.android.launcher3.model.data.ItemInfo;
import com.android.launcher3.views.ActivityContext;
import com.android.launcher3.workprofile.PersonalWorkSlidingTabStrip;
import java.lang.annotation.Retention;
@@ -104,8 +113,16 @@ public class WorkProfileManager implements PersonalWorkSlidingTabStrip.OnActiveP
@Override
public void onActivePageChanged(int page) {
updateWorkFAB(page);
}
private void updateWorkFAB(int page) {
if (mWorkModeSwitch != null) {
mWorkModeSwitch.onActivePageChanged(page);
if (page == MAIN || page == SEARCH) {
mWorkModeSwitch.animateVisibility(false);
} else if (page == WORK && mCurrentState == STATE_ENABLED) {
mWorkModeSwitch.animateVisibility(true);
}
}
}
@@ -123,7 +140,12 @@ public class WorkProfileManager implements PersonalWorkSlidingTabStrip.OnActiveP
getAH().mAppsList.updateAdapterItems();
}
if (mWorkModeSwitch != null) {
mWorkModeSwitch.updateCurrentState(currentState == STATE_ENABLED);
updateWorkFAB(mAllApps.getCurrentPage());
}
if (mCurrentState == STATE_ENABLED) {
attachWorkModeSwitch();
} else if (mCurrentState == STATE_DISABLED) {
detachWorkModeSwitch();
}
}
@@ -140,13 +162,16 @@ public class WorkProfileManager implements PersonalWorkSlidingTabStrip.OnActiveP
mWorkModeSwitch = (WorkModeSwitch) mAllApps.getLayoutInflater().inflate(
R.layout.work_mode_fab, mAllApps, false);
}
if (mWorkModeSwitch.getParent() != mAllApps) {
if (mWorkModeSwitch.getParent() == null) {
mAllApps.addView(mWorkModeSwitch);
}
if (mAllApps.getCurrentPage() != WORK) {
mWorkModeSwitch.animateVisibility(false);
}
if (getAH() != null) {
getAH().applyPadding();
}
mWorkModeSwitch.updateCurrentState(mCurrentState == STATE_ENABLED);
mWorkModeSwitch.setOnClickListener(this::onWorkFabClicked);
return true;
}
/**
@@ -169,7 +194,7 @@ public class WorkProfileManager implements PersonalWorkSlidingTabStrip.OnActiveP
}
private BaseAllAppsContainerView<?>.AdapterHolder getAH() {
return mAllApps.mAH.get(BaseAllAppsContainerView.AdapterHolder.WORK);
return mAllApps.mAH.get(WORK);
}
public int getCurrentState() {
@@ -199,4 +224,40 @@ public class WorkProfileManager implements PersonalWorkSlidingTabStrip.OnActiveP
private boolean isEduSeen() {
return mPreferences.getInt(KEY_WORK_EDU_STEP, 0) != 0;
}
private void onWorkFabClicked(View view) {
if (Utilities.ATLEAST_P && mCurrentState == STATE_ENABLED && mWorkModeSwitch.isEnabled()) {
ActivityContext activityContext = ActivityContext.lookupContext(
mWorkModeSwitch.getContext());
activityContext.getStatsLogManager().logger().log(LAUNCHER_TURN_OFF_WORK_APPS_TAP);
setWorkProfileEnabled(false);
}
}
public RecyclerView.OnScrollListener newScrollListener() {
return new RecyclerView.OnScrollListener() {
int totalDelta = 0;
@Override
public void onScrollStateChanged(@NonNull RecyclerView recyclerView, int newState){
if (newState == RecyclerView.SCROLL_STATE_IDLE) {
totalDelta = 0;
}
}
@Override
public void onScrolled(@NonNull RecyclerView recyclerView, int dx, int dy) {
WorkModeSwitch fab = getWorkModeSwitch();
if (fab == null){
return;
}
totalDelta = Utilities.boundToRange(totalDelta,
-fab.getScrollThreshold(), fab.getScrollThreshold()) + dy;
boolean isScrollAtTop = recyclerView.computeVerticalScrollOffset() == 0;
if ((isScrollAtTop || totalDelta < -fab.getScrollThreshold())) {
fab.extend();
} else if (totalDelta > fab.getScrollThreshold()) {
fab.shrink();
}
}
};
}
}