Thursday, 20 December 2012

DropDown PopUp Window

On click on Button or Text or image you want to a Popup window with Drop Down  feel.then follow the steps:
1.main.xml res folder

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:background="@drawable/android_wallpaper">

<Button
android:id="@+id/show_popup"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Show Popup"
android:layout_alignParentRight="true" />
</RelativeLayout>

2.popup.xml res folder

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<RelativeLayout
android:id="@+id/popup"
android:background="@drawable/popupwindow_background"
android:layout_width="80dp"
android:layout_height="200dp">
    <Button
    android:background="@drawable/write"
    android:layout_width="60dp"
    android:layout_height="60dp"
    android:layout_alignParentTop="true"
    android:layout_centerHorizontal="true"
    android:layout_marginTop="25dp"
    android:id="@+id/ButtonPopup"
android:onClick="onButtonInPopup"/>
    <Button
    android:background="@drawable/search"
    android:layout_below="@id/ButtonPopup"
    android:layout_width="60dp"
    android:id="@+id/button2"
    android:layout_height="60dp"
    android:layout_centerHorizontal="true"
    android:layout_marginTop="30dp"/>
</RelativeLayout>
</RelativeLayout>

3.PopupActivity .java in src folder

package com.android.prashant;

import android.app.Activity;
import android.content.Context;
import android.graphics.Point;
import android.graphics.drawable.Animatable;
import android.graphics.drawable.BitmapDrawable;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.view.Display;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.WindowManager;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.PopupWindow;
import android.widget.Toast;

public class PopupActivity extends Activity implements OnClickListener {
    /** Called when the activity is first created. */
Point p;
static int buttonstatus=0;
Button btn_show,button1;
    PopupWindow popup;
 
 
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
     
        btn_show = (Button) findViewById(R.id.show_popup);
        btn_show.setOnClickListener(this);
     
    }
@Override
public void onClick(View v) {
if(v==btn_show){
if(buttonstatus==0){
 // btn_show.setClickable(true);
  showPopup(this);
}else if(buttonstatus==1){
popup.dismiss();
buttonstatus=0;
}
}
}

private void showPopup(final Activity context) {
// TODO Auto-generated method stub

WindowManager wm = (WindowManager)getSystemService(Context.WINDOW_SERVICE);
   Display display1 = getWindowManager().getDefaultDisplay();
   int Twidth = display1.getWidth();
   int Theight = display1.getHeight();
 
 
int popupWidth = 125;
int popupHeight =300;
LinearLayout viewGroup = (LinearLayout) context.findViewById(R.id.popup);
LayoutInflater layoutInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View layout = layoutInflater.inflate(R.layout.popup, viewGroup);
  popup = new PopupWindow(context);
  popup.setContentView(layout);

  buttonstatus=1;
  popup.setWidth(popupWidth);
  popup.setHeight(popupHeight);
  popup.setFocusable(false);

  int OFFSET_X =(Twidth-40);
  int OFFSET_Y =Theight-(Theight-125);
  Toast.makeText(getApplicationContext(), "Hi"+popup.isFocusable(), 150).show();
  popup.setBackgroundDrawable(new BitmapDrawable());
  popup.showAsDropDown(layout,OFFSET_X,OFFSET_Y);
  Button close = (Button) layout.findViewById(R.id.ButtonPopup);
  close.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
popup.setFocusable(true);
buttonstatus=0;
    popup.dismiss();
Toast.makeText(getApplicationContext(), "Hi"+popup.isFocusable(), 150).show();
}
});

  Button btn2 = (Button) layout.findViewById(R.id.button2);
  btn2.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
popup.setFocusable(true);
buttonstatus=0;
    popup.dismiss();
}
});
   }
}


4.res/drawable/ images:






Output:




Friday, 12 October 2012

Android TCP Connection Server Client communication


In this tutorial we will make a TCP Connection. The server will be written in Java and the client will be written in Android. Actually it will be a very simple messenger client.

A. Make the Server in Java

1.To create the server create a new project in Java and make a class called "TCPServer". In this class put the following code:



