summaryrefslogtreecommitdiff
path: root/android/support/v7/widget
diff options
context:
space:
mode:
Diffstat (limited to 'android/support/v7/widget')
-rw-r--r--android/support/v7/widget/ActionMenuView.java4
-rw-r--r--android/support/v7/widget/AdapterHelperTest.java124
-rw-r--r--android/support/v7/widget/AppCompatTextViewAutoSizeHelper.java10
-rw-r--r--android/support/v7/widget/ButtonBarLayout.java8
-rw-r--r--android/support/v7/widget/CardView.java93
-rw-r--r--android/support/v7/widget/LinearLayoutManager.java45
-rw-r--r--android/support/v7/widget/ListPopupWindow.java2
-rw-r--r--android/support/v7/widget/OrientationHelper.java10
-rw-r--r--android/support/v7/widget/RecyclerView.java176
-rw-r--r--android/support/v7/widget/StaggeredGridLayoutManager.java4
-rw-r--r--android/support/v7/widget/TooltipCompat.java35
-rw-r--r--android/support/v7/widget/ViewInfoStoreTest.java11
-rw-r--r--android/support/v7/widget/helper/ItemTouchHelper.java2
13 files changed, 268 insertions, 256 deletions
diff --git a/android/support/v7/widget/ActionMenuView.java b/android/support/v7/widget/ActionMenuView.java
index 76e06da6..14723a0c 100644
--- a/android/support/v7/widget/ActionMenuView.java
+++ b/android/support/v7/widget/ActionMenuView.java
@@ -268,10 +268,10 @@ public class ActionMenuView extends LinearLayoutCompat implements MenuBuilder.It
// Mark indices of children that can receive an extra cell.
if (lp.cellsUsed < minCells) {
minCells = lp.cellsUsed;
- minCellsAt = 1 << i;
+ minCellsAt = 1L << i;
minCellsItemCount = 1;
} else if (lp.cellsUsed == minCells) {
- minCellsAt |= 1 << i;
+ minCellsAt |= 1L << i;
minCellsItemCount++;
}
}
diff --git a/android/support/v7/widget/AdapterHelperTest.java b/android/support/v7/widget/AdapterHelperTest.java
index e0dbde50..a76f40e2 100644
--- a/android/support/v7/widget/AdapterHelperTest.java
+++ b/android/support/v7/widget/AdapterHelperTest.java
@@ -18,19 +18,21 @@ package android.support.v7.widget;
import static android.support.v7.widget.RecyclerView.ViewHolder;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertSame;
+
import android.support.test.filters.SmallTest;
-import android.test.AndroidTestCase;
-import android.util.Log;
import android.view.View;
-import android.widget.TextView;
-
-import junit.framework.AssertionFailedError;
-import junit.framework.TestResult;
import org.junit.Before;
+import org.junit.Rule;
import org.junit.Test;
+import org.junit.rules.TestWatcher;
+import org.junit.runner.Description;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;
+import org.mockito.Mockito;
import java.util.ArrayList;
import java.util.LinkedList;
@@ -41,7 +43,7 @@ import java.util.concurrent.atomic.AtomicInteger;
@RunWith(JUnit4.class)
@SmallTest
-public class AdapterHelperTest extends AndroidTestCase {
+public class AdapterHelperTest {
private static final boolean DEBUG = false;
@@ -49,35 +51,40 @@ public class AdapterHelperTest extends AndroidTestCase {
private static final String TAG = "AHT";
- List<MockViewHolder> mViewHolders;
+ private List<MockViewHolder> mViewHolders;
- AdapterHelper mAdapterHelper;
+ private AdapterHelper mAdapterHelper;
- List<AdapterHelper.UpdateOp> mFirstPassUpdates, mSecondPassUpdates;
+ private List<AdapterHelper.UpdateOp> mFirstPassUpdates, mSecondPassUpdates;
TestAdapter mTestAdapter;
- TestAdapter mPreProcessClone; // we clone adapter pre-process to run operations to see result
+ private TestAdapter mPreProcessClone;
+ // we clone adapter pre-process to run operations to see result
private List<TestAdapter.Item> mPreLayoutItems;
private StringBuilder mLog = new StringBuilder();
- @Override
- public void run(TestResult result) {
- super.run(result);
- if (!result.wasSuccessful()) {
- result.addFailure(this, new AssertionFailedError(mLog.toString()));
+ @Rule
+ public TestWatcher reportErrorLog = new TestWatcher() {
+ @Override
+ protected void failed(Throwable e, Description description) {
+ System.out.println(mLog.toString());
}
- }
+
+ @Override
+ protected void succeeded(Description description) {
+ }
+ };
@Before
public void cleanState() {
mLog.setLength(0);
- mPreLayoutItems = new ArrayList<TestAdapter.Item>();
- mViewHolders = new ArrayList<MockViewHolder>();
- mFirstPassUpdates = new ArrayList<AdapterHelper.UpdateOp>();
- mSecondPassUpdates = new ArrayList<AdapterHelper.UpdateOp>();
+ mPreLayoutItems = new ArrayList<>();
+ mViewHolders = new ArrayList<>();
+ mFirstPassUpdates = new ArrayList<>();
+ mSecondPassUpdates = new ArrayList<>();
mPreProcessClone = null;
mAdapterHelper = new AdapterHelper(new AdapterHelper.Callback() {
@Override
@@ -189,7 +196,7 @@ public class AdapterHelperTest extends AndroidTestCase {
if (mCollectLogs) {
mLog.append(msg).append("\n");
} else {
- Log.d(TAG, msg);
+ System.out.println(TAG + ":" + msg);
}
}
@@ -205,8 +212,7 @@ public class AdapterHelperTest extends AndroidTestCase {
}
private void addViewHolder(int position) {
- MockViewHolder viewHolder = new MockViewHolder(
- new TextView(getContext()));
+ MockViewHolder viewHolder = new MockViewHolder();
viewHolder.mPosition = position;
viewHolder.mItem = mTestAdapter.mItems.get(position);
mViewHolders.add(viewHolder);
@@ -502,7 +508,7 @@ public class AdapterHelperTest extends AndroidTestCase {
}
@Test
- public void testScenario18() throws InterruptedException {
+ public void testScenario18() {
setupBasic(10, 1, 4);
add(2, 11);
rm(16, 1);
@@ -622,7 +628,7 @@ public class AdapterHelperTest extends AndroidTestCase {
}
@Test
- public void testScenerio30() throws InterruptedException {
+ public void testScenerio30() {
mCollectLogs = true;
setupBasic(10, 3, 1);
rm(3, 2);
@@ -631,7 +637,7 @@ public class AdapterHelperTest extends AndroidTestCase {
}
@Test
- public void testScenerio31() throws InterruptedException {
+ public void testScenerio31() {
mCollectLogs = true;
setupBasic(10, 3, 1);
rm(3, 1);
@@ -844,7 +850,7 @@ public class AdapterHelperTest extends AndroidTestCase {
Random random = new Random(System.nanoTime());
for (int i = 0; i < 100; i++) {
try {
- Log.d(TAG, "running random test " + i);
+ log("running random test " + i);
randomTest(random, Math.max(40, 10 + nextInt(random, i)));
} catch (Throwable t) {
throw new Throwable("failure at random test " + i + "\n" + t.getMessage()
@@ -853,7 +859,7 @@ public class AdapterHelperTest extends AndroidTestCase {
}
}
- public void randomTest(Random random, int opCount) {
+ private void randomTest(Random random, int opCount) {
cleanState();
if (DEBUG) {
log("randomTest");
@@ -907,14 +913,14 @@ public class AdapterHelperTest extends AndroidTestCase {
preProcess();
}
- int nextInt(Random random, int n) {
+ private int nextInt(Random random, int n) {
if (n == 0) {
return 0;
}
return random.nextInt(n);
}
- public void assertOps(List<AdapterHelper.UpdateOp> actual,
+ private void assertOps(List<AdapterHelper.UpdateOp> actual,
AdapterHelper.UpdateOp... expected) {
assertEquals(expected.length, actual.size());
for (int i = 0; i < expected.length; i++) {
@@ -922,12 +928,12 @@ public class AdapterHelperTest extends AndroidTestCase {
}
}
- void assertDispatch(int firstPass, int secondPass) {
+ private void assertDispatch(int firstPass, int secondPass) {
assertEquals(firstPass, mFirstPassUpdates.size());
assertEquals(secondPass, mSecondPassUpdates.size());
}
- void preProcess() {
+ private void preProcess() {
for (MockViewHolder vh : mViewHolders) {
final int ind = mTestAdapter.mItems.indexOf(vh.mItem);
assertEquals("actual adapter position should match", ind,
@@ -975,23 +981,20 @@ public class AdapterHelperTest extends AndroidTestCase {
assertEquals(0, a2.mPendingAdded.size());
}
- AdapterHelper.UpdateOp op(int cmd, int start, int count) {
+ private AdapterHelper.UpdateOp op(int cmd, int start, int count) {
return new AdapterHelper.UpdateOp(cmd, start, count, null);
}
- AdapterHelper.UpdateOp op(int cmd, int start, int count, Object payload) {
+ private AdapterHelper.UpdateOp op(int cmd, int start, int count, Object payload) {
return new AdapterHelper.UpdateOp(cmd, start, count, payload);
}
- AdapterHelper.UpdateOp addOp(int start, int count) {
- return op(AdapterHelper.UpdateOp.ADD, start, count);
- }
-
- AdapterHelper.UpdateOp rmOp(int start, int count) {
+ private AdapterHelper.UpdateOp rmOp(int start, int count) {
return op(AdapterHelper.UpdateOp.REMOVE, start, count);
}
- AdapterHelper.UpdateOp upOp(int start, int count, Object payload) {
+ private AdapterHelper.UpdateOp upOp(int start, int count, @SuppressWarnings
+ ("SameParameterValue") Object payload) {
return op(AdapterHelper.UpdateOp.UPDATE, start, count, payload);
}
@@ -1002,7 +1005,7 @@ public class AdapterHelperTest extends AndroidTestCase {
mTestAdapter.add(start, count);
}
- boolean isItemLaidOut(int pos) {
+ private boolean isItemLaidOut(int pos) {
for (ViewHolder viewHolder : mViewHolders) {
if (viewHolder.mOldPosition == pos) {
return true;
@@ -1018,7 +1021,7 @@ public class AdapterHelperTest extends AndroidTestCase {
mTestAdapter.move(from, to);
}
- void rm(int start, int count) {
+ private void rm(int start, int count) {
if (DEBUG) {
log("rm(" + start + "," + count + ");");
}
@@ -1054,9 +1057,9 @@ public class AdapterHelperTest extends AndroidTestCase {
Queue<Item> mPendingAdded;
public TestAdapter(int initialCount, AdapterHelper container) {
- mItems = new ArrayList<Item>();
+ mItems = new ArrayList<>();
mAdapterHelper = container;
- mPendingAdded = new LinkedList<Item>();
+ mPendingAdded = new LinkedList<>();
for (int i = 0; i < initialCount; i++) {
mItems.add(new Item());
}
@@ -1102,15 +1105,13 @@ public class AdapterHelperTest extends AndroidTestCase {
));
}
- protected TestAdapter createCopy() {
+ TestAdapter createCopy() {
TestAdapter adapter = new TestAdapter(0, mAdapterHelper);
- for (Item item : mItems) {
- adapter.mItems.add(item);
- }
+ adapter.mItems.addAll(mItems);
return adapter;
}
- public void applyOps(List<AdapterHelper.UpdateOp> updates,
+ void applyOps(List<AdapterHelper.UpdateOp> updates,
TestAdapter dataSource) {
for (AdapterHelper.UpdateOp op : updates) {
switch (op.cmd) {
@@ -1140,20 +1141,16 @@ public class AdapterHelperTest extends AndroidTestCase {
return mPendingAdded.remove();
}
- public void createFakeItemAt(int fakeAddedItemIndex) {
- Item fakeItem = new Item();
- ((LinkedList<Item>) mPendingAdded).add(fakeAddedItemIndex, fakeItem);
- }
-
public static class Item {
private static AtomicInteger itemCounter = new AtomicInteger();
+ @SuppressWarnings("unused")
private final int id;
private int mVersionCount = 0;
- private ArrayList<Object> mPayloads = new ArrayList<Object>();
+ private ArrayList<Object> mPayloads = new ArrayList<>();
public Item() {
id = itemCounter.incrementAndGet();
@@ -1164,26 +1161,23 @@ public class AdapterHelperTest extends AndroidTestCase {
mVersionCount++;
}
- public void handleUpdate(Object payload) {
+ void handleUpdate(Object payload) {
assertSame(payload, mPayloads.get(0));
mPayloads.remove(0);
mVersionCount--;
}
- public int getUpdateCount() {
+ int getUpdateCount() {
return mVersionCount;
}
}
}
- void waitForDebugger() {
- android.os.Debug.waitForDebugger();
- }
-
static class MockViewHolder extends RecyclerView.ViewHolder {
- public Object mItem;
- public MockViewHolder(View itemView) {
- super(itemView);
+ TestAdapter.Item mItem;
+
+ MockViewHolder() {
+ super(Mockito.mock(View.class));
}
@Override
diff --git a/android/support/v7/widget/AppCompatTextViewAutoSizeHelper.java b/android/support/v7/widget/AppCompatTextViewAutoSizeHelper.java
index e82e4694..6b9d05a7 100644
--- a/android/support/v7/widget/AppCompatTextViewAutoSizeHelper.java
+++ b/android/support/v7/widget/AppCompatTextViewAutoSizeHelper.java
@@ -18,7 +18,6 @@ package android.support.v7.widget;
import static android.support.annotation.RestrictTo.Scope.LIBRARY_GROUP;
-import android.annotation.TargetApi;
import android.content.Context;
import android.content.res.Resources;
import android.content.res.TypedArray;
@@ -26,6 +25,7 @@ import android.graphics.RectF;
import android.os.Build;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
+import android.support.annotation.RequiresApi;
import android.support.annotation.RestrictTo;
import android.support.v4.widget.TextViewCompat;
import android.support.v7.appcompat.R;
@@ -45,8 +45,8 @@ import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
-import java.util.Hashtable;
import java.util.List;
+import java.util.concurrent.ConcurrentHashMap;
/**
* Utility class which encapsulates the logic for the TextView auto-size text feature added to
@@ -66,7 +66,8 @@ class AppCompatTextViewAutoSizeHelper {
private static final int DEFAULT_AUTO_SIZE_GRANULARITY_IN_PX = 1;
// Cache of TextView methods used via reflection; the key is the method name and the value is
// the method itself or null if it can not be found.
- private static Hashtable<String, Method> sTextViewMethodByNameCache = new Hashtable<>();
+ private static ConcurrentHashMap<String, Method> sTextViewMethodByNameCache =
+ new ConcurrentHashMap<>();
// Use this to specify that any of the auto-size configuration int values have not been set.
static final float UNSET_AUTO_SIZE_UNIFORM_CONFIGURATION_VALUE = -1f;
// Ported from TextView#VERY_WIDE. Represents a maximum width in pixels the TextView takes when
@@ -701,7 +702,7 @@ class AppCompatTextViewAutoSizeHelper {
return true;
}
- @TargetApi(23)
+ @RequiresApi(23)
private StaticLayout createStaticLayoutForMeasuring(CharSequence text,
Layout.Alignment alignment, int availableWidth, int maxLines) {
// Can use the StaticLayout.Builder (along with TextView params added in or after
@@ -725,7 +726,6 @@ class AppCompatTextViewAutoSizeHelper {
.build();
}
- @TargetApi(14)
private StaticLayout createStaticLayoutForMeasuringPre23(CharSequence text,
Layout.Alignment alignment, int availableWidth) {
// Setup defaults.
diff --git a/android/support/v7/widget/ButtonBarLayout.java b/android/support/v7/widget/ButtonBarLayout.java
index b47a5689..f4bbc6c3 100644
--- a/android/support/v7/widget/ButtonBarLayout.java
+++ b/android/support/v7/widget/ButtonBarLayout.java
@@ -35,9 +35,6 @@ import android.widget.LinearLayout;
*/
@RestrictTo(LIBRARY_GROUP)
public class ButtonBarLayout extends LinearLayout {
- /** Minimum screen height required for button stacking. */
- private static final int ALLOW_STACKING_MIN_HEIGHT_DP = 320;
-
/** Amount of the second button to "peek" above the fold when stacked. */
private static final int PEEK_BUTTON_DP = 16;
@@ -50,11 +47,8 @@ public class ButtonBarLayout extends LinearLayout {
public ButtonBarLayout(Context context, AttributeSet attrs) {
super(context, attrs);
- final boolean allowStackingDefault =
- getResources().getConfiguration().screenHeightDp >= ALLOW_STACKING_MIN_HEIGHT_DP;
final TypedArray ta = context.obtainStyledAttributes(attrs, R.styleable.ButtonBarLayout);
- mAllowStacking = ta.getBoolean(R.styleable.ButtonBarLayout_allowStacking,
- allowStackingDefault);
+ mAllowStacking = ta.getBoolean(R.styleable.ButtonBarLayout_allowStacking, true);
ta.recycle();
}
diff --git a/android/support/v7/widget/CardView.java b/android/support/v7/widget/CardView.java
index 58a04f0a..a45ee989 100644
--- a/android/support/v7/widget/CardView.java
+++ b/android/support/v7/widget/CardView.java
@@ -108,18 +108,57 @@ public class CardView extends FrameLayout {
final Rect mShadowBounds = new Rect();
public CardView(@NonNull Context context) {
- super(context);
- initialize(context, null, 0);
+ this(context, null);
}
public CardView(@NonNull Context context, @Nullable AttributeSet attrs) {
- super(context, attrs);
- initialize(context, attrs, 0);
+ this(context, attrs, R.attr.cardViewStyle);
}
public CardView(@NonNull Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
- initialize(context, attrs, defStyleAttr);
+
+ TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.CardView, defStyleAttr,
+ R.style.CardView);
+ ColorStateList backgroundColor;
+ if (a.hasValue(R.styleable.CardView_cardBackgroundColor)) {
+ backgroundColor = a.getColorStateList(R.styleable.CardView_cardBackgroundColor);
+ } else {
+ // There isn't one set, so we'll compute one based on the theme
+ final TypedArray aa = getContext().obtainStyledAttributes(COLOR_BACKGROUND_ATTR);
+ final int themeColorBackground = aa.getColor(0, 0);
+ aa.recycle();
+
+ // If the theme colorBackground is light, use our own light color, otherwise dark
+ final float[] hsv = new float[3];
+ Color.colorToHSV(themeColorBackground, hsv);
+ backgroundColor = ColorStateList.valueOf(hsv[2] > 0.5f
+ ? getResources().getColor(R.color.cardview_light_background)
+ : getResources().getColor(R.color.cardview_dark_background));
+ }
+ float radius = a.getDimension(R.styleable.CardView_cardCornerRadius, 0);
+ float elevation = a.getDimension(R.styleable.CardView_cardElevation, 0);
+ float maxElevation = a.getDimension(R.styleable.CardView_cardMaxElevation, 0);
+ mCompatPadding = a.getBoolean(R.styleable.CardView_cardUseCompatPadding, false);
+ mPreventCornerOverlap = a.getBoolean(R.styleable.CardView_cardPreventCornerOverlap, true);
+ int defaultPadding = a.getDimensionPixelSize(R.styleable.CardView_contentPadding, 0);
+ mContentPadding.left = a.getDimensionPixelSize(R.styleable.CardView_contentPaddingLeft,
+ defaultPadding);
+ mContentPadding.top = a.getDimensionPixelSize(R.styleable.CardView_contentPaddingTop,
+ defaultPadding);
+ mContentPadding.right = a.getDimensionPixelSize(R.styleable.CardView_contentPaddingRight,
+ defaultPadding);
+ mContentPadding.bottom = a.getDimensionPixelSize(R.styleable.CardView_contentPaddingBottom,
+ defaultPadding);
+ if (elevation > maxElevation) {
+ maxElevation = elevation;
+ }
+ mUserSetMinWidth = a.getDimensionPixelSize(R.styleable.CardView_android_minWidth, 0);
+ mUserSetMinHeight = a.getDimensionPixelSize(R.styleable.CardView_android_minHeight, 0);
+ a.recycle();
+
+ IMPL.initialize(mCardViewDelegate, context, backgroundColor, radius,
+ elevation, maxElevation);
}
@Override
@@ -220,50 +259,6 @@ public class CardView extends FrameLayout {
}
}
- private void initialize(Context context, AttributeSet attrs, int defStyleAttr) {
- TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.CardView, defStyleAttr,
- R.style.CardView);
- ColorStateList backgroundColor;
- if (a.hasValue(R.styleable.CardView_cardBackgroundColor)) {
- backgroundColor = a.getColorStateList(R.styleable.CardView_cardBackgroundColor);
- } else {
- // There isn't one set, so we'll compute one based on the theme
- final TypedArray aa = getContext().obtainStyledAttributes(COLOR_BACKGROUND_ATTR);
- final int themeColorBackground = aa.getColor(0, 0);
- aa.recycle();
-
- // If the theme colorBackground is light, use our own light color, otherwise dark
- final float[] hsv = new float[3];
- Color.colorToHSV(themeColorBackground, hsv);
- backgroundColor = ColorStateList.valueOf(hsv[2] > 0.5f
- ? getResources().getColor(R.color.cardview_light_background)
- : getResources().getColor(R.color.cardview_dark_background));
- }
- float radius = a.getDimension(R.styleable.CardView_cardCornerRadius, 0);
- float elevation = a.getDimension(R.styleable.CardView_cardElevation, 0);
- float maxElevation = a.getDimension(R.styleable.CardView_cardMaxElevation, 0);
- mCompatPadding = a.getBoolean(R.styleable.CardView_cardUseCompatPadding, false);
- mPreventCornerOverlap = a.getBoolean(R.styleable.CardView_cardPreventCornerOverlap, true);
- int defaultPadding = a.getDimensionPixelSize(R.styleable.CardView_contentPadding, 0);
- mContentPadding.left = a.getDimensionPixelSize(R.styleable.CardView_contentPaddingLeft,
- defaultPadding);
- mContentPadding.top = a.getDimensionPixelSize(R.styleable.CardView_contentPaddingTop,
- defaultPadding);
- mContentPadding.right = a.getDimensionPixelSize(R.styleable.CardView_contentPaddingRight,
- defaultPadding);
- mContentPadding.bottom = a.getDimensionPixelSize(R.styleable.CardView_contentPaddingBottom,
- defaultPadding);
- if (elevation > maxElevation) {
- maxElevation = elevation;
- }
- mUserSetMinWidth = a.getDimensionPixelSize(R.styleable.CardView_android_minWidth, 0);
- mUserSetMinHeight = a.getDimensionPixelSize(R.styleable.CardView_android_minHeight, 0);
- a.recycle();
-
- IMPL.initialize(mCardViewDelegate, context, backgroundColor, radius,
- elevation, maxElevation);
- }
-
@Override
public void setMinimumWidth(int minWidth) {
mUserSetMinWidth = minWidth;
diff --git a/android/support/v7/widget/LinearLayoutManager.java b/android/support/v7/widget/LinearLayoutManager.java
index 27df4901..fe4a37a6 100644
--- a/android/support/v7/widget/LinearLayoutManager.java
+++ b/android/support/v7/widget/LinearLayoutManager.java
@@ -48,9 +48,9 @@ public class LinearLayoutManager extends RecyclerView.LayoutManager implements
static final boolean DEBUG = false;
- public static final int HORIZONTAL = OrientationHelper.HORIZONTAL;
+ public static final int HORIZONTAL = RecyclerView.HORIZONTAL;
- public static final int VERTICAL = OrientationHelper.VERTICAL;
+ public static final int VERTICAL = RecyclerView.VERTICAL;
public static final int INVALID_OFFSET = Integer.MIN_VALUE;
@@ -66,7 +66,7 @@ public class LinearLayoutManager extends RecyclerView.LayoutManager implements
* Current orientation. Either {@link #HORIZONTAL} or {@link #VERTICAL}
*/
@RecyclerView.Orientation
- int mOrientation;
+ int mOrientation = RecyclerView.DEFAULT_ORIENTATION;
/**
* Helper class that keeps temporary layout state.
@@ -78,8 +78,6 @@ public class LinearLayoutManager extends RecyclerView.LayoutManager implements
/**
* Many calculations are made depending on orientation. To keep it clean, this interface
* helps {@link LinearLayoutManager} make those decisions.
- * Based on {@link #mOrientation}, an implementation is lazily created in
- * {@link #ensureLayoutState} method.
*/
OrientationHelper mOrientationHelper;
@@ -154,7 +152,7 @@ public class LinearLayoutManager extends RecyclerView.LayoutManager implements
* @param context Current context, will be used to access resources.
*/
public LinearLayoutManager(Context context) {
- this(context, VERTICAL, false);
+ this(context, RecyclerView.DEFAULT_ORIENTATION, false);
}
/**
@@ -335,13 +333,16 @@ public class LinearLayoutManager extends RecyclerView.LayoutManager implements
if (orientation != HORIZONTAL && orientation != VERTICAL) {
throw new IllegalArgumentException("invalid orientation:" + orientation);
}
+
assertNotInLayoutOrScroll(null);
- if (orientation == mOrientation) {
- return;
+
+ if (orientation != mOrientation || mOrientationHelper == null) {
+ mOrientationHelper =
+ OrientationHelper.createOrientationHelper(this, orientation);
+ mAnchorInfo.mOrientationHelper = mOrientationHelper;
+ mOrientation = orientation;
+ requestLayout();
}
- mOrientation = orientation;
- mOrientationHelper = null;
- requestLayout();
}
/**
@@ -516,7 +517,7 @@ public class LinearLayoutManager extends RecyclerView.LayoutManager implements
// TestResizingRelayoutWithAutoMeasure), which happens if we were to call
// updateAnchorInfoForLayout for an anchor that's not the focused view (e.g. a reference
// child which can change between layout passes).
- mAnchorInfo.assignFromViewAndKeepVisibleRect(focused);
+ mAnchorInfo.assignFromViewAndKeepVisibleRect(focused, getPosition(focused));
}
if (DEBUG) {
Log.d(TAG, "Anchor info:" + mAnchorInfo);
@@ -781,7 +782,7 @@ public class LinearLayoutManager extends RecyclerView.LayoutManager implements
}
final View focused = getFocusedChild();
if (focused != null && anchorInfo.isViewValidAsAnchor(focused, state)) {
- anchorInfo.assignFromViewAndKeepVisibleRect(focused);
+ anchorInfo.assignFromViewAndKeepVisibleRect(focused, getPosition(focused));
return true;
}
if (mLastStackFromEnd != mStackFromEnd) {
@@ -791,7 +792,7 @@ public class LinearLayoutManager extends RecyclerView.LayoutManager implements
? findReferenceChildClosestToEnd(recycler, state)
: findReferenceChildClosestToStart(recycler, state);
if (referenceChild != null) {
- anchorInfo.assignFromView(referenceChild);
+ anchorInfo.assignFromView(referenceChild, getPosition(referenceChild));
// If all visible views are removed in 1 pass, reference child might be out of bounds.
// If that is the case, offset it back to 0 so that we use these pre-layout children.
if (!state.isPreLayout() && supportsPredictiveItemAnimations()) {
@@ -985,9 +986,6 @@ public class LinearLayoutManager extends RecyclerView.LayoutManager implements
if (mLayoutState == null) {
mLayoutState = createLayoutState();
}
- if (mOrientationHelper == null) {
- mOrientationHelper = OrientationHelper.createOrientationHelper(this, mOrientation);
- }
}
/**
@@ -2370,7 +2368,8 @@ public class LinearLayoutManager extends RecyclerView.LayoutManager implements
/**
* Simple data class to keep Anchor information
*/
- class AnchorInfo {
+ static class AnchorInfo {
+ OrientationHelper mOrientationHelper;
int mPosition;
int mCoordinate;
boolean mLayoutFromEnd;
@@ -2413,13 +2412,13 @@ public class LinearLayoutManager extends RecyclerView.LayoutManager implements
&& lp.getViewLayoutPosition() < state.getItemCount();
}
- public void assignFromViewAndKeepVisibleRect(View child) {
+ public void assignFromViewAndKeepVisibleRect(View child, int position) {
final int spaceChange = mOrientationHelper.getTotalSpaceChange();
if (spaceChange >= 0) {
- assignFromView(child);
+ assignFromView(child, position);
return;
}
- mPosition = getPosition(child);
+ mPosition = position;
if (mLayoutFromEnd) {
final int prevLayoutEnd = mOrientationHelper.getEndAfterPadding() - spaceChange;
final int childEnd = mOrientationHelper.getDecoratedEnd(child);
@@ -2460,7 +2459,7 @@ public class LinearLayoutManager extends RecyclerView.LayoutManager implements
}
}
- public void assignFromView(View child) {
+ public void assignFromView(View child, int position) {
if (mLayoutFromEnd) {
mCoordinate = mOrientationHelper.getDecoratedEnd(child)
+ mOrientationHelper.getTotalSpaceChange();
@@ -2468,7 +2467,7 @@ public class LinearLayoutManager extends RecyclerView.LayoutManager implements
mCoordinate = mOrientationHelper.getDecoratedStart(child);
}
- mPosition = getPosition(child);
+ mPosition = position;
}
}
diff --git a/android/support/v7/widget/ListPopupWindow.java b/android/support/v7/widget/ListPopupWindow.java
index edc9781c..b98197c9 100644
--- a/android/support/v7/widget/ListPopupWindow.java
+++ b/android/support/v7/widget/ListPopupWindow.java
@@ -283,7 +283,7 @@ public class ListPopupWindow implements ShowableListMenu {
mAdapter.unregisterDataSetObserver(mObserver);
}
mAdapter = adapter;
- if (mAdapter != null) {
+ if (adapter != null) {
adapter.registerDataSetObserver(mObserver);
}
diff --git a/android/support/v7/widget/OrientationHelper.java b/android/support/v7/widget/OrientationHelper.java
index 5e90f2e7..99bcbaa0 100644
--- a/android/support/v7/widget/OrientationHelper.java
+++ b/android/support/v7/widget/OrientationHelper.java
@@ -48,6 +48,14 @@ public abstract class OrientationHelper {
}
/**
+ * Returns the {@link android.support.v7.widget.RecyclerView.LayoutManager LayoutManager} that
+ * is associated with this OrientationHelper.
+ */
+ public RecyclerView.LayoutManager getLayoutManager() {
+ return mLayoutManager;
+ }
+
+ /**
* Call this method after onLayout method is complete if state is NOT pre-layout.
* This method records information like layout bounds that might be useful in the next layout
* calculations.
@@ -435,4 +443,4 @@ public abstract class OrientationHelper {
}
};
}
-} \ No newline at end of file
+}
diff --git a/android/support/v7/widget/RecyclerView.java b/android/support/v7/widget/RecyclerView.java
index 84c28b10..a2879796 100644
--- a/android/support/v7/widget/RecyclerView.java
+++ b/android/support/v7/widget/RecyclerView.java
@@ -217,6 +217,7 @@ public class RecyclerView extends ViewGroup implements ScrollingView, NestedScro
public static final int HORIZONTAL = LinearLayout.HORIZONTAL;
public static final int VERTICAL = LinearLayout.VERTICAL;
+ static final int DEFAULT_ORIENTATION = VERTICAL;
public static final int NO_POSITION = -1;
public static final long NO_ID = -1;
public static final int INVALID_TYPE = -1;
@@ -349,7 +350,7 @@ public class RecyclerView extends ViewGroup implements ScrollingView, NestedScro
return;
}
if (mLayoutFrozen) {
- mLayoutRequestEaten = true;
+ mLayoutWasDefered = true;
return; //we'll process updates when ice age ends.
}
consumePendingUpdateOperations();
@@ -371,10 +372,21 @@ public class RecyclerView extends ViewGroup implements ScrollingView, NestedScro
boolean mEnableFastScroller;
@VisibleForTesting boolean mFirstLayoutComplete;
- // Counting lock to control whether we should ignore requestLayout calls from children or not.
- private int mEatRequestLayout = 0;
+ /**
+ * The current depth of nested calls to {@link #startInterceptRequestLayout()} (number of
+ * calls to {@link #startInterceptRequestLayout()} - number of calls to
+ * {@link #stopInterceptRequestLayout(boolean)} . This is used to signal whether we
+ * should defer layout operations caused by layout requests from children of
+ * {@link RecyclerView}.
+ */
+ private int mInterceptRequestLayoutDepth = 0;
+
+ /**
+ * True if a call to requestLayout was intercepted and prevented from executing like normal and
+ * we plan on continuing with normal execution later.
+ */
+ boolean mLayoutWasDefered;
- boolean mLayoutRequestEaten;
boolean mLayoutFrozen;
private boolean mIgnoreMotionEventTillDown;
@@ -1355,7 +1367,7 @@ public class RecyclerView extends ViewGroup implements ScrollingView, NestedScro
* @return true if an animating view is removed
*/
boolean removeAnimatingView(View view) {
- eatRequestLayout();
+ startInterceptRequestLayout();
final boolean removed = mChildHelper.removeViewIfHidden(view);
if (removed) {
final ViewHolder viewHolder = getChildViewHolderInt(view);
@@ -1366,7 +1378,7 @@ public class RecyclerView extends ViewGroup implements ScrollingView, NestedScro
}
}
// only clear request eaten flag if we removed the view.
- resumeRequestLayout(!removed);
+ stopInterceptRequestLayout(!removed);
return removed;
}
@@ -1736,10 +1748,10 @@ public class RecyclerView extends ViewGroup implements ScrollingView, NestedScro
.hasAnyUpdateTypes(AdapterHelper.UpdateOp.ADD | AdapterHelper.UpdateOp.REMOVE
| AdapterHelper.UpdateOp.MOVE)) {
TraceCompat.beginSection(TRACE_HANDLE_ADAPTER_UPDATES_TAG);
- eatRequestLayout();
+ startInterceptRequestLayout();
onEnterLayoutOrScroll();
mAdapterHelper.preProcess();
- if (!mLayoutRequestEaten) {
+ if (!mLayoutWasDefered) {
if (hasUpdatedView()) {
dispatchLayout();
} else {
@@ -1747,7 +1759,7 @@ public class RecyclerView extends ViewGroup implements ScrollingView, NestedScro
mAdapterHelper.consumePostponedUpdates();
}
}
- resumeRequestLayout(true);
+ stopInterceptRequestLayout(true);
onExitLayoutOrScroll();
TraceCompat.endSection();
} else if (mAdapterHelper.hasPendingUpdates()) {
@@ -1791,7 +1803,7 @@ public class RecyclerView extends ViewGroup implements ScrollingView, NestedScro
consumePendingUpdateOperations();
if (mAdapter != null) {
- eatRequestLayout();
+ startInterceptRequestLayout();
onEnterLayoutOrScroll();
TraceCompat.beginSection(TRACE_SCROLL_TAG);
fillRemainingScrollValues(mState);
@@ -1806,7 +1818,7 @@ public class RecyclerView extends ViewGroup implements ScrollingView, NestedScro
TraceCompat.endSection();
repositionShadowingViews();
onExitLayoutOrScroll();
- resumeRequestLayout(false);
+ stopInterceptRequestLayout(false);
}
if (!mItemDecorations.isEmpty()) {
invalidate();
@@ -1983,24 +1995,45 @@ public class RecyclerView extends ViewGroup implements ScrollingView, NestedScro
return mLayout.canScrollVertically() ? mLayout.computeVerticalScrollRange(mState) : 0;
}
-
- void eatRequestLayout() {
- mEatRequestLayout++;
- if (mEatRequestLayout == 1 && !mLayoutFrozen) {
- mLayoutRequestEaten = false;
+ /**
+ * This method should be called before any code that may trigger a child view to cause a call to
+ * {@link RecyclerView#requestLayout()}. Doing so enables {@link RecyclerView} to avoid
+ * reacting to additional redundant calls to {@link #requestLayout()}.
+ * <p>
+ * A call to this method must always be accompanied by a call to
+ * {@link #stopInterceptRequestLayout(boolean)} that follows the code that may trigger a
+ * child View to cause a call to {@link RecyclerView#requestLayout()}.
+ *
+ * @see #stopInterceptRequestLayout(boolean)
+ */
+ void startInterceptRequestLayout() {
+ mInterceptRequestLayoutDepth++;
+ if (mInterceptRequestLayoutDepth == 1 && !mLayoutFrozen) {
+ mLayoutWasDefered = false;
}
}
- void resumeRequestLayout(boolean performLayoutChildren) {
- if (mEatRequestLayout < 1) {
+ /**
+ * This method should be called after any code that may trigger a child view to cause a call to
+ * {@link RecyclerView#requestLayout()}.
+ * <p>
+ * A call to this method must always be accompanied by a call to
+ * {@link #startInterceptRequestLayout()} that precedes the code that may trigger a child
+ * View to cause a call to {@link RecyclerView#requestLayout()}.
+ *
+ * @see #startInterceptRequestLayout()
+ */
+ void stopInterceptRequestLayout(boolean performLayoutChildren) {
+ if (mInterceptRequestLayoutDepth < 1) {
//noinspection PointlessBooleanExpression
if (DEBUG) {
- throw new IllegalStateException("invalid eat request layout count"
+ throw new IllegalStateException("stopInterceptRequestLayout was called more "
+ + "times than startInterceptRequestLayout."
+ exceptionLabel());
}
- mEatRequestLayout = 1;
+ mInterceptRequestLayoutDepth = 1;
}
- if (!performLayoutChildren) {
+ if (!performLayoutChildren && !mLayoutFrozen) {
// Reset the layout request eaten counter.
// This is necessary since eatRequest calls can be nested in which case the other
// call will override the inner one.
@@ -2009,19 +2042,19 @@ public class RecyclerView extends ViewGroup implements ScrollingView, NestedScro
// eat layout for dispatchLayout
// a bunch of req layout calls arrive
- mLayoutRequestEaten = false;
+ mLayoutWasDefered = false;
}
- if (mEatRequestLayout == 1) {
+ if (mInterceptRequestLayoutDepth == 1) {
// when layout is frozen we should delay dispatchLayout()
- if (performLayoutChildren && mLayoutRequestEaten && !mLayoutFrozen
+ if (performLayoutChildren && mLayoutWasDefered && !mLayoutFrozen
&& mLayout != null && mAdapter != null) {
dispatchLayout();
}
if (!mLayoutFrozen) {
- mLayoutRequestEaten = false;
+ mLayoutWasDefered = false;
}
}
- mEatRequestLayout--;
+ mInterceptRequestLayoutDepth--;
}
/**
@@ -2051,10 +2084,10 @@ public class RecyclerView extends ViewGroup implements ScrollingView, NestedScro
assertNotInLayoutOrScroll("Do not setLayoutFrozen in layout or scroll");
if (!frozen) {
mLayoutFrozen = false;
- if (mLayoutRequestEaten && mLayout != null && mAdapter != null) {
+ if (mLayoutWasDefered && mLayout != null && mAdapter != null) {
requestLayout();
}
- mLayoutRequestEaten = false;
+ mLayoutWasDefered = false;
} else {
final long now = SystemClock.uptimeMillis();
MotionEvent cancelEvent = MotionEvent.obtain(now, now,
@@ -2471,9 +2504,9 @@ public class RecyclerView extends ViewGroup implements ScrollingView, NestedScro
// panic, focused view is not a child anymore, cannot call super.
return null;
}
- eatRequestLayout();
+ startInterceptRequestLayout();
mLayout.onFocusSearchFailed(focused, direction, mRecycler, mState);
- resumeRequestLayout(false);
+ stopInterceptRequestLayout(false);
}
result = ff.findNextFocus(this, focused, direction);
} else {
@@ -2485,9 +2518,9 @@ public class RecyclerView extends ViewGroup implements ScrollingView, NestedScro
// panic, focused view is not a child anymore, cannot call super.
return null;
}
- eatRequestLayout();
+ startInterceptRequestLayout();
result = mLayout.onFocusSearchFailed(focused, direction, mRecycler, mState);
- resumeRequestLayout(false);
+ stopInterceptRequestLayout(false);
}
}
if (result != null && !result.hasFocusable()) {
@@ -3202,7 +3235,7 @@ public class RecyclerView extends ViewGroup implements ScrollingView, NestedScro
}
// custom onMeasure
if (mAdapterUpdateDuringMeasure) {
- eatRequestLayout();
+ startInterceptRequestLayout();
onEnterLayoutOrScroll();
processAdapterUpdatesAndSetAnimationFlags();
onExitLayoutOrScroll();
@@ -3215,7 +3248,7 @@ public class RecyclerView extends ViewGroup implements ScrollingView, NestedScro
mState.mInPreLayout = false;
}
mAdapterUpdateDuringMeasure = false;
- resumeRequestLayout(false);
+ stopInterceptRequestLayout(false);
} else if (mState.mRunPredictiveAnimations) {
// If mAdapterUpdateDuringMeasure is false and mRunPredictiveAnimations is true:
// this means there is already an onMeasure() call performed to handle the pending
@@ -3231,9 +3264,9 @@ public class RecyclerView extends ViewGroup implements ScrollingView, NestedScro
} else {
mState.mItemCount = 0;
}
- eatRequestLayout();
+ startInterceptRequestLayout();
mLayout.onMeasure(mRecycler, mState, widthSpec, heightSpec);
- resumeRequestLayout(false);
+ stopInterceptRequestLayout(false);
mState.mInPreLayout = false; // clear
}
}
@@ -3668,7 +3701,7 @@ public class RecyclerView extends ViewGroup implements ScrollingView, NestedScro
mState.assertLayoutStep(State.STEP_START);
fillRemainingScrollValues(mState);
mState.mIsMeasuring = false;
- eatRequestLayout();
+ startInterceptRequestLayout();
mViewInfoStore.clear();
onEnterLayoutOrScroll();
processAdapterUpdatesAndSetAnimationFlags();
@@ -3748,7 +3781,7 @@ public class RecyclerView extends ViewGroup implements ScrollingView, NestedScro
clearOldPositions();
}
onExitLayoutOrScroll();
- resumeRequestLayout(false);
+ stopInterceptRequestLayout(false);
mState.mLayoutStep = State.STEP_LAYOUT;
}
@@ -3757,7 +3790,7 @@ public class RecyclerView extends ViewGroup implements ScrollingView, NestedScro
* This step might be run multiple times if necessary (e.g. measure).
*/
private void dispatchLayoutStep2() {
- eatRequestLayout();
+ startInterceptRequestLayout();
onEnterLayoutOrScroll();
mState.assertLayoutStep(State.STEP_LAYOUT | State.STEP_ANIMATIONS);
mAdapterHelper.consumeUpdatesInOnePass();
@@ -3775,7 +3808,7 @@ public class RecyclerView extends ViewGroup implements ScrollingView, NestedScro
mState.mRunSimpleAnimations = mState.mRunSimpleAnimations && mItemAnimator != null;
mState.mLayoutStep = State.STEP_ANIMATIONS;
onExitLayoutOrScroll();
- resumeRequestLayout(false);
+ stopInterceptRequestLayout(false);
}
/**
@@ -3784,7 +3817,7 @@ public class RecyclerView extends ViewGroup implements ScrollingView, NestedScro
*/
private void dispatchLayoutStep3() {
mState.assertLayoutStep(State.STEP_ANIMATIONS);
- eatRequestLayout();
+ startInterceptRequestLayout();
onEnterLayoutOrScroll();
mState.mLayoutStep = State.STEP_START;
if (mState.mRunSimpleAnimations) {
@@ -3860,7 +3893,7 @@ public class RecyclerView extends ViewGroup implements ScrollingView, NestedScro
mLayout.onLayoutCompleted(mState);
onExitLayoutOrScroll();
- resumeRequestLayout(false);
+ stopInterceptRequestLayout(false);
mViewInfoStore.clear();
if (didChildRangeChange(mMinMaxLayoutPositions[0], mMinMaxLayoutPositions[1])) {
dispatchOnScrolled(0, 0);
@@ -4043,10 +4076,10 @@ public class RecyclerView extends ViewGroup implements ScrollingView, NestedScro
@Override
public void requestLayout() {
- if (mEatRequestLayout == 0 && !mLayoutFrozen) {
+ if (mInterceptRequestLayoutDepth == 0 && !mLayoutFrozen) {
super.requestLayout();
} else {
- mLayoutRequestEaten = true;
+ mLayoutWasDefered = true;
}
}
@@ -4905,7 +4938,7 @@ public class RecyclerView extends ViewGroup implements ScrollingView, NestedScro
}
if (mAdapter != null) {
- eatRequestLayout();
+ startInterceptRequestLayout();
onEnterLayoutOrScroll();
TraceCompat.beginSection(TRACE_SCROLL_TAG);
fillRemainingScrollValues(mState);
@@ -4921,7 +4954,7 @@ public class RecyclerView extends ViewGroup implements ScrollingView, NestedScro
repositionShadowingViews();
onExitLayoutOrScroll();
- resumeRequestLayout(false);
+ stopInterceptRequestLayout(false);
if (smoothScroller != null && !smoothScroller.isPendingInitialRun()
&& smoothScroller.isRunning()) {
@@ -6544,7 +6577,8 @@ public class RecyclerView extends ViewGroup implements ScrollingView, NestedScro
* @see #getItemViewType(int)
* @see #onBindViewHolder(ViewHolder, int)
*/
- public abstract VH onCreateViewHolder(ViewGroup parent, int viewType);
+ @NonNull
+ public abstract VH onCreateViewHolder(@NonNull ViewGroup parent, int viewType);
/**
* Called by RecyclerView to display the data at the specified position. This method should
@@ -6566,7 +6600,7 @@ public class RecyclerView extends ViewGroup implements ScrollingView, NestedScro
* item at the given position in the data set.
* @param position The position of the item within the adapter's data set.
*/
- public abstract void onBindViewHolder(VH holder, int position);
+ public abstract void onBindViewHolder(@NonNull VH holder, int position);
/**
* Called by RecyclerView to display the data at the specified position. This method
@@ -6597,7 +6631,8 @@ public class RecyclerView extends ViewGroup implements ScrollingView, NestedScro
* @param payloads A non-null list of merged payloads. Can be empty list if requires full
* update.
*/
- public void onBindViewHolder(VH holder, int position, List<Object> payloads) {
+ public void onBindViewHolder(@NonNull VH holder, int position,
+ @NonNull List<Object> payloads) {
onBindViewHolder(holder, position);
}
@@ -6607,7 +6642,7 @@ public class RecyclerView extends ViewGroup implements ScrollingView, NestedScro
*
* @see #onCreateViewHolder(ViewGroup, int)
*/
- public final VH createViewHolder(ViewGroup parent, int viewType) {
+ public final VH createViewHolder(@NonNull ViewGroup parent, int viewType) {
TraceCompat.beginSection(TRACE_CREATE_VIEW_TAG);
final VH holder = onCreateViewHolder(parent, viewType);
holder.mItemViewType = viewType;
@@ -6622,7 +6657,7 @@ public class RecyclerView extends ViewGroup implements ScrollingView, NestedScro
*
* @see #onBindViewHolder(ViewHolder, int)
*/
- public final void bindViewHolder(VH holder, int position) {
+ public final void bindViewHolder(@NonNull VH holder, int position) {
holder.mPosition = position;
if (hasStableIds()) {
holder.mItemId = getItemId(position);
@@ -6719,7 +6754,7 @@ public class RecyclerView extends ViewGroup implements ScrollingView, NestedScro
*
* @param holder The ViewHolder for the view being recycled
*/
- public void onViewRecycled(VH holder) {
+ public void onViewRecycled(@NonNull VH holder) {
}
/**
@@ -6756,7 +6791,7 @@ public class RecyclerView extends ViewGroup implements ScrollingView, NestedScro
* RecyclerView will check the View's transient state again before giving a final decision.
* Default implementation returns false.
*/
- public boolean onFailedToRecycleView(VH holder) {
+ public boolean onFailedToRecycleView(@NonNull VH holder) {
return false;
}
@@ -6770,7 +6805,7 @@ public class RecyclerView extends ViewGroup implements ScrollingView, NestedScro
*
* @param holder Holder of the view being attached
*/
- public void onViewAttachedToWindow(VH holder) {
+ public void onViewAttachedToWindow(@NonNull VH holder) {
}
/**
@@ -6782,7 +6817,7 @@ public class RecyclerView extends ViewGroup implements ScrollingView, NestedScro
*
* @param holder Holder of the view being detached
*/
- public void onViewDetachedFromWindow(VH holder) {
+ public void onViewDetachedFromWindow(@NonNull VH holder) {
}
/**
@@ -6810,7 +6845,7 @@ public class RecyclerView extends ViewGroup implements ScrollingView, NestedScro
*
* @see #unregisterAdapterDataObserver(RecyclerView.AdapterDataObserver)
*/
- public void registerAdapterDataObserver(AdapterDataObserver observer) {
+ public void registerAdapterDataObserver(@NonNull AdapterDataObserver observer) {
mObservable.registerObserver(observer);
}
@@ -6824,7 +6859,7 @@ public class RecyclerView extends ViewGroup implements ScrollingView, NestedScro
*
* @see #registerAdapterDataObserver(RecyclerView.AdapterDataObserver)
*/
- public void unregisterAdapterDataObserver(AdapterDataObserver observer) {
+ public void unregisterAdapterDataObserver(@NonNull AdapterDataObserver observer) {
mObservable.unregisterObserver(observer);
}
@@ -6836,7 +6871,7 @@ public class RecyclerView extends ViewGroup implements ScrollingView, NestedScro
* @param recyclerView The RecyclerView instance which started observing this adapter.
* @see #onDetachedFromRecyclerView(RecyclerView)
*/
- public void onAttachedToRecyclerView(RecyclerView recyclerView) {
+ public void onAttachedToRecyclerView(@NonNull RecyclerView recyclerView) {
}
/**
@@ -6845,7 +6880,7 @@ public class RecyclerView extends ViewGroup implements ScrollingView, NestedScro
* @param recyclerView The RecyclerView instance which stopped observing this adapter.
* @see #onAttachedToRecyclerView(RecyclerView)
*/
- public void onDetachedFromRecyclerView(RecyclerView recyclerView) {
+ public void onDetachedFromRecyclerView(@NonNull RecyclerView recyclerView) {
}
/**
@@ -6921,7 +6956,7 @@ public class RecyclerView extends ViewGroup implements ScrollingView, NestedScro
*
* @see #notifyItemRangeChanged(int, int)
*/
- public final void notifyItemChanged(int position, Object payload) {
+ public final void notifyItemChanged(int position, @Nullable Object payload) {
mObservable.notifyItemRangeChanged(position, 1, payload);
}
@@ -6969,7 +7004,8 @@ public class RecyclerView extends ViewGroup implements ScrollingView, NestedScro
*
* @see #notifyItemChanged(int)
*/
- public final void notifyItemRangeChanged(int positionStart, int itemCount, Object payload) {
+ public final void notifyItemRangeChanged(int positionStart, int itemCount,
+ @Nullable Object payload) {
mObservable.notifyItemRangeChanged(positionStart, itemCount, payload);
}
@@ -10072,7 +10108,7 @@ public class RecyclerView extends ViewGroup implements ScrollingView, NestedScro
if (vScroll == 0 && hScroll == 0) {
return false;
}
- mRecyclerView.smoothScrollBy(hScroll, vScroll);
+ mRecyclerView.scrollBy(hScroll, vScroll);
return true;
}
@@ -10118,7 +10154,7 @@ public class RecyclerView extends ViewGroup implements ScrollingView, NestedScro
TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.RecyclerView,
defStyleAttr, defStyleRes);
properties.orientation = a.getInt(R.styleable.RecyclerView_android_orientation,
- VERTICAL);
+ DEFAULT_ORIENTATION);
properties.spanCount = a.getInt(R.styleable.RecyclerView_spanCount, 1);
properties.reverseLayout = a.getBoolean(R.styleable.RecyclerView_reverseLayout, false);
properties.stackFromEnd = a.getBoolean(R.styleable.RecyclerView_stackFromEnd, false);
@@ -10833,8 +10869,12 @@ public class RecyclerView extends ViewGroup implements ScrollingView, NestedScro
*/
private void onEnteredHiddenState(RecyclerView parent) {
// While the view item is in hidden state, make it invisible for the accessibility.
- mWasImportantForAccessibilityBeforeHidden =
- ViewCompat.getImportantForAccessibility(itemView);
+ if (mPendingAccessibilityState != PENDING_ACCESSIBILITY_STATE_NOT_SET) {
+ mWasImportantForAccessibilityBeforeHidden = mPendingAccessibilityState;
+ } else {
+ mWasImportantForAccessibilityBeforeHidden =
+ ViewCompat.getImportantForAccessibility(itemView);
+ }
parent.setChildImportantForAccessibilityInternal(this,
ViewCompat.IMPORTANT_FOR_ACCESSIBILITY_NO_HIDE_DESCENDANTS);
}
@@ -11193,7 +11233,7 @@ public class RecyclerView extends ViewGroup implements ScrollingView, NestedScro
// do nothing
}
- public void onItemRangeChanged(int positionStart, int itemCount, Object payload) {
+ public void onItemRangeChanged(int positionStart, int itemCount, @Nullable Object payload) {
// fallback to onItemRangeChanged(positionStart, itemCount) if app
// does not override this method.
onItemRangeChanged(positionStart, itemCount);
@@ -11670,7 +11710,8 @@ public class RecyclerView extends ViewGroup implements ScrollingView, NestedScro
notifyItemRangeChanged(positionStart, itemCount, null);
}
- public void notifyItemRangeChanged(int positionStart, int itemCount, Object payload) {
+ public void notifyItemRangeChanged(int positionStart, int itemCount,
+ @Nullable Object payload) {
// since onItemRangeChanged() is implemented by the app, it could do anything, including
// removing itself from {@link mObservers} - and that could cause problems if
// an iterator is used on the ArrayList {@link mObservers}.
@@ -12063,6 +12104,7 @@ public class RecyclerView extends ViewGroup implements ScrollingView, NestedScro
+ "mTargetPosition=" + mTargetPosition
+ ", mData=" + mData
+ ", mItemCount=" + mItemCount
+ + ", mIsMeasuring=" + mIsMeasuring
+ ", mPreviousLayoutItemCount=" + mPreviousLayoutItemCount
+ ", mDeletedInvisibleItemCountSincePreviousLayout="
+ mDeletedInvisibleItemCountSincePreviousLayout
diff --git a/android/support/v7/widget/StaggeredGridLayoutManager.java b/android/support/v7/widget/StaggeredGridLayoutManager.java
index f3ea0453..55fb14e8 100644
--- a/android/support/v7/widget/StaggeredGridLayoutManager.java
+++ b/android/support/v7/widget/StaggeredGridLayoutManager.java
@@ -59,9 +59,9 @@ public class StaggeredGridLayoutManager extends RecyclerView.LayoutManager imple
static final boolean DEBUG = false;
- public static final int HORIZONTAL = OrientationHelper.HORIZONTAL;
+ public static final int HORIZONTAL = RecyclerView.HORIZONTAL;
- public static final int VERTICAL = OrientationHelper.VERTICAL;
+ public static final int VERTICAL = RecyclerView.VERTICAL;
/**
* Does not do anything to hide gaps.
diff --git a/android/support/v7/widget/TooltipCompat.java b/android/support/v7/widget/TooltipCompat.java
index 470c3b2c..4a583da1 100644
--- a/android/support/v7/widget/TooltipCompat.java
+++ b/android/support/v7/widget/TooltipCompat.java
@@ -16,7 +16,6 @@
package android.support.v7.widget;
-import android.annotation.TargetApi;
import android.os.Build;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
@@ -28,34 +27,6 @@ import android.view.View;
*
*/
public class TooltipCompat {
- private interface ViewCompatImpl {
- void setTooltipText(@NonNull View view, @Nullable CharSequence tooltipText);
- }
-
- private static class BaseViewCompatImpl implements ViewCompatImpl {
- @Override
- public void setTooltipText(@NonNull View view, @Nullable CharSequence tooltipText) {
- TooltipCompatHandler.setTooltipText(view, tooltipText);
- }
- }
-
- @TargetApi(26)
- private static class Api26ViewCompatImpl implements ViewCompatImpl {
- @Override
- public void setTooltipText(@NonNull View view, @Nullable CharSequence tooltipText) {
- view.setTooltipText(tooltipText);
- }
- }
-
- private static final ViewCompatImpl IMPL;
- static {
- if (Build.VERSION.SDK_INT >= 26) {
- IMPL = new Api26ViewCompatImpl();
- } else {
- IMPL = new BaseViewCompatImpl();
- }
- }
-
/**
* Sets the tooltip text for the view.
* <p> Prior to API 26 this method sets or clears (when tooltip is null) the view's
@@ -66,7 +37,11 @@ public class TooltipCompat {
* @param tooltipText the tooltip text
*/
public static void setTooltipText(@NonNull View view, @Nullable CharSequence tooltipText) {
- IMPL.setTooltipText(view, tooltipText);
+ if (Build.VERSION.SDK_INT >= 26) {
+ view.setTooltipText(tooltipText);
+ } else {
+ TooltipCompatHandler.setTooltipText(view, tooltipText);
+ }
}
private TooltipCompat() {}
diff --git a/android/support/v7/widget/ViewInfoStoreTest.java b/android/support/v7/widget/ViewInfoStoreTest.java
index 4a224a41..c4163140 100644
--- a/android/support/v7/widget/ViewInfoStoreTest.java
+++ b/android/support/v7/widget/ViewInfoStoreTest.java
@@ -21,6 +21,13 @@ import static android.support.v7.widget.ViewInfoStore.InfoRecord.FLAG_DISAPPEARE
import static android.support.v7.widget.ViewInfoStore.InfoRecord.FLAG_POST;
import static android.support.v7.widget.ViewInfoStore.InfoRecord.FLAG_PRE;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertSame;
+import static org.junit.Assert.assertTrue;
+
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.test.filters.SmallTest;
@@ -29,8 +36,6 @@ import android.support.v7.widget.RecyclerView.ItemAnimator.ItemHolderInfo;
import android.support.v7.widget.RecyclerView.ViewHolder;
import android.view.View;
-import junit.framework.TestCase;
-
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -44,7 +49,7 @@ import java.util.Map;
@SuppressWarnings("ConstantConditions")
@RunWith(JUnit4.class)
@SmallTest
-public class ViewInfoStoreTest extends TestCase {
+public class ViewInfoStoreTest {
ViewInfoStore mStore;
LoggingProcessCallback mCallback;
@Before
diff --git a/android/support/v7/widget/helper/ItemTouchHelper.java b/android/support/v7/widget/helper/ItemTouchHelper.java
index aee48dfa..d2b6a202 100644
--- a/android/support/v7/widget/helper/ItemTouchHelper.java
+++ b/android/support/v7/widget/helper/ItemTouchHelper.java
@@ -457,7 +457,7 @@ public class ItemTouchHelper extends RecyclerView.ItemDecoration
destroyCallbacks();
}
mRecyclerView = recyclerView;
- if (mRecyclerView != null) {
+ if (recyclerView != null) {
final Resources resources = recyclerView.getResources();
mSwipeEscapeVelocity = resources
.getDimension(R.dimen.item_touch_helper_swipe_escape_velocity);