Revision 600b1343
Added by Leszek Koltunski almost 2 years ago
src/main/java/org/distorted/purchase/PurchaseScreenPane.java | ||
---|---|---|
9 | 9 |
|
10 | 10 |
package org.distorted.purchase; |
11 | 11 |
|
12 |
import android.graphics.drawable.Drawable; |
|
12 | 13 |
import android.util.TypedValue; |
13 | 14 |
import android.view.View; |
14 | 15 |
import android.widget.ImageButton; |
... | ... | |
16 | 17 |
import android.widget.LinearLayout; |
17 | 18 |
import android.widget.TextView; |
18 | 19 |
|
20 |
import androidx.core.content.res.ResourcesCompat; |
|
21 |
|
|
19 | 22 |
import org.distorted.main.R; |
20 | 23 |
import org.distorted.objectlib.json.JsonReader; |
21 | 24 |
import org.distorted.objects.RubikObject; |
... | ... | |
86 | 89 |
|
87 | 90 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
88 | 91 |
|
89 |
private void setUpButtons(int price, LinearLayout one, LinearLayout all)
|
|
92 |
private void setUpButtons(PurchaseActivity act, LinearLayout one, LinearLayout all)
|
|
90 | 93 |
{ |
91 | 94 |
ImageButton butO = one.findViewById(R.id.purchaseButtonOne); |
92 | 95 |
ImageButton butA = all.findViewById(R.id.purchaseButtonAll); |
93 | 96 |
|
97 |
int id,price = act.getObjectPrice(); |
|
98 |
|
|
99 |
if( price<=10 ) id = R.drawable.price_10; |
|
100 |
else if( price<=20 ) id = R.drawable.price_20; |
|
101 |
else if( price<=30 ) id = R.drawable.price_30; |
|
102 |
else if( price<=40 ) id = R.drawable.price_40; |
|
103 |
else if( price<=50 ) id = R.drawable.price_50; |
|
104 |
else if( price<=60 ) id = R.drawable.price_60; |
|
105 |
else if( price<=70 ) id = R.drawable.price_70; |
|
106 |
else if( price<=80 ) id = R.drawable.price_80; |
|
107 |
else if( price<=90 ) id = R.drawable.price_90; |
|
108 |
else id = R.drawable.price_100; |
|
109 |
|
|
110 |
Drawable drawable = ResourcesCompat.getDrawable(act.getResources(), id, null); |
|
111 |
butO.setImageDrawable(drawable); |
|
112 |
|
|
94 | 113 |
butO.setOnClickListener( new View.OnClickListener() |
95 | 114 |
{ |
96 | 115 |
@Override |
... | ... | |
159 | 178 |
{ |
160 | 179 |
int width = act.getScreenWidthInPixels(); |
161 | 180 |
float textSize = width*TEXT_RATIO; |
162 |
int padding = (int)(width*PADDING_RATIO); |
|
181 |
int margin = (int)(width*PADDING_RATIO); |
|
182 |
int padding = margin/3; |
|
163 | 183 |
|
164 | 184 |
LinearLayout upperBar = act.findViewById(R.id.upperBar); |
165 | 185 |
LinearLayout oneLayout = act.findViewById(R.id.purchaseLayoutOne); |
166 | 186 |
LinearLayout allLayout = act.findViewById(R.id.purchaseLayoutAll); |
167 | 187 |
|
168 |
upperBar.setPadding( padding,padding ,padding,padding );
|
|
169 |
oneLayout.setPadding(padding,padding/2,padding,padding/2);
|
|
170 |
allLayout.setPadding(padding,padding/2,padding,padding/2);
|
|
188 |
upperBar.setPadding( margin, margin, margin, margin);
|
|
189 |
oneLayout.setPadding( padding, padding, padding, padding);
|
|
190 |
allLayout.setPadding( padding, padding, padding, padding);
|
|
171 | 191 |
|
172 | 192 |
LinearLayout.LayoutParams params1 = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, 0, 1.00f); |
173 | 193 |
params1.bottomMargin = 0; |
174 |
params1.topMargin = padding;
|
|
175 |
params1.leftMargin = padding;
|
|
176 |
params1.rightMargin = padding;
|
|
194 |
params1.topMargin = margin;
|
|
195 |
params1.leftMargin = margin;
|
|
196 |
params1.rightMargin = margin;
|
|
177 | 197 |
|
178 | 198 |
LinearLayout.LayoutParams params2 = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, 0, 1.00f); |
179 |
params2.bottomMargin = padding;
|
|
180 |
params2.topMargin = padding;
|
|
181 |
params2.leftMargin = padding;
|
|
182 |
params2.rightMargin = padding;
|
|
199 |
params2.bottomMargin = margin;
|
|
200 |
params2.topMargin = margin;
|
|
201 |
params2.leftMargin = margin;
|
|
202 |
params2.rightMargin = margin;
|
|
183 | 203 |
|
184 | 204 |
LinearLayout.LayoutParams params3 = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, 0, 1.00f); |
185 | 205 |
params3.bottomMargin = 0; |
186 | 206 |
params3.topMargin = 0; |
187 |
params3.leftMargin = padding;
|
|
188 |
params3.rightMargin = padding;
|
|
207 |
params3.leftMargin = margin;
|
|
208 |
params3.rightMargin = margin;
|
|
189 | 209 |
|
190 | 210 |
upperBar.setLayoutParams(params1); |
191 | 211 |
oneLayout.setLayoutParams(params3); |
... | ... | |
201 | 221 |
text = allLayout.findViewById(R.id.purchaseTextAll); |
202 | 222 |
text.setTextSize(TypedValue.COMPLEX_UNIT_PX, textSize); |
203 | 223 |
|
204 |
int price = act.getObjectPrice(); |
|
205 |
setUpButtons(price,oneLayout,allLayout); |
|
224 |
setUpButtons(act,oneLayout,allLayout); |
|
206 | 225 |
} |
207 | 226 |
} |
Also available in: Unified diff
Purchase Pane: buttons (part2)