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..092878aedc35d418f2100c1e433799ed9febccd4 |
| --- /dev/null |
| +++ b/chrome/android/java/src/org/chromium/chrome/browser/signin/AccountSigninConfirmationView.java |
| @@ -0,0 +1,108 @@ |
| +// 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.CheckBox; |
| +import android.widget.LinearLayout; |
| +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 CheckBox mCheckBox; |
| + private boolean mCheckBoxVisibility; |
| + |
| + /** |
| + * Personalize service checkbox visibility observer. |
| + */ |
| + public interface Observer { |
| + /** |
| + * Visibility of the personalize service checkbox is changed. |
| + * @param isVisible if true, the checkbox is fully visible to user, otherwise it is partially |
| + * or completely invisible to user. |
|
newt (away)
2016/04/01 23:43:11
nit: capitalize first word of param description, a
gogerald1
2016/04/12 01:21:12
Done.
|
| + */ |
| + void onPersonalizeServiceCheckBoxVisibilityChanged(boolean isVisible); |
|
newt (away)
2016/04/01 23:43:11
We really only need to notify the observer once: t
gogerald1
2016/04/12 01:21:12
Done.
|
| + } |
| + |
| + public AccountSigninConfirmationView(Context context, AttributeSet attrs) { |
| + super(context, attrs); |
| + } |
| + |
| + @Override |
| + protected void onFinishInflate() { |
| + super.onFinishInflate(); |
| + |
| + mCheckBox = (CheckBox) findViewById(R.id.signin_personalize_service_checkbox); |
| + } |
| + |
| + @Override |
| + protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { |
| + // This assumes that view's layout_width is set to match_parent. |
| + assert MeasureSpec.getMode(widthMeasureSpec) == MeasureSpec.EXACTLY; |
|
newt (away)
2016/04/01 23:43:11
you should have a similar assert for the height
gogerald1
2016/04/12 01:21:12
Done.
|
| + |
| + 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); |
| + LinearLayout.LayoutParams params = (LinearLayout.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); |
| + |
| + checkAndNotifyPersonalizeCheckBoxVisibility(true); |
| + } |
| + |
| + @Override |
| + protected void onScrollChanged(int l, int t, int oldl, int oldt) { |
| + super.onScrollChanged(l, t, oldl, oldt); |
| + |
| + checkAndNotifyPersonalizeCheckBoxVisibility(false); |
| + } |
| + |
| + /** |
| + * Set the personalize service checkbox visibility changed observer. See {@link Observer} |
| + * |
| + * @param observer The observer. |
| + */ |
| + public void setObserver(Observer observer) { |
|
newt (away)
2016/04/01 23:43:11
This name should be clearer. Maybe "setScrolledToB
gogerald1
2016/04/12 01:21:13
Done.
|
| + mObserver = observer; |
| + } |
| + |
| + private void checkAndNotifyPersonalizeCheckBoxVisibility(boolean forceNotify) { |
| + if (mObserver == null) return; |
| + |
| + boolean isVisible = true; |
| + int distance = (getChildAt(getChildCount() - 1).getBottom() - (getHeight() + getScrollY())); |
| + int bottomPadding = findViewById(R.id.signin_confirmation_bottom_padding).getHeight(); |
| + if (distance > bottomPadding) isVisible = false; |
| + |
| + if (mCheckBoxVisibility == isVisible && !forceNotify) return; |
| + |
| + mObserver.onPersonalizeServiceCheckBoxVisibilityChanged(isVisible); |
| + mCheckBoxVisibility = isVisible; |
| + } |
| +} |