1 package com.android.settings;
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;
22 * Radio Band Mode Selection Class
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.
27 * After user select one band, it will send the selection to baseband.
29 * It will alter user the result of select operation and exit, no matter success
33 public class BandMode extends Activity {
34 private static final String LOG_TAG = "phone";
35 private static final boolean DBG = false;
37 private static final int EVENT_BAND_SCAN_COMPLETED = 100;
38 private static final int EVENT_BAND_SELECTION_DONE = 200;
40 private static final String[] BAND_NAMES = new String[] {
49 private ListView mBandList;
50 private ArrayAdapter mBandListAdapter;
51 private BandListItem mTargetBand = null;
52 private DialogInterface mProgressPanel;
54 private Phone mPhone = null;
57 protected void onCreate(Bundle icicle) {
58 super.onCreate(icicle);
60 requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);
62 setContentView(R.layout.band_mode);
64 setTitle(getString(R.string.band_mode_title));
65 getWindow().setLayout(WindowManager.LayoutParams.MATCH_PARENT,
66 WindowManager.LayoutParams.WRAP_CONTENT);
68 mPhone = PhoneFactory.getDefaultPhone();
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);
81 private AdapterView.OnItemClickListener mBandSelectionHandler =
82 new AdapterView.OnItemClickListener () {
83 public void onItemClick(AdapterView parent, View v,
84 int position, long id) {
86 getWindow().setFeatureInt(
87 Window.FEATURE_INDETERMINATE_PROGRESS,
88 Window.PROGRESS_VISIBILITY_ON);
90 mTargetBand = (BandListItem) parent.getAdapter().getItem(position);
92 if (DBG) log("Select band : " + mTargetBand.toString());
95 mHandler.obtainMessage(EVENT_BAND_SELECTION_DONE);
96 mPhone.setBandMode(mTargetBand.getBand(), msg);
100 static private class BandListItem {
101 private int mBandMode = Phone.BM_UNSPECIFIED;
103 public BandListItem(int bm) {
107 public int getBand() {
111 public String toString() {
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 displayBandSelectionResult(ar.exception);