ConfigEditFragment: Copy public key on click

Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
This commit is contained in:
Samuel Holland 2017-08-24 02:11:55 -05:00
parent 4fdb3458ec
commit dcc7ddcd3b
3 changed files with 19 additions and 0 deletions

View File

@ -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;

View File

@ -5,6 +5,8 @@
<data>
<import type="com.wireguard.android.ConfigEditFragment" />
<import type="com.wireguard.android.KeyInputFilter" />
<import type="com.wireguard.android.NameInputFilter" />
@ -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}" />
<TextView

View File

@ -34,6 +34,8 @@
<string name="primary_config_summary">This configuration will be controlled by the quick settings tile</string>
<string name="private_key">Private key</string>
<string name="public_key">Public key</string>
<string name="public_key_copied_message">Public key copied to clipboard</string>
<string name="public_key_description">WireGuard public key</string>
<string name="restore_on_boot">Restore on boot</string>
<string name="restore_on_boot_summary">Restore previously enabled configurations on boot</string>
<string name="save">Save</string>