am 68cf75c5: Merge "Per "designer" request:" into jb-mr2-dev
* commit '68cf75c58ecc3fbf3a24189443490608efcc9caf':
Per "designer" request:
diff --git a/res/layout/time_zone_item.xml b/res/layout/time_zone_item.xml
index 4007bbb..fe27fc3 100644
--- a/res/layout/time_zone_item.xml
+++ b/res/layout/time_zone_item.xml
@@ -26,21 +26,6 @@
android:paddingRight="20dp" >
<TextView
- android:id="@+id/label"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_gravity="center_vertical"
- android:layout_marginBottom="0dp"
- android:layout_marginTop="0dp"
- android:ellipsize="marquee"
- android:gravity="center_vertical"
- android:minHeight="32dp"
- android:padding="0dp"
- android:singleLine="true"
- android:textAppearance="?android:attr/textAppearanceSmall"
- android:textStyle="bold" />
-
- <TextView
android:id="@+id/time_zone"
style="@style/font_family_thin"
android:layout_width="wrap_content"
diff --git a/res/layout/timezonepickerview.xml b/res/layout/timezonepickerview.xml
index 5dcb2be..7597eee 100644
--- a/res/layout/timezonepickerview.xml
+++ b/res/layout/timezonepickerview.xml
@@ -67,24 +67,4 @@
android:background="#FFECECEC"
android:choiceMode="singleChoice" >
</ListView>
-
- <View
- android:layout_width="match_parent"
- android:layout_height="1dp"
- android:background="?android:attr/listDivider"
- tools:ignore="PxUsage" />
-
- <TextView
- style="@style/font_family_thin"
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:background="#FFECECEC"
- android:ellipsize="marquee"
- android:paddingBottom="8dp"
- android:paddingLeft="16dp"
- android:paddingRight="16dp"
- android:paddingTop="8dp"
- android:text="@string/dst_note"
- android:textAppearance="?android:attr/textAppearanceSmall" />
-
</LinearLayout>
\ No newline at end of file
diff --git a/res/values-v16/strings.xml b/res/values-v16/strings.xml
deleted file mode 100644
index 1c16be9..0000000
--- a/res/values-v16/strings.xml
+++ /dev/null
@@ -1,21 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<!--
- Copyright (C) 2013 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.
--->
-<resources xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
- <!-- Legend for the * symbol to mean that the time zone has
- a future day light savings time [CHAR LIMIT=30] -->
- <string name="dst_note">\u2600 Observes daylight saving time</string>
-</resources>
\ No newline at end of file
diff --git a/res/values/strings.xml b/res/values/strings.xml
index 395458a..ce71469 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -20,22 +20,9 @@
[CHAR LIMIT=25] -->
<string name="hint_time_zone_search">Country</string>
- <!-- Label for the currently selected time zone [CHAR LIMIT=30] -->
- <string name="current_time_zone">CURRENT TIME ZONE</string>
-
- <!-- Label for the recently selected time zones [CHAR LIMIT=30] -->
- <plurals name="recent_time_zone">
- <item quantity="one">RECENT TIME ZONE</item>
- <!-- This is the label for 2 or more time zones. -->
- <item quantity="other">RECENT TIME ZONES</item>
- </plurals>
-
<!-- Label for a list of time zones searched by country name [CHAR LIMIT=30] -->
<string name="country">Country</string>
- <!-- Label for a list of time zones searched by time zone name [CHAR LIMIT=30] -->
- <string name="time_zone">Time zones</string>
-
<!-- Label for a list of time zones searched by GMT Offset [CHAR LIMIT=30] -->
<string name="gmt_offset">GMT offset</string>
@@ -51,10 +38,6 @@
<!-- Label for a list of time zones in a certain hour of the day [CHAR LIMIT=25] -->
<string name="results_local_type">"TIME ZONES AT <xliff:g id="local_time">%s</xliff:g>"</string>
- <!-- Legend for the * symbol to mean that the time zone has
- a future day light savings time [CHAR LIMIT=30] -->
- <string name="dst_note">\u002A Observes daylight saving time</string>
-
<!-- Description of clear icon in the search bar, for accessibility. [CHAR LIMIT=NONE]-->
<string name="searchview_description_clear">Clear query</string>
</resources>
\ No newline at end of file
diff --git a/src/com/android/timezonepicker/TimeZoneFilterTypeAdapter.java b/src/com/android/timezonepicker/TimeZoneFilterTypeAdapter.java
index cadd4f2..c08f073 100644
--- a/src/com/android/timezonepicker/TimeZoneFilterTypeAdapter.java
+++ b/src/com/android/timezonepicker/TimeZoneFilterTypeAdapter.java
@@ -36,10 +36,9 @@
public static final int FILTER_TYPE_EMPTY = -1;
public static final int FILTER_TYPE_NONE = 0;
public static final int FILTER_TYPE_TIME = 1;
- public static final int FILTER_TYPE_TIME_ZONE = 2;
- public static final int FILTER_TYPE_COUNTRY = 3;
- public static final int FILTER_TYPE_STATE = 4;
- public static final int FILTER_TYPE_GMT = 5;
+ public static final int FILTER_TYPE_COUNTRY = 2;
+ public static final int FILTER_TYPE_STATE = 3;
+ public static final int FILTER_TYPE_GMT = 4;
public interface OnSetFilterListener {
void onSetFilter(int filterType, String str, int time);
@@ -153,9 +152,6 @@
case FILTER_TYPE_TIME:
resId = R.string.local_time;
break;
- case FILTER_TYPE_TIME_ZONE:
- resId = R.string.time_zone;
- break;
case FILTER_TYPE_COUNTRY:
resId = R.string.country;
break;
diff --git a/src/com/android/timezonepicker/TimeZoneInfo.java b/src/com/android/timezonepicker/TimeZoneInfo.java
index c8d6eed..d16c5cb 100644
--- a/src/com/android/timezonepicker/TimeZoneInfo.java
+++ b/src/com/android/timezonepicker/TimeZoneInfo.java
@@ -17,8 +17,11 @@
package com.android.timezonepicker;
import android.content.Context;
+import android.text.Spannable;
+import android.text.Spannable.Factory;
import android.text.format.DateUtils;
import android.text.format.Time;
+import android.text.style.ForegroundColorSpan;
import android.util.Log;
import android.util.SparseArray;
@@ -31,11 +34,13 @@
import java.util.TimeZone;
public class TimeZoneInfo implements Comparable<TimeZoneInfo> {
+ private static final int DST_SYMBOL_COLOR = 0xFF606060;
private static final char SEPARATOR = ',';
private static final String TAG = null;
public static int NUM_OF_TRANSITIONS = 6;
public static long time = System.currentTimeMillis() / 1000;
public static boolean is24HourFormat;
+ private static final Factory mSpannableFactory = Spannable.Factory.getInstance();
TimeZone mTz;
public String mTzId;
@@ -43,7 +48,6 @@
public int[] mTransitions; // may have trailing 0's.
public String mCountry;
public int groupId;
- private boolean hasDst;
public String mDisplayName;
private Time recycledTime = new Time();
private static StringBuilder mSB = new StringBuilder(50);
@@ -54,7 +58,6 @@
mTzId = tz.getID();
mCountry = country;
mRawoffset = tz.getRawOffset();
- hasDst = tz.useDaylightTime();
try {
mTransitions = getTransitions(tz, time);
@@ -67,7 +70,8 @@
SparseArray<String> mLocalTimeCache = new SparseArray<String>();
long mLocalTimeCacheReferenceTime = 0;
static private long mGmtDisplayNameUpdateTime;
- static private SparseArray<String> mGmtDisplayNameCache = new SparseArray<String>();
+ static private SparseArray<CharSequence> mGmtDisplayNameCache =
+ new SparseArray<CharSequence>();
public String getLocalTime(long referenceTime) {
recycledTime.timezone = TimeZone.getDefault().getID();
@@ -125,7 +129,7 @@
* mFormatter, per instance. If there are multiple callers for
* getGmtDisplayName, the output may be mangled.
*/
- public synchronized String getGmtDisplayName(Context context) {
+ public synchronized CharSequence getGmtDisplayName(Context context) {
// TODO Note: The local time is shown in current time (current GMT
// offset) which may be different from the time specified by
// mTimeMillis
@@ -142,7 +146,7 @@
cacheKey = (int) (gmtOffset - 36 * DateUtils.HOUR_IN_MILLIS);
}
- String displayName = null;
+ CharSequence displayName = null;
if (mGmtDisplayNameUpdateTime != nowMinute) {
mGmtDisplayNameUpdateTime = nowMinute;
mGmtDisplayNameCache.clear();
@@ -160,34 +164,22 @@
// mFormatter writes to mSB
DateUtils.formatDateRange(context, mFormatter, now, now, flags, mTzId);
- mSB.append(" (GMT");
-
- if (gmtOffset < 0) {
- mSB.append('-');
- } else {
- mSB.append('+');
- }
-
- final int p = Math.abs(gmtOffset);
- mSB.append(p / DateUtils.HOUR_IN_MILLIS); // Hour
-
- final int min = (p / 60000) % 60;
- if (min != 0) { // Show minutes if non-zero
- mSB.append(':');
- if (min < 10) {
- mSB.append('0');
- }
- mSB.append(min);
- }
- mSB.append(')');
+ mSB.append(' ');
+ TimeZonePickerUtils.appendGmtOffset(mSB, gmtOffset);
if (hasFutureDST) {
- String dstSymbol = TimeZonePickerUtils.getDstSymbol();
- mSB.append(" ");
- mSB.append(dstSymbol); // Sun symbol
- }
+ mSB.append(' ');
+ mSB.append(TimeZonePickerUtils.getDstSymbol()); // Sun symbol
- displayName = mSB.toString();
+ final int end = mSB.length();
+ final int start = end - 1;
+ Spannable spannableText = mSpannableFactory.newSpannable(mSB);
+ spannableText.setSpan(new ForegroundColorSpan(DST_SYMBOL_COLOR), start, end,
+ Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
+ displayName = spannableText;
+ } else {
+ displayName = mSB.toString();
+ }
mGmtDisplayNameCache.put(cacheKey, displayName);
}
return displayName;
diff --git a/src/com/android/timezonepicker/TimeZonePickerUtils.java b/src/com/android/timezonepicker/TimeZonePickerUtils.java
index 92d8083..783fcb9 100644
--- a/src/com/android/timezonepicker/TimeZonePickerUtils.java
+++ b/src/com/android/timezonepicker/TimeZonePickerUtils.java
@@ -75,9 +75,23 @@
time.set(timeMillis);
StringBuilder sb = new StringBuilder();
+ final int gmtOffset = tz.getOffset(timeMillis);
+ appendGmtOffset(sb, gmtOffset);
+
+ String displayName = getDisplayName(tz, time.isDst != 0);
+ sb.append(" ");
+ sb.append(displayName);
+
+ if (tz.useDaylightTime()) {
+ sb.append(" ");
+ sb.append(getDstSymbol()); // Sun symbol
+ }
+ return sb.toString();
+ }
+
+ public static void appendGmtOffset(StringBuilder sb, final int gmtOffset) {
sb.append("(GMT");
- final int gmtOffset = tz.getOffset(timeMillis);
if (gmtOffset < 0) {
sb.append('-');
} else {
@@ -95,24 +109,14 @@
}
sb.append(min);
}
- sb.append(") ");
-
- String displayName = getDisplayName(tz, time.isDst != 0);
- sb.append(displayName);
-
- if (tz.useDaylightTime()) {
- String dstSymbol = getDstSymbol();
- sb.append(" ");
- sb.append(dstSymbol); // Sun symbol
- }
- return sb.toString();
+ sb.append(')');
}
- public static String getDstSymbol() {
+ public static char getDstSymbol() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
- return "\u2600"; // The Sun emoji icon.
+ return '\u2600'; // The Sun emoji icon.
} else {
- return "*";
+ return '*';
}
}
diff --git a/src/com/android/timezonepicker/TimeZoneResultAdapter.java b/src/com/android/timezonepicker/TimeZoneResultAdapter.java
index 7e9744b..151ba8a 100644
--- a/src/com/android/timezonepicker/TimeZoneResultAdapter.java
+++ b/src/com/android/timezonepicker/TimeZoneResultAdapter.java
@@ -32,9 +32,7 @@
import com.android.timezonepicker.TimeZonePickerView.OnTimeZoneSetListener;
import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Iterator;
-import java.util.List;
+import java.util.LinkedHashSet;
public class TimeZoneResultAdapter extends BaseAdapter implements OnItemClickListener,
OnSetFilterListener {
@@ -54,21 +52,16 @@
/** The maximum number of recent timezones to save */
private static final int MAX_RECENT_TIMEZONES = 3;
- private static final int RESULT_LABEL_RECENT = -100;
- private static final int RESULT_LABEL_CURRENT = -200;
-
static class ViewHolder {
TextView timeZone;
TextView timeOffset;
TextView location;
- TextView label;
static void setupViewHolder(View v) {
ViewHolder vh = new ViewHolder();
vh.timeZone = (TextView) v.findViewById(R.id.time_zone);
vh.timeOffset = (TextView) v.findViewById(R.id.time_offset);
vh.location = (TextView) v.findViewById(R.id.location);
- vh.label = (TextView) v.findViewById(R.id.label);
v.setTag(vh);
}
}
@@ -81,7 +74,6 @@
private int[] mFilteredTimeZoneIndices;
private int mFilteredTimeZoneLength = 0;
- private int mFilterType;
public TimeZoneResultAdapter(Context context, TimeZoneData tzd,
com.android.timezonepicker.TimeZonePickerView.OnTimeZoneSetListener l) {
@@ -103,7 +95,6 @@
public void onSetFilter(int filterType, String str, int time) {
Log.d(TAG, "onSetFilter: " + filterType + " [" + str + "] " + time);
- mFilterType = filterType;
mFilteredTimeZoneLength = 0;
int idx = 0;
@@ -114,7 +105,6 @@
// Show the default/current value first
int defaultTzIndex = mTimeZoneData.getDefaultTimeZoneIndex();
if (defaultTzIndex != -1) {
- mFilteredTimeZoneIndices[mFilteredTimeZoneLength++] = RESULT_LABEL_CURRENT;
mFilteredTimeZoneIndices[mFilteredTimeZoneLength++] = defaultTzIndex;
}
@@ -124,17 +114,11 @@
String recentsString = prefs.getString(KEY_RECENT_TIMEZONES, null);
if (!TextUtils.isEmpty(recentsString)) {
String[] recents = recentsString.split(RECENT_TIMEZONES_DELIMITER);
- boolean first = true;
for (int i = recents.length - 1; i >= 0; i--) {
if (!TextUtils.isEmpty(recents[i])
&& !recents[i].equals(mTimeZoneData.mDefaultTimeZoneId)) {
int index = mTimeZoneData.findIndexByTimeZoneIdSlow(recents[i]);
if (index != -1) {
- if (first) {
- mFilteredTimeZoneIndices[mFilteredTimeZoneLength++] =
- RESULT_LABEL_RECENT;
- first = false;
- }
mFilteredTimeZoneIndices[mFilteredTimeZoneLength++] = index;
}
}
@@ -168,16 +152,6 @@
idx++;
}
break;
- case TimeZoneFilterTypeAdapter.FILTER_TYPE_TIME_ZONE:
- if (str != null) {
- for (TimeZoneInfo tzi : mTimeZoneData.mTimeZones) {
- if (str.equalsIgnoreCase(tzi.mDisplayName)) {
- mFilteredTimeZoneIndices[mFilteredTimeZoneLength++] = idx;
- }
- idx++;
- }
- }
- break;
case TimeZoneFilterTypeAdapter.FILTER_TYPE_COUNTRY:
ArrayList<Integer> tzIds = mTimeZoneData.mTimeZonesByCountry.get(str);
if (tzIds != null) {
@@ -210,13 +184,11 @@
if (recentsString == null) {
recentsString = id;
} else {
- List<String> recents = new ArrayList<String>(
- Arrays.asList(recentsString.split(RECENT_TIMEZONES_DELIMITER)));
- Iterator<String> it = recents.iterator();
- while (it.hasNext()) {
- String tz = it.next();
- if (id.equals(tz)) {
- it.remove();
+ // De-dup
+ LinkedHashSet<String> recents = new LinkedHashSet<String>();
+ for(String tzId : recentsString.split(RECENT_TIMEZONES_DELIMITER)) {
+ if (!recents.contains(tzId) && !id.equals(tzId)) {
+ recents.add(tzId);
}
}
@@ -252,13 +224,6 @@
return null;
}
- switch (mFilteredTimeZoneIndices[position]) {
- case RESULT_LABEL_CURRENT:
- return "CURRENT TIME ZONE";
- case RESULT_LABEL_RECENT:
- return "RECENT TIME ZONE";
- }
-
return mTimeZoneData.get(mFilteredTimeZoneIndices[position]);
}
@@ -288,36 +253,19 @@
ViewHolder vh = (ViewHolder) v.getTag();
- if (mFilteredTimeZoneIndices[position] >= 0) {
- TimeZoneInfo tzi = mTimeZoneData.get(mFilteredTimeZoneIndices[position]);
- v.setTag(VIEW_TAG_TIME_ZONE, tzi);
+ TimeZoneInfo tzi = mTimeZoneData.get(mFilteredTimeZoneIndices[position]);
+ v.setTag(VIEW_TAG_TIME_ZONE, tzi);
- vh.label.setVisibility(View.GONE);
- vh.timeZone.setText(tzi.mDisplayName);
- vh.timeZone.setVisibility(View.VISIBLE);
+ vh.timeZone.setText(tzi.mDisplayName);
- vh.timeOffset.setText(tzi.getGmtDisplayName(mContext));
- vh.timeOffset.setVisibility(View.VISIBLE);
+ vh.timeOffset.setText(tzi.getGmtDisplayName(mContext));
- String location = tzi.mCountry;
- if (location == null) {
- vh.location.setVisibility(View.INVISIBLE);
- } else {
- vh.location.setText(location);
- vh.location.setVisibility(View.VISIBLE);
- }
+ String location = tzi.mCountry;
+ if (location == null) {
+ vh.location.setVisibility(View.INVISIBLE);
} else {
- if (mFilteredTimeZoneIndices[position] == RESULT_LABEL_CURRENT) {
- vh.label.setText(v.getResources().getText(R.string.current_time_zone));
- } else if (mFilteredTimeZoneIndices[position] == RESULT_LABEL_RECENT) {
- vh.label.setText(v.getResources().getQuantityText(R.plurals.recent_time_zone,
- /* num of recent tzs */ mFilteredTimeZoneLength - position - 1));
- }
- vh.label.setVisibility(View.VISIBLE);
- vh.timeZone.setVisibility(View.GONE);
- vh.timeOffset.setVisibility(View.GONE);
- vh.location.setVisibility(View.GONE);
- v.setTag(VIEW_TAG_TIME_ZONE, null);
+ vh.location.setText(location);
+ vh.location.setVisibility(View.VISIBLE);
}
return v;