move copy text to UiUtils

This commit is contained in:
sk 2022-12-19 15:12:37 +01:00 committed by LucasGGamerM
parent 71ba1bb0d5
commit 05eceecbea
2 changed files with 16 additions and 8 deletions

View File

@ -291,14 +291,7 @@ public class ProfileFragment extends LoaderFragment implements OnBackPressedList
if(!username.contains("@")){ if(!username.contains("@")){
username+="@"+AccountSessionManager.getInstance().getAccount(accountID).domain; username+="@"+AccountSessionManager.getInstance().getAccount(accountID).domain;
} }
getActivity().getSystemService(ClipboardManager.class).setPrimaryClip(ClipData.newPlainText(null, "@"+username)); UiUtils.copyText(getActivity(), '@'+username);
// fork: always show toast because MIUI doesn't play along
// if(Build.VERSION.SDK_INT<Build.VERSION_CODES.TIRAMISU){ // Android 13+ SystemUI shows its own thing when you put things into the clipboard
Toast.makeText(getActivity(), R.string.text_copied, Toast.LENGTH_SHORT).show();
// }
Vibrator vibrator = (Vibrator) getActivity().getSystemService(Context.VIBRATOR_SERVICE);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) vibrator.vibrate(VibrationEffect.createOneShot(50, VibrationEffect.DEFAULT_AMPLITUDE));
else vibrator.vibrate(50);
return true; return true;
}); });

View File

@ -3,6 +3,8 @@ package org.joinmastodon.android.ui.utils;
import android.annotation.SuppressLint; import android.annotation.SuppressLint;
import android.app.Activity; import android.app.Activity;
import android.content.ActivityNotFoundException; import android.content.ActivityNotFoundException;
import android.content.ClipData;
import android.content.ClipboardManager;
import android.content.Context; import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.content.res.ColorStateList; import android.content.res.ColorStateList;
@ -19,6 +21,8 @@ import android.os.Build;
import android.os.Bundle; import android.os.Bundle;
import android.os.Handler; import android.os.Handler;
import android.os.Looper; import android.os.Looper;
import android.os.VibrationEffect;
import android.os.Vibrator;
import android.provider.OpenableColumns; import android.provider.OpenableColumns;
import android.provider.Settings; import android.provider.Settings;
import android.text.SpannableStringBuilder; import android.text.SpannableStringBuilder;
@ -776,4 +780,15 @@ public class UiUtils{
} }
launchWebBrowser(context, url); launchWebBrowser(context, url);
} }
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.TIRAMISU){ // Android 13+ SystemUI shows its own thing when you put things into the clipboard
Toast.makeText(context, R.string.text_copied, Toast.LENGTH_SHORT).show();
// }
Vibrator vibrator = (Vibrator) context.getSystemService(Context.VIBRATOR_SERVICE);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) vibrator.vibrate(VibrationEffect.createOneShot(50, VibrationEffect.DEFAULT_AMPLITUDE));
else vibrator.vibrate(50);
}
} }