aboutsummaryrefslogtreecommitdiffstats
path: root/main/src/cgeo/geocaching/settings
diff options
context:
space:
mode:
Diffstat (limited to 'main/src/cgeo/geocaching/settings')
-rw-r--r--main/src/cgeo/geocaching/settings/AbstractAttributeBasedPrefence.java54
-rw-r--r--main/src/cgeo/geocaching/settings/CapabilitiesPreference.java82
-rw-r--r--main/src/cgeo/geocaching/settings/EditPasswordPreference.java5
-rw-r--r--main/src/cgeo/geocaching/settings/InfoPreference.java53
-rw-r--r--main/src/cgeo/geocaching/settings/SettingsActivity.java2
-rw-r--r--main/src/cgeo/geocaching/settings/TextPreference.java45
-rw-r--r--main/src/cgeo/geocaching/settings/WpThresholdPreference.java3
7 files changed, 197 insertions, 47 deletions
diff --git a/main/src/cgeo/geocaching/settings/AbstractAttributeBasedPrefence.java b/main/src/cgeo/geocaching/settings/AbstractAttributeBasedPrefence.java
new file mode 100644
index 0000000..1930c17
--- /dev/null
+++ b/main/src/cgeo/geocaching/settings/AbstractAttributeBasedPrefence.java
@@ -0,0 +1,54 @@
+package cgeo.geocaching.settings;
+
+import org.eclipse.jdt.annotation.Nullable;
+
+import android.content.Context;
+import android.content.res.TypedArray;
+import android.preference.Preference;
+import android.util.AttributeSet;
+
+/**
+ * Base class for preferences which evaluate their XML attributes for further processing.
+ *
+ */
+public abstract class AbstractAttributeBasedPrefence extends Preference {
+
+ public AbstractAttributeBasedPrefence(Context context) {
+ super(context);
+ }
+
+ public AbstractAttributeBasedPrefence(Context context, AttributeSet attrs) {
+ super(context, attrs);
+ processAttributes(context, attrs, 0);
+ }
+
+ public AbstractAttributeBasedPrefence(Context context, AttributeSet attrs, int defStyle) {
+ super(context, attrs, defStyle);
+ processAttributes(context, attrs, defStyle);
+ }
+
+ private void processAttributes(Context context, @Nullable AttributeSet attrs, int defStyle) {
+ if (attrs == null) {
+ return;
+ }
+ TypedArray types = context.obtainStyledAttributes(attrs, getAttributeNames(),
+ defStyle, 0);
+
+ processAttributeValues(types);
+
+ types.recycle();
+ }
+
+ /**
+ * Evaluate the attributes which where requested in {@link AbstractAttributeBasedPrefence#getAttributeNames()}.
+ *
+ * @param values
+ */
+ protected abstract void processAttributeValues(TypedArray values);
+
+ /**
+ * @return the names of the attributes you want to read in your preference implementation
+ */
+ protected abstract int[] getAttributeNames();
+
+}
diff --git a/main/src/cgeo/geocaching/settings/CapabilitiesPreference.java b/main/src/cgeo/geocaching/settings/CapabilitiesPreference.java
new file mode 100644
index 0000000..d7e55a4
--- /dev/null
+++ b/main/src/cgeo/geocaching/settings/CapabilitiesPreference.java
@@ -0,0 +1,82 @@
+package cgeo.geocaching.settings;
+
+import cgeo.geocaching.R;
+import cgeo.geocaching.connector.ConnectorFactory;
+import cgeo.geocaching.connector.IConnector;
+
+import org.apache.commons.lang3.StringUtils;
+
+import android.app.AlertDialog;
+import android.content.Context;
+import android.content.DialogInterface;
+import android.content.res.TypedArray;
+import android.preference.Preference;
+import android.util.AttributeSet;
+import android.view.View;
+import android.view.ViewGroup;
+import android.webkit.WebView;
+
+/**
+ * Preference for displaying the supported capabilities of an {@link IConnector} implementation.
+ */
+public class CapabilitiesPreference extends AbstractAttributeBasedPrefence {
+
+ private String connectorCode;
+
+ public CapabilitiesPreference(Context context) {
+ super(context);
+ }
+
+ public CapabilitiesPreference(Context context, AttributeSet attrs) {
+ super(context, attrs);
+ }
+
+ public CapabilitiesPreference(Context context, AttributeSet attrs, int defStyle) {
+ super(context, attrs, defStyle);
+ }
+
+ @Override
+ public View getView(View convertView, ViewGroup parent) {
+ setOnPreferenceClickListener(new ClickListener());
+ return super.getView(convertView, parent);
+ }
+
+ private final class ClickListener implements OnPreferenceClickListener {
+ @Override
+ public boolean onPreferenceClick(final Preference preference) {
+ WebView htmlView = new WebView(preference.getContext());
+ htmlView.loadData(createCapabilitiesMessage(), "text/html", null);
+ AlertDialog.Builder builder = new AlertDialog.Builder(preference.getContext());
+ builder.setView(htmlView)
+ .setIcon(android.R.drawable.ic_dialog_info)
+ .setTitle(R.string.settings_features)
+ .setPositiveButton(R.string.err_none, new DialogInterface.OnClickListener() {
+ @Override
+ public void onClick(DialogInterface dialog, int id) {
+ dialog.cancel();
+ }
+ });
+ builder.create().show();
+ return false;
+ }
+ }
+
+ public String createCapabilitiesMessage() {
+ // TODO: this needs a better key for the connectors
+ IConnector connector = ConnectorFactory.getConnector(connectorCode + "1234");
+ if (connector == null) {
+ return StringUtils.EMPTY;
+ }
+ return connector.getCapabilitiesMessage();
+ }
+
+ @Override
+ protected void processAttributeValues(TypedArray values) {
+ connectorCode = values.getString(0);
+ }
+
+ @Override
+ protected int[] getAttributeNames() {
+ return new int[] { R.attr.connector };
+ }
+}
diff --git a/main/src/cgeo/geocaching/settings/EditPasswordPreference.java b/main/src/cgeo/geocaching/settings/EditPasswordPreference.java
index b127f52..af07041 100644
--- a/main/src/cgeo/geocaching/settings/EditPasswordPreference.java
+++ b/main/src/cgeo/geocaching/settings/EditPasswordPreference.java
@@ -7,11 +7,10 @@ import android.preference.EditTextPreference;
import android.util.AttributeSet;
/**
- * This is just a dummy preference, to be able check for the type.
+ * Password preference. It will only show a row of asterisks as summary instead of the password.
* <p>
* Use it exactly as an EditTextPreference
- *
- * @see SettingsActivity - search for EditPasswordPreference
+ *
*/
public class EditPasswordPreference extends EditTextPreference {
diff --git a/main/src/cgeo/geocaching/settings/InfoPreference.java b/main/src/cgeo/geocaching/settings/InfoPreference.java
index ea740b4..3b59bcc 100644
--- a/main/src/cgeo/geocaching/settings/InfoPreference.java
+++ b/main/src/cgeo/geocaching/settings/InfoPreference.java
@@ -17,48 +17,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
diff --git a/main/src/cgeo/geocaching/settings/SettingsActivity.java b/main/src/cgeo/geocaching/settings/SettingsActivity.java
index 6b4a71b..46dacb2 100644
--- a/main/src/cgeo/geocaching/settings/SettingsActivity.java
+++ b/main/src/cgeo/geocaching/settings/SettingsActivity.java
@@ -476,7 +476,7 @@ public class SettingsActivity extends PreferenceActivity {
final int mapSourceId = Integer.valueOf(stringValue);
mapSource = MapProviderFactory.getMapSource(mapSourceId);
} catch (final NumberFormatException e) {
- Log.e("SettingsActivity.onPreferenceChange: bad source id `" + stringValue + "'");
+ Log.e("SettingsActivity.onPreferenceChange: bad source id '" + stringValue + "'");
mapSource = null;
}
// If there is no corresponding map source (because some map sources were
diff --git a/main/src/cgeo/geocaching/settings/TextPreference.java b/main/src/cgeo/geocaching/settings/TextPreference.java
index bcd03ff..eecf4cc 100644
--- a/main/src/cgeo/geocaching/settings/TextPreference.java
+++ b/main/src/cgeo/geocaching/settings/TextPreference.java
@@ -4,21 +4,26 @@ import cgeo.geocaching.R;
import android.content.Context;
import android.content.res.TypedArray;
-import android.preference.Preference;
import android.util.AttributeSet;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
/**
- * Preference to simply show a text message.
+ * Preference to simply show a text message. Links are not shown.
* <p>
- * Links are not shown - I tried everything (koem)
- * <p>
- * example: <cgeo.geocaching.settings.TextPreference android:text="@string/legal_note"
- * android:layout="@string/text_preference_default_layout" />
+ * Usage: The displayed text is taken from the "android:text" attribute of the preference definition. Example:
+ *
+ * <pre>
+ * <cgeo.geocaching.settings.TextPreference
+ * android:text="@string/legal_note"
+ * android:layout="@string/text_preference_default_layout"
+ * />
+ * </pre>
+ *
+ * </p>
*/
-public class TextPreference extends Preference {
+public class TextPreference extends AbstractAttributeBasedPrefence {
private String text;
private TextView summaryView;
@@ -30,23 +35,20 @@ public class TextPreference extends Preference {
public TextPreference(Context context, AttributeSet attrs) {
super(context, attrs);
- processAttributes(context, attrs, 0);
}
public TextPreference(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
- processAttributes(context, attrs, defStyle);
}
- private void processAttributes(Context context, AttributeSet attrs, int defStyle) {
- if (attrs == null) {
- return;
- }
+ @Override
+ protected int[] getAttributeNames() {
+ return new int[] { android.R.attr.text };
+ }
- TypedArray types = context.obtainStyledAttributes(attrs, new int[] {
- android.R.attr.text }, defStyle, 0);
- this.text = types.getString(0);
- types.recycle();
+ @Override
+ protected void processAttributeValues(TypedArray values) {
+ this.text = values.getString(0);
}
@Override
@@ -67,20 +69,21 @@ public class TextPreference extends Preference {
@Override
public void setSummary(CharSequence summaryText) {
// the layout hasn't been inflated yet, save the summaryText for later use
- if (this.summaryView == null) {
+ if (summaryView == null) {
this.summaryText = summaryText;
return;
}
- // if summaryText is null, take it from the previous saved summary
+ // if summaryText is null, take it from the previously saved summary
if (summaryText == null) {
if (this.summaryText == null) {
return;
}
- this.summaryView.setText(this.summaryText);
+ summaryView.setText(this.summaryText);
} else {
- this.summaryView.setText(summaryText);
+ summaryView.setText(summaryText);
}
this.summaryView.setVisibility(View.VISIBLE);
}
+
}
diff --git a/main/src/cgeo/geocaching/settings/WpThresholdPreference.java b/main/src/cgeo/geocaching/settings/WpThresholdPreference.java
index 867714f..4c43acf 100644
--- a/main/src/cgeo/geocaching/settings/WpThresholdPreference.java
+++ b/main/src/cgeo/geocaching/settings/WpThresholdPreference.java
@@ -1,7 +1,6 @@
package cgeo.geocaching.settings;
import cgeo.geocaching.R;
-import cgeo.geocaching.settings.Settings;
import android.content.Context;
import android.preference.Preference;
@@ -14,7 +13,7 @@ import android.widget.TextView;
public class WpThresholdPreference extends Preference {
- TextView valueView;
+ private TextView valueView;
public WpThresholdPreference(Context context) {
super(context);