Merge "Upload basic UI files for Wi-Fi DPP Settings development II."
diff --git a/res/layout/wifi_dpp_add_device_fragment.xml b/res/layout/wifi_dpp_add_device_fragment.xml
new file mode 100644
index 0000000..03add62
--- /dev/null
+++ b/res/layout/wifi_dpp_add_device_fragment.xml
@@ -0,0 +1,48 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+     Copyright (C) 2018 The Android Open Source Project
+
+     Licensed under the Apache License, Version 2.0 (the "License");
+     you may not use this file except in compliance with the License.
+     You may obtain a copy of the License at
+
+          http://www.apache.org/licenses/LICENSE-2.0
+
+     Unless required by applicable law or agreed to in writing, software
+     distributed under the License is distributed on an "AS IS" BASIS,
+     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+     See the License for the specific language governing permissions and
+     limitations under the License.
+-->
+
+<LinearLayout
+    xmlns:android="http://schemas.android.com/apk/res/android"
+    android:id="@+id/root"
+    android:layout_width="match_parent"
+    android:layout_height="match_parent"
+    android:orientation="vertical">
+
+    <include layout="@layout/wifi_dpp_fragment_header"/>
+
+    <ProgressBar
+      android:id="@+id/progress_bar"
+      android:layout_width="match_parent"
+      android:layout_height="wrap_content"
+      android:indeterminate="true"/>
+
+    <ImageView
+        android:id="@+id/wifi_ap_picture_view"
+        android:layout_width="match_parent"
+        android:layout_height="match_parent"
+        android:layout_gravity="center"/>
+
+    <TextView android:id="@+id/choose_different_network"
+        android:layout_width="wrap_content"
+        android:layout_height="wrap_content"
+        android:layout_gravity="center"/>
+
+    <include layout="@layout/wifi_dpp_fragment_footer"
+        android:gravity="center|bottom"/>
+
+</LinearLayout>
+
diff --git a/res/layout/wifi_dpp_choose_saved_wifi_network_fragment.xml b/res/layout/wifi_dpp_choose_saved_wifi_network_fragment.xml
new file mode 100644
index 0000000..a65cf3e
--- /dev/null
+++ b/res/layout/wifi_dpp_choose_saved_wifi_network_fragment.xml
@@ -0,0 +1,35 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+     Copyright (C) 2018 The Android Open Source Project
+
+     Licensed under the Apache License, Version 2.0 (the "License");
+     you may not use this file except in compliance with the License.
+     You may obtain a copy of the License at
+
+          http://www.apache.org/licenses/LICENSE-2.0
+
+     Unless required by applicable law or agreed to in writing, software
+     distributed under the License is distributed on an "AS IS" BASIS,
+     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+     See the License for the specific language governing permissions and
+     limitations under the License.
+-->
+
+<LinearLayout
+    xmlns:android="http://schemas.android.com/apk/res/android"
+    android:id="@+id/root"
+    android:layout_width="match_parent"
+    android:layout_height="match_parent"
+    android:orientation="vertical">
+
+    <include layout="@layout/wifi_dpp_fragment_header"/>
+
+    <ListView android:id="@+id/saved_wifi_network_list"
+        android:layout_width="match_parent"
+        android:layout_height="wrap_content"/>
+
+    <include layout="@layout/wifi_dpp_fragment_footer"
+        android:gravity="center|bottom"/>
+
+</LinearLayout>
+
diff --git a/res/layout/wifi_dpp_qrcode_generator_fragment.xml b/res/layout/wifi_dpp_qrcode_generator_fragment.xml
new file mode 100644
index 0000000..789b3a3
--- /dev/null
+++ b/res/layout/wifi_dpp_qrcode_generator_fragment.xml
@@ -0,0 +1,34 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+     Copyright (C) 2018 The Android Open Source Project
+
+     Licensed under the Apache License, Version 2.0 (the "License");
+     you may not use this file except in compliance with the License.
+     You may obtain a copy of the License at
+
+          http://www.apache.org/licenses/LICENSE-2.0
+
+     Unless required by applicable law or agreed to in writing, software
+     distributed under the License is distributed on an "AS IS" BASIS,
+     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+     See the License for the specific language governing permissions and
+     limitations under the License.
+-->
+
+<LinearLayout
+    xmlns:android="http://schemas.android.com/apk/res/android"
+    android:id="@+id/root"
+    android:layout_width="match_parent"
+    android:layout_height="match_parent"
+    android:orientation="vertical">
+
+    <include layout="@layout/wifi_dpp_fragment_header"/>
+
+    <ImageView
+        android:id="@+id/barcode_view"
+        android:layout_width="match_parent"
+        android:layout_height="match_parent"
+        android:layout_gravity="center"/>
+
+</LinearLayout>
+
diff --git a/res/layout/wifi_dpp_qrcode_scanner_fragment.xml b/res/layout/wifi_dpp_qrcode_scanner_fragment.xml
index 130bb6d..a864f51 100644
--- a/res/layout/wifi_dpp_qrcode_scanner_fragment.xml
+++ b/res/layout/wifi_dpp_qrcode_scanner_fragment.xml
@@ -17,7 +17,6 @@
 
 <LinearLayout
     xmlns:android="http://schemas.android.com/apk/res/android"
