diff options
Diffstat (limited to 'src/com/android/launcher3/allapps/search/AppsSearchContainerLayout.java')
-rw-r--r-- | src/com/android/launcher3/allapps/search/AppsSearchContainerLayout.java | 28 |
1 files changed, 21 insertions, 7 deletions
diff --git a/src/com/android/launcher3/allapps/search/AppsSearchContainerLayout.java b/src/com/android/launcher3/allapps/search/AppsSearchContainerLayout.java index 31fcc8c64..bcfdf916b 100644 --- a/src/com/android/launcher3/allapps/search/AppsSearchContainerLayout.java +++ b/src/com/android/launcher3/allapps/search/AppsSearchContainerLayout.java @@ -49,6 +49,7 @@ import com.android.launcher3.allapps.SearchUiManager; import com.android.launcher3.anim.PropertySetter; import com.android.launcher3.graphics.TintedDrawableSpan; import com.android.launcher3.util.ComponentKey; +import com.android.launcher3.views.ActivityContext; import java.util.ArrayList; @@ -61,6 +62,7 @@ public class AppsSearchContainerLayout extends ExtendedEditText private final Launcher mLauncher; + private final ActivityContext mActivity; private final AllAppsSearchBarController mSearchBarController; private final SpannableStringBuilder mSearchQueryBuilder; @@ -82,16 +84,27 @@ public class AppsSearchContainerLayout extends ExtendedEditText public AppsSearchContainerLayout(Context context, AttributeSet attrs, int defStyleAttr) { super(context, attrs, defStyleAttr); - mLauncher = Launcher.getLauncher(context); + mActivity = ActivityContext.lookupContext(context); + mLauncher = tryGetLauncher(context); mSearchBarController = new AllAppsSearchBarController(); mSearchQueryBuilder = new SpannableStringBuilder(); Selection.setSelection(mSearchQueryBuilder, 0); - mFixedTranslationY = getTranslationY(); + mFixedTranslationY = Math.round(getTranslationY()); mMarginTopAdjusting = mFixedTranslationY - getPaddingTop(); setHint(prefixTextWithIcon(getContext(), R.drawable.ic_allapps_search, getHint())); + + setTranslationY(0); + } + + private Launcher tryGetLauncher(Context context) { + try { + return Launcher.getLauncher(context); + } catch (IllegalArgumentException e) { + return null; + } } @Override @@ -109,11 +122,11 @@ public class AppsSearchContainerLayout extends ExtendedEditText @Override protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { // Update the width to match the grid padding - DeviceProfile dp = mLauncher.getDeviceProfile(); + DeviceProfile dp = mActivity.getDeviceProfile(); int myRequestedWidth = getSize(widthMeasureSpec); - int rowWidth = myRequestedWidth - mAppsView.getActiveRecyclerView().getPaddingLeft() - - mAppsView.getActiveRecyclerView().getPaddingRight(); - + int leftRightPadding = dp.desiredWorkspaceLeftRightMarginPx + + dp.cellLayoutPaddingLeftRightPx; + int rowWidth = myRequestedWidth - leftRightPadding * 2; int cellWidth = DeviceProfile.calculateCellWidth(rowWidth, dp.inv.numHotseatIcons); int iconVisibleSize = Math.round(ICON_VISIBLE_AREA_FACTOR * dp.iconSizePx); int iconPadding = cellWidth - iconVisibleSize; @@ -133,6 +146,7 @@ public class AppsSearchContainerLayout extends ExtendedEditText int expectedLeft = parent.getPaddingLeft() + (availableWidth - myWidth) / 2; int shift = expectedLeft - left; setTranslationX(shift); + offsetTopAndBottom((int) mFixedTranslationY); } @Override @@ -207,7 +221,7 @@ public class AppsSearchContainerLayout extends ExtendedEditText @Override public float getScrollRangeDelta(Rect insets) { - if (mLauncher.getDeviceProfile().isVerticalBarLayout()) { + if (mActivity.getDeviceProfile().isVerticalBarLayout()) { return 0; } else { int topMargin = Math.round(Math.max( |