From eb1dd954ee0071120118efdac03e6990918d4aef Mon Sep 17 00:00:00 2001 From: sk Date: Mon, 19 Dec 2022 19:03:11 +0100 Subject: [PATCH] merge miui fix for copying text --- .../android/ui/utils/UiUtils.java | 21 +++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/mastodon/src/main/java/org/joinmastodon/android/ui/utils/UiUtils.java b/mastodon/src/main/java/org/joinmastodon/android/ui/utils/UiUtils.java index d82206621..d64413b8a 100644 --- a/mastodon/src/main/java/org/joinmastodon/android/ui/utils/UiUtils.java +++ b/mastodon/src/main/java/org/joinmastodon/android/ui/utils/UiUtils.java @@ -27,6 +27,7 @@ import android.provider.OpenableColumns; import android.provider.Settings; import android.text.SpannableStringBuilder; import android.text.Spanned; +import android.text.TextUtils; import android.view.Menu; import android.view.MenuItem; import android.view.View; @@ -783,12 +784,24 @@ public class UiUtils{ public static void copyText(Context context, String text) { context.getSystemService(ClipboardManager.class).setPrimaryClip(ClipData.newPlainText(null, text)); - // fork: always show toast because MIUI doesn't play along - // if(Build.VERSION.SDK_INT= Build.VERSION_CODES.O) vibrator.vibrate(VibrationEffect.createOneShot(50, VibrationEffect.DEFAULT_AMPLITUDE)); else vibrator.vibrate(50); } + + private static String getSystemProperty(String key){ + try{ + Class props=Class.forName("android.os.SystemProperties"); + Method get=props.getMethod("get", String.class); + return (String)get.invoke(null, key); + }catch(Exception ignore){} + return null; + } + + public static boolean isMIUI(){ + return !TextUtils.isEmpty(getSystemProperty("ro.miui.ui.version.code")); + } }