|
|
@ -1,14 +1,12 @@
|
|
|
|
package org.thoughtcrime.securesms.components.emoji;
|
|
|
|
package org.thoughtcrime.securesms.components.emoji;
|
|
|
|
|
|
|
|
|
|
|
|
import android.content.Context;
|
|
|
|
import android.content.Context;
|
|
|
|
import android.os.Bundle;
|
|
|
|
|
|
|
|
import android.support.annotation.ArrayRes;
|
|
|
|
import android.support.annotation.ArrayRes;
|
|
|
|
import android.support.annotation.NonNull;
|
|
|
|
import android.support.annotation.NonNull;
|
|
|
|
import android.support.annotation.Nullable;
|
|
|
|
import android.support.annotation.Nullable;
|
|
|
|
import android.support.v4.app.Fragment;
|
|
|
|
import android.support.v4.view.PagerAdapter;
|
|
|
|
import android.support.v4.app.FragmentManager;
|
|
|
|
|
|
|
|
import android.support.v4.app.FragmentStatePagerAdapter;
|
|
|
|
|
|
|
|
import android.support.v4.view.ViewPager;
|
|
|
|
import android.support.v4.view.ViewPager;
|
|
|
|
|
|
|
|
import android.util.AttributeSet;
|
|
|
|
import android.util.Log;
|
|
|
|
import android.util.Log;
|
|
|
|
import android.view.KeyEvent;
|
|
|
|
import android.view.KeyEvent;
|
|
|
|
import android.view.LayoutInflater;
|
|
|
|
import android.view.LayoutInflater;
|
|
|
@ -17,6 +15,7 @@ import android.view.ViewGroup;
|
|
|
|
import android.widget.FrameLayout;
|
|
|
|
import android.widget.FrameLayout;
|
|
|
|
import android.widget.ImageView;
|
|
|
|
import android.widget.ImageView;
|
|
|
|
import android.widget.ImageView.ScaleType;
|
|
|
|
import android.widget.ImageView.ScaleType;
|
|
|
|
|
|
|
|
import android.widget.LinearLayout;
|
|
|
|
import android.widget.RelativeLayout;
|
|
|
|
import android.widget.RelativeLayout;
|
|
|
|
|
|
|
|
|
|
|
|
import com.astuetz.PagerSlidingTabStrip;
|
|
|
|
import com.astuetz.PagerSlidingTabStrip;
|
|
|
@ -25,13 +24,13 @@ import org.thoughtcrime.securesms.R;
|
|
|
|
import org.thoughtcrime.securesms.components.KeyboardAwareLinearLayout;
|
|
|
|
import org.thoughtcrime.securesms.components.KeyboardAwareLinearLayout;
|
|
|
|
import org.thoughtcrime.securesms.components.RepeatableImageKey;
|
|
|
|
import org.thoughtcrime.securesms.components.RepeatableImageKey;
|
|
|
|
import org.thoughtcrime.securesms.components.RepeatableImageKey.KeyEventListener;
|
|
|
|
import org.thoughtcrime.securesms.components.RepeatableImageKey.KeyEventListener;
|
|
|
|
import org.thoughtcrime.securesms.components.emoji.EmojiPageFragment.EmojiSelectionListener;
|
|
|
|
import org.thoughtcrime.securesms.components.emoji.EmojiPageView.EmojiSelectionListener;
|
|
|
|
import org.thoughtcrime.securesms.util.ResUtil;
|
|
|
|
import org.thoughtcrime.securesms.util.ResUtil;
|
|
|
|
|
|
|
|
|
|
|
|
import java.util.LinkedList;
|
|
|
|
import java.util.LinkedList;
|
|
|
|
import java.util.List;
|
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
|
|
|
|
public class EmojiDrawer extends Fragment {
|
|
|
|
public class EmojiDrawer extends KeyboardAwareLinearLayout {
|
|
|
|
private static final KeyEvent DELETE_KEY_EVENT = new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_DEL);
|
|
|
|
private static final KeyEvent DELETE_KEY_EVENT = new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_DEL);
|
|
|
|
|
|
|
|
|
|
|
|
private EmojiEditText composeText;
|
|
|
|
private EmojiEditText composeText;
|
|
|
@ -41,30 +40,30 @@ public class EmojiDrawer extends Fragment {
|
|
|
|
private PagerSlidingTabStrip strip;
|
|
|
|
private PagerSlidingTabStrip strip;
|
|
|
|
private RecentEmojiPageModel recentModel;
|
|
|
|
private RecentEmojiPageModel recentModel;
|
|
|
|
|
|
|
|
|
|
|
|
public static EmojiDrawer newInstance(@ArrayRes int categories, @ArrayRes int icons) {
|
|
|
|
public EmojiDrawer(Context context) {
|
|
|
|
final EmojiDrawer fragment = new EmojiDrawer();
|
|
|
|
super(context);
|
|
|
|
final Bundle args = new Bundle();
|
|
|
|
init();
|
|
|
|
args.putInt("categories", categories);
|
|
|
|
|
|
|
|
args.putInt("icons", icons);
|
|
|
|
|
|
|
|
fragment.setArguments(args);
|
|
|
|
|
|
|
|
return fragment;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public static EmojiDrawer newInstance() {
|
|
|
|
public EmojiDrawer(Context context, AttributeSet attrs) {
|
|
|
|
return newInstance(R.array.emoji_categories, R.array.emoji_category_icons);
|
|
|
|
super(context, attrs);
|
|
|
|
|
|
|
|
init();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public EmojiDrawer(Context context, AttributeSet attrs, int defStyle) {
|
|
|
|
|
|
|
|
super(context, attrs, defStyle);
|
|
|
|
|
|
|
|
init();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void setComposeEditText(EmojiEditText composeText) {
|
|
|
|
public void setComposeEditText(EmojiEditText composeText) {
|
|
|
|
this.composeText = composeText;
|
|
|
|
this.composeText = composeText;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
private void init() {
|
|
|
|
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
|
|
|
final View v = LayoutInflater.from(getContext()).inflate(R.layout.emoji_drawer, this, true);
|
|
|
|
final View v = inflater.inflate(R.layout.emoji_drawer, container, false);
|
|
|
|
|
|
|
|
initializeResources(v);
|
|
|
|
initializeResources(v);
|
|
|
|
initializePageModels(getArguments().getInt("categories"), getArguments().getInt("icons"));
|
|
|
|
initializePageModels(R.array.emoji_categories, R.array.emoji_category_icons);
|
|
|
|
initializeEmojiGrid();
|
|
|
|
initializeEmojiGrid();
|
|
|
|
return v;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void initializeResources(View v) {
|
|
|
|
private void initializeResources(View v) {
|
|
|
@ -90,7 +89,7 @@ public class EmojiDrawer extends Fragment {
|
|
|
|
public void show() {
|
|
|
|
public void show() {
|
|
|
|
int keyboardHeight = container.getKeyboardHeight();
|
|
|
|
int keyboardHeight = container.getKeyboardHeight();
|
|
|
|
Log.w("EmojiDrawer", "setting emoji drawer to height " + keyboardHeight);
|
|
|
|
Log.w("EmojiDrawer", "setting emoji drawer to height " + keyboardHeight);
|
|
|
|
container.setLayoutParams(new FrameLayout.LayoutParams(RelativeLayout.LayoutParams.MATCH_PARENT, keyboardHeight));
|
|
|
|
container.setLayoutParams(new LinearLayout.LayoutParams(RelativeLayout.LayoutParams.MATCH_PARENT, keyboardHeight));
|
|
|
|
container.requestLayout();
|
|
|
|
container.requestLayout();
|
|
|
|
container.setVisibility(View.VISIBLE);
|
|
|
|
container.setVisibility(View.VISIBLE);
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -100,8 +99,7 @@ public class EmojiDrawer extends Fragment {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void initializeEmojiGrid() {
|
|
|
|
private void initializeEmojiGrid() {
|
|
|
|
pager.setAdapter(new EmojiPagerAdapter(getActivity(),
|
|
|
|
pager.setAdapter(new EmojiPagerAdapter(getContext(),
|
|
|
|
getFragmentManager(),
|
|
|
|
|
|
|
|
models,
|
|
|
|
models,
|
|
|
|
new EmojiSelectionListener() {
|
|
|
|
new EmojiSelectionListener() {
|
|
|
|
@Override public void onEmojiSelected(int emojiCode) {
|
|
|
|
@Override public void onEmojiSelected(int emojiCode) {
|
|
|
@ -117,17 +115,17 @@ public class EmojiDrawer extends Fragment {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void initializePageModels(@ArrayRes int pagesRes, @ArrayRes int iconsRes) {
|
|
|
|
private void initializePageModels(@ArrayRes int pagesRes, @ArrayRes int iconsRes) {
|
|
|
|
final int[] icons = ResUtil.getResourceIds(getActivity(), iconsRes);
|
|
|
|
final int[] icons = ResUtil.getResourceIds(getContext(), iconsRes);
|
|
|
|
final int[] pages = ResUtil.getResourceIds(getActivity(), pagesRes);
|
|
|
|
final int[] pages = ResUtil.getResourceIds(getContext(), pagesRes);
|
|
|
|
this.models = new LinkedList<>();
|
|
|
|
this.models = new LinkedList<>();
|
|
|
|
this.recentModel = new RecentEmojiPageModel(getActivity());
|
|
|
|
this.recentModel = new RecentEmojiPageModel(getContext());
|
|
|
|
this.models.add(recentModel);
|
|
|
|
this.models.add(recentModel);
|
|
|
|
for (int i = 0; i < icons.length; i++) {
|
|
|
|
for (int i = 0; i < icons.length; i++) {
|
|
|
|
this.models.add(new StaticEmojiPageModel(icons[i], getResources().getIntArray(pages[i])));
|
|
|
|
this.models.add(new StaticEmojiPageModel(icons[i], getResources().getIntArray(pages[i])));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public static class EmojiPagerAdapter extends FragmentStatePagerAdapter
|
|
|
|
public static class EmojiPagerAdapter extends PagerAdapter
|
|
|
|
implements PagerSlidingTabStrip.CustomTabProvider
|
|
|
|
implements PagerSlidingTabStrip.CustomTabProvider
|
|
|
|
{
|
|
|
|
{
|
|
|
|
private Context context;
|
|
|
|
private Context context;
|
|
|
@ -135,11 +133,10 @@ public class EmojiDrawer extends Fragment {
|
|
|
|
private EmojiSelectionListener listener;
|
|
|
|
private EmojiSelectionListener listener;
|
|
|
|
|
|
|
|
|
|
|
|
public EmojiPagerAdapter(@NonNull Context context,
|
|
|
|
public EmojiPagerAdapter(@NonNull Context context,
|
|
|
|
@NonNull FragmentManager fm,
|
|
|
|
|
|
|
|
@NonNull List<EmojiPageModel> pages,
|
|
|
|
@NonNull List<EmojiPageModel> pages,
|
|
|
|
@Nullable EmojiSelectionListener listener)
|
|
|
|
@Nullable EmojiSelectionListener listener)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
super(fm);
|
|
|
|
super();
|
|
|
|
this.context = context;
|
|
|
|
this.context = context;
|
|
|
|
this.pages = pages;
|
|
|
|
this.pages = pages;
|
|
|
|
this.listener = listener;
|
|
|
|
this.listener = listener;
|
|
|
@ -150,16 +147,28 @@ public class EmojiDrawer extends Fragment {
|
|
|
|
return pages.size();
|
|
|
|
return pages.size();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override public Fragment getItem(int i) {
|
|
|
|
@Override public Object instantiateItem(ViewGroup container, int position) {
|
|
|
|
return EmojiPageFragment.newInstance(pages.get(i), listener);
|
|
|
|
EmojiPageView page = new EmojiPageView(context);
|
|
|
|
|
|
|
|
page.setModel(pages.get(position));
|
|
|
|
|
|
|
|
page.setEmojiSelectedListener(listener);
|
|
|
|
|
|
|
|
container.addView(page);
|
|
|
|
|
|
|
|
return page;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override public void destroyItem(ViewGroup container, int position, Object object) {
|
|
|
|
|
|
|
|
container.removeView((View)object);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override public void setPrimaryItem(ViewGroup container, int position, Object object) {
|
|
|
|
@Override public void setPrimaryItem(ViewGroup container, int position, Object object) {
|
|
|
|
EmojiPageFragment current = (EmojiPageFragment) object;
|
|
|
|
EmojiPageView current = (EmojiPageView) object;
|
|
|
|
current.onSelected();
|
|
|
|
current.onSelected();
|
|
|
|
super.setPrimaryItem(container, position, object);
|
|
|
|
super.setPrimaryItem(container, position, object);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override public boolean isViewFromObject(View view, Object object) {
|
|
|
|
|
|
|
|
return view == object;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override public View getCustomTabView(ViewGroup viewGroup, int i) {
|
|
|
|
@Override public View getCustomTabView(ViewGroup viewGroup, int i) {
|
|
|
|
ImageView image = new ImageView(context);
|
|
|
|
ImageView image = new ImageView(context);
|
|
|
|
image.setScaleType(ScaleType.CENTER_INSIDE);
|
|
|
|
image.setScaleType(ScaleType.CENTER_INSIDE);
|
|
|
|