packages/apps/Settings
修訂 | 0fd7736b7153c1a304d7c6098ecf1223052f56d5 (tree) |
---|---|
時間 | 2011-06-08 04:53:41 |
作者 | Freeman Ng <tenorslowworm@goog...> |
Commiter | Android (Google) Code Review |
Merge "use prefs-style layout for setup wizard date/time settings on non-xlarge screens" into honeycomb-mr2
@@ -1,168 +1,68 @@ | ||
1 | 1 | <?xml version="1.0" encoding="utf-8"?> |
2 | -<!-- Copyright (C) 2010 The Android Open Source Project | |
2 | +<!-- Copyright (C) 2011 The Android Open Source Project | |
3 | 3 | |
4 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); |
5 | 5 | you may not use this file except in compliance with the License. |
6 | 6 | You may obtain a copy of the License at |
7 | 7 | |
8 | - http://www.apache.org/licenses/LICENSE-2.0 | |
8 | + http://www.apache.org/licenses/LICENSE-2.0 | |
9 | 9 | |
10 | 10 | Unless required by applicable law or agreed to in writing, software |
11 | 11 | distributed under the License is distributed on an "AS IS" BASIS, |
12 | 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
13 | 13 | See the License for the specific language governing permissions and |
14 | 14 | limitations under the License. |
15 | - --> | |
16 | -<RelativeLayout | |
17 | - android:id="@+id/layout_root" | |
18 | - xmlns:android="http://schemas.android.com/apk/res/android" | |
19 | - android:orientation="vertical" | |
20 | - android:layout_width="match_parent" | |
21 | - android:layout_height="match_parent" | |
22 | - android:paddingTop="@dimen/datetime_margin_top" | |
23 | - android:paddingLeft="@dimen/screen_margin_sides" | |
24 | - android:paddingRight="@dimen/screen_margin_sides" | |
25 | - android:paddingBottom="@dimen/datetime_margin_bottom"> | |
15 | +--> | |
26 | 16 | |
27 | - <!-- Title: Set date & time--> | |
28 | - <TextView | |
29 | - android:id="@+id/title" | |
30 | - android:layout_width="wrap_content" | |
31 | - android:layout_height="wrap_content" | |
32 | - android:minHeight="48dip" | |
33 | - android:layout_alignParentLeft="true" | |
34 | - android:layout_marginLeft="16dip" | |
35 | - android:layout_alignParentTop="true" | |
36 | - android:textSize="32dip" | |
37 | - android:textColor="#FF99cc00" | |
38 | - android:text="@string/date_and_time_settings_title_setup_wizard" | |
39 | - android:gravity="bottom" /> | |
40 | - | |
41 | - <!-- Divider --> | |
42 | - <View | |
43 | - android:id="@+id/top_divider" | |
17 | +<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" | |
18 | + android:id="@+id/layout_root" | |
19 | + android:layout_height="match_parent" | |
44 | 20 | android:layout_width="match_parent" |
45 | - android:layout_height="3dip" | |
46 | - android:layout_below="@id/title" | |
47 | - android:layout_marginTop="6dip" | |
48 | - android:layout_marginBottom="17dip" | |
49 | - android:background="@color/divider_color" /> | |
50 | - | |
51 | - <RelativeLayout | |
52 | - android:id="@+id/timezone_auto_time" | |
53 | - android:layout_width="716dip" | |
54 | - android:layout_height="wrap_content" | |
55 | - android:layout_centerHorizontal="true" | |
56 | - android:layout_below="@id/top_divider"> | |
57 | - <!-- timezone --> | |
58 | - <Button | |
59 | - android:id="@+id/time_zone_button" | |
60 | - style="?android:attr/dropDownSpinnerStyle" | |
61 | - android:layout_width="304dip" | |
62 | - android:layout_height="48dip" | |
63 | - android:layout_alignParentLeft="true" | |
64 | - android:layout_alignBottom="@+id/date_time_auto" | |
65 | - android:gravity="left|center_vertical" | |
66 | - android:textAppearance="?android:attr/textAppearanceMedium" | |
67 | - android:textSize="20dip" /> | |
68 | - | |
69 | - <LinearLayout | |
70 | - android:id="@+id/date_time_auto" | |
71 | - android:layout_width="wrap_content" | |
72 | - android:layout_height="wrap_content" | |
73 | - android:orientation="vertical" | |
74 | - android:layout_toRightOf="@id/time_zone_button" | |
75 | - android:layout_marginLeft="32dip" | |
76 | - android:layout_alignParentRight="true"> | |
77 | - | |
78 | - <Switch | |
79 | - android:id="@+id/date_time_auto_button" | |
80 | - android:layout_width="match_parent" | |
81 | - android:layout_height="wrap_content" | |
82 | - android:minHeight="?android:attr/listPreferredItemHeight" | |
83 | - android:layout_marginLeft="16dip" | |
84 | - android:text="@string/date_time_auto" | |
85 | - android:textAppearance="?android:attr/textAppearanceMedium" | |
86 | - android:textSize="20dip" /> | |
87 | - | |
88 | - <!-- Divider --> | |
89 | - <View | |
90 | - android:layout_width="match_parent" | |
91 | - android:layout_height="1px" | |
92 | - android:background="@color/divider_color" /> | |
93 | - </LinearLayout> | |
94 | - </RelativeLayout> | |
21 | + android:paddingTop="96dip" | |
22 | + android:paddingLeft="40dip" | |
23 | + android:paddingRight="40dip" | |
24 | + android:paddingBottom="96dip" | |
25 | + android:orientation="vertical"> | |
26 | + | |
27 | + <FrameLayout android:id="@+id/timezone_dropdown_anchor" | |
28 | + android:layout_height="0px" | |
29 | + android:layout_width="match_parent" | |
30 | + android:layout_marginLeft="40dip" | |
31 | + android:layout_marginRight="40dip"/> | |
32 | + | |
33 | + <LinearLayout android:layout_height="0px" | |
34 | + android:layout_weight="1" | |
35 | + android:layout_width="match_parent" | |
36 | + android:orientation="vertical"> | |
37 | + | |
38 | + <fragment android:id="@+id/date_time_settings_fragment" | |
39 | + class="com.android.settings.DateTimeSettings" | |
40 | + android:layout_width="match_parent" | |
41 | + android:layout_height="match_parent" /> | |
95 | 42 | |
96 | - <LinearLayout | |
97 | - android:layout_width="624dip" | |
98 | - android:layout_height="wrap_content" | |
99 | - android:layout_centerHorizontal="true" | |
100 | - android:layout_below="@+id/timezone_auto_time" | |
101 | - android:layout_marginTop="48dip" | |
102 | - android:orientation="horizontal"> | |
43 | + </LinearLayout> | |
103 | 44 | |
104 | - <LinearLayout | |
105 | - android:layout_width="312dip" | |
106 | - android:layout_height="wrap_content" | |
107 | - android:orientation="vertical"> | |
108 | - <TextView | |
109 | - android:id="@+id/date_picker_title" | |
110 | - android:layout_width="match_parent" | |
111 | - android:layout_height="48dip" | |
112 | - android:text="@string/date_picker_title" | |
113 | - android:textAppearance="?android:attr/textAppearanceMedium" | |
114 | - android:textSize="20dip" | |
115 | - android:clickable="false" | |
116 | - android:longClickable="false" | |
117 | - android:gravity="center" /> | |
118 | - <DatePicker | |
119 | - android:id="@+id/date_picker" | |
120 | - android:layout_width="match_parent" | |
121 | - android:layout_height="wrap_content" | |
122 | - android:layout_below="@id/date_picker_title" /> | |
123 | - </LinearLayout> | |
45 | + <RelativeLayout android:layout_height="wrap_content" | |
46 | + android:layout_weight="0" | |
47 | + android:layout_width="match_parent"> | |
124 | 48 | |
125 | - <!-- divider --> | |
126 | 49 | <View |
127 | - android:id="@+id/center_divider" | |
128 | - android:layout_width="1dip" | |
129 | - android:layout_height="match_parent" | |
130 | - android:background="@color/divider_color" /> | |
131 | - | |
132 | - <LinearLayout | |
133 | - android:layout_width="312dip" | |
134 | - android:layout_height="wrap_content" | |
135 | - android:orientation="vertical"> | |
136 | - <TextView | |
137 | - android:id="@+id/time_picker_title" | |
138 | - android:layout_width="match_parent" | |
139 | - android:layout_height="48dip" | |
140 | - android:text="@string/time_picker_title" | |
141 | - android:textAppearance="?android:attr/textAppearanceMedium" | |
142 | - android:textSize="20dip" | |
143 | - android:gravity="center" /> | |
144 | - | |
145 | - <TimePicker | |
146 | - android:id="@+id/time_picker" | |
147 | - android:layout_width="match_parent" | |
148 | - android:layout_height="wrap_content" | |
149 | - android:layout_below="@id/time_picker_title" /> | |
150 | - </LinearLayout> | |
151 | - </LinearLayout> | |
50 | + android:id="@+id/bottom_divider" | |
51 | + android:layout_height="3dip" | |
52 | + android:layout_width="match_parent" | |
53 | + android:layout_marginTop="0dip" | |
54 | + android:layout_marginBottom="16dip" | |
55 | + android:background="@color/divider_color" | |
56 | + android:layout_above="@+id/next_button"/> | |
57 | + | |
58 | + <Button android:id="@+id/next_button" | |
59 | + android:layout_width="wrap_content" | |
60 | + android:minWidth="208dip" | |
61 | + android:layout_height="48dip" | |
62 | + android:layout_marginTop="10dip" | |
63 | + android:layout_alignParentRight="true" | |
64 | + android:text="@string/next_label"/> | |
152 | 65 | |
153 | - <View | |
154 | - android:id="@+id/bottom_divider" | |
155 | - android:layout_width="match_parent" | |
156 | - android:layout_height="3dip" | |
157 | - android:layout_alignLeft="@id/timezone_auto_time" | |
158 | - android:layout_above="@+id/next_button" | |
159 | - android:layout_marginBottom="16dip" | |
160 | - android:background="@color/divider_color" /> | |
66 | + </RelativeLayout> | |
161 | 67 | |
162 | - <Button | |
163 | - android:id="@+id/next_button" | |
164 | - style="@style/setup_wizard_button" | |
165 | - android:layout_alignParentBottom="true" | |
166 | - android:layout_alignParentRight="true" | |
167 | - android:text="@string/next_label" /> | |
168 | -</RelativeLayout> | |
68 | +</LinearLayout> |
@@ -1,11 +1,11 @@ | ||
1 | 1 | <?xml version="1.0" encoding="utf-8"?> |
2 | -<!-- Copyright (C) 2010 The Android Open Source Project | |
2 | +<!-- Copyright (C) 2011 The Android Open Source Project | |
3 | 3 | |
4 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); |
5 | 5 | you may not use this file except in compliance with the License. |
6 | 6 | You may obtain a copy of the License at |
7 | 7 | |
8 | - http://www.apache.org/licenses/LICENSE-2.0 | |
8 | + http://www.apache.org/licenses/LICENSE-2.0 | |
9 | 9 | |
10 | 10 | Unless required by applicable law or agreed to in writing, software |
11 | 11 | distributed under the License is distributed on an "AS IS" BASIS, |
@@ -60,6 +60,9 @@ public class DateTimeSettings extends SettingsPreferenceFragment | ||
60 | 60 | private static final int DIALOG_DATEPICKER = 0; |
61 | 61 | private static final int DIALOG_TIMEPICKER = 1; |
62 | 62 | |
63 | + // have we been launched from the setup wizard? | |
64 | + protected static final String EXTRA_IS_FIRST_RUN = "firstRun"; | |
65 | + | |
63 | 66 | private CheckBoxPreference mAutoTimePref; |
64 | 67 | private Preference mTimePref; |
65 | 68 | private Preference mTime24Pref; |
@@ -81,15 +84,18 @@ public class DateTimeSettings extends SettingsPreferenceFragment | ||
81 | 84 | boolean autoTimeEnabled = getAutoState(Settings.System.AUTO_TIME); |
82 | 85 | boolean autoTimeZoneEnabled = getAutoState(Settings.System.AUTO_TIME_ZONE); |
83 | 86 | |
87 | + Intent intent = getActivity().getIntent(); | |
88 | + boolean isFirstRun = intent.getBooleanExtra(EXTRA_IS_FIRST_RUN, false); | |
89 | + | |
84 | 90 | mDummyDate = Calendar.getInstance(); |
85 | 91 | mDummyDate.set(mDummyDate.get(Calendar.YEAR), 11, 31, 13, 0, 0); |
86 | 92 | |
87 | 93 | mAutoTimePref = (CheckBoxPreference) findPreference(KEY_AUTO_TIME); |
88 | 94 | mAutoTimePref.setChecked(autoTimeEnabled); |
89 | 95 | mAutoTimeZonePref = (CheckBoxPreference) findPreference(KEY_AUTO_TIME_ZONE); |
90 | - // Override auto-timezone if it's a wifi-only device. | |
91 | - // TODO: Remove this when auto-timezone is implemented based on wifi-location. | |
92 | - if (Utils.isWifiOnly()) { | |
96 | + // Override auto-timezone if it's a wifi-only device or if we're still in setup wizard. | |
97 | + // TODO: Remove the wifiOnly test when auto-timezone is implemented based on wifi-location. | |
98 | + if (Utils.isWifiOnly() || isFirstRun) { | |
93 | 99 | getPreferenceScreen().removePreference(mAutoTimeZonePref); |
94 | 100 | autoTimeZoneEnabled = false; |
95 | 101 | } |
@@ -100,6 +106,10 @@ public class DateTimeSettings extends SettingsPreferenceFragment | ||
100 | 106 | mTimeZone = findPreference("timezone"); |
101 | 107 | mDatePref = findPreference("date"); |
102 | 108 | mDateFormat = (ListPreference) findPreference(KEY_DATE_FORMAT); |
109 | + if (isFirstRun) { | |
110 | + getPreferenceScreen().removePreference(mTime24Pref); | |
111 | + getPreferenceScreen().removePreference(mDateFormat); | |
112 | + } | |
103 | 113 | |
104 | 114 | String [] dateFormats = getResources().getStringArray(R.array.date_format_values); |
105 | 115 | String [] formattedDates = new String[dateFormats.length]; |
@@ -158,7 +168,7 @@ public class DateTimeSettings extends SettingsPreferenceFragment | ||
158 | 168 | .unregisterOnSharedPreferenceChangeListener(this); |
159 | 169 | } |
160 | 170 | |
161 | - private void updateTimeAndDateDisplay(Context context) { | |
171 | + public void updateTimeAndDateDisplay(Context context) { | |
162 | 172 | java.text.DateFormat shortDateFormat = DateFormat.getDateFormat(context); |
163 | 173 | final Calendar now = Calendar.getInstance(); |
164 | 174 | Date dummyDate = mDummyDate.getTime(); |
@@ -18,6 +18,8 @@ package com.android.settings; | ||
18 | 18 | |
19 | 19 | import android.app.Activity; |
20 | 20 | import android.app.AlarmManager; |
21 | +import android.app.Fragment; | |
22 | +import android.app.FragmentTransaction; | |
21 | 23 | import android.content.BroadcastReceiver; |
22 | 24 | import android.content.Context; |
23 | 25 | import android.content.Intent; |
@@ -25,6 +27,8 @@ import android.content.IntentFilter; | ||
25 | 27 | import android.content.pm.ActivityInfo; |
26 | 28 | import android.content.res.Configuration; |
27 | 29 | import android.os.Bundle; |
30 | +import android.preference.Preference; | |
31 | +import android.preference.PreferenceFragment; | |
28 | 32 | import android.provider.Settings; |
29 | 33 | import android.provider.Settings.SettingNotFoundException; |
30 | 34 | import android.text.format.DateFormat; |
@@ -39,6 +43,7 @@ import android.widget.Button; | ||
39 | 43 | import android.widget.CompoundButton; |
40 | 44 | import android.widget.CompoundButton.OnCheckedChangeListener; |
41 | 45 | import android.widget.DatePicker; |
46 | +import android.widget.LinearLayout; | |
42 | 47 | import android.widget.ListPopupWindow; |
43 | 48 | import android.widget.SimpleAdapter; |
44 | 49 | import android.widget.TimePicker; |
@@ -47,14 +52,18 @@ import java.util.Calendar; | ||
47 | 52 | import java.util.TimeZone; |
48 | 53 | |
49 | 54 | public class DateTimeSettingsSetupWizard extends Activity |
50 | - implements OnClickListener, OnItemClickListener, OnCheckedChangeListener{ | |
55 | + implements OnClickListener, OnItemClickListener, OnCheckedChangeListener, | |
56 | + PreferenceFragment.OnPreferenceStartFragmentCallback { | |
51 | 57 | private static final String TAG = DateTimeSettingsSetupWizard.class.getSimpleName(); |
52 | 58 | |
53 | 59 | // force the first status of auto datetime flag. |
54 | 60 | private static final String EXTRA_INITIAL_AUTO_DATETIME_VALUE = |
55 | 61 | "extra_initial_auto_datetime_value"; |
56 | 62 | |
57 | - private boolean mXLargeScreenSize; | |
63 | + // If we have enough screen real estate, we use a radically different layout with | |
64 | + // big date and time pickers right on the screen, which requires very different handling. | |
65 | + // Otherwise, we use the standard date time settings fragment. | |
66 | + private boolean mUsingXLargeLayout; | |
58 | 67 | |
59 | 68 | /* Available only in XL */ |
60 | 69 | private CompoundButton mAutoDateTimeButton; |
@@ -74,20 +83,25 @@ public class DateTimeSettingsSetupWizard extends Activity | ||
74 | 83 | requestWindowFeature(Window.FEATURE_NO_TITLE); |
75 | 84 | super.onCreate(savedInstanceState); |
76 | 85 | setContentView(R.layout.date_time_settings_setupwizard); |
77 | - mXLargeScreenSize = (getResources().getConfiguration().screenLayout | |
78 | - & Configuration.SCREENLAYOUT_SIZE_MASK) | |
79 | - >= Configuration.SCREENLAYOUT_SIZE_LARGE; | |
80 | - if (mXLargeScreenSize) { | |
86 | + | |
87 | + // we know we've loaded the special xlarge layout because it has controls | |
88 | + // not present in the standard layout | |
89 | + mUsingXLargeLayout = findViewById(R.id.time_zone_button) != null; | |
90 | + if (mUsingXLargeLayout) { | |
91 | + setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE); | |
81 | 92 | initUiForXl(); |
82 | 93 | } else { |
94 | + setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT); | |
83 | 95 | findViewById(R.id.next_button).setOnClickListener(this); |
84 | 96 | } |
85 | - } | |
97 | + mTimeZoneAdapter = ZonePicker.constructTimezoneAdapter(this, false, | |
98 | + R.layout.date_time_setup_custom_list_item_2); | |
86 | 99 | |
87 | - public void initUiForXl() { | |
88 | 100 | final View layoutRoot = findViewById(R.id.layout_root); |
89 | 101 | layoutRoot.setSystemUiVisibility(View.STATUS_BAR_DISABLE_BACK); |
102 | + } | |
90 | 103 | |
104 | + public void initUiForXl() { | |
91 | 105 | // Currently just comment out codes related to auto timezone. |
92 | 106 | // TODO: Remove them when we are sure they are unnecessary. |
93 | 107 | /* |
@@ -98,16 +112,12 @@ public class DateTimeSettingsSetupWizard extends Activity | ||
98 | 112 | mAutoTimeZoneButton.setText(autoTimeZoneEnabled ? R.string.zone_auto_summaryOn : |
99 | 113 | R.string.zone_auto_summaryOff);*/ |
100 | 114 | |
101 | - setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE); | |
102 | - | |
103 | 115 | final TimeZone tz = TimeZone.getDefault(); |
104 | 116 | mSelectedTimeZone = tz; |
105 | 117 | mTimeZoneButton = (Button)findViewById(R.id.time_zone_button); |
106 | 118 | mTimeZoneButton.setText(tz.getDisplayName()); |
107 | 119 | // mTimeZoneButton.setText(DateTimeSettings.getTimeZoneText(tz)); |
108 | 120 | mTimeZoneButton.setOnClickListener(this); |
109 | - mTimeZoneAdapter = ZonePicker.constructTimezoneAdapter(this, false, | |
110 | - R.layout.date_time_setup_custom_list_item_2); | |
111 | 121 | |
112 | 122 | final boolean autoDateTimeEnabled; |
113 | 123 | final Intent intent = getIntent(); |
@@ -158,22 +168,11 @@ public class DateTimeSettingsSetupWizard extends Activity | ||
158 | 168 | public void onClick(View view) { |
159 | 169 | switch (view.getId()) { |
160 | 170 | case R.id.time_zone_button: { |
161 | - mTimeZonePopup = new ListPopupWindow(this, null); | |
162 | - mTimeZonePopup.setWidth(mTimeZoneButton.getWidth()); | |
163 | - mTimeZonePopup.setAnchorView(mTimeZoneButton); | |
164 | - mTimeZonePopup.setAdapter(mTimeZoneAdapter); | |
165 | - mTimeZonePopup.setOnItemClickListener(this); | |
166 | - mTimeZonePopup.setModal(true); | |
167 | - mTimeZonePopup.show(); | |
171 | + showTimezonePicker(R.id.time_zone_button); | |
168 | 172 | break; |
169 | 173 | } |
170 | 174 | case R.id.next_button: { |
171 | - if (mXLargeScreenSize) { | |
172 | - /* Settings.System.putInt(getContentResolver(), Settings.System.AUTO_TIME_ZONE, | |
173 | - mAutoTimeZoneButton.isChecked() ? 1 : 0); */ | |
174 | - Settings.System.putInt(getContentResolver(), Settings.System.AUTO_TIME, | |
175 | - mAutoDateTimeButton.isChecked() ? 1 : 0); | |
176 | - | |
175 | + if (mSelectedTimeZone != null) { | |
177 | 176 | final TimeZone systemTimeZone = TimeZone.getDefault(); |
178 | 177 | if (!systemTimeZone.equals(mSelectedTimeZone)) { |
179 | 178 | Log.i(TAG, "Another TimeZone is selected by a user. Changing system TimeZone."); |
@@ -181,7 +180,10 @@ public class DateTimeSettingsSetupWizard extends Activity | ||
181 | 180 | getSystemService(Context.ALARM_SERVICE); |
182 | 181 | alarm.setTimeZone(mSelectedTimeZone.getID()); |
183 | 182 | } |
184 | - | |
183 | + } | |
184 | + if (mAutoDateTimeButton != null) { | |
185 | + Settings.System.putInt(getContentResolver(), Settings.System.AUTO_TIME, | |
186 | + mAutoDateTimeButton.isChecked() ? 1 : 0); | |
185 | 187 | if (!mAutoDateTimeButton.isChecked()) { |
186 | 188 | DateTimeSettings.setDate(mDatePicker.getYear(), mDatePicker.getMonth(), |
187 | 189 | mDatePicker.getDayOfMonth()); |
@@ -203,7 +205,7 @@ public class DateTimeSettingsSetupWizard extends Activity | ||
203 | 205 | final boolean autoEnabled = isChecked; // just for readibility. |
204 | 206 | /*if (buttonView == mAutoTimeZoneButton) { |
205 | 207 | // In XL screen, we save all the state only when the next button is pressed. |
206 | - if (!mXLargeScreenSize) { | |
208 | + if (!mUsingXLargeLayout) { | |
207 | 209 | Settings.System.putInt(getContentResolver(), |
208 | 210 | Settings.System.AUTO_TIME_ZONE, |
209 | 211 | isChecked ? 1 : 0); |
@@ -233,18 +235,62 @@ public class DateTimeSettingsSetupWizard extends Activity | ||
233 | 235 | @Override |
234 | 236 | public void onItemClick(AdapterView<?> parent, View view, int position, long id) { |
235 | 237 | final TimeZone tz = ZonePicker.obtainTimeZoneFromItem(parent.getItemAtPosition(position)); |
236 | - mSelectedTimeZone = tz; | |
237 | - | |
238 | - final Calendar now = Calendar.getInstance(tz); | |
239 | - mTimeZoneButton.setText(tz.getDisplayName()); | |
240 | - // mTimeZoneButton.setText(DateTimeSettings.getTimeZoneText(tz)); | |
241 | - mDatePicker.updateDate(now.get(Calendar.YEAR), now.get(Calendar.MONTH), | |
242 | - now.get(Calendar.DAY_OF_MONTH)); | |
243 | - mTimePicker.setCurrentHour(now.get(Calendar.HOUR_OF_DAY)); | |
244 | - mTimePicker.setCurrentMinute(now.get(Calendar.MINUTE)); | |
238 | + if (mUsingXLargeLayout) { | |
239 | + mSelectedTimeZone = tz; | |
240 | + final Calendar now = Calendar.getInstance(tz); | |
241 | + if (mTimeZoneButton != null) { | |
242 | + mTimeZoneButton.setText(tz.getDisplayName()); | |
243 | + } | |
244 | + // mTimeZoneButton.setText(DateTimeSettings.getTimeZoneText(tz)); | |
245 | + mDatePicker.updateDate(now.get(Calendar.YEAR), now.get(Calendar.MONTH), | |
246 | + now.get(Calendar.DAY_OF_MONTH)); | |
247 | + mTimePicker.setCurrentHour(now.get(Calendar.HOUR_OF_DAY)); | |
248 | + mTimePicker.setCurrentMinute(now.get(Calendar.MINUTE)); | |
249 | + } else { | |
250 | + // in prefs mode, we actually change the setting right now, as opposed to waiting | |
251 | + // until Next is pressed in xLarge mode | |
252 | + final AlarmManager alarm = (AlarmManager) getSystemService(Context.ALARM_SERVICE); | |
253 | + alarm.setTimeZone(tz.getID()); | |
254 | + DateTimeSettings settingsFragment = (DateTimeSettings) getFragmentManager(). | |
255 | + findFragmentById(R.id.date_time_settings_fragment); | |
256 | + settingsFragment.updateTimeAndDateDisplay(this); | |
257 | + } | |
245 | 258 | mTimeZonePopup.dismiss(); |
246 | 259 | } |
247 | 260 | |
261 | + /** | |
262 | + * If this is called, that means we're in prefs style portrait mode for a large display | |
263 | + * and the user has tapped on the time zone preference. If we were a PreferenceActivity, | |
264 | + * we'd then launch the timezone fragment in a new activity, but we aren't, and here | |
265 | + * on a tablet display, we really want more of a popup picker look' like the one we use | |
266 | + * for the xlarge version of this activity. So we just take this opportunity to launch that. | |
267 | + * | |
268 | + * TODO: For phones, we might want to change this to do the "normal" opening | |
269 | + * of the zonepicker fragment in its own activity. Or we might end up just | |
270 | + * creating a separate DateTimeSettingsSetupWizardPhone activity that subclasses | |
271 | + * PreferenceActivity in the first place to handle all that automatically. | |
272 | + */ | |
273 | + @Override | |
274 | + public boolean onPreferenceStartFragment(PreferenceFragment caller, Preference pref) { | |
275 | + showTimezonePicker(R.id.timezone_dropdown_anchor); | |
276 | + return true; | |
277 | + } | |
278 | + | |
279 | + private void showTimezonePicker(int anchorViewId) { | |
280 | + View anchorView = findViewById(anchorViewId); | |
281 | + if (anchorView == null) { | |
282 | + Log.e(TAG, "Unable to find zone picker anchor view " + anchorViewId); | |
283 | + return; | |
284 | + } | |
285 | + mTimeZonePopup = new ListPopupWindow(this, null); | |
286 | + mTimeZonePopup.setWidth(anchorView.getWidth()); | |
287 | + mTimeZonePopup.setAnchorView(anchorView); | |
288 | + mTimeZonePopup.setAdapter(mTimeZoneAdapter); | |
289 | + mTimeZonePopup.setOnItemClickListener(this); | |
290 | + mTimeZonePopup.setModal(true); | |
291 | + mTimeZonePopup.show(); | |
292 | + } | |
293 | + | |
248 | 294 | private boolean isAutoDateTimeEnabled() { |
249 | 295 | try { |
250 | 296 | return Settings.System.getInt(getContentResolver(), Settings.System.AUTO_TIME) > 0; |
@@ -264,6 +310,9 @@ public class DateTimeSettingsSetupWizard extends Activity | ||
264 | 310 | }*/ |
265 | 311 | |
266 | 312 | private void updateTimeAndDateDisplay() { |
313 | + if (!mUsingXLargeLayout) { | |
314 | + return; | |
315 | + } | |
267 | 316 | final Calendar now = Calendar.getInstance(); |
268 | 317 | mTimeZoneButton.setText(now.getTimeZone().getDisplayName()); |
269 | 318 | mDatePicker.updateDate(now.get(Calendar.YEAR), now.get(Calendar.MONTH), |