Mercurial > gmapzoominvert
comparison XposedLibrary/src/de/robv/android/xposed/library/ui/IntegerListPreference.java @ 0:3da8a7a621cd
Initial commit
author | Brad Greco <brad@bgreco.net> |
---|---|
date | Mon, 20 Jan 2014 22:56:13 -0600 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:3da8a7a621cd |
---|---|
1 package de.robv.android.xposed.library.ui; | |
2 | |
3 import android.content.Context; | |
4 import android.content.SharedPreferences; | |
5 import android.preference.ListPreference; | |
6 import android.util.AttributeSet; | |
7 | |
8 public class IntegerListPreference extends ListPreference { | |
9 public IntegerListPreference(Context context) { | |
10 super(context); | |
11 } | |
12 | |
13 public IntegerListPreference(Context context, AttributeSet attrs) { | |
14 super(context, attrs); | |
15 } | |
16 | |
17 @Override | |
18 public void setValue(String value) { | |
19 super.setValue(value); | |
20 notifyChanged(); | |
21 } | |
22 | |
23 @Override | |
24 protected boolean persistString(String value) { | |
25 if (value == null) | |
26 return false; | |
27 | |
28 return persistInt(getIntValue(value)); | |
29 } | |
30 | |
31 @Override | |
32 protected String getPersistedString(String defaultReturnValue) { | |
33 SharedPreferences pref = getPreferenceManager().getSharedPreferences(); | |
34 String key = getKey(); | |
35 if (!shouldPersist() || !pref.contains(key)) | |
36 return defaultReturnValue; | |
37 | |
38 return String.valueOf(pref.getInt(key, 0)); | |
39 } | |
40 | |
41 @Override | |
42 public int findIndexOfValue(String value) { | |
43 CharSequence[] entryValues = getEntryValues(); | |
44 int intValue = getIntValue(value); | |
45 if (value != null && entryValues != null) { | |
46 for (int i = entryValues.length - 1; i >= 0; i--) { | |
47 if (getIntValue(entryValues[i].toString()) == intValue) { | |
48 return i; | |
49 } | |
50 } | |
51 } | |
52 return -1; | |
53 } | |
54 | |
55 public static int getIntValue(String value) { | |
56 if (value == null) | |
57 return 0; | |
58 | |
59 return (int)((value.startsWith("0x")) | |
60 ? Long.parseLong(value.substring(2), 16) | |
61 : Long.parseLong(value)); | |
62 } | |
63 } |