Project

General

Profile

« Previous | Next » 

Revision 3bedda30

Added by Leszek Koltunski about 21 hours ago

Full support for multiple solvers per object.

View differences:

src/main/java/org/distorted/dialogs/RubikDialogSolverView.java
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.main.TwistyObject;
20
import org.distorted.solvers.SolvingList;
21
import org.distorted.solvers.SolvingThread;
22
import org.distorted.solverui.SolverActivity;
23

  
24
///////////////////////////////////////////////////////////////////////////////////////////////////
25

  
26
public class RubikDialogSolverView
27
  {
28
  private final View mView;
29

  
30
///////////////////////////////////////////////////////////////////////////////////////////////////
31

  
32
  public RubikDialogSolverView(final SolverActivity act, final RubikDialogSolvers dialog,
33
                               int solverOrdinal, int title, int desc, int padding,
34
                               int fontSize, LinearLayout.LayoutParams pView,
35
                               LinearLayout.LayoutParams pText, LinearLayout.LayoutParams pButt )
36
    {
37
    mView = act.getLayoutInflater().inflate(R.layout.dialog_solvers_pane, null);
38
    mView.setLayoutParams(pView);
39
    mView.setPadding(padding,padding,padding,padding);
40

  
41
    TextView titleView = mView.findViewById(R.id.solvers_pane_title);
42
    titleView.setText(title);
43
    TextView descView = mView.findViewById(R.id.solvers_pane_description);
44
    descView.setText(desc);
45

  
46
    titleView.setLayoutParams(pText);
47
    Button button = mView.findViewById(R.id.solvers_pane_button);
48

  
49
    button.setOnClickListener( new View.OnClickListener()
50
      {
51
      @Override
52
      public void onClick(View v)
53
        {
54
        dialog.dismiss();
55
        SolvingList list = SolvingList.getSolver(solverOrdinal);
56
        TwistyObject object = act.getObject();
57
        SolvingThread solver = new SolvingThread( act.getInterface(), act.getResources(), object, list );
58
        solver.start();
59
        }
60
      });
61

  
62
    button.setTextSize(TypedValue.COMPLEX_UNIT_PX, fontSize);
63
    button.setLayoutParams(pButt);
64
    }
65

  
66
///////////////////////////////////////////////////////////////////////////////////////////////////
67

  
68
  public View getView()
69
    {
70
    return mView;
71
    }
72
  }
