1 /* 2 * Copyright (C) 2023 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.car.settings.wifi.preferences; 18 19 import android.content.Context; 20 import android.graphics.Bitmap; 21 import android.util.AttributeSet; 22 import android.widget.ImageView; 23 import android.widget.TextView; 24 25 import androidx.preference.PreferenceViewHolder; 26 27 import com.android.car.settings.R; 28 import com.android.car.settings.common.Logger; 29 import com.android.car.ui.preference.CarUiPreference; 30 31 /** 32 * A Preference used to show the QR code for the Hotspot. 33 */ 34 public class WifiTetherQrCodePreference extends CarUiPreference { 35 private static final Logger LOG = new Logger(WifiTetherQrCodePreference.class); 36 37 private Bitmap mImage; 38 private String mName; 39 private String mPassword; 40 WifiTetherQrCodePreference( Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes)41 public WifiTetherQrCodePreference( 42 Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) { 43 super(context, attrs, defStyleAttr, defStyleRes); 44 init(); 45 } 46 WifiTetherQrCodePreference(Context context, AttributeSet attrs, int defStyleAttr)47 public WifiTetherQrCodePreference(Context context, AttributeSet attrs, int defStyleAttr) { 48 super(context, attrs, defStyleAttr); 49 init(); 50 } 51 WifiTetherQrCodePreference(Context context, AttributeSet attrs)52 public WifiTetherQrCodePreference(Context context, AttributeSet attrs) { 53 super(context, attrs); 54 init(); 55 } 56 WifiTetherQrCodePreference(Context context)57 public WifiTetherQrCodePreference(Context context) { 58 super(context); 59 init(); 60 } 61 init()62 private void init() { 63 setLayoutResource(R.layout.wifi_tether_qr_code_preference); 64 } 65 66 @Override onBindViewHolder(PreferenceViewHolder holder)67 public void onBindViewHolder(PreferenceViewHolder holder) { 68 super.onBindViewHolder(holder); 69 70 ImageView qrCode = (ImageView) holder.findViewById(R.id.hotspot_qr_code); 71 if (qrCode != null && mImage != null) { 72 qrCode.setImageBitmap(mImage); 73 } else { 74 LOG.v("The QR code ImageView is null"); 75 } 76 77 TextView nameView = (TextView) holder.findViewById(R.id.hotspot_qr_code_instruction); 78 if (nameView != null) { 79 nameView.setText(getContext().getString(R.string.wifi_hotspot_qr_code_text, mName)); 80 } 81 82 TextView passwordView = (TextView) holder.findViewById(R.id.hotspot_qr_code_password); 83 if (passwordView != null) { 84 passwordView.setText( 85 getContext().getString(R.string.wifi_hotspot_qr_code_password_text, mPassword)); 86 } 87 } 88 89 /** 90 * Sets information for this preference. 91 */ setPreferenceInfo(Bitmap bmp, String name, String password)92 public void setPreferenceInfo(Bitmap bmp, String name, String password) { 93 mImage = bmp; 94 mName = name; 95 mPassword = password; 96 97 notifyChanged(); 98 } 99 } 100