| 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(getContext()); | 
|  49     final ViewGroup widgetFrameView = ((ViewGroup) view.findViewById(android.R.i
    d.widget_frame)); |  49     final ViewGroup widgetFrameView = ((ViewGroup) view.findViewById(android.R.i
    d.widget_frame)); | 
|  50     if (widgetFrameView == null) |  50     if (widgetFrameView == null) | 
|  51       return; |  51       return; | 
|  52     widgetFrameView.setVisibility(View.VISIBLE); |  52     widgetFrameView.setVisibility(View.VISIBLE); | 
|  53     final int rightPaddingDip = android.os.Build.VERSION.SDK_INT < 14 ? 8 : 5; |  53     final int rightPaddingDip = android.os.Build.VERSION.SDK_INT < 14 ? 8 : 5; | 
|  54     final float mDensity = getContext().getResources().getDisplayMetrics().densi
    ty; |  54     final float mDensity = getContext().getResources().getDisplayMetrics().densi
    ty; | 
|  55     if (widgetFrameView instanceof LinearLayout) |  55     if (widgetFrameView instanceof LinearLayout) | 
|  56     { |  56     { | 
|  57       ((LinearLayout) widgetFrameView).setOrientation(LinearLayout.HORIZONTAL); |  57       ((LinearLayout) widgetFrameView).setOrientation(LinearLayout.HORIZONTAL); | 
|  58     } |  58     } | 
|  59     widgetFrameView.addView(helpImage, 0); |  59     widgetFrameView.addView(helpImage, 0); | 
|  60     helpImage.setImageResource(R.drawable.ic_menu_help); |  60     helpImage.setImageResource(R.drawable.ic_menu_help); | 
|  61     helpImage.setPadding(helpImage.getPaddingLeft(), helpImage.getPaddingTop(), 
    (int) (mDensity * rightPaddingDip), helpImage.getPaddingBottom()); |  61     helpImage.setPadding(helpImage.getPaddingLeft(), helpImage.getPaddingTop(), 
    (int) (mDensity * rightPaddingDip), helpImage.getPaddingBottom()); | 
|  62     helpImage.setOnClickListener(new OnClickListener() |  62     helpImage.setOnClickListener(new OnClickListener() | 
|  63     { |  63     { | 
|  64       @Override |  64       @Override | 
|  65       public void onClick(View v) |  65       public void onClick(final View v) | 
|  66       { |  66       { | 
|  67         if (helpClickListener != null) |  67         if (helpClickListener != null) | 
|  68         { |  68         { | 
|  69           helpClickListener.onClick(helpImage); |  69           helpClickListener.onClick(helpImage); | 
|  70         } |  70         } | 
|  71         else if (url != null) |  71         else if (url != null) | 
|  72         { |  72         { | 
|  73           Uri uri = Uri.parse(url); |  73           final Uri uri = Uri.parse(url); | 
|  74           Intent intent = new Intent(Intent.ACTION_VIEW, uri); |  74           final Intent intent = new Intent(Intent.ACTION_VIEW, uri); | 
|  75           HelpfulCheckBoxPreference.this.getContext().startActivity(intent); |  75           HelpfulCheckBoxPreference.this.getContext().startActivity(intent); | 
|  76         } |  76         } | 
|  77       } |  77       } | 
|  78     }); |  78     }); | 
|  79   } |  79   } | 
|  80  |  80  | 
|  81   public void setOnHelpClickListener(OnClickListener l) |  81   public void setOnHelpClickListener(final OnClickListener l) | 
|  82   { |  82   { | 
|  83     helpClickListener = l; |  83     helpClickListener = l; | 
|  84   } |  84   } | 
|  85  |  85  | 
|  86   public void setHelpUrl(String url) |  86   public void setHelpUrl(final String url) | 
|  87   { |  87   { | 
|  88     this.url = url; |  88     this.url = url; | 
|  89   } |  89   } | 
|  90 } |  90 } | 
| OLD | NEW |