Revision c02fa107
Added by Leszek Koltunski over 1 year ago
src/main/java/org/distorted/dialogs/RubikDialogSolved.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 |
|
... | ... | |
31 | 25 |
|
32 | 26 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
33 | 27 |
|
34 |
public class RubikDialogSolved extends AppCompatDialogFragment
|
|
28 |
public class RubikDialogSolved extends RubikDialogAbstract
|
|
35 | 29 |
{ |
36 |
@NonNull |
|
37 |
@Override |
|
38 |
public Dialog onCreateDialog(Bundle savedInstanceState) |
|
30 |
public int getResource() |
|
31 |
{ |
|
32 |
return R.layout.dialog_solved; |
|
33 |
} |
|
34 |
|
|
35 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
36 |
|
|
37 |
public int getTitleResource() |
|
38 |
{ |
|
39 |
return R.string.solved; |
|
40 |
} |
|
41 |
|
|
42 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
43 |
|
|
44 |
public boolean hasArgument() |
|
45 |
{ |
|
46 |
return true; |
|
47 |
} |
|
48 |
|
|
49 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
50 |
|
|
51 |
public void setPositive(AlertDialog.Builder builder) |
|
39 | 52 |
{ |
40 |
FragmentActivity act = getActivity(); |
|
41 |
LayoutInflater inflater = act.getLayoutInflater(); |
|
42 |
AlertDialog.Builder builder = new AlertDialog.Builder(act); |
|
43 |
|
|
44 |
DisplayMetrics displaymetrics = new DisplayMetrics(); |
|
45 |
act.getWindowManager().getDefaultDisplay().getMetrics(displaymetrics); |
|
46 |
int h = displaymetrics.heightPixels; |
|
47 |
final float titleSize= h*0.032f; |
|
48 |
final float okSize = h*0.040f; |
|
49 |
final float textSize = h*0.022f; |
|
50 |
|
|
51 |
TextView tv = (TextView) inflater.inflate(R.layout.dialog_title, null); |
|
52 |
tv.setTextSize(TypedValue.COMPLEX_UNIT_PX, titleSize); |
|
53 |
tv.setText(R.string.solved); |
|
54 |
builder.setCustomTitle(tv); |
|
55 |
|
|
56 |
builder.setCancelable(true); |
|
57 | 53 |
builder.setPositiveButton( R.string.ok, new DialogInterface.OnClickListener() |
58 | 54 |
{ |
59 | 55 |
@Override |
... | ... | |
63 | 59 |
ScreenList.switchScreen(act, ScreenList.PLAY); |
64 | 60 |
} |
65 | 61 |
}); |
62 |
} |
|
66 | 63 |
|
67 |
Bundle args = getArguments(); |
|
68 |
long time; |
|
64 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
69 | 65 |
|
70 |
try |
|
71 |
{ |
|
72 |
time = args.getLong("time"); |
|
73 |
} |
|
74 |
catch(Exception e) |
|
75 |
{ |
|
76 |
time = 0; |
|
77 |
} |
|
66 |
public void setNegative(AlertDialog.Builder builder) |
|
67 |
{ |
|
78 | 68 |
|
79 |
final View view = inflater.inflate(R.layout.dialog_solved, null); |
|
80 |
TextView text = view.findViewById(R.id.solved_time); |
|
81 |
text.setTextSize(TypedValue.COMPLEX_UNIT_PX, textSize); |
|
82 |
text.setText(getString(R.string.ti_placeholder, (time/10)/100.0f)); |
|
83 |
builder.setView(view); |
|
69 |
} |
|
84 | 70 |
|
85 |
Dialog dialog = builder.create(); |
|
86 |
dialog.setCanceledOnTouchOutside(false); |
|
87 |
Window window = dialog.getWindow(); |
|
71 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
88 | 72 |
|
89 |
if( window!=null ) |
|
90 |
{ |
|
91 |
window.getDecorView().setSystemUiVisibility(RubikActivity.FLAGS); |
|
92 |
} |
|
73 |
public void onShowDialog(DialogInterface dialog, float size) |
|
74 |
{ |
|
75 |
Button btnPositive = ((AlertDialog)dialog).getButton(Dialog.BUTTON_POSITIVE); |
|
76 |
btnPositive.setTextSize(TypedValue.COMPLEX_UNIT_PX, size); |
|
77 |
} |
|
93 | 78 |
|
94 |
dialog.setOnShowListener(new DialogInterface.OnShowListener() |
|
95 |
{ |
|
96 |
@Override |
|
97 |
public void onShow(DialogInterface dialog) |
|
98 |
{ |
|
99 |
Button btnPositive = ((AlertDialog)dialog).getButton(Dialog.BUTTON_POSITIVE); |
|
100 |
btnPositive.setTextSize(TypedValue.COMPLEX_UNIT_PX, okSize); |
|
101 |
} |
|
102 |
}); |
|
79 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
103 | 80 |
|
104 |
return dialog; |
|
81 |
public void prepareBody(Dialog dialog, View view, FragmentActivity act, float size) |
|
82 |
{ |
|
83 |
TextView text = view.findViewById(R.id.solved_time); |
|
84 |
text.setTextSize(TypedValue.COMPLEX_UNIT_PX, size); |
|
85 |
text.setText(getString(R.string.ti_placeholder, mArgument)); |
|
105 | 86 |
} |
106 | 87 |
|
107 | 88 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
Also available in: Unified diff
Continue unifying all the dialogs under one RubikDialogAbstract.