Skip to content

Commit

Permalink
Updated to 1.2.2
Browse files Browse the repository at this point in the history
  • Loading branch information
Aghajari committed Aug 31, 2020
1 parent 1775caf commit ccee7e4
Show file tree
Hide file tree
Showing 83 changed files with 5,918 additions and 4,015 deletions.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1,3 +1,20 @@
/*
* Copyright (C) 2020 - Amir Hossein Aghajari
*
* 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.aghajari.emojiview;

import android.graphics.Color;
Expand All @@ -19,7 +36,7 @@ public class AXEmojiTheme {
int categoryColor = 0xffebeff2;
int titleColor = Color.DKGRAY;
Typeface titleTypeface = Typeface.DEFAULT_BOLD;
boolean alwaysShowDivider=false;
boolean alwaysShowDivider = false;
boolean categoryEnabled = true;

public int getBackgroundColor() {
Expand Down Expand Up @@ -142,11 +159,11 @@ public int getCategoryColor() {
return this.categoryColor;
}

public void setAlwaysShowDivider(boolean value){
public void setAlwaysShowDivider(boolean value) {
alwaysShowDivider = value;
}

public boolean shouldShowAlwaysDivider(){
public boolean shouldShowAlwaysDivider() {
return alwaysShowDivider;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,32 @@
/*
* Copyright (C) 2020 - Amir Hossein Aghajari
*
* 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.aghajari.emojiview;

import android.content.Context;
import android.graphics.Paint;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import android.text.SpannableStringBuilder;
import android.text.TextUtils;
import android.view.KeyEvent;
import android.view.View;
import android.widget.EditText;

import com.aghajari.emojiview.emoji.Emoji;
Expand All @@ -18,82 +38,115 @@
import java.util.regex.Pattern;

public final class AXEmojiUtils {
private static final Pattern SPACE_REMOVAL = Pattern.compile("[\\s]");
private static final Pattern SPACE_REMOVAL = Pattern.compile("[\\s]");

/**
* returns true when the string contains only emojis. Note that whitespace will be filtered out.
*/
public static boolean isOnlyEmojis(@Nullable final CharSequence text) {
if (!TextUtils.isEmpty(text)) {
final String inputWithoutSpaces = SPACE_REMOVAL.matcher(text).replaceAll(Matcher.quoteReplacement(""));

return AXEmojiManager.getInstance()
.getEmojiRepetitivePattern()
.matcher(inputWithoutSpaces)
.matches();
}

return false;
}

