From 842c340860a10b58d1d56e69d334cdf4d19dc25d Mon Sep 17 00:00:00 2001 From: M66B Date: Sat, 16 Aug 2014 13:52:42 +0200 Subject: [PATCH] Added help items to template Fixes #1827 --- CHANGELOG.md | 2 + res/layout/templateentry.xml | 10 +++ src/biz/bokhorst/xprivacy/ActivityApp.java | 75 +++++++++++---------- src/biz/bokhorst/xprivacy/ActivityMain.java | 24 ++++++- 4 files changed, 73 insertions(+), 38 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c33a9d53c..a465bf822 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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** diff --git a/res/layout/templateentry.xml b/res/layout/templateentry.xml index bb19b46b6..9e8d78128 100644 --- a/res/layout/templateentry.xml +++ b/res/layout/templateentry.xml @@ -14,6 +14,16 @@ android:contentDescription="@string/title_category" android:src="?attr/icon_expander_minimized" /> + + 0) { - text += "

" + getString(R.string.title_permissions) + "

"; - if (permissions[0].equals("")) - text += "-"; - else - text += TextUtils.join("
", 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); } }); } @@ -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 += "

" + context.getString(R.string.title_permissions) + "

"; + if (permissions[0].equals("")) + text += "-"; + else + text += TextUtils.join("
", 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); + } } diff --git a/src/biz/bokhorst/xprivacy/ActivityMain.java b/src/biz/bokhorst/xprivacy/ActivityMain.java index a9fb69c98..ed57fb264 100644 --- a/src/biz/bokhorst/xprivacy/ActivityMain.java +++ b/src/biz/bokhorst/xprivacy/ActivityMain.java @@ -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); @@ -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 listRestrictionName; private List 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 tmRestriction = PrivacyManager.getRestrictions(context); @@ -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; @@ -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); @@ -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); @@ -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(