26 | * 27 | * @author lp 28 | * @date 2018/5/16 29 | */ 30 | public abstract class BaseActivity
extends AppCompatActivity implements BaseView {
31 | public Activity mContext;
32 | protected P mPresenter;
33 |
34 | protected abstract P createPresenter();
35 |
36 | @Override
37 | protected void onCreate(Bundle savedInstanceState) {
38 | super.onCreate(savedInstanceState);
39 | mContext = this;
40 | setContentView(getLayoutId());
41 | mPresenter = createPresenter();
42 | ButterKnife.bind(this);
43 | this.initData();
44 | }
45 |
46 | /**
47 | * 获取布局ID
48 | *
49 | * @return
50 | */
51 | protected abstract int getLayoutId();
52 |
53 | /**
54 | * 数据初始化操作
55 | */
56 | protected abstract void initData();
57 |
58 |
59 | @Override
60 | public void showError(String msg) {
61 | }
62 |
63 | @Override
64 | public void onErrorCode(BaseModel model) {
65 | }
66 |
67 | @Override
68 | public void showLoading() {
69 | }
70 |
71 | @Override
72 | public void hideLoading() {
73 | }
74 |
75 | @Override
76 | protected void onDestroy() {
77 | super.onDestroy();
78 | ButterKnife.bind(this).unbind();
79 | if (mPresenter != null) {
80 | mPresenter.detachView();
81 | }
82 | }
83 |
84 | /**
85 | * [页面跳转]
86 | *
87 | * @param clz
88 | */
89 | public void startActivity(Class> clz) {
90 | startActivity(clz, null);
91 | }
92 |
93 |
94 | /**
95 | * [携带数据的页面跳转]
96 | *
97 | * @param clz
98 | * @param bundle
99 | */
100 | public void startActivity(Class> clz, Bundle bundle) {
101 | Intent intent = new Intent();
102 | intent.setClass(this, clz);
103 | if (bundle != null) {
104 | intent.putExtras(bundle);
105 | }
106 | startActivity(intent);
107 | }
108 | }
109 |
--------------------------------------------------------------------------------
/app/src/main/java/com/lp/sidebar_master/activity/Country2Activity.java:
--------------------------------------------------------------------------------
1 | package com.lp.sidebar_master.activity;
2 |
3 | import android.widget.ListView;
4 | import android.widget.TextView;
5 |
6 | import com.lp.sidebar_master.R;
7 | import com.lp.sidebar_master.adapter.CountryLvAdapter;
8 | import com.lp.sidebar_master.base.BaseActivity;
9 | import com.lp.sidebar_master.base.mvp.BaseModel;
10 | import com.lp.sidebar_master.presenter.CountryBean;
11 | import com.lp.sidebar_master.presenter.CountryPresenter;
12 | import com.lp.sidebar_master.presenter.CountryView;
13 | import com.lp.sidebar_master.utils.PinYinKit;
14 | import com.lp.sidebar_master.widget.WaveSideBar;
15 |
16 | import net.sourceforge.pinyin4j.format.exception.BadHanyuPinyinOutputFormatCombination;
17 |
18 | import java.util.ArrayList;
19 | import java.util.List;
20 |
21 | import butterknife.BindView;
22 |
23 |
24 | /**
25 | * File descripition: 侧滑栏拼音全部显示,有动态效果
26 | *
27 | * @author lp
28 | * @date 2018/8/4
29 | */
30 |
31 | public class Country2Activity extends BaseActivity
36 | * Email: chjie.jaeger@gmail.com
37 | * GitHub: https://github.com/laobie
38 | */
39 | public class StatusBarUtil {
40 | public static final int DEFAULT_STATUS_BAR_ALPHA = 112;
41 | private static final int FAKE_STATUS_BAR_VIEW_ID = R.id.statusbarutil_fake_status_bar_view;
42 | private static final int FAKE_TRANSLUCENT_VIEW_ID = R.id.statusbarutil_translucent_view;
43 | private static final int TAG_KEY_HAVE_SET_OFFSET = -123;
44 |
45 | /**
46 | * 设置状态栏颜色
47 | *
48 | * @param activity 需要设置的 activity
49 | * @param color 状态栏颜色值
50 | */
51 | public static void setColor(Activity activity, @ColorInt int color) {
52 | setColor(activity, color, DEFAULT_STATUS_BAR_ALPHA);
53 | }
54 |
55 | /**
56 | * 设置状态栏颜色
57 | *
58 | * @param activity 需要设置的activity
59 | * @param color 状态栏颜色值
60 | * @param statusBarAlpha 状态栏透明度
61 | */
62 |
63 | public static void setColor(Activity activity, @ColorInt int color, @IntRange(from = 0, to = 255) int statusBarAlpha) {
64 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
65 | activity.getWindow().addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
66 | activity.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
67 | activity.getWindow().setStatusBarColor(calculateStatusColor(color, statusBarAlpha));
68 | } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
69 | activity.getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
70 | ViewGroup decorView = (ViewGroup) activity.getWindow().getDecorView();
71 | View fakeStatusBarView = decorView.findViewById(FAKE_STATUS_BAR_VIEW_ID);
72 | if (fakeStatusBarView != null) {
73 | if (fakeStatusBarView.getVisibility() == View.GONE) {
74 | fakeStatusBarView.setVisibility(View.VISIBLE);
75 | }
76 | fakeStatusBarView.setBackgroundColor(calculateStatusColor(color, statusBarAlpha));
77 | } else {
78 | decorView.addView(createStatusBarView(activity, color, statusBarAlpha));
79 | }
80 | setRootView(activity);
81 | }
82 | }
83 |
84 | /**
85 | * 为滑动返回界面设置状态栏颜色
86 | *
87 | * @param activity 需要设置的activity
88 | * @param color 状态栏颜色值
89 | */
90 | public static void setColorForSwipeBack(Activity activity, int color) {
91 | setColorForSwipeBack(activity, color, DEFAULT_STATUS_BAR_ALPHA);
92 | }
93 |
94 | /**
95 | * 为滑动返回界面设置状态栏颜色
96 | *
97 | * @param activity 需要设置的activity
98 | * @param color 状态栏颜色值
99 | * @param statusBarAlpha 状态栏透明度
100 | */
101 | public static void setColorForSwipeBack(Activity activity, @ColorInt int color,
102 | @IntRange(from = 0, to = 255) int statusBarAlpha) {
103 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
104 |
105 | ViewGroup contentView = ((ViewGroup) activity.findViewById(android.R.id.content));
106 | View rootView = contentView.getChildAt(0);
107 | int statusBarHeight = getStatusBarHeight(activity);
108 | if (rootView != null && rootView instanceof CoordinatorLayout) {
109 | final CoordinatorLayout coordinatorLayout = (CoordinatorLayout) rootView;
110 | if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
111 | coordinatorLayout.setFitsSystemWindows(false);
112 | contentView.setBackgroundColor(calculateStatusColor(color, statusBarAlpha));
113 | boolean isNeedRequestLayout = contentView.getPaddingTop() < statusBarHeight;
114 | if (isNeedRequestLayout) {
115 | contentView.setPadding(0, statusBarHeight, 0, 0);
116 | coordinatorLayout.post(new Runnable() {
117 | @Override
118 | public void run() {
119 | coordinatorLayout.requestLayout();
120 | }
121 | });
122 | }
123 | } else {
124 | coordinatorLayout.setStatusBarBackgroundColor(calculateStatusColor(color, statusBarAlpha));
125 | }
126 | } else {
127 | contentView.setPadding(0, statusBarHeight, 0, 0);
128 | contentView.setBackgroundColor(calculateStatusColor(color, statusBarAlpha));
129 | }
130 | setTransparentForWindow(activity);
131 | }
132 | }
133 |
134 | /**
135 | * 设置状态栏纯色 不加半透明效果
136 | *
137 | * @param activity 需要设置的 activity
138 | * @param color 状态栏颜色值
139 | */
140 | public static void setColorNoTranslucent(Activity activity, @ColorInt int color) {
141 | setColor(activity, color, 0);
142 | }
143 |
144 | /**
145 | * 设置状态栏颜色(5.0以下无半透明效果,不建议使用)
146 | *
147 | * @param activity 需要设置的 activity
148 | * @param color 状态栏颜色值
149 | */
150 | @Deprecated
151 | public static void setColorDiff(Activity activity, @ColorInt int color) {
152 | if (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT) {
153 | return;
154 | }
155 | transparentStatusBar(activity);
156 | ViewGroup contentView = (ViewGroup) activity.findViewById(android.R.id.content);
157 | // 移除半透明矩形,以免叠加
158 | View fakeStatusBarView = contentView.findViewById(FAKE_STATUS_BAR_VIEW_ID);
159 | if (fakeStatusBarView != null) {
160 | if (fakeStatusBarView.getVisibility() == View.GONE) {
161 | fakeStatusBarView.setVisibility(View.VISIBLE);
162 | }
163 | fakeStatusBarView.setBackgroundColor(color);
164 | } else {
165 | contentView.addView(createStatusBarView(activity, color));
166 | }
167 | setRootView(activity);
168 | }
169 |
170 | /**
171 | * 使状态栏半透明
172 | *
173 | * 适用于图片作为背景的界面,此时需要图片填充到状态栏
174 | *
175 | * @param activity 需要设置的activity
176 | */
177 | public static void setTranslucent(Activity activity) {
178 | setTranslucent(activity, DEFAULT_STATUS_BAR_ALPHA);
179 | }
180 |
181 | /**
182 | * 使状态栏半透明
183 | *
184 | * 适用于图片作为背景的界面,此时需要图片填充到状态栏
185 | *
186 | * @param activity 需要设置的activity
187 | * @param statusBarAlpha 状态栏透明度
188 | */
189 | public static void setTranslucent(Activity activity, @IntRange(from = 0, to = 255) int statusBarAlpha) {
190 | if (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT) {
191 | return;
192 | }
193 | setTransparent(activity);
194 | addTranslucentView(activity, statusBarAlpha);
195 | }
196 |
197 | /**
198 | * 针对根布局是 CoordinatorLayout, 使状态栏半透明
199 | *
200 | * 适用于图片作为背景的界面,此时需要图片填充到状态栏
201 | *
202 | * @param activity 需要设置的activity
203 | * @param statusBarAlpha 状态栏透明度
204 | */
205 | public static void setTranslucentForCoordinatorLayout(Activity activity, @IntRange(from = 0, to = 255) int statusBarAlpha) {
206 | if (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT) {
207 | return;
208 | }
209 | transparentStatusBar(activity);
210 | addTranslucentView(activity, statusBarAlpha);
211 | }
212 |
213 | /**
214 | * 设置状态栏全透明
215 | *
216 | * @param activity 需要设置的activity
217 | */
218 | public static void setTransparent(Activity activity) {
219 | if (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT) {
220 | return;
221 | }
222 | transparentStatusBar(activity);
223 | setRootView(activity);
224 | }
225 |
226 | /**
227 | * 使状态栏透明(5.0以上半透明效果,不建议使用)
228 | *
229 | * 适用于图片作为背景的界面,此时需要图片填充到状态栏
230 | *
231 | * @param activity 需要设置的activity
232 | */
233 | @Deprecated
234 | public static void setTranslucentDiff(Activity activity) {
235 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
236 | // 设置状态栏透明
237 | activity.getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
238 | setRootView(activity);
239 | }
240 | }
241 |
242 | /**
243 | * 为DrawerLayout 布局设置状态栏变色
244 | *
245 | * @param activity 需要设置的activity
246 | * @param drawerLayout DrawerLayout
247 | * @param color 状态栏颜色值
248 | */
249 | public static void setColorForDrawerLayout(Activity activity, DrawerLayout drawerLayout, @ColorInt int color) {
250 | setColorForDrawerLayout(activity, drawerLayout, color, DEFAULT_STATUS_BAR_ALPHA);
251 | }
252 |
253 | /**
254 | * 为DrawerLayout 布局设置状态栏颜色,纯色
255 | *
256 | * @param activity 需要设置的activity
257 | * @param drawerLayout DrawerLayout
258 | * @param color 状态栏颜色值
259 | */
260 | public static void setColorNoTranslucentForDrawerLayout(Activity activity, DrawerLayout drawerLayout, @ColorInt int color) {
261 | setColorForDrawerLayout(activity, drawerLayout, color, 0);
262 | }
263 |
264 | /**
265 | * 为DrawerLayout 布局设置状态栏变色
266 | *
267 | * @param activity 需要设置的activity
268 | * @param drawerLayout DrawerLayout
269 | * @param color 状态栏颜色值
270 | * @param statusBarAlpha 状态栏透明度
271 | */
272 | public static void setColorForDrawerLayout(Activity activity, DrawerLayout drawerLayout, @ColorInt int color,
273 | @IntRange(from = 0, to = 255) int statusBarAlpha) {
274 | if (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT) {
275 | return;
276 | }
277 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
278 | activity.getWindow().addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
279 | activity.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
280 | activity.getWindow().setStatusBarColor(Color.TRANSPARENT);
281 | } else {
282 | activity.getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
283 | }
284 | // 生成一个状态栏大小的矩形
285 | // 添加 statusBarView 到布局中
286 | ViewGroup contentLayout = (ViewGroup) drawerLayout.getChildAt(0);
287 | View fakeStatusBarView = contentLayout.findViewById(FAKE_STATUS_BAR_VIEW_ID);
288 | if (fakeStatusBarView != null) {
289 | if (fakeStatusBarView.getVisibility() == View.GONE) {
290 | fakeStatusBarView.setVisibility(View.VISIBLE);
291 | }
292 | fakeStatusBarView.setBackgroundColor(color);
293 | } else {
294 | contentLayout.addView(createStatusBarView(activity, color), 0);
295 | }
296 | // 内容布局不是 LinearLayout 时,设置padding top
297 | if (!(contentLayout instanceof LinearLayout) && contentLayout.getChildAt(1) != null) {
298 | contentLayout.getChildAt(1)
299 | .setPadding(contentLayout.getPaddingLeft(), getStatusBarHeight(activity) + contentLayout.getPaddingTop(),
300 | contentLayout.getPaddingRight(), contentLayout.getPaddingBottom());
301 | }
302 | // 设置属性
303 | setDrawerLayoutProperty(drawerLayout, contentLayout);
304 | addTranslucentView(activity, statusBarAlpha);
305 | }
306 |
307 | /**
308 | * 设置 DrawerLayout 属性
309 | *
310 | * @param drawerLayout DrawerLayout
311 | * @param drawerLayoutContentLayout DrawerLayout 的内容布局
312 | */
313 | private static void setDrawerLayoutProperty(DrawerLayout drawerLayout, ViewGroup drawerLayoutContentLayout) {
314 | ViewGroup drawer = (ViewGroup) drawerLayout.getChildAt(1);
315 | drawerLayout.setFitsSystemWindows(false);
316 | drawerLayoutContentLayout.setFitsSystemWindows(false);
317 | drawerLayoutContentLayout.setClipToPadding(true);
318 | drawer.setFitsSystemWindows(false);
319 | }
320 |
321 | /**
322 | * 为DrawerLayout 布局设置状态栏变色(5.0以下无半透明效果,不建议使用)
323 | *
324 | * @param activity 需要设置的activity
325 | * @param drawerLayout DrawerLayout
326 | * @param color 状态栏颜色值
327 | */
328 | @Deprecated
329 | public static void setColorForDrawerLayoutDiff(Activity activity, DrawerLayout drawerLayout, @ColorInt int color) {
330 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
331 | activity.getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
332 | // 生成一个状态栏大小的矩形
333 | ViewGroup contentLayout = (ViewGroup) drawerLayout.getChildAt(0);
334 | View fakeStatusBarView = contentLayout.findViewById(FAKE_STATUS_BAR_VIEW_ID);
335 | if (fakeStatusBarView != null) {
336 | if (fakeStatusBarView.getVisibility() == View.GONE) {
337 | fakeStatusBarView.setVisibility(View.VISIBLE);
338 | }
339 | fakeStatusBarView.setBackgroundColor(calculateStatusColor(color, DEFAULT_STATUS_BAR_ALPHA));
340 | } else {
341 | // 添加 statusBarView 到布局中
342 | contentLayout.addView(createStatusBarView(activity, color), 0);
343 | }
344 | // 内容布局不是 LinearLayout 时,设置padding top
345 | if (!(contentLayout instanceof LinearLayout) && contentLayout.getChildAt(1) != null) {
346 | contentLayout.getChildAt(1).setPadding(0, getStatusBarHeight(activity), 0, 0);
347 | }
348 | // 设置属性
349 | setDrawerLayoutProperty(drawerLayout, contentLayout);
350 | }
351 | }
352 |
353 | /**
354 | * 为 DrawerLayout 布局设置状态栏透明
355 | *
356 | * @param activity 需要设置的activity
357 | * @param drawerLayout DrawerLayout
358 | */
359 | public static void setTranslucentForDrawerLayout(Activity activity, DrawerLayout drawerLayout) {
360 | setTranslucentForDrawerLayout(activity, drawerLayout, DEFAULT_STATUS_BAR_ALPHA);
361 | }
362 |
363 | /**
364 | * 为 DrawerLayout 布局设置状态栏透明
365 | *
366 | * @param activity 需要设置的activity
367 | * @param drawerLayout DrawerLayout
368 | */
369 | public static void setTranslucentForDrawerLayout(Activity activity, DrawerLayout drawerLayout,
370 | @IntRange(from = 0, to = 255) int statusBarAlpha) {
371 | if (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT) {
372 | return;
373 | }
374 | setTransparentForDrawerLayout(activity, drawerLayout);
375 | addTranslucentView(activity, statusBarAlpha);
376 | }
377 |
378 | /**
379 | * 为 DrawerLayout 布局设置状态栏透明
380 | *
381 | * @param activity 需要设置的activity
382 | * @param drawerLayout DrawerLayout
383 | */
384 | public static void setTransparentForDrawerLayout(Activity activity, DrawerLayout drawerLayout) {
385 | if (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT) {
386 | return;
387 | }
388 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
389 | activity.getWindow().addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
390 | activity.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
391 | activity.getWindow().setStatusBarColor(Color.TRANSPARENT);
392 | } else {
393 | activity.getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
394 | }
395 |
396 | ViewGroup contentLayout = (ViewGroup) drawerLayout.getChildAt(0);
397 | // 内容布局不是 LinearLayout 时,设置padding top
398 | if (!(contentLayout instanceof LinearLayout) && contentLayout.getChildAt(1) != null) {
399 | contentLayout.getChildAt(1).setPadding(0, getStatusBarHeight(activity), 0, 0);
400 | }
401 |
402 | // 设置属性
403 | setDrawerLayoutProperty(drawerLayout, contentLayout);
404 | }
405 |
406 | /**
407 | * 为 DrawerLayout 布局设置状态栏透明(5.0以上半透明效果,不建议使用)
408 | *
409 | * @param activity 需要设置的activity
410 | * @param drawerLayout DrawerLayout
411 | */
412 | @Deprecated
413 | public static void setTranslucentForDrawerLayoutDiff(Activity activity, DrawerLayout drawerLayout) {
414 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
415 | // 设置状态栏透明
416 | activity.getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
417 | // 设置内容布局属性
418 | ViewGroup contentLayout = (ViewGroup) drawerLayout.getChildAt(0);
419 | contentLayout.setFitsSystemWindows(true);
420 | contentLayout.setClipToPadding(true);
421 | // 设置抽屉布局属性
422 | ViewGroup vg = (ViewGroup) drawerLayout.getChildAt(1);
423 | vg.setFitsSystemWindows(false);
424 | // 设置 DrawerLayout 属性
425 | drawerLayout.setFitsSystemWindows(false);
426 | }
427 | }
428 |
429 | /**
430 | * 为头部是 ImageView 的界面设置状态栏全透明
431 | *
432 | * @param activity 需要设置的activity
433 | * @param needOffsetView 需要向下偏移的 View
434 | */
435 | public static void setTransparentForImageView(Activity activity, View needOffsetView) {
436 | setTranslucentForImageView(activity, 0, needOffsetView);
437 | }
438 |
439 | /**
440 | * 为头部是 ImageView 的界面设置状态栏透明(使用默认透明度)
441 | *
442 | * @param activity 需要设置的activity
443 | * @param needOffsetView 需要向下偏移的 View
444 | */
445 | public static void setTranslucentForImageView(Activity activity, View needOffsetView) {
446 | setTranslucentForImageView(activity, DEFAULT_STATUS_BAR_ALPHA, needOffsetView);
447 | }
448 |
449 | /**
450 | * 为头部是 ImageView 的界面设置状态栏透明
451 | *
452 | * @param activity 需要设置的activity
453 | * @param statusBarAlpha 状态栏透明度
454 | * @param needOffsetView 需要向下偏移的 View
455 | */
456 | public static void setTranslucentForImageView(Activity activity, @IntRange(from = 0, to = 255) int statusBarAlpha,
457 | View needOffsetView) {
458 | if (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT) {
459 | return;
460 | }
461 | setTransparentForWindow(activity);
462 | addTranslucentView(activity, statusBarAlpha);
463 | if (needOffsetView != null) {
464 | Object haveSetOffset = needOffsetView.getTag(TAG_KEY_HAVE_SET_OFFSET);
465 | if (haveSetOffset != null && (Boolean) haveSetOffset) {
466 | return;
467 | }
468 | ViewGroup.MarginLayoutParams layoutParams = (ViewGroup.MarginLayoutParams) needOffsetView.getLayoutParams();
469 | layoutParams.setMargins(layoutParams.leftMargin, layoutParams.topMargin + getStatusBarHeight(activity),
470 | layoutParams.rightMargin, layoutParams.bottomMargin);
471 | needOffsetView.setTag(TAG_KEY_HAVE_SET_OFFSET, true);
472 | }
473 | }
474 |
475 | /**
476 | * 为 fragment 头部是 ImageView 的设置状态栏透明
477 | *
478 | * @param activity fragment 对应的 activity
479 | * @param needOffsetView 需要向下偏移的 View
480 | */
481 | public static void setTranslucentForImageViewInFragment(Activity activity, View needOffsetView) {
482 | setTranslucentForImageViewInFragment(activity, DEFAULT_STATUS_BAR_ALPHA, needOffsetView);
483 | }
484 |
485 | /**
486 | * 为 fragment 头部是 ImageView 的设置状态栏透明
487 | *
488 | * @param activity fragment 对应的 activity
489 | * @param needOffsetView 需要向下偏移的 View
490 | */
491 | public static void setTransparentForImageViewInFragment(Activity activity, View needOffsetView) {
492 | setTranslucentForImageViewInFragment(activity, 0, needOffsetView);
493 | }
494 |
495 | /**
496 | * 为 fragment 头部是 ImageView 的设置状态栏透明
497 | *
498 | * @param activity fragment 对应的 activity
499 | * @param statusBarAlpha 状态栏透明度
500 | * @param needOffsetView 需要向下偏移的 View
501 | */
502 | public static void setTranslucentForImageViewInFragment(Activity activity, @IntRange(from = 0, to = 255) int statusBarAlpha,
503 | View needOffsetView) {
504 | setTranslucentForImageView(activity, statusBarAlpha, needOffsetView);
505 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT && Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
506 | clearPreviousSetting(activity);
507 | }
508 | }
509 |
510 | /**
511 | * 隐藏伪状态栏 View
512 | *
513 | * @param activity 调用的 Activity
514 | */
515 | public static void hideFakeStatusBarView(Activity activity) {
516 | ViewGroup decorView = (ViewGroup) activity.getWindow().getDecorView();
517 | View fakeStatusBarView = decorView.findViewById(FAKE_STATUS_BAR_VIEW_ID);
518 | if (fakeStatusBarView != null) {
519 | fakeStatusBarView.setVisibility(View.GONE);
520 | }
521 | View fakeTranslucentView = decorView.findViewById(FAKE_TRANSLUCENT_VIEW_ID);
522 | if (fakeTranslucentView != null) {
523 | fakeTranslucentView.setVisibility(View.GONE);
524 | }
525 | }
526 |
527 | @TargetApi(Build.VERSION_CODES.M)
528 | public static void setLightMode(Activity activity) {
529 | setMIUIStatusBarDarkIcon(activity, true);
530 | setMeizuStatusBarDarkIcon(activity, true);
531 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
532 | activity.getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN);
533 | }
534 | }
535 |
536 | @TargetApi(Build.VERSION_CODES.M)
537 | public static void setDarkMode(Activity activity) {
538 | setMIUIStatusBarDarkIcon(activity, false);
539 | setMeizuStatusBarDarkIcon(activity, false);
540 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
541 | activity.getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN);
542 | }
543 | }
544 |
545 | /**
546 | * 修改 MIUI V6 以上状态栏颜色
547 | */
548 | private static void setMIUIStatusBarDarkIcon(@NonNull Activity activity, boolean darkIcon) {
549 | Class extends Window> clazz = activity.getWindow().getClass();
550 | try {
551 | Class> layoutParams = Class.forName("android.view.MiuiWindowManager$LayoutParams");
552 | Field field = layoutParams.getField("EXTRA_FLAG_STATUS_BAR_DARK_MODE");
553 | int darkModeFlag = field.getInt(layoutParams);
554 | Method extraFlagField = clazz.getMethod("setExtraFlags", int.class, int.class);
555 | extraFlagField.invoke(activity.getWindow(), darkIcon ? darkModeFlag : 0, darkModeFlag);
556 | } catch (Exception e) {
557 | //e.printStackTrace();
558 | }
559 | }
560 |
561 | /**
562 | * 修改魅族状态栏字体颜色 Flyme 4.0
563 | */
564 | private static void setMeizuStatusBarDarkIcon(@NonNull Activity activity, boolean darkIcon) {
565 | try {
566 | WindowManager.LayoutParams lp = activity.getWindow().getAttributes();
567 | Field darkFlag = WindowManager.LayoutParams.class.getDeclaredField("MEIZU_FLAG_DARK_STATUS_BAR_ICON");
568 | Field meizuFlags = WindowManager.LayoutParams.class.getDeclaredField("meizuFlags");
569 | darkFlag.setAccessible(true);
570 | meizuFlags.setAccessible(true);
571 | int bit = darkFlag.getInt(null);
572 | int value = meizuFlags.getInt(lp);
573 | if (darkIcon) {
574 | value |= bit;
575 | } else {
576 | value &= ~bit;
577 | }
578 | meizuFlags.setInt(lp, value);
579 | activity.getWindow().setAttributes(lp);
580 | } catch (Exception e) {
581 | //e.printStackTrace();
582 | }
583 | }
584 |
585 | ///////////////////////////////////////////////////////////////////////////////////
586 |
587 | @TargetApi(Build.VERSION_CODES.KITKAT)
588 | private static void clearPreviousSetting(Activity activity) {
589 | ViewGroup decorView = (ViewGroup) activity.getWindow().getDecorView();
590 | View fakeStatusBarView = decorView.findViewById(FAKE_STATUS_BAR_VIEW_ID);
591 | if (fakeStatusBarView != null) {
592 | decorView.removeView(fakeStatusBarView);
593 | ViewGroup rootView = (ViewGroup) ((ViewGroup) activity.findViewById(android.R.id.content)).getChildAt(0);
594 | rootView.setPadding(0, 0, 0, 0);
595 | }
596 | }
597 |
598 | /**
599 | * 添加半透明矩形条
600 | *
601 | * @param activity 需要设置的 activity
602 | * @param statusBarAlpha 透明值
603 | */
604 | private static void addTranslucentView(Activity activity, @IntRange(from = 0, to = 255) int statusBarAlpha) {
605 | ViewGroup contentView = (ViewGroup) activity.findViewById(android.R.id.content);
606 | View fakeTranslucentView = contentView.findViewById(FAKE_TRANSLUCENT_VIEW_ID);
607 | if (fakeTranslucentView != null) {
608 | if (fakeTranslucentView.getVisibility() == View.GONE) {
609 | fakeTranslucentView.setVisibility(View.VISIBLE);
610 | }
611 | fakeTranslucentView.setBackgroundColor(Color.argb(statusBarAlpha, 0, 0, 0));
612 | } else {
613 | contentView.addView(createTranslucentStatusBarView(activity, statusBarAlpha));
614 | }
615 | }
616 |
617 | /**
618 | * 生成一个和状态栏大小相同的彩色矩形条
619 | *
620 | * @param activity 需要设置的 activity
621 | * @param color 状态栏颜色值
622 | * @return 状态栏矩形条
623 | */
624 | private static View createStatusBarView(Activity activity, @ColorInt int color) {
625 | return createStatusBarView(activity, color, 0);
626 | }
627 |
628 | /**
629 | * 生成一个和状态栏大小相同的半透明矩形条
630 | *
631 | * @param activity 需要设置的activity
632 | * @param color 状态栏颜色值
633 | * @param alpha 透明值
634 | * @return 状态栏矩形条
635 | */
636 | private static View createStatusBarView(Activity activity, @ColorInt int color, int alpha) {
637 | // 绘制一个和状态栏一样高的矩形
638 | View statusBarView = new View(activity);
639 | LinearLayout.LayoutParams params =
640 | new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, getStatusBarHeight(activity));
641 | statusBarView.setLayoutParams(params);
642 | statusBarView.setBackgroundColor(calculateStatusColor(color, alpha));
643 | statusBarView.setId(FAKE_STATUS_BAR_VIEW_ID);
644 | return statusBarView;
645 | }
646 |
647 | /**
648 | * 设置根布局参数
649 | */
650 | private static void setRootView(Activity activity) {
651 | ViewGroup parent = (ViewGroup) activity.findViewById(android.R.id.content);
652 | for (int i = 0, count = parent.getChildCount(); i < count; i++) {
653 | View childView = parent.getChildAt(i);
654 | if (childView instanceof ViewGroup) {
655 | childView.setFitsSystemWindows(true);
656 | ((ViewGroup) childView).setClipToPadding(true);
657 | }
658 | }
659 | }
660 |
661 | /**
662 | * 设置透明
663 | */
664 | private static void setTransparentForWindow(Activity activity) {
665 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
666 | activity.getWindow().setStatusBarColor(Color.TRANSPARENT);
667 | activity.getWindow()
668 | .getDecorView()
669 | .setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_STABLE | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN);
670 | } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
671 | activity.getWindow()
672 | .setFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS, WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
673 | }
674 | }
675 |
676 | /**
677 | * 使状态栏透明
678 | */
679 | @TargetApi(Build.VERSION_CODES.KITKAT)
680 | private static void transparentStatusBar(Activity activity) {
681 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
682 | activity.getWindow().addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
683 | activity.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
684 | activity.getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);
685 | activity.getWindow().setStatusBarColor(Color.TRANSPARENT);
686 | } else {
687 | activity.getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
688 | }
689 | }
690 |
691 | /**
692 | * 创建半透明矩形 View
693 | *
694 | * @param alpha 透明值
695 | * @return 半透明 View
696 | */
697 | private static View createTranslucentStatusBarView(Activity activity, int alpha) {
698 | // 绘制一个和状态栏一样高的矩形
699 | View statusBarView = new View(activity);
700 | LinearLayout.LayoutParams params =
701 | new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, getStatusBarHeight(activity));
702 | statusBarView.setLayoutParams(params);
703 | statusBarView.setBackgroundColor(Color.argb(alpha, 0, 0, 0));
704 | statusBarView.setId(FAKE_TRANSLUCENT_VIEW_ID);
705 | return statusBarView;
706 | }
707 |
708 | /**
709 | * 获取状态栏高度
710 | *
711 | * @param context context
712 | * @return 状态栏高度
713 | */
714 | public static int getStatusBarHeight(Context context) {
715 | // 获得状态栏高度
716 | int resourceId = context.getResources().getIdentifier("status_bar_height", "dimen", "android");
717 | return context.getResources().getDimensionPixelSize(resourceId);
718 | }
719 |
720 | /**
721 | * 计算状态栏颜色
722 | *
723 | * @param color color值
724 | * @param alpha alpha值
725 | * @return 最终的状态栏颜色
726 | */
727 | private static int calculateStatusColor(@ColorInt int color, int alpha) {
728 | if (alpha == 0) {
729 | return color;
730 | }
731 | float a = 1 - alpha / 255f;
732 | int red = color >> 16 & 0xff;
733 | int green = color >> 8 & 0xff;
734 | int blue = color & 0xff;
735 | red = (int) (red * a + 0.5);
736 | green = (int) (green * a + 0.5);
737 | blue = (int) (blue * a + 0.5);
738 | return 0xff << 24 | red << 16 | green << 8 | blue;
739 | }
740 |
741 |
742 | /**
743 | * 为布局文件中新增的状态栏布局设置背景色和高度
744 | */
745 | public static void setStatusViewAttr(View view, Activity activity, int color) {
746 | if (view == null || activity == null) {
747 | return;
748 | }
749 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
750 | ViewGroup.LayoutParams layoutParams = view.getLayoutParams();
751 | layoutParams.height = StatusBarUtil.getStatusBarHeight(activity);
752 | view.setLayoutParams(layoutParams);
753 | if (color == -1) {
754 | view.setBackgroundColor(activity.getResources().getColor(R.color.colorAccent));
755 | } else {
756 | view.setBackgroundColor(color);
757 | }
758 |
759 | }
760 | }
761 |
762 |
763 | /**
764 | * 为布局文件中新增的状态栏布局设置背景色和高度
765 | */
766 | public static void setStatusViewAttr(View view, Activity activity) {
767 | if (view == null || activity == null) {
768 | return;
769 | }
770 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
771 | ViewGroup.LayoutParams layoutParams = view.getLayoutParams();
772 | layoutParams.height = StatusBarUtil.getStatusBarHeight(activity);
773 | view.setLayoutParams(layoutParams);
774 | }
775 | }
776 |
777 | /**
778 | * 增加View的paddingTop,增加的值为状态栏高度 (智能判断,并设置高度)
779 | */
780 | public static void setPaddingSmart(Context context, View view) {
781 | if (Build.VERSION.SDK_INT >= 19) {
782 | ViewGroup.LayoutParams lp = view.getLayoutParams();
783 | if (lp != null && lp.height > 0) {
784 | lp.height += getStatusBarHeight(context);//增高
785 | }
786 | view.setPadding(view.getPaddingLeft(), view.getPaddingTop() + getStatusBarHeight(context),
787 | view.getPaddingRight(), view.getPaddingBottom());
788 | }
789 | }
790 |
791 | }
792 |
--------------------------------------------------------------------------------
> o) {
67 | try {
68 | mCountryList.clear();
69 | mCountryList.addAll(PinYinKit.filledData(o.getData()));
70 | mAdapter.notifyDataSetChanged();
71 | } catch (BadHanyuPinyinOutputFormatCombination badHanyuPinyinOutputFormatCombination) {
72 | badHanyuPinyinOutputFormatCombination.printStackTrace();
73 | }
74 | }
75 |
76 |
77 | @Override
78 | public void onSelectIndexItem(String str) {
79 | try {
80 | int position = PinYinKit.getPositionForSection(mCountryList, str.charAt(0));
81 | if (position != -1) {
82 | mListView.setSelection(position);
83 | }
84 | } catch (Exception e) {
85 | e.printStackTrace();
86 | }
87 | }
88 | }
89 |
--------------------------------------------------------------------------------
/app/src/main/java/com/lp/sidebar_master/activity/Country1Activity.java:
--------------------------------------------------------------------------------
1 | package com.lp.sidebar_master.activity;
2 |
3 | import android.widget.ListView;
4 | import android.widget.TextView;
5 |
6 | import com.lp.sidebar_master.R;
7 | import com.lp.sidebar_master.adapter.CountryLvAdapter;
8 | import com.lp.sidebar_master.base.BaseActivity;
9 | import com.lp.sidebar_master.base.mvp.BaseModel;
10 | import com.lp.sidebar_master.presenter.CountryBean;
11 | import com.lp.sidebar_master.presenter.CountryPresenter;
12 | import com.lp.sidebar_master.presenter.CountryView;
13 | import com.lp.sidebar_master.utils.PinYinKit;
14 | import com.lp.sidebar_master.widget.SideBar;
15 |
16 | import net.sourceforge.pinyin4j.format.exception.BadHanyuPinyinOutputFormatCombination;
17 |
18 | import java.util.ArrayList;
19 | import java.util.List;
20 |
21 | import butterknife.BindView;
22 |
23 |
24 | /**
25 | * File descripition:侧滑栏拼音全部显示
26 | *
27 | * @author lp
28 | * @date 2018/8/4
29 | */
30 |
31 | public class Country1Activity extends BaseActivity
> o) {
67 | try {
68 | mCountryList.clear();
69 | mCountryList.addAll(PinYinKit.filledData(o.getData()));
70 | mAdapter.notifyDataSetChanged();
71 | } catch (BadHanyuPinyinOutputFormatCombination badHanyuPinyinOutputFormatCombination) {
72 | badHanyuPinyinOutputFormatCombination.printStackTrace();
73 | }
74 | }
75 |
76 | @Override
77 | public void onTouchingLetterChanged(String str) {
78 | try {
79 | int position = PinYinKit.getPositionForSection(mCountryList, str.charAt(0));
80 | if (position != -1) {
81 | mListView.setSelection(position);
82 | }
83 | } catch (Exception e) {
84 | e.printStackTrace();
85 | }
86 | }
87 | }
88 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
> o) {
72 | try {
73 | mCountryList.clear();
74 | mCountryList.addAll(PinYinKit.filledData(o.getData()));
75 |
76 | mLetter.clear();
77 | for (int i = 0; i < mCountryList.size(); i++) {
78 | mLetter.add(mCountryList.get(i).getSortLetters());
79 | }
80 | removeDuplicate(mLetter);
81 | String[] letters = mLetter.toArray(new String[mLetter.size()]);
82 | mSidebar.setIndexs(letters);
83 |
84 | mAdapter.notifyDataSetChanged();
85 | } catch (BadHanyuPinyinOutputFormatCombination badHanyuPinyinOutputFormatCombination) {
86 | badHanyuPinyinOutputFormatCombination.printStackTrace();
87 | }
88 | }
89 |
90 |
91 | private static void removeDuplicate(List
> o) {
89 | try {
90 | mCountryList.clear();
91 | mCountryList.addAll(PinYinKit.filledData(o.getData()));
92 | mAdapter.notifyDataSetChanged();
93 | } catch (BadHanyuPinyinOutputFormatCombination badHanyuPinyinOutputFormatCombination) {
94 | badHanyuPinyinOutputFormatCombination.printStackTrace();
95 | }
96 | }
97 |
98 | private class mScrollListener implements AbsListView.OnScrollListener {
99 |
100 | private int mCurrentPosition = -1;
101 |
102 | @Override
103 | public void onScrollStateChanged(AbsListView absListView, int i) {
104 | if (mLlIndex != null || mFlowHeight < 1) {
105 | mFlowHeight = mLlIndex.getMeasuredHeight();
106 | }
107 | }
108 |
109 | @Override
110 | public void onScroll(AbsListView absListView, int position, int i1, int i2) {
111 | int firstVisibleItemPosition = absListView.getFirstVisiblePosition();
112 | View view = absListView.getChildAt(position + 1 - absListView.getFirstVisiblePosition());
113 |
114 | if (view != null) {
115 | if (view.getTop() <= mFlowHeight && mCountryList.get(firstVisibleItemPosition + 1).getLetter()) {
116 | mLlIndex.setY(view.getTop() - mFlowHeight);
117 | } else {
118 | mLlIndex.setY(0);
119 | }
120 | }
121 |
122 | if (mCurrentPosition != firstVisibleItemPosition) {
123 | mCurrentPosition = firstVisibleItemPosition;
124 | if (mCountryList.size() > 0) {
125 | mTvIndex.setText(mCountryList.get(mCurrentPosition).getSortLetters());
126 | }
127 | }
128 | }
129 | }
130 |
131 | @Override
132 | public void onSelectIndexItem(String str) {
133 | try {
134 | int position = PinYinKit.getPositionForSection(mCountryList, str.charAt(0));
135 | if (position != -1) {
136 | mRecyclerView.setSelection(position);
137 | }
138 | } catch (Exception e) {
139 | e.printStackTrace();
140 | }
141 | }
142 | }
143 |
--------------------------------------------------------------------------------
/app/src/main/java/com/lp/sidebar_master/activity/Country3RvActivity.java:
--------------------------------------------------------------------------------
1 | package com.lp.sidebar_master.activity;
2 |
3 | import android.support.v7.widget.LinearLayoutManager;
4 | import android.support.v7.widget.RecyclerView;
5 | import android.view.View;
6 | import android.widget.LinearLayout;
7 | import android.widget.TextView;
8 |
9 | import com.lp.sidebar_master.R;
10 | import com.lp.sidebar_master.adapter.CountryRvAdapter;
11 | import com.lp.sidebar_master.base.BaseActivity;
12 | import com.lp.sidebar_master.base.mvp.BaseModel;
13 | import com.lp.sidebar_master.presenter.CountryBean;
14 | import com.lp.sidebar_master.presenter.CountryPresenter;
15 | import com.lp.sidebar_master.presenter.CountryView;
16 | import com.lp.sidebar_master.utils.PinYinKit;
17 | import com.lp.sidebar_master.widget.WaveSideBar;
18 |
19 | import net.sourceforge.pinyin4j.format.exception.BadHanyuPinyinOutputFormatCombination;
20 |
21 | import java.util.ArrayList;
22 | import java.util.List;
23 |
24 | import butterknife.BindView;
25 |
26 |
27 | /**
28 | * File descripition: 侧滑栏拼音全部显示,有动态效果,拼音字母顶部停留
29 | *
30 | * @author lp
31 | * @date 2018/8/4
32 | */
33 |
34 | public class Country3RvActivity extends BaseActivity
> o) {
80 | try {
81 | mCountryList.clear();
82 | mCountryList.addAll(PinYinKit.filledData(o.getData()));
83 | mAdapter.notifyDataSetChanged();
84 | } catch (BadHanyuPinyinOutputFormatCombination badHanyuPinyinOutputFormatCombination) {
85 | badHanyuPinyinOutputFormatCombination.printStackTrace();
86 | }
87 | }
88 |
89 |
90 | private class mScrollListener extends RecyclerView.OnScrollListener {
91 |
92 | private int mFlowHeight = 0;
93 | private int mCurrentPosition = -1;
94 |
95 | @Override
96 | public void onScrollStateChanged(RecyclerView recyclerView, int newState) {
97 | if (mLlIndex != null || mFlowHeight < 1) {
98 | mFlowHeight = mLlIndex.getMeasuredHeight();
99 | }
100 | }
101 |
102 | @Override
103 | public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
104 | int firstVisibleItemPosition = layoutManager.findFirstVisibleItemPosition();
105 | View view = layoutManager.findViewByPosition(firstVisibleItemPosition + 1);
106 |
107 | if (view != null) {
108 | if (view.getTop() <= mFlowHeight && mCountryList.get(firstVisibleItemPosition + 1).getLetter()) {
109 | mLlIndex.setY(view.getTop() - mFlowHeight);
110 | } else {
111 | mLlIndex.setY(0);
112 | }
113 | }
114 |
115 | if (mCurrentPosition != firstVisibleItemPosition) {
116 | mCurrentPosition = firstVisibleItemPosition;
117 | if (mCountryList.size() > 0) {
118 | mTvIndex.setText(mCountryList.get(mCurrentPosition).getSortLetters());
119 | mLlIndex.setVisibility(View.VISIBLE);
120 | } else {
121 | mLlIndex.setVisibility(View.GONE);
122 | }
123 | }
124 | }
125 | }
126 |
127 | @Override
128 | public void onSelectIndexItem(String str) {
129 | try {
130 | int position = PinYinKit.getPositionForSection(mCountryList, str.charAt(0));
131 | if (position != -1) {
132 | /**
133 | * 直接到指定位置
134 | */
135 | layoutManager.scrollToPositionWithOffset(position, 0);
136 | layoutManager.setStackFromEnd(true);
137 | /**
138 | * 滚动到指定位置(有滚动效果)
139 | */
140 | // linearSmoothScroller.setTargetPosition(position);
141 | // layoutManager.startSmoothScroll(linearSmoothScroller);
142 |
143 | }
144 | } catch (Exception e) {
145 | e.printStackTrace();
146 | }
147 | }
148 |
149 |
150 | }
151 |
--------------------------------------------------------------------------------
/gradlew:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env bash
2 |
3 | ##############################################################################
4 | ##
5 | ## Gradle start up script for UN*X
6 | ##
7 | ##############################################################################
8 |
9 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
10 | DEFAULT_JVM_OPTS=""
11 |
12 | APP_NAME="Gradle"
13 | APP_BASE_NAME=`basename "$0"`
14 |
15 | # Use the maximum available, or set MAX_FD != -1 to use that value.
16 | MAX_FD="maximum"
17 |
18 | warn ( ) {
19 | echo "$*"
20 | }
21 |
22 | die ( ) {
23 | echo
24 | echo "$*"
25 | echo
26 | exit 1
27 | }
28 |
29 | # OS specific support (must be 'true' or 'false').
30 | cygwin=false
31 | msys=false
32 | darwin=false
33 | case "`uname`" in
34 | CYGWIN* )
35 | cygwin=true
36 | ;;
37 | Darwin* )
38 | darwin=true
39 | ;;
40 | MINGW* )
41 | msys=true
42 | ;;
43 | esac
44 |
45 | # Attempt to set APP_HOME
46 | # Resolve links: $0 may be a link
47 | PRG="$0"
48 | # Need this for relative symlinks.
49 | while [ -h "$PRG" ] ; do
50 | ls=`ls -ld "$PRG"`
51 | link=`expr "$ls" : '.*-> \(.*\)$'`
52 | if expr "$link" : '/.*' > /dev/null; then
53 | PRG="$link"
54 | else
55 | PRG=`dirname "$PRG"`"/$link"
56 | fi
57 | done
58 | SAVED="`pwd`"
59 | cd "`dirname \"$PRG\"`/" >/dev/null
60 | APP_HOME="`pwd -P`"
61 | cd "$SAVED" >/dev/null
62 |
63 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
64 |
65 | # Determine the Java command to use to start the JVM.
66 | if [ -n "$JAVA_HOME" ] ; then
67 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
68 | # IBM's JDK on AIX uses strange locations for the executables
69 | JAVACMD="$JAVA_HOME/jre/sh/java"
70 | else
71 | JAVACMD="$JAVA_HOME/bin/java"
72 | fi
73 | if [ ! -x "$JAVACMD" ] ; then
74 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
75 |
76 | Please set the JAVA_HOME variable in your environment to match the
77 | location of your Java installation."
78 | fi
79 | else
80 | JAVACMD="java"
81 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
82 |
83 | Please set the JAVA_HOME variable in your environment to match the
84 | location of your Java installation."
85 | fi
86 |
87 | # Increase the maximum file descriptors if we can.
88 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then
89 | MAX_FD_LIMIT=`ulimit -H -n`
90 | if [ $? -eq 0 ] ; then
91 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
92 | MAX_FD="$MAX_FD_LIMIT"
93 | fi
94 | ulimit -n $MAX_FD
95 | if [ $? -ne 0 ] ; then
96 | warn "Could not set maximum file descriptor limit: $MAX_FD"
97 | fi
98 | else
99 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
100 | fi
101 | fi
102 |
103 | # For Darwin, add options to specify how the application appears in the dock
104 | if $darwin; then
105 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
106 | fi
107 |
108 | # For Cygwin, switch paths to Windows format before running java
109 | if $cygwin ; then
110 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
111 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
112 | JAVACMD=`cygpath --unix "$JAVACMD"`
113 |
114 | # We build the pattern for arguments to be converted via cygpath
115 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
116 | SEP=""
117 | for dir in $ROOTDIRSRAW ; do
118 | ROOTDIRS="$ROOTDIRS$SEP$dir"
119 | SEP="|"
120 | done
121 | OURCYGPATTERN="(^($ROOTDIRS))"
122 | # Add a user-defined pattern to the cygpath arguments
123 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
124 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
125 | fi
126 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
127 | i=0
128 | for arg in "$@" ; do
129 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
130 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
131 |
132 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
133 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
134 | else
135 | eval `echo args$i`="\"$arg\""
136 | fi
137 | i=$((i+1))
138 | done
139 | case $i in
140 | (0) set -- ;;
141 | (1) set -- "$args0" ;;
142 | (2) set -- "$args0" "$args1" ;;
143 | (3) set -- "$args0" "$args1" "$args2" ;;
144 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
145 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
146 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
147 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
148 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
149 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
150 | esac
151 | fi
152 |
153 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules
154 | function splitJvmOpts() {
155 | JVM_OPTS=("$@")
156 | }
157 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS
158 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"
159 |
160 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@"
161 |
--------------------------------------------------------------------------------
/app/src/main/java/com/lp/sidebar_master/widget/SideBar.java:
--------------------------------------------------------------------------------
1 | package com.lp.sidebar_master.widget;
2 | import android.content.Context;
3 | import android.graphics.Canvas;
4 | import android.graphics.Color;
5 | import android.graphics.Paint;
6 | import android.graphics.Typeface;
7 | import android.graphics.drawable.ColorDrawable;
8 | import android.util.AttributeSet;
9 | import android.view.MotionEvent;
10 | import android.view.View;
11 | import android.widget.TextView;
12 |
13 | import com.lp.sidebar_master.R;
14 |
15 |
16 | /**
17 | * 侧滑拼音
18 | */
19 |
20 | public class SideBar extends View {
21 |
22 | /**
23 | * 触摸字母索引发生变化的回调接口
24 | */
25 | private OnTouchingLetterChangedListener onTouchingLetterChangedListener;
26 | /**
27 | * 侧边栏字母显示
28 | */
29 | public static String[] b =
30 | {
31 | "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K",
32 | "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V",
33 | "W", "X", "Y", "Z", "#"
34 | };
35 | /**
36 | * 变量 choose 用来标示当前手指触摸的字母索引在 alphabet 数组中的下标
37 | */
38 | private int choose = -1;
39 | /**
40 | * 定义画笔
41 | */
42 | private Paint paint = new Paint();
43 | /**
44 | * 当手指在 SideBar 上滑动的时候,会有一个 TextView 来显示当前手指触摸的字母索引,
45 | */
46 | private TextView mTextDialog;
47 |
48 | /**
49 | * 为SideBar设置显示字母的TextView
50 | *
51 | * @param mTextDialog
52 | */
53 | public void setmTextDialog(TextView mTextDialog) {
54 | this.mTextDialog = mTextDialog;
55 | }
56 |
57 | public SideBar(Context context, AttributeSet attrs, int defStyleAttr) {
58 | super(context, attrs, defStyleAttr);
59 | }
60 |
61 | public SideBar(Context context, AttributeSet attrs) {
62 | super(context, attrs);
63 | }
64 |
65 | public SideBar(Context context) {
66 | super(context);
67 | }
68 |
69 | /**
70 | * 绘制列表控件的方法
71 | * 将要绘制的字母以从上到下的顺序绘制在一个指定区域
72 | * 如果是进行选中的字母就进行高亮显示
73 | */
74 | @Override
75 | protected void onDraw(Canvas canvas) {
76 | super.onDraw(canvas);
77 | // 获取SideBar的高度
78 | int height = getHeight();
79 | // 获取SideBar的宽度
80 | int width = getWidth();
81 | // 获得每个字母索引的高度
82 | int singleHeight = height / b.length;
83 |
84 | //绘制每一个字母的索引
85 | for (int i = 0; i < b.length; i++) {
86 | paint.setColor(Color.rgb(33, 65, 98));//设置字母颜色
87 | paint.setTypeface(Typeface.DEFAULT_BOLD);//设置字体
88 | paint.setAntiAlias(true);//抗锯齿
89 | paint.setTextSize(20);//设置字体大小
90 |
91 | // 如果当前的手指触摸索引和字母索引相同,那么字体颜色进行区分
92 | if (i == choose) {
93 | paint.setColor(Color.parseColor("#3399ff"));
94 | paint.setFakeBoldText(true);
95 | }
96 |
97 | /**
98 | * 绘制字体,需要制定绘制的x、y轴坐标
99 | * x轴坐标 = 控件宽度的一半 - 字体宽度的一半
100 | * y轴坐标 = singleHeight * i + singleHeight
101 | */
102 | float x = width / 2 - paint.measureText(b[i]) / 2;
103 | float y = singleHeight * i + singleHeight;
104 | canvas.drawText(b[i], x, y, paint);
105 |
106 | // 重置画笔,准备绘制下一个字母索引
107 | paint.reset();
108 | }
109 | }
110 |
111 | @SuppressWarnings("deprecation")
112 | @Override
113 | public boolean dispatchTouchEvent(MotionEvent event) {
114 | // 触摸事件的代码
115 | final int action = event.getAction();
116 | //手指触摸点在屏幕的Y坐标
117 | final float y = event.getY();
118 | // 因为currentChoosenAlphabetIndex会不断发生变化,所以用一个变量存储起来
119 | final int oldChoose = choose;
120 | final OnTouchingLetterChangedListener changedListener = onTouchingLetterChangedListener;
121 | // 比例 = 手指触摸点在屏幕的y轴坐标 / SideBar的高度
122 | // 触摸点的索引 = 比例 * 字母索引数组的长度
123 | final int letterPos = (int) (y / getHeight() * b.length);
124 |
125 | switch (action) {
126 | case MotionEvent.ACTION_UP:
127 | // 如果手指没有触摸屏幕,SideBar的背景颜色为默认,索引字母提示控件不可见
128 | setBackgroundDrawable(new ColorDrawable(0x00000000));
129 | choose = -1;
130 | invalidate();
131 | if (mTextDialog != null) {
132 | mTextDialog.setVisibility(View.INVISIBLE);
133 | }
134 | break;
135 |
136 | default:
137 | // 其他情况,比如滑动屏幕、点击屏幕等等,SideBar会改变背景颜色,索引字母提示控件可见,同时需要设置内容
138 | setBackgroundResource(R.drawable.bg_sidebar);
139 | // 不是同一个字母索引
140 | if (oldChoose != letterPos) {
141 | // 如果触摸点没有超出控件范围
142 | if (letterPos >= 0 && letterPos < b.length) {
143 | if (changedListener != null)
144 | changedListener.onTouchingLetterChanged(b[letterPos]);
145 | if (mTextDialog != null) {
146 | mTextDialog.setText(b[letterPos]);
147 | mTextDialog.setVisibility(View.VISIBLE);
148 | }
149 |
150 | choose = letterPos;
151 | invalidate();
152 | }
153 | }
154 | break;
155 | }
156 | return true;
157 | }
158 |
159 | public void setOnTouchingLetterChangedListener(OnTouchingLetterChangedListener changedListener) {
160 | this.onTouchingLetterChangedListener = changedListener;
161 | }
162 |
163 | /**
164 | * 当手指触摸的字母索引发生变化时,调用该回调接口
165 | */
166 | public interface OnTouchingLetterChangedListener {
167 | void onTouchingLetterChanged(String str);
168 | }
169 | }
170 |
--------------------------------------------------------------------------------
/app/src/main/java/com/lp/sidebar_master/widget/IndexBar.java:
--------------------------------------------------------------------------------
1 | package com.lp.sidebar_master.widget;
2 |
3 | import android.annotation.SuppressLint;
4 | import android.content.Context;
5 | import android.graphics.Canvas;
6 | import android.graphics.Paint;
7 | import android.graphics.Rect;
8 | import android.util.AttributeSet;
9 | import android.util.DisplayMetrics;
10 | import android.view.MotionEvent;
11 | import android.view.View;
12 | import android.widget.TextView;
13 |
14 |
15 |
16 | /**
17 | * Created by SouthernBox on 2016/10/25 0025.
18 | * 侧边索引栏控件
19 | */
20 |
21 | public class IndexBar extends View {
22 |
23 | /**
24 | * 索引字母颜色
25 | */
26 | private static final int LETTER_COLOR = 0xFF2E8BE6;
27 |
28 | /**
29 | * 索引字母数组
30 | */
31 | public String[] indexs = {};
32 |
33 | /**
34 | * 控件的宽高
35 | */
36 | private int mWidth;
37 | private int mHeight;
38 |
39 | /**
40 | * 单元格的高度
41 | */
42 | private float mCellHeight;
43 |
44 | /**
45 | * 顶部间距
46 | */
47 | private float mMarginTop;
48 |
49 | private Paint mPaint;
50 |
51 | public IndexBar(Context context) {
52 | super(context);
53 | init();
54 | }
55 |
56 | public IndexBar(Context context, AttributeSet attrs) {
57 | super(context, attrs);
58 | init();
59 | }
60 |
61 | private void init() {
62 | mPaint = new Paint();
63 | mPaint.setColor(LETTER_COLOR);
64 | mPaint.setTextSize(dp2px(getContext(), 12));
65 | mPaint.setAntiAlias(true); // 去掉锯齿,让字体边缘变得平滑
66 | }
67 |
68 | public void setIndexs(String[] indexs) {
69 | this.indexs = indexs;
70 | mMarginTop = (mHeight - mCellHeight * indexs.length) / 2;
71 | invalidate();
72 | }
73 |
74 | @Override
75 | protected void onDraw(Canvas canvas) {
76 | //字母的坐标点:(x,y)
77 | if (indexs.length <= 0) {
78 | return;
79 | }
80 | for (int i = 0; i < indexs.length; i++) {
81 | String letter = indexs[i];
82 | float x = mWidth / 2 - getTextWidth(letter) / 2;
83 | float y = mCellHeight / 2 + getTextHeight(letter) / 2 + mCellHeight * i + mMarginTop;
84 | canvas.drawText(letter, x, y, mPaint);
85 | }
86 | }
87 |
88 | /**
89 | * 获取字符的宽度
90 | *
91 | * @param text 需要测量的字母
92 | * @return 对应字母的高度
93 | */
94 | public float getTextWidth(String text) {
95 | Rect bounds = new Rect();
96 | mPaint.getTextBounds(text, 0, text.length(), bounds);
97 | return bounds.width();
98 | }
99 |
100 | /**
101 | * 获取字符的高度
102 | *
103 | * @param text 需要测量的字母
104 | * @return 对应字母的高度
105 | */
106 | public float getTextHeight(String text) {
107 | Rect bounds = new Rect();
108 | mPaint.getTextBounds(text, 0, text.length(), bounds);
109 | return bounds.height();
110 | }
111 |
112 |
113 | @Override
114 | protected void onSizeChanged(int w, int h, int oldw, int oldh) {
115 | super.onSizeChanged(w, h, oldw, oldh);
116 | mWidth = getMeasuredWidth();
117 | mHeight = getMeasuredHeight();
118 | mCellHeight = (mHeight * 1f / 27); //26个字母加上“#”
119 | mMarginTop = (mHeight - mCellHeight * indexs.length) / 2;
120 | }
121 |
122 | @Override
123 | @SuppressLint("ClickableViewAccessibility")
124 | public boolean onTouchEvent(MotionEvent event) {
125 | switch (event.getAction()) {
126 | case MotionEvent.ACTION_DOWN:
127 | case MotionEvent.ACTION_MOVE:
128 | // 按下字母的下标
129 | int letterIndex = (int) ((event.getY() - mMarginTop) / mCellHeight);
130 | // 判断是否越界
131 | if (letterIndex >= 0 && letterIndex < indexs.length) {
132 | // 显示按下的字母
133 | if (textView != null) {
134 | textView.setVisibility(View.VISIBLE);
135 | textView.setText(indexs[letterIndex]);
136 | }
137 | //通过回调方法通知列表定位
138 | if (mOnIndexChangedListener != null) {
139 | mOnIndexChangedListener.onIndexChanged(indexs[letterIndex]);
140 | }
141 | }
142 | break;
143 | case MotionEvent.ACTION_UP:
144 | case MotionEvent.ACTION_CANCEL:
145 | if (textView != null) {
146 | textView.setVisibility(View.GONE);
147 | }
148 | break;
149 | }
150 |
151 | return true;
152 | }
153 |
154 | public interface OnIndexChangedListener {
155 | /**
156 | * 按下字母改变了
157 | *
158 | * @param index 按下的字母
159 | */
160 | void onIndexChanged(String index);
161 | }
162 |
163 | private OnIndexChangedListener mOnIndexChangedListener;
164 |
165 | private TextView textView;
166 |
167 | public void setOnIndexChangedListener(OnIndexChangedListener onIndexChangedListener) {
168 | this.mOnIndexChangedListener = onIndexChangedListener;
169 | }
170 |
171 | /**
172 | * 设置显示按下首字母的TextView
173 | */
174 | public void setSelectedIndexTextView(TextView textView) {
175 | this.textView = textView;
176 | }
177 |
178 | /**
179 | * 将dp值转换为px值
180 | *
181 | * @param context 上下文
182 | * @param dpValue dp单位的长度
183 | * @return px单位的长度
184 | */
185 | public static int dp2px(Context context, int dpValue) {
186 | //获取屏幕密度
187 | DisplayMetrics displayMetrics = context.getResources().getDisplayMetrics();
188 | //屏幕密度的比例值
189 | float density = displayMetrics.density;
190 | //将dp转换为px
191 | return (int) (dpValue * density + 0.5);
192 | }
193 | }
194 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_launcher_background.xml:
--------------------------------------------------------------------------------
1 |
2 |
> o) {
123 | try {
124 | mCountryList.clear();
125 | mCountryListAll.clear();
126 | mCountryList.addAll(PinYinKit.filledData(o.getData()));
127 | mCountryListAll.addAll(PinYinKit.filledData(o.getData()));
128 | mAdapter.notifyDataSetChanged();
129 | } catch (BadHanyuPinyinOutputFormatCombination badHanyuPinyinOutputFormatCombination) {
130 | badHanyuPinyinOutputFormatCombination.printStackTrace();
131 | }
132 | }
133 |
134 |
135 | private class mScrollListener extends RecyclerView.OnScrollListener {
136 |
137 | private int mFlowHeight = 0;
138 | private int mCurrentPosition = -1;
139 |
140 | @Override
141 | public void onScrollStateChanged(RecyclerView recyclerView, int newState) {
142 | if (mLlIndex != null || mFlowHeight < 1) {
143 | mFlowHeight = mLlIndex.getMeasuredHeight();
144 | }
145 | }
146 |
147 | @Override
148 | public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
149 | int firstVisibleItemPosition = layoutManager.findFirstVisibleItemPosition();
150 | View view = layoutManager.findViewByPosition(firstVisibleItemPosition + 1);
151 |
152 | if (view != null) {
153 | if (view.getTop() <= mFlowHeight && mCountryList.get(firstVisibleItemPosition + 1).getLetter()) {
154 | mLlIndex.setY(view.getTop() - mFlowHeight);
155 | } else {
156 | mLlIndex.setY(0);
157 | }
158 | }
159 |
160 | // if (mCurrentPosition != firstVisibleItemPosition) {
161 | mCurrentPosition = firstVisibleItemPosition;
162 | if (mCountryList.size() > 0) {
163 | mTvIndex.setText(mCountryList.get(mCurrentPosition).getSortLetters());
164 | mLlIndex.setVisibility(View.VISIBLE);
165 | } else {
166 | mLlIndex.setVisibility(View.GONE);
167 | }
168 | // }
169 | }
170 | }
171 |
172 |
173 | @Override
174 | public void onSelectIndexItem(String str) {
175 | try {
176 | int position = PinYinKit.getPositionForSection(mCountryList, str.charAt(0));
177 | if (position != -1) {
178 | /**
179 | * 直接到指定位置
180 | */
181 | layoutManager.scrollToPositionWithOffset(position, 0);
182 | // layoutManager.setStackFromEnd(true);
183 | /**
184 | * 滚动到指定位置(有滚动效果)
185 | */
186 | // LinearSmoothScroller s1 = new TopSmoothScroller(this);
187 | // s1.setTargetPosition(position);
188 | // layoutManager.startSmoothScroll(s1);
189 | }
190 | } catch (Exception e) {
191 | e.printStackTrace();
192 | }
193 | }
194 |
195 |
196 | private void filerData(String str) throws BadHanyuPinyinOutputFormatCombination {
197 | if (TextUtils.isEmpty(str)) {
198 | mCountryList.clear();
199 | mCountryList.addAll(mCountryListAll);
200 | } else {
201 | mCountryList.clear();
202 | for (CountryBean ms : mCountryListAll) {
203 | String name = ms.getName();
204 | String code = ms.getCode();
205 | if (name.indexOf(str.toString()) != -1
206 | || PinYinKit.getPingYin(name).startsWith(str.toString())
207 | || PinYinKit.getPingYin(name).startsWith(str.toUpperCase().toString())
208 | || name.contains(str)
209 |
210 | || PinYinKit.getPingYin(code).startsWith(str.toString())
211 | || PinYinKit.getPingYin(code).startsWith(str.toUpperCase().toString())
212 | || code.contains(str)
213 | ) {
214 | mCountryList.add(ms);
215 | }
216 | }
217 | }
218 | PinYinKit.initLetter(mCountryList);
219 | layoutManager.scrollToPositionWithOffset(0, 0);
220 | mAdapter.notifyDataSetChanged();
221 | }
222 | }
223 |
--------------------------------------------------------------------------------
/app/src/main/java/com/lp/sidebar_master/base/viewholder/ViewHolder.java:
--------------------------------------------------------------------------------
1 | package com.lp.sidebar_master.base.viewholder;
2 |
3 | import android.annotation.SuppressLint;
4 | import android.content.Context;
5 | import android.graphics.Bitmap;
6 | import android.graphics.Paint;
7 | import android.graphics.Typeface;
8 | import android.graphics.drawable.Drawable;
9 | import android.os.Build;
10 | import android.text.util.Linkify;
11 | import android.util.SparseArray;
12 | import android.view.LayoutInflater;
13 | import android.view.View;
14 | import android.view.ViewGroup;
15 | import android.view.animation.AlphaAnimation;
16 | import android.widget.Checkable;
17 | import android.widget.ImageView;
18 | import android.widget.ProgressBar;
19 | import android.widget.RatingBar;
20 | import android.widget.TextView;
21 |
22 | /**
23 | * 以前的做法是这样子的
24 | * viewHolder = new ViewHolder();
25 | * convertView = layoutInflater.inflate(R.layout.people_list_item, null, false);
26 | * viewHolder.checkBox = (CheckBox)convertView.findViewById(R.id.checkBox);
27 | * viewHolder.name = (TextView)convertView.findViewById(R.id.name);
28 | * 缺点,如果我们换了一个Item,我们就需要在ViewHolder中从新添加对应空间的变量
29 | * 也就需要重写viewHolder,
30 | * 因此这里用了一个通用的方法,就是在viewHolder中用一个类似于map的键值来保存findViewById对象,
31 | * 这种比先前还有一个好处就是,不管多少条Item,Item中的每个控件只会被findViewById一次
32 | * 以前的方法,当前页面缓存的个数4个,然后内存中对每个控件都是对应4个,也就是findViewById4次,如果屏幕较大就会越来越多
33 | * 以后一个项目几十个Adapter一个ViewHolder直接hold住全场
34 | *
35 | * @ Author: qiyue (ustory)
36 | * @ Email: qiyuekoon@foxmail.com
37 | * @ Data:2016/3/6
38 | */
39 | public class ViewHolder {
40 | private SparseArray
> o) {
122 | mCountryList.clear();
123 | mCountryList.addAll(o.getData());
124 |
125 | mCountryShowList = (ArrayList