|
1
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
|
2
|
// Copyright 2023 Leszek Koltunski //
|
|
3
|
// //
|
|
4
|
// This file is part of Magic Cube. //
|
|
5
|
// //
|
|
6
|
// Magic Cube is proprietary software licensed under an EULA which you should have received //
|
|
7
|
// along with the code. If not, check https://distorted.org/magic/License-Magic-Cube.html //
|
|
8
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
|
9
|
|
|
10
|
package org.distorted.dialogs;
|
|
11
|
|
|
12
|
import android.util.TypedValue;
|
|
13
|
import android.view.View;
|
|
14
|
import android.widget.Button;
|
|
15
|
import android.widget.LinearLayout;
|
|
16
|
import android.widget.TextView;
|
|
17
|
|
|
18
|
import org.distorted.main.R;
|
|
19
|
import org.distorted.objectlib.helpers.OperatingSystemInterface;
|
|
20
|
import org.distorted.objectlib.main.TwistyObject;
|
|
21
|
import org.distorted.objectlib.solvers.verifiers.SolverAbstract;
|
|
22
|
import org.distorted.objectlib.solvers.verifiers.ImplementedVerifierList;
|
|
23
|
import org.distorted.solvers.ScreenList;
|
|
24
|
import org.distorted.solvers.ScreenSetupPosition;
|
|
25
|
import org.distorted.solvers.SolverActivity;
|
|
26
|
|
|
27
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
|
28
|
|
|
29
|
public class DialogSolverView
|
|
30
|
{
|
|
31
|
private final View mView;
|
|
32
|
|
|
33
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
|
34
|
|
|
35
|
public DialogSolverView(final SolverActivity act, final DialogSolvers dialog,
|
|
36
|
int solverOrdinal, int title, int desc, int padding,
|
|
37
|
int fontSize, LinearLayout.LayoutParams pView,
|
|
38
|
LinearLayout.LayoutParams pText, LinearLayout.LayoutParams pButt)
|
|
39
|
{
|
|
40
|
mView = act.getLayoutInflater().inflate(R.layout.dialog_solvers_pane, null);
|
|
41
|
mView.setLayoutParams(pView);
|
|
42
|
mView.setPadding(padding,padding,padding,padding);
|
|
43
|
|
|
44
|
TextView titleView = mView.findViewById(R.id.solvers_pane_title);
|
|
45
|
titleView.setText(title);
|
|
46
|
TextView descView = mView.findViewById(R.id.solvers_pane_description);
|
|
47
|
descView.setText(desc);
|
|
48
|
|
|
49
|
titleView.setLayoutParams(pText);
|
|
50
|
Button button = mView.findViewById(R.id.solvers_pane_button);
|
|
51
|
|
|
52
|
button.setOnClickListener( new View.OnClickListener()
|
|
53
|
{
|
|
54
|
@Override
|
|
55
|
public void onClick(View v)
|
|
56
|
{
|
|
57
|
dialog.dismiss();
|
|
58
|
ImplementedVerifierList list = ImplementedVerifierList.getSolver(solverOrdinal);
|
|
59
|
OperatingSystemInterface os = act.getInterface();
|
|
60
|
TwistyObject object = act.getObject();
|
|
61
|
SolverAbstract solver = list.create(os,object);
|
|
62
|
ScreenSetupPosition screen = (ScreenSetupPosition)ScreenList.SVER.getScreenClass();
|
|
63
|
|
|
64
|
if( solver!=null )
|
|
65
|
{
|
|
66
|
act.setSolver(solver);
|
|
67
|
int[] result = solver.validatePosition(object);
|
|
68
|
if( result[0]>=0 ) solver.solve(screen,result);
|
|
69
|
else screen.displayImpossibleDialog(result,solver.getFaceColors());
|
|
70
|
}
|
|
71
|
else screen.displayErrorDialog(act.getString(R.string.solver_generic_not_implemented));
|
|
72
|
}
|
|
73
|
});
|
|
74
|
|
|
75
|
button.setTextSize(TypedValue.COMPLEX_UNIT_PX, fontSize);
|
|
76
|
button.setLayoutParams(pButt);
|
|
77
|
}
|
|
78
|
|
|
79
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
|
80
|
|
|
81
|
public View getView()
|
|
82
|
{
|
|
83
|
return mView;
|
|
84
|
}
|
|
85
|
}
|