Saturday, November 15, 2014

Why I couldn't do what an UXD proposed me to do in my android app

Don’t shoot a programmer, He draws as he can..

Things to keep in mind with UI Assets.. 

Scale and Size of Image and Icons. For every icon/image that we would use strictly follow android UI guidelines so we need 5 size for icons with 2:3:4:6:8 scaling ratio. This means the baseline (MDPI) asset is 48x48 px, and the high-density(HDPI) asset should be 1.5x the baseline at 72x72 px, and the x-high density (XHDPI) asset should be 2x the baseline at 96x96 px, and so on.


So we must create icons/image with above scalling. The easiest thing for a developer to use http://romannurik.github.io/AndroidAssetStudio/  link.
Howto’s : If we have the highest density and scaled image we can easily create assets with the above link for Luncher/Action bar/Notification/Generic Icons. This tool will create all necessary set of icons for all device size. Note : Create an  image/icon with highest density/scale with GIMP or adobe illustartor first then use them as the input for the above tools.
Some Take away :

Splash Screen  – I couldn’t implement it cause the screen-shot that the UXD gave me was not covering the phone width, it was little ugly when I tried to stretch and I didn’t have screen shot for the Icons that I had created with a replacement for the icons shared by him, for the helper views too. So skipped for this release (I liked the proposal, if not today some day I will incorporate with the app)

SearchWidget – I am using the default android search widget in which the search_icon comes in the left side I tried a lot, did some search but could not make it possible to keep it in right side. (I could have achieved with my customized search widget which would take me few days to build !, Why ? if I make my customized control again that should follow android UI specifications which would need me to create controls for every device size, everycolor, 9 patch image, icons- which would be cost me around a week of time, its lack of time that forced me to keep it still hidden and pops up from a menu click).

Location Icons – Customized location Icons again has to be for different device density. And the location icon given to me was eye catchy though I had to use the default map icons. Icons were left anchored but my requirement was for centered gravity.

Theme with the app color : It took me a few days to find out the best theme color that suit my app. I did a lot of experiement with themes. There are still some controls, for which its hard to create theme specific controls e.g android switch !  So I am still living with the default android theme controls.

Refer : The links that I refer while creating my icons for my app / webpages.

Geo-Pulse list icons – Again the asset that he shared was awesome but I couldn’t generate icons using http://romannurik.github.io/AndroidAssetStudio/icons-generic.html link. We must generate all icons with the android studio as it ensures that we have the right size and scaled icons. But remember any given icon by a designer should be with the highest size i.e  192px/192px (if not minm should be atlest 96px / 96px) so that you can create smaller and bigger icons wihtout loosing the quality. The most important thing is any icon given by a designer should be transparent in nature without which you cant create icon for different devices using the above links. So I had to create my own icons with cliparts that collected from web which are holo and tranparent and matched the UXD’s proposals.

Luncher Icon :Luncher icon should be created from a 512px / 512px Image without which you will loose the quality again  for different devices. Just a small note, all the assets name should be in small letters and underscores (no hiphens) .


This is just for book keeping of all that I did for ZPulse which might help for an enthusiastic android programmer and ease him for beautification for his/her app.

Saturday, October 4, 2014

How to set events on EditTextPreference dialog like longpress

Spent a lot on working on the preferences settings in android google also couldn't help me at last I could do some experiement and made it work.

Goal : Open the Contacts and fill the phone number in one of the inputs for Preferences.

e.g You want to set the Number only Edit text

public class SettingsFragment extends PreferenceFragment {
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        addPreferencesFromResource(R.xml.preferences_activity);
        
        Preference preference = findPreference("EMERGENCY_PH_NO") ;
        EditTextPreference editTextPreference = (EditTextPreference) preference;
    }
}

now its easy just grab the handle and set the longpress event

All the code is given below

public class SettingsFragment extends PreferenceFragment {

EditText m_emergency_number = null;
final int EMERGENCY_CONTACT_PICK = 1337;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        addPreferencesFromResource(R.xml.preferences_activity);
        
