AppSettingspublic class AppSettings extends Form implements CommandListener, ItemStateListenerThe Graphical MIDlet suite settings form. |
Fields Summary |
---|
private static final int | INTERRUPT_CHOICE_IDID for the interrupt choice. | private static final int | PUSH_OPTION_1_IDID for the first push option radio button. | private Command | saveAppSettingsCmdCommand object for "OK" command for the form. | private Command | cancelCmdCommand object for "Cancel" command for the form. | private int | displayedSettingIDThe ID of the setting displayed in the form. | private int | lastPopupChoiceThe ID of the popup button selected. | private RadioButtonSet | initialSettingThe initial setting to display. | private RadioButtonSet | settingsPopupThe settings popup choice group. | private RadioButtonSet | interruptChoiceThe application interruption setting. | private RadioButtonSet[] | groupSettingsThe application permission settings. | private int | numberOfSettingsThe number of group permission settings. | private byte[] | maxLevelsHolds the maximum levels for permissions. | private byte[] | curLevelsHolds the updated permissions. | private byte | pushInterruptSettingHolds the updated push interrupt level. | private int | pushOptionsHolds the updated push options. | private PermissionGroup[] | groupsPermission group information. | MIDletSuiteStorage | midletSuiteStorageMIDlet Suite storage object. | DisplayError | displayErrorUI to display error alerts. | Displayable | nextScreenThe displayable to be displayed after dismissing AppSettings. | Display | displayDisplay for the Manager midlet. | String | suiteDisplayNameDisplay name of the suite. | MIDletSuiteImpl | midletSuiteInterface to suite | InstallInfo | installInfoInstallation information of the suite. | Image | iconIcon to display for the suite |
Constructors Summary |
---|
public AppSettings(int suiteId, Display display, DisplayError displayError, Displayable nextScreen)Create and initialize a new application settings MIDlet.
super(null);
this.displayError = displayError;
midletSuiteStorage = MIDletSuiteStorage.getMIDletSuiteStorage();
this.display = display;
this.nextScreen = nextScreen;
displayApplicationSettings(suiteId);
|
Methods Summary |
---|
public void | commandAction(Command c, Displayable s)Respond to a command issued on any Screen.
if (c == saveAppSettingsCmd) {
saveApplicationSettings();
midletSuite.close();
} else if (c == cancelCmd) {
display.setCurrent(nextScreen);
midletSuite.close();
}
| private void | displayApplicationSettings(int suiteId)Display the MIDlet suite settings as choice groups.
int maxLevel;
String[] values = new String[1];
int interruptSetting;
initialSetting = null;
try {
groups = Permissions.getSettingGroups();
midletSuite = midletSuiteStorage.getMIDletSuite(suiteId, false);
initMidletSuiteInfo(midletSuite);
maxLevels =
(Permissions.forDomain(installInfo.getSecurityDomain()))
[Permissions.MAX_LEVELS];
curLevels = midletSuite.getPermissions();
pushInterruptSetting = midletSuite.getPushInterruptSetting();
pushOptions = midletSuite.getPushOptions();
values[0] = suiteDisplayName;
setTitle(Resource.getString(
ResourceConstants.AMS_MGR_SETTINGS));
settingsPopup = new RadioButtonSet(
Resource.getString(ResourceConstants.AMS_MGR_PREFERENCES),
true);
if (maxLevels[Permissions.PUSH] == Permissions.ALLOW) {
maxLevel = Permissions.BLANKET;
} else {
maxLevel = maxLevels[Permissions.PUSH];
}
if ((pushOptions &
PushRegistryInternal.PUSH_OPT_WHEN_ONLY_APP) != 0) {
interruptSetting = PUSH_OPTION_1_ID;
} else {
interruptSetting = pushInterruptSetting;
}
interruptChoice =
newSettingChoice(settingsPopup,
ResourceConstants.AMS_MGR_INTRUPT,
INTERRUPT_CHOICE_ID,
ResourceConstants.AMS_MGR_INTRUPT_QUE,
ResourceConstants.AMS_MGR_INTRUPT_QUE_DONT,
maxLevel,
interruptSetting, suiteDisplayName,
ResourceConstants.AMS_MGR_SETTINGS_PUSH_OPT_ANSWER,
PUSH_OPTION_1_ID);
groupSettings = new RadioButtonSet[groups.length];
if (interruptChoice != null) {
numberOfSettings = 1;
} else {
numberOfSettings = 0;
}
for (int i = 0; i < groups.length; i++) {
byte maxGroupSetting = Permissions.getPermissionGroupLevel(
maxLevels, groups[i]);
byte currentGroupSetting = Permissions.getPermissionGroupLevel(
curLevels, groups[i]);
groupSettings[i] = newSettingChoice(
settingsPopup,
groups[i].getName(),
i,
groups[i].getSettingsQuestion(),
groups[i].getDisableSettingChoice(),
maxGroupSetting,
currentGroupSetting,
suiteDisplayName,
0, 0);
if (groupSettings[i] != null) {
numberOfSettings++;
}
}
if (numberOfSettings > 1) {
/*
* There is more then one setting to display so add the
* popup to the settings form
*/
append(settingsPopup);
}
if (initialSetting != null) {
displayedSettingID = append(initialSetting);
}
} catch (Throwable t) {
if (midletSuite != null) {
midletSuite.close();
}
throw t;
}
addCommand(saveAppSettingsCmd);
addCommand(cancelCmd);
setCommandListener(this);
setItemStateListener(this);
| private void | displaySuccessMessage(java.lang.String successMessage)Alert the user that an action was successful.
Image icon = GraphicalInstaller.getImageFromInternalStorage("_dukeok8");
Alert successAlert = new Alert(null, successMessage, icon, null);
successAlert.setTimeout(GraphicalInstaller.ALERT_TIMEOUT);
display.setCurrent(successAlert, nextScreen);
| private void | initMidletSuiteInfo(MIDletSuiteImpl midletSuite)Initialize the MIDlet suite info fields for a given suite.
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);
}
| public void | itemStateChanged(Item item)Called when internal state of an item in Settings form is
changed by the user. This is used to dynamically display
the setting the user chooses from the settings popup.
int selected;
if (item != settingsPopup) {
/* ignore the other items besides the popup */
return;
}
selected = settingsPopup.getSelectedButton();
if (selected == lastPopupChoice) {
return;
}
lastPopupChoice = selected;
delete(displayedSettingID);
try {
if (selected == INTERRUPT_CHOICE_ID) {
displayedSettingID = append(interruptChoice);
} else {
displayedSettingID = append(groupSettings[selected]);
}
} catch (IndexOutOfBoundsException e) {
// for safety/completeness.
displayedSettingID = 0;
Logging.report(Logging.ERROR, LogChannels.LC_AMS,
"AppSettings: selected=" + selected);
}
| private com.sun.midp.appmanager.RadioButtonSet | newSettingChoice(com.sun.midp.appmanager.RadioButtonSet popup, int groupName, int groupID, int question, int denyAnswer, int maxLevel, int level, java.lang.String name, int extraAnswer, int extraAnswerId)Creates a new choice group in a form if it is user settable,
with the 3 preset choices and a initial one set.
String[] values = {name};
int initValue;
RadioButtonSet choice;
if (question <= 0 ||
maxLevel == Permissions.ALLOW || maxLevel == Permissions.NEVER ||
level == Permissions.ALLOW || level == Permissions.NEVER) {
return null;
}
choice = new RadioButtonSet(Resource.getString(question, values),
false);
settingsPopup.append(Resource.getString(groupName), 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(Resource.getString(denyAnswer),
Permissions.BLANKET_DENIED);
break;
}
if (Logging.REPORT_LEVEL <= Logging.INFORMATION) {
Logging.report(Logging.INFORMATION, LogChannels.LC_AMS,
"AppSettings: " + Resource.getString(groupName) +
" 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.setDefaultButton(initValue);
choice.setPreferredSize(getWidth(), -1);
if (initialSetting == null) {
initialSetting = choice;
lastPopupChoice = groupID;
}
return choice;
| private void | saveApplicationSettings()Save the application settings the user entered.
try {
if (interruptChoice != null) {
byte maxInterruptSetting;
int interruptSetting = interruptChoice.getSelectedButton();
if (maxLevels[Permissions.PUSH] == Permissions.ALLOW) {
maxInterruptSetting = Permissions.BLANKET_GRANTED;
} else {
maxInterruptSetting = maxLevels[Permissions.PUSH];
}
if (interruptSetting == PUSH_OPTION_1_ID) {
pushOptions = PushRegistryInternal.PUSH_OPT_WHEN_ONLY_APP;
pushInterruptSetting = maxInterruptSetting;
} else {
pushOptions = 0;
Permissions.checkPushInterruptLevel(curLevels,
(byte)interruptSetting);
pushInterruptSetting = (byte)interruptSetting;
}
}
for (int i = 0; i < groups.length; i++) {
if (groupSettings[i] != null) {
byte newSetting =
(byte)groupSettings[i].getSelectedButton();
if (newSetting != Permissions.getPermissionGroupLevel(
curLevels, groups[i])) {
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);
}
|
|