-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathConfig.java
More file actions
140 lines (101 loc) · 3.69 KB
/
Config.java
File metadata and controls
140 lines (101 loc) · 3.69 KB
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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
package app.ue;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileWriter;
import java.io.IOException;
import java.io.OutputStream;
import java.util.Properties;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.os.Environment;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;
public class Config extends Activity {
TextView txt_server;
TextView txt_port;
TextView txt_freq;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.config);
try {
FileInputStream in = openFileInput(".uesec");
Properties conf = new Properties();
conf.load(in);
in.close();
txt_server = (TextView)findViewById(R.id.server);
txt_port = (TextView)findViewById(R.id.port);
txt_freq = (TextView)findViewById(R.id.freq);
txt_server.setText(conf.getProperty("server"));
txt_port.setText(conf.getProperty("port"));
txt_freq.setText(conf.getProperty("interval"));
}
catch (Exception e)
{
//Config not found?
e.printStackTrace();
}
final Button save_button = (Button) findViewById(R.id.save);
save_button.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
// Connect to server
saveConfig(false);
}
});
final Button restart_button = (Button) findViewById(R.id.restart);
restart_button.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
// Connect to server
saveConfig(true);
}
});
}
public void saveConfig(boolean restart)
{
try {
File f = new File(".uesec");
if ( !f.exists() )
{
OutputStream o = openFileOutput(".uesec", Context.MODE_PRIVATE);
o.write(' ');
o.close();
FileInputStream in = openFileInput(".uesec");
Properties conf = new Properties();
conf.load(in);
in.close();
conf.setProperty("interval", "60000");
conf.setProperty("server", "76.249.179.148");
conf.setProperty("port", "19876");
OutputStream out = openFileOutput(".uesec", Context.MODE_PRIVATE);
conf.store(out, "");
out.close();
}
FileInputStream in = openFileInput(".uesec");
Properties conf = new Properties();
conf.load(in);
in.close();
conf.setProperty("interval", ""+txt_freq.getText());
conf.setProperty("server", ""+txt_server.getText());
conf.setProperty("port", ""+txt_port.getText());
OutputStream out = openFileOutput(".uesec", Context.MODE_PRIVATE);
conf.store(out, "");
out.close();
if ( restart )
{
final Intent service = new Intent(this, Updater.class);
stopService(service);
startService(service);
}
Toast.makeText(this, "Config Saved", Toast.LENGTH_LONG).show();
}
catch (Exception e)
{
e.printStackTrace();
}
}
}