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