1 |
1cbcc6bf
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
2 |
|
|
// Copyright 2019 Leszek Koltunski //
|
3 |
|
|
// //
|
4 |
fdec60a3
|
Leszek Koltunski
|
// This file is part of Magic Cube. //
|
5 |
1cbcc6bf
|
Leszek Koltunski
|
// //
|
6 |
fdec60a3
|
Leszek Koltunski
|
// Magic Cube is free software: you can redistribute it and/or modify //
|
7 |
1cbcc6bf
|
Leszek Koltunski
|
// 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 |
fdec60a3
|
Leszek Koltunski
|
// Magic Cube is distributed in the hope that it will be useful, //
|
12 |
1cbcc6bf
|
Leszek Koltunski
|
// 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 |
fdec60a3
|
Leszek Koltunski
|
// along with Magic Cube. If not, see <http://www.gnu.org/licenses/>. //
|
18 |
1cbcc6bf
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
19 |
|
|
|
20 |
1f9772f3
|
Leszek Koltunski
|
package org.distorted.dialogs;
|
21 |
1cbcc6bf
|
Leszek Koltunski
|
|
22 |
|
|
import android.app.Dialog;
|
23 |
|
|
import android.content.DialogInterface;
|
24 |
1780dcb0
|
Leszek Koltunski
|
import android.content.pm.PackageInfo;
|
25 |
|
|
import android.content.pm.PackageManager;
|
26 |
1cbcc6bf
|
Leszek Koltunski
|
import android.os.Bundle;
|
27 |
66e777b0
|
Leszek Koltunski
|
import androidx.annotation.NonNull;
|
28 |
|
|
import androidx.fragment.app.FragmentActivity;
|
29 |
|
|
import androidx.appcompat.app.AlertDialog;
|
30 |
|
|
import androidx.appcompat.app.AppCompatDialogFragment;
|
31 |
703aee64
|
Leszek Koltunski
|
|
32 |
|
|
import android.text.method.LinkMovementMethod;
|
33 |
1780dcb0
|
Leszek Koltunski
|
import android.text.method.MovementMethod;
|
34 |
2eb74743
|
Leszek Koltunski
|
import android.util.DisplayMetrics;
|
35 |
|
|
import android.util.TypedValue;
|
36 |
1cbcc6bf
|
Leszek Koltunski
|
import android.view.LayoutInflater;
|
37 |
|
|
import android.view.View;
|
38 |
4235de9b
|
Leszek Koltunski
|
import android.view.Window;
|
39 |
2eb74743
|
Leszek Koltunski
|
import android.widget.Button;
|
40 |
0fd3ac1f
|
Leszek Koltunski
|
import android.widget.TextView;
|
41 |
1cbcc6bf
|
Leszek Koltunski
|
|
42 |
1f9772f3
|
Leszek Koltunski
|
import org.distorted.main.R;
|
43 |
2eb74743
|
Leszek Koltunski
|
import org.distorted.main.RubikActivity;
|
44 |
211b48f2
|
Leszek Koltunski
|
|
45 |
1cbcc6bf
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
46 |
|
|
|
47 |
0fd3ac1f
|
Leszek Koltunski
|
public class RubikDialogAbout extends AppCompatDialogFragment
|
48 |
1cbcc6bf
|
Leszek Koltunski
|
{
|
49 |
|
|
@NonNull
|
50 |
|
|
@Override
|
51 |
|
|
public Dialog onCreateDialog(Bundle savedInstanceState)
|
52 |
|
|
{
|
53 |
|
|
FragmentActivity act = getActivity();
|
54 |
0fd3ac1f
|
Leszek Koltunski
|
LayoutInflater inflater = act.getLayoutInflater();
|
55 |
1cbcc6bf
|
Leszek Koltunski
|
AlertDialog.Builder builder = new AlertDialog.Builder(act);
|
56 |
|
|
|
57 |
2eb74743
|
Leszek Koltunski
|
DisplayMetrics displaymetrics = new DisplayMetrics();
|
58 |
|
|
act.getWindowManager().getDefaultDisplay().getMetrics(displaymetrics);
|
59 |
|
|
final float titleSize= displaymetrics.widthPixels * RubikActivity.MENU_BIG_TEXT_SIZE;
|
60 |
eb376d3a
|
Leszek Koltunski
|
final float okSize = displaymetrics.widthPixels * RubikActivity.DIALOG_BUTTON_SIZE;
|
61 |
2eb74743
|
Leszek Koltunski
|
final float textSize = displaymetrics.widthPixels * RubikActivity.MENU_SMALL_TEXT_SIZE;
|
62 |
|
|
|
63 |
0fd3ac1f
|
Leszek Koltunski
|
TextView tv = (TextView) inflater.inflate(R.layout.dialog_title, null);
|
64 |
2eb74743
|
Leszek Koltunski
|
tv.setTextSize(TypedValue.COMPLEX_UNIT_PX, titleSize);
|
65 |
4235de9b
|
Leszek Koltunski
|
tv.setText(R.string.about);
|
66 |
0fd3ac1f
|
Leszek Koltunski
|
builder.setCustomTitle(tv);
|
67 |
|
|
|
68 |
|
|
builder.setCancelable(true);
|
69 |
1cbcc6bf
|
Leszek Koltunski
|
builder.setPositiveButton( R.string.ok, new DialogInterface.OnClickListener()
|
70 |
|
|
{
|
71 |
|
|
@Override
|
72 |
|
|
public void onClick(DialogInterface dialog, int which)
|
73 |
|
|
{
|
74 |
|
|
|
75 |
|
|
}
|
76 |
|
|
});
|
77 |
|
|
|
78 |
0fd3ac1f
|
Leszek Koltunski
|
final View view = inflater.inflate(R.layout.dialog_about, null);
|
79 |
|
|
TextView text = view.findViewById(R.id.about_version);
|
80 |
329c0aeb
|
Leszek Koltunski
|
String appName = getString(R.string.app_name);
|
81 |
1780dcb0
|
Leszek Koltunski
|
|
82 |
2eb74743
|
Leszek Koltunski
|
text.setTextSize(TypedValue.COMPLEX_UNIT_PX, textSize);
|
83 |
b1e9596b
|
Leszek Koltunski
|
text.setText(getString(R.string.ap_placeholder,appName, getAppVers(act)));
|
84 |
703aee64
|
Leszek Koltunski
|
|
85 |
1780dcb0
|
Leszek Koltunski
|
MovementMethod mm = LinkMovementMethod.getInstance();
|
86 |
703aee64
|
Leszek Koltunski
|
TextView text1 = view.findViewById(R.id.about_section1);
|
87 |
2eb74743
|
Leszek Koltunski
|
text1.setTextSize(TypedValue.COMPLEX_UNIT_PX, textSize);
|
88 |
1780dcb0
|
Leszek Koltunski
|
text1.setMovementMethod(mm);
|
89 |
703aee64
|
Leszek Koltunski
|
TextView text2 = view.findViewById(R.id.about_section2);
|
90 |
2eb74743
|
Leszek Koltunski
|
text2.setTextSize(TypedValue.COMPLEX_UNIT_PX, textSize);
|
91 |
1780dcb0
|
Leszek Koltunski
|
text2.setMovementMethod(mm);
|
92 |
|
|
TextView text3 = view.findViewById(R.id.about_section3);
|
93 |
2eb74743
|
Leszek Koltunski
|
text3.setTextSize(TypedValue.COMPLEX_UNIT_PX, textSize);
|
94 |
1780dcb0
|
Leszek Koltunski
|
text3.setMovementMethod(mm);
|
95 |
703aee64
|
Leszek Koltunski
|
|
96 |
b1e9596b
|
Leszek Koltunski
|
TextView text4 = view.findViewById(R.id.about_section4);
|
97 |
|
|
|
98 |
|
|
if( RubikActivity.localeIsChinese() )
|
99 |
|
|
{
|
100 |
|
|
text4.setTextSize(TypedValue.COMPLEX_UNIT_PX, textSize);
|
101 |
|
|
text4.setMovementMethod(mm);
|
102 |
|
|
}
|
103 |
|
|
else
|
104 |
|
|
{
|
105 |
|
|
text4.setVisibility(View.GONE);
|
106 |
6a083c6a
|
Leszek Koltunski
|
/*
|
107 |
|
|
text4.setTextSize(TypedValue.COMPLEX_UNIT_PX, textSize);
|
108 |
|
|
String version = DistortedLibrary.getDriverVersion();
|
109 |
|
|
text4.setText(version);
|
110 |
|
|
*/
|
111 |
b1e9596b
|
Leszek Koltunski
|
}
|
112 |
|
|
|
113 |
1cbcc6bf
|
Leszek Koltunski
|
builder.setView(view);
|
114 |
|
|
|
115 |
85248b04
|
Leszek Koltunski
|
Dialog dialog = builder.create();
|
116 |
|
|
dialog.setCanceledOnTouchOutside(false);
|
117 |
|
|
Window window = dialog.getWindow();
|
118 |
|
|
|
119 |
|
|
if( window!=null )
|
120 |
|
|
{
|
121 |
ffd68f35
|
Leszek Koltunski
|
window.getDecorView().setSystemUiVisibility(RubikActivity.FLAGS);
|
122 |
85248b04
|
Leszek Koltunski
|
}
|
123 |
|
|
|
124 |
2eb74743
|
Leszek Koltunski
|
dialog.setOnShowListener(new DialogInterface.OnShowListener()
|
125 |
|
|
{
|
126 |
|
|
@Override
|
127 |
|
|
public void onShow(DialogInterface dialog)
|
128 |
|
|
{
|
129 |
|
|
Button btnPositive = ((AlertDialog)dialog).getButton(Dialog.BUTTON_POSITIVE);
|
130 |
|
|
btnPositive.setTextSize(TypedValue.COMPLEX_UNIT_PX, okSize);
|
131 |
|
|
}
|
132 |
|
|
});
|
133 |
|
|
|
134 |
85248b04
|
Leszek Koltunski
|
return dialog;
|
135 |
1cbcc6bf
|
Leszek Koltunski
|
}
|
136 |
b1e9596b
|
Leszek Koltunski
|
|
137 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
138 |
|
|
|
139 |
|
|
private String getAppVers(FragmentActivity act)
|
140 |
|
|
{
|
141 |
|
|
try
|
142 |
|
|
{
|
143 |
|
|
PackageInfo pInfo = act.getPackageManager().getPackageInfo( act.getPackageName(), 0);
|
144 |
|
|
return pInfo.versionName;
|
145 |
|
|
}
|
146 |
|
|
catch (PackageManager.NameNotFoundException e)
|
147 |
|
|
{
|
148 |
|
|
return "unknown";
|
149 |
|
|
}
|
150 |
|
|
}
|
151 |
1cbcc6bf
|
Leszek Koltunski
|
}
|