Commit 32b18060 authored by Alice Wang's avatar Alice Wang Committed by Commit Bot

[Android][Signin][UI] Change account picker dialog add account icon

This CL changes add account icon in account picker dialog to mobile
identity consistency project style.

Screenshots: https://crbug.com/1044614#c1
Bug: 1044614
Change-Id: I4684c23a1cedee2459b223c7ec10e14be2411324
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1995165
Commit-Queue: Alice Wang <aliceywang@chromium.org>
Reviewed-by: default avatarBoris Sazonov <bsazonov@chromium.org>
Reviewed-by: default avatarTanmoy Mollik <triploblastic@chromium.org>
Cr-Commit-Position: refs/heads/master@{#742092}
parent 9541d95b
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright 2020 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. -->
<vector xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
tools:targetApi="21"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24">
<path
android:fillColor="@color/default_icon_color"
android:pathData="M9,12c2.21,0 4,-1.79 4,-4s-1.79,-4 -4,-4 -4,1.79 -4,4 1.79,4 4,4zM9,6c1.1,0 2,0.9 2,2s-0.9,2 -2,2 -2,-0.9 -2,-2 0.9,-2 2,-2zM9,13c-2.67,0 -8,1.34 -8,4v3h16v-3c0,-2.66 -5.33,-4 -8,-4zM15,18L3,18v-0.99C3.2,16.29 6.3,15 9,15s5.8,1.29 6,2v1zM18,14v-3h-3L15,9h3L18,6h2v3h3v2h-3v3h-2z"/>
</vector>
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright 2018 The Chromium Authors. All rights reserved.
<!-- Copyright 2020 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. -->
<TextView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:drawablePadding="16dp"
android:drawablePadding="22dp"
android:paddingStart="18dp"
android:paddingEnd="8dp"
android:paddingTop="8dp"
android:paddingBottom="8dp"
android:gravity="center_vertical"
android:padding="8dp"
android:text="@string/signin_add_account"
android:textAppearance="@style/TextAppearance.TextMedium.Primary" />
android:textAppearance="@style/TextAppearance.TextLarge.Primary" />
<?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. -->
<TextView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:drawablePadding="16dp"
android:gravity="center_vertical"
android:padding="8dp"
android:text="@string/signin_add_account"
android:textAppearance="@style/TextAppearance.TextMedium.Primary" />
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright 2018 The Chromium Authors. All rights reserved.
<!-- Copyright 2020 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. -->
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
......@@ -26,17 +26,15 @@
android:id="@+id/account_text_primary"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:minHeight="20dp"
android:textAppearance="@style/TextAppearance.TextMedium.Primary"
android:gravity="top"
android:textAppearance="@style/TextAppearance.TextLarge.Primary"
tools:text="John Doe"/>
<TextView
android:id="@+id/account_text_secondary"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:minHeight="20dp"
android:textAppearance="@style/TextAppearance.TextSmall.Secondary"
android:gravity="top"
android:textAppearance="@style/TextAppearance.TextMedium.Secondary"
tools:text="john.doe@example.com"/>
</LinearLayout>
<ImageView
......
<?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. -->
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:orientation="horizontal"
android:padding="8dp">
<ImageView
android:id="@+id/account_image"
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_marginEnd="16dp"
tools:ignore="ContentDescription"
tools:src="@drawable/logo_avatar_anonymous"/>
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="vertical">
<TextView
android:id="@+id/account_text_primary"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:minHeight="20dp"
android:textAppearance="@style/TextAppearance.TextMedium.Primary"
tools:text="John Doe"/>
<TextView
android:id="@+id/account_text_secondary"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:minHeight="20dp"
android:textAppearance="@style/TextAppearance.TextSmall.Secondary"
tools:text="john.doe@example.com"/>
</LinearLayout>
<ImageView
android:id="@+id/account_selection_mark"
android:layout_width="24dp"
android:layout_height="24dp"
android:layout_marginStart="16dp"
tools:ignore="ContentDescription"
android:src="@drawable/ic_check_googblue_24dp"
app:tint="@color/default_icon_color_blue" />
</LinearLayout>
......@@ -25,6 +25,7 @@ import androidx.annotation.Nullable;
import org.chromium.base.Log;
import org.chromium.chrome.R;
import org.chromium.chrome.browser.flags.ChromeFeatureList;
import org.chromium.components.signin.AccountManagerDelegateException;
import org.chromium.components.signin.AccountManagerFacade;
import org.chromium.components.signin.AccountsChangeObserver;
......@@ -112,20 +113,10 @@ public class AccountPickerDialogFragment extends DialogFragment {
@Override
public ViewHolder onCreateViewHolder(ViewGroup viewGroup, @ViewType int viewType) {
LayoutInflater inflater = LayoutInflater.from(viewGroup.getContext());
View view = inflateRowView(viewGroup, viewType);
if (viewType == ViewType.NEW_ACCOUNT) {
TextView view = (TextView) inflater.inflate(
R.layout.account_picker_new_account_row, viewGroup, false);
// Set the vector drawable programmatically because app:drawableStartCompat is only
// available after AndroidX appcompat library.
// TODO(https://crbug.com/948367): Use app:drawableStartCompat.
view.setCompoundDrawablesRelativeWithIntrinsicBounds(
AppCompatResources.getDrawable(
viewGroup.getContext(), R.drawable.ic_add_circle_40dp),
null, null, null);
return new ViewHolder(view);
}
View view = inflater.inflate(R.layout.account_picker_row, viewGroup, false);
ImageView accountImage = view.findViewById(R.id.account_image);
TextView accountTextPrimary = view.findViewById(R.id.account_text_primary);
TextView accountTextSecondary = view.findViewById(R.id.account_text_secondary);
......@@ -134,6 +125,39 @@ public class AccountPickerDialogFragment extends DialogFragment {
view, accountImage, accountTextPrimary, accountTextSecondary, selectionMark);
}
private View inflateRowView(ViewGroup viewGroup, @ViewType int viewType) {
LayoutInflater inflater = LayoutInflater.from(viewGroup.getContext());
if (ChromeFeatureList.isEnabled(ChromeFeatureList.MOBILE_IDENTITY_CONSISTENCY)) {
if (viewType == ViewType.NEW_ACCOUNT) {
TextView view = (TextView) inflater.inflate(
R.layout.account_picker_new_account_row, viewGroup, false);
view.setCompoundDrawablesRelativeWithIntrinsicBounds(
AppCompatResources.getDrawable(
viewGroup.getContext(), R.drawable.ic_person_add_24dp),
null, null, null);
return view;
} else {
return inflater.inflate(R.layout.account_picker_row, viewGroup, false);
}
} else {
if (viewType == ViewType.NEW_ACCOUNT) {
TextView view = (TextView) inflater.inflate(
R.layout.account_picker_new_account_row_legacy, viewGroup, false);
// Set the vector drawable programmatically because app:drawableStartCompat is
// only available after AndroidX appcompat library.
// TODO(https://crbug.com/948367): Use app:drawableStartCompat.
view.setCompoundDrawablesRelativeWithIntrinsicBounds(
AppCompatResources.getDrawable(
viewGroup.getContext(), R.drawable.ic_add_circle_40dp),
null, null, null);
return view;
} else {
return inflater.inflate(R.layout.account_picker_row_legacy, viewGroup, false);
}
}
}
@Override
public void onBindViewHolder(ViewHolder holder, int position) {
switch (holder.getItemViewType()) {
......
......@@ -14,8 +14,10 @@ import static org.mockito.Mockito.verify;
import static org.mockito.MockitoAnnotations.initMocks;
import android.accounts.Account;
import android.support.test.InstrumentationRegistry;
import android.support.v4.app.FragmentManager;
import androidx.test.filters.LargeTest;
import androidx.test.filters.MediumTest;
import org.junit.Before;
......@@ -25,9 +27,13 @@ import org.junit.runner.RunWith;
import org.mockito.Spy;
import org.chromium.base.test.util.CommandLineFlags;
import org.chromium.base.test.util.Feature;
import org.chromium.chrome.R;
import org.chromium.chrome.browser.ChromeSwitches;
import org.chromium.chrome.browser.flags.ChromeFeatureList;
import org.chromium.chrome.test.ChromeJUnit4ClassRunner;
import org.chromium.chrome.test.util.ChromeRenderTestRule;
import org.chromium.chrome.test.util.browser.Features;
import org.chromium.components.signin.AccountManagerFacade;
import org.chromium.components.signin.ProfileDataSource;
import org.chromium.components.signin.test.util.AccountHolder;
......@@ -35,16 +41,30 @@ import org.chromium.components.signin.test.util.AccountManagerTestRule;
import org.chromium.components.signin.test.util.FakeAccountManagerDelegate;
import org.chromium.ui.test.util.DummyUiActivityTestCase;
import java.io.IOException;
/**
* Render tests for {@link AccountPickerDialogFragment}.
* TODO(https://crbug.com/1032488):
* Use FragmentScenario to test this fragment once we start using fragment from androidx.
*/
@RunWith(ChromeJUnit4ClassRunner.class)
@CommandLineFlags.Add({ChromeSwitches.DISABLE_FIRST_RUN_EXPERIENCE})
public class AccountPickerDialogFragmentTest extends DummyUiActivityTestCase {
@CommandLineFlags
.Add({ChromeSwitches.DISABLE_FIRST_RUN_EXPERIENCE})
@Features.DisableFeatures({ChromeFeatureList.MOBILE_IDENTITY_CONSISTENCY})
public class AccountPickerDialogFragmentTest extends DummyUiActivityTestCase {
@Rule
public final Features.JUnitProcessor mProcessor = new Features.JUnitProcessor();
@Rule
public final ChromeRenderTestRule mRenderTestRule = new ChromeRenderTestRule();
@Rule
public final AccountManagerTestRule mAccountManagerTestRule =
new AccountManagerTestRule(FakeAccountManagerDelegate.ENABLE_PROFILE_DATA_SOURCE);
@Spy
private DummyAccountPickerTargetFragment mTargetFragmentMock =
private DummyAccountPickerTargetFragment mTargetFragment =
new DummyAccountPickerTargetFragment();
private final String mFullName1 = "Test Account1";
......@@ -53,9 +73,7 @@ public class AccountPickerDialogFragmentTest extends DummyUiActivityTestCase {
private final String mAccountName2 = "test.account2@gmail.com";
@Rule
public final AccountManagerTestRule mAccountManagerTestRule =
new AccountManagerTestRule(FakeAccountManagerDelegate.ENABLE_PROFILE_DATA_SOURCE);
private AccountPickerDialogFragment mDialog;
@Before
public void setUp() {
......@@ -63,10 +81,10 @@ public class AccountPickerDialogFragmentTest extends DummyUiActivityTestCase {
addAccount(mAccountName1, mFullName1);
addAccount(mAccountName2, "");
FragmentManager fragmentManager = getActivity().getSupportFragmentManager();
fragmentManager.beginTransaction().add(mTargetFragmentMock, "Parent").commit();
AccountPickerDialogFragment dialog = AccountPickerDialogFragment.create(mAccountName1);
dialog.setTargetFragment(mTargetFragmentMock, 0);
dialog.show(fragmentManager, "");
fragmentManager.beginTransaction().add(mTargetFragment, "target").commit();
mDialog = AccountPickerDialogFragment.create(mAccountName1);
mDialog.setTargetFragment(mTargetFragment, 0);
mDialog.show(fragmentManager, null);
}
@Test
......@@ -79,7 +97,7 @@ public class AccountPickerDialogFragmentTest extends DummyUiActivityTestCase {
@MediumTest
public void testAddAccount() {
onView(withText(R.string.signin_add_account)).perform(click());
verify(mTargetFragmentMock).addAccount();
verify(mTargetFragment).addAccount();
}
@Test
......@@ -87,14 +105,33 @@ public class AccountPickerDialogFragmentTest extends DummyUiActivityTestCase {
public void testSelectDefaultAccount() {
onView(withText(mAccountName1)).check(matches(isDisplayed()));
onView(withText(mFullName1)).perform(click());
verify(mTargetFragmentMock).onAccountSelected(mAccountName1, true);
verify(mTargetFragment).onAccountSelected(mAccountName1, true);
}
@Test
@MediumTest
public void testSelectNonDefaultAccount() {
onView(withText(mAccountName2)).perform(click());
verify(mTargetFragmentMock).onAccountSelected(mAccountName2, false);
verify(mTargetFragment).onAccountSelected(mAccountName2, false);
}
@Test
@LargeTest
@Feature("RenderTest")
public void testAccountPickerDialogViewLegacy() throws IOException {
InstrumentationRegistry.getInstrumentation().waitForIdleSync();
mRenderTestRule.render(
mDialog.getDialog().getWindow().getDecorView(), "account_picker_dialog_legacy");
}
@Test
@LargeTest
@Feature("RenderTest")
@Features.EnableFeatures({ChromeFeatureList.MOBILE_IDENTITY_CONSISTENCY})
public void testAccountPickerDialogView() throws IOException {
InstrumentationRegistry.getInstrumentation().waitForIdleSync();
mRenderTestRule.render(
mDialog.getDialog().getWindow().getDecorView(), "account_picker_dialog");
}
private void addAccount(String accountName, String fullName) {
......
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