From b681ebe3d21f17a21e4302fe78d61604b471a6b6 Mon Sep 17 00:00:00 2001 From: Sunny Goyal Date: Mon, 30 Mar 2020 14:12:06 -0700 Subject: [PATCH] Fixing Search box placement in Launcher3 Bug: 152372445 Change-Id: Ifabcc73f33f18de48b737d3e325b14fba75d0d96 --- res/layout/search_container_all_apps.xml | 3 +-- .../search/AppsSearchContainerLayout.java | 20 +++++++++---------- .../launcher3/states/RotationHelper.java | 12 +++++++---- 3 files changed, 18 insertions(+), 17 deletions(-) diff --git a/res/layout/search_container_all_apps.xml b/res/layout/search_container_all_apps.xml index fd9cb60fc7..e1646ba43e 100644 --- a/res/layout/search_container_all_apps.xml +++ b/res/layout/search_container_all_apps.xml @@ -34,5 +34,4 @@ android:singleLine="true" android:textColor="?android:attr/textColorSecondary" android:textColorHint="@drawable/all_apps_search_hint" - android:textSize="16sp" - android:translationY="24dp" /> \ No newline at end of file + android:textSize="16sp" /> \ No newline at end of file diff --git a/src/com/android/launcher3/allapps/search/AppsSearchContainerLayout.java b/src/com/android/launcher3/allapps/search/AppsSearchContainerLayout.java index d497c3a502..9e3a862263 100644 --- a/src/com/android/launcher3/allapps/search/AppsSearchContainerLayout.java +++ b/src/com/android/launcher3/allapps/search/AppsSearchContainerLayout.java @@ -62,9 +62,8 @@ public class AppsSearchContainerLayout extends ExtendedEditText private AlphabeticalAppsList mApps; private AllAppsContainerView mAppsView; - // This value was used to position the QSB. We store it here for translationY animations. - private final float mFixedTranslationY; - private final float mMarginTopAdjusting; + // The amount of pixels to shift down and overlap with the rest of the content. + private final int mContentOverlap; public AppsSearchContainerLayout(Context context) { this(context, null); @@ -82,11 +81,10 @@ public class AppsSearchContainerLayout extends ExtendedEditText mSearchQueryBuilder = new SpannableStringBuilder(); Selection.setSelection(mSearchQueryBuilder, 0); - - mFixedTranslationY = getTranslationY(); - mMarginTopAdjusting = mFixedTranslationY - getPaddingTop(); - setHint(prefixTextWithIcon(getContext(), R.drawable.ic_allapps_search, getHint())); + + mContentOverlap = + getResources().getDimensionPixelSize(R.dimen.all_apps_search_bar_field_height) / 2; } @Override @@ -128,6 +126,8 @@ public class AppsSearchContainerLayout extends ExtendedEditText int expectedLeft = parent.getPaddingLeft() + (availableWidth - myWidth) / 2; int shift = expectedLeft - left; setTranslationX(shift); + + offsetTopAndBottom(mContentOverlap); } @Override @@ -196,7 +196,7 @@ public class AppsSearchContainerLayout extends ExtendedEditText @Override public void setInsets(Rect insets) { MarginLayoutParams mlp = (MarginLayoutParams) getLayoutParams(); - mlp.topMargin = Math.round(Math.max(-mFixedTranslationY, insets.top - mMarginTopAdjusting)); + mlp.topMargin = insets.top; requestLayout(); } @@ -205,9 +205,7 @@ public class AppsSearchContainerLayout extends ExtendedEditText if (mLauncher.getDeviceProfile().isVerticalBarLayout()) { return 0; } else { - int topMargin = Math.round(Math.max( - -mFixedTranslationY, insets.top - mMarginTopAdjusting)); - return insets.bottom + topMargin + mFixedTranslationY; + return insets.bottom + insets.top; } } diff --git a/src/com/android/launcher3/states/RotationHelper.java b/src/com/android/launcher3/states/RotationHelper.java index fae0fe2d81..d28fcf6884 100644 --- a/src/com/android/launcher3/states/RotationHelper.java +++ b/src/com/android/launcher3/states/RotationHelper.java @@ -15,10 +15,12 @@ */ package com.android.launcher3.states; +import static android.Manifest.permission.WRITE_SECURE_SETTINGS; import static android.content.pm.ActivityInfo.SCREEN_ORIENTATION_LOCKED; import static android.content.pm.ActivityInfo.SCREEN_ORIENTATION_NOSENSOR; import static android.content.pm.ActivityInfo.SCREEN_ORIENTATION_PORTRAIT; import static android.content.pm.ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED; +import static android.content.pm.PackageManager.PERMISSION_GRANTED; import static android.util.DisplayMetrics.DENSITY_DEVICE_STABLE; import static com.android.launcher3.config.FeatureFlags.FLAG_ENABLE_FIXED_ROTATION_TRANSFORM; @@ -37,7 +39,6 @@ import android.view.Surface; import android.view.WindowManager; import com.android.launcher3.Launcher; -import com.android.launcher3.PagedView; import com.android.launcher3.R; import com.android.launcher3.Utilities; import com.android.launcher3.config.FeatureFlags; @@ -142,9 +143,12 @@ public class RotationHelper implements OnSharedPreferenceChangeListener { if (setValueFromPrefs) { mForcedRotation = isForcedRotation; } - UI_HELPER_EXECUTOR.execute( - () -> Settings.Global.putInt(mContentResolver, FIXED_ROTATION_TRANSFORM_SETTING_NAME, - mForcedRotation ? 1 : 0)); + UI_HELPER_EXECUTOR.execute(() -> { + if (mLauncher.checkSelfPermission(WRITE_SECURE_SETTINGS) == PERMISSION_GRANTED) { + Settings.Global.putInt(mContentResolver, FIXED_ROTATION_TRANSFORM_SETTING_NAME, + mForcedRotation ? 1 : 0); + } + }); for (ForcedRotationChangedListener listener : mForcedRotationChangedListeners) { listener.onForcedRotationChanged(mForcedRotation); }