-
Notifications
You must be signed in to change notification settings - Fork 10.2k
Expand file tree
/
Copy pathDocumentObject.java
More file actions
162 lines (146 loc) · 6.4 KB
/
Copy pathDocumentObject.java
File metadata and controls
162 lines (146 loc) · 6.4 KB
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
161
162
package org.telegram.messenger;
import android.graphics.Paint;
import android.graphics.Path;
import org.telegram.tgnet.TLRPC;
import org.telegram.ui.ActionBar.Theme;
import java.util.ArrayList;
public class DocumentObject {
public static class ThemeDocument extends TLRPC.TL_document {
public TLRPC.ThemeSettings themeSettings;
public TLRPC.Document wallpaper;
public Theme.ThemeInfo baseTheme;
public Theme.ThemeAccent accent;
public ThemeDocument(TLRPC.ThemeSettings settings) {
themeSettings = settings;
baseTheme = Theme.getTheme(Theme.getBaseThemeKey(settings));
accent = baseTheme.createNewAccent(settings);
if (themeSettings.wallpaper instanceof TLRPC.TL_wallPaper) {
TLRPC.TL_wallPaper object = (TLRPC.TL_wallPaper) themeSettings.wallpaper;
wallpaper = object.document;
id = wallpaper.id;
access_hash = wallpaper.access_hash;
file_reference = wallpaper.file_reference;
user_id = wallpaper.user_id;
date = wallpaper.date;
file_name = wallpaper.file_name;
mime_type = wallpaper.mime_type;
size = wallpaper.size;
thumbs = wallpaper.thumbs;
version = wallpaper.version;
dc_id = wallpaper.dc_id;
key = wallpaper.key;
iv = wallpaper.iv;
attributes = wallpaper.attributes;
} else {
id = Integer.MIN_VALUE;
dc_id = Integer.MIN_VALUE;
}
}
}
public static boolean containsPhotoSizeType(ArrayList<TLRPC.PhotoSize> sizes, String type) {
if (type == null)
return false;
for (int a = 0, N = sizes.size(); a < N; a++) {
TLRPC.PhotoSize photoSize = sizes.get(a);
if (type.equalsIgnoreCase(photoSize.type))
return true;
}
return false;
}
public static SvgHelper.SvgDrawable getSvgThumb(ArrayList<TLRPC.PhotoSize> sizes, int colorKey, float alpha) {
return getSvgThumb(sizes, colorKey, alpha, false);
}
public static SvgHelper.SvgDrawable getSvgThumb(ArrayList<TLRPC.PhotoSize> sizes, int colorKey, float alpha, boolean usePhotoSize) {
int w = 512;
int h = 512;
TLRPC.TL_photoPathSize photoPathSize = null;
for (int a = 0, N = sizes.size(); a < N; a++) {
TLRPC.PhotoSize photoSize = sizes.get(a);
if (photoSize instanceof TLRPC.TL_photoPathSize) {
photoPathSize = (TLRPC.TL_photoPathSize) photoSize;
} else if (photoSize instanceof TLRPC.TL_photoSize && usePhotoSize) {
w = photoSize.w;
h = photoSize.h;
}
}
if (photoPathSize != null && w != 0 && h != 0) {
SvgHelper.SvgDrawable pathThumb = SvgHelper.getDrawableByPath(photoPathSize.svgPath, w, h);
if (pathThumb != null) {
pathThumb.setupGradient(colorKey, alpha, false);
}
return pathThumb;
}
return null;
}
public static SvgHelper.SvgDrawable getCircleThumb(float radius, int colorKey, float alpha) {
return getCircleThumb(radius, colorKey, null, alpha);
}
public static SvgHelper.SvgDrawable getCircleThumb(float radius, int colorKey, Theme.ResourcesProvider resourcesProvider, float alpha) {
try {
SvgHelper.SvgDrawable drawable = new SvgHelper.SvgDrawable();
SvgHelper.Circle circle = new SvgHelper.Circle(256, 256, radius * 512);
drawable.commands.add(circle);
drawable.paints.put(circle, new Paint(Paint.ANTI_ALIAS_FLAG));
drawable.width = 512;
drawable.height = 512;
drawable.setupGradient(colorKey, alpha, false);
return drawable;
} catch (Exception e) {
FileLog.e(e);
return null;
}
}
public static SvgHelper.SvgDrawable getSvgThumb(TLRPC.Document document, int colorKey, float alpha) {
return getSvgThumb(document, colorKey, alpha, 1.0f, null);
}
public static SvgHelper.SvgDrawable getSvgRectThumb(int colorKey, float alpha) {
Path path = new Path();
path.addRect(0, 0, 512, 512, Path.Direction.CW);
path.close();
SvgHelper.SvgDrawable drawable = new SvgHelper.SvgDrawable();
drawable.commands.add(path);
drawable.paints.put(path, new Paint(Paint.ANTI_ALIAS_FLAG));
drawable.width = 512;
drawable.height = 512;
drawable.setupGradient(colorKey, alpha, false);
return drawable;
}
public static SvgHelper.SvgDrawable getSvgThumb(TLRPC.Document document, int colorKey, float alpha, float zoom, Theme.ResourcesProvider resourcesProvider) {
if (document == null) {
return null;
}
SvgHelper.SvgDrawable pathThumb = null;
for (int b = 0, N2 = document.thumbs.size(); b < N2; b++) {
TLRPC.PhotoSize size = document.thumbs.get(b);
if (size instanceof TLRPC.TL_photoPathSize) {
int w = 512, h = 512;
for (int a = 0, N = document.attributes.size(); a < N; a++) {
TLRPC.DocumentAttribute attribute = document.attributes.get(a);
if (
attribute instanceof TLRPC.TL_documentAttributeImageSize ||
attribute instanceof TLRPC.TL_documentAttributeVideo
) {
w = attribute.w;
h = attribute.h;
break;
}
}
if (w != 0 && h != 0) {
pathThumb = SvgHelper.getDrawableByPath(((TLRPC.TL_photoPathSize) size).svgPath, (int) (w * zoom), (int) (h * zoom));
if (pathThumb != null) {
pathThumb.setupGradient(colorKey, resourcesProvider, alpha, false);
}
}
break;
}
}
return pathThumb;
}
public static SvgHelper.SvgDrawable getSvgThumb(int resourceId, int colorKey, float alpha) {
SvgHelper.SvgDrawable pathThumb = SvgHelper.getDrawable(resourceId, 0xffff0000);
if (pathThumb != null) {
pathThumb.setupGradient(colorKey, alpha, false);
}
return pathThumb;
}
}