-    xmlns:app="http://schemas.android.com/apk/res-auto"
     android:id="@+id/root"
     android:layout_width="match_parent"
     android:layout_height="match_parent"
diff --git a/src/com/android/settings/wifi/dpp/WifiDppAddDeviceFragment.java b/src/com/android/settings/wifi/dpp/WifiDppAddDeviceFragment.java
new file mode 100644
index 0000000..177e79d
--- /dev/null
+++ b/src/com/android/settings/wifi/dpp/WifiDppAddDeviceFragment.java
@@ -0,0 +1,37 @@
+/*
+ * Copyright (C) 2018 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.settings.wifi.dpp;
+
+import android.os.Bundle;
+
+import com.android.settings.R;
+
+/**
+ * After getting Wi-Fi network information and(or) QR code, this fragment config a device to connect
+ * to the Wi-Fi network.
+ */
+public class WifiDppAddDeviceFragment extends WifiDppQrCodeBaseFragment {
+    @Override
+    protected int getLayout() {
+        return R.layout.wifi_dpp_add_device_fragment;
+    }
+
+    @Override
+    public void onActivityCreated (Bundle savedInstanceState) {
+        super.onActivityCreated(savedInstanceState);
+    }
+}
diff --git a/src/com/android/settings/wifi/dpp/WifiDppChooseSavedWifiNetworkFragment.java b/src/com/android/settings/wifi/dpp/WifiDppChooseSavedWifiNetworkFragment.java
new file mode 100644
index 0000000..7d031c1
--- /dev/null
+++ b/src/com/android/settings/wifi/dpp/WifiDppChooseSavedWifiNetworkFragment.java
@@ -0,0 +1,37 @@
+/*
+ * Copyright (C) 2018 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.settings.wifi.dpp;
+
+import android.os.Bundle;
+
+import com.android.settings.R;
+
+/**
+ * After a camera APP scanned a Wi-Fi DPP QR code, it can trigger
+ * {@code WifiDppConfiguratorActivity} to start with this fragment to choose a saved Wi-Fi network.
+ */
+public class WifiDppChooseSavedWifiNetworkFragment extends WifiDppQrCodeBaseFragment {
+    @Override
+    protected int getLayout() {
+        return R.layout.wifi_dpp_choose_saved_wifi_network_fragment;
+    }
+
+    @Override
+    public void onActivityCreated (Bundle savedInstanceState) {
+        super.onActivityCreated(savedInstanceState);
+    }
+}
diff --git a/src/com/android/settings/wifi/dpp/WifiDppConfiguratorActivity.java b/src/com/android/settings/wifi/dpp/WifiDppConfiguratorActivity.java
index bccb53a..e631c84 100644
--- a/src/com/android/settings/wifi/dpp/WifiDppConfiguratorActivity.java
+++ b/src/com/android/settings/wifi/dpp/WifiDppConfiguratorActivity.java
@@ -67,25 +67,48 @@
         super.onCreate(savedInstanceState);
         setContentView(R.layout.wifi_dpp_activity);
 
