Implement DateTimeSetings for Setup Wizard XL.

Make the orientation "behind", as XL would require landscape.

TODO:
- Automatic Time Zone should be available.
- Layout is immature: need to have better theme and layout xml.

Change-Id: Iafe141223a227643ca774f4df5e5b7fde9520d31
This commit is contained in:
Daisuke Miyakawa
2010-09-09 11:51:16 -07:00
parent 0f4f2f3a81
commit 71cc548f7e
7 changed files with 330 additions and 86 deletions

View File

@@ -224,7 +224,7 @@
</activity-alias> </activity-alias>
<activity android:name="DateTimeSettingsSetupWizard" android:label="@string/date_and_time" <activity android:name="DateTimeSettingsSetupWizard" android:label="@string/date_and_time"
android:screenOrientation="portrait"> android:screenOrientation="behind">
<intent-filter> <intent-filter>
<action android:name="android.intent.action.MAIN" /> <action android:name="android.intent.action.MAIN" />
</intent-filter> </intent-filter>

View File

@@ -0,0 +1,133 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright (C) 2010 The Android Open Source Project
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
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:paddingTop="70dip"
android:paddingBottom="40dip"
android:paddingLeft="60dip"
android:paddingRight="60dip">
<!-- 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="10dip"
android:layout_alignParentTop="true"
android:textSize="64dip"
android:textColor="#FF30FF30"
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 -->
<LinearLayout android:orientation="vertical"
android:layout_width="0px"
android:layout_weight="1"
android:layout_height="fill_parent">
<!-- TODO: replace with appropratie UI component -->
<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"/>
<!-- 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"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:paddingLeft="10dip"
android:paddingBottom="20dip"
android:gravity="center"
android:visibility="gone"
android:clickable="true">
<fragment android:id="@+id/zone_picker_fragment"
class="com.android.settings.ZonePicker"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
</LinearLayout>
</LinearLayout>
<!-- Right side: date & time setting -->
<LinearLayout android:orientation="vertical"
android:layout_width="0px"
android:layout_weight="1"
android:layout_height="fill_parent">
<!-- TODO: replace with appropratie UI component -->
<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" />
<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>
</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="300dip"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_marginRight="50dip"
android:textSize="32dip"
android:text="@string/skip_label"/>
<Button android:id="@+id/next_button"
android:layout_width="300dip"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:layout_marginLeft="50dip"
android:textSize="32dip"
android:text="@string/next_label" />
</LinearLayout>
</LinearLayout>

View File

@@ -15,30 +15,24 @@
--> -->
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="match_parent" android:layout_height="fill_parent"
android:layout_width="match_parent" android:layout_width="fill_parent"
android:orientation="vertical"> android:orientation="vertical">
<LinearLayout <LinearLayout android:layout_height="0px"
android:orientation="vertical" android:layout_weight="1"
android:layout_height="0dip" android:layout_width="fill_parent"
android:layout_width="match_parent" android:orientation="vertical">
android:layout_weight="1" <fragment android:id="@+id/date_time_settings_fragment"
android:gravity="left"> class="com.android.settings.DateTimeSettings"
android:layout_width="fill_parent"
<ListView android:id="@android:id/list" android:layout_height="fill_parent" />
android:layout_width="match_parent"
android:layout_height="match_parent"
android:drawSelectorOnTop="false"
android:paddingTop="2dip"
/>
</LinearLayout> </LinearLayout>
<RelativeLayout <RelativeLayout android:layout_height="wrap_content"
android:layout_height="wrap_content" android:layout_weight="0"
android:layout_width="match_parent" android:layout_width="fill_parent"
android:background="@android:drawable/bottom_bar"> android:background="@android:drawable/bottom_bar">
<Button android:id="@+id/next_button" <Button android:id="@+id/next_button"
android:layout_width="150dip" android:layout_width="150dip"

View File

