1 package com.android.settings;
3 import android.app.Activity;
4 import android.app.AlertDialog;
5 import android.content.DialogInterface;
6 import android.os.AsyncResult;
7 import android.os.Bundle;
8 import android.os.Handler;
9 import android.os.Message;
10 import android.util.Log;
11 import android.view.View;
12 import android.view.Window;
13 import android.view.WindowManager;
14 import android.widget.AdapterView;
15 import android.widget.ArrayAdapter;
16 import android.widget.ListView;
18 import com.android.internal.telephony.Phone;
19 import com.android.internal.telephony.PhoneFactory;
23 * Radio Band Mode Selection Class
25 * It will query baseband about all available band modes and display them
26 * in screen. It will display all six band modes if the query failed.
28 * After user select one band, it will send the selection to baseband.
30 * It will alter user the result of select operation and exit, no matter success
34 public class BandMode extends Activity {
35 private static final String LOG_TAG = "phone";
36 private static final boolean DBG = false;
38 private static final int EVENT_BAND_SCAN_COMPLETED = 100;
39 private static final int EVENT_BAND_SELECTION_DONE = 200;
41 //Directly maps to RIL_RadioBandMode from ril.h
42 private static final String[] BAND_NAMES = new String[] {
52 "Class 4 (Korea-PCS)",
55 "Class 7 (700Mhz-Upper)",
56 "Class 8 (1800Mhz-Upper)",
58 "Class 10 (800Mhz-Secondary)",
59 "Class 11 (Europe PAMR 400Mhz)",
61 "Class 16 (US-2500Mhz)"
64 private ListView mBandList;
65 private ArrayAdapter mBandListAdapter;
66 private BandListItem mTargetBand = null;
67 private DialogInterface mProgressPanel;
69 private Phone mPhone = null;
72 protected void onCreate(Bundle icicle) {
73 super.onCreate(icicle);
75 requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);
77 setContentView(R.layout.band_mode);
79 setTitle(getString(R.string.band_mode_title));
80 getWindow().setLayout(WindowManager.LayoutParams.MATCH_PARENT,
81 WindowManager.LayoutParams.WRAP_CONTENT);
83 mPhone = PhoneFactory.getDefaultPhone();
85 mBandList = (ListView) findViewById(R.id.band);
86 mBandListAdapter = new ArrayAdapter<BandListItem>(this,
87 android.R.layout.simple_list_item_1);
88 mBandList.setAdapter(mBandListAdapter);
89 mBandList.setOnItemClickListener(mBandSelectionHandler);
94 private AdapterView.OnItemClickListener mBandSelectionHandler =
95 new AdapterView.OnItemClickListener () {
96 public void onItemClick(AdapterView parent, View v,
97 int position, long id) {
99 getWindow().setFeatureInt(
100 Window.FEATURE_INDETERMINATE_PROGRESS,
101 Window.PROGRESS_VISIBILITY_ON);
103 mTargetBand = (BandListItem) parent.getAdapter().getItem(position);
105 if (DBG) log("Select band : " + mTargetBand.toString());
108 mHandler.obtainMessage(EVENT_BAND_SELECTION_DONE);
109 mPhone.setBandMode(mTargetBand.getBand(), msg);
113 static private class BandListItem {
114 private int mBandMode = Phone.BM_UNSPECIFIED;
116 public BandListItem(int bm) {
120 public int getBand() {
124 public String toString() {
125 if (mBandMode >= BAND_NAMES.length) return "Band mode " + mBandMode;
126 return BAND_NAMES[mBandMode];
130 private void loadBandList() {
131 String str = getString(R.string.band_mode_loading);
136 //ProgressDialog.show(this, null, str, true, true, null);
137 mProgressPanel = new AlertDialog.Builder(this)
141 Message msg = mHandler.obtainMessage(EVENT_BAND_SCAN_COMPLETED);
142 mPhone.queryAvailableBandMode(msg);
146 private void bandListLoaded(AsyncResult result) {
147 if (DBG) log("network list loaded");
149 if (mProgressPanel != null) mProgressPanel.dismiss();
153 boolean addBandSuccess = false;
156 if (result.result != null) {
157 int bands[] = (int[])result.result;
159 if(bands.length == 0) {
160 Log.wtf(LOG_TAG, "No Supported Band Modes");
167 mBandListAdapter.add(
168 new BandListItem(Phone.BM_UNSPECIFIED)); //Always include AUTOMATIC
169 for (int i=1; i<=size; i++) {
170 if (bands[i] == Phone.BM_UNSPECIFIED) {
173 item = new BandListItem(bands[i]);
174 mBandListAdapter.add(item);
175 if (DBG) log("Add " + item.toString());
177 addBandSuccess = true;
181 if (addBandSuccess == false) {
182 if (DBG) log("Error in query, add default list");
183 for (int i=0; i<Phone.BM_NUM_BAND_MODES; i++) {
184 item = new BandListItem(i);
185 mBandListAdapter.add(item);
186 if (DBG) log("Add default " + item.toString());
189 mBandList.requestFocus();
192 private void displayBandSelectionResult(Throwable ex) {
193 String status = getString(R.string.band_mode_set)
194 +" [" + mTargetBand.toString() + "] ";
197 status = status + getString(R.string.band_mode_failed);
199 status = status + getString(R.string.band_mode_succeeded);
202 mProgressPanel = new AlertDialog.Builder(this)
204 .setPositiveButton(android.R.string.ok, null).show();
207 private void clearList() {
208 while(mBandListAdapter.getCount() > 0) {
209 mBandListAdapter.remove(
210 mBandListAdapter.getItem(0));
214 private void log(String msg) {
215 Log.d(LOG_TAG, "[BandsList] " + msg);
218 private Handler mHandler = new Handler() {
219 public void handleMessage(Message msg) {
222 case EVENT_BAND_SCAN_COMPLETED:
223 ar = (AsyncResult) msg.obj;
228 case EVENT_BAND_SELECTION_DONE:
229 ar = (AsyncResult) msg.obj;
231 getWindow().setFeatureInt(
232 Window.FEATURE_INDETERMINATE_PROGRESS,
233 Window.PROGRESS_VISIBILITY_OFF);
235 if (!isFinishing()) {
236 displayBandSelectionResult(ar.exception);