appsettingsimpl.java
来自「This is a resource based on j2me embedde」· Java 代码 · 共 761 行 · 第 1/2 页
JAVA
761 行
*/ private void showGroupsInConflictAlert() { String[] values = {groupsInConflict[0].getName(), groupsInConflict[1].getName()}; String txt = Resource.getString( ResourceConstants.PERMISSION_MUTUALLY_EXCLUSIVE_SELECT_MESSAGE, values); Alert alert = new Alert(Resource.getString(ResourceConstants.WARNING), txt, null, AlertType.WARNING); alert.addCommand(noExclusiveChoiceSelectionCmd); alert.addCommand(okExclusiveChoiceSelectionCmd); alert.setCommandListener(this); alert.setTimeout(Alert.FOREVER); display.setCurrent(alert); } /** * Returns ValueChoice that contains set of available application * setting names and IDs. Selected ID represents the initial setting * to be shown to the user. * @return value choice */ public ValueChoice getSettings() { return groupChoice; } /** * Returns ValueChoice that contains set of possible value' IDs and * lables for specified setting. Selected ID represents value that * is currently active for this setting. * @param settingID * @return available setting values */ public ValueChoice getSettingValues(int settingID) { if (settingID == INTERRUPT_CHOICE_ID) { return interruptChoice; } else { //else ID of group is equivalent to index in array return groupSettings[settingID]; } } /** * Initialize the MIDlet suite info fields for a given suite. * * @param midletSuite the MIDletSuiteImpl object instance * * @exception Exception if problem occurs while getting the suite info */ private void initMidletSuiteInfo(MIDletSuiteImpl midletSuite) { int numberOfMidlets = midletSuite.getNumberOfMIDlets(); installInfo = midletSuite.getInstallInfo(); if (numberOfMidlets == 1) { String value = midletSuite.getProperty("MIDlet-1"); MIDletInfo temp = new MIDletInfo(value); suiteDisplayName = temp.name; } else { suiteDisplayName = midletSuite.getProperty( MIDletSuiteImpl.SUITE_NAME_PROP); } } /** * Load the MIDlet suite settings as choice group infos. * * @param suiteId ID for suite * @throws MIDletSuiteLockedException if the suite is locked * @throws MIDletSuiteCorruptedException if the suite is corrupted */ private void loadApplicationSettings(int suiteId) throws MIDletSuiteLockedException, MIDletSuiteCorruptedException { int maxLevel; int interruptSetting; boolean loadDone = false; try { midletSuite = midletSuiteStorage.getMIDletSuite(suiteId, false); initMidletSuiteInfo(midletSuite); maxLevels = (Permissions.forDomain(installInfo.getSecurityDomain())) [Permissions.MAX_LEVELS]; curLevels = midletSuite.getPermissions(); tmpLevels = new byte[curLevels.length]; System.arraycopy(curLevels, 0, tmpLevels, 0, curLevels.length); prevTmpLevels = new byte[curLevels.length]; pushInterruptSetting = midletSuite.getPushInterruptSetting(); tmpPushInterruptSetting= pushInterruptSetting; pushOptions = midletSuite.getPushOptions(); groupChoice = new ValueChoiceImpl(null, -1, Resource.getString(ResourceConstants.AMS_MGR_PREFERENCES)); if (maxLevels[PUSH_ID] == Permissions.ALLOW) { maxLevel = Permissions.BLANKET; } else { maxLevel = maxLevels[PUSH_ID]; } if ((pushOptions & PushRegistryInternal.PUSH_OPT_WHEN_ONLY_APP) != 0) { interruptSetting = PUSH_OPTION_1_ID; } else { interruptSetting = pushInterruptSetting; } interruptChoice = newSettingChoice( Permissions.getPushInterruptGroup(), INTERRUPT_CHOICE_ID, maxLevel, interruptSetting, suiteDisplayName, ResourceConstants.AMS_MGR_SETTINGS_PUSH_OPT_ANSWER, PUSH_OPTION_1_ID); groups = Permissions.getSettingGroups(curLevels); groupSettings = new ValueChoiceImpl[groups.length]; if (interruptChoice != null) { numberOfSettings = 1; } else { numberOfSettings = 0; } for (int i = 0; i < groups.length; i++) { byte maxGroupSetting = Permissions.getMaximumPermissionGroupLevel( maxLevels, groups[i]); byte currentGroupSetting = Permissions.getPermissionGroupLevel( curLevels, groups[i]); groupSettings[i] = newSettingChoice( groups[i], i, maxGroupSetting, currentGroupSetting, suiteDisplayName, 0, 0); if (groupSettings[i] != null) { numberOfSettings++; } } loadDone = true; } finally { if (!loadDone) { if (midletSuite != null) { midletSuite.close(); midletSuite = null; } } } } /** * Creates a new choice info if it is user settable, * with the 3 preset choices and a initial one selected. * * @param permissionGroup correspondent permission group * @param groupID button ID of group in settings popup, * @param maxLevel maximum permission level * @param level current permission level * @param name name of suite * @param extraAnswer if > 0, add this extra answer before last * answer, i18N will be translated * @param extraAnswerId ID for the extra answer * * @return choice info or null if setting cannot be modified */ private ValueChoiceImpl newSettingChoice( PermissionGroup permissionGroup, int groupID, int maxLevel, int level, String name, int extraAnswer, int extraAnswerId) { String[] values = {name}; int initValue; ValueChoiceImpl choice; if (permissionGroup.getSettingsQuestion() == null || maxLevel == Permissions.ALLOW || maxLevel == Permissions.NEVER || level == Permissions.ALLOW || level == Permissions.NEVER) { return null; } choice = new ValueChoiceImpl(permissionGroup, groupID, Resource.getString(permissionGroup.getSettingsQuestion(), values)); groupChoice.append(permissionGroup.getName(), groupID); switch (maxLevel) { case Permissions.BLANKET: choice.append(Resource.getString( ResourceConstants.AMS_MGR_SETTINGS_BLANKET_ANSWER), Permissions.BLANKET_GRANTED); // fall through, since this security level permits the // next response. case Permissions.SESSION: choice.append(Resource.getString( ResourceConstants.AMS_MGR_SETTINGS_SESSION_ANSWER), Permissions.SESSION); // fall through, since this security level permits the // next response. default: choice.append(Resource.getString( ResourceConstants.AMS_MGR_SETTINGS_ONE_SHOT_ANSWER), Permissions.ONESHOT); if (extraAnswer > 0) { choice.append(Resource.getString(extraAnswer), extraAnswerId); } choice.append(permissionGroup.getDisableSettingChoice(), Permissions.BLANKET_DENIED); break; } if (Logging.REPORT_LEVEL <= Logging.INFORMATION) { Logging.report(Logging.INFORMATION, LogChannels.LC_AMS, "AppSettings: " + permissionGroup.getName() + " level = " + level); } switch (level) { case Permissions.BLANKET_GRANTED: case Permissions.BLANKET: initValue = Permissions.BLANKET_GRANTED; break; case Permissions.SESSION: initValue = Permissions.SESSION; break; case Permissions.ONESHOT: initValue = Permissions.ONESHOT; break; default: if (level == extraAnswerId) { initValue = extraAnswerId; } else { initValue = Permissions.BLANKET_DENIED; } break; } choice.setSelectedID(initValue); if (initialSetting == null) { initialSetting = choice; groupChoice.setSelectedID(groupID); } return choice; } /** * Cancel application settings the user entered and dismiss UI. * Called by AppSettingsUI as response to user request. */ public void cancelApplicationSettings() { display.setCurrent(nextScreen); midletSuite.close(); } /** * Save application settings the user entered and dismiss UI. * Called by AppSettingsUI as a response to user request. * * IMPL_NOTE: This method has no arguments as AppSettings is * aware of changes user made due to onSettingChanged calls. * */ public void saveApplicationSettings() { try { if (midletSuite == null) { return; } if (interruptChoice != null) { byte maxInterruptSetting; int interruptSetting = interruptChoice.getSelectedID(); if (maxLevels[PUSH_ID] == Permissions.ALLOW) { maxInterruptSetting = Permissions.BLANKET_GRANTED; } else { maxInterruptSetting = maxLevels[PUSH_ID]; } if (interruptSetting == PUSH_OPTION_1_ID) { pushOptions = PushRegistryInternal.PUSH_OPT_WHEN_ONLY_APP; pushInterruptSetting = maxInterruptSetting; } else { pushOptions = 0; Permissions.checkPushInterruptLevel(tmpLevels, (byte)interruptSetting); pushInterruptSetting = (byte)interruptSetting; } } for (int i = 0; i < groups.length; i++) { if (groupSettings[i] != null) { byte newSetting = (byte)groupSettings[i].getSelectedID(); if (newSetting != Permissions.getPermissionGroupLevel( curLevels, groups[i])) { if (newSetting != Permissions.BLANKET_GRANTED) { /* * first apply only weak permissions to avoid mutual * exclusive combination */ Permissions.setPermissionGroup(curLevels, pushInterruptSetting, groups[i], newSetting); } } } } for (int i = 0; i < groups.length; i++) { if (groupSettings[i] != null) { byte newSetting = (byte)groupSettings[i].getSelectedID(); if (newSetting != Permissions.getPermissionGroupLevel( curLevels, groups[i])) { if (newSetting == Permissions.BLANKET_GRANTED) { Permissions.setPermissionGroup(curLevels, pushInterruptSetting, groups[i], newSetting); } } } } if (numberOfSettings > 0) { midletSuiteStorage.saveSuiteSettings(midletSuite.getID(), pushInterruptSetting, pushOptions, curLevels); displaySuccessMessage(Resource.getString (ResourceConstants.AMS_MGR_SAVED)); } } catch (SecurityException ex) { Alert a = new Alert(Resource.getString(ResourceConstants.ERROR), ex.getMessage(), null, AlertType.ERROR); a.setTimeout(Alert.FOREVER); display.setCurrent(a); throw ex; } catch (Throwable t) { t.printStackTrace(); displayError.showErrorAlert(suiteDisplayName, t, Resource.getString (ResourceConstants.EXCEPTION), null); } finally { midletSuite.close(); midletSuite = null; } } /** * Alert the user that an action was successful. * @param successMessage message to display to user */ private void displaySuccessMessage(String successMessage) { Image icon = GraphicalInstaller.getImageFromInternalStorage("_dukeok8"); Alert successAlert = new Alert(null, successMessage, icon, null); successAlert.setTimeout(GraphicalInstaller.ALERT_TIMEOUT); display.setCurrent(successAlert, nextScreen); }}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?