2016-07-10 11:06:09 +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/>.
|
|
|
|
|
2016-12-29 08:27:58 +00:00
|
|
|
Copyright 2015-2017 by Marcel Bokhorst (M66B)
|
2016-07-10 11:06:09 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
import android.annotation.TargetApi;
|
2016-07-23 06:48:29 +00:00
|
|
|
import android.content.Intent;
|
2016-07-10 11:06:09 +00:00
|
|
|
import android.content.SharedPreferences;
|
2017-06-30 12:41:38 +00:00
|
|
|
import android.graphics.drawable.Icon;
|
2016-07-10 11:06:09 +00:00
|
|
|
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)
|
2016-07-22 05:59:12 +00:00
|
|
|
public class ServiceTileGraph extends TileService implements SharedPreferences.OnSharedPreferenceChangeListener {
|
|
|
|
private static final String TAG = "NetGuard.TileGraph";
|
2016-07-10 11:06:09 +00:00
|
|
|
|
|
|
|
public void onStartListening() {
|
|
|
|
Log.i(TAG, "Start listening");
|
|
|
|
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
|
|
|
|
prefs.registerOnSharedPreferenceChangeListener(this);
|
2016-07-23 06:39:57 +00:00
|
|
|
update();
|
2016-07-10 11:06:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onSharedPreferenceChanged(SharedPreferences prefs, String key) {
|
2016-07-23 06:39:57 +00:00
|
|
|
if ("show_stats".equals(key))
|
|
|
|
update();
|
|
|
|
}
|
|
|
|
|
|
|
|
private void update() {
|
|
|
|
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
|
|
|
|
boolean stats = prefs.getBoolean("show_stats", false);
|
2016-09-12 14:21:59 +00:00
|
|
|
Tile tile = getQsTile();
|
|
|
|
if (tile != null) {
|
|
|
|
tile.setState(stats ? Tile.STATE_ACTIVE : Tile.STATE_INACTIVE);
|
2017-06-30 12:41:38 +00:00
|
|
|
tile.setIcon(Icon.createWithResource(this, stats ? R.drawable.ic_equalizer_white_24dp : R.drawable.ic_equalizer_white_24dp_60));
|
2016-09-12 14:21:59 +00:00
|
|
|
tile.updateTile();
|
|
|
|
}
|
2016-07-10 11:06:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public void onStopListening() {
|
|
|
|
Log.i(TAG, "Stop listening");
|
|
|
|
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
|
|
|
|
prefs.unregisterOnSharedPreferenceChangeListener(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void onClick() {
|
|
|
|
Log.i(TAG, "Click");
|
2016-07-19 11:30:48 +00:00
|
|
|
|
|
|
|
// Check state
|
2016-07-10 11:06:09 +00:00
|
|
|
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
|
2016-07-22 05:59:12 +00:00
|
|
|
boolean stats = !prefs.getBoolean("show_stats", false);
|
2016-07-23 06:48:29 +00:00
|
|
|
if (stats && !IAB.isPurchased(ActivityPro.SKU_SPEED, this))
|
|
|
|
startActivity(new Intent(this, ActivityPro.class));
|
|
|
|
else
|
|
|
|
prefs.edit().putBoolean("show_stats", stats).apply();
|
2016-07-22 05:59:12 +00:00
|
|
|
ServiceSinkhole.reloadStats("tile", this);
|
2016-07-10 11:06:09 +00:00
|
|
|
}
|
|
|
|
}
|