import javax.swing.*;
import java.io.*;
import java.net.ServerSocket;
import java.net.Socket;

/**
 * The class extends the Thread class so we can receive and send messages at the same time
 */
public class TCPServer extends Thread {

    public static final int SERVERPORT = 4444;
    private boolean running = false;
    private PrintWriter mOut;
    private OnMessageReceived messageListener;

    public static void main(String[] args) {

        //opens the window where the messages will be received and sent
        ServerBoard frame = new ServerBoard();
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.pack();
        frame.setVisible(true);

    }

    /**
     * Constructor of the class
     * @param messageListener listens for the messages
     */
    public TCPServer(OnMessageReceived messageListener) {
        this.messageListener = messageListener;
    }


    /**
     * Method to send the messages from server to client
     * @param message the message sent by the server
     */
    public void sendMessage(String message){
        if (mOut != null && !mOut.checkError()) {
            mOut.println(message);
            mOut.flush();
        }
    }

    @Override
    public void run() {
        super.run();

        running = true;

        try {
            System.out.println("S: Connecting...");

            //create a server socket. A server socket waits for requests to come in over the network.
            ServerSocket serverSocket = new ServerSocket(SERVERPORT);

            //create client socket... the method accept() listens for a connection to be made to this socket and accepts it.
            Socket client = serverSocket.accept();
            System.out.println("S: Receiving...");

            try {

                //sends the message to the client
                mOut = new PrintWriter(new BufferedWriter(new OutputStreamWriter(client.getOutputStream())), true);

                //read the message received from client
                BufferedReader in = new BufferedReader(new InputStreamReader(client.getInputStream()));

                //in this while we wait to receive messages from client (it's an infinite loop)
                //this while it's like a listener for messages
                while (running) {
                    String message = in.readLine();

                    if (message != null && messageListener != null) {
                        //call the method messageReceived from ServerBoard class
                        messageListener.messageReceived(message);
                    }
                }

            } catch (Exception e) {
                System.out.println("S: Error");
                e.printStackTrace();
            } finally {
                client.close();
                System.out.println("S: Done.");
            }

        } catch (Exception e) {
            System.out.println("S: Error");
            e.printStackTrace();
        }

    }


    //Declare the interface. The method messageReceived(String message) will must be implemented in the ServerBoard
    //class at on startServer button click
    public interface OnMessageReceived {
        public void messageReceived(String message);
    }

}

2.Now create another java class and call it "ServerBoard". In this class we will make the "messenger" UI (a very simple one) with a field where the messages will be added, a text field where the server side can enter a message and 2 buttons: one to start the connection and one to send the messages. The code is like this:



import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;


public class ServerBoard extends JFrame {
    private JTextArea messagesArea;
    private JButton sendButton;
    private JTextField message;
    private JButton startServer;
    private TCPServer mServer;

    public ServerBoard() {

        super("ServerBoard");

        JPanel panelFields = new JPanel();
        panelFields.setLayout(new BoxLayout(panelFields,BoxLayout.X_AXIS));

        JPanel panelFields2 = new JPanel();
        panelFields2.setLayout(new BoxLayout(panelFields2,BoxLayout.X_AXIS));

        //here we will have the text messages screen
        messagesArea = new JTextArea();
        messagesArea.setColumns(30);
        messagesArea.setRows(10);
        messagesArea.setEditable(false);

        sendButton = new JButton("Send");
        sendButton.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                // get the message from the text view
                String messageText = message.getText();
                // add message to the message area
                messagesArea.append("\n" + messageText);
                // send the message to the client
                mServer.sendMessage(messageText);
                // clear text
                message.setText("");
            }
        });

        startServer = new JButton("Start");
        startServer.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                // disable the start button
                startServer.setEnabled(false);

                //creates the object OnMessageReceived asked by the TCPServer constructor
                mServer = new TCPServer(new TCPServer.OnMessageReceived() {
                    @Override
                    //this method declared in the interface from TCPServer class is implemented here
                    //this method is actually a callback method, because it will run every time when it will be called from
                    //TCPServer class (at while)
                    public void messageReceived(String message) {
                        messagesArea.append("\n "+message);
                    }
                });
                mServer.start();

            }
        });

        //the box where the user enters the text (EditText is called in Android)
        message = new JTextField();
        message.setSize(200, 20);

        //add the buttons and the text fields to the panel
        panelFields.add(messagesArea);
        panelFields.add(startServer);

        panelFields2.add(message);
        panelFields2.add(sendButton);

        getContentPane().add(panelFields);
        getContentPane().add(panelFields2);


        getContentPane().setLayout(new BoxLayout(getContentPane(),BoxLayout.Y_AXIS));

        setSize(300, 170);
        setVisible(true);
    }
}




