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.documentsui; 18 19 import android.annotation.IntDef; 20 import android.app.Dialog; 21 import android.app.DialogFragment; 22 import android.app.FragmentManager; 23 import android.app.FragmentTransaction; 24 import android.content.DialogInterface; 25 import android.net.Uri; 26 import android.os.Bundle; 27 import android.support.v7.app.AlertDialog; 28 import android.text.Html; 29 30 import com.android.documentsui.base.DocumentInfo; 31 import com.android.documentsui.base.DocumentStack; 32 import com.android.documentsui.services.FileOperationService; 33 import com.android.documentsui.services.FileOperationService.OpType; 34 import com.android.documentsui.ui.MessageBuilder; 35 36 import java.lang.annotation.Retention; 37 import java.lang.annotation.RetentionPolicy; 38 import java.util.ArrayList; 39 40 /** 41 * Alert dialog for operation dialogs. 42 */ 43 public class OperationDialogFragment extends DialogFragment { 44 45 public static final int DIALOG_TYPE_UNKNOWN = 0; 46 public static final int DIALOG_TYPE_FAILURE = 1; 47 public static final int DIALOG_TYPE_CONVERTED = 2; 48 49 @IntDef(flag = true, value = { 50 DIALOG_TYPE_UNKNOWN, 51 DIALOG_TYPE_FAILURE, 52 DIALOG_TYPE_CONVERTED 53 }) 54 55 @Retention(RetentionPolicy.SOURCE) 56 public @interface DialogType {} 57 58 private static final String TAG = "OperationDialogFragment"; 59 60 public static void show( 61 FragmentManager fm, 62 @DialogType int dialogType, 63 ArrayList<DocumentInfo> failedSrcList, 64 ArrayList<Uri> uriList, 65 DocumentStack dstStack, 66 @OpType int operationType) { 67 68 final Bundle args = new Bundle(); 69 args.putInt(FileOperationService.EXTRA_DIALOG_TYPE, dialogType); 70 args.putInt(FileOperationService.EXTRA_OPERATION_TYPE, operationType); 71 args.putParcelableArrayList(FileOperationService.EXTRA_FAILED_DOCS, failedSrcList); 72 args.putParcelableArrayList(FileOperationService.EXTRA_FAILED_URIS, uriList); 73 74 final FragmentTransaction ft = fm.beginTransaction(); 75 final OperationDialogFragment fragment = new OperationDialogFragment(); 76 fragment.setArguments(args); 77 78 ft.add(fragment, TAG); 79 ft.commitAllowingStateLoss(); 80 } 81 82 @Override 83 public Dialog onCreateDialog(Bundle inState) { 84 super.onCreate(inState); 85 86 final @DialogType int dialogType = 87 getArguments().getInt(FileOperationService.EXTRA_DIALOG_TYPE); 88 final @OpType int operationType = 89 getArguments().getInt(FileOperationService.EXTRA_OPERATION_TYPE); 90 final ArrayList<Uri> uriList = getArguments().getParcelableArrayList( 91 FileOperationService.EXTRA_FAILED_URIS); 92 final ArrayList<DocumentInfo> docList = getArguments().getParcelableArrayList( 93 FileOperationService.EXTRA_FAILED_DOCS); 94 95 final AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); 96 final String message = new MessageBuilder(getContext()).generateListMessage( 97 dialogType, operationType, docList, uriList); 98 99 builder.setMessage(Html.fromHtml(message)); 100 builder.setPositiveButton( 101 R.string.close, 102 new DialogInterface.OnClickListener() { 103 @Override 104 public void onClick(DialogInterface dialog, int id) { 105 dialog.dismiss(); 106 } 107 }); 108 109 return builder.create(); 110 } 111 } 112