/** * Adding key support. up and down arrows can be used to scroll listbox or dropdownList,up and * down, use shift+up/down for faster scrolling, use alt+up/down to jump to the top or bottom. * * @exclude {@inheritDoc} */ @ControlP5.Invisible public void keyEvent(final KeyEvent theEvent) { super.keyEvent(theEvent); float x = getAbsolutePosition().x; float y = getAbsolutePosition().y; boolean b = (getWindow().mouseX > x && getWindow().mouseX < (x + _myWidth) && getWindow().mouseY > (y - getBarHeight()) && getWindow().mouseY < y + _myOriginalBackgroundHeight); if (b && isOpen()) { float step = (1.0f / (float) items.size()); if (cp5.isShiftDown()) { step *= 10; } else if (cp5.isAltDown()) { step = 1; } if (theEvent.getAction() == KeyEvent.PRESSED) { switch (theEvent.getKeyCode()) { case (PApplet.UP): _myScrollbar.setValue(PApplet.constrain(_myScrollbar.getValue() + step, 0, 1)); break; case (PApplet.DOWN): _myScrollbar.setValue(PApplet.constrain(_myScrollbar.getValue() - step, 0, 1)); break; } } } }
/** {@inheritDoc} */ @Override public ListBox setColorLabel(int theColor) { super.setColorLabel(theColor); for (int i = 0; i < items.size(); i++) { (items.get(i)).getColor().setCaptionLabel(theColor); } scroll(); return this; }
/** {@inheritDoc} */ @Override public ListBox setColorBackground(int theColor) { super.setColorBackground(theColor); for (int i = 0; i < items.size(); i++) { (items.get(i)).getColor().setBackground(theColor); } scroll(); return this; }
/** {@inheritDoc} */ @Override @ControlP5.Invisible public ListBox setColorValue(int theColor) { super.setColorValue(theColor); for (int i = 0; i < items.size(); i++) { (items.get(i)).getColor().setValueLabel(theColor); } scroll(); return this; }
/** * Sets the value for all RadioButton items according to the values of the array passed on. 0 will * turn off an item, any other value will turn it on. */ @Override public RadioButton setArrayValue(float[] theArray) { for (int i = 0; i < theArray.length; i++) { if (_myArrayValue[i] != theArray[i]) { if (theArray[i] == 0) { deactivate(i); } else { activate(i); } } } super.setArrayValue(theArray); return this; }
public AndroidAppProcess(int pid) throws IOException, NotAndroidAppProcessException { super(pid); final boolean foreground; int uid; if (SYS_SUPPORTS_SCHEDGROUPS) { Cgroup cgroup = cgroup(); ControlGroup cpuacct = cgroup.getGroup("cpuacct"); ControlGroup cpu = cgroup.getGroup("cpu"); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { if (cpu == null || cpuacct == null || !cpuacct.group.contains("pid_")) { throw new NotAndroidAppProcessException(pid); } foreground = !cpu.group.contains("bg_non_interactive"); try { uid = Integer.parseInt(cpuacct.group.split("/")[1].replace("uid_", "")); } catch (Exception e) { uid = status().getUid(); } ProcessManager.log( "name=%s, pid=%d, uid=%d, foreground=%b, cpuacct=%s, cpu=%s", name, pid, uid, foreground, cpuacct.toString(), cpu.toString()); } else { if (cpu == null || cpuacct == null || !cpu.group.contains("apps")) { throw new NotAndroidAppProcessException(pid); } foreground = !cpu.group.contains("bg_non_interactive"); try { uid = Integer.parseInt(cpuacct.group.substring(cpuacct.group.lastIndexOf("/") + 1)); } catch (Exception e) { uid = status().getUid(); } ProcessManager.log( "name=%s, pid=%d, uid=%d foreground=%b, cpuacct=%s, cpu=%s", name, pid, uid, foreground, cpuacct.toString(), cpu.toString()); } } else { // this is a really ugly way to check if the process is an application. // we could possibly check the UID name (starts with "app_" or "u<USER_ID>_a") if (name.startsWith("/") || !new File("/data/data", getPackageName()).exists()) { throw new NotAndroidAppProcessException(pid); } Stat stat = stat(); Status status = status(); // https://github.com/android/platform_system_core/blob/jb-mr1-release/libcutils/sched_policy.c#L245-256 foreground = stat.policy() == 0; // SCHED_NORMAL uid = status.getUid(); ProcessManager.log("name=%s, pid=%d, uid=%d foreground=%b", name, pid, uid, foreground); } this.foreground = foreground; this.uid = uid; }