-        // Hide action bar
-        ActionBar action = getActionBar();
-        if (action != null) {
-            action.hide();
-        }
-
         mFragmentManager = getSupportFragmentManager();
         mFragmentTransaction = getSupportFragmentManager().beginTransaction();
 
         final int launchMode = getIntent().getIntExtra(EXTRA_LAUNCH_MODE,
             LaunchMode.LAUNCH_MODE_NOT_DEFINED.getMode());
         if (launchMode == LaunchMode.LAUNCH_MODE_QR_CODE_SCANNER.getMode()) {
-            WifiDppQrCodeScannerFragment scanFragment = new WifiDppQrCodeScannerFragment();
-            mFragmentTransaction.add(R.id.fragment_container, scanFragment);
-            mFragmentTransaction.commit();
+            addQrCodeScannerFragment();
+        } else if (launchMode == LaunchMode.LAUNCH_MODE_QR_CODE_GENERATOR.getMode()) {
+            addQrCodeGeneratorFragment();
+        } else if (launchMode == LaunchMode.LAUNCH_MODE_CHOOSE_SAVED_WIFI_NETWORK.getMode()) {
+            addChooseSavedWifiNetworkFragment();
         } else {
             Log.e(TAG, "Launch with an invalid mode extra");
             setResult(Activity.RESULT_CANCELED);
             finish();
         }
     }
+
+    private void addQrCodeScannerFragment() {
+        WifiDppQrCodeScannerFragment fragment = new WifiDppQrCodeScannerFragment();
+        mFragmentTransaction.add(R.id.fragment_container, fragment);
+        mFragmentTransaction.addToBackStack(null);
+        mFragmentTransaction.commit();
+    }
+
+    private void addQrCodeGeneratorFragment() {
+        WifiDppQrCodeGeneratorFragment fragment = new WifiDppQrCodeGeneratorFragment();
+        mFragmentTransaction.add(R.id.fragment_container, fragment);
+        mFragmentTransaction.addToBackStack(null);
+        mFragmentTransaction.commit();
+    }
+
+    private void addChooseSavedWifiNetworkFragment() {
+        ActionBar action = getActionBar();
+        if (action != null) {
+            action.hide();
+        }
+
+        WifiDppChooseSavedWifiNetworkFragment fragment =
+                new WifiDppChooseSavedWifiNetworkFragment();
+        mFragmentTransaction.add(R.id.fragment_container, fragment);
+        mFragmentTransaction.addToBackStack(null);
+        mFragmentTransaction.commit();
+    }
 }
diff --git a/src/com/android/settings/wifi/dpp/WifiDppQrCodeBaseFragment.java b/src/com/android/settings/wifi/dpp/WifiDppQrCodeBaseFragment.java
index 004cb18..0d30a79 100644
--- a/src/com/android/settings/wifi/dpp/WifiDppQrCodeBaseFragment.java
+++ b/src/com/android/settings/wifi/dpp/WifiDppQrCodeBaseFragment.java
@@ -22,6 +22,9 @@
 import android.view.View;
 import android.view.ViewGroup;
 import android.widget.Button;
+import android.widget.ImageView;
+import android.widget.ListView;
+import android.widget.ProgressBar;
 import android.widget.TextView;
 
 import com.android.internal.logging.nano.MetricsProto;
