[Unity][Android] Implement bottom button bar in SyncAndServicesPreferences

This CL implements bottom bar with "Cancel" and "Confirm" buttons in
SyncAndServicesPreferences. This bottom bar is only shown when the user
opens SyncAndServicesPreferences screen from the sign-in screen.

Bug: 914056
Change-Id: I3f5f2002ab7bcd566f3305fd2344a79069bb82fb
Reviewed-on: https://chromium-review.googlesource.com/c/1435276
Reviewed-by: Theresa <twellington@chromium.org>
Commit-Queue: Boris Sazonov <bsazonov@chromium.org>
Cr-Commit-Position: refs/heads/master@{#630098}
diff --git a/chrome/android/java/res/layout/storage_preferences.xml b/chrome/android/java/res/layout/storage_preferences.xml
index 03c3511..5eecae7 100644
--- a/chrome/android/java/res/layout/storage_preferences.xml
+++ b/chrome/android/java/res/layout/storage_preferences.xml
@@ -3,6 +3,7 @@
      Use of this source code is governed by a BSD-style license that can be
      found in the LICENSE file. -->
 
+<!-- TODO(https://crbug.com/929743): Use standard layout and specify only bottom button here. -->
 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
     xmlns:tools="http://schemas.android.com/tools"
     android:orientation="vertical"
diff --git a/chrome/android/java/res/layout/sync_and_services_bottom_bar.xml b/chrome/android/java/res/layout/sync_and_services_bottom_bar.xml
new file mode 100644
index 0000000..0deda60
--- /dev/null
+++ b/chrome/android/java/res/layout/sync_and_services_bottom_bar.xml
@@ -0,0 +1,44 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright 2019 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. -->
+<merge
+    xmlns:android="http://schemas.android.com/apk/res/android">
+
+    <ImageView
+        android:id="@+id/bottom_bar_shadow"
+        android:layout_width="match_parent"
+        android:layout_height="@dimen/action_bar_shadow_height"
+        android:layout_marginTop="@dimen/action_bar_shadow_margin_negative"
+        android:background="@drawable/modern_toolbar_shadow"
+        android:scaleY="-1"
+        android:importantForAccessibility="no"/>
+
+    <LinearLayout
+        android:id="@+id/bottom_bar_button_container"
+        android:layout_width="match_parent"
+        android:layout_height="wrap_content"
+        android:orientation="horizontal"
+        android:padding="16dp">
+
+        <org.chromium.ui.widget.ButtonCompat
+            android:id="@+id/cancel_button"
+            style="@style/TextButton"
+            android:layout_width="wrap_content"
+            android:layout_height="wrap_content"
+            android:text="@string/cancel"/>
+
+        <View
+            android:layout_width="0dp"
+            android:layout_height="0dp"
+            android:layout_weight="1"
+            android:visibility="invisible"/>
+
+        <org.chromium.ui.widget.ButtonCompat
+            android:id="@+id/confirm_button"
+            style="@style/FilledButton.Flat"
+            android:layout_width="wrap_content"
+            android:layout_height="wrap_content"
+            android:text="@string/confirm"/>
+    </LinearLayout>
+</merge>
diff --git a/chrome/android/java/res/values/dimens.xml b/chrome/android/java/res/values/dimens.xml
index c993ac5..1fd973d 100644
--- a/chrome/android/java/res/values/dimens.xml
+++ b/chrome/android/java/res/values/dimens.xml
@@ -524,6 +524,8 @@
 
     <!--  Miscellaneous dimensions -->
     <dimen name="action_bar_shadow_height">10dp</dimen>
+    <!--  Used as a margin to force the shadow view to overlap other views. -->
+    <dimen name="action_bar_shadow_margin_negative">-10dp</dimen>
     <dimen name="clear_text_button_end_padding">10dp</dimen>
     <dimen name="sync_promo_view_padding">16dp</dimen>
     <dimen name="open_new_tab_animation_y_translation">-20dp</dimen>
diff --git a/chrome/android/java/src/org/chromium/chrome/browser/preferences/SyncAndServicesPreferences.java b/chrome/android/java/src/org/chromium/chrome/browser/preferences/SyncAndServicesPreferences.java
index 8d44c5b..0dd713f 100644
--- a/chrome/android/java/src/org/chromium/chrome/browser/preferences/SyncAndServicesPreferences.java
+++ b/chrome/android/java/src/org/chromium/chrome/browser/preferences/SyncAndServicesPreferences.java
@@ -21,9 +21,12 @@
 import android.support.annotation.IntDef;
 import android.support.annotation.Nullable;
 import android.support.v7.app.AlertDialog;
+import android.view.LayoutInflater;
 import android.view.Menu;
 import android.view.MenuInflater;
 import android.view.MenuItem;
+import android.view.View;
+import android.view.ViewGroup;
 
 import org.chromium.base.BuildInfo;
 import org.chromium.base.ContextUtils;
@@ -51,6 +54,7 @@
 import org.chromium.components.sync.AndroidSyncSettings;
 import org.chromium.components.sync.ProtocolErrorClientAction;
 import org.chromium.content_public.browser.UiThreadTaskTraits;
+import org.chromium.ui.widget.ButtonCompat;
 
 import java.lang.annotation.Retention;
 import java.lang.annotation.RetentionPolicy;
@@ -247,15 +251,41 @@
     }
 
     @Override
+    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container,
+            @Nullable Bundle savedInstanceState) {
+        ViewGroup result = (ViewGroup) super.onCreateView(inflater, container, savedInstanceState);
+        if (mIsFromSigninScreen) {
+            inflater.inflate(R.layout.sync_and_services_bottom_bar, result, true);
+            ButtonCompat cancelButton = result.findViewById(R.id.cancel_button);
+            cancelButton.setOnClickListener(view -> cancelSync());
+
+            ButtonCompat confirmButton = result.findViewById(R.id.confirm_button);
+            confirmButton.setOnClickListener(view -> confirmSettings());
+        }
+        return result;
+    }
+
+    private void confirmSettings() {
+        // Settings will be applied when mSyncSetupInProgressHandle is released in onDestroy.
+        getActivity().finish();
+    }
+
+    @Override
     public void onStart() {
         super.onStart();
         mProfileSyncService.addSyncStateChangedListener(this);
         mSigninPreference.registerForUpdates();
 
-        if (!ChromeSigninController.get().isSignedIn()) {
-            // Don't show CancelSyncDialog.
-            mIsFromSigninScreen = false;
+        if (!mIsFromSigninScreen || ChromeSigninController.get().isSignedIn()) {
+            return;
         }
+
+        // Don't show CancelSyncDialog and hide bottom bar.
+        mIsFromSigninScreen = false;
+        View bottomBarShadow = getView().findViewById(R.id.bottom_bar_shadow);
+        bottomBarShadow.setVisibility(View.GONE);
+        View bottomBarButtonContainer = getView().findViewById(R.id.bottom_bar_button_container);
+        bottomBarButtonContainer.setVisibility(View.GONE);
     }
 
     @Override
diff --git a/chrome/android/java/strings/android_chrome_strings.grd b/chrome/android/java/strings/android_chrome_strings.grd
index 032a65b..9441e8f 100644
--- a/chrome/android/java/strings/android_chrome_strings.grd
+++ b/chrome/android/java/strings/android_chrome_strings.grd
@@ -251,6 +251,9 @@
       <message name="IDS_BACK" desc="Label for a back button to return to a previous UI state or screen. Used in multiple contexts. [CHAR-LIMIT=20]">
         Back
       </message>
+      <message name="IDS_CONFIRM" desc="Label for a confirm button. Used in multiple contexts. [CHAR-LIMIT=20]">
+        Confirm
+      </message>
 
       <!-- Main Preferences -->
       <message name="IDS_PREFERENCES" desc="Title for Chrome's Settings.">