summaryrefslogtreecommitdiff
path: root/src/de/blinkt/openvpn/VPNPreferences.java
diff options
context:
space:
mode:
authorArne Schwabe <arne@rfc2549.org>2012-04-27 23:24:49 +0200
committerArne Schwabe <arne@rfc2549.org>2012-04-27 23:24:49 +0200
commit031186e74c9f174d05a09c4059def7bcbc558ac6 (patch)
tree8506351e5a3e9904c70c881b1d13b2a1d1030383 /src/de/blinkt/openvpn/VPNPreferences.java
parent817812066576fb1e2fd627927ad5cfc7bf7c79d5 (diff)
it is not getIntent() nor savedState nor other fancy stuff, getArgument() is what I want
Diffstat (limited to 'src/de/blinkt/openvpn/VPNPreferences.java')
-rw-r--r--src/de/blinkt/openvpn/VPNPreferences.java193
1 files changed, 73 insertions, 120 deletions
diff --git a/src/de/blinkt/openvpn/VPNPreferences.java b/src/de/blinkt/openvpn/VPNPreferences.java
index 27731453..75788d74 100644
--- a/src/de/blinkt/openvpn/VPNPreferences.java
+++ b/src/de/blinkt/openvpn/VPNPreferences.java
@@ -1,151 +1,104 @@
package de.blinkt.openvpn;
+import java.io.FileNotFoundException;
+import java.io.IOException;
+import java.io.ObjectOutputStream;
import java.util.List;
+import android.app.Activity;
+import android.content.Intent;
import android.os.Bundle;
-import android.preference.CheckBoxPreference;
-import android.preference.EditTextPreference;
-import android.preference.Preference;
-import android.preference.Preference.OnPreferenceChangeListener;
import android.preference.PreferenceActivity;
-import android.preference.PreferenceFragment;
-import android.preference.PreferenceManager;
-import android.preference.SwitchPreference;
import android.widget.Button;
public class VPNPreferences extends PreferenceActivity {
private VpnProfile mProfile;
+ private BasicSettings mBS;
+ public void setmBS(BasicSettings mBS) {
+ this.mBS = mBS;
+ }
+
public VPNPreferences() {
super();
+
+ }
+
+
+ protected void onPause() {
+ super.onPause();
+ saveSettings();
+
+ }
+
+
+ @Override
+ protected void onStop() {
+ super.onStop();
+ };
+
+
+ private void saveSettings() {
+ // First let basic settings save its state
+ if(mBS!=null)
+ mBS.savePreferences();
+
+ ObjectOutputStream vpnfile;
+ try {
+ vpnfile = new ObjectOutputStream(openFileOutput((mProfile.getUUID().toString() + ".vp"),Activity.MODE_PRIVATE));
+
+ vpnfile.writeObject(mProfile);
+ vpnfile.flush();
+ vpnfile.close();
+ } catch (FileNotFoundException e) {
+
+ e.printStackTrace();
+ } catch (IOException e) {
+
+ e.printStackTrace();
+ }
+ }
+
+ @Override
+ protected void onSaveInstanceState(Bundle outState) {
+ super.onSaveInstanceState(outState);
+ outState.putSerializable(getPackageName() + ".VpnProfile",mProfile);
}
+
+ @Override
+ protected void onRestoreInstanceState(Bundle state) {
+ super.onRestoreInstanceState(state);
+ mProfile = (VpnProfile) state.getSerializable(getPackageName() + ".VpnProfile");
+ }
+
+
@Override
protected void onCreate(Bundle savedInstanceState) {
+ mProfile = (VpnProfile) getIntent().getSerializableExtra(getPackageName() + ".VpnProfile");
super.onCreate(savedInstanceState);
- mProfile = getIntent().getParcelableExtra("VpnProfile");
+
if (hasHeaders()) {
Button button = new Button(this);
- button.setText("Some action");
+ button.setText("Save");
setListFooter(button);
}
}
+
+
@Override
public void onBuildHeaders(List<Header> target) {
- loadHeadersFromResource(R.xml.vpn_headers, target);
- }
-
- public static class IP_Settings extends PreferenceFragment implements OnPreferenceChangeListener {
- private EditTextPreference mIPv4;
- private EditTextPreference mIPv6;
- private SwitchPreference mUsePull;
- private CheckBoxPreference mOverrideDNS;
- private Preference mSearchdomain;
- private Preference mDNS1;
- private Preference mDNS2;
-
- @Override
- public void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
-
-
- // Make sure default values are applied. In a real app, you would
- // want this in a shared function that is used to retrieve the
- // SharedPreferences wherever they are needed.
- PreferenceManager.setDefaultValues(getActivity(),
- R.xml.vpn_ipsettings, false);
-
- // Load the preferences from an XML resource
- addPreferencesFromResource(R.xml.vpn_ipsettings);
- mIPv4 = (EditTextPreference) findPreference("ipv4_address");
- mIPv6 = (EditTextPreference) findPreference("ipv6_address");
- mUsePull = (SwitchPreference) findPreference("usePull");
- mOverrideDNS = (CheckBoxPreference) findPreference("overrideDNS");
- mSearchdomain =findPreference("searchdomain");
- mDNS1 = findPreference("dns1");
- mDNS2 = findPreference("dns2");
-
- mIPv4.setOnPreferenceChangeListener(this);
- mIPv6.setOnPreferenceChangeListener(this);
- mDNS1.setOnPreferenceChangeListener(this);
- mDNS2.setOnPreferenceChangeListener(this);
- mUsePull.setOnPreferenceChangeListener(this);
- mOverrideDNS.setOnPreferenceChangeListener(this);
-
-
- VpnProfile vp = ((VPNPreferences) getActivity()).getVPNProfile();
-
-
- setDNSState();
-
-
+ loadHeadersFromResource(R.xml.vpn_headers, target);
+ for (Header header : target) {
+ if(header.fragmentArguments==null)
+ header.fragmentArguments = new Bundle();
+ header.fragmentArguments.putString(getPackageName() + ".profileUUID",mProfile.getUUID().toString());
+ if(header.extras==null)
+ header.extras = new Bundle();
+ header.extras.putString(getPackageName() + ".profileUUID",mProfile.getUUID().toString());
}
-
- @Override
- public boolean onPreferenceChange(Preference preference,
- Object newValue) {
- if(preference==mIPv4 || preference == mIPv6 ||
- preference==mDNS1 || preference == mDNS2)
- preference.setSummary((String)newValue);
-
- if(preference== mUsePull || preference == mOverrideDNS)
- setDNSState();
-
- return true;
- }
-
- private void setDNSState() {
- boolean enabled;
- mOverrideDNS.setEnabled(mUsePull.isChecked());
- if(!mUsePull.isChecked())
- enabled =true;
- else if (mOverrideDNS.isChecked())
- enabled = true;
- else
- enabled = false;
-
- mDNS1.setEnabled(enabled);
- mDNS2.setEnabled(enabled);
- mSearchdomain.setEnabled(enabled);
-
- }
-
-
- }
- public static class Authentication extends PreferenceFragment {
- @Override
- public void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
-
- // Make sure default values are applied. In a real app, you would
- // want this in a shared function that is used to retrieve the
- // SharedPreferences wherever they are needed.
- PreferenceManager.setDefaultValues(getActivity(),
- R.xml.vpn_authentification, false);
-
- // Load the preferences from an XML resource
- addPreferencesFromResource(R.xml.vpn_authentification);
- }
- }
- public static class Obscure extends PreferenceFragment {
- @Override
- public void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
-
- // Make sure default values are applied. In a real app, you would
- // want this in a shared function that is used to retrieve the
- // SharedPreferences wherever they are needed.
- PreferenceManager.setDefaultValues(getActivity(),
- R.xml.vpn_ipsettings, false);
-
- // Load the preferences from an XML resource
- addPreferencesFromResource(R.xml.vpn_obscure);
- }
- }
- public VpnProfile getVPNProfile() {
- return mProfile;
}
}