Clean up DatetimeSettingsSetupWizard

Test: Clean up. Existing tests pass
Bug: 32516406
Change-Id: Id7361f6eee26a30d179277c1d425b2f61a99d07d
This commit is contained in:
Maurice Lam
2016-10-28 17:57:23 -07:00
parent 5abaef7dd1
commit 5ed50af025
7 changed files with 1 additions and 626 deletions

View File

@@ -560,15 +560,6 @@
android:value="true" /> android:value="true" />
</activity> </activity>
<activity android:name="DateTimeSettingsSetupWizard"
android:label="@string/date_and_time"
android:theme="@android:style/Theme.DeviceDefault.Light.NoActionBar"
android:screenOrientation="behind">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
</intent-filter>
</activity>
<activity android:name="Settings$LocalePickerActivity" <activity android:name="Settings$LocalePickerActivity"
android:label="@string/language_picker_title" android:label="@string/language_picker_title"
android:icon="@drawable/ic_settings_language" android:icon="@drawable/ic_settings_language"

View File

@@ -1,68 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright (C) 2011 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.
-->
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/layout_root"
android:layout_height="match_parent"
android:layout_width="match_parent"
android:paddingTop="96dip"
android:paddingStart="40dip"
android:paddingEnd="40dip"
android:paddingBottom="96dip"
android:orientation="vertical">
<FrameLayout android:id="@+id/timezone_dropdown_anchor"
android:layout_height="0px"
android:layout_width="match_parent"
android:layout_marginStart="40dip"
android:layout_marginEnd="40dip"/>
<LinearLayout android:layout_height="0px"
android:layout_weight="1"
android:layout_width="match_parent"
android:orientation="vertical">
<fragment android:id="@+id/date_time_settings_fragment"
class="com.android.settings.DateTimeSettings"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>
<RelativeLayout android:layout_height="wrap_content"
android:layout_weight="0"
android:layout_width="match_parent">
<View
android:id="@+id/bottom_divider"
android:layout_height="3dip"
android:layout_width="match_parent"
android:layout_marginTop="0dip"
android:layout_marginBottom="16dip"
android:background="@color/divider_color"
android:layout_above="@+id/next_button"/>
<Button android:id="@+id/next_button"
android:layout_width="wrap_content"
android:minWidth="208dip"
android:layout_height="48dip"
android:layout_marginTop="10dip"
android:layout_alignParentEnd="true"
android:text="@string/next_label"/>
</RelativeLayout>
</LinearLayout>

View File

@@ -1,168 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright (C) 2011 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.
-->
<RelativeLayout
android:id="@+id/layout_root"
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingTop="@dimen/datetime_margin_top"
android:paddingStart="@dimen/screen_margin_sides"
android:paddingEnd="@dimen/screen_margin_sides"
android:paddingBottom="@dimen/datetime_margin_bottom">
<!-- Title: Set date & time-->
<TextView
android:id="@+id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:minHeight="48dip"
android:layout_alignParentStart="true"
android:layout_marginStart="16dip"
android:layout_alignParentTop="true"
android:textSize="32dip"
android:textColor="@color/title_color"
android:text="@string/date_and_time_settings_title_setup_wizard"
android:gravity="bottom" />
<!-- Divider -->
<View
android:id="@+id/top_divider"
android:layout_width="match_parent"
android:layout_height="3dip"
android:layout_below="@id/title"
android:layout_marginTop="6dip"
android:layout_marginBottom="17dip"
android:background="@color/divider_color" />
<RelativeLayout
android:id="@+id/timezone_auto_time"
android:layout_width="716dip"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_below="@id/top_divider">
<!-- timezone -->
<Button
android:id="@+id/time_zone_button"
style="?android:attr/dropDownSpinnerStyle"
android:layout_width="304dip"
android:layout_height="48dip"
android:layout_alignParentStart="true"
android:layout_alignBottom="@+id/date_time_auto"
android:gravity="start|center_vertical"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textSize="20dip" />
<LinearLayout
android:id="@+id/date_time_auto"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_toEndOf="@id/time_zone_button"
android:layout_marginStart="32dip"
android:layout_alignParentEnd="true">
<Switch
android:id="@+id/date_time_auto_button"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:minHeight="?android:attr/listPreferredItemHeight"
android:layout_marginStart="16dip"
android:text="@string/date_time_auto"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textSize="20dip" />
<!-- Divider -->
<View
android:layout_width="match_parent"
android:layout_height="1px"
android:background="@color/divider_color" />
</LinearLayout>
</RelativeLayout>
<LinearLayout
android:layout_width="624dip"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_below="@+id/timezone_auto_time"
android:layout_marginTop="48dip"
android:orientation="horizontal">
<LinearLayout
android:layout_width="312dip"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:id="@+id/date_picker_title"
android:layout_width="match_parent"
android:layout_height="48dip"
android:text="@string/date_picker_title"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textSize="20dip"
android:clickable="false"
android:longClickable="false"
android:gravity="center" />
<DatePicker
android:id="@+id/date_picker"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/date_picker_title" />
</LinearLayout>
<!-- divider -->
<View
android:id="@+id/center_divider"
android:layout_width="1dip"
android:layout_height="match_parent"
android:background="@color/divider_color" />
<LinearLayout
android:layout_width="312dip"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:id="@+id/time_picker_title"
android:layout_width="match_parent"
android:layout_height="48dip"
android:text="@string/time_picker_title"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textSize="20dip"
android:gravity="center" />
<TimePicker
android:id="@+id/time_picker"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/time_picker_title" />
</LinearLayout>
</LinearLayout>
<View
android:id="@+id/bottom_divider"
android:layout_width="match_parent"
android:layout_height="3dip"
android:layout_alignStart="@id/timezone_auto_time"
android:layout_above="@+id/next_button"
android:layout_marginBottom="16dip"
android:background="@color/divider_color" />
<Button
android:id="@+id/next_button"
style="@style/setup_wizard_button"
android:layout_alignParentBottom="true"
android:layout_alignParentEnd="true"
android:text="@string/next_label" />
</RelativeLayout>

