Thursday 14 June 2012

photgraph with frame


<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/mainlayout"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="horizontal" >

   <RelativeLayout
        android:id="@+id/thumblayout"
        android:layout_width="100dp"
        android:layout_height="100dp"
        android:layout_gravity="center_horizontal"
        android:background="@drawable/frame_gujarat"
        android:gravity="center_horizontal"
        android:orientation="horizontal" >

        <ImageView
            android:id="@+id/pic"
            android:layout_width="81dp"
            android:layout_height="83dp"
            android:layout_alignParentTop="true"
            android:layout_centerInParent="true"
            android:layout_margin="0dp"
            android:padding="0dp" >
        </ImageView>
    </RelativeLayout>
   
    <LinearLayout
        android:id="@+id/middlelayout"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:layout_weight="1"
        android:gravity="center"
        android:orientation="vertical" >

        <TextView
            android:id="@+id/heading"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center_horizontal"
            android:gravity="center_horizontal"
            android:textColor="#663300" />
    </LinearLayout>

    <ImageView
        android:id="@+id/pic_aerrow"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center_vertical" />

</LinearLayout>

photo with frame

Thursday 7 June 2012

Mapper.java(urhre)


package com.qualcomm.QCARSamples.ImageTargets;

/**
 * Google Maps Tutorial
 * Txt2Java pCode Generated File
 * Version 1.0.1.4
 * B&P Software 2011
 *
 * This requires the Google API (Android 2.1)
 * The mapping requires the correct API key in main.xml (B&P's won't work for other compilers)
 * Uses the direction service to draw a blue line between the endpoints of the direction steps
 * Stores the written directions also
 *
 */

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Locale;

import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.util.EntityUtils;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import android.app.ProgressDialog;
import android.content.Context;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Point;
import android.hardware.SensorListener;
import android.location.Address;
import android.location.Criteria;
import android.location.Geocoder;
import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.os.Bundle;
import android.util.Log;
import android.view.Gravity;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup.LayoutParams;
import android.view.ViewGroup.MarginLayoutParams;
import android.widget.Button;
import android.widget.EditText;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TabHost;
import android.widget.TabWidget;
import android.widget.TextView;
import android.widget.Toast;

import com.google.android.maps.GeoPoint;
import com.google.android.maps.MapActivity;
import com.google.android.maps.MapController;
import com.google.android.maps.MapView;
import com.google.android.maps.Overlay;
import android.view.View.OnClickListener;

public class Mapper extends MapActivity implements LocationListener,
SensorListener {
MapView mapView;
MapController mc;
GeoPoint p;
ArrayList<Direction> directions = new ArrayList<Direction>();
Direction source_dir = null, dest = null;
EditText place;
EditText place_et;
String destination;
double lat, lng;
String source;
boolean flag_online = false;
private LocationManager locationManager;
private String provider;
int height, width;
ImageView i1, i2, i3, i4;
ProgressDialog dialog;
Button home, back, exchange;
String temp;
int flag_firsttime = 1;

@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
setContentView(R.layout.navigate);
mapView = (MapView) findViewById(R.id.mapview);
this.mapView = (MapView) findViewById(R.id.mapview);
double l1 = 22.97884;
double l2 = 72.49037;

GeoPoint point = new GeoPoint((int) (l1 * 1E6), (int) (l2 * 1E6));
this.mapView.getController().animateTo(point);

height = getWindowManager().getDefaultDisplay().getHeight();
width = getWindowManager().getDefaultDisplay().getWidth();
LinearLayout main = (LinearLayout) findViewById(R.id.main);
main.getLayoutParams().height = (int) ((height) * 0.90);

place = (EditText) findViewById(R.id.place);
place_et = (EditText) findViewById(R.id.place_et);
home = (Button) findViewById(R.id.home);
exchange = (Button) findViewById(R.id.exchange);
back = (Button) findViewById(R.id.back);
source = "Wait..... ";
destination = "surat,gujarat";
destination = place_et.getText().toString();
Button gps = (Button) findViewById(R.id.gps);
gps.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
// if (flag_online == false) {
// String coordinates[] = { "42.35849", "-71.06010" };
// lat = Double.parseDouble(coordinates[0]);
// lng = Double.parseDouble(coordinates[1]);
// p = new GeoPoint((int) (lat * 1E6), (int) (lng * 1E6));
// place.setText("Name of Place" + "    Ahmedabad");
// getDirections("http://maps.googleapis.com/maps/api/directions/json?origin="
// + source
// + "&destination="
// + "vadodara,gujarat"
// + "&sensor=false");
//
//
// goToPoint();
// showPosition();
// flag_online = true;
// } else if (isConnected() == true) {
if (isConnected()) {

String destination1 = place_et.getText().toString();
destination = destination1.replaceAll("\\s", "");

locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
// Define the criteria how to select the locatioin
// provider -> use
// default
Criteria criteria = new Criteria();
provider = locationManager.getBestProvider(criteria, false);
Location location = locationManager
.getLastKnownLocation(provider);

// Initialize the location fields
String coordinates[] = { "42.35849", "-71.06010" };
lat = Double.parseDouble(coordinates[0]);
lng = Double.parseDouble(coordinates[1]);

if (location != null) {
System.out.println("Provider " + provider
+ " has been selected.");
String lat1 = " " + (double) (location.getLatitude());
String lng1 = " " + (double) (location.getLongitude());
lat = Double.parseDouble(lat1);
lng = Double.parseDouble(lng1);

} else {

Toast.makeText(getApplicationContext(),
"Provider not available", 4000).show();
}
onLocationChanged(location);
getAddress();

p = new GeoPoint((int) (lat * 1E6), (int) (lng * 1E6));
place.setText(source);
source_dir = new Direction(lat, lng, "s");
// dest = new Direction(20.25,
// 65.70, "d");
//
directions.clear();
directions.add(source_dir);
// source.replaceAll(" ", "");

getDirections_online("http://maps.googleapis.com/maps/api/directions/json?origin="
+ source.trim()
+ "&destination="
+ destination.trim() + "&sensor=false");

// directions.add(dest);
goToPoint();
showPosition();

} else {
Toast.makeText(getApplicationContext(),
"no internet connection", 4000).show();
}
}
});

