Skip to content

Commit

Permalink
Added questionmark icons
Browse files Browse the repository at this point in the history
  • Loading branch information
jpeg729 committed Feb 10, 2014
1 parent d1da5b3 commit 68fec7e
Show file tree
Hide file tree
Showing 8 changed files with 193 additions and 215 deletions.
Binary file added res/drawable-nodpi/questionmark_outline.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
11 changes: 0 additions & 11 deletions res/layout/mainentry.xml
Original file line number Diff line number Diff line change
Expand Up @@ -86,17 +86,6 @@
android:contentDescription="@string/title_restrict"
android:visibility="invisible" />

<TextView
android:id="@+id/tvOnDemand"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:text="@string/msg_question"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textStyle="bold"
android:visibility="invisible" />

<TextView
android:id="@+id/tvName"
android:layout_width="match_parent"
Expand Down
45 changes: 24 additions & 21 deletions res/layout/restrictionchild.xml
Original file line number Diff line number Diff line change
Expand Up @@ -36,30 +36,33 @@
android:src="?attr/icon_info"
android:visibility="gone" />

<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="vertical"
<RelativeLayout
android:id="@+id/rlMethodName"
android:layout_width="match_parent"
android:layout_height="?android:attr/listPreferredItemHeightSmall"
android:background="@drawable/list_item_pressed"
android:clickable="true"
android:paddingLeft="6dip" >

<CheckedTextView
android:id="@+id/ctvMethodName"
<ImageView
android:id="@+id/imgCBMethodName"
android:layout_width="32dip"
android:layout_height="32dip"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:layout_marginLeft="3dip"
android:layout_marginRight="6dip"
android:contentDescription="@string/title_restrict"
android:visibility="invisible" />

<TextView
android:id="@+id/tvMethodName"
android:layout_width="match_parent"
android:layout_height="?android:attr/listPreferredItemHeightSmall"
android:checkMark="?android:attr/listChoiceIndicatorMultiple"
android:gravity="center_vertical"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:layout_toLeftOf="@id/imgCBName"
android:textAppearance="?android:attr/textAppearanceSmall" />
</LinearLayout>

<TextView
android:id="@+id/tvOnDemand"
android:layout_width="wrap_content"
android:layout_height="?android:attr/listPreferredItemHeightSmall"
android:gravity="center_vertical"
android:text="@string/msg_question"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textStyle="bold"
android:visibility="invisible" />
</RelativeLayout>

</LinearLayout>
11 changes: 0 additions & 11 deletions res/layout/restrictionentry.xml
Original file line number Diff line number Diff line change
Expand Up @@ -61,17 +61,6 @@
android:contentDescription="@string/title_restrict"
android:visibility="invisible" />

<TextView
android:id="@+id/tvOnDemand"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:text="@string/msg_question"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textStyle="bold"
android:visibility="invisible" />

<TextView
android:id="@+id/tvName"
android:layout_width="match_parent"
Expand Down
138 changes: 51 additions & 87 deletions src/biz/bokhorst/xprivacy/ActivityApp.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
import java.util.concurrent.Executors;
import java.util.concurrent.ThreadFactory;

import biz.bokhorst.xprivacy.Util.RState;

