28
28
import android .support .drag2d .lib .MaterialVelocity ;
29
29
import android .support .drag2d .lib .Velocity2D ;
30
30
import android .util .AttributeSet ;
31
+ import android .util .Log ;
32
+
31
33
import android .view .MotionEvent ;
32
34
import android .view .VelocityTracker ;
33
35
import android .view .View ;
@@ -84,6 +86,9 @@ public class DragCardActivity extends AppCompatActivity {
84
86
@ Override
85
87
protected void onCreate (Bundle savedInstanceState ) {
86
88
super .onCreate (savedInstanceState );
89
+ int orientation = getResources ().getConfiguration ().orientation ;
90
+ Log .v ("MAIN" ,"orientation = " +orientation );
91
+
87
92
requestWindowFeature (Window .FEATURE_ACTION_BAR );
88
93
LinearLayout topCol = new LinearLayout (this );
89
94
LinearLayout row = new LinearLayout (this );
@@ -92,7 +97,8 @@ protected void onCreate(Bundle savedInstanceState) {
92
97
col .setOrientation (LinearLayout .VERTICAL );
93
98
ScrollView scrollView = new ScrollView (this );
94
99
CardMover m = new CardMover (this );
95
- AppCompatButton []buttons = new AppCompatButton [sEasingNames .length ];
100
+ AppCompatButton [] buttons = new AppCompatButton [sEasingNames .length ];
101
+
96
102
for (int i = 0 ; i < sEasingNames .length ; i ++) {
97
103
AppCompatButton b = new AppCompatButton (this );
98
104
buttons [i ] = b ;
@@ -108,7 +114,8 @@ protected void onCreate(Bundle savedInstanceState) {
108
114
for (int j = 0 ; j < buttons .length ; j ++) {
109
115
Drawable draw = buttons [j ].getBackground ();
110
116
draw = draw .mutate ();
111
- draw .setTint ((mode == j )?0xff328855 :0xffAA88AA );
117
+ draw .setTint ((mode == j ) ? 0xff328855 : 0xffAA88AA );
118
+
112
119
buttons [j ].setBackgroundDrawable (draw );
113
120
}
114
121
@@ -179,6 +186,9 @@ static class CardMover extends View {
179
186
Paint mCardPaint = new Paint ();
180
187
MaterialVelocity .Easing easing = null ;
181
188
float [] points = new float [10000 ];
189
+ float [] mSegTime1 = new float [4 ];
190
+ float [] mSegTime2 = new float [4 ];
191
+
182
192
Paint paint = new Paint ();
183
193
Paint paintDot = new Paint ();
184
194
private float mDuration ;
@@ -230,6 +240,29 @@ protected void onDraw(Canvas canvas) {
230
240
startAnimationTime = 0 ;
231
241
}
232
242
canvas .drawLines (points , paint );
243
+
244
+
245
+ for (int i = 0 ; i < mSegTime1 .length ; i ++) {
246
+ float t = mSegTime1 [i ];
247
+ if (Float .isNaN (t )) {
248
+ break ;
249
+ }
250
+ int mark = velocity2D .getPointOffsetX (points .length , t / mDuration );
251
+ float x = points [mark ], y = points [mark + 1 ];
252
+ canvas .drawRoundRect (x - 10 , y - 10 , x + 10 , y + 10 , 20 , 20 , paint );
253
+ }
254
+
255
+ for (int i = 0 ; i < mSegTime2 .length ; i ++) {
256
+ float t = mSegTime2 [i ];
257
+ if (Float .isNaN (t )) {
258
+ break ;
259
+ }
260
+
261
+ int mark = velocity2D .getPointOffsetY (points .length , t / mDuration );
262
+ float x = points [mark ], y = points [mark + 1 ];
263
+ canvas .drawRoundRect (x - 10 , y - 10 , x + 10 , y + 10 , 20 , 20 , paint );
264
+ }
265
+
233
266
int xPos = velocity2D .getPointOffsetX (points .length , time / mDuration );
234
267
int yPos = velocity2D .getPointOffsetY (points .length , time / mDuration );
235
268
float x = points [xPos ], y = points [xPos + 1 ];
@@ -242,8 +275,10 @@ protected void onDraw(Canvas canvas) {
242
275
243
276
canvas .drawRoundRect (mCardX , mCardY , mCardX + getWidth () / 2 , getHeight () + mCardY , rounding , rounding , mCardPaint );
244
277
int scale = 128 ;
245
- int ballX = mCardX + getWidth () / 4 - scale /2 ;
246
- int ballY = mCardY + getHeight () / 2 - scale /2 ;
278
+
279
+ int ballX = mCardX + getWidth () / 4 - scale / 2 ;
280
+ int ballY = mCardY + getHeight () / 2 - scale / 2 ;
281
+
247
282
ball .setBounds (ballX , ballY , ballX + scale , ballY + scale );
248
283
ball .setTint (Color .CYAN );
249
284
ball .draw (canvas );
@@ -294,6 +329,7 @@ public boolean onTouchEvent(MotionEvent event) {
294
329
duration , maxV , maxA ,
295
330
easing );
296
331
velocity2D .getCurves (points , getWidth (), getHeight (), mGraphMode );
332
+ velocity2D .getCurvesSegments (mSegTime1 , mSegTime2 );
297
333
mDuration = velocity2D .getDuration ();
298
334
invalidate ();
299
335
break ;
0 commit comments