-
Notifications
You must be signed in to change notification settings - Fork 0
/
EmojiViewBackup.java
309 lines (275 loc) · 11 KB
/
EmojiViewBackup.java
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
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
/*
* This is the source code of Telegram for Android v. 1.3.2.
* It is licensed under GNU GPL v. 2 or later.
* You should have received a copy of the license in this archive (see LICENSE).
*
* Copyright Nikolai Kudashov, 2013.
*/
package org.tomato1.fbtext.ui;
import java.util.ArrayList;
import org.tomato1.fbtext.R;
import android.annotation.TargetApi;
import android.content.Context;
import android.database.DataSetObserver;
import android.graphics.drawable.GradientDrawable;
import android.os.Build;
import android.support.v4.view.PagerAdapter;
import android.support.v4.view.ViewPager;
import android.text.TextUtils;
import android.util.AttributeSet;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.FrameLayout;
import android.widget.GridView;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
public class EmojiView extends LinearLayout {
private ArrayList<EmojiGridAdapter> adapters = new ArrayList<EmojiGridAdapter>();
private int[] icons = {
R.drawable.ic_emoji_recent,
R.drawable.ic_emoji_smile,
R.drawable.ic_emoji_flower,
R.drawable.ic_emoji_bell,
R.drawable.ic_emoji_car,
R.drawable.ic_emoji_symbol };
private Listener listener;
private ViewPager pager;
private FrameLayout recentsWrap;
private ArrayList<GridView> views = new ArrayList<GridView>();
public EmojiView(Context paramContext) {
super(paramContext);
init();
}
public EmojiView(Context paramContext, AttributeSet paramAttributeSet) {
super(paramContext, paramAttributeSet);
init();
}
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
public EmojiView(Context paramContext, AttributeSet paramAttributeSet, int paramInt) {
super(paramContext, paramAttributeSet, paramInt);
init();
}
private void addToRecent(long paramLong) {
if (this.pager.getCurrentItem() == 0) {
return;
}
ArrayList<Long> localArrayList = new ArrayList<Long>();
long[] currentRecent = Emoji.data[0];
boolean was = false;
for (long aCurrentRecent : currentRecent) {
if (paramLong == aCurrentRecent) {
localArrayList.add(0, paramLong);
was = true;
} else {
localArrayList.add(aCurrentRecent);
}
}
if (!was) {
localArrayList.add(0, paramLong);
}
Emoji.data[0] = new long[Math.min(localArrayList.size(), 50)];
for (int q = 0; q < Emoji.data[0].length; q++) {
Emoji.data[0][q] = localArrayList.get(q);
}
adapters.get(0).data = Emoji.data[0];
adapters.get(0).notifyDataSetChanged();
saveRecents();
}
private String convert(long paramLong) {
String str = "";
for (int i = 0; ; i++) {
if (i >= 4) {
return str;
}
int j = (int)(0xFFFF & paramLong >> 16 * (3 - i));
if (j != 0) {
str = str + (char)j;
}
}
}
private void init() {
setOrientation(LinearLayout.VERTICAL);
for (int i = 0; i < Emoji.data.length; i++) {
GridView gridView = new GridView(getContext());
if (Utils.isTablet()) {
gridView.setColumnWidth(Utils.dp(60));
} else {
gridView.setColumnWidth(Utils.dp(45));
}
gridView.setNumColumns(-1);
views.add(gridView);
EmojiGridAdapter localEmojiGridAdapter = new EmojiGridAdapter(Emoji.data[i]);
gridView.setAdapter(localEmojiGridAdapter);
adapters.add(localEmojiGridAdapter);
}
setBackgroundDrawable(new GradientDrawable(GradientDrawable.Orientation.TOP_BOTTOM, new int[] { -14145496, -16777216 }));
pager = new ViewPager(getContext());
pager.setAdapter(new EmojiPagesAdapter());
PagerSlidingTabStrip tabs = new PagerSlidingTabStrip(getContext());
tabs.setViewPager(pager);
tabs.setShouldExpand(true);
tabs.setIndicatorColor(0xff33b5e5);
tabs.setIndicatorHeight(Utils.dpf(2.0f));
tabs.setUnderlineHeight(Utils.dpf(2.0f));
tabs.setUnderlineColor(0x66000000);
tabs.setTabBackground(0);
LinearLayout localLinearLayout = new LinearLayout(getContext());
localLinearLayout.setOrientation(LinearLayout.HORIZONTAL);
localLinearLayout.addView(tabs, new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT, 1.0f));
ImageView localImageView = new ImageView(getContext());
localImageView.setImageResource(R.drawable.ic_emoji_backspace);
localImageView.setScaleType(ImageView.ScaleType.CENTER);
localImageView.setBackgroundResource(R.drawable.bg_emoji_bs);
localImageView.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
if (EmojiView.this.listener != null) {
EmojiView.this.listener.onBackspace();
}
}
});
localLinearLayout.addView(localImageView, new LinearLayout.LayoutParams(Utils.dp(61), LayoutParams.MATCH_PARENT));
recentsWrap = new FrameLayout(getContext());
recentsWrap.addView(views.get(0));
TextView localTextView = new TextView(getContext());
localTextView.setText("No recent");
localTextView.setTextSize(18.0f);
localTextView.setTextColor(-7829368);
localTextView.setGravity(17);
recentsWrap.addView(localTextView);
views.get(0).setEmptyView(localTextView);
addView(localLinearLayout, new LinearLayout.LayoutParams(-1, Utils.dpf(48.0f)));
addView(pager);
loadRecents();
if (Emoji.data[0] == null || Emoji.data[0].length == 0) {
pager.setCurrentItem(1);
}
}
private void saveRecents() {
ArrayList<Long> localArrayList = new ArrayList<Long>();
long[] arrayOfLong = Emoji.data[0];
int i = arrayOfLong.length;
for (int j = 0; ; j++) {
if (j >= i) {
getContext().getSharedPreferences("emoji", 0).edit().putString("recents", TextUtils.join(",", localArrayList)).commit();
return;
}
localArrayList.add(arrayOfLong[j]);
}
}
public void loadRecents() {
String str = getContext().getSharedPreferences("emoji", 0).getString("recents", "");
String[] arrayOfString = null;
if ((str != null) && (str.length() > 0)) {
arrayOfString = str.split(",");
Emoji.data[0] = new long[arrayOfString.length];
}
if (arrayOfString != null) {
for (int i = 0; i < arrayOfString.length; i++) {
Emoji.data[0][i] = Long.parseLong(arrayOfString[i]);
}
adapters.get(0).data = Emoji.data[0];
adapters.get(0).notifyDataSetChanged();
}
}
public void onMeasure(int paramInt1, int paramInt2) {
super.onMeasure(View.MeasureSpec.makeMeasureSpec(View.MeasureSpec.getSize(paramInt1), MeasureSpec.EXACTLY), View.MeasureSpec.makeMeasureSpec(View.MeasureSpec.getSize(paramInt2), MeasureSpec.EXACTLY));
}
public void setListener(Listener paramListener) {
this.listener = paramListener;
}
public void invalidateViews() {
for (GridView gridView : views) {
if (gridView != null) {
gridView.invalidateViews();
}
}
}
private class EmojiGridAdapter extends BaseAdapter {
long[] data;
public EmojiGridAdapter(long[] arg2) {
this.data = arg2;
}
public int getCount() {
return data.length;
}
public Object getItem(int i) {
return null;
}
public long getItemId(int i) {
return data[i];
}
public View getView(int i, View view, ViewGroup paramViewGroup) {
ImageView imageView = (ImageView)view;
if (imageView == null) {
imageView = new ImageView(EmojiView.this.getContext()) {
public void onMeasure(int paramAnonymousInt1, int paramAnonymousInt2) {
setMeasuredDimension(View.MeasureSpec.getSize(paramAnonymousInt1), View.MeasureSpec.getSize(paramAnonymousInt1));
}
};
imageView.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
if (EmojiView.this.listener != null) {
EmojiView.this.listener.onEmojiSelected(EmojiView.this.convert((Long)view.getTag()));
}
EmojiView.this.addToRecent((Long)view.getTag());
}
});
imageView.setBackgroundResource(R.drawable.list_selector);
imageView.setScaleType(ImageView.ScaleType.CENTER);
}
imageView.setImageDrawable(Emoji.getEmojiBigDrawable(data[i]));
imageView.setTag(data[i]);
return imageView;
}
@Override
public void unregisterDataSetObserver(DataSetObserver observer) {
if (observer != null) {
super.unregisterDataSetObserver(observer);
}
}
}
private class EmojiPagesAdapter extends PagerAdapter implements PagerSlidingTabStrip.IconTabProvider {
private EmojiPagesAdapter() {
}
public void destroyItem(ViewGroup paramViewGroup, int paramInt, Object paramObject) {
View localObject;
if (paramInt == 0) {
localObject = EmojiView.this.recentsWrap;
} else {
localObject = EmojiView.this.views.get(paramInt);
}
paramViewGroup.removeView(localObject);
}
public int getCount() {
return EmojiView.this.views.size();
}
public int getPageIconResId(int paramInt) {
return EmojiView.this.icons[paramInt];
}
public Object instantiateItem(ViewGroup paramViewGroup, int paramInt) {
View localObject;
if (paramInt == 0) {
localObject = EmojiView.this.recentsWrap;
} else {
localObject = EmojiView.this.views.get(paramInt);
}
paramViewGroup.addView(localObject);
return localObject;
}
public boolean isViewFromObject(View paramView, Object paramObject) {
return paramView == paramObject;
}
@Override
public void unregisterDataSetObserver(DataSetObserver observer) {
if (observer != null) {
super.unregisterDataSetObserver(observer);
}
}
}
public static abstract interface Listener {
public abstract void onBackspace();
public abstract void onEmojiSelected(String paramString);
}
}