Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Edit screen: add emoji compat #49

Merged
merged 14 commits into from
Oct 15, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ dependencies {
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
implementation 'androidx.navigation:navigation-fragment-ktx:2.0.0'
implementation 'androidx.navigation:navigation-ui-ktx:2.0.0'
implementation 'androidx.emoji:emoji:1.0.0'
implementation "androidx.preference:preference-ktx:1.1.0-rc01"

implementation 'com.google.android.material:material:1.0.0'
Expand Down
4 changes: 4 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@

<uses-permission android:name="android.permission.VIBRATE"/>

<!-- Adding this meta-data will download the font when application is installed from
Google Play Store. This way the font will be downloaded and ready when your app starts
for the first time. -->
<meta-data android:name="fontProviderRequests" android:value="Noto Color Emoji Compat"/>

<application
android:allowBackup="true"
Expand Down
39 changes: 38 additions & 1 deletion app/src/main/java/com/automattic/portkey/Portkey.kt
Original file line number Diff line number Diff line change
@@ -1,17 +1,54 @@
package com.automattic.portkey

import android.app.Application
import android.util.Log
import androidx.core.provider.FontRequest
import androidx.emoji.text.EmojiCompat
import androidx.emoji.text.FontRequestEmojiCompatConfig
import com.automattic.portkey.R.array
import com.automattic.portkey.util.CrashLoggingUtils

class Portkey : Application() {
private var statusBarHeight: Int = 0

override fun onCreate() {
super.onCreate()

AppPrefs.init(this)

CrashLoggingUtils.startCrashLogging(this)

initEmojiCompat()
}

private fun initEmojiCompat() {
val config: EmojiCompat.Config

// Use a downloadable font for EmojiCompat
val fontRequest = FontRequest(
"com.google.android.gms.fonts",
"com.google.android.gms",
"Noto Color Emoji Compat",
array.com_google_android_gms_fonts_certs
)
config = FontRequestEmojiCompatConfig(applicationContext, fontRequest)
config.setReplaceAll(true)
config.setUseEmojiAsDefaultStyle(true)

config.registerInitCallback(object : EmojiCompat.InitCallback() {
override fun onInitialized() {
Log.d(TAG, "EmojiCompat initialized")
}

override fun onFailed(throwable: Throwable?) {
Log.d(TAG, "EmojiCompat initialization failed", throwable)
}
})

EmojiCompat.init(config)
}

companion object {
const val TAG = "Portkey"
}

fun setStatusBarHeight(newHeight: Int) {
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/layout/row_emoji.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
android:layout_width="match_parent"
android:layout_height="wrap_content">

<TextView
<androidx.emoji.widget.EmojiTextView
android:id="@+id/txtEmoji"
android:layout_width="match_parent"
android:layout_height="wrap_content"
Expand Down
29 changes: 29 additions & 0 deletions app/src/main/res/values/font_certs.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
Copyright 2017 The Android Open Source Project
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.
-->
<resources>
<array name="com_google_android_gms_fonts_certs">
<item>@array/com_google_android_gms_fonts_certs_dev</item>
<item>@array/com_google_android_gms_fonts_certs_prod</item>
</array>
<string-array name="com_google_android_gms_fonts_certs_dev">
<item>
MIIEqDCCA5CgAwIBAgIJANWFuGx90071MA0GCSqGSIb3DQEBBAUAMIGUMQswCQYDVQQGEwJVUzETMBEGA1UECBMKQ2FsaWZvcm5pYTEWMBQG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puzSqeYTcfi6idkyugwfYwXFU1+5fZKUaRKYCwkkFQVfcAs1fXA5V+++FGfvjJ/CxURaSxaBvGdGDhfXE28LWuT9ozCl5xw4Yq5OGazvV24mZVSoOO0yZ31j7kYvtwYK6NeADwbSxDdJEqO4k//0zOHKrUiGYXtqw/A0LFFtqoZKFjnkCAQOjgdkwgdYwHQYDVR0OBBYEFMd9jMIhF1Ylmn/Tgt9r45jk14alMIGmBgNVHSMEgZ4wgZuAFMd9jMIhF1Ylmn/Tgt9r45jk14aloXikdjB0MQswCQYDVQQGEwJVUzETMBEGA1UECBMKQ2FsaWZvcm5pYTEWMBQGA1UEBxMNTW91bnRhaW4gVmlldzEUMBIGA1UEChMLR29vZ2xlIEluYy4xEDAOBgNVBAsTB0FuZHJvaWQxEDAOBgNVBAMTB0FuZHJvaWSCCQDC4IdGZEowjTAMBgNVHRMEBTADAQH/MA0GCSqGSIb3DQEBBAUAA4IBAQBt0lLO74UwLDYKqs6Tm8/yzKkEu116FmH4rkaymUIE0P9KaMftGlMexFlaYjzmB2OxZyl6euNXEsQH8gjwyxCUKRJNexBiGcCEyj6z+a1fuHHvkiaai+KL8W1EyNmgjmyy8AW7P+LLlkR+ho5zEHatRbM/YAnqGcFh5iZBqpknHf1SKMXFh4dd239FJ1jWYfbMDMy3NS5CTMQ2XFI1MvcyUTdZPErjQfTbQe3aDQsQcafEQPD+nqActifKZ0Np0IS9L9kR/wbNvyz6ENwPiTrjV2KRkEjH78ZMcUQXg0L3BYHJ3lc69Vs5Ddf9uUGGMYldX3WfMBEmh/9iFBDAaTCK
</item>
</string-array>
</resources>
1 change: 1 addition & 0 deletions photoeditor/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ dependencies {
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test:runner:1.2.0'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
implementation 'androidx.emoji:emoji:1.0.0'
}
repositories {
mavenCentral()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ import androidx.annotation.ColorInt
import androidx.annotation.IntRange
import androidx.annotation.RequiresPermission
import androidx.annotation.UiThread
import androidx.emoji.text.EmojiCompat
import androidx.emoji.text.EmojiCompat.InitCallback
import com.automattic.photoeditor.gesture.MultiTouchListener
import com.automattic.photoeditor.gesture.MultiTouchListener.OnMultiTouchListener
import com.automattic.photoeditor.util.BitmapUtil
Expand All @@ -48,6 +50,7 @@ import java.io.File
import java.io.FileInputStream
import java.io.FileOutputStream
import java.util.ArrayList
import java.lang.ref.WeakReference

/**
*
Expand Down Expand Up @@ -367,9 +370,31 @@ class PhotoEditor private constructor(builder: Builder) :

if (emojiTypeface != null) {
emojiTextView.typeface = emojiTypeface
emojiTextView.text = emojiName
} else {
// if user did not set a specific emojiTypeface, use EmojiCompat to process
// the string and make sure we have an emoji that can be rendered
EmojiCompat.get().registerInitCallback(object : EmojiCompat.InitCallback() {
val regularTextViewRef = WeakReference(emojiTextView)
override fun onInitialized() {
EmojiCompat.get().unregisterInitCallback(this)

val regularTextView = regularTextViewRef.get()
if (regularTextView != null) {
val compat = EmojiCompat.get()
regularTextView.text = compat.process(emojiName)
}
}

override fun onFailed(throwable: Throwable?) {
EmojiCompat.get().unregisterInitCallback(this)

// just fallback to setting the text
emojiTextView.text = emojiName
}
})
}
emojiTextView.textSize = 56f
emojiTextView.text = emojiName

// hide cross and background borders for now
imgClose.visibility = View.GONE
Expand Down Expand Up @@ -418,7 +443,7 @@ class PhotoEditor private constructor(builder: Builder) :
rootView = layoutInflater.inflate(R.layout.view_photo_editor_text, null)
if (rootView.tvPhotoEditorText != null && mDefaultTextTypeface != null) {
rootView.tvPhotoEditorText.gravity = Gravity.CENTER
if (mDefaultEmojiTypeface != null) {
if (mDefaultTextTypeface != null) {
rootView.tvPhotoEditorText.typeface = mDefaultTextTypeface
}
}
Expand Down