Tuesday, 16 April 2013

Get response from asyn task

public interface OnTaskCompleted{
    void onTaskCompleted(values);
}
----------------------------
public YourActivity implements OnTaskCompleted{
    //your Activity
    YourTask  task = new YourTask(this); // here is the initalization code for your asyncTask 
 
 
//will call 
    void onTaskCompleted(String values){
    } 
 
}

-----------------------------
public YourTask extends AsyncTask<Object,Object,Object>{ //change Object to required type
    private OnTaskCompleted listener;

    public YourTask(OnTaskCompleted listener){
        this.listener=listener;
    }

    //required methods

    protected void onPostExecute(Object o){
        //your stuff
        listener.onTaskCompleted(values);
    }
}

Monday, 15 April 2013

main.xml

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" >

    <ListView
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:id="@+id/list01"
        android:layout_margin="5dip"
        style="@style/mylist"
        android:listSelector="@drawable/list_selector"
        android:background="@drawable/listviewbackground"
     />
        <!-- android:listSelector="#00000000" -->
     

</LinearLayout>


singlerow.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="fill_parent"
    android:orientation="vertical" >
   

<LinearLayout
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="horizontal"
    android:layout_margin="5dip"
    android:background="@drawable/login_bg"
    android:gravity="center_horizontal"
    >
    <TextView
        android:id="@+id/singlerownameid"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_weight="5"
        android:maxWidth="10dip"
        android:text="Name"
        android:textStyle="bold" />
    <TextView
        android:id="@+id/singlerowaddressid"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_weight="5"
        android:gravity="right"
        android:maxWidth="10dip"
        android:text="Address"
        android:textStyle="bold" />
</LinearLayout>

</LinearLayout>

<?xml version="1.0" encoding="utf-8"?>
<shape
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle">
   
    gradient_bg_cover.xml


  <gradient
      android:startColor="#18d7e5"
      android:centerColor="#16cedb"
      android:endColor="#09adb9"
      android:angle="270" />
   <stroke
      android:width="1.0dip"
      android:color="#18d7e5" />
   <corners
      android:radius="8.0dip" />
   <padding
       android:top="5dip"
       />
</shape>


gradient_bg.xml

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle">
   
  <gradient
      android:startColor="#f1f1f2"
      android:centerColor="#e7e7e8"
      android:endColor="#cfcfcf"
      android:angle="270" />
 
  <stroke
      android:width="1.0dip"
      android:color="#f1f1f2" />
  <corners
      android:radius="8.0dip" />


</shape>


login_bg.xml


<?xml version="1.0" encoding="utf-8"?>
<shape android:shape="rectangle"
  xmlns:android="http://schemas.android.com/apk/res/android">
    <gradient android:startColor="#ff545454" android:endColor="#ff545454" android:angle="270.0" />
    <stroke android:width="1.0dip" android:color="#ff5e5e5e" />
    <corners android:radius="8.0dip" />
</shape>


listselector.xml


<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item
     android:state_selected="false"
        android:state_pressed="false"
        android:drawable="@drawable/gradient_bg" />

    <item android:state_pressed="true"
        android:drawable="@drawable/gradient_bg_hover" />

    <item android:state_selected="true"
     android:state_pressed="false"
        android:drawable="@drawable/gradient_bg_hover" />
</selector>


Items.java

package customBaseAdapterExample;

public class Items {
   
    String name="",address="";
   
    public Items(String name,String address){
        this.name = name;
        this.address = address;
    }
   
    public void setname(String name){
       
        this.name = name;
       
    }
   
    public void setaddress(String address){
       
        this.address = address;
    }
   
    public String getname(){
       
        return this.name;
    }
   
    public String getaddress(){
       
        return this.address;
    }
   
   

}


CustomAdapter.java

package customBaseAdapterExample;

import java.util.ArrayList;

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 com.example1.customlistview.R;

public class CustomAdapter  extends BaseAdapter{

    private ArrayList<Items> arrayList;
    private LayoutInflater mInflater;
    Context context1;
   
   
   
    public CustomAdapter(Context context,ArrayList<Items> list) {
      
   
        this.context1 = context;
        this.arrayList = list;
        mInflater = (LayoutInflater)context1.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
   
    }
   
    @Override
    public int getCount() {
      
        return arrayList.size();
    }

    @Override
    public Object getItem(int position) {
      
        return arrayList.get(position);
    }

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

