Refactor DateTimeSettingsSetup.
- Use Popup instead of bare fragment. - Expose Adapters in ZonePicker.java so that it can be used outside the fragment. - Fix layout Bug: 3175603 Change-Id: I2726fde4fa1a9aea1ecb29b6aa2d23dbc54232b9
This commit is contained in:
@@ -14,66 +14,61 @@
|
||||
limitations under the License.
|
||||
-->
|
||||
<!-- TODO: too many LinearLayout. -->
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:orientation="vertical"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="fill_parent"
|
||||
android:keepScreenOn="true"
|
||||
android:paddingTop="70dip"
|
||||
android:paddingBottom="100dip"
|
||||
android:paddingLeft="60dip"
|
||||
android:paddingRight="60dip">
|
||||
<RelativeLayout
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:orientation="vertical"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:keepScreenOn="true"
|
||||
android:paddingTop="60dip"
|
||||
android:paddingLeft="100dip"
|
||||
android:paddingRight="100dip"
|
||||
android:paddingBottom="40dip">
|
||||
|
||||
<!-- Title: Set date & time-->
|
||||
<TextView android:id="@+id/title"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="0"
|
||||
android:gravity="center"
|
||||
android:layout_marginBottom="30dip"
|
||||
android:layout_alignParentTop="true"
|
||||
android:textSize="64dip"
|
||||
android:textColor="#FF99cc00"
|
||||
android:text="@string/date_and_time_settings_title"/>
|
||||
<TextView
|
||||
android:id="@+id/title"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_alignParentLeft="true"
|
||||
android:layout_alignParentTop="true"
|
||||
android:textSize="40dip"
|
||||
android:textColor="#FF99cc00"
|
||||
android:text="@string/date_and_time_settings_title"/>
|
||||
|
||||
<LinearLayout android:id="@+id/main"
|
||||
android:orientation="horizontal"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="fill_parent"
|
||||
android:layout_weight="1">
|
||||
<!-- Left side: time zone setting -->
|
||||
<RelativeLayout android:layout_width="0px"
|
||||
android:layout_weight="1"
|
||||
android:layout_height="fill_parent"
|
||||
android:layout_marginRight="50dip">
|
||||
<LinearLayout android:id="@+id/timezone"
|
||||
android:orientation="vertical"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:layout_alignParentTop="true">
|
||||
<!-- Divider -->
|
||||
<View
|
||||
android:id="@+id/top_divider"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="1px"
|
||||
android:layout_below="@id/title"
|
||||
android:background="@color/divider_color"
|
||||
android:layout_marginBottom="5dip" />
|
||||
|
||||
<!--
|
||||
<CheckBox android:id="@+id/time_zone_auto"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:gravity="right|center_horizontal"
|
||||
android:layout_marginBottom="5dip"
|
||||
android:textSize="32dip"
|
||||
android:text="@string/time_zone_auto_stub"/> -->
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_below="@id/top_divider"
|
||||
android:layout_alignParentLeft="true"
|
||||
android:layout_marginTop="60dip"
|
||||
android:orientation="horizontal">
|
||||
|
||||
<!-- text should manually be set. -->
|
||||
<Button android:id="@+id/current_time_zone"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:textSize="24dip"
|
||||
android:layout_alignParentTop="true" />
|
||||
<LinearLayout android:id="@+id/zone_picker"
|
||||
android:orientation="vertical"
|
||||
<!-- left: timezone -->
|
||||
<LinearLayout
|
||||
android:layout_width="0px"
|
||||
android:layout_weight=".48"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical">
|
||||
<!-- text should manually be set. -->
|
||||
<Button
|
||||
android:id="@+id/time_zone_button"
|
||||
android:layout_width="400dip"
|
||||
android:layout_height="60dip"
|
||||
android:textSize="24dip" />
|
||||
<!-- <LinearLayout android:id="@+id/zone_picker"
|
||||
android:orientation="vertical"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="350dip"
|
||||
android:paddingLeft="10dip"
|
||||
android:paddingBottom="20dip"
|
||||
android:gravity="center"
|
||||
android:visibility="gone"
|
||||
android:clickable="true">
|
||||
@@ -81,68 +76,75 @@
|
||||
class="com.android.settings.ZonePicker"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content" />
|
||||
</LinearLayout>
|
||||
</LinearLayout>
|
||||
<Button android:id="@+id/skip_button"
|
||||
android:layout_width="300dip"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="0"
|
||||
android:layout_alignParentBottom="true"
|
||||
android:layout_centerHorizontal="true"
|
||||
android:textSize="32dip"
|
||||
android:text="@string/skip_label"/>
|
||||
</RelativeLayout>
|
||||
</LinearLayout> -->
|
||||
</LinearLayout>
|
||||
|
||||
<!-- Right side: date & time setting -->
|
||||
<RelativeLayout android:layout_width="0px"
|
||||
android:layout_weight="1"
|
||||
android:layout_height="fill_parent"
|
||||
android:layout_marginLeft="50dip">
|
||||
<LinearLayout android:id="@+id/datetime"
|
||||
android:orientation="vertical"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:layout_alignParentTop="true">
|
||||
<!-- spacer on center -->
|
||||
<View
|
||||
android:layout_width="0px"
|
||||
android:layout_weight=".04"
|
||||
android:layout_height="0dip"
|
||||
android:visibility="invisible" />
|
||||
|
||||
<CheckBox android:id="@+id/date_time_auto"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:gravity="right|center_horizontal"
|
||||
android:textSize="32dip"
|
||||
android:text="@string/date_time_auto" />
|
||||
<!-- right: DateTime -->
|
||||
<RelativeLayout
|
||||
android:layout_width="0px"
|
||||
android:layout_weight=".48"
|
||||
android:layout_height="wrap_content">
|
||||
|
||||
<CheckBox
|
||||
android:id="@+id/date_time_auto"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_alignParentTop="true"
|
||||
android:gravity="left"
|
||||
android:textSize="22dip"
|
||||
android:text="@string/date_time_auto" />
|
||||
|
||||
<!-- Divider -->
|
||||
<View
|
||||
android:id="@+id/datetime_divider"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="1px"
|
||||
android:layout_below="@id/date_time_auto"
|
||||
android:background="@color/divider_color"
|
||||
android:layout_marginTop="15dip"
|
||||
android:layout_marginBottom="80dip" />
|
||||
|
||||
<TimePicker
|
||||
android:id="@+id/time_picker"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_alignParentLeft="true"
|
||||
android:layout_below="@id/datetime_divider" />
|
||||
|
||||
<DatePicker
|
||||
android:id="@+id/date_picker"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_alignParentRight="true"
|
||||
android:layout_below="@id/datetime_divider" />
|
||||
|
||||
<LinearLayout android:orientation="horizontal"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content">
|
||||
<TimePicker android:id="@+id/time_picker"
|
||||
android:layout_width="0px"
|
||||
android:layout_weight=".5"
|
||||
android:layout_height="wrap_content"
|
||||
android:visibility="visible"/>
|
||||
<DatePicker android:id="@+id/date_picker"
|
||||
android:layout_width="0px"
|
||||
android:layout_weight=".5"
|
||||
android:layout_height="wrap_content"/>
|
||||
</LinearLayout>
|
||||
</LinearLayout>
|
||||
<Button android:id="@+id/next_button"
|
||||
android:layout_width="300dip"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="0"
|
||||
android:layout_alignParentBottom="true"
|
||||
android:layout_centerHorizontal="true"
|
||||
android:textSize="32dip"
|
||||
android:text="@string/next_label" />
|
||||
</RelativeLayout>
|
||||
</LinearLayout>
|
||||
|
||||
<LinearLayout android:id="@+id/bottom"
|
||||
android:orientation="horizontal"
|
||||
android:layout_width="fill_parent"
|
||||
android:gravity="center"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="0">
|
||||
<Button
|
||||
android:id="@+id/skip_button"
|
||||
android:layout_width="250dip"
|
||||
android:layout_height="80dip"
|
||||
android:layout_alignParentBottom="true"
|
||||
android:layout_toLeftOf="@+id/next_button"
|
||||
android:layout_marginRight="20dip"
|
||||
android:textSize="24dip"
|
||||
android:text="@string/skip_label"/>
|
||||
|
||||
</LinearLayout>
|
||||
</LinearLayout>
|
||||
<Button
|
||||
android:id="@+id/next_button"
|
||||
android:layout_width="250dip"
|
||||
android:layout_height="80dip"
|
||||
android:layout_alignParentBottom="true"
|
||||
android:layout_alignParentRight="true"
|
||||
android:textSize="24dip"
|
||||
android:text="@string/next_label" />
|
||||
|
||||
</RelativeLayout>
|
||||
|
@@ -30,18 +30,17 @@
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_alignParentLeft="true"
|
||||
android:layout_alignParentTop="true"
|
||||
android:gravity="left"
|
||||
android:textSize="40dip"
|
||||
android:textColor="#FF99cc00"
|
||||
android:text="@string/wifi_setup_title"/>
|
||||
|
||||
<ProgressBar
|
||||
android:id="@+id/scanning_progress_bar"
|
||||
android:layout_width="100dip"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_above="@+id/scanning_progress_text"
|
||||
android:layout_alignParentRight="true"
|
||||
style="?android:attr/progressBarStyleHorizontal" />
|
||||
android:id="@+id/scanning_progress_bar"
|
||||
android:layout_width="100dip"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_above="@+id/scanning_progress_text"
|
||||
android:layout_alignParentRight="true"
|
||||
style="?android:attr/progressBarStyleHorizontal" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/scanning_progress_text"
|
||||
|
@@ -16,30 +16,34 @@
|
||||
|
||||
package com.android.settings;
|
||||
|
||||
import com.android.settings.ZonePicker.ZoneSelectionListener;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.app.AlarmManager;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.res.Configuration;
|
||||
import android.os.Bundle;
|
||||
import android.provider.Settings;
|
||||
import android.provider.Settings.SettingNotFoundException;
|
||||
import android.util.Log;
|
||||
import android.view.View;
|
||||
import android.view.View.OnClickListener;
|
||||
import android.view.Window;
|
||||
import android.view.inputmethod.InputMethodManager;
|
||||
import android.widget.AdapterView;
|
||||
import android.widget.AdapterView.OnItemClickListener;
|
||||
import android.widget.Button;
|
||||
import android.widget.CompoundButton;
|
||||
import android.widget.CompoundButton.OnCheckedChangeListener;
|
||||
import android.widget.DatePicker;
|
||||
import android.widget.ListPopupWindow;
|
||||
import android.widget.SimpleAdapter;
|
||||
import android.widget.TimePicker;
|
||||
|
||||
import java.util.Calendar;
|
||||
import java.util.TimeZone;
|
||||
|
||||
public class DateTimeSettingsSetupWizard extends Activity
|
||||
implements OnClickListener, ZoneSelectionListener, OnCheckedChangeListener{
|
||||
implements OnClickListener, OnItemClickListener, OnCheckedChangeListener{
|
||||
private static final String TAG = DateTimeSettingsSetupWizard.class.getSimpleName();
|
||||
|
||||
// force the first status of auto datetime flag.
|
||||
@@ -51,7 +55,12 @@ public class DateTimeSettingsSetupWizard extends Activity
|
||||
/* Available only in XL */
|
||||
private CompoundButton mAutoDateTimeButton;
|
||||
// private CompoundButton mAutoTimeZoneButton;
|
||||
private Button mTimeZone;
|
||||
|
||||
private Button mTimeZoneButton;
|
||||
private ListPopupWindow mTimeZonePopup;
|
||||
private SimpleAdapter mTimeZoneAdapter;
|
||||
private TimeZone mSelectedTimeZone;
|
||||
|
||||
private TimePicker mTimePicker;
|
||||
private DatePicker mDatePicker;
|
||||
private InputMethodManager mInputMethodManager;
|
||||
@@ -83,10 +92,12 @@ public class DateTimeSettingsSetupWizard extends Activity
|
||||
R.string.zone_auto_summaryOff);*/
|
||||
|
||||
final TimeZone tz = TimeZone.getDefault();
|
||||
mTimeZone = (Button)findViewById(R.id.current_time_zone);
|
||||
mTimeZone.setText(DateTimeSettings.getTimeZoneText(tz));
|
||||
mTimeZone.setOnClickListener(this);
|
||||
// mTimeZone.setEnabled(!autoTimeZoneEnabled);
|
||||
mSelectedTimeZone = tz;
|
||||
mTimeZoneButton = (Button)findViewById(R.id.time_zone_button);
|
||||
mTimeZoneButton.setText(tz.getDisplayName());
|
||||
// mTimeZoneButton.setText(DateTimeSettings.getTimeZoneText(tz));
|
||||
mTimeZoneButton.setOnClickListener(this);
|
||||
mTimeZoneAdapter = ZonePicker.constructTimezoneAdapter(this, false);
|
||||
|
||||
final boolean autoDateTimeEnabled;
|
||||
final Intent intent = getIntent();
|
||||
@@ -109,9 +120,6 @@ public class DateTimeSettingsSetupWizard extends Activity
|
||||
|
||||
mInputMethodManager = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
|
||||
|
||||
((ZonePicker)getFragmentManager().findFragmentById(R.id.zone_picker_fragment))
|
||||
.setZoneSelectionListener(this);
|
||||
|
||||
((Button)findViewById(R.id.next_button)).setOnClickListener(this);
|
||||
((Button)findViewById(R.id.skip_button)).setOnClickListener(this);
|
||||
}
|
||||
@@ -119,9 +127,14 @@ public class DateTimeSettingsSetupWizard extends Activity
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
switch (view.getId()) {
|
||||
case R.id.current_time_zone: {
|
||||
findViewById(R.id.current_time_zone).setVisibility(View.GONE);
|
||||
findViewById(R.id.zone_picker).setVisibility(View.VISIBLE);
|
||||
case R.id.time_zone_button: {
|
||||
mTimeZonePopup = new ListPopupWindow(this, null);
|
||||
mTimeZonePopup.setWidth(mTimeZoneButton.getWidth());
|
||||
mTimeZonePopup.setAnchorView(mTimeZoneButton);
|
||||
mTimeZonePopup.setAdapter(mTimeZoneAdapter);
|
||||
mTimeZonePopup.setOnItemClickListener(this);
|
||||
mTimeZonePopup.setModal(true);
|
||||
mTimeZonePopup.show();
|
||||
break;
|
||||
}
|
||||
case R.id.next_button: {
|
||||
@@ -130,6 +143,15 @@ public class DateTimeSettingsSetupWizard extends Activity
|
||||
mAutoTimeZoneButton.isChecked() ? 1 : 0); */
|
||||
Settings.System.putInt(getContentResolver(), Settings.System.AUTO_TIME,
|
||||
mAutoDateTimeButton.isChecked() ? 1 : 0);
|
||||
|
||||
final TimeZone systemTimeZone = TimeZone.getDefault();
|
||||
if (!systemTimeZone.equals(mSelectedTimeZone)) {
|
||||
Log.i(TAG, "Another TimeZone is selected by a user. Changing system TimeZone.");
|
||||
final AlarmManager alarm = (AlarmManager)
|
||||
getSystemService(Context.ALARM_SERVICE);
|
||||
alarm.setTimeZone(mSelectedTimeZone.getID());
|
||||
}
|
||||
|
||||
// Note: in non-XL, Date & Time is stored by DatePickerDialog/TimePickerDialog,
|
||||
// so we don't need to save those values there, while in XL, we need to as
|
||||
// we don't use those Dialogs.
|
||||
@@ -182,15 +204,18 @@ public class DateTimeSettingsSetupWizard extends Activity
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onZoneSelected(TimeZone tz) {
|
||||
findViewById(R.id.current_time_zone).setVisibility(View.VISIBLE);
|
||||
findViewById(R.id.zone_picker).setVisibility(View.GONE);
|
||||
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
|
||||
final TimeZone tz = ZonePicker.obtainTimeZoneFromItem(parent.getItemAtPosition(position));
|
||||
mSelectedTimeZone = tz;
|
||||
|
||||
final Calendar now = Calendar.getInstance(tz);
|
||||
mTimeZone.setText(DateTimeSettings.getTimeZoneText(tz));
|
||||
mTimeZoneButton.setText(tz.getDisplayName());
|
||||
// mTimeZoneButton.setText(DateTimeSettings.getTimeZoneText(tz));
|
||||
mDatePicker.updateDate(now.get(Calendar.YEAR), now.get(Calendar.MONTH),
|
||||
now.get(Calendar.DAY_OF_MONTH));
|
||||
mTimePicker.setCurrentHour(now.get(Calendar.HOUR));
|
||||
mTimePicker.setCurrentMinute(now.get(Calendar.MINUTE));
|
||||
mTimeZonePopup.dismiss();
|
||||
}
|
||||
|
||||
private boolean isAutoDateTimeEnabled() {
|
||||
|
@@ -55,10 +55,10 @@ public class ZonePicker extends ListFragment {
|
||||
public void onZoneSelected(TimeZone tz);
|
||||
}
|
||||
|
||||
private static final String KEY_ID = "id";
|
||||
private static final String KEY_DISPLAYNAME = "name";
|
||||
private static final String KEY_GMT = "gmt";
|
||||
private static final String KEY_OFFSET = "offset";
|
||||
private static final String KEY_ID = "id"; // value: String
|
||||
private static final String KEY_DISPLAYNAME = "name"; // value: String
|
||||
private static final String KEY_GMT = "gmt"; // value: String
|
||||
private static final String KEY_OFFSET = "offset"; // value: int (Integer)
|
||||
private static final String XMLTAG_TIMEZONE = "timezone";
|
||||
|
||||
private static final int HOURS_1 = 60 * 60000;
|
||||
@@ -66,9 +66,6 @@ public class ZonePicker extends ListFragment {
|
||||
private static final int MENU_TIMEZONE = Menu.FIRST+1;
|
||||
private static final int MENU_ALPHABETICAL = Menu.FIRST;
|
||||
|
||||
// Initial focus position
|
||||
private int mDefault;
|
||||
|
||||
private boolean mSortedByTimezone;
|
||||
|
||||
private SimpleAdapter mTimezoneSortedAdapter;
|
||||
@@ -76,38 +73,73 @@ public class ZonePicker extends ListFragment {
|
||||
|
||||
private ZoneSelectionListener mListener;
|
||||
|
||||
/**
|
||||
* Constructs an adapter with TimeZone list. Sorted by TimeZone in default.
|
||||
*
|
||||
* @param sortedByName use Name for sorting the list.
|
||||
*/
|
||||
public static SimpleAdapter constructTimezoneAdapter(Context context,
|
||||
boolean sortedByName) {
|
||||
final String[] from = new String[] {KEY_DISPLAYNAME, KEY_GMT};
|
||||
final int[] to = new int[] {android.R.id.text1, android.R.id.text2};
|
||||
|
||||
final String sortKey = (sortedByName ? KEY_DISPLAYNAME : KEY_OFFSET);
|
||||
final MyComparator comparator = new MyComparator(sortKey);
|
||||
final List<HashMap<String, Object>> sortedList = getZones(context);
|
||||
Collections.sort(sortedList, comparator);
|
||||
final SimpleAdapter adapter = new SimpleAdapter(context,
|
||||
sortedList,
|
||||
android.R.layout.simple_list_item_2,
|
||||
from,
|
||||
to);
|
||||
|
||||
return adapter;
|
||||
}
|
||||
|
||||
/**
|
||||
* Searches {@link TimeZone} from the given {@link SimpleAdapter} object, and returns
|
||||
* the index for the TimeZone.
|
||||
*
|
||||
* @param adapter SimpleAdapter constructed by
|
||||
* {@link #constructTimezoneAdapter(Context, boolean)}.
|
||||
* @param tz TimeZone to be searched.
|
||||
* @return Index for the given TimeZone. -1 when there's no corresponding list item.
|
||||
* returned.
|
||||
*/
|
||||
public static int getTimeZoneIndex(SimpleAdapter adapter, TimeZone tz) {
|
||||
final String defaultId = tz.getID();
|
||||
final int listSize = adapter.getCount();
|
||||
for (int i = 0; i < listSize; i++) {
|
||||
// Using HashMap<String, Object> induces unnecessary warning.
|
||||
final HashMap<?,?> map = (HashMap<?,?>)adapter.getItem(i);
|
||||
final String id = (String)map.get(KEY_ID);
|
||||
if (defaultId.equals(id)) {
|
||||
// If current timezone is in this list, move focus to it
|
||||
return i;
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param item one of items in adapters. The adapter should be constructed by
|
||||
* {@link #constructTimezoneAdapter(Context, boolean)}.
|
||||
* @return TimeZone object corresponding to the item.
|
||||
*/
|
||||
public static TimeZone obtainTimeZoneFromItem(Object item) {
|
||||
return TimeZone.getTimeZone((String)((Map<?, ?>)item).get(KEY_ID));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onActivityCreated(Bundle savedInstanseState) {
|
||||
super.onActivityCreated(savedInstanseState);
|
||||
|
||||
final String[] from = new String[] {KEY_DISPLAYNAME, KEY_GMT};
|
||||
final int[] to = new int[] {android.R.id.text1, android.R.id.text2};
|
||||
|
||||
MyComparator comparator = new MyComparator(KEY_OFFSET);
|
||||
|
||||
Activity activity = getActivity();
|
||||
List<HashMap> timezoneSortedList = getZones();
|
||||
Collections.sort(timezoneSortedList, comparator);
|
||||
mTimezoneSortedAdapter = new SimpleAdapter(activity,
|
||||
(List) timezoneSortedList,
|
||||
android.R.layout.simple_list_item_2,
|
||||
from,
|
||||
to);
|
||||
|
||||
List<HashMap> alphabeticalList = new ArrayList<HashMap>(timezoneSortedList);
|
||||
comparator.setSortingKey(KEY_DISPLAYNAME);
|
||||
Collections.sort(alphabeticalList, comparator);
|
||||
mAlphabeticalAdapter = new SimpleAdapter(getActivity(),
|
||||
(List) alphabeticalList,
|
||||
android.R.layout.simple_list_item_2,
|
||||
from,
|
||||
to);
|
||||
final Activity activity = getActivity();
|
||||
mTimezoneSortedAdapter = constructTimezoneAdapter(activity, false);
|
||||
mAlphabeticalAdapter = constructTimezoneAdapter(activity, true);
|
||||
|
||||
// Sets the adapter
|
||||
setSorting(true);
|
||||
|
||||
// If current timezone is in this list, move focus to it
|
||||
setSelection(mDefault);
|
||||
setHasOptionsMenu(true);
|
||||
}
|
||||
|
||||
@@ -152,16 +184,22 @@ public class ZonePicker extends ListFragment {
|
||||
mListener = listener;
|
||||
}
|
||||
|
||||
private void setSorting(boolean timezone) {
|
||||
setListAdapter(timezone ? mTimezoneSortedAdapter : mAlphabeticalAdapter);
|
||||
mSortedByTimezone = timezone;
|
||||
private void setSorting(boolean sortByTimezone) {
|
||||
final SimpleAdapter adapter =
|
||||
sortByTimezone ? mTimezoneSortedAdapter : mAlphabeticalAdapter;
|
||||
setListAdapter(adapter);
|
||||
mSortedByTimezone = sortByTimezone;
|
||||
final int defaultIndex = getTimeZoneIndex(adapter, TimeZone.getDefault());
|
||||
if (defaultIndex >= 0) {
|
||||
setSelection(defaultIndex);
|
||||
}
|
||||
}
|
||||
|
||||
private List<HashMap> getZones() {
|
||||
List<HashMap> myData = new ArrayList<HashMap>();
|
||||
long date = Calendar.getInstance().getTimeInMillis();
|
||||
private static List<HashMap<String, Object>> getZones(Context context) {
|
||||
final List<HashMap<String, Object>> myData = new ArrayList<HashMap<String, Object>>();
|
||||
final long date = Calendar.getInstance().getTimeInMillis();
|
||||
try {
|
||||
XmlResourceParser xrp = getActivity().getResources().getXml(R.xml.timezones);
|
||||
XmlResourceParser xrp = context.getResources().getXml(R.xml.timezones);
|
||||
while (xrp.next() != XmlResourceParser.START_TAG)
|
||||
continue;
|
||||
xrp.next();
|
||||
@@ -192,15 +230,15 @@ public class ZonePicker extends ListFragment {
|
||||
return myData;
|
||||
}
|
||||
|
||||
protected void addItem(List<HashMap> myData, String id, String displayName,
|
||||
long date) {
|
||||
HashMap map = new HashMap();
|
||||
private static void addItem(
|
||||
List<HashMap<String, Object>> myData, String id, String displayName, long date) {
|
||||
final HashMap<String, Object> map = new HashMap<String, Object>();
|
||||
map.put(KEY_ID, id);
|
||||
map.put(KEY_DISPLAYNAME, displayName);
|
||||
TimeZone tz = TimeZone.getTimeZone(id);
|
||||
int offset = tz.getOffset(date);
|
||||
int p = Math.abs(offset);
|
||||
StringBuilder name = new StringBuilder();
|
||||
final TimeZone tz = TimeZone.getTimeZone(id);
|
||||
final int offset = tz.getOffset(date);
|
||||
final int p = Math.abs(offset);
|
||||
final StringBuilder name = new StringBuilder();
|
||||
name.append("GMT");
|
||||
|
||||
if (offset < 0) {
|
||||
@@ -223,20 +261,17 @@ public class ZonePicker extends ListFragment {
|
||||
map.put(KEY_GMT, name.toString());
|
||||
map.put(KEY_OFFSET, offset);
|
||||
|
||||
if (id.equals(TimeZone.getDefault().getID())) {
|
||||
mDefault = myData.size();
|
||||
}
|
||||
|
||||
myData.add(map);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onListItemClick(ListView l, View v, int position, long id) {
|
||||
Map map = (Map) l.getItemAtPosition(position);
|
||||
public void onListItemClick(ListView listView, View v, int position, long id) {
|
||||
final Map<?, ?> map = (Map<?, ?>)listView.getItemAtPosition(position);
|
||||
final String tzId = (String) map.get(KEY_ID);
|
||||
|
||||
// Update the system timezone value
|
||||
final Activity activity = getActivity();
|
||||
AlarmManager alarm = (AlarmManager) activity.getSystemService(Context.ALARM_SERVICE);
|
||||
String tzId = (String) map.get(KEY_ID);
|
||||
final AlarmManager alarm = (AlarmManager) activity.getSystemService(Context.ALARM_SERVICE);
|
||||
alarm.setTimeZone(tzId);
|
||||
final TimeZone tz = TimeZone.getTimeZone(tzId);
|
||||
if (mListener != null) {
|
||||
@@ -246,7 +281,7 @@ public class ZonePicker extends ListFragment {
|
||||
}
|
||||
}
|
||||
|
||||
private static class MyComparator implements Comparator<HashMap> {
|
||||
private static class MyComparator implements Comparator<HashMap<?, ?>> {
|
||||
private String mSortingKey;
|
||||
|
||||
public MyComparator(String sortingKey) {
|
||||
@@ -257,7 +292,7 @@ public class ZonePicker extends ListFragment {
|
||||
mSortingKey = sortingKey;
|
||||
}
|
||||
|
||||
public int compare(HashMap map1, HashMap map2) {
|
||||
public int compare(HashMap<?, ?> map1, HashMap<?, ?> map2) {
|
||||
Object value1 = map1.get(mSortingKey);
|
||||
Object value2 = map2.get(mSortingKey);
|
||||
|
||||
|
Reference in New Issue
Block a user