Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Side by Side Diff: src/org/adblockplus/android/RefreshableListPreference.java

Issue 5697499218051072: Usage of new API, cleanups (reduced) (Closed)
Patch Set: Created April 11, 2014, 1:31 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * This file is part of Adblock Plus <http://adblockplus.org/>, 2 * This file is part of Adblock Plus <http://adblockplus.org/>,
3 * Copyright (C) 2006-2014 Eyeo GmbH 3 * Copyright (C) 2006-2014 Eyeo GmbH
4 * 4 *
5 * Adblock Plus is free software: you can redistribute it and/or modify 5 * Adblock Plus is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 3 as 6 * it under the terms of the GNU General Public License version 3 as
7 * published by the Free Software Foundation. 7 * published by the Free Software Foundation.
8 * 8 *
9 * Adblock Plus is distributed in the hope that it will be useful, 9 * Adblock Plus is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
(...skipping 15 matching lines...) Expand all
26 import android.widget.ImageView; 26 import android.widget.ImageView;
27 import android.widget.LinearLayout; 27 import android.widget.LinearLayout;
28 28
29 /** 29 /**
30 * ListPreference UI with refresh button. 30 * ListPreference UI with refresh button.
31 */ 31 */
32 public class RefreshableListPreference extends ListPreference 32 public class RefreshableListPreference extends ListPreference
33 { 33 {
34 private OnClickListener refreshClickListener; 34 private OnClickListener refreshClickListener;
35 35
36 public RefreshableListPreference(Context context, AttributeSet attrs) 36 public RefreshableListPreference(final Context context, final AttributeSet att rs)
37 { 37 {
38 super(context, attrs); 38 super(context, attrs);
39 } 39 }
40 40
41 @Override 41 @Override
42 protected void onBindView(View view) 42 protected void onBindView(final View view)
43 { 43 {
44 super.onBindView(view); 44 super.onBindView(view);
45 final ImageView refreshImage = new ImageView(getContext()); 45 final ImageView refreshImage = new ImageView(this.getContext());
46 ViewGroup widgetFrameView = ((ViewGroup) view.findViewById(android.R.id.widg et_frame)); 46 final ViewGroup widgetFrameView = ((ViewGroup)view.findViewById(android.R.id .widget_frame));
47 if (widgetFrameView == null) 47 if (widgetFrameView == null)
48 {
48 return; 49 return;
50 }
49 widgetFrameView.setVisibility(View.VISIBLE); 51 widgetFrameView.setVisibility(View.VISIBLE);
50 int rightPaddingDip = android.os.Build.VERSION.SDK_INT < 14 ? 8 : 5; 52 final int rightPaddingDip = android.os.Build.VERSION.SDK_INT < 14 ? 8 : 5;
51 float density = getContext().getResources().getDisplayMetrics().density; 53 final float density = this.getContext().getResources().getDisplayMetrics().d ensity;
52 if (widgetFrameView instanceof LinearLayout) 54 if (widgetFrameView instanceof LinearLayout)
53 { 55 {
54 ((LinearLayout) widgetFrameView).setOrientation(LinearLayout.HORIZONTAL); 56 ((LinearLayout)widgetFrameView).setOrientation(LinearLayout.HORIZONTAL);
55 } 57 }
56 widgetFrameView.addView(refreshImage, 0); 58 widgetFrameView.addView(refreshImage, 0);
57 refreshImage.setImageResource(R.drawable.ic_menu_refresh); 59 refreshImage.setImageResource(R.drawable.ic_menu_refresh);
58 refreshImage.setPadding(refreshImage.getPaddingLeft(), refreshImage.getPaddi ngTop(), (int) (density * rightPaddingDip), refreshImage.getPaddingBottom()); 60 refreshImage.setPadding(refreshImage.getPaddingLeft(), refreshImage.getPaddi ngTop(), (int)(density * rightPaddingDip),
61 refreshImage.getPaddingBottom());
59 refreshImage.setOnClickListener(new OnClickListener() 62 refreshImage.setOnClickListener(new OnClickListener()
60 { 63 {
61 @Override 64 @Override
62 public void onClick(View v) 65 public void onClick(final View v)
63 { 66 {
64 if (refreshClickListener != null) 67 if (RefreshableListPreference.this.refreshClickListener != null)
65 refreshClickListener.onClick(refreshImage); 68 {
69 RefreshableListPreference.this.refreshClickListener.onClick(refreshIma ge);
70 }
66 } 71 }
67 }); 72 });
68 } 73 }
69 74
70 public void setOnRefreshClickListener(OnClickListener l) 75 public void setOnRefreshClickListener(final OnClickListener l)
71 { 76 {
72 refreshClickListener = l; 77 this.refreshClickListener = l;
73 } 78 }
74 } 79 }
OLDNEW

Powered by Google App Engine
This is Rietveld