18
18
import android .content .Context ;
19
19
import android .content .res .TypedArray ;
20
20
import android .util .AttributeSet ;
21
+ import android .util .Log ;
21
22
import android .util .Pair ;
22
23
24
+ import androidx .constraintlayout .motion .widget .Debug ;
23
25
import androidx .constraintlayout .widget .ConstraintLayout ;
24
26
import androidx .constraintlayout .widget .ConstraintSet ;
25
27
import androidx .constraintlayout .widget .Guideline ;
81
83
*/
82
84
public class Grid extends VirtualLayout {
83
85
private static final String TAG = "Grid" ;
84
- private static final String VERTICAL = "vertical" ;
85
- private static final String HORIZONTAL = "horizontal" ;
86
+ public static final int VERTICAL = 1 ;
87
+ public static final int HORIZONTAL = 0 ;
86
88
private final int mMaxRows = 50 ; // maximum number of rows can be specified.
87
89
private final int mMaxColumns = 50 ; // maximum number of columns can be specified.
88
90
private final ConstraintSet mConstraintSet = new ConstraintSet ();
@@ -131,17 +133,17 @@ public class Grid extends VirtualLayout {
131
133
/**
132
134
* Horizontal gaps in Dp
133
135
*/
134
- private int mHorizontalGaps ;
136
+ private float mHorizontalGaps ;
135
137
136
138
/**
137
139
* Vertical gaps in Dp
138
140
*/
139
- private int mVerticalGaps ;
141
+ private float mVerticalGaps ;
140
142
141
143
/**
142
144
* orientation of the view arrangement - vertical or horizontal
143
145
*/
144
- private String mOrientation ;
146
+ private int mOrientation = 0 ; // default value is horizontal
145
147
146
148
/**
147
149
* Indicates what is the next available position to place an widget
@@ -207,11 +209,11 @@ protected void init(AttributeSet attrs) {
207
209
} else if (attr == R .styleable .Grid_grid_columnWeights ) {
208
210
mStrColumnWeights = a .getString (attr );
209
211
} else if (attr == R .styleable .Grid_grid_orientation ) {
210
- mOrientation = a .getString (attr );
212
+ mOrientation = a .getInt (attr , 0 );
211
213
} else if (attr == R .styleable .Grid_grid_horizontalGaps ) {
212
- mHorizontalGaps = a .getInteger (attr , 0 );
214
+ mHorizontalGaps = a .getDimension (attr , 0 );
213
215
} else if (attr == R .styleable .Grid_grid_verticalGaps ) {
214
- mVerticalGaps = a .getInteger (attr , 0 );
216
+ mVerticalGaps = a .getDimension (attr , 0 );
215
217
} else if (attr == R .styleable .Grid_grid_validateInputs ) {
216
218
// @TODO handle validation
217
219
mValidateInputs = a .getBoolean (attr , false );
@@ -220,7 +222,7 @@ protected void init(AttributeSet attrs) {
220
222
mUseRtl = a .getBoolean (attr , false );
221
223
}
222
224
}
223
-
225
+ Log . v ( TAG , " >>>>>>>>>>> col = " + mColumns );
224
226
initVariables ();
225
227
a .recycle ();
226
228
}
@@ -387,26 +389,26 @@ private void updateGuideLinePosition(Guideline guideline, float position) {
387
389
* @param column column position to place the view
388
390
*/
389
391
private void connectView (int viewId , int row , int column , int rowSpan , int columnSpan ,
390
- int horizontalGaps , int verticalGaps ) {
392
+ float horizontalGaps , float verticalGaps ) {
391
393
392
394
// @TODO handle RTL
393
395
// connect Start of the view
394
396
mConstraintSet .connect (viewId , ConstraintSet .START ,
395
- mVerticalGuideLines [column ].getId (), ConstraintSet .END , horizontalGaps );
397
+ mVerticalGuideLines [column ].getId (), ConstraintSet .END ,( int ) horizontalGaps );
396
398
397
399
// connect Top of the view
398
400
mConstraintSet .connect (viewId , ConstraintSet .TOP ,
399
- mHorizontalGuideLines [row ].getId (), ConstraintSet .BOTTOM , verticalGaps );
401
+ mHorizontalGuideLines [row ].getId (), ConstraintSet .BOTTOM , ( int ) verticalGaps );
400
402
401
403
// connect End of the view
402
404
mConstraintSet .connect (viewId , ConstraintSet .END ,
403
405
mVerticalGuideLines [column + columnSpan ].getId (),
404
- ConstraintSet .START , horizontalGaps );
406
+ ConstraintSet .START , ( int ) horizontalGaps );
405
407
406
408
// connect Bottom of the view
407
409
mConstraintSet .connect (viewId , ConstraintSet .BOTTOM ,
408
410
mHorizontalGuideLines [row + rowSpan ].getId (),
409
- ConstraintSet .TOP , verticalGaps );
411
+ ConstraintSet .TOP ,( int ) verticalGaps );
410
412
}
411
413
412
414
/**
@@ -444,7 +446,7 @@ private Pair<Integer, Integer> getPositionByIndex(int index) {
444
446
int row ;
445
447
int col ;
446
448
447
- if (mOrientation . equals ( VERTICAL ) ) {
449
+ if (mOrientation == 1 ) {
448
450
row = index % mRows ;
449
451
col = index / mRows ;
450
452
} else {
@@ -662,6 +664,7 @@ public int getColumns() {
662
664
* @return true if it succeeds otherwise false
663
665
*/
664
666
public boolean setColumns (int columns ) {
667
+ Debug .logStack (TAG , " >>>>>>>>>>>>> col " + columns , 5 );
665
668
if (columns < 2 || columns > mMaxColumns ) {
666
669
return false ;
667
670
}
@@ -682,7 +685,7 @@ public boolean setColumns(int columns) {
682
685
* get the value of orientation
683
686
* @return the value of orientation
684
687
*/
685
- public String getOrientation () {
688
+ public int getOrientation () {
686
689
return mOrientation ;
687
690
}
688
691
@@ -691,12 +694,12 @@ public String getOrientation() {
691
694
* @param orientation new orientation value
692
695
* @return true if it succeeds otherwise false
693
696
*/
694
- public boolean setOrientation (String orientation ) {
695
- if (!(orientation . equals ( HORIZONTAL ) || orientation . equals ( VERTICAL ) )) {
697
+ public boolean setOrientation (int orientation ) {
698
+ if (!(orientation == HORIZONTAL || orientation == VERTICAL )) {
696
699
return false ;
697
700
}
698
701
699
- if (mOrientation != null && mOrientation . equals ( orientation ) ) {
702
+ if (mOrientation == orientation ) {
700
703
return true ;
701
704
}
702
705
@@ -823,7 +826,7 @@ public Boolean setColumnWeights(String columnWeights) {
823
826
* get the value of horizontalGaps
824
827
* @return the value of horizontalGaps
825
828
*/
826
- public int getHorizontalGaps () {
829
+ public float getHorizontalGaps () {
827
830
return mHorizontalGaps ;
828
831
}
829
832
@@ -832,7 +835,7 @@ public int getHorizontalGaps() {
832
835
* @param horizontalGaps new horizontalGaps value
833
836
* @return true if it succeeds otherwise false
834
837
*/
835
- public boolean setHorizontalGaps (int horizontalGaps ) {
838
+ public boolean setHorizontalGaps (float horizontalGaps ) {
836
839
if (horizontalGaps < 0 ) {
837
840
return false ;
838
841
}
@@ -851,7 +854,7 @@ public boolean setHorizontalGaps(int horizontalGaps) {
851
854
* get the value of verticalGaps
852
855
* @return the value of verticalGaps
853
856
*/
854
- public int getVerticalGaps () {
857
+ public float getVerticalGaps () {
855
858
return mVerticalGaps ;
856
859
}
857
860
@@ -860,7 +863,7 @@ public int getVerticalGaps() {
860
863
* @param verticalGaps new verticalGaps value
861
864
* @return true if it succeeds otherwise false
862
865
*/
863
- public boolean setVerticalGaps (int verticalGaps ) {
866
+ public boolean setVerticalGaps (float verticalGaps ) {
864
867
if (verticalGaps < 0 ) {
865
868
return false ;
866
869
}
0 commit comments