Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 87ef55ea authored by Amin Shaikh's avatar Amin Shaikh
Browse files

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
parent 3683a688
Loading
Loading
Loading
Loading
+22 −5
Original line number Original line Diff line number Diff line
@@ -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);
+12 −12
Original line number Original line Diff line number Diff line
@@ -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;
                }
                }
            };
            };
+24 −0
Original line number Original line Diff line number Diff line
@@ -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(