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.permissioncontroller.permission.ui.handheld 18 19 import android.app.Application 20 import android.content.Context 21 import android.os.UserHandle 22 import android.widget.ImageButton 23 import androidx.preference.PreferenceViewHolder 24 import com.android.permissioncontroller.R 25 import com.android.permissioncontroller.permission.ui.RemovablePref 26 27 /** 28 * A preference which represents an app that is unused. Has the app icon and label, as well as a 29 * button to uninstall/disable the app, and a button to open the app. 30 * 31 * @param app The current application 32 * @param packageName The name of the package whose icon this preference will retrieve 33 * @param user The user whose package icon will be retrieved 34 * @param context The current context 35 */ 36 class UnusedAppPreference( 37 app: Application, 38 packageName: String, 39 user: UserHandle, 40 context: Context 41 ) : SmartIconLoadPackagePermissionPreference(app, packageName, user, context), RemovablePref { 42 private var removeRunnable: Runnable? = null 43 private var removeButtonEnabled: Boolean = false 44 45 init { 46 widgetLayoutResource = R.xml.uninstall_button_preference_widget 47 } 48 onBindViewHoldernull49 override fun onBindViewHolder(holder: PreferenceViewHolder) { 50 super.onBindViewHolder(holder) 51 52 val removeButton = holder.findViewById(R.id.uninstall_button) as ImageButton 53 removeButton.setOnClickListener { removeRunnable?.run() } 54 removeButton.isEnabled = removeButtonEnabled 55 } 56 setRemoveClickRunnablenull57 override fun setRemoveClickRunnable(runnable: Runnable) { 58 removeRunnable = runnable 59 } 60 setRemoveComponentEnablednull61 override fun setRemoveComponentEnabled(enabled: Boolean) { 62 removeButtonEnabled = enabled 63 } 64 } 65