Exemplo n.º 1
0
 public static Color byName(String name) throws Exception {
   for (Color color : values()) {
     if (color.getName().equals(name)) {
       return color;
     }
   }
   throw new Exception("Unknown color name " + name + '.');
 }
Exemplo n.º 2
0
 @Override
 public String toString() {
   return "Node [key="
       + key
       + ", color="
       + color.getName()
       + ", p.key="
       + p.key
       + ", right.key="
       + right.key
       + ", left.key="
       + left.key
       + ", size="
       + size
       + "]";
 }
Exemplo n.º 3
0
        public boolean onChildClick(
            ExpandableListView parent, View v, int groupPosition, int childPosition, long id) {

          click = true;

          // get the group header
          Brightness brightInfo = brightList.get(groupPosition);
          // get the child info
          Color colorInfo = brightInfo.getColorList().get(childPosition);

          txt.setText("/" + brightInfo.getName() + "/" + colorInfo.getName());
          int index =
              parent.getFlatListPosition(
                  ExpandableListView.getPackedPositionForChild(groupPosition, childPosition));
          parent.setItemChecked(index, true);

          return false;
        }
Exemplo n.º 4
0
        public void afterTextChanged(Editable s) {
          String inputTxt = txt.getText().toString().toLowerCase();

          String brightString = inputTxt;
          String colorString = "";
          int groupPosition;
          int count = 0;
          int countB = 0;

          expandAll();

          // fel, kolla en bool typ, om checkText = true;
          System.out.println("click: " + click);
          if (click == true) {
            click = false;
            return;
          }

          // check if the text contains a /
          if (inputTxt.contains("/") && inputTxt.length() > 1) {
            String[] separated = inputTxt.split("/");

            if (inputTxt.startsWith("/")) {
              brightString = separated[1];
              colorString = "";

              if (separated.length > 2) {
                brightString = separated[1];
                colorString = separated[2];
              }
            } else {
              if (separated.length > 1) {
                brightString = separated[0];
                colorString = separated[1];
              } else {
                brightString = separated[0];
                colorString = "";
              }
            }
          }

          // System.out.println("brString: " + brightString);
          // System.out.println("colString: " + colorString);

          // check the header
          for (int i = 0; i < listAdapter.getGroupCount(); i++) {

            // get the group header
            Brightness headerInfo = brightList.get(i);

            if (headerInfo.getName().startsWith(brightString)) {

              groupPosition = brightList.indexOf(headerInfo);
              txt.setBackgroundColor(android.graphics.Color.WHITE);
              countB = 1;

              // loop through the children
              for (int j = 0; j < headerInfo.getColorList().size(); j++) {

                // get the child info
                Color childInfo = headerInfo.getColorList().get(j);

                if (childInfo.getName().startsWith(colorString) && colorString.length() > 0) {

                  // expand other groups
                  collapseAll(groupPosition);
                  count = 1;

                  // check if the whole word is typed
                  if (colorString.contains(childInfo.getName())) {

                    index =
                        myList.getFlatListPosition(
                            ExpandableListView.getPackedPositionForChild(i, j));
                    myList.setItemChecked(index, true);
                  }
                }
              }

              if (count == 0 && colorString.length() > 0) {
                txt.setBackgroundColor(android.graphics.Color.RED);
                myList.setItemChecked(index, false);
                return;
              }
            }
            if (countB == 0 && brightString.length() > 0) {
              if (brightString.startsWith("/"))
                txt.setBackgroundColor(android.graphics.Color.WHITE);
              else txt.setBackgroundColor(android.graphics.Color.RED);
            }
          }
        }