| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
package android.preference; |
| 18 |
|
| 19 |
import android.content.Context; |
| 20 |
import android.content.Intent; |
| 21 |
import android.util.AttributeSet; |
| 22 |
|
| 23 |
import com.android.internal.util.XmlUtils; |
| 24 |
|
| 25 |
import org.xmlpull.v1.XmlPullParser; |
| 26 |
import org.xmlpull.v1.XmlPullParserException; |
| 27 |
|
| 28 |
import java.io.IOException; |
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
@Deprecated |
| 45 |
class PreferenceInflater extends GenericInflater<Preference, PreferenceGroup> { |
| 46 |
private static final String TAG = "PreferenceInflater"; |
| 47 |
private static final String INTENT_TAG_NAME = "intent"; |
| 48 |
private static final String EXTRA_TAG_NAME = "extra"; |
| 49 |
|
| 50 |
private PreferenceManager mPreferenceManager; |
| 51 |
|
| 52 |
public PreferenceInflater(Context context, PreferenceManager preferenceManager) { |
| 53 |
super(context); |
| 54 |
init(preferenceManager); |
| 55 |
} |
| 56 |
|
| 57 |
PreferenceInflater(GenericInflater<Preference, PreferenceGroup> original, PreferenceManager preferenceManager, Context newContext) { |
| 58 |
super(original, newContext); |
| 59 |
init(preferenceManager); |
| 60 |
} |
| 61 |
|
| 62 |
@Override |
| 63 |
public GenericInflater<Preference, PreferenceGroup> cloneInContext(Context newContext) { |
| 64 |
return new PreferenceInflater(this, mPreferenceManager, newContext); |
| 65 |
} |
| 66 |
|
| 67 |
private void init(PreferenceManager preferenceManager) { |
| 68 |
mPreferenceManager = preferenceManager; |
| 69 |
setDefaultPackage("android.preference."); |
| 70 |
} |
| 71 |
|
| 72 |
@Override |
| 73 |
protected boolean onCreateCustomFromTag(XmlPullParser parser, Preference parentPreference, |
| 74 |
AttributeSet attrs) throws XmlPullParserException { |
| 75 |
final String tag = parser.getName(); |
| 76 |
|
| 77 |
if (tag.equals(INTENT_TAG_NAME)) { |
| 78 |
Intent intent = null; |
| 79 |
|
| 80 |
try { |
| 81 |
intent = Intent.parseIntent(getContext().getResources(), parser, attrs); |
| 82 |
} catch (IOException e) { |
| 83 |
XmlPullParserException ex = new XmlPullParserException( |
| 84 |
"Error parsing preference"); |
| 85 |
ex.initCause(e); |
| 86 |
throw ex; |
| 87 |
} |
| 88 |
|
| 89 |
if (intent != null) { |
| 90 |
parentPreference.setIntent(intent); |
| 91 |
} |
| 92 |
|
| 93 |
return true; |
| 94 |
} else if (tag.equals(EXTRA_TAG_NAME)) { |
| 95 |
getContext().getResources().parseBundleExtra(EXTRA_TAG_NAME, attrs, |
| 96 |
parentPreference.getExtras()); |
| 97 |
try { |
| 98 |
XmlUtils.skipCurrentTag(parser); |
| 99 |
} catch (IOException e) { |
| 100 |
XmlPullParserException ex = new XmlPullParserException( |
| 101 |
"Error parsing preference"); |
| 102 |
ex.initCause(e); |
| 103 |
throw ex; |
| 104 |
} |
| 105 |
return true; |
| 106 |
} |
| 107 |
|
| 108 |
return false; |
| 109 |
} |
| 110 |
|
| 111 |
@Override |
| 112 |
protected PreferenceGroup onMergeRoots(PreferenceGroup givenRoot, boolean attachToGivenRoot, |
| 113 |
PreferenceGroup xmlRoot) { |
| 114 |
|
| 115 |
|
| 116 |
if (givenRoot == null) { |
| 117 |
xmlRoot.onAttachedToHierarchy(mPreferenceManager); |
| 118 |
return xmlRoot; |
| 119 |
} else { |
| 120 |
return givenRoot; |
| 121 |
} |
| 122 |
} |
| 123 |
|
| 124 |
} |