Thursday, July 3, 2014

Compatibility chart for java script libaries

BackBone

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
    <script src="http://ajax.cdnjs.com/ajax/libs/underscore.js/1.6.0/underscore-min.js"></script>
    <script src="http://cdnjs.cloudflare.com/ajax/libs/backbone.js/1.1.2/backbone-min.js"></script>

Sunday, June 15, 2014

How to read phonebook with phonegap from android

                function queryPhoneBook()
                {
// find all contacts field
var options = new ContactFindOptions();
options.filter="";
options.multiple=true;
var fields = ["name", "phoneNumbers"];
navigator.contacts.find(fields, onSuccess, onError, options);
                }

                function onSuccess(contacts) {
                //navigator.notification.alert(contacts.length);
                var j = 0;
                $.mobile.showPageLoadingMsg(true);
                //$("#userList").html('');
                for(var i=0; i < contacts.length ; i++)
                {
if( contacts[i].phoneNumbers == null )
continue;
                if(contacts[i].phoneNumbers.length > 0)
                {
                //navigator.notification.alert(contacts[i]);
                //var temp = contacts[i].displayName + "" + contacts[i].phoneNumbers[0].value;
        //navigator.notification.alert(temp);

var htmlData = '<li id="'+j+'"><a href="#"><h2>'+contacts[i].displayName+'</h2><p class="ui-li-aside">'+contacts[i].phoneNumbers[0].value+'</p></a></li>';
$("#userList").append(htmlData).listview('refresh');
j++;
        }
        }
        $.mobile.changePage($("#index"), { transition : "slide"});
$.mobile.hidePageLoadingMsg();
}

Thursday, June 5, 2014

Playing with digital Ocean

amazon ec2 seemed to be complecated though not so difficlut but I am trying didgital ocean now for all my home based research here is what i did today to setup a new instance of droplet and installed Lamp


passwd
adduser sandeep

visudo

# User privilege specification
root    ALL=(ALL:ALL) ALL
demo    ALL=(ALL:ALL) ALL

nano /etc/ssh/sshd_config
Port 4444

PermitRootLogin no
AllowUsers sandeep

sudo apt-get update
sudo apt-get install apache2

sudo apt-get install mysql-server libapache2-mod-auth-mysql php5-mysql
sudo mysql_install_db
sudo /usr/bin/mysql_secure_installation

sudo apt-get install php5 libapache2-mod-php5 php5-mcrypt

sudo nano /etc/apache2/mods-enabled/dir.conf 
change index.php

https://www.digitalocean.com/community/tutorials/how-to-set-up-multiple-wordpress-sites-using-multisite

Get the Mysql password

tail -1 /root/.my.cnf | awk -F'=' '{print $2}'
Setting Up Java

sudo apt-get install default-jre
sudo apt-get install default-jdk
sudo nano /etc/environment and append this line
JAVA_HOME=/usr/lib/jvm/java-7-openjdk-amd64
source /etc/environment
echo $JAVA_HOME

Installing SFTP/ProFtp

sudo apt-get update && sudo apt-get install proftpd
apt-get install openbsd-inetd
lrwxrwxrwx   1 root root    16 Sep 23 15:34 openlibs -> /opt/GLOBAL/libs
lrwxrwxrwx   1 root root    20 Sep 23 15:34 openservices -> /opt/GLOBAL/services


00 12 * * sat /home/root/monitoring/config/start/procmon.sh
00 12 * * sat /home/root/monitoring/config/stop/procmon.sh

CLASSPATH="/usr/java/bin:/home/s_gcm/gcmserver:/home/s_gcm/gcmserver/libs"
https://www.digitalocean.com/community/tutorials/how-to-configure-proftpd-to-use-sftp-instead-of-ftp
Setting up Smack library in Ubuntu
wget http://www.java2s.com/Code/JarDownload/xmlpull/xmlpull-xpp3-1.1.4c.jar.zip
http://www.java2s.com/Code/JarDownload/xmlpull/xmlpull-xpp3-1.1.4c.jar.zip
Setting up two domain names with DO
https://www.digitalocean.com/community/tutorials/how-to-set-up-multiple-wordpress-sites-on-a-single-ubuntu-vps

Setting up a subdomain e.g <blog> in this case


Lets say subdomain name is blog on zoogaru.com



sudo mkdir -p /var/www/blog.zoogaru.com/public_html
sudo chown -R www-data:www-data /var/www/blog.zoogaru.com/public_html
sudo chmod -R 755 /var/www

put all content with an index file at 
/var/www/blog.zoogaru.com/public_html/

cp /etc/apache2/sites-available/000-default.conf /etc/apache2/sites-available/blog.zoogaru.com.conf
vi /etc/apache2/sites-available/blog.zoogaru.com.conf