TabHost tabH = new TabHost(this);
TabWidget tabWidget = new TabWidget(this);
LinearLayout lin = new LinearLayout(this);
lin.setOrientation(LinearLayout.HORIZONTAL);
tabWidget.setId(android.R.id.tabs);
tabH.addView(tabWidget);
tabH.addView(lin);
FrameLayout fl = new FrameLayout(this);
fl.setId(android.R.id.tabcontent);

fl.setPadding(0, (int) (getWindowManager().getDefaultDisplay()
.getHeight() * 0.90), 0, 0);

lin.addView(fl);
tabH.setup();
// android.widget.TabHost.TabSpec ts1 = tabH.newTabSpec("hi");

tabH.addTab(tabH.newTabSpec("tag")

.setIndicator("").setContent(new TabHost.TabContentFactory() {
public View createTabContent(String tag) {
// -- this tab contains multiple control grouped in a panel --
// //
LinearLayout panel = new LinearLayout(Mapper.this);
panel.setOrientation(LinearLayout.HORIZONTAL);

panel.setBackgroundResource(R.drawable.bottom_bar);
i1 = new ImageView(Mapper.this);
i1.setBackgroundResource(R.drawable.map_file);
i2 = new ImageView(Mapper.this);
i2.setBackgroundResource(R.drawable.urhere_file);

i3 = new ImageView(Mapper.this);
i3.setBackgroundResource(R.drawable.navigate_file);

i4 = new ImageView(Mapper.this);
i4.setBackgroundResource(R.drawable.arroundme_file);

panel.addView(i1);
panel.addView(i2);
panel.addView(i3);
panel.addView(i4);

// i1.getLayoutParams().width = getWindowManager()
// .getDefaultDisplay().getWidth() / 4;
// i2.getLayoutParams().width = getWindowManager()
// .getDefaultDisplay().getWidth() / 4;
// i3.getLayoutParams().width = getWindowManager()
// .getDefaultDisplay().getWidth() / 4;
// i4.getLayoutParams().width = getWindowManager()
// .getDefaultDisplay().getWidth() / 4;

MarginLayoutParams marginParams_i1 = new MarginLayoutParams(i1
.getLayoutParams());
if (height >= 800) {
marginParams_i1.setMargins(12, 0, 12, 0);

} else if (height < 480) {
marginParams_i1.setMargins(8, 0, 8, 0);
} else {

marginParams_i1.setMargins(12, 0, 12, 0);
}
LinearLayout.LayoutParams layoutParams_i1 = new LinearLayout.LayoutParams(
marginParams_i1);
i1.setLayoutParams(layoutParams_i1);

MarginLayoutParams marginParams_i2 = new MarginLayoutParams(i2
.getLayoutParams());
if (height >= 800) {
marginParams_i2.setMargins(12, 0, 12, 0);

} else if (height < 480) {
marginParams_i2.setMargins(8, 0, 8, 0);
} else {
marginParams_i2.setMargins(12, 0, 12, 0);
}
LinearLayout.LayoutParams layoutParams_i2 = new LinearLayout.LayoutParams(
marginParams_i2);
i2.setLayoutParams(layoutParams_i2);

MarginLayoutParams marginParams_i3 = new MarginLayoutParams(i3
.getLayoutParams());
if (height >= 800) {
marginParams_i3.setMargins(12, 0, 12, 0);

} else if (height < 480) {
marginParams_i3.setMargins(8, 0, 8, 0);
} else {
marginParams_i3.setMargins(12, 0, 12, 0);
}
LinearLayout.LayoutParams layoutParams_i3 = new LinearLayout.LayoutParams(
marginParams_i3);
i3.setLayoutParams(layoutParams_i3);

MarginLayoutParams marginParams_i4 = new MarginLayoutParams(i4
.getLayoutParams());
if (height >= 800) {
marginParams_i4.setMargins(12, 0, 12, 0);
} else if (height < 480) {
marginParams_i4.setMargins(8, 0, 8, 0);
} else {
marginParams_i4.setMargins(12, 0, 12, 0);
}
LinearLayout.LayoutParams layoutParams_i4 = new LinearLayout.LayoutParams(
marginParams_i4);
i4.setLayoutParams(layoutParams_i4);
return panel;
} // TAB 1 done
}));
// ts1.setContent(new Intent(this,Tab1.class));
// tabH.addTab(ts1);
tabH.getTabWidget().getChildAt(0).getLayoutParams().height = (int) 0.000000001;
tabH.getTabWidget().getChildAt(0).getLayoutParams().width = (int) 0.0000000001;

RelativeLayout.LayoutParams tab = new RelativeLayout.LayoutParams(
LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);

// tab.setMargins(0,(int)
// (getWindowManager().getDefaultDisplay().getHeight()*0.8) , 0, 0);
addContentView(tabH, tab);
i1.setOnClickListener(new View.OnClickListener() {

@Override
public void onClick(View v) {
// do whatever you need
Intent intent = new Intent(Mapper.this, Map.class);

startActivity(intent);
}
});

