Skip to content

Commit

Permalink
Nuke EmojiEditTextInterface and allow any kind of EditText to be passed.
Browse files Browse the repository at this point in the history
  • Loading branch information
vanniktech committed Jan 16, 2019
1 parent 182e1ff commit 40ec068
Show file tree
Hide file tree
Showing 20 changed files with 118 additions and 139 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public static void show(@NonNull final AppCompatActivity activity) {
super.onStop();
}

@NonNull @Override public Dialog onCreateDialog(final Bundle savedInstanceState) {
@Override @NonNull public Dialog onCreateDialog(final Bundle savedInstanceState) {
return new AlertDialog.Builder(getContext())
.setView(buildView())
.create();
Expand Down
36 changes: 18 additions & 18 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ apply plugin: 'com.vanniktech.code.quality.tools'
apply plugin: 'com.vanniktech.android.junit.jacoco'

buildscript {
ext.kotlinVersion = '1.2.41'
ext.kotlinVersion = '1.3.11'
ext.versions = [
espresso: '3.0.1',
testRules: '1.0.1',
espresso: '3.0.2',
testRules: '1.0.2',
]

ext.deps = [
Expand All @@ -19,7 +19,7 @@ buildscript {
'rules': "com.android.support.test:rules:${versions.testRules}",
],
],
'fastLaneScreenGrab': "tools.fastlane:screengrab:1.1.0",
'fastLaneScreenGrab': "tools.fastlane:screengrab:1.2.0",
]

repositories {
Expand All @@ -28,12 +28,12 @@ buildscript {
gradlePluginPortal()
}
dependencies {
classpath 'com.vanniktech:gradle-code-quality-tools-plugin:0.10.0'
classpath 'com.vanniktech:gradle-code-quality-tools-plugin:0.15.0'
classpath 'com.vanniktech:gradle-android-junit-jacoco-plugin:0.11.0'
classpath 'com.vanniktech:gradle-maven-publish-plugin:0.4.0'
classpath 'com.vanniktech:gradle-maven-publish-plugin:0.7.0'

classpath 'com.android.tools.build:gradle:3.0.1'
classpath 'com.github.ben-manes:gradle-versions-plugin:0.17.0'
classpath 'com.android.tools.build:gradle:3.3.0'
classpath 'com.github.ben-manes:gradle-versions-plugin:0.20.0'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlinVersion"
}
}
Expand All @@ -49,10 +49,10 @@ codeQualityTools {
toolVersion = '6.0.1'
}
ktlint {
toolVersion = '0.24.0'
toolVersion = '0.29.0'
}
detekt {
toolVersion = '1.0.0.RC7'
toolVersion = '1.0.0-RC12'
}
errorProne {
toolVersion = '2.1.2'
Expand All @@ -74,11 +74,11 @@ subprojects {

ext {
minSdkVersion = 15
compileSdkVersion = 27
targetSdkVersion = 27
compileSdkVersion = 28
targetSdkVersion = 28

supportLibraryVersion = '27.0.2'
leakCanaryVersion = '1.5.1'
supportLibraryVersion = '28.0.0'
leakCanaryVersion = '1.6.3'

versionCode = VERSION_CODE
versionName = VERSION_NAME
Expand All @@ -96,17 +96,17 @@ ext {
leakCanaryRelease = "com.squareup.leakcanary:leakcanary-android-no-op:$leakCanaryVersion"

testing = [
junit : 'junit:junit:4.12',
junit : 'junit:junit:4.13-beta1',
robolectric : 'org.robolectric:robolectric:3.5.1',
privateConstructor: 'com.pushtorefresh.java-private-constructor-checker:checker:1.2.0',
assertJ : 'org.assertj:assertj-core:3.8.0'
assertJ : 'org.assertj:assertj-core:3.11.1'
]

javaVersion = JavaVersion.VERSION_1_7
}

task wrapper(type: Wrapper) {
gradleVersion = '4.8'
wrapper {
gradleVersion = '5.0'
distributionType = Wrapper.DistributionType.ALL
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public GoogleCompatEmoji(final int codePoint, final Emoji... emojis) {
super(codePoint, -1, emojis);
}

@NonNull @Override public Drawable getDrawable(@NonNull final Context context) {
@Override @NonNull public Drawable getDrawable(@NonNull final Context context) {
return new GoogleCompatEmojiDrawable(getUnicode());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public GoogleEmoji(@NonNull final int[] codePoints, final int x, final int y, fi
this.y = y;
}

@NonNull @Override public Drawable getDrawable(final Context context) {
@Override @NonNull public Drawable getDrawable(final Context context) {
final CacheKey key = new CacheKey(x, y);
final Bitmap bitmap = BITMAP_CACHE.get(key);
if (bitmap != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public IosEmoji(@NonNull final int[] codePoints, final int x, final int y, final
this.y = y;
}

@NonNull @Override public Drawable getDrawable(final Context context) {
@Override @NonNull public Drawable getDrawable(final Context context) {
final CacheKey key = new CacheKey(x, y);
final Bitmap bitmap = BITMAP_CACHE.get(key);
if (bitmap != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public EmojiOne(@NonNull final int[] codePoints, final int x, final int y, final
this.y = y;
}

@NonNull @Override public Drawable getDrawable(final Context context) {
@Override @NonNull public Drawable getDrawable(final Context context) {
final CacheKey key = new CacheKey(x, y);
final Bitmap bitmap = BITMAP_CACHE.get(key);
if (bitmap != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public TwitterEmoji(@NonNull final int[] codePoints, final int x, final int y, f
this.y = y;
}

@NonNull @Override public Drawable getDrawable(final Context context) {
@Override @NonNull public Drawable getDrawable(final Context context) {
final CacheKey key = new CacheKey(x, y);
final Bitmap bitmap = BITMAP_CACHE.get(key);
if (bitmap != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ final class EmojiArrayAdapter extends ArrayAdapter<Emoji> {
this.longListener = longListener;
}

@NonNull @Override public View getView(final int position, final View convertView, @NonNull final ViewGroup parent) {
@Override @NonNull public View getView(final int position, final View convertView, @NonNull final ViewGroup parent) {
EmojiImageView image = (EmojiImageView) convertView;

final Context context = getContext();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,11 @@
import android.support.annotation.Px;
import android.support.v7.widget.AppCompatAutoCompleteTextView;
import android.util.AttributeSet;
import android.view.KeyEvent;

import com.vanniktech.emoji.emoji.Emoji;

/** Reference implementation for an EmojiAutoCompleteTextView with emoji support. */
@SuppressWarnings("CPD-START") public class EmojiAutoCompleteTextView extends AppCompatAutoCompleteTextView implements EmojiEditTextInterface {
@SuppressWarnings("CPD-START") public class EmojiAutoCompleteTextView extends AppCompatAutoCompleteTextView {
private float emojiSize;

public EmojiAutoCompleteTextView(final Context context) {
Expand Down Expand Up @@ -51,45 +50,40 @@ public EmojiAutoCompleteTextView(final Context context, final AttributeSet attrs
EmojiManager.getInstance().replaceWithImages(getContext(), getText(), emojiSize, defaultEmojiSize);
}

@Override public float getEmojiSize() {
return emojiSize;
@CallSuper public void backspace() {
Utils.backspace(this);
}

@Override @CallSuper public void backspace() {
final KeyEvent event = new KeyEvent(0, 0, 0, KeyEvent.KEYCODE_DEL, 0, 0, 0, 0, KeyEvent.KEYCODE_ENDCALL);
dispatchKeyEvent(event);
@CallSuper public void input(final Emoji emoji) {
Utils.input(this, emoji);
}

@Override @CallSuper public void input(final Emoji emoji) {
if (emoji != null) {
final int start = getSelectionStart();
final int end = getSelectionEnd();

if (start < 0) {
append(emoji.getUnicode());
} else {
getText().replace(Math.min(start, end), Math.max(start, end), emoji.getUnicode(), 0, emoji.getUnicode().length());
}
}
/** returns the emoji size */
public final float getEmojiSize() {
return emojiSize;
}

@Override public final void setEmojiSize(@Px final int pixels) {
/** sets the emoji size in pixels and automatically invalidates the text and renders it with the new size */
public final void setEmojiSize(@Px final int pixels) {
setEmojiSize(pixels, true);
}

@Override public final void setEmojiSize(@Px final int pixels, final boolean shouldInvalidate) {
/** sets the emoji size in pixels and automatically invalidates the text and renders it with the new size when {@code shouldInvalidate} is true */
public final void setEmojiSize(@Px final int pixels, final boolean shouldInvalidate) {
emojiSize = pixels;

if (shouldInvalidate) {
setText(getText());
}
}

@Override public final void setEmojiSizeRes(@DimenRes final int res) {
/** sets the emoji size in pixels with the provided resource and automatically invalidates the text and renders it with the new size */
public final void setEmojiSizeRes(@DimenRes final int res) {
setEmojiSizeRes(res, true);
}

@Override public final void setEmojiSizeRes(@DimenRes final int res, final boolean shouldInvalidate) {
/** sets the emoji size in pixels with the provided resource and invalidates the text and renders it with the new size when {@code shouldInvalidate} is true */
public final void setEmojiSizeRes(@DimenRes final int res, final boolean shouldInvalidate) {
setEmojiSize(getResources().getDimensionPixelSize(res), shouldInvalidate);
}
}
39 changes: 17 additions & 22 deletions emoji/src/main/java/com/vanniktech/emoji/EmojiEditText.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@
import android.support.annotation.Px;
import android.support.v7.widget.AppCompatEditText;
import android.util.AttributeSet;
import android.view.KeyEvent;

import com.vanniktech.emoji.emoji.Emoji;

/** Reference implementation for an EditText with emoji support. */
@SuppressWarnings("CPD-START") public class EmojiEditText extends AppCompatEditText implements EmojiEditTextInterface {
@SuppressWarnings("CPD-START") public class EmojiEditText extends AppCompatEditText {
private float emojiSize;

public EmojiEditText(final Context context) {
Expand Down Expand Up @@ -50,45 +50,40 @@ public EmojiEditText(final Context context, final AttributeSet attrs) {
EmojiManager.getInstance().replaceWithImages(getContext(), getText(), emojiSize, defaultEmojiSize);
}

@Override public float getEmojiSize() {
return emojiSize;
@CallSuper public void backspace() {
Utils.backspace(this);
}

@Override @CallSuper public void backspace() {
final KeyEvent event = new KeyEvent(0, 0, 0, KeyEvent.KEYCODE_DEL, 0, 0, 0, 0, KeyEvent.KEYCODE_ENDCALL);
dispatchKeyEvent(event);
@CallSuper public void input(final Emoji emoji) {
Utils.input(this, emoji);
}

@Override @CallSuper public void input(final Emoji emoji) {
if (emoji != null) {
final int start = getSelectionStart();
final int end = getSelectionEnd();

if (start < 0) {
append(emoji.getUnicode());
} else {
getText().replace(Math.min(start, end), Math.max(start, end), emoji.getUnicode(), 0, emoji.getUnicode().length());
}
}
/** returns the emoji size */
public final float getEmojiSize() {
return emojiSize;
}

@Override public final void setEmojiSize(@Px final int pixels) {
/** sets the emoji size in pixels and automatically invalidates the text and renders it with the new size */
public final void setEmojiSize(@Px final int pixels) {
setEmojiSize(pixels, true);
}

@Override public final void setEmojiSize(@Px final int pixels, final boolean shouldInvalidate) {
/** sets the emoji size in pixels and automatically invalidates the text and renders it with the new size when {@code shouldInvalidate} is true */
public final void setEmojiSize(@Px final int pixels, final boolean shouldInvalidate) {
emojiSize = pixels;

if (shouldInvalidate) {
setText(getText());
}
}

@Override public final void setEmojiSizeRes(@DimenRes final int res) {
/** sets the emoji size in pixels with the provided resource and automatically invalidates the text and renders it with the new size */
public final void setEmojiSizeRes(@DimenRes final int res) {
setEmojiSizeRes(res, true);
}

@Override public final void setEmojiSizeRes(@DimenRes final int res, final boolean shouldInvalidate) {
/** sets the emoji size in pixels with the provided resource and invalidates the text and renders it with the new size when {@code shouldInvalidate} is true */
public final void setEmojiSizeRes(@DimenRes final int res, final boolean shouldInvalidate) {
setEmojiSize(getResources().getDimensionPixelSize(res), shouldInvalidate);
}
}

This file was deleted.

Loading

0 comments on commit 40ec068

Please sign in to comment.