Java源码示例:javax.microedition.midlet.MIDlet

示例1
/**
   * Get a URL to install from the Invocation mechanism, if one
   * has been queued.
   * @param midlet to check for an invocation
   * @return the URL to install; <code>null</code> if none available.
   * @see com.sun.midp.content.CHManagerImpl
   */
  public String getInstallURL(MIDlet midlet) {
try {
    handler = Registry.getServer(midlet.getClass().getName());
} catch (ContentHandlerException che) {
       return null;
   }

      installInvoc = handler.getRequest(false);
      if (installInvoc != null) {
          String url = installInvoc.getURL();
          if (url != null && url.length() > 0) {
              return url;
          }
      }
      return null;
  }
 
示例2
/**
 * Called by the MIDlet constructor to a new MIDletPeer object.
 *
 * @param token security token for authorizing the caller
 * @param m the MIDlet for which this state is being created;
 *          must not be <code>null</code>.
 * @return the preallocated MIDletPeer for the MIDlet being constructed by
 *         {@link #createMIDlet}
 *
 * @exception SecurityException AMS permission is not granted and
 * if is constructor is not being called in the context of
 * <code>createMIDlet</code>.
 */
public static MIDletPeer newMIDletPeer(SecurityToken token, MIDlet m) {
    token.checkIfPermissionAllowed(Permissions.MIDP);

    synchronized (createMIDletLock) {
        MIDletPeer temp;

        if (newMidletPeer == null) {
            throw new SecurityException(
                "MIDlet not constructed by createMIDlet.");
        }

        temp = newMidletPeer;
        newMidletPeer = null;
        temp.midlet = m;
        return temp;
    }
}
 
示例3
/**
 * Checks the value of a Jad attribute and returns the corresponding 
 * boolean value.
 * Only attributes that have <code>enabled</code> and <code>disabled</code>
 * should be used with this method.
 * 
 * @param midlet the MIDlet which Jad attributes to read.
 * @param id logging setup identifier or <code>null</code> to use common logging setup.
 * @param attrName name of the attribute to check.
 * @param defaultValue default value to be used in case the attribute is not defined.
 * 
 * @return <code>true</code> if the specified attribute has the value 
 *         <code>enabled</code> and <code>false</code> otherwise.
 */
private static final boolean isEnabled(MIDlet midlet, String id, String attrName, boolean defaultValue) {
    String origAttrName = attrName;
    
    if (id != null) {
        // Read setup specific attribute first.
        attrName = id + "-" + attrName;
    }
    
    String value = midlet.getAppProperty(attrName);

    if (value == null) {
        
        if (id != null) {
            // Setup specific value not specified - use common logging setup instead.
            return isEnabled(midlet, null, origAttrName, defaultValue);
        }
        
        return defaultValue;
    } else if (value.equalsIgnoreCase("enabled")) {
        return true;
    } else {
        return false;
    }
}
 
示例4
public LinkedHashMap<String, String> loadMIDletList() {
	LinkedHashMap<String, String> midlets = new LinkedHashMap<>();
	LinkedHashMap<String, String> params =
			FileUtils.loadManifest(new File(path, Config.MIDLET_MANIFEST_FILE));
	MIDlet.initProps(params);
	for (Map.Entry<String, String> entry : params.entrySet()) {
		if (entry.getKey().matches("MIDlet-[0-9]+")) {
			String tmp = entry.getValue();
			String key = tmp.substring(tmp.lastIndexOf(',') + 1).trim();
			String value = tmp.substring(0, tmp.indexOf(',')).trim();
			midlets.put(key, value);
		}
	}
	return midlets;
}
 
示例5
MIDlet loadMIDlet(String mainClass)
		throws IOException, ClassNotFoundException, InstantiationException,
		IllegalAccessException, NoSuchMethodException, InvocationTargetException {
	File dexSource = new File(path, Config.MIDLET_DEX_FILE);
	File dexTargetDir = new File(context.getApplicationInfo().dataDir, Config.TEMP_DEX_DIR);
	if (dexTargetDir.exists()) {
		FileUtils.deleteDirectory(dexTargetDir);
	}
	dexTargetDir.mkdir();
	File dexTargetOptDir = new File(context.getApplicationInfo().dataDir, Config.TEMP_DEX_OPT_DIR);
	if (dexTargetOptDir.exists()) {
		FileUtils.deleteDirectory(dexTargetOptDir);
	}
	dexTargetOptDir.mkdir();
	File dexTarget = new File(dexTargetDir, Config.MIDLET_DEX_FILE);
	FileUtils.copyFileUsingChannel(dexSource, dexTarget);
	File resDir = new File(path, Config.MIDLET_RES_DIR);
	ClassLoader loader = new AppClassLoader(dexTarget.getAbsolutePath(),
			dexTargetOptDir.getAbsolutePath(), context.getClassLoader(), resDir);
	Log.i(TAG, "loadMIDletList main: " + mainClass + " from dex:" + dexTarget.getPath());
	Log.i(TAG, "MIDlet-Name: " + AppClassLoader.getName());
	//noinspection unchecked
	Class<MIDlet> clazz = (Class<MIDlet>) loader.loadClass(mainClass);
	Constructor<MIDlet> init = clazz.getDeclaredConstructor();
	init.setAccessible(true);
	MIDlet midlet = init.newInstance();
	return midlet;
}
 
