Merge "Revise homepage highlight mechanism" into sc-v2-dev am: 7bfe3e869a am: 3b9ad4de7f
Original change: https://googleplex-android-review.googlesource.com/c/platform/packages/apps/Settings/+/16366004 Change-Id: Ib86f125d24836fb955d5dd31ec26f250460d3161
This commit is contained in:
@@ -36,7 +36,6 @@ import static com.android.settingslib.drawer.TileUtils.META_DATA_PREFERENCE_TITL
|
||||
import android.app.settings.SettingsEnums;
|
||||
import android.content.ComponentName;
|
||||
import android.content.Context;
|
||||
import android.content.DialogInterface.OnCancelListener;
|
||||
import android.content.IContentProvider;
|
||||
import android.content.Intent;
|
||||
import android.content.pm.PackageManager;
|
||||
@@ -63,6 +62,7 @@ import com.android.settings.Utils;
|
||||
import com.android.settings.activityembedding.ActivityEmbeddingRulesController;
|
||||
import com.android.settings.activityembedding.ActivityEmbeddingUtils;
|
||||
import com.android.settings.dashboard.profileselector.ProfileSelectDialog;
|
||||
import com.android.settings.homepage.TopLevelHighlightMixin;
|
||||
import com.android.settings.homepage.TopLevelSettings;
|
||||
import com.android.settings.overlay.FeatureFactory;
|
||||
import com.android.settingslib.PrimarySwitchPreference;
|
||||
@@ -170,27 +170,23 @@ public class DashboardFeatureProviderImpl implements DashboardFeatureProvider {
|
||||
if (action != null) {
|
||||
intent.setAction(action);
|
||||
}
|
||||
// Register the rule for injected apps.
|
||||
ActivityEmbeddingRulesController.registerTwoPanePairRuleForSettingsHome(
|
||||
mContext,
|
||||
new ComponentName(tile.getPackageName(), tile.getComponentName()),
|
||||
action,
|
||||
true /* clearTop */);
|
||||
pref.setOnPreferenceClickListener(preference -> {
|
||||
OnCancelListener listener = null;
|
||||
TopLevelHighlightMixin highlightMixin = null;
|
||||
if (fragment instanceof TopLevelSettings
|
||||
&& ActivityEmbeddingUtils.isEmbeddingActivityEnabled(mContext)) {
|
||||
// Register the rule for injected apps.
|
||||
ActivityEmbeddingRulesController.registerTwoPanePairRuleForSettingsHome(
|
||||
mContext,
|
||||
new ComponentName(tile.getPackageName(), tile.getComponentName()),
|
||||
null /* secondaryIntentAction */,
|
||||
true /* clearTop */);
|
||||
|
||||
// Highlight preference ui.
|
||||
// Highlight the preference whenever it's clicked
|
||||
final TopLevelSettings topLevelSettings = (TopLevelSettings) fragment;
|
||||
// Highlight the tile immediately whenever it's clicked
|
||||
topLevelSettings.setHighlightPreferenceKey(key);
|
||||
// If the tile allows users to select profile, the pop-op dialog may be
|
||||
// cancelled and then the previous highlight entry should be restored.
|
||||
listener = dialog -> topLevelSettings.restorePreviousHighlight();
|
||||
highlightMixin = topLevelSettings.getHighlightMixin();
|
||||
}
|
||||
launchIntentOrSelectProfile(activity, tile, intent, sourceMetricsCategory,
|
||||
listener);
|
||||
highlightMixin);
|
||||
return true;
|
||||
});
|
||||
}
|
||||
@@ -223,7 +219,7 @@ public class DashboardFeatureProviderImpl implements DashboardFeatureProvider {
|
||||
SettingsEnums.DASHBOARD_SUMMARY)
|
||||
.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);
|
||||
launchIntentOrSelectProfile(activity, tile, intent, SettingsEnums.DASHBOARD_SUMMARY,
|
||||
/* listener= */ null);
|
||||
/* highlightMixin= */ null);
|
||||
}
|
||||
|
||||
private DynamicDataObserver createDynamicDataObserver(String method, Uri uri, Preference pref) {
|
||||
@@ -438,7 +434,7 @@ public class DashboardFeatureProviderImpl implements DashboardFeatureProvider {
|
||||
}
|
||||
|
||||
private void launchIntentOrSelectProfile(FragmentActivity activity, Tile tile, Intent intent,
|
||||
int sourceMetricCategory, OnCancelListener listener) {
|
||||
int sourceMetricCategory, TopLevelHighlightMixin highlightMixin) {
|
||||
if (!isIntentResolvable(intent)) {
|
||||
Log.w(TAG, "Cannot resolve intent, skipping. " + intent);
|
||||
return;
|
||||
@@ -469,7 +465,9 @@ public class DashboardFeatureProviderImpl implements DashboardFeatureProvider {
|
||||
}
|
||||
|
||||
ProfileSelectDialog.show(activity.getSupportFragmentManager(), tile,
|
||||
sourceMetricCategory, listener);
|
||||
sourceMetricCategory, /* onShowListener= */ highlightMixin,
|
||||
/* onDismissListener= */ highlightMixin,
|
||||
/* onCancelListener= */ highlightMixin);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -21,6 +21,8 @@ import android.content.Context;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.DialogInterface.OnCancelListener;
|
||||
import android.content.DialogInterface.OnClickListener;
|
||||
import android.content.DialogInterface.OnDismissListener;
|
||||
import android.content.DialogInterface.OnShowListener;
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.os.UserHandle;
|
||||
@@ -45,23 +47,30 @@ public class ProfileSelectDialog extends DialogFragment implements OnClickListen
|
||||
|
||||
private int mSourceMetricCategory;
|
||||
private Tile mSelectedTile;
|
||||
private OnShowListener mOnShowListener;
|
||||
private OnCancelListener mOnCancelListener;
|
||||
private OnDismissListener mOnDismissListener;
|
||||
|
||||
/**
|
||||
* Display the profile select dialog, adding the fragment to the given FragmentManager.
|
||||
* @param manager The FragmentManager this fragment will be added to.
|
||||
* @param tile The tile for this fragment.
|
||||
* @param sourceMetricCategory The source metric category.
|
||||
* @param listener The listener listens to the dialog cancelling event.
|
||||
* @param onShowListener The listener listens to the dialog showing event.
|
||||
* @param onDismissListener The listener listens to the dialog dismissing event.
|
||||
* @param onCancelListener The listener listens to the dialog cancelling event.
|
||||
*/
|
||||
public static void show(FragmentManager manager, Tile tile, int sourceMetricCategory,
|
||||
OnCancelListener listener) {
|
||||
OnShowListener onShowListener, OnDismissListener onDismissListener,
|
||||
OnCancelListener onCancelListener) {
|
||||
final ProfileSelectDialog dialog = new ProfileSelectDialog();
|
||||
final Bundle args = new Bundle();
|
||||
args.putParcelable(ARG_SELECTED_TILE, tile);
|
||||
args.putInt(ARG_SOURCE_METRIC_CATEGORY, sourceMetricCategory);
|
||||
dialog.setArguments(args);
|
||||
dialog.mOnCancelListener = listener;
|
||||
dialog.mOnShowListener = onShowListener;
|
||||
dialog.mOnDismissListener = onDismissListener;
|
||||
dialog.mOnCancelListener = onCancelListener;
|
||||
dialog.show(manager, "select_profile");
|
||||
}
|
||||
|
||||
@@ -96,13 +105,31 @@ public class ProfileSelectDialog extends DialogFragment implements OnClickListen
|
||||
getActivity().startActivityAsUser(intent, user);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStart() {
|
||||
super.onStart();
|
||||
// The fragment shows the dialog within onStart()
|
||||
if (mOnShowListener != null) {
|
||||
mOnShowListener.onShow(getDialog());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCancel(DialogInterface dialog) {
|
||||
super.onCancel(dialog);
|
||||
if (mOnCancelListener != null) {
|
||||
mOnCancelListener.onCancel(dialog);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDismiss(DialogInterface dialog) {
|
||||
super.onDismiss(dialog);
|
||||
if (mOnDismissListener != null) {
|
||||
mOnDismissListener.onDismiss(dialog);
|
||||
}
|
||||
}
|
||||
|
||||
public static void updateUserHandlesIfNeeded(Context context, Tile tile) {
|
||||
final List<UserHandle> userHandles = tile.userHandle;
|
||||
if (tile.userHandle == null || tile.userHandle.size() <= 1) {
|
||||
|
||||
Reference in New Issue
Block a user