i2.setOnClickListener(new View.OnClickListener() {

@Override
public void onClick(View v) {
// do whatever you need
// Intent intent = new Intent(Mapper.this, Mapper.class);
//
// startActivity(intent);
}
});
i3.setOnClickListener(new View.OnClickListener() {

@Override
public void onClick(View v) {
// do whatever you need
Intent intent = new Intent(Mapper.this,
navigateAllActivity.class);

startActivity(intent);
}
});
i4.setOnClickListener(new View.OnClickListener() {

@Override
public void onClick(View v) {
// do whatever you need
Intent intent = new Intent(Mapper.this,
AroundmeActivity.class);

startActivity(intent);
}
});


home.setOnClickListener(new View.OnClickListener() {

@Override
public void onClick(View v) {
// do whatever you need
Intent intent = new Intent(Mapper.this,
ZoomByEnterPageActivity.class);

startActivity(intent);
}
});
back.setOnClickListener(new View.OnClickListener() {

@Override
public void onClick(View v) {
// do whatever you need
Intent intent = new Intent(Mapper.this,
ZoomByEnterPageActivity.class);
Mapper.this.finish();

startActivity(intent);
}
});

exchange.setOnClickListener(new View.OnClickListener() {

@Override
public void onClick(View v) {
if (isConnected()) {

if (flag_firsttime == 1) {

String destination1 = place_et.getText().toString();
destination = destination1.replaceAll("\\s", "");

// source = "vadodara";
locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
// Define the criteria how to select the locatioin
// provider -> use
// default
Criteria criteria = new Criteria();
provider = locationManager.getBestProvider(criteria,
false);
Location location = locationManager
.getLastKnownLocation(provider);

// Initialize the location fields
String coordinates[] = { "42.35849", "-71.06010" };
lat = Double.parseDouble(coordinates[0]);
lng = Double.parseDouble(coordinates[1]);

if (location != null) {
System.out.println("Provider " + provider
+ " has been selected.");
String lat1 = " "
+ (double) (location.getLatitude());
String lng1 = " "
+ (double) (location.getLongitude());
lat = Double.parseDouble(lat1);
lng = Double.parseDouble(lng1);

} else {

Toast.makeText(getApplicationContext(),
"Provider not available", 4000).show();
}
onLocationChanged(location);
getAddress();

p = new GeoPoint((int) (lat * 1E6), (int) (lng * 1E6));
flag_firsttime = 0;
}

temp = source;
source = destination;
destination = temp;
place.setText(source);
place_et.setText(destination);
// source_dir = new Direction(lat, lng, "s");
// // dest = new Direction(20.25,
// // 65.70, "d");
// //
// directions.clear();
// directions.add(source_dir);
// // source.replaceAll(" ", "");

getDirections("http://maps.googleapis.com/maps/api/directions/json?origin="
+ source.trim()
+ "&destination="
+ destination.trim() + "&sensor=false");

// directions.add(dest);
goToPoint();
showPosition();
} else {
Toast.makeText(getApplicationContext(),
"no internet connection", 4000).show();
}
}
});

// getDirections("http://maps.googleapis.com/maps/api/directions/json?origin=Ahmedabad,Gujarat&destination=Vadodara,Gujarat&sensor=false");

mapView.setBuiltInZoomControls(true); // newer one

// This sets up where to show a push pin

// This gets everything going
// goToPoint();
// showPosition();

}// oncreate

@Override
protected boolean isRouteDisplayed() {
return true;
}// isroutedisplayed

public boolean isConnected() {
boolean haveConnectedWifi = false;
boolean haveConnectedMobile = false;

ConnectivityManager cm = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo[] netInfo = cm.getAllNetworkInfo();
for (NetworkInfo ni : netInfo) {
if (ni.getTypeName().equalsIgnoreCase("WIFI"))
if (ni.isConnected())
haveConnectedWifi = true;
if (ni.getTypeName().equalsIgnoreCase("MOBILE"))
if (ni.isConnected())
haveConnectedMobile = true;
}
return haveConnectedWifi || haveConnectedMobile;
} // This moves the map center to point p

// This moves the map center to point p
public void goToPoint() {
int cx = (int) (((directions.get(0).lat + directions.get(directions
.size() - 1).lat) / 2d) * 1E6);
int cy = (int) (((directions.get(0).lng + directions.get(directions
.size() - 1).lng) / 2d) * 1E6);
GeoPoint gp = new GeoPoint(cx, cy);
int latSpan = (int) (Math.abs(directions.get(0).lat
- directions.get(directions.size() - 1).lat) * 1E6);
int lngSpan = (int) (Math.abs(directions.get(0).lng
- directions.get(directions.size() - 1).lng) * 1E6);
mc = mapView.getController();
mc.zoomToSpan(latSpan, lngSpan);
mc.animateTo(gp);

}// goto

// This shows the pushpin at point p
public void showPosition() {
MapOverlay mapOverlay = new MapOverlay();
List<Overlay> listOfOverlays = mapView.getOverlays();
listOfOverlays.clear();
listOfOverlays.add(mapOverlay);
mapView.invalidate();

}// showpos

