Code Example‎ > ‎

Drawing


Create a new project

Choose File >>New>>Project under eclipse menu.
Then from the New Project Dialog, Select Droidget Wizard>>Project
Fill necessary fields including project name..etc.. and Click Finish
Project with the given name will appear in the Eclipse project explorer.

Edit config.xml

<?xml version="1.0" encoding="UTF-8"?>
<widget id="DrawingSample_1279678358797" version="1.0" width="500" height="300">
    <content src="index.html" type="text/html"/>
    <name>DrawingSample</name>
    <description>The sample of Drawing</description>
    <author url="http://www.gclue.jp">GClue</author>
    <icon src="icon.png"/>
    <license>(C)2010 GClue KK</license>
</widget>

Create a Javascript file

Under src folder, create another folder called ‘js’ and create a file called scripts.js under ‘js’ folder

  • Right click (Command click on Mac) on the Project name
  • Choose File >> New >> Folder and name it as js
  • Right click (Command click on Mac) on js foder , then File >> New >> File  and name it as scripts.js
function drawLine() {
var elem = document.getElementById('Line');
if (!elem || !elem.getContext) {
return;
}
var context = elem.getContext('2d');
if (!context) {
return;
}
context.strokeStyle = 'red';
context.lineWidth   = 1;
context.beginPath();
context.moveTo(50, 50);
context.lineTo(200, 200);
context.stroke();
context.closePath();
}

function drawSquare(){
var elem = document.getElementById('Line');
if (!elem || !elem.getContext) {
return;
}
var context = elem.getContext('2d');
if (!context) {
return;
}
context.fillStyle = 'blue';
context.fillRect(100, 100, 100, 100);
}


function drawCircle() {
var elem = document.getElementById('Line');
if (!elem || !elem.getContext) {
return;
}
  
var context = elem.getContext('2d');
if (!context) {
return;
}
  
context.strokeStyle = 'green';
context.lineWidth   = 2;
context.beginPath();
context.arc(150, 120, 50, 0, 360, false);
context.stroke();
context.closePath();
}

Edit 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>The sample of Drawing</title>
    <script type="text/javascript" src="js/script.js"></script>
</head>

<body bgcolor="white">
    <canvas id="Line" width="200" height="200"></canvas>
    <button onclick="javascript:drawLine();">Line</button>
    <button onclick="javascript:drawSquare();">Square</button>
    <button onclick="javascript:drawCircle();">Circle</button>
</body>

</html>

Deploy the Widget

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/ButtonSample.wgt">ButtonSample</a><br>
</body>
</html>

Preview

サブページ (1): More
ċ
DroidgetCircleExample.wgt
(1k)
ユーザー不明,
2010/09/03 2:06
ċ
DroidgetLineExample.wgt
(1k)
ユーザー不明,
2010/09/03 2:06
Comments