Commit a7f353b6 authored by Boris Sazonov's avatar Boris Sazonov Committed by Commit Bot

[Unity][Android] Add account picker to sign-in screen

This CL adds account picker to the streamlined sign-in screen. It will
be wired up by subsequent CLs. RelativeLayout is used to avoid using
nested LinearLayouts and minimize the depth of the layout. Strings in
grd file are currently marked as not translateable as they haven't been
confirmed by the UI team yet.
This CL also adds initialization for ConsentTextTracker in
SigninFragmentBase.

Bug: 814728
Change-Id: I60ae3841998d5dd9c13d35583915e7fe443d3b31
Reviewed-on: https://chromium-review.googlesource.com/966902
Commit-Queue: Boris Sazonov <bsazonov@chromium.org>
Reviewed-by: default avatarBernhard Bauer <bauerb@chromium.org>
Cr-Commit-Position: refs/heads/master@{#544384}
parent a3cc953f
<?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. -->
<shape
xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<solid android:color="@color/modern_light_grey"/>
<corners android:radius="8dp"/>
</shape>
...@@ -17,7 +17,82 @@ ...@@ -17,7 +17,82 @@
android:layout_weight="1" android:layout_weight="1"
android:requiresFadingEdge="vertical" android:requiresFadingEdge="vertical"
android:scrollbars="none"> android:scrollbars="none">
<!-- TODO(https://crbug.com/819142): Add the rest of the layout. --> <RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<!-- TODO(https://crbug.com/814728): Add asset for this image when UI is confirmed. -->
<ImageView
android:id="@+id/signin_header_image"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:adjustViewBounds="true"
android:contentDescription="@null"
android:layout_alignParentTop="true"
android:scaleType="fitCenter"/>
<TextView
android:id="@+id/signin_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="@dimen/signin_margin_start"
android:layout_marginEnd="@dimen/signin_margin_end"
android:layout_below="@id/signin_header_image"
android:layout_marginTop="26dp"
android:textAppearance="@style/BlackHeadline1"
tools:text="@string/signin_title"/>
<RelativeLayout
android:id="@+id/signin_account_picker"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="@dimen/signin_margin_start"
android:layout_marginEnd="@dimen/signin_margin_end"
android:background="@drawable/account_picker_background"
android:layout_below="@id/signin_title"
android:layout_marginTop="26dp"
android:orientation="horizontal"
android:paddingBottom="12dp"
android:paddingEnd="12dp"
android:paddingStart="16dp"
android:paddingTop="12dp">
<ImageView
android:id="@+id/account_image"
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_marginEnd="16dp"
android:contentDescription="@null"
android:layout_alignParentStart="true"
chrome:srcCompat="@drawable/logo_avatar_anonymous"/>
<TextView
android:id="@+id/account_name"
android:layout_width="match_parent"
android:layout_height="20dp"
android:gravity="center_vertical"
android:layout_toEndOf="@id/account_image"
android:layout_toStartOf="@id/expand_icon"
android:textAppearance="@style/BlackBodyDefault"
tools:text="John Doe"/>
<TextView
android:id="@+id/account_email"
android:layout_width="match_parent"
android:layout_height="20dp"
android:gravity="center_vertical"
android:layout_below="@id/account_name"
android:layout_toEndOf="@id/account_image"
android:layout_toStartOf="@id/expand_icon"
android:textAppearance="@style/BlackCaption"
tools:text="john.doe@example.com"/>
<ImageView
android:id="@+id/expand_icon"
android:layout_width="24dp"
android:layout_height="24dp"
android:layout_marginStart="16dp"
android:alpha="0.54"
android:contentDescription="@null"
android:layout_alignParentEnd="true"
android:layout_centerVertical="true"
android:src="@drawable/ic_expand_more_black_24dp"/>
</RelativeLayout>
<!-- TODO(https://crbug.com/819142): Add the rest of the layout. -->
</RelativeLayout>
</org.chromium.chrome.browser.signin.SigninScrollView> </org.chromium.chrome.browser.signin.SigninScrollView>
<LinearLayout <LinearLayout
android:id="@+id/button_bar" android:id="@+id/button_bar"
......
...@@ -177,6 +177,9 @@ ...@@ -177,6 +177,9 @@
<dimen name="signin_chooser_padding">16dp</dimen> <dimen name="signin_chooser_padding">16dp</dimen>
<dimen name="signin_screen_top_padding">50dp</dimen> <dimen name="signin_screen_top_padding">50dp</dimen>
<dimen name="signin_margin_start">16dp</dimen>
<dimen name="signin_margin_end">16dp</dimen>
<!-- Signin promo dimensions --> <!-- Signin promo dimensions -->
<dimen name="signin_promo_account_image_size">48dp</dimen> <dimen name="signin_promo_account_image_size">48dp</dimen>
<dimen name="signin_promo_cold_state_image_size">24dp</dimen> <dimen name="signin_promo_cold_state_image_size">24dp</dimen>
......
...@@ -4,10 +4,13 @@ ...@@ -4,10 +4,13 @@
package org.chromium.chrome.browser.signin; package org.chromium.chrome.browser.signin;
import android.annotation.SuppressLint;
import android.app.Fragment; import android.app.Fragment;
import android.graphics.drawable.Drawable;
import android.os.Bundle; import android.os.Bundle;
import android.support.annotation.Nullable; import android.support.annotation.Nullable;
import android.support.annotation.StringRes; import android.support.annotation.StringRes;
import android.support.v7.content.res.AppCompatResources;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
...@@ -72,6 +75,8 @@ public abstract class SigninFragmentBase extends Fragment { ...@@ -72,6 +75,8 @@ public abstract class SigninFragmentBase extends Fragment {
Bundle arguments = getSigninArguments(); Bundle arguments = getSigninArguments();
initAccessPoint(arguments.getInt(ARGUMENT_ACCESS_POINT, -1)); initAccessPoint(arguments.getInt(ARGUMENT_ACCESS_POINT, -1));
mConsentTextTracker = new ConsentTextTracker(getResources());
} }
private void initAccessPoint(@SigninAccessPoint int accessPoint) { private void initAccessPoint(@SigninAccessPoint int accessPoint) {
...@@ -95,6 +100,7 @@ public abstract class SigninFragmentBase extends Fragment { ...@@ -95,6 +100,7 @@ public abstract class SigninFragmentBase extends Fragment {
public View onCreateView( public View onCreateView(
LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
mView = (SigninView) inflater.inflate(R.layout.signin_view, container, false); mView = (SigninView) inflater.inflate(R.layout.signin_view, container, false);
mView.getAcceptButton().setVisibility(View.GONE); mView.getAcceptButton().setVisibility(View.GONE);
mView.getMoreButton().setVisibility(View.VISIBLE); mView.getMoreButton().setVisibility(View.VISIBLE);
mView.getMoreButton().setOnClickListener(view -> { mView.getMoreButton().setOnClickListener(view -> {
...@@ -110,16 +116,29 @@ public abstract class SigninFragmentBase extends Fragment { ...@@ -110,16 +116,29 @@ public abstract class SigninFragmentBase extends Fragment {
}); });
updateConsentText(); updateConsentText();
updateProfileData();
return mView; return mView;
} }
private void updateConsentText() { private void updateConsentText() {
mConsentTextTracker.setText(mView.getTitleView(), R.string.signin_title);
mConsentTextTracker.setText(mView.getRefuseButton(), mCancelButtonTextId); mConsentTextTracker.setText(mView.getRefuseButton(), mCancelButtonTextId);
mConsentTextTracker.setText(mView.getAcceptButton(), R.string.signin_accept_button); mConsentTextTracker.setText(mView.getAcceptButton(), R.string.signin_accept_button);
mConsentTextTracker.setText(mView.getMoreButton(), R.string.more); mConsentTextTracker.setText(mView.getMoreButton(), R.string.more);
} }
// TODO(https://crbug.com/814728): Get real profile data and remove SuppressLint.
@SuppressLint("SetTextI18n")
private void updateProfileData() {
Drawable avatar =
AppCompatResources.getDrawable(getActivity(), R.drawable.logo_avatar_anonymous);
mView.getAccountImageView().setImageDrawable(avatar);
mConsentTextTracker.setTextNonRecordable(mView.getAccountNameView(), "John Doe");
mConsentTextTracker.setTextNonRecordable(
mView.getAccountEmailView(), "john.doe@example.com");
}
private void showAcceptButton() { private void showAcceptButton() {
mView.getAcceptButton().setVisibility(View.VISIBLE); mView.getAcceptButton().setVisibility(View.VISIBLE);
mView.getMoreButton().setVisibility(View.GONE); mView.getMoreButton().setVisibility(View.GONE);
......
...@@ -9,7 +9,9 @@ import android.support.annotation.Nullable; ...@@ -9,7 +9,9 @@ import android.support.annotation.Nullable;
import android.util.AttributeSet; import android.util.AttributeSet;
import android.view.View; import android.view.View;
import android.widget.Button; import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout; import android.widget.LinearLayout;
import android.widget.TextView;
import org.chromium.chrome.R; import org.chromium.chrome.R;
import org.chromium.ui.widget.ButtonCompat; import org.chromium.ui.widget.ButtonCompat;
...@@ -17,6 +19,10 @@ import org.chromium.ui.widget.ButtonCompat; ...@@ -17,6 +19,10 @@ import org.chromium.ui.widget.ButtonCompat;
/** View that wraps signin screen and caches references to UI elements. */ /** View that wraps signin screen and caches references to UI elements. */
public class SigninView extends LinearLayout { public class SigninView extends LinearLayout {
private SigninScrollView mScrollView; private SigninScrollView mScrollView;
private TextView mTitle;
private ImageView mAccountImage;
private TextView mAccountName;
private TextView mAccountEmail;
private ButtonCompat mAcceptButton; private ButtonCompat mAcceptButton;
private Button mRefuseButton; private Button mRefuseButton;
private Button mMoreButton; private Button mMoreButton;
...@@ -31,6 +37,10 @@ public class SigninView extends LinearLayout { ...@@ -31,6 +37,10 @@ public class SigninView extends LinearLayout {
super.onFinishInflate(); super.onFinishInflate();
mScrollView = (SigninScrollView) findViewById(R.id.signin_scroll_view); mScrollView = (SigninScrollView) findViewById(R.id.signin_scroll_view);
mTitle = (TextView) findViewById(R.id.signin_title);
mAccountImage = (ImageView) findViewById(R.id.account_image);
mAccountName = (TextView) findViewById(R.id.account_name);
mAccountEmail = (TextView) findViewById(R.id.account_email);
mAcceptButton = (ButtonCompat) findViewById(R.id.positive_button); mAcceptButton = (ButtonCompat) findViewById(R.id.positive_button);
mRefuseButton = (Button) findViewById(R.id.negative_button); mRefuseButton = (Button) findViewById(R.id.negative_button);
mMoreButton = (Button) findViewById(R.id.more_button); mMoreButton = (Button) findViewById(R.id.more_button);
...@@ -41,6 +51,22 @@ public class SigninView extends LinearLayout { ...@@ -41,6 +51,22 @@ public class SigninView extends LinearLayout {
return mScrollView; return mScrollView;
} }
public TextView getTitleView() {
return mTitle;
}
public ImageView getAccountImageView() {
return mAccountImage;
}
public TextView getAccountNameView() {
return mAccountName;
}
public TextView getAccountEmailView() {
return mAccountEmail;
}
public ButtonCompat getAcceptButton() { public ButtonCompat getAcceptButton() {
return mAcceptButton; return mAcceptButton;
} }
......
...@@ -2298,6 +2298,9 @@ To obtain new licenses, connect to the internet and play your downloaded content ...@@ -2298,6 +2298,9 @@ To obtain new licenses, connect to the internet and play your downloaded content
<!-- Strings for Streamlined Signin and Unified Consent. --> <!-- Strings for Streamlined Signin and Unified Consent. -->
<!-- TODO(https://crbug.com/814728): Make translatable when strings are approved. --> <!-- TODO(https://crbug.com/814728): Make translatable when strings are approved. -->
<message name="IDS_SIGNIN_TITLE" desc="Title for the screen that asks users to sign-in and turn on Sync and personalization. [CHAR-LIMIT=27]" translateable="false">
Get even more from Chrome
</message>
<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"> <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 Yes, I'm in
</message> </message>
......
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