Skip to content

Commit cf00fa7

Browse files
authored
Merge pull request #30 from BrandonTsai/support_visibility
Support visibility property.
2 parents 860b881 + 4c97828 commit cf00fa7

File tree

3 files changed

+56
-0
lines changed

3 files changed

+56
-0
lines changed

json2view/src/androidTest/java/com/avocarrot/json2view/TestViewPropertiesCase.java

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,30 @@ public void testDummyView() {
4343
assertNotNull("Cannot create dynamic View", view);
4444
}
4545

46+
/* test set visibility */
47+
public void testVisibility() {
48+
View view = DynamicView.createView(
49+
context,
50+
dummyJsonObj
51+
.addProperty(new DynamicPropertyJsonBuilder().setName(NAME.VISIBILITY).setType(TYPE.STRING).setValue("gone").build())
52+
.build());
53+
assertEquals(view.getVisibility(), View.GONE);
54+
55+
view = DynamicView.createView(
56+
context,
57+
dummyJsonObj
58+
.addProperty(new DynamicPropertyJsonBuilder().setName(NAME.VISIBILITY).setType(TYPE.STRING).setValue("visible").build())
59+
.build());
60+
assertEquals(view.getVisibility(), View.VISIBLE);
61+
62+
view = DynamicView.createView(
63+
context,
64+
dummyJsonObj
65+
.addProperty(new DynamicPropertyJsonBuilder().setName(NAME.VISIBILITY).setType(TYPE.STRING).setValue("invisible").build())
66+
.build());
67+
assertEquals(view.getVisibility(), View.INVISIBLE);
68+
}
69+
4670
/* test set padding as integer */
4771
public void testPaddingInteger() {
4872
int padding = 10;

json2view/src/main/java/com/avocarrot/json2view/DynamicHelper.java

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,10 @@ public static String applyStyleProperties(View view, List<DynamicProperty> prope
168168
applyFunction(view, dynProp);
169169
}
170170
break;
171+
case VISIBILITY:{
172+
applyVisibility(view, dynProp);
173+
}
174+
break;
171175
}
172176
}
173177
return id;
@@ -563,6 +567,33 @@ public static void applyScaleY(View view, DynamicProperty property) {
563567
}
564568
}
565569

570+
/**
571+
* apply visibility in view
572+
*/
573+
private static void applyVisibility(View view, DynamicProperty property) {
574+
if (view != null) {
575+
switch (property.type) {
576+
case STRING: {
577+
switch (property.getValueString()){
578+
case "gone":{
579+
view.setVisibility(View.GONE);
580+
}
581+
break;
582+
case "visible":{
583+
view.setVisibility(View.VISIBLE);
584+
}
585+
break;
586+
case "invisible":{
587+
view.setVisibility(View.INVISIBLE);
588+
}
589+
break;
590+
}
591+
}
592+
break;
593+
}
594+
}
595+
}
596+
566597
/*** TextView Properties ***/
567598

568599
/**

json2view/src/main/java/com/avocarrot/json2view/DynamicProperty.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ public enum NAME {
6767
SCALEY,
6868
MINWIDTH,
6969
MINHEIGTH,
70+
VISIBILITY,
7071
/* textView */
7172
TEXT,
7273
TEXTCOLOR,

0 commit comments

Comments
 (0)