1 /* 2 * Copyright (C) 2016 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.incallui.video.impl; 18 19 import android.app.AlertDialog; 20 import android.app.Dialog; 21 import android.content.DialogInterface; 22 import android.os.Bundle; 23 import android.support.annotation.NonNull; 24 import android.support.v4.app.DialogFragment; 25 import com.android.dialer.common.FragmentUtils; 26 27 /** Dialog fragment to ask for camera permission from user. */ 28 public class CameraPermissionDialogFragment extends DialogFragment { 29 30 static CameraPermissionDialogFragment newInstance() { 31 CameraPermissionDialogFragment fragment = new CameraPermissionDialogFragment(); 32 return fragment; 33 } 34 35 @NonNull 36 @Override 37 public Dialog onCreateDialog(Bundle bundle) { 38 return new AlertDialog.Builder(getContext()) 39 .setTitle(R.string.camera_permission_dialog_title) 40 .setMessage(R.string.camera_permission_dialog_message) 41 .setPositiveButton( 42 R.string.camera_permission_dialog_positive_button, 43 new DialogInterface.OnClickListener() { 44 @Override 45 public void onClick(DialogInterface dialog, int which) { 46 CameraPermissionDialogCallback fragment = 47 FragmentUtils.getParentUnsafe( 48 CameraPermissionDialogFragment.this, CameraPermissionDialogCallback.class); 49 fragment.onCameraPermissionGranted(); 50 } 51 }) 52 .setNegativeButton( 53 R.string.camera_permission_dialog_negative_button, 54 new DialogInterface.OnClickListener() { 55 @Override 56 public void onClick(DialogInterface dialog, int which) { 57 dialog.dismiss(); 58 } 59 }) 60 .create(); 61 } 62 63 /** Callback for being granted camera permission. */ 64 public interface CameraPermissionDialogCallback { 65 void onCameraPermissionGranted(); 66 } 67 } 68