Project

General

Profile

« Previous | Next » 

Revision e9397ae9

Added by Leszek Koltunski about 1 year ago

Progress with the generic PlayActivity.

View differences:

src/main/java/org/distorted/dialogs/RubikDialogNewRecord.java
18 18
import android.widget.TextView;
19 19

  
20 20
import org.distorted.main.R;
21
import org.distorted.main_old.RubikActivity;
22 21
import org.distorted.external.RubikScores;
23
import org.distorted.screens.ScreenList;
22
import org.distorted.playui.PlayActivity;
24 23

  
25 24
///////////////////////////////////////////////////////////////////////////////////////////////////
26 25

  
......
36 35

  
37 36
  public void positiveAction()
38 37
    {
39
    RubikActivity act = (RubikActivity)getActivity();
40 38
    RubikScores scores = RubikScores.getInstance();
41 39
    String name = scores.getName();
42 40
    Bundle bundle = new Bundle();
43
    ScreenList.switchScreen(act, ScreenList.PLAY);
41
    PlayActivity act = (PlayActivity)getActivity();
44 42

  
45
    if( name.length()>0 )
43
    if( act!=null )
46 44
      {
47
      bundle.putString("argument", "true");
48
      RubikDialogScores scoresDiag = new RubikDialogScores();
49
      scoresDiag.setArguments(bundle);
50
      scoresDiag.show(act.getSupportFragmentManager(), null);
51
      }
52
    else
53
      {
54
      bundle.putString("argument", name );
55
      RubikDialogSetName nameDiag = new RubikDialogSetName();
56
      nameDiag.setArguments(bundle);
57
      nameDiag.show(act.getSupportFragmentManager(), null);
45
      if(name.length()>0)
46
        {
47
        bundle.putString("argument", "true");
48
        RubikDialogScores scoresDiag = new RubikDialogScores();
49
        scoresDiag.setArguments(bundle);
50
        scoresDiag.show(act.getSupportFragmentManager(), null);
51
        }
52
      else
53
        {
54
        bundle.putString("argument", name);
55
        RubikDialogSetName nameDiag = new RubikDialogSetName();
56
        nameDiag.setArguments(bundle);
57
        nameDiag.show(act.getSupportFragmentManager(), null);
58
        }
59

  
60
      act.finish();
58 61
      }
59 62
    }
60 63

  
......
62 65

  
63 66
  public void negativeAction()
64 67
    {
65
    RubikActivity act = (RubikActivity)getActivity();
66
    ScreenList.switchScreen(act, ScreenList.PLAY);
68
    PlayActivity act = (PlayActivity)getActivity();
69
    if( act!=null ) act.finish();
67 70
    }
68 71

  
69 72
///////////////////////////////////////////////////////////////////////////////////////////////////
src/main/java/org/distorted/playui/PlayActivity.java
59 59
    private boolean mObjectLocal;
60 60
    private int mObjectOrdinal;
61 61
    private boolean mModeFree;
62
    private boolean mJustStarted;
62 63
    private FirebaseAnalytics mFirebaseAnalytics;
63 64

  
64 65
///////////////////////////////////////////////////////////////////////////////////////////////////
......
71 72
      setTheme(R.style.MaterialThemeNoActionBar);
72 73
      setContentView(R.layout.play);
73 74

  
75
      mJustStarted = true;
74 76
      mFirebaseAnalytics = FirebaseAnalytics.getInstance(this);
75 77

  
76 78
      Bundle b = getIntent().getExtras();
......
211 213
      super.onResume();
212 214
      DistortedLibrary.onResume(ACTIVITY_NUMBER);
213 215
      PlayView view = findViewById(R.id.playView);
216
      ObjectControl control = view.getObjectControl();
214 217
      view.onResume();
215 218

  
216 219
      ScreenList.switchScreen(this, mModeFree ? ScreenList.FREE : ScreenList.SCRA );
217

  
218 220
      SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this);
219 221
      restorePreferences(preferences);
220 222
      restoreMoves(preferences);
221 223

  
224
      mJustStarted = false;
225

  
222 226
      if( mObjectName.length()>0 )
223 227
        {
224
        changeIfDifferent(mObjectName,mObjectLocal,mObjectOrdinal,view.getObjectControl());
228
        changeIfDifferent(mObjectName,mObjectLocal,mObjectOrdinal,control);
225 229
        }
