summaryrefslogtreecommitdiff
path: root/src/de/blinkt/openvpn/VPNPreferences.java
blob: 75788d7403c54d0cabc90c51cbfeea28e192b264 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
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.PreferenceActivity;
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);

	
				
		if (hasHeaders()) {
			Button button = new Button(this);
			button.setText("Save");
			setListFooter(button);
		}
	}
	
	
	@Override
	public void onBuildHeaders(List<Header> target) {
		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());
		}
	}
}