@@ -29,13 +32,37 @@
 import com.android.settings.core.InstrumentedFragment;
 import com.android.settings.R;
 
+/**
+ * There are below 4 fragments for Wi-Fi DPP UI flow, to reduce redundant code of UI components,
+ * this parent fragment instantiates all UI components and provides setting APIs for them.
+ *
+ * {@code WifiDppQrCodeScannerFragment}
+ * {@code WifiDppQrCodeGeneratorFragment}
+ * {@code WifiDppChooseSavedWifiNetworkFragment}
+ * {@code WifiDppAddDeviceFragment}
+ */
 public abstract class WifiDppQrCodeBaseFragment extends InstrumentedFragment {
     private TextView mTitle;
     private TextView mDescription;
-    private SurfaceView mPreviewView;
-    private TextView mErrorMessage; //optional, view used to surface connectivity errors to the user
-    private Button mButtonLeft;
-    private Button mButtonRight;
+
+    private SurfaceView mPreviewView;       //optional, for WifiDppQrCodeScannerFragment
+    private ImageView mDecorateViiew;       //optional, for WifiDppQrCodeScannerFragment
+    private TextView mErrorMessage;         //optional, for WifiDppQrCodeScannerFragment
+
+    private ImageView mBarcodeView;         //optional, for WifiDppQrCodeGeneratorFragment
+
+    private ListView mSavedWifiNetworkList; //optional, for WifiDppChooseSavedWifiNetworkFragment
+
+    private ProgressBar mProgressBar;       //optional, for WifiDppAddDeviceFragment
+    private ImageView mWifiApPictureView;   //optional, for WifiDppAddDeviceFragment
+    private TextView mChooseDifferentNetwork;//optional, for WifiDppAddDeviceFragment
+
+    private Button mButtonLeft;             //optional, for WifiDppQrCodeScannerFragment,
+                                            //              WifiDppChooseSavedWifiNetworkFragment,
+                                            //              WifiDppAddDeviceFragment
+    private Button mButtonRight;            //optional, for WifiDppQrCodeScannerFragment,
+                                            //              WifiDppChooseSavedWifiNetworkFragment,
+                                            //              WifiDppAddDeviceFragment
 
     abstract protected int getLayout();
 
@@ -61,8 +88,19 @@
     private void initView(View view) {
         mTitle = view.findViewById(R.id.title);
         mDescription = view.findViewById(R.id.description);
+
         mPreviewView = view.findViewById(R.id.preview_view);
+        mDecorateViiew = view.findViewById(R.id.decorate_view);
         mErrorMessage = view.findViewById(R.id.error_message);
+
+        mBarcodeView = view.findViewById(R.id.barcode_view);
+
+        mSavedWifiNetworkList = view.findViewById(R.id.saved_wifi_network_list);
+
+        mProgressBar = view.findViewById(R.id.progress_bar);
+        mWifiApPictureView = view.findViewById(R.id.wifi_ap_picture_view);
+        mChooseDifferentNetwork = view.findViewById(R.id.choose_different_network);
+
         mButtonLeft = view.findViewById(R.id.button_left);
         mButtonRight = view.findViewById(R.id.button_right);
     }
@@ -75,33 +113,76 @@
         mDescription.setText(description);
     }
 
+    /** optional, for WifiDppQrCodeScannerFragment */
     protected void setErrorMessage(String errorMessage) {
         if (mErrorMessage != null) {
             mErrorMessage.setText(errorMessage);
         }
     }
 
+    /**
+     * optional, for WifiDppQrCodeScannerFragment,
+     *               WifiDppChooseSavedWifiNetworkFragment,
+     *               WifiDppAddDeviceFragment
+     */
     protected void setLeftButtonText(String text) {
-        mButtonLeft.setText(text);
+        if (mButtonLeft != null) {
+            mButtonLeft.setText(text);
+        }
     }
 
