blob: c258773a9e6d681b239217c6cdc9f62f61346807 [file] [log] [blame]
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -08001package com.android.settings;
2
3import android.app.Activity;
4import android.app.AlertDialog;
5import com.android.internal.telephony.Phone;
6import com.android.internal.telephony.PhoneFactory;
7import android.os.Bundle;
8import android.os.Message;
9import android.os.Handler;
10import android.os.AsyncResult;
11import android.util.Log;
12import android.content.DialogInterface;
13import android.view.View;
14import android.view.WindowManager;
15import android.view.Window;
16import android.widget.ListView;
17import android.widget.ArrayAdapter;
18import 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 */
33public 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
Nathan Harold575fe1a2016-02-12 10:03:36 -080040 //Directly maps to RIL_RadioBandMode from ril.h
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -080041 private static final String[] BAND_NAMES = new String[] {
42 "Automatic",
Nathan Harold575fe1a2016-02-12 10:03:36 -080043 "Europe",
44 "United States",
45 "Japan",
46 "Australia",
47 "Australia 2",
48 "Cellular 800",
49 "PCS",
50 "Class 3 (JTACS)",
51 "Class 4 (Korea-PCS)",
52 "Class 5",
53 "Class 6 (IMT2000)",
54 "Class 7 (700Mhz-Upper)",
55 "Class 8 (1800Mhz-Upper)",
56 "Class 9 (900Mhz)",
57 "Class 10 (800Mhz-Secondary)",
58 "Class 11 (Europe PAMR 400Mhz)",
59 "Class 15 (US-AWS)",
60 "Class 16 (US-2500Mhz)"
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -080061 };
62
63 private ListView mBandList;
64 private ArrayAdapter mBandListAdapter;
65 private BandListItem mTargetBand = null;
66 private DialogInterface mProgressPanel;
67
68 private Phone mPhone = null;
69
70 @Override
71 protected void onCreate(Bundle icicle) {
72 super.onCreate(icicle);
73
74 requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);
Derek Taneb4575e2014-04-25 16:47:54 -070075
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -080076 setContentView(R.layout.band_mode);
77
78 setTitle(getString(R.string.band_mode_title));
Romain Guy33787152010-01-08 15:07:10 -080079 getWindow().setLayout(WindowManager.LayoutParams.MATCH_PARENT,
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -080080 WindowManager.LayoutParams.WRAP_CONTENT);
81
82 mPhone = PhoneFactory.getDefaultPhone();
83
84 mBandList = (ListView) findViewById(R.id.band);
85 mBandListAdapter = new ArrayAdapter<BandListItem>(this,
86 android.R.layout.simple_list_item_1);
87 mBandList.setAdapter(mBandListAdapter);
88 mBandList.setOnItemClickListener(mBandSelectionHandler);
89
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -080090 loadBandList();
91 }
92
93 private AdapterView.OnItemClickListener mBandSelectionHandler =
94 new AdapterView.OnItemClickListener () {
95 public void onItemClick(AdapterView parent, View v,
96 int position, long id) {
97
98 getWindow().setFeatureInt(
99 Window.FEATURE_INDETERMINATE_PROGRESS,
100 Window.PROGRESS_VISIBILITY_ON);
101
102 mTargetBand = (BandListItem) parent.getAdapter().getItem(position);
103
104 if (DBG) log("Select band : " + mTargetBand.toString());
105
106 Message msg =
107 mHandler.obtainMessage(EVENT_BAND_SELECTION_DONE);
108 mPhone.setBandMode(mTargetBand.getBand(), msg);
109 }
110 };
111
Michael Chan87620932009-05-14 17:47:02 -0700112 static private class BandListItem {
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800113 private int mBandMode = Phone.BM_UNSPECIFIED;
114
115 public BandListItem(int bm) {
116 mBandMode = bm;
117 }
118
119 public int getBand() {
120 return mBandMode;
121 }
122
123 public String toString() {
Derek Taneb4575e2014-04-25 16:47:54 -0700124 if (mBandMode >= BAND_NAMES.length) return "Band mode " + mBandMode;
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800125 return BAND_NAMES[mBandMode];
126 }
127 }
128
129 private void loadBandList() {
130 String str = getString(R.string.band_mode_loading);
131
132 if (DBG) log(str);
133
134
135 //ProgressDialog.show(this, null, str, true, true, null);
136 mProgressPanel = new AlertDialog.Builder(this)
137 .setMessage(str)
138 .show();
139
140 Message msg = mHandler.obtainMessage(EVENT_BAND_SCAN_COMPLETED);
141 mPhone.queryAvailableBandMode(msg);
142
143 }
144
145 private void bandListLoaded(AsyncResult result) {
146 if (DBG) log("network list loaded");
147
148 if (mProgressPanel != null) mProgressPanel.dismiss();
149
150 clearList();
151
152 boolean addBandSuccess = false;
153 BandListItem item;
154
155 if (result.result != null) {
156 int bands[] = (int[])result.result;
Nathan Harold575fe1a2016-02-12 10:03:36 -0800157
158 if(bands.length == 0) {
159 Log.wtf(LOG_TAG, "No Supported Band Modes");
160 return;
161 }
162
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800163 int size = bands[0];
164
165 if (size > 0) {
Nathan Harold575fe1a2016-02-12 10:03:36 -0800166 for (int i=1; i<=size; i++) {
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800167 item = new BandListItem(bands[i]);
168 mBandListAdapter.add(item);
169 if (DBG) log("Add " + item.toString());
170 }
171 addBandSuccess = true;
172 }
173 }
174
175 if (addBandSuccess == false) {
176 if (DBG) log("Error in query, add default list");
Nathan Harold575fe1a2016-02-12 10:03:36 -0800177 for (int i=0; i<Phone.BM_NUM_BAND_MODES; i++) {
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800178 item = new BandListItem(i);
179 mBandListAdapter.add(item);
180 if (DBG) log("Add default " + item.toString());
181 }
182 }
183 mBandList.requestFocus();
184 }
185
186 private void displayBandSelectionResult(Throwable ex) {
187 String status = getString(R.string.band_mode_set)
188 +" [" + mTargetBand.toString() + "] ";
189
190 if (ex != null) {
191 status = status + getString(R.string.band_mode_failed);
192 } else {
193 status = status + getString(R.string.band_mode_succeeded);
194 }
195
196 mProgressPanel = new AlertDialog.Builder(this)
197 .setMessage(status)
198 .setPositiveButton(android.R.string.ok, null).show();
199 }
200
201 private void clearList() {
202 while(mBandListAdapter.getCount() > 0) {
203 mBandListAdapter.remove(
204 mBandListAdapter.getItem(0));
205 }
206 }
207
208 private void log(String msg) {
209 Log.d(LOG_TAG, "[BandsList] " + msg);
210 }
211
212 private Handler mHandler = new Handler() {
213 public void handleMessage(Message msg) {
214 AsyncResult ar;
215 switch (msg.what) {
216 case EVENT_BAND_SCAN_COMPLETED:
217 ar = (AsyncResult) msg.obj;
218
219 bandListLoaded(ar);
220 break;
221
222 case EVENT_BAND_SELECTION_DONE:
223 ar = (AsyncResult) msg.obj;
224
225 getWindow().setFeatureInt(
226 Window.FEATURE_INDETERMINATE_PROGRESS,
227 Window.PROGRESS_VISIBILITY_OFF);
228
Jeevaka Badrappan26ef2c32012-06-01 10:57:31 +0300229 if (!isFinishing()) {
230 displayBandSelectionResult(ar.exception);
231 }
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800232 break;
233 }
234 }
235 };
236
237
238}