Secrets of the Support Library (Droidcon NYC 2016)
The support library has become a necessity for the majority of Android developers. This talk will delve into some of its secrets, from bugs we’ve fixed, things we haven’t (yet), and how some of the features you’re using actually work back to API 9.
the UI Mode to reflect the new night mode config.uiMode = newNightMode | (config.uiMode & ~Configuration.UI_MODE_NIGHT_MASK); // Now update the configuration res.updateConfiguration(config, ...);
the UI Mode to reflect the new night mode config.uiMode = newNightMode | (config.uiMode & ~Configuration.UI_MODE_NIGHT_MASK); // Now update the configuration res.updateConfiguration(config, ...); Configuration.UI_MODE_NIGHT_YES
the UI Mode to reflect the new night mode config.uiMode = newNightMode | (config.uiMode & ~Configuration.UI_MODE_NIGHT_MASK); // Now update the configuration res.updateConfiguration(config, ...);
= ev.getY(); // 1010 // Calculate difference from last event int dy = mLastMotionY - y; // -10 for (int i = 0; i < getChildCount(); i++) { View child = getChildAt(i); child.offsetTopAndBottom(dy); }A
= ev.getY(); // 1010 // Calculate difference from last event int dy = mLastMotionY - y; // -10 for (int i = 0; i < getChildCount(); i++) { View child = getChildAt(i); child.offsetTopAndBottom(dy); }A // Finally update our recorded Y mLastMotionY = y;
How much we can scroll int scrollRange = ...; mScroller.fling(mScrollX, mScrollY, 0, velocityY, 0, 0, 0, scrollRange, 0, height / 2); ViewCompat.postInvalidateOnAnimation(this); }
How much we can scroll int scrollRange = ...; mScroller.fling(mScrollX, mScrollY, 0, velocityY, 0, 0, 0, scrollRange, 0, height / 2); ViewCompat.postInvalidateOnAnimation(this); }
How much we can scroll int scrollRange = ...; mScroller.fling(mScrollX, mScrollY, 0, velocityY, 0, 0, 0, scrollRange, 0, height / 2); ViewCompat.postInvalidateOnAnimation(this); } // Passed in from touch handling
How much we can scroll int scrollRange = ...; mScroller.fling(mScrollX, mScrollY, 0, velocityY, 0, 0, 0, scrollRange, 0, height / 2); ViewCompat.postInvalidateOnAnimation(this); }
How much we can scroll int scrollRange = ...; mScroller.fling(mScrollX, mScrollY, 0, velocityY, 0, 0, 0, scrollRange, 0, height / 2); ViewCompat.postInvalidateOnAnimation(this); }
How much we can scroll int scrollRange = ...; mScroller.fling(mScrollX, mScrollY, 0, velocityY, 0, 0, 0, scrollRange, 0, height / 2); ViewCompat.postInvalidateOnAnimation(this); } // Current scroll position
How much we can scroll int scrollRange = ...; mScroller.fling(mScrollX, mScrollY, 0, velocityY, 0, 0, 0, scrollRange, 0, height / 2); ViewCompat.postInvalidateOnAnimation(this); } // overscroll X, Y
How much we can scroll int scrollRange = ...; mScroller.fling(mScrollX, mScrollY, 0, velocityY, 0, 0, 0, scrollRange, 0, height / 2); ViewCompat.postInvalidateOnAnimation(this); }
// 1010 int dy = mLastMotionY - y; // -10 if (dispatchNestedPreScroll(0, dy, mScrollConsumed, ...)) { dy -= mScrollConsumed[1]; } // INSERT Move children by remaining dy // TODO call dispatchNestedScroll()
// 1010 int dy = mLastMotionY - y; // -10 if (dispatchNestedPreScroll(0, dy, mScrollConsumed, ...)) { dy -= mScrollConsumed[1]; } // INSERT Move children by remaining dy // TODO call dispatchNestedScroll() // -3 remember // dy = -7
// 1010 int dy = mLastMotionY - y; // -10 if (dispatchNestedPreScroll(0, dy, mScrollConsumed, ...)) { dy -= mScrollConsumed[1]; } // INSERT Move children by remaining dy // TODO call dispatchNestedScroll()
0, unconsumedY, ...) @Override void onNestedScroll(View target, int dxConsumed, int dyConsumed, int dxUnconsumed, int dyUnconsumed) { // Do something if you wish }
dx, int dy, int[] consumed); boolean dispatchNestedIndirectScroll(int dxConsumed, int dyConsumed, int dxUnconsumed, int dyUnconsumed); boolean hasNestedIndirectScrollingParent(); void stopNestedIndirectScroll(); Sending
View target, int axes); void onNestedIndirectPreScroll(View target, int dx, int dy, int[] consumed); void onNestedIndirectScroll(View target, int dxConsumed, int dyConsumed, int dxUnconsumed, int dyUnconsumed); void onStopNestedIndirectScroll(View child); Receiving