The Android Open Source Project | de2d9f5 | 2008-10-21 07:00:00 -0700 | [diff] [blame^] | 1 | /* |
| 2 | * Copyright (C) 2006 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | package com.android.settings; |
| 18 | |
| 19 | import android.app.ListActivity; |
| 20 | import android.content.Intent; |
| 21 | import android.os.Bundle; |
| 22 | import android.view.View; |
| 23 | import android.widget.ArrayAdapter; |
| 24 | import android.widget.ListView; |
| 25 | |
| 26 | import java.util.HashMap; |
| 27 | import java.util.List; |
| 28 | import java.util.Map; |
| 29 | |
| 30 | public class ZonePicker extends ListActivity { |
| 31 | |
| 32 | private ArrayAdapter<CharSequence> mFilterAdapter; |
| 33 | |
| 34 | @Override |
| 35 | public void onCreate(Bundle icicle) { |
| 36 | super.onCreate(icicle); |
| 37 | mFilterAdapter = ArrayAdapter.createFromResource(this, |
| 38 | R.array.timezone_filters, android.R.layout.simple_list_item_1); |
| 39 | setListAdapter(mFilterAdapter); |
| 40 | } |
| 41 | |
| 42 | protected void addItem(List<Map> data, String name, String zone) { |
| 43 | HashMap temp = new HashMap(); |
| 44 | temp.put("title", name); |
| 45 | temp.put("zone", zone); |
| 46 | data.add(temp); |
| 47 | } |
| 48 | |
| 49 | @Override |
| 50 | protected void onListItemClick(ListView l, View v, int position, long id) { |
| 51 | String filter = (String) mFilterAdapter.getItem(position); |
| 52 | // If All is chosen, reset the filter |
| 53 | if (filter.equals("All")) { |
| 54 | filter = null; |
| 55 | } |
| 56 | Intent zoneList = new Intent(); |
| 57 | zoneList.setClass(this, ZoneList.class); |
| 58 | zoneList.putExtra("filter", filter); |
| 59 | |
| 60 | startActivityForResult(zoneList, 0); |
| 61 | } |
| 62 | |
| 63 | @Override |
| 64 | protected void onActivityResult(int requestCode, int resultCode, Intent data) { |
| 65 | // If subactivity has resulted in a timezone selection, close this act. |
| 66 | if (resultCode == RESULT_OK) { |
| 67 | finish(); |
| 68 | } |
| 69 | } |
| 70 | } |