diff options
author | Maurice Lam <yukl@google.com> | 2015-05-11 17:31:16 +0000 |
---|---|---|
committer | Android (Google) Code Review <android-gerrit@google.com> | 2015-05-11 17:31:16 +0000 |
commit | bde9f28af53f6826c06e2afd8db5995f7f5ecff0 (patch) | |
tree | b10c8ddb5884dc13e28d788d0801764784ade97c | |
parent | e83f0555f1a0dc2671162a8a6e3876e591981de6 (diff) | |
parent | ae78742ac7987df09fa1b1301b54427beebdf4f6 (diff) | |
download | android_frameworks_opt_setupwizard-bde9f28af53f6826c06e2afd8db5995f7f5ecff0.tar.gz android_frameworks_opt_setupwizard-bde9f28af53f6826c06e2afd8db5995f7f5ecff0.tar.bz2 android_frameworks_opt_setupwizard-bde9f28af53f6826c06e2afd8db5995f7f5ecff0.zip |
Merge "[SetupWizardLib] Guard translationY with SDK version" into ub-setupwizard-alatar
-rw-r--r-- | library/main/src/com/android/setupwizardlib/view/StickyHeaderScrollView.java | 40 |
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 |