Loading src/com/android/settings/display/WallpaperPreferenceController.java +22 −5 Original line number Diff line number Diff line Loading @@ -53,8 +53,27 @@ public class WallpaperPreferenceController extends BasePreferenceController { public void displayPreference(PreferenceScreen screen) { super.displayPreference(screen); Preference preference = screen.findPreference(getPreferenceKey()); preference.setTitle(mContext.getString(areStylesAvailable() ? R.string.style_and_wallpaper_settings_title : R.string.wallpaper_settings_title)); preference.setTitle(getTitle()); } public String getTitle() { return mContext.getString(areStylesAvailable() ? R.string.style_and_wallpaper_settings_title : R.string.wallpaper_settings_title); } public ComponentName getComponentName() { return new ComponentName(mWallpaperPackage, areStylesAvailable() ? mStylesAndWallpaperClass : mWallpaperClass); } public String getKeywords() { StringBuilder sb = new StringBuilder(mContext.getString(R.string.keywords_wallpaper)); if (areStylesAvailable()) { // TODO(b/130759285): Create a new string keywords_styles_and_wallpaper sb.append(", ").append(mContext.getString(R.string.theme_customization_category)) .append(", ").append(mContext.getString(R.string.keywords_dark_ui_mode)); } return sb.toString(); } @Override Loading @@ -75,9 +94,7 @@ public class WallpaperPreferenceController extends BasePreferenceController { @Override public boolean handlePreferenceTreeClick(Preference preference) { if (getPreferenceKey().equals(preference.getKey())) { final ComponentName componentName = new ComponentName(mWallpaperPackage, areStylesAvailable() ? mStylesAndWallpaperClass : mWallpaperClass); preference.getContext().startActivity(new Intent().setComponent(componentName)); preference.getContext().startActivity(new Intent().setComponent(getComponentName())); return true; } return super.handlePreferenceTreeClick(preference); Loading src/com/android/settings/wallpaper/WallpaperSuggestionActivity.java +12 −12 Original line number Diff line number Diff line Loading @@ -19,6 +19,7 @@ package com.android.settings.wallpaper; import android.app.Activity; import android.app.WallpaperManager; import android.app.settings.SettingsEnums; import android.content.ComponentName; import android.content.Context; import android.content.Intent; import android.content.pm.PackageManager; Loading @@ -28,6 +29,7 @@ import androidx.annotation.VisibleForTesting; import com.android.settings.R; import com.android.settings.core.SubSettingLauncher; import com.android.settings.display.WallpaperPreferenceController; import com.android.settings.search.BaseSearchIndexProvider; import com.android.settings.search.Indexable; import com.android.settings.search.SearchIndexableRaw; Loading @@ -46,8 +48,8 @@ public class WallpaperSuggestionActivity extends Activity implements Indexable { super.onCreate(savedInstanceState); final PackageManager pm = getPackageManager(); final Intent intent = new Intent() .setClassName(getString(R.string.config_wallpaper_picker_package), getString(R.string.config_wallpaper_picker_class)) .setComponent(new WallpaperPreferenceController(this, "dummy key") .getComponentName()) .addFlags(Intent.FLAG_ACTIVITY_FORWARD_RESULT); // passing the necessary extra to next page Loading Loading @@ -95,21 +97,19 @@ public class WallpaperSuggestionActivity extends Activity implements Indexable { @Override public List<SearchIndexableRaw> getRawDataToIndex(Context context, boolean enabled) { final List<SearchIndexableRaw> result = new ArrayList<>(); WallpaperPreferenceController controller = new WallpaperPreferenceController(context, "dummy key"); SearchIndexableRaw data = new SearchIndexableRaw(context); data.title = context.getString(R.string.wallpaper_settings_fragment_title); data.screenTitle = context.getString( R.string.wallpaper_settings_fragment_title); data.intentTargetPackage = context.getString( R.string.config_wallpaper_picker_package); data.intentTargetClass = context.getString( R.string.config_wallpaper_picker_class); data.title = controller.getTitle(); data.screenTitle = data.title; ComponentName component = controller.getComponentName(); data.intentTargetPackage = component.getPackageName(); data.intentTargetClass = component.getClassName(); data.intentAction = Intent.ACTION_MAIN; data.key = SUPPORT_SEARCH_INDEX_KEY; data.keywords = controller.getKeywords(); result.add(data); return result; } }; Loading tests/robotests/src/com/android/settings/display/WallpaperPreferenceControllerTest.java +24 −0 Original line number Diff line number Diff line Loading @@ -115,6 +115,30 @@ public class WallpaperPreferenceControllerTest { assertThat(mController.areStylesAvailable()).isTrue(); } @Test public void getKeywords_withoutStyles() { mShadowPackageManager.setResolveInfosForIntent( mStylesAndWallpaperIntent, Lists.newArrayList()); assertThat(mController.getKeywords()) .contains(mContext.getString(R.string.keywords_wallpaper)); assertThat(mController.getKeywords()) .doesNotContain(mContext.getString(R.string.theme_customization_category)); } @Test public void getKeywords_withStyles() { mShadowPackageManager.setResolveInfosForIntent( mStylesAndWallpaperIntent, Lists.newArrayList(mock(ResolveInfo.class))); assertThat(mController.areStylesAvailable()).isTrue(); assertThat(mController.getKeywords()) .contains(mContext.getString(R.string.keywords_wallpaper)); assertThat(mController.getKeywords()) .contains(mContext.getString(R.string.theme_customization_category)); } @Test public void handlePreferenceTreeClick_wallpaperOnly() { mShadowPackageManager.setResolveInfosForIntent( Loading Loading
src/com/android/settings/display/WallpaperPreferenceController.java +22 −5 Original line number Diff line number Diff line Loading @@ -53,8 +53,27 @@ public class WallpaperPreferenceController extends BasePreferenceController { public void displayPreference(PreferenceScreen screen) { super.displayPreference(screen); Preference preference = screen.findPreference(getPreferenceKey()); preference.setTitle(mContext.getString(areStylesAvailable() ? R.string.style_and_wallpaper_settings_title : R.string.wallpaper_settings_title)); preference.setTitle(getTitle()); } public String getTitle() { return mContext.getString(areStylesAvailable() ? R.string.style_and_wallpaper_settings_title : R.string.wallpaper_settings_title); } public ComponentName getComponentName() { return new ComponentName(mWallpaperPackage, areStylesAvailable() ? mStylesAndWallpaperClass : mWallpaperClass); } public String getKeywords() { StringBuilder sb = new StringBuilder(mContext.getString(R.string.keywords_wallpaper)); if (areStylesAvailable()) { // TODO(b/130759285): Create a new string keywords_styles_and_wallpaper sb.append(", ").append(mContext.getString(R.string.theme_customization_category)) .append(", ").append(mContext.getString(R.string.keywords_dark_ui_mode)); } return sb.toString(); } @Override Loading @@ -75,9 +94,7 @@ public class WallpaperPreferenceController extends BasePreferenceController { @Override public boolean handlePreferenceTreeClick(Preference preference) { if (getPreferenceKey().equals(preference.getKey())) { final ComponentName componentName = new ComponentName(mWallpaperPackage, areStylesAvailable() ? mStylesAndWallpaperClass : mWallpaperClass); preference.getContext().startActivity(new Intent().setComponent(componentName)); preference.getContext().startActivity(new Intent().setComponent(getComponentName())); return true; } return super.handlePreferenceTreeClick(preference); Loading
src/com/android/settings/wallpaper/WallpaperSuggestionActivity.java +12 −12 Original line number Diff line number Diff line Loading @@ -19,6 +19,7 @@ package com.android.settings.wallpaper; import android.app.Activity; import android.app.WallpaperManager; import android.app.settings.SettingsEnums; import android.content.ComponentName; import android.content.Context; import android.content.Intent; import android.content.pm.PackageManager; Loading @@ -28,6 +29,7 @@ import androidx.annotation.VisibleForTesting; import com.android.settings.R; import com.android.settings.core.SubSettingLauncher; import com.android.settings.display.WallpaperPreferenceController; import com.android.settings.search.BaseSearchIndexProvider; import com.android.settings.search.Indexable; import com.android.settings.search.SearchIndexableRaw; Loading @@ -46,8 +48,8 @@ public class WallpaperSuggestionActivity extends Activity implements Indexable { super.onCreate(savedInstanceState); final PackageManager pm = getPackageManager(); final Intent intent = new Intent() .setClassName(getString(R.string.config_wallpaper_picker_package), getString(R.string.config_wallpaper_picker_class)) .setComponent(new WallpaperPreferenceController(this, "dummy key") .getComponentName()) .addFlags(Intent.FLAG_ACTIVITY_FORWARD_RESULT); // passing the necessary extra to next page Loading Loading @@ -95,21 +97,19 @@ public class WallpaperSuggestionActivity extends Activity implements Indexable { @Override public List<SearchIndexableRaw> getRawDataToIndex(Context context, boolean enabled) { final List<SearchIndexableRaw> result = new ArrayList<>(); WallpaperPreferenceController controller = new WallpaperPreferenceController(context, "dummy key"); SearchIndexableRaw data = new SearchIndexableRaw(context); data.title = context.getString(R.string.wallpaper_settings_fragment_title); data.screenTitle = context.getString( R.string.wallpaper_settings_fragment_title); data.intentTargetPackage = context.getString( R.string.config_wallpaper_picker_package); data.intentTargetClass = context.getString( R.string.config_wallpaper_picker_class); data.title = controller.getTitle(); data.screenTitle = data.title; ComponentName component = controller.getComponentName(); data.intentTargetPackage = component.getPackageName(); data.intentTargetClass = component.getClassName(); data.intentAction = Intent.ACTION_MAIN; data.key = SUPPORT_SEARCH_INDEX_KEY; data.keywords = controller.getKeywords(); result.add(data); return result; } }; Loading
tests/robotests/src/com/android/settings/display/WallpaperPreferenceControllerTest.java +24 −0 Original line number Diff line number Diff line Loading @@ -115,6 +115,30 @@ public class WallpaperPreferenceControllerTest { assertThat(mController.areStylesAvailable()).isTrue(); } @Test public void getKeywords_withoutStyles() { mShadowPackageManager.setResolveInfosForIntent( mStylesAndWallpaperIntent, Lists.newArrayList()); assertThat(mController.getKeywords()) .contains(mContext.getString(R.string.keywords_wallpaper)); assertThat(mController.getKeywords()) .doesNotContain(mContext.getString(R.string.theme_customization_category)); } @Test public void getKeywords_withStyles() { mShadowPackageManager.setResolveInfosForIntent( mStylesAndWallpaperIntent, Lists.newArrayList(mock(ResolveInfo.class))); assertThat(mController.areStylesAvailable()).isTrue(); assertThat(mController.getKeywords()) .contains(mContext.getString(R.string.keywords_wallpaper)); assertThat(mController.getKeywords()) .contains(mContext.getString(R.string.theme_customization_category)); } @Test public void handlePreferenceTreeClick_wallpaperOnly() { mShadowPackageManager.setResolveInfosForIntent( Loading