        Preference preference = findPreference("EMERGENCY_PH_NO") ;
        EditTextPreference editTextPreference = (EditTextPreference) preference;
        //TextView TextView = (TextView) editTextPreference.getEditText();
        m_emergency_number = (EditText) editTextPreference.getEditText();    
        m_emergency_number.setOnLongClickListener(new OnLongClickListener() {
@Override
public boolean onLongClick(View v) {
// TODO Auto-generated method stub
openContact(EMERGENCY_CONTACT_PICK);
return true;
}
});
    }    
    
    void openContact(int who)
{
Intent intent = new Intent(Intent.ACTION_PICK,ContactsContract.Contacts.CONTENT_URI);
intent.setType(Phone.CONTENT_TYPE); // Show user only contacts w/ phone numbers
        startActivityForResult(intent, who);
}
    
    @Override
    public void onActivityResult(int requestCode, int resultCode, Intent aData) {
    // TODO Auto-generated method stub
    if (resultCode == Activity.RESULT_OK) 
    {
       Uri contactUri = aData.getData();
       //Intent intent = new Intent(Intent.ACTION_GET_CONTENT,contactData);
           //startActivityForResult(intent, 1336);
       String[] projection = {Phone.NUMBER};
       
       Cursor cursor = getActivity().getContentResolver().query(contactUri, projection, null, null, null);
            cursor.moveToFirst();

               // Retrieve the phone number from the NUMBER column
               int column = cursor.getColumnIndex(Phone.NUMBER);
               String number = cursor.getString(column);
               if(EMERGENCY_CONTACT_PICK == requestCode)
               {
                m_emergency_number.setText(number);
               }
    }
    }
}

Wednesday, September 24, 2014

android layout tricks

Merging a image with map

<?xml version="1.0" encoding="utf-8"?>
<merge xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<fragment
          android:id="@+id/map"
          android:layout_width="match_parent"
          android:layout_height="match_parent"
          android:name="com.google.android.gms.maps.MapFragment"/>

          <RelativeLayout
    android:id="@+id/rl"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    >

    <ImageButton
        android:id="@+id/icon"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentRight="true"
        android:layout_alignParentTop="true"
        android:layout_marginTop="20dp"
        android:
        android:src="@drawable/star" />

</RelativeLayout>
</merge>

Actionbar theming
-------------------------
http://jgilfelt.github.io/android-actionbarstylegenerator/#name=example&compat=sherlock&theme=light&actionbarstyle=transparent&texture=0&hairline=0&neutralPressed=1&backColor=E4E4E4%2C100&secondaryColor=D6D6D6%2C100&tabColor=9c0%2C100&tertiaryColor=690%2C100&accentColor=6ad869%2C100&cabBackColor=FFFFFF%2C100&cabHighlightColor=33B5E5%2C100

Sunday, September 21, 2014

All about signing the apk and its effect in google play

  1. Generate a private key using keytool. For example:
    $ keytool -genkey -v -keystore my-release-key.keystore-alias alias_name -keyalg RSA -keysize 2048 -validity 10000
    This example prompts you for passwords for the keystore and key, and to provide the Distinguished Name fields for your key. It then generates the keystore as a file called my-release-key.keystore. The keystore contains a single key, valid for 10000 days. The alias is a name that you will use later when signing your app.
  2. Compile your app in release mode to obtain an unsigned APK.
  3. Stand on google_play_services first then run below commands
    android update lib-project --path .
    ant clean
    ant release

    stand on your project root folder
    android update lib-project --path .
    ant clean
    ant release

    make sure your project file is updated with
    android.library.reference.2=../../Android/sdk/extras/google/google_play_services/libproject/google-play-services_lib
  4. Sign your app with your private key using jarsigner:
  5. $ jarsigner -verbose -sigalg SHA1withRSA -digestalg SHA1-keystore my-release-key.keystore my_application.apk alias_name
    This example prompts you for passwords for the keystore and key. It then modifies the APK in-place to sign it. Note that you can sign an APK multiple times with different keys.
  6. Verify that your APK is signed. For example:
    $ jarsigner -verify -verbose -certs my_application.apk
  7. Align the final APK package using zipalign.
    $ zipalign -v 4 your_project_name-unaligned.apk your_project_name.apk
    zipalign ensures that all uncompressed data starts with a particular byte alignment relative to the start of the file, which reduces the amount of RAM consumed by an app
  8. How to check your details in the keystore 
  9. keytool -list -keystore .keystore
  10. keytool -list -keystore .keystore -alias foo
    1. List all info ::
    keytool -list -v -keystore android-release-key.keystore
How to find that debug SHA1 ley to be used by Android MAP key