+    /**
+     * optional, for WifiDppQrCodeScannerFragment,
+     *               WifiDppChooseSavedWifiNetworkFragment,
+     *               WifiDppAddDeviceFragment
+     */
     protected void setRightButtonText(String text) {
-        mButtonRight.setText(text);
+        if (mButtonRight != null) {
+            mButtonRight.setText(text);
+        }
     }
 
+    /**
+     * optional, for WifiDppQrCodeScannerFragment,
+     *               WifiDppChooseSavedWifiNetworkFragment,
+     *               WifiDppAddDeviceFragment
+     */
     protected void hideLeftButton() {
-        mButtonLeft.setVisibility(View.INVISIBLE);
+        if (mButtonLeft != null) {
+            mButtonLeft.setVisibility(View.INVISIBLE);
+        }
     }
 
+    /**
+     * optional, for WifiDppQrCodeScannerFragment,
+     *               WifiDppChooseSavedWifiNetworkFragment,
+     *               WifiDppAddDeviceFragment
+     */
     protected void hideRightButton() {
-        mButtonRight.setVisibility(View.INVISIBLE);
+        if (mButtonRight != null) {
+            mButtonRight.setVisibility(View.INVISIBLE);
+        }
     }
 
+    /**
+     * optional, for WifiDppQrCodeScannerFragment,
+     *               WifiDppChooseSavedWifiNetworkFragment,
+     *               WifiDppAddDeviceFragment
+     */
     protected void setLeftButtonOnClickListener(View.OnClickListener listener) {
-        mButtonLeft.setOnClickListener(listener);
+        if (mButtonLeft != null) {
+            mButtonLeft.setOnClickListener(listener);
+        }
     }
 
+    /**
+     * optional, for WifiDppQrCodeScannerFragment,
+     *               WifiDppChooseSavedWifiNetworkFragment,
+     *               WifiDppAddDeviceFragment
+     */
     protected void setRightButtonOnClickListener(View.OnClickListener listener) {
-        mButtonRight.setOnClickListener(listener);
+        if (mButtonRight != null) {
+            mButtonRight.setOnClickListener(listener);
+        }
     }
 }
diff --git a/src/com/android/settings/wifi/dpp/WifiDppQrCodeGeneratorFragment.java b/src/com/android/settings/wifi/dpp/WifiDppQrCodeGeneratorFragment.java
new file mode 100644
index 0000000..9935bf2
--- /dev/null
+++ b/src/com/android/settings/wifi/dpp/WifiDppQrCodeGeneratorFragment.java
@@ -0,0 +1,37 @@
+/*
+ * Copyright (C) 2018 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.settings.wifi.dpp;
+
+import android.os.Bundle;
+
+import com.android.settings.R;
+
+/**
+ * After sharing a saved Wi-Fi network, {@code WifiDppConfiguratorActivity} start with this fragment
+ * to generate a Wi-Fi DPP QR code for other device to initiate as an enrollee.
+ */
+public class WifiDppQrCodeGeneratorFragment extends WifiDppQrCodeBaseFragment {
+    @Override
+    protected int getLayout() {
+        return R.layout.wifi_dpp_qrcode_generator_fragment;
+    }
+
+    @Override
+    public void onActivityCreated (Bundle savedInstanceState) {
+        super.onActivityCreated(savedInstanceState);
+    }
+}
diff --git a/src/com/android/settings/wifi/dpp/WifiDppQrCodeScannerFragment.java b/src/com/android/settings/wifi/dpp/WifiDppQrCodeScannerFragment.java
index 0ee8434..cbaa5d5 100644
--- a/src/com/android/settings/wifi/dpp/WifiDppQrCodeScannerFragment.java
+++ b/src/com/android/settings/wifi/dpp/WifiDppQrCodeScannerFragment.java
@@ -19,10 +19,7 @@
 import android.app.Activity;
 import android.content.Intent;
 import android.os.Bundle;
-import android.view.LayoutInflater;
-import android.view.View;
 
