From 634e5b800a7ef1da3a2d72429374dff1c2cae598 Mon Sep 17 00:00:00 2001 From: Andrew Williams Date: Thu, 24 Nov 2022 23:34:05 -0500 Subject: [PATCH 1/2] Fix background color, Added alternate row color support --- ColinTreeListView.java | 122 ++++++++++++++++++++++++++++++++-- ColinTreeListViewElement.java | 12 ++-- 2 files changed, 126 insertions(+), 8 deletions(-) diff --git a/ColinTreeListView.java b/ColinTreeListView.java index cd11c84..c71eab6 100644 --- a/ColinTreeListView.java +++ b/ColinTreeListView.java @@ -89,7 +89,11 @@ public class ColinTreeListView extends AndroidNonvisibleComponent implements Com // Fixed a Get method bug (#11) // Added ExtraButtonImage in ColinTreeListViewElement // Removed flag deprecated from all blocks - public static final int VERSION = 11; + // VERSION 12: + // Fixed elementBackgroundColor overwrite after select. + // Added set row background color independently. + // Added support for alternate row colors + public static final int VERSION = 12; private static final String LOG_TAG = "ColinTreeListView"; @@ -106,6 +110,8 @@ public class ColinTreeListView extends AndroidNonvisibleComponent implements Com // Appearance private int elementHeight = 57; + private int elementBgColor = COLOR_WHITE; + private int elementAlternateRowColor = COLOR_LTGRAY; private int elementTouchDownColor = COLOR_DEFAULT; private int elementWidthBeforeIcon = 7; private int elementWidthAfterIcon = 5; @@ -144,6 +150,7 @@ public class ColinTreeListView extends AndroidNonvisibleComponent implements Com private boolean asyncImageLoad = false; private boolean cacheImage = false; private boolean extraButtonEnabled = false; + private boolean colorAltRows = false; private HashMap iconMap = new HashMap(); @@ -222,12 +229,23 @@ public YailList Get() { public void AddElement(YailList element) { int elementListSize = elementList.size(); if (currentListSize < elementListSize && elementListSize > 0) { + if(colorAltRows) { + if((currentListSize) % 2 == 0) + getElement(currentListSize + 1).bgColor = elementAlternateRowColor; + else + getElement(currentListSize + 1).bgColor = elementBgColor; + } getElement(currentListSize + 1) .show() .set(element); } else { final int elementIndex = currentListSize; - elementList.add(new Element(vaContainer, element) { + boolean alt = false; + if(colorAltRows) { + if((currentListSize + 1) % 2 == 0) + alt = true; + } + elementList.add(new Element(vaContainer, element, alt) { @Override public void onElementClick() { ElementClick(elementIndex); @@ -305,6 +323,12 @@ private void checkIndex(int elementIndex) throws IndexOutOfBoundsException { @SimpleFunction public void SetElement(int elementIndex, YailList element) { checkIndex(elementIndex); + if(colorAltRows) { + if((elementIndex) % 2 == 0) + getElement(elementIndex).bgColor = elementAlternateRowColor; + else + getElement(elementIndex).bgColor = elementBgColor; + } getElement(elementIndex).show().set(element); } @SimpleFunction @@ -377,6 +401,7 @@ public void ClearCache(String path) { @SimpleEvent public void ElementClick(int elementIndex) { lastClickedElement = elementIndex + 1; + toggleSelection(lastClickedElement); EventDispatcher.dispatchEvent(this, "ElementClick", elementIndex + 1); } @SimpleEvent @@ -429,6 +454,27 @@ public void ExtraButtonTouchUp(int elementIndex) { EventDispatcher.dispatchEvent(this, "ExtraButtonTouchUp", elementIndex + 1); } + @SimpleProperty(category = PropertyCategory.BEHAVIOR) + public int SelectionIndex() { + return lastClickedElement; + } + @SimpleProperty(category = PropertyCategory.BEHAVIOR) + public void SelectionIndex(int elementIndex) { + toggleSelection(elementIndex); + lastClickedElement = elementIndex; + + } + + private void toggleSelection(int elementIndex) { + checkIndex(elementIndex); + getElement(elementIndex).selected = true; + for (int i = 0; i < currentListSize; i++) { + if((i + 1) != elementIndex) + getElement(i + 1).selected = false; + } + refreshElementProperties(); + } + @SimpleProperty(category = PropertyCategory.BEHAVIOR) public int LastClickedElement() { return lastClickedElement; @@ -460,6 +506,41 @@ public void ElementHeight(int height) { refreshElementProperties(); } + @SimpleProperty(category = PropertyCategory.APPEARANCE) + public int ElementBackgroundColor() { + return elementBgColor; + } + + @SimpleProperty + @DesignerProperty(editorType = PropertyTypeConstants.PROPERTY_TYPE_COLOR, + defaultValue = DEFAULT_VALUE_COLOR_WHITE) + public void ElementBackgroundColor(int argb) { + elementBgColor = argb; + refreshElementProperties(); + } + + @SimpleProperty(category = PropertyCategory.APPEARANCE) + public boolean UseAltRowColors() { + return colorAltRows; + } + @SimpleProperty(category = PropertyCategory.APPEARANCE, description = "Use alternate row colors") + @DesignerProperty(editorType = PropertyTypeConstants.PROPERTY_TYPE_BOOLEAN, defaultValue = "False") + public void UseAltRowColors(boolean useAlt) { + colorAltRows = useAlt; + refreshElementProperties(); + } + @SimpleProperty(category = PropertyCategory.APPEARANCE) + public int AlternateRowColor() { + return elementAlternateRowColor; + } + @SimpleProperty + @DesignerProperty(editorType = PropertyTypeConstants.PROPERTY_TYPE_COLOR, + defaultValue = DEFAULT_VALUE_COLOR_LTGRAY) + public void AlternateRowColor(int argb) { + elementAlternateRowColor = argb; + refreshElementProperties(); + } + @SimpleProperty(category = PropertyCategory.APPEARANCE) public int TouchDownColor() { return elementTouchDownColor; @@ -822,6 +903,14 @@ public void UnderlineWidth(int lineWidth) { private void refreshElementProperties() { for (int i = 0; i < currentListSize; i++) { + if(colorAltRows) { + if((i + 1) % 2 == 0) + getElement(i + 1).bgColor = elementAlternateRowColor; + else + getElement(i + 1).bgColor = elementBgColor; + } else { + getElement(i + 1).bgColor = elementBgColor; + } getElement(i + 1).refreshProperties(); } } @@ -886,6 +975,7 @@ abstract class Element implements OnClickListener, OnLongClickListener, OnTouchL public final ButtonBase extraButton; public final Label labelAfterText; public final Label underline; + public boolean selected = false; private String iconValue = ""; private String extraImagePath = ""; @@ -893,8 +983,12 @@ abstract class Element implements OnClickListener, OnLongClickListener, OnTouchL private int currentSize; private boolean refreshLock = false; + public int bgColor = elementBgColor; public Element(ComponentContainer container, YailList list) { + this(container, list, false); + } + public Element(ComponentContainer container, YailList list, boolean useAlt) { this.container = container; ha = new HorizontalArrangement(container); @@ -903,6 +997,9 @@ public Element(ComponentContainer container, YailList list) { ha.getView().setOnTouchListener(this); ha.AlignVertical(ComponentConstants.GRAVITY_CENTER_VERTICAL); ha.Width(LENGTH_FILL_PARENT); + if(useAlt) + this.bgColor = elementAlternateRowColor; + ha.BackgroundColor(bgColor); labelBeforeIcon = new Label(ha); labelBeforeIcon.Text(""); @@ -1027,6 +1124,7 @@ public void TouchUp() { @Override public void onClick(View v) { + selected = true; onElementClick(); } @Override @@ -1034,11 +1132,13 @@ public boolean onLongClick(View v) { return onElementLongClick(); } private void ElementTouchDown() { - ha.BackgroundColor(elementTouchDownColor); + //ha.BackgroundColor(elementTouchDownColor); onElementTouchDown(); } private void ElementTouchUp() { - ha.BackgroundColor(0x00FFFFFF); + //ha.BackgroundColor(0x00FFFFFF); + //if(!selected) + // ha.BackgroundColor(bgColor); onElementTouchUp(); } @Override @@ -1060,6 +1160,12 @@ public Element refreshProperties() { show(); ha.Height(elementHeight); + if(selected) { + ha.BackgroundColor(elementTouchDownColor); + } + else { + ha.BackgroundColor(bgColor); + } labelBeforeIcon.Width(elementWidthBeforeIcon); @@ -1112,6 +1218,14 @@ public Element refreshProperties() { return this; } + public int getBackgroundColor() { + return bgColor; + } + public void setBackgroundColor(int argb) { + bgColor = argb; + refreshProperties(); + } + public Element setRefreshLock(boolean lock) { this.refreshLock = lock; return this; diff --git a/ColinTreeListViewElement.java b/ColinTreeListViewElement.java index 7e351a6..4e7abc8 100644 --- a/ColinTreeListViewElement.java +++ b/ColinTreeListViewElement.java @@ -95,11 +95,13 @@ public boolean UseGlobalProperties() { @SimpleProperty(category = PropertyCategory.APPEARANCE) public int ElementBackgroundColor() { - return element.ha.BackgroundColor(); + //return element.ha.BackgroundColor(); + return element.getBackgroundColor(); } @SimpleProperty(category = PropertyCategory.APPEARANCE) public void ElementBackgroundColor(int argb) { - element.ha.BackgroundColor(argb); + //element.ha.BackgroundColor(argb); + element.setBackgroundColor(argb); } //------------Properties that exists in ListView-------------- @@ -427,11 +429,13 @@ public static boolean UseGlobalProperties(ColinTreeListView listview, int elemen @SimpleFunction public static int ElementBackgroundColor(ColinTreeListView listview, int elementIndex) { - return listview.getElement(elementIndex).ha.BackgroundColor(); + //return listview.getElement(elementIndex).ha.BackgroundColor(); + return listview.getElement(elementIndex).getBackgroundColor(); } @SimpleFunction public static void ElementBackgroundColor_(ColinTreeListView listview, int elementIndex, int argb) { - listview.getElement(elementIndex).ha.BackgroundColor(argb); + //return listview.getElement(elementIndex).ha.BackgroundColor(argb); + listview.getElement(elementIndex).setBackgroundColor(argb); } //------------Properties that exists in ListView-------------- From a4a218eaeae3de415363fdb7b204c67ee2e6def5 Mon Sep 17 00:00:00 2001 From: Andrew Williams Date: Fri, 25 Nov 2022 01:37:19 -0500 Subject: [PATCH 2/2] Repair background fix --- ColinTreeListView.java | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/ColinTreeListView.java b/ColinTreeListView.java index c71eab6..59fb02c 100644 --- a/ColinTreeListView.java +++ b/ColinTreeListView.java @@ -908,9 +908,7 @@ private void refreshElementProperties() { getElement(i + 1).bgColor = elementAlternateRowColor; else getElement(i + 1).bgColor = elementBgColor; - } else { - getElement(i + 1).bgColor = elementBgColor; - } + } getElement(i + 1).refreshProperties(); } }