mirror of
https://github.com/LawnchairLauncher/lawnchair.git
synced 2026-03-01 00:06:47 +00:00
Landscape 3 button nav on taskbar phone supported
* TODO: Seascape bar positioning, add tests Change-Id: I542be2f2f682d8c8a9cdd9bb6c667c44ca167f3e Merged-In: I542be2f2f682d8c8a9cdd9bb6c667c44ca167f3e
This commit is contained in:
@@ -23,7 +23,6 @@ import static com.android.launcher3.LauncherAnimUtils.VIEW_TRANSLATE_X;
|
||||
import static com.android.launcher3.Utilities.getDescendantCoordRelativeToAncestor;
|
||||
import static com.android.launcher3.taskbar.LauncherTaskbarUIController.SYSUI_SURFACE_PROGRESS_INDEX;
|
||||
import static com.android.launcher3.taskbar.TaskbarManager.isPhoneButtonNavMode;
|
||||
import static com.android.launcher3.taskbar.TaskbarManager.isPhoneMode;
|
||||
import static com.android.launcher3.taskbar.TaskbarNavButtonController.BUTTON_A11Y;
|
||||
import static com.android.launcher3.taskbar.TaskbarNavButtonController.BUTTON_BACK;
|
||||
import static com.android.launcher3.taskbar.TaskbarNavButtonController.BUTTON_HOME;
|
||||
@@ -54,6 +53,7 @@ import android.content.res.ColorStateList;
|
||||
import android.content.res.Configuration;
|
||||
import android.content.res.Resources;
|
||||
import android.graphics.Color;
|
||||
import android.graphics.Point;
|
||||
import android.graphics.Rect;
|
||||
import android.graphics.Region;
|
||||
import android.graphics.Region.Op;
|
||||
@@ -81,6 +81,9 @@ import com.android.launcher3.R;
|
||||
import com.android.launcher3.Utilities;
|
||||
import com.android.launcher3.anim.AlphaUpdateListener;
|
||||
import com.android.launcher3.taskbar.TaskbarNavButtonController.TaskbarButton;
|
||||
import com.android.launcher3.taskbar.navbutton.NavButtonLayoutFactory;
|
||||
import com.android.launcher3.taskbar.navbutton.NavButtonLayoutFactory.NavButtonLayoutter;
|
||||
import com.android.launcher3.util.DimensionUtils;
|
||||
import com.android.launcher3.util.MultiValueAlpha;
|
||||
import com.android.launcher3.util.TouchController;
|
||||
import com.android.launcher3.views.BaseDragLayer;
|
||||
@@ -181,6 +184,7 @@ public class NavbarButtonsViewController implements TaskbarControllers.LoggableT
|
||||
private final ViewTreeObserver.OnComputeInternalInsetsListener mSeparateWindowInsetsComputer =
|
||||
this::onComputeInsetsForSeparateWindow;
|
||||
private final RecentsHitboxExtender mHitboxExtender = new RecentsHitboxExtender();
|
||||
private View mRecentsButton;
|
||||
|
||||
public NavbarButtonsViewController(TaskbarActivityContext context, FrameLayout navButtonsView) {
|
||||
mContext = context;
|
||||
@@ -203,11 +207,11 @@ public class NavbarButtonsViewController implements TaskbarControllers.LoggableT
|
||||
boolean isThreeButtonNav = mContext.isThreeButtonNav();
|
||||
DeviceProfile deviceProfile = mContext.getDeviceProfile();
|
||||
Resources resources = mContext.getResources();
|
||||
mNavButtonsView.getLayoutParams().height = !isPhoneMode(deviceProfile) ?
|
||||
mContext.isUserSetupComplete()
|
||||
? deviceProfile.taskbarSize
|
||||
: resources.getDimensionPixelSize(R.dimen.taskbar_suw_frame)
|
||||
: resources.getDimensionPixelSize(R.dimen.taskbar_size);
|
||||
Point p = !mContext.isUserSetupComplete()
|
||||
? new Point(0, resources.getDimensionPixelSize(R.dimen.taskbar_suw_frame))
|
||||
: DimensionUtils.getTaskbarPhoneDimensions(deviceProfile, resources,
|
||||
TaskbarManager.isPhoneMode(deviceProfile));
|
||||
mNavButtonsView.getLayoutParams().height = p.y;
|
||||
|
||||
mIsImeRenderingNavButtons =
|
||||
InputMethodService.canImeRenderGesturalNavButtons() && mContext.imeDrawsImeNavBar();
|
||||
@@ -268,81 +272,6 @@ public class NavbarButtonsViewController implements TaskbarControllers.LoggableT
|
||||
mControllers.navButtonController);
|
||||
updateButtonLayoutSpacing();
|
||||
updateStateForFlag(FLAG_SMALL_SCREEN, isPhoneButtonNavMode(mContext));
|
||||
if (isInSetup) {
|
||||
handleSetupUi();
|
||||
|
||||
// Hide back button in SUW if keyboard is showing (IME draws its own back).
|
||||
mPropertyHolders.add(new StatePropertyHolder(
|
||||
mBackButtonAlpha.getProperty(ALPHA_INDEX_SUW),
|
||||
flags -> (flags & FLAG_IME_VISIBLE) == 0));
|
||||
|
||||
// TODO(b/210906568) Dark intensity is currently not propagated during setup, so set
|
||||
// it based on dark theme for now.
|
||||
int mode = resources.getConfiguration().uiMode
|
||||
& Configuration.UI_MODE_NIGHT_MASK;
|
||||
boolean isDarkTheme = mode == Configuration.UI_MODE_NIGHT_YES;
|
||||
mTaskbarNavButtonDarkIntensity.updateValue(isDarkTheme ? 0 : 1);
|
||||
} else if (isInKidsMode) {
|
||||
int iconSize = resources.getDimensionPixelSize(
|
||||
R.dimen.taskbar_icon_size_kids);
|
||||
int buttonWidth = resources.getDimensionPixelSize(
|
||||
R.dimen.taskbar_nav_buttons_width_kids);
|
||||
int buttonHeight = resources.getDimensionPixelSize(
|
||||
R.dimen.taskbar_nav_buttons_height_kids);
|
||||
int buttonRadius = resources.getDimensionPixelSize(
|
||||
R.dimen.taskbar_nav_buttons_corner_radius_kids);
|
||||
int paddingleft = (buttonWidth - iconSize) / 2;
|
||||
int paddingRight = paddingleft;
|
||||
int paddingTop = (buttonHeight - iconSize) / 2;
|
||||
int paddingBottom = paddingTop;
|
||||
|
||||
// Update icons
|
||||
((ImageView) mBackButton).setImageDrawable(
|
||||
mBackButton.getContext().getDrawable(R.drawable.ic_sysbar_back_kids));
|
||||
((ImageView) mBackButton).setScaleType(ImageView.ScaleType.FIT_CENTER);
|
||||
mBackButton.setPadding(paddingleft, paddingTop, paddingRight, paddingBottom);
|
||||
((ImageView) mHomeButton).setImageDrawable(
|
||||
mHomeButton.getContext().getDrawable(R.drawable.ic_sysbar_home_kids));
|
||||
((ImageView) mHomeButton).setScaleType(ImageView.ScaleType.FIT_CENTER);
|
||||
mHomeButton.setPadding(paddingleft, paddingTop, paddingRight, paddingBottom);
|
||||
|
||||
// Home button layout
|
||||
LinearLayout.LayoutParams homeLayoutparams = new LinearLayout.LayoutParams(
|
||||
buttonWidth,
|
||||
buttonHeight
|
||||
);
|
||||
int homeButtonLeftMargin = resources.getDimensionPixelSize(
|
||||
R.dimen.taskbar_home_button_left_margin_kids);
|
||||
homeLayoutparams.setMargins(homeButtonLeftMargin, 0, 0, 0);
|
||||
mHomeButton.setLayoutParams(homeLayoutparams);
|
||||
|
||||
// Back button layout
|
||||
LinearLayout.LayoutParams backLayoutParams = new LinearLayout.LayoutParams(
|
||||
buttonWidth,
|
||||
buttonHeight
|
||||
);
|
||||
int backButtonLeftMargin = resources.getDimensionPixelSize(
|
||||
R.dimen.taskbar_back_button_left_margin_kids);
|
||||
backLayoutParams.setMargins(backButtonLeftMargin, 0, 0, 0);
|
||||
mBackButton.setLayoutParams(backLayoutParams);
|
||||
|
||||
// Button backgrounds
|
||||
int whiteWith10PctAlpha = Color.argb(0.1f, 1, 1, 1);
|
||||
PaintDrawable buttonBackground = new PaintDrawable(whiteWith10PctAlpha);
|
||||
buttonBackground.setCornerRadius(buttonRadius);
|
||||
mHomeButton.setBackground(buttonBackground);
|
||||
mBackButton.setBackground(buttonBackground);
|
||||
|
||||
// Update alignment within taskbar
|
||||
FrameLayout.LayoutParams navButtonsLayoutParams = (FrameLayout.LayoutParams)
|
||||
mNavButtonContainer.getLayoutParams();
|
||||
navButtonsLayoutParams.setMarginStart(navButtonsLayoutParams.getMarginEnd() / 2);
|
||||
navButtonsLayoutParams.setMarginEnd(navButtonsLayoutParams.getMarginStart());
|
||||
navButtonsLayoutParams.gravity = Gravity.CENTER;
|
||||
mNavButtonContainer.requestLayout();
|
||||
|
||||
mHomeButton.setOnLongClickListener(null);
|
||||
}
|
||||
|
||||
// Animate taskbar background when either..
|
||||
// notification shade expanded AND not on keyguard
|
||||
@@ -445,20 +374,20 @@ public class NavbarButtonsViewController implements TaskbarControllers.LoggableT
|
||||
(flags & FLAG_DISABLE_HOME) == 0));
|
||||
|
||||
// Recents button
|
||||
View recentsButton = addButton(R.drawable.ic_sysbar_recent, BUTTON_RECENTS,
|
||||
mRecentsButton = addButton(R.drawable.ic_sysbar_recent, BUTTON_RECENTS,
|
||||
navContainer, navButtonController, R.id.recent_apps);
|
||||
mHitboxExtender.init(recentsButton, mNavButtonsView, mContext.getDeviceProfile(),
|
||||
mHitboxExtender.init(mRecentsButton, mNavButtonsView, mContext.getDeviceProfile(),
|
||||
() -> {
|
||||
float[] recentsCoords = new float[2];
|
||||
getDescendantCoordRelativeToAncestor(recentsButton, mNavButtonsView,
|
||||
getDescendantCoordRelativeToAncestor(mRecentsButton, mNavButtonsView,
|
||||
recentsCoords, false);
|
||||
return recentsCoords;
|
||||
}, new Handler());
|
||||
recentsButton.setOnClickListener(v -> {
|
||||
mRecentsButton.setOnClickListener(v -> {
|
||||
navButtonController.onButtonClick(BUTTON_RECENTS, v);
|
||||
mHitboxExtender.onRecentsButtonClicked();
|
||||
});
|
||||
mPropertyHolders.add(new StatePropertyHolder(recentsButton,
|
||||
mPropertyHolders.add(new StatePropertyHolder(mRecentsButton,
|
||||
flags -> (flags & FLAG_KEYGUARD_VISIBLE) == 0 && (flags & FLAG_DISABLE_RECENTS) == 0
|
||||
&& !mContext.isNavBarKidsModeActive()));
|
||||
|
||||
@@ -773,14 +702,22 @@ public class NavbarButtonsViewController implements TaskbarControllers.LoggableT
|
||||
|| !mContext.isUserSetupComplete()) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (isPhoneButtonNavMode(mContext)) {
|
||||
updatePhoneButtonSpacing();
|
||||
return;
|
||||
}
|
||||
|
||||
DeviceProfile dp = mContext.getDeviceProfile();
|
||||
Resources res = mContext.getResources();
|
||||
boolean isInSetup = !mContext.isUserSetupComplete();
|
||||
// TODO(b/244231596) we're getting the incorrect kidsMode value in small-screen
|
||||
boolean isInKidsMode = mContext.isNavBarKidsModeActive();
|
||||
|
||||
if (TaskbarManager.FLAG_HIDE_NAVBAR_WINDOW) {
|
||||
boolean isThreeButtonNav = mContext.isThreeButtonNav();
|
||||
|
||||
NavButtonLayoutter navButtonLayoutter =
|
||||
NavButtonLayoutFactory.Companion.getUiLayoutter(
|
||||
dp, mNavButtonsView, res, isInKidsMode, isInSetup, isThreeButtonNav,
|
||||
TaskbarManager.isPhoneMode(dp));
|
||||
navButtonLayoutter.layoutButtons(dp, isContextualButtonShowing());
|
||||
return;
|
||||
}
|
||||
|
||||
// Add spacing after the end of the last nav button
|
||||
FrameLayout.LayoutParams navButtonParams =
|
||||
@@ -816,38 +753,84 @@ public class NavbarButtonsViewController implements TaskbarControllers.LoggableT
|
||||
buttonLayoutParams.setMarginEnd(spaceInBetween / 2);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/** Uniformly spaces out the 3 button nav for smaller phone screens */
|
||||
private void updatePhoneButtonSpacing() {
|
||||
DeviceProfile dp = mContext.getDeviceProfile();
|
||||
Resources res = mContext.getResources();
|
||||
if (isInSetup) {
|
||||
handleSetupUi();
|
||||
|
||||
// TODO: Polish pending, this is just to make it usable
|
||||
FrameLayout.LayoutParams navContainerParams =
|
||||
(FrameLayout.LayoutParams) mNavButtonContainer.getLayoutParams();
|
||||
int endStartMargins = res.getDimensionPixelSize(R.dimen.taskbar_nav_buttons_size);
|
||||
navContainerParams.gravity = Gravity.CENTER;
|
||||
navContainerParams.setMarginEnd(endStartMargins);
|
||||
navContainerParams.setMarginStart(endStartMargins);
|
||||
mNavButtonContainer.setLayoutParams(navContainerParams);
|
||||
// Hide back button in SUW if keyboard is showing (IME draws its own back).
|
||||
mPropertyHolders.add(new StatePropertyHolder(
|
||||
mBackButtonAlpha.getProperty(ALPHA_INDEX_SUW),
|
||||
flags -> (flags & FLAG_IME_VISIBLE) == 0));
|
||||
|
||||
// Add the spaces in between the nav buttons
|
||||
int spaceInBetween = res.getDimensionPixelSize(R.dimen.taskbar_button_space_inbetween_phone);
|
||||
for (int i = 0; i < mNavButtonContainer.getChildCount(); i++) {
|
||||
View navButton = mNavButtonContainer.getChildAt(i);
|
||||
LinearLayout.LayoutParams buttonLayoutParams =
|
||||
(LinearLayout.LayoutParams) navButton.getLayoutParams();
|
||||
buttonLayoutParams.weight = 1;
|
||||
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);
|
||||
}
|
||||
// TODO(b/210906568) Dark intensity is currently not propagated during setup, so set
|
||||
// it based on dark theme for now.
|
||||
int mode = res.getConfiguration().uiMode
|
||||
& Configuration.UI_MODE_NIGHT_MASK;
|
||||
boolean isDarkTheme = mode == Configuration.UI_MODE_NIGHT_YES;
|
||||
mTaskbarNavButtonDarkIntensity.updateValue(isDarkTheme ? 0 : 1);
|
||||
} else if (isInKidsMode) {
|
||||
int iconSize = res.getDimensionPixelSize(
|
||||
R.dimen.taskbar_icon_size_kids);
|
||||
int buttonWidth = res.getDimensionPixelSize(
|
||||
R.dimen.taskbar_nav_buttons_width_kids);
|
||||
int buttonHeight = res.getDimensionPixelSize(
|
||||
R.dimen.taskbar_nav_buttons_height_kids);
|
||||
int buttonRadius = res.getDimensionPixelSize(
|
||||
R.dimen.taskbar_nav_buttons_corner_radius_kids);
|
||||
int paddingleft = (buttonWidth - iconSize) / 2;
|
||||
int paddingRight = paddingleft;
|
||||
int paddingTop = (buttonHeight - iconSize) / 2;
|
||||
int paddingBottom = paddingTop;
|
||||
|
||||
// Update icons
|
||||
((ImageView) mBackButton).setImageDrawable(
|
||||
mBackButton.getContext().getDrawable(R.drawable.ic_sysbar_back_kids));
|
||||
((ImageView) mBackButton).setScaleType(ImageView.ScaleType.FIT_CENTER);
|
||||
mBackButton.setPadding(paddingleft, paddingTop, paddingRight, paddingBottom);
|
||||
((ImageView) mHomeButton).setImageDrawable(
|
||||
mHomeButton.getContext().getDrawable(R.drawable.ic_sysbar_home_kids));
|
||||
((ImageView) mHomeButton).setScaleType(ImageView.ScaleType.FIT_CENTER);
|
||||
mHomeButton.setPadding(paddingleft, paddingTop, paddingRight, paddingBottom);
|
||||
|
||||
// Home button layout
|
||||
LinearLayout.LayoutParams homeLayoutparams = new LinearLayout.LayoutParams(
|
||||
buttonWidth,
|
||||
buttonHeight
|
||||
);
|
||||
int homeButtonLeftMargin = res.getDimensionPixelSize(
|
||||
R.dimen.taskbar_home_button_left_margin_kids);
|
||||
homeLayoutparams.setMargins(homeButtonLeftMargin, 0, 0, 0);
|
||||
mHomeButton.setLayoutParams(homeLayoutparams);
|
||||
|
||||
// Back button layout
|
||||
LinearLayout.LayoutParams backLayoutParams = new LinearLayout.LayoutParams(
|
||||
buttonWidth,
|
||||
buttonHeight
|
||||
);
|
||||
int backButtonLeftMargin = res.getDimensionPixelSize(
|
||||
R.dimen.taskbar_back_button_left_margin_kids);
|
||||
backLayoutParams.setMargins(backButtonLeftMargin, 0, 0, 0);
|
||||
mBackButton.setLayoutParams(backLayoutParams);
|
||||
|
||||
// Button backgrounds
|
||||
int whiteWith10PctAlpha = Color.argb(0.1f, 1, 1, 1);
|
||||
PaintDrawable buttonBackground = new PaintDrawable(whiteWith10PctAlpha);
|
||||
buttonBackground.setCornerRadius(buttonRadius);
|
||||
mHomeButton.setBackground(buttonBackground);
|
||||
mBackButton.setBackground(buttonBackground);
|
||||
|
||||
// Update alignment within taskbar
|
||||
FrameLayout.LayoutParams navButtonsLayoutParams = (FrameLayout.LayoutParams)
|
||||
mNavButtonContainer.getLayoutParams();
|
||||
navButtonsLayoutParams.setMarginStart(
|
||||
navButtonsLayoutParams.getMarginEnd() / 2);
|
||||
navButtonsLayoutParams.setMarginEnd(navButtonsLayoutParams.getMarginStart());
|
||||
navButtonsLayoutParams.gravity = Gravity.CENTER;
|
||||
mNavButtonContainer.requestLayout();
|
||||
|
||||
mHomeButton.setOnLongClickListener(null);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void onDestroy() {
|
||||
@@ -859,6 +842,8 @@ public class NavbarButtonsViewController implements TaskbarControllers.LoggableT
|
||||
|
||||
moveNavButtonsBackToTaskbarWindow();
|
||||
mNavButtonContainer.removeAllViews();
|
||||
mEndContextualContainer.removeAllViews();
|
||||
mStartContextualContainer.removeAllViews();
|
||||
mAllButtons.clear();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user