    @Override
    public View getView(int position, View convertview, ViewGroup parent) {
      
        ViewHolder viewHolder = null;
        Items items = (Items) getItem(position);
        if(convertview == null){
          
            convertview = mInflater.inflate(R.layout.singlerow,null);
            viewHolder = new ViewHolder();
            viewHolder.textView = (TextView)convertview.findViewById(R.id.singlerownameid);
            viewHolder.textviewaddress = (TextView)convertview.findViewById(R.id.singlerowaddressid);
            convertview.setTag(viewHolder);
        }
        else{
            viewHolder=(ViewHolder) convertview.getTag();
        }
      
        viewHolder.textView.setText(items.getname());
        viewHolder.textviewaddress.setText(items.getaddress());
      
        return convertview;
    }

    public static class ViewHolder {
      
        TextView textView,textviewaddress;
    }
   
}


CustomList.java
 package com.example1.customlistview;

import java.util.ArrayList;

import customBaseAdapterExample.CustomAdapter;
import customBaseAdapterExample.Items;

import android.os.Bundle;
import android.app.Activity;
import android.app.ListActivity;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.Toast;

public class CustomList extends Activity implements  OnItemClickListener {

  
    ListView listview;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_custom_list);
      
        listview = (ListView )findViewById(R.id.list01);
        ArrayList<Items> list = new ArrayList<Items>();
        list.add(new Items("EEEE", "MDU"));
        list.add(new Items("SSSS", "MDU"));
        list.add(new Items("HHHH", "MDU"));
      
        CustomAdapter adapter = new CustomAdapter(this,list);
        listview.setAdapter(adapter);
        listview.setOnItemClickListener(this);
    }
  

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.activity_custom_list, menu);
        return true;
    }


    @Override
    public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
      
        Toast.makeText(CustomList.this ,arg2+"" ,Toast.LENGTH_SHORT).show();
      
    }


  
}








Sunday, 14 April 2013

GridView with imageview

xml file:
---------

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

    <GridView
       
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:id="@+id/mygriwview_id"
        android:numColumns="auto_fit"
        android:gravity="center"
        android:columnWidth="90dp"
        android:verticalSpacing="10dp"
        android:horizontalSpacing="10dp"
        android:stretchMode="columnWidth"
       
        />

</RelativeLayout>


ImageADapter.java
---------------------
import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.GridView;
import android.widget.ImageView;

import com.exampl.samples.R;

public class ImageADapter extends BaseAdapter{

    Context context;
   
    public ImageADapter(Context context) {
       
        this.context = context;
    }
    @Override
    public int getCount() {
       
        return mImages.length;
    }

    @Override
    public Object getItem(int arg0) {
       
        return null;
    }

    @Override
    public long getItemId(int arg0) {
       
        return 0;
    }

    @Override
    public View getView(int position, View convertview, ViewGroup parent) {
       
   
            ImageView imageview;
            if(convertview == null){
               
                imageview = new ImageView(context);
                imageview.setLayoutParams(new GridView.LayoutParams(85, 85));
                imageview.setScaleType(ImageView.ScaleType.CENTER_CROP);
                imageview.setPadding(8, 8, 8, 8);
            }
            else{
                imageview = (ImageView) convertview;
            }
           
            imageview.setImageResource(mImages[position]);
           
         return imageview;
    }
   
    private Integer mImages[] = {R.drawable.charts,R.drawable.charts,R.drawable.charts,R.drawable.charts,R.drawable.charts,R.drawable.charts,R.drawable.charts,R.drawable.charts,R.drawable.charts,R.drawable.charts};

}









GridviewActivity.java
-------------------------


public class GridviewActivity extends Activity {

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_gridview);
        GridView gridview = (GridView) findViewById(R.id.mygriwview_id);
        gridview.setAdapter(new ImageADapter(this));
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.activity_gridview, menu);
        return true;
    }
}



Wednesday, 13 March 2013

Apk to code

http://blog.inyourbits.com/2012/11/extending-existing-android-applications.html

http://blog.inyourbits.com/2012/12/extending-existing-android-applications.html


http://code.google.com/p/android-apktool/downloads/list

http://java.decompiler.free.fr/?q=jdgui

Tuesday, 12 March 2013

Route Map

http://mobiforge.com/developing/story/using-google-maps-android

http://csie-tw.blogspot.in/2009/06/android-driving-direction-route-path.html
http://www.anddev.org/route_-_improved_google_driving_directions-t1892.html

http://stackoverflow.com/questions/2023669/j2me-android-blackberry-driving-directions-route-between-two-locations

http://code.google.com/p/j2memaprouteprovider/source/browse/trunk/J2MEMapRouteAndroidEx/#J2MEMapRouteAndroidEx%2Fsrc%253Fstate%253Dclosed   (Code)

Monday, 11 March 2013

IntentService

http://stackoverflow.com/questions/5682632/android-httpclient-as-a-backgroundservice

http://www.vogella.com/articles/AndroidServices/article.html

