Flatten ActionBarDrawerToggle and DrawerLayout.
Test: ./gradlew assemble
Change-Id: I9a84274f3a37e55895b9a27580381a255bb8b164
diff --git a/core-ui/Android.mk b/core-ui/Android.mk
index 9e4ad0e..bb7a4be 100644
--- a/core-ui/Android.mk
+++ b/core-ui/Android.mk
@@ -26,11 +26,7 @@
LOCAL_USE_AAPT2 := true
LOCAL_MODULE := android-support-core-ui
LOCAL_SDK_VERSION := $(SUPPORT_CURRENT_SDK_VERSION)
-LOCAL_SRC_FILES := \
- $(call all-java-files-under,ics) \
- $(call all-java-files-under,jellybean-mr2) \
- $(call all-java-files-under,api21) \
- $(call all-java-files-under,java)
+LOCAL_SRC_FILES := $(call all-java-files-under,java)
LOCAL_RESOURCE_DIR := $(LOCAL_PATH)/res
LOCAL_SHARED_ANDROID_LIBRARIES := \
android-support-compat \
diff --git a/core-ui/api21/android/support/v4/widget/DrawerLayoutCompatApi21.java b/core-ui/api21/android/support/v4/widget/DrawerLayoutCompatApi21.java
deleted file mode 100644
index f0612d1..0000000
--- a/core-ui/api21/android/support/v4/widget/DrawerLayoutCompatApi21.java
+++ /dev/null
@@ -1,96 +0,0 @@
-/*
- * 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.support.v4.widget;
-
-import android.content.Context;
-import android.content.res.TypedArray;
-import android.graphics.drawable.Drawable;
-import android.support.annotation.RequiresApi;
-import android.view.Gravity;
-import android.view.View;
-import android.view.ViewGroup;
-import android.view.WindowInsets;
-
-/**
- * Provides functionality for DrawerLayout unique to API 21
- */
-@RequiresApi(21)
-class DrawerLayoutCompatApi21 {
-
- private static final int[] THEME_ATTRS = {
- android.R.attr.colorPrimaryDark
- };
-
- public static void configureApplyInsets(View drawerLayout) {
- if (drawerLayout instanceof DrawerLayoutImpl) {
- drawerLayout.setOnApplyWindowInsetsListener(new InsetsListener());
- drawerLayout.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_STABLE
- | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN);
- }
- }
-
- public static void dispatchChildInsets(View child, Object insets, int gravity) {
- WindowInsets wi = (WindowInsets) insets;
- if (gravity == Gravity.LEFT) {
- wi = wi.replaceSystemWindowInsets(wi.getSystemWindowInsetLeft(),
- wi.getSystemWindowInsetTop(), 0, wi.getSystemWindowInsetBottom());
- } else if (gravity == Gravity.RIGHT) {
- wi = wi.replaceSystemWindowInsets(0, wi.getSystemWindowInsetTop(),
- wi.getSystemWindowInsetRight(), wi.getSystemWindowInsetBottom());
- }
- child.dispatchApplyWindowInsets(wi);
- }
-
- public static void applyMarginInsets(ViewGroup.MarginLayoutParams lp, Object insets,
- int gravity) {
- WindowInsets wi = (WindowInsets) insets;
- if (gravity == Gravity.LEFT) {
- wi = wi.replaceSystemWindowInsets(wi.getSystemWindowInsetLeft(),
- wi.getSystemWindowInsetTop(), 0, wi.getSystemWindowInsetBottom());
- } else if (gravity == Gravity.RIGHT) {
- wi = wi.replaceSystemWindowInsets(0, wi.getSystemWindowInsetTop(),
- wi.getSystemWindowInsetRight(), wi.getSystemWindowInsetBottom());
- }
- lp.leftMargin = wi.getSystemWindowInsetLeft();
- lp.topMargin = wi.getSystemWindowInsetTop();
- lp.rightMargin = wi.getSystemWindowInsetRight();
- lp.bottomMargin = wi.getSystemWindowInsetBottom();
- }
-
- public static int getTopInset(Object insets) {
- return insets != null ? ((WindowInsets) insets).getSystemWindowInsetTop() : 0;
- }
-
- public static Drawable getDefaultStatusBarBackground(Context context) {
- final TypedArray a = context.obtainStyledAttributes(THEME_ATTRS);
- try {
- return a.getDrawable(0);
- } finally {
- a.recycle();
- }
- }
-
- static class InsetsListener implements View.OnApplyWindowInsetsListener {
- @Override
- public WindowInsets onApplyWindowInsets(View v, WindowInsets insets) {
- final DrawerLayoutImpl drawerLayout = (DrawerLayoutImpl) v;
- drawerLayout.setChildInsets(insets, insets.getSystemWindowInsetTop() > 0);
- return insets.consumeSystemWindowInsets();
- }
- }
-}
diff --git a/core-ui/api21/android/support/v4/widget/DrawerLayoutImpl.java b/core-ui/api21/android/support/v4/widget/DrawerLayoutImpl.java
deleted file mode 100644
index 02545c1..0000000
--- a/core-ui/api21/android/support/v4/widget/DrawerLayoutImpl.java
+++ /dev/null
@@ -1,26 +0,0 @@
-/*
- * 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.support.v4.widget;
-
-/**
- * Interface used to communicate from the v21-specific code for configuring a DrawerLayout
- * to the DrawerLayout itself.
- */
-interface DrawerLayoutImpl {
- void setChildInsets(Object insets, boolean drawStatusBar);
-}
diff --git a/core-ui/build.gradle b/core-ui/build.gradle
index 2126921..2cd1806 100644
--- a/core-ui/build.gradle
+++ b/core-ui/build.gradle
@@ -23,9 +23,6 @@
sourceSets {
main.java.srcDirs = [
- 'ics',
- 'jellybean-mr2',
- 'api21',
'java'
]
}
diff --git a/core-ui/ics/android/support/v4/app/ActionBarDrawerToggleIcs.java b/core-ui/ics/android/support/v4/app/ActionBarDrawerToggleIcs.java
deleted file mode 100644
index a332b8a..0000000
--- a/core-ui/ics/android/support/v4/app/ActionBarDrawerToggleIcs.java
+++ /dev/null
@@ -1,140 +0,0 @@
-/*
- * Copyright (C) 2013 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.support.v4.app;
-
-import android.R;
-import android.app.ActionBar;
-import android.app.Activity;
-import android.content.res.TypedArray;
-import android.graphics.drawable.Drawable;
-import android.os.Build;
-import android.support.annotation.RequiresApi;
-import android.util.Log;
-import android.view.View;
-import android.view.ViewGroup;
-import android.widget.ImageView;
-
-import java.lang.reflect.Method;
-
-/**
- * This class encapsulates some awful hacks.
- *
- * Before JB-MR2 (API 18) it was not possible to change the home-as-up indicator glyph
- * in an action bar without some really gross hacks. Since the MR2 SDK is not published as of
- * this writing, the new API is accessed via reflection here if available.
- */
-@RequiresApi(14)
-class ActionBarDrawerToggleIcs {
- private static final String TAG = "ActionBarDrawerToggle";
-
- private static final int[] THEME_ATTRS = new int[] {
- R.attr.homeAsUpIndicator
- };
-
- public static Object setActionBarUpIndicator(Object info, Activity activity,
- Drawable drawable, int contentDescRes) {
- if (info == null) {
- info = new SetIndicatorInfo(activity);
- }
- final SetIndicatorInfo sii = (SetIndicatorInfo) info;
- if (sii.setHomeAsUpIndicator != null) {
- try {
- final ActionBar actionBar = activity.getActionBar();
- sii.setHomeAsUpIndicator.invoke(actionBar, drawable);
- sii.setHomeActionContentDescription.invoke(actionBar, contentDescRes);
- } catch (Exception e) {
- Log.w(TAG, "Couldn't set home-as-up indicator via JB-MR2 API", e);
- }
- } else if (sii.upIndicatorView != null) {
- sii.upIndicatorView.setImageDrawable(drawable);
- } else {
- Log.w(TAG, "Couldn't set home-as-up indicator");
- }
- return info;
- }
-
- public static Object setActionBarDescription(Object info, Activity activity,
- int contentDescRes) {
- if (info == null) {
- info = new SetIndicatorInfo(activity);
- }
- final SetIndicatorInfo sii = (SetIndicatorInfo) info;
- if (sii.setHomeAsUpIndicator != null) {
- try {
- final ActionBar actionBar = activity.getActionBar();
- sii.setHomeActionContentDescription.invoke(actionBar, contentDescRes);
- if (Build.VERSION.SDK_INT <= 19) {
- // For API 19 and earlier, we need to manually force the
- // action bar to generate a new content description.
- actionBar.setSubtitle(actionBar.getSubtitle());
- }
- } catch (Exception e) {
- Log.w(TAG, "Couldn't set content description via JB-MR2 API", e);
- }
- }
- return info;
- }
-
- public static Drawable getThemeUpIndicator(Activity activity) {
- final TypedArray a = activity.obtainStyledAttributes(THEME_ATTRS);
- final Drawable result = a.getDrawable(0);
- a.recycle();
- return result;
- }
-
- private static class SetIndicatorInfo {
- public Method setHomeAsUpIndicator;
- public Method setHomeActionContentDescription;
- public ImageView upIndicatorView;
-
- SetIndicatorInfo(Activity activity) {
- try {
- setHomeAsUpIndicator = ActionBar.class.getDeclaredMethod("setHomeAsUpIndicator",
- Drawable.class);
- setHomeActionContentDescription = ActionBar.class.getDeclaredMethod(
- "setHomeActionContentDescription", Integer.TYPE);
-
- // If we got the method we won't need the stuff below.
- return;
- } catch (NoSuchMethodException e) {
- // Oh well. We'll use the other mechanism below instead.
- }
-
- final View home = activity.findViewById(android.R.id.home);
- if (home == null) {
- // Action bar doesn't have a known configuration, an OEM messed with things.
- return;
- }
-
- final ViewGroup parent = (ViewGroup) home.getParent();
- final int childCount = parent.getChildCount();
- if (childCount != 2) {
- // No idea which one will be the right one, an OEM messed with things.
- return;
- }
-
- final View first = parent.getChildAt(0);
- final View second = parent.getChildAt(1);
- final View up = first.getId() == android.R.id.home ? second : first;
-
- if (up instanceof ImageView) {
- // Jackpot! (Probably...)
- upIndicatorView = (ImageView) up;
- }
- }
- }
-}
diff --git a/core-ui/java/android/support/v4/app/ActionBarDrawerToggle.java b/core-ui/java/android/support/v4/app/ActionBarDrawerToggle.java
index 226154f..d95e42c 100644
--- a/core-ui/java/android/support/v4/app/ActionBarDrawerToggle.java
+++ b/core-ui/java/android/support/v4/app/ActionBarDrawerToggle.java
@@ -17,24 +17,31 @@
package android.support.v4.app;
+import android.app.ActionBar;
import android.app.Activity;
import android.content.Context;
import android.content.res.Configuration;
+import android.content.res.TypedArray;
import android.graphics.Canvas;
import android.graphics.Rect;
import android.graphics.drawable.Drawable;
import android.graphics.drawable.InsetDrawable;
import android.os.Build;
import android.support.annotation.DrawableRes;
+import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
-import android.support.annotation.RequiresApi;
import android.support.annotation.StringRes;
import android.support.v4.content.ContextCompat;
import android.support.v4.view.GravityCompat;
import android.support.v4.view.ViewCompat;
import android.support.v4.widget.DrawerLayout;
+import android.util.Log;
import android.view.MenuItem;
import android.view.View;
+import android.view.ViewGroup;
+import android.widget.ImageView;
+
+import java.lang.reflect.Method;
/**
* This class provides a handy way to tie together the functionality of
@@ -107,71 +114,11 @@
void setActionBarDescription(@StringRes int contentDescRes);
}
- private interface ActionBarDrawerToggleImpl {
- Drawable getThemeUpIndicator(Activity activity);
- Object setActionBarUpIndicator(Object info, Activity activity,
- Drawable themeImage, int contentDescRes);
- Object setActionBarDescription(Object info, Activity activity, int contentDescRes);
- }
+ private static final String TAG = "ActionBarDrawerToggle";
- @RequiresApi(11)
- private static class ActionBarDrawerToggleImplIcs implements ActionBarDrawerToggleImpl {
- ActionBarDrawerToggleImplIcs() {
- }
-
- @Override
- public Drawable getThemeUpIndicator(Activity activity) {
- return ActionBarDrawerToggleIcs.getThemeUpIndicator(activity);
- }
-
- @Override
- public Object setActionBarUpIndicator(Object info, Activity activity,
- Drawable themeImage, int contentDescRes) {
- return ActionBarDrawerToggleIcs.setActionBarUpIndicator(info, activity,
- themeImage, contentDescRes);
- }
-
- @Override
- public Object setActionBarDescription(Object info, Activity activity, int contentDescRes) {
- return ActionBarDrawerToggleIcs.setActionBarDescription(info, activity,
- contentDescRes);
- }
- }
-
- @RequiresApi(18)
- private static class ActionBarDrawerToggleImplJellybeanMR2
- implements ActionBarDrawerToggleImpl {
- ActionBarDrawerToggleImplJellybeanMR2() {
- }
-
- @Override
- public Drawable getThemeUpIndicator(Activity activity) {
- return ActionBarDrawerToggleJellybeanMR2.getThemeUpIndicator(activity);
- }
-
- @Override
- public Object setActionBarUpIndicator(Object info, Activity activity,
- Drawable themeImage, int contentDescRes) {
- return ActionBarDrawerToggleJellybeanMR2.setActionBarUpIndicator(info, activity,
- themeImage, contentDescRes);
- }
-
- @Override
- public Object setActionBarDescription(Object info, Activity activity, int contentDescRes) {
- return ActionBarDrawerToggleJellybeanMR2.setActionBarDescription(info, activity,
- contentDescRes);
- }
- }
-
- private static final ActionBarDrawerToggleImpl IMPL;
-
- static {
- if (Build.VERSION.SDK_INT >= 18) {
- IMPL = new ActionBarDrawerToggleImplJellybeanMR2();
- } else {
- IMPL = new ActionBarDrawerToggleImplIcs();
- }
- }
+ private static final int[] THEME_ATTRS = new int[] {
+ android.R.attr.homeAsUpIndicator
+ };
/** Fraction of its total width by which to offset the toggle drawable. */
private static final float TOGGLE_DRAWABLE_OFFSET = 1 / 3f;
@@ -192,7 +139,7 @@
private final int mOpenDrawerContentDescRes;
private final int mCloseDrawerContentDescRes;
- private Object mSetIndicatorInfo;
+ private SetIndicatorInfo mSetIndicatorInfo;
/**
* Construct a new ActionBarDrawerToggle.
@@ -463,29 +410,133 @@
public void onDrawerStateChanged(int newState) {
}
- Drawable getThemeUpIndicator() {
+ private Drawable getThemeUpIndicator() {
if (mActivityImpl != null) {
return mActivityImpl.getThemeUpIndicator();
}
- return IMPL.getThemeUpIndicator(mActivity);
+ if (Build.VERSION.SDK_INT >= 18) {
+ final ActionBar actionBar = mActivity.getActionBar();
+ final Context context;
+ if (actionBar != null) {
+ context = actionBar.getThemedContext();
+ } else {
+ context = mActivity;
+ }
+
+ final TypedArray a = context.obtainStyledAttributes(null, THEME_ATTRS,
+ android.R.attr.actionBarStyle, 0);
+ final Drawable result = a.getDrawable(0);
+ a.recycle();
+ return result;
+ } else {
+ final TypedArray a = mActivity.obtainStyledAttributes(THEME_ATTRS);
+ final Drawable result = a.getDrawable(0);
+ a.recycle();
+ return result;
+ }
}
- void setActionBarUpIndicator(Drawable upDrawable, int contentDescRes) {
+ private void setActionBarUpIndicator(Drawable upDrawable, int contentDescRes) {
if (mActivityImpl != null) {
mActivityImpl.setActionBarUpIndicator(upDrawable, contentDescRes);
return;
}
- mSetIndicatorInfo = IMPL
- .setActionBarUpIndicator(mSetIndicatorInfo, mActivity, upDrawable, contentDescRes);
+ if (Build.VERSION.SDK_INT >= 18) {
+ final ActionBar actionBar = mActivity.getActionBar();
+ if (actionBar != null) {
+ actionBar.setHomeAsUpIndicator(upDrawable);
+ actionBar.setHomeActionContentDescription(contentDescRes);
+ }
+ } else {
+ if (mSetIndicatorInfo == null) {
+ mSetIndicatorInfo = new SetIndicatorInfo(mActivity);
+ }
+ if (mSetIndicatorInfo.mSetHomeAsUpIndicator != null) {
+ try {
+ final ActionBar actionBar = mActivity.getActionBar();
+ mSetIndicatorInfo.mSetHomeAsUpIndicator.invoke(actionBar, upDrawable);
+ mSetIndicatorInfo.mSetHomeActionContentDescription.invoke(
+ actionBar, contentDescRes);
+ } catch (Exception e) {
+ Log.w(TAG, "Couldn't set home-as-up indicator via JB-MR2 API", e);
+ }
+ } else if (mSetIndicatorInfo.mUpIndicatorView != null) {
+ mSetIndicatorInfo.mUpIndicatorView.setImageDrawable(upDrawable);
+ } else {
+ Log.w(TAG, "Couldn't set home-as-up indicator");
+ }
+ }
}
- void setActionBarDescription(int contentDescRes) {
+ private void setActionBarDescription(int contentDescRes) {
if (mActivityImpl != null) {
mActivityImpl.setActionBarDescription(contentDescRes);
return;
}
- mSetIndicatorInfo = IMPL
- .setActionBarDescription(mSetIndicatorInfo, mActivity, contentDescRes);
+ if (Build.VERSION.SDK_INT >= 18) {
+ final ActionBar actionBar = mActivity.getActionBar();
+ if (actionBar != null) {
+ actionBar.setHomeActionContentDescription(contentDescRes);
+ }
+ } else {
+ if (mSetIndicatorInfo == null) {
+ mSetIndicatorInfo = new SetIndicatorInfo(mActivity);
+ }
+ if (mSetIndicatorInfo.mSetHomeAsUpIndicator != null) {
+ try {
+ final ActionBar actionBar = mActivity.getActionBar();
+ mSetIndicatorInfo.mSetHomeActionContentDescription.invoke(
+ actionBar, contentDescRes);
+ // For API 19 and earlier, we need to manually force the
+ // action bar to generate a new content description.
+ actionBar.setSubtitle(actionBar.getSubtitle());
+ } catch (Exception e) {
+ Log.w(TAG, "Couldn't set content description via JB-MR2 API", e);
+ }
+ }
+ }
+ }
+
+ private static class SetIndicatorInfo {
+ Method mSetHomeAsUpIndicator;
+ Method mSetHomeActionContentDescription;
+ ImageView mUpIndicatorView;
+
+ SetIndicatorInfo(Activity activity) {
+ try {
+ mSetHomeAsUpIndicator = ActionBar.class.getDeclaredMethod("setHomeAsUpIndicator",
+ Drawable.class);
+ mSetHomeActionContentDescription = ActionBar.class.getDeclaredMethod(
+ "setHomeActionContentDescription", Integer.TYPE);
+
+ // If we got the method we won't need the stuff below.
+ return;
+ } catch (NoSuchMethodException e) {
+ // Oh well. We'll use the other mechanism below instead.
+ }
+
+ final View home = activity.findViewById(android.R.id.home);
+ if (home == null) {
+ // Action bar doesn't have a known configuration, an OEM messed with things.
+ return;
+ }
+
+ final ViewGroup parent = (ViewGroup) home.getParent();
+ final int childCount = parent.getChildCount();
+ if (childCount != 2) {
+ // No idea which one will be the right one, an OEM messed with things.
+ return;
+ }
+
+ final View first = parent.getChildAt(0);
+ final View second = parent.getChildAt(1);
+ final View up = first.getId() == android.R.id.home ? second : first;
+
+ if (up instanceof ImageView) {
+ // Jackpot! (Probably...)
+ mUpIndicatorView = (ImageView) up;
+ }
+ }
}
private class SlideDrawable extends InsetDrawable implements Drawable.Callback {
@@ -526,7 +577,7 @@
}
@Override
- public void draw(Canvas canvas) {
+ public void draw(@NonNull Canvas canvas) {
copyBounds(mTmpRect);
canvas.save();
diff --git a/core-ui/java/android/support/v4/widget/DrawerLayout.java b/core-ui/java/android/support/v4/widget/DrawerLayout.java
index fe35212..3b3a781 100644
--- a/core-ui/java/android/support/v4/widget/DrawerLayout.java
+++ b/core-ui/java/android/support/v4/widget/DrawerLayout.java
@@ -17,6 +17,9 @@
package android.support.v4.widget;
+import static android.support.annotation.RestrictTo.Scope.LIBRARY_GROUP;
+
+import android.annotation.TargetApi;
import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.Canvas;
@@ -34,7 +37,7 @@
import android.support.annotation.IntDef;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
-import android.support.annotation.RequiresApi;
+import android.support.annotation.RestrictTo;
import android.support.v4.content.ContextCompat;
import android.support.v4.graphics.drawable.DrawableCompat;
import android.support.v4.view.AbsSavedState;
@@ -51,6 +54,7 @@
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewParent;
+import android.view.WindowInsets;
import android.view.accessibility.AccessibilityEvent;
import java.lang.annotation.Retention;
@@ -91,9 +95,13 @@
* href="{@docRoot}training/implementing-navigation/nav-drawer.html">Creating a Navigation
* Drawer</a>.</p>
*/
-public class DrawerLayout extends ViewGroup implements DrawerLayoutImpl {
+public class DrawerLayout extends ViewGroup {
private static final String TAG = "DrawerLayout";
+ private static final int[] THEME_ATTRS = {
+ android.R.attr.colorPrimaryDark
+ };
+
@IntDef({STATE_IDLE, STATE_DRAGGING, STATE_SETTLING})
@Retention(RetentionPolicy.SOURCE)
private @interface State {}
@@ -287,79 +295,6 @@
}
}
- interface DrawerLayoutCompatImpl {
- void configureApplyInsets(View drawerLayout);
- void dispatchChildInsets(View child, Object insets, int drawerGravity);
- void applyMarginInsets(MarginLayoutParams lp, Object insets, int drawerGravity);
- int getTopInset(Object lastInsets);
- Drawable getDefaultStatusBarBackground(Context context);
- }
-
- static class DrawerLayoutCompatImplBase implements DrawerLayoutCompatImpl {
- @Override
- public void configureApplyInsets(View drawerLayout) {
- // This space for rent
- }
-
- @Override
- public void dispatchChildInsets(View child, Object insets, int drawerGravity) {
- // This space for rent
- }
-
- @Override
- public void applyMarginInsets(MarginLayoutParams lp, Object insets, int drawerGravity) {
- // This space for rent
- }
-
- @Override
- public int getTopInset(Object insets) {
- return 0;
- }
-
- @Override
- public Drawable getDefaultStatusBarBackground(Context context) {
- return null;
- }
- }
-
- @RequiresApi(21)
- static class DrawerLayoutCompatImplApi21 implements DrawerLayoutCompatImpl {
- @Override
- public void configureApplyInsets(View drawerLayout) {
- DrawerLayoutCompatApi21.configureApplyInsets(drawerLayout);
- }
-
- @Override
- public void dispatchChildInsets(View child, Object insets, int drawerGravity) {
- DrawerLayoutCompatApi21.dispatchChildInsets(child, insets, drawerGravity);
- }
-
- @Override
- public void applyMarginInsets(MarginLayoutParams lp, Object insets, int drawerGravity) {
- DrawerLayoutCompatApi21.applyMarginInsets(lp, insets, drawerGravity);
- }
-
- @Override
- public int getTopInset(Object insets) {
- return DrawerLayoutCompatApi21.getTopInset(insets);
- }
-
- @Override
- public Drawable getDefaultStatusBarBackground(Context context) {
- return DrawerLayoutCompatApi21.getDefaultStatusBarBackground(context);
- }
- }
-
- static {
- if (Build.VERSION.SDK_INT >= 21) {
- IMPL = new DrawerLayoutCompatImplApi21();
- } else {
- IMPL = new DrawerLayoutCompatImplBase();
- }
- }
-
- static final DrawerLayoutCompatImpl IMPL;
-
public DrawerLayout(Context context) {
this(context, null);
}
@@ -397,8 +332,27 @@
ViewCompat.setAccessibilityDelegate(this, new AccessibilityDelegate());
ViewGroupCompat.setMotionEventSplittingEnabled(this, false);
if (ViewCompat.getFitsSystemWindows(this)) {
- IMPL.configureApplyInsets(this);
- mStatusBarBackground = IMPL.getDefaultStatusBarBackground(context);
+ if (Build.VERSION.SDK_INT >= 21) {
+ setOnApplyWindowInsetsListener(new View.OnApplyWindowInsetsListener() {
+ @TargetApi(21)
+ @Override
+ public WindowInsets onApplyWindowInsets(View view, WindowInsets insets) {
+ final DrawerLayout drawerLayout = (DrawerLayout) view;
+ drawerLayout.setChildInsets(insets, insets.getSystemWindowInsetTop() > 0);
+ return insets.consumeSystemWindowInsets();
+ }
+ });
+ setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_STABLE
+ | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN);
+ final TypedArray a = context.obtainStyledAttributes(THEME_ATTRS);
+ try {
+ mStatusBarBackground = a.getDrawable(0);
+ } finally {
+ a.recycle();
+ }
+ } else {
+ mStatusBarBackground = null;
+ }
}
mDrawerElevation = DRAWER_ELEVATION * density;
@@ -440,7 +394,7 @@
* @hide Internal use only; called to apply window insets when configured
* with fitsSystemWindows="true"
*/
- @Override
+ @RestrictTo(LIBRARY_GROUP)
public void setChildInsets(Object insets, boolean draw) {
mLastInsets = insets;
mDrawStatusBarBackground = draw;
@@ -1063,9 +1017,36 @@
if (applyInsets) {
final int cgrav = GravityCompat.getAbsoluteGravity(lp.gravity, layoutDirection);
if (ViewCompat.getFitsSystemWindows(child)) {
- IMPL.dispatchChildInsets(child, mLastInsets, cgrav);
+ if (Build.VERSION.SDK_INT >= 21) {
+ WindowInsets wi = (WindowInsets) mLastInsets;
+ if (cgrav == Gravity.LEFT) {
+ wi = wi.replaceSystemWindowInsets(wi.getSystemWindowInsetLeft(),
+ wi.getSystemWindowInsetTop(), 0,
+ wi.getSystemWindowInsetBottom());
+ } else if (cgrav == Gravity.RIGHT) {
+ wi = wi.replaceSystemWindowInsets(0, wi.getSystemWindowInsetTop(),
+ wi.getSystemWindowInsetRight(),
+ wi.getSystemWindowInsetBottom());
+ }
+ child.dispatchApplyWindowInsets(wi);
+ }
} else {
- IMPL.applyMarginInsets(lp, mLastInsets, cgrav);
+ if (Build.VERSION.SDK_INT >= 21) {
+ WindowInsets wi = (WindowInsets) mLastInsets;
+ if (cgrav == Gravity.LEFT) {
+ wi = wi.replaceSystemWindowInsets(wi.getSystemWindowInsetLeft(),
+ wi.getSystemWindowInsetTop(), 0,
+ wi.getSystemWindowInsetBottom());
+ } else if (cgrav == Gravity.RIGHT) {
+ wi = wi.replaceSystemWindowInsets(0, wi.getSystemWindowInsetTop(),
+ wi.getSystemWindowInsetRight(),
+ wi.getSystemWindowInsetBottom());
+ }
+ lp.leftMargin = wi.getSystemWindowInsetLeft();
+ lp.topMargin = wi.getSystemWindowInsetTop();
+ lp.rightMargin = wi.getSystemWindowInsetRight();
+ lp.bottomMargin = wi.getSystemWindowInsetBottom();
+ }
}
}
@@ -1340,7 +1321,13 @@
public void onDraw(Canvas c) {
super.onDraw(c);
if (mDrawStatusBarBackground && mStatusBarBackground != null) {
- final int inset = IMPL.getTopInset(mLastInsets);
+ final int inset;
+ if (Build.VERSION.SDK_INT >= 21) {
+ inset = mLastInsets != null
+ ? ((WindowInsets) mLastInsets).getSystemWindowInsetTop() : 0;
+ } else {
+ inset = 0;
+ }
if (inset > 0) {
mStatusBarBackground.setBounds(0, 0, getWidth(), inset);
mStatusBarBackground.draw(c);
diff --git a/core-ui/jellybean-mr2/android/support/v4/app/ActionBarDrawerToggleJellybeanMR2.java b/core-ui/jellybean-mr2/android/support/v4/app/ActionBarDrawerToggleJellybeanMR2.java
deleted file mode 100644
index 40d180c..0000000
--- a/core-ui/jellybean-mr2/android/support/v4/app/ActionBarDrawerToggleJellybeanMR2.java
+++ /dev/null
@@ -1,70 +0,0 @@
-/*
- * Copyright (C) 2013 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.support.v4.app;
-
-import android.R;
-import android.app.ActionBar;
-import android.app.Activity;
-import android.content.Context;
-import android.content.res.TypedArray;
-import android.graphics.drawable.Drawable;
-import android.support.annotation.RequiresApi;
-
-@RequiresApi(18)
-class ActionBarDrawerToggleJellybeanMR2 {
- private static final String TAG = "ActionBarDrawerToggleImplJellybeanMR2";
-
- private static final int[] THEME_ATTRS = new int[] {
- R.attr.homeAsUpIndicator
- };
-
- public static Object setActionBarUpIndicator(Object info, Activity activity,
- Drawable drawable, int contentDescRes) {
- final ActionBar actionBar = activity.getActionBar();
- if (actionBar != null) {
- actionBar.setHomeAsUpIndicator(drawable);
- actionBar.setHomeActionContentDescription(contentDescRes);
- }
- return info;
- }
-
- public static Object setActionBarDescription(Object info, Activity activity,
- int contentDescRes) {
- final ActionBar actionBar = activity.getActionBar();
- if (actionBar != null) {
- actionBar.setHomeActionContentDescription(contentDescRes);
- }
- return info;
- }
-
- public static Drawable getThemeUpIndicator(Activity activity) {
- final ActionBar actionBar = activity.getActionBar();
- final Context context;
- if (actionBar != null) {
- context = actionBar.getThemedContext();
- } else {
- context = activity;
- }
-
- final TypedArray a = context.obtainStyledAttributes(null, THEME_ATTRS,
- R.attr.actionBarStyle, 0);
- final Drawable result = a.getDrawable(0);
- a.recycle();
- return result;
- }
-}