Merge "Fix QR code scanner layout in "Pair devices over Wi-Fi" page."

This commit is contained in:
Joshua Duong
2021-08-25 15:35:56 +00:00
committed by Android (Google) Code Review
7 changed files with 216 additions and 54 deletions

View File

@@ -0,0 +1,75 @@
/*
* Copyright (C) 2021 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.development;
import android.app.settings.SettingsEnums;
import android.content.Intent;
import android.os.Bundle;
import androidx.fragment.app.FragmentTransaction;
import com.android.settings.R;
import com.android.settings.wifi.dpp.WifiDppBaseActivity;
/**
* To scan an ADB QR code to pair a device.
*
* To use intent action {@code ACTION_ADB_QR_CODE_SCANNER}.
*/
public class AdbQrCodeActivity extends WifiDppBaseActivity {
private static final String TAG = "AdbQrCodeActivity";
static final String TAG_FRAGMENT_ADB_QR_CODE_SCANNER = "adb_qr_code_scanner_fragment";
public static final String ACTION_ADB_QR_CODE_SCANNER =
"android.settings.ADB_QR_CODE_SCANNER";
@Override
public int getMetricsCategory() {
return SettingsEnums.SETTINGS_ADB_WIRELESS;
}
@Override
protected void onCreate(Bundle icicle) {
super.onCreate(icicle);
AdbQrcodeScannerFragment fragment =
(AdbQrcodeScannerFragment) mFragmentManager.findFragmentByTag(
TAG_FRAGMENT_ADB_QR_CODE_SCANNER);
if (fragment == null) {
fragment = new AdbQrcodeScannerFragment();
} else {
if (fragment.isVisible()) {
return;
}
// When the fragment in back stack but not on top of the stack, we can simply pop
// stack because current fragment transactions are arranged in an order
mFragmentManager.popBackStackImmediate();
return;
}
final FragmentTransaction fragmentTransaction = mFragmentManager.beginTransaction();
fragmentTransaction.replace(R.id.fragment_container, fragment,
TAG_FRAGMENT_ADB_QR_CODE_SCANNER);
fragmentTransaction.commit();
}
@Override
protected void handleIntent(Intent intent) {
}
}

View File

@@ -16,8 +16,8 @@
package com.android.settings.development;
import android.app.settings.SettingsEnums;
import android.content.Context;
import android.content.Intent;
import android.debug.IAdbManager;
import android.os.RemoteException;
import android.os.ServiceManager;
@@ -28,7 +28,6 @@ import androidx.fragment.app.Fragment;
import androidx.preference.Preference;
import com.android.settings.core.BasePreferenceController;
import com.android.settings.core.SubSettingLauncher;
/**
* Controller for the "Pair device with QR code" preference in the Wireless debugging
@@ -68,12 +67,9 @@ public class AdbQrCodePreferenceController extends BasePreferenceController {
return false;
}
new SubSettingLauncher(preference.getContext())
.setDestination(AdbQrcodeScannerFragment.class.getName())
.setSourceMetricsCategory(SettingsEnums.SETTINGS_ADB_WIRELESS)
.setResultListener(mParentFragment,
WirelessDebuggingFragment.PAIRING_DEVICE_REQUEST)
.launch();
final Intent intent = new Intent(mContext, AdbQrCodeActivity.class);
mParentFragment.startActivityForResult(intent,
WirelessDebuggingFragment.PAIRING_DEVICE_REQUEST);
return true;
}
}

View File

@@ -44,12 +44,15 @@ import android.widget.TextView;
import androidx.annotation.StringRes;
import com.android.settings.R;
import com.android.settings.SetupWizardUtils;
import com.android.settings.wifi.dpp.AdbQrCode;
import com.android.settings.wifi.dpp.WifiDppQrCodeBaseFragment;
import com.android.settings.wifi.dpp.WifiNetworkConfig;
import com.android.settings.wifi.qrcode.QrCamera;
import com.android.settings.wifi.qrcode.QrDecorateView;
import com.google.android.setupdesign.util.ThemeHelper;
/**
* Fragment shown when clicking on the "Pair by QR code" preference in
* the Wireless Debugging fragment.
@@ -144,6 +147,9 @@ public class AdbQrcodeScannerFragment extends WifiDppQrCodeBaseFragment implemen
@Override
public void onCreate(Bundle savedInstanceState) {
Context context = getContext();
context.setTheme(SetupWizardUtils.getTheme(context, getActivity().getIntent()));
ThemeHelper.trySetDynamicColor(getContext());
super.onCreate(savedInstanceState);
mIntentFilter = new IntentFilter(AdbManager.WIRELESS_DEBUG_PAIRING_RESULT_ACTION);
@@ -158,6 +164,7 @@ public class AdbQrcodeScannerFragment extends WifiDppQrCodeBaseFragment implemen
@Override
public void onViewCreated(View view, Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
mSummary = view.findViewById(R.id.sud_layout_subtitle);
mTextureView = (TextureView) view.findViewById(R.id.preview_view);
mTextureView.setSurfaceTextureListener(this);
@@ -165,8 +172,6 @@ public class AdbQrcodeScannerFragment extends WifiDppQrCodeBaseFragment implemen
mDecorateView = view.findViewById(R.id.decorate_view);
setProgressBarShown(false);
setHeaderIconImageResource(R.drawable.ic_scan_24dp);
mQrCameraView = view.findViewById(R.id.camera_layout);
mVerifyingView = view.findViewById(R.id.verifying_layout);
mVerifyingTextView = view.findViewById(R.id.verifying_textview);
@@ -181,12 +186,18 @@ public class AdbQrcodeScannerFragment extends WifiDppQrCodeBaseFragment implemen
public void onResume() {
super.onResume();
restartCamera();
mAdbManager = IAdbManager.Stub.asInterface(ServiceManager.getService(Context.ADB_SERVICE));
getActivity().registerReceiver(mReceiver, mIntentFilter);
}
@Override
public void onPause() {
if (mCamera != null) {
mCamera.stop();
}
super.onPause();
getActivity().unregisterReceiver(mReceiver);
@@ -195,8 +206,6 @@ public class AdbQrcodeScannerFragment extends WifiDppQrCodeBaseFragment implemen
} catch (RemoteException e) {
Log.e(TAG, "Unable to cancel pairing");
}
getActivity().setResult(Activity.RESULT_CANCELED);
getActivity().finish();
}
@Override
@@ -213,7 +222,6 @@ public class AdbQrcodeScannerFragment extends WifiDppQrCodeBaseFragment implemen
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
getActivity().getActionBar().hide();
// setTitle for TalkBack
getActivity().setTitle(R.string.wifi_dpp_scan_qr_code);
}