Project

General

Profile

« Previous | Next » 

Revision 51f51f83

Added by Leszek Koltunski almost 3 years ago

Progress with RubikControl.

View differences:

src/main/java/org/distorted/control/RubikControl.java
19 19

  
20 20
package org.distorted.control;
21 21

  
22
import org.distorted.library.main.DistortedNode;
22 23
import org.distorted.library.message.EffectListener;
23 24
import org.distorted.main.RubikActivity;
25
import org.distorted.main.RubikPreRender;
26
import org.distorted.objects.TwistyObject;
24 27

  
25 28
import java.lang.ref.WeakReference;
26 29

  
27 30
///////////////////////////////////////////////////////////////////////////////////////////////////
28 31

  
29
public class RubikControl implements EffectListener, Runnable
32
public class RubikControl implements EffectListener
30 33
  {
31 34
  WeakReference<RubikActivity> mRefAct;
32
  long mWholeID, mRotateID;
33 35
  boolean mWholeReturned, mRotateReturned;
34 36

  
35
long mRetID;
37
  RubikControlWhole mWhole;
38
  RubikControlRotate mRotate;
36 39

  
37 40
///////////////////////////////////////////////////////////////////////////////////////////////////
38 41

  
39
  private void addWholeObjects()
42
  private TwistyObject getObject()
40 43
    {
41
    mWholeID = 0;
44
    RubikActivity act = mRefAct.get();
42 45

  
43
    mRetID = mWholeID;
46
    if( act!=null )
47
      {
48
      RubikPreRender pre = act.getPreRender();
49
      return pre!=null ? pre.getObject() : null;
50
      }
44 51

  
45
    Thread networkThrd = new Thread(this);
46
    networkThrd.start();
52
    return null;
47 53
    }
48 54

  
49 55
///////////////////////////////////////////////////////////////////////////////////////////////////
50 56

  
51
  private void addWholeEffects()
57
  private void addWholeObjects()
52 58
    {
59
    TwistyObject object = getObject();
60
    DistortedNode[] nodes = mWhole.getNodes();
53 61

  
62
    if( object!=null && nodes!=null )
63
      {
64
      for (DistortedNode node : nodes) object.attach(node);
65
      }
54 66
    }
55 67

  
56 68
///////////////////////////////////////////////////////////////////////////////////////////////////
57 69

  
58 70
  private void removeWholeObjects()
59 71
    {
72
    TwistyObject object = getObject();
73
    DistortedNode[] nodes = mWhole.returnNodes();
60 74

  
75
    if( object!=null && nodes!=null )
76
      {
77
      for (DistortedNode node : nodes) object.detach(node);
78
      }
61 79
    }
62 80

  
63 81
///////////////////////////////////////////////////////////////////////////////////////////////////
64 82

  
65 83
  private void addRotateObjects()
66 84
    {
67
    mRotateID = 1;
68

  
69
    mRetID = mRotateID;
70

  
71
    Thread networkThrd = new Thread(this);
72
    networkThrd.start();
73
    }
74

  
75
///////////////////////////////////////////////////////////////////////////////////////////////////
76

  
77
  private void addRotateEffects()
78
    {
85
    TwistyObject object = getObject();
86
    DistortedNode[] nodes = mRotate.getNodes();
79 87

  
88
    if( object!=null && nodes!=null )
89
      {
90
      for (DistortedNode node : nodes) object.attach(node);
91
      }
80 92
    }
81 93

  
82 94
///////////////////////////////////////////////////////////////////////////////////////////////////
83 95

  
84 96
  private void removeRotateObjects()
85 97
    {
98
    TwistyObject object = getObject();
99
    DistortedNode[] nodes = mRotate.returnNodes();
86 100

  
87
    }
88

  
89
///////////////////////////////////////////////////////////////////////////////////////////////////
90

  
91
  private void animateCubeWhole()
92
    {
93
    addWholeObjects();
94
    addWholeEffects();
101
    if( object!=null && nodes!=null )
102
      {
103
      for (DistortedNode node : nodes) object.detach(node);
104
      }
95 105
    }
96 106

  
97 107
///////////////////////////////////////////////////////////////////////////////////////////////////
......
102 112

  
103 113
    mWholeReturned = true;
104 114

  
105
    if( !mRotateReturned ) animateCubeRotate();
106
    }
107

  
108
///////////////////////////////////////////////////////////////////////////////////////////////////
109

  
110
  private void animateCubeRotate()
111
    {
112
    addRotateObjects();
113
    addRotateEffects();
115
    if( !mRotateReturned ) addRotateObjects();
114 116
    }
115 117

  
116 118
///////////////////////////////////////////////////////////////////////////////////////////////////
......
126 128
    }
127 129

  
128 130
///////////////////////////////////////////////////////////////////////////////////////////////////
129
// PUBLIC
130 131

  
131
  @Override
132
  public void run()
132
  RubikActivity getActivity()
133 133
    {
134
    android.util.Log.e("D", "running...");
135

  
136
    try
137
      {
138
      Thread.sleep(4000);
139
      }
140
    catch(InterruptedException ex)
141
      {
142
      // ignore
143
      }
134
    return mRefAct.get();
135
    }
144 136

  
145
    android.util.Log.e("D", "end running...");
137
///////////////////////////////////////////////////////////////////////////////////////////////////
138
// PUBLIC
146 139

  
147
    effectFinished(mRetID);
140
  public RubikControl()
141
    {
142
    mWhole = new RubikControlWhole(this);
143
    mRotate= new RubikControlRotate(this);
148 144
    }
149 145

  
150 146
///////////////////////////////////////////////////////////////////////////////////////////////////
151 147

  
152 148
  public void effectFinished(long effectID)
153 149
    {
154
    if( effectID==mWholeID  ) finishWhole();
155
    if( effectID==mRotateID ) finishRotate();
150
    if( effectID==mWhole.getEffectID()  ) finishWhole();
151
    if( effectID==mRotate.getEffectID() ) finishRotate();
156 152
    }
157 153

  
158 154
///////////////////////////////////////////////////////////////////////////////////////////////////
......
165 161
    mWholeReturned = false;
166 162
    mRotateReturned= false;
167 163

  
168
    animateCubeWhole();
164
    addWholeObjects();
169 165
    }
170 166

  
171 167
///////////////////////////////////////////////////////////////////////////////////////////////////
......
178 174
    mWholeReturned = true;
179 175
    mRotateReturned= false;
180 176

  
181
    animateCubeRotate();
177
    addRotateObjects();
182 178
    }
183 179
  }

Also available in: Unified diff