Project

General

Profile

« Previous | Next » 

Revision d78e2f1d

Added by Leszek Koltunski 3 days ago

make it possible to see touched cubit and face.

View differences:

src/main/java/org/distorted/phasedsolver/SolverActivity.java
40 40
  private InitAssets mAsset;
41 41
  private SharedPreferences mPreferences;
42 42
  private SolverLowerPane mLowerPane;
43
  private TextView mTextMoves, mTextStickers;
43
  private TextView mTextView;
44 44
  private SolvedObject mObject;
45
  private String mMoves;
46
  private int mNumMoves;
47
  private String mStickers;
48
  private int mNumStickers;
49
  private int mCurrSolver;
45
  private String mText;
46
  private int mCurrSolver, mCurrMode;
50 47
  private PhasedSolverAbstract mSolver;
51 48
  private long mTime;
52 49

  
......
62 59
    SolverSurfaceView view = findViewById(R.id.solverView);
63 60
    OSInterface os = view.getInterface();
64 61
    mAsset = new InitAssets(null, null, os);
65
    mTextMoves = findViewById(R.id.solverMoves);
66
    mTextStickers = findViewById(R.id.solverStickers);
67
    mMoves = "";
68
    mNumMoves = 0;
69
    mStickers = "";
70
    mNumStickers = 0;
71
    Spinner objectSpinner = findViewById(R.id.solverSpinner);
72
    objectSpinner.setOnItemSelectedListener(this);
62
    mTextView = findViewById(R.id.solverTextView);
63
    mText = "";
73 64

  
74 65
    mCurrSolver = 0;
66
    Spinner objectSpinner = findViewById(R.id.solverSpinner);
67
    objectSpinner.setOnItemSelectedListener(this);
75 68
    String[] solverNames = createSolverNames();
76 69
    ArrayAdapter<String> objAdapter = new ArrayAdapter<>(this, android.R.layout.simple_spinner_item, solverNames);
77 70
    objAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
78 71
    objectSpinner.setAdapter(objAdapter);
79 72

  
80
    String[] phaseNames = createSolver();
73
    mCurrMode = 0;
74
    Spinner modeSpinner = findViewById(R.id.solverMode);
75
    modeSpinner.setOnItemSelectedListener(this);
76
    String[] solverMode = { "MOVE", "CUBIT" };
77
    ArrayAdapter<String> modeAdapter = new ArrayAdapter<>(this, android.R.layout.simple_spinner_item, solverMode);
78
    modeAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
79
    modeSpinner.setAdapter(modeAdapter);
81 80

  
81
    String[] phaseNames = createSolver();
82 82
    mLowerPane = new SolverLowerPane(this,phaseNames);
83 83
    }
84 84

  
......
133 133
      int ordinal = getObjectOrdinal();
134 134
      ObjectControl control = getControl();
135 135
      control.changeObject(ordinal, MODE_NORM, mAsset);
136
      resetTexts();
137
      }
138

  
139
    if( parent.getId()==R.id.solverMode && mCurrMode!=pos )
140
      {
141
      mCurrMode = pos;
142
      resetTexts();
143
      SolverSurfaceView sv = findViewById(R.id.solverView);
144
      sv.switchMode();
136 145
      }
137 146
    }
138 147

  
......
267 276

  
268 277
  private void resetTexts()
269 278
    {
270
    mNumMoves = 0;
271
    mMoves = "";
272
    mTextMoves.setText(mMoves);
273
    mNumStickers = 0;
274
    mStickers = "";
275
    mTextStickers.setText(mStickers);
279
    mText = "";
280
    mTextView.setText(mText);
276 281
    }
277 282

  
278 283
///////////////////////////////////////////////////////////////////////////////////////////////////
......
299 304

  
300 305
  void addSticker(int cubit, int face)
301 306
    {
302
    mStickers += ("("+cubit+" "+face+") ");
303
    mNumStickers++;
304

  
305
    if( mNumStickers>6 )
307
    if( mCurrMode==1 )
306 308
      {
307
      int space = mStickers.indexOf(')');
308
      mStickers = mStickers.substring(space+1);
309
      mNumStickers--;
310
      }
309
      mText += ("("+cubit+" "+face+") ");
311 310

  
312
    runOnUiThread(new Runnable()
313
      {
314
      @Override
315
      public void run() { mTextStickers.setText(mStickers); }
316
      });
311
      while( mText.length()>32 )
312
        {
313
        int space = mText.indexOf(')');
314
        mText = mText.substring(space+1);
315
        }
316

  
317
      runOnUiThread(new Runnable()
318
        {
319
        @Override public void run() { mTextView.setText(mText); }
320
        });
321
      }
317 322
    }
318 323

  
319 324
///////////////////////////////////////////////////////////////////////////////////////////////////
320 325

  
321 326
  void addMove(int axis, int row, int angle)
322 327
    {
323
    int move = mObject.findMove(axis,row,angle);
324
    mMoves += (" "+move);
325
    mNumMoves++;
326

  
327
    if( mNumMoves>10 )
328
    if( mCurrMode==0 )
328 329
      {
329
      int space = mMoves.indexOf(' ');
330
      mMoves = mMoves.substring(space+1);
331
      mNumMoves--;
332
      }
330
      int move = mObject.findMove(axis,row,angle);
331
      mText += (" " + move);
333 332

  
334
    runOnUiThread(new Runnable()
335
      {
336
      @Override
337
      public void run() { mTextMoves.setText(mMoves); }
338
      });
333
      while( mText.length()>28 )
334
        {
335
        int space = mText.indexOf(' ');
336
        mText = mText.substring(space+1);
337
        }
338

  
339
      runOnUiThread(new Runnable()
340
        {
341
        @Override public void run() { mTextView.setText(mText); }
342
        });
343
      }