class MapOverlay extends Overlay {

@Override
public boolean draw(Canvas canvas, MapView mapView, boolean shadow,
long when) {
super.draw(canvas, mapView, shadow);
Paint paint = new Paint();
paint.setColor(Color.BLUE);
paint.setStrokeWidth(5);

Point screenPts = new Point();
GeoPoint gp;
int i = 0;
float lx = 0;
float ly = 0;
while (i < directions.size()) {
dest = directions.get(i);
gp = new GeoPoint((int) (dest.lat * 1E6),
(int) (dest.lng * 1E6));
mapView.getProjection().toPixels(gp, screenPts);
if (i > 0)
canvas.drawLine(lx, ly, screenPts.x, screenPts.y, paint);
lx = screenPts.x;
ly = screenPts.y;
i++;
}// drawing route

mapView.getProjection().toPixels(p, screenPts);

// This puts the marker on the map
Bitmap bmp = BitmapFactory.decodeResource(getResources(),
R.drawable.pushpin);
canvas.drawBitmap(bmp, screenPts.x, screenPts.y - 46, null);
return true;
}

@Override
public boolean onTouchEvent(MotionEvent event, MapView mapView) {
// Touch event
// When the map is pressed and released the pushpin goes
// to that point
if (event.getAction() == 1) {
p = mapView.getProjection().fromPixels((int) event.getX(),
(int) event.getY());
directions.clear();
source_dir = new Direction(lat, lng, "s");
// dest = new Direction(20.25,
// 65.70, "d");
//
directions.add(source_dir);
// source.replaceAll(" ", "");
getDirections_online("http://maps.googleapis.com/maps/api/directions/json?origin="
+ source.trim()
+ "&destination="
+ destination.trim()
+ "&sensor=false");

// directions.add(dest);

goToPoint();
showPosition();
}// if
return false;
}// ontouch

}// mapoverlay class

// http://maps.googleapis.com/maps/api/directions/output?parameters
// http://maps.googleapis.com/maps/api/directions/json?origin=Boston,MA&destination=Concord,MA&sensor=false

public void getDirections(String loginUrl) {
JSONObject jArray = null;
String result = "";
String s;
String s1;
String s2;
directions.clear();

try {
HttpGet request = new HttpGet(loginUrl);
HttpClient httpClient = new DefaultHttpClient();
HttpResponse response = httpClient.execute(request);
HttpEntity entityResponse = response.getEntity();
result = EntityUtils.toString(entityResponse);

} catch (Exception e) {
Log.e("log_tag", "Error converting result " + e.toString());
}
try {
jArray = new JSONObject(result);
} catch (JSONException e) {
Log.e("log_tag", "Error parsing data " + e.toString());
}

try {
JSONArray array = jArray.getJSONArray("routes");
JSONObject routes = array.getJSONObject(0);
JSONArray legs = routes.getJSONArray("legs");
JSONObject steps = legs.getJSONObject(0);
JSONArray legs1 = steps.getJSONArray("steps");
for (int i = 0; i < legs1.length(); i++) {
JSONObject steps1 = legs1.getJSONObject(i);
if (i == 0)
s = steps1.getString("start_location");
else
s = steps1.getString("end_location");

// Toast.makeText(getApplicationContext(), " "+s, 6000).show();

s1 = s.substring(s.indexOf(":") + 1); // cut off beginning
s = s1.substring(s1.indexOf(":") + 1, s1.indexOf("}")); // isolate
// longitude
s1 = s1.substring(0, s1.indexOf(",")); // isolate latitude
s.replaceAll(" ", ""); // remove spaces
s1.replaceAll(" ", "");
s2 = steps1.getString("html_instructions");
// Toast.makeText(getApplicationContext(), ""+s2, 4000).show();
source_dir = new Direction(Double.parseDouble(s),
Double.parseDouble(s1), s2);
directions.add(source_dir);
}// for
} catch (Exception e) {
Log.e("log_tag", "Error converting result " + e.toString());
}

}// getdirections

public void getDirections_online(String loginUrl) {

JSONObject jArray = null;
String result = "";
String s;
String s1;
String s2;
// directions.clear();

try {
HttpGet request = new HttpGet(loginUrl);
HttpClient httpClient = new DefaultHttpClient();
HttpResponse response = httpClient.execute(request);
HttpEntity entityResponse = response.getEntity();
result = EntityUtils.toString(entityResponse);

} catch (Exception e) {
Log.e("log_tag", "Error converting result " + e.toString());
}
try {
jArray = new JSONObject(result);
} catch (JSONException e) {
Log.e("log_tag", "Error parsing data " + e.toString());
}

try {
JSONArray array = jArray.getJSONArray("routes");
JSONObject routes = array.getJSONObject(0);
JSONArray legs = routes.getJSONArray("legs");
JSONObject steps = legs.getJSONObject(0);
JSONArray legs1 = steps.getJSONArray("steps");
for (int i = 0; i < legs1.length(); i++) {
JSONObject steps1 = legs1.getJSONObject(i);
/*
* if (i == 0) s = steps1.getString("start_location"); else
*/
s = steps1.getString("end_location");

// Toast.makeText(getApplicationContext(), " "+s, 6000).show();

s1 = s.substring(s.indexOf(":") + 1); // cut off beginning
s = s1.substring(s1.indexOf(":") + 1, s1.indexOf("}")); // isolate
// longitude
s1 = s1.substring(0, s1.indexOf(",")); // isolate latitude
s.replaceAll(" ", ""); // remove spaces
s1.replaceAll(" ", "");
s2 = steps1.getString("html_instructions");
// Toast.makeText(getApplicationContext(), ""+s2, 4000).show();
dest = new Direction(Double.parseDouble(s),
Double.parseDouble(s1), s2);
directions.add(dest);
}// for
} catch (Exception e) {
Log.e("log_tag", "Error converting result " + e.toString());
}

}// getdirections

