From e95b41e48b7f335c08833a2e9bab0902d1ce98f8 Mon Sep 17 00:00:00 2001 From: Samuel Holland Date: Wed, 16 Aug 2017 04:29:55 -0500 Subject: ConfigListPreference: ListPreference for configs Signed-off-by: Jason A. Donenfeld --- .../wireguard/android/ConfigListPreference.java | 35 ++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 app/src/main/java/com/wireguard/android/ConfigListPreference.java (limited to 'app/src/main/java') 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 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); + } +} -- cgit v1.2.3