Sunday, 16 February 2014

Zoom image in android

package com.example.testproject;
import com.example.testproject.R;

import android.annotation.SuppressLint;
import android.app.Activity;
import android.graphics.PointF;
import android.os.Bundle;
import android.util.FloatMath;
import android.util.Log;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.View.OnTouchListener;
import android.widget.Button;
import android.widget.LinearLayout;

@SuppressLint("NewApi")
public class PinchZoom extends Activity {
 View mainView = null;

 // Remember some things for zooming
 PointF start = new PointF();
 PointF mid = new PointF();

 float oldDist = 1f;
 PointF oldDistPoint = new PointF();

 public static String TAG = "ZOOM";

 static final int NONE = 0;
 static final int DRAG = 1;
 static final int ZOOM = 2;
 int mode = NONE;

 @Override
 public void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.zoom );
  mainView = (LinearLayout) findViewById(R.id.lytMain);

  Button buttonZoomOut = (Button) findViewById(R.id.btnZoomOut);
  Button buttonNormal = (Button) findViewById(R.id.btnZoom);
  Button buttonZoomIn = (Button) findViewById(R.id.btnZoomIn);

  buttonZoomOut.setOnClickListener(new OnClickListener() {
   @Override
   public void onClick(View v) {
    zoom(0.5f, 0.5f, new PointF(0, 0));
   }
  });
  buttonNormal.setOnClickListener(new OnClickListener() {
   @Override
   public void onClick(View v) {
    zoom(1f, 1f, new PointF(0, 0));
   }
  });
  buttonZoomIn.setOnClickListener(new OnClickListener() {
   @Override
   public void onClick(View v) {
    zoom(2f, 2f, new PointF(0, 0));
   }
  });

  mainView.setOnTouchListener(new OnTouchListener() {
   @Override
   public boolean onTouch(View v, MotionEvent event) {
    Log.d(TAG, "mode=DRAG");
    switch (event.getAction() & MotionEvent.ACTION_MASK) {
    case MotionEvent.ACTION_DOWN:
     start.set(event.getX(), event.getY());
     Log.d(TAG, "mode=DRAG");
     mode = DRAG;

     break;
    case MotionEvent.ACTION_POINTER_DOWN:
     oldDist = spacing(event);
     oldDistPoint = spacingPoint(event);
     Log.d(TAG, "oldDist=" + oldDist);
     if (oldDist > 10f) {
      midPoint(mid, event);
      mode = ZOOM;
      Log.d(TAG, "mode=ZOOM");
     }
     System.out.println("current time :" + System.currentTimeMillis());
     break;// return !gestureDetector.onTouchEvent(event);
    case MotionEvent.ACTION_UP:
    case MotionEvent.ACTION_POINTER_UP:
     Log.d(TAG, "mode=NONE");
     mode = NONE;
     break;
    case MotionEvent.ACTION_MOVE:
     if (mode == DRAG) {

     } else if (mode == ZOOM) {
      PointF newDist = spacingPoint(event);
      float newD = spacing(event);
      Log.e(TAG, "newDist=" + newDist);
      float[] old = new float[9];
      float[] newm = new float[9];
      Log.e(TAG, "x=" + old[0] + ":&:" + old[2]);
      Log.e(TAG, "y=" + old[4] + ":&:" + old[5]);
      float scale = newD / oldDist;
      float scalex = newDist.x / oldDistPoint.x;
      float scaley = newDist.y / oldDistPoint.y;
      zoom(scale, scale, start);
     }
     break;
    }
    return true;
   }
  });
 }

 /**
  * zooming is done from here
  */
 @SuppressLint("NewApi")
public void zoom(Float scaleX, Float scaleY, PointF pivot) {
  mainView.setPivotX(pivot.x);
  mainView.setPivotY(pivot.y);
  mainView.setScaleX(scaleX);
  mainView.setScaleY(scaleY);
 }

 /**
  * space between the first two fingers
  */
 private float spacing(MotionEvent event) {
  // ...
  float x = event.getX(0) - event.getX(1);
  float y = event.getY(0) - event.getY(1);
  return FloatMath.sqrt(x * x + y * y);
 }

 private PointF spacingPoint(MotionEvent event) {
  PointF f = new PointF();
  f.x = event.getX(0) - event.getX(1);
  f.y = event.getY(0) - event.getY(1);
  return f;
 }

 /**
  * the mid point of the first two fingers
  */
 private void midPoint(PointF point, MotionEvent event) {
  // ...
  float x = event.getX(0) + event.getX(1);
  float y = event.getY(0) + event.getY(1);
  point.set(x / 2, y / 2);
 }
}