void getAddress() {
try {

Geocoder gcd = new Geocoder(this, Locale.getDefault());
List<Address> addresses = gcd.getFromLocation(lat, lng, 5);

if (addresses.size() > 0) {
/*
* for (int i = 0; i < addresses.size(); i++) { Address address
* = addresses.get(i);
*
* int maxIndex = address.getMaxAddressLineIndex(); for (int x =
* 0; x <= maxIndex; x++) {
* result.append(address.getAddressLine(x)); result.append(",");
* } result.append(address.getLocality()); result.append(",");
* result.append(address.getPostalCode());
* result.append("\n\n"); }
*/
Address address = addresses.get(0);

String source1 = address.getAddressLine(1);
source = source1.substring(0, source1.indexOf(","));

// Toast.makeText(getApplicationContext(), source, 4000).show();
// result.append("" + lat + lng);

}
} catch (IOException ex) {
// editTextShowLocation.append(ex.getMessage().toString());
} catch (NullPointerException f) {

}
}

public class Direction {
public double lng = 0;
public double lat = 0;
public String txt = "";

public Direction(double latitude, double longitude, String written) {
lng = longitude;
lat = latitude;
txt = written;
}// constructor

}// direction class

@Override
public void onAccuracyChanged(int arg0, int arg1) {
// TODO Auto-generated method stub

}

@Override
public void onSensorChanged(int sensor, float[] values) {
// TODO Auto-generated method stub

}

@Override
public void onLocationChanged(Location location) {
// TODO Auto-generated method stub
String lat1 = " " + (double) (location.getLatitude());
String lng1 = " " + (double) (location.getLongitude());
lat = Double.parseDouble(lat1);
lng = Double.parseDouble(lng1);

p = new GeoPoint((int) (lat * 1E6), (int) (lng * 1E6));
// place.setText("    Ahmedabad");
getAddress();
directions.clear();
source_dir = new Direction(lat, lng, "s");
// dest = new Direction(20.25,
// 65.70, "d");
//
directions.add(source_dir);
// source.replaceAll(" ", "");
getDirections_online("http://maps.googleapis.com/maps/api/directions/json?origin="
+ source.trim()
+ "&destination="
+ destination.trim()
+ "&sensor=false");

// directions.add(dest);

goToPoint();
showPosition();
// Toast.makeText(getApplicationContext(), source + destination, 4000)
// .show();
}

@Override
public void onProviderDisabled(String provider) {
// TODO Auto-generated method stub

}

@Override
public void onProviderEnabled(String provider) {
// TODO Auto-generated method stub

}

@Override
public void onStatusChanged(String provider, int status, Bundle extras) {
// TODO Auto-generated method stub

}
// TODO: Fill In Methods Etc.
}// class

profiledetail.xml


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

    <LinearLayout
        android:id="@+id/toplayout"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:background="@drawable/top_bar" >

        <Button
            android:id="@+id/back"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:background="@drawable/back_btn" />

        <TextView
            android:id="@+id/textview"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:layout_weight="1"
            android:gravity="center"
            android:textColor="#663300"
            android:textSize="19sp" />

        <Button
            android:id="@+id/home"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:background="@drawable/home_btn" />
    </LinearLayout>

    <RelativeLayout
        android:id="@+id/thumblayout"
        android:layout_width="240dp"
        android:layout_height="200dp"
        android:layout_gravity="center_horizontal"
        android:background="@drawable/frame_gujarat"
        android:gravity="center_horizontal"
        android:orientation="horizontal" >

        <ImageView
            android:id="@+id/thumbpic"
            android:layout_width="220dp"
            android:layout_height="170dp"
            android:layout_alignParentTop="true"
            android:layout_centerInParent="true"
            android:layout_margin="0dp"
            android:padding="0dp" >
        </ImageView>
    </RelativeLayout>

    <ScrollView
        android:id="@+id/scrollview"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content" >

        <LinearLayout
            android:id="@+id/detaillayout"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_marginBottom="0dp"
            android:layout_marginTop="0dp"
            android:orientation="vertical"
            android:paddingBottom="0dp"
            android:paddingLeft="9dp"
            android:paddingTop="0dp" >

            <TextView
                android:id="@+id/tv1"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:gravity="left"
                android:textColor="#663300" />

            <TextView
                android:id="@+id/tv2"
                android:layout_width="wrap_content"
                android:layout_height="43dp"
                android:gravity="left"
                android:textColor="#663300" />

            <TextView
                android:id="@+id/tv3"
                android:layout_width="wrap_content"
                android:layout_height="43dp"
                android:gravity="left"
                android:textColor="#663300" />

            <TextView
                android:id="@+id/tv4"
                android:layout_width="wrap_content"
                android:layout_height="43dp"
                android:gravity="left"
                android:textColor="#663300" />

            <TextView
                android:id="@+id/tv5"
                android:layout_width="wrap_content"
                android:layout_height="43dp"
                android:gravity="left"
                android:textColor="#663300" />

            <TextView
                android:id="@+id/tv6"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:gravity="left"
                android:textColor="#663300" />

            <TextView
                android:id="@+id/tv7"
                android:layout_width="wrap_content"
                android:layout_height="43dp"
                android:gravity="left"
                android:textColor="#663300" />

            <TextView
                android:id="@+id/tv8"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:gravity="left"
                android:textColor="#663300" />
        </LinearLayout>
    </ScrollView>

</LinearLayout>

ProfiledetailActivity.java


package com.qualcomm.QCARSamples.ImageTargets;

import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.util.ArrayList;
import java.util.List;

import org.apache.http.NameValuePair;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.HttpClient;
import org.apache.http.client.ResponseHandler;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.BasicResponseHandler;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.message.BasicNameValuePair;
import org.apache.http.params.BasicHttpParams;
import org.apache.http.params.HttpConnectionParams;
import org.apache.http.params.HttpParams;
import org.json.JSONArray;
import org.json.JSONException;