226 230

  
227 231
      if( !mModeFree )
228 232
        {
229
        android.util.Log.e("D", "scrambles: "+mNumScrambles);
230
        ObjectControl control = getControl();
231 233
        control.scrambleObject(mNumScrambles);
232 234
        }
233 235
      }
......
280 282
      ScreenList.getScreen(i).getScreenClass().restorePreferences(preferences);
281 283
      }
282 284

  
283
    ScreenList.restorePreferences(preferences);
285
    if( !mJustStarted ) ScreenList.restorePreferences(preferences);
284 286
    }
285 287

  
286 288
///////////////////////////////////////////////////////////////////////////////////////////////////
src/main/java/org/distorted/playui/PlayLibInterface.java
202 202
        @Override
203 203
        public void run()
204 204
          {
205
          ScreenScrambling screen = (ScreenScrambling)ScreenList.SCRA.getScreenClass();
206
          screen.setReady();
205
          ScreenList.switchScreen(act,ScreenList.READ);
207 206
          ObjectControl control = act.getControl();
208 207
          control.unblockEverything();
209 208
          }
......
244 243

  
245 244
  public void onBeginRotation()
246 245
    {
247
    if( ScreenList.getCurrentScreen()==ScreenList.SCRA )
246
    if( ScreenList.getCurrentScreen()==ScreenList.READ )
248 247
      {
249 248
      ScreenSolving solving = (ScreenSolving) ScreenList.SOLV.getScreenClass();
250 249
      solving.resetElapsed();
251 250
      PlayActivity act = mAct.get();
251
      ScreenList.switchScreen( act,ScreenList.SOLV );
252 252

  
253
      /*
253 254
      act.runOnUiThread(new Runnable()
254 255
        {
255 256
        @Override
256 257
        public void run()
257 258
          {
258
          ScreenList.switchScreen( act,ScreenList.SOLV );
259

  
259 260
          }
260 261
        });
262

  
263
       */
261 264
      }
262 265
    }
263 266

  
src/main/java/org/distorted/playui/ScreenList.java
10 10
package org.distorted.playui;
11 11

  
12 12
import static org.distorted.objectlib.main.ObjectControl.MODE_DRAG;
13
import static org.distorted.objectlib.main.ObjectControl.MODE_NOTHING;
13 14
import static org.distorted.objectlib.main.ObjectControl.MODE_ROTATE;
14 15

  
15 16
import android.content.SharedPreferences;
......
19 20
public enum ScreenList
20 21
  {
21 22
  FREE ( null , MODE_ROTATE , new ScreenFree()       ),
22
  SCRA ( null , MODE_ROTATE , new ScreenScrambling() ),
23
  SCRA ( null , MODE_NOTHING, new ScreenScrambling() ),
24
  READ ( null , MODE_ROTATE , new ScreenReady()      ),
23 25
  SOLV ( null , MODE_ROTATE , new ScreenSolving()    ),
24 26
  DONE ( null , MODE_DRAG   , new ScreenDone()       ),
25 27
  ;
src/main/java/org/distorted/playui/ScreenReady.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.playui;
11

  
12
import android.content.SharedPreferences;
13
import android.util.TypedValue;
14
import android.view.LayoutInflater;
15
import android.view.View;
16
import android.widget.LinearLayout;
17
import android.widget.TextView;
18

  
19
import org.distorted.helpers.TransparentImageButton;
20
import org.distorted.main.R;
21

  
22
///////////////////////////////////////////////////////////////////////////////////////////////////
23

  
24
public class ScreenReady extends ScreenAbstract
25
  {
26
  private TransparentImageButton mBackButton;
27

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

  
30
  void leaveScreen(PlayActivity act)
31
    {
32

  
33
    }
34

  
35
///////////////////////////////////////////////////////////////////////////////////////////////////
36

  
37
  void enterScreen(final PlayActivity act)
38
    {
39
    float width = act.getScreenWidthInPixels();
40
    float titleSize = width*PlayActivity.TITLE_TEXT_SIZE;
41
    LayoutInflater inflater = act.getLayoutInflater();
42

  
43
    // TOP ////////////////////////////
44
    LinearLayout layoutTop = act.findViewById(R.id.upperBar);
45
    layoutTop.removeAllViews();
46
    TextView label = (TextView)inflater.inflate(R.layout.upper_text, null);
47
    label.setTextSize(TypedValue.COMPLEX_UNIT_PX, titleSize);
48
    label.setText(R.string.ready);
49
    layoutTop.addView(label);
50

  
51
    // BOT ////////////////////////////
52
    LinearLayout layoutBot = act.findViewById(R.id.lowerBar);
53
    layoutBot.removeAllViews();
54

  
55
    LinearLayout.LayoutParams paramsL = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,LinearLayout.LayoutParams.MATCH_PARENT,1);
56
    LinearLayout.LayoutParams paramsR = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,LinearLayout.LayoutParams.MATCH_PARENT,2);
57

  
58
    LinearLayout layoutLeft = new LinearLayout(act);
59
    layoutLeft.setLayoutParams(paramsL);
60
    LinearLayout layoutRight = new LinearLayout(act);
61
    layoutRight.setLayoutParams(paramsR);
62

  
63
    setupBackButton(act);
64

  
65
    layoutRight.addView(mBackButton);
66
    layoutBot.addView(layoutLeft);
67
    layoutBot.addView(layoutRight);
68
    }