Other Links
========
http://stackoverflow.com/questions/13398288/image-zoom-issue-with-universal-image-loader-and-view-pager

Monday, 10 February 2014

Custom Dialog Android

1)custom_dialog_calcel.xml
===================
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/layout_root"
    android:layout_width="280dp"
    android:layout_height="140dp"
    android:gravity="center"
    android:layout_gravity="center"
    android:background="@drawable/ractangle_button_background"
    android:orientation="vertical" >

    <TextView
        android:id="@+id/txtMsg"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:layout_margin="15dp"
        android:layout_weight="1"
        android:gravity="center"
        android:text="Your booking has been canceled successfully"
        android:textColor="@android:color/white"
        android:textSize="14sp" />

    <Button
        android:id="@+id/btnOk"
        android:layout_width="100dp"
        android:layout_height="wrap_content"
        android:layout_gravity="bottom|center"
        android:layout_marginBottom="15dp"
        android:background="@drawable/ractangle_button"
        android:gravity="center"
        android:padding="10dp"
        android:text="OK"
        android:textColor="@color/blue" />

</LinearLayout>

2)custom_dialog.xml
==============
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="@dimen/book_now_dialog_width"
    android:layout_height="@dimen/book_now_dialog_height"
    android:layout_gravity="center"
    android:background="@android:color/transparent" >

    <!-- Contents will go here.. -->

    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_margin="10dp"
        android:background="@color/blue"
        android:orientation="vertical" >

        <LinearLayout
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:layout_margin="1dp"
            android:background="@android:color/white"
            android:orientation="vertical" >

            <TextView
                android:id="@+id/txtHeading"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:layout_alignParentTop="true"
                android:background="@color/lemon_yellow"
                android:gravity="left"
                android:padding="5dp"
                android:text="Class"
                android:textColor="@color/blue"
                android:textSize="18dp" />

            <ScrollView
                android:layout_width="fill_parent"
                android:layout_height="wrap_content" >

                <LinearLayout
                    android:layout_width="fill_parent"
                    android:layout_height="fill_parent"
                    android:layout_margin="10dp"
                    android:layout_weight="1"
                    android:orientation="vertical" >

                    <LinearLayout
                        android:layout_width="fill_parent"
                        android:layout_height="wrap_content"
                        android:orientation="horizontal" >

                        <TextView
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:text="@string/class_name"
                            android:textColor="@color/blue"
                            android:textSize="14sp" />

                        <TextView
                            android:id="@+id/txtClassName"
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:text="Message"
                            android:textColor="@color/Black"
                            android:textSize="14sp" />
                    </LinearLayout>

                    <LinearLayout
                        android:layout_width="fill_parent"
                        android:layout_height="wrap_content"
                        android:layout_marginTop="5dp"
                        android:orientation="horizontal" >

                        <TextView
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:text="@string/teacher"
                            android:textColor="@color/blue"
                            android:textSize="14sp" />

                        <TextView
                            android:id="@+id/txtTeacher"
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:text="Message"
                            android:textColor="@color/Black"
                            android:textSize="14sp" />
                    </LinearLayout>

                    <LinearLayout
                        android:layout_width="fill_parent"
                        android:layout_height="wrap_content"
                        android:layout_marginTop="5dp"
                        android:orientation="horizontal" >

                        <TextView
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:text="@string/date"
                            android:textColor="@color/blue"
                            android:textSize="14sp" />

                        <TextView
                            android:id="@+id/txtDate"
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:text="Message"
                            android:textColor="@color/Black"
                            android:textSize="14sp" />
                    </LinearLayout>

                    <LinearLayout
                        android:layout_width="fill_parent"
                        android:layout_height="wrap_content"
                        android:layout_marginTop="5dp"
                        android:orientation="horizontal" >

                        <TextView
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:text="@string/time"
                            android:textColor="@color/blue"
                            android:textSize="14sp" />

                        <TextView
                            android:id="@+id/txtTime"
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:text="Message"
                            android:textColor="@color/Black"
                            android:textSize="14sp" />
                    </LinearLayout>

                    <LinearLayout
                        android:layout_width="fill_parent"
                        android:layout_height="wrap_content"
                        android:layout_marginTop="5dp"
                        android:orientation="horizontal" >

                        <TextView
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:text="@string/venue"
                            android:textColor="@color/blue"
                            android:textSize="14sp" />

                        <TextView
                            android:id="@+id/txtVenue"
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:text="Message"
                            android:textColor="@color/Black"
                            android:textSize="14sp" />
                    </LinearLayout>

                    <LinearLayout
                        android:layout_width="fill_parent"
                        android:layout_height="wrap_content"
                        android:layout_marginTop="5dp"
                        android:orientation="horizontal" >

                        <TextView
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:text="@string/class_type"
                            android:textColor="@color/blue"
                            android:textSize="14sp" />

                        <TextView
                            android:id="@+id/txtClassType"
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:text="Message"
                            android:textColor="@color/Black"
                            android:textSize="14sp" />
                    </LinearLayout>
                </LinearLayout>
            </ScrollView>

            <Button
                android:id="@+id/btnBookNow"
                android:layout_width="150dp"
                android:layout_height="40dp"
                android:layout_gravity="center|bottom"
                android:layout_margin="15dp"
                android:background="@drawable/ractangle_button"
                android:gravity="center"
                android:text="Book Now"
                android:textColor="@color/blue"
                android:textSize="14sp"
                android:textStyle="bold" />
        </LinearLayout>
    </LinearLayout>

    <Button
        android:id="@+id/btnClose"
        android:layout_width="@dimen/btn_close_width"
        android:layout_height="@dimen/btn_close_height"
        android:layout_alignParentRight="true"
        android:layout_gravity="right|center"
        android:layout_marginRight="3dp"
        android:background="@drawable/round_button_background"
        android:gravity="center_vertical|center_horizontal"
        android:text="X"
        android:textColor="@color/blue"
        android:textSize="12sp"
        android:textStyle="bold" />

</RelativeLayout>
3) in drawable folder put
A) ractangle_button_background.xml
     =======================
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"> 
    <solid android:color="#93772C"/>    

<!--     <stroke android:width="3dp" -->
<!--             android:color="#ff000000" -->
<!--             /> -->

    <padding android:left="1dp"
             android:top="1dp"
             android:right="1dp"
             android:bottom="1dp"
             /> 
    <corners android:bottomRightRadius="10dp" android:bottomLeftRadius="10dp" 
     android:topLeftRadius="10dp" android:topRightRadius="10dp"/> 
</shape>

B)ractangle_button.xml
===================
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"> 
    <solid android:color="@color/lemon_yellow"/>    

<!--     <stroke android:width="3dp" -->
<!--             android:color="#ff000000" -->
<!--             /> -->

    <padding android:left="1dp"
             android:top="1dp"
             android:right="1dp"
             android:bottom="1dp"/> 

    <corners android:bottomRightRadius="7dp" android:bottomLeftRadius="7dp" 
     android:topLeftRadius="7dp" android:topRightRadius="7dp"/> 
</shape> 

C) round_button_background.xml
     =====================
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
        android:shape="oval">
    <solid android:color="@color/lemon_yellow" />
    <stroke android:width="2dp" android:color="@color/blue" />
</shape>


4)
public void dialogCancelBooking() {
final Dialog dialog = new Dialog (this,android.R.style.Theme_Translucent_NoTitleBar);
dialog.setContentView(R.layout.custom_dialog_cancel);

Button btnOk = (Button) dialog.findViewById(R.id.btnOk);
TextView txtMsg = (TextView) dialog
.findViewById(R.id.txtMsg);

btnOk.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
dialog.dismiss();
}
});

dialog.show();
}

Wednesday, 5 February 2014

Image blur issue

// http://www.androiddevelopersolution.com/2013/12/android-make-image-sharper-android.html
Image Before:


Image After :


 1. ImageHelper.java : This is our helper class which helps in processing image
     sharper/



package com.exampl.imagerun;

import android.graphics.Bitmap;
import android.graphics.Color;
 
public class ImageHelper
{
    public static final int SIZE = 3;
 
    public double[][] Matrix;
    public double Factor = 1;
    public double Offset = 1;
 
   //Constructor with argument of size
    public ImageHelper(int size) {
        Matrix = new double[size][size];
    }
 
    public void setAll(double value) {
        for (int x = 0; x < SIZE; ++x) {
            for (int y = 0; y < SIZE; ++y) {
                Matrix[x][y] = value;
            }
        }
    }
 