update ServerAdmin blog@zoogaru.com
add ServerName blog.zoogaru.com
update DocumentRoot /var/www/blog.zoogaru.com/public_html

last and final step:
sudo a2ensite blog.zoogaru.com
sudo service restart apache2
or
/etc/init.d/apache2 restart

create a CNAME record in your owned domain as
* => @ 
give 20-30 minutes to zone file to be propagated.

Using filters on JSON
$scope.selectedTransporter = $filter('filter')($rootScope.CACHE['TRANSPORTER'], $scope.record.transporter_id);

phpmyadmin upgrade =>

sudo add-apt-repository ppa:nijel/phpmyadmin;
sudo apt-get update;
sudo apt-get install phpmyadmin;

Sunday, February 23, 2014

Integrating Google ads for mobile into an android app

makesure you have ant debug/release runs well with your application root folder with google-play-services-lib and you have creted the adUnitID for Banners/InterstitialAd with an account for your android app to monitize (to show google ads in your app and make money)

Now in your application main file the class which is the etry point of your Activity or which extends CordovaACtivity you should (not necessarily true always) implement the Banners/InterstitialAd.

How to implement Banners


import the following packages

import com.google.android.gms.ads.AdRequest;
import com.google.android.gms.ads.AdSize;
import com.google.android.gms.ads.AdView;

declare variables to hold the objects

private static final String AdMob_banner_Ad_Unit = "GOOGLE_ADMOB_BANNER_ID";
private AdView m_adView; 

in  public void onCreate(Bundle savedInstanceState) function 
write the below code

    @Override
    public void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        super.init();
                
        // Set by <content src="index.html" /> in config.xml
        super.loadUrl(Config.getStartUrl());
        //super.loadUrl("file:///android_asset/www/index.html")
        
        m_adView = new AdView(this);
        m_adView.setAdUnitId(AdMob_banner_Ad_Unit);
        m_adView.setAdSize(AdSize.BANNER);
         
        LinearLayout layout = super.root;
        layout.addView(m_adView); 
        AdRequest request1 = new AdRequest.Builder().build();
        m_adView.loadAd(request1);
}

also update the other override methods as

    @Override
    public void onPause() {
    m_adView.pause();
      super.onPause();
    }

    @Override
    public void onResume() {
      super.onResume();
      m_adView.resume();
    }

    @Override
    public void onDestroy() {
    m_adView.destroy();
      super.onDestroy();
    }


To Implement InterstitialAd

import com.google.android.gms.ads.AdListener;
import com.google.android.gms.ads.AdRequest;
import com.google.android.gms.ads.InterstitialAd;

declare variables to hold the objects

private InterstitialAd m_interstitial;
private static final String AdMob_interstitial_Ad_Unit = "GOOGLE_ADDMOB_INTERSTITIAL_UNIT_ID";

in  public void onCreate(Bundle savedInstanceState) function 
write the below code

    @Override
    public void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        super.init();
        super.loadUrl(Config.getStartUrl());
        
        // Create the interstitial.
        m_interstitial = new InterstitialAd(this);
        m_interstitial.setAdUnitId(AdMob_interstitial_Ad_Unit);
        
        m_interstitial.setAdListener(new AdListener() {
            @Override
            public void onAdLoaded() {
                //super.onAdLoaded();
                displayInterstitial();
            }

            @Override
            public void onAdFailedToLoad(int errorCode) {
                //super.onAdFailedToLoad(errorCode);
            }
        });

     // Create ad request.
        AdRequest adRequest2 = new AdRequest.Builder()
        .build();

        // Begin loading your interstitial.
        m_interstitial.loadAd(adRequest2);         
}

 // Invoke displayInterstitial() when you are ready to display an interstitial.
    public void displayInterstitial() {
      if (m_interstitial.isLoaded()) {
     m_interstitial.show();
      }
    }

integrating google_play_service with phone gap android application

It was even very painful foe me while integrating the Google Admobs which requires google_play_services to be integrated ! here is my share of tricks how I solved the play services Build problem.

When you try to publish an app you have to create a release build for which either you have to create release build with below command

  • ant release
  • cordova build --release

If you have not built anytime the play service with ant
You get the following error !

D:\workspace\HTML5\Wordizy>ant debug/release
Buildfile: build.xml does not exist!
Build failed

to fix this (ant must have been setup)
copy the whole google-play-services_lib folder from ANDROID_SDK_PATH\extras\google\google_play_services\libproject\to your project root directory.
copy
build.xml
local.properties
project.properties
files from root folder/Cordova lib folder to google-play-services_lib folder

