diff options
| -rw-r--r-- | res/menu/vpnpreferences_menu.xml | 10 | ||||
| -rw-r--r-- | src/de/blinkt/openvpn/VPNPreferences.java | 49 | ||||
| -rw-r--r-- | src/de/blinkt/openvpn/VPNProfileList.java | 92 | 
3 files changed, 75 insertions, 76 deletions
diff --git a/res/menu/vpnpreferences_menu.xml b/res/menu/vpnpreferences_menu.xml new file mode 100644 index 00000000..71744d3c --- /dev/null +++ b/res/menu/vpnpreferences_menu.xml @@ -0,0 +1,10 @@ +<?xml version="1.0" encoding="utf-8"?> +<menu xmlns:android="http://schemas.android.com/apk/res/android" > +    <item +        android:id="@+id/remove_vpn" +        android:alphabeticShortcut="d" +        android:icon="@android:drawable/ic_menu_delete" +        android:showAsAction="withText|ifRoom" +        android:title="@string/remove_vpn"/> +     +</menu>
\ No newline at end of file diff --git a/src/de/blinkt/openvpn/VPNPreferences.java b/src/de/blinkt/openvpn/VPNPreferences.java index a2c8407c..95f39548 100644 --- a/src/de/blinkt/openvpn/VPNPreferences.java +++ b/src/de/blinkt/openvpn/VPNPreferences.java @@ -2,13 +2,18 @@ package de.blinkt.openvpn;  import java.util.List; +import android.app.AlertDialog; +import android.content.DialogInterface;  import android.os.Bundle;  import android.preference.PreferenceActivity; +import android.view.Menu; +import android.view.MenuItem;  public class VPNPreferences extends PreferenceActivity {  	private String mProfileUUID; +	private VpnProfile mProfile;  	public VPNPreferences() {  		super(); @@ -28,9 +33,9 @@ public class VPNPreferences extends PreferenceActivity {  	@Override  	protected void onCreate(Bundle savedInstanceState) {  		mProfileUUID = getIntent().getStringExtra(getPackageName() + ".profileUUID"); -		VpnProfile profile = ProfileManager.get(this,mProfileUUID); -		if(profile!=null) { -			setTitle(getString(R.string.edit_profile_title, profile.getName())); +		mProfile = ProfileManager.get(this,mProfileUUID); +		if(mProfile!=null) { +			setTitle(getString(R.string.edit_profile_title, mProfile.getName()));  		}  		super.onCreate(savedInstanceState);  	} @@ -51,5 +56,43 @@ public class VPNPreferences extends PreferenceActivity {  		setResult(RESULT_OK, getIntent());  		super.onBackPressed();  	} + +	@Override +	public boolean onOptionsItemSelected(MenuItem item) { +		if(item.getItemId() == R.id.remove_vpn) +			askProfileRemoval(); +		return super.onOptionsItemSelected(item); +	} +	 +	@Override +	public boolean onCreateOptionsMenu(Menu menu) { + +		getMenuInflater().inflate(R.menu.vpnpreferences_menu, menu); + +		return super.onCreateOptionsMenu(menu); +	} +	 +	private void askProfileRemoval() { +		AlertDialog.Builder dialog = new AlertDialog.Builder(this); +		dialog.setTitle("Confirm deletion"); +		dialog.setMessage(getString(R.string.remove_vpn_query, mProfile.mName)); + +		dialog.setPositiveButton(android.R.string.yes, +				new DialogInterface.OnClickListener() { +			@Override +			public void onClick(DialogInterface dialog, int which) { +				removeProfile(mProfile); +			} + +		}); +		dialog.setNegativeButton(android.R.string.no,null); +		dialog.create().show(); +	} + +	protected void removeProfile(VpnProfile profile) { +		ProfileManager.getInstance(this).removeProfile(this,profile); +		setResult(VPNProfileList.RESULT_VPN_DELETED); +		finish(); +	}  } diff --git a/src/de/blinkt/openvpn/VPNProfileList.java b/src/de/blinkt/openvpn/VPNProfileList.java index aee3ce4b..974090d4 100644 --- a/src/de/blinkt/openvpn/VPNProfileList.java +++ b/src/de/blinkt/openvpn/VPNProfileList.java @@ -8,7 +8,6 @@ import android.content.DialogInterface;  import android.content.Intent;  import android.net.Uri;  import android.os.Bundle; -import android.view.ActionMode;  import android.view.Menu;  import android.view.MenuInflater;  import android.view.MenuItem; @@ -17,10 +16,12 @@ import android.view.View.OnClickListener;  import android.view.ViewGroup;  import android.widget.ArrayAdapter;  import android.widget.EditText; -import android.widget.ListView;  import android.widget.Toast;  public class VPNProfileList extends ListFragment { +	 +	final static int RESULT_VPN_DELETED = Activity.RESULT_FIRST_USER; +	  	class VPNArrayAdapter extends ArrayAdapter<VpnProfile> {  		public VPNArrayAdapter(Context context, int resource, @@ -46,13 +47,8 @@ public class VPNProfileList extends ListFragment {  				@Override  				public void onClick(View v) { -				    if (mActionMode != null) { -			            return; -			        } - -			        // Start the CAB using the ActionMode.Callback defined above -			        mActionMode = getActivity().startActionMode(mActionModeCallback);  					mEditProfile =(VpnProfile) getListAdapter().getItem(position); +					editVPN(mEditProfile);  				}  			}); @@ -76,8 +72,6 @@ public class VPNProfileList extends ListFragment {  	private ArrayAdapter<VpnProfile> mArrayadapter; -	protected Object mActionMode; -  	protected VpnProfile mEditProfile=null; @@ -130,37 +124,23 @@ public class VPNProfileList extends ListFragment {  			onAddProfileClicked();  			return true;  		} else if (itemId == MENU_IMPORT_PROFILE) { -			Intent intent = new Intent(getActivity(),FileSelect.class); -			intent.putExtra(FileSelect.NO_INLINE_SELECTION, true); -			intent.putExtra(FileSelect.WINDOW_TITLE, R.string.import_configuration_file); -			startActivityForResult(intent, SELECT_PROFILE); +			startImportConfig();  			return true;  		} else {  			return super.onOptionsItemSelected(item);  		}  	} -	private void askProfileRemoval() { -		AlertDialog.Builder dialog = new AlertDialog.Builder(getActivity()); -		dialog.setTitle("Confirm deletion"); -		dialog.setMessage(getString(R.string.remove_vpn_query, mEditProfile.mName)); - -		dialog.setPositiveButton(android.R.string.yes, -				new DialogInterface.OnClickListener() { -			@Override -			public void onClick(DialogInterface dialog, int which) { -				removeProfile(mEditProfile); -			} - -		}); -		dialog.setNegativeButton(android.R.string.no,null); -		dialog.create().show(); +	private void startImportConfig() { +		Intent intent = new Intent(getActivity(),FileSelect.class); +		intent.putExtra(FileSelect.NO_INLINE_SELECTION, true); +		intent.putExtra(FileSelect.WINDOW_TITLE, R.string.import_configuration_file); +		startActivityForResult(intent, SELECT_PROFILE);  	} -	protected void removeProfile(VpnProfile profile) { -		mArrayadapter.remove(profile); -		getPM().removeProfile(getActivity(),profile); -	} + + +  	private void onAddProfileClicked() {  		Context context = getActivity(); @@ -215,6 +195,12 @@ public class VPNProfileList extends ListFragment {  	@Override  	public void onActivityResult(int requestCode, int resultCode, Intent data) {  		super.onActivityResult(requestCode, resultCode, data); +		 +		if(resultCode == RESULT_VPN_DELETED){ +			if(mArrayadapter != null && mEditProfile !=null) +				mArrayadapter.remove(mEditProfile); +		} +		  		if(resultCode != Activity.RESULT_OK)  			return; @@ -261,44 +247,4 @@ public class VPNProfileList extends ListFragment {  		getActivity().finish();  	} -	private ActionMode.Callback mActionModeCallback = new ActionMode.Callback() { -		@Override -		public boolean onCreateActionMode(ActionMode mode, Menu menu) { -			MenuInflater inflater = mode.getMenuInflater(); -			inflater.inflate(R.menu.vpn_context, menu); -			return true; -		} - -		@Override -		public boolean onPrepareActionMode(ActionMode mode, Menu menu) { -			return false;// Return false if nothing is done -		} - -		@Override -		public boolean onActionItemClicked(ActionMode mode, MenuItem item) { -		      switch (item.getItemId()) { -	            case R.id.remove_vpn: -	                askProfileRemoval(); -	                mode.finish(); // Action picked, so close the CAB -	                return true; -/*	            case R.id.connect_vpn: -	            	startVPN(mEditProfile); -	            	mode.finish(); -	            	return true; */  -	            case R.id.edit_vpn: -	            	editVPN(mEditProfile); -	            	mode.finish(); -	            	return true; -	            default: -	                return false; -	        }		 -		} - -		@Override -		public void onDestroyActionMode(ActionMode mode) { -	        mActionMode = null; -	        getListView().setChoiceMode(ListView.CHOICE_MODE_NONE); -		} -	}; -  }  | 
