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.storagemanager.automatic;
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.content.DialogInterface.OnClickListener;
25 import android.os.Bundle;
26 import com.android.storagemanager.R;
27 
28 /**
29  * Fragment to warn the user about activating the storage manager.
30  */
31 public class WarningDialogFragment extends DialogFragment implements OnClickListener {
32     public static final String TAG = "WarningDialogFragment";
33 
34     /**
35      * Returns a new instance of the WarningDialogFragment.
36      */
newInstance()37     public static WarningDialogFragment newInstance() {
38         return new WarningDialogFragment();
39     }
40 
41     @Override
onCreateDialog(Bundle savedInstanceState)42     public Dialog onCreateDialog(Bundle savedInstanceState) {
43         return new AlertDialog.Builder(getActivity())
44                 .setMessage(R.string.automatic_storage_manager_activation_warning)
45                 .setNegativeButton(android.R.string.ok, (OnClickListener) this)
46                 .create();
47     }
48 
49     @Override
onClick(DialogInterface dialog, int which)50     public void onClick(DialogInterface dialog, int which) {
51         finishActivity();
52     }
53 
54     @Override
onCancel(DialogInterface dialog)55     public void onCancel(DialogInterface dialog) {
56         finishActivity();
57     }
58 
finishActivity()59     private void finishActivity() {
60         Activity activity = getActivity();
61         if (activity != null) {
62             activity.finish();
63         }
64     }
65 }