@@ -69,12 +69,12 @@ public class CircularFlow extends VirtualLayout {
69
69
/**
70
70
* @hide
71
71
*/
72
- private float [] mAngles = new float [ 32 ] ;
72
+ private float [] mAngles ;
73
73
74
74
/**
75
75
* @hide
76
76
*/
77
- private int [] mRadius = new int [ 32 ] ;
77
+ private int [] mRadius ;
78
78
79
79
/**
80
80
* @hide
@@ -150,7 +150,7 @@ protected void init(AttributeSet attrs) {
150
150
mReferenceDefaultAngle = a .getFloat (attr , DEFAULT_ANGLE );
151
151
setDefaultAngle (mReferenceDefaultAngle );
152
152
} else if (attr == R .styleable .ConstraintLayout_Layout_circularflow_defaultRadius ) {
153
- mReferenceDefaultRadius = a .getInt (attr , DEFAULT_RADIUS );
153
+ mReferenceDefaultRadius = a .getDimensionPixelSize (attr , DEFAULT_RADIUS );
154
154
setDefaultRadius (mReferenceDefaultRadius );
155
155
}
156
156
}
@@ -162,9 +162,11 @@ protected void init(AttributeSet attrs) {
162
162
public void onAttachedToWindow () {
163
163
super .onAttachedToWindow ();
164
164
if (mReferenceAngles != null ) {
165
+ mAngles = new float [1 ];
165
166
setAngles (mReferenceAngles );
166
167
}
167
168
if (mReferenceRadius != null ) {
169
+ mRadius = new int [1 ];
168
170
setRadius (mReferenceRadius );
169
171
}
170
172
if (mReferenceDefaultAngle != null ) {
@@ -178,41 +180,45 @@ public void onAttachedToWindow() {
178
180
179
181
private void anchorReferences () {
180
182
mContainer = (ConstraintLayout ) getParent ();
181
- ConstraintSet c = new ConstraintSet ();
182
- c .clone (mContainer );
183
- for (int i = 0 ; i <= mCount ; i ++) {
184
- int id = mIds [i ];
185
- View view = mContainer .getViewById (id );
186
-
187
- if (view != null ) {
188
- int radius = DEFAULT_RADIUS ;
189
- float angle = DEFAULT_ANGLE ;
190
-
191
- if (i < getRadius ().length ) {
192
- radius = getRadius ()[i ];
193
- } else if (mReferenceDefaultRadius != -1 ) {
194
- mCountRadius ++;
195
- mRadius = getRadius ();
196
- mRadius [mCountRadius - 1 ] = (int ) (radius * myContext .getResources ().getDisplayMetrics ().density );
197
- radius = getRadius ()[i ];
198
- } else {
199
- Log .e ("CircularFlow" , "Added radius to view with id: " + mMap .get (view .getId ()));
183
+ for (int i = 0 ; i < mCount ; i ++) {
184
+ View view = mContainer .getViewById (mIds [i ]);
185
+ if (view == null ) {
186
+ continue ;
187
+ }
188
+ int radius = DEFAULT_RADIUS ;
189
+ float angle = DEFAULT_ANGLE ;
190
+
191
+ if (mRadius != null && i < mRadius .length ) {
192
+ radius = mRadius [i ];
193
+ } else if (mReferenceDefaultRadius != null && mReferenceDefaultRadius != -1 ) {
194
+ mCountRadius ++;
195
+ if (mRadius == null ) {
196
+ mRadius = new int [1 ];
200
197
}
198
+ mRadius = getRadius ();
199
+ mRadius [mCountRadius - 1 ] = radius ;
200
+ } else {
201
+ Log .e ("CircularFlow" , "Added radius to view with id: " + mMap .get (view .getId ()));
202
+ }
201
203
202
- if (i < getAngles ().length ) {
203
- angle = getAngles ()[i ];
204
- } else if (mReferenceDefaultAngle != -1 ) {
205
- mCountAngle ++;
206
- mAngles = getAngles ();
207
- mAngles [mCountAngle - 1 ] = angle ;
208
- angle = getAngles ()[i ];
209
- } else {
210
- Log .e ("CircularFlow" , "Added angle to view with id: " + mMap .get (view .getId ()));
204
+ if (mAngles != null && i < mAngles .length ) {
205
+ angle = mAngles [i ];
206
+ } else if (mReferenceDefaultAngle != null && mReferenceDefaultAngle != -1 ) {
207
+ mCountAngle ++;
208
+ if (mAngles == null ) {
209
+ mAngles = new float [1 ];
211
210
}
212
- c .constrainCircle (view .getId (), mViewCenter , radius , angle );
211
+ mAngles = getAngles ();
212
+ mAngles [mCountAngle - 1 ] = angle ;
213
+ } else {
214
+ Log .e ("CircularFlow" , "Added angle to view with id: " + mMap .get (view .getId ()));
213
215
}
216
+ ConstraintLayout .LayoutParams params = (ConstraintLayout .LayoutParams ) view .getLayoutParams ();
217
+ params .circleAngle = angle ;
218
+ params .circleConstraint = mViewCenter ;
219
+ params .circleRadius = radius ;
220
+ view .setLayoutParams (params );
214
221
}
215
- c .applyTo (mContainer );
216
222
applyLayoutFeatures ();
217
223
}
218
224
@@ -430,7 +436,7 @@ private void addAngle(String angleString) {
430
436
}
431
437
432
438
if (mCountAngle + 1 > mAngles .length ) {
433
- mAngles = Arrays .copyOf (mAngles , mAngles .length * 2 );
439
+ mAngles = Arrays .copyOf (mAngles , mAngles .length + 1 );
434
440
}
435
441
mAngles [mCountAngle ] = Integer .parseInt (angleString );
436
442
mCountAngle ++;
@@ -451,7 +457,7 @@ private void addRadius(String radiusString) {
451
457
}
452
458
453
459
if (mCountRadius + 1 > mRadius .length ) {
454
- mRadius = Arrays .copyOf (mRadius , mRadius .length * 2 );
460
+ mRadius = Arrays .copyOf (mRadius , mRadius .length + 1 );
455
461
}
456
462
457
463
mRadius [mCountRadius ] = (int ) (Integer .parseInt (radiusString ) * myContext .getResources ().getDisplayMetrics ().density );
0 commit comments