Wednesday, January 18, 2012

custom girdview on top and custom listview below which iterates itself.

package com.inception.smui;
/**
 * Class Name : ProfilesList
 *
 * Parent Class :Activity
 *
 * Interfaces: None
 *
 * Description:It will display the profiles related each and every sub-category
 */
import java.util.ArrayList;
import java.util.List;

import com.ServiceMessenger.R;
import com.inception.dataparser.Category;
import com.inception.dataparser.Service1;
import com.inception.dataparser.ServiceProvider;
import com.inception.dataparser.UserComments;
import com.inception.dataprovider.DatabaseHelper;
import com.inception.sm.ApplicationManager;
import com.inception.sm.Globals;
import com.inception.sm.MyAppContext;


import android.R.color;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.Dialog;
import android.app.ProgressDialog;
import android.content.ComponentName;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.ServiceConnection;
import android.content.res.TypedArray;
import android.graphics.Bitmap;
import android.graphics.Color;
import android.graphics.Rect;
import android.os.Bundle;
import android.os.Handler;
import android.os.IBinder;
import android.os.Message;
import android.os.Messenger;
import android.os.RemoteException;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.Gallery;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.Toast;

public class SubCategoryMenu extends BaseClass{
    String TAG="SubCategoryMenu";

    private DatabaseHelper mDBHelper;
    private static final int INDETERMINATE = 0;
    private ProgressDialog mProgDlg;
    private static ApplicationManager mAppMgr;
    TextView tv;

    private ArrayList<ServiceProvider> mProfileList = new ArrayList<ServiceProvider>();
    //private ArrayList<ServiceProvider> mProfileList = new ArrayList<ServiceProvider>();
    public ArrayList<String> mList = new ArrayList<String>();
    public ArrayList<String> mList1 = new ArrayList<String>();
    public ArrayList<String> mList2 = new ArrayList<String>();
    public List<String> mList3 = null;
    public List<String> mCatUrls=new ArrayList<String>();
    private List<Bitmap> mCatImg=new ArrayList<Bitmap>();
    private List<String> mProfileId = new ArrayList<String>();
    private ArrayList<String> mCatid = new ArrayList<String>();
    private ArrayList<Category> mSubCatList = new ArrayList<Category>();
    ArrayList<Service1> serviceList=null;
    ArrayList<String> mProfileIds=null;
    ArrayList<String> mProfileCities=null;
    ArrayList<String> mProfileCountries=null;
    ArrayList<String> mProfileRatings=null;
    ArrayList<String> mProfileDes=null;
    ArrayList<String> mProfileNames=null;
    ArrayList<String> mProfileOnlinestatus=null;
    ArrayList<String> mProfile_pic_url=null;
    ArrayList<UserComments> usercomments=null;
    ArrayList<Messenger> mClients = new ArrayList<Messenger>();
    private Context mContext;
    boolean mIsBound;
    private int mCurrentView;
    //widgets

    public ListView mListView;
    private Gallery mGallery;
    public Button mBtn1,mBtn2;
    private LayoutInflater mInflater;
    MyAppContext mAppctx;

    public static String mCategory_id;
    public static String mSubcat;
    private static CharSequence pid;
    //public static String mCat;
    public static int mView;
    public static CharSequence cat;
    private Category mCat = new Category();
    BaseClass b = new BaseClass();

    /**
     * Callback method to launch the Acitivity
     *
     */

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        mDBHelper = new DatabaseHelper(this);
        mAppMgr = ApplicationManager.getApplicationMgrInstance(this.getApplicationContext());
        setContentView(R.layout.profile);
        mListView=(ListView)findViewById(R.id.lv_user1);
        mGallery = (Gallery) findViewById(R.id.gallery_catlog);
        mList3= new ArrayList<String>();
        mList3=mAppMgr.getCategories();
        mCatUrls=mAppMgr.getCategoriesUrls();
        Log.e(TAG,mCatUrls.get(0));
        mCatImg=mAppMgr.getCategoryImgs();
        mContext=this;
        mBtn1=(Button)findViewById(R.id.button_MyAcct1);
        mBtn2=(Button)findViewById(R.id.button_MySP1);
        /**
         *Button click listener for MyAccpunt button
         */
        mBtn1.setOnClickListener(new View.OnClickListener(){

            @Override
            public void onClick(View v) {
                Log.e(TAG,"button My Account clicked");
                if(CategoryMenu.mStatus){
                    Log.e("am in","login status true" );
                    MyAccount.mCurrentView1=Globals.SENT_FROM_SPLIST;
                    Intent i=new Intent(SubCategoryMenu.this,MyAccount.class);
                    startActivity(i);
                }
                else
                {
                    LoginInfo.mCurrentView1=Globals.LOGIN_IN_MYACCOUNT;
                    Intent i=new Intent(SubCategoryMenu.this,LoginInfo.class);
                    startActivity(i);

                }
            }

        });


