Add EmojiCompat

This commit is contained in:
Mygod
2019-01-31 20:40:24 +08:00
parent 5999ab66d1
commit 08ab6a54ff
7 changed files with 69 additions and 11 deletions

View File

@@ -64,16 +64,17 @@ dependencies {
kapt "androidx.lifecycle:lifecycle-compiler:$lifecycleVersion" kapt "androidx.lifecycle:lifecycle-compiler:$lifecycleVersion"
kapt "androidx.room:room-compiler:$roomVersion" kapt "androidx.room:room-compiler:$roomVersion"
implementation fileTree(dir: 'libs', include: ['*.jar']) implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation "androidx.browser:browser:1.0.0" implementation 'androidx.browser:browser:1.0.0'
implementation 'androidx.constraintlayout:constraintlayout:2.0.0-alpha3' implementation 'androidx.constraintlayout:constraintlayout:2.0.0-alpha3'
implementation "androidx.core:core-ktx:1.0.1" implementation 'androidx.core:core-ktx:1.0.1'
implementation 'androidx.emoji:emoji:1.0.0'
implementation "androidx.lifecycle:lifecycle-extensions:$lifecycleVersion" implementation "androidx.lifecycle:lifecycle-extensions:$lifecycleVersion"
implementation "androidx.lifecycle:lifecycle-viewmodel-ktx:$lifecycleVersion" implementation "androidx.lifecycle:lifecycle-viewmodel-ktx:$lifecycleVersion"
implementation "androidx.preference:preference:1.1.0-alpha02" implementation 'androidx.preference:preference:1.1.0-alpha02'
implementation "androidx.room:room-coroutines:$roomVersion" implementation "androidx.room:room-coroutines:$roomVersion"
implementation 'com.github.luongvo:BadgeView:1.1.5' implementation 'com.github.luongvo:BadgeView:1.1.5'
implementation 'com.github.topjohnwu.libsu:core:2.2.0' implementation 'com.github.topjohnwu.libsu:core:2.2.0'
implementation "com.google.android.material:material:1.0.0" implementation 'com.google.android.material:material:1.0.0'
implementation 'com.jakewharton.timber:timber:4.7.1' implementation 'com.jakewharton.timber:timber:4.7.1'
implementation 'com.linkedin.dexmaker:dexmaker:2.21.0' implementation 'com.linkedin.dexmaker:dexmaker:2.21.0'
implementation 'com.takisoft.preferencex:preferencex-simplemenu:1.0.0' implementation 'com.takisoft.preferencex:preferencex-simplemenu:1.0.0'
@@ -87,7 +88,7 @@ dependencies {
androidTestImplementation "androidx.room:room-testing:$roomVersion" androidTestImplementation "androidx.room:room-testing:$roomVersion"
androidTestImplementation 'androidx.test:runner:1.1.1' androidTestImplementation 'androidx.test:runner:1.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.1' androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.1'
androidTestImplementation "androidx.test.ext:junit-ktx:1.1.0" androidTestImplementation 'androidx.test.ext:junit-ktx:1.1.0'
} }
if (getGradle().getStartParameter().getTaskRequests().toString().contains("Base")) if (getGradle().getStartParameter().getTaskRequests().toString().contains("Base"))

View File

