Merge "Allowed custom secure-adb confirmation via Activity or Service. It used to only be available via an Activity." into klp-modular-dev
diff --git a/api/current.txt b/api/current.txt
index ee6f3f2..24ed33e 100644
--- a/api/current.txt
+++ b/api/current.txt
@@ -17667,6 +17667,7 @@
field public static final int JELLY_BEAN_MR1 = 17; // 0x11
field public static final int JELLY_BEAN_MR2 = 18; // 0x12
field public static final int KITKAT = 19; // 0x13
+ field public static final int KITKAT_WATCH = 10000; // 0x2710
}
public final class Bundle implements java.lang.Cloneable android.os.Parcelable {
@@ -28945,6 +28946,7 @@
method public boolean hasInsets();
method public boolean hasSystemWindowInsets();
method public boolean hasWindowDecorInsets();
+ method public boolean isRound();
}
public abstract interface WindowManager implements android.view.ViewManager {
diff --git a/core/java/android/app/ActivityManagerNative.java b/core/java/android/app/ActivityManagerNative.java
index 0b85686..14c495f 100644
--- a/core/java/android/app/ActivityManagerNative.java
+++ b/core/java/android/app/ActivityManagerNative.java
@@ -1998,7 +1998,7 @@
data.enforceInterface(IActivityManager.descriptor);
IBinder parentActivityToken = data.readStrongBinder();
IActivityContainerCallback callback =
- (IActivityContainerCallback) data.readStrongBinder();
+ IActivityContainerCallback.Stub.asInterface(data.readStrongBinder());
IActivityContainer activityContainer =
createActivityContainer(parentActivityToken, callback);
reply.writeNoException();
@@ -4627,7 +4627,7 @@
Parcel reply = Parcel.obtain();
data.writeInterfaceToken(IActivityManager.descriptor);
data.writeStrongBinder(parentActivityToken);
- data.writeStrongBinder((IBinder)callback);
+ data.writeStrongBinder(callback == null ? null : callback.asBinder());
mRemote.transact(CREATE_ACTIVITY_CONTAINER_TRANSACTION, data, reply, 0);
reply.readException();
final int result = reply.readInt();
diff --git a/core/java/android/app/ActivityView.java b/core/java/android/app/ActivityView.java
index 113f123..51cb12a 100644
--- a/core/java/android/app/ActivityView.java
+++ b/core/java/android/app/ActivityView.java
@@ -92,8 +92,8 @@
super.onAttachedToWindow();
try {
final IBinder token = mActivity.getActivityToken();
- mActivityContainer =
- ActivityManagerNative.getDefault().createActivityContainer(token, null);
+ mActivityContainer = ActivityManagerNative.getDefault().createActivityContainer(token,
+ new ActivityContainerCallback());
} catch (RemoteException e) {
throw new IllegalStateException("ActivityView: Unable to create ActivityContainer. "
+ e);
@@ -282,4 +282,14 @@
}
}
+
+ private class ActivityContainerCallback extends IActivityContainerCallback.Stub {
+ @Override
+ public void setVisible(IBinder container, boolean visible) {
+ if (DEBUG) Log.v(TAG, "setVisible(): container=" + container + " visible=" + visible);
+ if (visible) {
+ } else {
+ }
+ }
+ }
}
diff --git a/core/java/android/app/IActivityContainerCallback.aidl b/core/java/android/app/IActivityContainerCallback.aidl
index 55c2001..7f6d2c3 100644
--- a/core/java/android/app/IActivityContainerCallback.aidl
+++ b/core/java/android/app/IActivityContainerCallback.aidl
@@ -20,5 +20,5 @@
/** @hide */
interface IActivityContainerCallback {
- oneway void onLastActivityRemoved(IBinder container);
+ oneway void setVisible(IBinder container, boolean visible);
}
diff --git a/core/java/android/content/res/Resources.java b/core/java/android/content/res/Resources.java
index cd5b5d2f..02e1761 100644
--- a/core/java/android/content/res/Resources.java
+++ b/core/java/android/content/res/Resources.java
@@ -1461,6 +1461,11 @@
private final AssetManager mAssets;
private final int mTheme;
+
+ // Needed by layoutlib.
+ /*package*/ int getNativeTheme() {
+ return mTheme;
+ }
}
/**
diff --git a/core/java/android/os/Build.java b/core/java/android/os/Build.java
index 22e1476..bc5ea72 100644
--- a/core/java/android/os/Build.java
+++ b/core/java/android/os/Build.java
@@ -467,6 +467,11 @@
* </ul>
*/
public static final int KITKAT = 19;
+
+ /**
+ * Android 4.5: KitKat for watches, snacks on the run.
+ */
+ public static final int KITKAT_WATCH = CUR_DEVELOPMENT; // STOPSHIP: update API level
}
/** The type of build, like "user" or "eng". */
diff --git a/core/java/android/view/ViewRootImpl.java b/core/java/android/view/ViewRootImpl.java
index 521cfbfa..db80aed 100644
--- a/core/java/android/view/ViewRootImpl.java
+++ b/core/java/android/view/ViewRootImpl.java
@@ -1151,6 +1151,11 @@
return windowSizeMayChange;
}
+ void dispatchApplyInsets(View host) {
+ mFitSystemWindowsInsets.set(mAttachInfo.mContentInsets);
+ host.dispatchApplyWindowInsets(new WindowInsets(mFitSystemWindowsInsets));
+ }
+
private void performTraversals() {
// cache mView since it is used so much below...
final View host = mView;
@@ -1242,8 +1247,7 @@
}
host.dispatchAttachedToWindow(attachInfo, 0);
attachInfo.mTreeObserver.dispatchOnWindowAttachedChange(true);
- mFitSystemWindowsInsets.set(mAttachInfo.mContentInsets);
- host.fitSystemWindows(mFitSystemWindowsInsets);
+ dispatchApplyInsets(host);
//Log.i(TAG, "Screen on initialized: " + attachInfo.mKeepScreenOn);
} else {
@@ -1368,9 +1372,8 @@
if (mFitSystemWindowsRequested) {
mFitSystemWindowsRequested = false;
- mFitSystemWindowsInsets.set(mAttachInfo.mContentInsets);
mLastOverscanRequested = mAttachInfo.mOverscanRequested;
- host.fitSystemWindows(mFitSystemWindowsInsets);
+ dispatchApplyInsets(host);
if (mLayoutRequested) {
// Short-circuit catching a new layout request here, so
// we don't need to go through two layout passes when things
@@ -1549,8 +1552,7 @@
mLastSystemUiVisibility = mAttachInfo.mSystemUiVisibility;
mLastOverscanRequested = mAttachInfo.mOverscanRequested;
mFitSystemWindowsRequested = false;
- mFitSystemWindowsInsets.set(mAttachInfo.mContentInsets);
- host.fitSystemWindows(mFitSystemWindowsInsets);
+ dispatchApplyInsets(host);
}
if (visibleInsetsChanged) {
mAttachInfo.mVisibleInsets.set(mPendingVisibleInsets);
diff --git a/core/java/android/view/WindowInsets.java b/core/java/android/view/WindowInsets.java
index cdfcb43..f8cc793 100644
--- a/core/java/android/view/WindowInsets.java
+++ b/core/java/android/view/WindowInsets.java
@@ -33,6 +33,7 @@
private Rect mSystemWindowInsets;
private Rect mWindowDecorInsets;
private Rect mTempRect;
+ private boolean mIsRound;
private static final Rect EMPTY_RECT = new Rect(0, 0, 0, 0);
@@ -46,8 +47,14 @@
/** @hide */
public WindowInsets(Rect systemWindowInsets, Rect windowDecorInsets) {
+ this(systemWindowInsets, windowDecorInsets, false);
+ }
+
+ /** @hide */
+ public WindowInsets(Rect systemWindowInsets, Rect windowDecorInsets, boolean isRound) {
mSystemWindowInsets = systemWindowInsets;
mWindowDecorInsets = windowDecorInsets;
+ mIsRound = isRound;
}
/**
@@ -58,12 +65,12 @@
public WindowInsets(WindowInsets src) {
mSystemWindowInsets = src.mSystemWindowInsets;
mWindowDecorInsets = src.mWindowDecorInsets;
+ mIsRound = src.mIsRound;
}
/** @hide */
public WindowInsets(Rect systemWindowInsets) {
- mSystemWindowInsets = systemWindowInsets;
- mWindowDecorInsets = EMPTY_RECT;
+ this(systemWindowInsets, EMPTY_RECT);
}
/**
@@ -220,6 +227,20 @@
return hasSystemWindowInsets() || hasWindowDecorInsets();
}
+ /**
+ * Returns true if the associated window has a round shape.
+ *
+ * <p>A round window's left, top, right and bottom edges reach all the way to the
+ * associated edges of the window but the corners may not be visible. Views responding
+ * to round insets should take care to not lay out critical elements within the corners
+ * where they may not be accessible.</p>
+ *
+ * @return True if the window is round
+ */
+ public boolean isRound() {
+ return mIsRound;
+ }
+
public WindowInsets cloneWithSystemWindowInsetsConsumed() {
final WindowInsets result = new WindowInsets(this);
result.mSystemWindowInsets = new Rect(0, 0, 0, 0);
@@ -273,6 +294,6 @@
@Override
public String toString() {
return "WindowInsets{systemWindowInsets=" + mSystemWindowInsets + " windowDecorInsets=" +
- mWindowDecorInsets + "}";
+ mWindowDecorInsets + (isRound() ? "round}" : "}");
}
}
diff --git a/core/java/android/widget/ShareActionProvider.java b/core/java/android/widget/ShareActionProvider.java
index bdaaa01..fd6ca4c 100644
--- a/core/java/android/widget/ShareActionProvider.java
+++ b/core/java/android/widget/ShareActionProvider.java
@@ -161,9 +161,11 @@
@Override
public View onCreateActionView() {
// Create the view and set its data model.
- ActivityChooserModel dataModel = ActivityChooserModel.get(mContext, mShareHistoryFileName);
ActivityChooserView activityChooserView = new ActivityChooserView(mContext);
- activityChooserView.setActivityChooserModel(dataModel);
+ if (!activityChooserView.isInEditMode()) {
+ ActivityChooserModel dataModel = ActivityChooserModel.get(mContext, mShareHistoryFileName);
+ activityChooserView.setActivityChooserModel(dataModel);
+ }
// Lookup and set the expand action icon.
TypedValue outTypedValue = new TypedValue();
diff --git a/core/java/com/android/internal/app/ActionBarImpl.java b/core/java/com/android/internal/app/ActionBarImpl.java
index 066d6c3..ad45894 100644
--- a/core/java/com/android/internal/app/ActionBarImpl.java
+++ b/core/java/com/android/internal/app/ActionBarImpl.java
@@ -174,6 +174,15 @@
init(dialog.getWindow().getDecorView());
}
+ /**
+ * Only for edit mode.
+ * @hide
+ */
+ public ActionBarImpl(View layout) {
+ assert layout.isInEditMode();
+ init(layout);
+ }
+
private void init(View decor) {
mContext = decor.getContext();
mOverlayLayout = (ActionBarOverlayLayout) decor.findViewById(
@@ -559,8 +568,8 @@
return;
}
- final FragmentTransaction trans = mActivity.getFragmentManager().beginTransaction()
- .disallowAddToBackStack();
+ final FragmentTransaction trans = mActionView.isInEditMode() ? null :
+ mActivity.getFragmentManager().beginTransaction().disallowAddToBackStack();
if (mSelectedTab == tab) {
if (mSelectedTab != null) {
@@ -578,7 +587,7 @@
}
}
- if (!trans.isEmpty()) {
+ if (trans != null && !trans.isEmpty()) {
trans.commit();
}
}
diff --git a/core/jni/android_util_EventLog.cpp b/core/jni/android_util_EventLog.cpp
index 2593420..8a0eaa2 100644
--- a/core/jni/android_util_EventLog.cpp
+++ b/core/jni/android_util_EventLog.cpp
@@ -177,13 +177,13 @@
break;
}
if (ret < 0) {
- if (errno == EINTR) {
+ if (ret == -EINTR) {
continue;
}
- if (errno == EINVAL) {
+ if (ret == -EINVAL) {
jniThrowException(env, "java/io/IOException", "Event too short");
- } else if (errno != EAGAIN) {
- jniThrowIOException(env, errno); // Will throw on return
+ } else if (ret != -EAGAIN) {
+ jniThrowIOException(env, -ret); // Will throw on return
}
break;
}
diff --git a/services/core/java/com/android/server/am/ActivityStack.java b/services/core/java/com/android/server/am/ActivityStack.java
index 68ef815..42e1a37 100755
--- a/services/core/java/com/android/server/am/ActivityStack.java
+++ b/services/core/java/com/android/server/am/ActivityStack.java
@@ -1025,6 +1025,16 @@
return mStackSupervisor.isFrontStack(this);
}
+ private void setVisibile(ActivityRecord r, boolean visible) {
+ r.visible = visible;
+ mWindowManager.setAppVisibility(r.appToken, visible);
+ final ArrayList<ActivityStack> containers = r.mChildContainers;
+ for (int containerNdx = containers.size() - 1; containerNdx >= 0; --containerNdx) {
+ ActivityContainer container = containers.get(containerNdx).mActivityContainer;
+ container.setVisible(visible);
+ }
+ }
+
/**
* Version of ensureActivitiesVisible that can easily be called anywhere.
*/
@@ -1103,8 +1113,7 @@
if (!r.visible) {
if (DEBUG_VISBILITY) Slog.v(
TAG, "Starting and making visible: " + r);
- r.visible = true;
- mWindowManager.setAppVisibility(r.appToken, true);
+ setVisibile(r, true);
}
if (r != starting) {
mStackSupervisor.startSpecificActivityLocked(r, false, false);
@@ -1130,7 +1139,7 @@
if (mTranslucentActivityWaiting != null) {
mUndrawnActivitiesBelowTopTranslucent.add(r);
}
- mWindowManager.setAppVisibility(r.appToken, true);
+ setVisibile(r, true);
r.sleeping = false;
r.app.pendingUiClean = true;
r.app.thread.scheduleWindowVisibility(r.appToken, true);
@@ -1165,9 +1174,8 @@
// sure they no longer are keeping the screen frozen.
if (r.visible) {
if (DEBUG_VISBILITY) Slog.v(TAG, "Making invisible: " + r);
- r.visible = false;
try {
- mWindowManager.setAppVisibility(r.appToken, false);
+ setVisibile(r, false);
switch (r.state) {
case STOPPING:
case STOPPED:
diff --git a/services/core/java/com/android/server/am/ActivityStackSupervisor.java b/services/core/java/com/android/server/am/ActivityStackSupervisor.java
index 1d8b950..efa3ad49 100644
--- a/services/core/java/com/android/server/am/ActivityStackSupervisor.java
+++ b/services/core/java/com/android/server/am/ActivityStackSupervisor.java
@@ -126,6 +126,7 @@
static final int HANDLE_DISPLAY_ADDED = FIRST_SUPERVISOR_STACK_MSG + 5;
static final int HANDLE_DISPLAY_CHANGED = FIRST_SUPERVISOR_STACK_MSG + 6;
static final int HANDLE_DISPLAY_REMOVED = FIRST_SUPERVISOR_STACK_MSG + 7;
+ static final int CONTAINER_CALLBACK_VISIBILITY = FIRST_SUPERVISOR_STACK_MSG + 8;
private final static String VIRTUAL_DISPLAY_BASE_NAME = "ActivityViewVirtualDisplay";
@@ -2952,6 +2953,14 @@
case HANDLE_DISPLAY_REMOVED: {
handleDisplayRemovedLocked(msg.arg1);
} break;
+ case CONTAINER_CALLBACK_VISIBILITY: {
+ final ActivityContainer container = (ActivityContainer) msg.obj;
+ try {
+ // We only send this message if mCallback is non-null.
+ container.mCallback.setVisible(container.asBinder(), msg.arg1 == 1);
+ } catch (RemoteException e) {
+ }
+ }
}
}
}
@@ -2963,6 +2972,8 @@
final ActivityRecord mParentActivity;
final String mIdString;
+ boolean mVisible = true;
+
/** Display this ActivityStack is currently on. Null if not attached to a Display. */
ActivityDisplay mActivityDisplay;
@@ -3110,6 +3121,16 @@
}
}
+ void setVisible(boolean visible) {
+ if (mVisible != visible) {
+ mVisible = visible;
+ if (mCallback != null) {
+ mHandler.obtainMessage(CONTAINER_CALLBACK_VISIBILITY, visible ? 1 : 0,
+ 0 /* unused */, this).sendToTarget();
+ }
+ }
+ }
+
@Override
public String toString() {
return mIdString + (mActivityDisplay == null ? "N" : "A");
diff --git a/tools/layoutlib/bridge/resources/bars/action_bar.xml b/tools/layoutlib/bridge/resources/bars/action_bar.xml
deleted file mode 100644
index 7adc5af..0000000
--- a/tools/layoutlib/bridge/resources/bars/action_bar.xml
+++ /dev/null
@@ -1,7 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<merge xmlns:android="http://schemas.android.com/apk/res/android">
- <include layout="@android:layout/action_bar_home" />
- <TextView
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"/>
-</merge>
diff --git a/tools/layoutlib/bridge/src/android/content/res/AssetManager_Delegate.java b/tools/layoutlib/bridge/src/android/content/res/AssetManager_Delegate.java
new file mode 100644
index 0000000..f3d6ba3
--- /dev/null
+++ b/tools/layoutlib/bridge/src/android/content/res/AssetManager_Delegate.java
@@ -0,0 +1,48 @@
+/*
+ * Copyright (C) 2014 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package android.content.res;
+
+import com.android.tools.layoutlib.annotations.LayoutlibDelegate;
+
+/**
+ * Delegate used to provide implementation of a select few native methods of {@link AssetManager}
+ * <p/>
+ * Through the layoutlib_create tool, the original native methods of AssetManager have been replaced
+ * by calls to methods of the same name in this delegate class.
+ *
+ */
+public class AssetManager_Delegate {
+
+ @LayoutlibDelegate
+ /*package*/ static int newTheme(AssetManager manager) {
+ return Resources_Theme_Delegate.getDelegateManager()
+ .addNewDelegate(new Resources_Theme_Delegate());
+ }
+
+ @LayoutlibDelegate
+ /*package*/ static void deleteTheme(AssetManager manager, int theme) {
+ Resources_Theme_Delegate.getDelegateManager().removeJavaReferenceFor(theme);
+ }
+
+ @LayoutlibDelegate
+ /*package*/ static void applyThemeStyle(int theme, int styleRes, boolean force) {
+ Resources_Theme_Delegate delegate = Resources_Theme_Delegate.getDelegateManager()
+ .getDelegate(theme);
+ delegate.mThemeResId = styleRes;
+ delegate.force = force;
+ }
+}
diff --git a/tools/layoutlib/bridge/src/android/content/res/Resources_Theme_Delegate.java b/tools/layoutlib/bridge/src/android/content/res/Resources_Theme_Delegate.java
index c9d615c..b89d15f 100644
--- a/tools/layoutlib/bridge/src/android/content/res/Resources_Theme_Delegate.java
+++ b/tools/layoutlib/bridge/src/android/content/res/Resources_Theme_Delegate.java
@@ -16,7 +16,13 @@
package android.content.res;
+import com.android.annotations.Nullable;
+import com.android.ide.common.rendering.api.ResourceReference;
+import com.android.ide.common.rendering.api.StyleResourceValue;
+import com.android.layoutlib.bridge.android.BridgeContext;
+import com.android.layoutlib.bridge.impl.DelegateManager;
import com.android.layoutlib.bridge.impl.RenderSessionImpl;
+import com.android.resources.ResourceType;
import com.android.tools.layoutlib.annotations.LayoutlibDelegate;
import android.content.res.Resources.NotFoundException;
@@ -25,7 +31,7 @@
import android.util.TypedValue;
/**
- * Delegate used to provide new implementation of a select few methods of {@link Resources$Theme}
+ * Delegate used to provide new implementation of a select few methods of {@link Resources.Theme}
*
* Through the layoutlib_create tool, the original methods of Theme have been replaced
* by calls to methods of the same name in this delegate class.
@@ -33,11 +39,30 @@
*/
public class Resources_Theme_Delegate {
+ // Resource identifier for the theme.
+ int mThemeResId;
+ // Whether to use the Theme.mThemeResId as primary theme.
+ boolean force;
+
+ // ---- delegate manager ----
+
+ private static final DelegateManager<Resources_Theme_Delegate> sManager =
+ new DelegateManager<Resources_Theme_Delegate>(Resources_Theme_Delegate.class);
+
+ public static DelegateManager<Resources_Theme_Delegate> getDelegateManager() {
+ return sManager;
+ }
+
+ // ---- delegate methods. ----
+
@LayoutlibDelegate
/*package*/ static TypedArray obtainStyledAttributes(
Resources thisResources, Theme thisTheme,
int[] attrs) {
- return RenderSessionImpl.getCurrentContext().obtainStyledAttributes(attrs);
+ boolean changed = setupResources(thisTheme);
+ TypedArray ta = RenderSessionImpl.getCurrentContext().obtainStyledAttributes(attrs);
+ restoreResources(changed);
+ return ta;
}
@LayoutlibDelegate
@@ -45,15 +70,21 @@
Resources thisResources, Theme thisTheme,
int resid, int[] attrs)
throws NotFoundException {
- return RenderSessionImpl.getCurrentContext().obtainStyledAttributes(resid, attrs);
+ boolean changed = setupResources(thisTheme);
+ TypedArray ta = RenderSessionImpl.getCurrentContext().obtainStyledAttributes(resid, attrs);
+ restoreResources(changed);
+ return ta;
}
@LayoutlibDelegate
/*package*/ static TypedArray obtainStyledAttributes(
Resources thisResources, Theme thisTheme,
AttributeSet set, int[] attrs, int defStyleAttr, int defStyleRes) {
- return RenderSessionImpl.getCurrentContext().obtainStyledAttributes(
- set, attrs, defStyleAttr, defStyleRes);
+ boolean changed = setupResources(thisTheme);
+ TypedArray ta = RenderSessionImpl.getCurrentContext().obtainStyledAttributes(set, attrs,
+ defStyleAttr, defStyleRes);
+ restoreResources(changed);
+ return ta;
}
@LayoutlibDelegate
@@ -61,7 +92,45 @@
Resources thisResources, Theme thisTheme,
int resid, TypedValue outValue,
boolean resolveRefs) {
- return RenderSessionImpl.getCurrentContext().resolveThemeAttribute(
+ boolean changed = setupResources(thisTheme);
+ boolean found = RenderSessionImpl.getCurrentContext().resolveThemeAttribute(
resid, outValue, resolveRefs);
+ restoreResources(changed);
+ return found;
+ }
+
+ // ---- private helper methods ----
+
+ private static boolean setupResources(Theme thisTheme) {
+ Resources_Theme_Delegate themeDelegate = sManager.getDelegate(thisTheme.getNativeTheme());
+ StyleResourceValue style = resolveStyle(themeDelegate.mThemeResId);
+ if (style != null) {
+ RenderSessionImpl.getCurrentContext().getRenderResources()
+ .applyStyle(style, themeDelegate.force);
+ return true;
+ }
+ return false;
+ }
+
+ private static void restoreResources(boolean changed) {
+ if (changed) {
+ RenderSessionImpl.getCurrentContext().getRenderResources().clearStyles();
+ }
+ }
+
+ @Nullable
+ private static StyleResourceValue resolveStyle(int nativeResid) {
+ if (nativeResid == 0) {
+ return null;
+ }
+ BridgeContext context = RenderSessionImpl.getCurrentContext();
+ ResourceReference theme = context.resolveId(nativeResid);
+ if (theme.isFramework()) {
+ return (StyleResourceValue) context.getRenderResources()
+ .getFrameworkResource(ResourceType.STYLE, theme.getName());
+ } else {
+ return (StyleResourceValue) context.getRenderResources()
+ .getProjectResource(ResourceType.STYLE, theme.getName());
+ }
}
}
diff --git a/tools/layoutlib/bridge/src/android/graphics/Bitmap_Delegate.java b/tools/layoutlib/bridge/src/android/graphics/Bitmap_Delegate.java
index 89d7e23..7016136 100644
--- a/tools/layoutlib/bridge/src/android/graphics/Bitmap_Delegate.java
+++ b/tools/layoutlib/bridge/src/android/graphics/Bitmap_Delegate.java
@@ -518,7 +518,8 @@
}
@LayoutlibDelegate
- /*package*/ static void nativeSetHasAlpha(long nativeBitmap, boolean hasAlpha) {
+ /*package*/ static void nativeSetAlphaAndPremultiplied(long nativeBitmap, boolean hasAlpha,
+ boolean isPremul) {
// get the delegate from the native int.
Bitmap_Delegate delegate = sManager.getDelegate(nativeBitmap);
if (delegate == null) {
diff --git a/tools/layoutlib/bridge/src/android/graphics/Region_Delegate.java b/tools/layoutlib/bridge/src/android/graphics/Region_Delegate.java
index ea23649..d2aae92 100644
--- a/tools/layoutlib/bridge/src/android/graphics/Region_Delegate.java
+++ b/tools/layoutlib/bridge/src/android/graphics/Region_Delegate.java
@@ -275,21 +275,21 @@
}
@LayoutlibDelegate
- /*package*/ static boolean nativeSetRegion(long native_dst, long native_src) {
+ /*package*/ static void nativeSetRegion(long native_dst, long native_src) {
Region_Delegate dstRegion = sManager.getDelegate(native_dst);
if (dstRegion == null) {
- return true;
+ return;
}
Region_Delegate srcRegion = sManager.getDelegate(native_src);
if (srcRegion == null) {
- return true;
+ return;
}
dstRegion.mArea.reset();
dstRegion.mArea.add(srcRegion.mArea);
- return true;
+ return;
}
@LayoutlibDelegate
diff --git a/tools/layoutlib/bridge/src/com/android/internal/view/menu/MenuBuilderAccessor.java b/tools/layoutlib/bridge/src/com/android/internal/view/menu/MenuBuilderAccessor.java
new file mode 100644
index 0000000..f0798cb
--- /dev/null
+++ b/tools/layoutlib/bridge/src/com/android/internal/view/menu/MenuBuilderAccessor.java
@@ -0,0 +1,12 @@
+package com.android.internal.view.menu;
+
+import java.util.ArrayList;
+
+/**
+ * To access non public members of {@link MenuBuilder}
+ */
+public class MenuBuilderAccessor {
+ public static ArrayList<MenuItemImpl> getNonActionItems(MenuBuilder builder) {
+ return builder.getNonActionItems();
+ }
+}
diff --git a/tools/layoutlib/bridge/src/com/android/internal/widget/ActionBarAccessor.java b/tools/layoutlib/bridge/src/com/android/internal/widget/ActionBarAccessor.java
new file mode 100644
index 0000000..47a3679
--- /dev/null
+++ b/tools/layoutlib/bridge/src/com/android/internal/widget/ActionBarAccessor.java
@@ -0,0 +1,32 @@
+/*
+ * Copyright (C) 2014 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.internal.widget;
+
+import com.android.internal.view.menu.ActionMenuPresenter;
+
+/**
+ * To access non public members of AbsActionBarView
+ */
+public class ActionBarAccessor {
+
+ /**
+ * Returns the {@link ActionMenuPresenter} associated with the {@link AbsActionBarView}
+ */
+ public static ActionMenuPresenter getActionMenuPresenter(AbsActionBarView view) {
+ return view.mActionMenuPresenter;
+ }
+}
diff --git a/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/Bridge.java b/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/Bridge.java
index ab4be71..fa8050f 100644
--- a/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/Bridge.java
+++ b/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/Bridge.java
@@ -215,7 +215,8 @@
Capability.ADAPTER_BINDING,
Capability.EXTENDED_VIEWINFO,
Capability.FIXED_SCALABLE_NINE_PATCH,
- Capability.RTL);
+ Capability.RTL,
+ Capability.ACTION_BAR);
BridgeAssetManager.initSystem();
diff --git a/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/BridgeRenderSession.java b/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/BridgeRenderSession.java
index f9f4b3a..e0f87fd 100644
--- a/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/BridgeRenderSession.java
+++ b/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/BridgeRenderSession.java
@@ -64,6 +64,11 @@
}
@Override
+ public List<ViewInfo> getSystemRootViews() {
+ return mSession.getSystemViewInfos();
+ }
+
+ @Override
public Map<String, String> getDefaultProperties(Object viewObject) {
return mSession.getDefaultProperties(viewObject);
}
diff --git a/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/android/BridgeContext.java b/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/android/BridgeContext.java
index b9294ab..6595ce1 100644
--- a/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/android/BridgeContext.java
+++ b/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/android/BridgeContext.java
@@ -16,6 +16,7 @@
package com.android.layoutlib.bridge.android;
+import com.android.annotations.Nullable;
import com.android.ide.common.rendering.api.ILayoutPullParser;
import com.android.ide.common.rendering.api.IProjectCallback;
import com.android.ide.common.rendering.api.LayoutLog;
@@ -109,7 +110,7 @@
// maps for dynamically generated id representing style objects (StyleResourceValue)
private Map<Integer, StyleResourceValue> mDynamicIdToStyleMap;
private Map<StyleResourceValue, Integer> mStyleToDynamicIdMap;
- private int mDynamicIdGenerator = 0x01030000; // Base id for framework R.style
+ private int mDynamicIdGenerator = 0x02030000; // Base id for R.style in custom namespace
// cache for TypedArray generated from IStyleResourceValue object
private Map<int[], Map<Integer, TypedArray>> mTypedArrayCache;
@@ -315,6 +316,11 @@
}
}
+ // The base value for R.style is 0x01030000 and the custom style is 0x02030000.
+ // So, if the second byte is 03, it's probably a style.
+ if ((id >> 16 & 0xFF) == 0x03) {
+ return getStyleByDynamicId(id);
+ }
return null;
}
@@ -455,7 +461,10 @@
@Override
public final TypedArray obtainStyledAttributes(int[] attrs) {
- return createStyleBasedTypedArray(mRenderResources.getCurrentTheme(), attrs);
+ // No style is specified here, so create the typed array based on the default theme
+ // and the styles already applied to it. A null value of style indicates that the default
+ // theme should be used.
+ return createStyleBasedTypedArray(null, attrs);
}
@Override
@@ -604,7 +613,8 @@
}
if (value != null) {
- if (value.getFirst() == ResourceType.STYLE) {
+ if ((value.getFirst() == ResourceType.STYLE)
+ || (value.getFirst() == ResourceType.ATTR)) {
// look for the style in the current theme, and its parent:
ResourceValue item = mRenderResources.findItemInTheme(value.getSecond(),
isFrameworkRes);
@@ -723,11 +733,13 @@
/**
* Creates a {@link BridgeTypedArray} by filling the values defined by the int[] with the
- * values found in the given style.
+ * values found in the given style. If no style is specified, the default theme, along with the
+ * styles applied to it are used.
+ *
* @see #obtainStyledAttributes(int, int[])
*/
- private BridgeTypedArray createStyleBasedTypedArray(StyleResourceValue style, int[] attrs)
- throws Resources.NotFoundException {
+ private BridgeTypedArray createStyleBasedTypedArray(@Nullable StyleResourceValue style,
+ int[] attrs) throws Resources.NotFoundException {
List<Pair<String, Boolean>> attributes = searchAttrs(attrs);
@@ -740,8 +752,14 @@
if (attribute != null) {
// look for the value in the given style
- ResourceValue resValue = mRenderResources.findItemInStyle(style,
- attribute.getFirst(), attribute.getSecond());
+ ResourceValue resValue;
+ if (style != null) {
+ resValue = mRenderResources.findItemInStyle(style, attribute.getFirst(),
+ attribute.getSecond());
+ } else {
+ resValue = mRenderResources.findItemInTheme(attribute.getFirst(),
+ attribute.getSecond());
+ }
if (resValue != null) {
// resolve it to make sure there are no references left.
@@ -756,7 +774,6 @@
return ta;
}
-
/**
* The input int[] attrs is a list of attributes. The returns a list of information about
* each attributes. The information is (name, isFramework)
diff --git a/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/bars/ActionBarLayout.java b/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/bars/ActionBarLayout.java
new file mode 100644
index 0000000..69f6a65
--- /dev/null
+++ b/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/bars/ActionBarLayout.java
@@ -0,0 +1,355 @@
+/*
+ * Copyright (C) 2014 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.layoutlib.bridge.bars;
+
+import com.android.annotations.NonNull;
+import com.android.annotations.Nullable;
+import com.android.ide.common.rendering.api.ActionBarCallback;
+import com.android.ide.common.rendering.api.ActionBarCallback.HomeButtonStyle;
+import com.android.ide.common.rendering.api.RenderResources;
+import com.android.ide.common.rendering.api.ResourceValue;
+import com.android.ide.common.rendering.api.SessionParams;
+import com.android.internal.R;
+import com.android.internal.app.ActionBarImpl;
+import com.android.internal.view.menu.MenuBuilder;
+import com.android.internal.view.menu.MenuBuilderAccessor;
+import com.android.internal.view.menu.MenuItemImpl;
+import com.android.internal.widget.ActionBarAccessor;
+import com.android.internal.widget.ActionBarContainer;
+import com.android.internal.widget.ActionBarView;
+import com.android.layoutlib.bridge.android.BridgeContext;
+import com.android.layoutlib.bridge.impl.ResourceHelper;
+import com.android.resources.ResourceType;
+
+import android.app.ActionBar;
+import android.app.ActionBar.Tab;
+import android.app.ActionBar.TabListener;
+import android.app.FragmentTransaction;
+import android.content.Context;
+import android.content.res.TypedArray;
+import android.graphics.drawable.Drawable;
+import android.util.DisplayMetrics;
+import android.util.TypedValue;
+import android.view.Gravity;
+import android.view.LayoutInflater;
+import android.view.MenuInflater;
+import android.view.View;
+import android.view.ViewGroup;
+import android.widget.FrameLayout;
+import android.widget.LinearLayout;
+import android.widget.ListAdapter;
+import android.widget.ListView;
+import android.widget.RelativeLayout;
+
+import java.util.ArrayList;
+
+/**
+ * A layout representing the action bar.
+ */
+public class ActionBarLayout extends LinearLayout {
+
+ // Store another reference to the context so that we don't have to cast it repeatedly.
+ @NonNull private final BridgeContext mBridgeContext;
+ @NonNull private final Context mThemedContext;
+
+ @NonNull private final ActionBar mActionBar;
+
+ // Data for Action Bar.
+ @Nullable private final String mIcon;
+ @Nullable private final String mTitle;
+ @Nullable private final String mSubTitle;
+ private final boolean mSplit;
+ private final boolean mShowHomeAsUp;
+ private final int mNavMode;
+
+ // Helper fields.
+ @NonNull private final MenuBuilder mMenuBuilder;
+ private final int mPopupMaxWidth;
+ @NonNull private final RenderResources res;
+ @Nullable private final ActionBarView mActionBarView;
+ @Nullable private FrameLayout mContentRoot;
+ @NonNull private final ActionBarCallback mCallback;
+
+ // A fake parent for measuring views.
+ @Nullable private ViewGroup mMeasureParent;
+
+ public ActionBarLayout(@NonNull BridgeContext context, @NonNull SessionParams params) {
+
+ super(context);
+ setOrientation(LinearLayout.HORIZONTAL);
+ setGravity(Gravity.CENTER_VERTICAL);
+
+ // Inflate action bar layout.
+ LayoutInflater.from(context).inflate(R.layout.screen_action_bar, this,
+ true /*attachToRoot*/);
+ mActionBar = new ActionBarImpl(this);
+
+ // Set contexts.
+ mBridgeContext = context;
+ mThemedContext = mActionBar.getThemedContext();
+
+ // Set data for action bar.
+ mCallback = params.getProjectCallback().getActionBarCallback();
+ mIcon = params.getAppIcon();
+ mTitle = params.getAppLabel();
+ // Split Action Bar when the screen size is narrow and the application requests split action
+ // bar when narrow.
+ mSplit = context.getResources().getBoolean(R.bool.split_action_bar_is_narrow) &&
+ mCallback.getSplitActionBarWhenNarrow();
+ mNavMode = mCallback.getNavigationMode();
+ // TODO: Support Navigation Drawer Indicator.
+ mShowHomeAsUp = mCallback.getHomeButtonStyle() == HomeButtonStyle.SHOW_HOME_AS_UP;
+ mSubTitle = mCallback.getSubTitle();
+
+
+ // Set helper fields.
+ mMenuBuilder = new MenuBuilder(mThemedContext);
+ res = mBridgeContext.getRenderResources();
+ mPopupMaxWidth = Math.max(mBridgeContext.getMetrics().widthPixels / 2,
+ mThemedContext.getResources().getDimensionPixelSize(
+ R.dimen.config_prefDialogWidth));
+ mActionBarView = (ActionBarView) findViewById(R.id.action_bar);
+ mContentRoot = (FrameLayout) findViewById(android.R.id.content);
+
+ setupActionBar();
+ }
+
+ /**
+ * Sets up the action bar by filling the appropriate data.
+ */
+ private void setupActionBar() {
+ // Add title and sub title.
+ ResourceValue titleValue = res.findResValue(mTitle, false /*isFramework*/);
+ if (titleValue != null && titleValue.getValue() != null) {
+ mActionBar.setTitle(titleValue.getValue());
+ } else {
+ mActionBar.setTitle(mTitle);
+ }
+ if (mSubTitle != null) {
+ mActionBar.setSubtitle(mSubTitle);
+ }
+
+ // Add show home as up icon.
+ if (mShowHomeAsUp) {
+ mActionBar.setDisplayOptions(0xFF, ActionBar.DISPLAY_HOME_AS_UP);
+ }
+
+ // Set the navigation mode.
+ mActionBar.setNavigationMode(mNavMode);
+ if (mNavMode == ActionBar.NAVIGATION_MODE_TABS) {
+ setupTabs(3);
+ }
+
+ if (mActionBarView != null) {
+ // If the action bar style doesn't specify an icon, set the icon obtained from the session
+ // params.
+ if (!mActionBarView.hasIcon() && mIcon != null) {
+ Drawable iconDrawable = getDrawable(mIcon, false /*isFramework*/);
+ if (iconDrawable != null) {
+ mActionBar.setIcon(iconDrawable);
+ }
+ }
+
+ // Set action bar to be split, if needed.
+ mActionBarView.setSplitView((ActionBarContainer) findViewById(R.id.split_action_bar));
+ mActionBarView.setSplitActionBar(mSplit);
+
+ inflateMenus();
+ }
+ }
+
+ /**
+ * Gets the menus to add to the action bar from the callback, resolves them, inflates them and
+ * adds them to the action bar.
+ */
+ private void inflateMenus() {
+ if (mActionBarView == null) {
+ return;
+ }
+ final MenuInflater inflater = new MenuInflater(mThemedContext);
+ for (String name : mCallback.getMenuIdNames()) {
+ if (mBridgeContext.getRenderResources().getProjectResource(ResourceType.MENU, name)
+ != null) {
+ int id = mBridgeContext.getProjectResourceValue(ResourceType.MENU, name, -1);
+ if (id > -1) {
+ inflater.inflate(id, mMenuBuilder);
+ }
+ }
+ }
+ mActionBarView.setMenu(mMenuBuilder, null /*callback*/);
+ }
+
+ // TODO: Use an adapter, like List View to set up tabs.
+ private void setupTabs(int num) {
+ for (int i = 1; i <= num; i++) {
+ Tab tab = mActionBar.newTab().setText("Tab" + i).setTabListener(new TabListener() {
+ @Override
+ public void onTabUnselected(Tab t, FragmentTransaction ft) {
+ // pass
+ }
+ @Override
+ public void onTabSelected(Tab t, FragmentTransaction ft) {
+ // pass
+ }
+ @Override
+ public void onTabReselected(Tab t, FragmentTransaction ft) {
+ // pass
+ }
+ });
+ mActionBar.addTab(tab);
+ }
+ }
+
+ @Nullable
+ private Drawable getDrawable(@NonNull String name, boolean isFramework) {
+ ResourceValue value = res.findResValue(name, isFramework);
+ value = res.resolveResValue(value);
+ if (value != null) {
+ return ResourceHelper.getDrawable(value, mBridgeContext);
+ }
+ return null;
+ }
+
+ /**
+ * Creates a Popup and adds it to the content frame. It also adds another {@link FrameLayout} to
+ * the content frame which shall serve as the new content root.
+ */
+ public void createMenuPopup() {
+ assert mContentRoot != null && findViewById(android.R.id.content) == mContentRoot
+ : "Action Bar Menus have already been created.";
+
+ if (!isOverflowPopupNeeded()) {
+ return;
+ }
+
+ // Create a layout to hold the menus and the user's content.
+ RelativeLayout layout = new RelativeLayout(mThemedContext);
+ layout.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT,
+ LayoutParams.MATCH_PARENT));
+ mContentRoot.addView(layout);
+ // Create a layout for the user's content.
+ FrameLayout contentRoot = new FrameLayout(mBridgeContext);
+ contentRoot.setLayoutParams(new LayoutParams(
+ LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
+ // Add contentRoot and menus to the layout.
+ layout.addView(contentRoot);
+ layout.addView(createMenuView());
+ // ContentRoot is now the view we just created.
+ mContentRoot = contentRoot;
+ }
+
+ /**
+ * Returns a {@link LinearLayout} containing the menu list view to be embedded in a
+ * {@link RelativeLayout}
+ */
+ @NonNull
+ private View createMenuView() {
+ DisplayMetrics metrics = mBridgeContext.getMetrics();
+ OverflowMenuAdapter adapter = new OverflowMenuAdapter(mMenuBuilder, mThemedContext);
+
+ LinearLayout layout = new LinearLayout(mThemedContext);
+ RelativeLayout.LayoutParams layoutParams = new RelativeLayout.LayoutParams(
+ measureContentWidth(adapter), LayoutParams.WRAP_CONTENT);
+ layoutParams.addRule(RelativeLayout.ALIGN_PARENT_END);
+ if (mSplit) {
+ layoutParams.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
+ // TODO: Find correct value instead of hardcoded 10dp.
+ layoutParams.bottomMargin = getPixelValue("-10dp", metrics);
+ } else {
+ layoutParams.topMargin = getPixelValue("-10dp", metrics);
+ }
+ layout.setLayoutParams(layoutParams);
+ final TypedArray a = mThemedContext.obtainStyledAttributes(null,
+ R.styleable.PopupWindow, R.attr.popupMenuStyle, 0);
+ layout.setBackground(a.getDrawable(R.styleable.PopupWindow_popupBackground));
+ layout.setDividerDrawable(a.getDrawable(R.attr.actionBarDivider));
+ a.recycle();
+ layout.setOrientation(LinearLayout.VERTICAL);
+ layout.setDividerPadding(getPixelValue("12dp", metrics));
+ layout.setShowDividers(LinearLayout.SHOW_DIVIDER_MIDDLE);
+
+ ListView listView = new ListView(mThemedContext, null, R.attr.dropDownListViewStyle);
+ listView.setAdapter(adapter);
+ layout.addView(listView);
+ return layout;
+ }
+
+ private boolean isOverflowPopupNeeded() {
+ boolean needed = mCallback.isOverflowPopupNeeded();
+ if (!needed) {
+ return false;
+ }
+ // Copied from android.widget.ActionMenuPresenter.updateMenuView()
+ ArrayList<MenuItemImpl> menus = MenuBuilderAccessor.getNonActionItems(mMenuBuilder);
+ if (ActionBarAccessor.getActionMenuPresenter(mActionBarView).isOverflowReserved() &&
+ menus != null) {
+ final int count = menus.size();
+ if (count == 1) {
+ needed = !menus.get(0).isActionViewExpanded();
+ } else {
+ needed = count > 0;
+ }
+ }
+ return needed;
+ }
+
+ @Nullable
+ public FrameLayout getContentRoot() {
+ return mContentRoot;
+ }
+
+ // Copied from com.android.internal.view.menu.MenuPopHelper.measureContentWidth()
+ private int measureContentWidth(@NonNull ListAdapter adapter) {
+ // Menus don't tend to be long, so this is more sane than it looks.
+ int maxWidth = 0;
+ View itemView = null;
+ int itemType = 0;
+
+ final int widthMeasureSpec = MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED);
+ final int heightMeasureSpec = MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED);
+ final int count = adapter.getCount();
+ for (int i = 0; i < count; i++) {
+ final int positionType = adapter.getItemViewType(i);
+ if (positionType != itemType) {
+ itemType = positionType;
+ itemView = null;
+ }
+
+ if (mMeasureParent == null) {
+ mMeasureParent = new FrameLayout(mThemedContext);
+ }
+
+ itemView = adapter.getView(i, itemView, mMeasureParent);
+ itemView.measure(widthMeasureSpec, heightMeasureSpec);
+
+ final int itemWidth = itemView.getMeasuredWidth();
+ if (itemWidth >= mPopupMaxWidth) {
+ return mPopupMaxWidth;
+ } else if (itemWidth > maxWidth) {
+ maxWidth = itemWidth;
+ }
+ }
+
+ return maxWidth;
+ }
+
+ private int getPixelValue(@NonNull String value, @NonNull DisplayMetrics metrics) {
+ TypedValue typedValue = ResourceHelper.getValue(null, value, false /*requireUnit*/);
+ return (int) typedValue.getDimension(metrics);
+ }
+
+}
diff --git a/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/bars/FakeActionBar.java b/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/bars/FakeActionBar.java
deleted file mode 100644
index 226649d..0000000
--- a/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/bars/FakeActionBar.java
+++ /dev/null
@@ -1,48 +0,0 @@
-/*
- * Copyright (C) 2011 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.layoutlib.bridge.bars;
-
-import com.android.resources.Density;
-
-import org.xmlpull.v1.XmlPullParserException;
-
-import android.content.Context;
-import android.widget.LinearLayout;
-import android.widget.TextView;
-
-public class FakeActionBar extends CustomBar {
-
- private TextView mTextView;
-
- public FakeActionBar(Context context, Density density, String label, String icon)
- throws XmlPullParserException {
- super(context, density, LinearLayout.HORIZONTAL, "/bars/action_bar.xml", "action_bar.xml");
-
- // Cannot access the inside items through id because no R.id values have been
- // created for them.
- // We do know the order though.
- loadIconById(android.R.id.home, icon);
- mTextView = setText(1, label);
-
- setStyle("actionBarStyle");
- }
-
- @Override
- protected TextView getStyleableTextView() {
- return mTextView;
- }
-}
diff --git a/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/bars/OverflowMenuAdapter.java b/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/bars/OverflowMenuAdapter.java
new file mode 100644
index 0000000..79e231c
--- /dev/null
+++ b/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/bars/OverflowMenuAdapter.java
@@ -0,0 +1,100 @@
+/*
+ * Copyright (C) 2014 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.layoutlib.bridge.bars;
+
+import com.android.internal.view.menu.MenuBuilder;
+import com.android.internal.view.menu.MenuBuilderAccessor;
+import com.android.internal.view.menu.MenuItemImpl;
+import com.android.internal.view.menu.MenuView;
+
+import android.content.Context;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.view.ViewGroup;
+import android.widget.BaseAdapter;
+
+import java.util.ArrayList;
+
+/**
+ * Provides an adapter for Overflow menu popup. This is very similar to
+ * {@code MenuPopupHelper.MenuAdapter}
+ */
+public class OverflowMenuAdapter extends BaseAdapter {
+
+ private final MenuBuilder mMenu;
+ private int mExpandedIndex = -1;
+ private final Context context;
+
+ public OverflowMenuAdapter(MenuBuilder menu, Context context) {
+ mMenu = menu;
+ findExpandedIndex();
+ this.context = context;
+ }
+
+ @Override
+ public int getCount() {
+ ArrayList<MenuItemImpl> items = MenuBuilderAccessor.getNonActionItems(mMenu);
+ if (mExpandedIndex < 0) {
+ return items.size();
+ }
+ return items.size() - 1;
+ }
+
+ @Override
+ public MenuItemImpl getItem(int position) {
+ ArrayList<MenuItemImpl> items = MenuBuilderAccessor.getNonActionItems(mMenu);
+ if (mExpandedIndex >= 0 && position >= mExpandedIndex) {
+ position++;
+ }
+ return items.get(position);
+ }
+
+ @Override
+ public long getItemId(int position) {
+ // Since a menu item's ID is optional, we'll use the position as an
+ // ID for the item in the AdapterView
+ return position;
+ }
+
+ @Override
+ public View getView(int position, View convertView, ViewGroup parent) {
+ if (convertView == null) {
+ LayoutInflater mInflater = LayoutInflater.from(context);
+ convertView = mInflater.inflate(com.android.internal.R.layout.popup_menu_item_layout,
+ parent, false);
+ }
+
+ MenuView.ItemView itemView = (MenuView.ItemView) convertView;
+ itemView.initialize(getItem(position), 0);
+ return convertView;
+ }
+
+ private void findExpandedIndex() {
+ final MenuItemImpl expandedItem = mMenu.getExpandedItem();
+ if (expandedItem != null) {
+ final ArrayList<MenuItemImpl> items = MenuBuilderAccessor.getNonActionItems(mMenu);
+ final int count = items.size();
+ for (int i = 0; i < count; i++) {
+ final MenuItemImpl item = items.get(i);
+ if (item == expandedItem) {
+ mExpandedIndex = i;
+ return;
+ }
+ }
+ }
+ }
+}
diff --git a/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/impl/RenderSessionImpl.java b/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/impl/RenderSessionImpl.java
index 377d996..afcadef 100644
--- a/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/impl/RenderSessionImpl.java
+++ b/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/impl/RenderSessionImpl.java
@@ -43,12 +43,13 @@
import com.android.layoutlib.bridge.android.BridgeContext;
import com.android.layoutlib.bridge.android.BridgeLayoutParamsMapAttributes;
import com.android.layoutlib.bridge.android.BridgeXmlBlockParser;
-import com.android.layoutlib.bridge.bars.FakeActionBar;
import com.android.layoutlib.bridge.bars.NavigationBar;
import com.android.layoutlib.bridge.bars.StatusBar;
import com.android.layoutlib.bridge.bars.TitleBar;
+import com.android.layoutlib.bridge.bars.ActionBarLayout;
import com.android.layoutlib.bridge.impl.binding.FakeAdapter;
import com.android.layoutlib.bridge.impl.binding.FakeExpandableAdapter;
+import com.android.resources.Density;
import com.android.resources.ResourceType;
import com.android.resources.ScreenOrientation;
import com.android.util.Pair;
@@ -134,6 +135,7 @@
// information being returned through the API
private BufferedImage mImage;
private List<ViewInfo> mViewInfoList;
+ private List<ViewInfo> mSystemViewInfoList;
private static final class PostInflateException extends Exception {
private static final long serialVersionUID = 1L;
@@ -146,10 +148,11 @@
/**
* Creates a layout scene with all the information coming from the layout bridge API.
* <p>
- * This <b>must</b> be followed by a call to {@link RenderSessionImpl#init()}, which act as a
+ * This <b>must</b> be followed by a call to {@link RenderSessionImpl#init(long)},
+ * which act as a
* call to {@link RenderSessionImpl#acquire(long)}
*
- * @see LayoutBridge#createScene(com.android.layoutlib.api.SceneParams)
+ * @see Bridge#createSession(SessionParams)
*/
public RenderSessionImpl(SessionParams params) {
super(new SessionParams(params));
@@ -225,14 +228,15 @@
HardwareConfig hardwareConfig = params.getHardwareConfig();
BridgeContext context = getContext();
boolean isRtl = Bridge.isLocaleRtl(params.getLocale());
- int direction = isRtl ? View.LAYOUT_DIRECTION_RTL : View.LAYOUT_DIRECTION_LTR;
+ int layoutDirection = isRtl ? View.LAYOUT_DIRECTION_RTL : View.LAYOUT_DIRECTION_LTR;
+ ActionBarLayout actionBar = null;
// the view group that receives the window background.
ViewGroup backgroundView = null;
if (mWindowIsFloating || params.isForceNoDecor()) {
backgroundView = mViewRoot = mContentRoot = new FrameLayout(context);
- mViewRoot.setLayoutDirection(direction);
+ mViewRoot.setLayoutDirection(layoutDirection);
} else {
if (hasSoftwareButtons() && mNavigationBarOrientation == LinearLayout.VERTICAL) {
/*
@@ -254,18 +258,13 @@
the bottom
*/
LinearLayout topLayout = new LinearLayout(context);
- topLayout.setLayoutDirection(direction);
+ topLayout.setLayoutDirection(layoutDirection);
mViewRoot = topLayout;
topLayout.setOrientation(LinearLayout.HORIZONTAL);
try {
- NavigationBar navigationBar = new NavigationBar(context,
- hardwareConfig.getDensity(), LinearLayout.VERTICAL, isRtl,
- params.isRtlSupported());
- navigationBar.setLayoutParams(
- new LinearLayout.LayoutParams(
- mNavigationBarSize,
- LayoutParams.MATCH_PARENT));
+ NavigationBar navigationBar = createNavigationBar(context,
+ hardwareConfig.getDensity(), isRtl, params.isRtlSupported());
topLayout.addView(navigationBar);
} catch (XmlPullParserException e) {
@@ -293,14 +292,15 @@
LinearLayout topLayout = new LinearLayout(context);
topLayout.setOrientation(LinearLayout.VERTICAL);
- topLayout.setLayoutDirection(direction);
+ topLayout.setLayoutDirection(layoutDirection);
// if we don't already have a view root this is it
if (mViewRoot == null) {
mViewRoot = topLayout;
} else {
+ int topLayoutWidth =
+ params.getHardwareConfig().getScreenWidth() - mNavigationBarSize;
LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(
- LayoutParams.WRAP_CONTENT, LayoutParams.MATCH_PARENT);
- layoutParams.weight = 1;
+ topLayoutWidth, LayoutParams.MATCH_PARENT);
topLayout.setLayoutParams(layoutParams);
// this is the case of soft buttons + vertical bar.
@@ -319,12 +319,9 @@
if (mStatusBarSize > 0) {
// system bar
try {
- StatusBar systemBar = new StatusBar(context, hardwareConfig.getDensity(),
- direction, params.isRtlSupported());
- systemBar.setLayoutParams(
- new LinearLayout.LayoutParams(
- LayoutParams.MATCH_PARENT, mStatusBarSize));
- topLayout.addView(systemBar);
+ StatusBar statusBar = createStatusBar(context, hardwareConfig.getDensity(),
+ layoutDirection, params.isRtlSupported());
+ topLayout.addView(statusBar);
} catch (XmlPullParserException e) {
}
@@ -343,23 +340,17 @@
// if the theme says no title/action bar, then the size will be 0
if (mActionBarSize > 0) {
try {
- FakeActionBar actionBar = new FakeActionBar(context,
- hardwareConfig.getDensity(),
- params.getAppLabel(), params.getAppIcon());
- actionBar.setLayoutParams(
- new LinearLayout.LayoutParams(
- LayoutParams.MATCH_PARENT, mActionBarSize));
+ actionBar = createActionBar(context, params);
backgroundLayout.addView(actionBar);
+ actionBar.createMenuPopup();
+ mContentRoot = actionBar.getContentRoot();
} catch (XmlPullParserException e) {
}
} else if (mTitleBarSize > 0) {
try {
- TitleBar titleBar = new TitleBar(context,
+ TitleBar titleBar = createTitleBar(context,
hardwareConfig.getDensity(), params.getAppLabel());
- titleBar.setLayoutParams(
- new LinearLayout.LayoutParams(
- LayoutParams.MATCH_PARENT, mTitleBarSize));
backgroundLayout.addView(titleBar);
} catch (XmlPullParserException e) {
@@ -367,23 +358,21 @@
}
// content frame
- mContentRoot = new FrameLayout(context);
- layoutParams = new LinearLayout.LayoutParams(
- LayoutParams.MATCH_PARENT, 0);
- layoutParams.weight = 1;
- mContentRoot.setLayoutParams(layoutParams);
- backgroundLayout.addView(mContentRoot);
+ if (mContentRoot == null) {
+ mContentRoot = new FrameLayout(context);
+ layoutParams = new LinearLayout.LayoutParams(
+ LayoutParams.MATCH_PARENT, 0);
+ layoutParams.weight = 1;
+ mContentRoot.setLayoutParams(layoutParams);
+ backgroundLayout.addView(mContentRoot);
+ }
if (mNavigationBarOrientation == LinearLayout.HORIZONTAL &&
mNavigationBarSize > 0) {
// system bar
try {
- NavigationBar navigationBar = new NavigationBar(context,
- hardwareConfig.getDensity(), LinearLayout.HORIZONTAL, isRtl,
- params.isRtlSupported());
- navigationBar.setLayoutParams(
- new LinearLayout.LayoutParams(
- LayoutParams.MATCH_PARENT, mNavigationBarSize));
+ NavigationBar navigationBar = createNavigationBar(context,
+ hardwareConfig.getDensity(), isRtl, params.isRtlSupported());
topLayout.addView(navigationBar);
} catch (XmlPullParserException e) {
@@ -441,7 +430,7 @@
* @throws IllegalStateException if the current context is different than the one owned by
* the scene, or if {@link #acquire(long)} was not called.
*
- * @see RenderParams#getRenderingMode()
+ * @see SessionParams#getRenderingMode()
* @see RenderSession#render(long)
*/
public Result render(boolean freshRender) {
@@ -584,7 +573,7 @@
mViewRoot.draw(mCanvas);
}
- mViewInfoList = startVisitingViews(mViewRoot, 0, params.getExtendedViewInfoMode());
+ mSystemViewInfoList = visitAllChildren(mViewRoot, 0, params.getExtendedViewInfoMode(), false);
// success!
return SUCCESS.createResult();
@@ -1369,50 +1358,126 @@
}
}
- private List<ViewInfo> startVisitingViews(View view, int offset, boolean setExtendedInfo) {
- if (view == null) {
- return null;
- }
-
- // adjust the offset to this view.
- offset += view.getTop();
-
- if (view == mContentRoot) {
- return visitAllChildren(mContentRoot, offset, setExtendedInfo);
- }
-
- // otherwise, look for mContentRoot in the children
- if (view instanceof ViewGroup) {
- ViewGroup group = ((ViewGroup) view);
-
- for (int i = 0; i < group.getChildCount(); i++) {
- List<ViewInfo> list = startVisitingViews(group.getChildAt(i), offset,
- setExtendedInfo);
- if (list != null) {
- return list;
- }
- }
- }
-
- return null;
- }
-
/**
- * Visits a View and its children and generate a {@link ViewInfo} containing the
+ * Visits a {@link View} and its children and generate a {@link ViewInfo} containing the
* bounds of all the views.
+ *
* @param view the root View
* @param offset an offset for the view bounds.
* @param setExtendedInfo whether to set the extended view info in the {@link ViewInfo} object.
+ * @param isContentFrame {@code true} if the {@code ViewInfo} to be created is part of the
+ * content frame.
+ *
+ * @return {@code ViewInfo} containing the bounds of the view and it children otherwise.
*/
- private ViewInfo visit(View view, int offset, boolean setExtendedInfo) {
+ private ViewInfo visit(View view, int offset, boolean setExtendedInfo,
+ boolean isContentFrame) {
+ ViewInfo result = createViewInfo(view, offset, setExtendedInfo, isContentFrame);
+
+ if (view instanceof ViewGroup) {
+ ViewGroup group = ((ViewGroup) view);
+ result.setChildren(visitAllChildren(group, isContentFrame ? 0 : offset,
+ setExtendedInfo, isContentFrame));
+ }
+ return result;
+ }
+
+ /**
+ * Visits all the children of a given ViewGroup and generates a list of {@link ViewInfo}
+ * containing the bounds of all the views. It also initializes the {@link #mViewInfoList} with
+ * the children of the {@code mContentRoot}.
+ *
+ * @param viewGroup the root View
+ * @param offset an offset from the top for the content view frame.
+ * @param setExtendedInfo whether to set the extended view info in the {@link ViewInfo} object.
+ * @param isContentFrame {@code true} if the {@code ViewInfo} to be created is part of the
+ * content frame. {@code false} if the {@code ViewInfo} to be created is
+ * part of the system decor.
+ */
+ private List<ViewInfo> visitAllChildren(ViewGroup viewGroup, int offset,
+ boolean setExtendedInfo, boolean isContentFrame) {
+ if (viewGroup == null) {
+ return null;
+ }
+
+ if (!isContentFrame) {
+ offset += viewGroup.getTop();
+ }
+
+ int childCount = viewGroup.getChildCount();
+ if (viewGroup == mContentRoot) {
+ List<ViewInfo> childrenWithoutOffset = new ArrayList<ViewInfo>(childCount);
+ List<ViewInfo> childrenWithOffset = new ArrayList<ViewInfo>(childCount);
+ for (int i = 0; i < childCount; i++) {
+ ViewInfo[] childViewInfo = visitContentRoot(viewGroup.getChildAt(i), offset,
+ setExtendedInfo);
+ childrenWithoutOffset.add(childViewInfo[0]);
+ childrenWithOffset.add(childViewInfo[1]);
+ }
+ mViewInfoList = childrenWithOffset;
+ return childrenWithoutOffset;
+ } else {
+ List<ViewInfo> children = new ArrayList<ViewInfo>(childCount);
+ for (int i = 0; i < childCount; i++) {
+ children.add(visit(viewGroup.getChildAt(i), offset, setExtendedInfo,
+ isContentFrame));
+ }
+ return children;
+ }
+ }
+
+ /**
+ * Visits the children of {@link #mContentRoot} and generates {@link ViewInfo} containing the
+ * bounds of all the views. It returns two {@code ViewInfo} objects with the same children,
+ * one with the {@code offset} and other without the {@code offset}. The offset is needed to
+ * get the right bounds if the {@code ViewInfo} hierarchy is accessed from
+ * {@code mViewInfoList}. When the hierarchy is accessed via {@code mSystemViewInfoList}, the
+ * offset is not needed.
+ *
+ * @return an array of length two, with ViewInfo at index 0 is without offset and ViewInfo at
+ * index 1 is with the offset.
+ */
+ private ViewInfo[] visitContentRoot(View view, int offset, boolean setExtendedInfo) {
+ ViewInfo[] result = new ViewInfo[2];
+ if (view == null) {
+ return result;
+ }
+
+ result[0] = createViewInfo(view, 0, setExtendedInfo, true);
+ result[1] = createViewInfo(view, offset, setExtendedInfo, true);
+ if (view instanceof ViewGroup) {
+ List<ViewInfo> children = visitAllChildren((ViewGroup) view, 0, setExtendedInfo, true);
+ result[0].setChildren(children);
+ result[1].setChildren(children);
+ }
+ return result;
+ }
+
+ /**
+ * Creates a {@link ViewInfo} for the view. The {@code ViewInfo} corresponding to the children
+ * of the {@code view} are not created. Consequently, the children of {@code ViewInfo} is not
+ * set.
+ * @param offset an offset for the view bounds. Used only if view is part of the content frame.
+ */
+ private ViewInfo createViewInfo(View view, int offset, boolean setExtendedInfo,
+ boolean isContentFrame) {
if (view == null) {
return null;
}
- ViewInfo result = new ViewInfo(view.getClass().getName(),
- getContext().getViewKey(view),
- view.getLeft(), view.getTop() + offset, view.getRight(), view.getBottom() + offset,
- view, view.getLayoutParams());
+ ViewInfo result;
+ if (isContentFrame) {
+ result = new ViewInfo(view.getClass().getName(),
+ getContext().getViewKey(view),
+ view.getLeft(), view.getTop() + offset, view.getRight(),
+ view.getBottom() + offset, view, view.getLayoutParams());
+
+ } else {
+ result = new SystemViewInfo(view.getClass().getName(),
+ getContext().getViewKey(view),
+ view.getLeft(), view.getTop(), view.getRight(),
+ view.getBottom(), view, view.getLayoutParams());
+ }
if (setExtendedInfo) {
MarginLayoutParams marginParams = null;
@@ -1427,39 +1492,67 @@
marginParams != null ? marginParams.bottomMargin : 0);
}
- if (view instanceof ViewGroup) {
- ViewGroup group = ((ViewGroup) view);
- result.setChildren(visitAllChildren(group, 0 /*offset*/, setExtendedInfo));
- }
-
return result;
}
- /**
- * Visits all the children of a given ViewGroup generate a list of {@link ViewInfo}
- * containing the bounds of all the views.
- * @param view the root View
- * @param offset an offset for the view bounds.
- * @param setExtendedInfo whether to set the extended view info in the {@link ViewInfo} object.
- */
- private List<ViewInfo> visitAllChildren(ViewGroup viewGroup, int offset,
- boolean setExtendedInfo) {
- if (viewGroup == null) {
- return null;
- }
-
- List<ViewInfo> children = new ArrayList<ViewInfo>();
- for (int i = 0; i < viewGroup.getChildCount(); i++) {
- children.add(visit(viewGroup.getChildAt(i), offset, setExtendedInfo));
- }
- return children;
- }
-
-
private void invalidateRenderingSize() {
mMeasuredScreenWidth = mMeasuredScreenHeight = -1;
}
+ /**
+ * Creates the status bar with wifi and battery icons.
+ */
+ private StatusBar createStatusBar(BridgeContext context, Density density, int direction,
+ boolean isRtlSupported) throws XmlPullParserException {
+ StatusBar statusBar = new StatusBar(context, density,
+ direction, isRtlSupported);
+ statusBar.setLayoutParams(
+ new LinearLayout.LayoutParams(
+ LayoutParams.MATCH_PARENT, mStatusBarSize));
+ return statusBar;
+ }
+
+ /**
+ * Creates the navigation bar with back, home and recent buttons.
+ *
+ * @param isRtl true if the current locale is right-to-left
+ * @param isRtlSupported true is the project manifest declares that the application
+ * is RTL aware.
+ */
+ private NavigationBar createNavigationBar(BridgeContext context, Density density,
+ boolean isRtl, boolean isRtlSupported) throws XmlPullParserException {
+ NavigationBar navigationBar = new NavigationBar(context,
+ density, mNavigationBarOrientation, isRtl,
+ isRtlSupported);
+ if (mNavigationBarOrientation == LinearLayout.VERTICAL) {
+ navigationBar.setLayoutParams(new LinearLayout.LayoutParams(mNavigationBarSize,
+ LayoutParams.MATCH_PARENT));
+ } else {
+ navigationBar.setLayoutParams(new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT,
+ mNavigationBarSize));
+ }
+ return navigationBar;
+ }
+
+ private TitleBar createTitleBar(BridgeContext context, Density density, String title)
+ throws XmlPullParserException {
+ TitleBar titleBar = new TitleBar(context, density, title);
+ titleBar.setLayoutParams(
+ new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, mTitleBarSize));
+ return titleBar;
+ }
+
+ /**
+ * Creates the action bar. Also queries the project callback for missing information.
+ */
+ private ActionBarLayout createActionBar(BridgeContext context, SessionParams params)
+ throws XmlPullParserException {
+ ActionBarLayout actionBar = new ActionBarLayout(context, params);
+ actionBar.setLayoutParams(new LinearLayout.LayoutParams(
+ LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
+ return actionBar;
+ }
+
public BufferedImage getImage() {
return mImage;
}
@@ -1472,6 +1565,10 @@
return mViewInfoList;
}
+ public List<ViewInfo> getSystemViewInfos() {
+ return mSystemViewInfoList;
+ }
+
public Map<String, String> getDefaultProperties(Object viewObject) {
return getContext().getDefaultPropMap(viewObject);
}
diff --git a/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/impl/ResourceHelper.java b/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/impl/ResourceHelper.java
index 6dcb693..adb0937 100644
--- a/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/impl/ResourceHelper.java
+++ b/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/impl/ResourceHelper.java
@@ -165,6 +165,9 @@
* @param context the current context
*/
public static Drawable getDrawable(ResourceValue value, BridgeContext context) {
+ if (value == null) {
+ return null;
+ }
String stringValue = value.getValue();
if (RenderResources.REFERENCE_NULL.equals(stringValue)) {
return null;
diff --git a/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/impl/SystemViewInfo.java b/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/impl/SystemViewInfo.java
new file mode 100644
index 0000000..5c267df
--- /dev/null
+++ b/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/impl/SystemViewInfo.java
@@ -0,0 +1,38 @@
+/*
+ * Copyright (C) 2014 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.layoutlib.bridge.impl;
+
+import com.android.ide.common.rendering.api.ViewInfo;
+
+public class SystemViewInfo extends ViewInfo {
+
+ public SystemViewInfo(String name, Object cookie, int left, int top,
+ int right, int bottom) {
+ super(name, cookie, left, top, right, bottom);
+ }
+
+ public SystemViewInfo(String name, Object cookie, int left, int top,
+ int right, int bottom, Object viewObject, Object layoutParamsObject) {
+ super(name, cookie, left, top, right, bottom, viewObject,
+ layoutParamsObject);
+ }
+
+ @Override
+ public boolean isSystemView() {
+ return true;
+ }
+}
diff --git a/tools/layoutlib/bridge/tests/src/com/android/layoutlib/bridge/TestDelegates.java b/tools/layoutlib/bridge/tests/src/com/android/layoutlib/bridge/TestDelegates.java
index d3218db..7c0bc84 100644
--- a/tools/layoutlib/bridge/tests/src/com/android/layoutlib/bridge/TestDelegates.java
+++ b/tools/layoutlib/bridge/tests/src/com/android/layoutlib/bridge/TestDelegates.java
@@ -129,6 +129,15 @@
originalClass.getName()),
delegateMethod.getAnnotation(LayoutlibDelegate.class));
+ // check the return type of the methods match.
+ assertTrue(
+ String.format("Delegate method %1$s.%2$s does not match the corresponding " +
+ "framework method which returns %3$s",
+ delegateClass.getName(),
+ getMethodName(delegateMethod),
+ originalMethod.getReturnType().getName()),
+ delegateMethod.getReturnType() == originalMethod.getReturnType());
+
// check that the method is static
assertTrue(
String.format(
diff --git a/tools/layoutlib/create/src/com/android/tools/layoutlib/create/CreateInfo.java b/tools/layoutlib/create/src/com/android/tools/layoutlib/create/CreateInfo.java
index 79aa642..c03ccb7 100644
--- a/tools/layoutlib/create/src/com/android/tools/layoutlib/create/CreateInfo.java
+++ b/tools/layoutlib/create/src/com/android/tools/layoutlib/create/CreateInfo.java
@@ -125,6 +125,9 @@
"android.app.Fragment#instantiate", //(Landroid/content/Context;Ljava/lang/String;Landroid/os/Bundle;)Landroid/app/Fragment;",
"android.content.res.Resources$Theme#obtainStyledAttributes",
"android.content.res.Resources$Theme#resolveAttribute",
+ "android.content.res.AssetManager#newTheme",
+ "android.content.res.AssetManager#deleteTheme",
+ "android.content.res.AssetManager#applyThemeStyle",
"android.content.res.TypedArray#getValueAt",
"android.graphics.BitmapFactory#finishDecode",
"android.os.Handler#sendMessageAtTime",
diff --git a/tools/layoutlib/create/src/com/android/tools/layoutlib/create/Main.java b/tools/layoutlib/create/src/com/android/tools/layoutlib/create/Main.java
index 2ef3d5f..2e952fc 100644
--- a/tools/layoutlib/create/src/com/android/tools/layoutlib/create/Main.java
+++ b/tools/layoutlib/create/src/com/android/tools/layoutlib/create/Main.java
@@ -115,6 +115,8 @@
"android.database.ContentObserver", // for Digital clock
"com.android.i18n.phonenumbers.*", // for TextView with autolink attribute
"android.app.DatePickerDialog", // b.android.com/28318
+ "android.app.TimePickerDialog", // b.android.com/61515
+ "com.android.internal.view.menu.ActionMenu",
},
excludeClasses,
new String[] {