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 private static final String[] BAND_NAMES = new String[] {
50 private ListView mBandList;
51 private ArrayAdapter mBandListAdapter;
52 private BandListItem mTargetBand = null;
53 private DialogInterface mProgressPanel;
55 private Phone mPhone = null;
58 protected void onCreate(Bundle icicle) {
59 super.onCreate(icicle);
61 requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);
63 setContentView(R.layout.band_mode);
65 setTitle(getString(R.string.band_mode_title));
66 getWindow().setLayout(WindowManager.LayoutParams.MATCH_PARENT,
67 WindowManager.LayoutParams.WRAP_CONTENT);
69 mPhone = PhoneFactory.getDefaultPhone();
71 mBandList = (ListView) findViewById(R.id.band);
72 mBandListAdapter = new ArrayAdapter<BandListItem>(this,
73 android.R.layout.simple_list_item_1);
74 mBandList.setAdapter(mBandListAdapter);
75 mBandList.setOnItemClickListener(mBandSelectionHandler);
80 private AdapterView.OnItemClickListener mBandSelectionHandler =
81 new AdapterView.OnItemClickListener () {
82 public void onItemClick(AdapterView parent, View v,
83 int position, long id) {
85 getWindow().setFeatureInt(
86 Window.FEATURE_INDETERMINATE_PROGRESS,
87 Window.PROGRESS_VISIBILITY_ON);
89 mTargetBand = (BandListItem) parent.getAdapter().getItem(position);
91 if (DBG) log("Select band : " + mTargetBand.toString());
94 mHandler.obtainMessage(EVENT_BAND_SELECTION_DONE);
95 mPhone.setBandMode(mTargetBand.getBand(), msg);
99 static private class BandListItem {
100 private int mBandMode = Phone.BM_UNSPECIFIED;
102 public BandListItem(int bm) {
106 public int getBand() {
110 public String toString() {
111 if (mBandMode >= BAND_NAMES.length) return "Band mode " + mBandMode;
112 return BAND_NAMES[mBandMode];
116 private void loadBandList() {
117 String str = getString(R.string.band_mode_loading);
122 //ProgressDialog.show(this, null, str, true, true, null);
123 mProgressPanel = new AlertDialog.Builder(this)
127 Message msg = mHandler.obtainMessage(EVENT_BAND_SCAN_COMPLETED);
128 mPhone.queryAvailableBandMode(msg);
132 private void bandListLoaded(AsyncResult result) {
133 if (DBG) log("network list loaded");
135 if (mProgressPanel != null) mProgressPanel.dismiss();
139 boolean addBandSuccess = false;
142 if (result.result != null) {
143 int bands[] = (int[])result.result;
147 for (int i=1; i<size; i++) {
148 item = new BandListItem(bands[i]);
149 mBandListAdapter.add(item);
150 if (DBG) log("Add " + item.toString());
152 addBandSuccess = true;
156 if (addBandSuccess == false) {
157 if (DBG) log("Error in query, add default list");
158 for (int i=0; i<Phone.BM_BOUNDARY; i++) {
159 item = new BandListItem(i);
160 mBandListAdapter.add(item);
161 if (DBG) log("Add default " + item.toString());
164 mBandList.requestFocus();
167 private void displayBandSelectionResult(Throwable ex) {
168 String status = getString(R.string.band_mode_set)
169 +" [" + mTargetBand.toString() + "] ";
172 status = status + getString(R.string.band_mode_failed);
174 status = status + getString(R.string.band_mode_succeeded);
177 mProgressPanel = new AlertDialog.Builder(this)
179 .setPositiveButton(android.R.string.ok, null).show();
182 private void clearList() {
183 while(mBandListAdapter.getCount() > 0) {
184 mBandListAdapter.remove(
185 mBandListAdapter.getItem(0));
189 private void log(String msg) {
190 Log.d(LOG_TAG, "[BandsList] " + msg);
193 private Handler mHandler = new Handler() {
194 public void handleMessage(Message msg) {
197 case EVENT_BAND_SCAN_COMPLETED:
198 ar = (AsyncResult) msg.obj;
203 case EVENT_BAND_SELECTION_DONE:
204 ar = (AsyncResult) msg.obj;
206 getWindow().setFeatureInt(
207 Window.FEATURE_INDETERMINATE_PROGRESS,
208 Window.PROGRESS_VISIBILITY_OFF);
210 if (!isFinishing()) {
211 displayBandSelectionResult(ar.exception);