import android.app.Activity;
import android.app.ProgressDialog;
import android.content.Context;
import android.content.Intent;
import android.graphics.Color;
import android.graphics.Typeface;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.text.Html;
import android.util.Log;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup.LayoutParams;
import android.view.ViewGroup.MarginLayoutParams;
import android.widget.Button;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.ScrollView;
import android.widget.TabHost;
import android.widget.TabWidget;
import android.widget.TextView;
import android.widget.Toast;

public class ProfileDetailActivity extends Activity {
int height, width;
ImageView i1, i2, i3, i4, thumbpic;
Button home, back;

int total = 10;

ProgressDialog dialog;
String URL = MainURL.URL + "getinfo";
String responseBody;
JSONArray jArray, jSubArray;

String[] items;
String[] significance, longitude, latitude, thumb, population, languages,
weather, timezones, government;

String info;
TextView info_tv, longitude_tv, latitude_tv, toptext, population_tv,
languages_tv, weather_tv, timezones_tv, government_tv;
LayoutInflater inflater;
ImageLoader1 imageLoader;
LinearLayout.LayoutParams thumbparams;

public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.profiledetail);
dialog = ProgressDialog.show(ProfileDetailActivity.this, "",
"Loading Data ...Please Wait", true);
height = getWindowManager().getDefaultDisplay().getHeight();
width = getWindowManager().getDefaultDisplay().getWidth();
home = (Button) findViewById(R.id.home);
back = (Button) findViewById(R.id.back);
info_tv = (TextView) findViewById(R.id.tv1);
population_tv = (TextView) findViewById(R.id.tv2);
languages_tv = (TextView) findViewById(R.id.tv3);
weather_tv = (TextView) findViewById(R.id.tv4);
timezones_tv = (TextView) findViewById(R.id.tv5);
government_tv = (TextView) findViewById(R.id.tv6);
longitude_tv = (TextView) findViewById(R.id.tv7);
latitude_tv = (TextView) findViewById(R.id.tv8);
thumbpic = (ImageView) findViewById(R.id.thumbpic);
toptext = (TextView) findViewById(R.id.textview);
toptext.setText("Profile");
ScrollView sv = (ScrollView) findViewById(R.id.scrollview);
if (height == 320) {
sv.getLayoutParams().height = (int) (height * 0.36);
} else if (height == 400) {
sv.getLayoutParams().height = (int) (height * 0.42);
} else {
sv.getLayoutParams().height = (int) (height * 0.48);
}
RelativeLayout ll = (RelativeLayout) findViewById(R.id.centerlayout);
// ll.setOrientation(LinearLayout.VERTICAL);

// if (height <= 320) {
//
// thumbparams = new LinearLayout.LayoutParams((int) 230,
// (int) (height * 0.30));
//
// thumbparams.setMargins(0, 5, 0, 5);
// } else if ((height > 320) && (height < 800)) {
// if (width == 240) {
// thumbparams = new LinearLayout.LayoutParams((int) 230,
// (int) (height * 0.23));
//
// thumbparams.setMargins(0, 5, 0, 5);
// } else {// width=320
// thumbparams = new LinearLayout.LayoutParams((int) 310,
// (int) (height * 0.23));
//
// thumbparams.setMargins(0, 5, 0, 5);
//
// }
//
// } else {// width=480
// thumbparams = new LinearLayout.LayoutParams((int) 470,
// (int) (height * 0.27));
//
// thumbparams.setMargins(0, 10, 0, 5);
//
// }
// // thumbparams = new LinearLayout.LayoutParams(
// // LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
//
// ll.addView(thumbpic, thumbparams);
LinearLayout mainlayout = (LinearLayout) findViewById(R.id.mainlayout);
mainlayout.getLayoutParams().height = (int) (height * 0.90);
TabHost tabH = new TabHost(this);
TabWidget tabWidget = new TabWidget(this);
LinearLayout lin = new LinearLayout(this);
lin.setOrientation(LinearLayout.HORIZONTAL);
tabWidget.setId(android.R.id.tabs);
tabH.addView(tabWidget);
tabH.addView(lin);
FrameLayout fl = new FrameLayout(this);
fl.setId(android.R.id.tabcontent);

fl.setPadding(0, (int) (getWindowManager().getDefaultDisplay()
.getHeight() * 0.90), 0, 0);

lin.addView(fl);
tabH.setup();
// android.widget.TabHost.TabSpec ts1 = tabH.newTabSpec("hi");

