Merge "appcompat Fix keyboard tests for TV" into nyc-support-25.1-dev
diff --git a/annotations/src/android/support/annotation/IntDef.java b/annotations/src/android/support/annotation/IntDef.java
index be2e2b8..f621b7f 100644
--- a/annotations/src/android/support/annotation/IntDef.java
+++ b/annotations/src/android/support/annotation/IntDef.java
@@ -15,16 +15,12 @@
*/
package android.support.annotation;
-import java.lang.annotation.Retention;
-import java.lang.annotation.RetentionPolicy;
-import java.lang.annotation.Target;
-
import static java.lang.annotation.ElementType.ANNOTATION_TYPE;
-import static java.lang.annotation.ElementType.FIELD;
-import static java.lang.annotation.ElementType.METHOD;
-import static java.lang.annotation.ElementType.PARAMETER;
import static java.lang.annotation.RetentionPolicy.SOURCE;
+import java.lang.annotation.Retention;
+import java.lang.annotation.Target;
+
/**
* Denotes that the annotated element of integer type, represents
* a logical type and that its value should be one of the explicitly
@@ -47,7 +43,7 @@
* For a flag, set the flag attribute:
* <pre><code>
* @IntDef(
- * flag = true
+ * flag = true,
* value = {NAVIGATION_MODE_STANDARD, NAVIGATION_MODE_LIST, NAVIGATION_MODE_TABS})
* </code></pre>
*/
diff --git a/build.gradle b/build.gradle
index d7cced1..05a5999 100644
--- a/build.gradle
+++ b/build.gradle
@@ -41,7 +41,7 @@
}
gradle.ext.currentSdk = 25
-ext.supportVersion = '25.1.0'
+ext.supportVersion = '25.1.1-SNAPSHOT'
ext.extraVersion = 41
ext.supportRepoOut = ''
ext.buildToolsVersion = '24.0.1'
diff --git a/design/res/layout/design_bottom_navigation_item.xml b/design/res/layout/design_bottom_navigation_item.xml
index 67df838..f6212cf 100644
--- a/design/res/layout/design_bottom_navigation_item.xml
+++ b/design/res/layout/design_bottom_navigation_item.xml
@@ -26,8 +26,9 @@
<android.support.design.internal.BaselineLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
- android:layout_marginBottom="@dimen/design_bottom_navigation_margin"
android:layout_gravity="bottom|center_horizontal"
+ android:clipToPadding="false"
+ android:paddingBottom="10dp"
android:duplicateParentState="true">
<TextView
android:id="@+id/smallLabel"
diff --git a/design/src/android/support/design/internal/BaselineLayout.java b/design/src/android/support/design/internal/BaselineLayout.java
index eac3542..23a04cd 100644
--- a/design/src/android/support/design/internal/BaselineLayout.java
+++ b/design/src/android/support/design/internal/BaselineLayout.java
@@ -24,7 +24,8 @@
import android.view.ViewGroup;
/**
- * A simple ViewGroup that aligns all the views inside on a baseline.
+ * A simple ViewGroup that aligns all the views inside on a baseline. Note: bottom padding for this
+ * view will be measured starting from the baseline.
*
* @hide
*/
@@ -69,6 +70,7 @@
ViewCompat.getMeasuredState(child));
}
if (maxChildBaseline != -1) {
+ maxChildDescent = Math.max(maxChildDescent, getPaddingBottom());
maxHeight = Math.max(maxHeight, maxChildBaseline + maxChildDescent);
mBaseline = maxChildBaseline;
}
diff --git a/design/src/android/support/design/widget/TextInputLayout.java b/design/src/android/support/design/widget/TextInputLayout.java
index 92c1506..22f4546 100644
--- a/design/src/android/support/design/widget/TextInputLayout.java
+++ b/design/src/android/support/design/widget/TextInputLayout.java
@@ -1076,6 +1076,13 @@
});
}
+ if (mEditText != null && ViewCompat.getMinimumHeight(mEditText) <= 0) {
+ // We should make sure that the EditText has the same min-height as the password
+ // toggle view. This ensure focus works properly, and there is no visual jump
+ // if the password toggle is enabled/disabled.
+ mEditText.setMinimumHeight(ViewCompat.getMinimumHeight(mPasswordToggleView));
+ }
+
mPasswordToggleView.setVisibility(VISIBLE);
mPasswordToggleView.setChecked(mPasswordToggledVisible);
diff --git a/design/tests/res/layout/design_navigation_view.xml b/design/tests/res/layout/design_navigation_view.xml
index 1789843..4f7147d 100644
--- a/design/tests/res/layout/design_navigation_view.xml
+++ b/design/tests/res/layout/design_navigation_view.xml
@@ -37,7 +37,7 @@
android:fitsSystemWindows="true" tells the system to have
DrawerLayout span the full height of the screen, including the
system status bar on Lollipop+ versions of the plaform. -->
- <android.support.design.widget.NavigationView
+ <android.support.design.widget.NavigationTestView
android:id="@+id/start_drawer"
android:layout_width="wrap_content"
android:layout_height="match_parent"
diff --git a/design/tests/src/android/support/design/widget/NavigationTestView.java b/design/tests/src/android/support/design/widget/NavigationTestView.java
new file mode 100644
index 0000000..af3d69e
--- /dev/null
+++ b/design/tests/src/android/support/design/widget/NavigationTestView.java
@@ -0,0 +1,50 @@
+/*
+ * 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.content.Context;
+import android.support.v4.view.WindowInsetsCompat;
+import android.util.AttributeSet;
+
+/**
+ * Expose hasSystemWindowInsets() for testing.
+ */
+public class NavigationTestView extends NavigationView {
+
+ boolean mHashSystemWindowInsets;
+
+ public NavigationTestView(Context context) {
+ this(context, null);
+ }
+
+ public NavigationTestView(Context context, AttributeSet attrs) {
+ this(context, attrs, 0);
+ }
+
+ public NavigationTestView(Context context, AttributeSet attrs, int defStyleAttr) {
+ super(context, attrs, defStyleAttr);
+ }
+
+ @Override
+ protected void onInsetsChanged(WindowInsetsCompat insets) {
+ super.onInsetsChanged(insets);
+ mHashSystemWindowInsets = insets.hasSystemWindowInsets();
+ }
+
+ public boolean hasSystemWindowInsets() {
+ return mHashSystemWindowInsets;
+ }
+}
diff --git a/design/tests/src/android/support/design/widget/NavigationViewTest.java b/design/tests/src/android/support/design/widget/NavigationViewTest.java
index 7031281..f0c064e 100755
--- a/design/tests/src/android/support/design/widget/NavigationViewTest.java
+++ b/design/tests/src/android/support/design/widget/NavigationViewTest.java
@@ -94,7 +94,7 @@
private DrawerLayout mDrawerLayout;
- private NavigationView mNavigationView;
+ private NavigationTestView mNavigationView;
public NavigationViewTest() {
super(NavigationViewActivity.class);
@@ -104,7 +104,7 @@
public void setUp() throws Exception {
final NavigationViewActivity activity = mActivityTestRule.getActivity();
mDrawerLayout = (DrawerLayout) activity.findViewById(R.id.drawer_layout);
- mNavigationView = (NavigationView) mDrawerLayout.findViewById(R.id.start_drawer);
+ mNavigationView = (NavigationTestView) mDrawerLayout.findViewById(R.id.start_drawer);
// Close the drawer to reset the state for the next test
onView(withId(R.id.drawer_layout)).perform(closeDrawer(GravityCompat.START));
@@ -146,7 +146,11 @@
onView(withId(R.id.drawer_layout)).perform(openDrawer(GravityCompat.START));
if (Build.VERSION.SDK_INT >= 21) {
- assertFalse(mNavigationView.willNotDraw());
+ if (mNavigationView.hasSystemWindowInsets()) {
+ assertFalse(mNavigationView.willNotDraw());
+ } else {
+ assertTrue(mNavigationView.willNotDraw());
+ }
} else {
assertTrue(mNavigationView.willNotDraw());
}
diff --git a/design/tests/src/android/support/design/widget/TextInputLayoutTest.java b/design/tests/src/android/support/design/widget/TextInputLayoutTest.java
index 30c15b5..4944170 100755
--- a/design/tests/src/android/support/design/widget/TextInputLayoutTest.java
+++ b/design/tests/src/android/support/design/widget/TextInputLayoutTest.java
@@ -31,6 +31,7 @@
import static android.support.design.testutils.TextInputLayoutActions.setTypeface;
import static android.support.design.testutils.TextInputLayoutMatchers
.hasPasswordToggleContentDescription;
+import static android.support.test.InstrumentationRegistry.getInstrumentation;
import static android.support.test.espresso.Espresso.onView;
import static android.support.test.espresso.action.ViewActions.click;
import static android.support.test.espresso.action.ViewActions.typeText;
@@ -38,6 +39,7 @@
import static android.support.test.espresso.assertion.ViewAssertions.matches;
import static android.support.test.espresso.contrib.AccessibilityChecks.accessibilityAssertion;
import static android.support.test.espresso.matcher.ViewMatchers.hasContentDescription;
+import static android.support.test.espresso.matcher.ViewMatchers.hasFocus;
import static android.support.test.espresso.matcher.ViewMatchers.isChecked;
import static android.support.test.espresso.matcher.ViewMatchers.isDisplayed;
import static android.support.test.espresso.matcher.ViewMatchers.isEnabled;
@@ -66,6 +68,7 @@
import android.support.v4.widget.TextViewCompat;
import android.util.AttributeSet;
import android.util.SparseArray;
+import android.view.KeyEvent;
import android.view.View;
import android.view.inputmethod.EditorInfo;
import android.widget.EditText;
@@ -456,6 +459,21 @@
.check(matches(withTextColor(textColor)));
}
+ @Test
+ public void testFocusMovesToEditTextWithPasswordEnabled() {
+ // Focus the preceding EditText
+ onView(withId(R.id.textinput_edittext))
+ .perform(click())
+ .check(matches(hasFocus()));
+
+ // Then send a TAB to focus the next view
+ getInstrumentation().sendKeyDownUpSync(KeyEvent.KEYCODE_TAB);
+
+ // And check that the EditText is focused
+ onView(withId(R.id.textinput_edittext_pwd))
+ .check(matches(hasFocus()));
+ }
+
static ViewAssertion isHintExpanded(final boolean expanded) {
return new ViewAssertion() {
@Override
diff --git a/media-compat/build.gradle b/media-compat/build.gradle
index e26a1bc..9bec2a3 100644
--- a/media-compat/build.gradle
+++ b/media-compat/build.gradle
@@ -23,6 +23,8 @@
defaultConfig {
minSdkVersion 9
+
+ testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
sourceSets {
@@ -38,6 +40,11 @@
'java'
]
main.aidl.srcDirs = ['java']
+
+ androidTest.setRoot('tests')
+ androidTest.java.srcDir 'tests/src'
+ androidTest.res.srcDir 'tests/res'
+ androidTest.manifest.srcFile 'tests/AndroidManifest.xml'
}
compileOptions {
@@ -113,4 +120,4 @@
}
}
}
-}
\ No newline at end of file
+}
diff --git a/media-compat/tests/AndroidManifest.xml b/media-compat/tests/AndroidManifest.xml
new file mode 100644
index 0000000..00de2db
--- /dev/null
+++ b/media-compat/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.mediacompat.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"/>
+ <activity android:name="android.support.v4.media.session.TestActivity" />
+ </application>
+
+ <instrumentation
+ android:name="android.test.InstrumentationTestRunner"
+ android:targetPackage="android.support.mediacompat.test"/>
+
+</manifest>
diff --git a/media-compat/tests/NO_DOCS b/media-compat/tests/NO_DOCS
new file mode 100644
index 0000000..092a39c
--- /dev/null
+++ b/media-compat/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/media-compat/tests/src/android/support/v4/media/session/MediaSessionCompatTest.java b/media-compat/tests/src/android/support/v4/media/session/MediaSessionCompatTest.java
new file mode 100644
index 0000000..455a706
--- /dev/null
+++ b/media-compat/tests/src/android/support/v4/media/session/MediaSessionCompatTest.java
@@ -0,0 +1,99 @@
+/*
+ * 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.v4.media.session;
+
+import android.app.Activity;
+import android.content.Context;
+import android.os.Looper;
+import android.support.test.InstrumentationRegistry;
+import android.support.test.rule.ActivityTestRule;
+
+import java.util.HashMap;
+import java.util.Map;
+import java.util.concurrent.Semaphore;
+import java.util.concurrent.TimeUnit;
+
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+
+import static junit.framework.Assert.fail;
+
+public class MediaSessionCompatTest {
+ @Rule
+ public ActivityTestRule<TestActivity> mActivityRule =
+ new ActivityTestRule<>(TestActivity.class);
+ Context mContext;
+ Map<String, LockedObject> results = new HashMap<>();
+
+ @Before
+ public void setUp() {
+ mContext = InstrumentationRegistry.getContext();
+ }
+
+ @Test
+ public void testSetNullCallback() throws Throwable {
+ initWait("testSetNullCallback");
+ mActivityRule.runOnUiThread(new Runnable() {
+ @Override
+ public void run() {
+ try {
+ MediaSessionCompat session = new MediaSessionCompat(mContext, "TEST");
+ session.setCallback(null);
+ } catch (Exception e) {
+ fail("Fail with an exception: " + e);
+ } finally {
+ setResultData("testSetNullCallback", true);
+ }
+ }
+ });
+ waitFor("testSetNullCallback");
+ }
+
+ private void initWait(String key) throws InterruptedException {
+ results.put(key, new LockedObject());
+ }
+
+ private Object[] waitFor(String key) throws InterruptedException {
+ return results.get(key).waitFor();
+ }
+
+ private void setResultData(String key, Object... args) {
+ if (results.containsKey(key)) {
+ results.get(key).set(args);
+ }
+ }
+
+ private class LockedObject {
+ private Semaphore mLock = new Semaphore(1);
+ private volatile Object[] mArgs;
+
+ public LockedObject() {
+ mLock.drainPermits();
+ }
+
+ public void set(Object... args) {
+ mArgs = args;
+ mLock.release(1);
+ }
+
+ public Object[] waitFor() throws InterruptedException {
+ mLock.tryAcquire(1, 2, TimeUnit.SECONDS);
+ return mArgs;
+ }
+ }
+}
diff --git a/media-compat/tests/src/android/support/v4/media/session/TestActivity.java b/media-compat/tests/src/android/support/v4/media/session/TestActivity.java
new file mode 100644
index 0000000..dd56467
--- /dev/null
+++ b/media-compat/tests/src/android/support/v4/media/session/TestActivity.java
@@ -0,0 +1,22 @@
+/*
+ * 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.v4.media.session;
+
+import android.app.Activity;
+
+public class TestActivity extends Activity {
+}