Monday 27 August 2012

keyboard input stop working in Android Emulator



Hello Friends ,

After upgrading my Android SDK ADT plugin r20 from r16  keyboard input seem to have stopped working with both existing and new AVDs.
Everything was working fine prior to the upgrade. After doing lots of R&D. The issue is solved for me :)


If you want to enable the keyboard for your android virtual device via command line, edit~/.android/avd/[YOUR_AVD].avd/config.ini and add this to the file:
hw.keyboard=yes
Restart your AVD and you should be in business.
                         
                                          OR
Go to following path(in my case mukesh is user):
mukesh/.android/avd/[YOUR_AVD].avd/config.ini and add this line
hw.keyboard=yes


Hope this will help you...
Enjoy :)

Android Splash Screen Example

Android Splash Screen Example
Hello Friends,

Have you searching for Splash screen demo example in android ??
Today , I am sharing the full running code of splash screen in android.

1. SplashScreen.java

package com.mukesh.tutorials.splash;

import com.pxr.tutorials.splash.R;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.MotionEvent;

public class SplashScreen extends Activity {
        
        protected int _splashTime = 5000; 
        
        private Thread splashTread;
        
        /** Called when the activity is first created. */
        @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.splash);
            
            
            final SplashScreen sPlashScreen = this; 
            
            // thread for displaying the SplashScreen
            splashTread = new Thread() {
                @Override
                public void run() {
                    try {                       
                        synchronized(this){
                                wait(_splashTime);
                        }
                        
                    } catch(InterruptedException e) {} 
                    finally {
                        finish();
                        
                        Intent i = new Intent();
                        i.setClass(sPlashScreen, Main.class);
                                startActivity(i);
                        
                        //stop();
                    }
                }
            };
            
            splashTread.start();
        }
        //for fading effect
        /*@Override
        public boolean onTouchEvent(MotionEvent event) {
            if (event.getAction() == MotionEvent.ACTION_DOWN) {
                synchronized(splashTread){
                        splashTread.notifyAll();
                }
            }
            return true;
        }*/
        
}


2.AndroidManifest.xml

<?xml version="1.0" encoding="utf-8"?>

<manifest xmlns:android="http://schemas.android.com/apk/res/android"

      package="com.pxr.tutorials.splash"

      android:versionCode="1"

      android:versionName="1.0">

    <uses-sdk android:minSdkVersion="4" />



    <application android:icon="@drawable/icon" android:label="@string/app_name">

        <activity android:name=".SplashScreen"

                  android:label="@string/app_name">

            <intent-filter>

                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />

            </intent-filter>

        </activity>

       

        <activity android:name="com.mukesh.tutorials.splash.Main" />

    </application>

</manifest>


3.Main.Java


package com.mukesh.tutorials.splash;

import com.pxr.tutorials.splash.R;

import android.app.Activity;
import android.os.Bundle;

public class Main extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
    }
}




Download Source Code: 
SplashDemo


Hope this will helps anyone....
Enjoy :)

Friday 3 August 2012

Show Custom Alert Box| Dialogue Box in Phone Gap Application

Phonegap alert box

Hello Friends,


Here , I am sharing my code in which we show custom alert box in
Phone Gap Application ,Same as Android and Iphone.

In My Html code i am calling logout() method on button(Logout) click Which show
A confirmation alert box.


The Java Script code which i am using is:

<script type="text/javascript">
function  logout() {
    showConfirm();
}

function showConfirm() {
    navigator.notification.confirm(
        'Are you sure?',  // message
        onConfirm,        // callback to invoke with index of button pressed
        'Logout',         // title
        'Ok,Cancel'       // buttonLabels
    );
}

//process the confirmation dialog result
function onConfirm(button) {
    if(button==1){
        //your code
    }else {
      //your code
    }
}
</script>

Hope , this will Helps any one.

Network reachability code in Phone gap-Android

Phone Gap network check


Hello Friends,

Have you searching for how to check network connection in your
Phone Gap  Application ?

Here , I am sharing my network reachability code in phone gap
application.

Note:
        In some of the devices if you are trying to connect your app using GPRS.
In this case the connection type will be  'Unknown connection' so in my code i am
only checking following condition to show confirm dialogue.


