Project

General

Profile

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

magiccube / src / main / java / org / distorted / dialogs / RubikDialogNewRecord.java @ 66e777b0

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
    dialog.setCanceledOnTouchOutside(false);
53

    
54
    Window window = dialog.getWindow();
55

    
56
    if( window!=null )
57
      {
58
      window.setFlags(WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL,
59
                      WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL);
60
      window.clearFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND);
61
      }
62
    }
63

    
64
///////////////////////////////////////////////////////////////////////////////////////////////////
65

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

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

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

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

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

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

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

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

    
125
    Bundle args = getArguments();
126
    long time;
127

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

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

    
142
    return builder.create();
143
    }
144
  }
(4-4/13)