1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
|
/*
* 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.
*/
package com.android.customization.model.grid;
import android.content.Context;
import android.graphics.PorterDuff.Mode;
import android.net.Uri;
import android.os.Parcel;
import android.os.Parcelable;
import android.text.TextUtils;
import android.view.View;
import android.widget.ImageView;
import androidx.annotation.Nullable;
import com.android.customization.model.CustomizationManager;
import com.android.customization.model.CustomizationOption;
import com.android.customization.widget.GridTileDrawable;
import com.android.wallpaper.R;
import com.android.wallpaper.util.ResourceUtils;
/**
* Represents a grid layout option available in the current launcher.
*/
public class GridOption implements CustomizationOption<GridOption>, Parcelable {
public static final Creator<GridOption> CREATOR = new Creator<GridOption>() {
@Override
public GridOption createFromParcel(Parcel in) {
return new GridOption(in);
}
@Override
public GridOption[] newArray(int size) {
return new GridOption[size];
}
};
private final String mTitle;
private final boolean mIsCurrent;
private final String mIconShapePath;
private final GridTileDrawable mTileDrawable;
public final String name;
public final int rows;
public final int cols;
public final Uri previewImageUri;
public final int previewPagesCount;
public GridOption(String title, String name, boolean isCurrent, int rows, int cols,
Uri previewImageUri, int previewPagesCount, String iconShapePath) {
mTitle = title;
mIsCurrent = isCurrent;
mIconShapePath = iconShapePath;
mTileDrawable = new GridTileDrawable(rows, cols, mIconShapePath);
this.name = name;
this.rows = rows;
this.cols = cols;
this.previewImageUri = previewImageUri;
this.previewPagesCount = previewPagesCount;
}
protected GridOption(Parcel in) {
mTitle = in.readString();
mIsCurrent = in.readByte() != 0;
mIconShapePath = in.readString();
name = in.readString();
rows = in.readInt();
cols = in.readInt();
previewImageUri = in.readParcelable(Uri.class.getClassLoader());
previewPagesCount = in.readInt();
mTileDrawable = new GridTileDrawable(rows, cols, mIconShapePath);
}
@Override
public String getTitle() {
return mTitle;
}
@Override
public void bindThumbnailTile(View view) {
Context context = view.getContext();
int colorFilter = ResourceUtils.getColorAttr(context,
view.isActivated()
? (mIsCurrent
? android.R.attr.textColorPrimary
: android.R.attr.textColorPrimaryInverse)
: android.R.attr.textColorTertiary);
mTileDrawable.setColorFilter(colorFilter, Mode.SRC_ATOP);
((ImageView) view.findViewById(R.id.grid_option_thumbnail))
.setImageDrawable(mTileDrawable);
int backgroundResource = view.isActivated() && !mIsCurrent
? R.drawable.option_border_new_selection : R.drawable.option_border;
view.findViewById(R.id.option_tile).setBackgroundResource(backgroundResource);
}
@Override
public boolean isActive(CustomizationManager<GridOption> manager) {
return mIsCurrent;
}
@Override
public boolean equals(@Nullable Object obj) {
if (this == obj) {
return true;
}
if (obj instanceof GridOption) {
GridOption other = (GridOption) obj;
return TextUtils.equals(this.name, other.name)
&& this.cols == other.cols
&& this.rows == other.rows;
}
return false;
}
@Override
public int getLayoutResId() {
return R.layout.grid_option;
}
@Override
public int describeContents() {
return 0;
}
@Override
public void writeToParcel(Parcel parcel, int i) {
parcel.writeString(mTitle);
parcel.writeByte((byte) (mIsCurrent ? 1 : 0));
parcel.writeString(mIconShapePath);
parcel.writeString(name);
parcel.writeInt(rows);
parcel.writeInt(cols);
parcel.writeParcelable(previewImageUri, i);
parcel.writeInt(previewPagesCount);
}
@Override
public String toString() {
return String.format(
"GridOption{mTitle='%s', mIsCurrent=%s, mTileDrawable=%s, name='%s', rows=%d, "
+ "cols=%d, previewImageUri=%s, previewPagesCount=%d}\n",
mTitle, mIsCurrent, mTileDrawable, name, rows, cols, previewImageUri,
previewPagesCount);
}
}
|