82
82
public class Grid extends VirtualLayout {
83
83
private static final String TAG = "Grid" ;
84
84
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.
85
88
private final ConstraintSet mConstraintSet = new ConstraintSet ();
86
89
ConstraintLayout mContainer ;
87
90
@@ -444,15 +447,25 @@ private Pair<Integer, Integer> getNextPosition() {
444
447
}
445
448
446
449
/**
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
449
452
* @return true if it is valid else false
450
453
*/
451
454
private boolean isSpansValid (String str ) {
452
455
// TODO: check string has a valid format.
453
456
return true ;
454
457
}
455
458
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
+
456
469
/**
457
470
* parse the skips/spans in the string format into a HashMap<index, row_span, col_span>>
458
471
* 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[]
573
586
return positions ;
574
587
}
575
588
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
+
576
667
/**
577
668
* get the string value of spans
578
669
* @return the string value of spans
@@ -582,7 +673,7 @@ public String getSpans() {
582
673
}
583
674
584
675
/**
585
- * set new spans value and also invoke requestLayout
676
+ * set new spans value and also invoke invalidate
586
677
* @param spans new spans value
587
678
* @return true if it succeeds otherwise false
588
679
*/
@@ -591,7 +682,7 @@ public Boolean setSpans(String spans) {
591
682
return false ;
592
683
}
593
684
mStrSpans = spans ;
594
- requestLayout ();
685
+ invalidate ();
595
686
return true ;
596
687
}
597
688
@@ -604,7 +695,7 @@ public String getSkips() {
604
695
}
605
696
606
697
/**
607
- * set new skips value and also invoke requestLayout
698
+ * set new skips value and also invoke invalidate
608
699
* @param skips new spans value
609
700
* @return true if it succeeds otherwise false
610
701
*/
@@ -613,7 +704,53 @@ public Boolean setSkips(String skips) {
613
704
return false ;
614
705
}
615
706
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 ();
617
754
return true ;
618
755
}
619
756
}
0 commit comments