Jon Miranda | 16ea1b1 | 2017-12-12 14:52:48 -0800 | [diff] [blame] | 1 | /* |
| 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 | */ |
| 16 | package com.android.wallpaper.picker; |
| 17 | |
Chuck Liao | f646e05 | 2020-09-24 12:24:59 +0800 | [diff] [blame] | 18 | import android.app.AlertDialog; |
Jon Miranda | 16ea1b1 | 2017-12-12 14:52:48 -0800 | [diff] [blame] | 19 | import android.app.Dialog; |
| 20 | import android.content.DialogInterface; |
| 21 | import android.os.Bundle; |
Jon Miranda | 16ea1b1 | 2017-12-12 14:52:48 -0800 | [diff] [blame] | 22 | |
| 23 | import com.android.wallpaper.R; |
| 24 | |
Sunny Goyal | 8600a3f | 2018-08-15 12:48:01 -0700 | [diff] [blame] | 25 | import androidx.annotation.NonNull; |
Sunny Goyal | 8600a3f | 2018-08-15 12:48:01 -0700 | [diff] [blame] | 26 | import androidx.fragment.app.DialogFragment; |
| 27 | |
Jon Miranda | 16ea1b1 | 2017-12-12 14:52:48 -0800 | [diff] [blame] | 28 | /** |
| 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 | */ |
| 32 | public 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 | } |