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

Commit

Permalink
Added help items to template
Browse files Browse the repository at this point in the history
Fixes #1827
  • Loading branch information
M66B committed Aug 16, 2014
1 parent a4d7e00 commit 842c340
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 38 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ Version 2.99.x and version 3.x will be available with a [pro license](http://www

**Next release**

* Added help items to template ([issue](/../../issues/1827))

[Open issues](https://github.com/M66B/XPrivacy/issues?state=open)

**Version 2.99.29 BETA**
Expand Down
10 changes: 10 additions & 0 deletions res/layout/templateentry.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,16 @@
android:contentDescription="@string/title_category"
android:src="?attr/icon_expander_minimized" />

<ImageView
android:id="@+id/imgInfo"
android:layout_width="32dip"
android:layout_height="32dip"
android:layout_gravity="center_vertical"
android:contentDescription="@string/help_application"
android:paddingLeft="3dip"
android:src="?attr/icon_info_book"
android:visibility="gone" />

<TextView
android:id="@+id/tvRestriction"
android:layout_width="0dip"
Expand Down
75 changes: 40 additions & 35 deletions src/biz/bokhorst/xprivacy/ActivityApp.java
Original file line number Diff line number Diff line change
Expand Up @@ -1729,49 +1729,16 @@ public View getChildView(int groupPosition, int childPosition, boolean isLastChi
// Hide if permissions
holder.imgGranted.setVisibility(View.INVISIBLE);

// Function help
if (hook.getAnnotation() == null)
holder.imgInfo.setVisibility(View.GONE);
else {
holder.imgInfo.setVisibility(View.VISIBLE);
holder.imgInfo.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
LayoutInflater inflator = LayoutInflater.from(ActivityApp.this);
View layout = inflator.inflate(R.layout.popup, null);

TextView tvTitle = (TextView) layout.findViewById(R.id.tvTitle);
tvTitle.setText(hook.getName());

String text = hook.getAnnotation();
String[] permissions = hook.getPermissions();
if (permissions != null && permissions.length > 0) {
text += "<br /><br /><b>" + getString(R.string.title_permissions) + "</b><br /><br />";
if (permissions[0].equals(""))
text += "-";
else
text += TextUtils.join("<br />", permissions);
}

TextView tvInfo = (TextView) layout.findViewById(R.id.tvInfo);
tvInfo.setText(Html.fromHtml(text));
tvInfo.setMovementMethod(LinkMovementMethod.getInstance());

View parent = ActivityApp.this.findViewById(android.R.id.content);

final PopupWindow popup = new PopupWindow(layout);
popup.setHeight(WindowManager.LayoutParams.WRAP_CONTENT);
popup.setWidth(90 * parent.getWidth() / 100);

Button btnOk = (Button) layout.findViewById(R.id.btnOk);
btnOk.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if (popup.isShowing())
popup.dismiss();
}
});

popup.showAtLocation(parent, Gravity.CENTER, 0, 0);
showHelp(ActivityApp.this, parent, hook);
}
});
}
Expand Down Expand Up @@ -1799,4 +1766,42 @@ public boolean hasStableIds() {
return true;
}
}

@SuppressLint("InflateParams")
public static void showHelp(ActivityBase context, View parent, Hook hook) {
LayoutInflater inflator = LayoutInflater.from(context);
View layout = inflator.inflate(R.layout.popup, null);

TextView tvTitle = (TextView) layout.findViewById(R.id.tvTitle);
tvTitle.setText(hook.getName());

String text = hook.getAnnotation();
String[] permissions = hook.getPermissions();
if (permissions != null && permissions.length > 0) {
text += "<br /><br /><b>" + context.getString(R.string.title_permissions) + "</b><br /><br />";
if (permissions[0].equals(""))
text += "-";
else
text += TextUtils.join("<br />", permissions);
}

TextView tvInfo = (TextView) layout.findViewById(R.id.tvInfo);
tvInfo.setText(Html.fromHtml(text));
tvInfo.setMovementMethod(LinkMovementMethod.getInstance());

final PopupWindow popup = new PopupWindow(layout);
popup.setHeight(WindowManager.LayoutParams.WRAP_CONTENT);
popup.setWidth(90 * parent.getWidth() / 100);

Button btnOk = (Button) layout.findViewById(R.id.btnOk);
btnOk.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if (popup.isShowing())
popup.dismiss();
}
});