        /**
         *Button click listener for MySPs button
         */
        mBtn2.setOnClickListener(new View.OnClickListener(){

            @Override
            public void onClick(View v) {
                Log.e(TAG,"button 1 clicked");
                if(CategoryMenu.mStatus){
                    Log.e("am in","login status true" );
                    Intent i=new Intent(mContext,MyAccount.class);
                    startActivity(i);
                }
                else
                {
                    LoginInfo.mCurrentView1=Globals.LOGIN_IN_MYACCOUNT;
                    Intent i=new Intent(mContext,LoginInfo.class);
                    startActivity(i);

                }
            }

        });
       
        mAppctx = (MyAppContext)getApplicationContext();
        mGallery.setAdapter(new ImageAdapter(mContext));
        //mGallery.setFadingEdgeLength(20); 
        Intent ip = getIntent();
        //int view= ip.getIntExtra("view", Globals.CONST_SUBCATEGORY);

        cat=(String) ip.getCharSequenceExtra("cat");
        Log.d("cat",""+cat);
        int view=(int) ip.getIntExtra("view", 0);
        Log.d("view",""+view);

        //if(view  == Globals.CONST_SUBCATEGORY)
        //{
        //mList = null;
        cat = ip.getCharSequenceExtra("cat");
        Log.d("subcatarory",""+cat);

        mCurrentView = Globals.CONST_SUBCATEGORY;

        mSubCatList=mAppMgr.getSubCategories(cat);
        /*if(mSubCatList.size()==0)
            {
                finish();
                //mCurrentView = Globals.CONST_PROFILE;
            }
            else{*/
        System.out.println(mSubCatList);

        Log.d("u r in ",cat.toString());
        mList2 = prepareStringList1();
        Log.d("mList2",""+mList2.size());

        mListView.setAdapter(new ArrayAdapter<String>(this,R.layout.list_item3,R.id.subCatlog_text,mList2));
        //}

        //}








        //mSubcat = (String) ip.getCharSequenceExtra("subcat");
        //Log.e(TAG,mSubcat);
        //mList1= null;
        /*    SQLiteDatabase database = mDBHelper.getWritableDatabase();

        Cursor data = database.query("catalog2", new String[] {"category_id"},new String("category_name"+"=?"),new String[]{mSubcat.toString()}, null, null, null);
        if (data != null)
        {
            Log.d("database",database.toString());
            if (data.moveToFirst()){
                mCategory_id= data.getString(data.getColumnIndex("category_id"));


            }
        }*/

        /**
         *List item click listener for profiles
         */

        mListView.setOnItemClickListener(new OnItemClickListener() {
            public void onItemClick(AdapterView<?> parent, View view,
                    int position, long id) {
                Log.d("SM","position "+position);
                mCat = new Category();
                if(mCurrentView == Globals.CONST_SUBCATEGORY){



                    CharSequence category = mList2.get(position);
                    CharSequence catSelectId = mCatid.get(position);

                    Log.e("subcategory clicked",""+ catSelectId);

                    mCat=mAppMgr.getCategoryObjectFromId(catSelectId);
                    String isleaf = mCat.getIs_leaf();
                    String cat_id=mCat.getCategory_id();
                    String cat_name=mCat.getCategory_name();
                    //String parent_id=mCat.getParent_id();

                    Log.e("isleaf",isleaf);
                    if(isleaf.equals("false"))
                    {
                        Log.d("false executed","Thanks");
                        mSubCatList=mAppMgr.getSubCategories(cat_id);
                        System.out.println(mSubCatList);
                        mCurrentView = Globals.CONST_SUBCATEGORY;
                        mList2 = prepareStringList1();
                        mListView.setAdapter(new ArrayAdapter<String>(mContext,R.layout.list_item3,R.id.subCatlog_text,mList2));

                    }
                    else
                    {
                        Intent i=new Intent(SubCategoryMenu.this,ProfilesList.class);
                        Log.d("true executed","Thanks");
                        mAppctx.setCatId(cat_id);
                        mAppctx.setCatName(cat_name);
                        //i.putExtra("cat",cat_id);
                        //i.putExtra("view", Globals.CONST_PROFILE);
                        startActivity(i);

                    }
                    //Log.e("am in","sub categories");
                    //startActivity(i);


                }




            }
        });

        /**
         *Gallery item click listener for categories
         */

