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