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

Commit f0516ae7 authored by Wesley.CW Wang's avatar Wesley.CW Wang
Browse files

Adjust custom themes default naming

 - Change custom themes default naming, use custom themes amount plus 1
 as naming not "Custom", Doc: https://docs.google.com/presentation/d/15JadcGi5k1_0znUN_XdFpU7UxeXwxjK3Y7LxvhW5ETM/edit?ts=5eb540b5#slide=id.g812429ed29_51_16
 Video: https://drive.google.com/file/d/1Ijin203kGq9D9AG5FogaNtmb2gkcGfcW/view?usp=sharing

 Bug: 151285666
 Test: Manually

Change-Id: Ief25203a7911617d4f6287a44e2833db55ca8b2b
parent 4fb9e0f4
Loading
Loading
Loading
Loading
+5 −1
Original line number Diff line number Diff line
@@ -64,6 +64,7 @@ public class CustomThemeActivity extends FragmentActivity implements
    public static final String EXTRA_THEME_ID = "CustomThemeActivity.ThemeId";
    public static final String EXTRA_THEME_TITLE = "CustomThemeActivity.ThemeTitle";
    public static final String EXTRA_THEME_PACKAGES = "CustomThemeActivity.ThemePackages";
    public static final String CREATE_NEW_THEME = "CustomThemeActivity.NewTheme";
    public static final int REQUEST_CODE_CUSTOM_THEME = 1;
    public static final int RESULT_THEME_DELETED = 10;
    public static final int RESULT_THEME_APPLIED = 20;
@@ -78,6 +79,7 @@ public class CustomThemeActivity extends FragmentActivity implements
    private ThemeManager mThemeManager;
    private TextView mNextButton;
    private TextView mPreviousButton;
    private boolean mIsDefinedTheme = true;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
@@ -89,6 +91,7 @@ public class CustomThemeActivity extends FragmentActivity implements
                && intent.hasExtra(EXTRA_THEME_TITLE) && intent.hasExtra(EXTRA_THEME_ID)) {
            ThemeBundleProvider themeProvider =
                    new DefaultThemeProvider(this, injector.getCustomizationPreferences(this));
            mIsDefinedTheme = intent.getBooleanExtra(CREATE_NEW_THEME, true);
            try {
                CustomTheme.Builder themeBuilder = themeProvider.parseCustomTheme(
                        intent.getStringExtra(EXTRA_THEME_PACKAGES));
@@ -384,7 +387,8 @@ public class CustomThemeActivity extends FragmentActivity implements
            return CustomThemeNameFragment.newInstance(
                    title,
                    position,
                    titleResId);
                    titleResId,
                    mIsDefinedTheme);
        }
    }
}
+42 −3
Original line number Diff line number Diff line
@@ -16,6 +16,8 @@
package com.android.customization.picker.theme;

import android.os.Bundle;
import android.text.TextUtils;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
@@ -26,6 +28,8 @@ import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.android.customization.model.theme.ThemeBundle.PreviewInfo;
import com.android.customization.module.CustomizationInjector;
import com.android.customization.module.CustomizationPreferences;
import com.android.customization.picker.WallpaperPreviewer;
import com.android.wallpaper.R;
import com.android.wallpaper.model.WallpaperInfo;
@@ -34,15 +38,22 @@ import com.android.wallpaper.module.InjectorProvider;
import com.android.wallpaper.picker.AppbarFragment;
import com.android.wallpaper.widget.WallpaperColorsLoader;

import org.json.JSONArray;
import org.json.JSONException;

/** Fragment of naming a custom theme. */
public class CustomThemeNameFragment extends CustomThemeStepFragment {

    private static final String TAG = "CustomThemeNameFragment";
    private static final String ARG_IS_DEFINED_THEME = "CustomThemeNameFragment.new_theme";

