2016-11-11 16:32:16 +00:00
|
|
|
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/>.
|
|
|
|
|
2018-12-31 16:12:49 +00:00
|
|
|
Copyright 2015-2019 by Marcel Bokhorst (M66B)
|
2016-11-11 16:32:16 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
import android.annotation.TargetApi;
|
|
|
|
import android.content.SharedPreferences;
|
2017-06-30 12:41:38 +00:00
|
|
|
import android.graphics.drawable.Icon;
|
2016-11-11 16:32:16 +00:00
|
|
|
import android.os.Build;
|
|
|
|
import android.service.quicksettings.Tile;
|
|
|
|
import android.service.quicksettings.TileService;
|
|
|
|
import android.util.Log;
|
2017-04-11 05:49:28 +00:00
|
|
|
import android.widget.Toast;
|
2016-11-11 16:32:16 +00:00
|
|
|
|
2020-01-09 18:24:55 +00:00
|
|
|
import androidx.preference.PreferenceManager;
|
|
|
|
|
2016-11-11 16:32:16 +00:00
|
|
|
@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);
|
2017-06-30 12:41:38 +00:00
|
|
|
tile.setIcon(Icon.createWithResource(this, filter ? R.drawable.ic_filter_list_white_24dp : R.drawable.ic_filter_list_white_24dp_60));
|
2016-11-11 16:32:16 +00:00
|
|
|
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");
|
|
|
|
|
2017-04-11 05:49:28 +00:00
|
|
|
if (Util.canFilter(this)) {
|
|
|
|
if (IAB.isPurchased(ActivityPro.SKU_FILTER, this)) {
|
|
|
|
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
|
2017-04-08 06:30:42 +00:00
|
|
|
prefs.edit().putBoolean("filter", !prefs.getBoolean("filter", false)).apply();
|
2017-07-22 12:48:00 +00:00
|
|
|
ServiceSinkhole.reload("tile", this, false);
|
2017-04-11 05:49:28 +00:00
|
|
|
} else
|
2019-08-04 13:47:38 +00:00
|
|
|
Toast.makeText(this, R.string.title_pro_feature, Toast.LENGTH_SHORT).show();
|
2016-11-11 16:32:16 +00:00
|
|
|
} else
|
2017-04-11 05:49:28 +00:00
|
|
|
Toast.makeText(this, R.string.msg_unavailable, Toast.LENGTH_SHORT).show();
|
2016-11-11 16:32:16 +00:00
|
|
|
}
|
|
|
|
}
|