OLD | NEW |
(Empty) | |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 package org.chromium.chrome.browser.enhancedbookmarks; |
| 6 |
| 7 import android.content.Context; |
| 8 import android.util.AttributeSet; |
| 9 import android.widget.ScrollView; |
| 10 |
| 11 import com.google.android.apps.chrome.R; |
| 12 |
| 13 /** |
| 14 * Customized ScrollView used in EnhancedBookmarkDetailDialog. This ScrollView b
roadcasts scroll |
| 15 * change events and computes height compensation value used in detail dialog. |
| 16 */ |
| 17 public class EnhancedBookmarkDetailScrollView extends ScrollView { |
| 18 |
| 19 /** |
| 20 * Listener for scroll change event of the scrollView. |
| 21 */ |
| 22 public interface OnScrollListener { |
| 23 void onScrollChanged(int y, int oldY); |
| 24 } |
| 25 |
| 26 private int mHeightCompensation; |
| 27 // Maximum scroll amount by pixels in Y direction (height). |
| 28 private int mMaximumScrollY; |
| 29 private OnScrollListener mScrollListener; |
| 30 |
| 31 public EnhancedBookmarkDetailScrollView(Context context, AttributeSet attrs)
{ |
| 32 super(context, attrs); |
| 33 mHeightCompensation = |
| 34 getResources().getDimensionPixelSize(R.dimen.enhanced_bookmark_d
etail_image_height) |
| 35 - getResources().getDimensionPixelSize(R.dimen.toolbar_height_no
_shadow); |
| 36 } |
| 37 |
| 38 /** |
| 39 * Sets scroll listener that is called whenever scrollY changes. |
| 40 */ |
| 41 public void setOnScrollListener(OnScrollListener listener) { |
| 42 mScrollListener = listener; |
| 43 } |
| 44 |
| 45 /** |
| 46 * Gets height compensation, a fixed length that scroll view uses to extend
its length if |
| 47 * content is not long enough. |
| 48 */ |
| 49 public int getHeightCompensation() { |
| 50 return mHeightCompensation; |
| 51 } |
| 52 |
| 53 /** |
| 54 * Gets the maximum value scrollY can be. MaximumScrollY should never be les
s than |
| 55 * HeightCompensation. |
| 56 */ |
| 57 public int getMaximumScrollY() { |
| 58 return mMaximumScrollY; |
| 59 } |
| 60 |
| 61 @Override |
| 62 protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { |
| 63 super.onMeasure(widthMeasureSpec, heightMeasureSpec); |
| 64 int childHeight = getChildAt(0).getMeasuredHeight(); |
| 65 mMaximumScrollY = childHeight > getMeasuredHeight() ? childHeight - getM
easuredHeight() : 0; |
| 66 } |
| 67 |
| 68 @Override |
| 69 protected void onScrollChanged(int x, int y, int oldx, int oldy) { |
| 70 if (mScrollListener == null) return; |
| 71 mScrollListener.onScrollChanged(y, oldy); |
| 72 } |
| 73 } |
OLD | NEW |