    public static CustomThemeNameFragment newInstance(CharSequence toolbarTitle, int position,
            int titleResId) {
            int titleResId, boolean mIsDefinedTheme) {
        CustomThemeNameFragment fragment = new CustomThemeNameFragment();
        Bundle arguments = AppbarFragment.createArguments(toolbarTitle);
        arguments.putInt(ARG_KEY_POSITION, position);
        arguments.putInt(ARG_KEY_TITLE_RES_ID, titleResId);
        arguments.putBoolean(ARG_IS_DEFINED_THEME, mIsDefinedTheme);
        fragment.setArguments(arguments);
        return fragment;
    }
@@ -51,6 +62,7 @@ public class CustomThemeNameFragment extends CustomThemeStepFragment {
    private ImageView mWallpaperImage;
    private WallpaperInfo mCurrentHomeWallpaper;
    private ThemeOptionPreviewer mThemeOptionPreviewer;
    private CustomizationPreferences mCustomizationPreferences;

    @Nullable
    @Override
@@ -59,10 +71,10 @@ public class CustomThemeNameFragment extends CustomThemeStepFragment {
        View view = super.onCreateView(inflater, container, savedInstanceState);
        mTitle = view.findViewById(R.id.component_options_title);
        mTitle.setText(mTitleResId);
        mNameEditor = view.findViewById(R.id.custom_theme_name);
        mNameEditor.setText(mCustomThemeManager.getOriginalTheme().getTitle());
        CurrentWallpaperInfoFactory currentWallpaperFactory = InjectorProvider.getInjector()
                .getCurrentWallpaperFactory(getActivity().getApplicationContext());
        CustomizationInjector injector = (CustomizationInjector) InjectorProvider.getInjector();
        mCustomizationPreferences = injector.getCustomizationPreferences(getContext());

        // Set wallpaper background.
        mWallpaperImage = view.findViewById(R.id.wallpaper_preview_image);
@@ -86,6 +98,11 @@ public class CustomThemeNameFragment extends CustomThemeStepFragment {
        PreviewInfo previewInfo = mCustomThemeManager.buildCustomThemePreviewInfo(getContext());
        mThemeOptionPreviewer.setPreviewInfo(previewInfo);

        // Set theme default name.
        mNameEditor = view.findViewById(R.id.custom_theme_name);
        mNameEditor.setText(
                getCustomThemeDefaultName(getArguments().getBoolean(ARG_IS_DEFINED_THEME, true)));

        view.addOnLayoutChangeListener(new View.OnLayoutChangeListener() {
            @Override
            public void onLayoutChange(View v, int left, int top, int right, int bottom,
@@ -110,6 +127,28 @@ public class CustomThemeNameFragment extends CustomThemeStepFragment {
        }
    }

    private String getCustomThemeDefaultName(boolean mIsDefinedTheme) {
        if (mIsDefinedTheme) {
            // For new custom theme. use custom themes amount plus 1 as default naming.
            String serializedThemes = mCustomizationPreferences.getSerializedCustomThemes();
            int customThemesCount = 0;
            if (!TextUtils.isEmpty(serializedThemes)) {
                try {
                    JSONArray customThemes = new JSONArray(serializedThemes);
                    customThemesCount = customThemes.length();
                } catch (JSONException e) {
                    Log.w(TAG, "Couldn't read stored custom theme");
                }
            }
            return getContext().getString(
                    R.string.custom_theme_title, customThemesCount + 1);
        } else {
            // For existing custom theme, keep its name as default naming.
            return mCustomThemeManager.getOriginalTheme().getTitle();
        }

    }

    @Override
    protected int getFragmentLayoutResId() {
        return R.layout.fragment_custom_theme_name;
+1 −0
Original line number Diff line number Diff line
@@ -362,6 +362,7 @@ public class ThemeFragment extends AppbarFragment {
        intent.putExtra(CustomThemeActivity.EXTRA_THEME_ID, themeToEdit.getId());
        intent.putExtra(CustomThemeActivity.EXTRA_THEME_PACKAGES,
                themeToEdit.getSerializedPackages());
        intent.putExtra(CustomThemeActivity.CREATE_NEW_THEME, !themeToEdit.isDefined());
        startActivityForResult(intent, CustomThemeActivity.REQUEST_CODE_CUSTOM_THEME);
    }