1 /*
2  * Copyright (C) 2020 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 package com.android.customization.picker.theme;
17 
18 import android.content.Context;
19 import android.content.res.ColorStateList;
20 import android.util.AttributeSet;
21 import android.widget.ImageView;
22 import android.widget.LinearLayout;
23 import android.widget.TextView;
24 
25 import androidx.annotation.NonNull;
26 import androidx.annotation.Nullable;
27 
28 import com.android.customization.model.theme.ThemeBundle;
29 import com.android.wallpaper.R;
30 
31 /** A view for displaying style info. */
32 public class ThemeInfoView extends LinearLayout {
33     private static final int WIFI_ICON_PREVIEW_INDEX = 0;
34     private static final int SHAPE_PREVIEW_INDEX = 0;
35 
36     private TextView mTitle;
37     private TextView mFontPreviewTextView;
38     private ImageView mIconPreviewImageView;
39     private ImageView mAppPreviewImageView;
40     private ImageView mShapePreviewImageView;
41 
ThemeInfoView(Context context, @Nullable AttributeSet attrs)42     public ThemeInfoView(Context context, @Nullable AttributeSet attrs) {
43         super(context, attrs);
44     }
45 
46     @Override
onFinishInflate()47     protected void onFinishInflate() {
48         super.onFinishInflate();
49         mTitle = findViewById(R.id.style_info_title);
50         mFontPreviewTextView = findViewById(R.id.font_preview);
51         mIconPreviewImageView = findViewById(R.id.qs_preview_icon);
52         mAppPreviewImageView = findViewById(R.id.app_preview_icon);
53         mShapePreviewImageView = findViewById(R.id.shape_preview_icon);
54     }
55 
56     /** Populates theme info. */
populateThemeInfo(@onNull ThemeBundle selectedTheme)57     public void populateThemeInfo(@NonNull ThemeBundle selectedTheme) {
58         ThemeBundle.PreviewInfo previewInfo = selectedTheme.getPreviewInfo();
59 
60         if (previewInfo != null) {
61             mTitle.setText(getContext().getString(R.string.style_info_description));
62             if (previewInfo.headlineFontFamily != null) {
63                 mTitle.setTypeface(previewInfo.headlineFontFamily);
64                 mFontPreviewTextView.setTypeface(previewInfo.headlineFontFamily);
65             }
66 
67             if (previewInfo.icons.get(WIFI_ICON_PREVIEW_INDEX) != null) {
68                 mIconPreviewImageView.setImageDrawable(
69                         previewInfo.icons.get(WIFI_ICON_PREVIEW_INDEX));
70             }
71 
72             if (previewInfo.shapeAppIcons.get(SHAPE_PREVIEW_INDEX) != null) {
73                 mAppPreviewImageView.setBackground(
74                         previewInfo.shapeAppIcons.get(SHAPE_PREVIEW_INDEX).getDrawableCopy());
75             }
76 
77             if (previewInfo.shapeDrawable != null) {
78                 mShapePreviewImageView.setImageDrawable(previewInfo.shapeDrawable);
79                 mShapePreviewImageView.setImageTintList(
80                         ColorStateList.valueOf(previewInfo.resolveAccentColor(getResources())));
81             }
82         }
83     }
84 }
85