uitest.he
来自「维信SDK文档。源码要求为至少5个C或Java源码」· HE 代码 · 共 1,117 行 · 第 1/3 页
HE
1,117 行
class{ /* Following example demostrates usage of different UI components * introduced in Helium API. * * It also works as coding style guide, how to produce good * looking and functioning Helium code. * * Using layouts and styles you can easily re-skin your widgets * without code-changes. * * Some designlines * + Each example is isolated within one createXXX function * that follow Viewable prototype * * + Some examples have inner helper functions, for example * createTable. These functions can access local variables * declared in enclosing function, which make them very * usable in disabling redundancy. * * + Inner functions are also used to implement example-specific * action, softkey, menu, key, timer or paint -handlers, they * are named myXXXHandler. Rest use default handlers defined * in widget namespace. * * Some notes * + getStyle("default") is used where empty style is wanted, * actually getStyle() returns empty style with any name that * isn't found from stylesheet, but using always same name is * of course better. */ const int CMD_OPEN = 1; const int CMD_BACK = 2; const int CMD_CANCEL = 3; const int CMD_SELECT = 4; const int CMD_SHOOT = 5; //action ids used in examples should be bigger than this const int MAX_CMD_ID = 5; MenuItem BACK = new MenuItem(CMD_BACK, "Back"); MenuItem CANCEL = new MenuItem(CMD_CANCEL, "Cancel"); typedef Shell Viewable(); //------------------------------------------------------------------------ //------------------------------------------------------------------------ //------------------------------------------------------------------------ //Example implementations, all of which implements Viewable-type Shell createBubble() { setBubble(getImage("bubble_genie.png"), "Genie in a bubble"); return null; } //----- Shell createCamera() { //Picture object, used as holder for Image to be taken //Image inside it will be set by camera when it's taken //Picture pic = new Picture(getStyle("default"), null); //List of parameters for camera, you can set different //formats, sizes etc, however support for these parameters //differ between phones so we'll just set the image format //to be PNG /*List options = new List(); options.add("encoding=png"); if (!captureImage(pic, options, myCameraHandler)) { setBubble(null, "Your mobile doesn't support camera."); } void myCameraHandler(Picture pic, int action) { if (action == ITEM_CHANGED) { setBubble(pic.getImage(), "Your image"); } else if (action == ITEM_CANCEL) { setBubble(null, "Image capture canceled!"); } } return null;*/ List encTypes = new List() .add("encoding=jpeg&width=32&height=24") .add("encoding=jpeg") .add("encoding=jpg&width=32&height=24") .add("encoding=jpg") .add("encoding=png"); Flow flow = new Flow(getStyle("default")); Camera cam = new Camera(getStyle("default")); // Camera cam is global component cam.setFlags(VISIBLE|LINEFEED); cam.setPreferredSize(-100,-100); flow.add(cam); Shell shell = new Shell(flow); shell.setSoftKeyHandler(handleSoft); shell.setActionHandler(handleAction); MenuItem SHOOT = new MenuItem(CMD_SHOOT, "Shoot"); //menuitem for taking the picture void handleAction(Shell shell, Component source, int action) { if (action == CMD_SHOOT) { setBubble(getImage(cam.capture(encTypes)), "this is a camera"); // picture is taken from camera and sent to createPreview funktion for previewing popShell(shell); cam.close(); cam = null; } else if (action == CMD_BACK) { popShell(shell); cam.close(); cam = null; } } MenuItem handleSoft(final Shell shell, final Component focused, final int key) { if (key == SOFTKEY_MIDDLE) { return SHOOT; } else if (key == SOFTKEY_BACK) { return BACK; } else { return null; } } return shell; } //----- //TODO, simpler example Shell createCanvas() { Canvas clock = new Canvas(getStyle("clock"), painter); clock.setPreferredSize(-100, -100); Calendar time = new Calendar(); Timer timer = null; void resetTimer(int interval) { if (timer != null) { timer.cancel(); timer = null; } if (interval > 0) { time.setMillis(currentTimeMillis()); timer = schedule(1000, interval, timerCall); } } void painter(Component c, Graphics g, Style style, int width, int height) { int h = time[HOUR]; int m = time[MINUTE]; int s = time[SECOND]; int cx = width/2; int cy = height/2; { int angle = 6*s - 90; int dx = cx+(60*cos(angle))/MATH_SCALE; int dy = cy+(60*sin(angle))/MATH_SCALE; g.setColor(0x606060); drawHand(g, cx, cy, angle, 6, 60); } g.drawImage(style.image(0), cx, cy, HCENTER|VCENTER); } void drawHand(Graphics g, int cx, int cy, int angle, int base, int height) { int dx = cx+(height*cos(angle))/MATH_SCALE; int dy = cy+(height*sin(angle))/MATH_SCALE; int ax = cx+(base*cos(angle-90))/MATH_SCALE; int ay = cy+(base*sin(angle-90))/MATH_SCALE; int bx = cx+(base*cos(angle+90))/MATH_SCALE; int by = cy+(base*sin(angle+90))/MATH_SCALE; g.fillTriangle(ax, ay, bx, by, dx, dy); } void timerCall(Timer timer) { time.setMillis(currentTimeMillis()); clock.repaint(false); flushScreen(false); } resetTimer(1000); return getViewShell(clock); } //----- Shell createForm() { Style style = getStyle("form.choice.item"); Flow content = new Flow(getStyle("default")); content.setPreferredSize(-100, -100); content.add(createHeaderText("Form example")); //create some text components and choices addText("I tend to"); addChoice(["-Select-", "Hack", "Thunk", "Fix", "Solve problems", "Just hang around"]); addText("at work, when my buddies are playing"); addChoice(["-Select-", "Golf", "WOW", "Football", "Paintball", "Fool"]); addText("which makes me"); Choice selector = addChoice(["-Select-", "A dull", "Happy", "Sad", "Rich"]); //create text-input that can contain any characters //and is not visible by default Input input = new Input(getStyle("form.input"), "Edit title", "boy", ANY); input.setPreferredWidth(-100); input.setFlags(LINEFEED); content.add(input); final Shell shell = new Shell(content); shell.setStyle(getStyle("maxi")); shell.setActionHandler(myActionHandler); void myActionHandler(final Shell shell, final Component source, final int action) { if (action == CMD_BACK) { popShell(shell); } else if (action == ITEM_CHANGED) { if (Choice(source) == selector) { if (selector.getSelected() == 0) { input.setFlags(LINEFEED); } else { input.setFlags(VISIBLE|LINEFEED|FOCUSABLE); } //component was hidden/revealed, redraw and //calculate dimension again input.repaint(true); flushScreen(false); } } } Text addText(String st) { Text text = new Text(getStyle("form.label"), st); text.setPreferredWidth(-100); text.setFlags(VISIBLE|LINEFEED); content.add(text); return text; } Choice addChoice(Value items) { List elements = new List(); foreach (Value item : items) { Label label = new Label(style, String(item)); label.setFlags(VISIBLE|FOCUSABLE|LINEFEED); elements.add(label); } Choice choice = new Choice(getStyle("form.choice.display"), getStyle("form.choice.list")); choice.setChoices(elements, 0); choice.setFlags(VISIBLE|FOCUSABLE|LINEFEED); choice.setPreferredWidth(-100); content.add(choice); return choice; } return shell; } //----- Shell createInput() { final String STORE = "input.text"; final int CMD_CHANGE = MAX_CMD_ID+1; Flow content = new Flow(getStyle("default")); content.setFlags(VISIBLE|FOCUSABLE|LINEFEED); content.setPreferredSize(-100, -100); content.add(createHeaderText("Contents of following Input-field is stored into you phone's flash memory and it will be here when you re-open this view")); Store store = getStore(); String text = store.has(STORE)? String(store.getValue(STORE)) : "Example content"; Input input = new Input(getStyle("input"), "Your text", text, ANY); input.setFlags(VISIBLE|FOCUSABLE|LINEFEED); input.setPreferredWidth(-100); content.add(input); final Shell shell = new Shell(content); shell.setStyle(getStyle("maxi")); shell.setSoftKeyHandler(mySoftKeyHandler); shell.setActionHandler(myActionHandler); //Softkey handler is called whenever shell is being painted again, framework //asks for softkey button labels (MenuItem instances) for phone's OK and BACK -keys MenuItem mySoftKeyHandler(final Shell shell, final Component focused, final int key) { if (key == SOFTKEY_BACK) { return BACK; } else if (key == SOFTKEY_MIDDLE) { return new MenuItem(CMD_CHANGE, "Change"); } return null; } //Action handler is called for widget/shell whenever event is fired, event like //menu-item-select, softkeys are clicked, item is focused, item contents are changed, //etc void myActionHandler(final Shell shell, final Component source, final int action) { if (action == CMD_BACK) { //remove current shell (view) from display stack (= return to last view) popShell(shell); } else if (action == CMD_CHANGE) { //soft key was clicked, start editing mode //Note that Input-component captures phone's joystick-fire event and starts //editing mode itself input.edit(); } else if (action == ITEM_CHANGED && source == Component(input)) { //editing done, save new text to store getStore().put(STORE, Value(input.getText())); } } return shell; } //----- Shell createList() { final int CMD_SHOW = MAX_CMD_ID+1; //from imdb.com //stars-rating was rounded as CLCD 1.0 (and Helium) //doesn't support floating point numbers Value data = [ ["name" => "Flight of Fury",
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?