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

Commit 32bb6ef3 authored by Santiago Etchebehere's avatar Santiago Etchebehere
Browse files

Custom Theme 9/n: add shape step screen

Bug: 124796742

Change-Id: Ibd84051452cc1ca8e11dc46ae0189a3f91eb2b7e
parent 33db72b9
Loading
Loading
Loading
Loading
+34 −0
Original line number Diff line number Diff line
<?xml version="1.0" encoding="utf-8"?>
<!--
     Copyright (C) 2019 The Android Open Source Project

     Licensed under the Apache License, Version 2.0 (the "License");
     you may not use this file except in compliance with the License.
     You may obtain a copy of the License at

          http://www.apache.org/licenses/LICENSE-2.0

     Unless required by applicable law or agreed to in writing, software
     distributed under the License is distributed on an "AS IS" BASIS,
     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     See the License for the specific language governing permissions and
     limitations under the License.
-->
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
              android:layout_width="wrap_content"
              android:layout_height="match_parent"
              android:orientation="vertical">
    <FrameLayout
        android:id="@+id/option_tile"
        android:layout_width="@dimen/option_tile_width"
        android:layout_height="@dimen/option_tile_width"
        android:layout_gravity="center"
        android:layout_marginTop="16dp"
        android:padding="2dp">
        <ImageView
            android:id="@+id/shape_thumbnail"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_gravity="center"/>
    </FrameLayout>
</LinearLayout>
+2 −0
Original line number Diff line number Diff line
@@ -38,4 +38,6 @@
    <color name="tile_enabled_icon_color">@color/material_white_100</color>
    <color name="tile_disabled_icon_color">#2d2d2d</color>
    <color name="tile_disabled_background_color">@color/light_grey</color>

    <color name="shape_option_tile_foreground_color">#f8f9fa</color>
</resources>
+3 −0
Original line number Diff line number Diff line
@@ -76,4 +76,7 @@
    <dimen name="component_icon_thumb_size">40dp</dimen>

    <dimen name="component_color_chip_size">42dp</dimen>

    <dimen name="component_shape_thumb_size">72dp</dimen>
    <dimen name="component_shape_border_width">3dp</dimen>
</resources>
+3 −0
Original line number Diff line number Diff line
@@ -122,6 +122,9 @@
    <!-- Title of a page allowing the user to choose a color for a custom theme -->
    <string name="color_component_title">Choose color</string>

    <!-- Title of a page allowing the user to choose an icon shape for a custom theme -->
    <string name="shape_component_title">Choose shape</string>

    <!-- Title of a set of icons that the user can chose for their custom style (eg, "Icons 2") -->
    <string name="icon_component_label">Icons <xliff:g name="component_number" example="1">%1$d</xliff:g></string>

+43 −27
Original line number Diff line number Diff line
@@ -19,12 +19,14 @@ import static com.android.customization.model.ResourceConstants.ACCENT_COLOR_DAR
import static com.android.customization.model.ResourceConstants.ACCENT_COLOR_LIGHT_NAME;
import static com.android.customization.model.ResourceConstants.ANDROID_PACKAGE;
import static com.android.customization.model.ResourceConstants.CONFIG_ICON_MASK;
import static com.android.customization.model.ResourceConstants.OVERLAY_CATEGORY_COLOR;
import static com.android.customization.model.ResourceConstants.ICONS_FOR_PREVIEW;
import static com.android.customization.model.ResourceConstants.OVERLAY_CATEGORY_FONT;
import static com.android.customization.model.ResourceConstants.OVERLAY_CATEGORY_ICON_ANDROID;
import static com.android.customization.model.ResourceConstants.OVERLAY_CATEGORY_ICON_LAUNCHER;
import static com.android.customization.model.ResourceConstants.OVERLAY_CATEGORY_ICON_SETTINGS;
import static com.android.customization.model.ResourceConstants.OVERLAY_CATEGORY_ICON_SYSUI;
import static com.android.customization.model.ResourceConstants.OVERLAY_CATEGORY_SHAPE;
import static com.android.customization.model.ResourceConstants.SETTINGS_PACKAGE;
import static com.android.customization.model.ResourceConstants.SYSUI_PACKAGE;

@@ -70,7 +72,7 @@ public class DefaultThemeProvider extends ResourcesApkProvider implements ThemeB

    private static final String TAG = "DefaultThemeProvider";
    // TODO(b/124796742): remove once custom theme picker is ready to merge
    private static final boolean SHOW_CUSTOM_THEME_OPTION = false;
    private static final boolean SHOW_CUSTOM_THEME_OPTION = true;

    private static final String THEMES_ARRAY = "themes";
    private static final String TITLE_PREFIX = "theme_title_";
