WebOSDev - Programming has just evolved

The online blog for the webOS developer community you can find everything you need here to get a strong start developing applications for the webOS platform

avoiding virtual keyborad popup on textfield in Pre 3

Posted by codesos Monday, July 11, 2011 2 comments

courtesy of Doug Reeder:

Mojo presumes there's a keyboard present, and so sets keyboard focus on the first textfield in a scene, unless you call SceneController.setInitialFocusedElement(null). Many developers don't check whether their app is running on a TouchPad,

Hi from NYC!!

Posted by codesos Saturday, November 20, 2010 0 comments


Hi All ,

Now I'm in the Webos 2 Developer day in NYC , Having the time of my life.


CYA

Change background image of a palm dialog

Posted by codesos Thursday, June 24, 2010 0 comments

Ever wanted to change the background image of a palm dialog but all you could accomplish is an ugly rectangle inside of the Palm's Dialog;

Here is your solution:

In your CSS do this:

.palm-dialog-box

{

-webkit-border-image: url(../images/backdrop-dark.png) 32 24 32 24 stretch stretch;

}
 
where backdrop-dark.png is your image.
 
Enjoy

Move FilterField from top of scene

Posted by codesos Monday, April 5, 2010 2 comments



Tried to use FilterList widget with a view menu or a normal header? this is a problem because they  collided with the filter field once a letter is typed, because the filter field does not honor the height setting.

to over come it , add a class to your FilterListWidget and in the CSS do that:
.[Filter List Class] .filter-field-container {
    top: 0px;
    left: 0px;
    position: fixed;
    width: 100%;
    height: 100px;
    z-index: 0;
}

This will fix this issue.

Nice Ah?

How to Make SwipeToDelete Dynamic

Posted by codesos Saturday, April 3, 2010 0 comments



You have to declare in th attributes of the list swipeToDelete: true  to allow the list to delete items , but add this preventDeleteProperty:'noDelete'  also if you want the list to be able to determine which items can be deleted or not.

so for example:
var attributes =
{
    itemTemplate: 'food-filter-list/entry',
    swipeToDelete: true,
    preventDeleteProperty:'noDelete',
    reorderable: false,
    filterFunction: this.FilterList.bind(this),
    formatters:{Food_Item:this.formatName.bind(this),Points:this.formatNumber.bind(this)},
    delay: 500, //1 second delay before filter string is used
    disabledProperty: 'disabled'
 };

this.model = {disabled: false};

this.controller.setupWidget('filterlistID', attributes, this.model); 
this.filterlist = this.controller.get('filterlistID');


the default implementation allows delete of all the items.

Now if you want to allow an item not to be deleted :

entry = {Food_Item: $L(row.Portion + ConnectionWord + row.Food_Item), Points: row.Points,ItemObj:row,'noDelete':true};

this.FoodList[i] = entry;
this way you can dynamically determine which item can be deleted or not

cool , no?


Using scrollable log text box

Posted by codesos Sunday, February 21, 2010 0 comments

Want scrollable log trace or text edit? here's how:


HTML:
<div class="palm-group unlabeled" id="scrollID" x-mojo-element="Scroller">
        <div id="scrolling_contents">
        </div>
</div>

JS:
SETUP
this.modesModel = {scrollbars: true, mode: "vertical"},
    this.controller.setupWidget('scrollID', {}, this.modesModel);
    this.scroller = this.controller.get('scrollID');
    this.scrollStarting = this.scrollStarting.bind(this);
    this.controller.listen(this.scroller, Mojo.Event.scrollStarting, this.scrollStarting);


MyAssistant.prototype.scrollStarting = function(event) {
        event.scroller.addListener(this);
        Mojo.Log.info(new Date(), "scroll starting");           
    }

MyAssistant.prototype.AddLog= function(str,bClear)
{
   
   if(bClear==undefined){
        if(this.controller.get('scrolling_contents').innerHTML.length>0)
            this.controller.get('scrolling_contents').innerHTML+="<br />";
        this.controller.get('scrolling_contents').innerHTML+=str;       
    }
    else if(bClear==true)
    {
        this.controller.get('scrolling_contents').innerHTML=str;
    }

}


Magic , Isn't it?

AdMob.com integration

Posted by codesos 0 comments

Want to add professional advertisements to your palm pre applicatio?
It's as simple as 1,2,3



1 . go to  http://code.google.com/p/admob-webos/

download admob.js and place it in your application

2. HTML File:

<div id="admob_ad"></div>
3.
Initialize:


      AdMob.ad.initialize({
                      pub_id: '*********', // your publisher id get it from admob.com
                      bg_color: '#ccc', // optional background color, defaults to #fff
                      text_color: '#333' 
                      });


and for each time you want to display ad:

 AdMob.ad.request({
                        onSuccess: (function (ad)
                        {
                        Mojo.Log.info("**************** AdMob OK ");
                           // successful ad call, parameter 'ad' is the html markup for the ad                       
                            this.controller.get('admob_ad').insert(ad); // place mark up in the the previously declared div 
                               }).bind(this),    
                      onFailure: (function ()
                      { // no ad was returned or call was unsuccessful                       
                          Mojo.Log.info("**************** AdMob ERROr ");  
                       }).bind(this),
             });