keytool -list -v -keystore C:\Users\<username>\.android\debug.keystore
password : android

keytool -exportcert -alias androiddebugkey -keystore C:\Users\ssaho3\.android\debug.keystore -list -v

Friday, September 19, 2014

websites building references

http://www.layoutit.com/
https://bootstrapbay.com/blog/bootstrap-editors/
https://css-tricks.com/perfect-full-page-background-image/
http://nicolasgallagher.com/css-background-image-hacks/
http://www.minimit.com/articles/solutions-tutorials/bootstrap-3-responsive-columns-of-same-height
Ready made themes
---------------------------
http://premium.wpmudev.org/blog/30-top-quality-free-minimalist-and-stunning-wordpress-themes/
http://www.wpexplorer.com/pytheas-free-wordpress-theme/
https://wordpress.org/themes/tags/one-column
http://theme.wordpress.com/themes/features/one-column/
http://www.wpexplorer.com/pytheas-free-wordpress-theme/
http://speckyboy.com/2014/05/27/free-bootstrap-3-templates/
http://speckyboy.com/2014/12/08/jquery-plugins-2014/
http://plugins.adchsm.me/slidebars/index.php#download

Plugins
------------
http://tutorialzine.com/2013/04/50-amazing-jquery-plugins/
https://css-tricks.com/text-blocks-over-image/
http://nick-jonas.github.io/windows/
http://joelb.me/scrollpath/
http://www.seanmccambridge.com/tubular/
http://buildinternet.com/project/supersized/download.html
http://vegas.jaysalvat.com/
http://tutorialzine.com/2012/06/quick-tip-fullscreen-backgrounds/

Web Color theme and pallet choosers
------------------------------
http://www.colorzilla.com/
kuler.adobe.com
http://paletton.com
http://www.google.com/design/spec/style/color.html#color-ui-color-application
http://pixabay.com/en/
http://apps.pixlr.com/editor/

Logo : 250/100 px
http://ocpsoft.org/tutorials/regular-expressions/java-visual-regex-tester/
http://ocpsoft.org/opensource/guide-to-regular-expressions-in-java-part-1/
http://www.mobyaffiliates.com/blog/how-to-promote-your-ios-and-android-mobile-apps/

For android
-------------
http://romannurik.github.io/AndroidAssetStudio/index.html
http://jgilfelt.github.io/android-actionbarstylegenerator/
http://android-holo-colors.com/
https://developer.android.com/distribute/tools/promote/device-art.html
http://www.norio.be/android-feature-graphic-generator/
http://www.cs.dartmouth.edu/~campbell/cs65/lecture24/lecture24.html

Theming a searchview's autocomplete is tricky as it looks black !! from Theme.Holo.Light.DarkActionBar
This is what you need to do

<!-- this style is only referenced in a Light.DarkActionBar based theme -->
    <style name="Theme.Zpulse.Widget" parent="@android:style/Theme.Holo">
        <item name="android:popupMenuStyle">@style/PopupMenu.Zpulse</item>
        <item name="android:dropDownListViewStyle">@style/DropDownListView.Zpulse</item>
        <item name="android:autoCompleteTextViewStyle">@style/AutoCompleteTextViewAppTheme</item>
    </style>

 <style name="AutoCompleteTextViewAppTheme" parent="android:Widget.Holo.Light.AutoCompleteTextView">
      <item name="android:dropDownSelector">@drawable/apptheme_list_selector_holo_light</item>
   <item name="android:background">@drawable/apptheme_edit_text_holo_light</item>
  </style>

Promote:
On launch date, you can also consider submitting your press release to sites like PRWeb  There’s no shortage of Press Release submission websites but definitely go for quality, not quantity.
http://www.rahuljiresal.com/2014/02/user-location-on-android/

LogoDesign
--------------
http://www.logogarden.com/

Saturday, September 6, 2014

Integrating php-mailgun for auth user

Follow : https://github.com/mailgun/mailgun-php


Install curl php as below
sudo apt-get install curl libcurl3 libcurl3-dev php5-curl
restrat the apache server.
sudo service apache2 restart



Github Most frequent command

git push origin master
git tag -a v1.4 -m 'my version 1.4'
git push origin --tags

Go back to last version
git reset --hard HEAD

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);
}
});

Tuesday, January 21, 2014

JqueryMobile Headers Footer Navigation Bars

