blob: 23a64178e101d8a1c26e9e53694171a915a5e99d [file] [log] [blame]
Jon Miranda16ea1b12017-12-12 14:52:48 -08001/*
2 * Copyright (C) 2017 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 */
16package com.android.wallpaper.picker;
17
18import android.app.Dialog;
19import android.content.DialogInterface;
20import android.os.Bundle;
21import android.support.annotation.NonNull;
22import android.support.v4.app.DialogFragment;
23import android.support.v7.app.AlertDialog;
24
25import com.android.wallpaper.R;
26
27/**
28 * Dialog fragment which communicates a message that loading the wallpaper failed with an OK button,
29 * when clicked will navigate the user back to the previous activity.
30 */
31public class LoadWallpaperErrorDialogFragment extends DialogFragment {
32
33 public static LoadWallpaperErrorDialogFragment newInstance() {
34 return new LoadWallpaperErrorDialogFragment();
35 }
36
37 @Override
38 @NonNull
39 public Dialog onCreateDialog(Bundle savedInstanceState) {
40 super.onCreateDialog(savedInstanceState);
41
42 return new AlertDialog.Builder(getActivity(), R.style.LightDialogTheme)
43 .setMessage(R.string.load_wallpaper_error_message)
44 .setPositiveButton(android.R.string.ok,
45 new DialogInterface.OnClickListener() {
46 @Override
47 public void onClick(DialogInterface dialogInterface, int i) {
48 Listener callback = (Listener) getTargetFragment();
49 callback.onClickOk();
50 }
51 }
52 )
53 .create();
54 }
55
56 @Override
57 public void onDismiss(DialogInterface dialogInterface) {
58 super.onDismiss(dialogInterface);
59
60 // Treat a dismissal by user click outside the dialog foreground the same as the user clicking
61 // "OK" to dismiss the dialog.
62 Listener callback = (Listener) getTargetFragment();
63 callback.onClickOk();
64 }
65
66 /**
67 * Interface which clients of this DialogFragment should implement in order to handle user actions
68 * on the dialog's buttons.
69 */
70 public interface Listener {
71 void onClickOk();
72 }
73}