src/main/java/org/distorted/dialogs/RubikDialogSolvers.java
1
///////////////////////////////////////////////////////////////////////////////////////////////////
2
// Copyright 2022 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.app.Dialog;
13
import android.util.DisplayMetrics;
14
import android.view.View;
15
import android.view.Window;
16
import android.view.WindowManager;
17
import android.widget.LinearLayout;
18
import android.widget.ScrollView;
19
import android.widget.TextView;
20

  
21
import androidx.fragment.app.FragmentActivity;
22

  
23
import org.distorted.main.R;
24
import org.distorted.objectlib.metadata.ListObjects;
25
import org.distorted.solverui.SolverActivity;
26
import org.distorted.solvers.SolvingList;
27

  
28
///////////////////////////////////////////////////////////////////////////////////////////////////
29

  
30
public class RubikDialogSolvers extends RubikDialogAbstract
31
  {
32
  @Override
33
  public void onResume()
34
    {
35
    super.onResume();
36

  
37
    Window window = getDialog().getWindow();
38

  
39
    if( window!=null )
40
      {
41
      WindowManager.LayoutParams params = window.getAttributes();
42
      params.width  = (int)Math.min( mHeight*0.60f,mWidth*0.75f );
43
      window.setAttributes(params);
44
      }
45
    }
46

  
47
///////////////////////////////////////////////////////////////////////////////////////////////////
48

  
49
  public int getResource()            { return R.layout.dialog_scrollable_panes; }
50
  public int getTitleResource()       { return R.string.solver; }
51
  public boolean hasArgument()        { return true; }
52
  public int getPositive()            { return -1; }
53
  public int getNegative()            { return -1; }
54
  public static String getDialogTag() { return "DialogSolvers"; }
55
  public void positiveAction()        { }
56
  public void negativeAction()        { }
57

  
58
///////////////////////////////////////////////////////////////////////////////////////////////////
59

  
60
  public void prepareBody(Dialog dialog, View view, FragmentActivity act, float size)
61
    {
62
    int margin= (int)(mHeight*0.010f);
63
    int padd  = (int)(mHeight*0.010f);
64
    int font  = (int)(mHeight*0.025f);
65

  
66
    LinearLayout layout= view.findViewById(R.id.dialog_scrollable_main_layout);
67
    TextView text  = view.findViewById(R.id.dialog_scrollable_message);
68
    text.setVisibility(View.GONE);
69

  
70
    DisplayMetrics metrics = new DisplayMetrics();
71
    act.getWindowManager().getDefaultDisplay().getMetrics(metrics);
72
    float logicalDensity = metrics.density;
73
    int px = (int) Math.ceil(10*logicalDensity);
74
    ScrollView scroll = view.findViewById(R.id.updates_scroll);
75
    scroll.setPadding(px,0,px,px);
76

  
77
    LinearLayout.LayoutParams pV = new LinearLayout.LayoutParams( LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT );
78
    pV.setMargins(margin, margin, margin, 0);
79
    LinearLayout.LayoutParams pL = new LinearLayout.LayoutParams( LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT );
80
    pL.setMargins(margin, margin, margin, margin);
81
    LinearLayout.LayoutParams pT = new LinearLayout.LayoutParams( LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT );
82
    pT.setMargins(0,0,0,2*margin);
83
    LinearLayout.LayoutParams pB = new LinearLayout.LayoutParams( LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT );
84
    pB.setMargins(0,2*margin,0,0);
85

  
86
    SolverActivity sact = (SolverActivity) getContext();
87
    int objectOrdinal = ListObjects.getObjectIndex(mArgument);
88
    int[] solverOrdinals = SolvingList.getSolverOrdinals(objectOrdinal);
89
    int len = solverOrdinals==null ? 0 : solverOrdinals.length;
90

  
91
    for(int o=0; o<len; o++ )
92
      {
93
      int ord = solverOrdinals[o];
94
      SolvingList solver = SolvingList.getSolver(ord);
95
      int title  = solver.getTitle();
96
      int description = solver.getDescription();
97
      RubikDialogSolverView pane = new RubikDialogSolverView(sact,this,ord,title,description, padd, font, (o==len-1?pL:pV),pT,pB);
98
      layout.addView(pane.getView());
99
      }
100
    }
101
  }
src/main/java/org/distorted/solvers/SolvingList.java
27 27
{
28 28
  CUBE2          (CUBE_2.ordinal(), SolverTablebaseCUBE2.class, R.string.solver_cube2_title, R.string.solver_cube2_description, true),
29 29
  CUBE3_KOCIEMBA (CUBE_3.ordinal(), SolverKociembaCUBE3.class , R.string.solver_cube3_title, R.string.solver_cube3_description, true),
30
  //CUBE3_FAKE     (CUBE_3.ordinal(), SolverKociembaCUBE3.class , R.string.solver_cube3_title, R.string.solver_cube3_description, true),
30
  CUBE3_FAKE     (CUBE_3.ordinal(), SolverKociembaCUBE3.class , R.string.solver_cube3_title, R.string.solver_cube3_description, true),
31 31

  
32 32
  CU232          (CU_232.ordinal(), SolverTablebaseCU232.class, R.string.solver_cu232_title, R.string.solver_cu232_description, true),
33 33
  CU323          (CU_323.ordinal(), SolverTablebaseCU323.class, R.string.solver_cu323_title, R.string.solver_cu323_description, true),
src/main/java/org/distorted/solverui/ScreenSolver.java
26 26

  
27 27
import org.distorted.dialogs.RubikDialogSolverError;
28 28
import org.distorted.dialogs.RubikDialogSolverImpossible;
29
import org.distorted.dialogs.RubikDialogSolvers;
29 30
import org.distorted.helpers.TransparentImageButton;
30 31
import org.distorted.main.MainActivity;
31 32
import org.distorted.main.R;
32 33
import org.distorted.objectlib.main.ObjectControl;
33 34
import org.distorted.objectlib.main.TwistyObject;
35
import org.distorted.objectlib.metadata.ListObjects;
34 36
import org.distorted.objectlib.shape.*;
35 37
import org.distorted.solvers.SolvingList;
36 38
import org.distorted.solvers.SolvingThread;
......
257 259
        }