@@ -421,7 +421,8 @@
<string name="sdcard_settings_scanning_status">Scanning SD card for media\u2026</string> <string name="sdcard_settings_scanning_status">Scanning SD card for media\u2026</string>
<!-- Message when the SD card is mounted as read only --> <!-- Message when the SD card is mounted as read only -->
<string name="sdcard_settings_read_only_status">SD card mounted read-only</string> <string name="sdcard_settings_read_only_status">SD card mounted read-only</string>
<!-- SetupWizard strings used by DateTimeSettingsSetupWizard. The button label for going to the next screen without storing the setting. [CHAR LIMIT=5] -->
<string name="skip_label" >Skip</string>
<!-- SetupWizard strings used by DateTimeSettingsSetupWizard. The button label for going to the next screen. --> <!-- SetupWizard strings used by DateTimeSettingsSetupWizard. The button label for going to the next screen. -->
<string name="next_label">Next</string> <string name="next_label">Next</string>
@@ -2686,12 +2687,6 @@ found in the list of installed applications.</string>
Used in Wifi Setup For Setup Wizard with XL screen. --> Used in Wifi Setup For Setup Wizard with XL screen. -->
<string name="wifi_setup_status_connected">Connected</string> <string name="wifi_setup_status_connected">Connected</string>
<!-- Do not translate. Just a temprary stub. --> <!-- Do not translate. This is a stub which will be removed soon. -->
<string name="time_zone_manual_select_enabler" translatable="false">Experimental text</string> <string name="time_zone_auto_stub" translatable="false">Select Time Zone</string>
<!-- Do not translate. Just a temprary stub. -->
<string name="date_time_manual_select_enabler" translatable="false">Experimental text</string>
<!-- Do not translate. Just a temprary stub. -->
<string name="date_time_setup_skip" translatable="false">Skip</string>
<!-- Do not translate. Just a temprary stub. -->
<string name="date_time_setup_next" translatable="false">Next</string>
</resources> </resources>

View File

