15 |
15 |
import android.content.SharedPreferences;
|
16 |
16 |
import android.os.Bundle;
|
17 |
17 |
import android.view.View;
|
|
18 |
import android.widget.Toast;
|
|
19 |
|
18 |
20 |
import androidx.preference.PreferenceManager;
|
19 |
21 |
|
20 |
22 |
import org.distorted.library.main.DistortedLibrary;
|
... | ... | |
31 |
33 |
|
32 |
34 |
public class SolverActivity extends Activity
|
33 |
35 |
{
|
34 |
|
private InitAssets mAsset;
|
35 |
|
private SharedPreferences mPreferences;
|
36 |
|
private SolverLowerPane mLowerPane;
|
|
36 |
private InitAssets mAsset;
|
|
37 |
private SharedPreferences mPreferences;
|
|
38 |
private SolverLowerPane mLowerPane;
|
37 |
39 |
|
38 |
40 |
///////////////////////////////////////////////////////////////////////////////////////////////////
|
39 |
41 |
|
40 |
|
@Override
|
41 |
|
protected void onCreate(Bundle icicle)
|
42 |
|
{
|
43 |
|
super.onCreate(icicle);
|
44 |
|
mPreferences = PreferenceManager.getDefaultSharedPreferences(this);
|
45 |
|
DistortedLibrary.onCreate();
|
46 |
|
setContentView(R.layout.mainlayout);
|
47 |
|
SolverSurfaceView view = findViewById(R.id.solverView);
|
48 |
|
OSInterface os = view.getInterface();
|
49 |
|
mAsset = new InitAssets(null,null,os);
|
50 |
|
mLowerPane = new SolverLowerPane(this);
|
51 |
|
}
|
|
42 |
@Override
|
|
43 |
protected void onCreate(Bundle icicle)
|
|
44 |
{
|
|
45 |
super.onCreate(icicle);
|
|
46 |
mPreferences = PreferenceManager.getDefaultSharedPreferences(this);
|
|
47 |
DistortedLibrary.onCreate();
|
|
48 |
setContentView(R.layout.mainlayout);
|
|
49 |
SolverSurfaceView view = findViewById(R.id.solverView);
|
|
50 |
OSInterface os = view.getInterface();
|
|
51 |
mAsset = new InitAssets(null, null, os);
|
|
52 |
mLowerPane = new SolverLowerPane(this);
|
|
53 |
}
|
52 |
54 |
|
53 |
55 |
///////////////////////////////////////////////////////////////////////////////////////////////////
|
54 |
|
|
55 |
|
@Override
|
56 |
|
protected void onPause()
|
57 |
|
{
|
58 |
|
super.onPause();
|
59 |
|
SolverSurfaceView view = findViewById(R.id.solverView);
|
60 |
|
view.onPause();
|
61 |
|
DistortedLibrary.onPause();
|
62 |
56 |
|
63 |
|
savePreferences();
|
64 |
|
}
|
|
57 |
@Override
|
|
58 |
protected void onPause()
|
|
59 |
{
|
|
60 |
super.onPause();
|
|
61 |
SolverSurfaceView view = findViewById(R.id.solverView);
|
|
62 |
view.onPause();
|
|
63 |
DistortedLibrary.onPause();
|
|
64 |
|
|
65 |
savePreferences();
|
|
66 |
}
|
65 |
67 |
|
66 |
68 |
///////////////////////////////////////////////////////////////////////////////////////////////////
|
67 |
|
|
68 |
|
@Override
|
69 |
|
protected void onResume()
|
70 |
|
{
|
71 |
|
super.onResume();
|
72 |
|
SolverSurfaceView view = findViewById(R.id.solverView);
|
73 |
|
view.onResume();
|
74 |
|
DistortedLibrary.onResume();
|
75 |
69 |
|
76 |
|
restorePreferences();
|
|
70 |
@Override
|
|
71 |
protected void onResume()
|
|
72 |
{
|
|
73 |
super.onResume();
|
|
74 |
SolverSurfaceView view = findViewById(R.id.solverView);
|
|
75 |
view.onResume();
|
|
76 |
DistortedLibrary.onResume();
|
|
77 |
|
|
78 |
restorePreferences();
|
|
79 |
|
|
80 |
ObjectControl control = getControl();
|
|
81 |
control.changeObject(ListObjects.CUBE_3.ordinal(), MODE_NORM, mAsset);
|
|
82 |
}
|
77 |
83 |
|
78 |
|
ObjectControl control = getControl();
|
79 |
|
control.changeObject( ListObjects.CUBE_3.ordinal(), MODE_NORM, mAsset);
|
80 |
|
}
|
81 |
|
|
82 |
84 |
///////////////////////////////////////////////////////////////////////////////////////////////////
|
83 |
|
|
84 |
|
@Override
|
85 |
|
protected void onDestroy()
|
86 |
|
{
|
87 |
|
DistortedLibrary.onDestroy();
|
88 |
|
super.onDestroy();
|
89 |
|
}
|
|
85 |
|
|
86 |
@Override
|
|
87 |
protected void onDestroy()
|
|
88 |
{
|
|
89 |
DistortedLibrary.onDestroy();
|
|
90 |
super.onDestroy();
|
|
91 |
}
|
90 |
92 |
|
91 |
93 |
///////////////////////////////////////////////////////////////////////////////////////////////////
|
92 |
94 |
|
93 |
|
ObjectControl getControl()
|
94 |
|
{
|
95 |
|
SolverSurfaceView view = findViewById(R.id.solverView);
|
96 |
|
return view.getObjectControl();
|
97 |
|
}
|
|
95 |
ObjectControl getControl()
|
|
96 |
{
|
|
97 |
SolverSurfaceView view = findViewById(R.id.solverView);
|
|
98 |
return view.getObjectControl();
|
|
99 |
}
|
98 |
100 |
|
99 |
101 |
///////////////////////////////////////////////////////////////////////////////////////////////////
|
100 |
102 |
|
101 |
|
private void savePreferences()
|
102 |
|
{
|
103 |
|
SharedPreferences.Editor editor = mPreferences.edit();
|
104 |
|
SolverSurfaceView view = findViewById(R.id.solverView);
|
105 |
|
OSInterface os = view.getInterface();
|
106 |
|
os.setEditor(editor);
|
107 |
|
view.getObjectControl().savePreferences();
|
|
103 |
private void savePreferences()
|
|
104 |
{
|
|
105 |
SharedPreferences.Editor editor = mPreferences.edit();
|
|
106 |
SolverSurfaceView view = findViewById(R.id.solverView);
|
|
107 |
OSInterface os = view.getInterface();
|
|
108 |
os.setEditor(editor);
|
|
109 |
view.getObjectControl().savePreferences();
|
108 |
110 |
|
109 |
|
editor.apply();
|
110 |
|
}
|
|
111 |
editor.apply();
|
|
112 |
}
|
|
113 |
|
|
114 |
///////////////////////////////////////////////////////////////////////////////////////////////////
|
|
115 |
|
|
116 |
private void restorePreferences()
|
|
117 |
{
|
|
118 |
SolverSurfaceView view = findViewById(R.id.solverView);
|
|
119 |
OSInterface os = view.getInterface();
|
|
120 |
os.setPreferences(mPreferences);
|
|
121 |
view.getObjectControl().restorePreferences();
|
|
122 |
}
|
111 |
123 |
|
112 |
124 |
///////////////////////////////////////////////////////////////////////////////////////////////////
|
113 |
125 |
|
114 |
|
private void restorePreferences()
|
|
126 |
private void solve(PhasedSolver ps, int[] quats, int[][] moveTable)
|
|
127 |
{
|
|
128 |
int[][] sol = ps.solution(quats);
|
|
129 |
int numPhases = sol.length;
|
|
130 |
int totalLength = 0;
|
|
131 |
|
|
132 |
for(int p=0; p<numPhases; p++)
|
115 |
133 |
{
|
116 |
|
SolverSurfaceView view = findViewById(R.id.solverView);
|
117 |
|
OSInterface os = view.getInterface();
|
118 |
|
os.setPreferences(mPreferences);
|
119 |
|
view.getObjectControl().restorePreferences();
|
|
134 |
int numMoves = sol[p]==null ? -1 : sol[p][0];
|
|
135 |
|
|
136 |
if( numMoves<0 )
|
|
137 |
{
|
|
138 |
String message = "Phase "+p+": FAIL";
|
|
139 |
Toast.makeText(this,message,Toast.LENGTH_LONG).show();
|
|
140 |
return;
|
|
141 |
}
|
|
142 |
|
|
143 |
totalLength += numMoves;
|
120 |
144 |
}
|
121 |
145 |
|
122 |
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
|
146 |
int[][] moves = new int[totalLength][];
|
|
147 |
int index = 0;
|
123 |
148 |
|
124 |
|
public void Reset(View v)
|
|
149 |
for( int[] s : sol )
|
125 |
150 |
{
|
126 |
|
ObjectControl control = getControl();
|
127 |
|
control.solveObject();
|
128 |
|
mLowerPane.clearMoves(this);
|
|
151 |
int numMoves = s[0];
|
|
152 |
|
|
153 |
for(int m=1; m<=numMoves; m++)
|
|
154 |
{
|
|
155 |
int mi = s[m];
|
|
156 |
moves[index++] = moveTable[mi];
|
|
157 |
android.util.Log.e("D","move "+m+" : "+moveTable[mi][0]+" "+moveTable[mi][1]+" "+moveTable[mi][2]);
|
|
158 |
}
|
129 |
159 |
}
|
130 |
160 |
|
|
161 |
mLowerPane.setMoves(this,moves);
|
|
162 |
}
|
|
163 |
|
131 |
164 |
///////////////////////////////////////////////////////////////////////////////////////////////////
|
132 |
165 |
|
133 |
166 |
public void Solve(View v)
|
... | ... | |
157 |
190 |
@Override
|
158 |
191 |
public void run()
|
159 |
192 |
{
|
160 |
|
int[][] sol = ps.solution(qi);
|
161 |
|
int numPhases = sol.length;
|
162 |
|
android.util.Log.e("D", "Solution, num of phases: "+numPhases);
|
163 |
|
|
164 |
|
for(int p=0; p<numPhases; p++)
|
165 |
|
{
|
166 |
|
int numMoves = sol[p]==null ? -1 : sol[p].length;
|
167 |
|
android.util.Log.e("D", "Phase "+p+" numMoves="+numMoves);
|
168 |
|
|
169 |
|
for(int m=0; m<numMoves; m++)
|
170 |
|
{
|
171 |
|
android.util.Log.e("D", "move "+m+" : "+sol[p][m]);
|
172 |
|
}
|
173 |
|
}
|
|
193 |
solve(ps,qi,moves);
|
174 |
194 |
}
|
175 |
195 |
});
|
176 |
196 |
}
|
177 |
197 |
|
|
198 |
///////////////////////////////////////////////////////////////////////////////////////////////////
|
|
199 |
|
|
200 |
public void Reset(View v)
|
|
201 |
{
|
|
202 |
ObjectControl control = getControl();
|
|
203 |
control.solveObject();
|
|
204 |
mLowerPane.clearMoves(this);
|
|
205 |
}
|
|
206 |
|
178 |
207 |
///////////////////////////////////////////////////////////////////////////////////////////////////
|
179 |
208 |
|
180 |
209 |
public void Left(View v)
|
PhasedSolver app: bugfixes.