B. Create the Client in Android

*To create the Client, create a new project and call the class that creates with the project "   MyActivity". 

*After this make a new class and call it "TCPClient"
*Now in the class TCPClient put the following code:


1.

import android.util.Log;
import java.io.*;
import java.net.InetAddress;
import java.net.Socket;
public class TCPClient {
    private String serverMessage;
    public static final String SERVERIP = "192.168.0.102"; //your computer IP address
    public static final int SERVERPORT = 4444;
    private OnMessageReceived mMessageListener = null;
    private boolean mRun = false;
    PrintWriter out;
    BufferedReader in;
    /**
     *  Constructor of the class. OnMessagedReceived listens for the messages received from server
     */
    public TCPClient(OnMessageReceived listener) {
        mMessageListener = listener;
    }
    /**
     * Sends the message entered by client to the server
     * @param message text entered by client
     */
    public void sendMessage(String message){
        if (out != null && !out.checkError()) {
            out.println(message);
            out.flush();
        }
    }
    public void stopClient(){
        mRun = false;
    }
    public void run() {
        mRun = true;
        try {
            //here you must put your computer's IP address.
            InetAddress serverAddr = InetAddress.getByName(SERVERIP);
            Log.e("TCP Client", "C: Connecting...");
            //create a socket to make the connection with the server
            Socket socket = new Socket(serverAddr, SERVERPORT);
            try {
                //send the message to the server
                out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(socket.getOutputStream())), true);
                Log.e("TCP Client", "C: Sent.");
                Log.e("TCP Client", "C: Done.");
                //receive the message which the server sends back
                in = new BufferedReader(new InputStreamReader(socket.getInputStream()));
                //in this while the client listens for the messages sent by the server
                while (mRun) {
                    serverMessage = in.readLine();
                    if (serverMessage != null && mMessageListener != null) {
                        //call the method messageReceived from MyActivity class
                        mMessageListener.messageReceived(serverMessage);
                    }
                    serverMessage = null;
                }
                Log.e("RESPONSE FROM SERVER", "S: Received Message: '" + serverMessage + "'");
            } catch (Exception e) {
                Log.e("TCP", "S: Error", e);
            } finally {
                //the socket must be closed. It is not possible to reconnect to this socket
                // after it is closed, which means a new socket instance has to be created.
                socket.close();
            }
        } catch (Exception e) {
            Log.e("TCP", "C: Error", e);
        }
    }
    //Declare the interface. The method messageReceived(String message) will must be implemented in the MyActivity
    //class at on asynckTask doInBackground
    public interface OnMessageReceived {
        public void messageReceived(String message);
    }
}


At the beginning of this class you have a constant SERVERIP. In this constant you have to put your computer IPv4. To do this open the commander and type ipconfig and press Enter. Then you will see your computer's IP.




 Also the SERVERPORT from this class (TCPClient) must be the same with the SERVERPORT from server class (TCPServer).

Now that the server and client classes are done, we have to set the interface a little. For this we will make a ListView in MyActivity class where we will get the messages sent and received, an EditText to enter the message from client side and a button to send the message. So let's begin.