/** returns true when the string contains only emojis. Note that whitespace will be filtered out. */
public static boolean isOnlyEmojis(@Nullable final CharSequence text) {
if (!TextUtils.isEmpty(text)) {
final String inputWithoutSpaces = SPACE_REMOVAL.matcher(text).replaceAll(Matcher.quoteReplacement(""));
/**
* returns the emojis that were found in the given text
*/
@NonNull
public static List<EmojiRange> getEmojis(@Nullable final CharSequence text) {
return AXEmojiManager.getInstance().findAllEmojis(text);
}

return AXEmojiManager.getInstance()
.getEmojiRepetitivePattern()
.matcher(inputWithoutSpaces)
.matches();
/**
* returns the number of all emojis that were found in the given text
*/
public static int getEmojisCount(@Nullable final CharSequence text) {
return getEmojis(text).size();
}

return false;
}

/** returns the emojis that were found in the given text */
@NonNull public static List<EmojiRange> getEmojis(@Nullable final CharSequence text) {
return AXEmojiManager.getInstance().findAllEmojis(text);
}

/** returns the number of all emojis that were found in the given text */
public static int getEmojisCount(@Nullable final CharSequence text) {
return getEmojis(text).size();
}

public static SpannableStringBuilder replaceWithEmojis(Context context,Paint.FontMetrics fontMetrics, final CharSequence rawText,float emojiSize) {
final CharSequence text = rawText == null ? "" : rawText;
final SpannableStringBuilder spannableStringBuilder = new SpannableStringBuilder(text);
if (AXEmojiManager.isInstalled()) {
final float defaultEmojiSize = fontMetrics.descent - fontMetrics.ascent;
AXEmojiManager.getInstance().replaceWithImages(context, spannableStringBuilder, emojiSize,fontMetrics, defaultEmojiSize);
}
return spannableStringBuilder;
}

public static SpannableStringBuilder replaceWithEmojis(Context context, final CharSequence rawText,float emojiSize,float defaultSize) {
final CharSequence text = rawText == null ? "" : rawText;
final SpannableStringBuilder spannableStringBuilder = new SpannableStringBuilder(text);
if (AXEmojiManager.isInstalled()) {
AXEmojiManager.getInstance().replaceWithImages(context, spannableStringBuilder, emojiSize,null, defaultSize);
public static SpannableStringBuilder replaceWithEmojis(Context context, Paint.FontMetrics fontMetrics, final CharSequence rawText, float emojiSize) {
final CharSequence text = rawText == null ? "" : rawText;
final SpannableStringBuilder spannableStringBuilder = new SpannableStringBuilder(text);
if (AXEmojiManager.isInstalled()) {
AXEmojiManager.getInstance().replaceWithImages(context, spannableStringBuilder, emojiSize, fontMetrics);
}
return spannableStringBuilder;
}

public static SpannableStringBuilder replaceWithEmojis(Context context, final CharSequence rawText, float emojiSize) {
final CharSequence text = rawText == null ? "" : rawText;
final SpannableStringBuilder spannableStringBuilder = new SpannableStringBuilder(text);
if (AXEmojiManager.isInstalled()) {
AXEmojiManager.getInstance().replaceWithImages(context, spannableStringBuilder, emojiSize, null);
}
return spannableStringBuilder;
}
return spannableStringBuilder;
}


public static SpannableStringBuilder replaceWithEmojis(Context context, final CharSequence rawText,float emojiSize) {
final CharSequence text = rawText == null ? "" : rawText;
final SpannableStringBuilder spannableStringBuilder = new SpannableStringBuilder(text);
if (AXEmojiManager.isInstalled()) {
AXEmojiManager.getInstance().replaceWithImages(context, spannableStringBuilder, Utils.dpToPx(context,emojiSize),null, Utils.dpToPx(context,emojiSize));
public static SpannableStringBuilder replaceWithEmojisPxSize(Context context, final CharSequence rawText, float emojiSize) {
final CharSequence text = rawText == null ? "" : rawText;
final SpannableStringBuilder spannableStringBuilder = new SpannableStringBuilder(text);
if (AXEmojiManager.isInstalled()) {
AXEmojiManager.getInstance().replaceWithImages(context, spannableStringBuilder, Utils.dpToPx(context, emojiSize),null);
}
return spannableStringBuilder;
}
return spannableStringBuilder;
}

public static String getEmojiUnicode(@NonNull final int[] codePoints){
return new Emoji(codePoints,-1).getUnicode();
}
public static SpannableStringBuilder replaceWithEmojis(View view, Paint.FontMetrics fontMetrics, final CharSequence rawText, float emojiSize) {
final CharSequence text = rawText == null ? "" : rawText;
final SpannableStringBuilder spannableStringBuilder = new SpannableStringBuilder(text);
if (AXEmojiManager.isInstalled()) {
AXEmojiManager.getInstance().replaceWithImages(view.getContext(),view, spannableStringBuilder, emojiSize, fontMetrics);
}
return spannableStringBuilder;
}

public static String getEmojiUnicode(@NonNull final int codePoint){
return new Emoji(codePoint,-1).getUnicode();
}
public static SpannableStringBuilder replaceWithEmojis(View view, final CharSequence rawText, float emojiSize) {
final CharSequence text = rawText == null ? "" : rawText;
final SpannableStringBuilder spannableStringBuilder = new SpannableStringBuilder(text);
if (AXEmojiManager.isInstalled()) {
AXEmojiManager.getInstance().replaceWithImages(view.getContext(),view, spannableStringBuilder, emojiSize, null);
}
return spannableStringBuilder;
}

public static void backspace(@NonNull final EditText editText) {
final KeyEvent event = new KeyEvent(0, 0, 0, KeyEvent.KEYCODE_DEL, 0, 0, 0, 0, KeyEvent.KEYCODE_ENDCALL);
editText.dispatchKeyEvent(event);
}

public static SpannableStringBuilder replaceWithEmojisPxSize(View view, final CharSequence rawText, float emojiSize) {
final CharSequence text = rawText == null ? "" : rawText;
final SpannableStringBuilder spannableStringBuilder = new SpannableStringBuilder(text);
if (AXEmojiManager.isInstalled()) {
AXEmojiManager.getInstance().replaceWithImages(view.getContext(),view, spannableStringBuilder, Utils.dpToPx(view.getContext(), emojiSize),null);
}
return spannableStringBuilder;
}

public static String getEmojiUnicode(@NonNull final int[] codePoints) {
return new Emoji(codePoints, -1).getUnicode();
}

public static String getEmojiUnicode(@NonNull final int codePoint) {
return new Emoji(codePoint, -1).getUnicode();
}

public static void backspace(@NonNull final EditText editText) {
final KeyEvent event = new KeyEvent(0, 0, 0, KeyEvent.KEYCODE_DEL, 0, 0, 0, 0, KeyEvent.KEYCODE_ENDCALL);
editText.dispatchKeyEvent(event);
}

public static void input(@NonNull final EditText editText, @Nullable final Emoji emoji) {
if (emoji != null) {
AXEmojiManager.getInstance().getEditTextInputListener().input(editText, emoji);
public static void input(@NonNull final EditText editText, @Nullable final Emoji emoji) {
if (emoji != null) {
AXEmojiManager.getInstance().getEditTextInputListener().input(editText, emoji);
}
}
}

public static Emoji getEmojiFromUnicode (String unicode){
return AXEmojiManager.getInstance().emojiMap.get(unicode);
}
public static Emoji getEmojiFromUnicode(String unicode) {
return AXEmojiManager.getInstance().emojiMap.get(unicode);
}
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,31 @@
/*
* Copyright (C) 2020 - Amir Hossein Aghajari
*
* 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.aghajari.emojiview.adapters;

import android.graphics.drawable.Drawable;

import androidx.annotation.NonNull;
import androidx.appcompat.widget.AppCompatImageView;
import androidx.core.graphics.drawable.DrawableCompat;
import androidx.appcompat.content.res.AppCompatResources;
import androidx.recyclerview.widget.RecyclerView;

import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
Expand All @@ -22,60 +42,64 @@ public class AXCategoryAdapter extends RecyclerView.Adapter<RecyclerView.ViewHol
AXEmojiLayout pager;
StickerProvider provider;
boolean recent;
public AXCategoryAdapter(AXEmojiLayout pager, StickerProvider provider, RecentSticker RecentStickerManager){

public AXCategoryAdapter(AXEmojiLayout pager, StickerProvider provider, RecentSticker RecentStickerManager) {
recent = !RecentStickerManager.isEmpty() && provider.isRecentEnabled();
this.pager=pager;
this.provider=provider;
this.pager = pager;
this.provider = provider;
}

@NonNull
@Override
public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int i) {
int iconSize = Utils.dpToPx(viewGroup.getContext(),24);
int iconSize = Utils.dpToPx(viewGroup.getContext(), 24);
AXEmojiLayout layout = new AXEmojiLayout(viewGroup.getContext());
View icon;
if (i==10){
if (i == 10) {
icon = new AppCompatImageView(viewGroup.getContext());
}else{
} else {
icon = AXEmojiManager.getInstance().getStickerViewCreatorListener().onCreateCategoryView(viewGroup.getContext());
}
layout.addView(icon,new AXEmojiLayout.LayoutParams(Utils.dpToPx(viewGroup.getContext(),7),Utils.dpToPx(viewGroup.getContext(),7),iconSize,iconSize));
layout.setLayoutParams(new ViewGroup.LayoutParams(Utils.dpToPx(viewGroup.getContext(),38),Utils.dpToPx(viewGroup.getContext(),38)));
layout.addView(icon, new AXEmojiLayout.LayoutParams(Utils.dpToPx(viewGroup.getContext(), 7), Utils.dpToPx(viewGroup.getContext(), 7), iconSize, iconSize));
layout.setLayoutParams(new ViewGroup.LayoutParams(Utils.dpToPx(viewGroup.getContext(), 38), Utils.dpToPx(viewGroup.getContext(), 38)));

View selection = new View(viewGroup.getContext());
layout.addView(selection,new AXEmojiLayout.LayoutParams(
0,Utils.dpToPx(viewGroup.getContext(),36),Utils.dpToPx(viewGroup.getContext(),38),Utils.dpToPx(viewGroup.getContext(),2)));
layout.addView(selection, new AXEmojiLayout.LayoutParams(
0, Utils.dpToPx(viewGroup.getContext(), 36), Utils.dpToPx(viewGroup.getContext(), 38), Utils.dpToPx(viewGroup.getContext(), 2)));
selection.setBackgroundColor(AXEmojiManager.getStickerViewTheme().getSelectionColor());
selection.setVisibility(View.GONE);
return new RecyclerView.ViewHolder(layout){};
return new RecyclerView.ViewHolder(layout) {
};
}

@Override
public void onBindViewHolder(@NonNull RecyclerView.ViewHolder viewHolder, final int i) {
boolean selected = pager.getPageIndex()==i;
boolean selected = pager.getPageIndex() == i;
AXEmojiLayout layout = (AXEmojiLayout) viewHolder.itemView;
View icon = layout.getChildAt(0);
View selection = (View) layout.getChildAt(1);

if (selected) selection.setVisibility(View.VISIBLE); else selection.setVisibility(View.GONE);
if (selected) selection.setVisibility(View.VISIBLE);
else selection.setVisibility(View.GONE);

if (recent && i==0){
if (recent && i == 0) {
Drawable dr0 = AppCompatResources.getDrawable(layout.getContext(), R.drawable.emoji_recent);
Drawable dr = dr0.getConstantState().newDrawable();
if (selected) {
DrawableCompat.setTint(DrawableCompat.wrap(dr), AXEmojiManager.getStickerViewTheme().getSelectedColor());
}else{
} else {
DrawableCompat.setTint(DrawableCompat.wrap(dr), AXEmojiManager.getStickerViewTheme().getDefaultColor());
}
((AppCompatImageView)icon).setImageDrawable(dr);
}else{
int i2 = i; if (recent) i2--;
provider.getLoader().onLoadStickerCategory(((ImageView)icon),provider.getCategories()[i2],selected);
((AppCompatImageView) icon).setImageDrawable(dr);
} else {
int i2 = i;
if (recent) i2--;
provider.getLoader().onLoadStickerCategory(((ImageView) icon), provider.getCategories()[i2], selected);
}

Utils.setClickEffect(icon,true);
Utils.setClickEffect(icon, true);

View.OnClickListener listener = new View.OnClickListener(){
View.OnClickListener listener = new View.OnClickListener() {
@Override
public void onClick(View view) {
pager.setPageIndex(i);
Expand All @@ -87,13 +111,13 @@ public void onClick(View view) {

@Override
public int getItemCount() {
if (recent) return provider.getCategories().length+1;
if (recent) return provider.getCategories().length + 1;
return provider.getCategories().length;
}

@Override
public int getItemViewType(int position) {
if (position==0) return 10;
if (recent && position == 0) return 10;
return -1;
}
}
Loading

0 comments on commit ccee7e4

Please sign in to comment.