        mGallery.setOnItemClickListener(new OnItemClickListener() {
            public void onItemClick(AdapterView<?> parent, View v, int position, long id) {
                mCat = new Category();
                //v.setFocusable(true);
                //tv.setText("");
                CharSequence cat = mList3.get(position);
                Log.e("category clicked",""+ cat);
                CharSequence category = cat;
                mCat=mAppMgr.getCategoryObjectFromName(category);
                String isleaf = mCat.getIs_leaf();
                String parent_id=mCat.getParent_id();
                String cat_id=mCat.getCategory_id();
                Log.e("cat_id",cat_id);

                Log.e("isleaf",isleaf);
                //Log.e("parent_id",parent_id);
                if(isleaf.equals("false"))
                {
                    callsubcatlog(cat_id);
                }
                else
                {
                    Intent i=new Intent(mContext,ProfilesList.class);
                    Log.d("true executed","Thanks");

                    //i.putExtra("cat",cat_id);
                    mAppctx.setCatId(cat_id);

                    startActivity(i);

                }


            }
           
        });
       
       
    }



    public ArrayList<String> prepareStringList1()
    {

        int i =0;
        Log.e("am in","prepare string list");
        //    Log.e(TAG+"mList1.size()",""+mList1.size());
        mCatid=new ArrayList<String>();
        ArrayList<String> List2=new ArrayList<String>();
        //misleaf=new ArrayList<String>();
        for(;i< mSubCatList.size();i++){
            String profileStr = mSubCatList.get(i).category_id;
            String profileStr1 = mSubCatList.get(i).category_name;
            //String isleaf=mList1.get(i).is_leaf;

            Log.e("profileStr1",profileStr);
            mCatid.add(profileStr);

            List2.add(profileStr1);

            //misleaf.add(isleaf);



        }
        Log.e("TAG+mList1.size()",""+mSubCatList.size());


        return List2;
    }



    void callsubcatlog(String cat_id)
    {
        mSubCatList=mAppMgr.getSubCategories(cat_id);
        if(mSubCatList.size()==0)
        {
            finish();
            mCurrentView = Globals.CONST_PROFILE;
        }
        else{
            System.out.println(mSubCatList);

            Log.d("u r in ",cat.toString());
            mList2 = prepareStringList1();
            Log.d("mList2",""+mList2.size());

            mListView.setAdapter(new ArrayAdapter<String>(this,R.layout.list_item3,R.id.subCatlog_text,mList2));
        }
    }

    /**
     * To set image in profile list
     */
    class IconicAdapter extends ArrayAdapter {
        IconicAdapter() {
            super(SubCategoryMenu.this, R.layout.list_item,R.id.text,mProfileNames);
        }

        public View getView(int position, View convertView,
                ViewGroup parent) {
            LayoutInflater inflater=getLayoutInflater();
            View row=inflater.inflate(R.layout.list_item, parent,    false);


            ImageView icon=(ImageView)row.findViewById(R.id.icon);
            TextView label=(TextView)row.findViewById(R.id.text);
            label.setText(mProfileNames.get(position)+","+mProfileCountries.get(position));

            /*    if (mList1.get(0).startsWith("abc")) {
                Log.e("am in","abc profile");
                icon.setImageResource(R.drawable.icon);
            }
            if (mList1.get(0).startsWith("xyz")) {
                icon.setImageResource(R.drawable.d1);
                Log.e("am in","xyz profile");
            }*/

            return(row);
        }
    }
    /**
     * To papulate images , data in catalog gallery
     */

    public class ImageAdapter extends BaseAdapter {
        int mGalleryItemBackground;
        private Context mContext;
        ViewHolder holder;

        public ImageAdapter(Context c) {
            mContext = c;
            mInflater = LayoutInflater.from(c);

            TypedArray a = obtainStyledAttributes(R.styleable.Theme);
            mGalleryItemBackground = a.getResourceId(
                    R.styleable.Theme_android_galleryItemBackground, 0);
            a.recycle();
        }

        public int getCount() {
            Log.i(TAG+"i am taking images from local DB","");
            //mCatImg=mAppMgr.getCategoryImgs();
            return mCatUrls.size();
            //return mCatImg.size();
        }

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

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

        /**
         * To papulate each view of gallery with textview and imageview
         */

        public View getView(int position, View convertView, ViewGroup parent) {
            if (convertView == null) {
                convertView = mInflater.inflate(R.layout.list_item_icon_text, null);
               
               
                //convertView.setLayoutParams(new Gallery.LayoutParams(100, 150));
                // Creates a ViewHolder and store references to the two children views
                // we want to bind data to.
                holder = new ViewHolder();
                holder.text = (TextView) convertView.findViewById(R.id.text);
                holder.icon = (ImageView) convertView.findViewById(R.id.icon);
                convertView.setTag(holder);
               
               
            } else {
                // Get the ViewHolder back to get fast access to the TextView
                // and the ImageView.
                holder = (ViewHolder) convertView.getTag();
            }

            // Bind the data efficiently with the holder.
            holder.text.setText(mList3.get(position));
            holder.icon.setImageBitmap(mCatImg.get(position));

            holder.icon.setBackgroundResource(mGalleryItemBackground);
            return convertView;


        }
       


    }
    /**
     * To Hold TextView and ImageView
     */

    static class ViewHolder {
        TextView text;
        ImageView icon;
    }


}



list_item_icon_text.xml layout for custom gallery


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


<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical" android:layout_width="match_parent"
    android:layout_height="match_parent">

    <ImageView android:id="@+id/icon" android:layout_width="100dip"
        android:layout_height="100dip" />

    <TextView android:id="@+id/text" android:layout_width="100dip"

        android:layout_height="wrap_content" />

</LinearLayout>

profile.xml