tabH.addTab(tabH.newTabSpec("tag")

.setIndicator("").setContent(new TabHost.TabContentFactory() {
public View createTabContent(String tag) {
// -- this tab contains multiple control grouped in a panel --
// //
LinearLayout panel = new LinearLayout(
ProfileDetailActivity.this);
panel.setOrientation(LinearLayout.HORIZONTAL);

panel.setBackgroundResource(R.drawable.bottom_bar);
i1 = new ImageView(ProfileDetailActivity.this);
i1.setBackgroundResource(R.drawable.map_file);
i2 = new ImageView(ProfileDetailActivity.this);
i2.setBackgroundResource(R.drawable.urhere_file);

i3 = new ImageView(ProfileDetailActivity.this);
i3.setBackgroundResource(R.drawable.navigate_file);

i4 = new ImageView(ProfileDetailActivity.this);
i4.setBackgroundResource(R.drawable.arroundme_file);

panel.addView(i1);
panel.addView(i2);
panel.addView(i3);
panel.addView(i4);

// i1.getLayoutParams().width = getWindowManager()
// .getDefaultDisplay().getWidth() / 4;
// i2.getLayoutParams().width = getWindowManager()
// .getDefaultDisplay().getWidth() / 4;
// i3.getLayoutParams().width = getWindowManager()
// .getDefaultDisplay().getWidth() / 4;
// i4.getLayoutParams().width = getWindowManager()
// .getDefaultDisplay().getWidth() / 4;

MarginLayoutParams marginParams_i1 = new MarginLayoutParams(i1
.getLayoutParams());
if (height >= 800) {
marginParams_i1.setMargins(12, 0, 12, 0);

} else if (height < 480) {
marginParams_i1.setMargins(8, 0, 8, 0);
} else {

marginParams_i1.setMargins(12, 0, 12, 0);
}
LinearLayout.LayoutParams layoutParams_i1 = new LinearLayout.LayoutParams(
marginParams_i1);
i1.setLayoutParams(layoutParams_i1);

MarginLayoutParams marginParams_i2 = new MarginLayoutParams(i2
.getLayoutParams());
if (height >= 800) {
marginParams_i2.setMargins(12, 0, 12, 0);

} else if (height < 480) {
marginParams_i2.setMargins(8, 0, 8, 0);
} else {
marginParams_i2.setMargins(12, 0, 12, 0);
}
LinearLayout.LayoutParams layoutParams_i2 = new LinearLayout.LayoutParams(
marginParams_i2);
i2.setLayoutParams(layoutParams_i2);

MarginLayoutParams marginParams_i3 = new MarginLayoutParams(i3
.getLayoutParams());
if (height >= 800) {
marginParams_i3.setMargins(12, 0, 12, 0);

} else if (height < 480) {
marginParams_i3.setMargins(8, 0, 8, 0);
} else {
marginParams_i3.setMargins(12, 0, 12, 0);
}
LinearLayout.LayoutParams layoutParams_i3 = new LinearLayout.LayoutParams(
marginParams_i3);
i3.setLayoutParams(layoutParams_i3);

MarginLayoutParams marginParams_i4 = new MarginLayoutParams(i4
.getLayoutParams());
if (height >= 800) {
marginParams_i4.setMargins(12, 0, 12, 0);
} else if (height < 480) {
marginParams_i4.setMargins(8, 0, 8, 0);
} else {
marginParams_i4.setMargins(12, 0, 12, 0);
}
LinearLayout.LayoutParams layoutParams_i4 = new LinearLayout.LayoutParams(
marginParams_i4);
i4.setLayoutParams(layoutParams_i4);
return panel;
} // TAB 1 done
}));
// ts1.setContent(new Intent(this,Tab1.class));
// tabH.addTab(ts1);
tabH.getTabWidget().getChildAt(0).getLayoutParams().height = (int) 0.000000001;
tabH.getTabWidget().getChildAt(0).getLayoutParams().width = (int) 0.0000000001;

RelativeLayout.LayoutParams tab = new RelativeLayout.LayoutParams(
LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);

// tab.setMargins(0,(int)
// (getWindowManager().getDefaultDisplay().getHeight()*0.8) , 0, 0);
addContentView(tabH, tab);
i1.setOnClickListener(new View.OnClickListener() {

@Override
public void onClick(View v) {
// do whatever you need
Intent intent = new Intent(ProfileDetailActivity.this,
Map.class);

startActivity(intent);
}
});

i2.setOnClickListener(new View.OnClickListener() {

@Override
public void onClick(View v) {
// do whatever you need
Intent intent = new Intent(ProfileDetailActivity.this,
Mapper.class);

startActivity(intent);
}
});
i3.setOnClickListener(new View.OnClickListener() {

@Override
public void onClick(View v) {
// do whatever you need
Intent intent = new Intent(ProfileDetailActivity.this,
navigateAllActivity.class);

startActivity(intent);
}
});
i4.setOnClickListener(new View.OnClickListener() {

@Override
public void onClick(View v) {
// do whatever you need
Intent intent = new Intent(ProfileDetailActivity.this,
AroundmeActivity.class);

startActivity(intent);
}
});

home.setOnClickListener(new View.OnClickListener() {

@Override
public void onClick(View v) {
// do whatever you need
Intent intent = new Intent(ProfileDetailActivity.this,
ZoomByEnterPageActivity.class);

startActivity(intent);
}
});
back.setOnClickListener(new View.OnClickListener() {

@Override
public void onClick(View v) {
// do whatever you need
Intent intent = new Intent(ProfileDetailActivity.this,
ProfileActivity.class);
ProfileDetailActivity.this.finish();

startActivity(intent);
}
});

fetchData.start();

}

