1 |
b5c2adb4
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
2 |
|
|
// Copyright 2023 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 |
0a9adc31
|
leszek
|
import android.content.res.ColorStateList;
|
15 |
|
|
import android.graphics.Color;
|
16 |
|
|
import android.graphics.drawable.ColorDrawable;
|
17 |
b5c2adb4
|
Leszek Koltunski
|
import android.os.Bundle;
|
18 |
|
|
import android.util.DisplayMetrics;
|
19 |
|
|
import android.util.TypedValue;
|
20 |
|
|
import android.view.LayoutInflater;
|
21 |
|
|
import android.view.View;
|
22 |
|
|
import android.view.Window;
|
23 |
f8a21f6b
|
Leszek Koltunski
|
import android.widget.Button;
|
24 |
b5c2adb4
|
Leszek Koltunski
|
import android.widget.TextView;
|
25 |
|
|
|
26 |
|
|
import androidx.annotation.NonNull;
|
27 |
|
|
import androidx.appcompat.app.AlertDialog;
|
28 |
|
|
import androidx.appcompat.app.AppCompatDialogFragment;
|
29 |
|
|
import androidx.fragment.app.FragmentActivity;
|
30 |
|
|
|
31 |
0a9adc31
|
leszek
|
import org.distorted.helpers.BaseActivity;
|
32 |
7bb30586
|
leszek
|
import org.distorted.main.MainActivity;
|
33 |
b5c2adb4
|
Leszek Koltunski
|
import org.distorted.main.R;
|
34 |
|
|
|
35 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
36 |
|
|
|
37 |
|
|
abstract public class RubikDialogAbstract extends AppCompatDialogFragment
|
38 |
|
|
{
|
39 |
e71baee1
|
Leszek Koltunski
|
static final int PARAMETRIC_TITLE = -10000;
|
40 |
|
|
|
41 |
b5c2adb4
|
Leszek Koltunski
|
protected float mTitleSize, mButSize, mTextSize;
|
42 |
c02fa107
|
Leszek Koltunski
|
protected int mWidth, mHeight;
|
43 |
|
|
protected String mArgument;
|
44 |
b5c2adb4
|
Leszek Koltunski
|
|
45 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
46 |
|
|
|
47 |
|
|
abstract int getResource();
|
48 |
|
|
abstract int getTitleResource();
|
49 |
f8a21f6b
|
Leszek Koltunski
|
abstract int getPositive();
|
50 |
|
|
abstract int getNegative();
|
51 |
c02fa107
|
Leszek Koltunski
|
abstract boolean hasArgument();
|
52 |
f8a21f6b
|
Leszek Koltunski
|
abstract void positiveAction();
|
53 |
|
|
abstract void negativeAction();
|
54 |
c02fa107
|
Leszek Koltunski
|
abstract void prepareBody(Dialog dialog, View view, FragmentActivity act, float size);
|
55 |
b5c2adb4
|
Leszek Koltunski
|
|
56 |
e71baee1
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
57 |
|
|
|
58 |
|
|
String getTitleString(FragmentActivity act)
|
59 |
|
|
{
|
60 |
|
|
return "";
|
61 |
|
|
}
|
62 |
|
|
|
63 |
b5c2adb4
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
64 |
|
|
|
65 |
|
|
@NonNull
|
66 |
|
|
@Override
|
67 |
|
|
public Dialog onCreateDialog(Bundle savedInstanceState)
|
68 |
|
|
{
|
69 |
|
|
FragmentActivity act = getActivity();
|
70 |
|
|
LayoutInflater inflater = act.getLayoutInflater();
|
71 |
|
|
AlertDialog.Builder builder = new AlertDialog.Builder(act);
|
72 |
|
|
|
73 |
|
|
DisplayMetrics displaymetrics = new DisplayMetrics();
|
74 |
|
|
act.getWindowManager().getDefaultDisplay().getMetrics(displaymetrics);
|
75 |
c02fa107
|
Leszek Koltunski
|
mWidth = displaymetrics.widthPixels;
|
76 |
|
|
mHeight = displaymetrics.heightPixels;
|
77 |
|
|
mTitleSize= mHeight*0.032f;
|
78 |
|
|
mButSize = mHeight*0.040f;
|
79 |
|
|
mTextSize = mHeight*0.025f;
|
80 |
|
|
|
81 |
|
|
if( hasArgument() )
|
82 |
|
|
{
|
83 |
|
|
Bundle args = getArguments();
|
84 |
|
|
|
85 |
|
|
try
|
86 |
|
|
{
|
87 |
|
|
mArgument = args!=null ? args.getString("argument") : "";
|
88 |
|
|
}
|
89 |
|
|
catch(Exception e)
|
90 |
|
|
{
|
91 |
|
|
mArgument = "";
|
92 |
|
|
}
|
93 |
|
|
}
|
94 |
|
|
else mArgument = "";
|
95 |
b5c2adb4
|
Leszek Koltunski
|
|
96 |
|
|
final View view = inflater.inflate(getResource(), null);
|
97 |
|
|
builder.setView(view);
|
98 |
|
|
builder.setCancelable(true);
|
99 |
|
|
|
100 |
|
|
int title = getTitleResource();
|
101 |
e71baee1
|
Leszek Koltunski
|
if( title>=0 || title==PARAMETRIC_TITLE )
|
102 |
b5c2adb4
|
Leszek Koltunski
|
{
|
103 |
|
|
TextView tv = (TextView) inflater.inflate(R.layout.dialog_title, null);
|
104 |
|
|
tv.setTextSize(TypedValue.COMPLEX_UNIT_PX, mTitleSize);
|
105 |
e71baee1
|
Leszek Koltunski
|
|
106 |
|
|
if( title>=0 )
|
107 |
|
|
{
|
108 |
|
|
tv.setText(title);
|
109 |
|
|
}
|
110 |
|
|
else
|
111 |
|
|
{
|
112 |
|
|
String titleString = getTitleString(act);
|
113 |
|
|
tv.setText(titleString);
|
114 |
|
|
}
|
115 |
|
|
|
116 |
b5c2adb4
|
Leszek Koltunski
|
builder.setCustomTitle(tv);
|
117 |
|
|
}
|
118 |
|
|
|
119 |
f8a21f6b
|
Leszek Koltunski
|
int positive = getPositive();
|
120 |
|
|
if( positive>=0 )
|
121 |
|
|
{
|
122 |
|
|
builder.setPositiveButton( positive, new DialogInterface.OnClickListener()
|
123 |
|
|
{
|
124 |
|
|
@Override
|
125 |
|
|
public void onClick(DialogInterface dialog, int which)
|
126 |
|
|
{
|
127 |
|
|
positiveAction();
|
128 |
|
|
}
|
129 |
|
|
});
|
130 |
|
|
}
|
131 |
|
|
|
132 |
|
|
int negative = getNegative();
|
133 |
|
|
if( negative>=0 )
|
134 |
|
|
{
|
135 |
b2d7aa87
|
Leszek Koltunski
|
builder.setNegativeButton( negative, new DialogInterface.OnClickListener()
|
136 |
f8a21f6b
|
Leszek Koltunski
|
{
|
137 |
|
|
@Override
|
138 |
|
|
public void onClick(DialogInterface dialog, int which)
|
139 |
|
|
{
|
140 |
|
|
negativeAction();
|
141 |
|
|
}
|
142 |
|
|
});
|
143 |
|
|
}
|
144 |
b5c2adb4
|
Leszek Koltunski
|
|
145 |
|
|
Dialog dialog = builder.create();
|
146 |
|
|
dialog.setCanceledOnTouchOutside(false);
|
147 |
c02fa107
|
Leszek Koltunski
|
|
148 |
|
|
prepareBody(dialog,view,act,mTextSize);
|
149 |
|
|
|
150 |
b5c2adb4
|
Leszek Koltunski
|
Window window = dialog.getWindow();
|
151 |
|
|
|
152 |
|
|
if( window!=null )
|
153 |
|
|
{
|
154 |
0a9adc31
|
leszek
|
BaseActivity bact = (BaseActivity) act;
|
155 |
|
|
int m = bact.getMediumColor();
|
156 |
|
|
window.setBackgroundDrawableResource(m);
|
157 |
7bb30586
|
leszek
|
window.getDecorView().setSystemUiVisibility(MainActivity.FLAGS);
|
158 |
b5c2adb4
|
Leszek Koltunski
|
}
|
159 |
|
|
|
160 |
|
|
dialog.setOnShowListener(new DialogInterface.OnShowListener()
|
161 |
|
|
{
|
162 |
|
|
@Override
|
163 |
|
|
public void onShow(DialogInterface dialog)
|
164 |
|
|
{
|
165 |
f8a21f6b
|
Leszek Koltunski
|
if( positive>=0 )
|
166 |
|
|
{
|
167 |
|
|
Button btnPositive = ((AlertDialog)dialog).getButton(Dialog.BUTTON_POSITIVE);
|
168 |
|
|
btnPositive.setTextSize(TypedValue.COMPLEX_UNIT_PX, mButSize);
|
169 |
|
|
}
|
170 |
|
|
if( negative>=0 )
|
171 |
|
|
{
|
172 |
|
|
Button btnNegative = ((AlertDialog)dialog).getButton(Dialog.BUTTON_NEGATIVE);
|
173 |
|
|
btnNegative.setTextSize(TypedValue.COMPLEX_UNIT_PX, mButSize);
|
174 |
|
|
}
|
175 |
b5c2adb4
|
Leszek Koltunski
|
}
|
176 |
|
|
});
|
177 |
|
|
|
178 |
|
|
return dialog;
|
179 |
|
|
}
|
180 |
|
|
}
|