Added data saver settings button, caching settings intents

This commit is contained in:
M66B 2016-10-08 15:40:33 +02:00
parent d20a7595ce
commit e295abfffa
14 changed files with 113 additions and 45 deletions

View File

@ -111,12 +111,13 @@ public class AdapterRule extends RecyclerView.Adapter<AdapterRule.ViewHolder> im
public TextView tvDisabled;
public TextView tvStatistics;
public CheckBox cbApply;
public Button btnRelated;
public ImageButton ibSettings;
public ImageButton ibDatasaver;
public ImageButton ibLaunch;
public CheckBox cbApply;
public ImageView ivWifiLegend;
public CheckBox cbScreenWifi;
@ -160,12 +161,13 @@ public class AdapterRule extends RecyclerView.Adapter<AdapterRule.ViewHolder> im
tvDisabled = (TextView) itemView.findViewById(R.id.tvDisabled);
tvStatistics = (TextView) itemView.findViewById(R.id.tvStatistics);
cbApply = (CheckBox) itemView.findViewById(R.id.cbApply);
btnRelated = (Button) itemView.findViewById(R.id.btnRelated);
ibSettings = (ImageButton) itemView.findViewById(R.id.ibSettings);
ibDatasaver = (ImageButton) itemView.findViewById(R.id.ibDatasaver);
ibLaunch = (ImageButton) itemView.findViewById(R.id.ibLaunch);
cbApply = (CheckBox) itemView.findViewById(R.id.cbApply);
ivWifiLegend = (ImageView) itemView.findViewById(R.id.ivWifiLegend);
cbScreenWifi = (CheckBox) itemView.findViewById(R.id.cbScreenWifi);
@ -407,18 +409,6 @@ public class AdapterRule extends RecyclerView.Adapter<AdapterRule.ViewHolder> im
holder.tvStatistics.setVisibility(Build.VERSION.SDK_INT >= Build.VERSION_CODES.N ? View.GONE : View.VISIBLE);
holder.tvStatistics.setText(context.getString(R.string.msg_mbday, rule.upspeed, rule.downspeed));
// Apply
holder.cbApply.setEnabled(rule.pkg);
holder.cbApply.setOnCheckedChangeListener(null);
holder.cbApply.setChecked(rule.apply);
holder.cbApply.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton compoundButton, boolean isChecked) {
rule.apply = isChecked;
updateRule(rule, true, listAll);
}
});
// Show related
holder.btnRelated.setVisibility(rule.relateduids ? View.VISIBLE : View.GONE);
holder.btnRelated.setOnClickListener(new View.OnClickListener() {
@ -431,22 +421,41 @@ public class AdapterRule extends RecyclerView.Adapter<AdapterRule.ViewHolder> im
});
// Launch application settings
final Intent settings = new Intent(android.provider.Settings.ACTION_APPLICATION_DETAILS_SETTINGS);
settings.setData(Uri.parse("package:" + rule.info.packageName));
holder.ibSettings.setVisibility(settings.resolveActivity(context.getPackageManager()) == null ? View.GONE : View.VISIBLE);
holder.ibSettings.setVisibility(rule.settings == null ? View.GONE : View.VISIBLE);
holder.ibSettings.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
context.startActivity(settings);
context.startActivity(rule.settings);
}
});
// Data saver
holder.ibDatasaver.setVisibility(rule.datasaver == null ? View.GONE : View.VISIBLE);
holder.ibDatasaver.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
context.startActivity(rule.datasaver);
}
});
// Launch application
holder.ibLaunch.setVisibility(rule.intent == null ? View.GONE : View.VISIBLE);
holder.ibLaunch.setVisibility(rule.launch == null ? View.GONE : View.VISIBLE);
holder.ibLaunch.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
context.startActivity(rule.intent);
context.startActivity(rule.launch);
}
});
// Apply
holder.cbApply.setEnabled(rule.pkg);
holder.cbApply.setOnCheckedChangeListener(null);
holder.cbApply.setChecked(rule.apply);
holder.cbApply.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton compoundButton, boolean isChecked) {
rule.apply = isChecked;
updateRule(rule, true, listAll);
}
});

