am c7fe9793: am 48ab6bec: am 8c686ddd: am d20a518c: Merge "Make Preference-cookie map non static." into lmp-dev
* commit 'c7fe979303eb924d7fbb9fa342cc5cd7b929c2d2': Make Preference-cookie map non static.
This commit is contained in:
@@ -16,35 +16,36 @@
|
||||
|
||||
package android.preference;
|
||||
|
||||
import com.android.layoutlib.bridge.android.BridgeContext;
|
||||
import com.android.layoutlib.bridge.android.BridgeXmlBlockParser;
|
||||
|
||||
import android.content.Context;
|
||||
import android.util.AttributeSet;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
public class BridgePreferenceInflater extends PreferenceInflater {
|
||||
|
||||
private final Map<Preference, Object> mViewCookieMap;
|
||||
|
||||
public BridgePreferenceInflater(Context context, PreferenceManager preferenceManager,
|
||||
Map<Preference, Object> viewCookieMap) {
|
||||
public BridgePreferenceInflater(Context context, PreferenceManager preferenceManager) {
|
||||
super(context, preferenceManager);
|
||||
mViewCookieMap = viewCookieMap;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Preference onCreateItem(String name, AttributeSet attrs)
|
||||
throws ClassNotFoundException {
|
||||
Object viewKey;
|
||||
Object viewKey = null;
|
||||
BridgeContext bc = null;
|
||||
|
||||
Context context = getContext();
|
||||
if (context instanceof BridgeContext) {
|
||||
bc = (BridgeContext) context;
|
||||
}
|
||||
if (attrs instanceof BridgeXmlBlockParser) {
|
||||
viewKey = ((BridgeXmlBlockParser) attrs).getViewCookie();
|
||||
} else {
|
||||
viewKey = null;
|
||||
}
|
||||
|
||||
Preference preference = super.onCreateItem(name, attrs);
|
||||
if (viewKey != null) {
|
||||
mViewCookieMap.put(preference, viewKey);
|
||||
|
||||
if (viewKey != null && bc != null) {
|
||||
bc.addCookie(preference, viewKey);
|
||||
}
|
||||
return preference;
|
||||
}
|
||||
|
||||
@@ -40,29 +40,27 @@ import java.util.Map;
|
||||
*/
|
||||
public class Preference_Delegate {
|
||||
|
||||
private static final Map<Preference, Object> sViewCookies = new HashMap<Preference, Object>();
|
||||
|
||||
@LayoutlibDelegate
|
||||
/*package*/ static View getView(Preference pref, View convertView, ViewGroup parent) {
|
||||
Context context = pref.getContext();
|
||||
BridgeContext bc = context instanceof BridgeContext ? ((BridgeContext) context) : null;
|
||||
convertView = pref.getView_Original(convertView, parent);
|
||||
Object cookie = sViewCookies.get(pref);
|
||||
if (bc != null && cookie != null) {
|
||||
bc.addViewKey(convertView, cookie);
|
||||
if (bc != null) {
|
||||
Object cookie = bc.getCookie(pref);
|
||||
if (cookie != null) {
|
||||
bc.addViewKey(convertView, cookie);
|
||||
}
|
||||
}
|
||||
return convertView;
|
||||
}
|
||||
|
||||
/**
|
||||
* Inflates the parser and returns the ListView containing the Preferences. The caller must call
|
||||
* {@link #clearCookiesMap()} when the rendering is complete.
|
||||
* Inflates the parser and returns the ListView containing the Preferences.
|
||||
*/
|
||||
public static View inflatePreference(Context context, XmlPullParser parser, ViewGroup root) {
|
||||
assert sViewCookies.isEmpty();
|
||||
PreferenceManager pm = new PreferenceManager(context);
|
||||
PreferenceScreen ps = pm.getPreferenceScreen();
|
||||
PreferenceInflater inflater = new BridgePreferenceInflater(context, pm, sViewCookies);
|
||||
PreferenceInflater inflater = new BridgePreferenceInflater(context, pm);
|
||||
ps = (PreferenceScreen) inflater.inflate(parser, ps, true);
|
||||
ListView preferenceView = createContainerView(context, root);
|
||||
ps.bind(preferenceView);
|
||||
@@ -82,8 +80,4 @@ public class Preference_Delegate {
|
||||
|
||||
return (ListView) root.findViewById(android.R.id.list);
|
||||
}
|
||||
|
||||
public static void clearCookiesMap() {
|
||||
sViewCookies.clear();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -93,8 +93,15 @@ import java.util.Map;
|
||||
*/
|
||||
public final class BridgeContext extends Context {
|
||||
|
||||
private Resources mSystemResources;
|
||||
/** The map adds cookies to each view so that IDE can link xml tags to views. */
|
||||
private final HashMap<View, Object> mViewKeyMap = new HashMap<View, Object>();
|
||||
/**
|
||||
* In some cases, when inflating an xml, some objects are created. Then later, the objects are
|
||||
* converted to views. This map stores the mapping from objects to cookies which can then be
|
||||
* used to populate the mViewKeyMap.
|
||||
*/
|
||||
private final HashMap<Object, Object> mViewKeyHelpMap = new HashMap<Object, Object>();
|
||||
private Resources mSystemResources;
|
||||
private final Object mProjectKey;
|
||||
private final DisplayMetrics mMetrics;
|
||||
private final RenderResources mRenderResources;
|
||||
@@ -191,6 +198,14 @@ public final class BridgeContext extends Context {
|
||||
return mViewKeyMap.get(view);
|
||||
}
|
||||
|
||||
public void addCookie(Object o, Object cookie) {
|
||||
mViewKeyHelpMap.put(o, cookie);
|
||||
}
|
||||
|
||||
public Object getCookie(Object o) {
|
||||
return mViewKeyHelpMap.get(o);
|
||||
}
|
||||
|
||||
public Object getProjectKey() {
|
||||
return mProjectKey;
|
||||
}
|
||||
|
||||
@@ -599,9 +599,6 @@ public class RenderSessionImpl extends RenderAction<SessionParams> {
|
||||
mSystemViewInfoList = visitAllChildren(mViewRoot, 0, params.getExtendedViewInfoMode(),
|
||||
false);
|
||||
|
||||
// clear the preferences cookie map.
|
||||
Preference_Delegate.clearCookiesMap();
|
||||
|
||||
// success!
|
||||
return SUCCESS.createResult();
|
||||
} catch (Throwable e) {
|
||||
|
||||
Reference in New Issue
Block a user