2.go to res - layout - main.xml and put this code in main.xml:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
              android:orientation="vertical"
              android:layout_width="fill_parent"
              android:layout_height="fill_parent"
        >
    <ListView android:id="@+id/list"
              android:layout_width="fill_parent"
              android:layout_height="0dip"
              android:layout_weight="1"
              android:transcriptMode="alwaysScroll"
              android:cacheColorHint="#00000000"
              android:listSelector="@android:color/transparent"/>
    <LinearLayout android:id="@+id/footer"
                  android:layout_width="fill_parent"
                  android:layout_height="wrap_content"
                  android:orientation="horizontal"
                  android:gravity="bottom">
        <EditText android:inputType="textMultiLine|textNoSuggestions"
                  android:layout_width="0dp"
                  android:layout_height="40dp"
                  android:id="@+id/editText"
                  android:layout_weight="1"/>
        <Button android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:id="@+id/send_button"
                android:layout_gravity="center_vertical"
                android:text="send" />
    </LinearLayout>
</LinearLayout>

create a new xml file and call it "list_item.xml". This will contain a TextView for the messages which will be added to the ListView. The code will look like this:

3.<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:orientation="horizontal"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:id="@+id/list_item"
        android:gravity="center_vertical">
    <TextView android:layout_width="wrap_content"
              android:layout_height="wrap_content"
              android:id="@+id/list_item_text_view"
              android:textSize="20sp"
              android:padding="10dp"
              android:layout_marginLeft="5dp"/>
</LinearLayout>

4.create a new class and call it "MyCustomAdapter".  

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;
import java.util.ArrayList;
public class MyCustomAdapter extends BaseAdapter {
    private ArrayList<String> mListItems;
    private LayoutInflater mLayoutInflater;
    public MyCustomAdapter(Context context, ArrayList<String> arrayList){
        mListItems = arrayList;
        //get the layout inflater
        mLayoutInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    }
    @Override
    public int getCount() {
        //getCount() represents how many items are in the list
        return mListItems.size();
    }
    @Override
        //get the data of an item from a specific position
        //i represents the position of the item in the list
    public Object getItem(int i) {
        return null;
    }
    @Override
        //get the position id of the item from the list
    public long getItemId(int i) {
        return 0;
    }
    @Override
    public View getView(int position, View view, ViewGroup viewGroup) {
        //check to see if the reused view is null or not, if is not null then reuse it
        if (view == null) {
            view = mLayoutInflater.inflate(R.layout.list_item, null);
        }
        //get the string item from the position "position" from array list to put it on the TextView
        String stringItem = mListItems.get(position);
        if (stringItem != null) {
            TextView itemName = (TextView) view.findViewById(R.id.list_item_text_view);
            if (itemName != null) {
                //set the item name on the TextView
                itemName.setText(stringItem);
            }
        }
        //this method must return the view corresponding to the data at the specified position.
        return view;
    }
}

5.And now in the MyActivity class put the following code:
import android.app.Activity;
import android.os.AsyncTask;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ListView;
import java.util.ArrayList;
public class MyActivity extends Activity
{
    private ListView mList;
    private ArrayList<String> arrayList;
    private MyCustomAdapter mAdapter;
    private TCPClient mTcpClient;
    @Override
    public void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        arrayList = new ArrayList<String>();
        final EditText editText = (EditText) findViewById(R.id.editText);
        Button send = (Button)findViewById(R.id.send_button);
        //relate the listView from java to the one created in xml
        mList = (ListView)findViewById(R.id.list);
        mAdapter = new MyCustomAdapter(this, arrayList);
        mList.setAdapter(mAdapter);
        // connect to the server
        new connectTask().execute("");
        send.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                String message = editText.getText().toString();
                //add the text in the arrayList
                arrayList.add("c: " + message);
                //sends the message to the server
                if (mTcpClient != null) {
                    mTcpClient.sendMessage(message);
                }
                //refresh the list
                mAdapter.notifyDataSetChanged();
                editText.setText("");
            }
        });
    }
    public class connectTask extends AsyncTask<String,String,TCPClient> {
        @Override
        protected TCPClient doInBackground(String... message) {
            //we create a TCPClient object and
            mTcpClient = new TCPClient(new TCPClient.OnMessageReceived() {
                @Override
                //here the messageReceived method is implemented
                public void messageReceived(String message) {
                    //this method calls the onProgressUpdate
                    publishProgress(message);
                }
            });
            mTcpClient.run();
            return null;
        }
        @Override
        protected void onProgressUpdate(String... values) {
            super.onProgressUpdate(values);
            //in the arrayList we add the messaged received from server
            arrayList.add(values[0]);
            // notify the adapter that the data set has changed. This means that new message received
            // from server was added to the list
            mAdapter.notifyDataSetChanged();
        }
    }
}

