Update logic to check two pane resolution

Prior to this cl, we checked the app bounds for deciding
app in two pane or not. However, this might be broken in some certain
sceanrios.
Currently, api will check the entire task bounds.
If the width of task bounds is larger than two pane criteria,
then we treat it as in two pane mode.

Test: Highlighted behavior works correct.
Fix: 203763572
Change-Id: Ib14851b1e3e097328874c7956bb653f50820f877
This commit is contained in:
Tsung-Mao Fang
2021-10-20 18:40:44 +08:00
parent 16893da2e4
commit fce8565e5e
3 changed files with 17 additions and 10 deletions

View File

@@ -16,7 +16,10 @@
package com.android.settings.activityembedding;
import android.app.Activity;
import android.app.ActivityTaskManager;
import android.content.Context;
import android.graphics.Rect;
import android.util.DisplayMetrics;
import android.util.FeatureFlagUtils;
import android.util.Log;
@@ -64,10 +67,11 @@ public class ActivityEmbeddingUtils {
}
/** Whether the screen meets two-pane resolution. */
public static boolean isTwoPaneResolution(Context context) {
final Context appContext = context.getApplicationContext();
final DisplayMetrics dm = appContext.getResources().getDisplayMetrics();
return dm.widthPixels >= getMinCurrentScreenSplitWidthPx(appContext)
&& dm.heightPixels >= getMinSmallestScreenSplitWidthPx(appContext);
public static boolean isTwoPaneResolution(Activity activity) {
final Rect currentTaskBounds =
ActivityTaskManager.getInstance().getTaskBounds(activity.getTaskId());
return currentTaskBounds.width() >= getMinCurrentScreenSplitWidthPx(activity)
&& currentTaskBounds.height() >= getMinSmallestScreenSplitWidthPx(activity);
}
}

View File

@@ -196,8 +196,8 @@ public class TopLevelSettings extends DashboardFragment implements
}
Log.d(TAG, "onCreateAdapter, pref key: " + mHighlightedPreferenceKey);
mTopLevelAdapter = new HighlightableTopLevelPreferenceAdapter(preferenceScreen,
getListView(), mHighlightedPreferenceKey);
mTopLevelAdapter = new HighlightableTopLevelPreferenceAdapter(
getActivity(), preferenceScreen, getListView(), mHighlightedPreferenceKey);
return mTopLevelAdapter;
}

View File

@@ -16,6 +16,7 @@
package com.android.settings.widget;
import android.app.Activity;
import android.content.Context;
import android.graphics.drawable.Drawable;
import android.text.TextUtils;
@@ -53,6 +54,7 @@ public class HighlightableTopLevelPreferenceAdapter extends PreferenceGroupAdapt
final int mIconColorHighlight;
private final Context mContext;
private final Activity mActivity;
private final RecyclerView mRecyclerView;
private final int mNormalBackgroundRes;
private String mHighlightKey;
@@ -61,12 +63,13 @@ public class HighlightableTopLevelPreferenceAdapter extends PreferenceGroupAdapt
private boolean mHighlightNeeded;
private boolean mScrolled;
public HighlightableTopLevelPreferenceAdapter(PreferenceGroup preferenceGroup,
RecyclerView recyclerView, String key) {
public HighlightableTopLevelPreferenceAdapter(Activity activity,
PreferenceGroup preferenceGroup, RecyclerView recyclerView, String key) {
super(preferenceGroup);
mRecyclerView = recyclerView;
mHighlightKey = key;
mContext = preferenceGroup.getContext();
mActivity = activity;
final TypedValue outValue = new TypedValue();
mContext.getTheme().resolveAttribute(android.R.attr.selectableItemBackground,
outValue, true /* resolveRefs */);
@@ -233,6 +236,6 @@ public class HighlightableTopLevelPreferenceAdapter extends PreferenceGroupAdapt
}
private boolean isHighlightNeeded() {
return ActivityEmbeddingUtils.isTwoPaneResolution(mContext);
return ActivityEmbeddingUtils.isTwoPaneResolution(mActivity);
}
}