1 |
bc511ea5
|
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 |
bc511ea5
|
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 |
bc511ea5
|
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.objects.RubikObjectList;
|
38 |
f895e77a
|
Leszek Koltunski
|
import org.distorted.scores.RubikScores;
|
39 |
1f9772f3
|
Leszek Koltunski
|
import org.distorted.states.RubikState;
|
40 |
|
|
import org.distorted.states.RubikStatePlay;
|
41 |
bc511ea5
|
Leszek Koltunski
|
|
42 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
43 |
|
|
|
44 |
|
|
public class RubikDialogNewRecord extends AppCompatDialogFragment
|
45 |
|
|
{
|
46 |
|
|
@Override
|
47 |
|
|
public void onStart()
|
48 |
|
|
{
|
49 |
|
|
super.onStart();
|
50 |
|
|
|
51 |
584585d0
|
Leszek Koltunski
|
Dialog dialog = getDialog();
|
52 |
|
|
|
53 |
801b16db
|
Leszek Koltunski
|
if( dialog!=null )
|
54 |
584585d0
|
Leszek Koltunski
|
{
|
55 |
801b16db
|
Leszek Koltunski
|
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 |
584585d0
|
Leszek Koltunski
|
}
|
64 |
bc511ea5
|
Leszek Koltunski
|
}
|
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 |
f895e77a
|
Leszek Koltunski
|
|
81 |
bc511ea5
|
Leszek Koltunski
|
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 |
f895e77a
|
Leszek Koltunski
|
RubikScores scores = RubikScores.getInstance();
|
88 |
|
|
String name = scores.getName();
|
89 |
4895fff6
|
Leszek Koltunski
|
Bundle bundle = new Bundle();
|
90 |
f895e77a
|
Leszek Koltunski
|
RubikState.switchState(act,RubikState.PLAY);
|
91 |
4895fff6
|
Leszek Koltunski
|
|
92 |
f895e77a
|
Leszek Koltunski
|
if( name.length()>0 )
|
93 |
|
|
{
|
94 |
|
|
RubikStatePlay play = (RubikStatePlay) RubikState.PLAY.getStateClass();
|
95 |
|
|
int object = play.getObject();
|
96 |
|
|
int size = play.getSize();
|
97 |
53f23b64
|
Leszek Koltunski
|
int sizeIndex = RubikObjectList.getSizeIndex(object,size);
|
98 |
f895e77a
|
Leszek Koltunski
|
|
99 |
53f23b64
|
Leszek Koltunski
|
bundle.putInt("tab", RubikObjectList.pack(object,sizeIndex) );
|
100 |
f895e77a
|
Leszek Koltunski
|
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 |
bc511ea5
|
Leszek Koltunski
|
}
|
115 |
|
|
});
|
116 |
f895e77a
|
Leszek Koltunski
|
|
117 |
bc511ea5
|
Leszek Koltunski
|
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 |
85248b04
|
Leszek Koltunski
|
Dialog dialog = builder.create();
|
145 |
|
|
|
146 |
|
|
dialog.setCanceledOnTouchOutside(false);
|
147 |
|
|
|
148 |
|
|
Window window = dialog.getWindow();
|
149 |
|
|
|
150 |
|
|
if( window!=null )
|
151 |
|
|
{
|
152 |
|
|
window.clearFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND);
|
153 |
|
|
}
|
154 |
|
|
|
155 |
|
|
return dialog;
|
156 |
bc511ea5
|
Leszek Koltunski
|
}
|
157 |
|
|
}
|