⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 device.java

📁 J2me应用开发经典例子
💻 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;

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 fire softbutton */
  public static final int KEYCODE_FIRE_SOFT = -5; 
  /** 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 a unique id for this device. The K750i supports
   * the systemproperty "com.sonyericsson.imei" giving the IMEI number. This is used for
   * calculating a unique id. If this property does not exist, current time is
   * used for id creation instead.
   * The id is cached in RMS and is thus only calculated once.
   * 
   * @return	Device identifyer
   */
  public static int getDeviceId()
  {
    int id = RmsFacade.getInt(Bloglines.DEVICE_ID);
    if (id == 0)
    {
      String idStr = System.getProperty("com.sonyericsson.imei");
      if (idStr == null)
      {
        idStr = Long.toString(System.currentTimeMillis());
      }
      id = calcIdFromString(idStr);
      RmsFacade.setInt(Bloglines.DEVICE_ID, id);
    }
    return id;
  }
  
  /**
   * 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 + -