diff --git a/res/drawable-hdpi/ic_menu_3d_globe.png b/res/drawable-hdpi/ic_menu_3d_globe.png deleted file mode 100644 index 1b55f0913fc..00000000000 Binary files a/res/drawable-hdpi/ic_menu_3d_globe.png and /dev/null differ diff --git a/res/drawable-mdpi/ic_menu_3d_globe.png b/res/drawable-mdpi/ic_menu_3d_globe.png deleted file mode 100644 index 6755d5e6f2d..00000000000 Binary files a/res/drawable-mdpi/ic_menu_3d_globe.png and /dev/null differ diff --git a/res/drawable-xhdpi/ic_menu_3d_globe.png b/res/drawable-xhdpi/ic_menu_3d_globe.png deleted file mode 100644 index 1fda0a26bf0..00000000000 Binary files a/res/drawable-xhdpi/ic_menu_3d_globe.png and /dev/null differ diff --git a/res/values/strings.xml b/res/values/strings.xml index 34b23e79c12..533c1304c0f 100644 --- a/res/values/strings.xml +++ b/res/values/strings.xml @@ -774,16 +774,8 @@ Search region Region - - Time Zone - - Time zones in %1$s Select UTC offset - - Sort alphabetically - - Sort by time zone %1$s starts on %2$s. diff --git a/res/xml/date_time_prefs.xml b/res/xml/date_time_prefs.xml index 511b39fea48..edda1ba66d9 100644 --- a/res/xml/date_time_prefs.xml +++ b/res/xml/date_time_prefs.xml @@ -56,7 +56,7 @@ settings:userRestriction="no_config_date_time" /> > sortedList = ZoneGetter.getZonesList(context); - Collections.sort(sortedList, comparator); - final SimpleAdapter adapter = new SimpleAdapter(context, - sortedList, - layoutId, - from, - to); - adapter.setViewBinder(new TimeZoneViewBinder()); - return adapter; - } - - private static class TimeZoneViewBinder implements SimpleAdapter.ViewBinder { - - /** - * Set the text to the given {@link CharSequence} as is, instead of calling toString, so - * that additional information stored in the CharSequence is, like spans added to a - * {@link android.text.SpannableString} are preserved. - */ - @Override - public boolean setViewValue(View view, Object data, String textRepresentation) { - TextView textView = (TextView) view; - textView.setText((CharSequence) data); - return true; - } - } - - /** - * Searches {@link TimeZone} from the given {@link SimpleAdapter} object, and returns - * the index for the TimeZone. - * - * @param adapter SimpleAdapter constructed by - * {@link #constructTimezoneAdapter(Context, boolean)}. - * @param tz TimeZone to be searched. - * @return Index for the given TimeZone. -1 when there's no corresponding list item. - * returned. - */ - public static int getTimeZoneIndex(SimpleAdapter adapter, TimeZone tz) { - final String defaultId = tz.getID(); - final int listSize = adapter.getCount(); - for (int i = 0; i < listSize; i++) { - // Using HashMap induces unnecessary warning. - final HashMap map = (HashMap)adapter.getItem(i); - final String id = (String)map.get(ZoneGetter.KEY_ID); - if (defaultId.equals(id)) { - // If current timezone is in this list, move focus to it - return i; - } - } - return -1; - } - - @Override - public int getMetricsCategory() { - return MetricsProto.MetricsEvent.ZONE_PICKER; - } - - @Override - public void onActivityCreated(Bundle savedInstanceState) { - super.onActivityCreated(savedInstanceState); - - final Activity activity = getActivity(); - mTimezoneSortedAdapter = constructTimezoneAdapter(activity, false); - mAlphabeticalAdapter = constructTimezoneAdapter(activity, true); - - // Sets the adapter - setSorting(true); - setHasOptionsMenu(true); - activity.setTitle(R.string.date_time_set_timezone); - } - - @Override - public void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - mVisibilityLoggerMixin = new VisibilityLoggerMixin(getMetricsCategory(), - FeatureFactory.getFactory(getContext()).getMetricsFeatureProvider()); - } - - @Override - public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, - Bundle savedInstanceState) { - final View view = super.onCreateView(inflater, container, savedInstanceState); - final ListView list = view.findViewById(android.R.id.list); - prepareCustomPreferencesList(list); - return view; - } - - @Override - public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { - menu.add(0, MENU_ALPHABETICAL, 0, R.string.zone_list_menu_sort_alphabetically) - .setIcon(android.R.drawable.ic_menu_sort_alphabetically); - menu.add(0, MENU_TIMEZONE, 0, R.string.zone_list_menu_sort_by_timezone) - .setIcon(R.drawable.ic_menu_3d_globe); - super.onCreateOptionsMenu(menu, inflater); - } - - @Override - public void onPrepareOptionsMenu(Menu menu) { - if (mSortedByTimezone) { - menu.findItem(MENU_TIMEZONE).setVisible(false); - menu.findItem(MENU_ALPHABETICAL).setVisible(true); - } else { - menu.findItem(MENU_TIMEZONE).setVisible(true); - menu.findItem(MENU_ALPHABETICAL).setVisible(false); - } - } - - @Override - public void onResume() { - super.onResume(); - mVisibilityLoggerMixin.onResume(); - } - - @Override - public boolean onOptionsItemSelected(MenuItem item) { - switch (item.getItemId()) { - - case MENU_TIMEZONE: - setSorting(true); - return true; - - case MENU_ALPHABETICAL: - setSorting(false); - return true; - - default: - return false; - } - } - - static void prepareCustomPreferencesList(ListView list) { - list.setScrollBarStyle(View.SCROLLBARS_OUTSIDE_OVERLAY); - list.setClipToPadding(false); - list.setDivider(null); - } - - private void setSorting(boolean sortByTimezone) { - final SimpleAdapter adapter = - sortByTimezone ? mTimezoneSortedAdapter : mAlphabeticalAdapter; - setListAdapter(adapter); - mSortedByTimezone = sortByTimezone; - final int defaultIndex = getTimeZoneIndex(adapter, TimeZone.getDefault()); - if (defaultIndex >= 0) { - setSelection(defaultIndex); - } - } - - @Override - public void onListItemClick(ListView listView, View v, int position, long id) { - // Ignore extra clicks - if (!isResumed()) return; - final Map map = (Map)listView.getItemAtPosition(position); - final String tzId = (String) map.get(ZoneGetter.KEY_ID); - - // Update the system timezone value - final Activity activity = getActivity(); - final AlarmManager alarm = (AlarmManager) activity.getSystemService(Context.ALARM_SERVICE); - alarm.setTimeZone(tzId); - - getActivity().onBackPressed(); - - } - - @Override - public void onPause() { - super.onPause(); - mVisibilityLoggerMixin.onPause(); - } - - @VisibleForTesting - static class MyComparator implements Comparator> { - private final Collator mCollator; - private String mSortingKey; - private boolean mSortedByName; - - public MyComparator(String sortingKey) { - mCollator = Collator.getInstance(); - mSortingKey = sortingKey; - mSortedByName = ZoneGetter.KEY_DISPLAY_LABEL.equals(sortingKey); - } - - public void setSortingKey(String sortingKey) { - mSortingKey = sortingKey; - mSortedByName = ZoneGetter.KEY_DISPLAY_LABEL.equals(sortingKey); - } - - public int compare(Map map1, Map map2) { - Object value1 = map1.get(mSortingKey); - Object value2 = map2.get(mSortingKey); - - /* - * This should never happen, but just in-case, put non-comparable - * items at the end. - */ - if (!isComparable(value1)) { - return isComparable(value2) ? 1 : 0; - } else if (!isComparable(value2)) { - return -1; - } - - if (mSortedByName) { - return mCollator.compare(value1, value2); - } else { - return ((Comparable) value1).compareTo(value2); - } - } - - private boolean isComparable(Object value) { - return (value != null) && (value instanceof Comparable); - } - } -} diff --git a/tests/robotests/src/com/android/settings/ZonePickerTest.java b/tests/robotests/src/com/android/settings/ZonePickerTest.java deleted file mode 100644 index 7816a580c06..00000000000 --- a/tests/robotests/src/com/android/settings/ZonePickerTest.java +++ /dev/null @@ -1,71 +0,0 @@ -/* - * Copyright (C) 2016 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 static com.google.common.truth.Truth.assertThat; - -import android.text.Spanned; -import android.text.style.TtsSpan; -import android.view.ViewGroup; -import android.widget.FrameLayout; -import android.widget.SimpleAdapter; -import android.widget.TextView; - -import com.android.settings.datetime.ZonePicker; -import com.android.settings.testutils.SettingsRobolectricTestRunner; -import com.android.settings.testutils.shadow.ShadowLibcoreTimeZoneNames; -import com.android.settings.testutils.shadow.ShadowTimeZoneNames; -import com.android.settings.testutils.shadow.ShadowZoneGetterData; - -import org.junit.Test; -import org.junit.runner.RunWith; -import org.robolectric.RuntimeEnvironment; -import org.robolectric.annotation.Config; - -@RunWith(SettingsRobolectricTestRunner.class) -@Config(shadows = { - ShadowLibcoreTimeZoneNames.class, - ShadowLibcoreTimeZoneNames.ShadowZoneStringsCache.class, - ShadowTimeZoneNames.class, - ShadowZoneGetterData.class, -} -) -public class ZonePickerTest { - - @Test - public void testConstructTimeZoneAdapter() { - final SimpleAdapter adapter = - ZonePicker.constructTimezoneAdapter(RuntimeEnvironment.application, true); - assertThat(adapter).isNotNull(); - - ViewGroup parent = new FrameLayout(RuntimeEnvironment.application); - ViewGroup convertView = new FrameLayout(RuntimeEnvironment.application); - TextView text1 = new TextView(RuntimeEnvironment.application); - text1.setId(android.R.id.text1); - convertView.addView(text1); - TextView text2 = new TextView(RuntimeEnvironment.application); - text2.setId(android.R.id.text2); - convertView.addView(text2); - - adapter.getView(0, convertView, parent); - final CharSequence text = text2.getText(); - assertThat(text).isInstanceOf(Spanned.class); - final TtsSpan[] spans = ((Spanned) text).getSpans(0, text.length(), TtsSpan.class); - // GMT offset label should have TTS spans - assertThat(spans.length).isGreaterThan(0); - } -} diff --git a/tests/robotests/src/com/android/settings/datetime/ZonePickerComparatorTest.java b/tests/robotests/src/com/android/settings/datetime/ZonePickerComparatorTest.java deleted file mode 100644 index 5e07308bece..00000000000 --- a/tests/robotests/src/com/android/settings/datetime/ZonePickerComparatorTest.java +++ /dev/null @@ -1,109 +0,0 @@ -package com.android.settings.datetime; - -import static com.google.common.truth.Truth.assertThat; - -import com.android.settings.testutils.SettingsRobolectricTestRunner; -import com.android.settingslib.datetime.ZoneGetter; - -import org.junit.After; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.HashMap; -import java.util.List; -import java.util.Locale; -import java.util.Map; -import java.util.TimeZone; - -@RunWith(SettingsRobolectricTestRunner.class) -public class ZonePickerComparatorTest { - - // Strings in Chinese are sorted by alphabet order of their Pinyin. - // "伦敦" -> "lundun"; "纽约" -> "niuyue"; "悉尼" -> "xini" - // "开罗" -> "kailuo"; "雅典" -> "yadian"; "上海" -> "shanghai" - private static final String[] TEST_CHINESE_NAME = - {"伦敦", "纽约", "悉尼", "开罗", "雅典", "上海"}; - private static final String[] ORDERED_CHINESE_NAME = - {"开罗", "伦敦", "纽约", "上海", "悉尼", "雅典"}; - - private static final String[] TEST_ENGLISH_NAME = - {"London", "New York", "Sydney", "Cairo", "Athens", "Shanghai"}; - private static final String[] ORDERED_ENGLISH_NAME = - {"Athens", "Cairo", "London", "New York", "Shanghai", "Sydney"}; - - private static final Locale INIT_LOCALE = Locale.getDefault(); - - private Map> mTestDataMap; - private List> mTestList; - - @Before - public void setUp() { - mTestDataMap = new HashMap<>(); - mTestDataMap.put("zh_CN", Arrays.asList(TEST_CHINESE_NAME)); - mTestDataMap.put("en_US", Arrays.asList(TEST_ENGLISH_NAME)); - } - - @After - public void tearDown() { - Locale.setDefault(INIT_LOCALE); - } - - @Test - public void testComparator_sortChineseString() { - String sortKey = ZoneGetter.KEY_DISPLAY_LABEL; - mTestList = getMockZonesList("zh_CN"); - Locale.setDefault(new Locale("zh")); - mTestList.sort(new ZonePicker.MyComparator(sortKey)); - for (int i = 0; i < mTestList.size(); i++) { - assertThat(mTestList.get(i).get(sortKey).toString()).isEqualTo(ORDERED_CHINESE_NAME[i]); - } - } - - @Test - public void testComparator_sortEnglishString() { - String sortKey = ZoneGetter.KEY_DISPLAY_LABEL; - mTestList = getMockZonesList("en_US"); - Locale.setDefault(new Locale("en")); - mTestList.sort(new ZonePicker.MyComparator(sortKey)); - for (int i = 0; i < mTestList.size(); i++) { - assertThat(mTestList.get(i).get(sortKey).toString()).isEqualTo(ORDERED_ENGLISH_NAME[i]); - } - } - - @Test - public void testComparator_sortInteger() { - String sortKey = ZoneGetter.KEY_OFFSET; - // TestList of any locale can be selected to test integer sorting. - mTestList = getMockZonesList("en_US"); - mTestList.sort(new ZonePicker.MyComparator(sortKey)); - for (int i = 0; i < mTestList.size(); i++) { - assertThat(mTestList.get(i).get(sortKey)).isEqualTo(i); - } - } - - private List> getMockZonesList(String locale) { - List> zones = new ArrayList<>(); - List testData = mTestDataMap.get(locale); - TimeZone tz = TimeZone.getDefault(); - int testSize = testData.size(); - for (int i = 0; i < testSize; i++) { - zones.add(createMockDisplayEntry(tz, "GMT+08:00", testData.get(i), testSize - i - 1)); - } - return zones; - } - - private Map createMockDisplayEntry( - TimeZone tz, CharSequence gmtOffsetText, CharSequence displayName, int offsetMillis) { - Map 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; - } -} diff --git a/tests/robotests/src/com/android/settings/datetime/ZonePickerTest.java b/tests/robotests/src/com/android/settings/datetime/ZonePickerTest.java deleted file mode 100644 index e6a9ca76d80..00000000000 --- a/tests/robotests/src/com/android/settings/datetime/ZonePickerTest.java +++ /dev/null @@ -1,66 +0,0 @@ -/* - * 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 static org.mockito.ArgumentMatchers.nullable; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.spy; -import static org.mockito.Mockito.verify; - -import android.app.Activity; -import android.os.Bundle; -import android.view.LayoutInflater; -import android.view.ViewGroup; - -import com.android.settings.testutils.SettingsRobolectricTestRunner; -import com.android.settings.testutils.shadow.ShadowZoneGetter; -import com.android.settingslib.core.instrumentation.VisibilityLoggerMixin; - -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; - -@RunWith(SettingsRobolectricTestRunner.class) -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( - nullable(LayoutInflater.class), - nullable(ViewGroup.class), - nullable(Bundle.class)); - } -}