aboutsummaryrefslogtreecommitdiffstats
path: root/main/src/cgeo/geocaching/settings/InfoPreference.java
diff options
context:
space:
mode:
Diffstat (limited to 'main/src/cgeo/geocaching/settings/InfoPreference.java')
-rw-r--r--main/src/cgeo/geocaching/settings/InfoPreference.java105
1 files changed, 53 insertions, 52 deletions
diff --git a/main/src/cgeo/geocaching/settings/InfoPreference.java b/main/src/cgeo/geocaching/settings/InfoPreference.java
index ea740b4..8040a62 100644
--- a/main/src/cgeo/geocaching/settings/InfoPreference.java
+++ b/main/src/cgeo/geocaching/settings/InfoPreference.java
@@ -1,14 +1,11 @@
package cgeo.geocaching.settings;
import cgeo.geocaching.R;
+import cgeo.geocaching.ui.UrlPopup;
import android.app.Activity;
-import android.app.AlertDialog;
import android.content.Context;
-import android.content.DialogInterface;
-import android.content.Intent;
import android.content.res.TypedArray;
-import android.net.Uri;
import android.preference.Preference;
import android.util.AttributeSet;
import android.view.LayoutInflater;
@@ -17,48 +14,61 @@ import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
-public class InfoPreference extends Preference {
-
- // strings for the popup dialog
+/**
+ * Preference which shows a dialog containing textual explanation. The dialog has two buttons, where one will open a
+ * hyper link with more detailed information.
+ * <p>
+ * The URL for the hyper link and the text are given as custom attributes in the preference XML definition.
+ * </p>
+ *
+ */
+public class InfoPreference extends AbstractAttributeBasedPrefence {
+
+ /**
+ * Content of the dialog, filled from preferences XML.
+ */
private String text;
+ /**
+ * URL for the second button, filled from preferences XML.
+ */
private String url;
+ /**
+ * text for the second button to open an URL, filled from preferences XML.
+ */
private String urlButton;
private LayoutInflater inflater;
public InfoPreference(Context context) {
super(context);
- init(context, null, 0);
+ init(context);
}
public InfoPreference(Context context, AttributeSet attrs) {
super(context, attrs);
- init(context, attrs, 0);
+ init(context);
}
public InfoPreference(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
- init(context, attrs, defStyle);
+ init(context);
}
- private void init(Context context, AttributeSet attrs, int defStyle) {
+ private void init(Context context) {
inflater = ((Activity) context).getLayoutInflater();
-
setPersistent(false);
+ }
- if (attrs == null) {
- return; // coward's retreat
- }
-
- TypedArray types = context.obtainStyledAttributes(attrs, new int[] {
- android.R.attr.text, R.attr.url, R.attr.urlButton },
- defStyle, 0);
-
- text = types.getString(0);
- url = types.getString(1);
- urlButton = types.getString(2);
+ @Override
+ protected int[] getAttributeNames() {
+ return new int[] { android.R.attr.text, R.attr.url, R.attr.urlButton };
+ }
- types.recycle();
+ @Override
+ protected void processAttributeValues(TypedArray values) {
+ text = values.getString(0);
+ url = values.getString(1);
+ urlButton = values.getString(2);
}
@Override
@@ -69,39 +79,30 @@ public class InfoPreference extends Preference {
@Override
public boolean onPreferenceClick(final Preference preference) {
- AlertDialog.Builder builder = new AlertDialog.Builder(
- preference.getContext());
- builder.setMessage(text)
- .setIcon(android.R.drawable.ic_dialog_info)
- .setTitle(preference.getTitle())
- .setPositiveButton(R.string.err_none, new DialogInterface.OnClickListener() {
- @Override
- public void onClick(DialogInterface dialog, int id) {
- dialog.cancel();
- }
- })
- .setNegativeButton(urlButton, new DialogInterface.OnClickListener() {
- @Override
- public void onClick(DialogInterface dialog, int id) {
- Intent i = new Intent(Intent.ACTION_VIEW);
- i.setData(Uri.parse(url));
- preference.getContext().startActivity(i);
- }
- });
- builder.create().show();
+ new UrlPopup(preference.getContext()).show(preference.getTitle().toString(), text, url, urlButton);
+ // don't update the preference value
return false;
}
});
- // show an Info Icon
- View v = super.onCreateView(parent);
-
- ImageView i = (ImageView) inflater.inflate(R.layout.preference_info_icon, parent, false);
- LinearLayout l = (LinearLayout) v.findViewById(android.R.id.widget_frame);
- l.setVisibility(View.VISIBLE);
- l.addView(i);
+ return addInfoIcon(parent);
+ }
- return v;
+ /**
+ * Add an info icon at the left hand side of the preference.
+ *
+ * @param parent
+ * @return
+ */
+ private View addInfoIcon(ViewGroup parent) {
+ View preferenceView = super.onCreateView(parent);
+
+ ImageView iconView = (ImageView) inflater.inflate(R.layout.preference_info_icon, parent, false);
+ LinearLayout frame = (LinearLayout) preferenceView.findViewById(android.R.id.widget_frame);
+ frame.setVisibility(View.VISIBLE);
+ frame.addView(iconView);
+
+ return preferenceView;
}
}