Chromium Code Reviews| Index: chrome/android/java/src/org/chromium/chrome/browser/signin/AccountSigninConfirmationView.java |
| diff --git a/chrome/android/java/src/org/chromium/chrome/browser/signin/AccountSigninConfirmationView.java b/chrome/android/java/src/org/chromium/chrome/browser/signin/AccountSigninConfirmationView.java |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..1e7348824e713a8d79f30ea3c033757c6e5502af |
| --- /dev/null |
| +++ b/chrome/android/java/src/org/chromium/chrome/browser/signin/AccountSigninConfirmationView.java |
| @@ -0,0 +1,105 @@ |
| +// Copyright 2016 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +package org.chromium.chrome.browser.signin; |
| + |
| +import android.content.Context; |
| +import android.util.AttributeSet; |
| +import android.widget.LinearLayout; |
| +import android.widget.RelativeLayout; |
| +import android.widget.ScrollView; |
| + |
| +import org.chromium.chrome.R; |
| + |
| +/** |
| +* This view allows the user to confirm signed in account, sync, and service personalization. |
| +*/ |
| +public class AccountSigninConfirmationView extends ScrollView { |
| + private Observer mObserver; |
| + private boolean mScrolledToBottom = false; |
| + |
| + /** |
| + * Scrolled to bottom observer. |
| + */ |
| + public interface Observer { |
| + /** |
| + * On scrolled to bottom. |
| + * @param scrolledToBottom If true, this view has been scrolled to bottom. We consider the |
| + * view has been scrolled to bottom if the last embedded view has |
| + * been fully visible to user. |
| + */ |
| + void onScrolledToBottom(boolean scrolledToBottom); |
|
newt (away)
2016/04/13 18:13:30
I'd remove the boolean parameter altogether, since
gogerald1
2016/04/13 21:33:13
Done.
|
| + } |
| + |
| + public AccountSigninConfirmationView(Context context, AttributeSet attrs) { |
| + super(context, attrs); |
| + } |
| + |
| + @Override |
| + protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { |
| + // This assumes that view's layout_width and layout_height are set to match_parent. |
| + assert MeasureSpec.getMode(widthMeasureSpec) == MeasureSpec.EXACTLY; |
| + assert MeasureSpec.getMode(heightMeasureSpec) == MeasureSpec.EXACTLY; |
| + |
| + int width = MeasureSpec.getSize(widthMeasureSpec); |
| + int height = MeasureSpec.getSize(heightMeasureSpec); |
| + |
| + // Sets aspect ratio of the head to 16:9. |
| + if (height > width) { |
| + LinearLayout layout = (LinearLayout) findViewById(R.id.signin_confirmation_head); |
| + RelativeLayout.LayoutParams params = |
| + (RelativeLayout.LayoutParams) layout.getLayoutParams(); |
| + params.height = width * 9 / 16; |
| + params.width = LayoutParams.MATCH_PARENT; |
| + layout.setLayoutParams(params); |
| + } |
| + |
| + super.onMeasure(widthMeasureSpec, heightMeasureSpec); |
| + } |
| + |
| + @Override |
| + protected float getTopFadingEdgeStrength() { |
| + // Disable fading out effect at the top of this ScrollView. |
| + return 0; |
| + } |
| + |
| + @Override |
| + protected void onLayout(boolean changed, int left, int top, int right, int bottom) { |
| + super.onLayout(changed, left, top, right, bottom); |
| + |
| + checkAndNotifyScrolledToBottom(true); |
| + } |
| + |
| + @Override |
| + protected void onScrollChanged(int l, int t, int oldl, int oldt) { |
| + super.onScrollChanged(l, t, oldl, oldt); |
| + |
| + checkAndNotifyScrolledToBottom(false); |
| + } |
| + |
| + /** |
| + * Sets scrolled to bottom observer. See {@link Observer} |
| + * |
| + * @param observer The observer. |
| + */ |
| + public void setScrolledToBottomObserver(Observer observer) { |
| + mObserver = observer; |
| + } |
| + |
| + private void checkAndNotifyScrolledToBottom(boolean forceNotify) { |
|
newt (away)
2016/04/13 18:13:30
maybe call this "notifyIfScrolledToBottom()"
gogerald1
2016/04/13 21:33:13
Done.
|
| + if (mObserver == null) return; |
| + |
| + if (!forceNotify && mScrolledToBottom) return; |
| + |
| + boolean isBottomVisible = true; |
|
newt (away)
2016/04/13 18:13:30
We don't need the isBottomVisible variable anymore
gogerald1
2016/04/13 21:33:13
Done.
|
| + int distance = (getChildAt(getChildCount() - 1).getBottom() - (getHeight() + getScrollY())); |
| + int bottomPadding = findViewById(R.id.signin_confirmation_bottom_padding).getHeight(); |
| + if (distance > bottomPadding) isBottomVisible = false; |
| + |
| + if (mScrolledToBottom == isBottomVisible && !forceNotify) return; |
| + |
| + mObserver.onScrolledToBottom(isBottomVisible); |
| + mScrolledToBottom = isBottomVisible; |
| + } |
| +} |