Revision 1f9772f3
Added by Leszek Koltunski over 5 years ago
| src/main/AndroidManifest.xml | ||
|---|---|---|
| 1 | 1 |
<manifest xmlns:android="http://schemas.android.com/apk/res/android" |
| 2 |
package="org.distorted.magic">
|
|
| 2 |
package="org.distorted.main">
|
|
| 3 | 3 |
|
| 4 | 4 |
<uses-feature android:glEsVersion="0x00030001" android:required="true" /> |
| 5 | 5 |
<uses-permission android:name="android.permission.INTERNET" /> |
| ... | ... | |
| 11 | 11 |
android:supportsRtl="true" |
| 12 | 12 |
android:theme="@android:style/Theme.NoTitleBar.Fullscreen"> |
| 13 | 13 |
|
| 14 |
<activity android:name=".RubikActivity"> |
|
| 14 |
<activity android:name="org.distorted.main.RubikActivity">
|
|
| 15 | 15 |
<intent-filter> |
| 16 | 16 |
<action android:name="android.intent.action.MAIN" /> |
| 17 | 17 |
<category android:name="android.intent.category.LAUNCHER" /> |
| src/main/java/org/distorted/component/HorizontalNumberPicker.java | ||
|---|---|---|
| 27 | 27 |
import android.widget.LinearLayout; |
| 28 | 28 |
import android.widget.TextView; |
| 29 | 29 |
|
| 30 |
import org.distorted.magic.R;
|
|
| 30 |
import org.distorted.main.R;
|
|
| 31 | 31 |
|
| 32 | 32 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 33 | 33 |
|
| src/main/java/org/distorted/dialog/RubikDialogAbout.java | ||
|---|---|---|
| 1 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 2 |
// Copyright 2019 Leszek Koltunski // |
|
| 3 |
// // |
|
| 4 |
// This file is part of Magic Cube. // |
|
| 5 |
// // |
|
| 6 |
// Magic Cube is free software: you can redistribute it and/or modify // |
|
| 7 |
// 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 |
// Magic Cube is distributed in the hope that it will be useful, // |
|
| 12 |
// 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 |
// along with Magic Cube. If not, see <http://www.gnu.org/licenses/>. // |
|
| 18 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 19 |
|
|
| 20 |
package org.distorted.dialog; |
|
| 21 |
|
|
| 22 |
import android.app.Dialog; |
|
| 23 |
import android.content.DialogInterface; |
|
| 24 |
import android.os.Bundle; |
|
| 25 |
import android.support.annotation.NonNull; |
|
| 26 |
import android.support.v4.app.FragmentActivity; |
|
| 27 |
import android.support.v7.app.AlertDialog; |
|
| 28 |
import android.support.v7.app.AppCompatDialogFragment; |
|
| 29 |
import android.view.LayoutInflater; |
|
| 30 |
import android.view.View; |
|
| 31 |
import android.view.Window; |
|
| 32 |
import android.view.WindowManager; |
|
| 33 |
import android.widget.TextView; |
|
| 34 |
|
|
| 35 |
import org.distorted.magic.R; |
|
| 36 |
|
|
| 37 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 38 |
|
|
| 39 |
public class RubikDialogAbout extends AppCompatDialogFragment |
|
| 40 |
{
|
|
| 41 |
@Override |
|
| 42 |
public void onStart() |
|
| 43 |
{
|
|
| 44 |
super.onStart(); |
|
| 45 |
|
|
| 46 |
Window window = getDialog().getWindow(); |
|
| 47 |
window.setFlags(WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL, |
|
| 48 |
WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL); |
|
| 49 |
window.clearFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND); |
|
| 50 |
} |
|
| 51 |
|
|
| 52 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 53 |
|
|
| 54 |
@NonNull |
|
| 55 |
@Override |
|
| 56 |
public Dialog onCreateDialog(Bundle savedInstanceState) |
|
| 57 |
{
|
|
| 58 |
FragmentActivity act = getActivity(); |
|
| 59 |
LayoutInflater inflater = act.getLayoutInflater(); |
|
| 60 |
AlertDialog.Builder builder = new AlertDialog.Builder(act); |
|
| 61 |
|
|
| 62 |
TextView tv = (TextView) inflater.inflate(R.layout.dialog_title, null); |
|
| 63 |
tv.setText(R.string.about); |
|
| 64 |
builder.setCustomTitle(tv); |
|
| 65 |
|
|
| 66 |
builder.setCancelable(true); |
|
| 67 |
builder.setPositiveButton( R.string.ok, new DialogInterface.OnClickListener() |
|
| 68 |
{
|
|
| 69 |
@Override |
|
| 70 |
public void onClick(DialogInterface dialog, int which) |
|
| 71 |
{
|
|
| 72 |
|
|
| 73 |
} |
|
| 74 |
}); |
|
| 75 |
|
|
| 76 |
final View view = inflater.inflate(R.layout.dialog_about, null); |
|
| 77 |
TextView text = view.findViewById(R.id.about_version); |
|
| 78 |
String appName = getString(R.string.app_name); |
|
| 79 |
String appVers = getString(R.string.app_version); |
|
| 80 |
text.setText(getString(R.string.ap_placeholder,appName, appVers)); |
|
| 81 |
builder.setView(view); |
|
| 82 |
|
|
| 83 |
return builder.create(); |
|
| 84 |
} |
|
| 85 |
} |
|
| src/main/java/org/distorted/dialog/RubikDialogEffects.java | ||
|---|---|---|
| 1 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 2 |
// Copyright 2019 Leszek Koltunski // |
|
| 3 |
// // |
|
| 4 |
// This file is part of Magic Cube. // |
|
| 5 |
// // |
|
| 6 |
// Magic Cube is free software: you can redistribute it and/or modify // |
|
| 7 |
// 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 |
// Magic Cube is distributed in the hope that it will be useful, // |
|
| 12 |
// 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 |
// along with Magic Cube. If not, see <http://www.gnu.org/licenses/>. // |
|
| 18 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 19 |
|
|
| 20 |
package org.distorted.dialog; |
|
| 21 |
|
|
| 22 |
import android.app.Dialog; |
|
| 23 |
import android.content.DialogInterface; |
|
| 24 |
import android.os.Bundle; |
|
| 25 |
import android.support.annotation.NonNull; |
|
| 26 |
import android.support.v4.app.FragmentActivity; |
|
| 27 |
import android.support.v4.content.ContextCompat; |
|
| 28 |
import android.support.v7.app.AlertDialog; |
|
| 29 |
import android.support.v7.app.AppCompatDialogFragment; |
|
| 30 |
import android.util.DisplayMetrics; |
|
| 31 |
import android.view.Gravity; |
|
| 32 |
import android.view.LayoutInflater; |
|
| 33 |
import android.view.View; |
|
| 34 |
import android.view.Window; |
|
| 35 |
import android.view.WindowManager; |
|
| 36 |
import android.widget.AdapterView; |
|
| 37 |
import android.widget.ArrayAdapter; |
|
| 38 |
import android.widget.LinearLayout; |
|
| 39 |
import android.widget.SeekBar; |
|
| 40 |
import android.widget.Spinner; |
|
| 41 |
import android.widget.TextView; |
|
| 42 |
|
|
| 43 |
import org.distorted.effect.BaseEffect; |
|
| 44 |
import org.distorted.magic.R; |
|
| 45 |
|
|
| 46 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 47 |
|
|
| 48 |
public class RubikDialogEffects extends AppCompatDialogFragment implements SeekBar.OnSeekBarChangeListener, AdapterView.OnItemSelectedListener |
|
| 49 |
{
|
|
| 50 |
private TextView[] mDurationText; |
|
| 51 |
|
|
| 52 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 53 |
|
|
| 54 |
private void addSettingsSection(FragmentActivity act, LinearLayout layout, int index) |
|
| 55 |
{
|
|
| 56 |
BaseEffect.Type beType = BaseEffect.Type.getType(index); |
|
| 57 |
DisplayMetrics metrics = act.getResources().getDisplayMetrics(); |
|
| 58 |
float scale = metrics.density; |
|
| 59 |
|
|
| 60 |
int textH=32; |
|
| 61 |
int layoH=36; |
|
| 62 |
int margH=10; |
|
| 63 |
|
|
| 64 |
///// OUTER LAYOUT /////////////////////////////////////////////////////////////////// |
|
| 65 |
|
|
| 66 |
int margin = (int)(scale*margH + 0.5f); |
|
| 67 |
int color = ContextCompat.getColor(act, R.color.grey); |
|
| 68 |
LinearLayout outerLayout = new LinearLayout(act); |
|
| 69 |
LinearLayout.LayoutParams outerLayoutParams = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,LinearLayout.LayoutParams.MATCH_PARENT, 0.5f); |
|
| 70 |
outerLayoutParams.topMargin = index>0 ? margin : 0; |
|
| 71 |
outerLayoutParams.bottomMargin = 0; |
|
| 72 |
outerLayoutParams.leftMargin = margin; |
|
| 73 |
outerLayoutParams.rightMargin = margin; |
|
| 74 |
|
|
| 75 |
outerLayout.setLayoutParams(outerLayoutParams); |
|
| 76 |
outerLayout.setGravity(Gravity.CENTER|Gravity.FILL_HORIZONTAL); |
|
| 77 |
outerLayout.setBackgroundColor(color); |
|
| 78 |
outerLayout.setOrientation(LinearLayout.VERTICAL); |
|
| 79 |
layout.addView(outerLayout); |
|
| 80 |
|
|
| 81 |
///// TEXT /////////////////////////////////////////////////////////////////////////// |
|
| 82 |
|
|
| 83 |
int layoutHeight = (int)(scale*textH + 0.5f); |
|
| 84 |
int padding = (int)(scale*10 + 0.5f); |
|
| 85 |
|
|
| 86 |
LinearLayout.LayoutParams textParams = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,layoutHeight); |
|
| 87 |
|
|
| 88 |
TextView textView = new TextView(act); |
|
| 89 |
textView.setText(beType.getText()); |
|
| 90 |
textView.setLayoutParams(textParams); |
|
| 91 |
textView.setGravity(Gravity.CENTER); |
|
| 92 |
textView.setPadding(padding,0,padding,0); |
|
| 93 |
textView.setTextAppearance(android.R.style.TextAppearance_Small); |
|
| 94 |
outerLayout.addView(textView); |
|
| 95 |
|
|
| 96 |
///// INNER LAYOUT1 ////////////////////////////////////////////////////////////////// |
|
| 97 |
|
|
| 98 |
int innerLayout1Height = (int)(scale*layoH + 0.5f); |
|
| 99 |
LinearLayout innerLayout1 = new LinearLayout(act); |
|
| 100 |
LinearLayout.LayoutParams innerLayout1Params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,innerLayout1Height); |
|
| 101 |
|
|
| 102 |
innerLayout1.setLayoutParams(innerLayout1Params); |
|
| 103 |
innerLayout1.setGravity(Gravity.CENTER|Gravity.FILL_HORIZONTAL); |
|
| 104 |
innerLayout1.setOrientation(LinearLayout.HORIZONTAL); |
|
| 105 |
outerLayout.addView(innerLayout1); |
|
| 106 |
|
|
| 107 |
///// STUFF INSIDE INNER LAYOUT1 ///////////////////////////////////////////////////// |
|
| 108 |
|
|
| 109 |
int text1Padding = (int)(scale*5 + 0.5f); |
|
| 110 |
LinearLayout.LayoutParams text1LayoutParams = new LinearLayout.LayoutParams(0,layoutHeight,0.2f); |
|
| 111 |
|
|
| 112 |
TextView text1View = new TextView(act); |
|
| 113 |
text1View.setText(R.string.duration); |
|
| 114 |
text1View.setLayoutParams(text1LayoutParams); |
|
| 115 |
text1View.setGravity(Gravity.START|Gravity.CENTER); |
|
| 116 |
text1View.setPadding(text1Padding,0,text1Padding,0); |
|
| 117 |
text1View.setTextAppearance(android.R.style.TextAppearance_Small); |
|
| 118 |
innerLayout1.addView(text1View); |
|
| 119 |
////////////////////////////////////////////////////////////////// |
|
| 120 |
int text2Padding = (int)(scale*5 + 0.5f); |
|
| 121 |
LinearLayout.LayoutParams text2LayoutParams = new LinearLayout.LayoutParams(0,layoutHeight,0.2f); |
|
| 122 |
|
|
| 123 |
mDurationText[index] = new TextView(act); |
|
| 124 |
mDurationText[index].setLayoutParams(text2LayoutParams); |
|
| 125 |
mDurationText[index].setGravity(Gravity.END|Gravity.CENTER); |
|
| 126 |
mDurationText[index].setPadding(text2Padding,0,text2Padding,0); |
|
| 127 |
mDurationText[index].setTextAppearance(android.R.style.TextAppearance_Small); |
|
| 128 |
innerLayout1.addView(mDurationText[index]); |
|
| 129 |
////////////////////////////////////////////////////////////////// |
|
| 130 |
int seekPadding = (int)(scale*10 + 0.5f); |
|
| 131 |
LinearLayout.LayoutParams seekLayoutParams = new LinearLayout.LayoutParams(0,LinearLayout.LayoutParams.MATCH_PARENT,0.6f); |
|
| 132 |
|
|
| 133 |
SeekBar seekBar = new SeekBar(act); |
|
| 134 |
seekBar.setLayoutParams(seekLayoutParams); |
|
| 135 |
seekBar.setPadding(seekPadding,0,seekPadding,0); |
|
| 136 |
seekBar.setId(index); |
|
| 137 |
innerLayout1.addView(seekBar); |
|
| 138 |
|
|
| 139 |
seekBar.setOnSeekBarChangeListener(this); |
|
| 140 |
seekBar.setProgress(beType.getCurrentPos()); |
|
| 141 |
|
|
| 142 |
///// INNER LAYOUT2 ////////////////////////////////////////////////////////////////// |
|
| 143 |
|
|
| 144 |
int innerLayout2Height = (int)(scale*layoH + 0.5f); |
|
| 145 |
LinearLayout innerLayout2 = new LinearLayout(act); |
|
| 146 |
LinearLayout.LayoutParams innerLayout2Params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,innerLayout2Height); |
|
| 147 |
|
|
| 148 |
innerLayout2.setLayoutParams(innerLayout2Params); |
|
| 149 |
innerLayout2.setGravity(Gravity.CENTER|Gravity.FILL_HORIZONTAL); |
|
| 150 |
innerLayout2.setOrientation(LinearLayout.HORIZONTAL); |
|
| 151 |
outerLayout.addView(innerLayout2); |
|
| 152 |
|
|
| 153 |
///// STUFF INSIDE INNER LAYOUT2 ///////////////////////////////////////////////////// |
|
| 154 |
|
|
| 155 |
int text3Padding = (int)(scale*5 + 0.5f); |
|
| 156 |
LinearLayout.LayoutParams text3LayoutParams = new LinearLayout.LayoutParams(0,LinearLayout.LayoutParams.MATCH_PARENT,0.4f); |
|
| 157 |
|
|
| 158 |
TextView text3View = new TextView(act); |
|
| 159 |
text3View.setText(R.string.type); |
|
| 160 |
text3View.setLayoutParams(text3LayoutParams); |
|
| 161 |
text3View.setGravity(Gravity.START|Gravity.CENTER); |
|
| 162 |
text3View.setPadding(text3Padding,0,text3Padding,0); |
|
| 163 |
text3View.setTextAppearance(android.R.style.TextAppearance_Small); |
|
| 164 |
innerLayout2.addView(text3View); |
|
| 165 |
////////////////////////////////////////////////////////////////// |
|
| 166 |
int spinnerPadding = (int)(scale*10 + 0.5f); |
|
| 167 |
int spinnerMargin = (int)(scale* 3 + 0.5f); |
|
| 168 |
LinearLayout.LayoutParams spinnerLayoutParams = new LinearLayout.LayoutParams(0,LinearLayout.LayoutParams.MATCH_PARENT,0.6f); |
|
| 169 |
spinnerLayoutParams.topMargin = spinnerMargin; |
|
| 170 |
spinnerLayoutParams.bottomMargin = spinnerMargin; |
|
| 171 |
spinnerLayoutParams.leftMargin = spinnerMargin; |
|
| 172 |
spinnerLayoutParams.rightMargin = 2*spinnerMargin; |
|
| 173 |
|
|
| 174 |
Spinner spinner = new Spinner(act); |
|
| 175 |
spinner.setLayoutParams(spinnerLayoutParams); |
|
| 176 |
spinner.setPadding(spinnerPadding,0,spinnerPadding,0); |
|
| 177 |
spinner.setBackgroundResource(R.drawable.spinner); |
|
| 178 |
spinner.setTextAlignment(View.TEXT_ALIGNMENT_CENTER); |
|
| 179 |
spinner.setId(index+BaseEffect.Type.LENGTH); |
|
| 180 |
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 |
|
|
| 191 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 192 |
// PUBLIC API |
|
| 193 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 194 |
|
|
| 195 |
public RubikDialogEffects() |
|
| 196 |
{
|
|
| 197 |
mDurationText = new TextView[BaseEffect.Type.LENGTH]; |
|
| 198 |
} |
|
| 199 |
|
|
| 200 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 201 |
|
|
| 202 |
@Override |
|
| 203 |
public void onStart() |
|
| 204 |
{
|
|
| 205 |
super.onStart(); |
|
| 206 |
|
|
| 207 |
Window window = getDialog().getWindow(); |
|
| 208 |
window.setFlags(WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL, |
|
| 209 |
WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL); |
|
| 210 |
window.clearFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND); |
|
| 211 |
} |
|
| 212 |
|
|
| 213 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 214 |
|
|
| 215 |
@NonNull |
|
| 216 |
@Override |
|
| 217 |
public Dialog onCreateDialog(Bundle savedInstanceState) |
|
| 218 |
{
|
|
| 219 |
FragmentActivity act = getActivity(); |
|
| 220 |
LayoutInflater inflater = act.getLayoutInflater(); |
|
| 221 |
AlertDialog.Builder builder = new AlertDialog.Builder(act); |
|
| 222 |
TextView tv = (TextView) inflater.inflate(R.layout.dialog_title, null); |
|
| 223 |
tv.setText(R.string.effects); |
|
| 224 |
builder.setCustomTitle(tv); |
|
| 225 |
|
|
| 226 |
builder.setCancelable(true); |
|
| 227 |
builder.setPositiveButton( R.string.ok, new DialogInterface.OnClickListener() |
|
| 228 |
{
|
|
| 229 |
@Override |
|
| 230 |
public void onClick(DialogInterface dialog, int which) |
|
| 231 |
{
|
|
| 232 |
|
|
| 233 |
} |
|
| 234 |
}); |
|
| 235 |
|
|
| 236 |
final View view = inflater.inflate(R.layout.dialog_settings, null); |
|
| 237 |
builder.setView(view); |
|
| 238 |
|
|
| 239 |
LinearLayout linearLayout = view.findViewById(R.id.settingsLayout); |
|
| 240 |
|
|
| 241 |
if( linearLayout!=null ) |
|
| 242 |
{
|
|
| 243 |
for (int i=0; i< BaseEffect.Type.LENGTH; i++) |
|
| 244 |
{
|
|
| 245 |
addSettingsSection(act,linearLayout,i); |
|
| 246 |
} |
|
| 247 |
} |
|
| 248 |
else |
|
| 249 |
{
|
|
| 250 |
android.util.Log.e("dialog_settings", "linearLayout NULL!");
|
|
| 251 |
} |
|
| 252 |
|
|
| 253 |
return builder.create(); |
|
| 254 |
} |
|
| 255 |
|
|
| 256 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 257 |
|
|
| 258 |
public void onItemSelected(AdapterView<?> parent, View view, int pos, long id) |
|
| 259 |
{
|
|
| 260 |
int parentID = parent.getId(); |
|
| 261 |
int len = BaseEffect.Type.LENGTH; |
|
| 262 |
|
|
| 263 |
if( parentID>=len && parentID< 2*len) // ith spinner's ID is equal to i+LENGTH (see createSettingSection) |
|
| 264 |
{
|
|
| 265 |
BaseEffect.Type.getType(parentID-len).setCurrentType(pos); |
|
| 266 |
} |
|
| 267 |
} |
|
| 268 |
|
|
| 269 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 270 |
|
|
| 271 |
public void onProgressChanged(SeekBar bar, int progress, boolean fromUser) |
|
| 272 |
{
|
|
| 273 |
int barID = bar.getId(); |
|
| 274 |
|
|
| 275 |
if( barID>=0 && barID< BaseEffect.Type.LENGTH) // ith seekbar's ID is equal to i (see createSettingSection) |
|
| 276 |
{
|
|
| 277 |
BaseEffect.Type.getType(barID).setCurrentPos(progress); |
|
| 278 |
int ms = BaseEffect.Type.translatePos(progress); |
|
| 279 |
mDurationText[barID].setText(getString(R.string.ms_placeholder,ms)); |
|
| 280 |
} |
|
| 281 |
} |
|
| 282 |
|
|
| 283 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 284 |
|
|
| 285 |
public void onNothingSelected(AdapterView<?> parent) { }
|
|
| 286 |
public void onStartTrackingTouch(SeekBar bar) { }
|
|
| 287 |
public void onStopTrackingTouch(SeekBar bar) { }
|
|
| 288 |
} |
|
| src/main/java/org/distorted/dialog/RubikDialogMain.java | ||
|---|---|---|
| 1 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 2 |
// Copyright 2019 Leszek Koltunski // |
|
| 3 |
// // |
|
| 4 |
// This file is part of Magic Cube. // |
|
| 5 |
// // |
|
| 6 |
// Magic Cube is free software: you can redistribute it and/or modify // |
|
| 7 |
// 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 |
// Magic Cube is distributed in the hope that it will be useful, // |
|
| 12 |
// 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 |
// along with Magic Cube. If not, see <http://www.gnu.org/licenses/>. // |
|
| 18 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 19 |
|
|
| 20 |
package org.distorted.dialog; |
|
| 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 |
import android.support.v7.app.AlertDialog; |
|
| 27 |
import android.support.v7.app.AppCompatDialogFragment; |
|
| 28 |
import android.view.LayoutInflater; |
|
| 29 |
import android.view.View; |
|
| 30 |
import android.view.Window; |
|
| 31 |
import android.view.WindowManager; |
|
| 32 |
|
|
| 33 |
import org.distorted.magic.R; |
|
| 34 |
|
|
| 35 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 36 |
|
|
| 37 |
public class RubikDialogMain extends AppCompatDialogFragment |
|
| 38 |
{
|
|
| 39 |
@Override |
|
| 40 |
public void onStart() |
|
| 41 |
{
|
|
| 42 |
super.onStart(); |
|
| 43 |
|
|
| 44 |
Window window = getDialog().getWindow(); |
|
| 45 |
window.setFlags(WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL, |
|
| 46 |
WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL); |
|
| 47 |
window.clearFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND); |
|
| 48 |
} |
|
| 49 |
|
|
| 50 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 51 |
|
|
| 52 |
@NonNull |
|
| 53 |
@Override |
|
| 54 |
public Dialog onCreateDialog(Bundle savedInstanceState) |
|
| 55 |
{
|
|
| 56 |
FragmentActivity act = getActivity(); |
|
| 57 |
AlertDialog.Builder builder = new AlertDialog.Builder(act); |
|
| 58 |
LayoutInflater inflater = act.getLayoutInflater(); |
|
| 59 |
final View view = inflater.inflate(R.layout.dialog_main, null); |
|
| 60 |
builder.setView(view); |
|
| 61 |
|
|
| 62 |
return builder.create(); |
|
| 63 |
} |
|
| 64 |
|
|
| 65 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 66 |
|
|
| 67 |
public static String getDialogTag() |
|
| 68 |
{
|
|
| 69 |
return "DialogMain"; |
|
| 70 |
} |
|
| 71 |
} |
|
| src/main/java/org/distorted/dialog/RubikDialogNewRecord.java | ||
|---|---|---|
| 1 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 2 |
// Copyright 2020 Leszek Koltunski // |
|
| 3 |
// // |
|
| 4 |
// This file is part of Magic Cube. // |
|
| 5 |
// // |
|
| 6 |
// Magic Cube is free software: you can redistribute it and/or modify // |
|
| 7 |
// 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 |
// Magic Cube is distributed in the hope that it will be useful, // |
|
| 12 |
// 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 |
// along with Magic Cube. If not, see <http://www.gnu.org/licenses/>. // |
|
| 18 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 19 |
|
|
| 20 |
package org.distorted.dialog; |
|
| 21 |
|
|
| 22 |
import android.app.Dialog; |
|
| 23 |
import android.content.DialogInterface; |
|
| 24 |
import android.os.Bundle; |
|
| 25 |
import android.support.annotation.NonNull; |
|
| 26 |
import android.support.v4.app.FragmentActivity; |
|
| 27 |
import android.support.v7.app.AlertDialog; |
|
| 28 |
import android.support.v7.app.AppCompatDialogFragment; |
|
| 29 |
import android.view.LayoutInflater; |
|
| 30 |
import android.view.View; |
|
| 31 |
import android.view.Window; |
|
| 32 |
import android.view.WindowManager; |
|
| 33 |
import android.widget.TextView; |
|
| 34 |
|
|
| 35 |
import org.distorted.magic.R; |
|
| 36 |
import org.distorted.magic.RubikActivity; |
|
| 37 |
import org.distorted.object.RubikObjectList; |
|
| 38 |
import org.distorted.scores.RubikScores; |
|
| 39 |
import org.distorted.uistate.RubikState; |
|
| 40 |
import org.distorted.uistate.RubikStatePlay; |
|
| 41 |
|
|
| 42 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 43 |
|
|
| 44 |
public class RubikDialogNewRecord extends AppCompatDialogFragment |
|
| 45 |
{
|
|
| 46 |
@Override |
|
| 47 |
public void onStart() |
|
| 48 |
{
|
|
| 49 |
super.onStart(); |
|
| 50 |
|
|
| 51 |
Window window = getDialog().getWindow(); |
|
| 52 |
window.setFlags(WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL, |
|
| 53 |
WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL); |
|
| 54 |
window.clearFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND); |
|
| 55 |
} |
|
| 56 |
|
|
| 57 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 58 |
|
|
| 59 |
@NonNull |
|
| 60 |
@Override |
|
| 61 |
public Dialog onCreateDialog(Bundle savedInstanceState) |
|
| 62 |
{
|
|
| 63 |
FragmentActivity act = getActivity(); |
|
| 64 |
LayoutInflater inflater = act.getLayoutInflater(); |
|
| 65 |
AlertDialog.Builder builder = new AlertDialog.Builder(act); |
|
| 66 |
|
|
| 67 |
TextView tv = (TextView) inflater.inflate(R.layout.dialog_title, null); |
|
| 68 |
tv.setText(R.string.new_record); |
|
| 69 |
builder.setCustomTitle(tv); |
|
| 70 |
builder.setCancelable(true); |
|
| 71 |
|
|
| 72 |
builder.setPositiveButton( R.string.yes, new DialogInterface.OnClickListener() |
|
| 73 |
{
|
|
| 74 |
@Override |
|
| 75 |
public void onClick(DialogInterface dialog, int which) |
|
| 76 |
{
|
|
| 77 |
RubikActivity act = (RubikActivity)getActivity(); |
|
| 78 |
RubikScores scores = RubikScores.getInstance(); |
|
| 79 |
String name = scores.getName(); |
|
| 80 |
Bundle bundle = new Bundle(); |
|
| 81 |
RubikState.switchState(act,RubikState.PLAY); |
|
| 82 |
|
|
| 83 |
if( name.length()>0 ) |
|
| 84 |
{
|
|
| 85 |
RubikStatePlay play = (RubikStatePlay) RubikState.PLAY.getStateClass(); |
|
| 86 |
int object = play.getObject(); |
|
| 87 |
int size = play.getSize(); |
|
| 88 |
int sizeIndex = RubikObjectList.getSizeIndex(object,size); |
|
| 89 |
|
|
| 90 |
bundle.putInt("tab", RubikObjectList.pack(object,sizeIndex) );
|
|
| 91 |
bundle.putBoolean("submitting", true);
|
|
| 92 |
|
|
| 93 |
RubikDialogScores scoresDiag = new RubikDialogScores(); |
|
| 94 |
scoresDiag.setArguments(bundle); |
|
| 95 |
scoresDiag.show(act.getSupportFragmentManager(), null); |
|
| 96 |
} |
|
| 97 |
else |
|
| 98 |
{
|
|
| 99 |
bundle.putString("name", name );
|
|
| 100 |
|
|
| 101 |
RubikDialogSetName nameDiag = new RubikDialogSetName(); |
|
| 102 |
nameDiag.setArguments(bundle); |
|
| 103 |
nameDiag.show(act.getSupportFragmentManager(), null); |
|
| 104 |
} |
|
| 105 |
} |
|
| 106 |
}); |
|
| 107 |
|
|
| 108 |
builder.setNegativeButton(R.string.no, new DialogInterface.OnClickListener() |
|
| 109 |
{
|
|
| 110 |
@Override |
|
| 111 |
public void onClick(DialogInterface dialog, int which) |
|
| 112 |
{
|
|
| 113 |
RubikActivity act = (RubikActivity)getActivity(); |
|
| 114 |
RubikState.switchState(act,RubikState.PLAY); |
|
| 115 |
} |
|
| 116 |
}); |
|
| 117 |
|
|
| 118 |
Bundle args = getArguments(); |
|
| 119 |
long time; |
|
| 120 |
|
|
| 121 |
try |
|
| 122 |
{
|
|
| 123 |
time = args.getLong("time");
|
|
| 124 |
} |
|
| 125 |
catch(Exception e) |
|
| 126 |
{
|
|
| 127 |
time = 0; |
|
| 128 |
} |
|
| 129 |
|
|
| 130 |
final View view = inflater.inflate(R.layout.dialog_new_record, null); |
|
| 131 |
TextView text = view.findViewById(R.id.new_record_time); |
|
| 132 |
text.setText(getString(R.string.ti_placeholder, (time/100)/10.0f)); |
|
| 133 |
builder.setView(view); |
|
| 134 |
|
|
| 135 |
return builder.create(); |
|
| 136 |
} |
|
| 137 |
} |
|
| src/main/java/org/distorted/dialog/RubikDialogPattern.java | ||
|---|---|---|
| 1 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 2 |
// Copyright 2020 Leszek Koltunski // |
|
| 3 |
// // |
|
| 4 |
// This file is part of Magic Cube. // |
|
| 5 |
// // |
|
| 6 |
// Magic Cube is free software: you can redistribute it and/or modify // |
|
| 7 |
// 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 |
// Magic Cube is distributed in the hope that it will be useful, // |
|
| 12 |
// 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 |
// along with Magic Cube. If not, see <http://www.gnu.org/licenses/>. // |
|
| 18 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 19 |
|
|
| 20 |
package org.distorted.dialog; |
|
| 21 |
|
|
| 22 |
import android.app.Dialog; |
|
| 23 |
import android.content.Context; |
|
| 24 |
import android.os.Bundle; |
|
| 25 |
import android.support.annotation.NonNull; |
|
| 26 |
import android.support.v4.app.FragmentActivity; |
|
| 27 |
import android.support.v4.view.ViewPager; |
|
| 28 |
import android.support.v7.app.AlertDialog; |
|
| 29 |
import android.support.v7.app.AppCompatDialogFragment; |
|
| 30 |
import android.support.design.widget.TabLayout; |
|
| 31 |
import android.util.DisplayMetrics; |
|
| 32 |
import android.view.LayoutInflater; |
|
| 33 |
import android.view.View; |
|
| 34 |
import android.view.Window; |
|
| 35 |
import android.view.WindowManager; |
|
| 36 |
import android.widget.ImageView; |
|
| 37 |
import android.widget.TextView; |
|
| 38 |
|
|
| 39 |
import org.distorted.magic.R; |
|
| 40 |
import org.distorted.object.RubikObjectList; |
|
| 41 |
import org.distorted.patterns.RubikPatternList; |
|
| 42 |
|
|
| 43 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 44 |
|
|
| 45 |
public class RubikDialogPattern extends AppCompatDialogFragment |
|
| 46 |
{
|
|
| 47 |
RubikDialogPatternPagerAdapter mPagerAdapter; |
|
| 48 |
|
|
| 49 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 50 |
|
|
| 51 |
@Override |
|
| 52 |
public void onStart() |
|
| 53 |
{
|
|
| 54 |
super.onStart(); |
|
| 55 |
|
|
| 56 |
Window window = getDialog().getWindow(); |
|
| 57 |
window.setFlags(WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL, |
|
| 58 |
WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL); |
|
| 59 |
window.clearFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND); |
|
| 60 |
} |
|
| 61 |
|
|
| 62 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 63 |
|
|
| 64 |
@NonNull |
|
| 65 |
@Override |
|
| 66 |
public Dialog onCreateDialog(Bundle savedInstanceState) |
|
| 67 |
{
|
|
| 68 |
FragmentActivity act = getActivity(); |
|
| 69 |
AlertDialog.Builder builder = new AlertDialog.Builder(act); |
|
| 70 |
|
|
| 71 |
LayoutInflater layoutInflater = act.getLayoutInflater(); |
|
| 72 |
TextView tv = (TextView) layoutInflater.inflate(R.layout.dialog_title, null); |
|
| 73 |
tv.setText(R.string.choose_pattern); |
|
| 74 |
builder.setCustomTitle(tv); |
|
| 75 |
|
|
| 76 |
Bundle args = getArguments(); |
|
| 77 |
int curTab; |
|
| 78 |
|
|
| 79 |
try |
|
| 80 |
{
|
|
| 81 |
curTab = args.getInt("tab");
|
|
| 82 |
} |
|
| 83 |
catch(Exception e) |
|
| 84 |
{
|
|
| 85 |
curTab = 0; |
|
| 86 |
} |
|
| 87 |
|
|
| 88 |
LayoutInflater inflater = act.getLayoutInflater(); |
|
| 89 |
final View view = inflater.inflate(R.layout.dialog_tabbed, null); |
|
| 90 |
builder.setView(view); |
|
| 91 |
|
|
| 92 |
ViewPager viewPager = view.findViewById(R.id.viewpager); |
|
| 93 |
TabLayout tabLayout = view.findViewById(R.id.sliding_tabs); |
|
| 94 |
mPagerAdapter = new RubikDialogPatternPagerAdapter(act, viewPager, this); |
|
| 95 |
tabLayout.setupWithViewPager(viewPager); |
|
| 96 |
viewPager.setCurrentItem(curTab); |
|
| 97 |
|
|
| 98 |
for(int i=0; i< RubikPatternList.NUM_OBJECTS; i++) |
|
| 99 |
{
|
|
| 100 |
RubikObjectList list = RubikPatternList.getObject(i); |
|
| 101 |
int size = RubikPatternList.getSize(i); |
|
| 102 |
int sizeIndex = RubikObjectList.getSizeIndex(list.ordinal(),size); |
|
| 103 |
int iconID = list.getIconIDs()[sizeIndex]; |
|
| 104 |
|
|
| 105 |
ImageView imageView = new ImageView(act); |
|
| 106 |
imageView.setImageResource(iconID); |
|
| 107 |
TabLayout.Tab tab = tabLayout.getTabAt(i); |
|
| 108 |
if(tab!=null) tab.setCustomView(imageView); |
|
| 109 |
} |
|
| 110 |
|
|
| 111 |
return builder.create(); |
|
| 112 |
} |
|
| 113 |
|
|
| 114 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 115 |
|
|
| 116 |
@Override |
|
| 117 |
public void onResume() |
|
| 118 |
{
|
|
| 119 |
super.onResume(); |
|
| 120 |
|
|
| 121 |
Window window = getDialog().getWindow(); |
|
| 122 |
Context context = getContext(); |
|
| 123 |
|
|
| 124 |
if( window!=null && context!=null ) |
|
| 125 |
{
|
|
| 126 |
DisplayMetrics metrics = context.getResources().getDisplayMetrics(); |
|
| 127 |
final float height= metrics.heightPixels; |
|
| 128 |
|
|
| 129 |
WindowManager.LayoutParams params = window.getAttributes(); |
|
| 130 |
params.width = WindowManager.LayoutParams.WRAP_CONTENT; |
|
| 131 |
params.height = (int)(0.75f*height); |
|
| 132 |
window.setAttributes(params); |
|
| 133 |
} |
|
| 134 |
} |
|
| 135 |
|
|
| 136 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 137 |
|
|
| 138 |
public void rememberState() |
|
| 139 |
{
|
|
| 140 |
mPagerAdapter.rememberState(); |
|
| 141 |
} |
|
| 142 |
|
|
| 143 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 144 |
|
|
| 145 |
public static String getDialogTag() |
|
| 146 |
{
|
|
| 147 |
return "DialogPattern"; |
|
| 148 |
} |
|
| 149 |
} |
|
| src/main/java/org/distorted/dialog/RubikDialogPatternPagerAdapter.java | ||
|---|---|---|
| 1 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 2 |
// Copyright 2020 Leszek Koltunski // |
|
| 3 |
// // |
|
| 4 |
// This file is part of Magic Cube. // |
|
| 5 |
// // |
|
| 6 |
// Magic Cube is free software: you can redistribute it and/or modify // |
|
| 7 |
// 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 |
// Magic Cube is distributed in the hope that it will be useful, // |
|
| 12 |
// 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 |
// along with Magic Cube. If not, see <http://www.gnu.org/licenses/>. // |
|
| 18 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 19 |
|
|
| 20 |
package org.distorted.dialog; |
|
| 21 |
|
|
| 22 |
import android.support.annotation.NonNull; |
|
| 23 |
import android.support.v4.app.FragmentActivity; |
|
| 24 |
import android.support.v4.view.PagerAdapter; |
|
| 25 |
import android.support.v4.view.ViewPager; |
|
| 26 |
import android.view.View; |
|
| 27 |
import android.view.ViewGroup; |
|
| 28 |
|
|
| 29 |
import org.distorted.patterns.RubikPattern; |
|
| 30 |
import org.distorted.patterns.RubikPatternList; |
|
| 31 |
|
|
| 32 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 33 |
|
|
| 34 |
class RubikDialogPatternPagerAdapter extends PagerAdapter |
|
| 35 |
{
|
|
| 36 |
private FragmentActivity mAct; |
|
| 37 |
private RubikDialogPatternView[] mViews; |
|
| 38 |
private RubikDialogPattern mDialog; |
|
| 39 |
private int mNumTabs; |
|
| 40 |
|
|
| 41 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 42 |
|
|
| 43 |
RubikDialogPatternPagerAdapter(FragmentActivity act, ViewPager viewPager, RubikDialogPattern dialog) |
|
| 44 |
{
|
|
| 45 |
mAct = act; |
|
| 46 |
mDialog = dialog; |
|
| 47 |
mNumTabs = RubikPatternList.NUM_OBJECTS; |
|
| 48 |
mViews = new RubikDialogPatternView[mNumTabs]; |
|
| 49 |
|
|
| 50 |
viewPager.setAdapter(this); |
|
| 51 |
viewPager.setOffscreenPageLimit(mNumTabs-1); |
|
| 52 |
} |
|
| 53 |
|
|
| 54 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 55 |
|
|
| 56 |
void rememberState() |
|
| 57 |
{
|
|
| 58 |
RubikPattern pattern = RubikPattern.getInstance(); |
|
| 59 |
|
|
| 60 |
for(int i=0; i<mNumTabs; i++) |
|
| 61 |
{
|
|
| 62 |
int cat = mViews[i].getCurrentCategory(); |
|
| 63 |
int pos = mViews[i].getCurrentScrollPos(); |
|
| 64 |
pattern.rememberState(i,cat,pos); |
|
| 65 |
} |
|
| 66 |
} |
|
| 67 |
|
|
| 68 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 69 |
|
|
| 70 |
@Override |
|
| 71 |
@NonNull |
|
| 72 |
public Object instantiateItem(@NonNull ViewGroup collection, final int position) |
|
| 73 |
{
|
|
| 74 |
mViews[position] = new RubikDialogPatternView(mAct, mDialog, position); |
|
| 75 |
collection.addView(mViews[position]); |
|
| 76 |
|
|
| 77 |
return mViews[position]; |
|
| 78 |
} |
|
| 79 |
|
|
| 80 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 81 |
|
|
| 82 |
@Override |
|
| 83 |
public void destroyItem(ViewGroup collection, int position, @NonNull Object view) |
|
| 84 |
{
|
|
| 85 |
collection.removeView((View) view); |
|
| 86 |
} |
|
| 87 |
|
|
| 88 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 89 |
|
|
| 90 |
@Override |
|
| 91 |
public int getCount() |
|
| 92 |
{
|
|
| 93 |
return mNumTabs; |
|
| 94 |
} |
|
| 95 |
|
|
| 96 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 97 |
|
|
| 98 |
@Override |
|
| 99 |
public boolean isViewFromObject(@NonNull View view, @NonNull Object object) |
|
| 100 |
{
|
|
| 101 |
return view == object; |
|
| 102 |
} |
|
| 103 |
} |
|
| src/main/java/org/distorted/dialog/RubikDialogPatternView.java | ||
|---|---|---|
| 1 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 2 |
// Copyright 2020 Leszek Koltunski // |
|
| 3 |
// // |
|
| 4 |
// This file is part of Magic Cube. // |
|
| 5 |
// // |
|
| 6 |
// Magic Cube is free software: you can redistribute it and/or modify // |
|
| 7 |
// 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 |
// Magic Cube is distributed in the hope that it will be useful, // |
|
| 12 |
// 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 |
// along with Magic Cube. If not, see <http://www.gnu.org/licenses/>. // |
|
| 18 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 19 |
|
|
| 20 |
package org.distorted.dialog; |
|
| 21 |
|
|
| 22 |
import android.content.Context; |
|
| 23 |
import android.support.v4.app.FragmentActivity; |
|
| 24 |
import android.util.AttributeSet; |
|
| 25 |
import android.util.DisplayMetrics; |
|
| 26 |
import android.view.View; |
|
| 27 |
import android.widget.AdapterView; |
|
| 28 |
import android.widget.ArrayAdapter; |
|
| 29 |
import android.widget.Button; |
|
| 30 |
import android.widget.FrameLayout; |
|
| 31 |
import android.widget.LinearLayout; |
|
| 32 |
import android.widget.ScrollView; |
|
| 33 |
import android.widget.Spinner; |
|
| 34 |
|
|
| 35 |
import org.distorted.magic.R; |
|
| 36 |
import org.distorted.magic.RubikActivity; |
|
| 37 |
import org.distorted.object.RubikObjectList; |
|
| 38 |
import org.distorted.patterns.RubikPattern; |
|
| 39 |
import org.distorted.patterns.RubikPatternList; |
|
| 40 |
import org.distorted.uistate.RubikState; |
|
| 41 |
import org.distorted.uistate.RubikStatePattern; |
|
| 42 |
|
|
| 43 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 44 |
|
|
| 45 |
public class RubikDialogPatternView extends FrameLayout implements AdapterView.OnItemSelectedListener |
|
| 46 |
{
|
|
| 47 |
private LinearLayout mLayout; |
|
| 48 |
private ScrollView mScroll; |
|
| 49 |
private RubikDialogPattern mDialog; |
|
| 50 |
private int mTab, mPos; |
|
| 51 |
|
|
| 52 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 53 |
|
|
| 54 |
public RubikDialogPatternView(Context context, AttributeSet attrs, int defStyle) |
|
| 55 |
{
|
|
| 56 |
super(context, attrs, defStyle); |
|
| 57 |
} |
|
| 58 |
|
|
| 59 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 60 |
|
|
| 61 |
public RubikDialogPatternView(Context context, AttributeSet attrs) |
|
| 62 |
{
|
|
| 63 |
super(context, attrs); |
|
| 64 |
} |
|
| 65 |
|
|
| 66 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 67 |
|
|
| 68 |
public RubikDialogPatternView(FragmentActivity act, RubikDialogPattern dialog, int position) |
|
| 69 |
{
|
|
| 70 |
super(act); |
|
| 71 |
|
|
| 72 |
mDialog = dialog; |
|
| 73 |
mTab = position; |
|
| 74 |
View tab = inflate( act, R.layout.dialog_pattern_tab, null); |
|
| 75 |
mLayout = tab.findViewById(R.id.tabLayout); |
|
| 76 |
mScroll = tab.findViewById(R.id.tabScrollView); |
|
| 77 |
|
|
| 78 |
String[] categories = createCategories(); |
|
| 79 |
|
|
| 80 |
Spinner spinner = tab.findViewById(R.id.pattern_category_spinner); |
|
| 81 |
spinner.setOnItemSelectedListener(this); |
|
| 82 |
|
|
| 83 |
ArrayAdapter<String> adapter = new ArrayAdapter<>(act, android.R.layout.simple_spinner_item, categories); |
|
| 84 |
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); |
|
| 85 |
spinner.setAdapter(adapter); |
|
| 86 |
|
|
| 87 |
RubikPattern pattern = RubikPattern.getInstance(); |
|
| 88 |
spinner.setSelection(pattern.recallCategory(mTab)); |
|
| 89 |
|
|
| 90 |
addView(tab); |
|
| 91 |
} |
|
| 92 |
|
|
| 93 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 94 |
|
|
| 95 |
private String[] createCategories() |
|
| 96 |
{
|
|
| 97 |
RubikPattern pattern = RubikPattern.getInstance(); |
|
| 98 |
int numCat = pattern.getNumCategories(mTab); |
|
| 99 |
|
|
| 100 |
String[] ret = new String[numCat]; |
|
| 101 |
|
|
| 102 |
for(int i=0; i<numCat; i++) |
|
| 103 |
{
|
|
| 104 |
ret[i] = pattern.getCategoryName(mTab,i); |
|
| 105 |
} |
|
| 106 |
|
|
| 107 |
return ret; |
|
| 108 |
} |
|
| 109 |
|
|
| 110 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 111 |
|
|
| 112 |
private String[] createPatterns(int category) |
|
| 113 |
{
|
|
| 114 |
RubikPattern pattern = RubikPattern.getInstance(); |
|
| 115 |
int numPat = pattern.getNumPatterns(mTab, category); |
|
| 116 |
|
|
| 117 |
String[] ret = new String[numPat]; |
|
| 118 |
|
|
| 119 |
for(int i=0; i<numPat; i++) |
|
| 120 |
{
|
|
| 121 |
ret[i] = pattern.getPatternName(mTab, category, i); |
|
| 122 |
} |
|
| 123 |
|
|
| 124 |
return ret; |
|
| 125 |
} |
|
| 126 |
|
|
| 127 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 128 |
|
|
| 129 |
private void fillPatterns(final int category) |
|
| 130 |
{
|
|
| 131 |
final RubikActivity act = (RubikActivity)getContext(); |
|
| 132 |
|
|
| 133 |
DisplayMetrics metrics = act.getResources().getDisplayMetrics(); |
|
| 134 |
final float scale = metrics.density; |
|
| 135 |
int margin = (int)(3*scale + 0.5f); |
|
| 136 |
LinearLayout.LayoutParams bParams = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,LinearLayout.LayoutParams.WRAP_CONTENT); |
|
| 137 |
bParams.setMargins(margin, margin, margin, margin); |
|
| 138 |
|
|
| 139 |
final String[] patterns = createPatterns(category); |
|
| 140 |
int len = patterns.length; |
|
| 141 |
final RubikPattern pattern = RubikPattern.getInstance(); |
|
| 142 |
|
|
| 143 |
mLayout.removeAllViews(); |
|
| 144 |
|
|
| 145 |
for(int i=0; i<len; i++) |
|
| 146 |
{
|
|
| 147 |
final int ii = i; |
|
| 148 |
Button button = new Button(act); |
|
| 149 |
button.setLayoutParams(bParams); |
|
| 150 |
button.setText(patterns[i]); |
|
| 151 |
|
|
| 152 |
button.setOnClickListener( new View.OnClickListener() |
|
| 153 |
{
|
|
| 154 |
@Override |
|
| 155 |
public void onClick(View view) |
|
| 156 |
{
|
|
| 157 |
int[][] moves = pattern.reInitialize(mTab, category, ii); |
|
| 158 |
|
|
| 159 |
RubikObjectList list = RubikPatternList.getObject(mTab); |
|
| 160 |
int size = RubikPatternList.getSize(mTab); |
|
| 161 |
|
|
| 162 |
act.changeObject( list, size, moves); |
|
| 163 |
|
|
| 164 |
RubikStatePattern state = (RubikStatePattern) RubikState.PATT.getStateClass(); |
|
| 165 |
state.setPattern(act, mTab, category, ii); |
|
| 166 |
mDialog.rememberState(); |
|
| 167 |
mDialog.dismiss(); |
|
| 168 |
} |
|
| 169 |
}); |
|
| 170 |
|
|
| 171 |
mLayout.addView(button); |
|
| 172 |
} |
|
| 173 |
} |
|
| 174 |
|
|
| 175 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 176 |
|
|
| 177 |
int getCurrentCategory() |
|
| 178 |
{
|
|
| 179 |
return mPos; |
|
| 180 |
} |
|
| 181 |
|
|
| 182 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 183 |
|
|
| 184 |
int getCurrentScrollPos() |
|
| 185 |
{
|
|
| 186 |
return mScroll.getScrollY(); |
|
| 187 |
} |
|
| 188 |
|
|
| 189 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 190 |
|
|
| 191 |
@Override |
|
| 192 |
protected void onLayout(boolean changed, int left, int top, int right, int bottom) |
|
| 193 |
{
|
|
| 194 |
super.onLayout(changed,left,top,right,bottom); |
|
| 195 |
|
|
| 196 |
if( !changed ) |
|
| 197 |
{
|
|
| 198 |
final RubikPattern pattern = RubikPattern.getInstance(); |
|
| 199 |
mScroll.setScrollY( pattern.recallScrollPos(mTab) ); |
|
| 200 |
} |
|
| 201 |
} |
|
| 202 |
|
|
| 203 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 204 |
|
|
| 205 |
@Override |
|
| 206 |
public void onItemSelected(AdapterView<?> parent, View view, int pos, long id) |
|
| 207 |
{
|
|
| 208 |
if( parent.getId() == R.id.pattern_category_spinner ) |
|
| 209 |
{
|
|
| 210 |
mPos = pos; |
|
| 211 |
fillPatterns(pos); |
|
| 212 |
} |
|
| 213 |
} |
|
| 214 |
|
|
| 215 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 216 |
|
|
| 217 |
@Override |
|
| 218 |
public void onNothingSelected(AdapterView<?> parent) |
|
| 219 |
{
|
|
| 220 |
|
|
| 221 |
} |
|
| 222 |
} |
|
| src/main/java/org/distorted/dialog/RubikDialogScores.java | ||
|---|---|---|
| 1 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 2 |
// Copyright 2019 Leszek Koltunski // |
|
| 3 |
// // |
|
| 4 |
// This file is part of Magic Cube. // |
|
| 5 |
// // |
|
| 6 |
// Magic Cube is free software: you can redistribute it and/or modify // |
|
| 7 |
// 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 |
// Magic Cube is distributed in the hope that it will be useful, // |
|
| 12 |
// 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 |
// along with Magic Cube. If not, see <http://www.gnu.org/licenses/>. // |
|
| 18 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 19 |
|
|
| 20 |
package org.distorted.dialog; |
|
| 21 |
|
|
| 22 |
import android.app.Dialog; |
|
| 23 |
import android.content.DialogInterface; |
|
| 24 |
import android.os.Bundle; |
|
| 25 |
import android.support.annotation.NonNull; |
|
| 26 |
import android.support.v4.app.FragmentActivity; |
|
| 27 |
import android.support.v4.view.ViewPager; |
|
| 28 |
import android.support.v7.app.AlertDialog; |
|
| 29 |
import android.support.v7.app.AppCompatDialogFragment; |
|
| 30 |
import android.support.design.widget.TabLayout; |
|
| 31 |
import android.view.LayoutInflater; |
|
| 32 |
import android.view.View; |
|
| 33 |
import android.view.Window; |
|
| 34 |
import android.view.WindowManager; |
|
| 35 |
import android.widget.ImageView; |
|
| 36 |
import android.widget.TextView; |
|
| 37 |
|
|
| 38 |
import org.distorted.magic.R; |
|
| 39 |
import org.distorted.object.RubikObjectList; |
|
| 40 |
|
|
| 41 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 42 |
|
|
| 43 |
public class RubikDialogScores extends AppCompatDialogFragment |
|
| 44 |
{
|
|
| 45 |
RubikDialogScoresPagerAdapter mPagerAdapter; |
|
| 46 |
|
|
| 47 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 48 |
|
|
| 49 |
@Override |
|
| 50 |
public void onStart() |
|
| 51 |
{
|
|
| 52 |
super.onStart(); |
|
| 53 |
|
|
| 54 |
Window window = getDialog().getWindow(); |
|
| 55 |
window.setFlags(WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL, |
|
| 56 |
WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL); |
|
| 57 |
window.clearFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND); |
|
| 58 |
} |
|
| 59 |
|
|
| 60 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 61 |
|
|
| 62 |
@NonNull |
|
| 63 |
@Override |
|
| 64 |
public Dialog onCreateDialog(Bundle savedInstanceState) |
|
| 65 |
{
|
|
| 66 |
FragmentActivity act = getActivity(); |
|
| 67 |
AlertDialog.Builder builder = new AlertDialog.Builder(act); |
|
| 68 |
|
|
| 69 |
LayoutInflater layoutInflater = act.getLayoutInflater(); |
|
| 70 |
TextView tv = (TextView) layoutInflater.inflate(R.layout.dialog_title, null); |
|
| 71 |
tv.setText(R.string.scores); |
|
| 72 |
builder.setCustomTitle(tv); |
|
| 73 |
|
|
| 74 |
builder.setCancelable(true); |
|
| 75 |
builder.setPositiveButton( R.string.ok, new DialogInterface.OnClickListener() |
|
| 76 |
{
|
|
| 77 |
@Override |
|
| 78 |
public void onClick(DialogInterface dialog, int which) |
|
| 79 |
{
|
|
| 80 |
|
|
| 81 |
} |
|
| 82 |
}); |
|
| 83 |
|
|
| 84 |
Bundle args = getArguments(); |
|
| 85 |
int curTab; |
|
| 86 |
boolean isSubmitting; |
|
| 87 |
|
|
| 88 |
try |
|
| 89 |
{
|
|
| 90 |
curTab = args.getInt("tab");
|
|
| 91 |
isSubmitting = args.getBoolean("submitting");
|
|
| 92 |
} |
|
| 93 |
catch(Exception e) |
|
| 94 |
{
|
|
| 95 |
curTab = 0; |
|
| 96 |
isSubmitting = false; |
|
| 97 |
} |
|
| 98 |
|
|
| 99 |
LayoutInflater inflater = act.getLayoutInflater(); |
|
| 100 |
final View view = inflater.inflate(R.layout.dialog_tabbed, null); |
|
| 101 |
builder.setView(view); |
|
| 102 |
|
|
| 103 |
ViewPager viewPager = view.findViewById(R.id.viewpager); |
|
| 104 |
TabLayout tabLayout = view.findViewById(R.id.sliding_tabs); |
|
| 105 |
mPagerAdapter = new RubikDialogScoresPagerAdapter(act,viewPager,isSubmitting, this); |
|
| 106 |
tabLayout.setupWithViewPager(viewPager); |
|
| 107 |
|
|
| 108 |
viewPager.setCurrentItem(curTab); |
|
| 109 |
RubikObjectList list; |
|
| 110 |
|
|
| 111 |
for (int object=0; object<RubikObjectList.NUM_OBJECTS; object++) |
|
| 112 |
{
|
|
| 113 |
list = RubikObjectList.getObject(object); |
|
| 114 |
int[] iconID = list.getIconIDs(); |
|
| 115 |
int len = list.getSizes().length; |
|
| 116 |
|
|
| 117 |
for(int size=0; size<len; size++) |
|
| 118 |
{
|
|
| 119 |
int t = RubikObjectList.pack(object,size); |
|
| 120 |
ImageView imageView = new ImageView(act); |
|
| 121 |
imageView.setImageResource(iconID[size]); |
|
| 122 |
TabLayout.Tab tab = tabLayout.getTabAt(t); |
|
| 123 |
if(tab!=null) tab.setCustomView(imageView); |
|
| 124 |
} |
|
| 125 |
} |
|
| 126 |
|
|
| 127 |
return builder.create(); |
|
| 128 |
} |
|
| 129 |
} |
|
| src/main/java/org/distorted/dialog/RubikDialogScoresPagerAdapter.java | ||
|---|---|---|
| 1 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 2 |
// Copyright 2020 Leszek Koltunski // |
|
| 3 |
// // |
|
| 4 |
// This file is part of Magic Cube. // |
|
| 5 |
// // |
|
| 6 |
// Magic Cube is free software: you can redistribute it and/or modify // |
|
| 7 |
// 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 |
// Magic Cube is distributed in the hope that it will be useful, // |
|
| 12 |
// 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 |
// along with Magic Cube. If not, see <http://www.gnu.org/licenses/>. // |
|
| 18 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 19 |
|
|
| 20 |
package org.distorted.dialog; |
|
| 21 |
|
|
| 22 |
import android.os.Bundle; |
|
| 23 |
import android.support.annotation.NonNull; |
|
| 24 |
import android.support.v4.app.FragmentActivity; |
|
| 25 |
import android.support.v4.view.PagerAdapter; |
|
| 26 |
import android.support.v4.view.ViewPager; |
|
| 27 |
import android.view.View; |
|
| 28 |
import android.view.ViewGroup; |
|
| 29 |
import android.widget.LinearLayout; |
|
| 30 |
|
|
| 31 |
import org.distorted.scores.RubikScores; |
|
| 32 |
import org.distorted.scores.RubikScoresDownloader; |
|
| 33 |
import org.distorted.object.RubikObjectList; |
|
| 34 |
|
|
| 35 |
import static org.distorted.uistate.RubikStatePlay.MAX_SCRAMBLE; |
|
| 36 |
|
|
| 37 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 38 |
|
|
| 39 |
class RubikDialogScoresPagerAdapter extends PagerAdapter implements RubikScoresDownloader.Receiver |
|
| 40 |
{
|
|
| 41 |
private FragmentActivity mAct; |
|
| 42 |
private RubikDialogScores mDialog; |
|
| 43 |
private RubikDialogScoresView[] mViews; |
|
| 44 |
private ViewPager mViewPager; |
|
| 45 |
private int mNumTabs; |
|
| 46 |
private boolean mIsSubmitting; |
|
| 47 |
|
|
| 48 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 49 |
|
|
| 50 |
public void receive(final String[][][] country, final String[][][] name, final float[][][] time) |
|
| 51 |
{
|
|
| 52 |
prepareView(); |
|
| 53 |
|
|
| 54 |
int c = mViewPager.getCurrentItem(); |
|
| 55 |
|
|
| 56 |
addPage(c, mViews[c],country[c],name[c],time[c]); |
|
| 57 |
|
|
| 58 |
for(int i=0; i<mNumTabs; i++) |
|
| 59 |
{
|
|
| 60 |
if( i==c ) continue; |
|
| 61 |
|
|
| 62 |
addPage(i, mViews[i],country[i],name[i],time[i]); |
|
| 63 |
} |
|
| 64 |
} |
|
| 65 |
|
|
| 66 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 67 |
|
|
| 68 |
public void message(final String mess) |
|
| 69 |
{
|
|
| 70 |
mAct.runOnUiThread(new Runnable() |
|
| 71 |
{
|
|
| 72 |
@Override |
|
| 73 |
public void run() |
|
| 74 |
{
|
|
| 75 |
for(int i=0; i<mNumTabs; i++) |
|
| 76 |
{
|
|
| 77 |
mViews[i].message(mess); |
|
| 78 |
} |
|
| 79 |
} |
|
| 80 |
}); |
|
| 81 |
} |
|
| 82 |
|
|
| 83 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 84 |
|
|
| 85 |
public void error(final String error) |
|
| 86 |
{
|
|
| 87 |
char errorNumber = error.charAt(0); |
|
| 88 |
|
|
| 89 |
switch(errorNumber) |
|
| 90 |
{
|
|
| 91 |
case '1': message("Client error");
|
|
| 92 |
break; |
|
| 93 |
case '2': RubikScores scores = RubikScores.getInstance(); |
|
| 94 |
Bundle bundle = new Bundle(); |
|
| 95 |
bundle.putString("name", scores.getName() );
|
|
| 96 |
|
|
| 97 |
RubikDialogSetName nameDiag = new RubikDialogSetName(); |
|
| 98 |
nameDiag.setArguments(bundle); |
|
| 99 |
nameDiag.show(mAct.getSupportFragmentManager(), null); |
|
| 100 |
|
|
| 101 |
mDialog.dismiss(); |
|
| 102 |
|
|
| 103 |
break; |
|
| 104 |
case '3': message("Server error");
|
|
| 105 |
break; |
|
| 106 |
default : message("Unexpected error");
|
|
| 107 |
} |
|
| 108 |
} |
|
| 109 |
|
|
| 110 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 111 |
|
|
| 112 |
private void prepareView() |
|
| 113 |
{
|
|
| 114 |
mAct.runOnUiThread(new Runnable() |
|
| 115 |
{
|
|
| 116 |
@Override |
|
| 117 |
public void run() |
|
| 118 |
{
|
|
| 119 |
for(int i=0; i<mNumTabs; i++) |
|
| 120 |
{
|
|
| 121 |
mViews[i].prepareView(mAct); |
|
| 122 |
} |
|
| 123 |
} |
|
| 124 |
}); |
|
| 125 |
try |
|
| 126 |
{
|
|
| 127 |
Thread.sleep(150); |
|
| 128 |
} |
|
| 129 |
catch( InterruptedException ie) |
|
| 130 |
{
|
|
| 131 |
|
|
| 132 |
} |
|
| 133 |
} |
|
| 134 |
|
|
| 135 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 136 |
|
|
| 137 |
private void addPage(int tab, final RubikDialogScoresView view, final String[][] country, final String[][] name, final float[][] time) |
|
| 138 |
{
|
|
| 139 |
for(int i=0; i<MAX_SCRAMBLE; i++) |
|
| 140 |
{
|
|
| 141 |
final LinearLayout section = view.createSection(mAct, tab, i, country[i], name[i], time[i]); |
|
| 142 |
|
|
| 143 |
mAct.runOnUiThread(new Runnable() |
|
| 144 |
{
|
|
| 145 |
@Override |
|
| 146 |
public void run() |
|
| 147 |
{
|
|
| 148 |
view.addSection(section); |
|
| 149 |
} |
|
| 150 |
}); |
|
| 151 |
|
|
| 152 |
try |
|
| 153 |
{
|
|
| 154 |
Thread.sleep(50); |
|
| 155 |
} |
|
| 156 |
catch( InterruptedException ie) |
|
| 157 |
{
|
|
| 158 |
|
|
| 159 |
} |
|
| 160 |
} |
|
| 161 |
} |
|
| 162 |
|
|
| 163 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 164 |
|
|
| 165 |
RubikDialogScoresPagerAdapter(FragmentActivity act, ViewPager viewPager, boolean isSubmitting, RubikDialogScores diag) |
|
| 166 |
{
|
|
| 167 |
mAct = act; |
|
| 168 |
mDialog = diag; |
|
| 169 |
mNumTabs = RubikObjectList.getTotal(); |
|
| 170 |
mViews = new RubikDialogScoresView[mNumTabs]; |
|
| 171 |
mViewPager = viewPager; |
|
| 172 |
mIsSubmitting = isSubmitting; |
|
| 173 |
|
|
| 174 |
viewPager.setAdapter(this); |
|
| 175 |
viewPager.setOffscreenPageLimit(mNumTabs-1); |
|
| 176 |
} |
|
| 177 |
|
|
| 178 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 179 |
|
|
| 180 |
@Override |
|
| 181 |
@NonNull |
|
| 182 |
public Object instantiateItem(@NonNull ViewGroup collection, int position) |
|
| 183 |
{
|
|
| 184 |
mViews[position] = new RubikDialogScoresView(mAct, mIsSubmitting); |
|
| 185 |
collection.addView(mViews[position]); |
|
| 186 |
|
|
| 187 |
boolean allCreated = true; |
|
| 188 |
|
|
| 189 |
for(int i=0; i<mNumTabs; i++) |
|
| 190 |
{
|
|
| 191 |
if( mViews[i]==null ) |
|
| 192 |
{
|
|
| 193 |
allCreated = false; |
|
| 194 |
break; |
|
| 195 |
} |
|
| 196 |
} |
|
| 197 |
|
|
| 198 |
if( allCreated ) |
|
| 199 |
{
|
|
| 200 |
RubikScoresDownloader downloader = RubikScoresDownloader.getInstance(); |
|
| 201 |
|
|
| 202 |
if( mIsSubmitting ) downloader.submit ( this, mAct ); |
|
| 203 |
else downloader.download( this, mAct ); |
|
| 204 |
} |
|
| 205 |
|
|
| 206 |
return mViews[position]; |
|
| 207 |
} |
|
| 208 |
|
|
| 209 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 210 |
|
|
| 211 |
@Override |
|
| 212 |
public void destroyItem(ViewGroup collection, int position, @NonNull Object view) |
|
| 213 |
{
|
|
| 214 |
collection.removeView((View) view); |
|
| 215 |
} |
|
| 216 |
|
|
| 217 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 218 |
|
|
| 219 |
@Override |
|
| 220 |
public int getCount() |
|
| 221 |
{
|
|
| 222 |
return mNumTabs; |
|
| 223 |
} |
|
Also available in: Unified diff
More support for the 3x3x3 Solver: more of the actual 3x3x3 solver mechanism.