Code Example‎ > ‎

Appconfig


Appconfig is used to store data in persistent storage. 

Create a new project

Choose, File --> new project --> project 
Then select Droidget wizards --> project from New Project dialog  
Fill out Project name field, etc  In the Feature section , Click on Add and select Appconfig feature "http://bondi.omtp.org/api/appconfig".  
Then click Finish .
Droidget project with the given name will be created and displayed in the project explorer.

Config.xml

After finished creating project, Bondi Feature <feature name="http://bondi.omtp.org/api/appconfig" required="true"/> will be appeared in the config.xml file as follows.

config.xml
<?xml version="1.0" encoding="UTF-8"?>
<widget id="AppconfigSample_1279635473326" version="1.0" width="300" height="200">
    <content src="index.html" type="text/html"/>
    <name>AppconfigSample</name>
    <description>The sample of AppConfig</description>
    <author url="http://www.gclue.jp">GClue</author>
    <icon src="icon.png"/>
    <license>(c)2010 GClue KK</license>
    <feature name="http://bondi.omtp.org/api/appconfig" required="true"/>
</widget>

Create Javascript File

create a new folder called js and under that folder create a new file and name it as "script.js".
Then add the following functions.

js/script.js
var KEY = "common.sample0";

// Save
function saveData(mMsg){
    bondi.appconfig.set(KEY,mMsg);
    alert("save data");
}

// Load
function loadData(){
    var value = bondi.appconfig.get(KEY);
    alert("load data:"+value);
}

Edit index.html

Change the index.html file content as follows. 

index.html
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <meta http-equiv="Content-Style-Type" content="text/css" />
    <meta http-equiv="Content-Script-Type" content="text/javascript" />
    <title>AppconfigSample</title>
    <script type="text/javascript" src="js/script.js"></script>
</head>
<body>
    <button onclick="javascript:saveData('TEST');">Save</button>
    <button onclick="javascript:loadData();">Load</button>
</body>
</html>

Deploy the Widget

Selecte the project from Project Explorer and Click Droidget>>Packaging. Now save and deploy the project
  • From the eclipse menu select Droidget --> packaging
  • Then Droidget-->install packaging
Or 
  • upload the Widget to web server and update the download.html file as follows. Then access the download.html from the smart phone and install the widget from URI.

Download.html
<html>
<head>
    <title>Download</title>
</head>
<body>
    <a href="droidget://www.example.com/AppconfigSample.wgt">AppconfigSample</a><br>
</body>
</html>

Preview

Comments