OSDN Git Service

[Fingerprint] Remove learn more link if not provisioned. DO NOT MERGE
[android-x86/packages-apps-Settings.git] / src / com / android / settings / BandMode.java
1 package com.android.settings;
2
3 import android.app.Activity;
4 import android.app.AlertDialog;
5 import com.android.internal.telephony.Phone;
6 import com.android.internal.telephony.PhoneFactory;
7 import android.os.Bundle;
8 import android.os.Message;
9 import android.os.Handler;
10 import android.os.AsyncResult;
11 import android.util.Log;
12 import android.content.DialogInterface;
13 import android.view.View;
14 import android.view.WindowManager;
15 import android.view.Window;
16 import android.widget.ListView;
17 import android.widget.ArrayAdapter;
18 import android.widget.AdapterView;
19
20
21 /**
22  * Radio Band Mode Selection Class
23  *
24  * It will query baseband about all available band modes and display them
25  * in screen. It will display all six band modes if the query failed.
26  *
27  * After user select one band, it will send the selection to baseband.
28  *
29  * It will alter user the result of select operation and exit, no matter success
30  * or not.
31  *
32  */
33 public class BandMode extends Activity {
34     private static final String LOG_TAG = "phone";
35     private static final boolean DBG = false;
36
37     private static final int EVENT_BAND_SCAN_COMPLETED = 100;
38     private static final int EVENT_BAND_SELECTION_DONE = 200;
39
40     private static final String[] BAND_NAMES = new String[] {
41             "Automatic",
42             "EURO Band",
43             "USA Band",
44             "JAPAN Band",
45             "AUS Band",
46             "AUS2 Band"
47     };
48
49     private ListView mBandList;
50     private ArrayAdapter mBandListAdapter;
51     private BandListItem mTargetBand = null;
52     private DialogInterface mProgressPanel;
53
54     private Phone mPhone = null;
55
56     @Override
57     protected void onCreate(Bundle icicle) {
58         super.onCreate(icicle);
59
60         requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);
61
62         setContentView(R.layout.band_mode);
63
64         setTitle(getString(R.string.band_mode_title));
65         getWindow().setLayout(WindowManager.LayoutParams.MATCH_PARENT,
66                                     WindowManager.LayoutParams.WRAP_CONTENT);
67
68         mPhone = PhoneFactory.getDefaultPhone();
69
70         mBandList = (ListView) findViewById(R.id.band);
71         mBandListAdapter = new ArrayAdapter<BandListItem>(this,
72                 android.R.layout.simple_list_item_1);
73         mBandList.setAdapter(mBandListAdapter);
74         mBandList.setOnItemClickListener(mBandSelectionHandler);
75
76         loadBandList();
77     }
78
79     private AdapterView.OnItemClickListener mBandSelectionHandler =
80             new AdapterView.OnItemClickListener () {
81                 public void onItemClick(AdapterView parent, View v,
82                         int position, long id) {
83
84                     getWindow().setFeatureInt(
85                             Window.FEATURE_INDETERMINATE_PROGRESS,
86                             Window.PROGRESS_VISIBILITY_ON);
87
88                     mTargetBand = (BandListItem) parent.getAdapter().getItem(position);
89
90                     if (DBG) log("Select band : " + mTargetBand.toString());
91
92                     Message msg =
93                             mHandler.obtainMessage(EVENT_BAND_SELECTION_DONE);
94                     mPhone.setBandMode(mTargetBand.getBand(), msg);
95                 }
96             };
97
98     static private class BandListItem {
99         private int mBandMode = Phone.BM_UNSPECIFIED;
100
101         public BandListItem(int bm) {
102             mBandMode = bm;
103         }
104
105         public int getBand() {
106             return mBandMode;
107         }
108
109         public String toString() {
110             if (mBandMode >= BAND_NAMES.length) return "Band mode " + mBandMode;
111             return BAND_NAMES[mBandMode];
112         }
113     }
114
115     private void loadBandList() {
116         String str = getString(R.string.band_mode_loading);
117
118         if (DBG) log(str);
119
120
121         //ProgressDialog.show(this, null, str, true, true, null);
122         mProgressPanel = new AlertDialog.Builder(this)
123             .setMessage(str)
124             .show();
125
126         Message msg = mHandler.obtainMessage(EVENT_BAND_SCAN_COMPLETED);
127         mPhone.queryAvailableBandMode(msg);
128
129     }
130
131     private void bandListLoaded(AsyncResult result) {
132         if (DBG) log("network list loaded");
133
134         if (mProgressPanel != null) mProgressPanel.dismiss();
135
136         clearList();
137
138         boolean addBandSuccess = false;
139         BandListItem item;
140
141         if (result.result != null) {
142             int bands[] = (int[])result.result;
143             int size = bands[0];
144
145             if (size > 0) {
146                 for (int i=1; i<size; i++) {
147                     item = new BandListItem(bands[i]);
148                     mBandListAdapter.add(item);
149                     if (DBG) log("Add " + item.toString());
150                 }
151                 addBandSuccess = true;
152             }
153         }
154
155         if (addBandSuccess == false) {
156             if (DBG) log("Error in query, add default list");
157             for (int i=0; i<Phone.BM_BOUNDARY; i++) {
158                 item = new BandListItem(i);
159                 mBandListAdapter.add(item);
160                 if (DBG) log("Add default " + item.toString());
161             }
162         }
163         mBandList.requestFocus();
164     }
165
166     private void displayBandSelectionResult(Throwable ex) {
167         String status = getString(R.string.band_mode_set)
168                 +" [" + mTargetBand.toString() + "] ";
169
170         if (ex != null) {
171             status = status + getString(R.string.band_mode_failed);
172         } else {
173             status = status + getString(R.string.band_mode_succeeded);
174         }
175
176         mProgressPanel = new AlertDialog.Builder(this)
177             .setMessage(status)
178             .setPositiveButton(android.R.string.ok, null).show();
179     }
180
181     private void clearList() {
182         while(mBandListAdapter.getCount() > 0) {
183             mBandListAdapter.remove(
184                     mBandListAdapter.getItem(0));
185         }
186     }
187
188     private void log(String msg) {
189         Log.d(LOG_TAG, "[BandsList] " + msg);
190     }
191
192     private Handler mHandler = new Handler() {
193         public void handleMessage(Message msg) {
194             AsyncResult ar;
195             switch (msg.what) {
196                 case EVENT_BAND_SCAN_COMPLETED:
197                     ar = (AsyncResult) msg.obj;
198
199                     bandListLoaded(ar);
200                     break;
201
202                 case EVENT_BAND_SELECTION_DONE:
203                     ar = (AsyncResult) msg.obj;
204
205                     getWindow().setFeatureInt(
206                             Window.FEATURE_INDETERMINATE_PROGRESS,
207                             Window.PROGRESS_VISIBILITY_OFF);
208
209                     if (!isFinishing()) {
210                         displayBandSelectionResult(ar.exception);
211                     }
212                     break;
213             }
214         }
215     };
216
217
218 }