blob: 9f98b7095891d180b983336d689c0e5c79f1f8fe [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;
23import com.android.wallpaper.model.WallpaperRotationInitializer.NetworkPreference;
24
Sunny Goyal8600a3f2018-08-15 12:48:01 -070025import androidx.annotation.NonNull;
26import androidx.appcompat.app.AlertDialog;
27import androidx.fragment.app.DialogFragment;
28
Jon Miranda16ea1b12017-12-12 14:52:48 -080029/**
30 * Dialog fragment which communicates that starting a wallpaper rotation failed and gives the user
31 * an option to retry starting the rotation.
32 */
33public class StartRotationErrorDialogFragment extends DialogFragment {
34
35 private static final String ARG_NETWORK_PREFERENCE = "network_preference";
36
37 public static StartRotationErrorDialogFragment newInstance(
38 @NetworkPreference int networkPreference) {
39 StartRotationErrorDialogFragment dialogFragment = new StartRotationErrorDialogFragment();
40 Bundle args = new Bundle();
41 args.putInt(ARG_NETWORK_PREFERENCE, networkPreference);
42 dialogFragment.setArguments(args);
43 return dialogFragment;
44 }
45
46 @NonNull
47 @Override
48 public Dialog onCreateDialog(Bundle savedInstanceState) {
49 super.onCreateDialog(savedInstanceState);
50
51 @NetworkPreference final int networkPreference = getArguments().getInt(ARG_NETWORK_PREFERENCE);
52
53 return new AlertDialog.Builder(getActivity(), R.style.LightDialogTheme)
54 .setMessage(getResources().getString(R.string.start_rotation_error_message))
55 .setPositiveButton(com.android.wallpaper.R.string.try_again,
56 new DialogInterface.OnClickListener() {
57 @Override
58 public void onClick(DialogInterface dialogInterface, int i) {
59 Listener callback = (Listener) getTargetFragment();
60 callback.retryStartRotation(networkPreference);
61 }
62 }
63 )
64 .setNegativeButton(android.R.string.cancel, null)
65 .create();
66 }
67
68 /**
69 * Interface which clients of this DialogFragment should implement in order to handle user actions
70 * on the dialog's buttons.
71 */
72 public interface Listener {
73 void retryStartRotation(@NetworkPreference int networkPreference);
74 }
75}