summaryrefslogtreecommitdiff
path: root/src/com/android/launcher3/allapps/WorkModeSwitch.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/com/android/launcher3/allapps/WorkModeSwitch.java')
-rw-r--r--src/com/android/launcher3/allapps/WorkModeSwitch.java41
1 files changed, 34 insertions, 7 deletions
diff --git a/src/com/android/launcher3/allapps/WorkModeSwitch.java b/src/com/android/launcher3/allapps/WorkModeSwitch.java
index 733577eabf..edb012854a 100644
--- a/src/com/android/launcher3/allapps/WorkModeSwitch.java
+++ b/src/com/android/launcher3/allapps/WorkModeSwitch.java
@@ -16,20 +16,23 @@
package com.android.launcher3.allapps;
import static com.android.launcher3.logging.StatsLogManager.LauncherEvent.LAUNCHER_TURN_OFF_WORK_APPS_TAP;
+import static com.android.launcher3.workprofile.PersonalWorkSlidingTabStrip.getTabWidth;
import android.content.Context;
import android.graphics.Insets;
import android.graphics.Rect;
import android.util.AttributeSet;
import android.view.View;
-import android.view.ViewGroup;
+import android.view.ViewGroup.MarginLayoutParams;
import android.view.WindowInsets;
import android.widget.Button;
import com.android.launcher3.DeviceProfile;
import com.android.launcher3.Insettable;
+import com.android.launcher3.R;
import com.android.launcher3.Utilities;
import com.android.launcher3.anim.KeyboardInsetAnimationCallback;
+import com.android.launcher3.config.FeatureFlags;
import com.android.launcher3.model.StringCache;
import com.android.launcher3.views.ActivityContext;
import com.android.launcher3.workprofile.PersonalWorkSlidingTabStrip;
@@ -50,7 +53,6 @@ public class WorkModeSwitch extends Button implements Insettable, View.OnClickLi
private boolean mWorkEnabled;
private boolean mOnWorkTab;
-
public WorkModeSwitch(Context context) {
this(context, null, 0);
}
@@ -85,15 +87,40 @@ public class WorkModeSwitch extends Button implements Insettable, View.OnClickLi
@Override
public void setInsets(Rect insets) {
- int bottomInset = insets.bottom - mInsets.bottom;
mInsets.set(insets);
- ViewGroup.MarginLayoutParams marginLayoutParams =
- (ViewGroup.MarginLayoutParams) getLayoutParams();
- if (marginLayoutParams != null) {
- marginLayoutParams.bottomMargin = bottomInset + marginLayoutParams.bottomMargin;
+ MarginLayoutParams lp = (MarginLayoutParams) getLayoutParams();
+ if (lp != null) {
+ int bottomMargin = getResources().getDimensionPixelSize(R.dimen.work_fab_margin_bottom);
+ if (FeatureFlags.ENABLE_FLOATING_SEARCH_BAR.get()) {
+ bottomMargin <<= 1; // Double margin to add space above search bar.
+ bottomMargin += getResources().getDimensionPixelSize(R.dimen.qsb_widget_height);
+ }
+
+ DeviceProfile dp = ActivityContext.lookupContext(getContext()).getDeviceProfile();
+ lp.rightMargin = lp.leftMargin = dp.allAppsLeftRightPadding;
+ if (!dp.isGestureMode) {
+ if (dp.isTaskbarPresent) {
+ bottomMargin += dp.taskbarSize;
+ } else {
+ bottomMargin += insets.bottom;
+ }
+ }
+
+ lp.bottomMargin = bottomMargin;
}
}
+ @Override
+ protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
+ super.onLayout(changed, left, top, right, bottom);
+ DeviceProfile dp = ActivityContext.lookupContext(getContext()).getDeviceProfile();
+ View parent = (View) getParent();
+ int size = parent.getWidth() - parent.getPaddingLeft() - parent.getPaddingRight()
+ - 2 * dp.allAppsLeftRightPadding;
+ int tabWidth = getTabWidth(getContext(), size);
+ int shift = (size - tabWidth) / 2 + dp.allAppsLeftRightPadding;
+ setTranslationX(Utilities.isRtl(getResources()) ? shift : -shift);
+ }
@Override
public void onActivePageChanged(int page) {