-import android.view.ViewGroup;
 import com.android.settings.R;
 
 public class WifiDppQrCodeScannerFragment extends WifiDppQrCodeBaseFragment {
diff --git a/tests/unit/src/com/android/settings/wifi/dpp/WifiDppConfiguratorActivityTest.java b/tests/unit/src/com/android/settings/wifi/dpp/WifiDppConfiguratorActivityTest.java
index d101c92..208c344 100644
--- a/tests/unit/src/com/android/settings/wifi/dpp/WifiDppConfiguratorActivityTest.java
+++ b/tests/unit/src/com/android/settings/wifi/dpp/WifiDppConfiguratorActivityTest.java
@@ -35,18 +35,38 @@
             new ActivityTestRule<>(WifiDppConfiguratorActivity.class);
 
     @Test
-    public void testLaunchModeQrCodeScanner_shouldNotAutoFinish() {
+    public void launchActivity_modeQrCodeScanner_shouldNotAutoFinish() {
         Intent intent = new Intent();
         intent.putExtra(WifiDppConfiguratorActivity.EXTRA_LAUNCH_MODE,
                 WifiDppConfiguratorActivity.LaunchMode.LAUNCH_MODE_QR_CODE_SCANNER.getMode());
         mActivityRule.launchActivity(intent);
 
         assertThat(mActivityRule.getActivity().isFinishing()).isEqualTo(false);
-        mActivityRule.finishActivity();
     }
 
     @Test
-    public void testNoLaunchMode_shouldFinishActivityWithResultCodeCanceled() {
+    public void launchActivity_modeQrCodeGenerator_shouldNotAutoFinish() {
+        Intent intent = new Intent();
+        intent.putExtra(WifiDppConfiguratorActivity.EXTRA_LAUNCH_MODE,
+                WifiDppConfiguratorActivity.LaunchMode.LAUNCH_MODE_QR_CODE_GENERATOR.getMode());
+        mActivityRule.launchActivity(intent);
+
+        assertThat(mActivityRule.getActivity().isFinishing()).isEqualTo(false);
+    }
+
+    @Test
+    public void launchActivity_modeChooseSavedWifiNetwork_shouldNotAutoFinish() {
+        Intent intent = new Intent();
+        intent.putExtra(WifiDppConfiguratorActivity.EXTRA_LAUNCH_MODE,
+                WifiDppConfiguratorActivity.LaunchMode
+                .LAUNCH_MODE_CHOOSE_SAVED_WIFI_NETWORK.getMode());
+        mActivityRule.launchActivity(intent);
+
+        assertThat(mActivityRule.getActivity().isFinishing()).isEqualTo(false);
+    }
+
+    @Test
+    public void launchActivity_noLaunchMode_shouldFinishActivityWithResultCodeCanceled() {
         // If we do not specify launch mode, the activity will finish itself right away
         Intent intent = new Intent();
         mActivityRule.launchActivity(intent);
diff --git a/tests/unit/src/com/android/settings/wifi/dpp/WifiDppQrCodeScannerFragmentTest.java b/tests/unit/src/com/android/settings/wifi/dpp/WifiDppQrCodeScannerFragmentTest.java
index 58fa61f..0f4bfd9 100644
--- a/tests/unit/src/com/android/settings/wifi/dpp/WifiDppQrCodeScannerFragmentTest.java
+++ b/tests/unit/src/com/android/settings/wifi/dpp/WifiDppQrCodeScannerFragmentTest.java
@@ -47,8 +47,9 @@
     }
 
     @Test
-    public void testLeftButton_shouldFinishActivityWithResultCodeCanceled() {
+    public void leftButton_shouldFinishActivityWithResultCodeCanceled() {
         onView(withText("Cancel")).perform(click());
+
         assertThat(mActivityRule.getActivityResult().getResultCode()).
                 isEqualTo(Activity.RESULT_CANCELED);
     }