mirror of
https://github.com/M66B/NetGuard.git
synced 2025-02-24 07:10:50 +00:00
Added settings tile to enable/disable filtering
This commit is contained in:
parent
6af9e80925
commit
d282fa3e77
3 changed files with 87 additions and 1 deletions
|
@ -183,6 +183,16 @@
|
|||
</intent-filter>
|
||||
</service>
|
||||
|
||||
<service
|
||||
android:name=".ServiceTileFilter"
|
||||
android:icon="@drawable/ic_filter_list_white_24dp"
|
||||
android:label="@string/setting_filter"
|
||||
android:permission="android.permission.BIND_QUICK_SETTINGS_TILE">
|
||||
<intent-filter>
|
||||
<action android:name="android.service.quicksettings.action.QS_TILE" />
|
||||
</intent-filter>
|
||||
</service>
|
||||
|
||||
<receiver
|
||||
android:name=".Receiver"
|
||||
android:label="@string/app_name">
|
||||
|
|
|
@ -609,10 +609,11 @@ public class ActivitySettings extends AppCompatActivity implements SharedPrefere
|
|||
dialogFilter.show();
|
||||
} else if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP && !prefs.getBoolean(name, false)) {
|
||||
prefs.edit().putBoolean(name, true).apply();
|
||||
((TwoStatePreference) getPreferenceScreen().findPreference(name)).setChecked(true);
|
||||
Toast.makeText(ActivitySettings.this, R.string.msg_filter4, Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
|
||||
((TwoStatePreference) getPreferenceScreen().findPreference(name)).setChecked(prefs.getBoolean(name, false));
|
||||
|
||||
ServiceSinkhole.reload("changed " + name, this);
|
||||
|
||||
} else if ("use_hosts".equals(name))
|
||||
|
|
|
@ -0,0 +1,75 @@
|
|||
package eu.faircode.netguard;
|
||||
|
||||
/*
|
||||
This file is part of NetGuard.
|
||||
|
||||
NetGuard is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
NetGuard is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with NetGuard. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
Copyright 2015-2016 by Marcel Bokhorst (M66B)
|
||||
*/
|
||||
|
||||
|
||||
import android.annotation.TargetApi;
|
||||
import android.content.Intent;
|
||||
import android.content.SharedPreferences;
|
||||
import android.os.Build;
|
||||
import android.preference.PreferenceManager;
|
||||
import android.service.quicksettings.Tile;
|
||||
import android.service.quicksettings.TileService;
|
||||
import android.util.Log;
|
||||
|
||||
@TargetApi(Build.VERSION_CODES.N)
|
||||
public class ServiceTileFilter extends TileService implements SharedPreferences.OnSharedPreferenceChangeListener {
|
||||
private static final String TAG = "NetGuard.TileFilter";
|
||||
|
||||
public void onStartListening() {
|
||||
Log.i(TAG, "Start listening");
|
||||
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
|
||||
prefs.registerOnSharedPreferenceChangeListener(this);
|
||||
update();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSharedPreferenceChanged(SharedPreferences prefs, String key) {
|
||||
if ("filter".equals(key))
|
||||
update();
|
||||
}
|
||||
|
||||
private void update() {
|
||||
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
|
||||
boolean filter = prefs.getBoolean("filter", false);
|
||||
Tile tile = getQsTile();
|
||||
if (tile != null) {
|
||||
tile.setState(filter ? Tile.STATE_ACTIVE : Tile.STATE_INACTIVE);
|
||||
tile.updateTile();
|
||||
}
|
||||
}
|
||||
|
||||
public void onStopListening() {
|
||||
Log.i(TAG, "Stop listening");
|
||||
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
|
||||
prefs.unregisterOnSharedPreferenceChangeListener(this);
|
||||
}
|
||||
|
||||
public void onClick() {
|
||||
Log.i(TAG, "Click");
|
||||
|
||||
if (IAB.isPurchased(ActivityPro.SKU_FILTER, this)) {
|
||||
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
|
||||
prefs.edit().putBoolean("filter", !prefs.getBoolean("filter", false)).apply();
|
||||
ServiceSinkhole.reload("tile", this);
|
||||
} else
|
||||
startActivity(new Intent(this, ActivityPro.class));
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue