generalsettingsform.java

来自「moblie syncml mail javame」· Java 代码 · 共 631 行 · 第 1/2 页

JAVA
631
字号
                // Every 30 minutes
                minutes = 30;
                break;
            case 6:
                // Every 1 hour
                minutes = 60;
                break;
            case 7:
                // Every 2 hours
                minutes = 120;
                break;
            case 8:
                // Every 4 hours
                minutes = 240;
                break;
            case 9:
                // Every day
                minutes = 24 * 60;
                break;
            default:
                break;
        }
        return minutes;
    }

    private void appendSyncSetChoice() {
        boolean showTime = false;
        settedScheduler = false;
        if (syncSettingsChoice == null) {
            syncSettingsLabel = Localization.getMessages().ASSF_SYNC_SETTINGS_CHOICE_LABEL;
            syncSettingsChoice = new ChoiceGroup(syncSettingsLabel, Choice.POPUP, new String[]{
                Localization.getMessages().ASSF_SYNC_SETTINGS_CHOICE_PUSH,
                Localization.getMessages().ASSF_SYNC_SETTINGS_CHOICE_MAN,
                Localization.getMessages().ASSF_SYNC_SETTINGS_CHOICE_5M,
                Localization.getMessages().ASSF_SYNC_SETTINGS_CHOICE_10M,
                Localization.getMessages().ASSF_SYNC_SETTINGS_CHOICE_15M,
                Localization.getMessages().ASSF_SYNC_SETTINGS_CHOICE_30M,
                Localization.getMessages().ASSF_SYNC_SETTINGS_CHOICE_1H,
                Localization.getMessages().ASSF_SYNC_SETTINGS_CHOICE_2H,
                Localization.getMessages().ASSF_SYNC_SETTINGS_CHOICE_4H,
                Localization.getMessages().ASSF_SYNC_SETTINGS_CHOICE_1D
            }, new Image[]{
                null, null, null, null, null, null, null, null, null, null
            });
            int selectedIndex = 1;
            if (mailClientConfig.getCtpPushStatus() == mailClientConfig.CTP_ENABLED) {
                selectedIndex = 0;
            } else if (mailClientConfig.isSchedulerEnabled()) {
                Log.info("Scheduling enabled");
                int minutes = mailClientConfig.getPollInterval();
                selectedIndex = getScheduledIndex(minutes) + NUMBER_OF_NON_SCHEDULED_OPTIONS;
                if (minutes >= minutesInADay) {
                    getScheduledTimeField();
                    Date nextAlarmDate = new Date(mailClientConfig.getNextTimeAlarm());
                    Log.info("Next Alarm Date: " + MailDateFormatter.dateToUTC(nextAlarmDate));
                    scheduledTimeField.setDate(nextAlarmDate);
                    showTime = true;
                }
            }
            syncSettingsChoice.setSelectedIndex(selectedIndex, true);
        }
        append(syncSettingsChoice);
        if (showTime) {
            append(scheduledTimeField);
        }
    }

    private Item getScheduledTimeField() {
        if (scheduledTimeField == null) {
            scheduledTimeFieldLabel = Localization.getMessages().ASSF_SCHEDULED_TIME_FIELD_LABEL;
            scheduledTimeField =
                    new DateField(scheduledTimeFieldLabel, DateField.TIME);
        }
        return scheduledTimeField;
    }

    public void itemStateChanged(Item item) {
        if (item == syncSettingsChoice) {
            settedScheduler = true;
            int index = syncSettingsChoice.getSelectedIndex();
            if (getMinutes(index) >= minutesInADay) {
                addTimeChoice();
            } else {
                remove(getScheduledTimeField());
            }
        }

    // commented out for future use (turning of sound at night)
        /*else {
    if (item == soundSettingsChoice) {
    boolean[] selArray = new boolean[2];
    soundSettingsChoice.getSelectedFlags(selArray);
    // if we have notifications enabled
    if (selArray[0] || selArray[1]) {
    showSuppressNotificationChoice();
    } else {
    remove(suppressNotificationChoice);
    remove(getSuppressFrom());
    remove(getSuppressTo());
    }
    }
    }*/
    }

    private void remove(Item item) {

        for (int i = 0; i < this.size(); i++) {
            if (this.get(i) == item) {
                this.delete(i);
                break;
            }
        }
    }

    /**
     * Method to get the index for the scheduling choice to be set
     * based on the pollInterval property of the mailClientConfig
     * @return Index to set the choice of scheduling interval
     */
    public int getScheduledIndex(int minutes) {
        Log.info("PollInterval minutes found: " + minutes);
        for (int i = 0; i < scheduledMinutes.length; i++) {
            if (minutes == scheduledMinutes[i]) {
                return i;
            }
        }
        int hours = minutes / 60;
        for (int i = 0; i < scheduledHours.length; i++) {
            if (hours == scheduledHours[i]) {
                return scheduledMinutes.length + i;
            }
        }
        int days = hours / 24;
        for (int i = 0; i < scheduledDays.length; i++) {
            if (days == scheduledDays[i]) {
                return scheduledMinutes.length + scheduledHours.length + i;
            }
        }
        Log.error("Wrong pollInterval setting, no setting.");
        return 0;
    }

    private void addTimeChoice() {
        insert(2, getScheduledTimeField());
    }

    private void appendSoundChoiche() {

        if (soundSettingsChoice == null) {
            soundSettingsLabel = Localization.getMessages().SOUND_SETTINGS_CHOICE_LABEL;

            createMediaChoice(UserNotificationManager.getInstance().isAbleToPlayTones());

            append(soundSettingsChoice);
        }
    }

    private void createMediaChoice(boolean ableToSound) {
        // check if sound capabilities are allowed by jvm before creating choicegroup
        if (ableToSound) {
            soundSettingsChoice = new ChoiceGroup(soundSettingsLabel, Choice.MULTIPLE, new String[]{
                Localization.getMessages().SOUND_SETTINGS_CHOICE_PLAY_SOUND,
                Localization.getMessages().SOUND_SETTINGS_CHOICE_VIBRATE
            }, new Image[]{
                null, null
            });

            soundSettingsChoice.setSelectedIndex(0,
                    mailClientConfig.isSoundNotificationEnabled());
            soundSettingsChoice.setSelectedIndex(1,
                    mailClientConfig.isVibrateNotificationEnabled());
        } else {
            soundSettingsChoice = new ChoiceGroup(soundSettingsLabel, Choice.MULTIPLE, new String[]{
                Localization.getMessages().SOUND_SETTINGS_CHOICE_VIBRATE
            }, new Image[]{
                null
            });
            soundSettingsChoice.setSelectedIndex(0,
                    mailClientConfig.isVibrateNotificationEnabled());

        }

    }

    private void showSuppressNotificationChoice() {

        // search for the right position
        int i;
        boolean found = false;
        for (i = 0; i < this.size(); i++) {
            if (get(i) == soundSettingsChoice) {
                found = true;
                break;
            }
        }

        if (found) {
            if (this.size() > i + 1) {
                if (get(i + 1) != getSuppressNotificationChoice()) {
                    insert(i + 1, getSuppressNotificationChoice());
                    insert(i + 2, getSuppressFrom());
                    insert(i + 3, getSuppressTo());
                }
            } else {
                //we are at the last item
                append(getSuppressNotificationChoice());
                append(getSuppressFrom());
                append(getSuppressTo());
            }
        }
    }

    private Item getSuppressNotificationChoice() {
        if (suppressNotificationChoice == null) {

            suppressNotificationChoice = new ChoiceGroup(null, Choice.MULTIPLE, new String[]{
                Localization.getMessages().SUPPRESS_NOTIFICATION_CHOICE_UNLESS
            }, new Image[]{
                null
            });


        }

        return suppressNotificationChoice;
    }

    private Item getSuppressTo() {
        if (suppressToField == null) {
            suppressToField =
                    new DateField(Localization.getMessages().SUPPRESS_TO, DateField.TIME);
        }
        return suppressToField;
    }

    private Item getSuppressFrom() {
        if (suppressFromField == null) {
            suppressFromField =
                    new DateField(Localization.getMessages().SUPPRESS_FROM, DateField.TIME);
        }
        return suppressFromField;
    }

    private void appendSyncOnStartupChoice() {
        if (syncOnStartupChoice == null) {

            String[] values = new String[]{Localization.getMessages().SYNC_ON_STARTUP_ON,
                Localization.getMessages().SYNC_ON_STARTUP_OFF
            };
            Image[] images = new Image[]{null, null};

            syncOnStartupChoice = new ChoiceGroup(Localization.getMessages().SYNC_ON_STARTUP,
                    Choice.POPUP, values, images);

            if (mailClientConfig.isSyncOnStartupEnabled()) {
                syncOnStartupChoice.setSelectedIndex(0, true);
            } else {
                syncOnStartupChoice.setSelectedIndex(1, true);
            }

            append(syncOnStartupChoice);
        }
    }

    private void appendDeleteConfirmationChoice() {
        if (deleteConfirmationChoice == null) {

            String[] values = new String[]{Localization.getMessages().DELETE_CONFIRMATION_ON,
                Localization.getMessages().DELETE_CONFIRMATION_OFF
            };
            Image[] images = new Image[]{null, null};

            deleteConfirmationChoice = new ChoiceGroup(Localization.getMessages().DELETE_CONFIRMATION,
                    Choice.POPUP, values, images);

            if (mailClientConfig.getDeleteConfirmation()) {
                deleteConfirmationChoice.setSelectedIndex(0, true);
            } else {
                deleteConfirmationChoice.setSelectedIndex(1, true);
            }

            append(deleteConfirmationChoice);
        }
    }

    public class ResetPopupAction implements PopupAction, Runnable {

        public ResetPopupAction() {
        }

        public void cancel() {
            UIController.showBackScreen();
        }

        public void confirm() {
            Log.info("Resetting inbox...");
            popup.setTitle(Localization.getMessages().RESETTING_MSG);
            UIController.setSyncCaller(UIController.USER);
            UIController.getThreadPool().startThread(this);
        }

        public void run() {
            try {
                UIController.resetInboxFromServer();
            } catch (MailException e) {
                Log.error("Unable to resetWithSlow: " + e.getMessage());
                e.printStackTrace();
            } catch (RecordStoreException e) {
                Log.error("Unable to resetWithSlow: " + e.getMessage());
                e.printStackTrace();
            }
        }
    }
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?