Loading res/layout/settings_homepage.xml +1 −1 Original line number Diff line number Diff line Loading @@ -21,7 +21,7 @@ android:layout_height="wrap_content" android:orientation="vertical"> <androidx.recyclerview.widget.RecyclerView <com.android.settings.homepage.contextualcards.FocusRecyclerView android:id="@+id/card_container" android:layout_width="match_parent" android:layout_height="match_parent" Loading src/com/android/settings/homepage/contextualcards/ContextualCardManager.java +17 −1 Original line number Diff line number Diff line Loading @@ -43,6 +43,8 @@ import com.android.settingslib.core.instrumentation.MetricsFeatureProvider; import com.android.settingslib.core.lifecycle.Lifecycle; import com.android.settingslib.core.lifecycle.LifecycleObserver; import com.android.settingslib.core.lifecycle.events.OnSaveInstanceState; import com.android.settingslib.core.lifecycle.events.OnStart; import com.android.settingslib.core.lifecycle.events.OnStop; import java.util.ArrayList; import java.util.List; Loading Loading @@ -98,7 +100,6 @@ public class ContextualCardManager implements ContextualCardLoader.CardContentLo mLifecycleObservers = new ArrayList<>(); mControllerRendererPool = new ControllerRendererPool(); mLifecycle.addObserver(this); if (savedInstanceState == null) { mIsFirstLaunch = true; mSavedCards = null; Loading Loading @@ -240,6 +241,21 @@ public class ContextualCardManager implements ContextualCardLoader.CardContentLo outState.putStringArrayList(KEY_CONTEXTUAL_CARDS, cards); } public void onWindowFocusChanged(boolean hasWindowFocus) { // Duplicate a list to avoid java.util.ConcurrentModificationException. final List<ContextualCard> cards = new ArrayList<>(mContextualCards); for (ContextualCard card : cards) { final ContextualCardController controller = mControllerRendererPool .getController(mContext, card.getCardType()); if (hasWindowFocus && controller instanceof OnStart) { ((OnStart) controller).onStart(); } if (!hasWindowFocus && controller instanceof OnStop) { ((OnStop) controller).onStop(); } } } public ControllerRendererPool getControllerRendererPool() { return mControllerRendererPool; } Loading src/com/android/settings/homepage/contextualcards/ContextualCardsFragment.java +9 −3 Original line number Diff line number Diff line Loading @@ -27,17 +27,17 @@ import android.view.ViewGroup; import androidx.loader.app.LoaderManager; import androidx.recyclerview.widget.GridLayoutManager; import androidx.recyclerview.widget.RecyclerView; import com.android.settings.R; import com.android.settings.core.InstrumentedFragment; import com.android.settings.overlay.FeatureFactory; public class ContextualCardsFragment extends InstrumentedFragment { public class ContextualCardsFragment extends InstrumentedFragment implements FocusRecyclerView.FocusListener { private static final String TAG = "ContextualCardsFragment"; private RecyclerView mCardsContainer; private FocusRecyclerView mCardsContainer; private GridLayoutManager mLayoutManager; private ContextualCardsAdapter mContextualCardsAdapter; private ContextualCardManager mContextualCardManager; Loading Loading @@ -72,10 +72,16 @@ public class ContextualCardsFragment extends InstrumentedFragment { this /* lifecycleOwner */, mContextualCardManager); mCardsContainer.setAdapter(mContextualCardsAdapter); mContextualCardManager.setListener(mContextualCardsAdapter); mCardsContainer.setListener(this); return rootView; } @Override public void onWindowFocusChanged(boolean hasWindowFocus) { mContextualCardManager.onWindowFocusChanged(hasWindowFocus); } @Override public int getMetricsCategory() { return SettingsEnums.SETTINGS_HOMEPAGE; Loading src/com/android/settings/homepage/contextualcards/FocusRecyclerView.java 0 → 100644 +36 −0 Original line number Diff line number Diff line package com.android.settings.homepage.contextualcards; import android.content.Context; import android.util.AttributeSet; import androidx.annotation.Nullable; import androidx.recyclerview.widget.RecyclerView; public class FocusRecyclerView extends RecyclerView { private FocusListener mListener; public FocusRecyclerView(Context context) { super(context); } public FocusRecyclerView(Context context, @Nullable AttributeSet attrs) { super(context, attrs); } @Override public void onWindowFocusChanged(boolean hasWindowFocus) { super.onWindowFocusChanged(hasWindowFocus); if (mListener != null) { mListener.onWindowFocusChanged(hasWindowFocus); } } public void setListener(FocusListener listener) { mListener = listener; } public interface FocusListener { void onWindowFocusChanged(boolean hasWindowFocus); } } Loading
res/layout/settings_homepage.xml +1 −1 Original line number Diff line number Diff line Loading @@ -21,7 +21,7 @@ android:layout_height="wrap_content" android:orientation="vertical"> <androidx.recyclerview.widget.RecyclerView <com.android.settings.homepage.contextualcards.FocusRecyclerView android:id="@+id/card_container" android:layout_width="match_parent" android:layout_height="match_parent" Loading
src/com/android/settings/homepage/contextualcards/ContextualCardManager.java +17 −1 Original line number Diff line number Diff line Loading @@ -43,6 +43,8 @@ import com.android.settingslib.core.instrumentation.MetricsFeatureProvider; import com.android.settingslib.core.lifecycle.Lifecycle; import com.android.settingslib.core.lifecycle.LifecycleObserver; import com.android.settingslib.core.lifecycle.events.OnSaveInstanceState; import com.android.settingslib.core.lifecycle.events.OnStart; import com.android.settingslib.core.lifecycle.events.OnStop; import java.util.ArrayList; import java.util.List; Loading Loading @@ -98,7 +100,6 @@ public class ContextualCardManager implements ContextualCardLoader.CardContentLo mLifecycleObservers = new ArrayList<>(); mControllerRendererPool = new ControllerRendererPool(); mLifecycle.addObserver(this); if (savedInstanceState == null) { mIsFirstLaunch = true; mSavedCards = null; Loading Loading @@ -240,6 +241,21 @@ public class ContextualCardManager implements ContextualCardLoader.CardContentLo outState.putStringArrayList(KEY_CONTEXTUAL_CARDS, cards); } public void onWindowFocusChanged(boolean hasWindowFocus) { // Duplicate a list to avoid java.util.ConcurrentModificationException. final List<ContextualCard> cards = new ArrayList<>(mContextualCards); for (ContextualCard card : cards) { final ContextualCardController controller = mControllerRendererPool .getController(mContext, card.getCardType()); if (hasWindowFocus && controller instanceof OnStart) { ((OnStart) controller).onStart(); } if (!hasWindowFocus && controller instanceof OnStop) { ((OnStop) controller).onStop(); } } } public ControllerRendererPool getControllerRendererPool() { return mControllerRendererPool; } Loading
src/com/android/settings/homepage/contextualcards/ContextualCardsFragment.java +9 −3 Original line number Diff line number Diff line Loading @@ -27,17 +27,17 @@ import android.view.ViewGroup; import androidx.loader.app.LoaderManager; import androidx.recyclerview.widget.GridLayoutManager; import androidx.recyclerview.widget.RecyclerView; import com.android.settings.R; import com.android.settings.core.InstrumentedFragment; import com.android.settings.overlay.FeatureFactory; public class ContextualCardsFragment extends InstrumentedFragment { public class ContextualCardsFragment extends InstrumentedFragment implements FocusRecyclerView.FocusListener { private static final String TAG = "ContextualCardsFragment"; private RecyclerView mCardsContainer; private FocusRecyclerView mCardsContainer; private GridLayoutManager mLayoutManager; private ContextualCardsAdapter mContextualCardsAdapter; private ContextualCardManager mContextualCardManager; Loading Loading @@ -72,10 +72,16 @@ public class ContextualCardsFragment extends InstrumentedFragment { this /* lifecycleOwner */, mContextualCardManager); mCardsContainer.setAdapter(mContextualCardsAdapter); mContextualCardManager.setListener(mContextualCardsAdapter); mCardsContainer.setListener(this); return rootView; } @Override public void onWindowFocusChanged(boolean hasWindowFocus) { mContextualCardManager.onWindowFocusChanged(hasWindowFocus); } @Override public int getMetricsCategory() { return SettingsEnums.SETTINGS_HOMEPAGE; Loading
src/com/android/settings/homepage/contextualcards/FocusRecyclerView.java 0 → 100644 +36 −0 Original line number Diff line number Diff line package com.android.settings.homepage.contextualcards; import android.content.Context; import android.util.AttributeSet; import androidx.annotation.Nullable; import androidx.recyclerview.widget.RecyclerView; public class FocusRecyclerView extends RecyclerView { private FocusListener mListener; public FocusRecyclerView(Context context) { super(context); } public FocusRecyclerView(Context context, @Nullable AttributeSet attrs) { super(context, attrs); } @Override public void onWindowFocusChanged(boolean hasWindowFocus) { super.onWindowFocusChanged(hasWindowFocus); if (mListener != null) { mListener.onWindowFocusChanged(hasWindowFocus); } } public void setListener(FocusListener listener) { mListener = listener; } public interface FocusListener { void onWindowFocusChanged(boolean hasWindowFocus); } }