Add Settings keywords for Styles & Wallpaper.

Reusing existing strings since this is coming in after string freeze.
TODO: create a new keyword string for this preference.

Fixes: 130759285
Test: m RunSettingsRoboTests and searching keywords on device
Change-Id: Ice1bc34b381302745cb55056377cc94ea74e8d50
This commit is contained in:
Amin Shaikh
2019-04-18 11:13:01 -04:00
parent 3683a688f7
commit 87ef55ea90
3 changed files with 58 additions and 17 deletions

View File

@@ -53,8 +53,27 @@ public class WallpaperPreferenceController extends BasePreferenceController {
public void displayPreference(PreferenceScreen screen) { public void displayPreference(PreferenceScreen screen) {
super.displayPreference(screen); super.displayPreference(screen);
Preference preference = screen.findPreference(getPreferenceKey()); Preference preference = screen.findPreference(getPreferenceKey());
preference.setTitle(mContext.getString(areStylesAvailable() preference.setTitle(getTitle());
? R.string.style_and_wallpaper_settings_title : R.string.wallpaper_settings_title)); }
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 @Override
@@ -75,9 +94,7 @@ public class WallpaperPreferenceController extends BasePreferenceController {
@Override @Override
public boolean handlePreferenceTreeClick(Preference preference) { public boolean handlePreferenceTreeClick(Preference preference) {
if (getPreferenceKey().equals(preference.getKey())) { if (getPreferenceKey().equals(preference.getKey())) {
final ComponentName componentName = new ComponentName(mWallpaperPackage, preference.getContext().startActivity(new Intent().setComponent(getComponentName()));
areStylesAvailable() ? mStylesAndWallpaperClass : mWallpaperClass);
preference.getContext().startActivity(new Intent().setComponent(componentName));
return true; return true;
} }
return super.handlePreferenceTreeClick(preference); return super.handlePreferenceTreeClick(preference);

View File

@@ -19,6 +19,7 @@ package com.android.settings.wallpaper;
import android.app.Activity; import android.app.Activity;
import android.app.WallpaperManager; import android.app.WallpaperManager;
import android.app.settings.SettingsEnums; import android.app.settings.SettingsEnums;
import android.content.ComponentName;
import android.content.Context; import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.content.pm.PackageManager; import android.content.pm.PackageManager;
@@ -28,6 +29,7 @@ import androidx.annotation.VisibleForTesting;
import com.android.settings.R; import com.android.settings.R;
import com.android.settings.core.SubSettingLauncher; import com.android.settings.core.SubSettingLauncher;
import com.android.settings.display.WallpaperPreferenceController;
import com.android.settings.search.BaseSearchIndexProvider; import com.android.settings.search.BaseSearchIndexProvider;
import com.android.settings.search.Indexable; import com.android.settings.search.Indexable;
import com.android.settings.search.SearchIndexableRaw; import com.android.settings.search.SearchIndexableRaw;
@@ -46,8 +48,8 @@ public class WallpaperSuggestionActivity extends Activity implements Indexable {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
final PackageManager pm = getPackageManager(); final PackageManager pm = getPackageManager();
final Intent intent = new Intent() final Intent intent = new Intent()
.setClassName(getString(R.string.config_wallpaper_picker_package), .setComponent(new WallpaperPreferenceController(this, "dummy key")
getString(R.string.config_wallpaper_picker_class)) .getComponentName())
.addFlags(Intent.FLAG_ACTIVITY_FORWARD_RESULT); .addFlags(Intent.FLAG_ACTIVITY_FORWARD_RESULT);
// passing the necessary extra to next page // passing the necessary extra to next page
@@ -95,21 +97,19 @@ public class WallpaperSuggestionActivity extends Activity implements Indexable {
@Override @Override
public List<SearchIndexableRaw> getRawDataToIndex(Context context, public List<SearchIndexableRaw> getRawDataToIndex(Context context,
boolean enabled) { boolean enabled) {
final List<SearchIndexableRaw> result = new ArrayList<>(); final List<SearchIndexableRaw> result = new ArrayList<>();
WallpaperPreferenceController controller =
new WallpaperPreferenceController(context, "dummy key");
SearchIndexableRaw data = new SearchIndexableRaw(context); SearchIndexableRaw data = new SearchIndexableRaw(context);
data.title = context.getString(R.string.wallpaper_settings_fragment_title); data.title = controller.getTitle();
data.screenTitle = context.getString( data.screenTitle = data.title;
R.string.wallpaper_settings_fragment_title); ComponentName component = controller.getComponentName();
data.intentTargetPackage = context.getString( data.intentTargetPackage = component.getPackageName();
R.string.config_wallpaper_picker_package); data.intentTargetClass = component.getClassName();
data.intentTargetClass = context.getString(
R.string.config_wallpaper_picker_class);
data.intentAction = Intent.ACTION_MAIN; data.intentAction = Intent.ACTION_MAIN;
data.key = SUPPORT_SEARCH_INDEX_KEY; data.key = SUPPORT_SEARCH_INDEX_KEY;
data.keywords = controller.getKeywords();
result.add(data); result.add(data);
return result; return result;
} }
}; };

View File

@@ -115,6 +115,30 @@ public class WallpaperPreferenceControllerTest {
assertThat(mController.areStylesAvailable()).isTrue(); 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 @Test
public void handlePreferenceTreeClick_wallpaperOnly() { public void handlePreferenceTreeClick_wallpaperOnly() {
mShadowPackageManager.setResolveInfosForIntent( mShadowPackageManager.setResolveInfosForIntent(