if(networkStatusType == 'undefined' || networkStatusType == 'No network    
                     connection'){
         showConfirm();
}




Code:
Index.html

  <!DOCTYPE html>
<head>
  <meta charset="utf-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  <meta name="viewport" content="width=device-width, height=device-height" />
  <title>Login Form</title>
  <link rel="stylesheet" href="css/style.css">
  

<link rel="stylesheet" href="css/jquery.mobile-1.0b3.min.css" />


<script type="text/javascript" src="js/jquery-1.6.4.min.js"></script>
<script type="text/javascript" src="js/jquery.mobile-1.0b3.min.js"></script>

<script type="text/javascript" src="js/phonegap-1.0.0.js"></script>
<script type="text/javascript" src="js/SQLStore.js"></script>
<script type="text/javascript" src="js/NWReachability.js"></script>
<script type="text/javascript">
var DEBUG_ANDROID_THEME=true;
$(document).ready(function() {
//initDB();
});

</script
</head>

<body>
<div data-dom-cache="true" data-role="page" id="page">
 <div data-role="header" data-position="inline" data-theme="b">
<h1>LOGIN</h1>
         </div>

  <div class="container">
    <section class="login">
      <!--  <h1>Login to VEO App</h1>  -->
      <form>
        <p>
          <input type="text" name="txtName" id="loginName" value="" placeholder="Username">        
        </p>
        <p>
          <input type="password" name="txtPassword" id="password" value="" 
          placeholder="Password" > 
        </p>
        <p class="submit" style="width: 100px;">
           <input type="button" name="commit" value="Login" onclick="loginvalidation();">
        </p>
      </form>
    </section>    
  </div>
</div>
  
</body>
</html>



In my NetworkReachability.js


/*function for login validation */


function loginvalidation() {
        var msg="";
        //msg="Wrong Input";
        var ck_name = /^[A-Za-z0-9_.]{3,20}$/;
        var name_int = /[0-9]/;
        var ck_password = /^[A-Za-z0-9!@#$%^&*()_]{5,20}$/;
        var userName =$("#loginName").val();
        var password =$("#password").val();
        if(userName == "" || password == ""){
        msg="Please fill User Name and Password ";
            showErrorToast(msg);
        $("#loginName").focus();
        }
        else {
        var pos=userName.search(name_int);
        if(pos==0){
        msg="Invalid User Name "
        showErrorToast(msg);
        $("#loginName").focus();
                $("#loginName").val("");
        }
        else if(!ck_name.test(userName)){
        msg="Invalid User Name "
                $("#loginName").focus();
                $("#loginName").val("");
                showErrorToast(msg);
                }
        else if(!ck_password.test(password))
        {
        msg="Invalid Password "
                $("#password").focus();
                $("#password").val("");
                showErrorToast(msg);
               
        }
        else {
        var networkStatusType = checkConnection();
        alert(networkStatusType);
       
        if(networkStatusType == 'undefined' || networkStatusType == 'No network    
                     connection'){
        showConfirm();
        }
        else{
        //Your own call
        }
        
        
        }
        
     }
  }





//check network connection 
function checkConnection() {
    var networkState = navigator.network.connection.type;

    var states = {};
    states[Connection.UNKNOWN]  = 'Unknown connection';
    states[Connection.ETHERNET] = 'Ethernet connection';
    states[Connection.WIFI]     = 'WiFi connection';
    states[Connection.CELL_2G]  = 'Cell 2G connection';
    states[Connection.CELL_3G]  = 'Cell 3G connection';
    states[Connection.CELL_4G]  = 'Cell 4G connection';
    states[Connection.NONE]     = 'No network connection';

    //alert('Connection type: ' + states[networkState]);
    var  networkStatus=states[networkState];
    return networkStatus;

}

function showConfirm() {
    navigator.notification.confirm(
        'No network connection'// message
        onConfirm,              // callback to invoke with index of button pressed
        'Please Check Network Setting.',            // title
        'Ok,Cancel'          // buttonLabels
    );
}

//process the confirmation dialog result
function onConfirm(button) {
    if(button==1){
     //your code
    }else {
       //your code
    }
}


I think this will help you... 
Enjoy Coding :)

Please Comment if you have any query.

 

Copyright @ 2013 Android Developers Blog.