Skip to content

Row background colors #18

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
120 changes: 116 additions & 4 deletions ColinTreeListView.java
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand All @@ -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;
Expand Down Expand Up @@ -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<String, CachedImage> iconMap = new HashMap<String, CachedImage>();

Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -822,6 +903,12 @@ 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;
}
getElement(i + 1).refreshProperties();
}
}
Expand Down Expand Up @@ -886,15 +973,20 @@ 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 = "";

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);
Expand All @@ -903,6 +995,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("");
Expand Down Expand Up @@ -1027,18 +1122,21 @@ public void TouchUp() {

@Override
public void onClick(View v) {
selected = true;
onElementClick();
}
@Override
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
Expand All @@ -1060,6 +1158,12 @@ public Element refreshProperties() {
show();

ha.Height(elementHeight);
if(selected) {
ha.BackgroundColor(elementTouchDownColor);
}
else {
ha.BackgroundColor(bgColor);
}

labelBeforeIcon.Width(elementWidthBeforeIcon);

Expand Down Expand Up @@ -1112,6 +1216,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;
Expand Down
12 changes: 8 additions & 4 deletions ColinTreeListViewElement.java
Original file line number Diff line number Diff line change
Expand Up @@ -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--------------
Expand Down Expand Up @@ -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--------------
Expand Down