1 /* 2 * Copyright (C) 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 * 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.wm.shell.apptoweb 18 import android.content.Context 19 import android.graphics.drawable.Drawable 20 import android.util.AttributeSet 21 import android.view.View 22 import android.widget.Button 23 import androidx.constraintlayout.widget.ConstraintLayout 24 import com.android.wm.shell.R 25 26 /** View for open by default settings dialog for an application which allows the user to change 27 * where links will open by default, in the default browser or in the application. */ 28 class OpenByDefaultDialogView @JvmOverloads constructor( 29 context: Context, 30 attrs: AttributeSet? = null, 31 defStyleAttr: Int = 0, 32 defStyleRes: Int = 0 33 ) : ConstraintLayout(context, attrs, defStyleAttr, defStyleRes) { 34 35 private lateinit var dialogContainer: View 36 private lateinit var backgroundDim: Drawable 37 setDismissOnClickListenernull38 fun setDismissOnClickListener(callback: (View) -> Unit) { 39 // Clicks on the background dim should also dismiss the dialog. 40 setOnClickListener(callback) 41 // We add a no-op on-click listener to the dialog container so that clicks on it won't 42 // propagate to the listener of the layout (which represents the background dim). 43 dialogContainer.setOnClickListener { } 44 } 45 setConfirmButtonClickListenernull46 fun setConfirmButtonClickListener(callback: (View) -> Unit) { 47 val dismissButton = dialogContainer.requireViewById<Button>( 48 R.id.open_by_default_settings_dialog_confirm_button 49 ) 50 dismissButton.setOnClickListener(callback) 51 } 52 onFinishInflatenull53 override fun onFinishInflate() { 54 super.onFinishInflate() 55 dialogContainer = requireViewById(R.id.open_by_default_dialog_container) 56 backgroundDim = background.mutate() 57 backgroundDim.alpha = 128 58 } 59 } 60