<?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:background="@drawable/bk_gnd">
    <TextView android:id="@+id/empty" android:layout_width="fill_parent"
        android:layout_height="15dip" />
    <TextView android:id="@+id/catlogs_gallery_text" android:layout_width="fill_parent"
        android:layout_height="wrap_content" android:text="Categories"
        android:textColor="@color/menu_buttons" android:textSize="20sp"
        android:gravity="center" android:layout_below="@id/empty" />
    <TextView android:id="@+id/empty1" android:layout_width="fill_parent"
        android:layout_height="15dip" android:layout_below="@id/catlogs_gallery_text" />
    <Button android:id="@+id/button_MyAcct1" android:text="MyAccount"
        android:textSize="@dimen/menu_buttons_text_size" android:textColor="@color/menu_buttons"
        android:textStyle="bold" android:gravity="center"
        android:layout_width="wrap_content" android:layout_height="wrap_content"
        android:layout_alignParentBottom="true" android:background="@drawable/button_menu" />

    <Button android:id="@+id/button_MySP1" android:text="MySPs"
        android:textSize="@dimen/menu_buttons_text_size" android:textColor="@color/menu_buttons"
        android:textStyle="bold" android:gravity="center"
        android:layout_width="wrap_content" android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"

        android:layout_alignParentRight="true" android:background="@drawable/button_menu" />
    <Gallery android:id="@+id/gallery_catlog" android:layout_width="fill_parent"
        android:layout_height="wrap_content" android:layout_below="@id/catlogs_gallery_text" />
    <TextView android:id="@+id/empty2" android:layout_width="fill_parent"
        android:layout_height="15dip" android:layout_below="@id/gallery_catlog" />
    <TextView android:id="@+id/txt_subCat" android:layout_width="fill_parent"
        android:layout_height="wrap_content" android:text="Sub Categories"
        android:textColor="@color/menu_buttons" android:textSize="20sp"
        android:gravity="center" android:layout_below="@id/empty2" />
    <TextView android:id="@+id/txt_selectsubCat" android:layout_width="fill_parent"
        android:layout_height="wrap_content" android:text="Select any category to get subcategories"
        android:textColor="@color/menu_buttons" android:layout_below="@id/txt_subCat" />
    <ListView android:textSize="150sp" android:layout_width="fill_parent"
        android:layout_height="wrap_content" android:id="@+id/lv_user1"
        android:layout_below="@id/txt_selectsubCat" />

</RelativeLayout>

list_item3.xml

<?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">

   
    <TextView android:id="@+id/subCatlog_text" android:layout_width="fill_parent"
        android:layout_height="fill_parent" android:layout_toRightOf="@id/icon"
        android:padding="5dp" android:textSize="@dimen/menu_buttons_text_size"
        android:textColor="@color/menu_buttons" android:textStyle="bold"


        android:layout_margin="5dp" />

    <ImageView android:layout_width="wrap_content"
        android:layout_height="wrap_content" android:layout_centerVertical="true"
        android:id="@+id/iv_forward" android:src="@drawable/arrow1"

        android:layout_alignParentRight="true" android:layout_marginRight="10dip">
    </ImageView>
</RelativeLayout>

horizontal gallery view which contains image and texts like profile



//gallery wedgets
    private ScrollView nsv;
    private HorizontalScrollView sv;
    private LinearLayout llh;
    private LinearLayout.LayoutParams layoutParamsTV;
    private LinearLayout.LayoutParams layoutParamsLL;
    private LinearLayout.LayoutParams layoutParamsLLD;
    private LinearLayout.LayoutParams layoutParamsTXT;
    private LinearLayout.LayoutParams layoutParamsIMG;
    private LinearLayout.LayoutParams layoutParamsHOLDER;
    private LinearLayout llHoder;
    private LinearLayout llFrame;
    private LinearLayout lltxts;
    private LinearLayout llv;
    static int  total;

    //widgets
    ImageView img1;
    TextView txt_Name;
    TextView txt_Charge;
    TextView txt_CatName;
    Button b1;

    public ListView mListView;
    MyAppContext mAppctx;



Call the following method to create gallery and load views


