Sunday 1 February 2015

Monday 19 January 2015

Android Custom Horizontal progress bar | Custom Progress bar

Hello Friends,
                  Today,I am going to share my another blog which helps you in customizing
Horizontal Progress Bar.With the help of this Android tutorial we can also implement
the Android PI Chart view with multiple color.

Actually my need to show some PI Chart like view with multiple different color which fills
dynamically base on the percentage,  without using any 3rd party library. So , I first go
with Horizontal progress bar but in horizontal progress bar only show up-to two level 
progress with different color.

Finally, I have written a custom progress bar code using android seek bar. Using this we
can add "N level" of different color with different percentage.And Its very simple and
easily understandable.

Horizontal Progress bar

Here is my code :



import java.util.ArrayList;

import android.os.Bundle;
import android.util.Log;
import android.view.Menu;

public class MainActivity extends Activity {

 private CustomProgressBar seekbar;
 private ArrayList progressItemList;
 private ProgressItem mProgressItem;

 protected void onCreate(Bundle savedInstanceState) {
  seekbar = ((CustomProgressBar) findViewById(;

 private void initDataToSeekbar() {
  progressItemList = new ArrayList();
  // red span
  mProgressItem = new ProgressItem();
  mProgressItem.progressItemPercentage = 20;
  Log.i("Mainactivity", mProgressItem.progressItemPercentage + "");
  mProgressItem.color =;
  // blue span
  mProgressItem = new ProgressItem();
  mProgressItem.progressItemPercentage = 25;
  mProgressItem.color =;
  // green span
  mProgressItem = new ProgressItem();
  mProgressItem.progressItemPercentage = 35;
  mProgressItem.color =;
  //white span
  mProgressItem = new ProgressItem();
  mProgressItem.progressItemPercentage = 20;
  mProgressItem.color =  R.color.white;


 public boolean onCreateOptionsMenu(Menu menu) {
  getMenuInflater().inflate(, menu);
  return true;



import java.util.ArrayList;

import android.content.Context;
import android.util.AttributeSet;
import android.widget.SeekBar;

public class CustomProgressBar extends SeekBar {

 private ArrayList mProgressItemsList;

 public CustomProgressBar(Context context) {
  mProgressItemsList = new ArrayList();

 public CustomProgressBar(Context context, AttributeSet attrs) {
  super(context, attrs);

 public CustomProgressBar(Context context, AttributeSet attrs, int defStyle) {
  super(context, attrs, defStyle);

 public void initData(ArrayList progressItemsList) {
  this.mProgressItemsList = progressItemsList;

 protected synchronized void onMeasure(int widthMeasureSpec,
   int heightMeasureSpec) {
  // TODO Auto-generated method stub
  super.onMeasure(widthMeasureSpec, heightMeasureSpec);

 protected void onDraw(Canvas canvas) {
  if (mProgressItemsList.size() > 0) {
   int progressBarWidth = getWidth();
   int progressBarHeight = getHeight();
   int thumboffset = getThumbOffset();
   int lastProgressX = 0;
   int progressItemWidth, progressItemRight;
   for (int i = 0; i < mProgressItemsList.size(); i++) {
    ProgressItem progressItem = mProgressItemsList.get(i);
    Paint progressPaint = new Paint();

    progressItemWidth = (int) (progressItem.progressItemPercentage
      * progressBarWidth / 100);

    progressItemRight = lastProgressX + progressItemWidth;

    // for last item give right to progress item to the width
    if (i == mProgressItemsList.size() - 1
      && progressItemRight != progressBarWidth) {
     progressItemRight = progressBarWidth;
    Rect progressRect = new Rect();
    progressRect.set(lastProgressX, thumboffset / 2,
      progressItemRight, progressBarHeight - thumboffset / 2);
    canvas.drawRect(progressRect, progressPaint);
    lastProgressX = progressItemRight;




public class ProgressItem {
 public int color;
 public float progressItemPercentage;

Download complete Source code : CustomProgress Bar

Hope , this will helps some one .
Enjoy Coding...   :)

Sunday 24 August 2014

Android navigation drawer tutorial | Android navigation drawer with activities | Android Sliding Navigation Drawer – Example

Hello Droid Guys
     Today,  I am going to share the tutorial of  "Android sliding navigation drawer". You also find many tutorial on Google which helps you to show navigation drawer but most of them are using fragment to do that. Here, are the few good tutorial which I follows:
Android Navigation Drawer
Navigation drawer activity


Here, I am going show sliding menu using activity. We can also achieve
the functionality of  Navigation drawer with activities.

This Android tutorial describes How to implement a navigation drawer using  Support Library the DrawerLayout API.

1. Create Drawer Layout :
            To create a navigation drawer, We first declare user interface with a
DrawerLayout as the root view of layout.

Inside the Drawer Layout, add one view that contains the main content for the
screen (your primary layout when the drawer is hidden) and another view that
contains the contents of the navigationdrawer. In this example, I am using a DrawerLayout
with two child. One a Relative layout with webView(the main content), and other
with a ListView for the navigation drawer. The webview is my activity content view.

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




    android:layout_height="match_parent" >
          main content




        android:background="#ffffff" >





            android:background="#ffffff" />


        navigation list item



        android:layout_height="match_parent" />








        android:choiceMode="singleChoice" />


2. Initialize the Drawer List :
mDrawerLayout = (DrawerLayout) findViewById(;
mDrawerList = (ListView) findViewById(;

// set up the drawer's list view with items and click listener
mDrawerList.setAdapter(new MenuDrawerListAdapter(this, menuItemTitles,
mDrawerList.setOnItemClickListener(new DrawerItemClickListener());

3. Handle Navigation List click event :

/* The click listener for ListView in the navigation drawer */
public class DrawerItemClickListener implements
	ListView.OnItemClickListener {
	public void onItemClick(AdapterView parent, View view, int position,
		long id) {
		switch (position) {
		case 0: {
		Intent main = new Intent(getApplicationContext(),
		case 1: {
		Intent list = new Intent(getApplicationContext(),

Download Code : Navigation Drawer Demo

Hope this will help someone.
Enjoy Coding...   :)

Sunday 10 August 2014

Android Download Source code | Android Sample Project

Hello Friends,
  This is my small contribution , Now I am sharing the source code of all my android
  post or android tutorial at one place.

Android Tutorial Download Code
Android Custom Calendar Download Code
Android LinkedIn Integration Download Code
Android Crop Image in circular shape like gmail and facebook Download Code
Android facebook like left to right slide navigation Download Code
Android facebook and skype like animated splash screen Download Code
Google map V2 sample with draw polygon or draw geometry and save polygon Download Code
Android video Player Download Code
Android navigation drawer tutorial Download Code
Android Custom Horizontal progress bar |"N" level Horizontl Progress Bar Download Code

Sunday 20 July 2014

Android Splash Screen Example with Animation | Animated Splash Screen android

Hello Friends,
        Today, I am going to share the tutorial of android splash screen with animation.
With help of this tutorial you can easily implement the facebook like splash screen
or skype like splash screen.
Android animated splash screen

1. Create an Android Project "SplashScreen"
2. Create an folder "anim" inside the res folder
3. Create two file inside the "anim" folder
      a. alpha.xml
         <?xml version="1.0" encoding="utf-8"?>

              android:duration="3000" />

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


                 android:zAdjustment="top" />

4. inside your oncreate() called this method
public class SpalshScreenActivity extends Activity {

    /** Called when the activity is first created. */

    public void onCreate(Bundle savedInstanceState) {




      private void StartAnimations() {
    	Animation anim = AnimationUtils.loadAnimation(this, R.anim.alpha);
		LinearLayout l = (LinearLayout) findViewById(;

		anim = AnimationUtils.loadAnimation(this, R.anim.translate);
		ImageView iv = (ImageView) findViewById(;

		anim = AnimationUtils.loadAnimation(this, R.anim.translate);
		LinearLayout l2 = (LinearLayout) findViewById(;

Download the code : Android animate splash sreen

Hope this will help someone
Enjoy Coding.... :)

ActiveAndroid Tutorial | ActiveAndroid: Android ORM base database |Getting Started with ActiveAndroid - Part1

ActiveAndrid :                                                                               
Active Android

ActiveAndroid is an ORM (object relational mapper) . Which allows you to save(insert)
and retrieve(read) SQLite database records without even writing a single SQL statement.
Each database record is wrapped neatly into a class with methods like save().
It is same a Java Hibernate. It also based on annotation like: @Column(name="Column")  for creating column and Table(name = "Table")  for creating table .

Getting started : 
A.Now here we are going to start integrating ActiveAndroid in your project.
    1. Download the ActiveAndroid library
    2. Now generate the ActiveAndroid.jar by executing ant in root folder
    3. If you are unable to generate the jar file then download it from here

 Now, we have ActiveAndroid.jar file.  Now, we can add it inside the "libs" folder of
Android Project.    

B. Configuring Android Project with ActiveAndroid :
    1. Open the AndroidManifest.xml file located at the root directory of your Android project.

<manifest xmlns:android=""
    android:versionName="1.0" >
           android:theme="@style/AppTheme" >
             android:screenOrientation="landscape" >
               <action android:name="android.intent.action.MAIN" />
               <category android:name="android.intent.category.LAUNCHER" />
         <meta-data android:name="AA_DB_NAME" android:value="Student.db" />
         <meta-data android:name="AA_DB_VERSION" android:value="1" />

Note:  In your manifest.xml, if you are not using any Custom Application class then the application name points to the ActiveAndroid application class as we are doing above. But if you are using any Application levele custom class then your Custom Application class must extend instead of

public class MyApplication extends { ...

And initialize and dispose ActiveAndroid in the Application class.

public class MyApplication extends {

    public void onCreate() {

    public void onTerminate() {

Note : If you want to create your db in a specific location inside your Sd Card then change below line in manifest.xml

<meta-data android:name="AA_DB_NAME" android:value="/sdcard/Student.db" />

<meta-data android:name="AA_DB_VERSION" android:value="1" />

Here, we are creating our database file inside the sd card root folder.
So that we can easily import it in Sqlite Browser .

Tuesday 8 July 2014

Android Google Glass Configuration | Glass Development Kit | Android Google Glass Setup | Android Google Glass Development -Part1

Hello Friend ,
    This is my first blog on Android Google Glass . Lats month Google launches
some awesome feature like:                                                          
         1. Android L Developer Preview
         2. Android Wear SDK
         3. Android TV Preview SDK
         4. Google glass

Today, I am going to share my small tutorial on Google glass which helps you in 
in Configuring the Google glass development environment in Eclipse.

Glass Development Kit :  First you need GDK
The Glass Development Kit (GDK) is an add-on to the Android SDK that lets you build Glassware that runs directly on Glass. 

Steps to setup Google Glass Development :
    1.Get the Android 4.4.2 (API 19) SDK and Glass Development Kit Preview 
       add-on from the Android SDK Manager. see the image 

   2. On Glass, turn on USB debugging (Settings > Device Info > Turn on debug).
   3. Import some GDK samples with the File > New Project > Android Sample Project menu.
   4. When you're ready to create a project for your own Glassware, use these settings:
- Minimum and Target SDK Versions: 19 (There is only one Glass version, 
           so minimum and target SDK are the same.)
- Compile with: Glass Development Kit Developer Preview
- Theme: None (ADT and Android Studio usually assign a theme automatically,
           even if you specify no theme, so remove the android:theme property from your manifest after
           creating a project.)

For more Detail Check this link

2. Android Google Glass Development -Part2 - (coming soon)

Hope, this will helps someone.
Enjoy Coding..... :)

Sunday 15 June 2014

Android send emails | Android send emails w/t built-in mailing app | Android send emails from the background

Hello Friends,
                Today, I am sharing another important tutorial. While doing development
some times we came across to this requirement, "Sending emails to users" without
using any built-in mailing app(like: Gmail,Yahoo etc). In that time we normally depends
on web-service, we write a service in PHP or JAVA or .Net and the communicate b/w them.

But, know now no need to depends on web-service we can send the mail directly through
our java code.

This tutorial going to covers following features :

1. Sending email without using any built-in mailing app
2. Sending emails without User Intervention
3. Sending  emails to multiple users
4. Sending emails with attachment
5. Sending emails silently without any mail composer

Here are my code:

1. Download java mil.jar, activation.jar and additionnal.jar from below link :          

2. Add this jar files in your project libs folder




import android.os.AsyncTask;
import android.os.Bundle;
import android.os.Environment;
import android.util.Log;
import android.view.View;
import android.widget.ImageButton;
import android.widget.Toast;

 * @author: Mukesh Y
 * @link:
public class MainActivity extends Activity {

 protected void onCreate(Bundle savedInstanceState) {

  ImageButton addImage = (ImageButton) findViewById(;
  addImage.setOnClickListener(new View.OnClickListener() {
   public void onClick(View view) {
    new BackGroundAsyncTask().execute();


 public class BackGroundAsyncTask extends AsyncTask {

  ProgressDialog prog_synprocess = new ProgressDialog(MainActivity.this);

  String statusMessage = "";

  protected void onPostExecute(String status) {
   Toast.makeText(MainActivity.this, status, Toast.LENGTH_LONG).show();


  protected void onPreExecute() {

  protected String doInBackground(String... arg0) {

   try {
    statusMessage = sendLogFile();
   } catch (Exception e) {
    Log.e("Error", e.getMessage());
    statusMessage = "Error in updation";
   return statusMessage;


 private String sendLogFile() {
  String statusMessage = "";
  Mail m = new Mail("", "testtest");

  String[] toArr = { "" };
  String email_subject = "Testing Send mail";

  try {
   String pathToMyAttachedFile = Environment
     + File.separator
     + "Project.log";
   File file = new File(pathToMyAttachedFile);
   if (!file.exists() || !file.canRead()) {
    statusMessage = "File not found";
    return statusMessage;
   } else {
   if (m.send()) {
    statusMessage = "Email was sent successfully.";
   } else {
    statusMessage = "Email was not sent.";
  } catch (Exception e) {
   // Toast.makeText(MailApp.this,
   // "There was a problem sending the email.",
   // Toast.LENGTH_LONG).show();
   Log.e("Send Mail", e.getMessage());
   statusMessage = "There was a problem sending the email.";

  return statusMessage;




import java.util.Date;
import java.util.Properties;

import javax.activation.CommandMap;
import javax.activation.DataHandler;
import javax.activation.FileDataSource;
import javax.activation.MailcapCommandMap;
import javax.mail.BodyPart;
import javax.mail.Multipart;
import javax.mail.PasswordAuthentication;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeBodyPart;
import javax.mail.internet.MimeMessage;
import javax.mail.internet.MimeMultipart;

 * @author: Mukesh Y
 * @link:
public class Mail extends javax.mail.Authenticator {
 private String userName;
 private String password;

 private String[] to;
 private String from;

 private String portNumber;
 private String socketPortNumber;

 private String host;

 private String emailSubject;
 private String emailBody;

 private boolean auth;

 private boolean debuggable;

 private Multipart multipart;

 public Mail() {
  // default smtp server
  host = "";
  // default smtp port
  portNumber = "465"; 
  // default socketfactory port
  socketPortNumber = "465";
  // username
  userName = ""; 
  password = ""; 
  // email sent from
  from = ""; 
  // email subject
  emailSubject = "";
  // email body
  emailBody = ""; 

  // debug mode on or off - default off
  debuggable = false; 
  // smtp authentication - default on
  auth = true; 

  multipart = new MimeMultipart();

  // There is something wrong with MailCap, javamail can not find a
  // handler for the multipart/mixed part, so this bit needs to be added.
  MailcapCommandMap mc = (MailcapCommandMap) CommandMap
  mc.addMailcap("text/html;; x-java-content-handler=com.sun.mail.handlers.text_html");
  mc.addMailcap("text/xml;; x-java-content-handler=com.sun.mail.handlers.text_xml");
  mc.addMailcap("text/plain;; x-java-content-handler=com.sun.mail.handlers.text_plain");
  mc.addMailcap("multipart/*;; x-java-content-handler=com.sun.mail.handlers.multipart_mixed");
  mc.addMailcap("message/rfc822;; x-java-content-handler=com.sun.mail.handlers.message_rfc822");

 public Mail(String user, String pass) {

  userName = user;
  password = pass;

 public boolean send() throws Exception {
  Properties props = _setProperties();

  if (!userName.equals("") && !password.equals("") && to.length > 0
    && !from.equals("") && !emailSubject.equals("")
    && !emailBody.equals("")) {
   Session session = Session.getInstance(props, this);

   MimeMessage msg = new MimeMessage(session);

   msg.setFrom(new InternetAddress(from));

   InternetAddress[] addressTo = new InternetAddress[to.length];
   for (int i = 0; i < to.length; i++) {
    addressTo[i] = new InternetAddress(to[i]);
   msg.setRecipients(MimeMessage.RecipientType.TO, addressTo);

   msg.setSentDate(new Date());

   // setup message body
   BodyPart messageBodyPart = new MimeBodyPart();

   // Put parts in message

   // send email

   return true;
  } else {
   return false;

 public void addAttachment(String filename) throws Exception {
  BodyPart messageBodyPart = new MimeBodyPart();
  FileDataSource source = new FileDataSource(filename);
  messageBodyPart.setDataHandler(new DataHandler(source));


 public PasswordAuthentication getPasswordAuthentication() {
  return new PasswordAuthentication(userName, password);

 private Properties _setProperties() {
  Properties props = new Properties();

  props.put("", host);

  if (debuggable) {
   props.put("mail.debug", "true");

  if (auth) {
   props.put("mail.smtp.auth", "true");

  props.put("mail.smtp.port", portNumber);
  props.put("mail.smtp.socketFactory.port", socketPortNumber);
  props.put("mail.smtp.socketFactory.fallback", "false");

  return props;

 // the getters and setters
 public String getBody() {
  return emailBody;

 public void setBody(String _body) {
  this.emailBody = _body;

 // more of the getters and setters …..
 public void setTo(String[] toArr) { = toArr;

 public void setFrom(String string) {
  this.from = string;

 public void setSubject(String string) {
  this.emailSubject = string;

Hope this will helps some one.
Enjoy coding... cheers :)

Friday 13 June 2014

ListView setOnItemClickListener not working by adding button | ListView setOnItemClickListener issue

Hello Friends,
                    Today, I found another issue with Android  ListView.OnItemClickListner.
Actually I have a list view with items image and text and when I am clicking on it then ListView.OnItemClickListner called and all working fine. But when I added a
button or toggle button(android switch) in existing one then in this case the ListView.OnItemClickListner stop working.

This are the step to reproduce:

1) I have a ListView with an Image and textview.
2) I set ListView.OnItemClickListner. When I run my project It's show my ListView.
3) When I click on Listview It's working fine.
4) Then I added one more item in my item.xml file i.e:added    a button
5) Then When I click on Listview It's not working.
6) Then I removed the added Button from the item.xml and run  my project again when
     I click ListView It' work
7) What wrong ?

Then I figure out the problem by adding the following two line of code in my Button view.


Hope this will helpfull for some one. Enjoy Coding....... Cheers :)

Sunday 8 June 2014

Android accessing html control inside Java class| Getting html field value inside android activity class

Hello Friends,
                This is my another android tutorial. In this android demo I am going to
cover following parts:

1. Showing Android Login form in web view or loading html file in web view.
2. Getting the control  of log in button click,user name and password value inside
    our java class.
3. Checking the field validation inside  our java code.
4. Calling web service method based on valid user name and password.

Source Code:

1. Login.html :  This is my html file in which there is two edittext and a login button.
                           When I m clicking on login Button  I am checking the value of both
this text field inside my java class and if it is valid   then I am calling my login service

<!DOCTYPE html>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<title>Login Form</title>
<link rel="stylesheet" href="style.css">
<script type="text/javascript">
  function showAndroidToast() {
   var name = document.getElementById("loginName").value;
   var password = document.getElementById("password").value;

 <section class="container">
  <div class="login">
   <h1>Login to Android Developer Solutions</h1>
     <input type="text" name="login" id="loginName" value=""
      placeholder="Username or Email">
     <input type="password" name="password" id="password" value=""
    <p class="remember_me">
     <label> <input type="checkbox" name="remember_me"
      id="remember_me"> Remember me
    <p class="submit">
     <input type="submit" name="commit" value="Login"

  <div class="login-help">
    Forgot your password? <a href="index.html">Click here to reset

 <section class="about">
  <p class="about-author">
   &copy; 2013&ndash;2014 <a
    href="" target="_blank">Android
    Developer Solution</a><br> By <a
    href="" target="_blank">Mukesh



package com.mukesh.webview;

import android.annotation.SuppressLint;
import android.os.Bundle;
import android.webkit.WebSettings;
import android.webkit.WebView;

public class MainActivity extends Activity {

 protected void onCreate(Bundle savedInstanceState) {

  WebView webView = (WebView) findViewById(;

  WebSettings webSettings = webView.getSettings();
  webView.addJavascriptInterface(new WebAppInterface(this), "Android");


Download Code : WebView Demo

Enjoy Codiing....
Cheers :)


Copyright @ 2013 Android Developers Blog.