| 1 | /* |
|---|
| 2 | * This file is part of Adblock Plus <https://adblockplus.org/>, |
|---|
| 3 | * Copyright (C) 2006-2015 Eyeo GmbH |
|---|
| 4 | * |
|---|
| 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 |
|---|
| 7 | * published by the Free Software Foundation. |
|---|
| 8 | * |
|---|
| 9 | * Adblock Plus is distributed in the hope that it will be useful, |
|---|
| 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|---|
| 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|---|
| 12 | * GNU General Public License for more details. |
|---|
| 13 | * |
|---|
| 14 | * You should have received a copy of the GNU General Public License |
|---|
| 15 | * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. |
|---|
| 16 | */ |
|---|
| 17 | |
|---|
| 18 | package org.adblockplus.android; |
|---|
| 19 | |
|---|
| 20 | import android.content.Context; |
|---|
| 21 | import android.content.Intent; |
|---|
| 22 | import android.net.Uri; |
|---|
| 23 | import android.preference.CheckBoxPreference; |
|---|
| 24 | import android.util.AttributeSet; |
|---|
| 25 | import android.view.View; |
|---|
| 26 | import android.view.View.OnClickListener; |
|---|
| 27 | import android.widget.ImageView; |
|---|
| 28 | |
|---|
| 29 | import org.adblockplus.android.R; |
|---|
| 30 | |
|---|
| 31 | public class HelpfulCheckBoxPreference extends CheckBoxPreference |
|---|
| 32 | { |
|---|
| 33 | private OnClickListener helpClickListener; |
|---|
| 34 | private String url; |
|---|
| 35 | |
|---|
| 36 | public HelpfulCheckBoxPreference(final Context context, final AttributeSet attrs) |
|---|
| 37 | { |
|---|
| 38 | super(context, attrs); |
|---|
| 39 | } |
|---|
| 40 | |
|---|
| 41 | @Override |
|---|
| 42 | protected void onBindView(final View view) |
|---|
| 43 | { |
|---|
| 44 | super.onBindView(view); |
|---|
| 45 | |
|---|
| 46 | final ImageView helpImage = (ImageView) view.findViewById(R.id.menu_help); |
|---|
| 47 | |
|---|
| 48 | helpImage.setOnClickListener(new OnClickListener() |
|---|
| 49 | { |
|---|
| 50 | @Override |
|---|
| 51 | public void onClick(final View v) |
|---|
| 52 | { |
|---|
| 53 | if (helpClickListener != null) |
|---|
| 54 | { |
|---|
| 55 | helpClickListener.onClick(helpImage); |
|---|
| 56 | } |
|---|
| 57 | else if (url != null) |
|---|
| 58 | { |
|---|
| 59 | final Uri uri = Uri.parse(url); |
|---|
| 60 | final Intent intent = new Intent(Intent.ACTION_VIEW, uri); |
|---|
| 61 | HelpfulCheckBoxPreference.this.getContext().startActivity(intent); |
|---|
| 62 | } |
|---|
| 63 | } |
|---|
| 64 | }); |
|---|
| 65 | } |
|---|
| 66 | |
|---|
| 67 | public void setOnHelpClickListener(final OnClickListener l) |
|---|
| 68 | { |
|---|
| 69 | helpClickListener = l; |
|---|
| 70 | } |
|---|
| 71 | |
|---|
| 72 | public void setHelpUrl(final String url) |
|---|
| 73 | { |
|---|
| 74 | this.url = url; |
|---|
| 75 | } |
|---|
| 76 | } |
|---|