Revision c02fa107
Added by Leszek Koltunski over 1 year ago
src/main/java/org/distorted/dialogs/RubikDialogNewRecord.java | ||
---|---|---|
12 | 12 |
import android.app.Dialog; |
13 | 13 |
import android.content.DialogInterface; |
14 | 14 |
import android.os.Bundle; |
15 |
import androidx.annotation.NonNull; |
|
16 | 15 |
import androidx.fragment.app.FragmentActivity; |
17 | 16 |
import androidx.appcompat.app.AlertDialog; |
18 |
import androidx.appcompat.app.AppCompatDialogFragment; |
|
19 | 17 |
|
20 |
import android.util.DisplayMetrics; |
|
21 | 18 |
import android.util.TypedValue; |
22 |
import android.view.LayoutInflater; |
|
23 | 19 |
import android.view.View; |
24 |
import android.view.Window; |
|
25 | 20 |
import android.widget.Button; |
26 | 21 |
import android.widget.TextView; |
27 | 22 |
|
28 | 23 |
import org.distorted.main.R; |
29 | 24 |
import org.distorted.main.RubikActivity; |
30 | 25 |
import org.distorted.external.RubikScores; |
31 |
import org.distorted.objects.RubikObjectList; |
|
32 | 26 |
import org.distorted.screens.ScreenList; |
33 | 27 |
|
34 | 28 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
35 | 29 |
|
36 |
public class RubikDialogNewRecord extends AppCompatDialogFragment
|
|
30 |
public class RubikDialogNewRecord extends RubikDialogAbstract
|
|
37 | 31 |
{ |
38 |
@NonNull |
|
39 |
@Override |
|
40 |
public Dialog onCreateDialog(Bundle savedInstanceState) |
|
32 |
public int getResource() |
|
41 | 33 |
{ |
42 |
FragmentActivity act = getActivity();
|
|
43 |
LayoutInflater inflater = act.getLayoutInflater();
|
|
44 |
AlertDialog.Builder builder = new AlertDialog.Builder(act); |
|
45 |
|
|
46 |
DisplayMetrics displaymetrics = new DisplayMetrics(); |
|
47 |
act.getWindowManager().getDefaultDisplay().getMetrics(displaymetrics);
|
|
48 |
int h = displaymetrics.heightPixels;
|
|
49 |
final float titleSize= h*0.032f;
|
|
50 |
final float okSize = h*0.040f;
|
|
51 |
final float textSize = h*0.032f; |
|
52 |
|
|
53 |
TextView tv = (TextView) inflater.inflate(R.layout.dialog_title, null); |
|
54 |
tv.setTextSize(TypedValue.COMPLEX_UNIT_PX, titleSize);
|
|
55 |
tv.setText(R.string.new_record);
|
|
56 |
builder.setCustomTitle(tv);
|
|
57 |
builder.setCancelable(true);
|
|
34 |
return R.layout.dialog_new_record;
|
|
35 |
}
|
|
36 |
|
|
37 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
38 |
|
|
39 |
public int getTitleResource()
|
|
40 |
{
|
|
41 |
return R.string.new_record;
|
|
42 |
}
|
|
43 |
|
|
44 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
45 |
|
|
46 |
public boolean hasArgument()
|
|
47 |
{
|
|
48 |
return true;
|
|
49 |
}
|
|
58 | 50 |
|
51 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
52 |
|
|
53 |
public void setPositive(AlertDialog.Builder builder) |
|
54 |
{ |
|
59 | 55 |
builder.setPositiveButton( R.string.yes, new DialogInterface.OnClickListener() |
60 | 56 |
{ |
61 | 57 |
@Override |
... | ... | |
69 | 65 |
|
70 | 66 |
if( name.length()>0 ) |
71 | 67 |
{ |
72 |
int object = RubikObjectList.getCurrObject(); |
|
73 |
|
|
74 |
bundle.putInt("tab", object ); |
|
75 |
bundle.putBoolean("submitting", true); |
|
76 |
|
|
68 |
bundle.putString("argument", "true"); |
|
77 | 69 |
RubikDialogScores scoresDiag = new RubikDialogScores(); |
78 | 70 |
scoresDiag.setArguments(bundle); |
79 | 71 |
scoresDiag.show(act.getSupportFragmentManager(), null); |
80 | 72 |
} |
81 | 73 |
else |
82 | 74 |
{ |
83 |
bundle.putString("name", name ); |
|
84 |
|
|
75 |
bundle.putString("argument", name ); |
|
85 | 76 |
RubikDialogSetName nameDiag = new RubikDialogSetName(); |
86 | 77 |
nameDiag.setArguments(bundle); |
87 | 78 |
nameDiag.show(act.getSupportFragmentManager(), null); |
88 | 79 |
} |
89 | 80 |
} |
90 | 81 |
}); |
82 |
} |
|
91 | 83 |
|
84 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
85 |
|
|
86 |
public void setNegative(AlertDialog.Builder builder) |
|
87 |
{ |
|
92 | 88 |
builder.setNegativeButton(R.string.no, new DialogInterface.OnClickListener() |
93 | 89 |
{ |
94 | 90 |
@Override |
... | ... | |
98 | 94 |
ScreenList.switchScreen(act, ScreenList.PLAY); |
99 | 95 |
} |
100 | 96 |
}); |
97 |
} |
|
101 | 98 |
|
102 |
Bundle args = getArguments(); |
|
103 |
long time; |
|
99 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
104 | 100 |
|
105 |
try |
|
106 |
{ |
|
107 |
time = args.getLong("time"); |
|
108 |
} |
|
109 |
catch(Exception e) |
|
110 |
{ |
|
111 |
time = 0; |
|
112 |
} |
|
101 |
public void onShowDialog(DialogInterface dialog, float size) |
|
102 |
{ |
|
103 |
Button btnPositive = ((AlertDialog)dialog).getButton(Dialog.BUTTON_POSITIVE); |
|
104 |
btnPositive.setTextSize(TypedValue.COMPLEX_UNIT_PX, size); |
|
105 |
Button btnNegative = ((AlertDialog)dialog).getButton(Dialog.BUTTON_NEGATIVE); |
|
106 |
btnNegative.setTextSize(TypedValue.COMPLEX_UNIT_PX, size); |
|
107 |
} |
|
113 | 108 |
|
114 |
final View view = inflater.inflate(R.layout.dialog_new_record, null); |
|
115 |
TextView text = view.findViewById(R.id.new_record_time); |
|
116 |
text.setTextSize(TypedValue.COMPLEX_UNIT_PX, textSize); |
|
117 |
text.setText(getString(R.string.ti_placeholder, (time/10)/100.0f)); |
|
118 |
builder.setView(view); |
|
109 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
119 | 110 |
|
111 |
public void prepareBody(Dialog dialog, View view, FragmentActivity act, float size) |
|
112 |
{ |
|
113 |
TextView text = view.findViewById(R.id.new_record_time); |
|
114 |
text.setTextSize(TypedValue.COMPLEX_UNIT_PX, size); |
|
115 |
text.setText(getString(R.string.ti_placeholder, mArgument)); |
|
120 | 116 |
TextView submit = view.findViewById(R.id.new_record_submit); |
121 |
submit.setTextSize(TypedValue.COMPLEX_UNIT_PX, textSize); |
|
122 |
|
|
123 |
Dialog dialog = builder.create(); |
|
124 |
dialog.setCanceledOnTouchOutside(false); |
|
125 |
Window window = dialog.getWindow(); |
|
126 |
|
|
127 |
if( window!=null ) |
|
128 |
{ |
|
129 |
window.getDecorView().setSystemUiVisibility(RubikActivity.FLAGS); |
|
130 |
} |
|
131 |
|
|
132 |
dialog.setOnShowListener(new DialogInterface.OnShowListener() |
|
133 |
{ |
|
134 |
@Override |
|
135 |
public void onShow(DialogInterface dialog) |
|
136 |
{ |
|
137 |
Button btnPositive = ((AlertDialog)dialog).getButton(Dialog.BUTTON_POSITIVE); |
|
138 |
btnPositive.setTextSize(TypedValue.COMPLEX_UNIT_PX, okSize); |
|
139 |
Button btnNegative = ((AlertDialog)dialog).getButton(Dialog.BUTTON_NEGATIVE); |
|
140 |
btnNegative.setTextSize(TypedValue.COMPLEX_UNIT_PX, okSize); |
|
141 |
} |
|
142 |
}); |
|
143 |
|
|
144 |
return dialog; |
|
117 |
submit.setTextSize(TypedValue.COMPLEX_UNIT_PX, size); |
|
145 | 118 |
} |
146 | 119 |
|
147 | 120 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
Also available in: Unified diff
Continue unifying all the dialogs under one RubikDialogAbstract.