Revise homepage highlight mechanism

- Create TopLevelHighlightMixin to handle highlight actions and simplify
  TopLevelSettings
- Fix the error highlight and the flicker after screen rotation
- Postpone creating the fragment until it's needed to accelerate the
  initialization and to fix the search highlight function breakage after
  toggling light/dark mode
- Register activity embedding rules only once for injection and
  wallpaper
- Do not highlight Tips & support since it's full screen
- Refactor ActivityEmbeddingRulesController

Bug: 207316936
Test: manual, robotest build pass
Change-Id: If322ec180b03ee123987c70779a25c6a570d9faf
This commit is contained in:
Jason Chiu
2021-11-30 16:13:37 +08:00
parent 506c6b804f
commit a305c23f5e
9 changed files with 346 additions and 166 deletions

View File

@@ -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.settings.widget.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);
}
}