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

Commit

Permalink
Show function help in on demand dialog
Browse files Browse the repository at this point in the history
Closes #1790
  • Loading branch information
M66B committed Jul 6, 2014
1 parent c45a6bb commit b326cd7
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 11 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ Changelog
**Next release**

* Improved on demand dialog layout
* Added help for function documentation
* Added help for function documentation icon
* Show function help in on demand dialog ([issue](/../../issues/1790))
* Updated Dutch translation

[Open issues](https://github.com/M66B/XPrivacy/issues?state=open)
Expand Down
23 changes: 18 additions & 5 deletions res/layout/ondemand.xml
Original file line number Diff line number Diff line change
Expand Up @@ -130,18 +130,19 @@
</TableRow>

<TableRow
android:id="@+id/rowParameters"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:singleLine="true"
android:text="@string/title_ondemand_default"
android:text="@string/title_parameters"
android:textAppearance="?android:attr/textAppearanceSmall" />

<TextView
android:id="@+id/tvDefault"
android:id="@+id/tvParameters"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingLeft="6dip"
Expand All @@ -150,25 +151,37 @@
</TableRow>

<TableRow
android:id="@+id/rowParameters"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:singleLine="true"
android:text="@string/title_parameters"
android:text="@string/title_ondemand_default"
android:textAppearance="?android:attr/textAppearanceSmall" />

<TextView
android:id="@+id/tvParameters"
android:id="@+id/tvDefault"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingLeft="6dip"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textStyle="bold" />
</TableRow>

<TableRow
android:layout_width="wrap_content"
android:layout_height="wrap_content" >

<TextView
android:id="@+id/tvInfo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_span="2"
android:textAppearance="?android:attr/textAppearanceSmall"
android:visibility="gone" />
</TableRow>
</TableLayout>

<CheckBox
Expand Down
2 changes: 1 addition & 1 deletion src/biz/bokhorst/xprivacy/ActivityApp.java
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@ else if (extras.getInt(cAction) == cActionSettings)
}

// Annotate
Meta.annotate(this);
Meta.annotate(this.getResources());
}

@Override
Expand Down
8 changes: 4 additions & 4 deletions src/biz/bokhorst/xprivacy/Meta.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import java.util.ArrayList;
import java.util.List;

import android.content.Context;
import android.content.res.Resources;

public class Meta {
private static boolean mAnnotated = false;
Expand Down Expand Up @@ -328,17 +328,17 @@ public static List<Hook> get() {
return mListHook;
}

public static void annotate(Context context) {
public static void annotate(Resources resources) {
if (mAnnotated)
return;

String self = Meta.class.getPackage().getName();
for (Hook hook : get()) {
String name = hook.getRestrictionName() + "_" + hook.getName();
name = name.replace(".", "_").replace("/", "_").replace("%", "_").replace("-", "_");
int resId = context.getResources().getIdentifier(name, "string", self);
int resId = resources.getIdentifier(name, "string", self);
if (resId > 0)
hook.annotate(context.getString(resId));
hook.annotate(resources.getString(resId));
}

mAnnotated = true;
Expand Down
41 changes: 41 additions & 0 deletions src/biz/bokhorst/xprivacy/PrivacyService.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import android.annotation.SuppressLint;
import android.content.ContentValues;
import android.content.Context;
import android.content.Intent;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager;
import android.content.pm.PackageManager.NameNotFoundException;
Expand All @@ -44,11 +45,17 @@
import android.os.StrictMode;
import android.os.SystemClock;
import android.os.StrictMode.ThreadPolicy;
import android.text.Html;
import android.text.Layout;
import android.text.Spannable;
import android.text.TextUtils;
import android.text.method.LinkMovementMethod;
import android.text.style.URLSpan;
import android.util.Log;
import android.util.Patterns;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.view.WindowManager;
import android.widget.Button;
Expand Down Expand Up @@ -1549,6 +1556,30 @@ final class AlertDialogHolder {
public View dialog = null;
}

final class Touchy extends LinkMovementMethod {
// @formatter:off
// http://grepcode.com/file/repository.grepcode.com/java/ext/com.google.android/android/4.4.2_r1/android/text/method/LinkMovementMethod.java#LinkMovementMethod.onTouchEvent%28android.widget.TextView%2Candroid.text.Spannable%2Candroid.view.MotionEvent%29
// @formatter:on
public boolean onTouchEvent(TextView widget, Spannable buffer, android.view.MotionEvent event) {
if (event.getAction() == MotionEvent.ACTION_UP) {
int x = (int) event.getX() - widget.getTotalPaddingLeft() + widget.getScrollX();
int y = (int) event.getY() - widget.getTotalPaddingTop() + widget.getScrollY();

Layout layout = widget.getLayout();
int line = layout.getLineForVertical(y);
int off = layout.getOffsetForHorizontal(line, x);

URLSpan[] link = buffer.getSpans(off, off, URLSpan.class);
if (link.length != 0) {
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(link[0].getURL()));
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
getContext().startActivity(intent);
}
}
return true;
}
}

@SuppressLint("InflateParams")
private View getOnDemandView(final PRestriction restriction, final Hook hook, ApplicationInfoEx appInfo,
final PRestriction result, Context context, final CountDownLatch latch, final OnDemandResult oResult)
Expand All @@ -1567,6 +1598,7 @@ private View getOnDemandView(final PRestriction restriction, final Hook hook, Ap
TextView tvParameters = (TextView) view.findViewById(R.id.tvParameters);
TableRow rowParameters = (TableRow) view.findViewById(R.id.rowParameters);
TextView tvDefault = (TextView) view.findViewById(R.id.tvDefault);
TextView tvInfo = (TextView) view.findViewById(R.id.tvInfo);
final CheckBox cbCategory = (CheckBox) view.findViewById(R.id.cbCategory);
final CheckBox cbOnce = (CheckBox) view.findViewById(R.id.cbOnce);
final CheckBox cbWhitelist = (CheckBox) view.findViewById(R.id.cbWhitelist);
Expand Down Expand Up @@ -1598,6 +1630,15 @@ private View getOnDemandView(final PRestriction restriction, final Hook hook, Ap
tvParameters.setText(restriction.extra);
String defaultAction = resources.getString(result.restricted ? R.string.title_deny : R.string.title_allow);
tvDefault.setText(defaultAction);
if (hook != null) {
Meta.annotate(resources);
String info = hook.getAnnotation();
if (info != null) {
tvInfo.setVisibility(View.VISIBLE);
tvInfo.setText(Html.fromHtml(hook.getAnnotation()));
tvInfo.setMovementMethod(new Touchy());
}
}

cbCategory.setChecked(mSelectCategory);
cbOnce.setChecked(mSelectOnce);
Expand Down

0 comments on commit b326cd7

Please sign in to comment.