Commit 4df43b0c authored by Boris Sazonov's avatar Boris Sazonov Committed by Commit Bot

[Unity][Android] Add first part of SigninView

This CL adds SigninView to SigninFragmentBase and introduces the first
chunk of SigninView layout: SigninScrollView and a bottom button bar.
SigninScrollView implements observable ScrollView similarly to
AccountSigninConfirmationView, but without special onMeasure. Buttons
doesn't have android:text specified as SigninFragmentBase will set texts
for UI elements programmatically (similarly to
AccountSigninView.updateConsentText).
The rest of this layout will be added by subsequent CLs.

Bug: 814728
Change-Id: I3ac2c5fbdb41101a768abc70b3d1c3daa85fccb1
Reviewed-on: https://chromium-review.googlesource.com/962792Reviewed-by: default avatarBernhard Bauer <bauerb@chromium.org>
Commit-Queue: Boris Sazonov <bsazonov@chromium.org>
Cr-Commit-Position: refs/heads/master@{#543426}
parent 5d5a062f
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright 2018 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. -->
<org.chromium.chrome.browser.signin.SigninView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:chrome="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<org.chromium.chrome.browser.signin.SigninScrollView
android:id="@+id/signin_scroll_view"
android:layout_width="match_parent"
android:layout_height="0dp"
android:fadingEdgeLength="48dp"
android:layout_weight="1"
android:requiresFadingEdge="vertical"
android:scrollbars="none">
<!-- TODO(https://crbug.com/819142): Add the rest of the layout. -->
</org.chromium.chrome.browser.signin.SigninScrollView>
<LinearLayout
android:id="@+id/button_bar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:padding="16dp">
<!-- TODO(https://crbug.com/819142): Use textAppearance instead of text* attributes. -->
<Button
android:id="@+id/negative_button"
style="@style/ButtonCompatBorderless"
android:layout_width="wrap_content"
android:layout_height="36dp"
android:paddingEnd="@dimen/fre_button_padding"
android:paddingStart="@dimen/fre_button_padding"
android:textAllCaps="true"
android:textColor="@color/light_active_color"
android:textSize="14sp"
tools:text="@string/no_thanks"/>
<View
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_weight="1"
android:visibility="invisible"/>
<!-- TODO(https://crbug.com/819142): Specify WhiteBody as textAppearance. -->
<org.chromium.ui.widget.ButtonCompat
android:id="@+id/positive_button"
style="@style/WhiteBody"
android:layout_width="wrap_content"
android:layout_height="36dp"
android:paddingEnd="@dimen/fre_button_padding"
android:paddingStart="@dimen/fre_button_padding"
android:textAllCaps="true"
chrome:buttonColor="@color/light_active_color"
chrome:buttonRaised="false"
tools:text="@string/signin_accept_button"/>
<!-- TODO(https://crbug.com/819142): Use textAppearance instead of text* attributes. -->
<Button
android:id="@+id/more_button"
style="@style/ButtonCompatBorderless"
android:layout_width="wrap_content"
android:layout_height="36dp"
android:drawableEnd="@drawable/down_arrow"
android:drawablePadding="8dp"
android:textAllCaps="true"
android:textColor="@color/light_active_color"
android:textSize="@dimen/text_size_medium"
android:visibility="gone"
tools:text="@string/more"/>
<View
android:id="@+id/positive_button_end_padding"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_weight="1"
android:visibility="gone"/>
</LinearLayout>
</org.chromium.chrome.browser.signin.SigninView>
......@@ -8,7 +8,11 @@ import android.app.Fragment;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.annotation.StringRes;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import org.chromium.base.metrics.RecordUserAction;
import org.chromium.chrome.R;
/**
......@@ -22,6 +26,8 @@ public abstract class SigninFragmentBase extends Fragment {
private static final String ARGUMENT_ACCESS_POINT = "SigninFragmentBase.AccessPoint";
private @SigninAccessPoint int mSigninAccessPoint;
private SigninView mView;
private @StringRes int mCancelButtonTextId = R.string.cancel;
/**
......@@ -81,4 +87,38 @@ public abstract class SigninFragmentBase extends Fragment {
mCancelButtonTextId = R.string.no_thanks;
}
}
@Override
public View onCreateView(
LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
mView = (SigninView) inflater.inflate(R.layout.signin_view, container, false);
mView.getAcceptButton().setVisibility(View.GONE);
mView.getMoreButton().setVisibility(View.VISIBLE);
mView.getMoreButton().setOnClickListener(view -> {
mView.getScrollView().smoothScrollBy(0, mView.getScrollView().getHeight());
// TODO(https://crbug.com/821127): Revise this user action.
RecordUserAction.record("Signin_MoreButton_Shown");
});
mView.getScrollView().setScrolledToBottomObserver(this::showAcceptButton);
mView.getRefuseButton().setOnClickListener(view -> {
setButtonsEnabled(false);
onSigninRefused();
});
// TODO(https://crbug.com/814728): Set texts for UI elements
return mView;
}
private void showAcceptButton() {
mView.getAcceptButton().setVisibility(View.VISIBLE);
mView.getMoreButton().setVisibility(View.GONE);
mView.getScrollView().setScrolledToBottomObserver(null);
}
private void setButtonsEnabled(boolean enabled) {
mView.getAcceptButton().setEnabled(enabled);
mView.getRefuseButton().setEnabled(enabled);
}
}
// Copyright 2018 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.support.annotation.Nullable;
import android.util.AttributeSet;
import android.view.ViewTreeObserver;
import android.widget.ScrollView;
/**
* ScrollView without the top edge that also sends notification when it is scrolled to the bottom.
*/
public class SigninScrollView extends ScrollView {
private final ViewTreeObserver.OnGlobalLayoutListener mOnGlobalLayoutListener =
this::checkScrolledToBottom;
private final ViewTreeObserver.OnScrollChangedListener mOnScrollChangedListener =
this::checkScrolledToBottom;
private @Nullable Runnable mObserver;
public SigninScrollView(Context context, AttributeSet attrs) {
super(context, attrs);
}
@Override
protected float getTopFadingEdgeStrength() {
// Disable fading out effect at the top of this ScrollView.
return 0;
}
@Override
protected void onDetachedFromWindow() {
removeObserver();
super.onDetachedFromWindow();
}
private void checkScrolledToBottom() {
if (mObserver == null) return;
if (getChildCount() == 0) {
// The ScrollView is definitely scrolled to bottom if there are no children.
mObserver.run();
return;
}
if ((getHeight() + getScrollY()) < getChildAt(getChildCount() - 1).getBottom()) return;
mObserver.run();
}
/**
* Sets observer. Regardless of the passed value, notifications for the previous observer will
* be canceled.
* @param observer The Runnable to receive notification when SigninScrollView is scrolled to
* bottom, or null to clear the observer.
*/
public void setScrolledToBottomObserver(@Nullable Runnable observer) {
removeObserver();
if (observer == null) return;
mObserver = observer;
getViewTreeObserver().addOnGlobalLayoutListener(mOnGlobalLayoutListener);
getViewTreeObserver().addOnScrollChangedListener(mOnScrollChangedListener);
}
private void removeObserver() {
if (mObserver == null) return;
mObserver = null;
getViewTreeObserver().removeOnGlobalLayoutListener(mOnGlobalLayoutListener);
getViewTreeObserver().removeOnScrollChangedListener(mOnScrollChangedListener);
}
}
// Copyright 2018 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.support.annotation.Nullable;
import android.util.AttributeSet;
import android.view.View;
import android.widget.Button;
import android.widget.LinearLayout;
import org.chromium.chrome.R;
import org.chromium.ui.widget.ButtonCompat;
/** View that wraps signin screen and caches references to UI elements. */
public class SigninView extends LinearLayout {
private SigninScrollView mScrollView;
private ButtonCompat mAcceptButton;
private Button mRefuseButton;
private Button mMoreButton;
private View mAcceptButtonEndPadding;
public SigninView(Context context, @Nullable AttributeSet attrs) {
super(context, attrs);
}
@Override
protected void onFinishInflate() {
super.onFinishInflate();
mScrollView = (SigninScrollView) findViewById(R.id.signin_scroll_view);
mAcceptButton = (ButtonCompat) findViewById(R.id.positive_button);
mRefuseButton = (Button) findViewById(R.id.negative_button);
mMoreButton = (Button) findViewById(R.id.more_button);
mAcceptButtonEndPadding = findViewById(R.id.positive_button_end_padding);
}
public SigninScrollView getScrollView() {
return mScrollView;
}
public ButtonCompat getAcceptButton() {
return mAcceptButton;
}
public Button getRefuseButton() {
return mRefuseButton;
}
public Button getMoreButton() {
return mMoreButton;
}
public View getAcceptButtonEndPadding() {
return mAcceptButtonEndPadding;
}
}
......@@ -2296,7 +2296,13 @@ To obtain new licenses, connect to the internet and play your downloaded content
Waiting for Google Play Services to finish updating
</message>
<!-- New Signin Promos Strings -->
<!-- Strings for Streamlined Signin and Unified Consent. -->
<!-- TODO(https://crbug.com/814728): Make translatable when strings are approved. -->
<message name="IDS_SIGNIN_ACCEPT_BUTTON" desc="Text for the confirmation button in the sign-in screen. By clicking this button users signs in and turns on Sync and personalization. [CHAR-LIMIT=20]" translateable="false">
Yes, I'm in
</message>
<!-- Personalized Signin Promos Strings -->
<message name="IDS_SIGNIN_PROMO_DESCRIPTION_BOOKMARKS" desc="Description string for 'Continue as' signin promo shown in Bookmarks screen.">
To get your bookmarks on all your devices, sign in to Chrome.
</message>
......
......@@ -1120,6 +1120,8 @@ chrome_java_sources = [
"java/src/org/chromium/chrome/browser/signin/SigninManager.java",
"java/src/org/chromium/chrome/browser/signin/SigninPromoController.java",
"java/src/org/chromium/chrome/browser/signin/SigninPromoUtil.java",
"java/src/org/chromium/chrome/browser/signin/SigninScrollView.java",
"java/src/org/chromium/chrome/browser/signin/SigninView.java",
"java/src/org/chromium/chrome/browser/signin/SyncPromoView.java",
"java/src/org/chromium/chrome/browser/snackbar/BottomContainer.java",
"java/src/org/chromium/chrome/browser/snackbar/DataReductionPromoSnackbarController.java",
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment