Friday 10 March 2017

Reusable AsyncTask

HI All!

In every android application as a developer, It may chance to call the AsyncTask for each and every execution of call the web-service.

To reduce the code, i have find way to reuse the AsyncTask, just we can create a common class for Asyctask and with the help of Interface can reuse at any n of time.



Business class for carry the web-service output & service name

/** * Created by selvaraj on 3/10/2017. */
public class Callable_Async_B {

// result is the json output as string// action_4 is the action to call (like register,login & etc..,)
String result, action_4;
public Callable_Async_B() { } public Callable_Async_B(String result, String action_4) { this.result = result; this.action_4 = action_4; } public String getResult() { return result; } public void setResult(String result) { this.result = result; } public String getAction_4() { return action_4; } public void setAction_4(String action_4) { this.action_4 = action_4; } }




Interface for call around the application
/** * Created by selvaraj on 3/10/2017. */
public interface AsyncResponse {
    void ProcessFinished(Callable_Async_B j_obj);
}












Common & Reusable Asynctask class
import android.app.Activity;
import android.app.ProgressDialog;
import android.os.AsyncTask;
import android.util.Log;
import org.apache.http.NameValuePair;
import org.apache.http.message.BasicNameValuePair;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;


/** * Created by selvaraj on 3/10/2017. */
public class MainAsyncObj extends AsyncTask<String, String, String> {

// Dialog to show while executing
ProgressDialog p_dialog;
// result & action_4 we know already// text_2_show is a value where the text can appears while execution of web-service 
String rersult_s, text_2_show, action_4;
// HashMap to carry al your parameter name & value 
HashMap<String, String> param_map;
// delegate is used to assign the Activity 
public AsyncResponse delegate = null;
// Activity to show on
Activity activity;
public MainAsyncObj(HashMap<String, String> param_map_, String text_2_show_, String action_4_, Activity activity_) { this.activity = activity_; this.text_2_show = text_2_show_; this.action_4 = action_4_; this.param_map = param_map_; } @Override protected void onPreExecute() { super.onPreExecute(); p_dialog = new ProgressDialog(activity); p_dialog.setMessage(text_2_show); p_dialog.setCancelable(false); p_dialog.setIndeterminate(false); p_dialog.show(); } @Override protected String doInBackground(String... strings) { JSONParser parser = new JSONParser(); List<NameValuePair> n_pair = new ArrayList<>(); for (String key : param_map.keySet()) { String value = param_map.get(key); n_pair.add(new BasicNameValuePair(key, value)); } rersult_s = parser.GenrtHttpRequest("http://000.000.00.000/" + action_4, "POST", n_pair); Log.d("Callable_result", rersult_s); return null; } @Override protected void onPostExecute(String s) { super.onPostExecute(s); p_dialog.dismiss(); delegate.ProcessFinished(new Callable_Async_B(rersult_s, action_4)); } }





Reuse the Asynctask on Any Activity wherever you want 
// Implemet the interfacet to get the result 
public class Profile_F extends AppCompatActivity implements AsyncResponse{

// initiate the AsyncTask with parameters
HashMap<String, String> param_map = new HashMap<>();
// pass your Key Name & Value as you want
param_map.put("KEY_NAME", "VALUE");
param_map.put("KEY_NAME", "VALUE");
.... n param_map.put("KEY_NAME", "VALUE");
MainAsyncObj MAO = new MainAsyncObj(param_map,"Please Wait..,","register", this); MAO.delegate = this; MAO.execute();

// Result acter complete the AsyncTask
@Overridepublic void ProcessFinished(Callable_Async_B j_obj) {
    Log.d("Result",j_obj.getResult());
    Log.d("Action_4",j_obj.getAction_4());
}

Please Leave Your Comment..,

 


Enjoy The Day!
Have A Great Day!
Thank You..,


Android LKN

Hi!

By using Device we can track the user by their lastknown loc (LKN).

Method To Call The LKN

private Location getLastBestLocation() {

// get the locationmanager
    LocationManager locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);

// get the status of GPS
    Location locationGPS = locationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER);

// get the status of Provider
    Location locationNet = locationManager.getLastKnownLocation(LocationManager.NETWORK_PROVIDER);

    long GPSLocationTime = 0;
    if (null != locationGPS) {
        GPSLocationTime = locationGPS.getTime();
    }

    long NetLocationTime = 0;

    if (null != locationNet) {
        NetLocationTime = locationNet.getTime();
    }

    if (0 < GPSLocationTime - NetLocationTime) {
        return locationGPS;
    } else {
        return locationNet;
    }
}

// Convert the LKL as ADS

Location location = getLastBestLocation();
if (location != null) {
    latu = location.getLatitude();
    lngu = location.getLongitude();

    Geocoder geocoder;
    List<Address> addresses;
    geocoder = new Geocoder(PO_Entry.this, Locale.getDefault());

    try {
        addresses = geocoder.getFromLocation(location.getLatitude(), location.getLongitude(), 1);
        String address = addresses.get(0).getAddressLine(0);
        String city = addresses.get(0).getLocality();
        String state = addresses.get(0).getAdminArea();
        String country = addresses.get(0).getCountryName();
        String postalCode = addresses.get(0).getPostalCode();
        String knownName = addresses.get(0).getFeatureName();

        et_po_enty_loc.setText(address + " , " + city + "\n" + state + " , " + country + " , " + postalCode);
    } catch (IOException e) {
        e.printStackTrace();
    }
} else {
    et_po_enty_loc.setText("No Location Found");
}

Thank You!

Please Leave Your Comment..,


Have A Happy Day..,

Thursday 2 February 2017

Android Material Design Hero Components Transition Animations

Hi!

Material Design is a boon for developer to make our application with smooth animation on needy places. We are using animation based on different need like Activity, UI Components & etc.,

From android release 5.0 (Lollipop) Material design has introduced. In this tutorial, we are going to learn about UI components Transition (with animation effect) while move to one activity form another activity.

     We can Transition UI components like Button, TextView, Image & etc.., the Transitional UI components called as “Hero Components”, in this tutorial we are going to use a Button as Hero Component.

Gradle :

dependencies {
    compile fileTree(
include: ['*.jar'], dir: 'libs')
    androidTestCompile(
'com.android.support.test.espresso:espresso-core:2.2.2', {
        exclude
group: 'com.android.support', module: 'support-annotations'
   
})
   
testCompile 'junit:junit:4.12'
}

Style

(values/styles.xml)
<resources>



    <!-- App Theam-->

    <style name="AppMaterialTheame" parent="SuperMaterialTheme">



    </style>





    <!-- Base application theme. -->

    <style name="SuperMaterialTheme" parent="Theme.AppCompat.Light.DarkActionBar">

        <!-- Customize your theme here. -->

        <item name="windowNoTitle">true</item>

        <item name="windowActionBar">false</item>

        <item name="colorPrimary">@color/colorPrimary</item>

        <item name="colorPrimaryDark">@color/colorPrimaryDark</item>

        <item name="colorAccent">@color/colorAccent</item>

    </style>



</resources>


(values-v21/styles.xml)
<resources>



    <!-- App Theam-->

    <style name="AppMaterialTheame" parent="SuperMaterialTheme">

        <item name="android:windowContentTransitions">true</item>

        <item name="android:windowAllowEnterTransitionOverlap">true</item>

        <item name="android:windowAllowReturnTransitionOverlap">true</item>

</resources>


ActivityOne.Java
Button fblogin;
fblogin = (Button) findViewById(R.id.fblogin);

// On click to move ActivitySecond.Java
ActivityOptions a_optn;

Intent int_edprof = new Intent(Welcome.this,EDProfile.class);



if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {

    fblogin.setTransitionName("fblogin1");

    a_optn = ActivityOptions.makeSceneTransitionAnimation(Welcome.this, Pair.create((View)fblogin,"fblogin1"));

    startActivity(int_edprof,a_optn.toBundle());

} else {

    startActivity(int_edprof);

}



ActivitySecond.Java
Button btn_test;
btn_test = (Button) findViewById(R.id.btn_test);

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {

    btn_test.setTransitionName("fblogin1");

} else {

}


The both activity having the different button and the button become common for both activity by set the common name
Eg: setTransitionName("fblogin1");




That’s All..,


Please Leave Your Comment..,



Enjoy the code..,

Tuesday 19 April 2016

Auto Complete for Location Search

Hi!


