15 |
15 |
import android.content.SharedPreferences;
|
16 |
16 |
import android.os.Bundle;
|
17 |
17 |
import android.view.View;
|
|
18 |
import android.widget.AdapterView;
|
|
19 |
import android.widget.ArrayAdapter;
|
|
20 |
import android.widget.Spinner;
|
18 |
21 |
import android.widget.TextView;
|
19 |
22 |
import android.widget.Toast;
|
20 |
23 |
|
... | ... | |
22 |
25 |
|
23 |
26 |
import org.distorted.library.main.DistortedLibrary;
|
24 |
27 |
import org.distorted.objectlib.algsolvers.*;
|
|
28 |
import org.distorted.objectlib.algsolvers.implemented.Solver3x3Beginner;
|
|
29 |
import org.distorted.objectlib.algsolvers.implemented.SolverAbstract;
|
25 |
30 |
import org.distorted.objectlib.algsolvers.implemented.SolverKilominx;
|
26 |
31 |
import org.distorted.objectlib.main.InitAssets;
|
27 |
32 |
import org.distorted.objectlib.main.ObjectControl;
|
... | ... | |
31 |
36 |
|
32 |
37 |
///////////////////////////////////////////////////////////////////////////////////////////////////
|
33 |
38 |
|
34 |
|
public class SolverActivity extends Activity implements SolutionListener
|
|
39 |
public class SolverActivity extends Activity implements SolutionListener, AdapterView.OnItemSelectedListener
|
35 |
40 |
{
|
36 |
41 |
private InitAssets mAsset;
|
37 |
42 |
private SharedPreferences mPreferences;
|
... | ... | |
40 |
45 |
private SolvedObject mObject;
|
41 |
46 |
private String mMoves;
|
42 |
47 |
private int mNumMoves;
|
43 |
|
private SolverKilominx mBeginner;
|
|
48 |
private int mCurrSolver;
|
|
49 |
private SolverAbstract mSolver;
|
44 |
50 |
private long mTime;
|
45 |
51 |
|
46 |
52 |
///////////////////////////////////////////////////////////////////////////////////////////////////
|
... | ... | |
58 |
64 |
mText = findViewById(R.id.solverMoves);
|
59 |
65 |
mMoves = "";
|
60 |
66 |
mNumMoves = 0;
|
|
67 |
Spinner objectSpinner = findViewById(R.id.solverSpinner);
|
|
68 |
objectSpinner.setOnItemSelectedListener(this);
|
61 |
69 |
|
62 |
|
mBeginner = new SolverKilominx();
|
63 |
|
mObject = mBeginner.getObject();
|
|
70 |
mCurrSolver = 0;
|
|
71 |
String[] solverNames = createSolverNames();
|
|
72 |
ArrayAdapter<String> objAdapter = new ArrayAdapter<>(this, android.R.layout.simple_spinner_item, solverNames);
|
|
73 |
objAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
|
|
74 |
objectSpinner.setAdapter(objAdapter);
|
64 |
75 |
|
65 |
|
int numPhases = mBeginner.getNumPhases();
|
66 |
|
String[] names = new String[numPhases];
|
67 |
|
for(int p=0; p<numPhases; p++) names[p] = mBeginner.getPhaseName(p);
|
|
76 |
String[] phaseNames = createSolver();
|
68 |
77 |
|
69 |
|
mLowerPane = new SolverLowerPane(this,names);
|
|
78 |
mLowerPane = new SolverLowerPane(this,phaseNames);
|
70 |
79 |
}
|
71 |
80 |
|
72 |
81 |
///////////////////////////////////////////////////////////////////////////////////////////////////
|
... | ... | |
94 |
103 |
|
95 |
104 |
restorePreferences();
|
96 |
105 |
|
|
106 |
int ordinal = getObjectOrdinal();
|
97 |
107 |
ObjectControl control = getControl();
|
98 |
|
control.changeObject(ListObjects.KILO_3.ordinal(), MODE_NORM, mAsset);
|
|
108 |
control.changeObject(ordinal, MODE_NORM, mAsset);
|
99 |
109 |
}
|
100 |
110 |
|
101 |
111 |
///////////////////////////////////////////////////////////////////////////////////////////////////
|
... | ... | |
107 |
117 |
super.onDestroy();
|
108 |
118 |
}
|
109 |
119 |
|
|
120 |
///////////////////////////////////////////////////////////////////////////////////////////////////
|
|
121 |
|
|
122 |
public void onItemSelected(AdapterView<?> parent, View view, int pos, long id)
|
|
123 |
{
|
|
124 |
if( parent.getId()==R.id.solverSpinner && mCurrSolver!=pos )
|
|
125 |
{
|
|
126 |
mCurrSolver = pos;
|
|
127 |
String[] phaseNames = createSolver();
|
|
128 |
mLowerPane.updateNames(this,phaseNames);
|
|
129 |
int ordinal = getObjectOrdinal();
|
|
130 |
ObjectControl control = getControl();
|
|
131 |
control.changeObject(ordinal, MODE_NORM, mAsset);
|
|
132 |
}
|
|
133 |
}
|
|
134 |
|
|
135 |
///////////////////////////////////////////////////////////////////////////////////////////////////
|
|
136 |
|
|
137 |
public void onNothingSelected(AdapterView<?> parent) { }
|
|
138 |
|
|
139 |
///////////////////////////////////////////////////////////////////////////////////////////////////
|
|
140 |
|
|
141 |
private String[] createSolverNames()
|
|
142 |
{
|
|
143 |
return new String[] {"3x3", "Kilo"};
|
|
144 |
}
|
|
145 |
|
|
146 |
///////////////////////////////////////////////////////////////////////////////////////////////////
|
|
147 |
|
|
148 |
private int getObjectOrdinal()
|
|
149 |
{
|
|
150 |
if( mCurrSolver==1 ) return ListObjects.KILO_3.ordinal();
|
|
151 |
return ListObjects.CUBE_3.ordinal();
|
|
152 |
}
|
|
153 |
|
|
154 |
///////////////////////////////////////////////////////////////////////////////////////////////////
|
|
155 |
|
|
156 |
private String[] createSolver()
|
|
157 |
{
|
|
158 |
switch(mCurrSolver)
|
|
159 |
{
|
|
160 |
case 0 : mSolver = new Solver3x3Beginner(); break;
|
|
161 |
case 1 : mSolver = new SolverKilominx(); break;
|
|
162 |
default: android.util.Log.e("D", "unknown solver: "+mCurrSolver);
|
|
163 |
mSolver = new Solver3x3Beginner(); break;
|
|
164 |
}
|
|
165 |
|
|
166 |
mObject = mSolver.getObject();
|
|
167 |
|
|
168 |
int numPhases = mSolver.getNumPhases();
|
|
169 |
String[] names = new String[numPhases];
|
|
170 |
for(int p=0; p<numPhases; p++) names[p] = mSolver.getPhaseName(p);
|
|
171 |
|
|
172 |
return names;
|
|
173 |
}
|
|
174 |
|
110 |
175 |
///////////////////////////////////////////////////////////////////////////////////////////////////
|
111 |
176 |
|
112 |
177 |
public void Left(View v) { mLowerPane.backMove(this); }
|
... | ... | |
189 |
254 |
@Override
|
190 |
255 |
public void run()
|
191 |
256 |
{
|
192 |
|
mBeginner.solution(listener, qi);
|
|
257 |
mSolver.solution(listener, qi);
|
193 |
258 |
}
|
194 |
259 |
});
|
195 |
260 |
}
|
Add possibility to select different solvers.