Merge "WindowDecorActionBar name change fix." into mnc-ub-dev
This commit is contained in:
committed by
Android (Google) Code Review
commit
62302bd72a
@@ -16,10 +16,13 @@
|
|||||||
|
|
||||||
package com.android.layoutlib.bridge.bars;
|
package com.android.layoutlib.bridge.bars;
|
||||||
|
|
||||||
|
import com.android.ide.common.rendering.api.LayoutLog;
|
||||||
|
import com.android.ide.common.rendering.api.LayoutlibCallback;
|
||||||
import com.android.ide.common.rendering.api.RenderResources;
|
import com.android.ide.common.rendering.api.RenderResources;
|
||||||
import com.android.ide.common.rendering.api.ResourceValue;
|
import com.android.ide.common.rendering.api.ResourceValue;
|
||||||
import com.android.ide.common.rendering.api.SessionParams;
|
import com.android.ide.common.rendering.api.SessionParams;
|
||||||
import com.android.ide.common.rendering.api.StyleResourceValue;
|
import com.android.ide.common.rendering.api.StyleResourceValue;
|
||||||
|
import com.android.layoutlib.bridge.Bridge;
|
||||||
import com.android.layoutlib.bridge.android.BridgeContext;
|
import com.android.layoutlib.bridge.android.BridgeContext;
|
||||||
import com.android.layoutlib.bridge.impl.ResourceHelper;
|
import com.android.layoutlib.bridge.impl.ResourceHelper;
|
||||||
import com.android.resources.ResourceType;
|
import com.android.resources.ResourceType;
|
||||||
@@ -45,6 +48,8 @@ public class AppCompatActionBar extends BridgeActionBar {
|
|||||||
|
|
||||||
private Object mWindowDecorActionBar;
|
private Object mWindowDecorActionBar;
|
||||||
private static final String WINDOW_ACTION_BAR_CLASS = "android.support.v7.internal.app.WindowDecorActionBar";
|
private static final String WINDOW_ACTION_BAR_CLASS = "android.support.v7.internal.app.WindowDecorActionBar";
|
||||||
|
// This is used on v23.1.1 and later.
|
||||||
|
private static final String WINDOW_ACTION_BAR_CLASS_NEW = "android.support.v7.app.WindowDecorActionBar";
|
||||||
private Class<?> mWindowActionBarClass;
|
private Class<?> mWindowActionBarClass;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -70,14 +75,26 @@ public class AppCompatActionBar extends BridgeActionBar {
|
|||||||
try {
|
try {
|
||||||
Class[] constructorParams = {View.class};
|
Class[] constructorParams = {View.class};
|
||||||
Object[] constructorArgs = {getDecorContent()};
|
Object[] constructorArgs = {getDecorContent()};
|
||||||
mWindowDecorActionBar = params.getLayoutlibCallback().loadView(WINDOW_ACTION_BAR_CLASS,
|
LayoutlibCallback callback = params.getLayoutlibCallback();
|
||||||
constructorParams, constructorArgs);
|
// First try to load the class as was available before appcompat v23.1.1, without
|
||||||
|
// logging warnings.
|
||||||
|
try {
|
||||||
|
mWindowDecorActionBar = callback.loadClass(WINDOW_ACTION_BAR_CLASS,
|
||||||
|
constructorParams, constructorArgs);
|
||||||
|
} catch (ClassNotFoundException ignore) {
|
||||||
|
}
|
||||||
|
if (mWindowDecorActionBar == null) {
|
||||||
|
// If failed, load the new class, while logging warnings.
|
||||||
|
mWindowDecorActionBar = callback.loadView(WINDOW_ACTION_BAR_CLASS_NEW,
|
||||||
|
constructorParams, constructorArgs);
|
||||||
|
}
|
||||||
|
|
||||||
mWindowActionBarClass = mWindowDecorActionBar == null ? null :
|
mWindowActionBarClass = mWindowDecorActionBar == null ? null :
|
||||||
mWindowDecorActionBar.getClass();
|
mWindowDecorActionBar.getClass();
|
||||||
setupActionBar();
|
setupActionBar();
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
Bridge.getLog().warning(LayoutLog.TAG_BROKEN,
|
||||||
|
"Failed to load AppCompat ActionBar with unknown error.", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user