1 |
f6fcf06a
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
2 |
|
|
// Copyright 2019 Leszek Koltunski //
|
3 |
|
|
// //
|
4 |
fdec60a3
|
Leszek Koltunski
|
// This file is part of Magic Cube. //
|
5 |
f6fcf06a
|
Leszek Koltunski
|
// //
|
6 |
fdec60a3
|
Leszek Koltunski
|
// Magic Cube is free software: you can redistribute it and/or modify //
|
7 |
f6fcf06a
|
Leszek Koltunski
|
// it under the terms of the GNU General Public License as published by //
|
8 |
|
|
// the Free Software Foundation, either version 2 of the License, or //
|
9 |
|
|
// (at your option) any later version. //
|
10 |
|
|
// //
|
11 |
fdec60a3
|
Leszek Koltunski
|
// Magic Cube is distributed in the hope that it will be useful, //
|
12 |
f6fcf06a
|
Leszek Koltunski
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of //
|
13 |
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
|
14 |
|
|
// GNU General Public License for more details. //
|
15 |
|
|
// //
|
16 |
|
|
// You should have received a copy of the GNU General Public License //
|
17 |
fdec60a3
|
Leszek Koltunski
|
// along with Magic Cube. If not, see <http://www.gnu.org/licenses/>. //
|
18 |
f6fcf06a
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
19 |
|
|
|
20 |
|
|
package org.distorted.magic;
|
21 |
|
|
|
22 |
|
|
import android.app.Dialog;
|
23 |
|
|
import android.os.Bundle;
|
24 |
|
|
import android.support.annotation.NonNull;
|
25 |
|
|
import android.support.v4.app.FragmentActivity;
|
26 |
b8b38548
|
Leszek Koltunski
|
import android.support.v4.content.ContextCompat;
|
27 |
f6fcf06a
|
Leszek Koltunski
|
import android.support.v7.app.AlertDialog;
|
28 |
|
|
import android.support.v7.app.AppCompatDialogFragment;
|
29 |
0c96b376
|
Leszek Koltunski
|
import android.util.DisplayMetrics;
|
30 |
22fdfc36
|
Leszek Koltunski
|
import android.view.Gravity;
|
31 |
f6fcf06a
|
Leszek Koltunski
|
import android.view.LayoutInflater;
|
32 |
|
|
import android.view.View;
|
33 |
|
|
import android.widget.AdapterView;
|
34 |
|
|
import android.widget.ArrayAdapter;
|
35 |
22fdfc36
|
Leszek Koltunski
|
import android.widget.LinearLayout;
|
36 |
f6fcf06a
|
Leszek Koltunski
|
import android.widget.SeekBar;
|
37 |
|
|
import android.widget.Spinner;
|
38 |
1cbcc6bf
|
Leszek Koltunski
|
import android.widget.TextView;
|
39 |
f6fcf06a
|
Leszek Koltunski
|
|
40 |
64975793
|
Leszek Koltunski
|
import org.distorted.effect.BaseEffect;
|
41 |
|
|
|
42 |
f6fcf06a
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
43 |
|
|
|
44 |
|
|
public class RubikSettings extends AppCompatDialogFragment implements SeekBar.OnSeekBarChangeListener, AdapterView.OnItemSelectedListener
|
45 |
|
|
{
|
46 |
22fdfc36
|
Leszek Koltunski
|
private TextView[] mDurationText;
|
47 |
|
|
|
48 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
49 |
a7012218
|
Leszek Koltunski
|
|
50 |
64975793
|
Leszek Koltunski
|
private void createSettingsSection(FragmentActivity act, LinearLayout layout, int index)
|
51 |
|
|
{
|
52 |
|
|
BaseEffect.Type beType = BaseEffect.Type.getType(index);
|
53 |
0c96b376
|
Leszek Koltunski
|
DisplayMetrics metrics = act.getResources().getDisplayMetrics();
|
54 |
|
|
float scale = metrics.density;
|
55 |
|
|
|
56 |
|
|
int textH;
|
57 |
|
|
int layoH;
|
58 |
|
|
|
59 |
|
|
if( metrics.widthPixels > metrics.heightPixels )
|
60 |
|
|
{
|
61 |
|
|
textH = 20;
|
62 |
|
|
layoH = 26;
|
63 |
|
|
}
|
64 |
|
|
else
|
65 |
|
|
{
|
66 |
|
|
textH = 32;
|
67 |
|
|
layoH = 36;
|
68 |
|
|
}
|
69 |
64975793
|
Leszek Koltunski
|
|
70 |
|
|
///// OUTER LAYOUT ///////////////////////////////////////////////////////////////////
|
71 |
|
|
|
72 |
|
|
int margin = (int)(scale*10 + 0.5f);
|
73 |
b8b38548
|
Leszek Koltunski
|
int color = ContextCompat.getColor(act, R.color.grey);
|
74 |
64975793
|
Leszek Koltunski
|
LinearLayout outerLayout = new LinearLayout(act);
|
75 |
|
|
LinearLayout.LayoutParams outerLayoutParams = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,LinearLayout.LayoutParams.MATCH_PARENT, 0.5f);
|
76 |
47ba5ddc
|
Leszek Koltunski
|
outerLayoutParams.topMargin = margin;
|
77 |
64975793
|
Leszek Koltunski
|
outerLayoutParams.bottomMargin = margin;
|
78 |
|
|
outerLayoutParams.leftMargin = margin;
|
79 |
|
|
outerLayoutParams.rightMargin = margin;
|
80 |
|
|
|
81 |
|
|
outerLayout.setLayoutParams(outerLayoutParams);
|
82 |
|
|
outerLayout.setGravity(Gravity.CENTER|Gravity.FILL_HORIZONTAL);
|
83 |
|
|
outerLayout.setBackgroundColor(color);
|
84 |
|
|
outerLayout.setOrientation(LinearLayout.VERTICAL);
|
85 |
|
|
layout.addView(outerLayout);
|
86 |
|
|
|
87 |
47ba5ddc
|
Leszek Koltunski
|
///// TEXT ///////////////////////////////////////////////////////////////////////////
|
88 |
|
|
|
89 |
0c96b376
|
Leszek Koltunski
|
int layoutHeight = (int)(scale*textH + 0.5f);
|
90 |
|
|
int padding = (int)(scale*10 + 0.5f);
|
91 |
47ba5ddc
|
Leszek Koltunski
|
|
92 |
|
|
LinearLayout.LayoutParams textParams = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,layoutHeight);
|
93 |
|
|
|
94 |
|
|
TextView textView = new TextView(act);
|
95 |
|
|
textView.setText(beType.getText());
|
96 |
|
|
textView.setLayoutParams(textParams);
|
97 |
|
|
textView.setGravity(Gravity.CENTER);
|
98 |
|
|
textView.setPadding(padding,0,padding,0);
|
99 |
|
|
textView.setTextAppearance(android.R.style.TextAppearance_Small);
|
100 |
|
|
outerLayout.addView(textView);
|
101 |
|
|
|
102 |
64975793
|
Leszek Koltunski
|
///// INNER LAYOUT1 //////////////////////////////////////////////////////////////////
|
103 |
|
|
|
104 |
0c96b376
|
Leszek Koltunski
|
int innerLayout1Height = (int)(scale*layoH + 0.5f);
|
105 |
64975793
|
Leszek Koltunski
|
LinearLayout innerLayout1 = new LinearLayout(act);
|
106 |
|
|
LinearLayout.LayoutParams innerLayout1Params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,innerLayout1Height);
|
107 |
|
|
|
108 |
|
|
innerLayout1.setLayoutParams(innerLayout1Params);
|
109 |
|
|
innerLayout1.setGravity(Gravity.CENTER|Gravity.FILL_HORIZONTAL);
|
110 |
|
|
innerLayout1.setOrientation(LinearLayout.HORIZONTAL);
|
111 |
|
|
outerLayout.addView(innerLayout1);
|
112 |
|
|
|
113 |
|
|
///// STUFF INSIDE INNER LAYOUT1 /////////////////////////////////////////////////////
|
114 |
|
|
|
115 |
|
|
int text1Padding = (int)(scale*5 + 0.5f);
|
116 |
|
|
LinearLayout.LayoutParams text1LayoutParams = new LinearLayout.LayoutParams(0,layoutHeight,0.2f);
|
117 |
|
|
|
118 |
|
|
TextView text1View = new TextView(act);
|
119 |
|
|
text1View.setText(R.string.duration);
|
120 |
|
|
text1View.setLayoutParams(text1LayoutParams);
|
121 |
|
|
text1View.setGravity(Gravity.START|Gravity.CENTER);
|
122 |
|
|
text1View.setPadding(text1Padding,0,text1Padding,0);
|
123 |
|
|
text1View.setTextAppearance(android.R.style.TextAppearance_Small);
|
124 |
|
|
innerLayout1.addView(text1View);
|
125 |
|
|
//////////////////////////////////////////////////////////////////
|
126 |
|
|
int text2Padding = (int)(scale*5 + 0.5f);
|
127 |
|
|
LinearLayout.LayoutParams text2LayoutParams = new LinearLayout.LayoutParams(0,layoutHeight,0.2f);
|
128 |
|
|
|
129 |
|
|
mDurationText[index] = new TextView(act);
|
130 |
|
|
mDurationText[index].setLayoutParams(text2LayoutParams);
|
131 |
|
|
mDurationText[index].setGravity(Gravity.END|Gravity.CENTER);
|
132 |
|
|
mDurationText[index].setPadding(text2Padding,0,text2Padding,0);
|
133 |
|
|
mDurationText[index].setTextAppearance(android.R.style.TextAppearance_Small);
|
134 |
|
|
innerLayout1.addView(mDurationText[index]);
|
135 |
|
|
//////////////////////////////////////////////////////////////////
|
136 |
|
|
int seekPadding = (int)(scale*10 + 0.5f);
|
137 |
|
|
LinearLayout.LayoutParams seekLayoutParams = new LinearLayout.LayoutParams(0,LinearLayout.LayoutParams.MATCH_PARENT,0.6f);
|
138 |
|
|
|
139 |
|
|
SeekBar seekBar = new SeekBar(act);
|
140 |
|
|
seekBar.setLayoutParams(seekLayoutParams);
|
141 |
|
|
seekBar.setPadding(seekPadding,0,seekPadding,0);
|
142 |
|
|
seekBar.setId(index);
|
143 |
|
|
innerLayout1.addView(seekBar);
|
144 |
|
|
|
145 |
|
|
seekBar.setOnSeekBarChangeListener(this);
|
146 |
|
|
seekBar.setProgress(beType.getCurrentPos());
|
147 |
|
|
|
148 |
|
|
///// INNER LAYOUT2 //////////////////////////////////////////////////////////////////
|
149 |
|
|
|
150 |
0c96b376
|
Leszek Koltunski
|
int innerLayout2Height = (int)(scale*layoH + 0.5f);
|
151 |
64975793
|
Leszek Koltunski
|
LinearLayout innerLayout2 = new LinearLayout(act);
|
152 |
|
|
LinearLayout.LayoutParams innerLayout2Params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,innerLayout2Height);
|
153 |
|
|
|
154 |
|
|
innerLayout2.setLayoutParams(innerLayout2Params);
|
155 |
|
|
innerLayout2.setGravity(Gravity.CENTER|Gravity.FILL_HORIZONTAL);
|
156 |
|
|
innerLayout2.setOrientation(LinearLayout.HORIZONTAL);
|
157 |
|
|
outerLayout.addView(innerLayout2);
|
158 |
|
|
|
159 |
|
|
///// STUFF INSIDE INNER LAYOUT2 /////////////////////////////////////////////////////
|
160 |
|
|
|
161 |
|
|
int text3Padding = (int)(scale*5 + 0.5f);
|
162 |
|
|
LinearLayout.LayoutParams text3LayoutParams = new LinearLayout.LayoutParams(0,LinearLayout.LayoutParams.MATCH_PARENT,0.4f);
|
163 |
|
|
|
164 |
|
|
TextView text3View = new TextView(act);
|
165 |
|
|
text3View.setText(R.string.type);
|
166 |
|
|
text3View.setLayoutParams(text3LayoutParams);
|
167 |
|
|
text3View.setGravity(Gravity.START|Gravity.CENTER);
|
168 |
|
|
text3View.setPadding(text3Padding,0,text3Padding,0);
|
169 |
|
|
text3View.setTextAppearance(android.R.style.TextAppearance_Small);
|
170 |
|
|
innerLayout2.addView(text3View);
|
171 |
|
|
//////////////////////////////////////////////////////////////////
|
172 |
|
|
int spinnerPadding = (int)(scale*10 + 0.5f);
|
173 |
|
|
LinearLayout.LayoutParams spinnerLayoutParams = new LinearLayout.LayoutParams(0,LinearLayout.LayoutParams.MATCH_PARENT,0.6f);
|
174 |
|
|
|
175 |
|
|
Spinner spinner = new Spinner(act);
|
176 |
|
|
spinner.setLayoutParams(spinnerLayoutParams);
|
177 |
|
|
spinner.setPadding(spinnerPadding,0,spinnerPadding,0);
|
178 |
|
|
spinner.setTextAlignment(View.TEXT_ALIGNMENT_CENTER);
|
179 |
0c96b376
|
Leszek Koltunski
|
spinner.setId(index+BaseEffect.Type.LENGTH);
|
180 |
64975793
|
Leszek Koltunski
|
innerLayout2.addView(spinner);
|
181 |
|
|
|
182 |
|
|
spinner.setOnItemSelectedListener(this);
|
183 |
|
|
String[] appear = BaseEffect.Type.getType(index).getNames();
|
184 |
|
|
|
185 |
|
|
ArrayAdapter<String> adapterType = new ArrayAdapter<>(act,android.R.layout.simple_spinner_item, appear);
|
186 |
|
|
adapterType.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
|
187 |
|
|
spinner.setAdapter(adapterType);
|
188 |
|
|
spinner.setSelection(beType.getCurrentType());
|
189 |
|
|
}
|
190 |
f6fcf06a
|
Leszek Koltunski
|
|
191 |
47ba5ddc
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
192 |
|
|
// PUBLIC API
|
193 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
194 |
|
|
|
195 |
|
|
public RubikSettings()
|
196 |
|
|
{
|
197 |
|
|
mDurationText = new TextView[BaseEffect.Type.LENGTH];
|
198 |
|
|
}
|
199 |
|
|
|
200 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
201 |
|
|
|
202 |
|
|
@NonNull
|
203 |
|
|
@Override
|
204 |
|
|
public Dialog onCreateDialog(Bundle savedInstanceState)
|
205 |
|
|
{
|
206 |
|
|
FragmentActivity act = getActivity();
|
207 |
|
|
AlertDialog.Builder builder = new AlertDialog.Builder(act);
|
208 |
|
|
builder.setCancelable(false);
|
209 |
|
|
|
210 |
|
|
LayoutInflater inflater = act.getLayoutInflater();
|
211 |
|
|
final View view = inflater.inflate(R.layout.settings, null);
|
212 |
|
|
builder.setView(view);
|
213 |
|
|
|
214 |
|
|
LinearLayout linearLayout = view.findViewById(R.id.main_settings_layout);
|
215 |
|
|
|
216 |
|
|
if( linearLayout!=null )
|
217 |
|
|
{
|
218 |
|
|
for (int i=0; i< BaseEffect.Type.LENGTH; i++)
|
219 |
|
|
{
|
220 |
|
|
createSettingsSection(act,linearLayout,i);
|
221 |
|
|
}
|
222 |
|
|
}
|
223 |
|
|
else
|
224 |
|
|
{
|
225 |
|
|
android.util.Log.e("settings", "linearLayout NULL!");
|
226 |
|
|
}
|
227 |
|
|
|
228 |
|
|
return builder.create();
|
229 |
|
|
}
|
230 |
|
|
|
231 |
f6fcf06a
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
232 |
|
|
|
233 |
64975793
|
Leszek Koltunski
|
public void onItemSelected(AdapterView<?> parent, View view, int pos, long id)
|
234 |
|
|
{
|
235 |
|
|
int parentID = parent.getId();
|
236 |
0c96b376
|
Leszek Koltunski
|
int len = BaseEffect.Type.LENGTH;
|
237 |
22fdfc36
|
Leszek Koltunski
|
|
238 |
0c96b376
|
Leszek Koltunski
|
if( parentID>=len && parentID< 2*len) // ith spinner's ID is equal to i+LENGTH (see createSettingSection)
|
239 |
64975793
|
Leszek Koltunski
|
{
|
240 |
0c96b376
|
Leszek Koltunski
|
BaseEffect.Type.getType(parentID-len).setCurrentType(pos);
|
241 |
f6fcf06a
|
Leszek Koltunski
|
}
|
242 |
64975793
|
Leszek Koltunski
|
}
|
243 |
f6fcf06a
|
Leszek Koltunski
|
|
244 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
245 |
|
|
|
246 |
64975793
|
Leszek Koltunski
|
public void onProgressChanged(SeekBar bar, int progress, boolean fromUser)
|
247 |
|
|
{
|
248 |
|
|
int barID = bar.getId();
|
249 |
22fdfc36
|
Leszek Koltunski
|
|
250 |
64975793
|
Leszek Koltunski
|
if( barID>=0 && barID< BaseEffect.Type.LENGTH) // ith seekbar's ID is equal to i (see createSettingSection)
|
251 |
|
|
{
|
252 |
|
|
BaseEffect.Type.getType(barID).setCurrentPos(progress);
|
253 |
|
|
int ms = BaseEffect.Type.translatePos(progress);
|
254 |
|
|
mDurationText[barID].setText(getString(R.string.ms_placeholder,ms));
|
255 |
f6fcf06a
|
Leszek Koltunski
|
}
|
256 |
64975793
|
Leszek Koltunski
|
}
|
257 |
f6fcf06a
|
Leszek Koltunski
|
|
258 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
259 |
|
|
|
260 |
64975793
|
Leszek Koltunski
|
public void onNothingSelected(AdapterView<?> parent) { }
|
261 |
|
|
public void onStartTrackingTouch(SeekBar bar) { }
|
262 |
|
|
public void onStopTrackingTouch(SeekBar bar) { }
|
263 |
f6fcf06a
|
Leszek Koltunski
|
}
|