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:
@@ -224,7 +224,7 @@
|
||||
</activity-alias>
|
||||
|
||||
<activity android:name="DateTimeSettingsSetupWizard" android:label="@string/date_and_time"
|
||||
android:screenOrientation="portrait">
|
||||
android:screenOrientation="behind">
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.MAIN" />
|
||||
</intent-filter>
|
||||
|
133
res/layout-xlarge/date_time_settings_setupwizard.xml
Normal file
133
res/layout-xlarge/date_time_settings_setupwizard.xml
Normal 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>
|
@@ -15,29 +15,23 @@
|
||||
-->
|
||||
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="fill_parent"
|
||||
android:layout_width="fill_parent"
|
||||
android:orientation="vertical">
|
||||
|
||||
<LinearLayout
|
||||
android:orientation="vertical"
|
||||
android:layout_height="0dip"
|
||||
android:layout_width="match_parent"
|
||||
<LinearLayout android:layout_height="0px"
|
||||
android:layout_weight="1"
|
||||
android:gravity="left">
|
||||
|
||||
<ListView android:id="@android:id/list"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:drawSelectorOnTop="false"
|
||||
android:paddingTop="2dip"
|
||||
/>
|
||||
|
||||
android:layout_width="fill_parent"
|
||||
android:orientation="vertical">
|
||||
<fragment android:id="@+id/date_time_settings_fragment"
|
||||
class="com.android.settings.DateTimeSettings"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="fill_parent" />
|
||||
</LinearLayout>
|
||||
|
||||
<RelativeLayout
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_width="match_parent"
|
||||
<RelativeLayout android:layout_height="wrap_content"
|
||||
android:layout_weight="0"
|
||||
android:layout_width="fill_parent"
|
||||
android:background="@android:drawable/bottom_bar">
|
||||
|
||||
<Button android:id="@+id/next_button"
|
||||
|
@@ -421,7 +421,8 @@
|
||||
<string name="sdcard_settings_scanning_status">Scanning SD card for media\u2026</string>
|
||||
<!-- Message when the SD card is mounted as read only -->
|
||||
<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. -->
|
||||
<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. -->
|
||||
<string name="wifi_setup_status_connected">Connected</string>
|
||||
|
||||
<!-- Do not translate. Just a temprary stub. -->
|
||||
<string name="time_zone_manual_select_enabler" translatable="false">Experimental text</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>
|
||||
<!-- Do not translate. This is a stub which will be removed soon. -->
|
||||
<string name="time_zone_auto_stub" translatable="false">Select Time Zone</string>
|
||||
</resources>
|
||||
|
@@ -48,7 +48,10 @@ public class DateTimeSettings extends SettingsPreferenceFragment
|
||||
private static final String HOURS_12 = "12";
|
||||
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 static final String KEY_DATE_FORMAT = "date_format";
|
||||
private static final String KEY_AUTO_TIME = "auto_time";
|
||||
|
||||
@@ -143,40 +146,23 @@ public class DateTimeSettings extends SettingsPreferenceFragment
|
||||
|
||||
private void updateTimeAndDateDisplay() {
|
||||
java.text.DateFormat shortDateFormat = DateFormat.getDateFormat(getActivity());
|
||||
Date now = Calendar.getInstance().getTime();
|
||||
final Calendar now = Calendar.getInstance();
|
||||
Date dummyDate = mDummyDate.getTime();
|
||||
mTimePref.setSummary(DateFormat.getTimeFormat(getActivity()).format(now));
|
||||
mTimeZone.setSummary(getTimeZoneText());
|
||||
mDatePref.setSummary(shortDateFormat.format(now));
|
||||
mTimePref.setSummary(DateFormat.getTimeFormat(getActivity()).format(now.getTime()));
|
||||
mTimeZone.setSummary(getTimeZoneText(now.getTimeZone()));
|
||||
mDatePref.setSummary(shortDateFormat.format(now.getTime()));
|
||||
mDateFormat.setSummary(shortDateFormat.format(dummyDate));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDateSet(DatePicker view, int year, int month, int day) {
|
||||
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);
|
||||
}
|
||||
setDate(year, month, day);
|
||||
updateTimeAndDateDisplay();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onTimeSet(TimePicker view, 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);
|
||||
}
|
||||
setTime(hourOfDay, minute);
|
||||
updateTimeAndDateDisplay();
|
||||
|
||||
// We don't need to call timeUpdated() here because the TIME_CHANGED
|
||||
@@ -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 */
|
||||
|
||||
private String getTimeZoneText() {
|
||||
TimeZone tz = java.util.Calendar.getInstance().getTimeZone();
|
||||
/* package */ static void setDate(int year, int month, int day) {
|
||||
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());
|
||||
StringBuilder sb = new StringBuilder();
|
||||
|
||||
@@ -340,7 +342,7 @@ public class DateTimeSettings extends SettingsPreferenceFragment
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
private char[] formatOffset(int off) {
|
||||
private static char[] formatOffset(int off) {
|
||||
off = off / 1000 / 60;
|
||||
|
||||
char[] buf = new char[9];
|
||||
|
@@ -16,26 +16,142 @@
|
||||
|
||||
package com.android.settings;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.view.View;
|
||||
import android.view.Window;
|
||||
import android.view.View.OnClickListener;
|
||||
import com.android.settings.ZonePicker.ZoneSelectionListener;
|
||||
|
||||
public class DateTimeSettingsSetupWizard extends DateTimeSettingsActivity
|
||||
implements OnClickListener {
|
||||
private View mNextButton;
|
||||
import android.app.Activity;
|
||||
import android.content.res.Configuration;
|
||||
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
|
||||
protected void onCreate(Bundle icicle) {
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
requestWindowFeature(Window.FEATURE_NO_TITLE);
|
||||
super.onCreate(icicle);
|
||||
super.onCreate(savedInstanceState);
|
||||
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() {
|
||||
// TODO: use system value
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -52,7 +52,7 @@ public class ZonePicker extends ListFragment {
|
||||
|
||||
public static interface ZoneSelectionListener {
|
||||
// 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";
|
||||
@@ -235,9 +235,13 @@ public class ZonePicker extends ListFragment {
|
||||
// Update the system timezone value
|
||||
final Activity activity = getActivity();
|
||||
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) {
|
||||
mListener.onZoneSelected();
|
||||
mListener.onZoneSelected(tz);
|
||||
} else {
|
||||
getActivity().onBackPressed();
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user