示例6
/**
 * Registers a MIDlet being constructed.
 *
 * @param midlet to be registered with this state handler
 */
private void register(MIDlet midlet) {
    synchronized (this) {
        MIDletPeer state = MIDletPeer.getMIDletPeer(midlet);

        /*
         * If a MIDlet of the same class is already running
         * Make the existing MIDlet current so that startSuite()
         * will run it
         */
        int i = findMIDletByClass(state);
        if (i >= 0) {
            state.setState(MIDletPeer.DESTROY_PENDING);
            // Fall into adding it to the list so destroyApp
            // can be called at a reasonable time.
        }

        // Grow the list if necessary
        if (nmidlets >= midlets.length) {
            MIDletPeer[] n = new MIDletPeer[nmidlets+5];
            System.arraycopy(midlets, 0, n, 0, nmidlets);
            midlets = n;
        }

        // Add it to the end of the list
        midlets[nmidlets++] = state;

        // MIDlet peer is registered now
        underConstructionPeer = null;

        this.notify();
    }
}
 
示例7
public MIDlet getActiveMIDlet() {
	return null;
}
 
示例8
public static Display getDisplay(MIDlet midlet) {
	if (instance == null && midlet != null) {
		instance = new Display();
	}
	return instance;
}
 
示例9
/**
 * @inheritDoc
 */
public void init(Object m) {
    canvas = createCanvas();
    canvas.setTitle(null);
    if(!disableFullScreen) {
        canvas.setFullScreenMode(!com.codename1.ui.Display.getInstance().isNativeCommands());
    }

    // disable the flashGraphics bug on Nokia phones
    String platform = System.getProperty("microedition.platform");
    if (platform != null && platform.toUpperCase().indexOf("NOKIA") >= 0) {
        flushGraphicsBug = false;
        NOKIA = true;

        // Symbian devices should yield a bit to let the paint thread complete its work
        // problem is we can't differentiate S40 from S60...
        Display.getInstance().setTransitionYield(1);
        //nokia devices cannot use OutputStreamWriter flush when using 
        //MultipartRequest
        MultipartRequest.setCanFlushStream(false);
    } else {
        flushGraphicsBug = true;
        Display.getInstance().setTransitionYield(-1);
    }
    mid = (MIDlet)m;
    display = javax.microedition.lcdui.Display.getDisplay(mid);
    setSoftKeyCodes(mid);

    if(mid.getAppProperty("forceBackCommand") != null) {
        canvas.setCommandListener((CommandListener) canvas);
        canvas.addCommand(MIDP_BACK_COMMAND);
    }
    
    RecordEnumeration e = null;
    RecordStore r = null;
    try {
        r = RecordStore.openRecordStore("FAT", true);
        if (r.getNumRecords() > 0) {
            e = r.enumerateRecords(null, null, false);
            while (e.hasNextElement()) {
                byte[] rec = e.nextRecord();
                ByteArrayInputStream bi = new ByteArrayInputStream(rec);
                DataInputStream di = new DataInputStream(bi);
                String name = di.readUTF();
                short key = di.readShort();
                di.close();
                bi.close();
                fat.put(name, new Short(key));
                if(key >= currentKey) {
                    currentKey += key;
                }
            }
            e.destroy();
            e = null;
        }
        r.closeRecordStore();
        r = null;
    } catch (Exception ex) {
        ex.printStackTrace();
        cleanup(r);
        cleanup(e);
    }        
}
 