popup.showAtLocation(parent, Gravity.CENTER, 0, 0);
}
}
24 changes: 21 additions & 3 deletions src/biz/bokhorst/xprivacy/ActivityMain.java
Original file line number Diff line number Diff line change
Expand Up @@ -676,7 +676,7 @@ private void optionTemplate() {
spTemplate.setAdapter(spAdapter);

// Template definition
final TemplateListAdapter templateAdapter = new TemplateListAdapter(this, spTemplate, R.layout.templateentry);
final TemplateListAdapter templateAdapter = new TemplateListAdapter(this, view, R.layout.templateentry);
elvTemplate.setAdapter(templateAdapter);
elvTemplate.setGroupIndicator(null);

Expand Down Expand Up @@ -1180,14 +1180,16 @@ public SpinnerAdapter(Context context, int textViewResourceId) {

@SuppressLint("DefaultLocale")
private class TemplateListAdapter extends BaseExpandableListAdapter {
private View mView;
private Spinner mSpinner;
private List<String> listRestrictionName;
private List<String> listLocalizedTitle;
private boolean ondemand;
private LayoutInflater mInflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);

public TemplateListAdapter(Context context, Spinner spinner, int resource) {
mSpinner = spinner;
public TemplateListAdapter(Context context, View view, int resource) {
mView = view;
mSpinner = (Spinner) view.findViewById(R.id.spTemplate);

// Get restriction categories
TreeMap<String, String> tmRestriction = PrivacyManager.getRestrictions(context);
Expand All @@ -1208,6 +1210,7 @@ private String getTemplate() {
private class ViewHolder {
private View row;
public ImageView imgIndicator;
public ImageView imgInfo;
public TextView tvRestriction;
public ImageView imgCbRestrict;
public ImageView imgCbAsk;
Expand All @@ -1217,6 +1220,7 @@ private class ViewHolder {
public ViewHolder(View theRow) {
row = theRow;
imgIndicator = (ImageView) row.findViewById(R.id.imgIndicator);
imgInfo = (ImageView) row.findViewById(R.id.imgInfo);
tvRestriction = (TextView) row.findViewById(R.id.tvRestriction);
imgCbRestrict = (ImageView) row.findViewById(R.id.imgCbRestrict);
imgCbAsk = (ImageView) row.findViewById(R.id.imgCbAsk);
Expand Down Expand Up @@ -1283,6 +1287,7 @@ public View getGroupView(int groupPosition, boolean isExpanded, View convertView
holder.imgIndicator.setImageResource(getThemed(isExpanded ? R.attr.icon_expander_maximized
: R.attr.icon_expander_minimized));
holder.imgIndicator.setVisibility(View.VISIBLE);
holder.imgInfo.setVisibility(View.GONE);

// Set data
holder.tvRestriction.setTypeface(null, Typeface.BOLD);
Expand Down Expand Up @@ -1375,6 +1380,19 @@ public View getChildView(int groupPosition, int childPosition, boolean isLastChi
// Set indicator
holder.imgIndicator.setVisibility(View.INVISIBLE);

// Function help
if (hook.getAnnotation() == null)
holder.imgInfo.setVisibility(View.GONE);
else {
holder.imgInfo.setVisibility(View.VISIBLE);
holder.imgInfo.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
ActivityApp.showHelp(ActivityMain.this, mView, hook);
}
});
}

// Set data
if (hook.isDangerous())
holder.row.setBackgroundColor(getResources().getColor(
Expand Down

0 comments on commit 842c340

Please sign in to comment.