1 |
2d9fc972
|
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 |
|
|
package org.distorted.dialogs;
|
21 |
|
|
|
22 |
|
|
import android.app.Dialog;
|
23 |
|
|
import android.content.DialogInterface;
|
24 |
|
|
import android.os.Bundle;
|
25 |
fb37b424
|
Leszek Koltunski
|
import android.util.DisplayMetrics;
|
26 |
|
|
import android.util.TypedValue;
|
27 |
2d9fc972
|
Leszek Koltunski
|
import android.view.LayoutInflater;
|
28 |
|
|
import android.view.View;
|
29 |
ffd68f35
|
Leszek Koltunski
|
import android.view.Window;
|
30 |
|
|
import android.view.WindowManager;
|
31 |
fb37b424
|
Leszek Koltunski
|
import android.widget.Button;
|
32 |
2d9fc972
|
Leszek Koltunski
|
import android.widget.TextView;
|
33 |
|
|
|
34 |
|
|
import androidx.annotation.NonNull;
|
35 |
|
|
import androidx.appcompat.app.AlertDialog;
|
36 |
|
|
import androidx.appcompat.app.AppCompatDialogFragment;
|
37 |
|
|
import androidx.fragment.app.FragmentActivity;
|
38 |
|
|
|
39 |
|
|
import org.distorted.main.R;
|
40 |
fb37b424
|
Leszek Koltunski
|
import org.distorted.main.RubikActivity;
|
41 |
2d9fc972
|
Leszek Koltunski
|
|
42 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
43 |
|
|
|
44 |
|
|
public class RubikDialogError extends AppCompatDialogFragment
|
45 |
|
|
{
|
46 |
|
|
@NonNull
|
47 |
|
|
@Override
|
48 |
|
|
public Dialog onCreateDialog(Bundle savedInstanceState)
|
49 |
|
|
{
|
50 |
e7e0a94d
|
Leszek Koltunski
|
final FragmentActivity act = getActivity();
|
51 |
2d9fc972
|
Leszek Koltunski
|
LayoutInflater inflater = act.getLayoutInflater();
|
52 |
|
|
AlertDialog.Builder builder = new AlertDialog.Builder(act);
|
53 |
|
|
|
54 |
fb37b424
|
Leszek Koltunski
|
DisplayMetrics displaymetrics = new DisplayMetrics();
|
55 |
|
|
act.getWindowManager().getDefaultDisplay().getMetrics(displaymetrics);
|
56 |
|
|
final float titleSize= displaymetrics.widthPixels * RubikActivity.MENU_BIG_TEXT_SIZE;
|
57 |
eb376d3a
|
Leszek Koltunski
|
final float okSize = displaymetrics.widthPixels * RubikActivity.DIALOG_BUTTON_SIZE;
|
58 |
fb37b424
|
Leszek Koltunski
|
|
59 |
2d9fc972
|
Leszek Koltunski
|
TextView tv = (TextView) inflater.inflate(R.layout.dialog_title, null);
|
60 |
fb37b424
|
Leszek Koltunski
|
tv.setTextSize(TypedValue.COMPLEX_UNIT_PX, titleSize);
|
61 |
2d9fc972
|
Leszek Koltunski
|
tv.setText(R.string.opengl_error);
|
62 |
|
|
builder.setCustomTitle(tv);
|
63 |
|
|
|
64 |
|
|
final View view = inflater.inflate(R.layout.dialog_error, null);
|
65 |
|
|
TextView text = view.findViewById(R.id.error_string);
|
66 |
e7e0a94d
|
Leszek Koltunski
|
text.setText(R.string.opengl_error_text);
|
67 |
2d9fc972
|
Leszek Koltunski
|
|
68 |
|
|
builder.setPositiveButton( R.string.ok, new DialogInterface.OnClickListener()
|
69 |
|
|
{
|
70 |
|
|
@Override
|
71 |
|
|
public void onClick(DialogInterface dialog, int which)
|
72 |
|
|
{
|
73 |
e7e0a94d
|
Leszek Koltunski
|
act.finish();
|
74 |
2d9fc972
|
Leszek Koltunski
|
}
|
75 |
|
|
});
|
76 |
|
|
|
77 |
|
|
builder.setView(view);
|
78 |
|
|
|
79 |
|
|
final Dialog dialog = builder.create();
|
80 |
|
|
dialog.setCanceledOnTouchOutside(false);
|
81 |
|
|
|
82 |
ffd68f35
|
Leszek Koltunski
|
Window window = dialog.getWindow();
|
83 |
|
|
|
84 |
|
|
if( window!=null )
|
85 |
|
|
{
|
86 |
|
|
window.getDecorView().setSystemUiVisibility(RubikActivity.FLAGS);
|
87 |
|
|
}
|
88 |
|
|
|
89 |
fb37b424
|
Leszek Koltunski
|
dialog.setOnShowListener(new DialogInterface.OnShowListener()
|
90 |
|
|
{
|
91 |
|
|
@Override
|
92 |
|
|
public void onShow(DialogInterface dialog)
|
93 |
|
|
{
|
94 |
|
|
Button btnPositive = ((AlertDialog)dialog).getButton(Dialog.BUTTON_POSITIVE);
|
95 |
|
|
btnPositive.setTextSize(TypedValue.COMPLEX_UNIT_PX, okSize);
|
96 |
|
|
}
|
97 |
|
|
});
|
98 |
|
|
|
99 |
2d9fc972
|
Leszek Koltunski
|
return dialog;
|
100 |
|
|
}
|
101 |
|
|
}
|