Project

General

Profile

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

magiccube / src / main / java / org / distorted / dialogs / RubikDialogNewRecord.java @ 801b16db

1
///////////////////////////////////////////////////////////////////////////////////////////////////
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
package org.distorted.dialogs;
21

    
22
import android.app.Dialog;
23
import android.content.DialogInterface;
24
import android.os.Bundle;
25
import androidx.annotation.NonNull;
26
import androidx.fragment.app.FragmentActivity;
27
import androidx.appcompat.app.AlertDialog;
28
import androidx.appcompat.app.AppCompatDialogFragment;
29
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
import org.distorted.main.R;
36
import org.distorted.main.RubikActivity;
37
import org.distorted.objects.RubikObjectList;
38
import org.distorted.scores.RubikScores;
39
import org.distorted.states.RubikState;
40
import org.distorted.states.RubikStatePlay;
41

    
42
///////////////////////////////////////////////////////////////////////////////////////////////////
43

    
44
public class RubikDialogNewRecord extends AppCompatDialogFragment
45
  {
46
  @Override
47
  public void onStart()
48
    {
49
    super.onStart();
50

    
51
    Dialog dialog = getDialog();
52

    
53
    if( dialog!=null )
54
      {
55
      dialog.setCanceledOnTouchOutside(false);
56

    
57
      Window window = dialog.getWindow();
58

    
59
      if( window!=null )
60
        {
61
        window.clearFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND);
62
        }
63
      }
64
    }
65

    
66
///////////////////////////////////////////////////////////////////////////////////////////////////
67

    
68
  @NonNull
69
  @Override
70
  public Dialog onCreateDialog(Bundle savedInstanceState)
71
    {
72
    FragmentActivity act = getActivity();
73
    LayoutInflater inflater = act.getLayoutInflater();
74
    AlertDialog.Builder builder = new AlertDialog.Builder(act);
75

    
76
    TextView tv = (TextView) inflater.inflate(R.layout.dialog_title, null);
77
    tv.setText(R.string.new_record);
78
    builder.setCustomTitle(tv);
79
    builder.setCancelable(true);
80

    
81
    builder.setPositiveButton( R.string.yes, new DialogInterface.OnClickListener()
82
      {
83
      @Override
84
      public void onClick(DialogInterface dialog, int which)
85
        {
86
        RubikActivity act = (RubikActivity)getActivity();
87
        RubikScores scores = RubikScores.getInstance();
88
        String name = scores.getName();
89
        Bundle bundle = new Bundle();
90
        RubikState.switchState(act,RubikState.PLAY);
91

    
92
        if( name.length()>0 )
93
          {
94
          RubikStatePlay play = (RubikStatePlay) RubikState.PLAY.getStateClass();
95
          int object = play.getObject();
96
          int size   = play.getSize();
97
          int sizeIndex = RubikObjectList.getSizeIndex(object,size);
98

    
99
          bundle.putInt("tab", RubikObjectList.pack(object,sizeIndex) );
100
          bundle.putBoolean("submitting", true);
101

    
102
          RubikDialogScores scoresDiag = new RubikDialogScores();
103
          scoresDiag.setArguments(bundle);
104
          scoresDiag.show(act.getSupportFragmentManager(), null);
105
          }
106
        else
107
          {
108
          bundle.putString("name", name );
109

    
110
          RubikDialogSetName nameDiag = new RubikDialogSetName();
111
          nameDiag.setArguments(bundle);
112
          nameDiag.show(act.getSupportFragmentManager(), null);
113
          }
114
        }
115
      });
116

    
117
    builder.setNegativeButton(R.string.no, new DialogInterface.OnClickListener()
118
      {
119
      @Override
120
      public void onClick(DialogInterface dialog, int which)
121
        {
122
        RubikActivity act = (RubikActivity)getActivity();
123
        RubikState.switchState(act,RubikState.PLAY);
124
        }
125
      });
126

    
127
    Bundle args = getArguments();
128
    long time;
129

    
130
    try
131
      {
132
      time = args.getLong("time");
133
      }
134
    catch(Exception e)
135
      {
136
      time = 0;
137
      }
138

    
139
    final View view = inflater.inflate(R.layout.dialog_new_record, null);
140
    TextView text = view.findViewById(R.id.new_record_time);
141
    text.setText(getString(R.string.ti_placeholder, (time/100)/10.0f));
142
    builder.setView(view);
143

    
144
    return builder.create();
145
    }
146
  }
(4-4/13)