Project

General

Profile

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

magiccube / src / main / java / org / distorted / dialog / RubikDialogNewRecord.java @ 53f23b64

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.dialog;
21

    
22
import android.app.Dialog;
23
import android.content.DialogInterface;
24
import android.os.Bundle;
25
import android.support.annotation.NonNull;
26
import android.support.v4.app.FragmentActivity;
27
import android.support.v7.app.AlertDialog;
28
import android.support.v7.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.magic.R;
36
import org.distorted.magic.RubikActivity;
37
import org.distorted.object.RubikObjectList;
38
import org.distorted.scores.RubikScores;
39
import org.distorted.uistate.RubikState;
40
import org.distorted.uistate.RubikStatePlay;
41

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

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

    
51
    Window window = getDialog().getWindow();
52
    window.setFlags(WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL,
53
                    WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL);
54
    window.clearFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND);
55
    }
56

    
57
///////////////////////////////////////////////////////////////////////////////////////////////////
58

    
59
  @NonNull
60
  @Override
61
  public Dialog onCreateDialog(Bundle savedInstanceState)
62
    {
63
    FragmentActivity act = getActivity();
64
    LayoutInflater inflater = act.getLayoutInflater();
65
    AlertDialog.Builder builder = new AlertDialog.Builder(act);
66

    
67
    TextView tv = (TextView) inflater.inflate(R.layout.dialog_title, null);
68
    tv.setText(R.string.new_record);
69
    builder.setCustomTitle(tv);
70
    builder.setCancelable(true);
71

    
72
    builder.setPositiveButton( R.string.yes, new DialogInterface.OnClickListener()
73
      {
74
      @Override
75
      public void onClick(DialogInterface dialog, int which)
76
        {
77
        RubikActivity act = (RubikActivity)getActivity();
78
        RubikScores scores = RubikScores.getInstance();
79
        String name = scores.getName();
80
        Bundle bundle = new Bundle();
81
        RubikState.switchState(act,RubikState.PLAY);
82

    
83
        if( name.length()>0 )
84
          {
85
          RubikStatePlay play = (RubikStatePlay) RubikState.PLAY.getStateClass();
86
          int object = play.getObject();
87
          int size   = play.getSize();
88
          int sizeIndex = RubikObjectList.getSizeIndex(object,size);
89

    
90
          bundle.putInt("tab", RubikObjectList.pack(object,sizeIndex) );
91
          bundle.putBoolean("submitting", true);
92

    
93
          RubikDialogScores scoresDiag = new RubikDialogScores();
94
          scoresDiag.setArguments(bundle);
95
          scoresDiag.show(act.getSupportFragmentManager(), null);
96
          }
97
        else
98
          {
99
          bundle.putString("name", name );
100

    
101
          RubikDialogSetName nameDiag = new RubikDialogSetName();
102
          nameDiag.setArguments(bundle);
103
          nameDiag.show(act.getSupportFragmentManager(), null);
104
          }
105
        }
106
      });
107

    
108
    builder.setNegativeButton(R.string.no, new DialogInterface.OnClickListener()
109
      {
110
      @Override
111
      public void onClick(DialogInterface dialog, int which)
112
        {
113
        RubikActivity act = (RubikActivity)getActivity();
114
        RubikState.switchState(act,RubikState.PLAY);
115
        }
116
      });
117

    
118
    Bundle args = getArguments();
119
    long time;
120

    
121
    try
122
      {
123
      time = args.getLong("time");
124
      }
125
    catch(Exception e)
126
      {
127
      time = 0;
128
      }
129

    
130
    final View view = inflater.inflate(R.layout.dialog_new_record, null);
131
    TextView text = view.findViewById(R.id.new_record_time);
132
    text.setText(getString(R.string.ti_placeholder, (time/100)/10.0f));
133
    builder.setView(view);
134

    
135
    return builder.create();
136
    }
137
  }
(4-4/9)