Project

General

Profile

« Previous | Next » 

Revision a6d3b158

Added by Leszek Koltunski over 4 years ago

Progress with Pretty Patterns.

View differences:

src/main/java/org/distorted/dialog/RubikDialogPatternView.java
73 73
    {
74 74
    DisplayMetrics metrics = act.getResources().getDisplayMetrics();
75 75
    final float scale = metrics.density;
76
    int len = categories.length;
77 76
    int margin = (int)(3*scale + 0.5f);
78 77
    LinearLayout.LayoutParams bParams = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,LinearLayout.LayoutParams.WRAP_CONTENT);
79 78
    bParams.setMargins(margin, margin, margin, margin);
80 79

  
81 80
    final RubikActivity ract = (RubikActivity)getContext();
82 81

  
83
    for(int i=0; i<len; i++)
82
    for(String category: categories)
84 83
      {
85
      final int fi = i;
86 84
      Button button = new Button(act);
87 85
      button.setLayoutParams(bParams);
88
      button.setText(categories[i]);
86
      button.setText(category);
89 87

  
90 88
      button.setOnClickListener( new View.OnClickListener()
91 89
        {
src/main/java/org/distorted/magic/RubikActivity.java
36 36
import org.distorted.scores.RubikScoresDownloader;
37 37
import org.distorted.object.RubikObjectList;
38 38
import org.distorted.uistate.RubikState;
39
import org.distorted.uistate.RubikStateAbstract;
40 39
import org.distorted.uistate.RubikStatePlay;
41 40

  
42 41
///////////////////////////////////////////////////////////////////////////////////////////////////
43 42

  
44
public class RubikActivity extends AppCompatActivity implements View.OnClickListener
43
public class RubikActivity extends AppCompatActivity
45 44
{
46 45
    private boolean mJustStarted;
47 46

  
......
114 113
      super.onDestroy();
115 114
      }
116 115

  
117
///////////////////////////////////////////////////////////////////////////////////////////////////
118

  
119
    @Override
120
    public void onClick(View v)
121
      {
122
      if( v.getId() == RubikStateAbstract.BUTTON_ID_BACK )
123
        {
124
        RubikState.goBack(this);
125
        }
126
      }
127

  
128 116
///////////////////////////////////////////////////////////////////////////////////////////////////
129 117

  
130 118
    private void savePreferences()
......
173 161

  
174 162
///////////////////////////////////////////////////////////////////////////////////////////////////
175 163
// PUBLIC API
164
///////////////////////////////////////////////////////////////////////////////////////////////////
165

  
166
    public void setCanRotate(boolean can)
167
      {
168
      RubikSurfaceView view = findViewById(R.id.rubikSurfaceView);
169
      RubikRenderer renderer = view.getRenderer();
170

  
171
      renderer.setCanRotate(can);
172
      }
173

  
176 174
///////////////////////////////////////////////////////////////////////////////////////////////////
177 175

  
178 176
    public void changeObject(int object, int size)
......
181 179
      int objectSize = obj.getSizes()[size];
182 180

  
183 181
      RubikSurfaceView view = findViewById(R.id.rubikSurfaceView);
184
      view.getRenderer().createObject(obj,objectSize);
182
      RubikRenderer renderer = view.getRenderer();
183

  
184
      if( renderer.canDrag() )
185
        {
186
        renderer.createObject(obj,objectSize);
187
        }
185 188
      }
186 189

  
187 190
///////////////////////////////////////////////////////////////////////////////////////////////////
src/main/java/org/distorted/magic/RubikRenderer.java
163 163

  
164 164
   boolean createObject(RubikObjectList object, int size)
165 165
     {
166
     if( mCanDrag && mCanRotate && (object!=mNextObject || mNextSize!=size) && size>0 )
166
     if( (object!=mNextObject || mNextSize!=size) && size>0 )
167 167
       {
168 168
       mChangeObject = true;
169 169
       mNextObject = object;
......
195 195
       }
196 196
     }
197 197

  
198
///////////////////////////////////////////////////////////////////////////////////////////////////
199

  
200
   void setCanRotate(boolean can)
201
     {
202
     mCanRotate = can;
203
     }
204

  
198 205
///////////////////////////////////////////////////////////////////////////////////////////////////
199 206

  
200 207
   boolean canRotate()
src/main/java/org/distorted/magic/RubikSurfaceView.java
162 162

  
163 163
    private void setUpDragOrRotate(float x, float y)
164 164
      {
165
      Static4D touchPoint1 = new Static4D(x, y, 0, 0);
166
      Static4D rotatedTouchPoint1= rotateVectorByInvertedQuat(touchPoint1, mQuatAccumulated);
167
      Static4D rotatedCamera= rotateVectorByInvertedQuat(CAMERA_POINT, mQuatAccumulated);
165
      boolean rota = mRenderer.canRotate();
166
      boolean drag = mRenderer.canDrag();
168 167

  
169
      if( mMovement!=null && mMovement.faceTouched(rotatedTouchPoint1,rotatedCamera) )
168
      if( !rota && drag )
170 169
        {
171
        mDragging           = false;
172
        mBeginningRotation  = mRenderer.canRotate();
170
        mDragging           = true;
171
        mBeginningRotation  = false;
173 172
        mContinuingRotation = false;
174 173
        }
175 174
      else
176 175
        {
177
        mDragging           = mRenderer.canDrag();
178
        mBeginningRotation  = false;
179
        mContinuingRotation = false;
176
        Static4D touchPoint1 = new Static4D(x, y, 0, 0);
177
        Static4D rotatedTouchPoint1= rotateVectorByInvertedQuat(touchPoint1, mQuatAccumulated);
178
        Static4D rotatedCamera= rotateVectorByInvertedQuat(CAMERA_POINT, mQuatAccumulated);
179

  
180
        if( mMovement!=null && mMovement.faceTouched(rotatedTouchPoint1,rotatedCamera) )
181
          {
182
          mDragging           = false;
183
          mBeginningRotation  = rota;
184
          mContinuingRotation = false;
185
          }
186
        else
187
          {
188
          mDragging           = drag;
189
          mBeginningRotation  = false;
190
          mContinuingRotation = false;
191
          }
180 192
        }
181 193
      }
182 194

  
src/main/java/org/distorted/uistate/RubikState.java
37 37
  private final RubikStateAbstract mClass;
38 38
  private static final RubikState[] sizes;
39 39

  
40
  private static RubikState mCurrState, mPrevState;
40
  private static RubikState mCurrState;
41 41

  
42 42
  static
43 43
    {
......
70 70
  public static void savePreferences(SharedPreferences.Editor editor)
71 71
    {
72 72
    editor.putInt("curr_state", mCurrState.ordinal() );
73
    editor.putInt("prev_state", mPrevState.ordinal() );
74 73
    }
75 74

  
76 75
///////////////////////////////////////////////////////////////////////////////////////////////////
......
78 77
  public static void restorePreferences(SharedPreferences preferences)
79 78
    {
80 79
    int currState = preferences.getInt("curr_state", RubikState.MAIN.ordinal() );
81
    int prevState = preferences.getInt("prev_state", RubikState.MAIN.ordinal() );
82

  
83 80
    mCurrState = getState(currState);
84
    mPrevState = getState(prevState);
85 81
    }
86 82

  
87 83
///////////////////////////////////////////////////////////////////////////////////////////////////
......
95 91

  
96 92
  public static void setState(RubikActivity act)
97 93
    {
98
    mCurrState.enterState(act,mPrevState);
94
    mCurrState.enterState(act);
99 95
    }
100 96

  
101 97
///////////////////////////////////////////////////////////////////////////////////////////////////
......
105 101
    if( next!=null )
106 102
      {
107 103
      if( mCurrState!=null ) mCurrState.leaveState(act);
108
      next.enterState(act,mCurrState);
109
      mPrevState = mCurrState;
104
      next.enterState(act);
110 105
      mCurrState = next;
111 106
      }
112 107
    else
......
139 134

  
140 135
///////////////////////////////////////////////////////////////////////////////////////////////////
141 136

  
142
  public void enterState(RubikActivity act, RubikState prevState)
137
  public void enterState(RubikActivity act)
143 138
    {
144
    mClass.enterState(act,prevState);
139
    mClass.enterState(act);
145 140
    }
146 141
  }
src/main/java/org/distorted/uistate/RubikStateAbstract.java
26 26

  
27 27
public abstract class RubikStateAbstract
28 28
  {
29
  public static final int BUTTON_ID_BACK  = 1023;
29
  static final int BUTTON_ID_BACK  = 1023;
30 30

  
31
  abstract void enterState(RubikActivity act, RubikState prev);
31
  abstract void enterState(RubikActivity act);
32 32
  abstract void leaveState(RubikActivity act);
33 33
  public abstract void savePreferences(SharedPreferences.Editor editor);
34 34
  public abstract void restorePreferences(SharedPreferences preferences);
src/main/java/org/distorted/uistate/RubikStateMain.java
23 23
import android.support.v4.app.FragmentManager;
24 24
import android.util.DisplayMetrics;
25 25
import android.view.LayoutInflater;
26
import android.view.View;
26 27
import android.widget.Button;
27 28
import android.widget.LinearLayout;
28 29
import android.widget.TextView;
29 30

  
30 31
import org.distorted.dialog.RubikDialogMain;
31
import org.distorted.dialog.RubikDialogPattern;
32 32
import org.distorted.magic.R;
33 33
import org.distorted.magic.RubikActivity;
34 34

  
......
53 53

  
54 54
///////////////////////////////////////////////////////////////////////////////////////////////////
55 55

  
56
  void enterState(RubikActivity act, RubikState prev)
56
  void enterState(final RubikActivity act)
57 57
    {
58 58
    FragmentManager mana = act.getSupportFragmentManager();
59 59
    RubikDialogMain diag = (RubikDialogMain) mana.findFragmentByTag(RubikDialogMain.getDialogTag());
......
64 64
      diag2.show( mana, RubikDialogMain.getDialogTag() );
65 65
      }
66 66

  
67
    if( prev==RubikState.PATT )
68
      {
69
      RubikDialogPattern diag2 = new RubikDialogPattern();
70
      diag2.show( mana, RubikDialogPattern.getDialogTag() );
71
      }
72

  
73 67
    LayoutInflater inflater = act.getLayoutInflater();
74 68

  
75 69
    // TOP ////////////////////////////
......
95 89
    buttonR.setId(BUTTON_ID_BACK);
96 90
    buttonR.setPadding(padding,0,padding,0);
97 91
    buttonR.setText(R.string.exit);
98
    buttonR.setOnClickListener(act);
92

  
93
    buttonR.setOnClickListener( new View.OnClickListener()
94
      {
95
      @Override
96
      public void onClick(View v)
97
        {
98
        RubikState.goBack(act);
99
        }
100
      });
101

  
99 102
    layoutRight.addView(buttonR);
100 103
    }
101 104

  
src/main/java/org/distorted/uistate/RubikStatePattern.java
20 20
package org.distorted.uistate;
21 21

  
22 22
import android.content.SharedPreferences;
23
import android.support.v4.app.FragmentManager;
23 24
import android.util.DisplayMetrics;
24 25
import android.view.LayoutInflater;
26
import android.view.View;
25 27
import android.widget.Button;
26 28
import android.widget.LinearLayout;
27 29
import android.widget.TextView;
28 30

  
31
import org.distorted.dialog.RubikDialogPattern;
29 32
import org.distorted.magic.R;
30 33
import org.distorted.magic.RubikActivity;
31 34

  
......
46 49

  
47 50
  void leaveState(RubikActivity act)
48 51
    {
49

  
52
    act.setCanRotate(true);
50 53
    }
51 54

  
52 55
///////////////////////////////////////////////////////////////////////////////////////////////////
53 56

  
54
  void enterState(RubikActivity act, RubikState prev)
57
  void enterState(final RubikActivity act)
55 58
    {
59
    act.setCanRotate(false);
60

  
56 61
    LayoutInflater inflater = act.getLayoutInflater();
57 62

  
58 63
    // TOP ////////////////////////////
......
78 83
    button.setId(BUTTON_ID_BACK);
79 84
    button.setPadding(padding,0,padding,0);
80 85
    button.setText(R.string.back);
81
    button.setOnClickListener(act);
86

  
87
    button.setOnClickListener( new View.OnClickListener()
88
      {
89
      @Override
90
      public void onClick(View v)
91
        {
92
        RubikState.goBack(act);
93

  
94
        FragmentManager mana = act.getSupportFragmentManager();
95
        RubikDialogPattern diag = new RubikDialogPattern();
96
        diag.show( mana, RubikDialogPattern.getDialogTag() );
97
        }
98
      });
99

  
82 100
    layoutRight.addView(button);
83 101
    }
84 102

  
src/main/java/org/distorted/uistate/RubikStatePlay.java
65 65

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

  
68
  void enterState(final RubikActivity act, RubikState prev)
68
  void enterState(final RubikActivity act)
69 69
    {
70 70
    LayoutInflater inflater = act.getLayoutInflater();
71 71

  
......
141 141
    mBackButton.setId(BUTTON_ID_BACK);
142 142
    mBackButton.setPadding(padding,0,padding,0);
143 143
    mBackButton.setText(R.string.back);
144
    mBackButton.setOnClickListener(act);
144

  
145
    mBackButton.setOnClickListener( new View.OnClickListener()
146
      {
147
      @Override
148
      public void onClick(View v)
149
        {
150
        RubikState.goBack(act);
151
        }
152
      });
145 153
    }
146 154

  
147 155
///////////////////////////////////////////////////////////////////////////////////////////////////
src/main/java/org/distorted/uistate/RubikStateSolving.java
22 22
import android.content.SharedPreferences;
23 23
import android.util.DisplayMetrics;
24 24
import android.view.LayoutInflater;
25
import android.view.View;
25 26
import android.widget.Button;
26 27
import android.widget.LinearLayout;
27 28
import android.widget.TextView;
......
60 61

  
61 62
///////////////////////////////////////////////////////////////////////////////////////////////////
62 63

  
63
  void enterState(RubikActivity act, RubikState prev)
64
  void enterState(final RubikActivity act)
64 65
    {
65 66
    LayoutInflater inflater = act.getLayoutInflater();
66 67

  
......
87 88
    mBack.setId(BUTTON_ID_BACK);
88 89
    mBack.setPadding(padding,0,padding,0);
89 90
    mBack.setText(R.string.back);
90
    mBack.setOnClickListener(act);
91

  
92
    mBack.setOnClickListener( new View.OnClickListener()
93
      {
94
      @Override
95
      public void onClick(View v)
96
        {
97
        RubikState.goBack(act);
98
        }
99
      });
100

  
91 101
    layoutRight.addView(mBack);
92 102
    }
93 103

  

Also available in: Unified diff