Made getOnBoardingPrefs @Nullable & avoid NPE

Bug: 236679197
Test: Manual
Change-Id: I3cbb0891cbfcf7cab956a4e05a28dbbcc2b33e19
(cherry picked from commit c0650e7725)
This commit is contained in:
Sukesh Ram authored and Brian Isganitis committed 2022-09-01 22:20:35 +00:00
1 parent eaaf065b73
commit 82da9fc5be
2 files changed
+8 -4

No files matched your search

@@ -35,6 +35,7 @@ import androidx.core.content.ContextCompat;
import com.android.launcher3.R;
import com.android.launcher3.allapps.FloatingHeaderRow;
import com.android.launcher3.allapps.FloatingHeaderView;
import com.android.launcher3.util.OnboardingPrefs;
import com.android.launcher3.util.Themes;
import com.android.launcher3.views.ActivityContext;
@@ -92,8 +93,10 @@ public class AppsDividerView extends View implements FloatingHeaderRow {
? R.color.all_apps_label_text_dark
: R.color.all_apps_label_text);
mShowAllAppsLabel = !ActivityContext.lookupContext(
getContext()).getOnboardingPrefs().hasReachedMaxCount(ALL_APPS_VISITED_COUNT);
OnboardingPrefs<?> onboardingPrefs = ActivityContext.lookupContext(
getContext()).getOnboardingPrefs();
mShowAllAppsLabel = onboardingPrefs == null || !onboardingPrefs.hasReachedMaxCount(
ALL_APPS_VISITED_COUNT);
}
public void setup(FloatingHeaderView parent, FloatingHeaderRow[] rows, boolean tabsHidden) {
@@ -216,8 +219,8 @@ public class AppsDividerView extends View implements FloatingHeaderRow {
CharSequence allAppsLabelText = getResources().getText(R.string.all_apps_label);
mAllAppsLabelLayout = StaticLayout.Builder.obtain(
allAppsLabelText, 0, allAppsLabelText.length(), mPaint,
Math.round(mPaint.measureText(allAppsLabelText.toString())))
allAppsLabelText, 0, allAppsLabelText.length(), mPaint,
Math.round(mPaint.measureText(allAppsLabelText.toString())))
.setAlignment(Layout.Alignment.ALIGN_CENTER)
.setMaxLines(1)
.setIncludePad(true)
@@ -141,6 +141,7 @@ public interface ActivityContext {
default void applyOverwritesToLogItem(LauncherAtom.ItemInfo.Builder itemInfoBuilder) { }
/** Onboarding preferences for any onboarding data within this context. */
@Nullable
default OnboardingPrefs<?> getOnboardingPrefs() {
return null;
}