Change the project.properties file's project target to the right target (very important)

split.density=false
# Project target.
target=android-19 (important)
android.library=true

change android.library.reference.2=google-play-services_lib in your root/project project.properties file

Stand on the google-play-services-lib and in the cmd editor supply
android update project -p . (dot=current folder) you should not be getting any error
then supply the command
ant debug success
ant release success

Now you are done !

You can also call cordova build --release command at the root folder of the application and it should create a unsigned-release.apk file.

Friday, January 24, 2014

JqueryMobile very useful technique

Changing the text of a button at runtime
If you are trying to update the value of a button at run time then create the button with
<input type = "button" id="total_time" value= "Time : 00.00" class="ui-btn-right">
but not with <a href="" data-role="button">
You get the below error
 can not call method of button before initialization error.

Set the for attribute of the label to match the ID of the input so they are semantically associated and wrap them in a div with the data-role="fieldcontain" attribute to group them.

<div data-role="fieldcontain">
    <label for="password">Password Input:</label>
    <input type="password" name="password" id="password" value="" />
</div>

Grouping and dividing content

jQuery Mobile provides classes ui-bar and ui-body for subdividing and for visually grouping content.

Add class ui-bar to create a full-width heading or a separator between sections of content.
Additionally, classes ui-bar-[a-z] add the appropriate swatch from your theme.

Add class ui-body to visual group and/or emphasize a section of content.
Additionally, classes ui-body-[a-z] add the appropriate swatch from your theme.

<div id="are_you_lost" data-inline="true" align="center">
<h3 class="ui-bar ui-bar-b ui-corner-all" id="high_scrore_header">Are You Lost ?</h3>
 <div class="ui-body ui-body-b ui-corner-all">
<p>There is a keyboard for you at upper right corner !
  </br>Click it and start playing.</br></p>
  </div>
</div>

Creating a DialogBox like Popup

<div id="success_dialog" data-position-to="window" data-role="popup" data-history="false" data-transition="flip">
 <h3 class="ui-bar">Header </h3>
   <div class="ui-body ui-body-b">
  <p>This is a content
    </br>This is a content</br>
    </br>This is a content</br>
      </br></p>
                            </div>

</div>

This is a better example
<a href="#popupDialog" data-rel="popup" data-position-to="window" data-role="button" data-inline="true" data-transition="pop" data-icon="delete" data-theme="b">Delete page...</a>
<div data-role="popup" id="popupDialog" data-overlay-theme="a" data-theme="c" data-dismissible="false" style="max-width:400px;" class="ui-corner-all">
    <div data-role="header" data-theme="a" class="ui-corner-top">
        <h1>Delete Page?</h1>
    </div>
    <div data-role="content" data-theme="d" class="ui-corner-bottom ui-content">
        <h3 class="ui-title">Are you sure you want to delete this page?</h3>
        <p>This action cannot be undone.</p>
        <a href="#" data-role="button" data-inline="true" data-rel="back" data-theme="c">Cancel</a>
        <a href="#" data-role="button" data-inline="true" data-rel="back" data-transition="flow" data-theme="b">Delete</a>
    </div>
</div>

Creating grouped button

You can group buttons together and put them together in fotter/header e.g

<div data-role="controlgroup" data-type="horizontal" class="ui-btn-left">
<a href="quit.html" data-icon="delete" data-ajax="false" data-role="button">Quit</a>
<input type = "button" id="total_tries" value= "Tries : 0" >
</div>

Prevent ChangePage
-----------------
$(document).bind('pagebeforechange', function(e, data) {
    var to = data.toPage,
        from = data.options.fromPage;

    if (typeof to === 'string') {
        var u = $.mobile.path.parseUrl(to);
        to = u.hash || '#' + u.pathname.substring(1);
        if (from) from = '#' + from.attr('id');

        if (from === '#page1' && to === '#page3') {
            alert('Cannot change to page 3 from page 1');
            e.preventDefault();

            // remove active class on button
            // otherwise button would remain highlighted
            $.mobile.activePage
                .find('.ui-btn-active')
                .removeClass('ui-btn-active');
        }          
    }
});


How to display a scrollbar in a div  This is best way to display more informations in a Game

$(document).on("pageinit","#pageone",function(event){

var heightOfWindow = $(window).height();
var totalHeightOfContents = $(document).height();
if(heightOfWindow <= totalHeightOfContents){
var contentIDHeight = $('#content_id').height();
var infoDivIDHeight = $('#info').height();
var heightExcludingInfo = contentIDHeight - infoDivIDHeight;
var availableHeightForInfo = heightOfWindow - heightExcludingInfo;
var test = availableHeightForInfo - 420;
$('#info').height(test);
}
});