Note: To ensure backwards compatibility with earlier Series 40 devices, the Orientation API code is commented out. To enable Orientation API support, uncomment the Orientation API code (see the tutorial for reference) and rebuild the MIDlet. The Orientation API is supported from Java Runtime 2.0.0 for Series 40 onwards.
/** * Copyright (c) 2012 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.systemproperties; import javax.bluetooth.BluetoothStateException; import javax.microedition.lcdui.Form; import javax.microedition.lcdui.Command; import javax.microedition.lcdui.CommandListener; import javax.microedition.lcdui.Displayable; import javax.bluetooth.LocalDevice; import javax.microedition.m3g.Graphics3D; import java.util.Hashtable; //import com.nokia.mid.ui.orientation.*; public class SysPropForm extends Form implements CommandListener { //public class SysPropForm extends Form implements CommandListener, OrientationListener { private Command backCommand; private Command exitCommand; private SystemProperties midlet; private String[] items; public SysPropForm(String title, SystemProperties midlet, String[] list) { super(title); items = list; this.midlet = midlet; backCommand = new Command("Back", Command.BACK, 1); // Porting MIDlet from Series 40 full touch to Nokia Asha software platform (1.0) if(System.getProperty(SystemProperties.PLATFORM_UI).startsWith(SystemProperties.PLATFORM_2_0)){ exitCommand = new Command("Exit", Command.EXIT, 1); }else{ exitCommand = new Command("Exit", Command.ITEM, 1); } addCommand(backCommand); addCommand(exitCommand); setCommandListener(this); //Orientation.addOrientationListener(this); } protected void update(String title, String[] list) { this.setTitle(title); items = list; this.deleteAll(); //Clear the screen //Special case for Bluetooth details if (midlet.bt) { try { append("BT address: " + LocalDevice.getLocalDevice().getBluetoothAddress() + "\n"); append("Friendly name: " + LocalDevice.getLocalDevice().getFriendlyName() + "\n"); } catch (BluetoothStateException ex) { append("BluetoothStateException: " + ex.getMessage()); } } //Default way of displaying details for (int i = 0; i < items.length; i++) { append(items[i] + ":\n"); if (midlet.bt) { append(LocalDevice.getProperty(items[i]) + "\n"); } else if (midlet.m3g) { // Properties "maxViewportWidth" and "maxViewportHeight" were // added in M3G 1.1, in case of M3G 1.0 this MIDlet returns // "null" for these properties. // Property "m3gRelease" is not mandated by the specification, but // it is a implementation specific property. Hashtable g3dtable = new Hashtable(); g3dtable = Graphics3D.getProperties(); Object property = g3dtable.get(list[i]); if (property != null) { append(property.toString() + "\n"); } else { append("null\n"); } } else if (midlet.index == 14) { try { append(System.getProperty(items[i]) + "\n"); } catch (SecurityException se) { // In case of untrusted or trusted 3rd party MIDlet // SecurityException should be thrown for all the // PROTECTED_SYSPROPS properties. append("SecurityException: " + se.getMessage()); } } else { append(System.getProperty(items[i]) + "\n"); } } } public void commandAction(Command c, Displayable d) { if (c == backCommand) { midlet.showList(); midlet.bt = false; midlet.m3g = false; } if (c == exitCommand) { midlet.notifyDestroyed(); } } /** * This is method for changing orientation based on the device orientation. * @param newOrientation */ /*public void displayOrientationChanged(int newOrientation) { Orientation.setAppOrientation(newOrientation); switch( newOrientation ){ case Orientation.ORIENTATION_PORTRAIT: // 1 break; case Orientation.ORIENTATION_LANDSCAPE: // 2 break; case Orientation.ORIENTATION_LANDSCAPE_180: // Not supported currently break; case Orientation.ORIENTATION_PORTRAIT_180: // Not supported currently break; } }*/ }