From 7fb4309fddef72d3f23fa04209f5e3bef3859436 Mon Sep 17 00:00:00 2001 From: Arne Schwabe Date: Fri, 28 Nov 2014 15:50:39 +0100 Subject: Implement duplication of profiles --HG-- extra : rebase_source : 6eefffdcc7f67227c0fe3f67a5325c9df6d3429e --- .../main/java/de/blinkt/openvpn/VpnProfile.java | 23 ++++++++++++++- .../blinkt/openvpn/activities/VPNPreferences.java | 15 ++++++++-- .../blinkt/openvpn/fragments/VPNProfileList.java | 31 ++++++++++++++++----- .../drawable-hdpi/ic_content_copy_white_24dp.png | Bin 0 -> 287 bytes .../res/drawable-hdpi/ic_menu_copy_holo_dark.png | Bin 0 -> 186 bytes .../res/drawable-hdpi/ic_menu_copy_holo_light.png | Bin 0 -> 199 bytes .../drawable-mdpi/ic_content_copy_white_24dp.png | Bin 0 -> 216 bytes .../res/drawable-mdpi/ic_menu_copy_holo_dark.png | Bin 0 -> 162 bytes .../res/drawable-mdpi/ic_menu_copy_holo_light.png | Bin 0 -> 161 bytes .../drawable-xhdpi/ic_content_copy_white_24dp.png | Bin 0 -> 330 bytes .../res/drawable-xhdpi/ic_menu_copy_holo_dark.png | Bin 0 -> 261 bytes .../res/drawable-xhdpi/ic_menu_copy_holo_light.png | Bin 0 -> 252 bytes .../drawable-xxhdpi/ic_content_copy_white_24dp.png | Bin 0 -> 436 bytes .../res/drawable-xxhdpi/ic_menu_copy_holo_dark.png | Bin 0 -> 1272 bytes .../drawable-xxhdpi/ic_menu_copy_holo_light.png | Bin 0 -> 1279 bytes .../ic_content_copy_white_24dp.png | Bin 0 -> 522 bytes main/src/main/res/menu/vpnpreferences_menu.xml | 9 +++++- main/src/main/res/values-v21/refs.xml | 1 + main/src/main/res/values/refs.xml | 2 ++ main/src/main/res/values/strings.xml | 2 ++ 20 files changed, 72 insertions(+), 11 deletions(-) create mode 100644 main/src/main/res/drawable-hdpi/ic_content_copy_white_24dp.png create mode 100644 main/src/main/res/drawable-hdpi/ic_menu_copy_holo_dark.png create mode 100644 main/src/main/res/drawable-hdpi/ic_menu_copy_holo_light.png create mode 100644 main/src/main/res/drawable-mdpi/ic_content_copy_white_24dp.png create mode 100644 main/src/main/res/drawable-mdpi/ic_menu_copy_holo_dark.png create mode 100644 main/src/main/res/drawable-mdpi/ic_menu_copy_holo_light.png create mode 100644 main/src/main/res/drawable-xhdpi/ic_content_copy_white_24dp.png create mode 100644 main/src/main/res/drawable-xhdpi/ic_menu_copy_holo_dark.png create mode 100644 main/src/main/res/drawable-xhdpi/ic_menu_copy_holo_light.png create mode 100644 main/src/main/res/drawable-xxhdpi/ic_content_copy_white_24dp.png create mode 100644 main/src/main/res/drawable-xxhdpi/ic_menu_copy_holo_dark.png create mode 100644 main/src/main/res/drawable-xxhdpi/ic_menu_copy_holo_light.png create mode 100644 main/src/main/res/drawable-xxxhdpi/ic_content_copy_white_24dp.png diff --git a/main/src/main/java/de/blinkt/openvpn/VpnProfile.java b/main/src/main/java/de/blinkt/openvpn/VpnProfile.java index c8cf7ac8..fbc1dfff 100644 --- a/main/src/main/java/de/blinkt/openvpn/VpnProfile.java +++ b/main/src/main/java/de/blinkt/openvpn/VpnProfile.java @@ -55,7 +55,7 @@ import de.blinkt.openvpn.core.VPNLaunchHelper; import de.blinkt.openvpn.core.VpnStatus; import de.blinkt.openvpn.core.X509Utils; -public class VpnProfile implements Serializable { +public class VpnProfile implements Serializable, Cloneable { // Note that this class cannot be moved to core where it belongs since // the profile loading depends on it being here // The Serializable documentation mentions that class name change are possible @@ -667,6 +667,27 @@ public class VpnProfile implements Serializable { } } + @Override + protected VpnProfile clone() throws CloneNotSupportedException { + VpnProfile copy = (VpnProfile) super.clone(); + copy.mUuid = UUID.randomUUID(); + copy.mConnections = mConnections.clone(); + copy.mAllowedAppsVpn = (HashSet) mAllowedAppsVpn.clone(); + return copy; + } + + public VpnProfile copy(String name) { + try { + VpnProfile copy = (VpnProfile) clone(); + copy.mName = name; + return copy; + + } catch (CloneNotSupportedException e) { + e.printStackTrace(); + return null; + } + } + class NoCertReturnedException extends Exception { public NoCertReturnedException (String msg) { diff --git a/main/src/main/java/de/blinkt/openvpn/activities/VPNPreferences.java b/main/src/main/java/de/blinkt/openvpn/activities/VPNPreferences.java index 2ef0dcce..c8f34519 100644 --- a/main/src/main/java/de/blinkt/openvpn/activities/VPNPreferences.java +++ b/main/src/main/java/de/blinkt/openvpn/activities/VPNPreferences.java @@ -9,6 +9,7 @@ import android.annotation.TargetApi; import android.app.ActionBar; import android.app.Activity; import android.app.AlertDialog; +import android.content.Context; import android.content.DialogInterface; import android.content.Intent; import android.os.Build; @@ -17,6 +18,8 @@ import android.preference.PreferenceActivity; import android.support.v4n.view.ViewPager; import android.view.Menu; import android.view.MenuItem; +import android.widget.EditText; +import android.widget.Toast; import de.blinkt.openvpn.R; import de.blinkt.openvpn.VpnProfile; @@ -181,11 +184,19 @@ public class VPNPreferences extends Activity { @Override public boolean onOptionsItemSelected(MenuItem item) { - if(item.getItemId() == R.id.remove_vpn) + if (item.getItemId() == R.id.remove_vpn) askProfileRemoval(); - return super.onOptionsItemSelected(item); + if (item.getItemId() == R.id.duplicate_vpn) { + Intent data = new Intent(); + data.putExtra(VpnProfile.EXTRA_PROFILEUUID, mProfileUUID); + setResult(VPNProfileList.RESULT_VPN_DUPLICATE, data); + finish(); + } + + return super.onOptionsItemSelected(item); } + @Override public boolean onCreateOptionsMenu(Menu menu) { diff --git a/main/src/main/java/de/blinkt/openvpn/fragments/VPNProfileList.java b/main/src/main/java/de/blinkt/openvpn/fragments/VPNProfileList.java index d13d1ca6..5bd552f8 100644 --- a/main/src/main/java/de/blinkt/openvpn/fragments/VPNProfileList.java +++ b/main/src/main/java/de/blinkt/openvpn/fragments/VPNProfileList.java @@ -37,6 +37,7 @@ import java.util.TreeSet; public class VPNProfileList extends ListFragment { public final static int RESULT_VPN_DELETED = Activity.RESULT_FIRST_USER; + public final static int RESULT_VPN_DUPLICATE = Activity.RESULT_FIRST_USER +1 ; private static final int MENU_ADD_PROFILE = Menu.FIRST; @@ -204,7 +205,7 @@ public class VPNProfileList extends ListFragment { public boolean onOptionsItemSelected(MenuItem item) { final int itemId = item.getItemId(); if (itemId == MENU_ADD_PROFILE) { - onAddProfileClicked(); + onAddOrDuplicateProfile(null); return true; } else if (itemId == MENU_IMPORT_PROFILE) { boolean startOldFileDialog=true; @@ -242,15 +243,19 @@ public class VPNProfileList extends ListFragment { - private void onAddProfileClicked() { + private void onAddOrDuplicateProfile(final VpnProfile mCopyProfile) { Context context = getActivity(); if (context != null) { final EditText entry = new EditText(context); entry.setSingleLine(); AlertDialog.Builder dialog = new AlertDialog.Builder(context); - dialog.setTitle(R.string.menu_add_profile); - dialog.setMessage(R.string.add_profile_name_prompt); + if (mCopyProfile == null) + dialog.setTitle(R.string.menu_add_profile); + else + dialog.setTitle(context.getString(R.string.duplicate_profile_title, mCopyProfile.mName)); + + dialog.setMessage(R.string.add_profile_name_prompt); dialog.setView(entry); @@ -260,7 +265,12 @@ public class VPNProfileList extends ListFragment { public void onClick(DialogInterface dialog, int which) { String name = entry.getText().toString(); if (getPM().getProfileByName(name)==null) { - VpnProfile profile = new VpnProfile(name); + VpnProfile profile; + if (mCopyProfile!=null) + profile= mCopyProfile.copy(name); + else + profile = new VpnProfile(name); + addProfile(profile); editVPN(profile); } else { @@ -295,11 +305,18 @@ public class VPNProfileList extends ListFragment { if(resultCode == RESULT_VPN_DELETED){ if(mArrayadapter != null && mEditProfile !=null) mArrayadapter.remove(mEditProfile); - } + } else if (resultCode == RESULT_VPN_DUPLICATE && data != null) { + String profileUUID = data.getStringExtra(VpnProfile.EXTRA_PROFILEUUID); + VpnProfile profile = ProfileManager.get(getActivity(), profileUUID); + if (profile != null) + onAddOrDuplicateProfile(profile); + } + - if(resultCode != Activity.RESULT_OK) + if(resultCode != Activity.RESULT_OK) return; + if (requestCode == START_VPN_CONFIG) { String configuredVPN = data.getStringExtra(VpnProfile.EXTRA_PROFILEUUID); diff --git a/main/src/main/res/drawable-hdpi/ic_content_copy_white_24dp.png b/main/src/main/res/drawable-hdpi/ic_content_copy_white_24dp.png new file mode 100644 index 00000000..03b1aac4 Binary files /dev/null and b/main/src/main/res/drawable-hdpi/ic_content_copy_white_24dp.png differ diff --git a/main/src/main/res/drawable-hdpi/ic_menu_copy_holo_dark.png b/main/src/main/res/drawable-hdpi/ic_menu_copy_holo_dark.png new file mode 100644 index 00000000..d37d0a31 Binary files /dev/null and b/main/src/main/res/drawable-hdpi/ic_menu_copy_holo_dark.png differ diff --git a/main/src/main/res/drawable-hdpi/ic_menu_copy_holo_light.png b/main/src/main/res/drawable-hdpi/ic_menu_copy_holo_light.png new file mode 100644 index 00000000..0dd8865f Binary files /dev/null and b/main/src/main/res/drawable-hdpi/ic_menu_copy_holo_light.png differ diff --git a/main/src/main/res/drawable-mdpi/ic_content_copy_white_24dp.png b/main/src/main/res/drawable-mdpi/ic_content_copy_white_24dp.png new file mode 100644 index 00000000..6aa238c5 Binary files /dev/null and b/main/src/main/res/drawable-mdpi/ic_content_copy_white_24dp.png differ diff --git a/main/src/main/res/drawable-mdpi/ic_menu_copy_holo_dark.png b/main/src/main/res/drawable-mdpi/ic_menu_copy_holo_dark.png new file mode 100644 index 00000000..97e8ac1b Binary files /dev/null and b/main/src/main/res/drawable-mdpi/ic_menu_copy_holo_dark.png differ diff --git a/main/src/main/res/drawable-mdpi/ic_menu_copy_holo_light.png b/main/src/main/res/drawable-mdpi/ic_menu_copy_holo_light.png new file mode 100644 index 00000000..74cb920f Binary files /dev/null and b/main/src/main/res/drawable-mdpi/ic_menu_copy_holo_light.png differ diff --git a/main/src/main/res/drawable-xhdpi/ic_content_copy_white_24dp.png b/main/src/main/res/drawable-xhdpi/ic_content_copy_white_24dp.png new file mode 100644 index 00000000..04a0cc94 Binary files /dev/null and b/main/src/main/res/drawable-xhdpi/ic_content_copy_white_24dp.png differ diff --git a/main/src/main/res/drawable-xhdpi/ic_menu_copy_holo_dark.png b/main/src/main/res/drawable-xhdpi/ic_menu_copy_holo_dark.png new file mode 100644 index 00000000..ba883aec Binary files /dev/null and b/main/src/main/res/drawable-xhdpi/ic_menu_copy_holo_dark.png differ diff --git a/main/src/main/res/drawable-xhdpi/ic_menu_copy_holo_light.png b/main/src/main/res/drawable-xhdpi/ic_menu_copy_holo_light.png new file mode 100644 index 00000000..364b1692 Binary files /dev/null and b/main/src/main/res/drawable-xhdpi/ic_menu_copy_holo_light.png differ diff --git a/main/src/main/res/drawable-xxhdpi/ic_content_copy_white_24dp.png b/main/src/main/res/drawable-xxhdpi/ic_content_copy_white_24dp.png new file mode 100644 index 00000000..5fc17a4d Binary files /dev/null and b/main/src/main/res/drawable-xxhdpi/ic_content_copy_white_24dp.png differ diff --git a/main/src/main/res/drawable-xxhdpi/ic_menu_copy_holo_dark.png b/main/src/main/res/drawable-xxhdpi/ic_menu_copy_holo_dark.png new file mode 100644 index 00000000..9dd56eff Binary files /dev/null and b/main/src/main/res/drawable-xxhdpi/ic_menu_copy_holo_dark.png differ diff --git a/main/src/main/res/drawable-xxhdpi/ic_menu_copy_holo_light.png b/main/src/main/res/drawable-xxhdpi/ic_menu_copy_holo_light.png new file mode 100644 index 00000000..91043c9d Binary files /dev/null and b/main/src/main/res/drawable-xxhdpi/ic_menu_copy_holo_light.png differ diff --git a/main/src/main/res/drawable-xxxhdpi/ic_content_copy_white_24dp.png b/main/src/main/res/drawable-xxxhdpi/ic_content_copy_white_24dp.png new file mode 100644 index 00000000..557c64f7 Binary files /dev/null and b/main/src/main/res/drawable-xxxhdpi/ic_content_copy_white_24dp.png differ diff --git a/main/src/main/res/menu/vpnpreferences_menu.xml b/main/src/main/res/menu/vpnpreferences_menu.xml index 3be376ce..d8fe2a49 100644 --- a/main/src/main/res/menu/vpnpreferences_menu.xml +++ b/main/src/main/res/menu/vpnpreferences_menu.xml @@ -11,5 +11,12 @@ android:icon="@drawable/ic_menu_delete" android:showAsAction="withText|ifRoom" android:title="@string/remove_vpn"/> - + + + \ No newline at end of file diff --git a/main/src/main/res/values-v21/refs.xml b/main/src/main/res/values-v21/refs.xml index 70918ab9..44be98e9 100644 --- a/main/src/main/res/values-v21/refs.xml +++ b/main/src/main/res/values-v21/refs.xml @@ -10,6 +10,7 @@ @drawable/ic_check_white_24dp @drawable/ic_filter_list_white_24dp @drawable/ic_delete_white_24dp + @drawable/ic_content_copy_white_24dp @drawable/ic_delete_grey600_24dp @drawable/ic_edit_white_24dp diff --git a/main/src/main/res/values/refs.xml b/main/src/main/res/values/refs.xml index 937b5110..0d2bfce1 100644 --- a/main/src/main/res/values/refs.xml +++ b/main/src/main/res/values/refs.xml @@ -18,5 +18,7 @@ @android:drawable/ic_menu_add @drawable/ic_menu_archive @android:drawable/ic_menu_delete + @drawable/ic_menu_copy_holo_light + \ No newline at end of file diff --git a/main/src/main/res/values/strings.xml b/main/src/main/res/values/strings.xml index b692541d..09fab42f 100755 --- a/main/src/main/res/values/strings.xml +++ b/main/src/main/res/values/strings.xml @@ -346,5 +346,7 @@ Payload options TLS Settings No remote defined + Duplicate VPN profile + Duplicating profile: %s -- cgit v1.2.3