@@ -11,10 +11,14 @@ import android.preference.PreferenceManager
import androidx.browser.customtabs.CustomTabsIntent import androidx.browser.customtabs.CustomTabsIntent
import androidx.core.content.ContextCompat import androidx.core.content.ContextCompat
import androidx.core.content.getSystemService import androidx.core.content.getSystemService
import androidx.core.provider.FontRequest
import androidx.emoji.text.EmojiCompat
import androidx.emoji.text.FontRequestEmojiCompatConfig
import be.mygod.vpnhotspot.room.AppDatabase import be.mygod.vpnhotspot.room.AppDatabase
import be.mygod.vpnhotspot.util.DeviceStorageApp import be.mygod.vpnhotspot.util.DeviceStorageApp
import be.mygod.vpnhotspot.util.Event0 import be.mygod.vpnhotspot.util.Event0
import be.mygod.vpnhotspot.util.RootSession import be.mygod.vpnhotspot.util.RootSession
import timber.log.Timber
import java.util.* import java.util.*
class App : Application() { class App : Application() {
@@ -35,6 +39,16 @@ class App : Application() {
} else deviceStorage = this } else deviceStorage = this
DebugHelper.init() DebugHelper.init()
ServiceNotification.updateNotificationChannels() ServiceNotification.updateNotificationChannels()
EmojiCompat.init(FontRequestEmojiCompatConfig(deviceStorage, FontRequest(
"com.google.android.gms.fonts",
"com.google.android.gms",
"Noto Color Emoji Compat",
R.array.com_google_android_gms_fonts_certs)).apply {
setEmojiSpanIndicatorEnabled(BuildConfig.DEBUG)
registerInitCallback(object : EmojiCompat.InitCallback() {
override fun onFailed(throwable: Throwable?) = Timber.d(throwable)
})
})
} }
override fun onConfigurationChanged(newConfig: Configuration?) { override fun onConfigurationChanged(newConfig: Configuration?) {

View File

@@ -15,7 +15,6 @@ import be.mygod.vpnhotspot.room.ClientRecord
import be.mygod.vpnhotspot.room.macToString import be.mygod.vpnhotspot.room.macToString
import be.mygod.vpnhotspot.util.makeIpSpan import be.mygod.vpnhotspot.util.makeIpSpan
import be.mygod.vpnhotspot.util.makeMacSpan import be.mygod.vpnhotspot.util.makeMacSpan
import be.mygod.vpnhotspot.util.onEmpty
import java.net.InetAddress import java.net.InetAddress
import java.util.* import java.util.*
@@ -43,8 +42,10 @@ open class Client(val mac: Long, val iface: String) {
* we hijack the get title process to check if we need to perform MacLookup, * we hijack the get title process to check if we need to perform MacLookup,
* as record might not be initialized in other more appropriate places * as record might not be initialized in other more appropriate places
*/ */
if (record?.nickname.isNullOrEmpty() && record?.macLookupPending != false) MacLookup.perform(mac) SpannableStringBuilder(if (record?.nickname.isNullOrEmpty()) {
SpannableStringBuilder(record?.nickname.onEmpty(macIface)).apply { if (record?.macLookupPending != false) MacLookup.perform(mac)
macIface
} else emojize(record?.nickname)).apply {
if (record?.blocked == true) { if (record?.blocked == true) {
setSpan(StrikethroughSpan(), 0, length, Spanned.SPAN_INCLUSIVE_INCLUSIVE) setSpan(StrikethroughSpan(), 0, length, Spanned.SPAN_INCLUSIVE_INCLUSIVE)
} }

View File

@@ -55,7 +55,7 @@ class ClientsFragment : Fragment(), MainScope by MainScope.Supervisor() {
setTitle(getString(R.string.clients_nickname_title, arg.mac.macToString())) setTitle(getString(R.string.clients_nickname_title, arg.mac.macToString()))
setPositiveButton(android.R.string.ok, listener) setPositiveButton(android.R.string.ok, listener)
setNegativeButton(android.R.string.cancel, null) setNegativeButton(android.R.string.cancel, null)
setNeutralButton(R.string.clients_nickname_set_to_vendor, listener) setNeutralButton(emojize(getText(R.string.clients_nickname_set_to_vendor)), listener)
} }
override fun onCreateDialog(savedInstanceState: Bundle?) = super.onCreateDialog(savedInstanceState).apply { override fun onCreateDialog(savedInstanceState: Bundle?) = super.onCreateDialog(savedInstanceState).apply {

View File

@@ -0,0 +1,10 @@
package be.mygod.vpnhotspot.client
import androidx.emoji.text.EmojiCompat
import java.lang.IllegalStateException
fun emojize(text: CharSequence?): CharSequence? = if (text == null) null else try {
EmojiCompat.get().process(text)
} catch (_: IllegalStateException) {
text
}

View File

@@ -4,7 +4,7 @@
xmlns:tools="http://schemas.android.com/tools" xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content"> android:layout_height="wrap_content">
<EditText <androidx.emoji.widget.EmojiEditText
android:id="@android:id/edit" android:id="@android:id/edit"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
@@ -13,5 +13,5 @@
android:importantForAutofill="no" android:importantForAutofill="no"
tools:text="Nick"> tools:text="Nick">
<requestFocus/> <requestFocus/>
</EditText> </androidx.emoji.widget.EmojiEditText>
</FrameLayout> </FrameLayout>

View File

@@ -0,0 +1,32 @@
<?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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