    public void applyConfig(double[][] config) {
        for(int x = 0; x < SIZE; ++x) {
            for(int y = 0; y < SIZE; ++y) {
                Matrix[x][y] = config[x][y];
            }
        }
    }
 
    public static Bitmap computeConvolution3x3(Bitmap src, ImageHelper matrix) {
        int width = src.getWidth();
        int height = src.getHeight();
        Bitmap result = Bitmap.createBitmap(width, height, src.getConfig());
 
        int A, R, G, B;
        int sumR, sumG, sumB;
        int[][] pixels = new int[SIZE][SIZE];
 
        for(int y = 0; y < height - 2; ++y) {
            for(int x = 0; x < width - 2; ++x) {
 
                // get pixel matrix
                for(int i = 0; i < SIZE; ++i) {
                    for(int j = 0; j < SIZE; ++j) {
                        pixels[i][j] = src.getPixel(x + i, y + j);
                    }
                }
 
                // get alpha of center pixel
                A = Color.alpha(pixels[1][1]);
 
                // init color sum
                sumR = sumG = sumB = 0;
 
                // get sum of RGB on matrix
                for(int i = 0; i < SIZE; ++i) {
                    for(int j = 0; j < SIZE; ++j) {
                        sumR += (Color.red(pixels[i][j]) * matrix.Matrix[i][j]);
                        sumG += (Color.green(pixels[i][j]) * matrix.Matrix[i][j]);
                        sumB += (Color.blue(pixels[i][j]) * matrix.Matrix[i][j]);
                    }
                }
 
                // get final Red
                R = (int)(sumR / matrix.Factor + matrix.Offset);
                if(R < 0) { R = 0; }
                else if(R > 255) { R = 255; }
 
                // get final Green
                G = (int)(sumG / matrix.Factor + matrix.Offset);
                if(G < 0) { G = 0; }
                else if(G > 255) { G = 255; }
 
                // get final Blue
                B = (int)(sumB / matrix.Factor + matrix.Offset);
                if(B < 0) { B = 0; }
                else if(B > 255) { B = 255; }
 
                // apply new pixel
                result.setPixel(x + 1, y + 1, Color.argb(A, R, G, B));
            }
        }
 
        // final image
        return result;
    }
}

 Now, In our Activity class we need to add following code:

   
    ImageView imageView=(ImageView)findViewById(R.id.image);


Now set image on image view

   
    image.setImageBitmap(sharpenImage(BitmapFactory.
           decodeResource(getResources(),images[i]),12));


And, here we are using Convolution Matrix Theorem to make image sharper.


       public Bitmap sharpenImage(Bitmap src, double weight) {
    // set sharpness configuration
    double[][] SharpConfig = new double[][] { { 0, -2, 0 },
    { -2, weight, -2 }, { 0, -2, 0 } };
    // create convolution matrix instance
    ImageHelper convMatrix = new ImageHelper(3);
    // apply configuration
    convMatrix.applyConfig(SharpConfig);
    // set weight according to factor
    convMatrix.Factor = weight - 8;
    return ImageHelper.computeConvolution3x3(src, convMatrix);
 }

Monday, 20 January 2014

Load Image from URL

http://www.androidhive.info/2012/07/android-loading-image-from-url-http/

Saturday, 14 December 2013

Custom Toast

1) in Activity.java
==============
final View toastView = getLayoutInflater().inflate(
R.layout.custom_toast,(ViewGroup) findViewById(R.id.toastLayout));
ImageView imageView = (ImageView) toastView
.findViewById(R.id.image);
imageView.setImageResource(R.drawable.ic_info);

// imageView.setBackgroundDrawable(bitmapDrawable);
TextView textView = (TextView) toastView.findViewById(R.id.text);
textView.setText("Take a Clear photo of the Ticket");
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
toast = new Toast(HomeActivity.this);
toast.setGravity(Gravity.TOP, 0, 100);
toast.setDuration(Toast.LENGTH_LONG);
toast.setView(toastView);
toast.show();
}
}, 2000);

2) custom_toast.xml
==============
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/toastLayout"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="@layout/roundborder"
    android:orientation="horizontal"
    android:padding="10dp" >

    <ImageView
        android:id="@+id/image"
        android:layout_width="wrap_content"
        android:layout_height="fill_parent"
        android:layout_marginRight="1dp" />

    <TextView
        android:id="@+id/text"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_gravity="center"
        android:layout_marginRight="4dp"
        android:gravity="center"
        android:paddingLeft="5dip"
        android:text="Take a clear photo of the Ticket"
        android:textColor="#FFF"
        android:textSize="16dip" />

