OLD | NEW |
(Empty) | |
| 1 /* |
| 2 * This file is part of Adblock Plus <https://adblockplus.org/>, |
| 3 * Copyright (C) 2006-2016 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.libadblockplus.android.webviewapp; |
| 19 |
| 20 import android.os.Bundle; |
| 21 import android.preference.PreferenceActivity; |
| 22 import android.util.Log; |
| 23 |
| 24 import org.adblockplus.libadblockplus.android.AdblockEngine; |
| 25 import org.adblockplus.libadblockplus.android.settings.AdblockHelper; |
| 26 import org.adblockplus.libadblockplus.android.Utils; |
| 27 import org.adblockplus.libadblockplus.android.settings.GeneralSettingsFragment; |
| 28 import org.adblockplus.libadblockplus.android.settings.AdblockSettings; |
| 29 import org.adblockplus.libadblockplus.android.settings.BaseSettingsFragment; |
| 30 import org.adblockplus.libadblockplus.android.settings.AdblockSettingsStorage; |
| 31 import org.adblockplus.libadblockplus.android.settings.WhitelistedDomainsSetting
sFragment; |
| 32 |
| 33 public class SettingsActivity |
| 34 extends PreferenceActivity |
| 35 implements |
| 36 BaseSettingsFragment.Provider, |
| 37 GeneralSettingsFragment.Listener, |
| 38 WhitelistedDomainsSettingsFragment.Listener |
| 39 { |
| 40 private static final String TAG = Utils.getTag(SettingsActivity.class); |
| 41 |
| 42 @Override |
| 43 protected void onCreate(Bundle savedInstanceState) |
| 44 { |
| 45 super.onCreate(savedInstanceState); |
| 46 AdblockHelper.get().retain(MainActivity.ADBLOCKENGINE_RETAIN_ASYNC); |
| 47 |
| 48 insertGeneralFragment(); |
| 49 } |
| 50 |
| 51 private void insertGeneralFragment() |
| 52 { |
| 53 getFragmentManager() |
| 54 .beginTransaction() |
| 55 .replace( |
| 56 android.R.id.content, |
| 57 GeneralSettingsFragment.newInstance()) |
| 58 .commit(); |
| 59 } |
| 60 |
| 61 private void insertWhitelistedFragment() |
| 62 { |
| 63 getFragmentManager() |
| 64 .beginTransaction() |
| 65 .replace( |
| 66 android.R.id.content, |
| 67 WhitelistedDomainsSettingsFragment.newInstance()) |
| 68 .addToBackStack(WhitelistedDomainsSettingsFragment.class.getSimpleName()) |
| 69 .commit(); |
| 70 } |
| 71 |
| 72 // provider |
| 73 |
| 74 @Override |
| 75 public AdblockEngine getAdblockEngine() |
| 76 { |
| 77 // if it's retained asynchronously we have to wait until it's ready |
| 78 AdblockHelper.get().waitForReady(); |
| 79 return AdblockHelper.get().getEngine(); |
| 80 } |
| 81 |
| 82 @Override |
| 83 public AdblockSettingsStorage getAdblockSettingsStorage() |
| 84 { |
| 85 return AdblockHelper.get().getStorage(); |
| 86 } |
| 87 |
| 88 // listener |
| 89 |
| 90 @Override |
| 91 public void onAdblockSettingsChanged(BaseSettingsFragment fragment) |
| 92 { |
| 93 Log.d(TAG, "AdblockHelper setting changed:\n" + fragment.getSettings().toStr
ing()); |
| 94 } |
| 95 |
| 96 @Override |
| 97 public void onWhitelistedDomainsClicked(GeneralSettingsFragment fragment) |
| 98 { |
| 99 insertWhitelistedFragment(); |
| 100 } |
| 101 |
| 102 @Override |
| 103 public boolean isValidDomain(WhitelistedDomainsSettingsFragment fragment, |
| 104 String domain, |
| 105 AdblockSettings settings) |
| 106 { |
| 107 // show error here if domain is invalid |
| 108 return domain != null && domain.length() > 0; |
| 109 } |
| 110 |
| 111 @Override |
| 112 protected void onDestroy() |
| 113 { |
| 114 super.onDestroy(); |
| 115 AdblockHelper.get().release(); |
| 116 } |
| 117 } |
OLD | NEW |