That is all , Now start earning Money!!

Integrate with Flot Graph system using Webos

Posted by codesos Tuesday, January 12, 2010 0 comments

Want to be able to produce HI END graphs like this?:



It's very simple:

1. go to http://code.google.com/p/flot/ and download the package.
2. Extract it and add it to your project(just add the entire folder)
3. Add to the sources.json the relevant source you are going to use
(I.E {"source": "javascript/flot/jquery.js"},{"source": "javascript/flot/jquery.flot.js"}
4. Add new Scene or use exsiting one
5. In the HTML add the tag:
<div id="placeholder" style="top:20px;left:10px;width:300px;height:300px;"></div>
6. In the source file you can use this div:

var d1 = [];


for (var i = 0; i < 14; i += 0.5)
d1.push([i, Math.sin(i)]);
var d2 = [[0, 3], [4, 8], [8, 5], [9, 13]];
// a null signifies separate line segments
var d3 = [[0, 12], [7, 12], null, [7, 2.5], [12, 2.5]];
$.plot($("#placeholder"), [ d1, d2, d3 ],{ grid: { color: "#100" } });

Thats all!!

Howto interact between a wordpress site and webos

Posted by codesos Saturday, January 9, 2010 0 comments


Evere wanted to login to a wordpress type of site? here it is







1. load a PHP file to your site called myLogin.php

This file will act as your server side and it's job is to get the request wfom you app , do the login operation and returnt status



write the folowings inside the php file:



<?php

require( dirname(__FILE__) . '/wp-load.php' );

function login() {

$result = wp_signon();

if(!$result->data)

return "<br />Incorrect username or password.";

else

return TRUE;

}

echo login();

?>




2. in your webos application create a scene:

The idea is to send the PHP file the request with parameters

create username and password widget , emit a buttun press for login and write this:



ComunityAssistant.prototype.AjaxLogin = function(user,pwd)

{

var url = '[your site]/SERVICE-login.php';

try {

var request = new Ajax.Request(url, {

method: 'post',

parameters: {log: user, pwd: pwd},

onSuccess: this.AjaxLoginOK.bind(this),

onFailure: this.AjaxLoginError.bind(this)

});

}

catch(e)

{

Mojo.Log.info('Failed to get Ajax response');

Mojo.Log.info(e);

}

}





ComunityAssistant.prototype.AjaxLoginOK = function(response)

{

try

{

if (response.responseText.search("Incorrect username or password") != -1)

{

// error

}

else

{

if (response.responseText.search("1") != -1)

{

// OK

}

}

}

catch(e)

{

Mojo.log.error(e);

}

}







ComunityAssistant.prototype.AjaxLoginError =function(transport)

{

var t = new Template($L("Error: Status #{status} returned from AJAX Google search."));

var m = t.evaluate(transport);

this.controller.showAlertDialog

(

{

onChoose: function(value) {},

title: $L("Error"),

message: m,

choices:[

{label: $L('OK'), value:'ok', type:'color'}

]

}

);

}





there you go!!


User agents must consider statements that use the BEGIN, COMMIT, and ROLLBACK SQL features as being unsupported (and thus will mark them as bogus), so as to not let these statements interfere with the explicit transactions managed by the database API itself.

Activating one app menu for all the scenes

Posted by codesos Tuesday, November 3, 2009 0 comments

Want to define one app menu , Handle it once but acrivate it from all scenes?

Here is the way

1. Define the  menue modal and att as globals in the stage scene

glob = {};


glob.MenuAttr = {omitDefaultItems: true};



glob.appMenuModel = {

               visible: true,

               items: [

                           Mojo.Menu.editItem, //must


                            {label: $L("Preferences..."), command: "do-Prefs"},

                            {label: $L("Help"), command: "do-about"}


                          ]

                    };

define the handle command in the same stage scene :

StageAssistant.prototype.handleCommand = function(event)
{
                      var currentScene = Mojo.Controller.stageController.activeScene();

                      if (event.type == Mojo.Event.commandEnable) {

                                  if ((event.command == "do-Update")) {

                                            event.preventDefault();
                                   }

                       }

else {

           if(event.type == Mojo.Event.command) {

               switch(event.command) {

                     case "do-about":

                         Mojo.Controller.stageController.pushScene('support');

                     break;

                     case "do-Prefs":

                          Mojo.Log.info("do-Prefs");

                         Mojo.Controller.stageController.pushScene("preferences");

                     break;

                  case "do-Update":

                  break;

           }

     }

}
}

now in every scene's setup function do this:

this.controller.setupWidget(Mojo.Menu.appMenu, glob.MenuAttr, glob.appMenuModel);


Done!!

How to capture click on itemTemplate on FilterList

Posted by codesos Thursday, October 15, 2009 0 comments

Here are some tips regurding capturing "tap" events on itemTemplate on FilterList.

1. Define HTML Mojo object

<div x-mojo-element="FilterList" class="filterlistClass" id="filterlistID" x-mojo-focus-highlight="true"></div>

2. Difine the "filterlistID" in the .js file.

var attributes =
{
itemTemplate: 'food-filter-list/entry',
swipeToDelete: bSwipeToDelete,
reorderable: false,
filterFunction: this.list.bind(this),
formatters:{Food_Item:this.formatName.bind(this),Points:this.formatNumber.bind(this)},
delay: 500, //1 second delay before filter string is used
disabledProperty: 'disabled'
};
this.model = {
disabled: false
};


this.controller.setupWidget('filterlistID', attributes, this.model);
this.tapped = this.tapped.bindAsEventListener(this);
Mojo.Event.listen(this.controller.get('filterlistID'), Mojo.Event.listTap, this.tapped);


3. Int the entry.html file defined for the itemTemplate define


<div class="palm-row" x-mojo-tap-highlight="momentary">
<div class="palm-row-wrapper">
<table width="100%">
<tr>
<td width="90%"><div class="title"><font face="Comic Sans MS, Arial, Impact" size="3">
#{Food_Item} has the value of #{Points} DC Points
</font></div></td>
<td width="10%">
<div class="palm-button InfoBtnCL" id="InfoBtnID"></div>
</td>
</tr>
  <tr>
<div id='AdditionalInfoID'>
</div>
</tr>
</table>
</div>
</div>
</div>


now we want to capture the click event of the InfoBtnID button right?

4. in the .js file tapped function
FoodFilterListAssistant.prototype.tapped = function(event)
{
       Mojo.Log.info("*************** Tapped " + event.originalEvent.target.id );
if(event.originalEvent.target.alt!=undefined &&  event.originalEvent.target. id == "InfoBtnID")
{
//code for clicking on the InfoBtnID button
}
else
{
              //code for tapping the list item
        }
}

The FloatPicker

Posted by codesos 13 comments

Ever thought about why the mojo SDK doesn't contain a  floatPicker?
So did I.
With a little code changes and some thought  i present to you:


Usage:

HTML :

<div id="FloatPickerID" x-mojo-element="FloatPicker"></div>

JS :

****.prototype.setup = function() {
    attributes = {
            label:    'Float', // the label next to the control
            min: 0, // minimum value
            max: 10, // maximum value
            modelProperty:    'value',
                Interval:0.1 //the "jumps" of the value , use integers to display as integerPicker
            };
        this.model = {
            value : 0.1, // current value
                      disabled : false // use this to set enable/disable of the control
        }
        this.controller.setupWidget('FloatPickerID', attributes, this.model);
}

This FloatPicker is a subclass of IntegerPicker so it uses the same attributes and model , with the addition of  Interval attribute which determain the value "jumps" of the control.

to change the control's enable disable state use:

this.pickerModelNewPoints.disabled = true; // or false


this.controller.modelChanged(this.model);

Enjoy






v 1.2 comes with 

.palm-dialog-box .label.left.mv-picker-label {
display: none;
}

in global-widget-mvpicker.css


to overcome this changed in your css:

.palm-dialog-box .label.left.mv-picker-label {
display: block;
}


SDK version 1.2 issue

The problem happens when you try to call those dialogs from within a dialog created via

this.controller.showDialog(...) with preventCancel: true.
changing it to preventCancel: false Fixed the problem.



add { "escapeHTMLInTemplates": false } in framework_config.json file.

v1.2 rollback fix on XP

Posted by codesos Thursday, October 1, 2009 1 comments




1. Extract the msi file from the executable (run the executable after printing "extracting " and before the first next , you'll see in the %temp% folder this file "5dae9320.msi".
2. open it on orca (if you don't know what it is go here http://www.juergentreml.de/archives/802)
3. search for InstallUMDFXP.
4. remove the row in custo action.
5. save and run the MSI.
worked for me.

Avoid auto focus for integer picker on scene

Posted by codesos Tuesday, September 29, 2009 0 comments




in the scenes setup function add this:

this.controller.setInitialFocusedElement(null);

Simple....

Introducing new and improved v0.8.1

Posted by codesos Monday, September 28, 2009 0 comments



Graphs!! - Point,Bar and line graph to allow you to analyze your weight progress and food consumption.
  1. Favorites - you can now add your favorite food into a section in the database.
  2. Quantity control - you can now enter the amount of food you have consumed for each food item.
  3. Weight Update - you can now update your weight(once a day) and look at the progess using the graphs.
  4. Calculator improvements - You can now enter food description to freely calculated food.
  5. Help screen on each major scene.
  6. Brand new UI ,Using view menu buttons.
  7. Bug fixing.

diet control application

Never before controlling your weight was any easier





Change The width of Radiobutton

Posted by codesos Wednesday, September 23, 2009 0 comments

Tried to do that and failed?
Well it's a bug in the 191.14 SDK

Here's a workaround

in your .css file place this


.palm-radiobutton {
   min-width: 10px;
}

Now change the width

.[YourControl's Class]
{
    width:230px;
 }