View File

@ -27,10 +27,12 @@ import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.content.res.XmlResourceParser;
import android.net.TrafficStats;
import android.net.Uri;
import android.os.Build;
import android.os.Process;
import android.os.SystemClock;
import android.preference.PreferenceManager;
import android.provider.Settings;
import android.util.Log;
import org.xmlpull.v1.XmlPullParser;
@ -54,7 +56,9 @@ public class Rule {
public boolean system;
public boolean internet;
public boolean enabled;
public Intent intent;
public Intent launch;
public Intent settings;
public Intent datasaver;
public boolean pkg = true;
public boolean wifi_default = false;
@ -89,7 +93,9 @@ public class Rule {
private static Map<String, Boolean> cacheSystem = new HashMap<>();
private static Map<String, Boolean> cacheInternet = new HashMap<>();
private static Map<PackageInfo, Boolean> cacheEnabled = new HashMap<>();
private static Map<String, Intent> cacheIntent = new HashMap<>();
private static Map<String, Intent> cacheIntentLaunch = new HashMap<>();
private static Map<String, Intent> cacheIntentSettings = new HashMap<>();
private static Map<String, Intent> cacheIntentDatasaver = new HashMap<>();
private static Map<Integer, String[]> cachePackages = new HashMap<>();
private static List<PackageInfo> getPackages(Context context) {
@ -147,14 +153,44 @@ public class Rule {
}
}
private static Intent getIntent(String packageName, Context context) {
private static Intent getIntentLaunch(String packageName, Context context) {
synchronized (context.getApplicationContext()) {
if (!cacheIntent.containsKey(packageName))
cacheIntent.put(packageName, context.getPackageManager().getLaunchIntentForPackage(packageName));
return cacheIntent.get(packageName);
if (!cacheIntentLaunch.containsKey(packageName))
cacheIntentLaunch.put(packageName, context.getPackageManager().getLaunchIntentForPackage(packageName));
return cacheIntentLaunch.get(packageName);
}
}
private static Intent getIntentSettings(String packageName, Context context) {
synchronized (context.getApplicationContext()) {
if (!cacheIntentSettings.containsKey(packageName)) {
Intent intent = new Intent(android.provider.Settings.ACTION_APPLICATION_DETAILS_SETTINGS);
intent.setData(Uri.parse("package:" + packageName));
if (intent.resolveActivity(context.getPackageManager()) == null)
intent = null;
cacheIntentSettings.put(packageName, intent);
}
return cacheIntentSettings.get(packageName);
}
}
private static Intent getIntentDatasaver(String packageName, Context context) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N)
synchronized (context.getApplicationContext()) {
if (!cacheIntentDatasaver.containsKey(packageName)) {
Intent intent = new Intent(
Settings.ACTION_IGNORE_BACKGROUND_DATA_RESTRICTIONS_SETTINGS,
Uri.parse("package:" + packageName));
if (intent.resolveActivity(context.getPackageManager()) == null)
intent = null;
cacheIntentDatasaver.put(packageName, intent);
}
return cacheIntentDatasaver.get(packageName);
}
else
return null;
}
private static String[] getPackages(int uid, Context context) {
synchronized (context.getApplicationContext()) {
if (!cachePackages.containsKey(uid))
@ -172,7 +208,9 @@ public class Rule {
cacheSystem.clear();
cacheInternet.clear();
cacheEnabled.clear();
cacheIntent.clear();
cacheIntentLaunch.clear();
cacheIntentSettings.clear();
cacheIntentDatasaver.clear();
cachePackages.clear();
}
}
@ -185,7 +223,9 @@ public class Rule {
this.system = true;
this.internet = true;
this.enabled = true;
this.intent = null;
this.launch = null;
this.settings = null;
this.datasaver = null;
this.pkg = false;
} else if (info.applicationInfo.uid == 1013) {
this.name = context.getString(R.string.title_mediaserver);
@ -193,7 +233,9 @@ public class Rule {
this.system = true;
this.internet = true;
this.enabled = true;
this.intent = null;
this.launch = null;
this.settings = null;
this.datasaver = null;
this.pkg = false;
} else if (info.applicationInfo.uid == 9999) {
this.name = context.getString(R.string.title_nobody);
@ -201,7 +243,9 @@ public class Rule {
this.system = true;
this.internet = true;
this.enabled = true;
this.intent = null;
this.launch = null;
this.settings = null;
this.datasaver = null;
this.pkg = false;
} else {
this.name = getLabel(info, context);
@ -209,7 +253,9 @@ public class Rule {
this.system = isSystem(info.packageName, context);
this.internet = hasInternet(info.packageName, context);
this.enabled = isEnabled(info, context);
this.intent = getIntent(info.packageName, context);
this.launch = getIntentLaunch(info.packageName, context);
this.settings = getIntentSettings(info.packageName, context);
this.datasaver = getIntentDatasaver(info.packageName, context);
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 363 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 386 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 262 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 276 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 440 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 485 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 693 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 746 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 846 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 936 B

View File

@ -211,13 +211,6 @@
android:layout_gravity="center_vertical"
android:layout_marginTop="4dp" />
<CheckBox
android:id="@+id/cbApply"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="4dp"
android:text="@string/title_apply" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
@ -233,11 +226,23 @@
android:layout_marginRight="8dp"
android:text="@string/title_related" />
<ImageButton
android:id="@+id/ibDatasaver"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginEnd="8dp"
android:layout_marginRight="8dp"
android:src="?attr/iconDatasaver"
android:visibility="gone" />
<ImageButton
android:id="@+id/ibSettings"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginEnd="8dp"
android:layout_marginRight="8dp"
android:src="?attr/iconSettings" />
<ImageButton
@ -245,11 +250,16 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginLeft="8dp"
android:layout_marginStart="8dp"
android:src="?attr/iconLaunch" />
</LinearLayout>
<CheckBox
android:id="@+id/cbApply"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="4dp"
android:text="@string/title_apply" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"

View File

@ -5,8 +5,9 @@
<attr name="iconQueue" format="reference" />
<attr name="iconMetered" format="reference" />
<attr name="iconSettings" format="reference" />
<attr name="iconDelete" format="reference" />
<attr name="iconDatasaver" format="reference" />
<attr name="iconLaunch" format="reference" />
<attr name="iconDelete" format="reference" />
<style name="AppDialog" parent="Theme.AppCompat.Dialog">
<item name="windowActionBar">false</item>
@ -18,8 +19,9 @@
<item name="iconQueue">@drawable/ic_hourglass_empty_black_24dp</item>
<item name="iconMetered">@drawable/ic_attach_money_black_24dp</item>
<item name="iconSettings">@drawable/ic_settings_black_24dp</item>
<item name="iconDelete">@drawable/ic_delete_black_24dp</item>
<item name="iconDatasaver">@drawable/ic_perm_data_setting_black_24dp</item>
<item name="iconLaunch">@drawable/ic_launch_black_24dp</item>
<item name="iconDelete">@drawable/ic_delete_black_24dp</item>
<item name="android:windowDisablePreview">true</item>
</style>
@ -28,8 +30,9 @@
<item name="iconQueue">@drawable/ic_hourglass_empty_white_24dp</item>
<item name="iconMetered">@drawable/ic_attach_money_white_24dp</item>
<item name="iconSettings">@drawable/ic_settings_white_24dp</item>
<item name="iconDelete">@drawable/ic_delete_white_24dp</item>
<item name="iconDatasaver">@drawable/ic_perm_data_setting_white_24dp</item>
<item name="iconLaunch">@drawable/ic_launch_white_24dp</item>
<item name="iconDelete">@drawable/ic_delete_white_24dp</item>
<item name="android:windowDisablePreview">true</item>
</style>