Revision 64975793
Added by Leszek Koltunski over 4 years ago
src/main/java/org/distorted/magic/RubikSettings.java | ||
---|---|---|
35 | 35 |
import android.widget.Spinner; |
36 | 36 |
import android.widget.TextView; |
37 | 37 |
|
38 |
import org.distorted.effect.BaseEffect; |
|
39 |
|
|
38 | 40 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
39 | 41 |
|
40 | 42 |
public class RubikSettings extends AppCompatDialogFragment implements SeekBar.OnSeekBarChangeListener, AdapterView.OnItemSelectedListener |
... | ... | |
45 | 47 |
|
46 | 48 |
public RubikSettings() |
47 | 49 |
{ |
48 |
mDurationText = new TextView[RubikSettingsEnum.LENGTH];
|
|
50 |
mDurationText = new TextView[BaseEffect.Type.LENGTH];
|
|
49 | 51 |
} |
50 | 52 |
|
51 | 53 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
... | ... | |
66 | 68 |
|
67 | 69 |
if( linearLayout!=null ) |
68 | 70 |
{ |
69 |
for (int i=0; i<RubikSettingsEnum.LENGTH; i++)
|
|
71 |
for (int i=0; i< BaseEffect.Type.LENGTH; i++)
|
|
70 | 72 |
{ |
71 | 73 |
createSettingsSection(act,linearLayout,i); |
72 | 74 |
} |
... | ... | |
81 | 83 |
|
82 | 84 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
83 | 85 |
|
84 |
private void createSettingsSection(FragmentActivity act, LinearLayout layout, int index) |
|
85 |
{ |
|
86 |
RubikSettingsEnum rsEnum = RubikSettingsEnum.getEnum(index); |
|
87 |
float scale = act.getResources().getDisplayMetrics().density; |
|
88 |
|
|
89 |
///// TEXT /////////////////////////////////////////////////////////////////////////// |
|
90 |
|
|
91 |
int layoutHeight = (int)(scale*48 + 0.5f); |
|
92 |
int padding = (int)(scale*10 + 0.5f); |
|
93 |
|
|
94 |
LinearLayout.LayoutParams textParams = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,layoutHeight); |
|
95 |
|
|
96 |
TextView textView = new TextView(act); |
|
97 |
textView.setText(rsEnum.getText()); |
|
98 |
textView.setLayoutParams(textParams); |
|
99 |
textView.setGravity(Gravity.START|Gravity.CENTER); |
|
100 |
textView.setPadding(padding,0,padding,0); |
|
101 |
textView.setTextAppearance(android.R.style.TextAppearance_Medium); |
|
102 |
layout.addView(textView); |
|
103 |
|
|
104 |
///// OUTER LAYOUT /////////////////////////////////////////////////////////////////// |
|
105 |
|
|
106 |
int margin = (int)(scale*10 + 0.5f); |
|
107 |
int color = act.getResources().getColor(R.color.grey); |
|
108 |
LinearLayout outerLayout = new LinearLayout(act); |
|
109 |
LinearLayout.LayoutParams outerLayoutParams = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,LinearLayout.LayoutParams.MATCH_PARENT, 0.5f); |
|
110 |
outerLayoutParams.bottomMargin = margin; |
|
111 |
outerLayoutParams.leftMargin = margin; |
|
112 |
outerLayoutParams.rightMargin = margin; |
|
113 |
|
|
114 |
outerLayout.setLayoutParams(outerLayoutParams); |
|
115 |
outerLayout.setGravity(Gravity.CENTER|Gravity.FILL_HORIZONTAL); |
|
116 |
outerLayout.setBackgroundColor(color); |
|
117 |
outerLayout.setOrientation(LinearLayout.VERTICAL); |
|
118 |
layout.addView(outerLayout); |
|
119 |
|
|
120 |
///// INNER LAYOUT1 ////////////////////////////////////////////////////////////////// |
|
121 |
|
|
122 |
int innerLayout1Height = (int)(scale*36 + 0.5f); |
|
123 |
LinearLayout innerLayout1 = new LinearLayout(act); |
|
124 |
LinearLayout.LayoutParams innerLayout1Params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,innerLayout1Height); |
|
125 |
|
|
126 |
innerLayout1.setLayoutParams(innerLayout1Params); |
|
127 |
innerLayout1.setGravity(Gravity.CENTER|Gravity.FILL_HORIZONTAL); |
|
128 |
innerLayout1.setOrientation(LinearLayout.HORIZONTAL); |
|
129 |
outerLayout.addView(innerLayout1); |
|
130 |
|
|
131 |
///// STUFF INSIDE INNER LAYOUT1 ///////////////////////////////////////////////////// |
|
132 |
|
|
133 |
int text1Padding = (int)(scale*5 + 0.5f); |
|
134 |
LinearLayout.LayoutParams text1LayoutParams = new LinearLayout.LayoutParams(0,layoutHeight,0.2f); |
|
135 |
|
|
136 |
TextView text1View = new TextView(act); |
|
137 |
text1View.setText(R.string.duration); |
|
138 |
text1View.setLayoutParams(text1LayoutParams); |
|
139 |
text1View.setGravity(Gravity.START|Gravity.CENTER); |
|
140 |
text1View.setPadding(text1Padding,0,text1Padding,0); |
|
141 |
text1View.setTextAppearance(android.R.style.TextAppearance_Small); |
|
142 |
innerLayout1.addView(text1View); |
|
143 |
////////////////////////////////////////////////////////////////// |
|
144 |
int text2Padding = (int)(scale*5 + 0.5f); |
|
145 |
LinearLayout.LayoutParams text2LayoutParams = new LinearLayout.LayoutParams(0,layoutHeight,0.2f); |
|
146 |
|
|
147 |
mDurationText[index] = new TextView(act); |
|
148 |
mDurationText[index].setLayoutParams(text2LayoutParams); |
|
149 |
mDurationText[index].setGravity(Gravity.END|Gravity.CENTER); |
|
150 |
mDurationText[index].setPadding(text2Padding,0,text2Padding,0); |
|
151 |
mDurationText[index].setTextAppearance(android.R.style.TextAppearance_Small); |
|
152 |
innerLayout1.addView(mDurationText[index]); |
|
153 |
////////////////////////////////////////////////////////////////// |
|
154 |
int seekPadding = (int)(scale*10 + 0.5f); |
|
155 |
LinearLayout.LayoutParams seekLayoutParams = new LinearLayout.LayoutParams(0,LinearLayout.LayoutParams.MATCH_PARENT,0.6f); |
|
156 |
|
|
157 |
SeekBar seekBar = new SeekBar(act); |
|
158 |
seekBar.setLayoutParams(seekLayoutParams); |
|
159 |
seekBar.setPadding(seekPadding,0,seekPadding,0); |
|
160 |
seekBar.setId(index); |
|
161 |
innerLayout1.addView(seekBar); |
|
162 |
|
|
163 |
seekBar.setOnSeekBarChangeListener(this); |
|
164 |
seekBar.setProgress(rsEnum.getCurrentPos()); |
|
165 |
|
|
166 |
///// INNER LAYOUT2 ////////////////////////////////////////////////////////////////// |
|
167 |
|
|
168 |
int innerLayout2Height = (int)(scale*36 + 0.5f); |
|
169 |
LinearLayout innerLayout2 = new LinearLayout(act); |
|
170 |
LinearLayout.LayoutParams innerLayout2Params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,innerLayout2Height); |
|
171 |
|
|
172 |
innerLayout2.setLayoutParams(innerLayout2Params); |
|
173 |
innerLayout2.setGravity(Gravity.CENTER|Gravity.FILL_HORIZONTAL); |
|
174 |
innerLayout2.setOrientation(LinearLayout.HORIZONTAL); |
|
175 |
outerLayout.addView(innerLayout2); |
|
176 |
|
|
177 |
///// STUFF INSIDE INNER LAYOUT2 ///////////////////////////////////////////////////// |
|
178 |
|
|
179 |
int text3Padding = (int)(scale*5 + 0.5f); |
|
180 |
LinearLayout.LayoutParams text3LayoutParams = new LinearLayout.LayoutParams(0,LinearLayout.LayoutParams.MATCH_PARENT,0.4f); |
|
181 |
|
|
182 |
TextView text3View = new TextView(act); |
|
183 |
text3View.setText(R.string.type); |
|
184 |
text3View.setLayoutParams(text3LayoutParams); |
|
185 |
text3View.setGravity(Gravity.START|Gravity.CENTER); |
|
186 |
text3View.setPadding(text3Padding,0,text3Padding,0); |
|
187 |
text3View.setTextAppearance(android.R.style.TextAppearance_Small); |
|
188 |
innerLayout2.addView(text3View); |
|
189 |
////////////////////////////////////////////////////////////////// |
|
190 |
int spinnerPadding = (int)(scale*10 + 0.5f); |
|
191 |
LinearLayout.LayoutParams spinnerLayoutParams = new LinearLayout.LayoutParams(0,LinearLayout.LayoutParams.MATCH_PARENT,0.6f); |
|
192 |
|
|
193 |
Spinner spinner = new Spinner(act); |
|
194 |
spinner.setLayoutParams(spinnerLayoutParams); |
|
195 |
spinner.setPadding(spinnerPadding,0,spinnerPadding,0); |
|
196 |
spinner.setTextAlignment(View.TEXT_ALIGNMENT_CENTER); |
|
197 |
spinner.setId(index); |
|
198 |
innerLayout2.addView(spinner); |
|
199 |
|
|
200 |
spinner.setOnItemSelectedListener(this); |
|
201 |
String[] appear = RubikSettingsEnum.getNames(index); |
|
202 |
ArrayAdapter<String> adapterType = new ArrayAdapter<>(act,android.R.layout.simple_spinner_item, appear); |
|
203 |
adapterType.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); |
|
204 |
spinner.setAdapter(adapterType); |
|
205 |
spinner.setSelection(rsEnum.getCurrentType()); |
|
206 |
} |
|
86 |
private void createSettingsSection(FragmentActivity act, LinearLayout layout, int index) |
|
87 |
{ |
|
88 |
BaseEffect.Type beType = BaseEffect.Type.getType(index); |
|
89 |
float scale = act.getResources().getDisplayMetrics().density; |
|
90 |
|
|
91 |
///// TEXT /////////////////////////////////////////////////////////////////////////// |
|
92 |
|
|
93 |
int layoutHeight = (int)(scale*48 + 0.5f); |
|
94 |
int padding = (int)(scale*10 + 0.5f); |
|
95 |
|
|
96 |
LinearLayout.LayoutParams textParams = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,layoutHeight); |
|
97 |
|
|
98 |
TextView textView = new TextView(act); |
|
99 |
textView.setText(beType.getText()); |
|
100 |
textView.setLayoutParams(textParams); |
|
101 |
textView.setGravity(Gravity.START|Gravity.CENTER); |
|
102 |
textView.setPadding(padding,0,padding,0); |
|
103 |
textView.setTextAppearance(android.R.style.TextAppearance_Medium); |
|
104 |
layout.addView(textView); |
|
105 |
|
|
106 |
///// OUTER LAYOUT /////////////////////////////////////////////////////////////////// |
|
107 |
|
|
108 |
int margin = (int)(scale*10 + 0.5f); |
|
109 |
int color = act.getResources().getColor(R.color.grey); |
|
110 |
LinearLayout outerLayout = new LinearLayout(act); |
|
111 |
LinearLayout.LayoutParams outerLayoutParams = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,LinearLayout.LayoutParams.MATCH_PARENT, 0.5f); |
|
112 |
outerLayoutParams.bottomMargin = margin; |
|
113 |
outerLayoutParams.leftMargin = margin; |
|
114 |
outerLayoutParams.rightMargin = margin; |
|
115 |
|
|
116 |
outerLayout.setLayoutParams(outerLayoutParams); |
|
117 |
outerLayout.setGravity(Gravity.CENTER|Gravity.FILL_HORIZONTAL); |
|
118 |
outerLayout.setBackgroundColor(color); |
|
119 |
outerLayout.setOrientation(LinearLayout.VERTICAL); |
|
120 |
layout.addView(outerLayout); |
|
121 |
|
|
122 |
///// INNER LAYOUT1 ////////////////////////////////////////////////////////////////// |
|
123 |
|
|
124 |
int innerLayout1Height = (int)(scale*36 + 0.5f); |
|
125 |
LinearLayout innerLayout1 = new LinearLayout(act); |
|
126 |
LinearLayout.LayoutParams innerLayout1Params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,innerLayout1Height); |
|
127 |
|
|
128 |
innerLayout1.setLayoutParams(innerLayout1Params); |
|
129 |
innerLayout1.setGravity(Gravity.CENTER|Gravity.FILL_HORIZONTAL); |
|
130 |
innerLayout1.setOrientation(LinearLayout.HORIZONTAL); |
|
131 |
outerLayout.addView(innerLayout1); |
|
132 |
|
|
133 |
///// STUFF INSIDE INNER LAYOUT1 ///////////////////////////////////////////////////// |
|
134 |
|
|
135 |
int text1Padding = (int)(scale*5 + 0.5f); |
|
136 |
LinearLayout.LayoutParams text1LayoutParams = new LinearLayout.LayoutParams(0,layoutHeight,0.2f); |
|
137 |
|
|
138 |
TextView text1View = new TextView(act); |
|
139 |
text1View.setText(R.string.duration); |
|
140 |
text1View.setLayoutParams(text1LayoutParams); |
|
141 |
text1View.setGravity(Gravity.START|Gravity.CENTER); |
|
142 |
text1View.setPadding(text1Padding,0,text1Padding,0); |
|
143 |
text1View.setTextAppearance(android.R.style.TextAppearance_Small); |
|
144 |
innerLayout1.addView(text1View); |
|
145 |
////////////////////////////////////////////////////////////////// |
|
146 |
int text2Padding = (int)(scale*5 + 0.5f); |
|
147 |
LinearLayout.LayoutParams text2LayoutParams = new LinearLayout.LayoutParams(0,layoutHeight,0.2f); |
|
148 |
|
|
149 |
mDurationText[index] = new TextView(act); |
|
150 |
mDurationText[index].setLayoutParams(text2LayoutParams); |
|
151 |
mDurationText[index].setGravity(Gravity.END|Gravity.CENTER); |
|
152 |
mDurationText[index].setPadding(text2Padding,0,text2Padding,0); |
|
153 |
mDurationText[index].setTextAppearance(android.R.style.TextAppearance_Small); |
|
154 |
innerLayout1.addView(mDurationText[index]); |
|
155 |
////////////////////////////////////////////////////////////////// |
|
156 |
int seekPadding = (int)(scale*10 + 0.5f); |
|
157 |
LinearLayout.LayoutParams seekLayoutParams = new LinearLayout.LayoutParams(0,LinearLayout.LayoutParams.MATCH_PARENT,0.6f); |
|
158 |
|
|
159 |
SeekBar seekBar = new SeekBar(act); |
|
160 |
seekBar.setLayoutParams(seekLayoutParams); |
|
161 |
seekBar.setPadding(seekPadding,0,seekPadding,0); |
|
162 |
seekBar.setId(index); |
|
163 |
innerLayout1.addView(seekBar); |
|
164 |
|
|
165 |
seekBar.setOnSeekBarChangeListener(this); |
|
166 |
seekBar.setProgress(beType.getCurrentPos()); |
|
167 |
|
|
168 |
///// INNER LAYOUT2 ////////////////////////////////////////////////////////////////// |
|
169 |
|
|
170 |
int innerLayout2Height = (int)(scale*36 + 0.5f); |
|
171 |
LinearLayout innerLayout2 = new LinearLayout(act); |
|
172 |
LinearLayout.LayoutParams innerLayout2Params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,innerLayout2Height); |
|
173 |
|
|
174 |
innerLayout2.setLayoutParams(innerLayout2Params); |
|
175 |
innerLayout2.setGravity(Gravity.CENTER|Gravity.FILL_HORIZONTAL); |
|
176 |
innerLayout2.setOrientation(LinearLayout.HORIZONTAL); |
|
177 |
outerLayout.addView(innerLayout2); |
|
178 |
|
|
179 |
///// STUFF INSIDE INNER LAYOUT2 ///////////////////////////////////////////////////// |
|
180 |
|
|
181 |
int text3Padding = (int)(scale*5 + 0.5f); |
|
182 |
LinearLayout.LayoutParams text3LayoutParams = new LinearLayout.LayoutParams(0,LinearLayout.LayoutParams.MATCH_PARENT,0.4f); |
|
183 |
|
|
184 |
TextView text3View = new TextView(act); |
|
185 |
text3View.setText(R.string.type); |
|
186 |
text3View.setLayoutParams(text3LayoutParams); |
|
187 |
text3View.setGravity(Gravity.START|Gravity.CENTER); |
|
188 |
text3View.setPadding(text3Padding,0,text3Padding,0); |
|
189 |
text3View.setTextAppearance(android.R.style.TextAppearance_Small); |
|
190 |
innerLayout2.addView(text3View); |
|
191 |
////////////////////////////////////////////////////////////////// |
|
192 |
int spinnerPadding = (int)(scale*10 + 0.5f); |
|
193 |
LinearLayout.LayoutParams spinnerLayoutParams = new LinearLayout.LayoutParams(0,LinearLayout.LayoutParams.MATCH_PARENT,0.6f); |
|
194 |
|
|
195 |
Spinner spinner = new Spinner(act); |
|
196 |
spinner.setLayoutParams(spinnerLayoutParams); |
|
197 |
spinner.setPadding(spinnerPadding,0,spinnerPadding,0); |
|
198 |
spinner.setTextAlignment(View.TEXT_ALIGNMENT_CENTER); |
|
199 |
spinner.setId(index); |
|
200 |
innerLayout2.addView(spinner); |
|
201 |
|
|
202 |
spinner.setOnItemSelectedListener(this); |
|
203 |
String[] appear = BaseEffect.Type.getType(index).getNames(); |
|
204 |
|
|
205 |
ArrayAdapter<String> adapterType = new ArrayAdapter<>(act,android.R.layout.simple_spinner_item, appear); |
|
206 |
adapterType.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); |
|
207 |
spinner.setAdapter(adapterType); |
|
208 |
spinner.setSelection(beType.getCurrentType()); |
|
209 |
} |
|
207 | 210 |
|
208 | 211 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
209 | 212 |
|
210 |
public void onItemSelected(AdapterView<?> parent, View view, int pos, long id)
|
|
211 |
{
|
|
212 |
int parentID = parent.getId();
|
|
213 |
public void onItemSelected(AdapterView<?> parent, View view, int pos, long id) |
|
214 |
{ |
|
215 |
int parentID = parent.getId(); |
|
213 | 216 |
|
214 |
if( parentID>=0 && parentID< RubikSettingsEnum.LENGTH) // ith spinner's ID is equal to i (see createSettingSection) |
|
215 |
{ |
|
216 |
RubikSettingsEnum.getEnum(parentID).setCurrentType(pos); |
|
217 |
} |
|
217 |
if( parentID>=0 && parentID< BaseEffect.Type.LENGTH) // ith spinner's ID is equal to i (see createSettingSection) |
|
218 |
{ |
|
219 |
BaseEffect.Type.getType(parentID).setCurrentType(pos); |
|
218 | 220 |
} |
221 |
} |
|
219 | 222 |
|
220 | 223 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
221 | 224 |
|
222 |
public void onProgressChanged(SeekBar bar, int progress, boolean fromUser)
|
|
223 |
{
|
|
224 |
int barID = bar.getId();
|
|
225 |
public void onProgressChanged(SeekBar bar, int progress, boolean fromUser) |
|
226 |
{ |
|
227 |
int barID = bar.getId(); |
|
225 | 228 |
|
226 |
if( barID>=0 && barID< RubikSettingsEnum.LENGTH) // ith seekbar's ID is equal to i (see createSettingSection) |
|
227 |
{ |
|
228 |
RubikSettingsEnum.getEnum(barID).setCurrentPos(progress); |
|
229 |
int ms = RubikSettingsEnum.translatePos(progress); |
|
230 |
mDurationText[barID].setText(getString(R.string.ms_placeholder,ms)); |
|
231 |
} |
|
229 |
if( barID>=0 && barID< BaseEffect.Type.LENGTH) // ith seekbar's ID is equal to i (see createSettingSection) |
|
230 |
{ |
|
231 |
BaseEffect.Type.getType(barID).setCurrentPos(progress); |
|
232 |
int ms = BaseEffect.Type.translatePos(progress); |
|
233 |
mDurationText[barID].setText(getString(R.string.ms_placeholder,ms)); |
|
232 | 234 |
} |
235 |
} |
|
233 | 236 |
|
234 | 237 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
235 | 238 |
|
236 |
public void onNothingSelected(AdapterView<?> parent) { }
|
|
237 |
public void onStartTrackingTouch(SeekBar bar) { }
|
|
238 |
public void onStopTrackingTouch(SeekBar bar) { }
|
|
239 |
public void onNothingSelected(AdapterView<?> parent) { } |
|
240 |
public void onStartTrackingTouch(SeekBar bar) { } |
|
241 |
public void onStopTrackingTouch(SeekBar bar) { } |
|
239 | 242 |
} |
Also available in: Unified diff
RubikCube: renamed RubikSettingsEnum to BaseEffect and moved it to the 'effect' package.