appmanagerpeer.java
来自「This is a resource based on j2me embedde」· Java 代码 · 共 1,154 行 · 第 1/3 页
JAVA
1,154 行
return; } } } } /** * Called when state of a running midlet was changed. * * @param midlet proxy of a newly added MIDlet */ void notifyMidletStateChanged(MIDletProxy midlet) { RunningMIDletSuiteInfo msi; for (int i = 0; i < msiVector.size(); i++) { msi = (RunningMIDletSuiteInfo)msiVector.elementAt(i); if (msi.hasProxy(midlet)) { appManagerUI.notifyMidletStateChanged(msi, midlet); } } } /** * Called when a running midlet exited. * * @param midlet proxy of a newly added MIDlet */ void notifyMidletExited(MIDletProxy midlet) { String midletClassName = midlet.getClassName(); if (midlet.getSuiteId() == MIDletSuite.INTERNAL_SUITE_ID && !midletClassName.equals(DISCOVERY_APP) && !midletClassName.equals(INSTALLER) && !midletClassName.equals(CA_MANAGER) && !midletClassName.equals(COMP_MANAGER) && !midletClassName.equals(ODT_AGENT)) { appManagerMidlet = null; appManagerUI.notifyInternalMidletExited(midlet); } else { RunningMIDletSuiteInfo si; for (int i = 0; i < msiVector.size(); i++) { si = (RunningMIDletSuiteInfo)msiVector.elementAt(i); if (si.hasProxy(midlet)) { if (si.hasSingleMidlet()) { si.unlock(); } si.removeProxy(midlet); appManagerUI.notifyMidletExited(si, midletClassName); if (si.numberOfRunningMidlets() == 0) { manager.notifySuiteExited(si, null); } // remove the suite scheduled for removal after the midlet has exited // note that in the case of two running midlets, we must wait till the last midlet exits if (removeMsi != null && removeMsi.sameSuite(midlet) && !removeMsi.hasRunningMidlet()) { removeSuite(removeMsi); } /* * When the Installer midlet quites * (it is removed from the running apps list) * this is a good time to see if any new MIDlet suites * where added * Also the CA manager could have disabled a MIDlet. */ if (INSTALLER.equals(midletClassName)) { updateContent(); /* * After a MIDlet suite is successfully installed on the * device, ask the user whether or not to launch * a MIDlet from the suite. */ RunningMIDletSuiteInfo msi = getLastInstalledMidletItem(); if (msi != null) { appManagerUI.notifySuiteInstalled(msi); return; } } else if (CA_MANAGER.equals(midletClassName) || COMP_MANAGER.equals(midletClassName)) { updateContent(); } return; } } } } /** * Called when a new MIDlet suite is installed externally. * * @param suiteId ID of the newly installed MIDlet suite */ void notifySuiteInstalled(int suiteId) { updateContent(); int size = msiVector.size(); for (int i = 0; i < size; i++) { RunningMIDletSuiteInfo msi = (RunningMIDletSuiteInfo)msiVector.elementAt(i); if (msi.suiteId == suiteId) { appManagerUI.notifySuiteInstalledExt(msi); break; } } } /** * Called when a MIDlet suite has been removed externally. * * @param suiteId ID of the removed MIDlet suite */ void notifySuiteRemoved(int suiteId) { int size = msiVector.size(); for (int i = 0; i < size; i++) { RunningMIDletSuiteInfo msi = (RunningMIDletSuiteInfo)msiVector.elementAt(i); if (msi.suiteId == suiteId) { appManagerUI.notifySuiteRemovedExt(msi); msiVector.removeElementAt(i); appManagerUI.itemRemoved(msi); break; } } updateContent(); } /** * Called when a suite exited (last running MIDlet in suite exited). * @param suiteInfo Suite which just exited */ void notifySuiteExited(RunningMIDletSuiteInfo suiteInfo) { appManagerUI.notifySuiteExited(suiteInfo); } /** * Called when MIDlet selector exited. * @param suiteInfo Suite whose selector just exited */ void notifyMIDletSelectorExited(RunningMIDletSuiteInfo suiteInfo) { appManagerUI.notifyMIDletSelectorExited(suiteInfo); } // ------------------------------------------------------------------ /** * Read in and create a MIDletInfo for newly added MIDlet suite and * check enabled state of currently added MIDlet suites. */ private void updateContent() { int[] suiteIds; RunningMIDletSuiteInfo msi = null; suiteIds = midletSuiteStorage.getListOfSuites(); /* * IMPL_NOTE: Sorting MIDlet suite names is up to implementations * of the AppManagerUI interface. AppManagerPeer notifies the UI * via the append() function about added internal MIDlets and * user-added MIDlet suites, and this happens to be "internal * MIDlets first, then user-installed MIDlet suites in the order * of suite IDs", but the UI can sort the suite names on the * screen in any other way. */ // Add the Installer as the first installed midlet if (null == findInternalMidletRmsi(DISCOVERY_APP)) { msi = new RunningMIDletSuiteInfo(MIDletSuite.INTERNAL_SUITE_ID, DISCOVERY_APP, Resource.getString(ResourceConstants.INSTALL_APPLICATION), true) { public boolean sameSuite(MIDletProxy midlet) { // there is one exception when 2 midlets belong to the // same icon: Discovery app & Graphical installer. // Graphical Installer can be launched by Discover app // or when MIdlet update is needed. // In such cases we simply need to set the proxy on // corresponding icon (MidletCustomItem). // Note that when Discovery app exits and // Installer is launched // notifyMidletExited() will not find corresponding // icon in the list of MidletCustomItems. // (that midlet exit will be ignored). return sameSuiteId(midlet) && (INSTALLER.equals(midlet.getClassName()) || DISCOVERY_APP.equals(midlet.getClassName())); } }; append(msi); } if (caManagerIncluded) { // Add the CA manager as the second installed midlet if (null == findInternalMidletRmsi(CA_MANAGER)) { msi = new RunningMIDletSuiteInfo(MIDletSuite.INTERNAL_SUITE_ID, CA_MANAGER, Resource.getString(ResourceConstants.CA_MANAGER_APP), true); append(msi); } } if (compManagerIncluded) { // Add the component manager as the next installed midlet if (null == findInternalMidletRmsi(COMP_MANAGER)) { msi = new RunningMIDletSuiteInfo(MIDletSuite.INTERNAL_SUITE_ID, COMP_MANAGER, Resource.getString(ResourceConstants.COMP_MANAGER_APP), true); append(msi); } } if (oddEnabled) { // Add the ODT Agent midlet as the next installed midlet if (null == findInternalMidletRmsi(ODT_AGENT)) { msi = new RunningMIDletSuiteInfo(MIDletSuite.INTERNAL_SUITE_ID, ODT_AGENT, Resource.getString(ResourceConstants.ODT_AGENT_MIDLET), true); append(msi); } } // Add the rest of the installed midlets for (int lowest, i = 0; i < suiteIds.length; i++) { lowest = i; for (int k = i + 1; k < suiteIds.length; k++) { if (suiteIds[k] < suiteIds[lowest]) { lowest = k; } } try { RunningMIDletSuiteInfo updatedMsi = new RunningMIDletSuiteInfo( midletSuiteStorage.getMIDletSuiteInfo(suiteIds[lowest]), midletSuiteStorage); msi = findUserInstalledSuiteRmsi(suiteIds[lowest]); if (null == msi) { // newly added append(updatedMsi); launchSuite(updatedMsi); } else { MIDletSuiteInfo oldMsi = new MIDletSuiteInfo(msi.suiteId); oldMsi.copyFieldsFrom(msi); appManagerUI.notifyMIDletSuiteStateChanged(msi, updatedMsi); msi.copyFieldsFrom(updatedMsi); // Update all information about the suite; // if the suite's icon was changed, reload it. if (oldMsi.enabled != updatedMsi.enabled) { // MIDlet suite being enabled appManagerUI.notifyMIDletSuiteEnabled(msi); // running MIDlets will continue to run // even when disabled } if ((updatedMsi.iconName != null && !updatedMsi.iconName.equals(oldMsi.iconName)) || (updatedMsi.iconName == null && updatedMsi.numberOfMidlets != oldMsi.numberOfMidlets) ) { msi.icon = null; msi.loadIcon(midletSuiteStorage); appManagerUI.notifyMIDletSuiteIconChaged(updatedMsi); } } } catch (Exception e) { // move on to the next suite } suiteIds[lowest] = suiteIds[i]; } } /** * Appends an item to the list * * @param suiteInfo the midlet suite info * of the recently started midlet */ private void append(RunningMIDletSuiteInfo suiteInfo) { msiVector.addElement(suiteInfo); appManagerUI.itemAppended(suiteInfo); } /** * If extended MIDlet attributes support enabled, launch all MIDlets from * the suite that have MIDlet-Launch-Power-On attribute set to true. * <p/> * This method is used during JVM start-up to run all such MIDlets from all * installed suites. The method is also utilzied for newly installed * MIDlets that have the attribute to launch them right after installation * process is completed. * * @param suiteInfo describes the suite */ private void launchSuite(RunningMIDletSuiteInfo suiteInfo) { if (Constants.EXTENDED_MIDLET_ATTRIBUTES_ENABLED) { // IMPL_NOTE: for better performance open suite only one time MIDletSuite suite = MIDletSuiteUtils.getSuite(suiteInfo.suiteId); if (suite != null) { /** * Calling to MIDletSuiteUtils.getSuite locks the * suite this makes impossible to launch a MIDlet * from it. So we have to iterate over all MIDlets * in the suite and remember which of them must be * started upon JVM start-up. */ int midletsNum = suiteInfo.numberOfMidlets; Vector midletsToStart = new Vector(midletsNum); try { for (int m = 1; m <= midletsNum; m++) { String prop = MIDletSuiteUtils.getSuiteProperty( suite, m, MIDletSuite.LAUNCH_POWER_ON_PROP); if ("yes".equalsIgnoreCase(prop)) { String className = MIDletSuiteUtils.getMIDletClassName(suite, m); midletsToStart.addElement(className); } } } finally { suite.close(); } for (Enumeration e = midletsToStart.elements(); e.hasMoreElements() ;) { manager.launchSuite(suiteInfo, (String)e.nextElement()); } } } } /** * Removes a suite from the App Selector Screen * * @param suiteInfo the midlet suite info of a recently removed MIDlet */ public void removeSuite(RunningMIDletSuiteInfo suiteInfo) { if (suiteInfo == null) { // Invalid parameter, should not happen. return; } // the last item in AppSelector is time for (int i = 0; i < msiVector.size(); i++) { RunningMIDletSuiteInfo msi = (RunningMIDletSuiteInfo)msiVector.elementAt(i); if (msi == suiteInfo) { PAPICleanUp.removeMissedTransaction(suiteInfo.suiteId); while (msi.hasRunningMidlet()) { MIDletProxy proxy = msi.getFirstProxy(); proxy.destroyMidlet(); msi.removeProxy(proxy); } try { midletSuiteStorage.remove(suiteInfo.suiteId); } catch (Throwable t) { if (t instanceof MIDletSuiteLockedException) { String[] val = new String[1]; val[0] = suiteInfo.displayName; displayError.showErrorAlert(suiteInfo.displayName, null, Resource.getString(ResourceConstants.ERROR), Resource.getString( ResourceConstants.AMS_MGR_REMOVE_LOCKED_SUITE, val), appManagerUI.getMainDisplayable()); } else {
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?