| OLD | NEW |
| (Empty) |
| 1 /* | |
| 2 * This file is part of Adblock Plus <https://adblockplus.org/>, | |
| 3 * Copyright (C) 2006-present 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 | |
| 47 // retaining AdblockEngine asynchronously | |
| 48 AdblockHelper.get().getProvider().retain(true); | |
| 49 | |
| 50 insertGeneralFragment(); | |
| 51 } | |
| 52 | |
| 53 private void insertGeneralFragment() | |
| 54 { | |
| 55 getFragmentManager() | |
| 56 .beginTransaction() | |
| 57 .replace( | |
| 58 android.R.id.content, | |
| 59 GeneralSettingsFragment.newInstance()) | |
| 60 .commit(); | |
| 61 } | |
| 62 | |
| 63 private void insertWhitelistedFragment() | |
| 64 { | |
| 65 getFragmentManager() | |
| 66 .beginTransaction() | |
| 67 .replace( | |
| 68 android.R.id.content, | |
| 69 WhitelistedDomainsSettingsFragment.newInstance()) | |
| 70 .addToBackStack(WhitelistedDomainsSettingsFragment.class.getSimpleName()) | |
| 71 .commit(); | |
| 72 } | |
| 73 | |
| 74 // provider | |
| 75 | |
| 76 @Override | |
| 77 public AdblockEngine getAdblockEngine() | |
| 78 { | |
| 79 // if it's retained asynchronously we have to wait until it's ready | |
| 80 AdblockHelper.get().getProvider().waitForReady(); | |
| 81 return AdblockHelper.get().getProvider().getEngine(); | |
| 82 } | |
| 83 | |
| 84 @Override | |
| 85 public AdblockSettingsStorage getAdblockSettingsStorage() | |
| 86 { | |
| 87 return AdblockHelper.get().getStorage(); | |
| 88 } | |
| 89 | |
| 90 // listener | |
| 91 | |
| 92 @Override | |
| 93 public void onAdblockSettingsChanged(BaseSettingsFragment fragment) | |
| 94 { | |
| 95 Log.d(TAG, "AdblockHelper setting changed:\n" + fragment.getSettings().toStr
ing()); | |
| 96 } | |
| 97 | |
| 98 @Override | |
| 99 public void onWhitelistedDomainsClicked(GeneralSettingsFragment fragment) | |
| 100 { | |
| 101 insertWhitelistedFragment(); | |
| 102 } | |
| 103 | |
| 104 @Override | |
| 105 public boolean isValidDomain(WhitelistedDomainsSettingsFragment fragment, | |
| 106 String domain, | |
| 107 AdblockSettings settings) | |
| 108 { | |
| 109 // show error here if domain is invalid | |
| 110 return domain != null && domain.length() > 0; | |
| 111 } | |
| 112 | |
| 113 @Override | |
| 114 protected void onDestroy() | |
| 115 { | |
| 116 super.onDestroy(); | |
| 117 AdblockHelper.get().getProvider().release(); | |
| 118 } | |
| 119 } | |
| OLD | NEW |