Skip to content
This repository has been archived by the owner on Sep 6, 2019. It is now read-only.

Commit

Permalink
Added template for on demand restricting
Browse files Browse the repository at this point in the history
Closes #1376
Refs #1395
  • Loading branch information
M66B committed Feb 20, 2014
1 parent 0dc94bd commit 12a6e73
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 17 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ Changelog
* Fixed select/unselect all ([issue](/../../issues/1390))
* Fixed some more repeated asking on demand, thanks @[jpeg729](https://github.com/jpeg729)
* Improved tutorial/info background ([issue](/../../issues/1391))
* Added template for on demand restricting, thanks @[jpeg729](https://github.com/jpeg729) ([issue](/../../issues/1376))
* Updated German translation
* Updated French translation
* Updated Lithuanian translation
Expand Down
10 changes: 5 additions & 5 deletions res/layout/templateentry.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal" >
android:orientation="horizontal"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin" >

<TextView
android:id="@+id/tvRestriction"
android:layout_width="0dip"
android:layout_height="?android:attr/listPreferredItemHeightSmall"
android:gravity="center_vertical"
android:layout_height="?android:attr/listPreferredItemHeightSmall"
android:layout_weight="1"
android:layout_marginLeft="@dimen/activity_horizontal_margin"
android:layout_marginRight="@dimen/activity_horizontal_margin"
android:gravity="center_vertical"
android:textAppearance="?android:attr/textAppearanceSmall" />

</LinearLayout>
15 changes: 7 additions & 8 deletions src/biz/bokhorst/xprivacy/ActivityMain.java
Original file line number Diff line number Diff line change
Expand Up @@ -1110,17 +1110,16 @@ public View getView(int position, View convertView, ViewGroup parent) {
convertView = mInflater.inflate(R.layout.templateentry, null);
holder = new ViewHolder(convertView, position);
convertView.setTag(holder);
} else {
} else
holder = (ViewHolder) convertView.getTag();
}

// Get info
final String templateName = PrivacyManager.cSettingTemplate + "." + listRestrictionName.get(position);
String value = PrivacyManager.getSetting(0, templateName, "false+ask", false);
String value = PrivacyManager.getSetting(0, templateName, Boolean.toString(!ondemand) + "+ask", false);
holder.restricted = value.contains("true");
holder.asked = !ondemand || value.contains("asked");
Bitmap check = holder.asked ? (holder.restricted ? getFullCheckBox() : getOffCheckBox())
: getOnDemandCheckBox();
holder.asked = (!ondemand || value.contains("asked"));
Bitmap check = (holder.asked ? (holder.restricted ? getFullCheckBox() : getOffCheckBox())
: getOnDemandCheckBox());

// Set data
holder.tvRestriction.setText(listLocalizedTitle.get(position));
Expand All @@ -1140,8 +1139,8 @@ public void onClick(View arg0) {
holder.restricted = true;
holder.asked = true;
}
PrivacyManager.setSetting(0, templateName, (holder.restricted ? "true" : "false")
+ "+" + (holder.asked ? "asked" : "ask"));
PrivacyManager.setSetting(0, templateName, (holder.restricted ? "true" : "false") + "+"
+ (holder.asked ? "asked" : "ask"));

Bitmap check = holder.asked ? (holder.restricted ? getFullCheckBox() : getOffCheckBox())
: getOnDemandCheckBox();
Expand Down
10 changes: 6 additions & 4 deletions src/biz/bokhorst/xprivacy/PrivacyManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -411,14 +411,16 @@ public static void applyTemplate(int uid) {
// Enable on-demand
boolean ondemand = PrivacyManager.getSettingBool(0, PrivacyManager.cSettingOnDemand, true, false);
if (ondemand)
PrivacyManager.setSetting(uid, PrivacyManager.cSettingOnDemand, Boolean.toString(true));
ondemand = PrivacyManager.getSettingBool(-uid, PrivacyManager.cSettingOnDemand, false, false);

// Apply template
for (String restrictionName : PrivacyManager.getRestrictions()) {
String templateName = PrivacyManager.cSettingTemplate + "." + restrictionName;
String templateValue = PrivacyManager.getSetting(0, templateName, "false+ask", false);
PrivacyManager.setRestriction(uid, restrictionName, null, templateValue.contains("true"),
!ondemand || templateValue.contains("asked"));
String templateValue = PrivacyManager.getSetting(0, templateName, Boolean.toString(!ondemand) + "+ask",
false);
boolean restrict = templateValue.contains("true");
boolean asked = templateValue.contains("asked");
PrivacyManager.setRestriction(uid, restrictionName, null, restrict, asked || !ondemand);
}
}

Expand Down

0 comments on commit 12a6e73

Please sign in to comment.