/** * Copyright (c) 2012-2013 Nokia Corporation. All rights reserved. * Nokia and Nokia Connecting People are registered trademarks of Nokia Corporation. * Oracle and Java are trademarks or registered trademarks of Oracle and/or its * affiliates. Other product and company names mentioned herein may be trademarks * or trade names of their respective owners. * See LICENSE.TXT for license information. */ package com.nokia.example.explonoid.menu; import com.nokia.example.explonoid.effects.Slideable; import javax.microedition.lcdui.Graphics; import javax.microedition.lcdui.Image; /** * Displays the info screen. */ public class InfoScreen extends Menu implements Slideable { public static final boolean HW_BACK_KEY_EXISTS; public static final int ITEM_COUNT; public static final int LINK = 0; public static final int BACK = 1; public final int OUT_CX; public final int IN_CX; private int x; private int y; private int height; private int cornerY; private Image info; static { HW_BACK_KEY_EXISTS = System.getProperty("com.nokia.keyboard.type").equalsIgnoreCase("OnekeyBack"); ITEM_COUNT = HW_BACK_KEY_EXISTS ? 1 : 2; } public InfoScreen(int cornerX, int cornerY, int width, int height, Listener l, double scaling) { super(ITEM_COUNT, l); this.height = height; this.cornerY = cornerY; IN_CX = cornerX + width / 2; OUT_CX = IN_CX + width; info = loadImage("/info_text.png", 1, scaling); x = OUT_CX; y = cornerY + (int) (height * 0.8); MenuItem item = new MenuItem(loadSprite("/link.png", 2, scaling)); setItem(LINK, item); item.setCenter(x, y); if (!HW_BACK_KEY_EXISTS) { y += item.getHeight(); item = new MenuItem(loadSprite("/back.png", 2, scaling)); setItem(BACK, item); item.setCenter(x, y); selectItem(BACK); } } /** * Render the information and menu items */ public void paint(Graphics g) { super.paint(g); g.drawImage(info, x, cornerY + height / 2, Graphics.VCENTER | Graphics.HCENTER); } /** * Move view inwards */ public boolean slideIn() { int distance = x - IN_CX; distance *= 0.8; x = IN_CX + distance; positionMenuItems(); return distance != 0; } /** * Move view outwards */ public boolean slideOut() { int distance = x - OUT_CX; distance *= 0.8; x = OUT_CX + distance; positionMenuItems(); return distance != 0; } /** * Lay out menu items */ public void positionMenuItems() { MenuItem item = getItem(0); item.setHorizontalCenter(x); if (!HW_BACK_KEY_EXISTS) { item = getItem(1); item.setHorizontalCenter(x); } } }