Permalink
Browse files

Initial Revision

  • Loading branch information...
HyunJun Jung
HyunJun Jung committed May 22, 2012
1 parent f1215a6 commit 6be4a0889a7d507a40cd0f235863f46622f43536
@@ -0,0 +1,103 @@
+# Backlight Management API Information
+
+## NOTE: THIS IS A WORK IN PROGRESS
+
+The Backlight Management API will allow you to control the smartphone backlight. This API provides the ability to check for backlight properties as well as turning on and off the backlight.
+Currently the API does not allow for users to set a time and will default to the timeout value set by the user in the profile settings.
+
+
+**Authors:** [HyunJun Jung](https://github.com/hjung)
+
+## Known Issues
+
+* None
+
+## Tested On
+
+* BlackBerry Bold 9900 v7.1.0.xxx
+* BlackBerry Torch 9810 v7.0.0.261
+
+
+**Requires BlackBerry WebWorks SDK for Smartphones v2.0 or higher**
+
+Have a problem with this extension? [Log an Issue](https://github.com/blackberry/WebWorks-Community-APIs/issues) or contact the Authors
+
+## How To Configure The Extension For Use
+
+1. Locate your BlackBerry WebWorks SDK for Smartphone extensions directory using your File Explorer. Default path is _**C:\Program Files\Research In Motion\BlackBerry WebWorks Packager\ext**_
+
+2. Create a new _**webworks.device.backlight**_ directory in the _**ext**_ directory
+
+3. Download the source from this repository and unzip it to a location on your computer
+
+4. Using File Explorer browse to this extension's downloaded source code _**Smartphone\Backlight**_
+
+5. Copy the _**library.xml**_ file from the downloaded _**Smartphone\Backlight**_ directory to your new _**ext\webworks.device.backlight**_ directory
+
+6. Copy the downloaded _**Smartphone\Backlight\src\webworks**_ directory to your new _**ext\webworks.device.backlight\webworks**_ directory
+
+**NOTE:** Be sure to back-up this _**ext\webworks.device.backlight**_ directory in your WebWorks SDK extensions directory before performing a WebWorks SDK upgrade. Simply copy it back into the _**ext**_ directory after you have completed your SDK upgrade.
+
+## Required Feature ID
+Whenever you use the below feature id in any of your WebWorks applications this extension will be loaded for use.
+
+ <feature id="webworks.device.backlight" required="true" version="1.0.0.0"/>
+
+## Summary
+
+
+To list all backlight properties:
+webworks.device.backlight.manageBacklight([String:all])
+
+To list individual properties (Returns a JSON string of key value pairs)
+webworks.device.backlight.manageBacklight([String:Property, String:Property, String:Property...etc])
+
+Available properties include:
+
+1. Get Brightness: Property: getBrightness
+
+2. Get Brightness Default: Property: getBrightnessDefault
+
+3. Get Brightness Increment: Property: getBrightnessIncrement
+
+4. Get Timeout Default: Property: getTimeoutDefault
+
+5. Is Brightness Configurable: Property: isBrightnessConfigurable
+
+6. Is Enabled: Property: isEnabled
+
+
+To turn on or off the backlight:
+webworks.device.backlight.manageBacklight([String:backlightEnable, String:on|off)
+
+Set the brightness of the backlight
+webworks.device.backlight.manageBacklight([String:setBrightness, String:number of seconds])
+
+Set the timeout of the backlight
+webworks.device.backlight.manageBacklight([String:setTimeout, String:number of seconds])
+The maximum timeout is 255 seconds
+
+Example:
+
+
+ <script type="text/javascript" >
+ var app = {
+ getBacklightProperties : function () {
+
+ var properties = webworks.device.backlight.manageBacklight("all");
+ var propertyDiv = document.getElementById("properties");
+ propertyDiv.innerHTML = properties;
+
+ },
+ turnOffBacklight : function () {
+ alert('the backlight will be turned off for 10 seconds');
+ webworks.device.backlight.manageBacklight("backlightEnable", "off");
+ setTimeout("app.turnOnBacklight()", 10000);
+
+ },
+ turnOnBacklight : function () {
+ webworks.device.backlight.manageBacklight("backlightEnable", "on");
+ }
+ }
+ </script>
+
@@ -0,0 +1,39 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+* Copyright 2010-2012 Research In Motion Limited.
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+-->
+<library isWhitelist="true">
+
+ <extension id="webworks.device.backlight">
+ <entryClass>webworks.device.backlight.BacklightExtension</entryClass>
+ </extension>
+
+ <platforms>
+ <platform value="JAVA">
+ <target version="default" config="JAVA_XHR" />
+ </platform>
+ </platforms>
+
+ <configurations>
+ <configuration name="JAVA_XHR" version="1.0" comment="For XHR architecture for Java implementation">
+ <src type="text/java" path="webworks" comment="API implementation in Java" />
+ </configuration>
+ </configurations>
+
+ <features>
+ <feature id="webworks.device.backlight" version="1.0.0"/>
+ </features>
+
+</library>
@@ -0,0 +1,51 @@
+/*
+* Copyright 2010-2012 Research In Motion Limited.
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+package webworks.device.backlight;
+
+import org.w3c.dom.Document;
+
+import net.rim.device.api.browser.field2.BrowserField;
+import net.rim.device.api.script.ScriptEngine;
+import net.rim.device.api.web.WidgetConfig;
+import net.rim.device.api.web.WidgetExtension;
+
+public class BacklightExtension implements WidgetExtension {
+ public static final String FEATURE_BACKLIGHT = "webworks.device.backlight";
+
+ public String[] getFeatureList() {
+ String[] result = new String[] { FEATURE_BACKLIGHT };
+ return result;
+ }
+
+ public void loadFeature(String feature, String version, Document doc,
+ ScriptEngine scriptEngine) throws Exception {
+ if (feature.equals(FEATURE_BACKLIGHT))
+ {
+ scriptEngine.addExtension(FEATURE_BACKLIGHT, new BacklightNamespace());
+ }
+ }
+
+ public void register(WidgetConfig arg0, BrowserField arg1) {
+ // TODO Auto-generated method stub
+
+ }
+
+ public void unloadFeatures(Document arg0) {
+ // TODO Auto-generated method stub
+
+ }
+
+}
@@ -0,0 +1,160 @@
+/*
+* Copyright 2010-2012 Research In Motion Limited.
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+package webworks.device.backlight;
+
+
+import net.rim.device.api.script.Scriptable;
+import net.rim.device.api.script.ScriptableFunction;
+import net.rim.device.api.system.Backlight;
+
+
+
+public class BacklightNamespace extends Scriptable {
+
+ public static final String FUNCTION_BACKLIGHT = "manageBacklight";
+
+ public static final String BACKLIGHT_ENABLE = "backlightEnable";
+ public static final String GET_BRIGHTNESS = "getBrightness";
+ public static final String GET_BRIGHTNESS_DEFAULT = "getBrightnessDefault";
+ public static final String GET_BRIGHTNESS_INCREMENT = "getBrightnessIncrement";
+ public static final String GET_TIMEOUT_DEFAULT = "getTimeoutDefault";
+ public static final String IS_BRIGHTNESS_CONFIGURABLE = "isBrightnessConfigurable";
+ public static final String IS_ENABLED = "isEnabled";
+ public static final String SET_BRIGHTNESS = "setBrightness";
+ public static final String SET_TIMEOUT = "setTimeout";
+
+ public Object getField(String name) throws Exception
+ {
+ if (name.equals(FUNCTION_BACKLIGHT))
+ {
+ return new BacklightInfoProperties();
+ }
+ return super.getField(name);
+ }
+
+ public class BacklightInfoProperties extends ScriptableFunction
+ {
+
+ public Object invoke(Object obj, Object[] args) throws Exception
+ {
+ String jsonString = "";
+ String functionParameter = "";
+ if(args.length == 0) {
+ return UNDEFINED;
+ } else {
+ try {
+
+ if(args[0].toString().equalsIgnoreCase("all") || args[0].toString().equals("")) {
+ jsonString = getBacklightProperties("all");
+ return jsonString;
+ } else if(args[0].toString().equalsIgnoreCase(BacklightNamespace.BACKLIGHT_ENABLE)) {
+ if(args[1] != null || args[1].equals("")) {
+ if(args[1].toString().equalsIgnoreCase("on")) {
+ Backlight.enable(true);
+ return "Turned on the backlight";
+ } else if(args[1].toString().equalsIgnoreCase("off")) {
+ Backlight.enable(false);
+ return "Turned off the backlight";
+ }
+ return "Unable to turn on or off the backlight";
+ }
+ } else if(args[0].toString().equalsIgnoreCase(BacklightNamespace.SET_BRIGHTNESS)) {
+ if(args[1] != null || args[1].equals("")) {
+ int brightness = Integer.parseInt(args[1].toString());
+ Backlight.setBrightness(brightness);
+ return "Set the brightness level to " + args[0].toString();
+ }
+ return "Unable to set the brightness level. No brightness level provided.";
+ } else if(args[0].toString().equalsIgnoreCase(BacklightNamespace.SET_TIMEOUT)) {
+ if(args[1] != null || args[1].equals("")) {
+ int timeout = Integer.parseInt(args[1].toString());
+ Backlight.setTimeout(timeout);
+ return "Set the timeout value to " + args[0].toString();
+ }
+ return "Unable to set the timeout value. No timeout value provided.";
+ } else {
+ jsonString = "{ ";
+ for(int i=0; i<args.length; i++) {
+ functionParameter = args[i].toString();
+ if(functionParameter.equalsIgnoreCase(BacklightNamespace.GET_BRIGHTNESS)) {
+ jsonString += getBacklightProperties(BacklightNamespace.GET_BRIGHTNESS);
+ continue;
+ } else if (functionParameter.equals(BacklightNamespace.GET_BRIGHTNESS_DEFAULT)) {
+ jsonString += getBacklightProperties(BacklightNamespace.GET_BRIGHTNESS_DEFAULT);
+ continue;
+ }else if (functionParameter.equals(BacklightNamespace.GET_BRIGHTNESS_INCREMENT)) {
+ jsonString += getBacklightProperties(BacklightNamespace.GET_BRIGHTNESS_INCREMENT);
+ continue;
+ }else if (functionParameter.equals(BacklightNamespace.GET_TIMEOUT_DEFAULT)) {
+ jsonString += getBacklightProperties(BacklightNamespace.GET_TIMEOUT_DEFAULT);
+ continue;
+ }else if (functionParameter.equals(BacklightNamespace.IS_BRIGHTNESS_CONFIGURABLE)) {
+ jsonString += getBacklightProperties(BacklightNamespace.IS_BRIGHTNESS_CONFIGURABLE);
+ continue;
+ }else if (functionParameter.equals(BacklightNamespace.IS_ENABLED)) {
+ jsonString += getBacklightProperties(BacklightNamespace.IS_ENABLED);
+ continue;
+ }else {
+
+ //did not receive correct function parameter to build json string. send back the
+ //Json string with any errors.
+ jsonString += "\"Unknown backlight parameter received\" : \"" + functionParameter + "\", ";
+
+ }
+ }
+ int lastCommaIndex = jsonString.length();
+ jsonString = jsonString.substring(0, lastCommaIndex - 2);
+ jsonString += " }";
+ }
+ } catch (Exception ex) {
+ return "{\"Exception\":\"" + ex.getMessage() + "\"}";
+ }
+
+ }
+
+ return "Backlight properties returned or modified.";
+ }
+ public String getBacklightProperties(String props) {
+ BacklightProperties backlightProperties = new BacklightProperties();
+ String jsonString = "";
+ if(props.equalsIgnoreCase(GET_BRIGHTNESS)) {
+ jsonString = "\"getBrightness\" : \"" + backlightProperties.brightness + "\", ";
+ return jsonString;
+ } else if(props.equalsIgnoreCase(GET_BRIGHTNESS_DEFAULT)) {
+ jsonString = "\"getBrightnessDefault\" : \"" + backlightProperties.brightnessDefault + "\", ";
+ return jsonString;
+ } else if(props.equalsIgnoreCase(GET_BRIGHTNESS_INCREMENT)) {
+ jsonString = "\"getBrightnessIncrement\" : \"" + backlightProperties.brightnessIncrement + "\", ";
+ return jsonString;
+ } else if(props.equalsIgnoreCase(GET_TIMEOUT_DEFAULT)) {
+ jsonString = "\"getTimeoutDefault\" : \"" + backlightProperties.timeoutDefault + "\", ";
+ return jsonString;
+ } else if(props.equalsIgnoreCase(IS_BRIGHTNESS_CONFIGURABLE)) {
+ jsonString = "\"isBrightnessConfigurable\" : \"" + backlightProperties.isBrightnessConfigurable + "\", ";
+ return jsonString;
+ } else if(props.equalsIgnoreCase(IS_ENABLED)) {
+ jsonString = "\"isEnabled\" : \"" + backlightProperties.isEnabled + "\", ";
+ return jsonString;
+ } else if(props.equals("all")) {
+ return backlightProperties.objToJsonString();
+ }
+ return "\"PropertyUndefined\":\"" + props + "\"";
+ }
+
+
+ }
+
+}
Oops, something went wrong.

0 comments on commit 6be4a08

Please sign in to comment.