Today we are going to learn about the Auto-complete location searching feature in Android, In IOS it is very simple. But in android we have to take some effort to do that.

Type and search the location in android very common and mandatory feature for some application. With the help of Google we can achieve this.

Array Adopter to collect data form Google


package XXXX.raj.tot.xxxxxxxxxx.Common;

import android.content.Context;
import android.util.Log;
import android.widget.ArrayAdapter;
import android.widget.Filter;
import android.widget.Filterable;
import android.widget.Toast;

import com.google.android.gms.common.api.GoogleApiClient;
import com.google.android.gms.common.api.PendingResult;
import com.google.android.gms.common.api.Status;
import com.google.android.gms.location.places.AutocompleteFilter;
import com.google.android.gms.location.places.AutocompletePrediction;
import com.google.android.gms.location.places.AutocompletePredictionBuffer;
import com.google.android.gms.location.places.Places;
import com.google.android.gms.maps.model.LatLngBounds;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.concurrent.TimeUnit;

public class Place_A extends ArrayAdapter<Place_A.PlaceAutocomplete> implements Filterable {
    private static final String TAG = "PlaceArrayAdapter";
    private GoogleApiClient mGoogleApiClient;
    private AutocompleteFilter mPlaceFilter;
    private LatLngBounds mBounds;
    private ArrayList<PlaceAutocomplete> mResultList;

    /**     * Constructor     *     * @param context  Context     * @param resource Layout resource     * @param bounds   Used to specify the search bounds     * @param filter   Used to specify place types     */    public Place_A(Context context, int resource, LatLngBounds bounds,
                   AutocompleteFilter filter) {
        super(context, resource);
        mBounds = bounds;
        mPlaceFilter = filter;
    }

    public void setGoogleApiClient(GoogleApiClient googleApiClient) {
        if (googleApiClient == null || !googleApiClient.isConnected()) {
            mGoogleApiClient = null;
        } else {
            mGoogleApiClient = googleApiClient;
        }
    }

    @Override    public int getCount() {
        return mResultList.size();
    }

    @Override    public PlaceAutocomplete getItem(int position) {
        return mResultList.get(position);
    }

    private ArrayList<PlaceAutocomplete> getPredictions(CharSequence constraint) {
        if (mGoogleApiClient != null) {
            Log.i(TAG, "Executing autocomplete query for: " + constraint);
            PendingResult<AutocompletePredictionBuffer> results =
                    Places.GeoDataApi                            .getAutocompletePredictions(mGoogleApiClient, constraint.toString(),
                                    mBounds, mPlaceFilter);
            // Wait for predictions, set the timeout.            AutocompletePredictionBuffer autocompletePredictions = results
                    .await(60, TimeUnit.SECONDS);
            final Status status = autocompletePredictions.getStatus();
            if (!status.isSuccess()) {
                Toast.makeText(getContext(), "Error: " + status.toString(),
                        Toast.LENGTH_SHORT).show();
                Log.e(TAG, "Error getting place predictions: " + status
                        .toString());
                autocompletePredictions.release();
                return null;
            }

            Log.i(TAG, "Query completed. Received " + autocompletePredictions.getCount()
                    + " predictions.");
            Iterator<AutocompletePrediction> iterator = autocompletePredictions.iterator();
            ArrayList resultList = new ArrayList<>(autocompletePredictions.getCount());
            while (iterator.hasNext()) {
                AutocompletePrediction prediction = iterator.next();
                resultList.add(new PlaceAutocomplete(prediction.getPlaceId(),
                        prediction.getDescription()));
            }
            // Buffer release            autocompletePredictions.release();
            return resultList;
        }
        Log.e(TAG, "Google API client is not connected.");
        return null;
    }

    @Override    public Filter getFilter() {
        Filter filter = new Filter() {
            @Override            protected FilterResults performFiltering(CharSequence constraint) {
                FilterResults results = new FilterResults();
                if (constraint != null) {
                    // Query the autocomplete API for the entered constraint                    mResultList = getPredictions(constraint);
                    if (mResultList != null) {
                        // Results                        results.values = mResultList;
                        results.count = mResultList.size();
                    }
                }
                return results;
            }

            @Override            protected void publishResults(CharSequence constraint, FilterResults results) {
                if (results != null && results.count > 0) {
                    // The API returned at least one result, update the data.                    notifyDataSetChanged();
                } else {
                    // The API did not return any results, invalidate the data set.                    notifyDataSetInvalidated();
                }
            }
        };
        return filter;
    }

    class PlaceAutocomplete {

        public CharSequence placeId;
        public CharSequence description;

        PlaceAutocomplete(CharSequence placeId, CharSequence description) {
            this.placeId = placeId;
            this.description = description;
        }

        @Override        public String toString() {
            return description.toString();
        }
    }
}



Main Class for Search Location



package XXXX.raj.tot.xxxxxxxxxx.Common;
import android.app.ProgressDialog;
import android.content.Intent;
import android.os.AsyncTask;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.support.v7.app.AppCompatActivity;
import android.text.Html;
import android.util.Log;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.AutoCompleteTextView;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.Spinner;
import android.widget.Toast;

import com.google.android.gms.common.ConnectionResult;
import com.google.android.gms.common.api.GoogleApiClient;
import com.google.android.gms.common.api.PendingResult;
import com.google.android.gms.common.api.ResultCallback;
import com.google.android.gms.location.places.Place;
import com.google.android.gms.location.places.PlaceBuffer;
import com.google.android.gms.location.places.Places;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.LatLngBounds;

import org.apache.http.NameValuePair;
import org.apache.http.message.BasicNameValuePair;
import org.json.JSONArray;
import org.json.JSONObject;

import java.util.ArrayList;
import java.util.List;

import XXXX.raj.cp.helper.JSONParser;
import XXXX.raj.tot.xxxxxxxxxx.Others.URL_Loader;import XXXX.raj.tot.xxxxxxxxxx.R;import XXXX.raj.tot.xxxxxxxxxx.tracking_b.Vehicle_B;

public class PlaceSearch extends AppCompatActivity implements GoogleApiClient.OnConnectionFailedListener, GoogleApiClient.ConnectionCallbacks {

    // Google Info    private static final String LOG_TAG = "MainActivity";
    private static final int GOOGLE_API_CLIENT_ID = 0;
    private GoogleApiClient mGoogleApiClient;
    private static final LatLngBounds BOUNDS_MOUNTAIN_VIEW = new LatLngBounds(new LatLng(37.398160, -122.180831), new LatLng(37.430610, -121.972090));

    // Adoptr abjt    private Place_A from_adptr_loc;

