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

This commit is contained in:
Arc Wang
2018-11-23 02:10:40 +00:00
committed by Android (Google) Code Review
11 changed files with 538 additions and 0 deletions

View File

@@ -0,0 +1,91 @@
/*
* 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.app.ActionBar;
import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentTransaction;
import com.android.internal.logging.nano.MetricsProto;
import com.android.settings.core.InstrumentedActivity;
import com.android.settings.R;
public class WifiDppConfiguratorActivity extends InstrumentedActivity {
private static final String TAG = "WifiDppConfiguratorActivity";
private FragmentManager mFragmentManager;
private FragmentTransaction mFragmentTransaction;
public static final String EXTRA_LAUNCH_MODE =
"com.android.settings.wifi.dpp.EXTRA_LAUNCH_MODE";
public static final String EXTRA_SSID = "com.android.settings.wifi.dpp.EXTRA_SSID";
public enum LaunchMode {
LAUNCH_MODE_QR_CODE_SCANNER(1),
LAUNCH_MODE_QR_CODE_GENERATOR(2),
LAUNCH_MODE_CHOOSE_SAVED_WIFI_NETWORK(3),
LAUNCH_MODE_NOT_DEFINED(-1);
private int mMode;
LaunchMode(int mode) {
this.mMode = mode;
}
public int getMode() {
return mMode;
}
}
@Override
public int getMetricsCategory() {
//TODO:Should we use a new metrics category for Wi-Fi DPP?
return MetricsProto.MetricsEvent.WIFI_NETWORK_DETAILS;
}
@Override
protected void onCreate(Bundle savedInstanceState) {
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();
} else {
Log.e(TAG, "Launch with an invalid mode extra");
setResult(Activity.RESULT_CANCELED);
finish();
}
}
}

View File

@@ -0,0 +1,107 @@
/*
* 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 android.view.LayoutInflater;
import android.view.SurfaceView;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.TextView;
import com.android.internal.logging.nano.MetricsProto;
import com.android.settings.core.InstrumentedFragment;
import com.android.settings.R;
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;
abstract protected int getLayout();
@Override
public int getMetricsCategory() {
//TODO:Should we use a new metrics category for Wi-Fi DPP?
return MetricsProto.MetricsEvent.WIFI_NETWORK_DETAILS;
}
@Override
public final void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
}
@Override
public final View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view = inflater.inflate(getLayout(), container, false);
initView(view);
return view;
}
private void initView(View view) {
mTitle = view.findViewById(R.id.title);
mDescription = view.findViewById(R.id.description);
mPreviewView = view.findViewById(R.id.preview_view);
mErrorMessage = view.findViewById(R.id.error_message);
mButtonLeft = view.findViewById(R.id.button_left);
mButtonRight = view.findViewById(R.id.button_right);
}
protected void setTitle(String title) {
mTitle.setText(title);
}
protected void setDescription(String description) {
mDescription.setText(description);
}
protected void setErrorMessage(String errorMessage) {
if (mErrorMessage != null) {
mErrorMessage.setText(errorMessage);
}
}
protected void setLeftButtonText(String text) {
mButtonLeft.setText(text);
}
protected void setRightButtonText(String text) {
mButtonRight.setText(text);
}
protected void hideLeftButton() {
mButtonLeft.setVisibility(View.INVISIBLE);
}
protected void hideRightButton() {
mButtonRight.setVisibility(View.INVISIBLE);
}
protected void setLeftButtonOnClickListener(View.OnClickListener listener) {
mButtonLeft.setOnClickListener(listener);
}
protected void setRightButtonOnClickListener(View.OnClickListener listener) {
mButtonRight.setOnClickListener(listener);
}
}

View File

@@ -0,0 +1,55 @@
/*
* 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.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 {
@Override
protected int getLayout() {
return R.layout.wifi_dpp_qrcode_scanner_fragment;
}
@Override
public void onActivityCreated (Bundle savedInstanceState) {
super.onActivityCreated (savedInstanceState);
setTitle(getString(R.string.wifi_dpp_add_device_to_network));
String ssid = "";
Intent intent = getActivity().getIntent();
if (intent != null)
ssid = intent.getStringExtra(WifiDppConfiguratorActivity.EXTRA_SSID);
String description = getString(R.string.wifi_dpp_center_qr_code, ssid);
setDescription(description);
hideRightButton();
setLeftButtonText(getString(android.R.string.cancel));
setLeftButtonOnClickListener((view) -> {
getActivity().setResult(Activity.RESULT_CANCELED);
getActivity().finish();});
}
}