Upload basic UI files for Wi-Fi DPP Settings development II.

Add 3 fragments:

  WifiDppQrCodeGeneratorFragment
  WifiDppChooseSavedWifiNetworkFragment
  WifiDppAddDeviceFragment

Bug: 118797380
     118797202
     118794978
     118796825
     118794858
Test: atest WifiDppConfiguratorActivityTest
      atest WifiDppQrCodeScannerFragmentTest
      atest atest RunSettingsRoboTests

Change-Id: I2fbc2f46f941d49b63e4ac74d92f94bf617d2b9b
This commit is contained in:
Arc Wang
2018-11-23 10:51:27 +08:00
parent d4fc724f95
commit f5d6089d35
12 changed files with 376 additions and 27 deletions

View File

@@ -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>

View File

@@ -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>

View File

@@ -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>

View File

@@ -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"

View File

@@ -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);
}
}

View File

@@ -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);
}
}

View File

@@ -67,25 +67,48 @@ public class WifiDppConfiguratorActivity extends InstrumentedActivity {
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();
}
}

View File

@@ -22,6 +22,9 @@ import android.view.SurfaceView;
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.internal.logging.nano.MetricsProto;
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 @@ public abstract class WifiDppQrCodeBaseFragment extends InstrumentedFragment {
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 @@ public abstract class WifiDppQrCodeBaseFragment extends InstrumentedFragment {
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) {
if (mButtonLeft != null) {
mButtonLeft.setText(text);
}
}
/**
* optional, for WifiDppQrCodeScannerFragment,
* WifiDppChooseSavedWifiNetworkFragment,
* WifiDppAddDeviceFragment
*/
protected void setRightButtonText(String text) {
if (mButtonRight != null) {
mButtonRight.setText(text);
}
}
/**
* optional, for WifiDppQrCodeScannerFragment,
* WifiDppChooseSavedWifiNetworkFragment,
* WifiDppAddDeviceFragment
*/
protected void hideLeftButton() {
if (mButtonLeft != null) {
mButtonLeft.setVisibility(View.INVISIBLE);
}
}
/**
* optional, for WifiDppQrCodeScannerFragment,
* WifiDppChooseSavedWifiNetworkFragment,
* WifiDppAddDeviceFragment
*/
protected void hideRightButton() {
if (mButtonRight != null) {
mButtonRight.setVisibility(View.INVISIBLE);
}
}
/**
* optional, for WifiDppQrCodeScannerFragment,
* WifiDppChooseSavedWifiNetworkFragment,
* WifiDppAddDeviceFragment
*/
protected void setLeftButtonOnClickListener(View.OnClickListener listener) {
if (mButtonLeft != null) {
mButtonLeft.setOnClickListener(listener);
}
}
/**
* optional, for WifiDppQrCodeScannerFragment,
* WifiDppChooseSavedWifiNetworkFragment,
* WifiDppAddDeviceFragment
*/
protected void setRightButtonOnClickListener(View.OnClickListener listener) {
if (mButtonRight != null) {
mButtonRight.setOnClickListener(listener);
}
}
}

View File

@@ -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);
}
}

View File

@@ -19,10 +19,7 @@ package com.android.settings.wifi.dpp;
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 {

View File

@@ -35,18 +35,38 @@ public class WifiDppConfiguratorActivityTest {
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);

View File

@@ -47,8 +47,9 @@ public class WifiDppQrCodeScannerFragmentTest {
}
@Test
public void testLeftButton_shouldFinishActivityWithResultCodeCanceled() {
public void leftButton_shouldFinishActivityWithResultCodeCanceled() {
onView(withText("Cancel")).perform(click());
assertThat(mActivityRule.getActivityResult().getResultCode()).
isEqualTo(Activity.RESULT_CANCELED);
}