6.And one last thing. Go to AndroidManifest.xml and put the internet permission just before the </manifest>:
<uses-permission android:name="android.permission.INTERNET" />

7.

  • Now that the project is done we must see how it actually works

1. First, you must open the server, so run the TCPServer class, the one that is made in Java and a window called ServerBoard will appear. Press on the start button like in the picture below. Do NOT start the android project before you press the start button!




     2. The server waits the client to connect now, so run the android project on the emulator and wait for the project to load.

    3. After the project is loaded enter a message in the EditText and send it. Your text should appear on the ListView.

    4. Now go back to the ServerBoard and send a message to the client from Android. The message from server side should appear on the ListView too.

    NOTE: If you test this on a device and it's not working, probably you should turn off all your firewall (from Windows, from antivirus) . And make sure that your device WIFI is turned on (because the android client must be on the same network as the server).

    I hope that this tutorial helped you :)






    Wednesday, 3 October 2012

    Android linkify

    Create Android Project..
    and add this code in mainactivity as given below u will understand how to linkify in android.


    package com.prashant.AndroidLinkify;

    import android.app.Activity;
    import android.os.Bundle;
    import java.util.regex.Matcher;
    import java.util.regex.Pattern;
    import android.text.util.Linkify;
    import android.text.util.Linkify.MatchFilter;
    import android.text.util.Linkify.TransformFilter;
    import android.widget.TextView;

    public class AndroidLinkifyMain extends Activity {
    @Override
    public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    TextView textView = (TextView)findViewById(R.id.textView1);
    textView.setText("This is a demo of custom text linkify, developed by prashant click here");

        MatchFilter matchFilter = new MatchFilter() {
    public final boolean acceptMatch(CharSequence s, int start, int end) {
    // you can compare match over here
    // return s.toString().equals("@prashant");
    return true;
     }
    };


    //to which convert
    TransformFilter transformFilter = new TransformFilter() {
    public final String transformUrl(final Matcher match, String url) {
    return "http://prashant18993.blogspot.in/";
    }
    };

    Pattern pattern = Pattern.compile("click here");
    String scheme = "http://";
    Linkify.addLinks(textView, pattern, scheme, matchFilter, transformFilter);
    }
    }

    output:

    main screen:

    after click on linkify.......


    Friday, 28 September 2012

    Image CoverFlow in android

    All Image from SD card show in Cover Flow style in android
    create android project and add this two file and also in Androidmainfest.xml file set mainactivity is CoverflowExample.java
    in src/ folder

    1.  Coverflow.java

    package com.prashant.coverflow;

    import android.widget.Gallery;
    import android.content.Context;
    import android.graphics.Camera;
    import android.graphics.Matrix;
    import android.util.AttributeSet;
    import android.view.View;
    import android.view.animation.Transformation;
    import android.widget.ImageView;

    public class Coverflow extends Gallery {

        /**
         * Graphics Camera used for transforming the matrix of ImageViews
         */
        private Camera mCamera = new Camera();

        /**
         * The maximum angle the Child ImageView will be rotated by
         */  
        private int mMaxRotationAngle = 60;
       
        /**
         * The maximum zoom on the centre Child
         */
        private int mMaxZoom = -120;
       
        /**
         * The Centre of the Coverflow
         */  
        private int mCoveflowCenter;
     
     public Coverflow(Context context) {
      super(context);
      this.setStaticTransformationsEnabled(true);
     }

     public Coverflow(Context context, AttributeSet attrs) {
      super(context, attrs);
            this.setStaticTransformationsEnabled(true);
     }

      public Coverflow(Context context, AttributeSet attrs, int defStyle) {
       super(context, attrs, defStyle);
       this.setStaticTransformationsEnabled(true);  
      }
     
        /**
         * Get the max rotational angle of the image
      * @return the mMaxRotationAngle
      */
     public int getMaxRotationAngle() {
      return mMaxRotationAngle;
     }

     /**
      * Set the max rotational angle of each image
      * @param maxRotationAngle the mMaxRotationAngle to set
      */
     public void setMaxRotationAngle(int maxRotationAngle) {
      mMaxRotationAngle = maxRotationAngle;
     }

     /**
      * Get the Max zoom of the centre image
      * @return the mMaxZoom
      */
     public int getMaxZoom() {
      return mMaxZoom;
     }

     /**
      * Set the max zoom of the centre image
      * @param maxZoom the mMaxZoom to set
      */
     public void setMaxZoom(int maxZoom) {
      mMaxZoom = maxZoom;
     }

     /**
         * Get the Centre of the Coverflow
         * @return The centre of this Coverflow.
         */
        private int getCenterOfCoverflow() {
            return (getWidth() - getPaddingLeft() - getPaddingRight()) / 2 + getPaddingLeft();
        }
       
        /**
         * Get the Centre of the View
         * @return The centre of the given view.
         */
        private static int getCenterOfView(View view) {
            return view.getLeft() + view.getWidth() / 2;
        }
        /**
      * {@inheritDoc}
      *
      * @see #setStaticTransformationsEnabled(boolean)
      */
        protected boolean getChildStaticTransformation(View child, Transformation t) {
     
      final int childCenter = getCenterOfView(child);
      final int childWidth = child.getWidth() ;
      int rotationAngle = 0;
     
      t.clear();
      t.setTransformationType(Transformation.TYPE_MATRIX);
     
            if (childCenter == mCoveflowCenter) {
                transformImageBitmap((ImageView) child, t, 0);
            } else {    
                rotationAngle = (int) (((float) (mCoveflowCenter - childCenter)/ childWidth) *  mMaxRotationAngle);
                if (Math.abs(rotationAngle) > mMaxRotationAngle) {
                 rotationAngle = (rotationAngle < 0) ? -mMaxRotationAngle : mMaxRotationAngle;  
                }
                transformImageBitmap((ImageView) child, t, rotationAngle);        
            }  
               
      return true;
     }

     /**
      * This is called during layout when the size of this view has changed. If
      * you were just added to the view hierarchy, you're called with the old
      * values of 0.
      *
      * @param w Current width of this view.
      * @param h Current height of this view.
      * @param oldw Old width of this view.
      * @param oldh Old height of this view.
         */
         protected void onSizeChanged(int w, int h, int oldw, int oldh) {
          mCoveflowCenter = getCenterOfCoverflow();
          super.onSizeChanged(w, h, oldw, oldh);
         }
     
         /**
          * Transform the Image Bitmap by the Angle passed
          *
          * @param imageView ImageView the ImageView whose bitmap we want to rotate
          * @param t transformation
          * @param rotationAngle the Angle by which to rotate the Bitmap
          */
         private void transformImageBitmap(ImageView child, Transformation t, int rotationAngle) {          
          mCamera.save();
          final Matrix imageMatrix = t.getMatrix();;
          final int imageHeight = child.getLayoutParams().height;;
          final int imageWidth = child.getLayoutParams().width;
          final int rotation = Math.abs(rotationAngle);
                       
          mCamera.translate(0.0f, 0.0f, 100.0f);
           
          //As the angle of the view gets less, zoom in    
          if ( rotation < mMaxRotationAngle ) {
           float zoomAmount = (float) (mMaxZoom +  (rotation * 1.5));
           mCamera.translate(0.0f, 0.0f, zoomAmount);        
          }
         
          mCamera.rotateY(rotationAngle);
          mCamera.getMatrix(imageMatrix);              
          imageMatrix.preTranslate(-(imageWidth/2), -(imageHeight/2));
          imageMatrix.postTranslate((imageWidth/2), (imageHeight/2));
          mCamera.restore();
     }
    }


    2.CoverflowExample.java

    package com.prashant.coverflow;

    import java.io.File;
    import java.io.FileInputStream;
    import java.io.FileReader;
    import java.io.FilenameFilter;
    import java.util.ArrayList;
    import java.util.List;

    import android.app.Activity;
    import android.content.Context;
    import android.database.Cursor;
    import android.graphics.Bitmap;
    import android.graphics.BitmapFactory;
    import android.graphics.Canvas;
    import android.graphics.LinearGradient;
    import android.graphics.Matrix;
    import android.graphics.Paint;
    import android.graphics.PorterDuffXfermode;
    import android.graphics.Bitmap.Config;
    import android.graphics.PorterDuff.Mode;
    import android.graphics.Shader.TileMode;
    import android.graphics.drawable.BitmapDrawable;
    import android.net.Uri;
    import android.os.Bundle;
    import android.os.Environment;
    import android.provider.MediaStore;
    import android.util.Log;
    import android.view.View;
    import android.view.ViewGroup;
    import android.widget.BaseAdapter;
    import android.widget.ImageView;
    import android.widget.ImageView.ScaleType;

    public class CoverflowExample extends Activity {
    private Cursor cursor;
    private int columnIndex;
        /** Called when the activity is first created. */
        @Override
        public void onCreate(Bundle savedInstanceState) {
         super.onCreate(savedInstanceState);
       
         Coverflow coverFlow;
         coverFlow = new Coverflow(this);
         String[] projection = {MediaStore.Images.Thumbnails._ID};
         cursor = managedQuery( MediaStore.Images.Thumbnails.EXTERNAL_CONTENT_URI,
                 projection, // Which columns to return
                 null,       // Return all rows
                 null,
                 MediaStore.Images.Thumbnails.IMAGE_ID);
         columnIndex = cursor.getColumnIndexOrThrow(MediaStore.Images.Thumbnails._ID);

    coverFlow.setAdapter(new ImageAdapter(this));
         coverFlow.setSpacing(-25);
         coverFlow.setSelection(4, true);
         coverFlow.setAnimationDuration(1000);
         setContentView(coverFlow);
        }
     
     

    public class ImageAdapter extends BaseAdapter {
         int mGalleryItemBackground;
         private Context mContext;
         public ImageAdapter(Context c) {
             mContext = c;
         }
         public int getCount() {
             return cursor.getCount();
         }

         public Object getItem(int position) {
             return position;
         }

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

         public View getView(int position, View convertView, ViewGroup parent) {

          //Use this code if you want to load from resources
             ImageView i = new ImageView(mContext);
           
             if (convertView == null) {
                 i = new ImageView(mContext);
                 // Move cursor to current position
                 cursor.moveToPosition(position);
                 // Get the current value for the requested column
                 int imageID = cursor.getInt(columnIndex);
                 // Set the content of the image based on the provided URI
                 i.setImageURI(Uri.withAppendedPath(
                         MediaStore.Images.Thumbnails.EXTERNAL_CONTENT_URI, "" + imageID));
                 i.setScaleType(ImageView.ScaleType.CENTER_INSIDE);
               //  i.setPadding(8, 8, 8, 8);
                 i.setLayoutParams(new Coverflow.LayoutParams(250, 250));
             }
             else {
                 i = (ImageView)convertView;
             }
             BitmapDrawable drawable = (BitmapDrawable) i.getDrawable();
             drawable.setAntiAlias(true);
             return i;
         
          //return mImages[position];
         }
       /** Returns the size (0.0f to 1.0f) of the views
          * depending on the 'offset' to the center. */
          public float getScale(boolean focused, int offset) {
              return Math.max(0, 1.0f / (float)Math.pow(2, Math.abs(offset)));
          }

     }
    }

    OUTPUT:
    Download source code Here...