    // Local var    private AutoCompleteTextView aet_from_location, aet_to_location;
    EditText et_trking_id;
    Spinner spn_trk_num;
    CheckBox chbk_is_fav;
    Button btn_get_direct;
    String F_name, F_address, F_place_ID, F_Lat_Long, T_name, T_address, T_place_ID, T_Lat_Long, Trking_id, Slt_vcl_id, Slt_vcl_nm, Slt_vcl_num;
    boolean is_Slted;
    ArrayList<Vehicle_B> array_vcl;
    ArrayList<String> array_vcl_name;
    String rout_for;

@Overrideprotected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_place_search);
    rout_for = getIntent().getStringExtra("rout_for");

    mGoogleApiClient = new GoogleApiClient.Builder(PlaceSearch.this)
            .addApi(Places.GEO_DATA_API)
            .enableAutoManage(this, GOOGLE_API_CLIENT_ID, this)
            .addConnectionCallbacks(this)
            .build();

    aet_from_location = (AutoCompleteTextView) findViewById(R.id
            .aet_from_location);
    aet_from_location.setThreshold(3);
    aet_to_location = (AutoCompleteTextView) findViewById(R.id
            .aet_to_location);
    aet_to_location.setThreshold(3);
    btn_get_direct = (Button) findViewById(R.id.btn_get_direct);
    et_trking_id = (EditText) findViewById(R.id.et_trking_id);
    spn_trk_num = (Spinner) findViewById(R.id.spn_trk_num);
    chbk_is_fav = (CheckBox) findViewById(R.id.chbk_is_fav);

    aet_from_location.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            final Place_A.PlaceAutocomplete item = from_adptr_loc.getItem(position);
            final String placeId = String.valueOf(item.placeId);
            Log.i(LOG_TAG, "Selected: " + item.description);
            PendingResult<PlaceBuffer> placeResult = Places.GeoDataApi                    .getPlaceById(mGoogleApiClient, placeId);
            placeResult.setResultCallback(from_Loc_mUpdatePlaceDetailsCallback);
            Log.i(LOG_TAG, "Fetching details for ID: " + item.placeId);
        }
    });

    from_adptr_loc = new Place_A(this, android.R.layout.simple_list_item_1,
            BOUNDS_MOUNTAIN_VIEW, null);
    aet_from_location.setAdapter(from_adptr_loc);
    aet_to_location.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            final Place_A.PlaceAutocomplete item = from_adptr_loc.getItem(position);
            final String placeId = String.valueOf(item.placeId);
            Log.i(LOG_TAG, "Selected: " + item.description);
            PendingResult<PlaceBuffer> placeResult = Places.GeoDataApi                    .getPlaceById(mGoogleApiClient, placeId);
            placeResult.setResultCallback(to_Loc_mUpdatePlaceDetailsCallback);
            Log.i(LOG_TAG, "Fetching details for ID: " + item.placeId);
        }
    });
    aet_to_location.setAdapter(from_adptr_loc);
}
private ResultCallback<PlaceBuffer> to_Loc_mUpdatePlaceDetailsCallback        = new ResultCallback<PlaceBuffer>() {
    @Override    public void onResult(PlaceBuffer places) {
        if (!places.getStatus().isSuccess()) {
            Log.e(LOG_TAG, "Place query did not complete. Error: " +
                    places.getStatus().toString());
            return;
        }
        // Selecting the first object buffer.        final Place place = places.get(0);

        CharSequence attributions = places.getAttributions();
        T_name = String.valueOf(Html.fromHtml(place.getName() + ""));
        T_address = String.valueOf(Html.fromHtml(place.getAddress() + ""));
        T_place_ID = String.valueOf(Html.fromHtml(place.getId() + ""));
        T_Lat_Long = String.valueOf(Html.fromHtml(place.getLatLng() + ""));

       /* mNameTextView.setText(Html.fromHtml(place.getName() + ""));        mAddressTextView.setText(Html.fromHtml(place.getAddress() + ""));        mIdTextView.setText(Html.fromHtml(place.getId() + ""));        mPhoneTextView.setText(Html.fromHtml(place.getPhoneNumber() + ""));        mWebTextView.setText(place.getWebsiteUri() + "");        if (attributions != null) {            mAttTextView.setText(Html.fromHtml(attributions.toString()));        }*/    }
};

private ResultCallback<PlaceBuffer> from_Loc_mUpdatePlaceDetailsCallback        = new ResultCallback<PlaceBuffer>() {
    @Override    public void onResult(PlaceBuffer places) {
        if (!places.getStatus().isSuccess()) {
            Log.e(LOG_TAG, "Place query did not complete. Error: " +
                    places.getStatus().toString());
            return;
        }
        // Selecting the first object buffer.        final Place place = places.get(0);
        CharSequence attributions = places.getAttributions();
        F_name = String.valueOf(Html.fromHtml(place.getName() + ""));
        F_address = String.valueOf(Html.fromHtml(place.getAddress() + ""));
        F_place_ID = String.valueOf(Html.fromHtml(place.getId() + ""));
        F_Lat_Long = String.valueOf(Html.fromHtml(place.getLatLng() + ""));

       /* mNameTextView.setText(Html.fromHtml(place.getName() + ""));        mAddressTextView.setText(Html.fromHtml(place.getAddress() + ""));        mIdTextView.setText(Html.fromHtml(place.getId() + ""));        mPhoneTextView.setText(Html.fromHtml(place.getPhoneNumber() + ""));        mWebTextView.setText(place.getWebsiteUri() + "");        if (attributions != null) {            mAttTextView.setText(Html.fromHtml(attributions.toString()));        }*/    }
};


@Overridepublic void onConnected(Bundle bundle) {
    from_adptr_loc.setGoogleApiClient(mGoogleApiClient);
    Log.i(LOG_TAG, "Google Places API connected.");

}

@Overridepublic void onConnectionFailed(ConnectionResult connectionResult) {
    Log.e(LOG_TAG, "Google Places API connection failed with error code: "            + connectionResult.getErrorCode());

    Toast.makeText(this,
            "Google Places API connection failed with error code:" +
                    connectionResult.getErrorCode(),
            Toast.LENGTH_LONG).show();
}

