Friday, 19 April 2013

How to run monkeyrunner?


If you want to run monkeyrunner from anywhere within the command line, you need to add the path of the monkeyrunner directory(\tools ) to your system PATH variable.

in ubuntu follow the steps below.

1. open the ternminal

2. changed to to the direcotory

  android-sdk-linux/platform-tools$


3.   ./adb -d shell monkey -p com.neem23.fishwrap -v 20000


   here : com.neem23.fishwrap is my app package.

        20000 no of inputs.

         -d means device.

Monday, 15 April 2013

Customization of sendIntent android

Action send intent will pickup all the installed application and shown in a popup.

if we want customize this popup. we can get the the individual installed app and 
 we can filter the popup list.

example: 


    /**
     * this method will give all the installed applications
     */
    public void getInstalledPackages() {
       List<ResolveInfo>   activities = context.getPackageManager().queryIntentActivities(
                sendIntent, 0);

        final Object a[] = activities.toArray();
        for (int i = 0; i < activities.size(); i++) {

            Drawable appicon;
           //gets the app name
            String temp = ((ResolveInfo) a[i]).activityInfo.applicationInfo
                    .loadLabel(context.getPackageManager()).toString();
//gets the app icon
            appicon = ((ResolveInfo) a[i]).activityInfo.applicationInfo
                    .loadIcon(context.getPackageManager());
//saving in array list.
            listmessages.add(temp);
            currentDisp.add((ResolveInfo) a[i]);
            drawbles.add(appicon);


        }

    }


//inflating the custom layou

      dialog = new Dialog(context, R.style.Theme_Dialog_Translucent);
        dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
        dialog.setContentView(R.layout.shownetworksdialogue);
         listview = (ListView)dialog.findViewById(R.id.networklist);
        TextView okbuton = (TextView)dialog.findViewById(R.id.shownetworkok);
        TextView dialougeTitle = (TextView)dialog.findViewById(R.id.dialogtitle);


        listview.setAdapter(new CustomAdapter());


CustomAdapter class:



  
    public class CustomAdapter extends BaseAdapter {
      
        public int getCount() {
            return listmessages.size();
        }

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

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

        public View getView(final int position, View convertView, ViewGroup parent) {
           
                       Holder holderView = null;
            if (convertView == null) {
                holderView = new Holder();
                convertView = inflater.inflate(R.layout.networklist, null);
 
                holderView.network = (TextView) convertView
                        .findViewById(R.id.gmail);
                holderView.launcheicon=(ImageView) convertView.findViewById(R.id.launchericon);
      

               
                convertView.setTag(holderView);
            } else {
                holderView = (Holder) convertView.getTag();
            }

            holderView.launcheicon.setImageDrawable(drawbles.get(position));
holderView.network.setText(listmessages.get(position));               

            
            return convertView;
        }

    }

//holder class

    private class Holder {
     
        TextView network;
        RelativeLayout viewinfolayout,viewinfomainsiblinglayout;
        ImageView launcheicon;

    }



networklist xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
     xmlns:facebook="http://schemas.android.com/apk/res-auto"
    android:id="@+id/popupbg"
    android:layout_width="fill_parent"
    android:layout_height="48dip" >

    android:orientation="horizontal"

    <ImageView
        android:id="@+id/launchericon"
        android:layout_width="42dp"
        android:layout_height="42dp"
   />
      

    <TextView
        android:id="@+id/gmail"
        style="@style/textviewwrapcontent"
    
        android:text="@string/gmail"
        android:textStyle="bold" />
</LinearLayout>



shownetworksdialogue xml:


<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
   android:layout_marginLeft="16dp"
    android:layout_marginRight="16dp"
    android:layout_marginTop="48dp"
    android:layout_marginBottom="72dp"
    android:background="@color/lightblack"
    android:orientation="vertical" >
    <include android:id="@+id/showpopop" layout="@layout/popupheading"/>
    <LinearLayout android:layout_width="fill_parent"
                  android:layout_height="wrap_content"
                  android:layout_above="@+id/bellwolay"
                  android:layout_below="@+id/showpopop"
                   >
    <ListView android:layout_width="0dp"
              android:layout_height="wrap_content"
              android:layout_weight="1"
              android:id="@+id/networklist"></ListView>
    </LinearLayout>
    <LinearLayout android:layout_width="fill_parent"
                  android:layout_height="wrap_content"
                  android:layout_alignParentBottom="true"
                   android:id="@+id/bellwolay"
                  android:orientation="vertical">
    <View android:layout_width="fill_parent"
  
          android:layout_height="1dp"
          android:background="@color/thinkbule"/>
    <TextView
              style="@style/popupbottom"
              android:id="@+id/shownetworkok"
         
              android:text="@string/cancel"
              android:gravity="center"/>
    </LinearLayout>

</RelativeLayout>

 

how to use handlers

 A handler will be executed on the thread in which it is created.

    There are two uses of Handler
(1) to schedule messages and runnables to be executed as some point in the future

(2) to enqueue an action to be performed on a different thread than your own. 

sample code:

    private Runnable pageChangingTask = new Runnable() {
       
        @Override
        public void run() {
          //executable code write here
           
        }
    };






//this line of code will remove any of the pending task in queue.

handler.removeCallbacks(pageChangingTask);




//postDelayed method takes two arguements one runnable object and 
//  time in milliseconds.





                handler.postDelayed(pageChangingTask, 500);