</LinearLayout>

Friday, 13 December 2013

RSS Feed Reader

1)MainActivity.java
==============
package com.example.rssfeed;

import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.ArrayList;
import nl.matshofman.saxrssreader.RssFeed;
import nl.matshofman.saxrssreader.RssItem;
import nl.matshofman.saxrssreader.RssReader;
import org.xml.sax.SAXException;
import android.annotation.SuppressLint;
import android.app.Activity;
import android.os.Bundle;
import android.os.StrictMode;
import android.util.Log;
import android.widget.TextView;

public class MainActivity extends Activity {
private TextView txtTitle;

@SuppressLint("NewApi")
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

txtTitle = (TextView)findViewById(R.id.txtTitle);

if (android.os.Build.VERSION.SDK_INT > 9) {
   StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
   StrictMode.setThreadPolicy(policy);
}

URL url = null;
try {
url = new URL("http://www.vogella.com/article.rss");
} catch (MalformedURLException e) {
e.printStackTrace();
}
RssFeed feed = null;
try {
feed = RssReader.read(url);
} catch (SAXException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}

ArrayList<RssItem> rssItems = feed.getRssItems();
for(RssItem rssItem : rssItems) {
   Log.i("RSS Reader", rssItem.getTitle());
   txtTitle.setText(rssItem.getTitle());
}
}
}
2)Download library from

3)Manifest Permissions
    <uses-permission android:name="android.permission.INTERNET"/>
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>

ShowMultipleFileDownloadProgression

1) Create class CustomListViewAdapter.java
==============================
package com.example.showdownloadprogression;

import java.util.List;
import android.app.Activity;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;

public class CustomListViewAdapter extends BaseAdapter {

   Context context;
   List<RowItem> rowItems;

   public CustomListViewAdapter(Context context, List<RowItem> items) {
       this.context = context;
       this.rowItems = items;
   }

   private class ViewHolder {
       ImageView imageView;
   }

   public int getCount() {
       return rowItems.size();
   }

   public Object getItem(int position) {
       return rowItems.get(position);
   }

   public long getItemId(int position) {
       return 0;
   }

   public View getView(int position, View convertView, ViewGroup parent) {
       ViewHolder holder = null;
       LayoutInflater mInflater = (LayoutInflater) context
               .getSystemService(Activity.LAYOUT_INFLATER_SERVICE);
       if (convertView == null) {
           convertView = mInflater.inflate(R.layout.list_item, null);
           holder = new ViewHolder();
           holder.imageView = (ImageView) convertView
                   .findViewById(R.id.thumbnail);
           convertView.setTag(holder);
       } else {
           holder = (ViewHolder) convertView.getTag();
       }
       RowItem rowItem = (RowItem) getItem(position);
       holder.imageView.setImageBitmap(rowItem.getBitmapImage());
       return convertView;
   }
}

2) Create class FileUtils.java
====================
package com.example.showdownloadprogression;

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;

public class FileUtils {

