1 |
d05e7629
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
2 |
|
|
// Copyright 2022 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 android.util.DisplayMetrics;
|
16 |
|
|
import android.util.TypedValue;
|
17 |
|
|
import android.view.LayoutInflater;
|
18 |
|
|
import android.view.View;
|
19 |
|
|
import android.view.Window;
|
20 |
|
|
import android.widget.Button;
|
21 |
24cd23dd
|
Leszek Koltunski
|
import android.widget.LinearLayout;
|
22 |
4d6327a1
|
Leszek Koltunski
|
import android.widget.TextView;
|
23 |
d05e7629
|
Leszek Koltunski
|
|
24 |
|
|
import androidx.annotation.NonNull;
|
25 |
|
|
import androidx.appcompat.app.AlertDialog;
|
26 |
|
|
import androidx.appcompat.app.AppCompatDialogFragment;
|
27 |
|
|
import androidx.fragment.app.FragmentActivity;
|
28 |
|
|
|
29 |
4d6327a1
|
Leszek Koltunski
|
import org.distorted.external.RubikScores;
|
30 |
d05e7629
|
Leszek Koltunski
|
import org.distorted.main.R;
|
31 |
|
|
import org.distorted.main.RubikActivity;
|
32 |
|
|
|
33 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
34 |
|
|
|
35 |
4d6327a1
|
Leszek Koltunski
|
public class RubikDialogStarsStatus extends AppCompatDialogFragment
|
36 |
d05e7629
|
Leszek Koltunski
|
{
|
37 |
24cd23dd
|
Leszek Koltunski
|
private static final float LAYOUT_HEIGHT = 0.110f;
|
38 |
|
|
private static final float MARGIN = 0.007f;
|
39 |
|
|
|
40 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
41 |
|
|
|
42 |
d05e7629
|
Leszek Koltunski
|
@NonNull
|
43 |
|
|
@Override
|
44 |
|
|
public Dialog onCreateDialog(Bundle savedInstanceState)
|
45 |
|
|
{
|
46 |
|
|
FragmentActivity act = getActivity();
|
47 |
|
|
LayoutInflater inflater = act.getLayoutInflater();
|
48 |
|
|
AlertDialog.Builder builder = new AlertDialog.Builder(act);
|
49 |
|
|
DisplayMetrics displaymetrics = new DisplayMetrics();
|
50 |
|
|
act.getWindowManager().getDefaultDisplay().getMetrics(displaymetrics);
|
51 |
|
|
final float butSize = displaymetrics.widthPixels * RubikActivity.DIALOG_BUTTON_SIZE;
|
52 |
4d6327a1
|
Leszek Koltunski
|
final View view = inflater.inflate(R.layout.dialog_stars_status, null);
|
53 |
d05e7629
|
Leszek Koltunski
|
|
54 |
24cd23dd
|
Leszek Koltunski
|
int height = (int)(displaymetrics.heightPixels*LAYOUT_HEIGHT);
|
55 |
|
|
int margin = (int)(displaymetrics.heightPixels*MARGIN);
|
56 |
|
|
|
57 |
|
|
LinearLayout.LayoutParams params1 = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,LinearLayout.LayoutParams.WRAP_CONTENT);
|
58 |
|
|
params1.setMargins(margin, margin, margin, margin);
|
59 |
|
|
LinearLayout.LayoutParams params2 = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,height);
|
60 |
|
|
params2.setMargins(margin, margin, margin, margin);
|
61 |
|
|
|
62 |
|
|
LinearLayout lm = view.findViewById(R.id.stars_main);
|
63 |
|
|
lm.setPadding(margin,margin,margin,margin);
|
64 |
|
|
|
65 |
|
|
LinearLayout ls = view.findViewById(R.id.stars_strings);
|
66 |
|
|
ls.setLayoutParams(params1);
|
67 |
|
|
LinearLayout l1 = view.findViewById(R.id.stars_layout_1);
|
68 |
|
|
l1.setLayoutParams(params2);
|
69 |
|
|
LinearLayout l2 = view.findViewById(R.id.stars_layout_2);
|
70 |
|
|
l2.setLayoutParams(params2);
|
71 |
|
|
LinearLayout l3 = view.findViewById(R.id.stars_layout_3);
|
72 |
|
|
l3.setLayoutParams(params2);
|
73 |
|
|
|
74 |
4d6327a1
|
Leszek Koltunski
|
fillUpNumberOfStars(view);
|
75 |
45831b78
|
Leszek Koltunski
|
|
76 |
d05e7629
|
Leszek Koltunski
|
builder.setCancelable(true);
|
77 |
|
|
|
78 |
|
|
builder.setPositiveButton( R.string.ok, new DialogInterface.OnClickListener()
|
79 |
|
|
{
|
80 |
|
|
@Override
|
81 |
|
|
public void onClick(DialogInterface dialog, int which) { }
|
82 |
|
|
});
|
83 |
|
|
|
84 |
|
|
builder.setView(view);
|
85 |
|
|
|
86 |
|
|
final Dialog dialog = builder.create();
|
87 |
|
|
dialog.setCanceledOnTouchOutside(false);
|
88 |
|
|
Window window = dialog.getWindow();
|
89 |
|
|
|
90 |
|
|
if( window!=null )
|
91 |
|
|
{
|
92 |
|
|
window.getDecorView().setSystemUiVisibility(RubikActivity.FLAGS);
|
93 |
|
|
}
|
94 |
|
|
|
95 |
|
|
dialog.setOnShowListener(new DialogInterface.OnShowListener()
|
96 |
|
|
{
|
97 |
|
|
@Override
|
98 |
|
|
public void onShow(DialogInterface dialog)
|
99 |
|
|
{
|
100 |
|
|
Button btnPositive = ((AlertDialog)dialog).getButton(Dialog.BUTTON_POSITIVE);
|
101 |
|
|
btnPositive.setTextSize(TypedValue.COMPLEX_UNIT_PX, butSize);
|
102 |
|
|
}
|
103 |
|
|
});
|
104 |
|
|
|
105 |
|
|
return dialog;
|
106 |
|
|
}
|
107 |
4d6327a1
|
Leszek Koltunski
|
|
108 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
109 |
|
|
|
110 |
|
|
void fillUpNumberOfStars(View view)
|
111 |
|
|
{
|
112 |
|
|
int number = RubikScores.getInstance().getNumStars();
|
113 |
|
|
TextView v = view.findViewById(R.id.stars_string1);
|
114 |
|
|
v.setText(getString(R.string.buy_string1,number));
|
115 |
|
|
}
|
116 |
d05e7629
|
Leszek Koltunski
|
}
|