mirror of
https://github.com/LawnchairLauncher/lawnchair.git
synced 2026-03-01 08:16:49 +00:00
Space out 3 button nav on taskbar
* Add additional margin on nav buttons if there's overlap w/ contextual button * End spacing is dependent on grid layout Bug: 223724516 Test: Tested on unfolded with different grid sizes. Change-Id: Ie814f35cd1f35629744050ee3f7242c5a8599883
This commit is contained in:
@@ -46,6 +46,7 @@ import android.annotation.LayoutRes;
|
||||
import android.content.pm.ActivityInfo.Config;
|
||||
import android.content.res.ColorStateList;
|
||||
import android.content.res.Configuration;
|
||||
import android.content.res.Resources;
|
||||
import android.graphics.Color;
|
||||
import android.graphics.Rect;
|
||||
import android.graphics.Region;
|
||||
@@ -67,6 +68,7 @@ import android.widget.FrameLayout;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.LinearLayout;
|
||||
|
||||
import com.android.launcher3.DeviceProfile;
|
||||
import com.android.launcher3.LauncherAnimUtils;
|
||||
import com.android.launcher3.R;
|
||||
import com.android.launcher3.Utilities;
|
||||
@@ -94,7 +96,7 @@ public class NavbarButtonsViewController implements TaskbarControllers.LoggableT
|
||||
|
||||
private final Rect mTempRect = new Rect();
|
||||
|
||||
private static final int FLAG_SWITCHER_SUPPORTED = 1 << 0;
|
||||
private static final int FLAG_SWITCHER_SHOWING = 1 << 0;
|
||||
private static final int FLAG_IME_VISIBLE = 1 << 1;
|
||||
private static final int FLAG_ROTATION_BUTTON_VISIBLE = 1 << 2;
|
||||
private static final int FLAG_A11Y_VISIBLE = 1 << 3;
|
||||
@@ -189,7 +191,7 @@ public class NavbarButtonsViewController implements TaskbarControllers.LoggableT
|
||||
isThreeButtonNav ? mStartContextualContainer : mEndContextualContainer,
|
||||
mControllers.navButtonController, R.id.ime_switcher);
|
||||
mPropertyHolders.add(new StatePropertyHolder(imeSwitcherButton,
|
||||
flags -> ((flags & FLAG_SWITCHER_SUPPORTED) != 0)
|
||||
flags -> ((flags & FLAG_SWITCHER_SHOWING) != 0)
|
||||
&& ((flags & FLAG_ROTATION_BUTTON_VISIBLE) == 0)));
|
||||
}
|
||||
|
||||
@@ -228,6 +230,7 @@ public class NavbarButtonsViewController implements TaskbarControllers.LoggableT
|
||||
if (alwaysShowButtons) {
|
||||
initButtons(mNavButtonContainer, mEndContextualContainer,
|
||||
mControllers.navButtonController);
|
||||
updateButtonLayoutSpacing();
|
||||
|
||||
if (isInSetup) {
|
||||
// Since setup wizard only has back button enabled, it looks strange to be
|
||||
@@ -451,7 +454,7 @@ public class NavbarButtonsViewController implements TaskbarControllers.LoggableT
|
||||
|
||||
// TODO(b/202218289) we're getting IME as not visible on lockscreen from system
|
||||
updateStateForFlag(FLAG_IME_VISIBLE, isImeVisible);
|
||||
updateStateForFlag(FLAG_SWITCHER_SUPPORTED, isImeSwitcherShowing);
|
||||
updateStateForFlag(FLAG_SWITCHER_SHOWING, isImeSwitcherShowing);
|
||||
updateStateForFlag(FLAG_A11Y_VISIBLE, a11yVisible);
|
||||
updateStateForFlag(FLAG_DISABLE_HOME, isHomeDisabled);
|
||||
updateStateForFlag(FLAG_DISABLE_RECENTS, isRecentsDisabled);
|
||||
@@ -465,6 +468,7 @@ public class NavbarButtonsViewController implements TaskbarControllers.LoggableT
|
||||
boolean a11yLongClickable =
|
||||
(sysUiStateFlags & SYSUI_STATE_A11Y_BUTTON_LONG_CLICKABLE) != 0;
|
||||
mA11yButton.setLongClickable(a11yLongClickable);
|
||||
updateButtonLayoutSpacing();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -479,6 +483,13 @@ public class NavbarButtonsViewController implements TaskbarControllers.LoggableT
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return {@code true} if A11y is showing in 3 button nav taskbar
|
||||
*/
|
||||
private boolean isContextualButtonShowing() {
|
||||
return mContext.isThreeButtonNav() && (mState & FLAG_A11Y_VISIBLE) != 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Should be called when we need to show back button for bouncer
|
||||
*/
|
||||
@@ -508,7 +519,7 @@ public class NavbarButtonsViewController implements TaskbarControllers.LoggableT
|
||||
* Returns true if IME switcher is visible
|
||||
*/
|
||||
public boolean isImeSwitcherVisible() {
|
||||
return (mState & FLAG_SWITCHER_SUPPORTED) != 0;
|
||||
return (mState & FLAG_SWITCHER_SHOWING) != 0;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -662,6 +673,46 @@ public class NavbarButtonsViewController implements TaskbarControllers.LoggableT
|
||||
if (mFloatingRotationButton != null) {
|
||||
mFloatingRotationButton.onConfigurationChanged(configChanges);
|
||||
}
|
||||
updateButtonLayoutSpacing();
|
||||
}
|
||||
|
||||
/** Adds the correct spacing to 3 button nav container. No-op if using gesture nav */
|
||||
private void updateButtonLayoutSpacing() {
|
||||
if (!mContext.isThreeButtonNav()) {
|
||||
return;
|
||||
}
|
||||
DeviceProfile dp = mContext.getDeviceProfile();
|
||||
Resources res = mContext.getResources();
|
||||
|
||||
// Add spacing after the end of the last nav button
|
||||
FrameLayout.LayoutParams navButtonParams =
|
||||
(FrameLayout.LayoutParams) mNavButtonContainer.getLayoutParams();
|
||||
int navMarginEnd = (int) res.getDimension(dp.inv.inlineNavButtonsEndSpacing);
|
||||
int contextualWidth = mEndContextualContainer.getWidth();
|
||||
// If contextual buttons are showing, we check if the end margin is enough for the
|
||||
// contextual button to be showing - if not, move the nav buttons over a smidge
|
||||
if (isContextualButtonShowing() && navMarginEnd < contextualWidth) {
|
||||
// Additional spacing, eat up half of space between last icon and nav button
|
||||
navMarginEnd += res.getDimensionPixelSize(R.dimen.taskbar_hotseat_nav_spacing) / 2;
|
||||
}
|
||||
navButtonParams.setMarginEnd(navMarginEnd);
|
||||
mNavButtonContainer.setLayoutParams(navButtonParams);
|
||||
|
||||
// Add the spaces in between the nav buttons
|
||||
int spaceInBetween = res.getDimensionPixelSize(R.dimen.taskbar_button_space_inbetween);
|
||||
for (int i = 0; i < mNavButtonContainer.getChildCount(); i++) {
|
||||
View navButton = mNavButtonContainer.getChildAt(i);
|
||||
LinearLayout.LayoutParams buttonLayoutParams =
|
||||
(LinearLayout.LayoutParams) navButton.getLayoutParams();
|
||||
if (i == 0) {
|
||||
buttonLayoutParams.setMarginEnd(spaceInBetween / 2);
|
||||
} else if (i == mNavButtonContainer.getChildCount() - 1) {
|
||||
buttonLayoutParams.setMarginStart(spaceInBetween / 2);
|
||||
} else {
|
||||
buttonLayoutParams.setMarginStart(spaceInBetween / 2);
|
||||
buttonLayoutParams.setMarginEnd(spaceInBetween / 2);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void onDestroy() {
|
||||
@@ -749,7 +800,7 @@ public class NavbarButtonsViewController implements TaskbarControllers.LoggableT
|
||||
|
||||
private static String getStateString(int flags) {
|
||||
StringJoiner str = new StringJoiner("|");
|
||||
appendFlag(str, flags, FLAG_SWITCHER_SUPPORTED, "FLAG_SWITCHER_SUPPORTED");
|
||||
appendFlag(str, flags, FLAG_SWITCHER_SHOWING, "FLAG_SWITCHER_SHOWING");
|
||||
appendFlag(str, flags, FLAG_IME_VISIBLE, "FLAG_IME_VISIBLE");
|
||||
appendFlag(str, flags, FLAG_ROTATION_BUTTON_VISIBLE, "FLAG_ROTATION_BUTTON_VISIBLE");
|
||||
appendFlag(str, flags, FLAG_A11Y_VISIBLE, "FLAG_A11Y_VISIBLE");
|
||||
|
||||
Reference in New Issue
Block a user