Project

General

Profile

Download (4.01 KB) Statistics
| Branch: | Tag: | Revision:

magiccube / src / main / java / org / distorted / dialogs / RubikDialogSolved.java @ 90fd47b0

1 e41e7dc3 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
2
// Copyright 2020 Leszek Koltunski                                                               //
3
//                                                                                               //
4
// This file is part of Magic Cube.                                                              //
5
//                                                                                               //
6
// Magic Cube is free software: you can redistribute it and/or modify                            //
7
// it under the terms of the GNU General Public License as published by                          //
8
// the Free Software Foundation, either version 2 of the License, or                             //
9
// (at your option) any later version.                                                           //
10
//                                                                                               //
11
// Magic Cube is distributed in the hope that it will be useful,                                 //
12
// but WITHOUT ANY WARRANTY; without even the implied warranty of                                //
13
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the                                 //
14
// GNU General Public License for more details.                                                  //
15
//                                                                                               //
16
// You should have received a copy of the GNU General Public License                             //
17
// along with Magic Cube.  If not, see <http://www.gnu.org/licenses/>.                           //
18
///////////////////////////////////////////////////////////////////////////////////////////////////
19
20 1f9772f3 Leszek Koltunski
package org.distorted.dialogs;
21 e41e7dc3 Leszek Koltunski
22
import android.app.Dialog;
23
import android.content.DialogInterface;
24
import android.os.Bundle;
25 66e777b0 Leszek Koltunski
import androidx.annotation.NonNull;
26
import androidx.fragment.app.FragmentActivity;
27
import androidx.appcompat.app.AlertDialog;
28
import androidx.appcompat.app.AppCompatDialogFragment;
29 e41e7dc3 Leszek Koltunski
import android.view.LayoutInflater;
30
import android.view.View;
31
import android.view.Window;
32
import android.view.WindowManager;
33
import android.widget.TextView;
34
35 1f9772f3 Leszek Koltunski
import org.distorted.main.R;
36
import org.distorted.main.RubikActivity;
37
import org.distorted.states.RubikState;
38 e41e7dc3 Leszek Koltunski
39
///////////////////////////////////////////////////////////////////////////////////////////////////
40
41
public class RubikDialogSolved extends AppCompatDialogFragment
42
  {
43
  @Override
44
  public void onStart()
45
    {
46
    super.onStart();
47
48 584585d0 Leszek Koltunski
    Dialog dialog = getDialog();
49
    dialog.setCanceledOnTouchOutside(false);
50
51
    Window window = dialog.getWindow();
52
53
    if( window!=null )
54
      {
55
      window.clearFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND);
56
      }
57 e41e7dc3 Leszek Koltunski
    }
58
59
///////////////////////////////////////////////////////////////////////////////////////////////////
60
61
  @NonNull
62
  @Override
63
  public Dialog onCreateDialog(Bundle savedInstanceState)
64
    {
65
    FragmentActivity act = getActivity();
66
    LayoutInflater inflater = act.getLayoutInflater();
67
    AlertDialog.Builder builder = new AlertDialog.Builder(act);
68
69
    TextView tv = (TextView) inflater.inflate(R.layout.dialog_title, null);
70
    tv.setText(R.string.solved);
71
    builder.setCustomTitle(tv);
72
73
    builder.setCancelable(true);
74
    builder.setPositiveButton( R.string.ok, new DialogInterface.OnClickListener()
75
      {
76
      @Override
77
      public void onClick(DialogInterface dialog, int which)
78
        {
79
        RubikActivity act = (RubikActivity)getActivity();
80
        RubikState.switchState(act,RubikState.PLAY);
81
        }
82
      });
83
84
    Bundle args = getArguments();
85
    long time;
86
87
    try
88
      {
89
      time = args.getLong("time");
90
      }
91
    catch(Exception e)
92
      {
93
      time = 0;
94
      }
95
96
    final View view = inflater.inflate(R.layout.dialog_solved, null);
97
    TextView text = view.findViewById(R.id.solved_time);
98
    text.setText(getString(R.string.ti_placeholder, (time/100)/10.0f));
99
    builder.setView(view);
100
101
    return builder.create();
102
    }
103
  }