1 /* 2 * Copyright 2024 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 * https://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.devicediagnostics 18 19 import android.content.Intent 20 import android.os.Bundle 21 import android.provider.Settings 22 import androidx.fragment.app.commit 23 import androidx.preference.Preference 24 import androidx.preference.PreferenceFragmentCompat 25 import com.android.devicediagnostics.evaluated.QrCodeScanActivity 26 import com.android.settingslib.collapsingtoolbar.CollapsingToolbarBaseActivity 27 28 class EvaluationModeFragment : PreferenceFragmentCompat() { onCreatePreferencesnull29 override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) { 30 setPreferencesFromResource(R.xml.evaluation_mode_landing, rootKey) 31 } 32 onResumenull33 override fun onResume() { 34 super.onResume() 35 36 val btServer = ApplicationInterface.app.getBluetoothServer() 37 val enabled = btServer.bluetoothEnabled 38 findPreference<Preference>("trusted_device")!!.isVisible = enabled 39 findPreference<Preference>("evaluation_mode")!!.also { 40 it.isVisible = enabled 41 it.setOnPreferenceClickListener { 42 val intent = Intent() 43 intent.setClassName(activity!!, QrCodeScanActivity::class.java.name) 44 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK) 45 startActivity(intent) 46 true 47 } 48 } 49 findPreference<Preference>("bluetooth_disabled")!!.also { 50 it.isVisible = !enabled 51 it.setOnPreferenceClickListener { 52 startActivity(Intent().setAction(Settings.ACTION_BLUETOOTH_SETTINGS)) 53 true 54 } 55 } 56 } 57 } 58 59 class EvaluationModeActivity : CollapsingToolbarBaseActivity() { onCreatenull60 override fun onCreate(savedInstanceState: Bundle?) { 61 super.onCreate(savedInstanceState) 62 setContentView(R.layout.activity_one_fragment) 63 setTitle(R.string.evaluation_mode_title) 64 65 if (savedInstanceState == null) { 66 supportFragmentManager.commit { 67 setReorderingAllowed(true) 68 add(R.id.fragment_container_view, EvaluationModeFragment()) 69 } 70 } 71 } 72 } 73