From e9355c622d8d61a0e5a7bcd7d47576485196a033 Mon Sep 17 00:00:00 2001 From: Sunny Goyal Date: Wed, 26 Feb 2025 10:51:42 -0800 Subject: [PATCH] Removing unnecessary ActivityContextDelegate Bug: 393703968 Flag: EXEMPT refactor Test: Presubmit Change-Id: Ib95b26de000a2fe8204fdbc46c8a9da4f65c7eab --- src/com/android/launcher3/BaseActivity.java | 6 ++---- .../recyclerview/AllAppsRecyclerViewPool.kt | 11 ++++------- .../android/launcher3/views/ActivityContext.java | 16 ++-------------- 3 files changed, 8 insertions(+), 25 deletions(-) diff --git a/src/com/android/launcher3/BaseActivity.java b/src/com/android/launcher3/BaseActivity.java index 6277e41c14..84c80402b2 100644 --- a/src/com/android/launcher3/BaseActivity.java +++ b/src/com/android/launcher3/BaseActivity.java @@ -481,10 +481,8 @@ public abstract class BaseActivity extends Activity implements ActivityContext, public static T fromContext(Context context) { if (context instanceof BaseActivity) { return (T) context; - } else if (context instanceof ActivityContextDelegate) { - return (T) ((ActivityContextDelegate) context).mDelegate; - } else if (context instanceof ContextWrapper) { - return fromContext(((ContextWrapper) context).getBaseContext()); + } else if (context instanceof ContextWrapper cw) { + return fromContext(cw.getBaseContext()); } else { throw new IllegalArgumentException("Cannot find BaseActivity in parent tree"); } diff --git a/src/com/android/launcher3/recyclerview/AllAppsRecyclerViewPool.kt b/src/com/android/launcher3/recyclerview/AllAppsRecyclerViewPool.kt index e4c50f08b1..2d1a5f5a36 100644 --- a/src/com/android/launcher3/recyclerview/AllAppsRecyclerViewPool.kt +++ b/src/com/android/launcher3/recyclerview/AllAppsRecyclerViewPool.kt @@ -18,6 +18,7 @@ package com.android.launcher3.recyclerview import android.content.Context import android.util.Log +import android.view.ContextThemeWrapper import android.view.InflateException import androidx.annotation.VisibleForTesting import androidx.annotation.VisibleForTesting.Companion.PROTECTED @@ -33,8 +34,6 @@ import com.android.launcher3.util.Executors.MAIN_EXECUTOR import com.android.launcher3.util.Executors.VIEW_PREINFLATION_EXECUTOR import com.android.launcher3.util.Themes import com.android.launcher3.views.ActivityContext -import com.android.launcher3.views.ActivityContext.ActivityContextDelegate -import java.lang.IllegalStateException const val PREINFLATE_ICONS_ROW_COUNT = 4 const val EXTRA_ICONS_COUNT = 2 @@ -80,11 +79,9 @@ class AllAppsRecyclerViewPool : RecycledViewPool() where T : Context, T : Act // create a separate AssetManager obj internally to avoid lock contention with // AssetManager obj that is associated with the launcher context on the main thread. val allAppsPreInflationContext = - ActivityContextDelegate( - context.createConfigurationContext(context.resources.configuration), - Themes.getActivityThemeRes(context), - context, - ) + ContextThemeWrapper(context, Themes.getActivityThemeRes(context)).apply { + applyOverrideConfiguration(context.resources.configuration) + } // Because we perform onCreateViewHolder() on worker thread, we need a separate // adapter/inflator object as they are not thread-safe. Note that the adapter diff --git a/src/com/android/launcher3/views/ActivityContext.java b/src/com/android/launcher3/views/ActivityContext.java index 81968fce58..bbea043820 100644 --- a/src/com/android/launcher3/views/ActivityContext.java +++ b/src/com/android/launcher3/views/ActivityContext.java @@ -43,7 +43,6 @@ import android.os.IBinder; import android.os.Process; import android.os.UserHandle; import android.util.Log; -import android.view.ContextThemeWrapper; import android.view.Display; import android.view.LayoutInflater; import android.view.View; @@ -552,21 +551,10 @@ public interface ActivityContext { static T lookupContextNoThrow(Context context) { if (context instanceof ActivityContext) { return (T) context; - } else if (context instanceof ActivityContextDelegate acd) { - return (T) acd.mDelegate; - } else if (context instanceof ContextWrapper) { - return lookupContextNoThrow(((ContextWrapper) context).getBaseContext()); + } else if (context instanceof ContextWrapper cw) { + return lookupContextNoThrow(cw.getBaseContext()); } else { return null; } } - - class ActivityContextDelegate extends ContextThemeWrapper { - public final ActivityContext mDelegate; - - public ActivityContextDelegate(Context base, int themeResId, ActivityContext delegate) { - super(base, themeResId); - mDelegate = delegate; - } - } }