1
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
2
|
// Copyright 2022 Leszek Koltunski //
|
3
|
// //
|
4
|
// This file is part of Magic Sokoban. //
|
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.content.pm.PackageInfo;
|
15
|
import android.content.pm.PackageManager;
|
16
|
import android.os.Bundle;
|
17
|
import androidx.annotation.NonNull;
|
18
|
import androidx.fragment.app.FragmentActivity;
|
19
|
import androidx.appcompat.app.AlertDialog;
|
20
|
import androidx.appcompat.app.AppCompatDialogFragment;
|
21
|
|
22
|
import android.util.DisplayMetrics;
|
23
|
import android.util.TypedValue;
|
24
|
import android.view.LayoutInflater;
|
25
|
import android.view.View;
|
26
|
import android.view.Window;
|
27
|
import android.widget.Button;
|
28
|
import android.widget.TextView;
|
29
|
|
30
|
import org.distorted.sokoban.R;
|
31
|
import org.distorted.sokoban.SokobanActivity;
|
32
|
|
33
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
34
|
|
35
|
public class SokobanDialogAbout extends AppCompatDialogFragment
|
36
|
{
|
37
|
@NonNull
|
38
|
@Override
|
39
|
public Dialog onCreateDialog(Bundle savedInstanceState)
|
40
|
{
|
41
|
FragmentActivity act = getActivity();
|
42
|
LayoutInflater inflater = act.getLayoutInflater();
|
43
|
AlertDialog.Builder builder = new AlertDialog.Builder(act);
|
44
|
|
45
|
DisplayMetrics displaymetrics = new DisplayMetrics();
|
46
|
act.getWindowManager().getDefaultDisplay().getMetrics(displaymetrics);
|
47
|
final float titleSize= displaymetrics.widthPixels * SokobanActivity.MENU_BIG_TEXT_SIZE;
|
48
|
final float okSize = displaymetrics.widthPixels * SokobanActivity.DIALOG_BUTTON_SIZE;
|
49
|
final float textSize = displaymetrics.widthPixels * SokobanActivity.MENU_SMALL_TEXT_SIZE;
|
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.about);
|
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
|
|
63
|
}
|
64
|
});
|
65
|
|
66
|
final View view = inflater.inflate(R.layout.dialog_about, null);
|
67
|
TextView text = view.findViewById(R.id.about_version);
|
68
|
String appName = getString(R.string.app_name);
|
69
|
|
70
|
text.setTextSize(TypedValue.COMPLEX_UNIT_PX, textSize);
|
71
|
text.setText(getString(R.string.ap_placeholder,appName, getAppVers(act)));
|
72
|
|
73
|
TextView help = view.findViewById(R.id.about_help);
|
74
|
help.setTextSize(TypedValue.COMPLEX_UNIT_PX, textSize);
|
75
|
|
76
|
builder.setView(view);
|
77
|
|
78
|
Dialog dialog = builder.create();
|
79
|
dialog.setCanceledOnTouchOutside(false);
|
80
|
Window window = dialog.getWindow();
|
81
|
|
82
|
if( window!=null )
|
83
|
{
|
84
|
window.getDecorView().setSystemUiVisibility(SokobanActivity.FLAGS);
|
85
|
}
|
86
|
|
87
|
dialog.setOnShowListener(new DialogInterface.OnShowListener()
|
88
|
{
|
89
|
@Override
|
90
|
public void onShow(DialogInterface dialog)
|
91
|
{
|
92
|
Button btnPositive = ((AlertDialog)dialog).getButton(Dialog.BUTTON_POSITIVE);
|
93
|
btnPositive.setTextSize(TypedValue.COMPLEX_UNIT_PX, okSize);
|
94
|
}
|
95
|
});
|
96
|
|
97
|
return dialog;
|
98
|
}
|
99
|
|
100
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
101
|
|
102
|
private String getAppVers(FragmentActivity act)
|
103
|
{
|
104
|
try
|
105
|
{
|
106
|
PackageInfo pInfo = act.getPackageManager().getPackageInfo( act.getPackageName(), 0);
|
107
|
return pInfo.versionName;
|
108
|
}
|
109
|
catch (PackageManager.NameNotFoundException e)
|
110
|
{
|
111
|
return "unknown";
|
112
|
}
|
113
|
}
|
114
|
}
|