diff --git a/res/values/strings.xml b/res/values/strings.xml index 58cc856a9a..815af39a35 100644 --- a/res/values/strings.xml +++ b/res/values/strings.xml @@ -1529,5 +1529,8 @@ Copy Copied to Clipboard Register + + Share Public Key + Copied to Clipboard diff --git a/res/xml/preferences.xml b/res/xml/preferences.xml index af30444510..f6cfb733e4 100644 --- a/res/xml/preferences.xml +++ b/res/xml/preferences.xml @@ -33,4 +33,8 @@ android:title="@string/preferences__advanced" android:icon="@drawable/ic_advanced_24dp"/> + + diff --git a/src/org/thoughtcrime/securesms/ApplicationPreferencesActivity.java b/src/org/thoughtcrime/securesms/ApplicationPreferencesActivity.java index 77cc32e981..0ee87804df 100644 --- a/src/org/thoughtcrime/securesms/ApplicationPreferencesActivity.java +++ b/src/org/thoughtcrime/securesms/ApplicationPreferencesActivity.java @@ -18,6 +18,8 @@ package org.thoughtcrime.securesms; import android.annotation.TargetApi; +import android.content.ClipData; +import android.content.ClipboardManager; import android.content.Context; import android.content.Intent; import android.content.SharedPreferences; @@ -33,6 +35,7 @@ import android.support.v4.app.FragmentTransaction; import android.support.v4.content.ContextCompat; import android.support.v4.graphics.drawable.DrawableCompat; import android.support.v7.preference.Preference; +import android.widget.Toast; import org.thoughtcrime.securesms.preferences.AdvancedPreferenceFragment; import org.thoughtcrime.securesms.preferences.AppProtectionPreferenceFragment; @@ -68,6 +71,7 @@ public class ApplicationPreferencesActivity extends PassphraseRequiredActionBarA private static final String PREFERENCE_CATEGORY_CHATS = "preference_category_chats"; private static final String PREFERENCE_CATEGORY_DEVICES = "preference_category_devices"; private static final String PREFERENCE_CATEGORY_ADVANCED = "preference_category_advanced"; + private static final String PREFERENCE_CATEGORY_PUBLIC_KEY = "preference_category_public_key"; private final DynamicTheme dynamicTheme = new DynamicTheme(); private final DynamicLanguage dynamicLanguage = new DynamicLanguage(); @@ -154,6 +158,8 @@ public class ApplicationPreferencesActivity extends PassphraseRequiredActionBarA .setOnPreferenceClickListener(new CategoryClickListener(PREFERENCE_CATEGORY_DEVICES)); this.findPreference(PREFERENCE_CATEGORY_ADVANCED) .setOnPreferenceClickListener(new CategoryClickListener(PREFERENCE_CATEGORY_ADVANCED)); + this.findPreference(PREFERENCE_CATEGORY_PUBLIC_KEY) + .setOnPreferenceClickListener(new CategoryClickListener(PREFERENCE_CATEGORY_PUBLIC_KEY)); if (VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) { tintIcons(getActivity()); @@ -205,6 +211,7 @@ public class ApplicationPreferencesActivity extends PassphraseRequiredActionBarA Drawable chats = DrawableCompat.wrap(ContextCompat.getDrawable(context, R.drawable.ic_forum_white_24dp)); Drawable devices = DrawableCompat.wrap(ContextCompat.getDrawable(context, R.drawable.ic_laptop_white_24dp)); Drawable advanced = DrawableCompat.wrap(ContextCompat.getDrawable(context, R.drawable.ic_advanced_white_24dp)); + Drawable publicKey = DrawableCompat.wrap(ContextCompat.getDrawable(context, R.drawable.ic_share_white_24dp)); int[] tintAttr = new int[]{R.attr.pref_icon_tint}; TypedArray typedArray = context.obtainStyledAttributes(tintAttr); @@ -226,6 +233,7 @@ public class ApplicationPreferencesActivity extends PassphraseRequiredActionBarA this.findPreference(PREFERENCE_CATEGORY_CHATS).setIcon(chats); this.findPreference(PREFERENCE_CATEGORY_DEVICES).setIcon(devices); this.findPreference(PREFERENCE_CATEGORY_ADVANCED).setIcon(advanced); + this.findPreference(PREFERENCE_CATEGORY_PUBLIC_KEY).setIcon(publicKey); } private class CategoryClickListener implements Preference.OnPreferenceClickListener { @@ -262,6 +270,12 @@ public class ApplicationPreferencesActivity extends PassphraseRequiredActionBarA case PREFERENCE_CATEGORY_ADVANCED: fragment = new AdvancedPreferenceFragment(); break; + case PREFERENCE_CATEGORY_PUBLIC_KEY: + ClipboardManager clipboard = (ClipboardManager) getContext().getSystemService(Context.CLIPBOARD_SERVICE); + ClipData clip = ClipData.newPlainText("public key", "public key"); // TODO: Use actual public key + clipboard.setPrimaryClip(clip); + Toast.makeText(getContext(), R.string.activity_settings_public_key_copied_message, Toast.LENGTH_SHORT).show(); + break; default: throw new AssertionError(); }