ZoneItemAdapter.java
6.96 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
package com.sw.laryngoscope.adapter;
import android.annotation.SuppressLint;
import android.content.Context;
import android.icu.text.TimeZoneNames;
import android.text.BidiFormatter;
import android.text.TextDirectionHeuristics;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.TextView;
import com.sw.laryngoscope.R;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Locale;
import java.util.TimeZone;
import static com.sw.laryngoscope.common.InitParam.ZONE_COUNTRYNAME;
import static com.sw.laryngoscope.common.InitParam.ZONE_ID;
public class ZoneItemAdapter extends BaseAdapter {
private String TAG = getClass().getSimpleName();
private LayoutInflater mInflater;
private OnClickListener mlisten;
private List<HashMap<String, Object>> beans;
// 定义Context
private Context mContext;
public ZoneItemAdapter(Context c, List<HashMap<String, Object>> paramArrayList) {
mContext = c.getApplicationContext();
mInflater = LayoutInflater.from(c);
this.beans = paramArrayList;
}
public void setBeans(List<HashMap<String, Object>> beans) {
this.beans = beans;
}
/*public void setItemStatus(int item[]) {
beans = item;
}*/
/*public void setIsUpdate(int id, boolean param) {
isUpdate[id] = param;
}*/
public int getCount() {
/*Log.d(TAG, "==================" + mImageIds.length);*/
return beans.size();
}
public Object getItem(int position) {
return position;
}
public long getItemId(int position) {
return position;
}
public void setUpdateListener(OnClickListener listen) {
mlisten = listen;
}
@SuppressLint("ResourceAsColor")
public View getView(final int position, View convertView, ViewGroup parent) {
ViewHolder holder = null;
if ( convertView == null ) {
holder = new ViewHolder();
convertView = mInflater.inflate(R.layout.item_lan_choose, null);
//设置宽度和高度
ListView.LayoutParams params = new ListView.LayoutParams(ListView.LayoutParams.MATCH_PARENT, 68);
convertView.setLayoutParams(params);
holder.layout_lan_item = (LinearLayout)convertView.findViewById(R.id.layout_lan_item);
holder.item_lan = (TextView)convertView.findViewById(R.id.item_lan);
convertView.setTag(holder);
} else {
holder = (ViewHolder)convertView.getTag();
}
HashMap<String, Object> bean = this.beans.get(position);
//holder.item_lan.setText( bean.get(ZONE_COUNTRYNAME) + "");
final Locale locale = Locale.getDefault();
final Date now = new Date();
TimeZone tz = TimeZone.getTimeZone((String)bean.get(ZONE_ID));
String displayName = getZoneDisplayName(locale, tz, now, false);
holder.item_lan.setText( displayName + "");
//holder.item_lan.setText( TimeZone.getTimeZone( (String)bean.get(ZONE_ID) ).getDisplayName() + "");
if ( !TimeZone.getDefault().getID().equals(
TimeZone.getTimeZone( (String)bean.get(ZONE_ID) ).getID() ) ) {
holder.layout_lan_item.setBackgroundResource(R.drawable.bg_line_back_0);
/*holder.lay_userlist.setBackgroundColor(
mContext.getResources().getColor(R.color.color_white));*/
holder.item_lan.setTextColor(
mContext.getResources().getColor(R.color.color_white));
holder.item_lan.setTextSize(mContext.getResources().getDimension(R.dimen.text_size_24));
} else {
holder.layout_lan_item.setBackgroundResource(R.drawable.bg_line_back_1);
holder.item_lan.setTextColor(
mContext.getResources().getColor(R.color.color_0aede0));
holder.item_lan.setTextSize(mContext.getResources().getDimension(R.dimen.text_size_28));
}
return convertView;
}
public final class ViewHolder {
public LinearLayout layout_lan_item;
public TextView item_lan;
}
public interface OnClickListener {
void onClickEvent(int id);
}
private String getZoneDisplayName(Locale locale, TimeZone tz, Date now,
boolean preferLongName) {
String zoneNameString;
if (preferLongName) {
zoneNameString = getZoneLongName(locale, tz, now);
} else {
zoneNameString = getZoneExemplarLocation(locale, tz);
if (zoneNameString == null || zoneNameString.isEmpty()) {
// getZoneExemplarLocation can return null.
zoneNameString = getZoneLongName(locale, tz, now);
}
}
return zoneNameString;
}
private String getZoneExemplarLocation(Locale locale, TimeZone tz) {
final TimeZoneNames timeZoneNames = TimeZoneNames.getInstance(locale);
return timeZoneNames.getExemplarLocationName(/*locale.toString(), */tz.getID());
}
private String getZoneLongName(Locale locale, TimeZone tz, Date now) {
boolean daylight = tz.inDaylightTime(now);
// This returns a name if it can, or will fall back to GMT+0X:00 format.
return tz.getDisplayName(daylight, TimeZone.LONG, locale);
}
/*public static String getTimeZoneOffsetAndName(TimeZone tz, Date now) {
Locale locale = Locale.getDefault();
String gmtString = getGmtOffsetString(locale, tz, now);
String zoneNameString = getZoneLongName(locale, tz, now);
if (zoneNameString == null) {
return gmtString;
}
// We don't use punctuation here to avoid having to worry about localizing that too!
return gmtString + " " + zoneNameString;
}
private static String getZoneLongName(Locale locale, TimeZone tz, Date now) {
boolean daylight = tz.inDaylightTime(now);
// This returns a name if it can, or will fall back to GMT+0X:00 format.
return tz.getDisplayName(daylight, TimeZone.LONG, locale);
}
private static String getGmtOffsetString(Locale locale, TimeZone tz, Date now) {
// Use SimpleDateFormat to format the GMT+00:00 string.
SimpleDateFormat gmtFormatter = new SimpleDateFormat("ZZZZ");
gmtFormatter.setTimeZone(tz);
String gmtString = gmtFormatter.format(now);
// Ensure that the "GMT+" stays with the "00:00" even if the digits are RTL.
BidiFormatter bidiFormatter = BidiFormatter.getInstance();
boolean isRtl = TextUtils.getLayoutDirectionFromLocale(locale) == View.LAYOUT_DIRECTION_RTL;
gmtString = bidiFormatter.unicodeWrap(gmtString,
isRtl ? TextDirectionHeuristics.RTL : TextDirectionHeuristics.LTR);
return gmtString;
}
public static String getTimeZoneText(TimeZone tz, boolean includeName) {
Date now = new Date();
SimpleDateFormat gmtFormatter = new SimpleDateFormat("ZZZZ");
gmtFormatter.setTimeZone(tz);
String gmtString = gmtFormatter.format(now);
BidiFormatter bidiFormatter = BidiFormatter.getInstance();
Locale l = Locale.getDefault();
boolean isRtl = TextUtils.getLayoutDirectionFromLocale(l) == View.LAYOUT_DIRECTION_RTL;
gmtString = bidiFormatter.unicodeWrap(gmtString,
isRtl ? TextDirectionHeuristics.RTL : TextDirectionHeuristics.LTR);
if (!includeName) {
return gmtString;
}
return gmtString;
}*/
}