View File

@@ -1,54 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright (C) 2008 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.
-->
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/layout_root"
android:layout_height="fill_parent"
android:layout_width="fill_parent"
android:orientation="vertical">
<View
android:id="@+id/timezone_dropdown_anchor"
android:layout_width="match_parent"
android:layout_marginStart="20dip"
android:layout_marginEnd="20dip"
android:layout_height="0px" />
<LinearLayout android:layout_height="0px"
android:layout_weight="1"
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_weight="0"
android:padding="10dip"
android:layout_width="fill_parent">
<Button android:id="@+id/next_button"
android:layout_width="150dip"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:text="@string/next_label"
/>
</RelativeLayout>
</LinearLayout>

View File

@@ -1,326 +0,0 @@
/*
* Copyright (C) 2008 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.
*/
package com.android.settings;
import android.app.Activity;
import android.app.AlarmManager;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.Bundle;
import android.provider.Settings;
import android.provider.Settings.SettingNotFoundException;
import android.support.v14.preference.PreferenceFragment;
import android.support.v7.preference.Preference;
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, OnItemClickListener, OnCheckedChangeListener,
PreferenceFragment.OnPreferenceStartFragmentCallback {
private static final String TAG = DateTimeSettingsSetupWizard.class.getSimpleName();
// force the first status of auto datetime flag.
private static final String EXTRA_INITIAL_AUTO_DATETIME_VALUE =
"extra_initial_auto_datetime_value";
// If we have enough screen real estate, we use a radically different layout with
// big date and time pickers right on the screen, which requires very different handling.
// Otherwise, we use the standard date time settings fragment.
private boolean mUsingXLargeLayout;
/* Available only in XL */
private CompoundButton mAutoDateTimeButton;
// private CompoundButton mAutoTimeZoneButton;
private Button mTimeZoneButton;
private ListPopupWindow mTimeZonePopup;
private SimpleAdapter mTimeZoneAdapter;
private TimeZone mSelectedTimeZone;
private TimePicker mTimePicker;
private DatePicker mDatePicker;
private InputMethodManager mInputMethodManager;
@Override
protected void onCreate(Bundle savedInstanceState) {
requestWindowFeature(Window.FEATURE_NO_TITLE);
super.onCreate(savedInstanceState);
setContentView(R.layout.date_time_settings_setupwizard);
// we know we've loaded the special xlarge layout because it has controls
// not present in the standard layout
mUsingXLargeLayout = findViewById(R.id.time_zone_button) != null;
if (mUsingXLargeLayout) {
initUiForXl();
} else {
findViewById(R.id.next_button).setOnClickListener(this);
}
mTimeZoneAdapter = ZonePicker.constructTimezoneAdapter(this, false,
R.layout.date_time_setup_custom_list_item_2);
// For the normal view, disable Back since changes stick immediately
// and can't be canceled, and we already have a Next button. For xLarge,
// though, we save up our changes and set them upon Next, so Back can
// cancel. And also, in xlarge, we need the keyboard dismiss button
// to be available.
if (!mUsingXLargeLayout) {
final View layoutRoot = findViewById(R.id.layout_root);
layoutRoot.setSystemUiVisibility(View.STATUS_BAR_DISABLE_BACK);
}
}
public void initUiForXl() {
// Currently just comment out codes related to auto timezone.
// TODO: Remove them when we are sure they are unnecessary.
/*
final boolean autoTimeZoneEnabled = isAutoTimeZoneEnabled();
mAutoTimeZoneButton = (CompoundButton)findViewById(R.id.time_zone_auto);
mAutoTimeZoneButton.setChecked(autoTimeZoneEnabled);
mAutoTimeZoneButton.setOnCheckedChangeListener(this);
mAutoTimeZoneButton.setText(autoTimeZoneEnabled ? R.string.zone_auto_summaryOn :
R.string.zone_auto_summaryOff);*/
final TimeZone tz = TimeZone.getDefault();
mSelectedTimeZone = tz;
mTimeZoneButton = (Button)findViewById(R.id.time_zone_button);
mTimeZoneButton.setText(tz.getDisplayName());
mTimeZoneButton.setOnClickListener(this);
final boolean autoDateTimeEnabled;
final Intent intent = getIntent();
if (intent.hasExtra(EXTRA_INITIAL_AUTO_DATETIME_VALUE)) {
autoDateTimeEnabled = intent.getBooleanExtra(EXTRA_INITIAL_AUTO_DATETIME_VALUE, false);
} else {
autoDateTimeEnabled = isAutoDateTimeEnabled();
}
mAutoDateTimeButton = (CompoundButton)findViewById(R.id.date_time_auto_button);
mAutoDateTimeButton.setChecked(autoDateTimeEnabled);
mAutoDateTimeButton.setOnCheckedChangeListener(this);
mTimePicker = (TimePicker)findViewById(R.id.time_picker);
mTimePicker.setEnabled(!autoDateTimeEnabled);
mDatePicker = (DatePicker)findViewById(R.id.date_picker);
mDatePicker.setEnabled(!autoDateTimeEnabled);
mDatePicker.setCalendarViewShown(false);
DateTimeSettings.configureDatePicker(mDatePicker);
mInputMethodManager = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
((Button)findViewById(R.id.next_button)).setOnClickListener(this);
final Button skipButton = (Button)findViewById(R.id.skip_button);
if (skipButton != null) {
skipButton.setOnClickListener(this);
}
}
@Override
public void onResume() {
super.onResume();
IntentFilter filter = new IntentFilter();
filter.addAction(Intent.ACTION_TIME_TICK);
filter.addAction(Intent.ACTION_TIME_CHANGED);
filter.addAction(Intent.ACTION_TIMEZONE_CHANGED);
registerReceiver(mIntentReceiver, filter, null, null);
}
@Override
public void onPause() {
super.onPause();
unregisterReceiver(mIntentReceiver);
}
@Override
public void onClick(View view) {
switch (view.getId()) {
case R.id.time_zone_button: {
showTimezonePicker(R.id.time_zone_button);
break;
}
case R.id.next_button: {
if (mSelectedTimeZone != null) {
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());
}
}
if (mAutoDateTimeButton != null) {
Settings.Global.putInt(getContentResolver(), Settings.Global.AUTO_TIME,
mAutoDateTimeButton.isChecked() ? 1 : 0);
if (!mAutoDateTimeButton.isChecked()) {
DateTimeSettings.setDate(this, mDatePicker.getYear(), mDatePicker.getMonth(),
mDatePicker.getDayOfMonth());
DateTimeSettings.setTime(this,
mTimePicker.getCurrentHour(), mTimePicker.getCurrentMinute());
}
}
} // $FALL-THROUGH$
case R.id.skip_button: {
setResult(RESULT_OK);
finish();
break;
}
}
}
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
final boolean autoEnabled = isChecked; // just for readibility.
/*if (buttonView == mAutoTimeZoneButton) {
// In XL screen, we save all the state only when the next button is pressed.
if (!mUsingXLargeLayout) {
Settings.Global.putInt(getContentResolver(),
Settings.Global.AUTO_TIME_ZONE,
isChecked ? 1 : 0);
}
mTimeZone.setEnabled(!autoEnabled);
if (isChecked) {
findViewById(R.id.current_time_zone).setVisibility(View.VISIBLE);
findViewById(R.id.zone_picker).setVisibility(View.GONE);
}
} else */
if (buttonView == mAutoDateTimeButton) {
Settings.Global.putInt(getContentResolver(),
Settings.Global.AUTO_TIME,
isChecked ? 1 : 0);
mTimePicker.setEnabled(!autoEnabled);
mDatePicker.setEnabled(!autoEnabled);
}
if (autoEnabled) {
final View focusedView = getCurrentFocus();
if (focusedView != null) {
mInputMethodManager.hideSoftInputFromWindow(focusedView.getWindowToken(), 0);
focusedView.clearFocus();
}
}
}
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
final TimeZone tz = ZonePicker.obtainTimeZoneFromItem(parent.getItemAtPosition(position));
if (mUsingXLargeLayout) {
mSelectedTimeZone = tz;
final Calendar now = Calendar.getInstance(tz);
if (mTimeZoneButton != null) {
mTimeZoneButton.setText(tz.getDisplayName());
}
mDatePicker.updateDate(now.get(Calendar.YEAR), now.get(Calendar.MONTH),
now.get(Calendar.DAY_OF_MONTH));
mTimePicker.setCurrentHour(now.get(Calendar.HOUR_OF_DAY));
mTimePicker.setCurrentMinute(now.get(Calendar.MINUTE));
} else {
// in prefs mode, we actually change the setting right now, as opposed to waiting
// until Next is pressed in xLarge mode
final AlarmManager alarm = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
alarm.setTimeZone(tz.getID());
DateTimeSettings settingsFragment = (DateTimeSettings) getFragmentManager().
findFragmentById(R.id.date_time_settings_fragment);
settingsFragment.updateTimeAndDateDisplay(this);
}
mTimeZonePopup.dismiss();
}
/**
* If this is called, that means we're in prefs style portrait mode for a large display
* and the user has tapped on the time zone preference. If we were a PreferenceActivity,
* we'd then launch the timezone fragment in a new activity, but we aren't, and here
* on a tablet display, we really want more of a popup picker look' like the one we use
* for the xlarge version of this activity. So we just take this opportunity to launch that.
*
* TODO: For phones, we might want to change this to do the "normal" opening
* of the zonepicker fragment in its own activity. Or we might end up just
* creating a separate DateTimeSettingsSetupWizardPhone activity that subclasses
* PreferenceActivity in the first place to handle all that automatically.
*/
@Override
public boolean onPreferenceStartFragment(PreferenceFragment caller, Preference pref) {
showTimezonePicker(R.id.timezone_dropdown_anchor);
return true;
}
private void showTimezonePicker(int anchorViewId) {
View anchorView = findViewById(anchorViewId);
if (anchorView == null) {
Log.e(TAG, "Unable to find zone picker anchor view " + anchorViewId);
return;
}
mTimeZonePopup = new ListPopupWindow(this, null);
mTimeZonePopup.setWidth(anchorView.getWidth());
mTimeZonePopup.setAnchorView(anchorView);
mTimeZonePopup.setAdapter(mTimeZoneAdapter);
mTimeZonePopup.setOnItemClickListener(this);
mTimeZonePopup.setModal(true);
mTimeZonePopup.show();
}
private boolean isAutoDateTimeEnabled() {
try {
return Settings.Global.getInt(getContentResolver(), Settings.Global.AUTO_TIME) > 0;
} catch (SettingNotFoundException e) {
return true;
}
}
/*
private boolean isAutoTimeZoneEnabled() {
try {
return Settings.Global.getInt(getContentResolver(),
Settings.Global.AUTO_TIME_ZONE) > 0;
} catch (SettingNotFoundException e) {
return true;
}
}*/
private void updateTimeAndDateDisplay() {
if (!mUsingXLargeLayout) {
return;
}
final Calendar now = Calendar.getInstance();
mTimeZoneButton.setText(now.getTimeZone().getDisplayName());
mDatePicker.updateDate(now.get(Calendar.YEAR), now.get(Calendar.MONTH),
now.get(Calendar.DAY_OF_MONTH));
mTimePicker.setCurrentHour(now.get(Calendar.HOUR_OF_DAY));
mTimePicker.setCurrentMinute(now.get(Calendar.MINUTE));
}
private BroadcastReceiver mIntentReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
updateTimeAndDateDisplay();
}
};
}

View File

@@ -76,7 +76,7 @@ public class ZonePicker extends ListFragment implements Instrumentable {
public static SimpleAdapter constructTimezoneAdapter(Context context, public static SimpleAdapter constructTimezoneAdapter(Context context,
boolean sortedByName) { boolean sortedByName) {
return constructTimezoneAdapter(context, sortedByName, return constructTimezoneAdapter(context, sortedByName,
R.layout.date_time_setup_custom_list_item_2); R.layout.date_time_custom_list_item_2);
} }
/** /**