69

  
70
///////////////////////////////////////////////////////////////////////////////////////////////////
71

  
72
  private void setupBackButton(final PlayActivity act)
73
    {
74
    LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,LinearLayout.LayoutParams.MATCH_PARENT,1.0f);
75
    mBackButton = new TransparentImageButton(act,R.drawable.ui_back,params);
76

  
77
    mBackButton.setOnClickListener( new View.OnClickListener()
78
      {
79
      @Override
80
      public void onClick(View v)
81
        {
82
        ScreenList.goBack(act);
83
        }
84
      });
85
    }
86

  
87
///////////////////////////////////////////////////////////////////////////////////////////////////
88

  
89
  public void savePreferences(SharedPreferences.Editor editor)
90
    {
91

  
92
    }
93

  
94
///////////////////////////////////////////////////////////////////////////////////////////////////
95

  
96
  public void restorePreferences(SharedPreferences preferences)
97
    {
98

  
99
    }
100
  }
src/main/java/org/distorted/playui/ScreenScrambling.java
10 10
package org.distorted.playui;
11 11

  
12 12
import android.content.SharedPreferences;
13
import android.util.TypedValue;
14
import android.view.LayoutInflater;
15 13
import android.view.View;
16 14
import android.widget.LinearLayout;
17
import android.widget.TextView;
18 15

  
19 16
import org.distorted.helpers.TransparentImageButton;
20 17
import org.distorted.main.R;
......
24 21
public class ScreenScrambling extends ScreenAbstract
25 22
  {
26 23
  private TransparentImageButton mBackButton;
27
  private TextView mLabel;
28 24

  
29 25
///////////////////////////////////////////////////////////////////////////////////////////////////
30 26

  
......
37 33

  
38 34
  void enterScreen(final PlayActivity act)
39 35
    {
40
    float width = act.getScreenWidthInPixels();
41
    float titleSize = width*PlayActivity.TITLE_TEXT_SIZE;
42
    LayoutInflater inflater = act.getLayoutInflater();
43

  
44 36
    // TOP ////////////////////////////
45 37
    LinearLayout layoutTop = act.findViewById(R.id.upperBar);
46 38
    layoutTop.removeAllViews();
47
    mLabel = (TextView)inflater.inflate(R.layout.upper_text, null);
48
    mLabel.setTextSize(TypedValue.COMPLEX_UNIT_PX, titleSize);
49
    layoutTop.addView(mLabel);
50 39

  
51 40
    // BOT ////////////////////////////
52 41
    LinearLayout layoutBot = act.findViewById(R.id.lowerBar);
......
67 56
    layoutBot.addView(layoutRight);
68 57
    }
69 58

  
70
///////////////////////////////////////////////////////////////////////////////////////////////////
71

  
72
  void setReady()
73
    {
74
    mLabel.setText(R.string.ready);
75
    }
76

  
77 59
///////////////////////////////////////////////////////////////////////////////////////////////////
78 60

  
79 61
  private void setupBackButton(final PlayActivity act)

Also available in: Unified diff