Layar tutorial part 2
The first tutorial, we went through the steps to create a simple layer.
In this tutorial, we are going to explain how to include actions in this layer
Add a new table called "ACTION_Table" to the database.
- CREATE TABLE IF NOT EXISTS `ACTION_Table` (
- `poiID` varchar(255) NOT NULL,
- `label` varchar(30) NOT NULL,
- `uri` varchar(255) NOT NULL,
- `autoTriggerRange` int(10) default NULL,
- `autoTriggerOnly` tinyint(1) default NULL,
- `ID` int(10) NOT NULL,
- `contentType` varchar(255) default 'application/vnd.layar.interna
l', - `method` enum('GET','POST') default 'GET',
- `activityType` int(2) default NULL,
- `params` varchar(255) default NULL,
- `closeBiw` tinyint(1) default '0',
- `showActivity` tinyint(1) default '1',
- `activityMessage` varchar(255) default NULL,
- PRIMARY KEY (`ID`)
- ) ENGINE=MyISAM DEFAULT CHARSET=utf8;
Create a new function to retrieve actions
The new features include a video and MP3 playback, call and email.
- function getActions( $poi, $db ) {
- $sql_actions = $db->prepare( " SELECT label,
- uri, autoTriggerRange, autoTriggerOnly,
- contentType, method, activityType, params,
- closeBiw, showActivity, activityMessage
- FROM ACTION_Table WHERE poiID = :id " );
- $sql_actions->bindParam( ':id', $poi['id'], PDO::PARAM_INT );
- $sql_actions->execute();
- $count = 0;
- $actions = $sql_actions->fetchAll( PDO::FETCH_ASSOC );
- if ( empty( $actions ) ) {
- $poi["actions"] = array();
- } else {
- foreach ( $actions as $action ) {
- $poi["actions"][$count] = $action;
- $paramsArray = array();
- if ( substr_count( $action['params'],',' ) ) {
- $paramsArray = explode( ",", $action['params'] );
- }
- else if( strlen( $action['params'] ) ) {
- $paramsArray[0] = $action['params'];
- }
- $poi["actions"][$count]['params'] = $paramsArray;
- $poi["actions"][$count]['activityType'] = changeToInt $poi["actions"][$count] ['activityType'] );
- $poi["actions"][$count]['closeBiw'] = changeToBool( $poi["actions"][$count]['closeBiw'] );
- $poi["actions"][$count]['showActivity'] = changeToBool( $poi["actions"][$count]['showActivity'] );
- $poi["actions"][$count]['autoTriggerRange'] = changeToInt( $poi["actions"][$count]['autoTriggerRange'] );
- $poi["actions"][$count]['autoTriggerOnly'] = changeToBool( $poi["actions"][$count]['autoTriggerOnly'] );
- $count++;
- }
- }
- return $poi["actions"];
- }
We use a function called changeToBool to convert a Tinyint value to a Boolean value
and changeToInt to convert string value to integer.
- function changeToBool( $value_Tinyint ) {
- if ( $value_Tinyint == 1 )
- $value_Bool = TRUE;
- else
- $value_Bool = FALSE;
- return $value_Bool;
- }
- function changeToInt( $string ) {
- if ( strlen( trim( $string ) ) != 0 ) {
- return (int)$string;
- }
- else
- return NULL;
- }
Modify the Gethotspots function
$poi["actions"
If you're doing it right, you should see something like this:
This is the end of the second tutorial. In the next part, we are going to discuss how to implement 2d and 3d objects in a layer.
New tutorials from Helloandroid
Recent Apps
Android on Twitter
-
@Idevicegazette (iDevice Gazette)
GSM-to-Skype bridge lets you lose those roaming fees http://bit.ly/lbRJeh #android
11 years 45 weeks ago -
@tommy_banane (tom b.)
RT @AndroidFavorite: #Android New Desktop Android Market Is Live, Adds Several New Features http://zorr0.nl/lFwXNz
11 years 45 weeks ago -
@dwilliams5 (Dennis Williams)
just completed a runtastic run of 3.02 km in 40 min 11 s with #runtastic #Android App: http://tinyurl.com/5tvrpe3
11 years 45 weeks ago -
@S_Pinz (Spinz!)
RT @Androidheadline: Out of box #LG Optimus 3D got Quadrant 2420 score. Thanks @blink_c #io2011 #android http://twitpic.com/4whkdz
11 years 45 weeks ago -
@tayaitapps (Taya IT)
Next Google TV Looks A Lot Like Android http://t.co/dvlTim3 via @alleyinsider #google #apple #android #tv #honeycomb
11 years 45 weeks ago
Poll
Useful resources
Android Development Projects
- iOS/Android Developer to take older Games and bring them Current
- Android apps developer - need to finish urgent.
- Buliding MobileApp For onlie order
- looking for android APP developers
- Create an ecommerce app
- text-to voice for smartphones IOS - GOOGLE - HARMONY - AND ALEXA
- Optimize Images on App
- Create small feature with drag-drop text for Android
- Scouting for advanced website and Mobile apps developers. Potential Long-term contract.
- BLACK SCREEN