@@ -43,12 +43,15 @@ import java.util.TimeZone;
public class DateTimeSettings extends SettingsPreferenceFragment public class DateTimeSettings extends SettingsPreferenceFragment
implements OnSharedPreferenceChangeListener, implements OnSharedPreferenceChangeListener,
TimePickerDialog.OnTimeSetListener , DatePickerDialog.OnDateSetListener { TimePickerDialog.OnTimeSetListener, DatePickerDialog.OnDateSetListener {
private static final String HOURS_12 = "12"; private static final String HOURS_12 = "12";
private static final String HOURS_24 = "24"; private static final String HOURS_24 = "24";
// Used for showing the current date format, which looks like "12/31/2010", "2010/12/13", etc.
// The date value is dummy (independent of actual date).
private Calendar mDummyDate; private Calendar mDummyDate;
private static final String KEY_DATE_FORMAT = "date_format"; private static final String KEY_DATE_FORMAT = "date_format";
private static final String KEY_AUTO_TIME = "auto_time"; private static final String KEY_AUTO_TIME = "auto_time";
@@ -143,42 +146,25 @@ public class DateTimeSettings extends SettingsPreferenceFragment
private void updateTimeAndDateDisplay() { private void updateTimeAndDateDisplay() {
java.text.DateFormat shortDateFormat = DateFormat.getDateFormat(getActivity()); java.text.DateFormat shortDateFormat = DateFormat.getDateFormat(getActivity());
Date now = Calendar.getInstance().getTime(); final Calendar now = Calendar.getInstance();
Date dummyDate = mDummyDate.getTime(); Date dummyDate = mDummyDate.getTime();
mTimePref.setSummary(DateFormat.getTimeFormat(getActivity()).format(now)); mTimePref.setSummary(DateFormat.getTimeFormat(getActivity()).format(now.getTime()));
mTimeZone.setSummary(getTimeZoneText()); mTimeZone.setSummary(getTimeZoneText(now.getTimeZone()));
mDatePref.setSummary(shortDateFormat.format(now)); mDatePref.setSummary(shortDateFormat.format(now.getTime()));
mDateFormat.setSummary(shortDateFormat.format(dummyDate)); mDateFormat.setSummary(shortDateFormat.format(dummyDate));
} }
@Override @Override
public void onDateSet(DatePicker view, int year, int month, int day) { public void onDateSet(DatePicker view, int year, int month, int day) {
Calendar c = Calendar.getInstance(); setDate(year, month, day);
c.set(Calendar.YEAR, year);
c.set(Calendar.MONTH, month);
c.set(Calendar.DAY_OF_MONTH, day);
long when = c.getTimeInMillis();
if (when / 1000 < Integer.MAX_VALUE) {
SystemClock.setCurrentTimeMillis(when);
}
updateTimeAndDateDisplay(); updateTimeAndDateDisplay();
} }
@Override @Override
public void onTimeSet(TimePicker view, int hourOfDay, int minute) { public void onTimeSet(TimePicker view, int hourOfDay, int minute) {
Calendar c = Calendar.getInstance(); setTime(hourOfDay, minute);
c.set(Calendar.HOUR_OF_DAY, hourOfDay);
c.set(Calendar.MINUTE, minute);
long when = c.getTimeInMillis();
if (when / 1000 < Integer.MAX_VALUE) {
SystemClock.setCurrentTimeMillis(when);
}
updateTimeAndDateDisplay(); updateTimeAndDateDisplay();
// We don't need to call timeUpdated() here because the TIME_CHANGED // We don't need to call timeUpdated() here because the TIME_CHANGED
// broadcast is sent by the AlarmManager as a side effect of setting the // broadcast is sent by the AlarmManager as a side effect of setting the
// SystemClock time. // SystemClock time.
@@ -317,18 +303,34 @@ public class DateTimeSettings extends SettingsPreferenceFragment
} }
} }
private void setDateFormat(String format) {
if (format.length() == 0) {
format = null;
}
Settings.System.putString(getContentResolver(), Settings.System.DATE_FORMAT, format);
}
/* Helper routines to format timezone */ /* Helper routines to format timezone */
private String getTimeZoneText() { /* package */ static void setDate(int year, int month, int day) {
TimeZone tz = java.util.Calendar.getInstance().getTimeZone(); Calendar c = Calendar.getInstance();
c.set(Calendar.YEAR, year);
c.set(Calendar.MONTH, month);
c.set(Calendar.DAY_OF_MONTH, day);
long when = c.getTimeInMillis();
if (when / 1000 < Integer.MAX_VALUE) {
SystemClock.setCurrentTimeMillis(when);
}
}
/* package */ static void setTime(int hourOfDay, int minute) {
Calendar c = Calendar.getInstance();
c.set(Calendar.HOUR_OF_DAY, hourOfDay);
c.set(Calendar.MINUTE, minute);
long when = c.getTimeInMillis();
if (when / 1000 < Integer.MAX_VALUE) {
SystemClock.setCurrentTimeMillis(when);
}
}
/* package */ static String getTimeZoneText(TimeZone tz) {
boolean daylight = tz.inDaylightTime(new Date()); boolean daylight = tz.inDaylightTime(new Date());
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();
@@ -340,7 +342,7 @@ public class DateTimeSettings extends SettingsPreferenceFragment
return sb.toString(); return sb.toString();
} }
private char[] formatOffset(int off) { private static char[] formatOffset(int off) {
off = off / 1000 / 60; off = off / 1000 / 60;
char[] buf = new char[9]; char[] buf = new char[9];

View File

@@ -16,26 +16,142 @@
package com.android.settings; package com.android.settings;
import android.os.Bundle; import com.android.settings.ZonePicker.ZoneSelectionListener;
import android.view.View;
import android.view.Window;
import android.view.View.OnClickListener;
public class DateTimeSettingsSetupWizard extends DateTimeSettingsActivity import android.app.Activity;
implements OnClickListener { import android.content.res.Configuration;
private View mNextButton; import android.os.Bundle;
import android.provider.Settings;
import android.provider.Settings.SettingNotFoundException;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.Window;
import android.widget.Button;
import android.widget.CompoundButton;
import android.widget.CompoundButton.OnCheckedChangeListener;
import android.widget.DatePicker;
import android.widget.TimePicker;
import java.util.Calendar;
import java.util.TimeZone;
public class DateTimeSettingsSetupWizard extends Activity
implements OnClickListener, ZoneSelectionListener, OnCheckedChangeListener{
private boolean mXLargeScreenSize;
/* Available only in XL */
private Button mTimeZone;
private TimePicker mTimePicker;
private DatePicker mDatePicker;
@Override @Override
protected void onCreate(Bundle icicle) { protected void onCreate(Bundle savedInstanceState) {
requestWindowFeature(Window.FEATURE_NO_TITLE); requestWindowFeature(Window.FEATURE_NO_TITLE);
super.onCreate(icicle); super.onCreate(savedInstanceState);
setContentView(R.layout.date_time_settings_setupwizard); setContentView(R.layout.date_time_settings_setupwizard);
mNextButton = findViewById(R.id.next_button);
mNextButton.setOnClickListener(this); mXLargeScreenSize = (getResources().getConfiguration().screenLayout
& Configuration.SCREENLAYOUT_SIZE_MASK)
== Configuration.SCREENLAYOUT_SIZE_XLARGE;
if (mXLargeScreenSize) {
initUiForXl();
} else {
findViewById(R.id.next_button).setOnClickListener(this);
}
} }
public void onClick(View v) { public void initUiForXl() {
setResult(RESULT_OK); // TODO: use system value
finish(); final boolean autoTimeZoneEnabled = false;
final CompoundButton autoTimeZoneButton =
(CompoundButton)findViewById(R.id.time_zone_auto);
autoTimeZoneButton.setChecked(autoTimeZoneEnabled);
autoTimeZoneButton.setOnCheckedChangeListener(this);
// TODO: remove this after the system support.
autoTimeZoneButton.setEnabled(false);
final boolean autoDateTimeEnabled = isAutoDateTimeEnabled();
final CompoundButton autoDateTimeButton =
(CompoundButton)findViewById(R.id.date_time_auto);
autoDateTimeButton.setChecked(autoDateTimeEnabled);
autoDateTimeButton.setText(autoDateTimeEnabled ? R.string.date_time_auto_summaryOn :
R.string.date_time_auto_summaryOff);
autoDateTimeButton.setOnCheckedChangeListener(this);
final TimeZone tz = TimeZone.getDefault();
mTimeZone = (Button)findViewById(R.id.current_time_zone);
mTimeZone.setText(DateTimeSettings.getTimeZoneText(tz));
mTimeZone.setOnClickListener(this);
mTimeZone.setEnabled(!autoDateTimeEnabled);
mTimePicker = (TimePicker)findViewById(R.id.time_picker);
mTimePicker.setEnabled(!autoDateTimeEnabled);
mDatePicker = (DatePicker)findViewById(R.id.date_picker);
mDatePicker.setEnabled(!autoDateTimeEnabled);
((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);
}
@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);
break;
}
case R.id.next_button: {
if (mXLargeScreenSize) {
DateTimeSettings.setDate(mDatePicker.getYear(), mDatePicker.getMonth(),
mDatePicker.getDayOfMonth());
DateTimeSettings.setTime(
mTimePicker.getCurrentHour(), mTimePicker.getCurrentMinute());
}
} // $FALL-THROUGH$
case R.id.skip_button: {
setResult(RESULT_OK);
finish();
break;
}
}
}
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
Settings.System.putInt(getContentResolver(),
Settings.System.AUTO_TIME,
isChecked ? 1 : 0);
if (isChecked) {
findViewById(R.id.current_time_zone).setVisibility(View.VISIBLE);
findViewById(R.id.zone_picker).setVisibility(View.GONE);
}
mTimeZone.setEnabled(!isChecked);
mTimePicker.setEnabled(!isChecked);
mDatePicker.setEnabled(!isChecked);
}
@Override
public void onZoneSelected(TimeZone tz) {
findViewById(R.id.current_time_zone).setVisibility(View.VISIBLE);
findViewById(R.id.zone_picker).setVisibility(View.GONE);
final Calendar now = Calendar.getInstance(tz);
mTimeZone.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));
}
private boolean isAutoDateTimeEnabled() {
try {
return Settings.System.getInt(getContentResolver(), Settings.System.AUTO_TIME) > 0;
} catch (SettingNotFoundException e) {
return true;
}
} }
} }

View File

@@ -52,7 +52,7 @@ public class ZonePicker extends ListFragment {
public static interface ZoneSelectionListener { public static interface ZoneSelectionListener {
// You can add any argument if you really need it... // You can add any argument if you really need it...
public void onZoneSelected(); public void onZoneSelected(TimeZone tz);
} }
private static final String KEY_ID = "id"; private static final String KEY_ID = "id";
@@ -235,9 +235,13 @@ public class ZonePicker extends ListFragment {
// Update the system timezone value // Update the system timezone value
final Activity activity = getActivity(); final Activity activity = getActivity();
AlarmManager alarm = (AlarmManager) activity.getSystemService(Context.ALARM_SERVICE); AlarmManager alarm = (AlarmManager) activity.getSystemService(Context.ALARM_SERVICE);
alarm.setTimeZone((String) map.get(KEY_ID)); String tzId = (String) map.get(KEY_ID);
alarm.setTimeZone(tzId);
final TimeZone tz = TimeZone.getTimeZone(tzId);
if (mListener != null) { if (mListener != null) {
mListener.onZoneSelected(); mListener.onZoneSelected(tz);
} else {
getActivity().onBackPressed();
} }
} }