2013-10-25 17:19:00 +02:00
|
|
|
/*
|
2013-12-20 20:25:49 +01:00
|
|
|
* This is the source code of Telegram for Android v. 1.3.2.
|
2013-10-25 17:19:00 +02:00
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
2014-12-01 18:56:31 +01:00
|
|
|
package org.telegram.ui.Components;
|
2013-10-25 17:19:00 +02:00
|
|
|
|
2015-05-21 23:27:27 +02:00
|
|
|
import android.app.Activity;
|
2013-10-25 17:19:00 +02:00
|
|
|
import android.content.Context;
|
2015-05-21 23:27:27 +02:00
|
|
|
import android.content.SharedPreferences;
|
2014-06-20 02:18:13 +02:00
|
|
|
import android.database.DataSetObserver;
|
2015-06-29 19:12:11 +02:00
|
|
|
import android.os.Build;
|
2013-10-25 17:19:00 +02:00
|
|
|
import android.support.v4.view.PagerAdapter;
|
|
|
|
import android.support.v4.view.ViewPager;
|
|
|
|
import android.text.TextUtils;
|
2015-06-29 19:12:11 +02:00
|
|
|
import android.util.TypedValue;
|
2015-05-03 13:48:36 +02:00
|
|
|
import android.view.Gravity;
|
|
|
|
import android.view.HapticFeedbackConstants;
|
|
|
|
import android.view.MotionEvent;
|
2013-10-25 17:19:00 +02:00
|
|
|
import android.view.View;
|
|
|
|
import android.view.ViewGroup;
|
2015-06-29 19:12:11 +02:00
|
|
|
import android.widget.AbsListView;
|
2013-10-25 17:19:00 +02:00
|
|
|
import android.widget.BaseAdapter;
|
|
|
|
import android.widget.FrameLayout;
|
|
|
|
import android.widget.GridView;
|
|
|
|
import android.widget.ImageView;
|
|
|
|
import android.widget.LinearLayout;
|
|
|
|
import android.widget.TextView;
|
|
|
|
|
2014-07-03 00:39:05 +02:00
|
|
|
import org.telegram.android.AndroidUtilities;
|
2015-06-29 19:12:11 +02:00
|
|
|
import org.telegram.android.AnimationCompat.ViewProxy;
|
2014-07-03 00:39:05 +02:00
|
|
|
import org.telegram.android.Emoji;
|
|
|
|
import org.telegram.android.LocaleController;
|
2015-05-03 13:48:36 +02:00
|
|
|
import org.telegram.android.NotificationCenter;
|
|
|
|
import org.telegram.android.query.StickersQuery;
|
2015-05-21 23:27:27 +02:00
|
|
|
import org.telegram.messenger.FileLog;
|
2013-10-25 17:19:00 +02:00
|
|
|
import org.telegram.messenger.R;
|
2015-05-03 13:48:36 +02:00
|
|
|
import org.telegram.messenger.TLRPC;
|
2015-06-29 19:12:11 +02:00
|
|
|
import org.telegram.ui.Cells.EmptyCell;
|
2015-05-03 13:48:36 +02:00
|
|
|
import org.telegram.ui.Cells.StickerEmojiCell;
|
2013-10-25 17:19:00 +02:00
|
|
|
|
|
|
|
import java.util.ArrayList;
|
2015-05-21 23:27:27 +02:00
|
|
|
import java.util.Collections;
|
|
|
|
import java.util.Comparator;
|
|
|
|
import java.util.HashMap;
|
2013-10-25 17:19:00 +02:00
|
|
|
|
2015-06-29 19:12:11 +02:00
|
|
|
public class EmojiView extends FrameLayout implements NotificationCenter.NotificationCenterDelegate {
|
2015-05-03 13:48:36 +02:00
|
|
|
|
|
|
|
public interface Listener {
|
|
|
|
boolean onBackspace();
|
|
|
|
void onEmojiSelected(String emoji);
|
|
|
|
void onStickerSelected(TLRPC.Document sticker);
|
|
|
|
}
|
2015-04-09 20:00:14 +02:00
|
|
|
|
|
|
|
private ArrayList<EmojiGridAdapter> adapters = new ArrayList<>();
|
2015-05-21 23:27:27 +02:00
|
|
|
private HashMap<Long, Integer> stickersUseHistory = new HashMap<>();
|
2015-06-29 19:12:11 +02:00
|
|
|
private ArrayList<TLRPC.Document> recentStickers = new ArrayList<>();
|
|
|
|
private ArrayList<TLRPC.TL_messages_stickerSet> stickerSets = new ArrayList<>();
|
2015-05-21 23:27:27 +02:00
|
|
|
|
2013-10-25 17:19:00 +02:00
|
|
|
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,
|
2015-05-03 13:48:36 +02:00
|
|
|
R.drawable.ic_emoji_symbol,
|
|
|
|
R.drawable.ic_emoji_sticker};
|
|
|
|
|
2013-10-25 17:19:00 +02:00
|
|
|
private Listener listener;
|
|
|
|
private ViewPager pager;
|
|
|
|
private FrameLayout recentsWrap;
|
2015-06-29 19:12:11 +02:00
|
|
|
private FrameLayout stickersWrap;
|
2015-04-09 20:00:14 +02:00
|
|
|
private ArrayList<GridView> views = new ArrayList<>();
|
2015-05-03 13:48:36 +02:00
|
|
|
private ImageView backspaceButton;
|
2015-06-29 19:12:11 +02:00
|
|
|
private StickersGridAdapter stickersGridAdapter;
|
|
|
|
private LinearLayout pagerSlidingTabStripContainer;
|
|
|
|
private ScrollSlidingTabStrip scrollSlidingTabStrip;
|
|
|
|
|
|
|
|
private int oldWidth;
|
|
|
|
private int lastNotifyWidth;
|
2013-10-25 17:19:00 +02:00
|
|
|
|
2015-05-03 13:48:36 +02:00
|
|
|
private boolean backspacePressed;
|
|
|
|
private boolean backspaceOnce;
|
2015-05-21 23:27:27 +02:00
|
|
|
private boolean showStickers;
|
2015-05-03 13:48:36 +02:00
|
|
|
|
|
|
|
public EmojiView(boolean needStickers, Context context) {
|
|
|
|
super(context);
|
|
|
|
|
2015-05-21 23:27:27 +02:00
|
|
|
showStickers = needStickers;
|
|
|
|
|
2015-05-03 13:48:36 +02:00
|
|
|
for (int i = 0; i < Emoji.data.length; i++) {
|
|
|
|
GridView gridView = new GridView(context);
|
|
|
|
if (AndroidUtilities.isTablet()) {
|
|
|
|
gridView.setColumnWidth(AndroidUtilities.dp(60));
|
|
|
|
} else {
|
|
|
|
gridView.setColumnWidth(AndroidUtilities.dp(45));
|
|
|
|
}
|
|
|
|
gridView.setNumColumns(-1);
|
|
|
|
views.add(gridView);
|
|
|
|
|
|
|
|
EmojiGridAdapter emojiGridAdapter = new EmojiGridAdapter(Emoji.data[i]);
|
|
|
|
gridView.setAdapter(emojiGridAdapter);
|
|
|
|
AndroidUtilities.setListViewEdgeEffectColor(gridView, 0xfff5f6f7);
|
|
|
|
adapters.add(emojiGridAdapter);
|
|
|
|
}
|
|
|
|
|
2015-05-21 23:27:27 +02:00
|
|
|
if (showStickers) {
|
|
|
|
StickersQuery.checkStickers();
|
2015-05-03 13:48:36 +02:00
|
|
|
GridView gridView = new GridView(context);
|
|
|
|
gridView.setColumnWidth(AndroidUtilities.dp(72));
|
|
|
|
gridView.setNumColumns(-1);
|
|
|
|
gridView.setPadding(0, AndroidUtilities.dp(4), 0, 0);
|
|
|
|
gridView.setClipToPadding(false);
|
|
|
|
views.add(gridView);
|
|
|
|
stickersGridAdapter = new StickersGridAdapter(context);
|
|
|
|
gridView.setAdapter(stickersGridAdapter);
|
|
|
|
AndroidUtilities.setListViewEdgeEffectColor(gridView, 0xfff5f6f7);
|
2015-06-29 19:12:11 +02:00
|
|
|
|
|
|
|
stickersWrap = new FrameLayout(context);
|
|
|
|
stickersWrap.addView(gridView);
|
|
|
|
|
|
|
|
TextView textView = new TextView(context);
|
|
|
|
textView.setText(LocaleController.getString("NoStickers", R.string.NoStickers));
|
|
|
|
textView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 18);
|
|
|
|
textView.setTextColor(0xff888888);
|
|
|
|
stickersWrap.addView(textView, LayoutHelper.createFrame(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT, Gravity.CENTER));
|
|
|
|
gridView.setEmptyView(textView);
|
|
|
|
|
|
|
|
scrollSlidingTabStrip = new ScrollSlidingTabStrip(context) {
|
|
|
|
|
|
|
|
boolean startedScroll;
|
|
|
|
float lastX;
|
|
|
|
float lastTranslateX;
|
|
|
|
boolean first = true;
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean onInterceptTouchEvent(MotionEvent ev) {
|
|
|
|
if (getParent() != null) {
|
|
|
|
getParent().requestDisallowInterceptTouchEvent(true);
|
|
|
|
}
|
|
|
|
return super.onInterceptTouchEvent(ev);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean onTouchEvent(MotionEvent ev) {
|
|
|
|
if (Build.VERSION.SDK_INT >= 11) {
|
|
|
|
if (first) {
|
|
|
|
first = false;
|
|
|
|
lastX = ev.getX();
|
|
|
|
}
|
|
|
|
float newTranslationX = ViewProxy.getTranslationX(scrollSlidingTabStrip);
|
|
|
|
if (scrollSlidingTabStrip.getScrollX() == 0 && newTranslationX == 0) {
|
|
|
|
if (!startedScroll && lastX - ev.getX() < 0) {
|
|
|
|
if (pager.beginFakeDrag()) {
|
|
|
|
startedScroll = true;
|
|
|
|
lastTranslateX = ViewProxy.getTranslationX(scrollSlidingTabStrip);
|
|
|
|
}
|
|
|
|
} else if (startedScroll && lastX - ev.getX() > 0) {
|
|
|
|
if (pager.isFakeDragging()) {
|
|
|
|
pager.endFakeDrag();
|
|
|
|
startedScroll = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (startedScroll) {
|
|
|
|
int dx = (int) (ev.getX() - lastX + newTranslationX - lastTranslateX);
|
|
|
|
try {
|
|
|
|
pager.fakeDragBy(dx);
|
|
|
|
lastTranslateX = newTranslationX;
|
|
|
|
} catch (Exception e) {
|
|
|
|
try {
|
|
|
|
pager.endFakeDrag();
|
|
|
|
} catch (Exception e2) {
|
|
|
|
//don't promt
|
|
|
|
}
|
|
|
|
startedScroll = false;
|
|
|
|
FileLog.e("tmessages", e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
lastX = ev.getX();
|
|
|
|
if (ev.getAction() == MotionEvent.ACTION_CANCEL || ev.getAction() == MotionEvent.ACTION_UP) {
|
|
|
|
first = true;
|
|
|
|
if (startedScroll) {
|
|
|
|
pager.endFakeDrag();
|
|
|
|
startedScroll = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return startedScroll || super.onTouchEvent(ev);
|
|
|
|
}
|
|
|
|
return super.onTouchEvent(ev);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
scrollSlidingTabStrip.setUnderlineHeight(AndroidUtilities.dp(1));
|
|
|
|
scrollSlidingTabStrip.setIndicatorColor(0xffe2e5e7);
|
|
|
|
scrollSlidingTabStrip.setUnderlineColor(0xffe2e5e7);
|
|
|
|
addView(scrollSlidingTabStrip, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, 48, Gravity.LEFT | Gravity.TOP));
|
|
|
|
ViewProxy.setTranslationX(scrollSlidingTabStrip, AndroidUtilities.displaySize.x);
|
|
|
|
updateStickerTabs();
|
|
|
|
scrollSlidingTabStrip.setDelegate(new ScrollSlidingTabStrip.ScrollSlidingTabStripDelegate() {
|
|
|
|
@Override
|
|
|
|
public void onPageSelected(int page) {
|
|
|
|
if (page == 0) {
|
|
|
|
pager.setCurrentItem(0);
|
|
|
|
return;
|
|
|
|
} else if (page == 1 && !recentStickers.isEmpty()) {
|
|
|
|
views.get(6).setSelection(0);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
int index = page - (recentStickers.isEmpty() ? 1 : 2);
|
|
|
|
if (index >= stickerSets.size()) {
|
|
|
|
index = stickerSets.size() - 1;
|
|
|
|
}
|
|
|
|
views.get(6).setSelection(stickersGridAdapter.getPositionForPack(stickerSets.get(index)));
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
gridView.setOnScrollListener(new AbsListView.OnScrollListener() {
|
|
|
|
@Override
|
|
|
|
public void onScrollStateChanged(AbsListView view, int scrollState) {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) {
|
|
|
|
int count = view.getChildCount();
|
|
|
|
for (int a = 0; a < count; a++) {
|
|
|
|
View child = view.getChildAt(a);
|
|
|
|
if (child.getHeight() + child.getTop() < AndroidUtilities.dp(5)) {
|
|
|
|
firstVisibleItem++;
|
|
|
|
} else {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
scrollSlidingTabStrip.onPageScrolled(stickersGridAdapter.getTabForPosition(firstVisibleItem) + 1, 0);
|
|
|
|
}
|
|
|
|
});
|
2015-05-03 13:48:36 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
setBackgroundColor(0xfff5f6f7);
|
2013-10-25 17:19:00 +02:00
|
|
|
|
2015-06-29 19:12:11 +02:00
|
|
|
pager = new ViewPager(context) {
|
|
|
|
@Override
|
|
|
|
public boolean onInterceptTouchEvent(MotionEvent ev) {
|
|
|
|
if (getParent() != null) {
|
|
|
|
getParent().requestDisallowInterceptTouchEvent(true);
|
|
|
|
}
|
|
|
|
return super.onInterceptTouchEvent(ev);
|
|
|
|
}
|
|
|
|
};
|
2015-05-03 13:48:36 +02:00
|
|
|
pager.setAdapter(new EmojiPagesAdapter());
|
|
|
|
|
2015-06-29 19:12:11 +02:00
|
|
|
pagerSlidingTabStripContainer = new LinearLayout(context) {
|
|
|
|
@Override
|
|
|
|
public boolean onInterceptTouchEvent(MotionEvent ev) {
|
|
|
|
if (getParent() != null) {
|
|
|
|
getParent().requestDisallowInterceptTouchEvent(true);
|
|
|
|
}
|
|
|
|
return super.onInterceptTouchEvent(ev);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
pagerSlidingTabStripContainer.setOrientation(LinearLayout.HORIZONTAL);
|
|
|
|
pagerSlidingTabStripContainer.setBackgroundColor(0xfff5f6f7);
|
|
|
|
addView(pagerSlidingTabStripContainer, LayoutHelper.createFrame(LayoutParams.MATCH_PARENT, 48));
|
|
|
|
|
|
|
|
PagerSlidingTabStrip pagerSlidingTabStrip = new PagerSlidingTabStrip(context);
|
|
|
|
pagerSlidingTabStrip.setViewPager(pager);
|
|
|
|
pagerSlidingTabStrip.setShouldExpand(true);
|
|
|
|
pagerSlidingTabStrip.setIndicatorHeight(AndroidUtilities.dp(2));
|
|
|
|
pagerSlidingTabStrip.setUnderlineHeight(AndroidUtilities.dp(1));
|
|
|
|
pagerSlidingTabStrip.setIndicatorColor(0xff2b96e2);
|
|
|
|
pagerSlidingTabStrip.setUnderlineColor(0xffe2e5e7);
|
|
|
|
pagerSlidingTabStripContainer.addView(pagerSlidingTabStrip, LayoutHelper.createLinear(0, 48, 1.0f));
|
|
|
|
pagerSlidingTabStrip.setOnPageChangeListener(new ViewPager.OnPageChangeListener() {
|
|
|
|
@Override
|
|
|
|
public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
|
|
|
|
EmojiView.this.onPageScrolled(position, getMeasuredWidth(), positionOffsetPixels);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onPageSelected(int position) {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onPageScrollStateChanged(int state) {
|
2015-05-03 13:48:36 +02:00
|
|
|
|
2015-06-29 19:12:11 +02:00
|
|
|
}
|
|
|
|
});
|
2015-05-03 13:48:36 +02:00
|
|
|
|
|
|
|
FrameLayout frameLayout = new FrameLayout(context);
|
2015-06-29 19:12:11 +02:00
|
|
|
pagerSlidingTabStripContainer.addView(frameLayout, LayoutHelper.createLinear(52, 48));
|
2015-05-03 13:48:36 +02:00
|
|
|
|
|
|
|
backspaceButton = new ImageView(context) {
|
|
|
|
@Override
|
|
|
|
public boolean onTouchEvent(MotionEvent event) {
|
|
|
|
if (event.getAction() == MotionEvent.ACTION_DOWN) {
|
|
|
|
backspacePressed = true;
|
|
|
|
backspaceOnce = false;
|
|
|
|
postBackspaceRunnable(350);
|
|
|
|
} else if (event.getAction() == MotionEvent.ACTION_CANCEL || event.getAction() == MotionEvent.ACTION_UP) {
|
|
|
|
backspacePressed = false;
|
|
|
|
if (!backspaceOnce) {
|
|
|
|
if (EmojiView.this.listener != null && EmojiView.this.listener.onBackspace()) {
|
|
|
|
backspaceButton.performHapticFeedback(HapticFeedbackConstants.KEYBOARD_TAP);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
super.onTouchEvent(event);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
backspaceButton.setImageResource(R.drawable.ic_smiles_backspace);
|
|
|
|
backspaceButton.setBackgroundResource(R.drawable.ic_emoji_backspace);
|
|
|
|
backspaceButton.setScaleType(ImageView.ScaleType.CENTER);
|
2015-06-29 19:12:11 +02:00
|
|
|
frameLayout.addView(backspaceButton, LayoutHelper.createFrame(52, 48));
|
2015-05-03 13:48:36 +02:00
|
|
|
|
|
|
|
View view = new View(context);
|
|
|
|
view.setBackgroundColor(0xffe2e5e7);
|
2015-06-29 19:12:11 +02:00
|
|
|
frameLayout.addView(view, LayoutHelper.createFrame(52, 1, Gravity.LEFT | Gravity.BOTTOM));
|
2015-05-03 13:48:36 +02:00
|
|
|
|
|
|
|
recentsWrap = new FrameLayout(context);
|
|
|
|
recentsWrap.addView(views.get(0));
|
|
|
|
|
|
|
|
TextView textView = new TextView(context);
|
|
|
|
textView.setText(LocaleController.getString("NoRecent", R.string.NoRecent));
|
|
|
|
textView.setTextSize(18);
|
|
|
|
textView.setTextColor(0xff888888);
|
|
|
|
textView.setGravity(Gravity.CENTER);
|
|
|
|
recentsWrap.addView(textView);
|
|
|
|
views.get(0).setEmptyView(textView);
|
|
|
|
|
2015-06-29 19:12:11 +02:00
|
|
|
addView(pager, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT, Gravity.LEFT | Gravity.TOP, 0, 48, 0, 0));
|
2015-05-03 13:48:36 +02:00
|
|
|
|
|
|
|
loadRecents();
|
|
|
|
|
|
|
|
if (Emoji.data[0] == null || Emoji.data[0].length == 0) {
|
|
|
|
pager.setCurrentItem(1);
|
|
|
|
}
|
2013-10-25 17:19:00 +02:00
|
|
|
}
|
|
|
|
|
2015-06-29 19:12:11 +02:00
|
|
|
private void onPageScrolled(int position, int width, int positionOffsetPixels) {
|
|
|
|
if (scrollSlidingTabStrip == null) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (width == 0) {
|
|
|
|
width = AndroidUtilities.displaySize.x;
|
|
|
|
}
|
|
|
|
|
|
|
|
int margin = 0;
|
|
|
|
if (position == 5) {
|
|
|
|
margin = -positionOffsetPixels;
|
|
|
|
} else if (position == 6) {
|
|
|
|
margin = -width;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ViewProxy.getTranslationX(pagerSlidingTabStripContainer) != margin) {
|
|
|
|
ViewProxy.setTranslationX(pagerSlidingTabStripContainer, margin);
|
|
|
|
ViewProxy.setTranslationX(scrollSlidingTabStrip, width + margin);
|
|
|
|
if (Build.VERSION.SDK_INT < 11) {
|
|
|
|
if (margin <= -width) {
|
|
|
|
pagerSlidingTabStripContainer.clearAnimation();
|
|
|
|
pagerSlidingTabStripContainer.setVisibility(GONE);
|
|
|
|
} else {
|
|
|
|
pagerSlidingTabStripContainer.setVisibility(VISIBLE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else if (Build.VERSION.SDK_INT < 11 && pagerSlidingTabStripContainer.getVisibility() == GONE) {
|
|
|
|
pagerSlidingTabStripContainer.clearAnimation();
|
|
|
|
pagerSlidingTabStripContainer.setVisibility(GONE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-05-03 13:48:36 +02:00
|
|
|
private void postBackspaceRunnable(final int time) {
|
|
|
|
AndroidUtilities.runOnUIThread(new Runnable() {
|
|
|
|
@Override
|
|
|
|
public void run() {
|
|
|
|
if (!backspacePressed) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (EmojiView.this.listener != null && EmojiView.this.listener.onBackspace()) {
|
|
|
|
backspaceButton.performHapticFeedback(HapticFeedbackConstants.KEYBOARD_TAP);
|
|
|
|
}
|
|
|
|
backspaceOnce = true;
|
|
|
|
postBackspaceRunnable(Math.max(50, time - 100));
|
|
|
|
}
|
|
|
|
}, time);
|
2013-10-25 17:19:00 +02:00
|
|
|
}
|
|
|
|
|
2015-05-03 13:48:36 +02:00
|
|
|
private void addToRecent(long code) {
|
|
|
|
if (pager.getCurrentItem() == 0) {
|
2013-10-25 17:19:00 +02:00
|
|
|
return;
|
|
|
|
}
|
2015-05-03 13:48:36 +02:00
|
|
|
ArrayList<Long> recent = new ArrayList<>();
|
2013-10-25 17:19:00 +02:00
|
|
|
long[] currentRecent = Emoji.data[0];
|
|
|
|
boolean was = false;
|
|
|
|
for (long aCurrentRecent : currentRecent) {
|
2015-05-03 13:48:36 +02:00
|
|
|
if (code == aCurrentRecent) {
|
|
|
|
recent.add(0, code);
|
2013-10-25 17:19:00 +02:00
|
|
|
was = true;
|
|
|
|
} else {
|
2015-05-03 13:48:36 +02:00
|
|
|
recent.add(aCurrentRecent);
|
2013-10-25 17:19:00 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!was) {
|
2015-05-03 13:48:36 +02:00
|
|
|
recent.add(0, code);
|
2013-10-25 17:19:00 +02:00
|
|
|
}
|
2015-05-03 13:48:36 +02:00
|
|
|
Emoji.data[0] = new long[Math.min(recent.size(), 50)];
|
2013-10-25 17:19:00 +02:00
|
|
|
for (int q = 0; q < Emoji.data[0].length; q++) {
|
2015-05-03 13:48:36 +02:00
|
|
|
Emoji.data[0][q] = recent.get(q);
|
2013-10-25 17:19:00 +02:00
|
|
|
}
|
|
|
|
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;
|
|
|
|
}
|
2015-05-03 13:48:36 +02:00
|
|
|
int j = (int) (0xFFFF & paramLong >> 16 * (3 - i));
|
2013-10-25 17:19:00 +02:00
|
|
|
if (j != 0) {
|
2015-05-03 13:48:36 +02:00
|
|
|
str = str + (char) j;
|
2013-10-25 17:19:00 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private void saveRecents() {
|
2015-05-21 23:27:27 +02:00
|
|
|
ArrayList<Long> arrayList = new ArrayList<>(Emoji.data[0].length);
|
|
|
|
for (int j = 0; j < Emoji.data[0].length; j++) {
|
|
|
|
arrayList.add(Emoji.data[0][j]);
|
|
|
|
}
|
|
|
|
getContext().getSharedPreferences("emoji", 0).edit().putString("recents", TextUtils.join(",", arrayList)).commit();
|
|
|
|
}
|
|
|
|
|
|
|
|
private void saveRecentStickers() {
|
|
|
|
SharedPreferences preferences = getContext().getSharedPreferences("emoji", Activity.MODE_PRIVATE);
|
|
|
|
StringBuilder stringBuilder = new StringBuilder();
|
|
|
|
for (HashMap.Entry<Long, Integer> entry : stickersUseHistory.entrySet()) {
|
|
|
|
if (stringBuilder.length() != 0) {
|
|
|
|
stringBuilder.append(",");
|
2013-10-25 17:19:00 +02:00
|
|
|
}
|
2015-05-21 23:27:27 +02:00
|
|
|
stringBuilder.append(entry.getKey());
|
|
|
|
stringBuilder.append("=");
|
|
|
|
stringBuilder.append(entry.getValue());
|
2013-10-25 17:19:00 +02:00
|
|
|
}
|
2015-05-21 23:27:27 +02:00
|
|
|
getContext().getSharedPreferences("emoji", 0).edit().putString("stickers", stringBuilder.toString()).commit();
|
2013-10-25 17:19:00 +02:00
|
|
|
}
|
|
|
|
|
2015-05-21 23:27:27 +02:00
|
|
|
private void sortStickers() {
|
2015-06-29 19:12:11 +02:00
|
|
|
if (StickersQuery.getStickerSets().isEmpty()) {
|
|
|
|
recentStickers.clear();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
recentStickers.clear();
|
2015-05-21 23:27:27 +02:00
|
|
|
HashMap<Long, Integer> hashMap = new HashMap<>();
|
2015-06-29 19:12:11 +02:00
|
|
|
for (HashMap.Entry<Long, Integer> entry : stickersUseHistory.entrySet()) {
|
|
|
|
TLRPC.Document sticker = StickersQuery.getStickerById(entry.getKey());
|
|
|
|
if (sticker != null) {
|
|
|
|
recentStickers.add(sticker);
|
|
|
|
hashMap.put(sticker.id, entry.getValue());
|
2013-10-25 17:19:00 +02:00
|
|
|
}
|
2015-05-21 23:27:27 +02:00
|
|
|
}
|
|
|
|
if (!stickersUseHistory.isEmpty()) {
|
|
|
|
stickersUseHistory = hashMap;
|
|
|
|
saveRecents();
|
2015-05-03 13:48:36 +02:00
|
|
|
} else {
|
2015-05-21 23:27:27 +02:00
|
|
|
stickersUseHistory = hashMap;
|
|
|
|
}
|
2015-06-29 19:12:11 +02:00
|
|
|
Collections.sort(recentStickers, new Comparator<TLRPC.Document>() {
|
2015-05-21 23:27:27 +02:00
|
|
|
@Override
|
|
|
|
public int compare(TLRPC.Document lhs, TLRPC.Document rhs) {
|
|
|
|
Integer count1 = stickersUseHistory.get(lhs.id);
|
|
|
|
Integer count2 = stickersUseHistory.get(rhs.id);
|
|
|
|
if (count1 == null) {
|
|
|
|
count1 = 0;
|
|
|
|
}
|
|
|
|
if (count2 == null) {
|
|
|
|
count2 = 0;
|
|
|
|
}
|
|
|
|
if (count1 > count2) {
|
|
|
|
return -1;
|
|
|
|
} else if (count1 < count2) {
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
});
|
2015-06-29 19:12:11 +02:00
|
|
|
while (recentStickers.size() > 20) {
|
|
|
|
recentStickers.remove(recentStickers.size() - 1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private void updateStickerTabs() {
|
|
|
|
scrollSlidingTabStrip.removeTabs();
|
|
|
|
scrollSlidingTabStrip.addIconTab(R.drawable.ic_emoji_smile);
|
|
|
|
if (!recentStickers.isEmpty()) {
|
|
|
|
scrollSlidingTabStrip.addIconTab(R.drawable.ic_smiles_recent);
|
|
|
|
}
|
|
|
|
stickerSets.clear();
|
|
|
|
ArrayList<TLRPC.TL_messages_stickerSet> packs = StickersQuery.getStickerSets();
|
|
|
|
for (int a = 0; a < packs.size(); a++) {
|
|
|
|
TLRPC.TL_messages_stickerSet pack = packs.get(a);
|
|
|
|
if ((pack.set.flags & 2) != 0 || pack.documents == null || pack.documents.isEmpty()) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
stickerSets.add(pack);
|
|
|
|
scrollSlidingTabStrip.addStickerTab(pack.documents.get(0));
|
|
|
|
}
|
|
|
|
scrollSlidingTabStrip.updateTabStyles();
|
2015-05-21 23:27:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public void loadRecents() {
|
|
|
|
SharedPreferences preferences = getContext().getSharedPreferences("emoji", Activity.MODE_PRIVATE);
|
|
|
|
String str = preferences.getString("recents", "");
|
|
|
|
try {
|
|
|
|
if (str != null && str.length() > 0) {
|
|
|
|
String[] args = str.split(",");
|
|
|
|
Emoji.data[0] = new long[args.length];
|
|
|
|
for (int i = 0; i < args.length; i++) {
|
|
|
|
Emoji.data[0][i] = Long.parseLong(args[i]);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
Emoji.data[0] = new long[]{0x00000000D83DDE02L, 0x00000000D83DDE18L, 0x0000000000002764L, 0x00000000D83DDE0DL, 0x00000000D83DDE0AL, 0x00000000D83DDE01L,
|
|
|
|
0x00000000D83DDC4DL, 0x000000000000263AL, 0x00000000D83DDE14L, 0x00000000D83DDE04L, 0x00000000D83DDE2DL, 0x00000000D83DDC8BL,
|
|
|
|
0x00000000D83DDE12L, 0x00000000D83DDE33L, 0x00000000D83DDE1CL, 0x00000000D83DDE48L, 0x00000000D83DDE09L, 0x00000000D83DDE03L,
|
|
|
|
0x00000000D83DDE22L, 0x00000000D83DDE1DL, 0x00000000D83DDE31L, 0x00000000D83DDE21L, 0x00000000D83DDE0FL, 0x00000000D83DDE1EL,
|
|
|
|
0x00000000D83DDE05L, 0x00000000D83DDE1AL, 0x00000000D83DDE4AL, 0x00000000D83DDE0CL, 0x00000000D83DDE00L, 0x00000000D83DDE0BL,
|
|
|
|
0x00000000D83DDE06L, 0x00000000D83DDC4CL, 0x00000000D83DDE10L, 0x00000000D83DDE15L};
|
|
|
|
}
|
|
|
|
adapters.get(0).data = Emoji.data[0];
|
|
|
|
adapters.get(0).notifyDataSetChanged();
|
|
|
|
} catch (Exception e) {
|
|
|
|
FileLog.e("tmessages", e);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (showStickers) {
|
|
|
|
try {
|
|
|
|
stickersUseHistory.clear();
|
|
|
|
str = preferences.getString("stickers", "");
|
|
|
|
if (str != null && str.length() > 0) {
|
|
|
|
String[] args = str.split(",");
|
|
|
|
for (String arg : args) {
|
|
|
|
String[] args2 = arg.split("=");
|
|
|
|
stickersUseHistory.put(Long.parseLong(args2[0]), Integer.parseInt(args2[1]));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
sortStickers();
|
2015-06-29 19:12:11 +02:00
|
|
|
updateStickerTabs();
|
2015-05-21 23:27:27 +02:00
|
|
|
} catch (Exception e) {
|
|
|
|
FileLog.e("tmessages", e);
|
|
|
|
}
|
2013-10-25 17:19:00 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-06-29 19:12:11 +02:00
|
|
|
@Override
|
2015-05-03 13:48:36 +02:00
|
|
|
public void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
|
2015-06-29 19:12:11 +02:00
|
|
|
FrameLayout.LayoutParams layoutParams = (FrameLayout.LayoutParams) pagerSlidingTabStripContainer.getLayoutParams();
|
|
|
|
FrameLayout.LayoutParams layoutParams1 = null;
|
|
|
|
layoutParams.width = View.MeasureSpec.getSize(widthMeasureSpec);
|
|
|
|
if (scrollSlidingTabStrip != null) {
|
|
|
|
layoutParams1 = (FrameLayout.LayoutParams) scrollSlidingTabStrip.getLayoutParams();
|
|
|
|
layoutParams1.width = layoutParams.width;
|
|
|
|
}
|
|
|
|
if (layoutParams.width != oldWidth) {
|
|
|
|
if (scrollSlidingTabStrip != null) {
|
|
|
|
onPageScrolled(pager.getCurrentItem(), layoutParams.width, 0);
|
|
|
|
scrollSlidingTabStrip.setLayoutParams(layoutParams1);
|
|
|
|
}
|
|
|
|
pagerSlidingTabStripContainer.setLayoutParams(layoutParams);
|
|
|
|
oldWidth = layoutParams.width;
|
|
|
|
}
|
|
|
|
super.onMeasure(View.MeasureSpec.makeMeasureSpec(layoutParams.width, MeasureSpec.EXACTLY), View.MeasureSpec.makeMeasureSpec(View.MeasureSpec.getSize(heightMeasureSpec), MeasureSpec.EXACTLY));
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
|
|
|
|
if (lastNotifyWidth != right - left) {
|
|
|
|
lastNotifyWidth = right - left;
|
|
|
|
if (stickersGridAdapter != null) {
|
|
|
|
stickersGridAdapter.notifyDataSetChanged();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
super.onLayout(changed, left, top, right, bottom);
|
2013-10-25 17:19:00 +02:00
|
|
|
}
|
|
|
|
|
2015-05-03 13:48:36 +02:00
|
|
|
public void setListener(Listener value) {
|
|
|
|
listener = value;
|
2013-10-25 17:19:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public void invalidateViews() {
|
|
|
|
for (GridView gridView : views) {
|
|
|
|
if (gridView != null) {
|
|
|
|
gridView.invalidateViews();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-05-03 13:48:36 +02:00
|
|
|
@Override
|
|
|
|
protected void onAttachedToWindow() {
|
|
|
|
super.onAttachedToWindow();
|
|
|
|
if (stickersGridAdapter != null) {
|
|
|
|
NotificationCenter.getInstance().addObserver(this, NotificationCenter.stickersDidLoaded);
|
2015-06-29 19:12:11 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void setVisibility(int visibility) {
|
|
|
|
super.setVisibility(visibility);
|
|
|
|
if (visibility != GONE && stickersGridAdapter != null) {
|
|
|
|
NotificationCenter.getInstance().addObserver(this, NotificationCenter.stickersDidLoaded);
|
2015-05-21 23:27:27 +02:00
|
|
|
sortStickers();
|
2015-06-29 19:12:11 +02:00
|
|
|
updateStickerTabs();
|
2015-05-21 23:27:27 +02:00
|
|
|
stickersGridAdapter.notifyDataSetChanged();
|
2015-05-03 13:48:36 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void onDetachedFromWindow() {
|
|
|
|
super.onDetachedFromWindow();
|
|
|
|
if (stickersGridAdapter != null) {
|
|
|
|
NotificationCenter.getInstance().removeObserver(this, NotificationCenter.stickersDidLoaded);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void didReceivedNotification(int id, Object... args) {
|
|
|
|
if (id == NotificationCenter.stickersDidLoaded) {
|
2015-06-29 19:12:11 +02:00
|
|
|
updateStickerTabs();
|
2015-05-03 13:48:36 +02:00
|
|
|
stickersGridAdapter.notifyDataSetChanged();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private class StickersGridAdapter extends BaseAdapter {
|
|
|
|
|
2015-06-29 19:12:11 +02:00
|
|
|
private Context context;
|
|
|
|
private int stickersPerRow;
|
|
|
|
private HashMap<Integer, TLRPC.TL_messages_stickerSet> rowStartPack = new HashMap<>();
|
|
|
|
private HashMap<TLRPC.TL_messages_stickerSet, Integer> packStartRow = new HashMap<>();
|
|
|
|
private HashMap<Integer, TLRPC.Document> cache = new HashMap<>();
|
|
|
|
private int totalItems;
|
2015-05-03 13:48:36 +02:00
|
|
|
|
|
|
|
public StickersGridAdapter(Context context) {
|
|
|
|
this.context = context;
|
|
|
|
}
|
|
|
|
|
|
|
|
public int getCount() {
|
2015-06-29 19:12:11 +02:00
|
|
|
return totalItems != 0 ? totalItems + 1 : 0;
|
2015-05-03 13:48:36 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public Object getItem(int i) {
|
2015-06-29 19:12:11 +02:00
|
|
|
return cache.get(i);
|
2015-05-03 13:48:36 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public long getItemId(int i) {
|
2015-06-29 19:12:11 +02:00
|
|
|
return NO_ID;
|
|
|
|
}
|
|
|
|
|
|
|
|
public int getPositionForPack(TLRPC.TL_messages_stickerSet stickerSet) {
|
|
|
|
return packStartRow.get(stickerSet) * stickersPerRow;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean areAllItemsEnabled() {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean isEnabled(int position) {
|
|
|
|
return cache.get(position) != null;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public int getItemViewType(int position) {
|
|
|
|
if (cache.get(position) != null) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public int getViewTypeCount() {
|
|
|
|
return 2;
|
|
|
|
}
|
|
|
|
|
|
|
|
public int getTabForPosition(int position) {
|
|
|
|
if (stickersPerRow == 0) {
|
|
|
|
int width = getMeasuredWidth();
|
|
|
|
if (width == 0) {
|
|
|
|
width = AndroidUtilities.displaySize.x;
|
|
|
|
}
|
|
|
|
stickersPerRow = width / AndroidUtilities.dp(72);
|
|
|
|
}
|
|
|
|
int row = position / stickersPerRow;
|
|
|
|
TLRPC.TL_messages_stickerSet pack = rowStartPack.get(row);
|
|
|
|
if (pack == null) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
return stickerSets.indexOf(pack) + (recentStickers.isEmpty() ? 0 : 1);
|
2015-05-03 13:48:36 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public View getView(int i, View view, ViewGroup viewGroup) {
|
2015-06-29 19:12:11 +02:00
|
|
|
TLRPC.Document sticker = cache.get(i);
|
|
|
|
if (sticker != null) {
|
|
|
|
if (view == null) {
|
|
|
|
view = new StickerEmojiCell(context) {
|
|
|
|
public void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
|
|
|
|
super.onMeasure(widthMeasureSpec, MeasureSpec.makeMeasureSpec(AndroidUtilities.dp(82), MeasureSpec.EXACTLY));
|
|
|
|
}
|
|
|
|
};
|
|
|
|
view.setOnClickListener(new OnClickListener() {
|
|
|
|
@Override
|
|
|
|
public void onClick(View v) {
|
|
|
|
if (listener != null) {
|
|
|
|
TLRPC.Document document = ((StickerEmojiCell) v).getSticker();
|
|
|
|
Integer count = stickersUseHistory.get(document.id);
|
|
|
|
if (count == null) {
|
|
|
|
count = 0;
|
|
|
|
}
|
|
|
|
if (count == 0 && stickersUseHistory.size() > 19) {
|
|
|
|
for (int a = recentStickers.size() - 1; a >= 0; a--) {
|
|
|
|
TLRPC.Document sticker = recentStickers.get(a);
|
|
|
|
stickersUseHistory.remove(sticker.id);
|
|
|
|
recentStickers.remove(a);
|
|
|
|
if (stickersUseHistory.size() <= 19) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
stickersUseHistory.put(document.id, ++count);
|
|
|
|
saveRecentStickers();
|
|
|
|
listener.onStickerSelected(document);
|
2015-05-21 23:27:27 +02:00
|
|
|
}
|
2015-05-03 13:48:36 +02:00
|
|
|
}
|
2015-06-29 19:12:11 +02:00
|
|
|
});
|
|
|
|
}
|
|
|
|
((StickerEmojiCell) view).setSticker(sticker, false);
|
|
|
|
} else {
|
|
|
|
if (view == null) {
|
|
|
|
view = new EmptyCell(context);
|
|
|
|
}
|
|
|
|
if (i == totalItems) {
|
|
|
|
int row = (i - 1) / stickersPerRow;
|
|
|
|
TLRPC.TL_messages_stickerSet pack = rowStartPack.get(row);
|
|
|
|
if (pack == null) {
|
|
|
|
((EmptyCell) view).setHeight(1);
|
|
|
|
} else {
|
|
|
|
int height = pager.getHeight() - (int) Math.ceil(pack.documents.size() / (float) stickersPerRow) * AndroidUtilities.dp(82);
|
|
|
|
((EmptyCell) view).setHeight(height > 0 ? height : 1);
|
2015-05-03 13:48:36 +02:00
|
|
|
}
|
2015-06-29 19:12:11 +02:00
|
|
|
} else {
|
|
|
|
((EmptyCell) view).setHeight(AndroidUtilities.dp(82));
|
|
|
|
}
|
2015-05-03 13:48:36 +02:00
|
|
|
}
|
|
|
|
return view;
|
|
|
|
}
|
|
|
|
|
2015-06-29 19:12:11 +02:00
|
|
|
@Override
|
|
|
|
public void notifyDataSetChanged() {
|
|
|
|
int width = getMeasuredWidth();
|
|
|
|
if (width == 0) {
|
|
|
|
width = AndroidUtilities.displaySize.x;
|
|
|
|
}
|
|
|
|
stickersPerRow = width / AndroidUtilities.dp(72);
|
|
|
|
rowStartPack.clear();
|
|
|
|
packStartRow.clear();
|
|
|
|
cache.clear();
|
|
|
|
totalItems = 0;
|
|
|
|
ArrayList<TLRPC.TL_messages_stickerSet> packs = stickerSets;
|
|
|
|
for (int a = -1; a < packs.size(); a++) {
|
|
|
|
ArrayList<TLRPC.Document> documents;
|
|
|
|
TLRPC.TL_messages_stickerSet pack = null;
|
|
|
|
int startRow = totalItems / stickersPerRow;
|
|
|
|
if (a == -1) {
|
|
|
|
documents = recentStickers;
|
|
|
|
} else {
|
|
|
|
pack = packs.get(a);
|
|
|
|
documents = pack.documents;
|
|
|
|
packStartRow.put(pack, startRow);
|
|
|
|
}
|
|
|
|
if (documents.isEmpty()) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
int count = (int) Math.ceil(documents.size() / (float) stickersPerRow);
|
|
|
|
for (int b = 0; b < documents.size(); b++) {
|
|
|
|
cache.put(b + totalItems, documents.get(b));
|
|
|
|
}
|
|
|
|
totalItems += count * stickersPerRow;
|
|
|
|
for (int b = 0; b < count; b++) {
|
|
|
|
rowStartPack.put(startRow + b, pack);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
super.notifyDataSetChanged();
|
|
|
|
}
|
|
|
|
|
2015-05-03 13:48:36 +02:00
|
|
|
@Override
|
|
|
|
public void unregisterDataSetObserver(DataSetObserver observer) {
|
|
|
|
if (observer != null) {
|
|
|
|
super.unregisterDataSetObserver(observer);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-10-25 17:19:00 +02:00
|
|
|
private class EmojiGridAdapter extends BaseAdapter {
|
|
|
|
long[] data;
|
|
|
|
|
|
|
|
public EmojiGridAdapter(long[] arg2) {
|
|
|
|
this.data = arg2;
|
|
|
|
}
|
|
|
|
|
|
|
|
public int getCount() {
|
2014-09-28 15:37:26 +02:00
|
|
|
return data.length;
|
2013-10-25 17:19:00 +02:00
|
|
|
}
|
|
|
|
|
2014-09-28 15:37:26 +02:00
|
|
|
public Object getItem(int i) {
|
2013-10-25 17:19:00 +02:00
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2014-09-28 15:37:26 +02:00
|
|
|
public long getItemId(int i) {
|
|
|
|
return data[i];
|
2013-10-25 17:19:00 +02:00
|
|
|
}
|
|
|
|
|
2014-09-28 15:37:26 +02:00
|
|
|
public View getView(int i, View view, ViewGroup paramViewGroup) {
|
|
|
|
ImageView imageView = (ImageView)view;
|
|
|
|
if (imageView == null) {
|
|
|
|
imageView = new ImageView(EmojiView.this.getContext()) {
|
2013-10-25 17:19:00 +02:00
|
|
|
public void onMeasure(int paramAnonymousInt1, int paramAnonymousInt2) {
|
|
|
|
setMeasuredDimension(View.MeasureSpec.getSize(paramAnonymousInt1), View.MeasureSpec.getSize(paramAnonymousInt1));
|
|
|
|
}
|
|
|
|
};
|
2014-09-28 15:37:26 +02:00
|
|
|
imageView.setOnClickListener(new View.OnClickListener() {
|
2014-06-15 01:23:36 +02:00
|
|
|
public void onClick(View view) {
|
2013-10-25 17:19:00 +02:00
|
|
|
if (EmojiView.this.listener != null) {
|
2014-06-15 01:23:36 +02:00
|
|
|
EmojiView.this.listener.onEmojiSelected(EmojiView.this.convert((Long)view.getTag()));
|
2013-10-25 17:19:00 +02:00
|
|
|
}
|
2014-06-15 01:23:36 +02:00
|
|
|
EmojiView.this.addToRecent((Long)view.getTag());
|
2013-10-25 17:19:00 +02:00
|
|
|
}
|
|
|
|
});
|
2014-09-28 15:37:26 +02:00
|
|
|
imageView.setBackgroundResource(R.drawable.list_selector);
|
|
|
|
imageView.setScaleType(ImageView.ScaleType.CENTER);
|
2013-10-25 17:19:00 +02:00
|
|
|
}
|
2014-09-28 15:37:26 +02:00
|
|
|
imageView.setImageDrawable(Emoji.getEmojiBigDrawable(data[i]));
|
|
|
|
imageView.setTag(data[i]);
|
|
|
|
return imageView;
|
2013-10-25 17:19:00 +02:00
|
|
|
}
|
2014-06-20 02:18:13 +02:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public void unregisterDataSetObserver(DataSetObserver observer) {
|
|
|
|
if (observer != null) {
|
|
|
|
super.unregisterDataSetObserver(observer);
|
|
|
|
}
|
|
|
|
}
|
2013-10-25 17:19:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
private class EmojiPagesAdapter extends PagerAdapter implements PagerSlidingTabStrip.IconTabProvider {
|
|
|
|
|
2015-06-29 19:12:11 +02:00
|
|
|
public void destroyItem(ViewGroup viewGroup, int position, Object object) {
|
|
|
|
View view;
|
|
|
|
if (position == 0) {
|
|
|
|
view = recentsWrap;
|
|
|
|
} else if (position == 6) {
|
|
|
|
view = stickersWrap;
|
2013-10-25 17:19:00 +02:00
|
|
|
} else {
|
2015-06-29 19:12:11 +02:00
|
|
|
view = views.get(position);
|
2013-10-25 17:19:00 +02:00
|
|
|
}
|
2015-06-29 19:12:11 +02:00
|
|
|
viewGroup.removeView(view);
|
2013-10-25 17:19:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public int getCount() {
|
2014-11-17 23:04:31 +01:00
|
|
|
return views.size();
|
2013-10-25 17:19:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public int getPageIconResId(int paramInt) {
|
2014-11-17 23:04:31 +01:00
|
|
|
return icons[paramInt];
|
2013-10-25 17:19:00 +02:00
|
|
|
}
|
|
|
|
|
2015-06-29 19:12:11 +02:00
|
|
|
public Object instantiateItem(ViewGroup viewGroup, int position) {
|
|
|
|
View view;
|
|
|
|
if (position == 0) {
|
|
|
|
view = recentsWrap;
|
|
|
|
} else if (position == 6) {
|
|
|
|
view = stickersWrap;
|
2013-10-25 17:19:00 +02:00
|
|
|
} else {
|
2015-06-29 19:12:11 +02:00
|
|
|
view = views.get(position);
|
2013-10-25 17:19:00 +02:00
|
|
|
}
|
2015-06-29 19:12:11 +02:00
|
|
|
viewGroup.addView(view);
|
|
|
|
return view;
|
2013-10-25 17:19:00 +02:00
|
|
|
}
|
|
|
|
|
2015-06-29 19:12:11 +02:00
|
|
|
public boolean isViewFromObject(View view, Object object) {
|
|
|
|
return view == object;
|
2013-10-25 17:19:00 +02:00
|
|
|
}
|
2014-06-20 02:18:13 +02:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public void unregisterDataSetObserver(DataSetObserver observer) {
|
|
|
|
if (observer != null) {
|
|
|
|
super.unregisterDataSetObserver(observer);
|
|
|
|
}
|
|
|
|
}
|
2013-10-25 17:19:00 +02:00
|
|
|
}
|
|
|
|
}
|