Home | History | Annotate | Download | only in app
      1 /*
      2  * Copyright (C) 2015 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 androidx.appcompat.app;
     18 
     19 
     20 import static androidx.annotation.RestrictTo.Scope.LIBRARY_GROUP;
     21 
     22 import android.app.Dialog;
     23 import android.os.Bundle;
     24 import android.view.Window;
     25 import android.view.WindowManager;
     26 
     27 import androidx.annotation.RestrictTo;
     28 import androidx.fragment.app.DialogFragment;
     29 
     30 /**
     31  * A special version of {@link DialogFragment} which uses an {@link AppCompatDialog} in place of a
     32  * platform-styled dialog.
     33  *
     34  * @see DialogFragment
     35  */
     36 public class AppCompatDialogFragment extends DialogFragment {
     37 
     38     @Override
     39     public Dialog onCreateDialog(Bundle savedInstanceState) {
     40         return new AppCompatDialog(getContext(), getTheme());
     41     }
     42 
     43     /** @hide */
     44     @RestrictTo(LIBRARY_GROUP)
     45     @Override
     46     public void setupDialog(Dialog dialog, int style) {
     47         if (dialog instanceof AppCompatDialog) {
     48             // If the dialog is an AppCompatDialog, we'll handle it
     49             AppCompatDialog acd = (AppCompatDialog) dialog;
     50             switch (style) {
     51                 case STYLE_NO_INPUT:
     52                     dialog.getWindow().addFlags(
     53                             WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE |
     54                                     WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE);
     55                     // fall through...
     56                 case STYLE_NO_FRAME:
     57                 case STYLE_NO_TITLE:
     58                     acd.supportRequestWindowFeature(Window.FEATURE_NO_TITLE);
     59             }
     60         } else {
     61             // Else, just let super handle it
     62             super.setupDialog(dialog, style);
     63         }
     64     }
     65 
     66 }
     67