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
|
|
30
|
import android.util.DisplayMetrics;
|
31
|
import android.util.TypedValue;
|
32
|
import android.view.LayoutInflater;
|
33
|
import android.view.View;
|
34
|
import android.view.Window;
|
35
|
import android.view.WindowManager;
|
36
|
import android.widget.Button;
|
37
|
import android.widget.TextView;
|
38
|
|
39
|
import org.distorted.main.R;
|
40
|
import org.distorted.main.RubikActivity;
|
41
|
import org.distorted.objects.RubikObjectList;
|
42
|
import org.distorted.scores.RubikScores;
|
43
|
import org.distorted.states.RubikState;
|
44
|
import org.distorted.states.RubikStatePlay;
|
45
|
|
46
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
47
|
|
48
|
public class RubikDialogNewRecord extends AppCompatDialogFragment
|
49
|
{
|
50
|
@Override
|
51
|
public void onStart()
|
52
|
{
|
53
|
super.onStart();
|
54
|
|
55
|
Dialog dialog = getDialog();
|
56
|
|
57
|
if( dialog!=null )
|
58
|
{
|
59
|
dialog.setCanceledOnTouchOutside(false);
|
60
|
|
61
|
Window window = dialog.getWindow();
|
62
|
|
63
|
if( window!=null )
|
64
|
{
|
65
|
window.clearFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND);
|
66
|
}
|
67
|
}
|
68
|
}
|
69
|
|
70
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
71
|
|
72
|
@NonNull
|
73
|
@Override
|
74
|
public Dialog onCreateDialog(Bundle savedInstanceState)
|
75
|
{
|
76
|
FragmentActivity act = getActivity();
|
77
|
LayoutInflater inflater = act.getLayoutInflater();
|
78
|
AlertDialog.Builder builder = new AlertDialog.Builder(act);
|
79
|
|
80
|
DisplayMetrics displaymetrics = new DisplayMetrics();
|
81
|
act.getWindowManager().getDefaultDisplay().getMetrics(displaymetrics);
|
82
|
final float titleSize= displaymetrics.widthPixels * RubikActivity.MENU_BIG_TEXT_SIZE;
|
83
|
final float okSize = displaymetrics.widthPixels * RubikActivity.MENU_MEDIUM_TEXT_SIZE;
|
84
|
final float textSize = displaymetrics.widthPixels * RubikActivity.MENU_BIG_TEXT_SIZE;
|
85
|
|
86
|
TextView tv = (TextView) inflater.inflate(R.layout.dialog_title, null);
|
87
|
tv.setTextSize(TypedValue.COMPLEX_UNIT_PX, titleSize);
|
88
|
tv.setText(R.string.new_record);
|
89
|
builder.setCustomTitle(tv);
|
90
|
builder.setCancelable(true);
|
91
|
|
92
|
builder.setPositiveButton( R.string.yes, new DialogInterface.OnClickListener()
|
93
|
{
|
94
|
@Override
|
95
|
public void onClick(DialogInterface dialog, int which)
|
96
|
{
|
97
|
RubikActivity act = (RubikActivity)getActivity();
|
98
|
RubikScores scores = RubikScores.getInstance();
|
99
|
String name = scores.getName();
|
100
|
Bundle bundle = new Bundle();
|
101
|
RubikState.switchState(act,RubikState.PLAY);
|
102
|
|
103
|
if( name.length()>0 )
|
104
|
{
|
105
|
RubikStatePlay play = (RubikStatePlay) RubikState.PLAY.getStateClass();
|
106
|
int object = play.getObject();
|
107
|
int size = play.getSize();
|
108
|
int sizeIndex = RubikObjectList.getSizeIndex(object,size);
|
109
|
|
110
|
bundle.putInt("tab", RubikObjectList.pack(object,sizeIndex) );
|
111
|
bundle.putBoolean("submitting", true);
|
112
|
|
113
|
RubikDialogScores scoresDiag = new RubikDialogScores();
|
114
|
scoresDiag.setArguments(bundle);
|
115
|
scoresDiag.show(act.getSupportFragmentManager(), null);
|
116
|
}
|
117
|
else
|
118
|
{
|
119
|
bundle.putString("name", name );
|
120
|
|
121
|
RubikDialogSetName nameDiag = new RubikDialogSetName();
|
122
|
nameDiag.setArguments(bundle);
|
123
|
nameDiag.show(act.getSupportFragmentManager(), null);
|
124
|
}
|
125
|
}
|
126
|
});
|
127
|
|
128
|
builder.setNegativeButton(R.string.no, new DialogInterface.OnClickListener()
|
129
|
{
|
130
|
@Override
|
131
|
public void onClick(DialogInterface dialog, int which)
|
132
|
{
|
133
|
RubikActivity act = (RubikActivity)getActivity();
|
134
|
RubikState.switchState(act,RubikState.PLAY);
|
135
|
}
|
136
|
});
|
137
|
|
138
|
Bundle args = getArguments();
|
139
|
long time;
|
140
|
|
141
|
try
|
142
|
{
|
143
|
time = args.getLong("time");
|
144
|
}
|
145
|
catch(Exception e)
|
146
|
{
|
147
|
time = 0;
|
148
|
}
|
149
|
|
150
|
final View view = inflater.inflate(R.layout.dialog_new_record, null);
|
151
|
TextView text = view.findViewById(R.id.new_record_time);
|
152
|
text.setTextSize(TypedValue.COMPLEX_UNIT_PX, textSize);
|
153
|
text.setText(getString(R.string.ti_placeholder, (time/10)/100.0f));
|
154
|
builder.setView(view);
|
155
|
|
156
|
TextView submit = view.findViewById(R.id.new_record_submit);
|
157
|
submit.setTextSize(TypedValue.COMPLEX_UNIT_PX, textSize);
|
158
|
|
159
|
Dialog dialog = builder.create();
|
160
|
|
161
|
dialog.setCanceledOnTouchOutside(false);
|
162
|
|
163
|
Window window = dialog.getWindow();
|
164
|
|
165
|
if( window!=null )
|
166
|
{
|
167
|
window.clearFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND);
|
168
|
window.setFlags(WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE, WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE);
|
169
|
window.getDecorView().setSystemUiVisibility(RubikActivity.FLAGS);
|
170
|
}
|
171
|
|
172
|
dialog.setOnShowListener(new DialogInterface.OnShowListener()
|
173
|
{
|
174
|
@Override
|
175
|
public void onShow(DialogInterface dialog)
|
176
|
{
|
177
|
Button btnPositive = ((AlertDialog)dialog).getButton(Dialog.BUTTON_POSITIVE);
|
178
|
btnPositive.setTextSize(TypedValue.COMPLEX_UNIT_PX, okSize);
|
179
|
Button btnNegative = ((AlertDialog)dialog).getButton(Dialog.BUTTON_NEGATIVE);
|
180
|
btnNegative.setTextSize(TypedValue.COMPLEX_UNIT_PX, okSize);
|
181
|
}
|
182
|
});
|
183
|
|
184
|
return dialog;
|
185
|
}
|
186
|
}
|