Skip to content
This repository was archived by the owner on Dec 27, 2024. It is now read-only.

Improvement to CircularFlow #200

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -69,12 +69,12 @@ public class CircularFlow extends VirtualLayout {
/**
* @hide
*/
private float[] mAngles = new float[32];
private float[] mAngles;

/**
* @hide
*/
private int[] mRadius = new int[32];
private int[] mRadius;

/**
* @hide
Expand Down Expand Up @@ -150,7 +150,7 @@ protected void init(AttributeSet attrs) {
mReferenceDefaultAngle = a.getFloat(attr, DEFAULT_ANGLE);
setDefaultAngle(mReferenceDefaultAngle);
} else if (attr == R.styleable.ConstraintLayout_Layout_circularflow_defaultRadius) {
mReferenceDefaultRadius = a.getInt(attr, DEFAULT_RADIUS);
mReferenceDefaultRadius = a.getDimensionPixelSize(attr, DEFAULT_RADIUS);
setDefaultRadius(mReferenceDefaultRadius);
}
}
Expand All @@ -162,9 +162,11 @@ protected void init(AttributeSet attrs) {
public void onAttachedToWindow() {
super.onAttachedToWindow();
if (mReferenceAngles != null) {
mAngles = new float[1];
setAngles(mReferenceAngles);
}
if (mReferenceRadius != null) {
mRadius = new int[1];
setRadius(mReferenceRadius);
}
if (mReferenceDefaultAngle != null) {
Expand All @@ -178,41 +180,45 @@ public void onAttachedToWindow() {

private void anchorReferences() {
mContainer = (ConstraintLayout) getParent();
ConstraintSet c = new ConstraintSet();
c.clone(mContainer);
for (int i = 0; i <= mCount; i++) {
int id = mIds[i];
View view = mContainer.getViewById(id);

if (view != null) {
int radius = DEFAULT_RADIUS;
float angle = DEFAULT_ANGLE;

if (i < getRadius().length) {
radius = getRadius()[i];
} else if (mReferenceDefaultRadius != -1) {
mCountRadius++;
mRadius = getRadius();
mRadius[mCountRadius - 1] = (int) (radius * myContext.getResources().getDisplayMetrics().density);
radius = getRadius()[i];
} else {
Log.e("CircularFlow", "Added radius to view with id: " + mMap.get(view.getId()));
for (int i = 0; i < mCount; i++) {
View view = mContainer.getViewById(mIds[i]);
if (view == null) {
continue;
}
int radius = DEFAULT_RADIUS;
float angle = DEFAULT_ANGLE;

if (mRadius != null && i < mRadius.length) {
radius = mRadius[i];
} else if (mReferenceDefaultRadius != null && mReferenceDefaultRadius != -1) {
mCountRadius++;
if (mRadius == null) {
mRadius = new int[1];
}
mRadius = getRadius();
mRadius[mCountRadius - 1] = radius;
} else {
Log.e("CircularFlow", "Added radius to view with id: " + mMap.get(view.getId()));
}

if (i < getAngles().length) {
angle = getAngles()[i];
} else if (mReferenceDefaultAngle != -1) {
mCountAngle++;
mAngles = getAngles();
mAngles[mCountAngle - 1] = angle;
angle = getAngles()[i];
} else {
Log.e("CircularFlow", "Added angle to view with id: " + mMap.get(view.getId()));
if (mAngles != null && i < mAngles.length) {
angle = mAngles[i];
} else if (mReferenceDefaultAngle != null && mReferenceDefaultAngle != -1) {
mCountAngle++;
if (mAngles == null) {
mAngles = new float[1];
}
c.constrainCircle(view.getId(), mViewCenter, radius, angle);
mAngles = getAngles();
mAngles[mCountAngle - 1] = angle;
} else {
Log.e("CircularFlow", "Added angle to view with id: " + mMap.get(view.getId()));
}
ConstraintLayout.LayoutParams params = (ConstraintLayout.LayoutParams) view.getLayoutParams();
params.circleAngle = angle;
params.circleConstraint = mViewCenter;
params.circleRadius = radius;
view.setLayoutParams(params);
}
c.applyTo(mContainer);
applyLayoutFeatures();
}

Expand Down Expand Up @@ -430,7 +436,7 @@ private void addAngle(String angleString) {
}

if (mCountAngle + 1 > mAngles.length) {
mAngles = Arrays.copyOf(mAngles, mAngles.length * 2);
mAngles = Arrays.copyOf(mAngles, mAngles.length + 1);
}
mAngles[mCountAngle] = Integer.parseInt(angleString);
mCountAngle++;
Expand All @@ -451,7 +457,7 @@ private void addRadius(String radiusString) {
}

if (mCountRadius + 1 > mRadius.length) {
mRadius = Arrays.copyOf(mRadius, mRadius.length * 2);
mRadius = Arrays.copyOf(mRadius, mRadius.length + 1);
}

mRadius[mCountRadius] = (int) (Integer.parseInt(radiusString) * myContext.getResources().getDisplayMetrics().density);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@
<attr name="circularflow_angles" format="string"/>
<attr name="circularflow_viewCenter" format="reference"/>
<attr name="circularflow_defaultAngle" format="float"/>
<attr name="circularflow_defaultRadius" format="integer"/>
<attr name="circularflow_defaultRadius" format="dimension"/>


<!-- TODO allows to use a drawable as horizontal separator between elements -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,10 @@
android:id="@+id/circularFlow"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:circularflow_angles="0,40,80,120"
app:circularflow_radiusInDP="90,100,110,120"
app:circularflow_defaultRadius="110dp"
app:circularflow_defaultAngle="45"
app:circularflow_radiusInDP="110, 150, 170, 190"
app:circularflow_angles="10, 40, 80, 135"
app:circularflow_viewCenter="@+id/view1"
app:constraint_referenced_ids="view2,view3,view4,view5" />
</androidx.constraintlayout.widget.ConstraintLayout>
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@
android:id="@+id/circularFlow"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:circularflow_defaultRadius="140"
app:circularflow_defaultRadius="140dp"
app:circularflow_angles="0,0,15,30,45,60,75,90,105,120,135,150,165,180,195,210,225,240,255,270,285,300,315,330,345"
app:circularflow_radiusInDP="116"
app:circularflow_viewCenter="@id/earth"
Expand Down