@Overridepublic void onConnectionSuspended(int i) {
    from_adptr_loc.setGoogleApiClient(null);
    Log.e(LOG_TAG, "Google Places API connection suspended.");
}

private class GeocoderHandler extends Handler {
    @Override    public void handleMessage(Message message) {
        String locationAddress;
        switch (message.what) {
            case 1:
                Bundle bundle = message.getData();
                locationAddress = bundle.getString("address");
                break;
            default:
                locationAddress = null;
        }
        Toast.makeText(getApplicationContext(), locationAddress, Toast.LENGTH_LONG).show();
    }
}

}


View for the above Activity


<LinearLayout 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"    android:orientation="horizontal">

    <LinearLayout        android:layout_width="fill_parent"        android:layout_height="fill_parent"        android:layout_margin="5dp"        android:background="@color/wt"        android:gravity="center"        android:orientation="vertical"        android:weightSum="85">

        <LinearLayout            android:layout_width="fill_parent"            android:layout_height="0dp"            android:layout_weight="20"            android:orientation="horizontal">

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

                <AutoCompleteTextView                    android:id="@+id/aet_from_location"                    android:layout_width="fill_parent"                    android:layout_height="fill_parent"                    android:layout_centerHorizontal="true"                    android:hint="From Location" />
            </LinearLayout>

        </LinearLayout>

        <LinearLayout            android:layout_width="fill_parent"            android:layout_height="0dp"            android:layout_weight="20"            android:orientation="horizontal">

            <AutoCompleteTextView                android:id="@+id/aet_to_location"                android:layout_width="fill_parent"                android:layout_height="fill_parent"                android:layout_centerHorizontal="true"                android:hint="To Location" />
        </LinearLayout>

        <LinearLayout            android:layout_width="fill_parent"            android:layout_height="0dp"            android:layout_weight="15"            android:orientation="horizontal">

            <EditText                android:id="@+id/et_trking_id"                android:layout_width="fill_parent"                android:layout_height="fill_parent"                android:hint="TRUCKING ID" />
        </LinearLayout>

        <LinearLayout            android:layout_width="fill_parent"            android:layout_height="0dp"            android:layout_weight="15"            android:orientation="horizontal"            android:weightSum="100">

            <LinearLayout                android:layout_width="0dp"                android:layout_height="fill_parent"                android:layout_weight="60"                android:gravity="center"                android:orientation="horizontal"                android:padding="2dp">

                <Spinner                    android:id="@+id/spn_trk_num"                    android:layout_width="fill_parent"                    android:layout_height="fill_parent" />
            </LinearLayout>

            <LinearLayout                android:layout_width="0dp"                android:layout_height="fill_parent"                android:layout_weight="40"                android:gravity="center"                android:orientation="horizontal"                android:padding="2dp">

                <CheckBox                    android:id="@+id/chbk_is_fav"                    android:layout_width="fill_parent"                    android:layout_height="fill_parent"                    android:checked="false"                    android:text="Add To Favorite" />
            </LinearLayout>
        </LinearLayout>

        <LinearLayout            android:layout_width="fill_parent"            android:layout_height="0dp"            android:layout_weight="15"            android:orientation="horizontal">

            <Button                android:id="@+id/btn_get_direct"                android:layout_width="fill_parent"                android:layout_height="fill_parent"                android:layout_margin="3dp"                android:background="@color/orng"                android:text="Get Direction"                android:textColor="@color/wt" />
        </LinearLayout>

    </LinearLayout>

</LinearLayout>


Add Permission to your Manifest file


   <uses-permission android:name="android.permission.INTERNET" />
   <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
   <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
   <uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" />
   <!--The ACCESS_COARSE/FINE_LOCATION permissions are not required to use        Google Maps Android API v2, but are recommended.   -->   <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
   <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />

<meta-data    android:name="com.google.android.gms.version"    android:value="@integer/google_play_services_version" />
<meta-data    android:name="com.google.android.geo.API_KEY"    android:value="@string/google_maps_key" />





Thats All..,

Please Leave Your Comment..,


Have A Great Day..,