@@ -141,37 +143,13 @@ public class DefaultThemeProvider extends ResourcesApkProvider implements ThemeB
                                "string", mStubPackageName)));

                String shapeOverlayPackage = getOverlayPackage(SHAPE_PREFIX, themeName);
                if (!TextUtils.isEmpty(shapeOverlayPackage)) {
                    builder.addOverlayPackage(getOverlayCategory(shapeOverlayPackage),
                                shapeOverlayPackage)
                            .setShapePath(loadString(CONFIG_ICON_MASK, shapeOverlayPackage));
                } else {
                    builder.setShapePath(mContext.getResources().getString(
                            Resources.getSystem().getIdentifier(CONFIG_ICON_MASK, "string",
                                    ANDROID_PACKAGE)));
                }
                for (String packageName : mShapePreviewIconPackages) {
                    try {
                        builder.addShapePreviewIcon(
                                mContext.getPackageManager().getApplicationIcon(packageName));
                    } catch (NameNotFoundException e) {
                        Log.d(TAG, "Couldn't find app " + packageName
                                + ", won't use it for icon shape preview");
                    }
                }
                addShapeOverlay(builder, shapeOverlayPackage);

                String fontOverlayPackage = getOverlayPackage(FONT_PREFIX, themeName);
                addFontOverlay(builder, fontOverlayPackage);

                String colorOverlayPackage = getOverlayPackage(COLOR_PREFIX, themeName);
                if (!TextUtils.isEmpty(colorOverlayPackage)) {
                    builder.addOverlayPackage(getOverlayCategory(colorOverlayPackage),
                                colorOverlayPackage)
                            .setColorAccentLight(loadColor(ACCENT_COLOR_LIGHT_NAME,
                                    colorOverlayPackage))
                            .setColorAccentDark(loadColor(ACCENT_COLOR_DARK_NAME,
                                    colorOverlayPackage));
                }
                addColorOverlay(builder, colorOverlayPackage);

                String iconAndroidOverlayPackage = getOverlayPackage(ICON_ANDROID_PREFIX,
                        themeName);
@@ -224,6 +202,42 @@ public class DefaultThemeProvider extends ResourcesApkProvider implements ThemeB
        }
    }

    private void addColorOverlay(Builder builder, String colorOverlayPackage)
            throws NameNotFoundException {
        if (!TextUtils.isEmpty(colorOverlayPackage)) {
            builder.addOverlayPackage(getOverlayCategory(colorOverlayPackage),
                        colorOverlayPackage)
                    .setColorAccentLight(loadColor(ACCENT_COLOR_LIGHT_NAME,
                            colorOverlayPackage))
                    .setColorAccentDark(loadColor(ACCENT_COLOR_DARK_NAME,
                            colorOverlayPackage));
        } else {
            addSystemDefaultColor(builder);
        }
    }

    private void addShapeOverlay(Builder builder, String shapeOverlayPackage)
            throws NameNotFoundException {
        if (!TextUtils.isEmpty(shapeOverlayPackage)) {
            builder.addOverlayPackage(getOverlayCategory(shapeOverlayPackage),
                        shapeOverlayPackage)
                    .setShapePath(loadString(CONFIG_ICON_MASK, shapeOverlayPackage));
        } else {
            builder.setShapePath(mContext.getResources().getString(
                    Resources.getSystem().getIdentifier(CONFIG_ICON_MASK, "string",
                            ANDROID_PACKAGE)));
        }
        for (String packageName : mShapePreviewIconPackages) {
            try {
                builder.addShapePreviewIcon(
                        mContext.getPackageManager().getApplicationIcon(packageName));
            } catch (NameNotFoundException e) {
                Log.d(TAG, "Couldn't find app " + packageName
                        + ", won't use it for icon shape preview");
            }
        }
    }

    private void addNoPreviewIconOverlay(Builder builder, String overlayPackage) {
        if (!TextUtils.isEmpty(overlayPackage)) {
            builder.addOverlayPackage(getOverlayCategory(overlayPackage),
@@ -461,7 +475,9 @@ public class DefaultThemeProvider extends ResourcesApkProvider implements ThemeB
            }
            CustomTheme.Builder builder = new CustomTheme.Builder();
            builder.setTitle(mContext.getString(R.string.custom_theme_title));
            addShapeOverlay(builder, customPackages.get(OVERLAY_CATEGORY_SHAPE));
            addFontOverlay(builder, customPackages.get(OVERLAY_CATEGORY_FONT));
            addColorOverlay(builder, customPackages.get(OVERLAY_CATEGORY_COLOR));
            addAndroidIconOverlay(builder, customPackages.get(OVERLAY_CATEGORY_ICON_ANDROID));
            addSysUiIconOverlay(builder, customPackages.get(OVERLAY_CATEGORY_ICON_SYSUI));
            addNoPreviewIconOverlay(builder, customPackages.get(OVERLAY_CATEGORY_ICON_SETTINGS));
Loading