    public static void close(InputStream stream) {
        if(stream != null) {
            try {
                stream.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }

    public static void close(OutputStream stream) {
        if(stream != null) {
            try {
                stream.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
}


3) Create class MainActivity.java
=======================
package com.example.showdownloadprogression;

import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLConnection;
import java.util.ArrayList;
import java.util.List;
import android.app.Activity;
import android.app.ProgressDialog;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.AsyncTask;
import android.os.Bundle;
import android.widget.ListView;
public class MainActivity extends Activity {
    ProgressDialog progressDialog;
    CustomListViewAdapter listViewAdapter;
    ListView listView;
    public static final String URL =
        "http://theopentutorials.com/totwp331/wp-content/uploads/totlogo.png";
    public static final String URL1 =
        "http://theopentutorials.com/totwp331/wp-content/uploads/totlogo.png";
    public static final String URL2 =
        "http://theopentutorials.com/totwp331/wp-content/uploads/totlogo.png";
    
    @Override
    protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main);
            listView = (ListView) findViewById(R.id.imageList);
        /*Creating and executing background task*/
        GetXMLTask task = new GetXMLTask(this);
        task.execute(new String[] { URL, URL1, URL2 });
        progressDialog = new ProgressDialog(this);
        progressDialog.setTitle("In progress...");
        progressDialog.setMessage("Loading...");
        progressDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
        progressDialog.setIndeterminate(false);
        progressDialog.setMax(100);
        progressDialog.setIcon(R.drawable.arrow);
        progressDialog.setCancelable(true);
        progressDialog.show();
    }
// 
//    @Override
//    public boolean onCreateOptionsMenu(Menu menu) {
//        // Inflate the menu; this adds items to the action bar if it is present.
//        getMenuInflater().inflate(R.menu.activity_main, menu);
//        return true;
//    }
    private class GetXMLTask extends AsyncTask<String, Integer, List<RowItem>> {
        private Activity context;
        List<RowItem> rowItems;
        int noOfURLs;
        public GetXMLTask(Activity context) {
            this.context = context;
        }
        @Override
        protected List<RowItem> doInBackground(String... urls) {
            noOfURLs = urls.length;
            rowItems = new ArrayList<RowItem>();
            Bitmap map = null;
            for (String url : urls) {
                map = downloadImage(url);
                rowItems.add(new RowItem(map));
            }
            return rowItems;
        }
        private Bitmap downloadImage(String urlString) {
            int count = 0;
            Bitmap bitmap = null;
            URL url;
            InputStream inputStream = null;
            BufferedOutputStream outputStream = null;
            try {
                url = new URL(urlString);
                URLConnection connection = url.openConnection();
                int lenghtOfFile = connection.getContentLength();
                inputStream = new BufferedInputStream(url.openStream());
                ByteArrayOutputStream dataStream = new ByteArrayOutputStream();
                outputStream = new BufferedOutputStream(dataStream);
                byte data[] = new byte[512];
                long total = 0;
                while ((count = inputStream.read(data)) != -1) {
                    total += count;
                    /*publishing progress update on UI thread.
                    Invokes onProgressUpdate()*/
                    publishProgress((int)((total*100)/lenghtOfFile));
                    // writing data to byte array stream
                    outputStream.write(data, 0, count);
                }
                outputStream.flush();
                BitmapFactory.Options bmOptions = new BitmapFactory.Options();
                bmOptions.inSampleSize = 1;
                byte[] bytes = dataStream.toByteArray();
                bitmap = BitmapFactory.decodeByteArray(bytes, 0, bytes.length,bmOptions);
            } catch (MalformedURLException e) {
                e.printStackTrace();
            } catch (IOException e) {
                e.printStackTrace();
            } finally {
                FileUtils.close(inputStream);
                FileUtils.close(outputStream);
            }
            return bitmap;
        }
        protected void onProgressUpdate(Integer... progress) {
            progressDialog.setProgress(progress[0]);
            if(rowItems != null) {
                progressDialog.setMessage("Loading " + (rowItems.size()+1) + "/" + noOfURLs);
            }
       }
       @Override
       protected void onPostExecute(List<RowItem> rowItems) {
        listViewAdapter = new CustomListViewAdapter(context, rowItems);
        listView.setAdapter(listViewAdapter);
        progressDialog.dismiss();
       }    
    }
}

4) Create class RowItem.java
====================
package com.example.showdownloadprogression;

import android.graphics.Bitmap;

public class RowItem {
 
    private Bitmap bitmapImage;
    public RowItem(Bitmap bitmapImage) {
        this.bitmapImage =  bitmapImage;
    }
    public Bitmap getBitmapImage() {
        return bitmapImage;
    }
    public void setBitmapImage(Bitmap bitmapImage) {
        this.bitmapImage = bitmapImage;
    }
}

5)activity_main.xml
=============
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity" >
    <ListView
        android:id="@+id/imageList"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" />
</RelativeLayout>

6) list_item.xml
============
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical"
    android:padding="10dp" >
    <ImageView
        android:id="@+id/thumbnail"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" />
</LinearLayout>

7) in values-v11 style.xml
=================
<resources>

    <style name="AppBaseTheme" parent="android:Theme.Holo.Light">
        <!-- API 11 theme customizations can go here. -->
    </style>
</resources>

8) in values-v14 style.xml
==================
<resources>

  <style name="AppBaseTheme" parent="android:Theme.Holo.Light.DarkActionBar">
        <!-- API 14 theme customizations can go here. -->
    </style>
</resources>

9) Don't forget to give permission of "Internet" & "Access_Network_State"