-
-
Notifications
You must be signed in to change notification settings - Fork 290
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add emoji-material module for material bindings. (#394)
* Add emoji-material module for material bindings. * Add new lines. * More new lines. Co-authored-by: Ruben Gees <[email protected]>
- Loading branch information
1 parent
a2475e9
commit 3b132a3
Showing
29 changed files
with
320 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,8 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<resources> | ||
<style name="AppTheme" parent="Theme.AppCompat.DayNight.DarkActionBar"> | ||
<style name="AppTheme" parent="Theme.MaterialComponents.DayNight.DarkActionBar"> | ||
<item name="colorPrimary">@color/colorPrimary</item> | ||
<item name="colorPrimaryDark">@color/colorPrimaryDark</item> | ||
<item name="colorAccent">@color/colorAccent</item> | ||
<item name="colorSecondary">@color/colorSecondary</item> | ||
</style> | ||
</resources> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
POM_NAME=Emoji | ||
POM_ARTIFACT_ID=emoji-google-compat | ||
POM_PACKAGING=aar | ||
POM_PACKAGING=aar |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
POM_NAME=Emoji | ||
POM_ARTIFACT_ID=emoji-google | ||
POM_PACKAGING=aar | ||
POM_PACKAGING=aar |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
POM_NAME=Emoji | ||
POM_ARTIFACT_ID=emoji-ios | ||
POM_PACKAGING=aar | ||
POM_PACKAGING=aar |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
POM_NAME=Emoji | ||
POM_ARTIFACT_ID=emoji-kotlin | ||
POM_PACKAGING=aar | ||
POM_PACKAGING=aar |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
apply plugin: 'com.android.library' | ||
|
||
android { | ||
compileSdkVersion rootProject.ext.compileSdkVersion as int | ||
|
||
compileOptions { | ||
sourceCompatibility JavaVersion.VERSION_1_7 | ||
targetCompatibility JavaVersion.VERSION_1_7 | ||
} | ||
|
||
defaultConfig { | ||
minSdkVersion rootProject.ext.minSdkVersion as int | ||
} | ||
|
||
resourcePrefix 'emoji_' | ||
} | ||
|
||
dependencies { | ||
api project(':emoji') | ||
api deps.support.material | ||
} | ||
|
||
apply plugin: "com.vanniktech.maven.publish" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
POM_NAME=Emoji | ||
POM_ARTIFACT_ID=emoji-material | ||
POM_PACKAGING=aar |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
<manifest package="com.vanniktech.emoji.material" /> |
78 changes: 78 additions & 0 deletions
78
emoji-material/src/main/java/com/vanniktech/emoji/material/EmojiMaterialButton.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
package com.vanniktech.emoji.material; | ||
|
||
import android.content.Context; | ||
import android.content.res.TypedArray; | ||
import android.graphics.Paint; | ||
import android.text.SpannableStringBuilder; | ||
import android.util.AttributeSet; | ||
import androidx.annotation.CallSuper; | ||
import androidx.annotation.DimenRes; | ||
import androidx.annotation.Px; | ||
import com.google.android.material.button.MaterialButton; | ||
import com.vanniktech.emoji.EmojiManager; | ||
|
||
@SuppressWarnings("CPD-START") public class EmojiMaterialButton extends MaterialButton { | ||
private float emojiSize; | ||
|
||
public EmojiMaterialButton(final Context context) { | ||
this(context, null); | ||
} | ||
|
||
public EmojiMaterialButton(final Context context, final AttributeSet attrs) { | ||
super(context, attrs); | ||
|
||
if (!isInEditMode()) { | ||
EmojiManager.getInstance().verifyInstalled(); | ||
} | ||
|
||
final Paint.FontMetrics fontMetrics = getPaint().getFontMetrics(); | ||
final float defaultEmojiSize = fontMetrics.descent - fontMetrics.ascent; | ||
|
||
if (attrs == null) { | ||
emojiSize = defaultEmojiSize; | ||
} else { | ||
final TypedArray a = getContext().obtainStyledAttributes(attrs, R.styleable.EmojiMaterialButton); | ||
|
||
try { | ||
emojiSize = a.getDimension(R.styleable.EmojiMaterialButton_emojiSize, defaultEmojiSize); | ||
} finally { | ||
a.recycle(); | ||
} | ||
} | ||
|
||
setText(getText()); | ||
} | ||
|
||
@Override @CallSuper public void setText(final CharSequence rawText, final BufferType type) { | ||
final CharSequence text = rawText == null ? "" : rawText; | ||
final SpannableStringBuilder spannableStringBuilder = new SpannableStringBuilder(text); | ||
final Paint.FontMetrics fontMetrics = getPaint().getFontMetrics(); | ||
final float defaultEmojiSize = fontMetrics.descent - fontMetrics.ascent; | ||
EmojiManager.getInstance().replaceWithImages(getContext(), spannableStringBuilder, emojiSize, defaultEmojiSize); | ||
super.setText(spannableStringBuilder, type); | ||
} | ||
|
||
/** 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); | ||
} | ||
|
||
/** 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()); | ||
} | ||
} | ||
|
||
/** 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); | ||
} | ||
|
||
/** 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); | ||
} | ||
} |
78 changes: 78 additions & 0 deletions
78
emoji-material/src/main/java/com/vanniktech/emoji/material/EmojiMaterialCheckBox.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
package com.vanniktech.emoji.material; | ||
|
||
import android.content.Context; | ||
import android.content.res.TypedArray; | ||
import android.graphics.Paint; | ||
import android.text.SpannableStringBuilder; | ||
import android.util.AttributeSet; | ||
import androidx.annotation.CallSuper; | ||
import androidx.annotation.DimenRes; | ||
import androidx.annotation.Px; | ||
import com.google.android.material.checkbox.MaterialCheckBox; | ||
import com.vanniktech.emoji.EmojiManager; | ||
|
||
@SuppressWarnings("CPD-START") public class EmojiMaterialCheckBox extends MaterialCheckBox { | ||
private float emojiSize; | ||
|
||
public EmojiMaterialCheckBox(final Context context) { | ||
this(context, null); | ||
} | ||
|
||
public EmojiMaterialCheckBox(final Context context, final AttributeSet attrs) { | ||
super(context, attrs); | ||
|
||
if (!isInEditMode()) { | ||
EmojiManager.getInstance().verifyInstalled(); | ||
} | ||
|
||
final Paint.FontMetrics fontMetrics = getPaint().getFontMetrics(); | ||
final float defaultEmojiSize = fontMetrics.descent - fontMetrics.ascent; | ||
|
||
if (attrs == null) { | ||
emojiSize = defaultEmojiSize; | ||
} else { | ||
final TypedArray a = getContext().obtainStyledAttributes(attrs, R.styleable.EmojiMaterialCheckBox); | ||
|
||
try { | ||
emojiSize = a.getDimension(R.styleable.EmojiMaterialCheckBox_emojiSize, defaultEmojiSize); | ||
} finally { | ||
a.recycle(); | ||
} | ||
} | ||
|
||
setText(getText()); | ||
} | ||
|
||
@Override @CallSuper public void setText(final CharSequence rawText, final BufferType type) { | ||
final CharSequence text = rawText == null ? "" : rawText; | ||
final SpannableStringBuilder spannableStringBuilder = new SpannableStringBuilder(text); | ||
final Paint.FontMetrics fontMetrics = getPaint().getFontMetrics(); | ||
final float defaultEmojiSize = fontMetrics.descent - fontMetrics.ascent; | ||
EmojiManager.getInstance().replaceWithImages(getContext(), spannableStringBuilder, emojiSize, defaultEmojiSize); | ||
super.setText(spannableStringBuilder, type); | ||
} | ||
|
||
/** 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); | ||
} | ||
|
||
/** 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()); | ||
} | ||
} | ||
|
||
/** 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); | ||
} | ||
|
||
/** 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); | ||
} | ||
} |
Oops, something went wrong.