609194fae2
Signed-off-by: Samuel Holland <samuel@sholland.org>
33 lines
1.0 KiB
Java
33 lines
1.0 KiB
Java
package com.wireguard.android.util;
|
|
|
|
import android.content.ClipData;
|
|
import android.content.ClipboardManager;
|
|
import android.content.Context;
|
|
import android.view.View;
|
|
import android.widget.TextView;
|
|
|
|
import com.commonsware.cwac.crossport.design.widget.Snackbar;
|
|
|
|
/**
|
|
* Created by samuel on 12/30/17.
|
|
*/
|
|
|
|
public final class ClipboardUtils {
|
|
private ClipboardUtils() {
|
|
}
|
|
|
|
public static void copyTextView(final View view) {
|
|
if (!(view instanceof TextView))
|
|
return;
|
|
final CharSequence text = ((TextView) view).getText();
|
|
if (text == null || text.length() == 0)
|
|
return;
|
|
final Object service = view.getContext().getSystemService(Context.CLIPBOARD_SERVICE);
|
|
if (!(service instanceof ClipboardManager))
|
|
return;
|
|
final CharSequence description = view.getContentDescription();
|
|
((ClipboardManager) service).setPrimaryClip(ClipData.newPlainText(description, text));
|
|
Snackbar.make(view, description + " copied to clipboard", Snackbar.LENGTH_LONG).show();
|
|
}
|
|
}
|