SettingsView.java
/**
* Copyright (c) 2013 Nokia Corporation. All rights reserved.
* Nokia and Nokia Connecting People are registered trademarks of Nokia Corporation.
* Oracle and Java are trademarks or registered trademarks of Oracle and/or its
* affiliates. Other product and company names mentioned herein may be trademarks
* or trade names of their respective owners.
* See LICENSE.TXT for license information.
*/
package com.nokia.example.phonesettings;
import javax.microedition.lcdui.Form;
import com.nokia.mid.network.NetworkState;
import com.nokia.mid.network.SIMState;
import com.nokia.mid.network.WLANState;
import com.nokia.mid.setting.Setting;
import com.nokia.mid.ui.orientation.Orientation;
import com.nokia.mid.ui.orientation.OrientationListener;
/**
* View for displaying the selected setting details.
*/
public class SettingsView
extends Form
implements OrientationListener
{
// Constants
public static int SIM_SLOT_INDEX_1 = 0;
public static int SIM_SLOT_INDEX_2 = 1;
// Members
private boolean isDualSim = false;
/**
* Constructor
* @param title The title of the Form.
*/
public SettingsView(String title) {
super(title);
isDualSim = System.getProperty("com.nokia.multisim.cellid.sim1") != null;
Orientation.addOrientationListener(this);
}
/**
* @see OrientationListener#displayOrientationChanged(int)
*/
public void displayOrientationChanged(int newDisplayOrientation) {
Orientation.setAppOrientation(newDisplayOrientation);
}
/**
* Updates the setting details in the view based on the given index.
* @param index The index corresponding to a certain setting.
*/
public void update(int index) {
this.setTitle(MainView.PHONE_SETTING_STRING_LIST[index]);
this.deleteAll();
switch (index) {
case MainView.PHONE_SETTING_INDEX:
updatePhoneSetting();
break;
case MainView.NETWORK_STATE_INDEX:
updateNetworkState();
break;
case MainView.SIM_STATE_INDEX:
updateSIMState();
break;
case MainView.WLAN_STATE_INDEX:
if (WLANState.getState() == 1) {
append("WLAN: Connected");
}
else {
append("WLAN: Not connected");
}
break;
default:
break;
}
}
/**
* Displays the general phone settings in the form.
*/
private void updatePhoneSetting() {
String displayString = null;
int value = Setting.getSetting(Setting.SETTING_DATA_CONNECTION);
if (value == Setting.SETTING_DATA_CONNECTION) {
displayString = "Data Connection: Active";
}
else {
displayString = "Data Connection: Inactive";
}
append(displayString);
value = Setting.getSetting(Setting.SETTING_ROAMING_DATA_CONNECTION);
if (value == Setting.SETTING_ROAMING_DATA_CONNECTION) {
displayString = "Data Connection: Roam";
}
else {
displayString = "Data Connection: Don't roam";
}
append(displayString);
value = Setting.getSetting(Setting.SETTING_FLIGHT_MODE);
if (value == Setting.ON) {
displayString = "Flight Mode: On";
}
else {
displayString = "Flight Mode: Off";
}
append(displayString);
value = Setting.getSetting(Setting.SETTING_SILENT);
if (value == Setting.ON) {
displayString = "Silent Mode: On";
}
else {
displayString = "Silent Mode: Off";
}
append(displayString);
value = Setting.getSetting(Setting.SETTING_VIBRATOR);
if (value == Setting.ON) {
displayString = "Vibration: On";
}
else {
displayString = "Vibration: Off";
}
append(displayString);
}
/**
* Displays the SIM card specific network states in the form.
*/
private void updateNetworkState() {
int state = NetworkState.getState(SIM_SLOT_INDEX_1);
if (state == NetworkState.NETWORK_STATE_HOME) {
append("SIM1 Network State: Home");
}
else if (state == NetworkState.NETWORK_STATE_ROAMING) {
append("SIM1 Network State: Roaming");
}
else {
append("SIM1: No Network");
}
if (isDualSim) {
state = NetworkState.getState(SIM_SLOT_INDEX_2);
if (state == NetworkState.NETWORK_STATE_HOME) {
append("SIM2 Network State: Home");
}
else if (state == NetworkState.NETWORK_STATE_ROAMING) {
append("SIM2 Network State: Roaming");
}
else {
append("SIM2: No Network");
}
}
}
/**
* Displays the status of the SIM card(s) in the form.
*/
private void updateSIMState() {
int state = SIMState.getState(SIM_SLOT_INDEX_1);
if (state == SIMState.SIM_STATE_READY) {
append("SIM1 State: Ready");
}
else if (state == SIMState.SIM_STATE_NOT_READY) {
append("SIM1 State: Not ready");
}
else {
append("No SIM card in slot 1");
}
if (isDualSim) {
state = SIMState.getState(SIM_SLOT_INDEX_2);
if (state == SIMState.SIM_STATE_READY) {
append("SIM2 State: Ready");
}
else if (state == SIMState.SIM_STATE_NOT_READY) {
append("SIM2 State: Not ready");
}
else {
append("No SIM card in slot 2");
}
}
}
}