summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--library/main/src/com/android/setupwizardlib/view/StickyHeaderScrollView.java40
1 files changed, 24 insertions, 16 deletions
diff --git a/library/main/src/com/android/setupwizardlib/view/StickyHeaderScrollView.java b/library/main/src/com/android/setupwizardlib/view/StickyHeaderScrollView.java
index 97c682d..5214798 100644
--- a/library/main/src/com/android/setupwizardlib/view/StickyHeaderScrollView.java
+++ b/library/main/src/com/android/setupwizardlib/view/StickyHeaderScrollView.java
@@ -18,8 +18,6 @@ package com.android.setupwizardlib.view;
import android.annotation.TargetApi;
import android.content.Context;
-import android.graphics.Canvas;
-import android.graphics.RectF;
import android.os.Build;
import android.util.AttributeSet;
import android.view.View;
@@ -37,6 +35,7 @@ import android.view.WindowInsets;
* The arrow (->) represents parent/child relationship and must be immediate child.
* 2. If fitsSystemWindows is true, then this will offset the sticking position by the height of
* the system decorations at the top of the screen.
+ * 3. For versions before Honeycomb, this will behave like a regular ScrollView.
*
* @see StickyHeaderListView
*/
@@ -64,6 +63,7 @@ public class StickyHeaderScrollView extends BottomScrollView {
if (mSticky == null) {
updateStickyView();
}
+ updateStickyHeaderPosition();
}
public void updateStickyView() {
@@ -71,23 +71,31 @@ public class StickyHeaderScrollView extends BottomScrollView {
mStickyContainer = findViewWithTag("stickyContainer");
}
+ private void updateStickyHeaderPosition() {
+ // Note: for pre-Honeycomb the header will not be moved, so this ScrollView essentially
+ // behaves like a normal BottomScrollView.
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
+ if (mSticky != null) {
+ // The view to draw when sticking to the top
+ final View drawTarget = mStickyContainer != null ? mStickyContainer : mSticky;
+ // The offset to draw the view at when sticky
+ final int drawOffset = mStickyContainer != null ? mSticky.getTop() : 0;
+ // Position of the draw target, relative to the outside of the scrollView
+ final int drawTop = drawTarget.getTop() - getScrollY();
+ if (drawTop + drawOffset < mStatusBarInset || !drawTarget.isShown()) {
+ // ScrollView translates the whole canvas so we have to compensate for that
+ drawTarget.setTranslationY(getScrollY() - drawOffset);
+ } else {
+ drawTarget.setTranslationY(0);
+ }
+ }
+ }
+ }
+
@Override
protected void onScrollChanged(int l, int t, int oldl, int oldt) {
super.onScrollChanged(l, t, oldl, oldt);
- if (mSticky != null) {
- // The view to draw when sticking to the top
- final View drawTarget = mStickyContainer != null ? mStickyContainer : mSticky;
- // The offset to draw the view at when sticky
- final int drawOffset = mStickyContainer != null ? mSticky.getTop() : 0;
- // Position of the draw target, relative to the outside of the scrollView
- final int drawTop = drawTarget.getTop() - getScrollY();
- if (drawTop + drawOffset < mStatusBarInset || !drawTarget.isShown()) {
- // ScrollView translates the whole canvas so we have to compensate for that
- drawTarget.setTranslationY(getScrollY() - drawOffset);
- } else {
- drawTarget.setTranslationY(0);
- }
- }
+ updateStickyHeaderPosition();
}
@Override