|
1
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
|
2
|
// Copyright 2020 Leszek Koltunski //
|
|
3
|
// //
|
|
4
|
// This file is part of Magic Cube. //
|
|
5
|
// //
|
|
6
|
// Magic Cube is proprietary software licensed under an EULA which you should have received //
|
|
7
|
// along with the code. If not, check https://distorted.org/magic/License-Magic-Cube.html //
|
|
8
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
|
9
|
|
|
10
|
package org.distorted.dialogs;
|
|
11
|
|
|
12
|
import android.app.Dialog;
|
|
13
|
import android.content.DialogInterface;
|
|
14
|
import android.os.Bundle;
|
|
15
|
import androidx.annotation.NonNull;
|
|
16
|
import androidx.fragment.app.FragmentActivity;
|
|
17
|
import androidx.appcompat.app.AlertDialog;
|
|
18
|
import androidx.appcompat.app.AppCompatDialogFragment;
|
|
19
|
|
|
20
|
import android.util.DisplayMetrics;
|
|
21
|
import android.util.TypedValue;
|
|
22
|
import android.view.LayoutInflater;
|
|
23
|
import android.view.View;
|
|
24
|
import android.view.Window;
|
|
25
|
import android.widget.Button;
|
|
26
|
import android.widget.TextView;
|
|
27
|
|
|
28
|
import org.distorted.main.R;
|
|
29
|
import org.distorted.main.RubikActivity;
|
|
30
|
import org.distorted.screens.ScreenList;
|
|
31
|
|
|
32
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
|
33
|
|
|
34
|
public class RubikDialogSolved extends AppCompatDialogFragment
|
|
35
|
{
|
|
36
|
@NonNull
|
|
37
|
@Override
|
|
38
|
public Dialog onCreateDialog(Bundle savedInstanceState)
|
|
39
|
{
|
|
40
|
FragmentActivity act = getActivity();
|
|
41
|
LayoutInflater inflater = act.getLayoutInflater();
|
|
42
|
AlertDialog.Builder builder = new AlertDialog.Builder(act);
|
|
43
|
|
|
44
|
DisplayMetrics displaymetrics = new DisplayMetrics();
|
|
45
|
act.getWindowManager().getDefaultDisplay().getMetrics(displaymetrics);
|
|
46
|
int h = displaymetrics.heightPixels;
|
|
47
|
final float titleSize= h*0.032f;
|
|
48
|
final float okSize = h*0.040f;
|
|
49
|
final float textSize = h*0.022f;
|
|
50
|
|
|
51
|
TextView tv = (TextView) inflater.inflate(R.layout.dialog_title, null);
|
|
52
|
tv.setTextSize(TypedValue.COMPLEX_UNIT_PX, titleSize);
|
|
53
|
tv.setText(R.string.solved);
|
|
54
|
builder.setCustomTitle(tv);
|
|
55
|
|
|
56
|
builder.setCancelable(true);
|
|
57
|
builder.setPositiveButton( R.string.ok, new DialogInterface.OnClickListener()
|
|
58
|
{
|
|
59
|
@Override
|
|
60
|
public void onClick(DialogInterface dialog, int which)
|
|
61
|
{
|
|
62
|
RubikActivity act = (RubikActivity)getActivity();
|
|
63
|
ScreenList.switchScreen(act, ScreenList.PLAY);
|
|
64
|
}
|
|
65
|
});
|
|
66
|
|
|
67
|
Bundle args = getArguments();
|
|
68
|
long time;
|
|
69
|
|
|
70
|
try
|
|
71
|
{
|
|
72
|
time = args.getLong("time");
|
|
73
|
}
|
|
74
|
catch(Exception e)
|
|
75
|
{
|
|
76
|
time = 0;
|
|
77
|
}
|
|
78
|
|
|
79
|
final View view = inflater.inflate(R.layout.dialog_solved, null);
|
|
80
|
TextView text = view.findViewById(R.id.solved_time);
|
|
81
|
text.setTextSize(TypedValue.COMPLEX_UNIT_PX, textSize);
|
|
82
|
text.setText(getString(R.string.ti_placeholder, (time/10)/100.0f));
|
|
83
|
builder.setView(view);
|
|
84
|
|
|
85
|
Dialog dialog = builder.create();
|
|
86
|
dialog.setCanceledOnTouchOutside(false);
|
|
87
|
Window window = dialog.getWindow();
|
|
88
|
|
|
89
|
if( window!=null )
|
|
90
|
{
|
|
91
|
window.getDecorView().setSystemUiVisibility(RubikActivity.FLAGS);
|
|
92
|
}
|
|
93
|
|
|
94
|
dialog.setOnShowListener(new DialogInterface.OnShowListener()
|
|
95
|
{
|
|
96
|
@Override
|
|
97
|
public void onShow(DialogInterface dialog)
|
|
98
|
{
|
|
99
|
Button btnPositive = ((AlertDialog)dialog).getButton(Dialog.BUTTON_POSITIVE);
|
|
100
|
btnPositive.setTextSize(TypedValue.COMPLEX_UNIT_PX, okSize);
|
|
101
|
}
|
|
102
|
});
|
|
103
|
|
|
104
|
return dialog;
|
|
105
|
}
|
|
106
|
|
|
107
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
|
108
|
|
|
109
|
public static String getDialogTag()
|
|
110
|
{
|
|
111
|
return "DialogSolved";
|
|
112
|
}
|
|
113
|
}
|