• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 org.drrickorang.loopback;
18 
19 import android.app.Activity;
20 import android.app.AlertDialog;
21 import android.app.Dialog;
22 import android.app.DialogFragment;
23 import android.content.DialogInterface;
24 import android.os.Bundle;
25 
26 /**
27  * Displays an option for saving all files to file://mnt/sdcard/ or choosing filenames
28  */
29 public class SaveFilesDialogFragment extends DialogFragment {
30 
31     /* The activity that creates an instance of this dialog fragment must
32      * implement this interface in order to receive event callbacks. */
33     public interface NoticeDialogListener {
onSaveDialogSelect(DialogFragment dialog, boolean saveWithoutDialog)34         public void onSaveDialogSelect(DialogFragment dialog, boolean saveWithoutDialog);
35     }
36 
37     // Use this instance of the interface to deliver action events
38     NoticeDialogListener mListener;
39 
40     // Override the Fragment.onAttach() method to instantiate the NoticeDialogListener
41     @Override
onAttach(Activity activity)42     public void onAttach(Activity activity) {
43         super.onAttach(activity);
44         // Verify that the host activity implements the callback interface
45         try {
46             // Instantiate the NoticeDialogListener so we can send events to the host
47             mListener = (NoticeDialogListener) activity;
48         } catch (ClassCastException e) {
49             // The activity doesn't implement the interface, throw exception
50             throw new ClassCastException(activity.toString()
51                     + " must implement NoticeDialogListener");
52         }
53     }
54 
55     @Override
onCreateDialog(Bundle savedInstanceState)56     public Dialog onCreateDialog(Bundle savedInstanceState) {
57         AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
58 
59         builder.setMessage(R.string.SaveFileDialogLabel)
60                 .setPositiveButton(R.string.SaveFileDialogOK,
61                         new DialogInterface.OnClickListener() {
62                     public void onClick(DialogInterface dialog, int id) {
63                         dialog.dismiss();
64                         mListener.onSaveDialogSelect(SaveFilesDialogFragment.this, true);
65                     }
66                 })
67                 .setNegativeButton(R.string.SaveFileDialogChooseFilenames,
68                         new DialogInterface.OnClickListener() {
69                     public void onClick(DialogInterface dialog, int id) {
70                         dialog.dismiss();
71                         mListener.onSaveDialogSelect(SaveFilesDialogFragment.this, false);
72                     }
73                 });
74         // Create the AlertDialog object and return it
75         return builder.create();
76     }
77 }
78