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
|
|
31
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
32
|
|
33
|
public class RubikDialogSolverError extends AppCompatDialogFragment
|
34
|
{
|
35
|
@NonNull
|
36
|
@Override
|
37
|
public Dialog onCreateDialog(Bundle savedInstanceState)
|
38
|
{
|
39
|
FragmentActivity act = getActivity();
|
40
|
LayoutInflater inflater = act.getLayoutInflater();
|
41
|
AlertDialog.Builder builder = new AlertDialog.Builder(act);
|
42
|
|
43
|
DisplayMetrics displaymetrics = new DisplayMetrics();
|
44
|
act.getWindowManager().getDefaultDisplay().getMetrics(displaymetrics);
|
45
|
final float titleSize= displaymetrics.widthPixels * RubikActivity.MENU_BIG_TEXT_SIZE;
|
46
|
final float okSize = displaymetrics.widthPixels * RubikActivity.DIALOG_BUTTON_SIZE;
|
47
|
final float textSize = displaymetrics.widthPixels * RubikActivity.MENU_BIG_TEXT_SIZE;
|
48
|
|
49
|
TextView tv = (TextView) inflater.inflate(R.layout.dialog_title, null);
|
50
|
tv.setTextSize(TypedValue.COMPLEX_UNIT_PX, titleSize);
|
51
|
tv.setText(R.string.error);
|
52
|
builder.setCustomTitle(tv);
|
53
|
|
54
|
builder.setCancelable(true);
|
55
|
builder.setPositiveButton( R.string.ok, new DialogInterface.OnClickListener()
|
56
|
{
|
57
|
@Override
|
58
|
public void onClick(DialogInterface dialog, int which)
|
59
|
{
|
60
|
|
61
|
}
|
62
|
});
|
63
|
|
64
|
Bundle args = getArguments();
|
65
|
String errorStr;
|
66
|
|
67
|
try
|
68
|
{
|
69
|
errorStr = args.getString("error");
|
70
|
}
|
71
|
catch(Exception e)
|
72
|
{
|
73
|
errorStr = "Error";
|
74
|
}
|
75
|
|
76
|
final View view = inflater.inflate(R.layout.dialog_solver_error, null);
|
77
|
TextView text = view.findViewById(R.id.solver_error);
|
78
|
text.setTextSize(TypedValue.COMPLEX_UNIT_PX, textSize);
|
79
|
text.setText(errorStr);
|
80
|
builder.setView(view);
|
81
|
|
82
|
Dialog dialog = builder.create();
|
83
|
dialog.setCanceledOnTouchOutside(false);
|
84
|
Window window = dialog.getWindow();
|
85
|
|
86
|
if( window!=null )
|
87
|
{
|
88
|
window.getDecorView().setSystemUiVisibility(RubikActivity.FLAGS);
|
89
|
}
|
90
|
|
91
|
dialog.setOnShowListener(new DialogInterface.OnShowListener()
|
92
|
{
|
93
|
@Override
|
94
|
public void onShow(DialogInterface dialog)
|
95
|
{
|
96
|
Button btnPositive = ((AlertDialog)dialog).getButton(Dialog.BUTTON_POSITIVE);
|
97
|
btnPositive.setTextSize(TypedValue.COMPLEX_UNIT_PX, okSize);
|
98
|
}
|
99
|
});
|
100
|
|
101
|
return dialog;
|
102
|
}
|
103
|
}
|