DeviceDemo演示了如何使用DeviceFeatures Data Control中暴露的设备服务,比如:GPS,邮件,短信,联系人等等。
这个例子需要运行在真机上。
1. GPS
DeviceFeatures Data Control提供了startLocationMonitor服务,但是没有提供stopLocationMonitor服务,后者是定义在GPSBean.java中的。
package GPS;
import com.sun.util.logging.Level;
import java.sql.Timestamp;
import oracle.adf.model.datacontrols.device.DeviceManagerFactory;
import oracle.adfmf.amx.event.ActionEvent;
import oracle.adf.model.datacontrols.device.Location;
import oracle.adfmf.java.beans.PropertyChangeListener;
import oracle.adfmf.java.beans.PropertyChangeSupport;
import oracle.adfmf.util.Utility;
import oracle.adfmf.util.logging.Trace;
public class GPSBean {
private boolean highAccuracy = true;
private int updateInterval = 1000;
private boolean started = false;
private double accuracy = 0;
private double altitude = 0;
private double altitudeAccuracy = 0;
private double longitude = 0;
private double latitude = 0;
private double heading = 0;
private String watchId = "";
private double speed = 0;
private Timestamp timestamp = new Timestamp(0);
private transient PropertyChangeSupport propertyChangeSupport = new PropertyChangeSupport(this);
public GPSBean() {
super();
}
public void addPropertyChangeListener(PropertyChangeListener l) {
propertyChangeSupport.addPropertyChangeListener(l);
}
public void removePropertyChangeListener(PropertyChangeListener l) {
propertyChangeSupport.removePropertyChangeListener(l);
}
public void LocationHandler(Location currentLocation) {
Trace.log(Utility.ApplicationLogger, Level.INFO, GPSBean.class, "LocationHandler",
"#############LocationHandler called");
setAccuracy(currentLocation.getAccuracy());
setAltitude(currentLocation.getAltitude());
setAltitudeAccuracy(currentLocation.getAltitudeAccuracy());
setLongitude(currentLocation.getLongitude());
setLatitude(currentLocation.getLatitude());
setHeading(currentLocation.getHeading());
setWatchId(currentLocation.getWatchId());
setSpeed(currentLocation.getSpeed());
setTimestamp(new Timestamp(currentLocation.getTimestamp()));
}
public void stopLocationMonitor(ActionEvent actionEvent) {
Trace.log(Utility.ApplicationLogger, Level.INFO, GPSBean.class, "stopLocationMonitor",
"###############watchid=" + getWatchId());
if (getWatchId().length() > 0) {
DeviceManagerFactory.getDeviceManager().clearWatchPosition(getWatchId());
setAccuracy(0);
setAltitude(0);
setAltitudeAccuracy(0);
setLongitude(0);
setLatitude(0);
setHeading(0);
setWatchId("");
setSpeed(0);
setTimestamp(new Timestamp(0));
}
}
public void setAccuracy(double accuracy) {
double oldAccuracy = this.accuracy;
this.accuracy = accuracy;
propertyChangeSupport.firePropertyChange("accuracy", oldAccuracy, accuracy);
}
public double getAccuracy() {
return accuracy;
}
public void setAltitude(double altitude) {
double oldAltitude = this.altitude;
this.altitude = altitude;
propertyChangeSupport.firePropertyChange("altitude", oldAltitude, altitude);
}
public double getAltitude() {
return altitude;
}
public void setAltitudeAccuracy(double altitudeAccuracy) {
double oldAltitudeAccuracy = this.altitudeAccuracy;
this.altitudeAccuracy = altitudeAccuracy;
propertyChangeSupport.firePropertyChange("altitudeAccuracy", oldAltitudeAccuracy, altitudeAccuracy);
}
public double getAltitudeAccuracy() {
return altitudeAccuracy;
}
public void setLongitude(double longitude) {
double oldLongitude = this.longitude;
this.longitude = longitude;
propertyChangeSupport.firePropertyChange("longitude", oldLongitude, longitude);
}
public double getLongitude() {
return longitude;
}
public void setLatitude(double latitude) {
double oldLatitude = this.latitude;
this.latitude = latitude;
propertyChangeSupport.firePropertyChange("latitude", oldLatitude, latitude);
}
public double getLatitude() {
return latitude;
}
public void setHeading(double heading) {
double oldHeading = this.heading;
this.heading = heading;
propertyChangeSupport.firePropertyChange("heading", oldHeading, heading);
}
public double getHeading() {
return heading;
}
public void setWatchId(String watchId) {
String oldWatchId = this.watchId;
this.watchId = watchId;
propertyChangeSupport.firePropertyChange("watchId", oldWatchId, watchId);
}
public String getWatchId() {
return watchId;
}
public void setSpeed(double speed) {
double oldSpeed = this.speed;
this.speed = speed;
propertyChangeSupport.firePropertyChange("speed", oldSpeed, speed);
}
public double getSpeed() {
return speed;
}
public void setTimestamp(Timestamp timestamp) {
Timestamp oldTimestamp = this.timestamp;
this.timestamp = timestamp;
propertyChangeSupport.firePropertyChange("timestamp", oldTimestamp, timestamp);
}
public Timestamp getTimestamp() {
return timestamp;
}
public void setHighAccuracy(boolean highAccuracy) {
boolean oldHighAccuracy = this.highAccuracy;
this.highAccuracy = highAccuracy;
propertyChangeSupport.firePropertyChange("highAccuracy", oldHighAccuracy, highAccuracy);
}
public boolean isHighAccuracy() {
return highAccuracy;
}
public void setUpdateInterval(int updateInterval) {
int oldUpdateInterval = this.updateInterval;
this.updateInterval = updateInterval;
propertyChangeSupport.firePropertyChange("updateInterval", oldUpdateInterval, updateInterval);
}
public int getUpdateInterval() {
return updateInterval;
}
public void setStarted(boolean started) {
boolean oldStarted = this.started;
this.started = started;
propertyChangeSupport.firePropertyChange("started", oldStarted, started);
}
public boolean getStarted() {
return started;
}
}
DeviceFeatures Data Control提供了sendEmail服务。
3. SMS
DeviceFeatures Data Control提供了sendSMS服务。
4. Picture
DeviceFeatures Data Control提供了getPicture服务。
GetSource服务是定义在PictureBean.java中的,用来获取图片的Source。
PictureBean.java代码如下:
package Picture;
import oracle.adf.model.datacontrols.device.DeviceManager;
public class PictureBean {
public PictureBean() {
super();
}
private int quality = 25;
private int destination = DeviceManager.CAMERA_DESTINATIONTYPE_FILE_URI;
private int source = DeviceManager.CAMERA_SOURCETYPE_PHOTOLIBRARY;
private boolean allowEdit = false;
private int encoding = DeviceManager.CAMERA_ENCODINGTYPE_JPEG;
private int targetWidth = 0;
private int targetHeight= 0;
public void setQuality(int quality) {
this.quality = quality;
}
public int getQuality() {
return quality;
}
public void setDestination(int destination) {
this.destination = destination;
}
public int getDestination() {
return destination;
}
public void setSource(int source) {
this.source = source;
}
public int getSource() {
return source;
}
public void setAllowEdit(boolean allowEdit) {
this.allowEdit = allowEdit;
}
public boolean getAllowEdit() {
return allowEdit;
}
public boolean isAllowEdit() {
return allowEdit;
}
public void setEncoding(int encoding) {
this.encoding = encoding;
}
public int getEncoding() {
return encoding;
}
public void setTargetWidth(int targetWidth) {
this.targetWidth = targetWidth;
}
public int getTargetWidth() {
return targetWidth;
}
public void setTargetHeight(int targetHeight) {
this.targetHeight = targetHeight;
}
public int getTargetHeight() {
return targetHeight;
}
public String GetSource(String result) {
String src = "";
if( getDestination() == DeviceManager.CAMERA_DESTINATIONTYPE_DATA_URL ) {
src = "data:image/gif;base64,";
}
src = src + result;
return src;
}
}
5. Contacts
DeviceFeatures Data Control提供了findContacts和removeContact服务。
ContactBean.java代码:
package Contacts;
import oracle.adf.model.datacontrols.device.DeviceManager;
import oracle.adf.model.datacontrols.device.DeviceManagerFactory;
import oracle.adf.model.datacontrols.device.Contact;
import oracle.adfmf.java.beans.PropertyChangeListener;
import oracle.adfmf.java.beans.PropertyChangeSupport;
public class ContactBean {
String contactFields = "birthday,displayname,id,nickname,note,addresses,categories,emails,ims,name,organizations,phoneNumbers,photos,urls";
String filter = "";
boolean multiple = true;
private transient PropertyChangeSupport propertyChangeSupport = new PropertyChangeSupport(this);
public ContactBean() {
super();
}
public void setContactFields(String contactFields) {
String oldContactFields = this.contactFields;
this.contactFields = contactFields;
propertyChangeSupport.firePropertyChange("contactFields", oldContactFields, contactFields);
}
public void addPropertyChangeListener(PropertyChangeListener l) {
propertyChangeSupport.addPropertyChangeListener(l);
}
public void removePropertyChangeListener(PropertyChangeListener l) {
propertyChangeSupport.removePropertyChangeListener(l);
}
public String getContactFields() {
return contactFields;
}
public void setFilter(String filter) {
String oldFilter = this.filter;
this.filter = filter;
propertyChangeSupport.firePropertyChange("filter", oldFilter, filter);
}
public String getFilter() {
return filter;
}
public void setMultiple(boolean multiple) {
boolean oldMultiple = this.multiple;
this.multiple = multiple;
propertyChangeSupport.firePropertyChange("multiple", oldMultiple, multiple);
}
public boolean isMultiple() {
return multiple;
}
public void findContacts() {
DeviceManager deviceManager = DeviceManagerFactory.getDeviceManager();
Contact[] cons = deviceManager.findContacts(contactFields, filter, multiple);
}
}
deviceScope包括所有定义在设备级的信息,ADF Mobile目前支持如下设备属性:
(1)device
- model
- name
- os
- phonegap
- platform
- version
(2)hardware
- hasAccelerometer
- hasCamera
- hasCompass
- hasContacts
- hasFileAccess
- hasGeolocation
- hasLocalStorage
- hasMediaPlayer
- hasMediaRecorder
- hasTouchScreen
- networkStatus
- screen (availableHeight, availableWidth, height, width)
参考文献:
1. http://docs.oracle.com/cd/E35521_01/doc.111230/e24475/amxbinding.htm
没有评论:
发表评论