339 344
    }
340 345
}
src/main/java/org/distorted/phasedsolver/SolverSurfaceView.java
9 9

  
10 10
package org.distorted.phasedsolver;
11 11

  
12
import static org.distorted.objectlib.main.ObjectControl.MODE_REPLACE;
12 13
import static org.distorted.objectlib.main.ObjectControl.MODE_ROTATE;
13 14

  
14 15
import android.app.ActivityManager;
......
29 30
    private ObjectControl mObjectController;
30 31
    private OSInterface mInterface;
31 32
    private SolverRenderer mRenderer;
32
    private int mScreenWidth;
33 33
    private boolean mCreated;
34
    private int mMode;
34 35

  
35 36
///////////////////////////////////////////////////////////////////////////////////////////////////
36 37

  
37 38
    void setScreenSize(int width, int height)
38 39
      {
39
      mScreenWidth = width;
40 40
      mObjectController.setScreenSizeAndScaling(width,height, Math.min(width,height) );
41 41

  
42 42
      if( !mCreated )
......
50 50

  
51 51
///////////////////////////////////////////////////////////////////////////////////////////////////
52 52

  
53
    int getScreenWidth()
54
      {
55
      return mScreenWidth;
56
      }
57

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

  
60
    ObjectControl getObjectControl()
61
      {
62
      return mObjectController;
63
      }
64

  
65
///////////////////////////////////////////////////////////////////////////////////////////////////
66

  
67
    OSInterface getInterface()
68
      {
69
      return mInterface;
70
      }
71

  
72
///////////////////////////////////////////////////////////////////////////////////////////////////
73

  
74
    SolverRenderer getRenderer()
75
      {
76
      return mRenderer;
77
      }
53
    ObjectControl getObjectControl() { return mObjectController; }
54
    OSInterface getInterface() { return mInterface; }
55
    void switchMode() { mMode = (mMode==MODE_REPLACE) ? MODE_ROTATE : MODE_REPLACE; }
78 56

  
79 57
///////////////////////////////////////////////////////////////////////////////////////////////////
80 58

  
......
83 61
      super(context,attrs);
84 62

  
85 63
      mCreated = false;
64
      mMode = MODE_ROTATE;
86 65

  
87 66
      if(!isInEditMode())
88 67
        {
......
124 103
    public boolean onTouchEvent(MotionEvent event)
125 104
      {
126 105
      mInterface.setMotionEvent(event);
127
      return mObjectController.onTouchEvent(MODE_ROTATE);
106
      return mObjectController.onTouchEvent(mMode);
128 107
      }
129 108
}
130 109

  
src/main/res/layout/mainlayout.xml
46 46
            android:id="@+id/solverSolve"
47 47
            android:layout_width="0dp"
48 48
            android:layout_height="match_parent"
49
            android:layout_weight="0.9"
49
            android:layout_weight="0.8"
50 50
            android:gravity="center_vertical|center"
51 51
            android:text="@string/solve"
52 52
            android:onClick="Solve"
......
59 59
            android:layout_weight="1.0"/>
60 60
    </LinearLayout>
61 61

  
62
    <TextView
63
        android:id="@+id/solverMoves"
62
    <LinearLayout
64 63
        android:layout_below="@id/upperBar"
65 64
        android:layout_width="match_parent"
66
        android:layout_height="50dp"
67
        android:singleLine="true"
68
        android:background="@color/white"
69
        android:textColor="@color/black"
70
        android:layout_marginStart="3dp"
71
        android:layout_marginEnd="3dp"
72
        android:layout_marginTop="3dp"
73
        android:layout_marginBottom="5dp"
74
        android:textAppearance="?android:attr/textAppearanceLarge"
75
        android:gravity="center_vertical|start"/>
76

  
77
    <TextView
78
        android:id="@+id/solverStickers"
79
        android:layout_below="@id/solverMoves"
80
        android:layout_width="match_parent"
81
        android:layout_height="50dp"
82
        android:singleLine="true"
83
        android:background="@color/white"
84
        android:textColor="@color/black"
85
        android:layout_marginStart="3dp"
86
        android:layout_marginEnd="3dp"
87
        android:layout_marginTop="3dp"
88
        android:layout_marginBottom="5dp"
89
        android:textAppearance="?android:attr/textAppearanceLarge"
90
        android:gravity="center_vertical|start"/>
65
        android:layout_height="60dp"
66
        android:gravity="center"
67
        android:orientation="horizontal"
68
        android:background="@android:color/transparent">
69

  
70
        <TextView
71
            android:id="@+id/solverTextView"
72
            android:layout_width="0dp"
73
            android:layout_height="match_parent"
74
            android:layout_weight="2.6"
75
            android:singleLine="true"
76
            android:background="@color/white"
77
            android:textColor="@color/black"
78
            android:layout_marginStart="3dp"
79
            android:layout_marginEnd="3dp"
80
            android:layout_marginTop="3dp"
81
            android:layout_marginBottom="5dp"
82
            android:textAppearance="?android:attr/textAppearanceLarge"
83
            android:gravity="center_vertical|start"/>
84

  
85
        <Spinner
86
            android:id="@+id/solverMode"
87
            android:layout_width="0dp"
88
            android:layout_height="match_parent"
89
            android:layout_weight="1.0"/>
90

  
91
    </LinearLayout>
91 92

  
92 93
    <LinearLayout
93 94
        android:id="@+id/phaseBar"

Also available in: Unified diff