1
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
2
|
// Copyright 2019 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.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.text.method.LinkMovementMethod;
|
23
|
import android.text.method.MovementMethod;
|
24
|
import android.util.DisplayMetrics;
|
25
|
import android.util.TypedValue;
|
26
|
import android.view.LayoutInflater;
|
27
|
import android.view.View;
|
28
|
import android.view.Window;
|
29
|
import android.widget.Button;
|
30
|
import android.widget.TextView;
|
31
|
|
32
|
import org.distorted.main.R;
|
33
|
import org.distorted.main.RubikActivity;
|
34
|
|
35
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
36
|
|
37
|
public class RubikDialogAbout extends AppCompatDialogFragment
|
38
|
{
|
39
|
@NonNull
|
40
|
@Override
|
41
|
public Dialog onCreateDialog(Bundle savedInstanceState)
|
42
|
{
|
43
|
FragmentActivity act = getActivity();
|
44
|
LayoutInflater inflater = act.getLayoutInflater();
|
45
|
AlertDialog.Builder builder = new AlertDialog.Builder(act);
|
46
|
|
47
|
DisplayMetrics displaymetrics = new DisplayMetrics();
|
48
|
act.getWindowManager().getDefaultDisplay().getMetrics(displaymetrics);
|
49
|
final float titleSize= displaymetrics.widthPixels * RubikActivity.MENU_BIG_TEXT_SIZE;
|
50
|
final float okSize = displaymetrics.widthPixels * RubikActivity.DIALOG_BUTTON_SIZE;
|
51
|
final float textSize = displaymetrics.widthPixels * RubikActivity.MENU_SMALL_TEXT_SIZE;
|
52
|
|
53
|
TextView tv = (TextView) inflater.inflate(R.layout.dialog_title, null);
|
54
|
tv.setTextSize(TypedValue.COMPLEX_UNIT_PX, titleSize);
|
55
|
tv.setText(R.string.about);
|
56
|
builder.setCustomTitle(tv);
|
57
|
|
58
|
builder.setCancelable(true);
|
59
|
builder.setPositiveButton( R.string.ok, new DialogInterface.OnClickListener()
|
60
|
{
|
61
|
@Override
|
62
|
public void onClick(DialogInterface dialog, int which)
|
63
|
{
|
64
|
|
65
|
}
|
66
|
});
|
67
|
|
68
|
final View view = inflater.inflate(R.layout.dialog_about, null);
|
69
|
TextView text = view.findViewById(R.id.about_version);
|
70
|
String appName = getString(R.string.app_name);
|
71
|
|
72
|
text.setTextSize(TypedValue.COMPLEX_UNIT_PX, textSize);
|
73
|
text.setText(getString(R.string.ap_placeholder,appName, getAppVers(act)));
|
74
|
|
75
|
MovementMethod mm = LinkMovementMethod.getInstance();
|
76
|
TextView text2 = view.findViewById(R.id.about_section2);
|
77
|
text2.setTextSize(TypedValue.COMPLEX_UNIT_PX, textSize);
|
78
|
text2.setMovementMethod(mm);
|
79
|
TextView text3 = view.findViewById(R.id.about_section3);
|
80
|
text3.setTextSize(TypedValue.COMPLEX_UNIT_PX, textSize);
|
81
|
|
82
|
TextView text4 = view.findViewById(R.id.about_section4);
|
83
|
|
84
|
if( RubikActivity.localeIsChinese() )
|
85
|
{
|
86
|
text4.setTextSize(TypedValue.COMPLEX_UNIT_PX, textSize);
|
87
|
text4.setMovementMethod(mm);
|
88
|
}
|
89
|
else
|
90
|
{
|
91
|
text4.setVisibility(View.GONE);
|
92
|
/*
|
93
|
String version = DistortedLibrary.getDriverVersion();
|
94
|
String vendor = DistortedLibrary.getDriverVendor();
|
95
|
String renderer= DistortedLibrary.getDriverRenderer();
|
96
|
|
97
|
String mess = "Version: " + version + "\nVendor: "+vendor+"\nRenderer: "+renderer;
|
98
|
text4.setTextSize(TypedValue.COMPLEX_UNIT_PX, textSize);
|
99
|
text4.setText(mess);
|
100
|
*/
|
101
|
}
|
102
|
|
103
|
builder.setView(view);
|
104
|
|
105
|
Dialog dialog = builder.create();
|
106
|
dialog.setCanceledOnTouchOutside(false);
|
107
|
Window window = dialog.getWindow();
|
108
|
|
109
|
if( window!=null )
|
110
|
{
|
111
|
window.getDecorView().setSystemUiVisibility(RubikActivity.FLAGS);
|
112
|
}
|
113
|
|
114
|
dialog.setOnShowListener(new DialogInterface.OnShowListener()
|
115
|
{
|
116
|
@Override
|
117
|
public void onShow(DialogInterface dialog)
|
118
|
{
|
119
|
Button btnPositive = ((AlertDialog)dialog).getButton(Dialog.BUTTON_POSITIVE);
|
120
|
btnPositive.setTextSize(TypedValue.COMPLEX_UNIT_PX, okSize);
|
121
|
}
|
122
|
});
|
123
|
|
124
|
return dialog;
|
125
|
}
|
126
|
|
127
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
128
|
|
129
|
private String getAppVers(FragmentActivity act)
|
130
|
{
|
131
|
try
|
132
|
{
|
133
|
PackageInfo pInfo = act.getPackageManager().getPackageInfo( act.getPackageName(), 0);
|
134
|
return pInfo.versionName;
|
135
|
}
|
136
|
catch (PackageManager.NameNotFoundException e)
|
137
|
{
|
138
|
return "unknown";
|
139
|
}
|
140
|
}
|
141
|
}
|