From 4e5b9ef2e20d296b616405e142e4decea21a1218 Mon Sep 17 00:00:00 2001 From: Samuel Holland Date: Thu, 24 Aug 2017 02:11:55 -0500 Subject: ConfigEditFragment: Copy public key on click --- .../java/com/wireguard/android/ConfigEditFragment.java | 14 ++++++++++++++ app/src/main/res/layout/config_edit_fragment.xml | 3 +++ app/src/main/res/values/strings.xml | 2 ++ 3 files changed, 19 insertions(+) (limited to 'app/src/main') diff --git a/app/src/main/java/com/wireguard/android/ConfigEditFragment.java b/app/src/main/java/com/wireguard/android/ConfigEditFragment.java index 48d32d39..ebebef42 100644 --- a/app/src/main/java/com/wireguard/android/ConfigEditFragment.java +++ b/app/src/main/java/com/wireguard/android/ConfigEditFragment.java @@ -1,6 +1,8 @@ package com.wireguard.android; import android.app.Activity; +import android.content.ClipData; +import android.content.ClipboardManager; import android.content.Context; import android.os.Bundle; import android.view.LayoutInflater; @@ -23,6 +25,18 @@ public class ConfigEditFragment extends BaseConfigFragment { private static final String KEY_MODIFIED_CONFIG = "modifiedConfig"; private static final String KEY_ORIGINAL_NAME = "originalName"; + public static void copyPublicKey(final Context context, final String publicKey) { + if (publicKey == null || publicKey.isEmpty()) + return; + final ClipboardManager clipboard = + (ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE); + final String description = + context.getResources().getString(R.string.public_key_description); + clipboard.setPrimaryClip(ClipData.newPlainText(description, publicKey)); + final String message = context.getResources().getString(R.string.public_key_copied_message); + Toast.makeText(context, message, Toast.LENGTH_SHORT).show(); + } + private Config localConfig; private String originalName; diff --git a/app/src/main/res/layout/config_edit_fragment.xml b/app/src/main/res/layout/config_edit_fragment.xml index 86045324..e0d564f9 100644 --- a/app/src/main/res/layout/config_edit_fragment.xml +++ b/app/src/main/res/layout/config_edit_fragment.xml @@ -5,6 +5,8 @@ + + @@ -107,6 +109,7 @@ android:focusable="false" android:hint="@string/hint_generated" android:maxLines="1" + android:onClick="@{(view) -> ConfigEditFragment.copyPublicKey(view.getContext(), config.interface.publicKey)}" android:text="@{config.interface.publicKey}" /> This configuration will be controlled by the quick settings tile Private key Public key + Public key copied to clipboard + WireGuard public key Restore on boot Restore previously enabled configurations on boot Save -- cgit v1.2.3