final Handler handler = new Handler() {
public void handleMessage(Message msg) {
try {
// int start = responseBody.indexOf("{");
// int end = responseBody.length();
// String result = responseBody.substring(start, end);
// // Toast.makeText(getApplicationContext(), result,
// 9000).show();

int start = responseBody.indexOf("status");
int end = responseBody.length();
String result = responseBody.substring(start, end);
String result1 = "[{" + '"' + result.toString().trim();
// Toast.makeText(getApplicationContext(), result1,
// 9000).show();
// Log.e("result", "" + result1);

try {
jArray = new JSONArray(result1.toString());
} catch (JSONException e) {
Log.e("log_tag", "Error parsing data " + e.toString());
}

try {
items = new String[jArray.length()];

for (int i = 0; i < jArray.length(); i++) {

items[i] = jArray.getJSONObject(i).getString("status")
.toString();
info = jArray.getJSONObject(i).getString("info")
.toString();

}
jSubArray = new JSONArray(info.toString());

significance = new String[jSubArray.length()];
longitude = new String[jSubArray.length()];

latitude = new String[jSubArray.length()];
thumb = new String[jSubArray.length()];
population = new String[jSubArray.length()];
languages = new String[jSubArray.length()];
weather = new String[jSubArray.length()];
timezones = new String[jSubArray.length()];
government = new String[jSubArray.length()];

for (int j = 0; j < jSubArray.length(); j++) {
significance[j] = jSubArray.getJSONObject(j)
.getString("info").toString();
longitude[j] = jSubArray.getJSONObject(j)
.getString("longitude").toString();
latitude[j] = jSubArray.getJSONObject(j)
.getString("latitude").toString();
thumb[j] = jSubArray.getJSONObject(j)
.getString("thumb").toString();
population[j] = jSubArray.getJSONObject(j)
.getString("population").toString();
languages[j] = jSubArray.getJSONObject(j)
.getString("languages").toString();
weather[j] = jSubArray.getJSONObject(j)
.getString("weather").toString();
timezones[j] = jSubArray.getJSONObject(j)
.getString("timezones").toString();
government[j] = jSubArray.getJSONObject(j)
.getString("government").toString();

total = jSubArray.length();
}

} catch (JSONException e) {
Log.e("log_tag", "Error parsing data " + e.toString());
}
if (items[0].equalsIgnoreCase("OK")) {
if ((dialog.isShowing()))
dialog.dismiss();

} else {
if ((dialog.isShowing()))
dialog.dismiss();
Toast.makeText(getApplicationContext(),
"try after some time", 4000).show();
}
} catch (NullPointerException e) {
if ((dialog.isShowing()))
dialog.dismiss();
Toast.makeText(getApplicationContext(), "try after some time",
4000).show();
}

// for (int j = 0; j < total; j++) {
// info_tv.setText(Html.fromHtml("<p align=justify><b>  History  : </b>"
// + history[0] + "</p>"));
Typeface type = Typeface.createFromAsset(getAssets(), "hce.ttf");
info_tv.setTypeface(type);
longitude_tv.setTypeface(type);
latitude_tv.setTypeface(type);
population_tv.setTypeface(type);
languages_tv.setTypeface(type);
weather_tv.setTypeface(type);
timezones_tv.setTypeface(type);
government_tv.setTypeface(type);
info_tv.setText(Html.fromHtml("<p align=justify><b> Gujarat   </b> <br> <font color=black>"
+ significance[0] + "</font></p>"));

longitude_tv.setText(Html
.fromHtml("<p align=justify><b> Longitude  </b> <br> <font color=black>"
+ longitude[0] + "</font></p>"));

latitude_tv.setText(Html
.fromHtml("<p align=justify><b> Latitude  </b><br> <font color=black>"
+ latitude[0] + "</font></p>"));
population_tv.setText(Html
.fromHtml("<p align=justify><b> Population  </b><br><font color=black>"
+ population[0] + "</font></p>"));
languages_tv.setText(Html
.fromHtml("<p align=justify><b> Languages  </b><br><font color=black>"
+ languages[0] + "</font></p>"));
weather_tv.setText(Html
.fromHtml("<p align=justify><b> Weather  </b><br><font color=black>"
+ weather[0] + "</font></p>"));
timezones_tv.setText(Html
.fromHtml("<p align=justify><b> Timezones  </b><br><font color=black>"
+ timezones[0] + "</font></p>"));
government_tv.setText(Html
.fromHtml("<p align=justify><b> Government  </b><br> <font color=black>"
+ government[0] + "</font></p>"));
// }

try {

Activity activity;

activity = ProfileDetailActivity.this;

inflater = (LayoutInflater) activity
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);

imageLoader = new ImageLoader1(activity.getApplicationContext());

// for (int i = 0; i < total; i++) {

// imageview_left[i].setImageBitmap(bmp[i]);
thumbpic.setTag(thumb[0]);

imageLoader.DisplayImage(thumb[0], activity, thumbpic);

// }
} catch (NullPointerException f) {
Toast.makeText(getApplicationContext(), "reload the page", 5000)
.show();
} catch (ArrayIndexOutOfBoundsException g) {
Toast.makeText(getApplicationContext(), "reload the page", 5000)
.show();
}

if ((dialog.isShowing()))
dialog.dismiss();

}
};

Thread fetchData = new Thread() {// worker thread or background thread
public void run() {

double TIMEOUT_MILLISEC = 1234567890;

HttpParams httpParams = new BasicHttpParams();
HttpConnectionParams.setConnectionTimeout(httpParams,
(int) TIMEOUT_MILLISEC);
HttpConnectionParams.setSoTimeout(httpParams,
(int) TIMEOUT_MILLISEC);
//
HttpParams p = new BasicHttpParams();
// p.setParameter("name", pvo.getName());

p.setParameter("type_id", "1");
p.setParameter("type", "1");
p.setParameter("detail_id", "1.1");
p.setParameter("Get Information", "Get Information");

p.setParameter("key", "c89a7662dae613ea3d20d334339b6dff");

// Instantiate an HttpClient
HttpClient httpclient = new DefaultHttpClient(p);

HttpPost httppost = new HttpPost(URL);

List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(5);

nameValuePairs.add(new BasicNameValuePair("type_id", "1"));
nameValuePairs.add(new BasicNameValuePair("type", "1"));
nameValuePairs.add(new BasicNameValuePair("detail_id", "1.1"));
nameValuePairs.add(new BasicNameValuePair("Get Information",
"Get Information"));

nameValuePairs.add(new BasicNameValuePair("key",
"c89a7662dae613ea3d20d334339b6dff"));

try {
httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
} catch (UnsupportedEncodingException e) { // TODO Auto-generated
// catch
;
}

ResponseHandler<String> responseHandler = new BasicResponseHandler();
try {
responseBody = httpclient.execute(httppost, responseHandler);
Log.e("aaaaaaaaaaaaaaaaaaaaaaaaa+++", responseBody.toString());
} catch (ClientProtocolException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
handler.sendEmptyMessage(0);
}

};

}