aboutsummaryrefslogtreecommitdiffstats
path: root/main/src/cgeo/geocaching/settings/TextPreference.java
diff options
context:
space:
mode:
Diffstat (limited to 'main/src/cgeo/geocaching/settings/TextPreference.java')
-rw-r--r--main/src/cgeo/geocaching/settings/TextPreference.java45
1 files changed, 24 insertions, 21 deletions
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);
}
+
}