http://www.mysamplecode.com/2011/10/android-intentservice-example-using.html


http://stackoverflow.com/questions/4443278/toast-sending-message-to-a-handler-on-a-dead-thread

BackgroundUrlhit continously run in service

http://stackoverflow.com/questions/4443278/toast-sending-message-to-a-handler-on-a-dead-thread

AndroidNotifyService.java


import java.util.Calendar;
import android.app.Activity;
import android.app.AlarmManager;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;

public class AndroidNotifyService extends Activity {
    /** Called when the activity is first created. */
    Intent intent;
    NotifyService notifyService;
    PendingIntent pintent;
   
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        Button buttonStartService = (Button)findViewById(R.id.startservice);
        Button buttonStopService = (Button)findViewById(R.id.stopservice);
       
        buttonStartService.setOnClickListener(new Button.OnClickListener(){

            @Override
            public void onClick(View arg0) {
               
                /*intent = new Intent(AndroidNotifyService.this, NotifyService.class);
                startService(intent);
                */
               
                /*Calendar cur_cal = Calendar.getInstance();
                cur_cal.setTimeInMillis(System.currentTimeMillis());
                cur_cal.add(Calendar.SECOND, 50);
                Log.d("Testing", "Calender Set time:"+cur_cal.getTime());
               
                //Intent intent = new Intent(AndroidNotifyService.this, NotifyService.class);
                intent = new Intent(AndroidNotifyService.this, NotifyService.class);
                pintent = PendingIntent.getService(AndroidNotifyService.this, 0, intent, 0);
                AlarmManager alarm = (AlarmManager)getSystemService(Context.ALARM_SERVICE);
                alarm.setRepeating(AlarmManager.RTC_WAKEUP, cur_cal.getTimeInMillis(), 1*1000, pintent);
                */
               
                System.out.println("clicked");
                /*
                Intent i = new Intent ("com.example.serviceexample.BackgroundConnectionService");
                startService(i);*/
               
                Calendar cur_cal = Calendar.getInstance();
                cur_cal.setTimeInMillis(System.currentTimeMillis());
                cur_cal.add(Calendar.SECOND, 50);
                Log.d("Testing", "Calender Set time:"+cur_cal.getTime());
               
                //Intent intent = new Intent(AndroidNotifyService.this, NotifyService.class);
                intent = new Intent("com.example.serviceexample.BackgroundConnectionService");
                pintent = PendingIntent.getService(AndroidNotifyService.this, 0, intent, 0);
                AlarmManager alarm = (AlarmManager)getSystemService(Context.ALARM_SERVICE);
                alarm.setRepeating(AlarmManager.RTC_WAKEUP, cur_cal.getTimeInMillis(),1000, pintent);
               
               
               
            }});
       
        buttonStopService.setOnClickListener(new Button.OnClickListener(){

            @Override
            public void onClick(View arg0) {
               
                //stopService(intent);
                /*AlarmManager alarmManager = (AlarmManager)getSystemService(ALARM_SERVICE);
                alarmManager.cancel(pintent);
                */
            }});
       

    }
}



BackgroundConnectionService.java



package com.example.serviceexample;

import java.util.ArrayList;
import java.util.List;
import org.apache.http.NameValuePair;
import org.apache.http.message.BasicNameValuePair;
import android.app.IntentService;
import android.content.Intent;


public class BackgroundConnectionService extends IntentService {

    String res="";
    public BackgroundConnectionService() {
        // Need this to name the service
        super ("ConnectionServices");
        System.out.println("t1");
    }

    @Override
    protected void onHandleIntent(Intent arg0) {
       
        BasicNameValuePair nameValuePair = new BasicNameValuePair("UserID", "v3390");
        List<NameValuePair> nameValuePairList = new ArrayList<NameValuePair>();
        nameValuePairList.add(nameValuePair);
       
        URLHit url = new URLHit("http://121.242.232.139:8082/Sales_Service/predocs", nameValuePairList);
        res = url.hitresponse();
        System.out.println("Response: "+res);
    }
}



AndroidManifest.xml


<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.serviceexample"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk
        android:minSdkVersion="10"
        android:targetSdkVersion="15" />

    <uses-permission android:name="android.permission.INTERNET"/>
    <application
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name=".AndroidNotifyService"
            android:label="@string/title_activity_android_notify_service"
            android:screenOrientation="portrait"
            >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
       
       
        <service android:name="com.example.serviceexample.BackgroundConnectionService">
            <intent-filter>
                <action android:name="com.example.serviceexample.BackgroundConnectionService" />
                <category android:name="android.intent.category.DEFAULT" />
            </intent-filter>
        </service>
       

       
    </application>

</manifest>