8282public class Grid extends VirtualLayout {
8383 private static final String TAG = "Grid" ;
8484 private static final String VERTICAL = "vertical" ;
85+ private static final String HORIZONTAL = "horizontal" ;
86+ private final int mMaxRows = 50 ; // maximum number of rows can be specified.
87+ private final int mMaxColumns = 50 ; // maximum number of columns can be specified.
8588 private final ConstraintSet mConstraintSet = new ConstraintSet ();
8689 ConstraintLayout mContainer ;
8790
@@ -444,15 +447,25 @@ private Pair<Integer, Integer> getNextPosition() {
444447 }
445448
446449 /**
447- * Check if the value of the skips is valid
448- * @param str skips in string format
450+ * Check if the value of the spans/ skips is valid
451+ * @param str spans/ skips in string format
449452 * @return true if it is valid else false
450453 */
451454 private boolean isSpansValid (String str ) {
452455 // TODO: check string has a valid format.
453456 return true ;
454457 }
455458
459+ /**
460+ * Check if the value of the rowWeights or columnsWeights is valid
461+ * @param str rowWeights/columnsWeights in string format
462+ * @return true if it is valid else false
463+ */
464+ private boolean isWeightsValid (String str ) {
465+ // TODO: check string has a valid format.
466+ return true ;
467+ }
468+
456469 /**
457470 * parse the skips/spans in the string format into a HashMap<index, row_span, col_span>>
458471 * the format of the input string is index:row_spanxcol_span.
@@ -573,6 +586,84 @@ private float[] getLinePositions(float min, float max, int numPositions, float[]
573586 return positions ;
574587 }
575588
589+ /**
590+ * get the value of rows
591+ * @return the value of rows
592+ */
593+ public int getRows () {
594+ return mRows ;
595+ }
596+
597+ /**
598+ * set new rows value and also invoke initVariables and invalidate
599+ * @param rows new rows value
600+ * @return true if it succeeds otherwise false
601+ */
602+ public boolean setRows (int rows ) {
603+ if (rows < 2 || rows > mMaxRows ) {
604+ return false ;
605+ }
606+
607+ mRows = rows ;
608+ initVariables ();
609+ invalidate ();
610+ return true ;
611+ }
612+
613+ /**
614+ * get the value of columns
615+ * @return the value of columns
616+ */
617+ public int getColumns () {
618+ return mColumns ;
619+ }
620+
621+ /**
622+ * set new columns value and also invoke initVariables and invalidate
623+ * @param columns new rows value
624+ * @return true if it succeeds otherwise false
625+ */
626+ public boolean setColumns (int columns ) {
627+ if (columns < 2 || columns > mMaxColumns ) {
628+ return false ;
629+ }
630+
631+ mColumns = columns ;
632+ initVariables ();
633+ invalidate ();
634+ return true ;
635+ }
636+
637+
638+ /**
639+ * get the value of orientation
640+ * @return the value of orientation
641+ */
642+ public String getOrientation () {
643+ return mOrientation ;
644+ }
645+
646+ /**
647+ * set new orientation value and also invoke invalidate
648+ * @param orientation new orientation value
649+ * @return true if it succeeds otherwise false
650+ */
651+ public boolean setOrientation (String orientation ) {
652+ if (!(orientation .equals (HORIZONTAL ) || orientation .equals (VERTICAL ))) {
653+ return false ;
654+ }
655+
656+ if (orientation .equals (mOrientation )) {
657+ return true ;
658+ }
659+
660+ mOrientation = orientation ;
661+ invalidate ();
662+ return true ;
663+
664+ }
665+
666+
576667 /**
577668 * get the string value of spans
578669 * @return the string value of spans
@@ -582,7 +673,7 @@ public String getSpans() {
582673 }
583674
584675 /**
585- * set new spans value and also invoke requestLayout
676+ * set new spans value and also invoke invalidate
586677 * @param spans new spans value
587678 * @return true if it succeeds otherwise false
588679 */
@@ -591,7 +682,7 @@ public Boolean setSpans(String spans) {
591682 return false ;
592683 }
593684 mStrSpans = spans ;
594- requestLayout ();
685+ invalidate ();
595686 return true ;
596687 }
597688
@@ -604,7 +695,7 @@ public String getSkips() {
604695 }
605696
606697 /**
607- * set new skips value and also invoke requestLayout
698+ * set new skips value and also invoke invalidate
608699 * @param skips new spans value
609700 * @return true if it succeeds otherwise false
610701 */
@@ -613,7 +704,53 @@ public Boolean setSkips(String skips) {
613704 return false ;
614705 }
615706 mStrSkips = skips ;
616- requestLayout ();
707+ invalidate ();
708+ return true ;
709+ }
710+
711+ /**
712+ * get the string value of rowWeights
713+ * @return the string value of rowWeights
714+ */
715+ public String getRowWeights () {
716+ return mStrRowWeights ;
717+ }
718+
719+ /**
720+ * set new rowWeights value and also invoke invalidate
721+ * @param rowWeights new rowWeights value
722+ * @return rue if it succeeds otherwise false
723+ */
724+ public Boolean setRowWeights (String rowWeights ) {
725+ if (!isWeightsValid (rowWeights )) {
726+ return false ;
727+ }
728+
729+ mStrRowWeights = rowWeights ;
730+ invalidate ();
731+ return true ;
732+ }
733+
734+ /**
735+ * get the string value of columnWeights
736+ * @return the string value of columnWeights
737+ */
738+ public String getColumnWeights () {
739+ return mStrColumnWeights ;
740+ }
741+
742+ /**
743+ * set new columnWeights value and also invoke invalidate
744+ * @param columnWeights new columnWeights value
745+ * @return rue if it succeeds otherwise false
746+ */
747+ public Boolean setColumnWeights (String columnWeights ) {
748+ if (!isWeightsValid (columnWeights )) {
749+ return false ;
750+ }
751+
752+ mStrColumnWeights = columnWeights ;
753+ invalidate ();
617754 return true ;
618755 }
619756}
0 commit comments