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.states.StateList;
|
42
|
|
43
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
44
|
|
45
|
public class RubikDialogSolved extends AppCompatDialogFragment
|
46
|
{
|
47
|
@NonNull
|
48
|
@Override
|
49
|
public Dialog onCreateDialog(Bundle savedInstanceState)
|
50
|
{
|
51
|
FragmentActivity act = getActivity();
|
52
|
LayoutInflater inflater = act.getLayoutInflater();
|
53
|
AlertDialog.Builder builder = new AlertDialog.Builder(act);
|
54
|
|
55
|
DisplayMetrics displaymetrics = new DisplayMetrics();
|
56
|
act.getWindowManager().getDefaultDisplay().getMetrics(displaymetrics);
|
57
|
final float titleSize= displaymetrics.widthPixels * RubikActivity.MENU_BIG_TEXT_SIZE;
|
58
|
final float okSize = displaymetrics.widthPixels * RubikActivity.DIALOG_BUTTON_SIZE;
|
59
|
final float textSize = displaymetrics.widthPixels * RubikActivity.MENU_BIG_TEXT_SIZE;
|
60
|
|
61
|
TextView tv = (TextView) inflater.inflate(R.layout.dialog_title, null);
|
62
|
tv.setTextSize(TypedValue.COMPLEX_UNIT_PX, titleSize);
|
63
|
tv.setText(R.string.solved);
|
64
|
builder.setCustomTitle(tv);
|
65
|
|
66
|
builder.setCancelable(true);
|
67
|
builder.setPositiveButton( R.string.ok, new DialogInterface.OnClickListener()
|
68
|
{
|
69
|
@Override
|
70
|
public void onClick(DialogInterface dialog, int which)
|
71
|
{
|
72
|
RubikActivity act = (RubikActivity)getActivity();
|
73
|
StateList.switchState(act, StateList.PLAY);
|
74
|
}
|
75
|
});
|
76
|
|
77
|
Bundle args = getArguments();
|
78
|
long time;
|
79
|
|
80
|
try
|
81
|
{
|
82
|
time = args.getLong("time");
|
83
|
}
|
84
|
catch(Exception e)
|
85
|
{
|
86
|
time = 0;
|
87
|
}
|
88
|
|
89
|
final View view = inflater.inflate(R.layout.dialog_solved, null);
|
90
|
TextView text = view.findViewById(R.id.solved_time);
|
91
|
text.setTextSize(TypedValue.COMPLEX_UNIT_PX, textSize);
|
92
|
text.setText(getString(R.string.ti_placeholder, (time/10)/100.0f));
|
93
|
builder.setView(view);
|
94
|
|
95
|
Dialog dialog = builder.create();
|
96
|
dialog.setCanceledOnTouchOutside(false);
|
97
|
Window window = dialog.getWindow();
|
98
|
|
99
|
if( window!=null )
|
100
|
{
|
101
|
window.getDecorView().setSystemUiVisibility(RubikActivity.FLAGS);
|
102
|
}
|
103
|
|
104
|
dialog.setOnShowListener(new DialogInterface.OnShowListener()
|
105
|
{
|
106
|
@Override
|
107
|
public void onShow(DialogInterface dialog)
|
108
|
{
|
109
|
Button btnPositive = ((AlertDialog)dialog).getButton(Dialog.BUTTON_POSITIVE);
|
110
|
btnPositive.setTextSize(TypedValue.COMPLEX_UNIT_PX, okSize);
|
111
|
}
|
112
|
});
|
113
|
|
114
|
return dialog;
|
115
|
}
|
116
|
|
117
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
118
|
|
119
|
public static String getDialogTag()
|
120
|
{
|
121
|
return "DialogSolved";
|
122
|
}
|
123
|
}
|