📄 device.java
字号:
// Copyright (c) 2005 Sony Ericsson Mobile Communications AB
//
// This software is provided "AS IS," without a warranty of any kind.
// ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES,
// INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A
// PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED.
//
// THIS SOFTWARE IS COMPLEMENTARY OF JAYWAY AB (www.jayway.se)
package com.ultrapower.gui;
import javax.microedition.lcdui.Display;
import javax.microedition.midlet.MIDlet;
/**
* The <code>Device</code> represents the
* device the MIDlet is running on.
*
* @author Peter Andersson
*/
public final class Device
{
/** Canvas keycode for left softbutton */
public static final int KEYCODE_LEFT_SOFT = -6;
/** Canvas keycode for right softbutton */
public static final int KEYCODE_RIGHT_SOFT = -7;
/** Canvas keycode for back button */
public static final int KEYCODE_BACK = -11;
/** The display */
protected static Display m_display;
/** The midlet instance */
protected static MIDlet m_midlet;
/**
* Bluetooth support flag, 0 mean unsearched, 1 means searched
* and found, -1 means searched and not found.
*/
private static int m_bluetoothSupport = 0;
/**
* Initializes the <code>Device</code> class.
* @param midlet The midlet instance.
* @param display The display.
*/
public static void init(MIDlet midlet, Display display)
{
m_midlet = midlet;
m_display = display;
}
/**
* Returns the midlet instance.
* @return The midlet.
*/
public static MIDlet getMidlet()
{
return m_midlet;
}
/**
* Returns the display of this midlet.
* @return The display.
*/
public static Display getDisplay()
{
return m_display;
}
/**
* Returns whether this device implements bluetooth-apis or not.
* @return True if JSR82 is implemented, false otherwise.
*/
public static boolean canBluetooth()
{
if (m_bluetoothSupport == 0)
{
try
{
Class.forName("javax.bluetooth.LocalDevice");
m_bluetoothSupport = 1;
}
catch (Throwable t)
{
m_bluetoothSupport = -1;
}
}
return m_bluetoothSupport == 1;
}
/**
* Returns whether this device can vibrate via J2ME or not.
* @return True if vibration functionality is enabled, false otherwise.
*/
public static boolean canVibrate()
{
return true;
}
/**
* Calculates an indentifer from a string.
* @param s The string
* @return The id
*/
protected static int calcIdFromString(String s)
{
int res = 0;
// Left shift, XOR the char val, XOR shift overflow bit
for (int i = s.length()-1; i >= 0; i--)
{
res = ((res << 1) ^ s.charAt(i)) ^ ((res & 0x80000000) != 0 ? 1 : 0);
}
return res;
}
/** Prohibit construction */
private Device() {}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -