summaryrefslogtreecommitdiffhomepage
path: root/app/src/main/java/com/wireguard
diff options
context:
space:
mode:
authorSamuel Holland <samuel@sholland.org>2017-08-16 04:29:55 -0500
committerSamuel Holland <samuel@sholland.org>2017-08-16 04:29:55 -0500
commit5c30cd0a82a64949c017e2d5ea807d68873bb766 (patch)
tree6103987bc3d9d6b34155990adfdf36f124672e2f /app/src/main/java/com/wireguard
parent60b109b8c94a46a281f3beadadc20414d0be2307 (diff)
ConfigListPreference: ListPreference for configs
Diffstat (limited to 'app/src/main/java/com/wireguard')
-rw-r--r--app/src/main/java/com/wireguard/android/ConfigListPreference.java35
1 files changed, 35 insertions, 0 deletions
diff --git a/app/src/main/java/com/wireguard/android/ConfigListPreference.java b/app/src/main/java/com/wireguard/android/ConfigListPreference.java
new file mode 100644
index 00000000..38421610
--- /dev/null
+++ b/app/src/main/java/com/wireguard/android/ConfigListPreference.java
@@ -0,0 +1,35 @@
+package com.wireguard.android;
+
+import android.content.Context;
+import android.preference.ListPreference;
+import android.util.AttributeSet;
+
+import java.util.Set;
+
+/**
+ * ListPreference that is automatically filled with the list of configurations.
+ */
+
+public class ConfigListPreference extends ListPreference {
+ public ConfigListPreference(final Context context, final AttributeSet attrs,
+ final int defStyleAttr, final int defStyleRes) {
+ super(context, attrs, defStyleAttr, defStyleRes);
+ final Set<String> entrySet = VpnService.getInstance().getConfigs().keySet();
+ final CharSequence[] entries = entrySet.toArray(new CharSequence[entrySet.size()]);
+ setEntries(entries);
+ setEntryValues(entries);
+ }
+
+ public ConfigListPreference(final Context context, final AttributeSet attrs,
+ final int defStyleAttr) {
+ this(context, attrs, defStyleAttr, 0);
+ }
+
+ public ConfigListPreference(final Context context, final AttributeSet attrs) {
+ this(context, attrs, android.R.attr.dialogPreferenceStyle);
+ }
+
+ public ConfigListPreference(final Context context) {
+ this(context, null);
+ }
+}