示例10
/**
 * Enables or disables console (sysout/commconn) and file logging based on the 
 * classname (packagename not counted for) of the specified MIDlet.
 * The identifier can be used for allowing MIDlet specific logging settings
 * in case a MIDlet suite has multiple MIDlets. The 
 * MIDlet specific JAD attribute names are prefixed with 
 * <code>[id]-</code>, e.g. if identifier is <code>FgMidlet</code> 
 * the attributes are be <code>FgMidlet-logfile</code>,
 * <code>FgMidlet-logsysout</code> and <code>FgMidlet-logcomm</code>.
 * If MIDlet specific attributes are not defined then the common ones
 * are used instead, i.e. ones without the identifier prefix.
 * Note that since all logging methods are static methods this means
 * that there can be only one setup for a single classloader. So if
 * MIDlet suite is a normal one with multiple MIDlets then
 * usually they all use the same Log class and thus only one setup is possible.
 * 
 * @return <code>true</code> if log initialization was successful and 
 *         <code>false</code> if an error occurred.
 */
public static boolean initLogging(MIDlet midlet, String id) {
    
    if (id == null) {
        id = midlet.getClass().getName();
        int lastDot = id.lastIndexOf('.');
        
        if (lastDot > -1) {
            id = id.substring(lastDot + 1);
        }
    }
    
    Log.id = id;
    
    try {
        
        // Read default log settings from Jad attributes.
        if (isEnabled(midlet, id, "logfile", false)) {
            boolean append = isEnabled(midlet, id, "logfile-append", false);
            Log.setFileLogger(true, id, append);
        } else {
            Log.setFileLogger(false, id);
        }
        
        if (isEnabled(midlet, id, "logsysout", false)) {
            Log.setConsoleLogger(true);
        } else {
            Log.setConsoleLogger(false);
        }
        
        if (isEnabled(midlet, id, "logcomm", false)) {
            Log.setCommPortLogger(true, midlet.getAppProperty("logcomm-id"));
        } else {
            Log.setCommPortLogger(false, null);
        }
        
        return true;
    } catch (IOException ioe) { 
        return false;
    }
}
 
示例11
public static void setMidlet(MIDlet midlet) {
    mlet = midlet;
}
 
示例12
/**
 * Returns the MIDletPeer object corresponding to the given
 * midlet instance.
 *
 * @param m MIDlet instance
 *
 * @return associated MIDletPeer instance
 */
public MIDletPeer getMIDletPeer(MIDlet m);
 
示例13
/**
 * Calls the startApp method on the midlet instance.
 *
 * @param m MIDlet instance
 *
 * @exception javax.microedition.midlet.MIDletStateChangeException  
 *     is thrown if the <code>MIDlet</code> cannot start now but 
 *     might be able to start at a later time.
 */
public void callStartApp(MIDlet m) 
    throws MIDletStateChangeException;
 
示例14
/**
 * Calls the pauseApp method on the midlet instance.
 *
 * @param m MIDlet instance
 */
public void callPauseApp(MIDlet m);
 
示例15
/**
 * Calls the destroyApp method on the midlet instance.
 *
 * @param m MIDlet instance
 * @param unconditional the flag to pass to destroy
 *
 * @exception javax.microedition.midlet.MIDletStateChangeException 
 *     is thrown if the <code>MIDlet</code> wishes to continue 
 *     to execute (Not enter the <em>Destroyed</em> state).
 *     This exception is ignored if <code>unconditional</code>
 *     is equal to <code>true</code>.
 */
public void callDestroyApp(MIDlet m, boolean unconditional) 
    throws MIDletStateChangeException;
 
示例16
/**
 * Retrieves current state of the MIDlet given.
 * @param midlet the MIDlet of interest
 * @return the MIDlet state as defined in MIDletPeer class
 */
public static int getMIDletState(MIDlet midlet) {
    return MIDletPeer.getMIDletPeer(midlet).getState();
}
 
示例17
/**
 * Returns the MIDletPeer object corresponding to the given
 * midlet instance.
 *
 * @param m the midlet instance
 *
 * @return MIDletPeer instance associate with m
 */
static MIDletPeer getMIDletPeer(MIDlet m) {
    return tunnel.getMIDletPeer(m);
}
 
示例18
/**
 * Get the MIDlet for which this holds the state.
 *
 * @return the MIDlet; will not be null.
 */
public MIDlet getMIDlet() {
    return midlet;
}
 
示例19
/**
 * Check for a URL to install from the Invocation mechanism,
 * if one has been queued.
 * @param midlet the MIDlet that is the content handler.
 * @return the URL to install; <code>null</code> if none is available
 * @see com.sun.midp.content.CHInstallerImpl
 */
public String getInstallURL(MIDlet midlet) {
	return null;
}
 
示例20
/**
 * Enables or disables console (sysout/commconn) and file logging based on the 
 * classname (packagename not counted for) of the specified MIDlet.
 * 
 * @return <code>true</code> if log initialization was successful and 
 *         <code>false</code> if an error occurred.
 */
public static boolean initLogging(MIDlet midlet) {
    return initLogging(midlet, null);
}