public void horizontalScrollGalleryLayout (List<String> mList3,List<String> mList4,List<String> mList5,List<Service1> mList6) {
        Integer[] mThumbIds = {
                R.drawable.ds

        };
        total=0;
        Log.i("I got call","for creation of horizontalgallery");
        sv = new HorizontalScrollView(this);
        llh = new LinearLayout(this);
        llh.setOrientation(LinearLayout.HORIZONTAL);
        layoutParamsTV = new LinearLayout.LayoutParams(150,190);
        layoutParamsTV.setMargins(3, 30, 3, 30);
       
        layoutParamsIMG = new LinearLayout.LayoutParams(60,150);
        layoutParamsIMG.setMargins(3, 3, 3, 3);
        layoutParamsIMG.height=60;
        layoutParamsIMG.width= 60;
        layoutParamsTXT = new LinearLayout.LayoutParams(75,150);
        layoutParamsTXT.setMargins(3, 3, 3, 3);

        layoutParamsLL = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT);
        layoutParamsLLD = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.FILL_PARENT, LinearLayout.LayoutParams.FILL_PARENT);
        Log.e("in horizantal","scroll view 1");
        for(int k=0;k<mList3.size();k++)
        {  
            if(mList3.size()==total)
            {
                break;
            }
            llv = new LinearLayout(this);
           
            //llv.setBackgroundColor(R.drawable.border);
            for (int i=0; i<2; i++) {
                llv.setOrientation(LinearLayout.VERTICAL);
               

                llFrame = new LinearLayout(this);
                //llFrame.setPadding(1,1,1,1);
                //llFrame.setBackgroundColor(0xFFB0C4DE );
                llFrame.setBackgroundResource(R.drawable.layout_border);
               
                lltxts=new LinearLayout(this);
                lltxts.setOrientation(LinearLayout.VERTICAL);
                llFrame.setOrientation(LinearLayout.HORIZONTAL);   
                //button=new Button(this);
                img1 = new ImageView(this);
                txt_Name = new TextView(this);
                txt_CatName = new TextView(this);
                txt_Charge=new TextView(this);
                mCat = new Category();
                try {

                    img1.setImageResource(mThumbIds[0]);
                   
                    //img1.setTag(mList4.get(total));
                    img1.setTag(total);
                    if(!mProfile_pic_url.get(total).equals("null")&&!(mProfile_pic_url.get(total).startsWith(".."))&&(mProfile_pic_url.get(total)!=null)&&!(mProfile_pic_url.get(total).equals("")))
                    new DownloadImageAsyncTask(mProfileIds.get(total),mAppMgr,img1,"profile_img").execute(mProfile_pic_url.get(total));
                       
                    txt_Name.setText("Name : "+mList3.get(total));
                    txt_Name.setTextColor(Color.WHITE);
                    txt_CatName.setText("Category : "+mAppctx.getCatName());
                    txt_CatName.setTextColor(Color.WHITE);
                    txt_Charge.setText("Charge : "+mList6.get(total).service_charge);
                    txt_Charge.setTextColor(Color.WHITE);




                    //tx.setPadding(25, 0, 15, 0);
                    //txt_Name.setGravity(Gravity.CENTER_VERTICAL | Gravity.CENTER_HORIZONTAL);

                    img1.setOnClickListener(new View.OnClickListener() {
                        public void onClick(View view) {
                            // Perform action on click
                            //CharSequence cat = "Education";
                            Log.e("TAG","I entered const profile");
                            Integer id = (Integer) view.getTag();
                            Log.e("imgTag after clicked",""+ id);
                            pid=mProfileIds.get(id);
                            //pid=(CharSequence) img1.getTag();
                            Log.i("profileid",""+pid);
                            ArrayList<UserComments> personal_usercomments=new ArrayList<UserComments>();
                            //UserComments u=new UserComments();
                            //CharSequence pid = mList2.get(position);
                            for(int i=0;i<usercomments.size();i++)
                            {
                                UserComments u=new UserComments();
                                Log.i("size is",""+usercomments.size());
                                if(usercomments.get(i).sp_profileid.equals(pid))
                                {
                                    //UserComments u=new UserComments();
                                    u.name=usercomments.get(i).name;
                                    u.userComments=usercomments.get(i).userComments;
                                    personal_usercomments.add(u);
                                }

                            }
                            Log.e("pid is ",""+ pid);
                            ProfileInfo.mCurView=Globals.SENT_FROM_SPLIST;
                            Intent i1=new Intent(ProfilesList.this,ProfileInfo.class);
                            i1.putExtra("profileid", pid);
                            i1.putExtra("rating",mProfileRatings.get(id));
                            i1.putExtra("profilename",mProfileNames.get(id));
                            i1.putExtra("service_charge",serviceList.get(id).service_charge);
                            i1.putExtra("service_id", serviceList.get(id).service_id);
                            i1.putExtra("profiledes",mProfileDes.get(id));
                            i1.putParcelableArrayListExtra("comments", personal_usercomments);
                            i1.putExtra("country", mProfileCountries.get(id));
                            i1.putExtra("city", mProfileCities.get(id));

                            i1.putExtra("pic_url",mProfile_pic_url.get(id));
                            Log.e(TAG,"pic_url"+mProfile_pic_url.get(id));
                            startActivity(i1);

                        }
                    });
                    //if(total==13)
                    //break;
                    //new DownloadImageAsyncTask(mProfileIds.get(total),mAppMgr,img1,"profile_img").execute(Configure.SM_SERVER_URL_PREFIX+(mProfile_pic_url.get(total)));
                    total++;

                } catch (Exception e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
                lltxts.addView(txt_Name);
                lltxts.addView(txt_CatName);
                lltxts.addView(txt_Charge);
                llFrame.addView(img1,layoutParamsIMG);
                llFrame.addView(lltxts,layoutParamsTXT);
               
                llv.addView(llFrame,layoutParamsTV);
                //llv.addView(txt_Name);
                //llv.addView(txt_CatName);
                //llv.addView(txt_Charge);
                if(mList3.size()==total)
                    break;
                //b1[k].setBackgroundResource(mThumbIds[k]);
            }

            //llv.addView(button, layoutParamsTV);

            llh.addView(llv, layoutParamsLL);
            llh.setBackgroundColor(Color.TRANSPARENT);
            llh.setHorizontalScrollBarEnabled(false);
        }

        sv.addView(llh, layoutParamsLLD);
        //nsv.addView(sv);
        sv.setHorizontalScrollBarEnabled(false);
        //nsv.setVerticalScrollBarEnabled(false);
        setContentView(sv);
        //setContentView(nsv);

    }

