Merge changes from topic "two_pane_state" into sc-v2-dev am: 05896ef5fb
Original change: https://googleplex-android-review.googlesource.com/c/platform/packages/apps/Settings/+/16101559 Change-Id: I5f42aebba8811cc3d1711f709e71c3d82c529443
This commit is contained in:
@@ -16,13 +16,18 @@
|
||||
|
||||
package com.android.settings;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.app.Application;
|
||||
|
||||
import com.android.settings.activityembedding.ActivityEmbeddingRulesController;
|
||||
|
||||
import java.lang.ref.WeakReference;
|
||||
|
||||
/** Settings application which sets up activity embedding rules for the large screen device. */
|
||||
public class SettingsApplication extends Application {
|
||||
|
||||
private WeakReference<Activity> mHomeActivity = new WeakReference<>(null);
|
||||
|
||||
@Override
|
||||
public void onCreate() {
|
||||
super.onCreate();
|
||||
@@ -31,4 +36,12 @@ public class SettingsApplication extends Application {
|
||||
new ActivityEmbeddingRulesController(this);
|
||||
controller.initRules();
|
||||
}
|
||||
|
||||
public void setHomeActivity(Activity homeActivity) {
|
||||
mHomeActivity = new WeakReference<>(homeActivity);
|
||||
}
|
||||
|
||||
public Activity getHomeActivity() {
|
||||
return mHomeActivity.get();
|
||||
}
|
||||
}
|
||||
|
@@ -16,6 +16,7 @@
|
||||
|
||||
package com.android.settings.activityembedding;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.ContentProvider;
|
||||
import android.content.ContentValues;
|
||||
import android.database.Cursor;
|
||||
@@ -23,13 +24,17 @@ import android.net.Uri;
|
||||
import android.os.Bundle;
|
||||
import android.text.TextUtils;
|
||||
|
||||
import com.android.settings.SettingsApplication;
|
||||
|
||||
/**
|
||||
* A content provider for querying the state of activity embedding feature
|
||||
*/
|
||||
public class ActivityEmbeddingProvider extends ContentProvider {
|
||||
|
||||
private static final String METHOD_IS_EMBEDDING_ACTIVITY_ENABLED = "isEmbeddingActivityEnabled";
|
||||
private static final String METHOD_IS_IN_SETTINGS_TWO_PANE = "isInSettingsTwoPane";
|
||||
private static final String EXTRA_ENABLED_STATE = "enabled_state";
|
||||
private static final String EXTRA_TWO_PANE_STATE = "two_pane_state";
|
||||
|
||||
@Override
|
||||
public boolean onCreate() {
|
||||
@@ -43,6 +48,14 @@ public class ActivityEmbeddingProvider extends ContentProvider {
|
||||
bundle.putBoolean(EXTRA_ENABLED_STATE,
|
||||
ActivityEmbeddingUtils.isEmbeddingActivityEnabled(getContext()));
|
||||
return bundle;
|
||||
} else if (TextUtils.equals(method, METHOD_IS_IN_SETTINGS_TWO_PANE)) {
|
||||
final Activity homeActivity =
|
||||
((SettingsApplication) getContext().getApplicationContext()).getHomeActivity();
|
||||
final Bundle bundle = new Bundle();
|
||||
bundle.putBoolean(EXTRA_TWO_PANE_STATE,
|
||||
homeActivity == null ? false
|
||||
: ActivityEmbeddingUtils.isTwoPaneResolution(homeActivity));
|
||||
return bundle;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
@@ -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);
|
||||
}
|
||||
}
|
||||
|
@@ -42,6 +42,7 @@ import androidx.fragment.app.FragmentTransaction;
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.Settings;
|
||||
import com.android.settings.SettingsActivity;
|
||||
import com.android.settings.SettingsApplication;
|
||||
import com.android.settings.Utils;
|
||||
import com.android.settings.accounts.AvatarViewMixin;
|
||||
import com.android.settings.activityembedding.ActivityEmbeddingRulesController;
|
||||
@@ -95,6 +96,7 @@ public class SettingsHomepageActivity extends FragmentActivity implements
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
((SettingsApplication) getApplication()).setHomeActivity(this);
|
||||
setContentView(R.layout.settings_homepage_container);
|
||||
|
||||
final View appBar = findViewById(R.id.app_bar_container);
|
||||
|
@@ -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;
|
||||
}
|
||||
|
||||
|
@@ -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);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user