Create own custom Header/Fotter Bars

<div data-role="footer" class="ui-bar">
<a href="index.html" data-role="button" data-icon="plus">Add</a>
<a href="index.html" data-role="button" data-icon="arrow-u">Up</a>
<a href="index.html" data-role="button" data-icon="arrow-d" class="ui-btn-right">Down</a>
</div>

Note that .ui-bar should not be added to header or footer bars that span the full width of the page


To Create FullScreen Headers which goes away in fullscreen mode
<div data-role="header" data-fullscreen="true">

Alignment and grouping
To align all elements center in the header/footer use alighn="center" style
<div data-role="header" align="center" data-position="fixed">

use data-role="controlgroup" for grouping the buttons in headers or footers

<div data-role="footer" id="id_footer" data-position="fixed">
<div data-role="controlgroup" data-type="horizontal">
<input type = "button" id="total_tries" value= "Tries : 0">
<input type = "button" id="total_giveup" value= "GiveUp">
</div>
<input type = "button" id="total_time" class="ui-btn-right">
</div>

Navbar
A navbar is coded as an unordered list of links wrapped in a container element that has the data-role="navbar" attribute. This is an example of a two-button navbar:

<div data-role="navbar">
 <ul>
  <li><a href="a.html">One</a></li>
  <li><a href="b.html">Two</a></li>
 </ul>
</div><!-- /navbar -->

Navbar in Headers
If you want to add a navbar to the top of the page, you can still have a page title and buttons. Just add the navbar container inside the header block, right after the title and buttons in the source order.

Persistent navbar
There is also a persistent navbar variation that works more like a tab bar that stays fixed as you navigate across pages. To tell the framework to apply the persistent behavior, add the same data-id attribute to the header and/or footer of all HTML pages in the navigation

<div data-role="footer" data-id="foo1" data-position="fixed">
 <div data-role="navbar">
  <ul>
   <li><a href="a.html">Info</a></li>
   <li><a href="b.html">Friends</a></li>
   <li><a href="c.html">Albums</a></li>
   <li><a href="d.html">Emails</a></li>
  </ul>
 </div><!-- /navbar -->
</div><!-- /footer -->

To set the active state of an item in a persistent toolbar, add class="ui-btn-active ui-state-persist" to the corresponding anchor.
 
<li><a href="a.html" class="ui-btn-active ui-state-persist">Info</a></li>


Saturday, January 18, 2014

Creating an Application using PhoneGap (Cordova) with target android

Install Node js will install npm and other necessary component for phonegap utility
Install PhoneGap : npm install -g phonegap
Install Cordova : npm install -g phonegap

Go to Your Workspace Directory and Create a cordova project

cordova create CowsBulls com.zoogaru.games CowsBulls -d

-d option displays information about its progress.

It Creates following forlders

.cordova
merges
platforms --- all added platform code goes here..
plugins --- all installed plugins sits here
www --- root directory for the application assets like css, img, html, js present

WWW Folder
subdirectory houses your application's home page, along with various resources under cssjs, and img, which follow common web development file-naming conventions

Setting up for Android
Pre-requiste -- Android platform is available and emulator device setup is done

Set up environment variables
Create A UserVariable ANDROID_TOOLS = D:\Android\sdk\platform-tools;D:\Android\sdk\tools
Add it to Path variable = PATH;ANDROID_TOOLS

Install Java SDK and set path unless java runs from  command line

Install ant from below link zip version or which ever is applicable for your os
http://ant.apache.org/bindownload.cgi
Follow instructions at http://ant.apache.org/manual/install.html to setup ant

