From 8318a4cea906ae62a062a0543cf03eafe54084e6 Mon Sep 17 00:00:00 2001 From: paphonb Date: Thu, 19 Sep 2019 23:14:18 +0700 Subject: Launcher3: Fix launcher preview rendering Signed-off-by: Harsh Shandilya Change-Id: I8c6fc263a3021f3ff929bc75b2730962b29d3758 Signed-off-by: DennySPB --- .../allapps/search/AppsSearchContainerLayout.java | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/src/com/android/launcher3/allapps/search/AppsSearchContainerLayout.java b/src/com/android/launcher3/allapps/search/AppsSearchContainerLayout.java index 31fcc8c64..6866c827d 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,7 +84,8 @@ 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(); @@ -94,6 +97,14 @@ public class AppsSearchContainerLayout extends ExtendedEditText setHint(prefixTextWithIcon(getContext(), R.drawable.ic_allapps_search, getHint())); } + private Launcher tryGetLauncher(Context context) { + try { + return Launcher.getLauncher(context); + } catch (IllegalArgumentException e) { + return null; + } + } + @Override protected void onAttachedToWindow() { super.onAttachedToWindow(); @@ -109,7 +120,7 @@ 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(); @@ -207,7 +218,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( -- cgit v1.2.3