put layoutborder.xml in drawable forlder which puts border.

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
    <item>
        <shape android:shape="rectangle">
            <stroke android:width="5dp" android:height="5dp"
                android:color="#FFC0C0C0" />
            <solid android:color="#000000" />
            <padding android:left="1dp" android:top="1dp" android:right="1dp"
                android:bottom="1dp" />

            <corners android:radius="1dp" android:bottomRightRadius="5dp"
                android:bottomLeftRadius="5dp" android:topLeftRadius="5dp"
                android:topRightRadius="5dp" />
        </shape>
    </item>

</layer-list>

How to store cookie in Android execute post and attach with url

following methods make global application context for http Reques & Response


 /** Single instance of our HttpClient */
    private static HttpClient mHttpClient;
    private static HttpContext mHttpContext;
    private static Bitmap bitmap;

    public static Cookie mSessionCookie;

    static String TAG="CustomHttpClient";

    /**
     * Get our single instance of our HttpClient object.
     *
     * @return an HttpClient object with connection parameters set
     */
    public static HttpClient getHttpClient() {
        if (mHttpClient == null) {
            mHttpClient = new DefaultHttpClient();
            final HttpParams params = mHttpClient.getParams();
           
            HttpConnectionParams.setConnectionTimeout(params, HTTP_TIMEOUT);
            HttpConnectionParams.setSoTimeout(params, HTTP_TIMEOUT);
            ConnManagerParams.setTimeout(params, HTTP_TIMEOUT);
        }
        return mHttpClient;
    }
private static HttpContext getHttpContext(){
    if(mHttpContext==null){
        mHttpContext=new BasicHttpContext();
    }
    return mHttpContext;
}




storing cookie in execute post method.



public static String executeHttpPost(String url, ArrayList<NameValuePair> postParameters) throws Exception {
        BufferedReader in = null;
        try {
            HttpClient client = getHttpClient();
            // Create a local instance of cookie store
            CookieStore cookieStore = new BasicCookieStore();
            // Create local HTTP context
            HttpContext localContext=getHttpContext();
            // Bind custom cookie store to the local context
            localContext.setAttribute(ClientContext.COOKIE_STORE, cookieStore);
           
            HttpPost request = new HttpPost(url);
         
            UrlEncodedFormEntity formEntity = new UrlEncodedFormEntity(postParameters);
            Log.e( "postParameters",""+ postParameters);
            Log.e("formEntity",""+formEntity);

            /*    MultipartEntity entity = new MultipartEntity(
                    HttpMultipartMode.BROWSER_COMPATIBLE);

            ByteArrayOutputStream bos = new ByteArrayOutputStream();
            bitmap.compress(CompressFormat.JPEG, 100, bos);
            byte[] data = bos.toByteArray();
            entity.addPart("returnformat", new StringBody("json"));
            entity.addPart("uploaded", new ByteArrayBody(data,
                    "myImage.jpg"));*/
            request.setEntity(formEntity);
            HttpResponse response = client.execute(request,localContext);
            //HttpResponse response = client.execute(request);
            Log.e("headers",""+response.headerIterator());
           //String mSessionId=null;
          //  Log.e("mSessionId",""+mSessionId);
            HeaderElementIterator it = new BasicHeaderElementIterator(
                    response.headerIterator());
            while (it.hasNext()) {
                HeaderElement elem = it.nextElement();
                System.out.println(elem.getName() + " = " + elem.getValue());
                if(elem.getName().equals("JSESSIONID")){
                    NetworkManager.mSessionId=elem.getValue();
                }
                NameValuePair[] params = elem.getParameters();
                for (int i = 0; i < params.length; i++) {
                    System.out.println(" " + params[i]);
                }
            }

           
            in = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));

            StringBuffer sb = new StringBuffer("");
            String line = "";
            String NL = System.getProperty("line.separator");
            while ((line = in.readLine()) != null) {
                sb.append(line + NL);
            }
            in.close();

            String result = sb.toString();
            List<Cookie> cookies = cookieStore.getCookies();
            Log.e("CustomHttpClient","Cookies size= " + cookies.size());
            for (int i = 0; i < cookies.size(); i++) {
                Cookie cookie = cookies.get(i);
                Log.e("CustomHttpClient","Local cookie: " + cookie);
                mSessionCookie = cookie;
                Log.e("CustomHttpClient",""+cookie.getValue());
            }
           
            return result;
        } finally {
            if (in != null) {
                try {
                    in.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
    }


follwing class where we using stored cookie to attach with url to launch url in webview .store that cookiew in Application class in android and retrive where ever you are using.

WebClinetforPaypa.java


package com.inception.smui;

import org.apache.http.cookie.Cookie;


import com.ServiceMessenger.R;
import com.inception.dataparser.Configure;
import com.inception.dataparser.JSONSMParser;
import com.inception.network.CustomHttpClient;
import com.inception.sm.MyAppContext;

import android.app.Activity;
import android.content.Intent;
import android.os.AsyncTask;
import android.os.Bundle;
import android.os.SystemClock;

import android.util.Log;
import android.webkit.CookieManager;
import android.webkit.CookieSyncManager;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.TextView;

public class WebClinetforPaypal extends Activity{
    WebView mWebview;
    MyAppContext mAppctx;
    String url_paypal;
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.webview);
        mAppctx = (MyAppContext)getApplicationContext();       
        Intent i=getIntent();
        url_paypal=(String) i.getCharSequenceExtra("url");

        mWebview = (WebView) findViewById(R.id.web_engine);

        new WebViewTask().execute();


    }
    private class WebViewTask extends AsyncTask<Void, Void, Boolean> { 
        Cookie sessionCookie; 
        CookieManager cookieManager; 

        @Override 
        protected void onPreExecute() { 
            CookieSyncManager.createInstance(WebClinetforPaypal.this); 
            cookieManager = CookieManager.getInstance(); 

            sessionCookie = mAppctx.getMySessionCookie(); 
            Log.i("sessionCookie",""+sessionCookie);
            if (sessionCookie != null) { 
                // delete old cookies 
                cookieManager.setAcceptCookie(true);
                cookieManager.removeSessionCookie(); 
            } 
            super.onPreExecute(); 
        } 
        protected Boolean doInBackground(Void... param) { 
            // this is very important - THIS IS THE HACK 
            SystemClock.sleep(1000); 
            return false; 
        } 
        @Override 
        protected void onPostExecute(Boolean result) { 
            if (sessionCookie != null) { 
                //cookieManager.setCookie("http://50.28.26.182/SMS_rajesh", sessionCookie.getName() +"="+sessionCookie.getValue()+"; domain="+sessionCookie.getDomain());
                cookieManager.setCookie(Configure.SM_SERVER_DOMAIN_NAME+"/"+
                        Configure.SM_SERVER_WAR_FILE_NAME, sessionCookie.getName() +
                        "="+sessionCookie.getValue()+"; domain="+
                                sessionCookie.getDomain()); 
                CookieSyncManager.getInstance().sync(); 
            } 
            mWebview.getSettings().setJavaScriptEnabled(true);
            mWebview.setWebViewClient(new WebViewClient() { 
                @Override 
                public boolean shouldOverrideUrlLoading(WebView view, String url) { 
                    return super.shouldOverrideUrlLoading(view, url); 
                } 

            });

           
            /* mWebview.setWebViewClient(new WebViewClient() {
                    @Override
                    public void onReceivedError(WebView view, int errorCode, String description, String failingUrl)
                    {
                        // Handle the error
                    }

                    @Override
                    public boolean shouldOverrideUrlLoading(WebView view, String url)
                    {
                        view.loadUrl(url);
                        return true;
                    }
                    public WebResourceResponse shouldInterceptRequest(WebView view, String url) {
                        if (url.contains(".json")) {
                            return getCssWebResourceResponseFromAsset();
                        } else {
                            return super.shouldInterceptRequest(view, url);
                        }

                        }

                });*/
            mWebview.loadUrl(url_paypal);
           
            /*try {
                    String getPaypalResponse=CustomHttpClient.executeHttpGet(url_paypal);
                    String status=JSONSMParser.parseStatus(getPaypalResponse);
                    Log.d("payResponse",getPaypalResponse);
                } catch (Exception e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }*/
        } 
    }
}

