| OLD | NEW |
| 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 17 matching lines...) Expand all Loading... |
| 28 import android.widget.ImageView; | 28 import android.widget.ImageView; |
| 29 import android.widget.LinearLayout; | 29 import android.widget.LinearLayout; |
| 30 | 30 |
| 31 import org.adblockplus.android.R; | 31 import org.adblockplus.android.R; |
| 32 | 32 |
| 33 public class HelpfulCheckBoxPreference extends CheckBoxPreference | 33 public class HelpfulCheckBoxPreference extends CheckBoxPreference |
| 34 { | 34 { |
| 35 private OnClickListener helpClickListener; | 35 private OnClickListener helpClickListener; |
| 36 private String url; | 36 private String url; |
| 37 | 37 |
| 38 public HelpfulCheckBoxPreference(Context context, AttributeSet attrs) | 38 public HelpfulCheckBoxPreference(final Context context, final AttributeSet att
rs) |
| 39 { | 39 { |
| 40 super(context, attrs); | 40 super(context, attrs); |
| 41 } | 41 } |
| 42 | 42 |
| 43 @Override | 43 @Override |
| 44 protected void onBindView(View view) | 44 protected void onBindView(final View view) |
| 45 { | 45 { |
| 46 super.onBindView(view); | 46 super.onBindView(view); |
| 47 | 47 |
| 48 final ImageView helpImage = new ImageView(getContext()); | 48 final ImageView helpImage = new ImageView(this.getContext()); |
| 49 final ViewGroup widgetFrameView = ((ViewGroup) view.findViewById(android.R.i
d.widget_frame)); | 49 final ViewGroup widgetFrameView = ((ViewGroup)view.findViewById(android.R.id
.widget_frame)); |
| 50 if (widgetFrameView == null) | 50 if (widgetFrameView == null) |
| 51 { |
| 51 return; | 52 return; |
| 53 } |
| 52 widgetFrameView.setVisibility(View.VISIBLE); | 54 widgetFrameView.setVisibility(View.VISIBLE); |
| 53 final int rightPaddingDip = android.os.Build.VERSION.SDK_INT < 14 ? 8 : 5; | 55 final int rightPaddingDip = android.os.Build.VERSION.SDK_INT < 14 ? 8 : 5; |
| 54 final float mDensity = getContext().getResources().getDisplayMetrics().densi
ty; | 56 final float mDensity = this.getContext().getResources().getDisplayMetrics().
density; |
| 55 if (widgetFrameView instanceof LinearLayout) | 57 if (widgetFrameView instanceof LinearLayout) |
| 56 { | 58 { |
| 57 ((LinearLayout) widgetFrameView).setOrientation(LinearLayout.HORIZONTAL); | 59 ((LinearLayout)widgetFrameView).setOrientation(LinearLayout.HORIZONTAL); |
| 58 } | 60 } |
| 59 widgetFrameView.addView(helpImage, 0); | 61 widgetFrameView.addView(helpImage, 0); |
| 60 helpImage.setImageResource(R.drawable.ic_menu_help); | 62 helpImage.setImageResource(R.drawable.ic_menu_help); |
| 61 helpImage.setPadding(helpImage.getPaddingLeft(), helpImage.getPaddingTop(),
(int) (mDensity * rightPaddingDip), helpImage.getPaddingBottom()); | 63 helpImage.setPadding(helpImage.getPaddingLeft(), helpImage.getPaddingTop(),
(int)(mDensity * rightPaddingDip), helpImage.getPaddingBottom()); |
| 62 helpImage.setOnClickListener(new OnClickListener() | 64 helpImage.setOnClickListener(new OnClickListener() |
| 63 { | 65 { |
| 64 @Override | 66 @Override |
| 65 public void onClick(View v) | 67 public void onClick(final View v) |
| 66 { | 68 { |
| 67 if (helpClickListener != null) | 69 if (HelpfulCheckBoxPreference.this.helpClickListener != null) |
| 68 { | 70 { |
| 69 helpClickListener.onClick(helpImage); | 71 HelpfulCheckBoxPreference.this.helpClickListener.onClick(helpImage); |
| 70 } | 72 } |
| 71 else if (url != null) | 73 else if (HelpfulCheckBoxPreference.this.url != null) |
| 72 { | 74 { |
| 73 Uri uri = Uri.parse(url); | 75 final Uri uri = Uri.parse(HelpfulCheckBoxPreference.this.url); |
| 74 Intent intent = new Intent(Intent.ACTION_VIEW, uri); | 76 final Intent intent = new Intent(Intent.ACTION_VIEW, uri); |
| 75 HelpfulCheckBoxPreference.this.getContext().startActivity(intent); | 77 HelpfulCheckBoxPreference.this.getContext().startActivity(intent); |
| 76 } | 78 } |
| 77 } | 79 } |
| 78 }); | 80 }); |
| 79 } | 81 } |
| 80 | 82 |
| 81 public void setOnHelpClickListener(OnClickListener l) | 83 public void setOnHelpClickListener(final OnClickListener l) |
| 82 { | 84 { |
| 83 helpClickListener = l; | 85 this.helpClickListener = l; |
| 84 } | 86 } |
| 85 | 87 |
| 86 public void setHelpUrl(String url) | 88 public void setHelpUrl(final String url) |
| 87 { | 89 { |
| 88 this.url = url; | 90 this.url = url; |
| 89 } | 91 } |
| 90 } | 92 } |
| OLD | NEW |