258 260
      else  // more than one solver - launch a choosing dialog
259 261
        {
260
        // TODO
261
        android.util.Log.e("D", len+" solvers found for object "+mObjectOrdinal);
262
        ListObjects list = ListObjects.getObject(mObjectOrdinal);
263
        String upperName = list.name();
264
        Bundle bundle = new Bundle();
265
        bundle.putString("argument", upperName );
266
        RubikDialogSolvers solv = new RubikDialogSolvers();
267
        solv.setArguments(bundle);
268
        solv.show( act.getSupportFragmentManager(), RubikDialogSolvers.getDialogTag() );
262 269
        return false;
263 270
        }
264 271
      }
src/main/res/layout/dialog_solvers_pane.xml
5 5
	android:layout_height="wrap_content"
6 6
	android:background="?mediumC"
7 7
	android:padding="8dp"
8
	android:orientation="horizontal">
8
	android:orientation="vertical">
9 9

  
10
    <ImageView
11
   	     android:id="@+id/solvers_pane_image"
12
   	     android:scaleType="fitCenter"
13
		 android:adjustViewBounds="true"
14
   		 android:layout_width="0dp"
15
   		 android:layout_height="match_parent"
16
   		 android:layout_gravity="top"
17
   		 android:layout_weight="0.5"/>
10
	<TextView
11
		android:id="@+id/solvers_pane_title"
12
		android:gravity="top|start"
13
		android:layout_width="match_parent"
14
		android:layout_height="wrap_content"
15
		android:singleLine="true"
16
		android:textStyle="bold"/>
18 17

  
19
   	<LinearLayout
20
   		android:layout_width="0dp"
21
 		android:layout_height="match_parent"
22
 		android:orientation="vertical"
23
 		android:layout_marginStart="8dp"
24
 		android:layout_weight="1.0">
18
	<TextView
19
		android:id="@+id/solvers_pane_description"
20
		android:gravity="top|start"
21
		android:layout_width="match_parent"
22
		android:layout_height="wrap_content"/>
25 23

  
26
		<TextView
27
    		android:id="@+id/solvers_pane_title"
28
    		android:gravity="top|start"
29
    		android:layout_width="match_parent"
30
    		android:layout_height="wrap_content"
31
    		android:singleLine="true"
32
    		android:textStyle="bold"/>
24
	<Button
25
		 android:id="@+id/solvers_pane_button"
26
		 android:layout_width="match_parent"
27
		 android:layout_height="wrap_content"
28
		 android:layout_gravity="bottom"
29
		 android:gravity="center"
30
		 android:backgroundTint="?veryDarkC"
31
		 android:insetTop="0dp"
32
		 android:insetBottom="0dp"
33
		 android:text="@string/use_solver"/>
33 34

  
34
        <TextView
35
    		android:id="@+id/solvers_pane_description"
36
    		android:gravity="top|start"
37
    		android:layout_width="match_parent"
38
    		android:layout_height="wrap_content"/>
39

  
40
    	<Button
41
             android:id="@+id/solvers_pane_button"
42
             android:layout_width="match_parent"
43
             android:layout_height="wrap_content"
44
             android:layout_gravity="bottom"
45
             android:gravity="center"
46
             android:backgroundTint="?veryDarkC"
47
             android:insetTop="0dp"
48
             android:insetBottom="0dp"
49
             android:text="@string/use_solver"/>
50

  
51
 	</LinearLayout>
52 35
</LinearLayout>
src/main/res/values/strings.xml
231 231
    <string name="color_violet7">violet</string>
232 232
    <string name="color_grey7">grey</string>
233 233

  
234
    <string name="solver_cube3_title" translatable="false">3x3 Cube Solver</string>
234
    <string name="solver_cube3_title" translatable="false">Kociemba Solver</string>
235 235
    <string name="solver_pduo2_title" translatable="false">Pyraminx Duo Solver</string>
236 236
    <string name="solver_pyra3_title" translatable="false">Pyraminx Solver</string>
237 237
    <string name="solver_ivy_title" translatable="false">Ivy Solver</string>

Also available in: Unified diff