following methods which execute other http get & post methods.

 http get.

/**
     * Performs an HTTP GET request to the specified url.
     *
     * @param url The web address to post the request to
     * @return The result of the request
     * @throws Exception
     */
    public static String executeHttpGet(String url) throws Exception {
        BufferedReader in = null;
        try {
            HttpClient client = getHttpClient();
            HttpGet request = new HttpGet();
            HttpContext localContext=getHttpContext();
            request.setURI(new URI(url));
            HttpResponse response = client.execute(request,localContext);
            in = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));

            StringBuffer sb = new StringBuffer("");
            String line = "";
            String NL = System.getProperty("line.separator");
            while ((line = in.readLine()) != null) {
                sb.append(line + NL);
            }
            in.close();
            Log.e("headers",""+response.headerIterator());
            //String mSessionId=null;
           //  Log.e("mSessionId",""+mSessionId);
             HeaderElementIterator it = new BasicHeaderElementIterator(
                     response.headerIterator());
             while (it.hasNext()) {
                 HeaderElement elem = it.nextElement();
                 System.out.println(elem.getName() + " = " + elem.getValue());
                 if(elem.getName().equals("JSESSIONID")){
                     NetworkManager.mSessionId=elem.getValue();
                 }
                 NameValuePair[] params = elem.getParameters();
                 for (int i = 0; i < params.length; i++) {
                     System.out.println(" " + params[i]);
                 }
             }

            String result = sb.toString();
            return result;
        } finally {
            if (in != null) {
                try {
                    in.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
    }
}




following code to send multipart request 


 public static String executeHttpPost1(String url,ArrayList<NameValuePair> postParameters ) throws Exception {
        HttpPost post = new HttpPost(url);
      
        Bitmap bitmap; 
           String Result_STR=null;
            HttpClient client = getHttpClient();
            HttpContext localContext=getHttpContext();
           HttpEntity resmarkMessagesReadFrom =null;
           MultipartEntity reqmarkMessagesReadFrom = new MultipartEntity(HttpMultipartMode.BROWSER_COMPATIBLE);
           try {
               Log.e(TAG+"postParameters.size()",""+postParameters.size());
               for(int i=0;i<postParameters.size();i++){
                   Log.e(TAG+"parameters",""+postParameters.get(i).getName()+""+postParameters.get(i).getValue());
                  
                   if(postParameters.get(i).getName().equals("spProfilePic")){
                       bitmap = BitmapFactory.decodeFile(postParameters.get(i).getValue()); 

                       // you can change the format of you image compressed for what do you want; 
                       //now it is set up to 640 x 480; 

                       Bitmap bmpCompressed = Bitmap.createScaledBitmap(bitmap, 640, 480, true); 
                       ByteArrayOutputStream bos = new ByteArrayOutputStream(); 

                       // CompressFormat set up to JPG, you can change to PNG or whatever you want; 

                       bmpCompressed.compress(CompressFormat.JPEG, 100, bos); 
                       byte[] data = bos.toByteArray();
                       Log.e(TAG,"data"+data);     
                       reqmarkMessagesReadFrom.addPart(postParameters.get(i).getName(), new ByteArrayBody(data, "temp.jpg")); 
                       Log.e(TAG,"bitmap"+bitmap);     

                   }
                   else
                       reqmarkMessagesReadFrom.addPart(postParameters.get(i).getName(), new StringBody(postParameters.get(i).getValue()));
              

               }
               post.setEntity(reqmarkMessagesReadFrom);
               Log.e(TAG,"after for loop"+post.getEntity());
                HttpResponse response = client.execute(post,localContext);
                Log.e("headers",""+response.getAllHeaders());
                 resmarkMessagesReadFrom = response.getEntity();
               if (resmarkMessagesReadFrom != null) {
                   Result_STR=EntityUtils.toString(resmarkMessagesReadFrom);
                  // mMSGBox.setText(Result_STR);
               }
           }
           catch(Exception e){
               Log.e(TAG,e.toString());
           }
           finally {
              
               }
          
   return Result_STR;
    }



/**
     * This method connects to server through HTTP request .(simple http request).
     */
    private static String connect(String url){

        // Create the httpclient
        //HttpClient httpclient = new DefaultHttpClient();
        DefaultHttpClient httpclient = new DefaultHttpClient();

        // Prepare a request object
        HttpGet httpget = new HttpGet(url);
       
        //Header h="JSESSIONID";
        //HttpRequest req=null;
        //req.addHeader("JSESSIONID",mSessionId);
   
       
        httpget.getAllHeaders();
         HeaderElementIterator it1 = new BasicHeaderElementIterator(
                 httpget.headerIterator());
         System.out.println(httpget.getURI());

         while (it1.hasNext()) {
             HeaderElement elem = it1.nextElement();
           
             NameValuePair[] params = elem.getParameters();
             for (int i = 0; i < params.length; i++) {
                 System.out.println(" " + params[i]);
             }
         }
        // Execute the request
        HttpResponse response;

        // return string
        String returnString = null;

        try {

            // Open the webpage.
            response = httpclient.execute(httpget);

            //        if(response.getStatusLine().getStatusCode() == 200){
            if(true) {
                // Connection was established. Get the content.

                HttpEntity entity = response.getEntity();
                //SetCookie c=new Cookie();
                //SetCookie.setValue(mSessionId);
                response.getAllHeaders();
                Log.e(TAG,"headers"+response.getAllHeaders());
                 HeaderElementIterator it = new BasicHeaderElementIterator(
                            response.headerIterator());
                    while (it.hasNext()) {
                        HeaderElement elem = it.nextElement();
                        System.out.println(elem.getName() + " = " + elem.getValue());
                        NameValuePair[] params = elem.getParameters();
                        for (int i = 0; i < params.length; i++) {
                            System.out.println(" " + params[i]);
                        }
                    }
                // If the response does not enclose an entity, there is no need
                // to worry about connection release

                if (entity != null) {
                    // A Simple JSON Response Read
                    InputStream instream = entity.getContent();

                    // Load the requested page converted to a string into a JSONObject.
                    //    JSONObject myAwway = new JSONObject(convertStreamToString(instream));
                    returnString = convertStreamToString(instream);
                    //    Log.e(TAG,"instream  : "+convertStreamToString(instream));
                    //        Log.e(TAG,"myawway  : "+ myAwway);

                    // Get the query value'
                    //String query = myAwway.getString("query");
                    //    JSONObject menuObject =myAwway.getJSONObject("photos");
                    // Make array of the suggestions
                    //        JSONArray suggestions =menuObject.getJSONArray("photo");

                    // Build the return string.
                    //                    returnString = "Found: " + suggestions.length() ;
                    //                for (int i = 0; i < suggestions.length(); i++) {
                    //                    returnString += "\n\t" +(suggestions.getJSONObject(i).getString("id").toString());
                    //                }
                    //    returnString = "Found";
                    // Cose the stream.
                    instream.close();

                }
            }
            else {
                // code here for a response othet than 200.  A response 200 means the webpage was ok
                // Other codes include 404 - not found, 301 - redirect etc...
                // Display the response line.
                returnString = "Unable to load page - " + response.getStatusLine();
            }
            return returnString ; 
        }
        catch (IOException  ex) {
            // thrown by line 80 - getContent();
            // Connection was not established
            returnString = "Connection failed; " + ex.getMessage();
        }
        //        catch (JSONException ex){
        // JSON errors
        //            returnString = "JSON failed; " + ex.getMessage();
        //        }
        return returnString;
    }