1 /* 2 * Copyright (C) 2020 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package com.android.settings.development; 18 19 import android.content.Context; 20 import android.content.res.Resources; 21 import android.view.View; 22 import android.widget.TextView; 23 24 import com.android.settings.R; 25 26 /** 27 * The class for allowing UIs like {@link AdbWirelessDialog} and {@link AdbWirelessDialogUiBase} to 28 * share the logic for controlling buttons, text fields, etc. 29 */ 30 public class AdbWirelessDialogController { 31 private static final String TAG = "AdbWirelessDialogCtrl"; 32 33 private final AdbWirelessDialogUiBase mUi; 34 private final View mView; 35 36 private int mMode; 37 38 // The dialog for showing the six-digit code 39 private TextView mPairingCodeTitle; 40 private TextView mSixDigitCode; 41 private TextView mIpAddr; 42 43 // The dialog for showing pairing failed message 44 private TextView mFailedMsg; 45 46 private Context mContext; 47 AdbWirelessDialogController(AdbWirelessDialogUiBase parent, View view, int mode)48 public AdbWirelessDialogController(AdbWirelessDialogUiBase parent, View view, 49 int mode) { 50 mUi = parent; 51 mView = view; 52 mMode = mode; 53 54 mContext = mUi.getContext(); 55 final Resources res = mContext.getResources(); 56 57 mSixDigitCode = mView.findViewById(R.id.pairing_code); 58 mIpAddr = mView.findViewById(R.id.ip_addr); 59 60 switch (mMode) { 61 case AdbWirelessDialogUiBase.MODE_PAIRING: 62 String title = res.getString( 63 com.android.settingslib.R.string.adb_pairing_device_dialog_title); 64 mUi.setTitle(title); 65 mView.findViewById(R.id.l_pairing_six_digit).setVisibility(View.VISIBLE); 66 mUi.setCancelButton(res.getString(R.string.cancel)); 67 mUi.setCanceledOnTouchOutside(false); 68 break; 69 case AdbWirelessDialogUiBase.MODE_PAIRING_FAILED: 70 String msg = res.getString( 71 com.android.settingslib.R.string.adb_pairing_device_dialog_failed_msg); 72 mUi.setTitle( 73 com.android.settingslib.R.string.adb_pairing_device_dialog_failed_title); 74 mView.findViewById(R.id.l_pairing_failed).setVisibility(View.VISIBLE); 75 mFailedMsg = (TextView) mView.findViewById(R.id.pairing_failed_label); 76 mFailedMsg.setText(msg); 77 mUi.setSubmitButton(res.getString(R.string.okay)); 78 break; 79 case AdbWirelessDialogUiBase.MODE_QRCODE_FAILED: 80 mUi.setTitle( 81 com.android.settingslib.R.string.adb_pairing_device_dialog_failed_title); 82 mView.findViewById(R.id.l_qrcode_pairing_failed).setVisibility(View.VISIBLE); 83 mUi.setSubmitButton(res.getString(R.string.okay)); 84 break; 85 } 86 87 // After done view show and hide, request focus from parent view 88 mView.findViewById(R.id.l_adbwirelessdialog).requestFocus(); 89 } 90 91 /** 92 * Set the pairing code UI text field to code. 93 * 94 * @param code the pairing code string 95 */ setPairingCode(String code)96 public void setPairingCode(String code) { 97 mSixDigitCode.setText(code); 98 } 99 100 /** 101 * Set the Ip address UI text field to ipAddr. 102 * 103 * @param ipAddr the ip address string 104 */ setIpAddr(String ipAddr)105 public void setIpAddr(String ipAddr) { 106 mIpAddr.setText(ipAddr); 107 } 108 } 109