| 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 |
4918f19c
|
Leszek Koltunski
|
import android.content.DialogInterface;
|
| 24 |
f6fcf06a
|
Leszek Koltunski
|
import android.os.Bundle;
|
| 25 |
|
|
import android.support.annotation.NonNull;
|
| 26 |
|
|
import android.support.v4.app.FragmentActivity;
|
| 27 |
b8b38548
|
Leszek Koltunski
|
import android.support.v4.content.ContextCompat;
|
| 28 |
f6fcf06a
|
Leszek Koltunski
|
import android.support.v7.app.AlertDialog;
|
| 29 |
|
|
import android.support.v7.app.AppCompatDialogFragment;
|
| 30 |
0c96b376
|
Leszek Koltunski
|
import android.util.DisplayMetrics;
|
| 31 |
22fdfc36
|
Leszek Koltunski
|
import android.view.Gravity;
|
| 32 |
f6fcf06a
|
Leszek Koltunski
|
import android.view.LayoutInflater;
|
| 33 |
|
|
import android.view.View;
|
| 34 |
|
|
import android.widget.AdapterView;
|
| 35 |
|
|
import android.widget.ArrayAdapter;
|
| 36 |
22fdfc36
|
Leszek Koltunski
|
import android.widget.LinearLayout;
|
| 37 |
f6fcf06a
|
Leszek Koltunski
|
import android.widget.SeekBar;
|
| 38 |
|
|
import android.widget.Spinner;
|
| 39 |
1cbcc6bf
|
Leszek Koltunski
|
import android.widget.TextView;
|
| 40 |
f6fcf06a
|
Leszek Koltunski
|
|
| 41 |
64975793
|
Leszek Koltunski
|
import org.distorted.effect.BaseEffect;
|
| 42 |
|
|
|
| 43 |
f6fcf06a
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
| 44 |
|
|
|
| 45 |
0fd3ac1f
|
Leszek Koltunski
|
public class RubikDialogSettings extends AppCompatDialogFragment implements SeekBar.OnSeekBarChangeListener, AdapterView.OnItemSelectedListener
|
| 46 |
f6fcf06a
|
Leszek Koltunski
|
{
|
| 47 |
22fdfc36
|
Leszek Koltunski
|
private TextView[] mDurationText;
|
| 48 |
|
|
|
| 49 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
| 50 |
a7012218
|
Leszek Koltunski
|
|
| 51 |
0fd3ac1f
|
Leszek Koltunski
|
private void addSettingsSection(FragmentActivity act, LinearLayout layout, int index)
|
| 52 |
64975793
|
Leszek Koltunski
|
{
|
| 53 |
|
|
BaseEffect.Type beType = BaseEffect.Type.getType(index);
|
| 54 |
0c96b376
|
Leszek Koltunski
|
DisplayMetrics metrics = act.getResources().getDisplayMetrics();
|
| 55 |
|
|
float scale = metrics.density;
|
| 56 |
|
|
|
| 57 |
0fd3ac1f
|
Leszek Koltunski
|
int textH=32;
|
| 58 |
|
|
int layoH=36;
|
| 59 |
|
|
int margH=10;
|
| 60 |
|
|
/*
|
| 61 |
0c96b376
|
Leszek Koltunski
|
if( metrics.widthPixels > metrics.heightPixels )
|
| 62 |
|
|
{
|
| 63 |
0fd3ac1f
|
Leszek Koltunski
|
textH = 18;
|
| 64 |
|
|
layoH = 25;
|
| 65 |
|
|
margH = 5;
|
| 66 |
0c96b376
|
Leszek Koltunski
|
}
|
| 67 |
|
|
else
|
| 68 |
|
|
{
|
| 69 |
|
|
textH = 32;
|
| 70 |
|
|
layoH = 36;
|
| 71 |
0fd3ac1f
|
Leszek Koltunski
|
margH = 10;
|
| 72 |
0c96b376
|
Leszek Koltunski
|
}
|
| 73 |
0fd3ac1f
|
Leszek Koltunski
|
*/
|
| 74 |
64975793
|
Leszek Koltunski
|
///// OUTER LAYOUT ///////////////////////////////////////////////////////////////////
|
| 75 |
|
|
|
| 76 |
0fd3ac1f
|
Leszek Koltunski
|
int margin = (int)(scale*margH + 0.5f);
|
| 77 |
b8b38548
|
Leszek Koltunski
|
int color = ContextCompat.getColor(act, R.color.grey);
|
| 78 |
64975793
|
Leszek Koltunski
|
LinearLayout outerLayout = new LinearLayout(act);
|
| 79 |
|
|
LinearLayout.LayoutParams outerLayoutParams = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,LinearLayout.LayoutParams.MATCH_PARENT, 0.5f);
|
| 80 |
47ba5ddc
|
Leszek Koltunski
|
outerLayoutParams.topMargin = margin;
|
| 81 |
4918f19c
|
Leszek Koltunski
|
outerLayoutParams.bottomMargin = 0;
|
| 82 |
64975793
|
Leszek Koltunski
|
outerLayoutParams.leftMargin = margin;
|
| 83 |
|
|
outerLayoutParams.rightMargin = margin;
|
| 84 |
|
|
|
| 85 |
|
|
outerLayout.setLayoutParams(outerLayoutParams);
|
| 86 |
|
|
outerLayout.setGravity(Gravity.CENTER|Gravity.FILL_HORIZONTAL);
|
| 87 |
|
|
outerLayout.setBackgroundColor(color);
|
| 88 |
|
|
outerLayout.setOrientation(LinearLayout.VERTICAL);
|
| 89 |
|
|
layout.addView(outerLayout);
|
| 90 |
|
|
|
| 91 |
47ba5ddc
|
Leszek Koltunski
|
///// TEXT ///////////////////////////////////////////////////////////////////////////
|
| 92 |
|
|
|
| 93 |
0c96b376
|
Leszek Koltunski
|
int layoutHeight = (int)(scale*textH + 0.5f);
|
| 94 |
|
|
int padding = (int)(scale*10 + 0.5f);
|
| 95 |
47ba5ddc
|
Leszek Koltunski
|
|
| 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.CENTER);
|
| 102 |
|
|
textView.setPadding(padding,0,padding,0);
|
| 103 |
|
|
textView.setTextAppearance(android.R.style.TextAppearance_Small);
|
| 104 |
|
|
outerLayout.addView(textView);
|
| 105 |
|
|
|
| 106 |
64975793
|
Leszek Koltunski
|
///// INNER LAYOUT1 //////////////////////////////////////////////////////////////////
|
| 107 |
|
|
|
| 108 |
0c96b376
|
Leszek Koltunski
|
int innerLayout1Height = (int)(scale*layoH + 0.5f);
|
| 109 |
64975793
|
Leszek Koltunski
|
LinearLayout innerLayout1 = new LinearLayout(act);
|
| 110 |
|
|
LinearLayout.LayoutParams innerLayout1Params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,innerLayout1Height);
|
| 111 |
|
|
|
| 112 |
|
|
innerLayout1.setLayoutParams(innerLayout1Params);
|
| 113 |
|
|
innerLayout1.setGravity(Gravity.CENTER|Gravity.FILL_HORIZONTAL);
|
| 114 |
|
|
innerLayout1.setOrientation(LinearLayout.HORIZONTAL);
|
| 115 |
|
|
outerLayout.addView(innerLayout1);
|
| 116 |
|
|
|
| 117 |
|
|
///// STUFF INSIDE INNER LAYOUT1 /////////////////////////////////////////////////////
|
| 118 |
|
|
|
| 119 |
|
|
int text1Padding = (int)(scale*5 + 0.5f);
|
| 120 |
|
|
LinearLayout.LayoutParams text1LayoutParams = new LinearLayout.LayoutParams(0,layoutHeight,0.2f);
|
| 121 |
|
|
|
| 122 |
|
|
TextView text1View = new TextView(act);
|
| 123 |
|
|
text1View.setText(R.string.duration);
|
| 124 |
|
|
text1View.setLayoutParams(text1LayoutParams);
|
| 125 |
|
|
text1View.setGravity(Gravity.START|Gravity.CENTER);
|
| 126 |
|
|
text1View.setPadding(text1Padding,0,text1Padding,0);
|
| 127 |
|
|
text1View.setTextAppearance(android.R.style.TextAppearance_Small);
|
| 128 |
|
|
innerLayout1.addView(text1View);
|
| 129 |
|
|
//////////////////////////////////////////////////////////////////
|
| 130 |
|
|
int text2Padding = (int)(scale*5 + 0.5f);
|
| 131 |
|
|
LinearLayout.LayoutParams text2LayoutParams = new LinearLayout.LayoutParams(0,layoutHeight,0.2f);
|
| 132 |
|
|
|
| 133 |
|
|
mDurationText[index] = new TextView(act);
|
| 134 |
|
|
mDurationText[index].setLayoutParams(text2LayoutParams);
|
| 135 |
|
|
mDurationText[index].setGravity(Gravity.END|Gravity.CENTER);
|
| 136 |
|
|
mDurationText[index].setPadding(text2Padding,0,text2Padding,0);
|
| 137 |
|
|
mDurationText[index].setTextAppearance(android.R.style.TextAppearance_Small);
|
| 138 |
|
|
innerLayout1.addView(mDurationText[index]);
|
| 139 |
|
|
//////////////////////////////////////////////////////////////////
|
| 140 |
|
|
int seekPadding = (int)(scale*10 + 0.5f);
|
| 141 |
|
|
LinearLayout.LayoutParams seekLayoutParams = new LinearLayout.LayoutParams(0,LinearLayout.LayoutParams.MATCH_PARENT,0.6f);
|
| 142 |
|
|
|
| 143 |
|
|
SeekBar seekBar = new SeekBar(act);
|
| 144 |
|
|
seekBar.setLayoutParams(seekLayoutParams);
|
| 145 |
|
|
seekBar.setPadding(seekPadding,0,seekPadding,0);
|
| 146 |
|
|
seekBar.setId(index);
|
| 147 |
|
|
innerLayout1.addView(seekBar);
|
| 148 |
|
|
|
| 149 |
|
|
seekBar.setOnSeekBarChangeListener(this);
|
| 150 |
|
|
seekBar.setProgress(beType.getCurrentPos());
|
| 151 |
|
|
|
| 152 |
|
|
///// INNER LAYOUT2 //////////////////////////////////////////////////////////////////
|
| 153 |
|
|
|
| 154 |
0c96b376
|
Leszek Koltunski
|
int innerLayout2Height = (int)(scale*layoH + 0.5f);
|
| 155 |
64975793
|
Leszek Koltunski
|
LinearLayout innerLayout2 = new LinearLayout(act);
|
| 156 |
|
|
LinearLayout.LayoutParams innerLayout2Params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,innerLayout2Height);
|
| 157 |
|
|
|
| 158 |
|
|
innerLayout2.setLayoutParams(innerLayout2Params);
|
| 159 |
|
|
innerLayout2.setGravity(Gravity.CENTER|Gravity.FILL_HORIZONTAL);
|
| 160 |
|
|
innerLayout2.setOrientation(LinearLayout.HORIZONTAL);
|
| 161 |
|
|
outerLayout.addView(innerLayout2);
|
| 162 |
|
|
|
| 163 |
|
|
///// STUFF INSIDE INNER LAYOUT2 /////////////////////////////////////////////////////
|
| 164 |
|
|
|
| 165 |
|
|
int text3Padding = (int)(scale*5 + 0.5f);
|
| 166 |
|
|
LinearLayout.LayoutParams text3LayoutParams = new LinearLayout.LayoutParams(0,LinearLayout.LayoutParams.MATCH_PARENT,0.4f);
|
| 167 |
|
|
|
| 168 |
|
|
TextView text3View = new TextView(act);
|
| 169 |
|
|
text3View.setText(R.string.type);
|
| 170 |
|
|
text3View.setLayoutParams(text3LayoutParams);
|
| 171 |
|
|
text3View.setGravity(Gravity.START|Gravity.CENTER);
|
| 172 |
|
|
text3View.setPadding(text3Padding,0,text3Padding,0);
|
| 173 |
|
|
text3View.setTextAppearance(android.R.style.TextAppearance_Small);
|
| 174 |
|
|
innerLayout2.addView(text3View);
|
| 175 |
|
|
//////////////////////////////////////////////////////////////////
|
| 176 |
|
|
int spinnerPadding = (int)(scale*10 + 0.5f);
|
| 177 |
|
|
LinearLayout.LayoutParams spinnerLayoutParams = new LinearLayout.LayoutParams(0,LinearLayout.LayoutParams.MATCH_PARENT,0.6f);
|
| 178 |
|
|
|
| 179 |
|
|
Spinner spinner = new Spinner(act);
|
| 180 |
|
|
spinner.setLayoutParams(spinnerLayoutParams);
|
| 181 |
|
|
spinner.setPadding(spinnerPadding,0,spinnerPadding,0);
|
| 182 |
|
|
spinner.setTextAlignment(View.TEXT_ALIGNMENT_CENTER);
|
| 183 |
0c96b376
|
Leszek Koltunski
|
spinner.setId(index+BaseEffect.Type.LENGTH);
|
| 184 |
64975793
|
Leszek Koltunski
|
innerLayout2.addView(spinner);
|
| 185 |
|
|
|
| 186 |
|
|
spinner.setOnItemSelectedListener(this);
|
| 187 |
|
|
String[] appear = BaseEffect.Type.getType(index).getNames();
|
| 188 |
|
|
|
| 189 |
|
|
ArrayAdapter<String> adapterType = new ArrayAdapter<>(act,android.R.layout.simple_spinner_item, appear);
|
| 190 |
|
|
adapterType.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
|
| 191 |
|
|
spinner.setAdapter(adapterType);
|
| 192 |
|
|
spinner.setSelection(beType.getCurrentType());
|
| 193 |
|
|
}
|
| 194 |
f6fcf06a
|
Leszek Koltunski
|
|
| 195 |
47ba5ddc
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
| 196 |
|
|
// PUBLIC API
|
| 197 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
| 198 |
|
|
|
| 199 |
0fd3ac1f
|
Leszek Koltunski
|
public RubikDialogSettings()
|
| 200 |
47ba5ddc
|
Leszek Koltunski
|
{
|
| 201 |
|
|
mDurationText = new TextView[BaseEffect.Type.LENGTH];
|
| 202 |
|
|
}
|
| 203 |
|
|
|
| 204 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
| 205 |
|
|
|
| 206 |
|
|
@NonNull
|
| 207 |
|
|
@Override
|
| 208 |
|
|
public Dialog onCreateDialog(Bundle savedInstanceState)
|
| 209 |
|
|
{
|
| 210 |
|
|
FragmentActivity act = getActivity();
|
| 211 |
0fd3ac1f
|
Leszek Koltunski
|
LayoutInflater inflater = act.getLayoutInflater();
|
| 212 |
47ba5ddc
|
Leszek Koltunski
|
AlertDialog.Builder builder = new AlertDialog.Builder(act);
|
| 213 |
0fd3ac1f
|
Leszek Koltunski
|
TextView tv = (TextView) inflater.inflate(R.layout.dialog_title, null);
|
| 214 |
|
|
tv.setText(R.string.settings_title);
|
| 215 |
|
|
builder.setCustomTitle(tv);
|
| 216 |
4918f19c
|
Leszek Koltunski
|
|
| 217 |
|
|
builder.setCancelable(true);
|
| 218 |
|
|
builder.setPositiveButton( R.string.ok, new DialogInterface.OnClickListener()
|
| 219 |
|
|
{
|
| 220 |
|
|
@Override
|
| 221 |
|
|
public void onClick(DialogInterface dialog, int which)
|
| 222 |
|
|
{
|
| 223 |
|
|
|
| 224 |
|
|
}
|
| 225 |
|
|
});
|
| 226 |
47ba5ddc
|
Leszek Koltunski
|
|
| 227 |
0fd3ac1f
|
Leszek Koltunski
|
final View view = inflater.inflate(R.layout.dialog_settings, null);
|
| 228 |
47ba5ddc
|
Leszek Koltunski
|
builder.setView(view);
|
| 229 |
|
|
|
| 230 |
0fd3ac1f
|
Leszek Koltunski
|
LinearLayout linearLayout = view.findViewById(R.id.settingsLayout);
|
| 231 |
47ba5ddc
|
Leszek Koltunski
|
|
| 232 |
|
|
if( linearLayout!=null )
|
| 233 |
|
|
{
|
| 234 |
|
|
for (int i=0; i< BaseEffect.Type.LENGTH; i++)
|
| 235 |
|
|
{
|
| 236 |
0fd3ac1f
|
Leszek Koltunski
|
addSettingsSection(act,linearLayout,i);
|
| 237 |
47ba5ddc
|
Leszek Koltunski
|
}
|
| 238 |
|
|
}
|
| 239 |
|
|
else
|
| 240 |
|
|
{
|
| 241 |
0fd3ac1f
|
Leszek Koltunski
|
android.util.Log.e("dialog_settings", "linearLayout NULL!");
|
| 242 |
47ba5ddc
|
Leszek Koltunski
|
}
|
| 243 |
|
|
|
| 244 |
|
|
return builder.create();
|
| 245 |
|
|
}
|
| 246 |
|
|
|
| 247 |
f6fcf06a
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
| 248 |
|
|
|
| 249 |
64975793
|
Leszek Koltunski
|
public void onItemSelected(AdapterView<?> parent, View view, int pos, long id)
|
| 250 |
|
|
{
|
| 251 |
|
|
int parentID = parent.getId();
|
| 252 |
0c96b376
|
Leszek Koltunski
|
int len = BaseEffect.Type.LENGTH;
|
| 253 |
22fdfc36
|
Leszek Koltunski
|
|
| 254 |
0c96b376
|
Leszek Koltunski
|
if( parentID>=len && parentID< 2*len) // ith spinner's ID is equal to i+LENGTH (see createSettingSection)
|
| 255 |
64975793
|
Leszek Koltunski
|
{
|
| 256 |
0c96b376
|
Leszek Koltunski
|
BaseEffect.Type.getType(parentID-len).setCurrentType(pos);
|
| 257 |
f6fcf06a
|
Leszek Koltunski
|
}
|
| 258 |
64975793
|
Leszek Koltunski
|
}
|
| 259 |
f6fcf06a
|
Leszek Koltunski
|
|
| 260 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
| 261 |
|
|
|
| 262 |
64975793
|
Leszek Koltunski
|
public void onProgressChanged(SeekBar bar, int progress, boolean fromUser)
|
| 263 |
|
|
{
|
| 264 |
|
|
int barID = bar.getId();
|
| 265 |
22fdfc36
|
Leszek Koltunski
|
|
| 266 |
64975793
|
Leszek Koltunski
|
if( barID>=0 && barID< BaseEffect.Type.LENGTH) // ith seekbar's ID is equal to i (see createSettingSection)
|
| 267 |
|
|
{
|
| 268 |
|
|
BaseEffect.Type.getType(barID).setCurrentPos(progress);
|
| 269 |
|
|
int ms = BaseEffect.Type.translatePos(progress);
|
| 270 |
|
|
mDurationText[barID].setText(getString(R.string.ms_placeholder,ms));
|
| 271 |
f6fcf06a
|
Leszek Koltunski
|
}
|
| 272 |
64975793
|
Leszek Koltunski
|
}
|
| 273 |
f6fcf06a
|
Leszek Koltunski
|
|
| 274 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
| 275 |
|
|
|
| 276 |
64975793
|
Leszek Koltunski
|
public void onNothingSelected(AdapterView<?> parent) { }
|
| 277 |
|
|
public void onStartTrackingTouch(SeekBar bar) { }
|
| 278 |
|
|
public void onStopTrackingTouch(SeekBar bar) { }
|
| 279 |
f6fcf06a
|
Leszek Koltunski
|
}
|