Revision c02fa107
Added by Leszek Koltunski over 1 year ago
src/main/java/org/distorted/dialogs/RubikDialogError.java | ||
---|---|---|
11 | 11 |
|
12 | 12 |
import android.app.Dialog; |
13 | 13 |
import android.content.DialogInterface; |
14 |
import android.os.Bundle; |
|
15 |
import android.util.DisplayMetrics; |
|
16 | 14 |
import android.util.TypedValue; |
17 |
import android.view.LayoutInflater; |
|
18 | 15 |
import android.view.View; |
19 |
import android.view.Window; |
|
20 | 16 |
import android.widget.Button; |
21 | 17 |
import android.widget.TextView; |
22 | 18 |
|
23 |
import androidx.annotation.NonNull; |
|
24 | 19 |
import androidx.appcompat.app.AlertDialog; |
25 |
import androidx.appcompat.app.AppCompatDialogFragment; |
|
26 | 20 |
import androidx.fragment.app.FragmentActivity; |
27 | 21 |
|
28 | 22 |
import org.distorted.main.R; |
29 |
import org.distorted.main.RubikActivity; |
|
30 | 23 |
|
31 | 24 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
32 | 25 |
|
33 |
public class RubikDialogError extends AppCompatDialogFragment
|
|
26 |
public class RubikDialogError extends RubikDialogAbstract
|
|
34 | 27 |
{ |
35 |
@NonNull |
|
36 |
@Override |
|
37 |
public Dialog onCreateDialog(Bundle savedInstanceState) |
|
28 |
public int getResource() |
|
38 | 29 |
{ |
39 |
final FragmentActivity act = getActivity(); |
|
40 |
LayoutInflater inflater = act.getLayoutInflater(); |
|
41 |
AlertDialog.Builder builder = new AlertDialog.Builder(act); |
|
30 |
return R.layout.dialog_error; |
|
31 |
} |
|
42 | 32 |
|
43 |
DisplayMetrics displaymetrics = new DisplayMetrics(); |
|
44 |
act.getWindowManager().getDefaultDisplay().getMetrics(displaymetrics); |
|
45 |
int h = displaymetrics.heightPixels; |
|
46 |
final float titleSize= h * 0.032f; |
|
47 |
final float okSize = h * 0.040f; |
|
33 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
48 | 34 |
|
49 |
TextView tv = (TextView) inflater.inflate(R.layout.dialog_title, null);
|
|
50 |
tv.setTextSize(TypedValue.COMPLEX_UNIT_PX, titleSize);
|
|
51 |
tv.setText(R.string.opengl_error);
|
|
52 |
builder.setCustomTitle(tv);
|
|
35 |
public int getTitleResource()
|
|
36 |
{
|
|
37 |
return R.string.opengl_error;
|
|
38 |
}
|
|
53 | 39 |
|
54 |
final View view = inflater.inflate(R.layout.dialog_error, null); |
|
55 |
TextView text = view.findViewById(R.id.error_string); |
|
56 |
text.setText(R.string.opengl_error_text); |
|
40 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
41 |
|
|
42 |
public boolean hasArgument() |
|
43 |
{ |
|
44 |
return false; |
|
45 |
} |
|
46 |
|
|
47 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
48 |
|
|
49 |
public void setPositive(AlertDialog.Builder builder) |
|
50 |
{ |
|
51 |
final FragmentActivity act = getActivity(); |
|
57 | 52 |
|
58 | 53 |
builder.setPositiveButton( R.string.ok, new DialogInterface.OnClickListener() |
59 | 54 |
{ |
60 | 55 |
@Override |
61 | 56 |
public void onClick(DialogInterface dialog, int which) |
62 | 57 |
{ |
63 |
act.finish(); |
|
58 |
if( act!=null ) act.finish();
|
|
64 | 59 |
} |
65 | 60 |
}); |
61 |
} |
|
66 | 62 |
|
67 |
builder.setView(view);
|
|
63 |
///////////////////////////////////////////////////////////////////////////////////////////////////
|
|
68 | 64 |
|
69 |
final Dialog dialog = builder.create();
|
|
70 |
dialog.setCanceledOnTouchOutside(false);
|
|
65 |
public void setNegative(AlertDialog.Builder builder)
|
|
66 |
{
|
|
71 | 67 |
|
72 |
Window window = dialog.getWindow();
|
|
68 |
}
|
|
73 | 69 |
|
74 |
if( window!=null ) |
|
75 |
{ |
|
76 |
window.getDecorView().setSystemUiVisibility(RubikActivity.FLAGS); |
|
77 |
} |
|
70 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
78 | 71 |
|
79 |
dialog.setOnShowListener(new DialogInterface.OnShowListener() |
|
80 |
{ |
|
81 |
@Override |
|
82 |
public void onShow(DialogInterface dialog) |
|
83 |
{ |
|
84 |
Button btnPositive = ((AlertDialog)dialog).getButton(Dialog.BUTTON_POSITIVE); |
|
85 |
btnPositive.setTextSize(TypedValue.COMPLEX_UNIT_PX, okSize); |
|
86 |
} |
|
87 |
}); |
|
72 |
public void onShowDialog(DialogInterface dialog, float size) |
|
73 |
{ |
|
74 |
Button btnPositive = ((AlertDialog)dialog).getButton(Dialog.BUTTON_POSITIVE); |
|
75 |
btnPositive.setTextSize(TypedValue.COMPLEX_UNIT_PX, size); |
|
76 |
} |
|
77 |
|
|
78 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
88 | 79 |
|
89 |
return dialog; |
|
80 |
public void prepareBody(Dialog dialog, View view, FragmentActivity act, float size) |
|
81 |
{ |
|
82 |
TextView text = view.findViewById(R.id.error_string); |
|
83 |
text.setTextSize(TypedValue.COMPLEX_UNIT_PX, size); |
|
84 |
text.setText(R.string.opengl_error_text); |
|
90 | 85 |
} |
91 | 86 |
} |
Also available in: Unified diff
Continue unifying all the dialogs under one RubikDialogAbstract.