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

Commit 7d2f130d authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Dynamically render color preview card" into ub-launcher3-master

parents ab639850 15e3cfaf
Loading
Loading
Loading
Loading
+152 −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"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="200dp"
    android:layout_height="200dp"
    android:layout_gravity="center"
    android:gravity="center_horizontal|bottom"
    android:orientation="vertical"
    tools:showIn="@layout/theme_preview_card">
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_weight="0"
        android:gravity="center|bottom"
        android:orientation="horizontal">
        <FrameLayout
            android:layout_width="@dimen/preview_theme_icon_size"
            android:layout_height="@dimen/preview_theme_icon_size">
            <ImageView
                android:layout_width="@dimen/preview_theme_icon_size"
                android:layout_height="@dimen/preview_theme_icon_size"
                android:id="@+id/preview_color_qs_0_bg"/>
            <ImageView
                android:layout_width="@dimen/preview_theme_tile_size"
                android:layout_height="@dimen/preview_theme_tile_size"
                android:id="@+id/preview_color_qs_0_icon"
                android:tint="@color/tile_enabled_icon_color"
                android:layout_gravity="center"/>
        </FrameLayout>
        <FrameLayout
            android:layout_width="@dimen/preview_theme_icon_size"
            android:layout_height="@dimen/preview_theme_icon_size"
            android:layout_marginHorizontal="28dp">
            <ImageView
                android:layout_width="@dimen/preview_theme_icon_size"
                android:layout_height="@dimen/preview_theme_icon_size"
                android:id="@+id/preview_color_qs_1_bg"/>
            <ImageView
                android:layout_width="@dimen/preview_theme_tile_size"
                android:layout_height="@dimen/preview_theme_tile_size"
                android:id="@+id/preview_color_qs_1_icon"
                android:tint="@color/tile_enabled_icon_color"
                android:layout_gravity="center"/>
        </FrameLayout>
        <FrameLayout
            android:layout_width="@dimen/preview_theme_icon_size"
            android:layout_height="@dimen/preview_theme_icon_size">
            <ImageView
                android:layout_width="@dimen/preview_theme_icon_size"
                android:layout_height="@dimen/preview_theme_icon_size"
                android:id="@+id/preview_color_qs_2_bg"
                android:tint="@color/tile_disabled_background_color"/>
            <ImageView
                android:layout_width="@dimen/preview_theme_tile_size"
                android:layout_height="@dimen/preview_theme_tile_size"
                android:id="@+id/preview_color_qs_2_icon"
                android:color="@color/tile_disabled_icon_color"
                android:layout_gravity="center"/>
        </FrameLayout>
    </LinearLayout>
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_weight="0"
        android:orientation="horizontal"
        android:layout_marginTop="30dp"
        android:gravity="center|bottom">
        <SeekBar
            android:id="@+id/preview_seekbar"
            android:layout_height="wrap_content"
            android:layout_width="match_parent"
            android:tint="@color/theme_preview_icon_color"
            android:maxHeight="2dp"
            android:progress="1"
            android:max="3"/>
    </LinearLayout>
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_weight="0"
        android:layout_marginTop="15dp"
        android:gravity="center"
        android:orientation="horizontal">
        <CheckBox
            android:id="@+id/preview_check_selected"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:checked="true"
            android:layout_gravity="center"
            android:clickable="false"/>
        <RadioButton
            android:id="@+id/preview_radio_selected"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginLeft="30dp"
            android:layout_marginRight="22dp"
            android:checked="true"
            android:layout_gravity="center"
            android:clickable="false"/>
        <Switch
            android:id="@+id/preview_toggle_selected"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:checked="true"
            android:layout_gravity="center"
            android:clickable="false"/>
    </LinearLayout>
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_weight="0"
        android:layout_marginTop="20dp"
        android:gravity="center"
        android:orientation="horizontal">
        <CheckBox
            android:id="@+id/preview_check_unselected"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:clickable="false"/>
        <RadioButton
            android:id="@+id/preview_radio_unselected"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginLeft="30dp"
            android:layout_marginRight="22dp"
            android:layout_gravity="center"
            android:clickable="false"/>
        <Switch
            android:id="@+id/preview_toggle_unselected"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:clickable="false"/>
    </LinearLayout>
</LinearLayout>
+5 −1
Original line number Diff line number Diff line
@@ -19,4 +19,8 @@
    <color name="theme_preview_icon_color">@color/white_70_alpha</color>

    <color name="icon_thumbnail_color">@color/white_70_alpha</color>

    <color name="tile_enabled_icon_color">#2d2d2d</color>
    <color name="tile_disabled_icon_color">@color/light_grey</color>
    <color name="tile_disabled_background_color">#353535</color>