The ant.bat script makes use of three environment variables - ANT_HOME, CLASSPATH and JAVA_HOME. Ensure that ANT_HOME and JAVA_HOME variables are set, and that they do not have quotes (either ' or ") and they do not end with \ or with /. CLASSPATH should be unset or empty.

Create ANT_HOME
Create JAVA_HOME

set ANT_HOME=c:\ant
set JAVA_HOME=c:\jdk1.7.0_51
set PATH=%PATH%;%ANT_HOME%\bin

Now Check the ANT SetUp

You can check the basic installation with opening a new shell and typing ant. You should get a message like this
Buildfile: build.xml does not exist!
Build failed
So Ant works. This message is there because you need to write an individual buildfile for your project. With a ant -version you should get an output like

add android platform
D:\workspace\HTML5\CowsBulls>cordova platform add android
Creating android project...
Preparing android project

build
D:\workspace\HTML5\CowsBulls>cordova build
Generating config.xml from defaults for platform "android"
Preparing android project
Compiling app on platform "android" via command "cmd" /c D:\workspace\HTML5\Cows
Bulls\platforms\android\cordova\build
Platform "android" compiled successfully.

run in device
D:\workspace\HTML5\CowsBulls>cordova run
Generating config.xml from defaults for platform "android"
Preparing android project
Running app on platform "android" via command "cmd" /c D:\workspace\HTML5\CowsBu
lls\platforms\android\cordova\run --device
Platform "android" ran successfully.

Our Application might use internet so enable internet plugin
install git command line tool from http://git-scm.com/
Access files on device or network (File API):

D:\workspace\HTML5\CowsBulls>phonegap local plugin add https://git-wip-us.apache
.org/repos/asf/cordova-plugin-file.git
[phonegap] adding the plugin: https://git-wip-us.apache.org/repos/asf/cordova-pl
ugin-file.git
[phonegap] successfully added the plugin

D:\workspace\HTML5\CowsBulls>phonegap local plugin add https://git-wip-us.apache
.org/repos/asf/cordova-plugin-vibration.git
[phonegap] adding the plugin: https://git-wip-us.apache.org/repos/asf/cordova-pl
ugin-vibration.git

[phonegap] successfully added the plugin


Add DialogBox and Vibration tool for notifications
D:\workspace\HTML5\CowsBulls>phonegap local plugin add https://git-wip-us.apache
.org/repos/asf/cordova-plugin-dialogs.git
[phonegap] adding the plugin: https://git-wip-us.apache.org/repos/asf/cordova-pl
ugin-dialogs.git

[phonegap] successfully added the plugin

Open new browser windows (InAppBrowser):

$ phonegap local plugin add https://git-wip-us.apache.org/repos/asf/cordova-plugin-inappbrowser.git

Debug console:


$ phonegap local plugin add https://git-wip-us.apache.org/repos/asf/cordova-plugin-console.git

To List all Plugins

D:\workspace\HTML5\CowsBulls> phonegap local plugin list
[phonegap] org.apache.cordova.console
[phonegap] org.apache.cordova.dialogs
[phonegap] org.apache.cordova.file
[phonegap] org.apache.cordova.inappbrowser

[phonegap] org.apache.cordova.vibration

The config.xml File
Many aspects of an app's behavior can be controlled with a global configuration file, config.xml
config.xml file can be found in the top-level www directory
 D:\workspace\HTML5\CowsBulls\www

Read ..
http://docs.phonegap.com/en/edge/config_ref_index.md.html#The%20config.xml%20File

Setting Global Level preferences
Full Screen true/false and Orientation portrait/landscape
<preference name="Fullscreen" value="true" />
<preference name="Orientation" value="landscape" />

The came config gets copied to the folder
D:\workspace\HTML5\CowsBulls\platforms\android\assets\www

There is also one config file which android specific
D:\workspace\HTML5\CowsBulls\platforms\android\res\xml\
where you see device specific plugin informations are added e.g
    <feature name="Notification">
        <param name="android-package" value="org.apache.cordova.dialogs.Notification" />
    </feature>

NOW LETS ENABLE OUR HTML5 GAME in Cordova

drop all the html file to application/www folder
run the cordova build command
Check all the files got copeid to
D:\workspace\HTML5\CowsBulls\platforms\android\assets\www

Change the <content src="index.html" /> to
<content src="home.html" /> to point to your application landing page

And you are done !!

Now Create a Icon for the android
create a image icon using GIMP or photoshop
use the android asset tool and generate icon from the image.
use http://makeappicon.com/ for creating icon for android/ihone device

Splash Screen
http://android-ui-utils.googlecode.com/hg/asset-studio/dist/nine-patches.html

Create the release version
cordova build --release

Signing process
keytool -genkey -v -keystore my-release-key.keystore-alias alias_name -keyalg RSA -keysize 2048 -validity 10000
jarsigner -verbose -sigalg SHA1withRSA -digestalg SHA1 -keystore my-release-key.keystore my_application.apk alias_name
jarsigner -verify my_signed.apk
zipalign -v 4 your_project_name-unaligned.apk your_project_name.apk