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