</resources>
+4 −0
Original line number Diff line number Diff line
@@ -34,4 +34,8 @@

    <color name="text_color_dark">#2d2d2d</color>
    <color name="text_color_light">@color/material_white_text</color>

    <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>
</resources>
+1 −0
Original line number Diff line number Diff line
@@ -59,6 +59,7 @@

    <dimen name="card_title_text_size">16sp</dimen>
    <dimen name="preview_theme_icon_size">40dp</dimen>
    <dimen name="preview_theme_tile_size">20dp</dimen>

    <dimen name="color_preview_image_width">182dp</dimen>
    <dimen name="color_preview_image_height">194dp</dimen>
+53 −8
Original line number Diff line number Diff line
@@ -23,6 +23,7 @@ import android.content.res.ColorStateList;
import android.content.res.Resources;
import android.graphics.Bitmap;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
@@ -32,6 +33,8 @@ import android.view.ViewGroup;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.ImageView;
import android.widget.SeekBar;
import android.widget.Switch;
import android.widget.TextView;
import android.widget.Toast;

@@ -267,6 +270,15 @@ public class ThemeFragment extends ToolbarFragment {
                R.id.preview_icon_0, R.id.preview_icon_1, R.id.preview_icon_2, R.id.preview_icon_3,
                R.id.preview_icon_4, R.id.preview_icon_5
        };
        private int[] mColorButtonIds = {
            R.id.preview_check_selected, R.id.preview_radio_selected, R.id.preview_toggle_selected,
        };
        private int[] mColorTileIds = {
            R.id.preview_color_qs_0_bg, R.id.preview_color_qs_1_bg, R.id.preview_color_qs_2_bg
        };
        private int[] mColorTileIconIds = {
            R.id.preview_color_qs_0_icon, R.id.preview_color_qs_1_icon, R.id.preview_color_qs_2_icon
        };

        ThemePreviewAdapter(Activity activity, ThemeBundle theme) {
            super(activity, R.layout.theme_preview_card);
@@ -298,17 +310,50 @@ public class ThemeFragment extends ToolbarFragment {
            }
            if (previewInfo.colorPreviewAsset != null) {
                addPage(new ThemePreviewPage(activity, R.string.preview_name_color,
                        R.drawable.ic_colorize_24px, R.layout.preview_card_static_content,
                        R.drawable.ic_colorize_24px, R.layout.preview_card_color_content,
                        previewInfo.resolveAccentColor(res)) {
                    @Override
                    protected void bindBody(boolean forceRebind) {
                        ImageView staticImage = card.findViewById(R.id.preview_static_image);
                        previewInfo.colorPreviewAsset.loadDrawable(activity,
                                staticImage, card.getCardBackgroundColor().getDefaultColor());
                        staticImage.getLayoutParams().width = res.getDimensionPixelSize(
                                R.dimen.color_preview_image_width);
                        staticImage.getLayoutParams().height = res.getDimensionPixelSize(
                                R.dimen.color_preview_image_height);
                        ColorStateList tintList = new ColorStateList(
                                new int[][]{
                                    new int[]{android.R.attr.state_selected},
                                    new int[]{android.R.attr.state_checked}
                                },
                                new int[] {
                                    accentColor,
                                    accentColor
                                }
                            );

                        for (int i = 0; i < mColorButtonIds.length; i++) {
                            CompoundButton button = card.findViewById(mColorButtonIds[i]);
                            button.setButtonTintList(tintList);
                        }

                        Switch switch1 = card.findViewById(R.id.preview_toggle_selected);
                        switch1.setThumbTintList(tintList);
                        switch1.setTrackTintList(tintList);

                        ColorStateList seekbarTintList = ColorStateList.valueOf(accentColor);
                        SeekBar seekbar = card.findViewById(R.id.preview_seekbar);
                        seekbar.setThumbTintList(seekbarTintList);
                        seekbar.setProgressTintList(seekbarTintList);
                        seekbar.setProgressBackgroundTintList(seekbarTintList);
                        // Disable seekbar
                        seekbar.setOnTouchListener((view, motionEvent) -> true);

                        for (int i = 0; i < mColorTileIds.length; i++) {
                            Drawable icon =
                                previewInfo.icons.get(i).getConstantState().newDrawable();
                            Drawable bgShape =
                                previewInfo.shapeDrawable.getConstantState().newDrawable();
                            bgShape.setTint(accentColor);

                            ImageView bg = card.findViewById(mColorTileIds[i]);
                            bg.setImageDrawable(bgShape);
                            ImageView fg = card.findViewById(mColorTileIconIds[i]);
                            fg.setImageDrawable(icon);
                        }
                    }
                });
            }