Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Side by Side Diff: libadblockplus-android-webviewapp/src/org/adblockplus/libadblockplus/android/webviewapp/SettingsActivity.java

Issue 29361445: Issue 4399 - Add WebView inheritor with ad blocking (Closed)
Patch Set: fixed 2 more members in AdblockEngine Created Dec. 16, 2016, 8:31 a.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
OLDNEW
(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.Utils;
26 import org.adblockplus.libadblockplus.android.settings.Adblock;
27 import org.adblockplus.libadblockplus.android.settings.AdblockGeneralSettingsFra gment;
28 import org.adblockplus.libadblockplus.android.settings.AdblockSettings;
29 import org.adblockplus.libadblockplus.android.settings.AdblockSettingsFragment;
30 import org.adblockplus.libadblockplus.android.settings.AdblockSettingsStorage;
31 import org.adblockplus.libadblockplus.android.settings.AdblockWhitelistedDomains SettingsFragment;
32
33 public class SettingsActivity
34 extends PreferenceActivity
35 implements
36 AdblockGeneralSettingsFragment.Provider,
37 AdblockGeneralSettingsFragment.Listener,
38 AdblockWhitelistedDomainsSettingsFragment.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 Adblock.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 AdblockGeneralSettingsFragment.newInstance())
58 .commit();
59 }
60
61 private void insertWhitelistedFragment()
62 {
63 getFragmentManager()
64 .beginTransaction()
65 .replace(
66 android.R.id.content,
67 AdblockWhitelistedDomainsSettingsFragment.newInstance())
68 .addToBackStack(AdblockWhitelistedDomainsSettingsFragment.class.getSimpleN ame())
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 Adblock.get().waitForReady();
79 return Adblock.get().getEngine();
80 }
81
82 @Override
83 public AdblockSettingsStorage getAdblockSettingsStorage()
84 {
85 return Adblock.get().getStorage();
86 }
87
88 // listener
89
90 @Override
91 public void onAdblockSettingsChanged(AdblockSettingsFragment fragment)
92 {
93 Log.d(TAG, "Adblock setting changed:\n" + fragment.getSettings().toString()) ;
94 }
95
96 @Override
97 public void onWhitelistedDomainsClicked(AdblockGeneralSettingsFragment fragmen t)
98 {
99 insertWhitelistedFragment();
100 }
101
102 @Override
103 public boolean isValidDomain(AdblockWhitelistedDomainsSettingsFragment fragmen t,
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 Adblock.get().release();
116 }
117 }
OLDNEW

Powered by Google App Engine
This is Rietveld