• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2021 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.ui.appstyledview;
18 
19 import android.app.Dialog;
20 import android.content.Context;
21 import android.content.DialogInterface;
22 import android.os.Bundle;
23 import android.view.View;
24 import android.view.Window;
25 import android.view.WindowManager;
26 
27 import androidx.annotation.NonNull;
28 
29 import com.android.car.ui.appstyledview.AppStyledViewController.AppStyledDismissListener;
30 
31 /**
32  * App styled dialog used to display a view that cannot be customized via OEM. Dialog will inflate a
33  * layout and add the view provided by the application into the layout. Everything other than the
34  * view within the layout can be customized by OEM.
35  *
36  * Apps should not use this directly. App's should use {@link AppStyledDialogController}.
37  */
38 public class AppStyledDialog extends Dialog implements DialogInterface.OnDismissListener {
39 
40     private final AppStyledViewController mController;
41     private AppStyledDismissListener mOnDismissListener;
42     private View mContent;
43 
AppStyledDialog(@onNull Context context, AppStyledViewController controller)44     public AppStyledDialog(@NonNull Context context, AppStyledViewController controller) {
45         super(context);
46         mController = controller;
47         setOnDismissListener(this);
48     }
49 
50     @Override
onCreate(Bundle savedInstanceState)51     protected void onCreate(Bundle savedInstanceState) {
52         super.onCreate(savedInstanceState);
53         requestWindowFeature(Window.FEATURE_NO_TITLE);
54         setContentView(mController.getAppStyledView(mContent));
55 
56         WindowManager.LayoutParams params = getWindow().getAttributes();
57         getWindow().setAttributes(mController.getDialogWindowLayoutParam(params));
58     }
59 
60     @Override
onDismiss(DialogInterface dialog)61     public void onDismiss(DialogInterface dialog) {
62         if (mOnDismissListener != null) {
63             mOnDismissListener.onDismiss();
64         }
65     }
66 
setContent(View contentView)67     void setContent(View contentView) {
68         mContent = contentView;
69     }
70 
setOnDismissListener(AppStyledDismissListener listener)71     void setOnDismissListener(AppStyledDismissListener listener) {
72         mOnDismissListener = listener;
73     }
74 
getWindowLayoutParams()75     WindowManager.LayoutParams getWindowLayoutParams() {
76         return getWindow().getAttributes();
77     }
78 }
79