MediaSessionCompat: Fix NPE
am: 3cc527755f
Change-Id: I7c4dab0ecd85f47aa8396d32030161fb9ab63010
diff --git a/build.gradle b/build.gradle
index d7cced1..2013436 100644
--- a/build.gradle
+++ b/build.gradle
@@ -24,7 +24,7 @@
}
dependencies {
// Keep gradle plugin version in sync with ub_supportlib-master manifest.
- classpath 'com.android.tools.build:gradle:2.2.1'
+ classpath 'com.android.tools.build:gradle:2.2.3'
}
}
@@ -41,7 +41,7 @@
}
gradle.ext.currentSdk = 25
-ext.supportVersion = '25.1.0'
+ext.supportVersion = '25.2.0-SNAPSHOT'
ext.extraVersion = 41
ext.supportRepoOut = ''
ext.buildToolsVersion = '24.0.1'
diff --git a/compat/build.gradle b/compat/build.gradle
index 5722998..f200989 100644
--- a/compat/build.gradle
+++ b/compat/build.gradle
@@ -78,16 +78,6 @@
from variant.javaCompile.destinationDir
from 'LICENSE.txt'
}
- def javadocTask = project.tasks.create(name: "javadoc${suffix}", type: Javadoc) {
- source android.sourceSets.main.java
- classpath = files(variant.javaCompile.classpath.files) + files(
- "${android.sdkDirectory}/platforms/${android.compileSdkVersion}/android.jar")
- }
-
- def javadocJarTask = project.tasks.create(name: "javadocJar${suffix}", type: Jar) {
- classifier = 'javadoc'
- from 'build/docs/javadoc'
- }
def sourcesJarTask = project.tasks.create(name: "sourceJar${suffix}", type: Jar) {
classifier = 'sources'
@@ -96,7 +86,6 @@
exclude('android/service/media/**')
}
- artifacts.add('archives', javadocJarTask);
artifacts.add('archives', sourcesJarTask);
}
diff --git a/core-ui/build.gradle b/core-ui/build.gradle
index 89796ea..32ed4b0 100644
--- a/core-ui/build.gradle
+++ b/core-ui/build.gradle
@@ -16,9 +16,6 @@
testCompile 'junit:junit:4.12'
}
-sourceCompatibility = JavaVersion.VERSION_1_7
-targetCompatibility = JavaVersion.VERSION_1_7
-
android {
compileSdkVersion project.ext.currentSdk
@@ -54,7 +51,6 @@
testOptions {
unitTests.returnDefaultValues = true
- compileSdkVersion project.ext.currentSdk
}
}
@@ -71,16 +67,6 @@
from variant.javaCompile.destinationDir
from 'LICENSE.txt'
}
- def javadocTask = project.tasks.create(name: "javadoc${suffix}", type: Javadoc) {
- source android.sourceSets.main.java
- classpath = files(variant.javaCompile.classpath.files) + files(
- "${android.sdkDirectory}/platforms/${android.compileSdkVersion}/android.jar")
- }
-
- def javadocJarTask = project.tasks.create(name: "javadocJar${suffix}", type: Jar) {
- classifier = 'javadoc'
- from 'build/docs/javadoc'
- }
def sourcesJarTask = project.tasks.create(name: "sourceJar${suffix}", type: Jar) {
classifier = 'sources'
@@ -89,7 +75,6 @@
exclude('android/service/media/**')
}
- artifacts.add('archives', javadocJarTask);
artifacts.add('archives', sourcesJarTask);
}
diff --git a/core-utils/build.gradle b/core-utils/build.gradle
index 750cf49..18a94ec 100644
--- a/core-utils/build.gradle
+++ b/core-utils/build.gradle
@@ -51,7 +51,6 @@
testOptions {
unitTests.returnDefaultValues = true
- compileSdkVersion project.ext.currentSdk
}
}
@@ -68,16 +67,6 @@
from variant.javaCompile.destinationDir
from 'LICENSE.txt'
}
- def javadocTask = project.tasks.create(name: "javadoc${suffix}", type: Javadoc) {
- source android.sourceSets.main.java
- classpath = files(variant.javaCompile.classpath.files) + files(
- "${android.sdkDirectory}/platforms/${android.compileSdkVersion}/android.jar")
- }
-
- def javadocJarTask = project.tasks.create(name: "javadocJar${suffix}", type: Jar) {
- classifier = 'javadoc'
- from 'build/docs/javadoc'
- }
def sourcesJarTask = project.tasks.create(name: "sourceJar${suffix}", type: Jar) {
classifier = 'sources'
@@ -86,7 +75,6 @@
exclude('android/service/media/**')
}
- artifacts.add('archives', javadocJarTask);
artifacts.add('archives', sourcesJarTask);
}
diff --git a/customtabs/build.gradle b/customtabs/build.gradle
index a409dba..4e494a2 100644
--- a/customtabs/build.gradle
+++ b/customtabs/build.gradle
@@ -53,22 +53,11 @@
from variant.javaCompile.destinationDir
from 'LICENSE.txt'
}
- def javadocTask = project.tasks.create(name: "javadoc${suffix}", type: Javadoc) {
- source android.sourceSets.main.java
- classpath = files(variant.javaCompile.classpath.files) + files(
- "${android.sdkDirectory}/platforms/${android.compileSdkVersion}/android.jar")
- }
-
- def javadocJarTask = project.tasks.create(name: "javadocJar${suffix}", type: Jar) {
- classifier = 'javadoc'
- from 'build/docs/javadoc'
- }
def sourcesJarTask = project.tasks.create(name: "sourceJar${suffix}", type: Jar) {
classifier = 'sources'
from android.sourceSets.main.java.srcDirs
}
- artifacts.add('archives', javadocJarTask);
artifacts.add('archives', sourcesJarTask);
}
diff --git a/design/build.gradle b/design/build.gradle
index abd99c0..ef40ace 100644
--- a/design/build.gradle
+++ b/design/build.gradle
@@ -88,23 +88,12 @@
from variant.javaCompile.destinationDir
from 'LICENSE.txt'
}
- def javadocTask = project.tasks.create(name: "javadoc${suffix}", type: Javadoc) {
- source android.sourceSets.main.java
- classpath = files(variant.javaCompile.classpath.files) + files(
- "${android.sdkDirectory}/platforms/${android.compileSdkVersion}/android.jar")
- }
-
- def javadocJarTask = project.tasks.create(name: "javadocJar${suffix}", type: Jar) {
- classifier = 'javadoc'
- from 'build/docs/javadoc'
- }
def sourcesJarTask = project.tasks.create(name: "sourceJar${suffix}", type: Jar) {
classifier = 'sources'
from android.sourceSets.main.java.srcDirs
}
- artifacts.add('archives', javadocJarTask);
artifacts.add('archives', sourcesJarTask);
}
diff --git a/design/src/android/support/design/widget/AppBarLayout.java b/design/src/android/support/design/widget/AppBarLayout.java
index 4c7ef0a..8a34239 100644
--- a/design/src/android/support/design/widget/AppBarLayout.java
+++ b/design/src/android/support/design/widget/AppBarLayout.java
@@ -111,6 +111,7 @@
static final int PENDING_ACTION_EXPANDED = 0x1;
static final int PENDING_ACTION_COLLAPSED = 0x2;
static final int PENDING_ACTION_ANIMATE_ENABLED = 0x4;
+ static final int PENDING_ACTION_FORCE = 0x8;
/**
* Interface definition for a callback to be invoked when an {@link AppBarLayout}'s vertical
@@ -172,7 +173,7 @@
0, R.style.Widget_Design_AppBarLayout);
ViewCompat.setBackground(this, a.getDrawable(R.styleable.AppBarLayout_android_background));
if (a.hasValue(R.styleable.AppBarLayout_expanded)) {
- setExpanded(a.getBoolean(R.styleable.AppBarLayout_expanded, false));
+ setExpanded(a.getBoolean(R.styleable.AppBarLayout_expanded, false), false, false);
}
if (Build.VERSION.SDK_INT >= 21 && a.hasValue(R.styleable.AppBarLayout_elevation)) {
ViewUtilsLollipop.setDefaultAppBarLayoutStateListAnimator(
@@ -299,8 +300,13 @@
* @attr ref android.support.design.R.styleable#AppBarLayout_expanded
*/
public void setExpanded(boolean expanded, boolean animate) {
+ setExpanded(expanded, animate, true);
+ }
+
+ private void setExpanded(boolean expanded, boolean animate, boolean force) {
mPendingAction = (expanded ? PENDING_ACTION_EXPANDED : PENDING_ACTION_COLLAPSED)
- | (animate ? PENDING_ACTION_ANIMATE_ENABLED : 0);
+ | (animate ? PENDING_ACTION_ANIMATE_ENABLED : 0)
+ | (force ? PENDING_ACTION_FORCE : 0);
requestLayout();
}
@@ -1048,8 +1054,21 @@
int layoutDirection) {
boolean handled = super.onLayoutChild(parent, abl, layoutDirection);
+ // The priority for for actions here is (first which is true wins):
+ // 1. forced pending actions
+ // 2. offsets for restorations
+ // 3. non-forced pending actions
final int pendingAction = abl.getPendingAction();
- if (pendingAction != PENDING_ACTION_NONE) {
+ if (mOffsetToChildIndexOnLayout >= 0 && (pendingAction & PENDING_ACTION_FORCE) == 0) {
+ View child = abl.getChildAt(mOffsetToChildIndexOnLayout);
+ int offset = -child.getBottom();
+ if (mOffsetToChildIndexOnLayoutIsMinHeight) {
+ offset += ViewCompat.getMinimumHeight(child) + abl.getTopInset();
+ } else {
+ offset += Math.round(child.getHeight() * mOffsetToChildIndexOnLayoutPerc);
+ }
+ setHeaderTopBottomOffset(parent, abl, offset);
+ } else if (pendingAction != PENDING_ACTION_NONE) {
final boolean animate = (pendingAction & PENDING_ACTION_ANIMATE_ENABLED) != 0;
if ((pendingAction & PENDING_ACTION_COLLAPSED) != 0) {
final int offset = -abl.getUpNestedPreScrollRange();
@@ -1065,15 +1084,6 @@
setHeaderTopBottomOffset(parent, abl, 0);
}
}
- } else if (mOffsetToChildIndexOnLayout >= 0) {
- View child = abl.getChildAt(mOffsetToChildIndexOnLayout);
- int offset = -child.getBottom();
- if (mOffsetToChildIndexOnLayoutIsMinHeight) {
- offset += ViewCompat.getMinimumHeight(child);
- } else {
- offset += Math.round(child.getHeight() * mOffsetToChildIndexOnLayoutPerc);
- }
- setTopAndBottomOffset(offset);
}
// Finally reset any pending states
@@ -1085,6 +1095,11 @@
setTopAndBottomOffset(
MathUtils.constrain(getTopAndBottomOffset(), -abl.getTotalScrollRange(), 0));
+ // Update the AppBarLayout's drawable state for any elevation changes.
+ // This is needed so that the elevation is set in the first layout, so that
+ // we don't get a visual elevation jump pre-N (due to the draw dispatch skip)
+ updateAppBarLayoutDrawableState(parent, abl, getTopAndBottomOffset(), 0, true);
+
// Make sure we dispatch the offset update
abl.dispatchOffsetUpdates(getTopAndBottomOffset());
@@ -1161,7 +1176,7 @@
// Update the AppBarLayout's drawable state (for any elevation changes)
updateAppBarLayoutDrawableState(coordinatorLayout, appBarLayout, newOffset,
- newOffset < curOffset ? -1 : 1);
+ newOffset < curOffset ? -1 : 1, false);
}
} else {
// Reset the offset delta
@@ -1224,7 +1239,8 @@
}
private void updateAppBarLayoutDrawableState(final CoordinatorLayout parent,
- final AppBarLayout layout, final int offset, final int direction) {
+ final AppBarLayout layout, final int offset, final int direction,
+ final boolean forceJump) {
final View child = getAppBarChildOnOffset(layout, offset);
if (child != null) {
final AppBarLayout.LayoutParams childLp = (LayoutParams) child.getLayoutParams();
@@ -1248,8 +1264,8 @@
final boolean changed = layout.setCollapsedState(collapsed);
- if (changed && Build.VERSION.SDK_INT >= 11
- && shouldJumpElevationState(parent, layout)) {
+ if (Build.VERSION.SDK_INT >= 11 && (forceJump
+ || (changed && shouldJumpElevationState(parent, layout)))) {
// If the collapsed state changed, we may need to
// jump to the current state if we have an overlapping view
layout.jumpDrawablesToCurrentState();
diff --git a/design/src/android/support/design/widget/CoordinatorLayout.java b/design/src/android/support/design/widget/CoordinatorLayout.java
index bac67f9..1f570b6 100644
--- a/design/src/android/support/design/widget/CoordinatorLayout.java
+++ b/design/src/android/support/design/widget/CoordinatorLayout.java
@@ -1293,7 +1293,7 @@
offsetChildByInset(child, inset, layoutDirection);
}
- if (type == EVENT_PRE_DRAW) {
+ if (type != EVENT_VIEW_REMOVED) {
// Did it change? if not continue
getLastChildRect(child, lastDrawRect);
if (lastDrawRect.equals(drawRect)) {
diff --git a/design/src/android/support/design/widget/TextInputLayout.java b/design/src/android/support/design/widget/TextInputLayout.java
index 92c1506..3b38251 100644
--- a/design/src/android/support/design/widget/TextInputLayout.java
+++ b/design/src/android/support/design/widget/TextInputLayout.java
@@ -201,8 +201,6 @@
mCollapsingTextHelper.setPositionInterpolator(new AccelerateInterpolator());
mCollapsingTextHelper.setCollapsedTextGravity(Gravity.TOP | GravityCompat.START);
- mHintExpanded = mCollapsingTextHelper.getExpansionFraction() == 1f;
-
final TintTypedArray a = TintTypedArray.obtainStyledAttributes(context, attrs,
R.styleable.TextInputLayout, defStyleAttr, R.style.Widget_Design_TextInputLayout);
mHintEnabled = a.getBoolean(R.styleable.TextInputLayout_hintEnabled, true);
@@ -380,8 +378,8 @@
updatePasswordToggleView();
- // Update the label visibility with no animation
- updateLabelState(false);
+ // Update the label visibility with no animation, but force a state change
+ updateLabelState(false, true);
}
private void updateInputLayoutMargins() {
@@ -408,6 +406,10 @@
}
void updateLabelState(boolean animate) {
+ updateLabelState(animate, false);
+ }
+
+ void updateLabelState(final boolean animate, final boolean force) {
final boolean isEnabled = isEnabled();
final boolean hasText = mEditText != null && !TextUtils.isEmpty(mEditText.getText());
final boolean isFocused = arrayContains(getDrawableState(), android.R.attr.state_focused);
@@ -427,12 +429,12 @@
if (hasText || (isEnabled() && (isFocused || isErrorShowing))) {
// We should be showing the label so do so if it isn't already
- if (mHintExpanded) {
+ if (force || mHintExpanded) {
collapseHint(animate);
}
} else {
// We should not be showing the label so hide it
- if (!mHintExpanded) {
+ if (force || !mHintExpanded) {
expandHint(animate);
}
}
diff --git a/design/tests/AndroidManifest.xml b/design/tests/AndroidManifest.xml
index 29d46e0..886540d 100755
--- a/design/tests/AndroidManifest.xml
+++ b/design/tests/AndroidManifest.xml
@@ -88,6 +88,10 @@
<activity
android:name="android.support.v7.app.AppCompatActivity"/>
+ <activity
+ android:name="android.support.design.widget.AppBarLayoutCollapsePinTestActivity"
+ android:theme="@style/Theme.TranslucentStatus"/>
+
</application>
<instrumentation
diff --git a/design/tests/res/layout/design_appbar_toolbar_collapse_pin_restore_test.xml b/design/tests/res/layout/design_appbar_toolbar_collapse_pin_restore_test.xml
new file mode 100644
index 0000000..fbe031b
--- /dev/null
+++ b/design/tests/res/layout/design_appbar_toolbar_collapse_pin_restore_test.xml
@@ -0,0 +1,51 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+ Copyright (C) 2016 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.
+-->
+
+<android.support.design.widget.CoordinatorLayout
+ xmlns:android="http://schemas.android.com/apk/res/android"
+ xmlns:app="http://schemas.android.com/apk/res-auto"
+ android:id="@+id/coordinator_layout"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent"
+ android:fitsSystemWindows="true">
+
+ <android.support.design.widget.AppBarLayout
+ android:id="@+id/app_bar"
+ android:layout_width="match_parent"
+ android:layout_height="@dimen/appbar_height"
+ android:fitsSystemWindows="true"
+ app:expanded="true">
+
+ <android.support.design.widget.CollapsingToolbarLayout
+ android:id="@+id/collapsing_app_bar"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent"
+ app:layout_scrollFlags="scroll|exitUntilCollapsed">
+
+ <android.support.v7.widget.Toolbar
+ android:id="@+id/toolbar"
+ android:layout_height="?attr/actionBarSize"
+ android:layout_width="match_parent"
+ app:layout_collapseMode="pin"/>
+
+ </android.support.design.widget.CollapsingToolbarLayout>
+
+ </android.support.design.widget.AppBarLayout>
+
+ <include layout="@layout/include_appbar_scrollview" />
+
+</android.support.design.widget.CoordinatorLayout>
diff --git a/design/tests/res/layout/design_text_input.xml b/design/tests/res/layout/design_text_input.xml
index f4bd1d1..4dba825 100644
--- a/design/tests/res/layout/design_text_input.xml
+++ b/design/tests/res/layout/design_text_input.xml
@@ -58,4 +58,18 @@
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
+ <android.support.design.widget.TextInputLayout
+ android:id="@+id/textinput_with_text"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content">
+
+ <android.support.design.widget.TextInputEditText
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:imeOptions="flagNoExtractUi"
+ android:hint="@string/textinput_hint"
+ android:text="@string/snackbar_text"/>
+
+ </android.support.design.widget.TextInputLayout>
+
</LinearLayout>
\ No newline at end of file
diff --git a/design/tests/src/android/support/design/testutils/AppBarLayoutMatchers.java b/design/tests/src/android/support/design/testutils/AppBarLayoutMatchers.java
new file mode 100755
index 0000000..4d6fc63
--- /dev/null
+++ b/design/tests/src/android/support/design/testutils/AppBarLayoutMatchers.java
@@ -0,0 +1,44 @@
+/*
+ * Copyright (C) 2016 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.design.testutils;
+
+import android.support.design.widget.AppBarLayout;
+
+import org.hamcrest.Description;
+import org.hamcrest.Matcher;
+import org.hamcrest.TypeSafeMatcher;
+
+public class AppBarLayoutMatchers {
+
+ /**
+ * Returns a matcher that matches AppBarLayouts which are collapsed.
+ */
+ public static Matcher isCollapsed() {
+ return new TypeSafeMatcher<AppBarLayout>() {
+ @Override
+ public void describeTo(Description description) {
+ description.appendText("AppBarLayout is collapsed");
+ }
+
+ @Override
+ protected boolean matchesSafely(AppBarLayout item) {
+ return item.getBottom() == (item.getHeight() - item.getTotalScrollRange());
+ }
+ };
+ }
+
+}
diff --git a/design/tests/src/android/support/design/testutils/SwipeUtils.java b/design/tests/src/android/support/design/testutils/SwipeUtils.java
new file mode 100644
index 0000000..cf92883
--- /dev/null
+++ b/design/tests/src/android/support/design/testutils/SwipeUtils.java
@@ -0,0 +1,68 @@
+/*
+ * Copyright (C) 2016 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.design.testutils;
+
+import android.support.test.espresso.action.CoordinatesProvider;
+import android.support.test.espresso.action.GeneralSwipeAction;
+import android.support.test.espresso.action.Press;
+import android.support.test.espresso.action.Swipe;
+import android.view.View;
+
+public class SwipeUtils {
+
+ public static GeneralSwipeAction swipeUp(final int swipeX,
+ final int swipeStartY, final int swipeAmountY) {
+ return new GeneralSwipeAction(
+ Swipe.SLOW,
+ new CoordinatesProvider() {
+ @Override
+ public float[] calculateCoordinates(View view) {
+ return new float[] { swipeX, swipeStartY };
+ }
+ },
+ new CoordinatesProvider() {
+ @Override
+ public float[] calculateCoordinates(View view) {
+ return new float[] { swipeX, swipeStartY - swipeAmountY };
+ }
+ },
+ Press.FINGER
+ );
+ }
+
+ public static GeneralSwipeAction swipeDown(final int swipeX,
+ final int swipeStartY, final int swipeAmountY) {
+ return new GeneralSwipeAction(
+ Swipe.SLOW,
+ new CoordinatesProvider() {
+ @Override
+ public float[] calculateCoordinates(View view) {
+ return new float[] { swipeX, swipeStartY };
+ }
+ },
+ new CoordinatesProvider() {
+ @Override
+ public float[] calculateCoordinates(View view) {
+ return new float[] { swipeX, swipeStartY + swipeAmountY };
+ }
+ },
+ Press.FINGER
+ );
+ }
+
+
+}
diff --git a/design/tests/src/android/support/design/testutils/TestUtils.java b/design/tests/src/android/support/design/testutils/TestUtils.java
index b9aae7a..2f9187d 100644
--- a/design/tests/src/android/support/design/testutils/TestUtils.java
+++ b/design/tests/src/android/support/design/testutils/TestUtils.java
@@ -16,7 +16,10 @@
package android.support.design.testutils;
+import android.app.Activity;
import android.content.Context;
+import android.content.pm.ActivityInfo;
+import android.content.res.Configuration;
import android.content.res.TypedArray;
import android.graphics.Bitmap;
import android.graphics.Canvas;
@@ -124,4 +127,20 @@
}
}
}
+
+ /**
+ * Rotates the given Activity to either portrait or landscape, depending on the current
+ * orientation.
+ */
+ public static void rotateOrientation(@NonNull Activity activity) {
+ switch (activity.getResources().getConfiguration().orientation) {
+ case Configuration.ORIENTATION_PORTRAIT:
+ activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
+ break;
+ case Configuration.ORIENTATION_LANDSCAPE:
+ default:
+ activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
+ break;
+ }
+ }
}
\ No newline at end of file
diff --git a/design/tests/src/android/support/design/testutils/TestUtilsMatchers.java b/design/tests/src/android/support/design/testutils/TestUtilsMatchers.java
index 2f1f30d..9d13ce7 100644
--- a/design/tests/src/android/support/design/testutils/TestUtilsMatchers.java
+++ b/design/tests/src/android/support/design/testutils/TestUtilsMatchers.java
@@ -22,6 +22,7 @@
import android.graphics.Rect;
import android.graphics.Typeface;
import android.graphics.drawable.Drawable;
+import android.os.Build;
import android.support.annotation.ColorInt;
import android.support.annotation.NonNull;
import android.support.design.widget.FloatingActionButton;
@@ -461,6 +462,24 @@
}
/**
+ * Returns a matcher that matches views which have a z-value greater than 0. Also matches if
+ * the platform we're running on does not support z-values.
+ */
+ public static Matcher<View> hasZ() {
+ return new TypeSafeMatcher<View>() {
+ @Override
+ public void describeTo(Description description) {
+ description.appendText("has a z value greater than 0");
+ }
+
+ @Override
+ public boolean matchesSafely(View view) {
+ return Build.VERSION.SDK_INT < 21 || ViewCompat.getZ(view) > 0f;
+ }
+ };
+ }
+
+ /**
* Returns a matcher that matches TextViews with the specified typeface.
*/
public static Matcher withTypeface(@NonNull final Typeface typeface) {
diff --git a/design/tests/src/android/support/design/widget/AppBarLayoutBaseTest.java b/design/tests/src/android/support/design/widget/AppBarLayoutBaseTest.java
index fc131a4..6fd4470 100644
--- a/design/tests/src/android/support/design/widget/AppBarLayoutBaseTest.java
+++ b/design/tests/src/android/support/design/widget/AppBarLayoutBaseTest.java
@@ -17,6 +17,8 @@
package android.support.design.widget;
import static android.support.design.testutils.CollapsingToolbarLayoutActions.setContentScrimColor;
+import static android.support.design.testutils.SwipeUtils.swipeDown;
+import static android.support.design.testutils.SwipeUtils.swipeUp;
import static android.support.design.testutils.TestUtilsActions.setText;
import static android.support.design.testutils.TestUtilsActions.setTitle;
import static android.support.test.espresso.Espresso.onView;
@@ -35,15 +37,10 @@
import android.support.annotation.StringRes;
import android.support.design.test.R;
import android.support.design.testutils.Shakespeare;
-import android.support.test.espresso.action.CoordinatesProvider;
-import android.support.test.espresso.action.GeneralSwipeAction;
-import android.support.test.espresso.action.Press;
-import android.support.test.espresso.action.Swipe;
import android.support.v4.view.ViewCompat;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.text.TextUtils;
-import android.view.View;
import android.widget.TextView;
import org.hamcrest.Description;
@@ -64,38 +61,12 @@
protected static void performVerticalSwipeUpGesture(@IdRes int containerId, final int swipeX,
final int swipeStartY, final int swipeAmountY) {
- onView(withId(containerId)).perform(new GeneralSwipeAction(
- Swipe.SLOW,
- new CoordinatesProvider() {
- @Override
- public float[] calculateCoordinates(View view) {
- return new float[] { swipeX, swipeStartY };
- }
- },
- new CoordinatesProvider() {
- @Override
- public float[] calculateCoordinates(View view) {
- return new float[] { swipeX, swipeStartY - swipeAmountY };
- }
- }, Press.FINGER));
+ onView(withId(containerId)).perform(swipeUp(swipeX, swipeStartY, swipeAmountY));
}
protected static void performVerticalSwipeDownGesture(@IdRes int containerId, final int swipeX,
final int swipeStartY, final int swipeAmountY) {
- onView(withId(containerId)).perform(new GeneralSwipeAction(
- Swipe.SLOW,
- new CoordinatesProvider() {
- @Override
- public float[] calculateCoordinates(View view) {
- return new float[] { swipeX, swipeStartY };
- }
- },
- new CoordinatesProvider() {
- @Override
- public float[] calculateCoordinates(View view) {
- return new float[] { swipeX, swipeStartY + swipeAmountY };
- }
- }, Press.FINGER));
+ onView(withId(containerId)).perform(swipeDown(swipeX, swipeStartY, swipeAmountY));
}
@CallSuper
diff --git a/design/tests/src/android/support/design/widget/AppBarLayoutCollapsePinTestActivity.java b/design/tests/src/android/support/design/widget/AppBarLayoutCollapsePinTestActivity.java
new file mode 100644
index 0000000..38ea4fc
--- /dev/null
+++ b/design/tests/src/android/support/design/widget/AppBarLayoutCollapsePinTestActivity.java
@@ -0,0 +1,34 @@
+/*
+ * Copyright (C) 2016 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.design.widget;
+
+import android.support.design.test.R;
+import android.support.v7.widget.Toolbar;
+
+public class AppBarLayoutCollapsePinTestActivity extends BaseTestActivity {
+
+ @Override
+ protected int getContentViewLayoutResId() {
+ return R.layout.design_appbar_toolbar_collapse_pin_restore_test;
+ }
+
+ @Override
+ protected void onContentViewSet() {
+ Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
+ setSupportActionBar(toolbar);
+ }
+}
diff --git a/design/tests/src/android/support/design/widget/AppBarWithCollapsingToolbarStateRestoreTest.java b/design/tests/src/android/support/design/widget/AppBarWithCollapsingToolbarStateRestoreTest.java
new file mode 100644
index 0000000..52f4ab2
--- /dev/null
+++ b/design/tests/src/android/support/design/widget/AppBarWithCollapsingToolbarStateRestoreTest.java
@@ -0,0 +1,63 @@
+/*
+ * Copyright (C) 2016 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.design.widget;
+
+import static android.support.design.testutils.AppBarLayoutMatchers.isCollapsed;
+import static android.support.design.testutils.SwipeUtils.swipeUp;
+import static android.support.design.testutils.TestUtils.rotateOrientation;
+import static android.support.design.testutils.TestUtilsMatchers.hasZ;
+import static android.support.test.espresso.Espresso.onView;
+import static android.support.test.espresso.assertion.ViewAssertions.matches;
+import static android.support.test.espresso.matcher.ViewMatchers.withId;
+
+import android.app.Activity;
+import android.support.design.test.R;
+
+import org.junit.Test;
+
+public class AppBarWithCollapsingToolbarStateRestoreTest
+ extends BaseInstrumentationTestCase<AppBarLayoutCollapsePinTestActivity> {
+
+ public AppBarWithCollapsingToolbarStateRestoreTest() {
+ super(AppBarLayoutCollapsePinTestActivity.class);
+ }
+
+ @Test
+ public void testRotateAndRestore() {
+ Activity activity = mActivityTestRule.getActivity();
+ final AppBarLayout appBar = (AppBarLayout) activity.findViewById(R.id.app_bar);
+
+ // Swipe up and collapse the AppBarLayout
+ onView(withId(R.id.coordinator_layout))
+ .perform(swipeUp(
+ appBar.getLeft() + (appBar.getWidth() / 2),
+ appBar.getBottom() + 20,
+ appBar.getHeight()));
+ onView(withId(R.id.app_bar))
+ .check(matches(hasZ()))
+ .check(matches(isCollapsed()));
+
+ // Now rotate the Activity
+ rotateOrientation(activity);
+
+ // And check that the app bar still is restored correctly
+ onView(withId(R.id.app_bar))
+ .check(matches(hasZ()))
+ .check(matches(isCollapsed()));
+ }
+
+}
diff --git a/design/tests/src/android/support/design/widget/CoordinatorLayoutTest.java b/design/tests/src/android/support/design/widget/CoordinatorLayoutTest.java
index 1d4f0a7..f8e4f99 100644
--- a/design/tests/src/android/support/design/widget/CoordinatorLayoutTest.java
+++ b/design/tests/src/android/support/design/widget/CoordinatorLayoutTest.java
@@ -16,6 +16,7 @@
package android.support.design.widget;
+import static android.support.test.InstrumentationRegistry.getInstrumentation;
import static android.support.test.espresso.Espresso.onView;
import static android.support.test.espresso.action.ViewActions.swipeUp;
import static android.support.test.espresso.matcher.ViewMatchers.withId;
@@ -40,8 +41,8 @@
import android.graphics.Rect;
import android.support.design.test.R;
import android.support.design.testutils.CoordinatorLayoutUtils;
+import android.support.design.testutils.CoordinatorLayoutUtils.DependentBehavior;
import android.support.design.widget.CoordinatorLayout.Behavior;
-import android.support.test.InstrumentationRegistry;
import android.support.test.filters.MediumTest;
import android.support.test.filters.SdkSuppress;
import android.support.v4.view.ViewCompat;
@@ -69,13 +70,13 @@
@Before
public void setup() {
- mInstrumentation = InstrumentationRegistry.getInstrumentation();
+ mInstrumentation = getInstrumentation();
}
@Test
@SdkSuppress(minSdkVersion = 21)
public void testSetFitSystemWindows() throws Throwable {
- final Instrumentation instrumentation = InstrumentationRegistry.getInstrumentation();
+ final Instrumentation instrumentation = getInstrumentation();
final CoordinatorLayout col = mActivityTestRule.getActivity().mCoordinatorLayout;
final View view = new View(col.getContext());
@@ -183,7 +184,7 @@
@Test
public void testInsetEdge() throws Throwable {
- final Instrumentation instrumentation = InstrumentationRegistry.getInstrumentation();
+ final Instrumentation instrumentation = getInstrumentation();
final CoordinatorLayout col = mActivityTestRule.getActivity().mCoordinatorLayout;
final View insetView = new View(col.getContext());
@@ -236,7 +237,7 @@
@Test
public void testDependentViewChanged() throws Throwable {
- final Instrumentation instrumentation = InstrumentationRegistry.getInstrumentation();
+ final Instrumentation instrumentation = getInstrumentation();
final CoordinatorLayout col = mActivityTestRule.getActivity().mCoordinatorLayout;
// Add two views, A & B, where B depends on A
@@ -250,7 +251,7 @@
lpB.width = 100;
lpB.height = 100;
final CoordinatorLayout.Behavior behavior =
- spy(new CoordinatorLayoutUtils.DependentBehavior(viewA));
+ spy(new DependentBehavior(viewA));
lpB.setBehavior(behavior);
mActivityTestRule.runOnUiThread(new Runnable() {
@@ -282,7 +283,7 @@
@Test
public void testDependentViewRemoved() throws Throwable {
- final Instrumentation instrumentation = InstrumentationRegistry.getInstrumentation();
+ final Instrumentation instrumentation = getInstrumentation();
final CoordinatorLayout col = mActivityTestRule.getActivity().mCoordinatorLayout;
// Add two views, A & B, where B depends on A
@@ -290,7 +291,7 @@
final View viewB = new View(col.getContext());
final CoordinatorLayout.LayoutParams lpB = col.generateDefaultLayoutParams();
final CoordinatorLayout.Behavior behavior =
- spy(new CoordinatorLayoutUtils.DependentBehavior(viewA));
+ spy(new DependentBehavior(viewA));
lpB.setBehavior(behavior);
mActivityTestRule.runOnUiThread(new Runnable() {
@@ -316,7 +317,7 @@
@Test
public void testGetDependenciesAfterDependentViewRemoved() throws Throwable {
- final Instrumentation instrumentation = InstrumentationRegistry.getInstrumentation();
+ final Instrumentation instrumentation = getInstrumentation();
final CoordinatorLayout col = mActivityTestRule.getActivity().mCoordinatorLayout;
// Add two views, A & B, where B depends on A
@@ -572,6 +573,55 @@
}
@Test
+ public void testNestedScrollingTriggeringDependentViewChanged() throws Throwable {
+ final CoordinatorLayoutActivity activity = mActivityTestRule.getActivity();
+ final CoordinatorLayout col = activity.mCoordinatorLayout;
+
+ // First a NestedScrollView to trigger nested scrolling
+ final View scrollView = LayoutInflater.from(activity).inflate(
+ R.layout.include_nestedscrollview, col, false);
+
+ // Now create a View and Behavior which depend on the scrollview
+ final ImageView dependentView = new ImageView(activity);
+ final CoordinatorLayout.Behavior dependentBehavior = spy(new DependentBehavior(scrollView));
+
+ // Finally a view which accepts nested scrolling in the CoordinatorLayout
+ final ImageView nestedScrollAwareView = new ImageView(activity);
+
+ mActivityTestRule.runOnUiThread(new Runnable() {
+ @Override
+ public void run() {
+ // First add the ScrollView
+ col.addView(scrollView);
+
+ // Now add the view which depends on the scrollview
+ CoordinatorLayout.LayoutParams clp = new CoordinatorLayout.LayoutParams(200, 200);
+ clp.setBehavior(dependentBehavior);
+ col.addView(dependentView, clp);
+
+ // Now add the nested scrolling aware view
+ clp = new CoordinatorLayout.LayoutParams(200, 200);
+ clp.setBehavior(new NestedScrollingBehavior());
+ col.addView(nestedScrollAwareView, clp);
+ }
+ });
+
+ // Wait for any layouts, and reset the Behavior so that the call counts are 0
+ getInstrumentation().waitForIdleSync();
+ reset(dependentBehavior);
+
+ // Now vertically swipe up on the NSV, causing nested scrolling to occur
+ onView(withId(R.id.nested_scrollview)).perform(swipeUp());
+
+ // Verify that the Behavior's onDependentViewChanged is not called due to the
+ // nested scroll
+ verify(dependentBehavior, never()).onDependentViewChanged(
+ eq(col), // parent
+ eq(dependentView), // child
+ eq(scrollView)); // axes
+ }
+
+ @Test
public void testDodgeInsetViewWithEmptyBounds() throws Throwable {
final CoordinatorLayout col = mActivityTestRule.getActivity().mCoordinatorLayout;
@@ -614,9 +664,9 @@
.getInsetDodgeRect(same(col), same(view), any(Rect.class));
}
- public static class NestedScrollingBehavior extends CoordinatorLayout.Behavior<ImageView> {
+ public static class NestedScrollingBehavior extends CoordinatorLayout.Behavior<View> {
@Override
- public boolean onStartNestedScroll(CoordinatorLayout coordinatorLayout, ImageView child,
+ public boolean onStartNestedScroll(CoordinatorLayout coordinatorLayout, View child,
View directTargetChild, View target, int nestedScrollAxes) {
// Return true so that we always accept nested scroll events
return true;
diff --git a/design/tests/src/android/support/design/widget/FloatingActionButtonTest.java b/design/tests/src/android/support/design/widget/FloatingActionButtonTest.java
index 069055b..e8cc701 100644
--- a/design/tests/src/android/support/design/widget/FloatingActionButtonTest.java
+++ b/design/tests/src/android/support/design/widget/FloatingActionButtonTest.java
@@ -33,11 +33,15 @@
import static android.support.design.testutils.TestUtilsMatchers.withFabContentHeight;
import static android.support.design.widget.DesignViewActions.setVisibility;
import static android.support.test.espresso.Espresso.onView;
+import static android.support.test.espresso.action.ViewActions.click;
import static android.support.test.espresso.assertion.ViewAssertions.matches;
import static android.support.test.espresso.matcher.ViewMatchers.isDisplayed;
import static android.support.test.espresso.matcher.ViewMatchers.withId;
import static org.hamcrest.Matchers.not;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.verify;
import android.app.Activity;
import android.content.res.ColorStateList;
@@ -229,6 +233,19 @@
}
@Test
+ public void testOnClickListener() {
+ final View.OnClickListener listener = mock(View.OnClickListener.class);
+ final View view = mActivityTestRule.getActivity().findViewById(R.id.fab_standard);
+ view.setOnClickListener(listener);
+
+ // Click on the fab
+ onView(withId(R.id.fab_standard)).perform(click());
+
+ // And verify that the listener was invoked once
+ verify(listener, times(1)).onClick(view);
+ }
+
+ @Test
public void testSetCompatElevation() {
onView(withId(R.id.fab_standard))
.perform(setEnabled(false))
diff --git a/design/tests/src/android/support/design/widget/TextInputLayoutTest.java b/design/tests/src/android/support/design/widget/TextInputLayoutTest.java
index 30c15b5..ee32b3f 100755
--- a/design/tests/src/android/support/design/widget/TextInputLayoutTest.java
+++ b/design/tests/src/android/support/design/widget/TextInputLayoutTest.java
@@ -456,6 +456,12 @@
.check(matches(withTextColor(textColor)));
}
+ @Test
+ public void testTextSetViaAttributeCollapsedHint() {
+ onView(withId(R.id.textinput_with_text))
+ .check(isHintExpanded(false));
+ }
+
static ViewAssertion isHintExpanded(final boolean expanded) {
return new ViewAssertion() {
@Override
diff --git a/exifinterface/build.gradle b/exifinterface/build.gradle
index 42f50c1..5cbffcf 100644
--- a/exifinterface/build.gradle
+++ b/exifinterface/build.gradle
@@ -38,23 +38,12 @@
from variant.javaCompile.destinationDir
from 'LICENSE.txt'
}
- def javadocTask = project.tasks.create(name: "javadoc${suffix}", type: Javadoc) {
- source android.sourceSets.main.java
- classpath = files(variant.javaCompile.classpath.files) + files(
- "${android.sdkDirectory}/platforms/${android.compileSdkVersion}/android.jar")
- }
-
- def javadocJarTask = project.tasks.create(name: "javadocJar${suffix}", type: Jar) {
- classifier = 'javadoc'
- from 'build/docs/javadoc'
- }
def sourcesJarTask = project.tasks.create(name: "sourceJar${suffix}", type: Jar) {
classifier = 'sources'
from android.sourceSets.main.java.srcDirs
}
- artifacts.add('archives', javadocJarTask);
artifacts.add('archives', sourcesJarTask);
}
diff --git a/fragment/build.gradle b/fragment/build.gradle
index 26e9f1c..a7e0f2a 100644
--- a/fragment/build.gradle
+++ b/fragment/build.gradle
@@ -53,7 +53,6 @@
testOptions {
unitTests.returnDefaultValues = true
- compileSdkVersion project.ext.currentSdk
}
}
@@ -70,16 +69,6 @@
from variant.javaCompile.destinationDir
from 'LICENSE.txt'
}
- def javadocTask = project.tasks.create(name: "javadoc${suffix}", type: Javadoc) {
- source android.sourceSets.main.java
- classpath = files(variant.javaCompile.classpath.files) + files(
- "${android.sdkDirectory}/platforms/${android.compileSdkVersion}/android.jar")
- }
-
- def javadocJarTask = project.tasks.create(name: "javadocJar${suffix}", type: Jar) {
- classifier = 'javadoc'
- from 'build/docs/javadoc'
- }
def sourcesJarTask = project.tasks.create(name: "sourceJar${suffix}", type: Jar) {
classifier = 'sources'
@@ -88,7 +77,6 @@
exclude('android/service/media/**')
}
- artifacts.add('archives', javadocJarTask);
artifacts.add('archives', sourcesJarTask);
}
diff --git a/graphics/drawable/animated/build.gradle b/graphics/drawable/animated/build.gradle
index bb110a1..a8cfd8a 100644
--- a/graphics/drawable/animated/build.gradle
+++ b/graphics/drawable/animated/build.gradle
@@ -67,23 +67,12 @@
from variant.javaCompile.destinationDir
from 'LICENSE.txt'
}
- def javadocTask = project.tasks.create(name: "javadoc${suffix}", type: Javadoc) {
- source android.sourceSets.main.java
- classpath = files(variant.javaCompile.classpath.files) + files(
- "${android.sdkDirectory}/platforms/${android.compileSdkVersion}/android.jar")
- }
-
- def javadocJarTask = project.tasks.create(name: "javadocJar${suffix}", type: Jar) {
- classifier = 'javadoc'
- from 'build/docs/javadoc'
- }
def sourcesJarTask = project.tasks.create(name: "sourceJar${suffix}", type: Jar) {
classifier = 'sources'
from android.sourceSets.main.java.srcDirs
}
- artifacts.add('archives', javadocJarTask);
artifacts.add('archives', sourcesJarTask);
}
diff --git a/graphics/drawable/static/build.gradle b/graphics/drawable/static/build.gradle
index 2c72f9f..f034999 100644
--- a/graphics/drawable/static/build.gradle
+++ b/graphics/drawable/static/build.gradle
@@ -43,10 +43,6 @@
additionalParameters "--no-version-vectors"
}
- packagingOptions {
- exclude 'LICENSE.txt'
- }
-
testOptions {
unitTests.returnDefaultValues = true
}
@@ -65,23 +61,12 @@
from variant.javaCompile.destinationDir
from 'LICENSE.txt'
}
- def javadocTask = project.tasks.create(name: "javadoc${suffix}", type: Javadoc) {
- source android.sourceSets.main.java
- classpath = files(variant.javaCompile.classpath.files) + files(
- "${android.sdkDirectory}/platforms/${android.compileSdkVersion}/android.jar")
- }
-
- def javadocJarTask = project.tasks.create(name: "javadocJar${suffix}", type: Jar) {
- classifier = 'javadoc'
- from 'build/docs/javadoc'
- }
def sourcesJarTask = project.tasks.create(name: "sourceJar${suffix}", type: Jar) {
classifier = 'sources'
from android.sourceSets.main.java.srcDirs
}
- artifacts.add('archives', javadocJarTask);
artifacts.add('archives', sourcesJarTask);
}
diff --git a/media-compat/build.gradle b/media-compat/build.gradle
index e26a1bc..34730f5 100644
--- a/media-compat/build.gradle
+++ b/media-compat/build.gradle
@@ -59,16 +59,6 @@
from variant.javaCompile.destinationDir
from 'LICENSE.txt'
}
- def javadocTask = project.tasks.create(name: "javadoc${suffix}", type: Javadoc) {
- source android.sourceSets.main.java
- classpath = files(variant.javaCompile.classpath.files) + files(
- "${android.sdkDirectory}/platforms/${android.compileSdkVersion}/android.jar")
- }
-
- def javadocJarTask = project.tasks.create(name: "javadocJar${suffix}", type: Jar) {
- classifier = 'javadoc'
- from 'build/docs/javadoc'
- }
def sourcesJarTask = project.tasks.create(name: "sourceJar${suffix}", type: Jar) {
classifier = 'sources'
@@ -77,7 +67,6 @@
exclude('android/service/media/**')
}
- artifacts.add('archives', javadocJarTask);
artifacts.add('archives', sourcesJarTask);
}
diff --git a/percent/build.gradle b/percent/build.gradle
index c3f386e..41e45ef 100644
--- a/percent/build.gradle
+++ b/percent/build.gradle
@@ -58,23 +58,12 @@
from variant.javaCompile.destinationDir
from 'LICENSE.txt'
}
- def javadocTask = project.tasks.create(name: "javadoc${suffix}", type: Javadoc) {
- source android.sourceSets.main.java
- classpath = files(variant.javaCompile.classpath.files) + files(
- "${android.sdkDirectory}/platforms/${android.compileSdkVersion}/android.jar")
- }
-
- def javadocJarTask = project.tasks.create(name: "javadocJar${suffix}", type: Jar) {
- classifier = 'javadoc'
- from 'build/docs/javadoc'
- }
def sourcesJarTask = project.tasks.create(name: "sourceJar${suffix}", type: Jar) {
classifier = 'sources'
from android.sourceSets.main.java.srcDirs
}
- artifacts.add('archives', javadocJarTask);
artifacts.add('archives', sourcesJarTask);
}
diff --git a/recommendation/build.gradle b/recommendation/build.gradle
index 75d68d1..1c51da0 100644
--- a/recommendation/build.gradle
+++ b/recommendation/build.gradle
@@ -46,22 +46,11 @@
from variant.javaCompile.destinationDir
from 'LICENSE.txt'
}
- def javadocTask = project.tasks.create(name: "javadoc${suffix}", type: Javadoc) {
- source android.sourceSets.main.java
- classpath = files(variant.javaCompile.classpath.files) + files(
- "${android.sdkDirectory}/platforms/${android.compileSdkVersion}/android.jar")
- }
-
- def javadocJarTask = project.tasks.create(name: "javadocJar${suffix}", type: Jar) {
- classifier = 'javadoc'
- from 'build/docs/javadoc'
- }
def sourcesJarTask = project.tasks.create(name: "sourceJar${suffix}", type: Jar) {
classifier = 'sources'
from android.sourceSets.main.java.srcDirs
}
- artifacts.add('archives', javadocJarTask);
artifacts.add('archives', sourcesJarTask);
}
diff --git a/samples/SupportLeanbackDemos/src/com/example/android/leanback/PlaybackControlHelper.java b/samples/SupportLeanbackDemos/src/com/example/android/leanback/PlaybackControlHelper.java
index df6995e..a6752eb 100644
--- a/samples/SupportLeanbackDemos/src/com/example/android/leanback/PlaybackControlHelper.java
+++ b/samples/SupportLeanbackDemos/src/com/example/android/leanback/PlaybackControlHelper.java
@@ -55,6 +55,9 @@
private PlaybackControlsRow.PictureInPictureAction mPipAction;
private Handler mHandler = new Handler();
+ // simulating whether the media is yet prepared and ready to play
+ private boolean mInitialized = true;
+
private final Runnable mUpdateProgressRunnable = new Runnable() {
@Override
public void run() {
@@ -159,7 +162,7 @@
@Override
public boolean hasValidMedia() {
- return true;
+ return mInitialized;
}
@Override
@@ -179,7 +182,7 @@
@Override
public int getMediaDuration() {
- return FAUX_DURATION;
+ return mInitialized ? FAUX_DURATION : 0;
}
@Override
@@ -280,4 +283,16 @@
mUpdateProgressRunnable.run();
}
}
+
+ public boolean isInitialized() {
+ return mInitialized;
+ }
+
+ public void setInitialized(boolean initialized) {
+ if (mInitialized != initialized) {
+ mInitialized = initialized;
+ onMetadataChanged();
+ onStateChanged();
+ }
+ }
};
diff --git a/samples/SupportLeanbackDemos/src/com/example/android/leanback/PlaybackControlSupportHelper.java b/samples/SupportLeanbackDemos/src/com/example/android/leanback/PlaybackControlSupportHelper.java
index e7afb27..0425e60 100644
--- a/samples/SupportLeanbackDemos/src/com/example/android/leanback/PlaybackControlSupportHelper.java
+++ b/samples/SupportLeanbackDemos/src/com/example/android/leanback/PlaybackControlSupportHelper.java
@@ -58,6 +58,9 @@
private PlaybackControlsRow.PictureInPictureAction mPipAction;
private Handler mHandler = new Handler();
+ // simulating whether the media is yet prepared and ready to play
+ private boolean mInitialized = true;
+
private final Runnable mUpdateProgressRunnable = new Runnable() {
@Override
public void run() {
@@ -162,7 +165,7 @@
@Override
public boolean hasValidMedia() {
- return true;
+ return mInitialized;
}
@Override
@@ -182,7 +185,7 @@
@Override
public int getMediaDuration() {
- return FAUX_DURATION;
+ return mInitialized ? FAUX_DURATION : 0;
}
@Override
@@ -283,4 +286,16 @@
mUpdateProgressRunnable.run();
}
}
+
+ public boolean isInitialized() {
+ return mInitialized;
+ }
+
+ public void setInitialized(boolean initialized) {
+ if (mInitialized != initialized) {
+ mInitialized = initialized;
+ onMetadataChanged();
+ onStateChanged();
+ }
+ }
};
diff --git a/samples/SupportLeanbackDemos/src/com/example/android/leanback/PlaybackOverlayFragment.java b/samples/SupportLeanbackDemos/src/com/example/android/leanback/PlaybackOverlayFragment.java
index 1531d14..bca057f 100644
--- a/samples/SupportLeanbackDemos/src/com/example/android/leanback/PlaybackOverlayFragment.java
+++ b/samples/SupportLeanbackDemos/src/com/example/android/leanback/PlaybackOverlayFragment.java
@@ -15,6 +15,7 @@
import android.content.Context;
import android.os.Bundle;
+import android.os.Handler;
import android.support.v17.leanback.widget.Action;
import android.support.v17.leanback.widget.ArrayObjectAdapter;
import android.support.v17.leanback.widget.HeaderItem;
@@ -56,6 +57,11 @@
private PlaybackControlHelper mGlue;
private PlaybackControlsRowPresenter mPlaybackControlsRowPresenter;
private ListRowPresenter mListRowPresenter;
+ final Handler mHandler = new Handler();
+
+ // Artificial delay to simulate a media being prepared. The onRowChanged callback should be
+ // called and the playback row UI should be updated after this delay.
+ private static final int MEDIA_PREPARATION_DELAY = 500;
private OnItemViewClickedListener mOnItemViewClickedListener = new OnItemViewClickedListener() {
@Override
@@ -124,6 +130,13 @@
}
};
+ mGlue.setInitialized(false);
+ mHandler.postDelayed(new Runnable() {
+ @Override
+ public void run() {
+ mGlue.setInitialized(true);
+ }
+ }, MEDIA_PREPARATION_DELAY);
mGlue.setOnItemViewClickedListener(mOnItemViewClickedListener);
mPlaybackControlsRowPresenter = mGlue.createControlsRowAndPresenter();
diff --git a/samples/SupportLeanbackDemos/src/com/example/android/leanback/PlaybackOverlaySupportFragment.java b/samples/SupportLeanbackDemos/src/com/example/android/leanback/PlaybackOverlaySupportFragment.java
index 7a33493..f51513c 100644
--- a/samples/SupportLeanbackDemos/src/com/example/android/leanback/PlaybackOverlaySupportFragment.java
+++ b/samples/SupportLeanbackDemos/src/com/example/android/leanback/PlaybackOverlaySupportFragment.java
@@ -18,6 +18,7 @@
import android.content.Context;
import android.os.Bundle;
+import android.os.Handler;
import android.support.v17.leanback.widget.Action;
import android.support.v17.leanback.widget.ArrayObjectAdapter;
import android.support.v17.leanback.widget.HeaderItem;
@@ -59,6 +60,11 @@
private PlaybackControlSupportHelper mGlue;
private PlaybackControlsRowPresenter mPlaybackControlsRowPresenter;
private ListRowPresenter mListRowPresenter;
+ final Handler mHandler = new Handler();
+
+ // Artificial delay to simulate a media being prepared. The onRowChanged callback should be
+ // called and the playback row UI should be updated after this delay.
+ private static final int MEDIA_PREPARATION_DELAY = 500;
private OnItemViewClickedListener mOnItemViewClickedListener = new OnItemViewClickedListener() {
@Override
@@ -127,6 +133,14 @@
}
};
+ mGlue.setInitialized(false);
+ mHandler.postDelayed(new Runnable() {
+ @Override
+ public void run() {
+ mGlue.setInitialized(true);
+ }
+ }, MEDIA_PREPARATION_DELAY);
+
mGlue.setOnItemViewClickedListener(mOnItemViewClickedListener);
mPlaybackControlsRowPresenter = mGlue.createControlsRowAndPresenter();
diff --git a/transition/build.gradle b/transition/build.gradle
index 05675f9..1071448 100644
--- a/transition/build.gradle
+++ b/transition/build.gradle
@@ -66,23 +66,12 @@
from variant.javaCompile.destinationDir
from 'LICENSE.txt'
}
- def javadocTask = project.tasks.create(name: "javadoc${suffix}", type: Javadoc) {
- source android.sourceSets.main.java
- classpath = files(variant.javaCompile.classpath.files) + files(
- "${android.sdkDirectory}/platforms/${android.compileSdkVersion}/android.jar")
- }
-
- def javadocJarTask = project.tasks.create(name: "javadocJar${suffix}", type: Jar) {
- classifier = 'javadoc'
- from 'build/docs/javadoc'
- }
def sourcesJarTask = project.tasks.create(name: "sourceJar${suffix}", type: Jar) {
classifier = 'sources'
from android.sourceSets.main.java.srcDirs
}
- artifacts.add('archives', javadocJarTask);
artifacts.add('archives', sourcesJarTask);
}
diff --git a/v13/build.gradle b/v13/build.gradle
index 85aa8a8..ef1da57 100644
--- a/v13/build.gradle
+++ b/v13/build.gradle
@@ -60,23 +60,12 @@
from variant.javaCompile.destinationDir
from 'LICENSE.txt'
}
- def javadocTask = project.tasks.create(name: "javadoc${suffix}", type: Javadoc) {
- source android.sourceSets.main.java
- classpath = files(variant.javaCompile.classpath.files) + files(
- "${android.sdkDirectory}/platforms/${android.compileSdkVersion}/android.jar")
- }
-
- def javadocJarTask = project.tasks.create(name: "javadocJar${suffix}", type: Jar) {
- classifier = 'javadoc'
- from 'build/docs/javadoc'
- }
def sourcesJarTask = project.tasks.create(name: "sourceJar${suffix}", type: Jar) {
classifier = 'sources'
from android.sourceSets.main.java.srcDirs
}
- artifacts.add('archives', javadocJarTask);
artifacts.add('archives', sourcesJarTask);
}
diff --git a/v14/preference/build.gradle b/v14/preference/build.gradle
index a7e63d5..e7d547b 100644
--- a/v14/preference/build.gradle
+++ b/v14/preference/build.gradle
@@ -67,23 +67,12 @@
from variant.javaCompile.destinationDir
from 'LICENSE.txt'
}
- def javadocTask = project.tasks.create(name: "javadoc${suffix}", type: Javadoc) {
- source android.sourceSets.main.java
- classpath = files(variant.javaCompile.classpath.files) + files(
- "${android.sdkDirectory}/platforms/${android.compileSdkVersion}/android.jar")
- }
-
- def javadocJarTask = project.tasks.create(name: "javadocJar${suffix}", type: Jar) {
- classifier = 'javadoc'
- from 'build/docs/javadoc'
- }
def sourcesJarTask = project.tasks.create(name: "sourceJar${suffix}", type: Jar) {
classifier = 'sources'
from android.sourceSets.main.java.srcDirs
}
- artifacts.add('archives', javadocJarTask);
artifacts.add('archives', sourcesJarTask);
}
diff --git a/v17/leanback/build.gradle b/v17/leanback/build.gradle
index f5befa7..7738081 100644
--- a/v17/leanback/build.gradle
+++ b/v17/leanback/build.gradle
@@ -69,23 +69,12 @@
from variant.javaCompile.destinationDir
from 'LICENSE.txt'
}
- def javadocTask = project.tasks.create(name: "javadoc${suffix}", type: Javadoc) {
- source android.sourceSets.main.java
- classpath = files(variant.javaCompile.classpath.files) + files(
- "${android.sdkDirectory}/platforms/${android.compileSdkVersion}/android.jar")
- }
-
- def javadocJarTask = project.tasks.create(name: "javadocJar${suffix}", type: Jar) {
- classifier = 'javadoc'
- from 'build/docs/javadoc'
- }
def sourcesJarTask = project.tasks.create(name: "sourceJar${suffix}", type: Jar) {
classifier = 'sources'
from android.sourceSets.main.java.srcDirs
}
- artifacts.add('archives', javadocJarTask);
artifacts.add('archives', sourcesJarTask);
}
diff --git a/v17/leanback/src/android/support/v17/leanback/app/PlaybackControlGlue.java b/v17/leanback/src/android/support/v17/leanback/app/PlaybackControlGlue.java
index b16f432..190ce22 100644
--- a/v17/leanback/src/android/support/v17/leanback/app/PlaybackControlGlue.java
+++ b/v17/leanback/src/android/support/v17/leanback/app/PlaybackControlGlue.java
@@ -211,9 +211,6 @@
* containing this row should be notified.
*/
protected void onRowChanged(PlaybackControlsRow row) {
- if (getHost() != null) {
- getHost().notifyPlaybackRowChanged();
- }
}
/**
@@ -330,5 +327,10 @@
public void fadeOut() {
mFragment.fadeOut();
}
+
+ @Override
+ public void notifyPlaybackRowChanged() {
+ mGlue.onRowChanged(mGlue.getControlsRow());
+ }
}
}
diff --git a/v17/leanback/src/android/support/v17/leanback/app/PlaybackControlSupportGlue.java b/v17/leanback/src/android/support/v17/leanback/app/PlaybackControlSupportGlue.java
index 55ce89e..b3d19ae 100644
--- a/v17/leanback/src/android/support/v17/leanback/app/PlaybackControlSupportGlue.java
+++ b/v17/leanback/src/android/support/v17/leanback/app/PlaybackControlSupportGlue.java
@@ -193,5 +193,10 @@
public void fadeOut() {
mFragment.fadeOut();
}
+
+ @Override
+ public void notifyPlaybackRowChanged() {
+ mGlue.onRowChanged(mGlue.getControlsRow());
+ }
}
}
diff --git a/v17/leanback/tests/java/android/support/v17/leanback/app/PlaybackControlGlueTest.java b/v17/leanback/tests/java/android/support/v17/leanback/app/PlaybackControlGlueTest.java
index f26c60c..326d2be 100644
--- a/v17/leanback/tests/java/android/support/v17/leanback/app/PlaybackControlGlueTest.java
+++ b/v17/leanback/tests/java/android/support/v17/leanback/app/PlaybackControlGlueTest.java
@@ -50,6 +50,8 @@
static class PlayControlGlueImpl extends PlaybackControlGlue {
int mSpeedId = PLAYBACK_SPEED_PAUSED;
+ // number of times onRowChanged callback is called
+ int mOnRowChangedCallCount = 0;
PlayControlGlueImpl(Context context, int[] seekSpeeds) {
super(context, seekSpeeds);
@@ -59,6 +61,11 @@
super(context, ffSpeeds, rwSpeeds);
}
+ PlayControlGlueImpl(Context context, PlaybackOverlayFragment fragment,
+ int[] seekSpeeds) {
+ super(context, fragment, seekSpeeds);
+ }
+
@Override
public boolean hasValidMedia() {
return true;
@@ -124,6 +131,16 @@
@Override
protected void onRowChanged(PlaybackControlsRow row) {
+ mOnRowChangedCallCount++;
+ }
+
+ public void notifyMetaDataChanged() {
+ onMetadataChanged();
+ onStateChanged();
+ }
+
+ public int getOnRowChangedCallCount() {
+ return mOnRowChangedCallCount;
}
}
@@ -557,4 +574,32 @@
assertEquals(PlaybackControlGlue.PLAYBACK_SPEED_NORMAL, glue.getCurrentSpeedId());
}
+ @Test
+ public void testOnRowChangedCallback() throws Exception {
+ final PlaybackOverlayFragment[] fragmentResult = new
+ PlaybackOverlayFragment[1];
+ InstrumentationRegistry.getInstrumentation().runOnMainSync(new Runnable() {
+ @Override
+ public void run() {
+ fragmentResult[0] = new PlaybackOverlayFragment();
+ }
+ });
+ PlaybackOverlayFragment fragment = fragmentResult[0];
+ PlayControlGlueImpl playbackGlue = new PlayControlGlueImpl(context, fragment,
+ new int[]{
+ PlaybackControlGlue.PLAYBACK_SPEED_FAST_L0,
+ PlaybackControlGlue.PLAYBACK_SPEED_FAST_L1,
+ PlaybackControlGlue.PLAYBACK_SPEED_FAST_L2
+ });
+
+ // before any controls row is created the count is zero
+ assertEquals(playbackGlue.getOnRowChangedCallCount(), 0);
+ playbackGlue.createControlsRowAndPresenter();
+ // after a controls row is created, onRowChanged() call back is called once
+ assertEquals(playbackGlue.getOnRowChangedCallCount(), 1);
+ playbackGlue.notifyMetaDataChanged();
+ // onMetaDataChanged() calls updateRowMetadata which ends up calling
+ // notifyPlaybackRowChanged on the old host and finally onRowChanged on the glue.
+ assertEquals(playbackGlue.getOnRowChangedCallCount(), 2);
+ }
}
diff --git a/v17/leanback/tests/java/android/support/v17/leanback/app/PlaybackControlSupportGlueTest.java b/v17/leanback/tests/java/android/support/v17/leanback/app/PlaybackControlSupportGlueTest.java
index 211b42c..748a39f 100644
--- a/v17/leanback/tests/java/android/support/v17/leanback/app/PlaybackControlSupportGlueTest.java
+++ b/v17/leanback/tests/java/android/support/v17/leanback/app/PlaybackControlSupportGlueTest.java
@@ -51,8 +51,10 @@
public class PlaybackControlSupportGlueTest {
- static class PlayControlGlueImpl extends PlaybackControlSupportGlue {
+ public static class PlayControlGlueImpl extends PlaybackControlSupportGlue {
int mSpeedId = PLAYBACK_SPEED_PAUSED;
+ // number of times onRowChanged callback is called
+ int mOnRowChangedCallCount = 0;
PlayControlGlueImpl(Context context, int[] seekSpeeds) {
super(context, seekSpeeds);
@@ -62,6 +64,11 @@
super(context, ffSpeeds, rwSpeeds);
}
+ PlayControlGlueImpl(Context context, PlaybackOverlaySupportFragment fragment,
+ int[] seekSpeeds) {
+ super(context, fragment, seekSpeeds);
+ }
+
@Override
public boolean hasValidMedia() {
return true;
@@ -127,6 +134,16 @@
@Override
protected void onRowChanged(PlaybackControlsRow row) {
+ mOnRowChangedCallCount++;
+ }
+
+ public void notifyMetaDataChanged() {
+ onMetadataChanged();
+ onStateChanged();
+ }
+
+ public int getOnRowChangedCallCount() {
+ return mOnRowChangedCallCount;
}
}
@@ -560,4 +577,33 @@
assertEquals(PlaybackControlSupportGlue.PLAYBACK_SPEED_NORMAL, glue.getCurrentSpeedId());
}
+ @Test
+ public void testOnRowChangedCallback() throws Exception {
+ final PlaybackOverlaySupportFragment[] fragmentResult = new
+ PlaybackOverlaySupportFragment[1];
+ InstrumentationRegistry.getInstrumentation().runOnMainSync(new Runnable() {
+ @Override
+ public void run() {
+ fragmentResult[0] = new PlaybackOverlaySupportFragment();
+ }
+ });
+ PlaybackOverlaySupportFragment fragment = fragmentResult[0];
+ PlayControlGlueImpl playbackGlue = new PlayControlGlueImpl(context, fragment,
+ new int[]{
+ PlaybackControlSupportGlue.PLAYBACK_SPEED_FAST_L0,
+ PlaybackControlSupportGlue.PLAYBACK_SPEED_FAST_L1,
+ PlaybackControlSupportGlue.PLAYBACK_SPEED_FAST_L2
+ });
+
+ // before any controls row is created the count is zero
+ assertEquals(playbackGlue.getOnRowChangedCallCount(), 0);
+ playbackGlue.createControlsRowAndPresenter();
+ // after a controls row is created, onRowChanged() call back is called once
+ assertEquals(playbackGlue.getOnRowChangedCallCount(), 1);
+ playbackGlue.notifyMetaDataChanged();
+ // onMetaDataChanged() calls updateRowMetadata which ends up calling
+ // notifyPlaybackRowChanged on the old host and finally onRowChanged on the glue.
+ assertEquals(playbackGlue.getOnRowChangedCallCount(), 2);
+ }
+
}
diff --git a/v17/preference-leanback/build.gradle b/v17/preference-leanback/build.gradle
index 9bfd0f3..11289d2 100644
--- a/v17/preference-leanback/build.gradle
+++ b/v17/preference-leanback/build.gradle
@@ -41,23 +41,12 @@
from variant.javaCompile.destinationDir
from 'LICENSE.txt'
}
- def javadocTask = project.tasks.create(name: "javadoc${suffix}", type: Javadoc) {
- source android.sourceSets.main.java
- classpath = files(variant.javaCompile.classpath.files) + files(
- "${android.sdkDirectory}/platforms/${android.compileSdkVersion}/android.jar")
- }
-
- def javadocJarTask = project.tasks.create(name: "javadocJar${suffix}", type: Jar) {
- classifier = 'javadoc'
- from 'build/docs/javadoc'
- }
def sourcesJarTask = project.tasks.create(name: "sourceJar${suffix}", type: Jar) {
classifier = 'sources'
from android.sourceSets.main.java.srcDirs
}
- artifacts.add('archives', javadocJarTask);
artifacts.add('archives', sourcesJarTask);
}
diff --git a/v7/appcompat/build.gradle b/v7/appcompat/build.gradle
index aa62632..1468503 100644
--- a/v7/appcompat/build.gradle
+++ b/v7/appcompat/build.gradle
@@ -66,23 +66,12 @@
from variant.javaCompile.destinationDir
from 'LICENSE.txt'
}
- def javadocTask = project.tasks.create(name: "javadoc${suffix}", type: Javadoc) {
- source android.sourceSets.main.java
- classpath = files(variant.javaCompile.classpath.files) + files(
- "${android.sdkDirectory}/platforms/${android.compileSdkVersion}/android.jar")
- }
-
- def javadocJarTask = project.tasks.create(name: "javadocJar${suffix}", type: Jar) {
- classifier = 'javadoc'
- from 'build/docs/javadoc'
- }
def sourcesJarTask = project.tasks.create(name: "sourceJar${suffix}", type: Jar) {
classifier = 'sources'
from android.sourceSets.main.java.srcDirs
}
- artifacts.add('archives', javadocJarTask);
artifacts.add('archives', sourcesJarTask);
}
diff --git a/v7/cardview/build.gradle b/v7/cardview/build.gradle
index b88aad7..4633a46 100644
--- a/v7/cardview/build.gradle
+++ b/v7/cardview/build.gradle
@@ -43,23 +43,12 @@
from variant.javaCompile.destinationDir
from 'LICENSE.txt'
}
- def javadocTask = project.tasks.create(name: "javadoc${suffix}", type: Javadoc) {
- source android.sourceSets.main.java
- classpath = files(variant.javaCompile.classpath.files) + files(
- "${android.sdkDirectory}/platforms/${android.compileSdkVersion}/android.jar")
- }
-
- def javadocJarTask = project.tasks.create(name: "javadocJar${suffix}", type: Jar) {
- classifier = 'javadoc'
- from 'build/docs/javadoc'
- }
def sourcesJarTask = project.tasks.create(name: "sourceJar${suffix}", type: Jar) {
classifier = 'sources'
from android.sourceSets.main.java.srcDirs
}
- artifacts.add('archives', javadocJarTask);
artifacts.add('archives', sourcesJarTask);
}
diff --git a/v7/gridlayout/build.gradle b/v7/gridlayout/build.gradle
index 542d5a7..beebabe 100644
--- a/v7/gridlayout/build.gradle
+++ b/v7/gridlayout/build.gradle
@@ -58,23 +58,12 @@
from variant.javaCompile.destinationDir
from 'LICENSE.txt'
}
- def javadocTask = project.tasks.create(name: "javadoc${suffix}", type: Javadoc) {
- source android.sourceSets.main.java
- classpath = files(variant.javaCompile.classpath.files) + files(
- "${android.sdkDirectory}/platforms/${android.compileSdkVersion}/android.jar")
- }
-
- def javadocJarTask = project.tasks.create(name: "javadocJar${suffix}", type: Jar) {
- classifier = 'javadoc'
- from 'build/docs/javadoc'
- }
def sourcesJarTask = project.tasks.create(name: "sourceJar${suffix}", type: Jar) {
classifier = 'sources'
from android.sourceSets.main.java.srcDirs
}
- artifacts.add('archives', javadocJarTask);
artifacts.add('archives', sourcesJarTask);
}
diff --git a/v7/mediarouter/build.gradle b/v7/mediarouter/build.gradle
index 6b63089..d6c4d78 100644
--- a/v7/mediarouter/build.gradle
+++ b/v7/mediarouter/build.gradle
@@ -4,6 +4,9 @@
dependencies {
compile project(":support-appcompat-v7")
compile project(":support-palette-v7")
+
+ androidTestCompile ("com.android.support.test:runner:${project.rootProject.ext.testRunnerVersion}")
+ testCompile 'junit:junit:4.12'
}
android {
@@ -11,6 +14,8 @@
defaultConfig {
minSdkVersion 9
+
+ testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
sourceSets {
@@ -23,6 +28,11 @@
'src'
]
main.res.srcDir 'res'
+
+ androidTest.setRoot('tests')
+ androidTest.java.srcDir 'tests/src'
+ androidTest.res.srcDir 'tests/res'
+ androidTest.manifest.srcFile 'tests/AndroidManifest.xml'
}
compileOptions {
@@ -44,23 +54,12 @@
from variant.javaCompile.destinationDir
from 'LICENSE.txt'
}
- def javadocTask = project.tasks.create(name: "javadoc${suffix}", type: Javadoc) {
- source android.sourceSets.main.java
- classpath = files(variant.javaCompile.classpath.files) + files(
- "${android.sdkDirectory}/platforms/${android.compileSdkVersion}/android.jar")
- }
-
- def javadocJarTask = project.tasks.create(name: "javadocJar${suffix}", type: Jar) {
- classifier = 'javadoc'
- from 'build/docs/javadoc'
- }
def sourcesJarTask = project.tasks.create(name: "sourceJar${suffix}", type: Jar) {
classifier = 'sources'
from android.sourceSets.main.java.srcDirs
}
- artifacts.add('archives', javadocJarTask);
artifacts.add('archives', sourcesJarTask);
}
diff --git a/v7/mediarouter/src/android/support/v7/app/MediaRouteChooserDialog.java b/v7/mediarouter/src/android/support/v7/app/MediaRouteChooserDialog.java
index ac79f2d..2e5b983 100644
--- a/v7/mediarouter/src/android/support/v7/app/MediaRouteChooserDialog.java
+++ b/v7/mediarouter/src/android/support/v7/app/MediaRouteChooserDialog.java
@@ -378,12 +378,12 @@
}
}
- private static final class RouteComparator implements Comparator<MediaRouter.RouteInfo> {
+ static final class RouteComparator implements Comparator<MediaRouter.RouteInfo> {
public static final RouteComparator sInstance = new RouteComparator();
@Override
public int compare(MediaRouter.RouteInfo lhs, MediaRouter.RouteInfo rhs) {
- return lhs.getName().compareTo(rhs.getName());
+ return lhs.getName().compareToIgnoreCase(rhs.getName());
}
}
}
diff --git a/v7/mediarouter/tests/AndroidManifest.xml b/v7/mediarouter/tests/AndroidManifest.xml
new file mode 100644
index 0000000..87c4d65
--- /dev/null
+++ b/v7/mediarouter/tests/AndroidManifest.xml
@@ -0,0 +1,36 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+ Copyright (C) 2016 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.
+ -->
+<manifest xmlns:android="http://schemas.android.com/apk/res/android"
+ xmlns:tools="http://schemas.android.com/tools"
+ package="android.support.v7.mediarouter.test">
+
+ <uses-sdk
+ android:minSdkVersion="9"
+ android:targetSdkVersion="23"
+ tools:overrideLibrary="android.support.test, android.app, android.support.test.rule,
+ android.support.test.espresso, android.support.test.espresso.idling"/>
+
+ <application android:supportsRtl="true">
+
+ <uses-library android:name="android.test.runner"/>
+ </application>
+
+ <instrumentation
+ android:name="android.test.InstrumentationTestRunner"
+ android:targetPackage="android.support.v7.mediarouter.test"/>
+
+</manifest>
diff --git a/v7/mediarouter/tests/NO_DOCS b/v7/mediarouter/tests/NO_DOCS
new file mode 100644
index 0000000..092a39c
--- /dev/null
+++ b/v7/mediarouter/tests/NO_DOCS
@@ -0,0 +1,17 @@
+# Copyright (C) 2016 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.
+
+Having this file, named NO_DOCS, in a directory will prevent
+Android javadocs from being generated for java files under
+the directory. This is especially useful for test projects.
diff --git a/v7/mediarouter/tests/src/android/support/v7/app/MediaRouteChooserDialogTest.java b/v7/mediarouter/tests/src/android/support/v7/app/MediaRouteChooserDialogTest.java
new file mode 100644
index 0000000..7a21cdb
--- /dev/null
+++ b/v7/mediarouter/tests/src/android/support/v7/app/MediaRouteChooserDialogTest.java
@@ -0,0 +1,68 @@
+/*
+ * Copyright (C) 2016 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.v7.app;
+
+import static org.junit.Assert.assertTrue;
+
+import android.support.test.filters.SmallTest;
+import android.support.test.runner.AndroidJUnit4;
+import android.support.v7.media.MediaRouter.RouteInfo;
+import android.support.v7.media.TestUtils;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+@RunWith(AndroidJUnit4.class)
+@SmallTest
+public class MediaRouteChooserDialogTest {
+ private MediaRouteChooserDialog.RouteComparator mComparator;
+
+ @Before
+ public void setup() {
+ mComparator = new MediaRouteChooserDialog.RouteComparator();
+ }
+
+ @Test
+ public void testRouteComparatorWithSameRouteName() {
+ RouteInfo routeInfo1 = TestUtils.createRouteInfo("ROUTE_ID_1", "ROUTE_NAME_1");
+ RouteInfo routeInfo2 = TestUtils.createRouteInfo("ROUTE_ID_2", "ROUTE_NAME_1");
+ int result = mComparator.compare(routeInfo1, routeInfo2);
+ assertTrue(result == 0);
+ }
+
+ @Test
+ public void testRouteComparatorWithCommonComparison() {
+ RouteInfo routeInfo1 = TestUtils.createRouteInfo("ROUTE_ID_1", "Route ABC");
+ RouteInfo routeInfo2 = TestUtils.createRouteInfo("ROUTE_ID_2", "Route XYZ");
+ int result = mComparator.compare(routeInfo1, routeInfo2);
+ assertTrue(result < 0);
+ }
+
+ @Test
+ public void testRouteComparatorWithCaseInsensitiveComparison() {
+ RouteInfo routeInfo1 = TestUtils.createRouteInfo("ROUTE_ID_1", "living room abc");
+ RouteInfo routeInfo2 = TestUtils.createRouteInfo("ROUTE_ID_2", "LIVING ROOM XYZ");
+ int result1 = mComparator.compare(routeInfo1, routeInfo2);
+ assertTrue(result1 < 0);
+
+ RouteInfo routeInfo3 = TestUtils.createRouteInfo("ROUTE_ID_3", "LIVING ROOM ABC");
+ RouteInfo routeInfo4 = TestUtils.createRouteInfo("ROUTE_ID_4", "living room xyz");
+ int result2 = mComparator.compare(routeInfo3, routeInfo4);
+ assertTrue(result2 < 0);
+ }
+}
diff --git a/v7/mediarouter/tests/src/android/support/v7/media/TestUtils.java b/v7/mediarouter/tests/src/android/support/v7/media/TestUtils.java
new file mode 100644
index 0000000..f92a4d2
--- /dev/null
+++ b/v7/mediarouter/tests/src/android/support/v7/media/TestUtils.java
@@ -0,0 +1,26 @@
+/*
+ * Copyright (C) 2016 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.v7.media;
+
+public class TestUtils {
+ public static MediaRouter.RouteInfo createRouteInfo(String id, String name) {
+ MediaRouteDescriptor descriptor = new MediaRouteDescriptor.Builder(id, name).build();
+ MediaRouter.RouteInfo routeInfo = new MediaRouter.RouteInfo(null, null, null);
+ routeInfo.updateDescriptor(descriptor);
+ return routeInfo;
+ }
+}
diff --git a/v7/palette/build.gradle b/v7/palette/build.gradle
index 2494370..8e332f5 100644
--- a/v7/palette/build.gradle
+++ b/v7/palette/build.gradle
@@ -39,23 +39,12 @@
from variant.javaCompile.destinationDir
from 'LICENSE.txt'
}
- def javadocTask = project.tasks.create(name: "javadoc${suffix}", type: Javadoc) {
- source android.sourceSets.main.java
- classpath = files(variant.javaCompile.classpath.files) + files(
- "${android.sdkDirectory}/platforms/${android.compileSdkVersion}/android.jar")
- }
-
- def javadocJarTask = project.tasks.create(name: "javadocJar${suffix}", type: Jar) {
- classifier = 'javadoc'
- from 'build/docs/javadoc'
- }
def sourcesJarTask = project.tasks.create(name: "sourceJar${suffix}", type: Jar) {
classifier = 'sources'
from android.sourceSets.main.java.srcDirs
}
- artifacts.add('archives', javadocJarTask);
artifacts.add('archives', sourcesJarTask);
}
diff --git a/v7/preference/build.gradle b/v7/preference/build.gradle
index a63cc9e..f6e1ce0 100644
--- a/v7/preference/build.gradle
+++ b/v7/preference/build.gradle
@@ -85,23 +85,12 @@
from variant.javaCompile.destinationDir
from 'LICENSE.txt'
}
- def javadocTask = project.tasks.create(name: "javadoc${suffix}", type: Javadoc) {
- source android.sourceSets.main.java
- classpath = files(variant.javaCompile.classpath.files) + files(
- "${android.sdkDirectory}/platforms/${android.compileSdkVersion}/android.jar")
- }
-
- def javadocJarTask = project.tasks.create(name: "javadocJar${suffix}", type: Jar) {
- classifier = 'javadoc'
- from 'build/docs/javadoc'
- }
def sourcesJarTask = project.tasks.create(name: "sourceJar${suffix}", type: Jar) {
classifier = 'sources'
from android.sourceSets.main.java.srcDirs
}
- artifacts.add('archives', javadocJarTask);
artifacts.add('archives', sourcesJarTask);
}
diff --git a/v7/recyclerview/build.gradle b/v7/recyclerview/build.gradle
index 11a098e..0e03496 100644
--- a/v7/recyclerview/build.gradle
+++ b/v7/recyclerview/build.gradle
@@ -47,10 +47,6 @@
targetCompatibility JavaVersion.VERSION_1_7
}
- packagingOptions {
- exclude 'LICENSE.txt'
- }
-
testOptions {
unitTests.returnDefaultValues = true
}
@@ -73,23 +69,12 @@
from variant.javaCompile.destinationDir
from 'LICENSE.txt'
}
- def javadocTask = project.tasks.create(name: "javadoc${suffix}", type: Javadoc) {
- source android.sourceSets.main.java
- classpath = files(variant.javaCompile.classpath.files) + files(
- "${android.sdkDirectory}/platforms/${android.compileSdkVersion}/android.jar")
- }
-
- def javadocJarTask = project.tasks.create(name: "javadocJar${suffix}", type: Jar) {
- classifier = 'javadoc'
- from 'build/docs/javadoc'
- }
def sourcesJarTask = project.tasks.create(name: "sourceJar${suffix}", type: Jar) {
classifier = 'sources'
from android.sourceSets.main.java.srcDirs
}
- artifacts.add('archives', javadocJarTask);
artifacts.add('archives', sourcesJarTask);
}