import android.accounts.Account;
import android.accounts.AccountManager;
import android.app.Activity;
Expand Down Expand Up @@ -52,7 +54,6 @@
import android.view.WindowManager;
import android.widget.BaseExpandableListAdapter;
import android.widget.Button;
import android.widget.CheckedTextView;
import android.widget.CompoundButton;
import android.widget.ExpandableListView;
import android.widget.ImageView;
Expand Down Expand Up @@ -898,7 +899,6 @@ private class GroupViewHolder {
public ImageView imgInfo;
public TextView tvName;
public ImageView imgCBName;
public TextView tvOnDemand;
public RelativeLayout rlName;

public GroupViewHolder(View theRow, int thePosition) {
Expand All @@ -910,7 +910,6 @@ public GroupViewHolder(View theRow, int thePosition) {
imgInfo = (ImageView) row.findViewById(R.id.imgInfo);
tvName = (TextView) row.findViewById(R.id.tvName);
imgCBName = (ImageView) row.findViewById(R.id.imgCBName);
tvOnDemand = (TextView) row.findViewById(R.id.tvOnDemand);
rlName = (RelativeLayout) row.findViewById(R.id.rlName);
}
}
Expand All @@ -921,10 +920,7 @@ private class GroupHolderTask extends AsyncTask<Object, Object, Object> {
private String restrictionName;
private boolean used;
private boolean permission;
private boolean crestricted;
private boolean allRestricted;
private boolean someRestricted;
private boolean asked;
private RState rstate;

public GroupHolderTask(int thePosition, GroupViewHolder theHolder, String theRestrictionName) {
position = thePosition;
Expand All @@ -938,23 +934,7 @@ protected Object doInBackground(Object... params) {
// Get info
used = (PrivacyManager.getUsage(mAppInfo.getUid(), restrictionName, null) != 0);
permission = PrivacyManager.hasPermission(ActivityApp.this, mAppInfo, restrictionName);
PRestriction query = PrivacyManager.getRestrictionEx(mAppInfo.getUid(), restrictionName, null);
crestricted = PrivacyManager.getRestrictionEx(mAppInfo.getUid(), restrictionName, null).restricted;

// Get all/some restricted
allRestricted = true;
someRestricted = false;
for (PRestriction restriction : PrivacyManager.getRestrictionList(mAppInfo.getUid(),
restrictionName)) {
allRestricted = (allRestricted && restriction.restricted);
someRestricted = (someRestricted || restriction.restricted);
}

if (PrivacyManager
.getSettingBool(-mAppInfo.getUid(), PrivacyManager.cSettingOnDemand, false, false))
asked = query.asked;
else
asked = true;
rstate = Util.getRestrictionState(mAppInfo.getUid(), restrictionName, null);

return holder;
}
Expand All @@ -970,47 +950,32 @@ protected void onPostExecute(Object result) {
holder.imgGranted.setVisibility(permission ? View.VISIBLE : View.INVISIBLE);

// Display restriction
if (allRestricted)
holder.imgCBName.setImageBitmap(mCheck[2]); // Full
else if (someRestricted || crestricted)
if (!rstate.asked)
holder.imgCBName.setImageBitmap(mCheck[3]); // ?
else if (rstate.partial)
holder.imgCBName.setImageBitmap(mCheck[1]); // Half
else if (rstate.restricted)
holder.imgCBName.setImageBitmap(mCheck[2]); // Full
else
holder.imgCBName.setImageBitmap(mCheck[0]); // Off
holder.imgCBName.setVisibility(View.VISIBLE);

holder.tvOnDemand.setVisibility(asked ? View.INVISIBLE : View.VISIBLE);

// Listen for restriction changes
holder.rlName.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
crestricted = PrivacyManager.getRestrictionEx(mAppInfo.getUid(), restrictionName, null).restricted;
crestricted = !crestricted;
// Set change
boolean ask = rstate.asked;
boolean restrict = ask ? !rstate.restricted : rstate.restricted;

List<Boolean> oldState = PrivacyManager.getRestartStates(mAppInfo.getUid(), restrictionName);
if (!crestricted)
if (!restrict)
PrivacyManager.deleteRestrictions(mAppInfo.getUid(), restrictionName);
PrivacyManager.setRestriction(mAppInfo.getUid(), restrictionName, null, crestricted, false);
PrivacyManager.setRestriction(mAppInfo.getUid(), restrictionName, null, restrict, !ask);
List<Boolean> newState = PrivacyManager.getRestartStates(mAppInfo.getUid(), restrictionName);

// Update all/some restricted
allRestricted = true;
someRestricted = false;
for (PRestriction restriction : PrivacyManager.getRestrictionList(mAppInfo.getUid(),
restrictionName)) {
allRestricted = (allRestricted && restriction.restricted);
someRestricted = (someRestricted || restriction.restricted);
}

// Display restriction
if (allRestricted)
holder.imgCBName.setImageBitmap(mCheck[2]); // Full
else if (someRestricted || crestricted)
holder.imgCBName.setImageBitmap(mCheck[1]); // Half
else
holder.imgCBName.setImageBitmap(mCheck[0]); // Off

// Refresh display
notifyDataSetChanged(); // Needed to update childs
notifyDataSetChanged(); // Needed to update children

// Notify restart
if (!newState.equals(oldState))
Expand Down Expand Up @@ -1070,7 +1035,6 @@ public void onClick(View view) {

// Display restriction
holder.imgCBName.setVisibility(View.INVISIBLE);
holder.tvOnDemand.setVisibility(View.INVISIBLE);

// Async update
new GroupHolderTask(groupPosition, holder, restrictionName).executeOnExecutor(mExecutor, (Object) null);
Expand Down Expand Up @@ -1124,8 +1088,9 @@ private class ChildViewHolder {
public ImageView imgUsed;
public ImageView imgGranted;
public ImageView imgInfo;
public CheckedTextView ctvMethodName;
private TextView tvOnDemand;
public TextView tvMethodName;
public ImageView imgCBMethodName;
public RelativeLayout rlMethodName;

private ChildViewHolder(View theRow, int gPosition, int cPosition) {
row = theRow;
Expand All @@ -1134,8 +1099,9 @@ private ChildViewHolder(View theRow, int gPosition, int cPosition) {
imgUsed = (ImageView) row.findViewById(R.id.imgUsed);
imgGranted = (ImageView) row.findViewById(R.id.imgGranted);
imgInfo = (ImageView) row.findViewById(R.id.imgInfo);
ctvMethodName = (CheckedTextView) row.findViewById(R.id.ctvMethodName);
tvOnDemand = (TextView) row.findViewById(R.id.tvOnDemand);
tvMethodName = (TextView) row.findViewById(R.id.tvMethodName);
imgCBMethodName = (ImageView) row.findViewById(R.id.imgCBMethodName);
rlMethodName = (RelativeLayout) row.findViewById(R.id.rlMethodName);
}
}

Expand All @@ -1146,10 +1112,9 @@ private class ChildHolderTask extends AsyncTask<Object, Object, Object> {
private String restrictionName;
private Hook md;
private long lastUsage;
private boolean parentRestricted;
private PRestriction parent;
private boolean permission;
private boolean restricted;
private boolean asked;
private RState rstate;

public ChildHolderTask(int gPosition, int cPosition, ChildViewHolder theHolder, String theRestrictionName) {
groupPosition = gPosition;
Expand All @@ -1164,17 +1129,9 @@ protected Object doInBackground(Object... params) {
// Get info
md = (Hook) getChild(groupPosition, childPosition);
lastUsage = PrivacyManager.getUsage(mAppInfo.getUid(), restrictionName, md.getName());
parentRestricted = PrivacyManager.getRestrictionEx(mAppInfo.getUid(), restrictionName, null).restricted;
parent = PrivacyManager.getRestrictionEx(mAppInfo.getUid(), restrictionName, null);
permission = PrivacyManager.hasPermission(ActivityApp.this, mAppInfo, md);
PRestriction query = PrivacyManager.getRestrictionEx(mAppInfo.getUid(), restrictionName,
md.getName());
restricted = query.restricted;

if (PrivacyManager
.getSettingBool(-mAppInfo.getUid(), PrivacyManager.cSettingOnDemand, false, false))
asked = query.asked;
else
asked = true;
rstate = Util.getRestrictionState(mAppInfo.getUid(), restrictionName, md.getName());

return holder;
}
Expand All @@ -1188,28 +1145,36 @@ protected void onPostExecute(Object result) {
if (lastUsage > 0) {
CharSequence sLastUsage = DateUtils.getRelativeTimeSpanString(lastUsage, new Date().getTime(),
DateUtils.SECOND_IN_MILLIS, 0);
holder.ctvMethodName.setText(String.format("%s (%s)", md.getName(), sLastUsage));
holder.tvMethodName.setText(String.format("%s (%s)", md.getName(), sLastUsage));
}
holder.ctvMethodName.setEnabled(parentRestricted);
holder.tvMethodName.setEnabled(parent.restricted || !parent.asked);
holder.imgUsed.setImageResource(Util.getThemed(ActivityApp.this,
md.hasUsageData() ? R.attr.icon_used : R.attr.icon_used_grayed));
holder.imgUsed.setVisibility(lastUsage == 0 && md.hasUsageData() ? View.INVISIBLE : View.VISIBLE);
holder.ctvMethodName.setTypeface(null, lastUsage == 0 ? Typeface.NORMAL : Typeface.BOLD_ITALIC);
holder.tvMethodName.setTypeface(null, lastUsage == 0 ? Typeface.NORMAL : Typeface.BOLD_ITALIC);
holder.imgGranted.setVisibility(permission ? View.VISIBLE : View.INVISIBLE);
holder.ctvMethodName.setChecked(restricted);

holder.tvOnDemand.setVisibility(asked ? View.INVISIBLE : View.VISIBLE);
// Display restriction
if (!rstate.asked)
holder.imgCBMethodName.setImageBitmap(mCheck[3]); // ?
else if (rstate.partial)
holder.imgCBMethodName.setImageBitmap(mCheck[1]); // Half
else if (rstate.restricted)
holder.imgCBMethodName.setImageBitmap(mCheck[2]); // Full
else
holder.imgCBMethodName.setImageBitmap(mCheck[0]); // Off
holder.imgCBMethodName.setVisibility(View.VISIBLE);

// Listen for restriction changes
holder.ctvMethodName.setOnClickListener(new View.OnClickListener() {
holder.rlMethodName.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
boolean restricted = PrivacyManager.getRestrictionEx(mAppInfo.getUid(), restrictionName,
md.getName()).restricted;
restricted = !restricted;
holder.ctvMethodName.setChecked(restricted);
PrivacyManager.setRestriction(mAppInfo.getUid(), restrictionName, md.getName(), restricted,
false);
// Set change
boolean ask = rstate.asked;
boolean restrict = ask ? !rstate.restricted : rstate.restricted;

PrivacyManager.setRestriction(mAppInfo.getUid(), restrictionName, md.getName(), restrict,
!ask);

// Refresh display
notifyDataSetChanged(); // Needed to update parent
Expand All @@ -1222,7 +1187,7 @@ public void onClick(View view) {
});

// Listen for long press
holder.ctvMethodName.setOnLongClickListener(new View.OnLongClickListener() {
holder.rlMethodName.setOnLongClickListener(new View.OnLongClickListener() {
@Override
public boolean onLongClick(View view) {
md.toggleDangerous();
Expand Down Expand Up @@ -1267,9 +1232,9 @@ public View getChildView(int groupPosition, int childPosition, boolean isLastChi
holder.row.setBackgroundColor(Color.TRANSPARENT);

// Display method name
holder.ctvMethodName.setText(md.getName());
holder.ctvMethodName.setEnabled(false);
holder.ctvMethodName.setTypeface(null, Typeface.NORMAL);
holder.tvMethodName.setText(md.getName());
holder.tvMethodName.setEnabled(false);
holder.tvMethodName.setTypeface(null, Typeface.NORMAL);

// Display if used
holder.imgUsed.setVisibility(View.INVISIBLE);
Expand Down Expand Up @@ -1313,8 +1278,7 @@ public void onClick(View v) {
}

// Display restriction
holder.ctvMethodName.setChecked(false);
holder.ctvMethodName.setClickable(false);
holder.tvMethodName.setClickable(false);

// Async update
new ChildHolderTask(groupPosition, childPosition, holder, restrictionName).executeOnExecutor(mExecutor,
Expand Down
Loading

0 comments on commit 68fec7e

Please sign in to comment.