-
Notifications
You must be signed in to change notification settings - Fork 0
/
MainSetting.java
105 lines (94 loc) · 4.67 KB
/
MainSetting.java
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
package edu.nctu.wirelab.testsignalv1;
import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.util.Log;
import android.util.SparseBooleanArray;
import android.view.View;
import android.widget.AbsListView;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ListView;
import android.widget.TextView;
public class MainSetting extends ActionBarActivity {
ListView list;
private final String TagName = "MainSetting";
private SparseBooleanArray tempchoice;
public static boolean AtInfoSwitch = true, NbtInfoSwitch = true, PhoneStateSwitch = true, TrafficSwitch = true;
private static boolean TempAtInfoSwitch = true, TempNbtInfoSwitch = true, TempPhoneStateSwitch = true, TempTrafficSwitch = true;
private EditText LogPrefixEditText, IntervalEditText;
private Button ConfirmButton;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main_setting);
LogPrefixEditText = (EditText) findViewById(R.id.LogPrefixEditText);
IntervalEditText = (EditText) findViewById(R.id.IntervalEditText);
ConfirmButton = (Button) findViewById(R.id.ConfirmButton);
list = (ListView) findViewById(R.id.list);
TempAtInfoSwitch = AtInfoSwitch;
TempNbtInfoSwitch = NbtInfoSwitch;
TempPhoneStateSwitch = PhoneStateSwitch;
TempTrafficSwitch = TrafficSwitch;
IntervalEditText.setText(String.valueOf(MainActivity.FlashInterval), TextView.BufferType.EDITABLE);
LogPrefixEditText.setText(MainActivity.RecordPrefix, TextView.BufferType.EDITABLE);
String[] liststr = new String[] { "Sense Attached Info", "Sense All Info", "Sense Phone State", "Sense PS Traffic" };
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_multiple_choice, android.R.id.text1, liststr);
list.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE);
list.setAdapter(adapter);
list.setItemChecked(0, AtInfoSwitch);
list.setItemChecked(1, NbtInfoSwitch);
list.setItemChecked(2, PhoneStateSwitch);
list.setItemChecked(3, TrafficSwitch);
list.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> adapterView, View view, int pos, long l) {
AbsListView list = (AbsListView) adapterView;
//Log.d(TagName, "onItemClick");
tempchoice = list.getCheckedItemPositions();
for (int i = 0; i < tempchoice.size(); i++) {
//Log.d(TagName, "i:"+i+" get(i):"+tempchoice.get(i)+" keyat(i):"+tempchoice.keyAt(i));
int key = tempchoice.keyAt(i);
switch (key) {
case 0:
if (tempchoice.get(i)) TempAtInfoSwitch = true;
else TempAtInfoSwitch = false;
break;
case 1:
if (tempchoice.get(i)) TempNbtInfoSwitch = true;
else TempNbtInfoSwitch = false;
break;
case 2:
if (tempchoice.get(i)) TempPhoneStateSwitch = true;
else TempPhoneStateSwitch = false;
break;
case 3:
if (tempchoice.get(i)) TempTrafficSwitch = true;
else TempTrafficSwitch = false;
break;
}
}
}
});
ConfirmButton.setOnClickListener(new Button.OnClickListener() {
public void onClick(View v) {
String inputInterval = IntervalEditText.getText().toString();
if( !inputInterval.isEmpty() ) {
// Log.d(TagName, "inputInterval:"+inputInterval);
MainActivity.FlashInterval = Integer.valueOf(inputInterval);
}
String LogPrefix = LogPrefixEditText.getText().toString();
if( !LogPrefix.isEmpty() ) {
// Log.d(TagName, "LogPrefix:"+LogPrefix);
MainActivity.RecordPrefix = LogPrefix;
}
AtInfoSwitch = TempAtInfoSwitch;
NbtInfoSwitch = TempNbtInfoSwitch;
PhoneStateSwitch = TempPhoneStateSwitch;
TrafficSwitch = TempTrafficSwitch;
onBackPressed();
}
});
}
}