1 | package org.rapidandroid.activity; |
---|
2 | |
---|
3 | import java.io.File; |
---|
4 | import java.io.FileInputStream; |
---|
5 | import java.io.FileNotFoundException; |
---|
6 | import java.io.FileOutputStream; |
---|
7 | import java.io.IOException; |
---|
8 | import java.io.InputStreamReader; |
---|
9 | |
---|
10 | import org.json.JSONException; |
---|
11 | import org.json.JSONObject; |
---|
12 | import org.rapidandroid.ApplicationGlobals; |
---|
13 | import org.rapidandroid.R; |
---|
14 | |
---|
15 | import android.app.Activity; |
---|
16 | import android.content.Context; |
---|
17 | import android.os.Bundle; |
---|
18 | import android.util.Log; |
---|
19 | import android.view.Menu; |
---|
20 | import android.view.MenuItem; |
---|
21 | import android.view.View; |
---|
22 | import android.view.View.OnClickListener; |
---|
23 | import android.widget.CheckBox; |
---|
24 | import android.widget.EditText; |
---|
25 | |
---|
26 | /** |
---|
27 | * @author Daniel Myung [email protected] |
---|
28 | * @created Feb 10, 2009 Summary: |
---|
29 | */ |
---|
30 | public class GlobalSettings extends Activity { |
---|
31 | |
---|
32 | |
---|
33 | /** |
---|
34 | * |
---|
35 | */ |
---|
36 | private static final String ACTIVITY_TITLE_STRING = "RapidAndroid :: Global Settings"; |
---|
37 | |
---|
38 | /** |
---|
39 | * |
---|
40 | */ |
---|
41 | public static final String LOG_DEBUG_KEY = "GlobalSettings"; |
---|
42 | |
---|
43 | private static final int MENU_DONE = Menu.FIRST; |
---|
44 | |
---|
45 | private CheckBox mParseCheckbox; |
---|
46 | private EditText mParseReplyText; |
---|
47 | private CheckBox mNoparseCheckBox; |
---|
48 | private EditText mNoparseReplyText; |
---|
49 | |
---|
50 | |
---|
51 | private OnClickListener mCheckChangeListener = new OnClickListener() { |
---|
52 | |
---|
53 | public void onClick(View v) { |
---|
54 | if (v.equals(mParseCheckbox)) { |
---|
55 | mNoparseCheckBox.setEnabled(mParseCheckbox.isChecked()); |
---|
56 | } else if (v.equals(mNoparseCheckBox)) { |
---|
57 | mNoparseCheckBox.setEnabled(mNoparseCheckBox.isChecked()); |
---|
58 | } |
---|
59 | } |
---|
60 | }; |
---|
61 | |
---|
62 | /* |
---|
63 | * (non-Javadoc) |
---|
64 | * |
---|
65 | * @see android.app.Activity#onCreate(android.os.Bundle) |
---|
66 | */ |
---|
67 | @Override |
---|
68 | protected void onCreate(Bundle savedInstanceState) { |
---|
69 | // TODO Auto-generated method stub |
---|
70 | super.onCreate(savedInstanceState); |
---|
71 | |
---|
72 | setTitle(ACTIVITY_TITLE_STRING); |
---|
73 | setContentView(R.layout.global_settings); |
---|
74 | |
---|
75 | mParseCheckbox = (CheckBox) findViewById(R.id.glb_chk_parse); |
---|
76 | mParseCheckbox.setOnClickListener(mCheckChangeListener); |
---|
77 | this.mParseReplyText = (EditText) findViewById(R.id.glb_etx_success); |
---|
78 | |
---|
79 | mNoparseCheckBox = (CheckBox) findViewById(R.id.glb_chk_noparse); |
---|
80 | mNoparseCheckBox.setOnClickListener(mCheckChangeListener); |
---|
81 | this.mNoparseReplyText = (EditText) findViewById(R.id.glb_etx_failed); |
---|
82 | |
---|
83 | loadSettingsFromGlobals(); |
---|
84 | } |
---|
85 | |
---|
86 | /** |
---|
87 | * |
---|
88 | */ |
---|
89 | private void loadSettingsFromGlobals() { |
---|
90 | // TODO Auto-generated method stub |
---|
91 | JSONObject globals = ApplicationGlobals.loadSettingsFromFile(this); |
---|
92 | try { |
---|
93 | mParseCheckbox.setChecked(globals.getBoolean(ApplicationGlobals.KEY_PARSE_REPLY)); |
---|
94 | mParseReplyText.setText(globals.getString(ApplicationGlobals.KEY_PARSE_REPLY_TEXT)); |
---|
95 | mNoparseCheckBox.setChecked(globals.getBoolean(ApplicationGlobals.KEY_FAILED_REPLY)); |
---|
96 | mNoparseReplyText.setText(globals.getString(ApplicationGlobals.KEY_FAILED_REPLY_TEXT)); |
---|
97 | } catch (JSONException e) { |
---|
98 | // TODO Auto-generated catch block |
---|
99 | e.printStackTrace(); |
---|
100 | } |
---|
101 | } |
---|
102 | |
---|
103 | /* |
---|
104 | * (non-Javadoc) |
---|
105 | * |
---|
106 | * @see android.app.Activity#onCreateOptionsMenu(android.view.Menu) |
---|
107 | */ |
---|
108 | @Override |
---|
109 | public boolean onCreateOptionsMenu(Menu menu) { |
---|
110 | super.onCreateOptionsMenu(menu); |
---|
111 | menu.add(0, MENU_DONE, 0, R.string.formreview_menu_done).setIcon(android.R.drawable.ic_menu_close_clear_cancel); |
---|
112 | return true; |
---|
113 | } |
---|
114 | |
---|
115 | /* |
---|
116 | * (non-Javadoc) |
---|
117 | * |
---|
118 | * @see android.app.Activity#onOptionsItemSelected(android.view.MenuItem) |
---|
119 | */ |
---|
120 | @Override |
---|
121 | public boolean onOptionsItemSelected(MenuItem item) { |
---|
122 | super.onOptionsItemSelected(item); |
---|
123 | switch (item.getItemId()) { |
---|
124 | case MENU_DONE: |
---|
125 | finish(); |
---|
126 | break; |
---|
127 | } |
---|
128 | return true; |
---|
129 | } |
---|
130 | |
---|
131 | /* |
---|
132 | * (non-Javadoc) |
---|
133 | * |
---|
134 | * @see android.app.Activity#onPause() |
---|
135 | */ |
---|
136 | @Override |
---|
137 | protected void onPause() { |
---|
138 | super.onPause(); |
---|
139 | ApplicationGlobals.saveGlobalSettings(this, mParseCheckbox.isChecked(), |
---|
140 | mParseReplyText.getText().toString(), |
---|
141 | mNoparseCheckBox.isChecked(), |
---|
142 | mNoparseReplyText.getText().toString()); |
---|
143 | |
---|
144 | } |
---|
145 | |
---|
146 | |
---|
147 | |
---|
148 | /* |
---|
149 | * (non-Javadoc) |
---|
150 | * |
---|
151 | * @see android.app.Activity#onResume() |
---|
152 | */ |
---|
153 | @Override |
---|
154 | protected void onResume() { |
---|
155 | super.onResume(); |
---|
156 | loadSettingsFromGlobals(); |
---|
157 | } |
---|
158 | |
---|
159 | } |
---|