Fix layout for time zone picker
Change-Id: I2f1dedac7d747901978ef5d4a1a58bae2fa02921 Fix: 35856915 Test: make RunSettingsRoboTests
This commit is contained in:
@@ -15,29 +15,28 @@
|
|||||||
-->
|
-->
|
||||||
|
|
||||||
<!-- Based on simple_list_item_2.xml in framework -->
|
<!-- Based on simple_list_item_2.xml in framework -->
|
||||||
<TwoLineListItem xmlns:android="http://schemas.android.com/apk/res/android"
|
<LinearLayout
|
||||||
|
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:minHeight="?android:attr/listPreferredItemHeight"
|
android:background="?android:attr/selectableItemBackground"
|
||||||
android:mode="twoLine"
|
|
||||||
android:gravity="center_vertical"
|
android:gravity="center_vertical"
|
||||||
>
|
android:minHeight="?android:attr/listPreferredItemHeight"
|
||||||
|
android:orientation="vertical"
|
||||||
|
android:paddingStart="@dimen/preference_no_icon_padding_start"
|
||||||
|
android:paddingEnd="?android:attr/listPreferredItemPaddingEnd">
|
||||||
|
|
||||||
<TextView android:id="@android:id/text1"
|
<TextView
|
||||||
|
android:id="@android:id/text1"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:minHeight="16dip"
|
android:textAppearance="?android:attr/textAppearanceListItem" />
|
||||||
android:layout_marginStart="10dip"
|
|
||||||
android:textAppearance="?android:attr/textAppearanceMedium"
|
|
||||||
/>
|
|
||||||
|
|
||||||
<TextView android:id="@android:id/text2"
|
<TextView
|
||||||
|
android:id="@android:id/text2"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:minHeight="10dip"
|
android:textAppearance="?android:attr/textAppearanceListItemSecondary"
|
||||||
android:layout_below="@android:id/text1"
|
android:textColor="?android:attr/textColorSecondary" />
|
||||||
android:layout_alignStart="@android:id/text1"
|
|
||||||
android:textAppearance="?android:attr/textAppearanceSmall"
|
|
||||||
/>
|
|
||||||
|
|
||||||
</TwoLineListItem>
|
</LinearLayout>
|
||||||
|
@@ -44,7 +44,7 @@
|
|||||||
/>
|
/>
|
||||||
|
|
||||||
<Preference
|
<Preference
|
||||||
android:fragment="com.android.settings.ZonePicker"
|
android:fragment="com.android.settings.datetime.ZonePicker"
|
||||||
android:key="timezone"
|
android:key="timezone"
|
||||||
android:title="@string/date_time_set_timezone"
|
android:title="@string/date_time_set_timezone"
|
||||||
android:summary="GMT-8:00"
|
android:summary="GMT-8:00"
|
||||||
|
@@ -302,13 +302,6 @@ public final class Utils extends com.android.settingslib.Utils {
|
|||||||
return formatPercentage(getBatteryLevel(batteryChangedIntent));
|
return formatPercentage(getBatteryLevel(batteryChangedIntent));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void forcePrepareCustomPreferencesList(
|
|
||||||
ViewGroup parent, View child, ListView list, boolean ignoreSidePadding) {
|
|
||||||
list.setScrollBarStyle(View.SCROLLBARS_OUTSIDE_OVERLAY);
|
|
||||||
list.setClipToPadding(false);
|
|
||||||
prepareCustomPreferencesList(parent, child, list, ignoreSidePadding);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Prepare a custom preferences layout, moving padding to {@link ListView}
|
* Prepare a custom preferences layout, moving padding to {@link ListView}
|
||||||
* when outside scrollbars are requested. Usually used to display
|
* when outside scrollbars are requested. Usually used to display
|
||||||
|
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (C) 2006 The Android Open Source Project
|
* Copyright (C) 2017 The Android Open Source Project
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -14,7 +14,7 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package com.android.settings;
|
package com.android.settings.datetime;
|
||||||
|
|
||||||
import android.annotation.NonNull;
|
import android.annotation.NonNull;
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
@@ -33,8 +33,9 @@ import android.widget.SimpleAdapter;
|
|||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
|
|
||||||
import com.android.internal.logging.nano.MetricsProto;
|
import com.android.internal.logging.nano.MetricsProto;
|
||||||
import com.android.settings.core.instrumentation.VisibilityLoggerMixin;
|
import com.android.settings.R;
|
||||||
import com.android.settings.core.instrumentation.Instrumentable;
|
import com.android.settings.core.instrumentation.Instrumentable;
|
||||||
|
import com.android.settings.core.instrumentation.VisibilityLoggerMixin;
|
||||||
import com.android.settingslib.datetime.ZoneGetter;
|
import com.android.settingslib.datetime.ZoneGetter;
|
||||||
|
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
@@ -52,11 +53,6 @@ import java.util.TimeZone;
|
|||||||
*/
|
*/
|
||||||
public class ZonePicker extends ListFragment implements Instrumentable {
|
public class ZonePicker extends ListFragment implements Instrumentable {
|
||||||
|
|
||||||
public interface ZoneSelectionListener {
|
|
||||||
// You can add any argument if you really need it...
|
|
||||||
void onZoneSelected(TimeZone tz);
|
|
||||||
}
|
|
||||||
|
|
||||||
private static final int MENU_TIMEZONE = Menu.FIRST+1;
|
private static final int MENU_TIMEZONE = Menu.FIRST+1;
|
||||||
private static final int MENU_ALPHABETICAL = Menu.FIRST;
|
private static final int MENU_ALPHABETICAL = Menu.FIRST;
|
||||||
private final VisibilityLoggerMixin mVisibilityLoggerMixin =
|
private final VisibilityLoggerMixin mVisibilityLoggerMixin =
|
||||||
@@ -67,8 +63,6 @@ public class ZonePicker extends ListFragment implements Instrumentable {
|
|||||||
private SimpleAdapter mTimezoneSortedAdapter;
|
private SimpleAdapter mTimezoneSortedAdapter;
|
||||||
private SimpleAdapter mAlphabeticalAdapter;
|
private SimpleAdapter mAlphabeticalAdapter;
|
||||||
|
|
||||||
private ZoneSelectionListener mListener;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructs an adapter with TimeZone list. Sorted by TimeZone in default.
|
* Constructs an adapter with TimeZone list. Sorted by TimeZone in default.
|
||||||
*
|
*
|
||||||
@@ -148,15 +142,6 @@ public class ZonePicker extends ListFragment implements Instrumentable {
|
|||||||
return -1;
|
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(ZoneGetter.KEY_ID));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onAttach(Context context) {
|
public void onAttach(Context context) {
|
||||||
super.onAttach(context);
|
super.onAttach(context);
|
||||||
@@ -185,8 +170,8 @@ public class ZonePicker extends ListFragment implements Instrumentable {
|
|||||||
public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container,
|
public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container,
|
||||||
Bundle savedInstanceState) {
|
Bundle savedInstanceState) {
|
||||||
final View view = super.onCreateView(inflater, container, savedInstanceState);
|
final View view = super.onCreateView(inflater, container, savedInstanceState);
|
||||||
final ListView list = (ListView) view.findViewById(android.R.id.list);
|
final ListView list = view.findViewById(android.R.id.list);
|
||||||
Utils.forcePrepareCustomPreferencesList(container, view, list, false);
|
prepareCustomPreferencesList(list);
|
||||||
return view;
|
return view;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -233,8 +218,10 @@ public class ZonePicker extends ListFragment implements Instrumentable {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setZoneSelectionListener(ZoneSelectionListener listener) {
|
static void prepareCustomPreferencesList(ListView list) {
|
||||||
mListener = listener;
|
list.setScrollBarStyle(View.SCROLLBARS_OUTSIDE_OVERLAY);
|
||||||
|
list.setClipToPadding(false);
|
||||||
|
list.setDivider(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setSorting(boolean sortByTimezone) {
|
private void setSorting(boolean sortByTimezone) {
|
||||||
@@ -259,12 +246,9 @@ public class ZonePicker extends ListFragment implements Instrumentable {
|
|||||||
final Activity activity = getActivity();
|
final Activity activity = getActivity();
|
||||||
final AlarmManager alarm = (AlarmManager) activity.getSystemService(Context.ALARM_SERVICE);
|
final AlarmManager alarm = (AlarmManager) activity.getSystemService(Context.ALARM_SERVICE);
|
||||||
alarm.setTimeZone(tzId);
|
alarm.setTimeZone(tzId);
|
||||||
final TimeZone tz = TimeZone.getTimeZone(tzId);
|
|
||||||
if (mListener != null) {
|
|
||||||
mListener.onZoneSelected(tz);
|
|
||||||
} else {
|
|
||||||
getActivity().onBackPressed();
|
getActivity().onBackPressed();
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
@@ -25,6 +25,7 @@ import android.widget.FrameLayout;
|
|||||||
import android.widget.SimpleAdapter;
|
import android.widget.SimpleAdapter;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
|
|
||||||
|
import com.android.settings.datetime.ZonePicker;
|
||||||
import com.android.settings.testutils.shadow.ShadowLibcoreTimeZoneNames;
|
import com.android.settings.testutils.shadow.ShadowLibcoreTimeZoneNames;
|
||||||
import com.android.settings.testutils.shadow.ShadowTimeZoneNames;
|
import com.android.settings.testutils.shadow.ShadowTimeZoneNames;
|
||||||
|
|
||||||
|
@@ -0,0 +1,71 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2017 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.datetime;
|
||||||
|
|
||||||
|
import android.app.Activity;
|
||||||
|
import android.os.Bundle;
|
||||||
|
import android.view.LayoutInflater;
|
||||||
|
import android.view.ViewGroup;
|
||||||
|
|
||||||
|
import com.android.settings.SettingsRobolectricTestRunner;
|
||||||
|
import com.android.settings.TestConfig;
|
||||||
|
import com.android.settings.core.instrumentation.VisibilityLoggerMixin;
|
||||||
|
import com.android.settings.testutils.shadow.ShadowZoneGetter;
|
||||||
|
|
||||||
|
import org.junit.Before;
|
||||||
|
import org.junit.Test;
|
||||||
|
import org.junit.runner.RunWith;
|
||||||
|
import org.robolectric.Robolectric;
|
||||||
|
import org.robolectric.annotation.Config;
|
||||||
|
import org.robolectric.util.ReflectionHelpers;
|
||||||
|
|
||||||
|
import static org.mockito.Matchers.any;
|
||||||
|
import static org.mockito.Mockito.mock;
|
||||||
|
import static org.mockito.Mockito.spy;
|
||||||
|
import static org.mockito.Mockito.verify;
|
||||||
|
|
||||||
|
@RunWith(SettingsRobolectricTestRunner.class)
|
||||||
|
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
|
||||||
|
public class ZonePickerTest {
|
||||||
|
|
||||||
|
private Activity mActivity;
|
||||||
|
private ZonePicker mZonePicker;
|
||||||
|
|
||||||
|
@Before
|
||||||
|
public void setUp() {
|
||||||
|
mActivity = Robolectric.setupActivity(Activity.class);
|
||||||
|
mZonePicker = spy(ZonePicker.class);
|
||||||
|
ReflectionHelpers.setField(mZonePicker, "mVisibilityLoggerMixin",
|
||||||
|
mock(VisibilityLoggerMixin.class));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@Config(shadows = ShadowZoneGetter.class)
|
||||||
|
public void testLaunch() {
|
||||||
|
// Shouldn't crash
|
||||||
|
mActivity.getFragmentManager()
|
||||||
|
.beginTransaction()
|
||||||
|
.add(mZonePicker, "test_tag")
|
||||||
|
.commit();
|
||||||
|
|
||||||
|
// Should render
|
||||||
|
verify(mZonePicker).onCreateView(
|
||||||
|
any(LayoutInflater.class),
|
||||||
|
any(ViewGroup.class),
|
||||||
|
any(Bundle.class));
|
||||||
|
}
|
||||||
|
}
|
@@ -0,0 +1,53 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2017 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.testutils.shadow;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
|
||||||
|
import com.android.settingslib.datetime.ZoneGetter;
|
||||||
|
|
||||||
|
import org.robolectric.annotation.Implementation;
|
||||||
|
import org.robolectric.annotation.Implements;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.TimeZone;
|
||||||
|
|
||||||
|
@Implements(ZoneGetter.class)
|
||||||
|
public class ShadowZoneGetter {
|
||||||
|
|
||||||
|
@Implementation
|
||||||
|
public static List<Map<String, Object>> getZonesList(Context context) {
|
||||||
|
List<Map<String, Object>> zones = new ArrayList<>();
|
||||||
|
zones.add(createDisplayEntry(TimeZone.getDefault(), "gmt-1:00", "FakePlace", 10000));
|
||||||
|
return zones;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static Map<String, Object> createDisplayEntry(
|
||||||
|
TimeZone tz, CharSequence gmtOffsetText, CharSequence displayName, int offsetMillis) {
|
||||||
|
Map<String, Object> map = new HashMap<>();
|
||||||
|
map.put(ZoneGetter.KEY_ID, tz.getID());
|
||||||
|
map.put(ZoneGetter.KEY_DISPLAYNAME, displayName.toString());
|
||||||
|
map.put(ZoneGetter.KEY_DISPLAY_LABEL, displayName);
|
||||||
|
map.put(ZoneGetter.KEY_GMT, gmtOffsetText.toString());
|
||||||
|
map.put(ZoneGetter.KEY_OFFSET_LABEL, gmtOffsetText);
|
||||||
|
map.put(ZoneGetter.KEY_OFFSET, offsetMillis);
|
||||||
|
return map;
|
||||||
|
}
|
||||||
|
}
|
Reference in New Issue
Block a user