Revision c02fa107
Added by Leszek Koltunski over 1 year ago
src/main/java/org/distorted/dialogs/RubikDialogStarsStatus.java | ||
---|---|---|
12 | 12 |
import android.app.Dialog; |
13 | 13 |
import android.content.Context; |
14 | 14 |
import android.content.DialogInterface; |
15 |
import android.os.Bundle; |
|
16 | 15 |
import android.util.DisplayMetrics; |
17 | 16 |
import android.util.TypedValue; |
18 |
import android.view.LayoutInflater; |
|
19 | 17 |
import android.view.View; |
20 | 18 |
import android.view.Window; |
21 | 19 |
import android.view.WindowManager; |
... | ... | |
23 | 21 |
import android.widget.LinearLayout; |
24 | 22 |
import android.widget.TextView; |
25 | 23 |
|
26 |
import androidx.annotation.NonNull; |
|
27 | 24 |
import androidx.appcompat.app.AlertDialog; |
28 |
import androidx.appcompat.app.AppCompatDialogFragment; |
|
29 | 25 |
import androidx.fragment.app.FragmentActivity; |
30 | 26 |
|
31 | 27 |
import org.distorted.external.RubikScores; |
32 | 28 |
import org.distorted.main.R; |
33 |
import org.distorted.main.RubikActivity; |
|
34 | 29 |
|
35 | 30 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
36 | 31 |
|
37 |
public class RubikDialogStarsStatus extends AppCompatDialogFragment
|
|
32 |
public class RubikDialogStarsStatus extends RubikDialogAbstract
|
|
38 | 33 |
{ |
39 |
private static final float LAYOUT_HEIGHT = 0.110f; |
|
40 |
private static final float MARGIN = 0.007f; |
|
41 |
private static final float BUTTON_SIZE = 0.040f; |
|
42 |
|
|
43 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
44 |
|
|
45 |
@NonNull |
|
46 | 34 |
@Override |
47 |
public Dialog onCreateDialog(Bundle savedInstanceState)
|
|
35 |
public void onResume()
|
|
48 | 36 |
{ |
49 |
FragmentActivity act = getActivity(); |
|
50 |
LayoutInflater inflater = act.getLayoutInflater(); |
|
51 |
AlertDialog.Builder builder = new AlertDialog.Builder(act); |
|
52 |
DisplayMetrics displaymetrics = new DisplayMetrics(); |
|
53 |
act.getWindowManager().getDefaultDisplay().getMetrics(displaymetrics); |
|
54 |
final View view = inflater.inflate(R.layout.dialog_stars_status, null); |
|
55 |
|
|
56 |
int h = displaymetrics.heightPixels; |
|
57 |
final float butSize = h * BUTTON_SIZE; |
|
58 |
int height = (int)(h*LAYOUT_HEIGHT); |
|
59 |
int margin = (int)(h*MARGIN); |
|
37 |
super.onResume(); |
|
60 | 38 |
|
61 |
LinearLayout.LayoutParams params1 = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,LinearLayout.LayoutParams.WRAP_CONTENT); |
|
62 |
params1.setMargins(margin, margin, margin, margin); |
|
63 |
LinearLayout.LayoutParams params2 = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,height); |
|
64 |
params2.setMargins(margin, margin, margin, margin); |
|
39 |
Window window = getDialog().getWindow(); |
|
40 |
Context context = getContext(); |
|
65 | 41 |
|
66 |
LinearLayout lm = view.findViewById(R.id.stars_main); |
|
67 |
lm.setPadding(margin,margin,margin,margin); |
|
42 |
if( window!=null && context!=null ) |
|
43 |
{ |
|
44 |
WindowManager.LayoutParams params = window.getAttributes(); |
|
45 |
params.width = (int)Math.min( mHeight*0.65f,mWidth*0.95f ); |
|
46 |
params.height = WindowManager.LayoutParams.WRAP_CONTENT; |
|
47 |
window.setAttributes(params); |
|
48 |
} |
|
49 |
} |
|
68 | 50 |
|
69 |
LinearLayout ls = view.findViewById(R.id.stars_strings); |
|
70 |
ls.setLayoutParams(params1); |
|
71 |
LinearLayout l1 = view.findViewById(R.id.stars_layout_1); |
|
72 |
l1.setLayoutParams(params2); |
|
73 |
LinearLayout l2 = view.findViewById(R.id.stars_layout_2); |
|
74 |
l2.setLayoutParams(params2); |
|
75 |
LinearLayout l3 = view.findViewById(R.id.stars_layout_3); |
|
76 |
l3.setLayoutParams(params2); |
|
51 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
77 | 52 |
|
78 |
fillUpNumberOfStars(view); |
|
53 |
public int getResource() |
|
54 |
{ |
|
55 |
return R.layout.dialog_stars_status; |
|
56 |
} |
|
79 | 57 |
|
80 |
builder.setCancelable(true);
|
|
58 |
///////////////////////////////////////////////////////////////////////////////////////////////////
|
|
81 | 59 |
|
82 |
builder.setPositiveButton( R.string.ok, new DialogInterface.OnClickListener() |
|
83 |
{ |
|
84 |
@Override |
|
85 |
public void onClick(DialogInterface dialog, int which) { } |
|
86 |
}); |
|
60 |
public int getTitleResource() |
|
61 |
{ |
|
62 |
return -1; |
|
63 |
} |
|
87 | 64 |
|
88 |
builder.setView(view);
|
|
65 |
///////////////////////////////////////////////////////////////////////////////////////////////////
|
|
89 | 66 |
|
90 |
final Dialog dialog = builder.create(); |
|
91 |
dialog.setCanceledOnTouchOutside(false); |
|
92 |
Window window = dialog.getWindow(); |
|
67 |
public boolean hasArgument() |
|
68 |
{ |
|
69 |
return false; |
|
70 |
} |
|
93 | 71 |
|
94 |
if( window!=null ) |
|
95 |
{ |
|
96 |
window.getDecorView().setSystemUiVisibility(RubikActivity.FLAGS); |
|
97 |
} |
|
72 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
98 | 73 |
|
99 |
dialog.setOnShowListener(new DialogInterface.OnShowListener() |
|
74 |
public void setPositive(AlertDialog.Builder builder) |
|
75 |
{ |
|
76 |
builder.setPositiveButton( R.string.ok, new DialogInterface.OnClickListener() |
|
100 | 77 |
{ |
101 | 78 |
@Override |
102 |
public void onShow(DialogInterface dialog)
|
|
79 |
public void onClick(DialogInterface dialog, int which)
|
|
103 | 80 |
{ |
104 |
Button btnPositive = ((AlertDialog)dialog).getButton(Dialog.BUTTON_POSITIVE); |
|
105 |
btnPositive.setTextSize(TypedValue.COMPLEX_UNIT_PX, butSize); |
|
81 |
|
|
106 | 82 |
} |
107 | 83 |
}); |
108 |
|
|
109 |
return dialog; |
|
110 | 84 |
} |
111 | 85 |
|
112 | 86 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
113 | 87 |
|
114 |
@Override |
|
115 |
public void onResume() |
|
88 |
public void setNegative(AlertDialog.Builder builder) |
|
116 | 89 |
{ |
117 |
super.onResume(); |
|
118 | 90 |
|
119 |
Window window = getDialog().getWindow(); |
|
120 |
Context context = getContext(); |
|
91 |
} |
|
121 | 92 |
|
122 |
if( window!=null && context!=null ) |
|
123 |
{ |
|
124 |
DisplayMetrics metrics = context.getResources().getDisplayMetrics(); |
|
125 |
WindowManager.LayoutParams params = window.getAttributes(); |
|
126 |
params.width = (int)Math.min( 0.65f*metrics.heightPixels,0.95f*metrics.widthPixels ); |
|
127 |
params.height = WindowManager.LayoutParams.WRAP_CONTENT; |
|
128 |
window.setAttributes(params); |
|
129 |
} |
|
93 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
94 |
|
|
95 |
public void onShowDialog(DialogInterface dialog, float size) |
|
96 |
{ |
|
97 |
Button btnPositive = ((AlertDialog)dialog).getButton(Dialog.BUTTON_POSITIVE); |
|
98 |
btnPositive.setTextSize(TypedValue.COMPLEX_UNIT_PX, size); |
|
130 | 99 |
} |
100 |
|
|
131 | 101 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
132 | 102 |
|
133 |
void fillUpNumberOfStars(View view)
|
|
103 |
public void prepareBody(Dialog dialog, View view, FragmentActivity act, float size)
|
|
134 | 104 |
{ |
105 |
int height = (int)(mHeight*0.110f); |
|
106 |
int margin = (int)(mHeight*0.007f); |
|
107 |
|
|
108 |
LinearLayout.LayoutParams params1 = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,LinearLayout.LayoutParams.WRAP_CONTENT); |
|
109 |
params1.setMargins(margin, margin, margin, margin); |
|
110 |
LinearLayout.LayoutParams params2 = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,height); |
|
111 |
params2.setMargins(margin, margin, margin, margin); |
|
112 |
|
|
113 |
LinearLayout lm = view.findViewById(R.id.stars_main); |
|
114 |
lm.setPadding(margin,margin,margin,margin); |
|
115 |
|
|
116 |
LinearLayout ls = view.findViewById(R.id.stars_strings); |
|
117 |
ls.setLayoutParams(params1); |
|
118 |
LinearLayout l1 = view.findViewById(R.id.stars_layout_1); |
|
119 |
l1.setLayoutParams(params2); |
|
120 |
LinearLayout l2 = view.findViewById(R.id.stars_layout_2); |
|
121 |
l2.setLayoutParams(params2); |
|
122 |
LinearLayout l3 = view.findViewById(R.id.stars_layout_3); |
|
123 |
l3.setLayoutParams(params2); |
|
124 |
|
|
135 | 125 |
int number = RubikScores.getInstance().getNumStars(); |
136 | 126 |
TextView v = view.findViewById(R.id.stars_string1); |
137 | 127 |
v.setText(getString(R.string.buy_string1,number)); |
Also available in: Unified diff
Continue unifying all the dialogs under one RubikDialogAbstract.