Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.example.free;
- import java.io.BufferedReader;
- import java.io.IOException;
- import java.io.InputStream;
- import java.io.InputStreamReader;
- import java.util.ArrayList;
- import java.util.HashMap;
- import java.util.List;
- import java.util.Locale;
- import org.apache.http.HttpEntity;
- import org.apache.http.HttpResponse;
- import org.apache.http.HttpStatus;
- import org.apache.http.client.HttpClient;
- import org.apache.http.client.methods.HttpGet;
- import org.apache.http.client.methods.HttpPost;
- import org.apache.http.impl.client.DefaultHttpClient;
- import org.json.JSONArray;
- import org.json.JSONException;
- import org.json.JSONObject;
- import android.content.Context;
- import android.content.Intent;
- import android.graphics.Bitmap;
- import android.graphics.BitmapFactory;
- 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.Uri;
- import android.os.AsyncTask;
- import android.os.Bundle;
- import android.support.v4.app.Fragment;
- import android.util.Log;
- import android.view.LayoutInflater;
- import android.view.View;
- import android.view.View.OnClickListener;
- import android.view.ViewGroup;
- import android.widget.ImageView;
- import android.widget.ProgressBar;
- import android.widget.ScrollView;
- import android.widget.TextView;
- import android.widget.Toast;
- import com.google.android.gms.maps.CameraUpdateFactory;
- import com.google.android.gms.maps.GoogleMap;
- import com.google.android.gms.maps.GoogleMap.OnInfoWindowClickListener;
- import com.google.android.gms.maps.GoogleMap.OnMapLongClickListener;
- import com.google.android.gms.maps.MapFragment;
- import com.google.android.gms.maps.model.BitmapDescriptorFactory;
- import com.google.android.gms.maps.model.LatLng;
- import com.google.android.gms.maps.model.Marker;
- import com.google.android.gms.maps.model.MarkerOptions;
- public class MainActivity extends Fragment implements OnMapLongClickListener {
- public void ToastLoadShout(String msg) {
- Toast.makeText(getActivity(), msg.toString(), Toast.LENGTH_LONG).show();
- }
- // GoogleMap variables
- // static final LatLng gps = new LatLng(0, 0);
- static double lat = 0.0;
- static double lon = 0.0;
- private GoogleMap map;
- Marker loc;
- Marker lastOpened = null;
- private HashMap<Marker, Integer> markerMap = new HashMap<Marker, Integer>();
- // For checking server's json output
- // String datadata;
- // http request variables
- HttpClient client;
- HttpPost httppost;
- HttpGet httpget;
- JSONObject json;
- // items holding variables
- List<List<String>> items;
- List<item> markers = new ArrayList<item>();
- // other variables
- // private ProgressDialog m_ProgressDialog = null;
- static int tries = 0;
- TextView loader;
- View line1;
- View line2;
- View line3;
- ProgressBar loadbar;
- ImageView Load;
- ImageView Add;
- ScrollView itemView;
- ImageView closeItemView;
- String addrString = "";
- ProgressBar Loadimg;
- TextView title;
- TextView category;
- TextView addr;
- TextView desc;
- TextView pub;
- TextView positive;
- TextView negative;
- TextView idfeed;
- ImageView view;
- double itemLat;
- double itemLon;
- @Override
- public View onCreateView(LayoutInflater inflater, ViewGroup container,
- Bundle savedInstanceState) {
- return inflater.inflate(R.layout.activity_main, container, false);
- }
- @Override
- public void onStart() {
- super.onStart();
- // getActivity().getActionBar().setDisplayOptions(
- // ActionBar.DISPLAY_SHOW_CUSTOM);
- // getActivity().getActionBar().setCustomView(R.layout.titlebar);
- //
- // getActivity().getActionBar().setHomeButtonEnabled(true);
- // getActivity().getActionBar().setDisplayHomeAsUpEnabled(true);
- // converting int to string and vice versa
- /*
- * String num="4321"; int n = Integer.parseInt(num); String after=
- * Integer.toString(n); ToastLoadShout(after);
- */
- // itemView Scrollview views
- title = (TextView) getView().findViewById(R.id.title);
- category = (TextView) getView().findViewById(R.id.category);
- Loadimg = (ProgressBar) getView().findViewById(R.id.Loadimg);
- addr = (TextView) getView().findViewById(R.id.addr);
- desc = (TextView) getView().findViewById(R.id.desc);
- pub = (TextView) getView().findViewById(R.id.pub);
- view = (ImageView) getView().findViewById(R.id.imageView1);
- positive = (TextView) getView().findViewById(R.id.positive);
- negative = (TextView) getView().findViewById(R.id.negative);
- idfeed = (TextView) getView().findViewById(R.id.idfeed);
- itemView = (ScrollView) getView().findViewById(R.id.itemwin);
- itemView.setVisibility(View.INVISIBLE);
- closeItemView = (ImageView) getView().findViewById(R.id.closeitem);
- closeItemView.setVisibility(View.INVISIBLE);
- Loadimg.setVisibility(View.INVISIBLE);
- turnGPSOn();
- map = ((MapFragment) getActivity().getFragmentManager()
- .findFragmentById(R.id.map)).getMap();
- ImageView locate;
- locate = (ImageView) getView().findViewById(R.id.locate);
- locate.setOnClickListener(new OnClickListener() {
- public void onClick(View v) {
- tries++;
- ReNewCoordinates();
- ReNewCoordinates();
- if (lat == 0 && lon == 0)
- getLocation();
- if (tries > 2 && lat == 0 && lon == 0) {
- ToastLoadShout("Unable to determine location.\nPlease enable Wireless and GPS satelites.");
- startActivity(new Intent(
- android.provider.Settings.ACTION_LOCATION_SOURCE_SETTINGS));
- }
- if (loc != null)
- loc.remove();
- if (lat == 0 && lon == 0)
- ToastLoadShout("Try again in a few seconds. (#" + tries
- + ")");
- else {
- map.moveCamera(CameraUpdateFactory.newLatLngZoom(
- new LatLng(lat, lon), 10));
- ToastLoadShout("your location is: " + lat + " , " + lon);
- map.animateCamera(CameraUpdateFactory.zoomTo(14), 3000,
- null);
- loc = map.addMarker(new MarkerOptions().position(
- new LatLng(lat, lon)).icon(
- BitmapDescriptorFactory
- .fromResource(R.drawable.loc)));
- }
- }
- });
- loadbar = (ProgressBar) getView().findViewById(R.id.loadbar);
- loadbar.setVisibility(View.INVISIBLE);
- line1 = (View) getView().findViewById(R.id.line1);
- line2 = (View) getView().findViewById(R.id.line2);
- line3 = (View) getView().findViewById(R.id.line3);
- loader = (TextView) getView().findViewById(R.id.loader);
- loader.setVisibility(View.INVISIBLE);
- line1.setVisibility(View.INVISIBLE);
- line2.setVisibility(View.INVISIBLE);
- line3.setVisibility(View.INVISIBLE);
- Load = (ImageView) getView().findViewById(R.id.refresh);
- Load.setOnClickListener(new OnClickListener() {
- public void onClick(View v) {
- map.clear();
- markers.clear();
- new Load().execute();
- }
- });
- // Add = (ImageView) getView().findViewById(R.id.add);
- // Add.setOnClickListener(new OnClickListener() {
- // public void onClick(View v) {
- // Intent Intent = new Intent(MainActivity.this,Add.class);
- // Bundle bndlanimation =
- // ActivityOptions.makeCustomAnimation(getApplicationContext(),
- // R.anim.animation,R.anim.animation2).toBundle();
- // startActivity(Intent, bndlanimation);
- // }
- // });
- closeItemView.setOnClickListener(new OnClickListener() {
- public void onClick(View v) {
- itemView.setVisibility(View.INVISIBLE);
- closeItemView.setVisibility(View.INVISIBLE);
- line3.setVisibility(View.INVISIBLE);
- }
- });
- map.getUiSettings().setZoomControlsEnabled(false);
- map.moveCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(50.909474,
- 13.917618), 10000));
- map.animateCamera(CameraUpdateFactory.zoomTo(1), 20, null);
- // Move the camera instantly to hamburg with a zoom of 15.
- // map.moveCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(lat,lon),
- // 15));
- // Zoom in, animating the camera.
- // map.animateCamera(CameraUpdateFactory.zoomTo(10), 2000, null);
- // ToastLoadShout("your location is: "+lat+" , "+lon);
- map.setOnInfoWindowClickListener(new OnInfoWindowClickListener() {
- public void onInfoWindowClick(Marker marker) {
- // Intent Intent = new Intent(MainActivity.this,ItemView.class);
- for (int i = 0; i < markers.size(); i++) {
- if (markerMap.get(marker) == markers.get(i).getId()) {
- /*
- * Intent.putExtra("thing",markers.get(i));
- * startActivity(Intent);
- */
- view.setImageDrawable(null);
- itemView.fullScroll(View.FOCUS_UP);
- itemView.setVisibility(View.VISIBLE);
- closeItemView.setVisibility(View.VISIBLE);
- line3.setVisibility(View.VISIBLE);
- Loadimg.setVisibility(View.VISIBLE);
- title.setText(markers.get(i).getTitle());
- category.setText(markers.get(i).getCat() + "");
- desc.setText(markers.get(i).getDesc());
- addr.setText(markers.get(i).getAddr());
- pub.setText(markers.get(i).getPub());
- positive.setText(markers.get(i).getP() + "");
- negative.setText(markers.get(i).getN() + "");
- idfeed.setText("№" + markers.get(i).getId() + "");
- // itemLat=markers.get(i).getLat();
- // itemLon=markers.get(i).getLon();
- // new LoadAddress().execute();
- new ImageDownloader()
- .execute("http://apple.sourcherry.tk/freeapp/resize.php?h=400&img=upload/id"
- + markers.get(i).getId() + ".jpg");
- break;
- }
- }
- }
- });
- map.setOnMapLongClickListener(this);
- }
- public void onMapLongClick(LatLng point) {
- if (loc != null)
- loc.remove();
- loc = map.addMarker(new MarkerOptions().position(point).icon(
- BitmapDescriptorFactory.fromResource(R.drawable.loc)));
- lat = point.latitude;
- lon = point.longitude;
- }
- public void ArrangePutMarkers() {
- if (items != null) {
- for (int i = 0; i < items.get(0).size(); i++) {
- // My old method //markers.add(new
- // item(Integer.parseInt(items.get(0).get(i))/*id*/,
- // items.get(1).get(i)/*title*/,items.get(2).get(i)/*snippet*/,
- // Integer.parseInt(items.get(3).get(i))/*cat*/,items.get(4).get(i)/*desc*/,
- // Double.parseDouble(items.get(5).get(i))/*lat*/,
- // Double.parseDouble(items.get(6).get(i))/*lon*/,
- // items.get(7).get(i)/*pub*/,
- // Integer.parseInt(items.get(8).get(i))/*p*/,
- // Integer.parseInt(items.get(9).get(i))/*n*/,Integer.parseInt(items.get(10).get(i))/*program*/,items.get(11).get(i)/*address*/));
- markers.add(new item(
- Integer.parseInt(items.get(0).get(i))/* id */, items
- .get(1).get(i)/* title */,
- items.get(2).get(i)/* snippet */, Double
- .parseDouble(items.get(3).get(i))/* lat */,
- Double.parseDouble(items.get(4).get(i))/* lon */,
- Integer.parseInt(items.get(5).get(i))/* program */));
- }
- for (int i = 0; i < markers.size(); i++) {
- LatLng ll = new LatLng(markers.get(i).getLat(), markers.get(i)
- .getLon());
- String title = markers.get(i).getTitle();
- String snippet = markers.get(i).getSnippet();
- // String desc=markers.get(i).getDesc();
- if (markers.get(i).getProgram() == 0)
- this.markerMap.put(this.map.addMarker(new MarkerOptions()
- .position(ll)
- .title(title)
- .snippet(snippet)
- .icon(BitmapDescriptorFactory
- .fromResource(R.drawable.bronze))), markers
- .get(i).getId());
- else if (markers.get(i).getProgram() == 1)
- this.markerMap.put(this.map.addMarker(new MarkerOptions()
- .position(ll)
- .title(title)
- .snippet(snippet)
- .icon(BitmapDescriptorFactory
- .fromResource(R.drawable.silver))), markers
- .get(i).getId());
- else if (markers.get(i).getProgram() == 2)
- this.markerMap.put(this.map.addMarker(new MarkerOptions()
- .position(ll)
- .title(title)
- .snippet(snippet)
- .icon(BitmapDescriptorFactory
- .fromResource(R.drawable.gold))), markers
- .get(i).getId());
- }
- }
- // loader.setText("Done.");
- }
- class Load extends AsyncTask<String, Integer, Boolean> {
- @Override
- protected void onPreExecute() {
- loadbar.setVisibility(View.VISIBLE);
- Load.setVisibility(View.INVISIBLE);
- loader.setVisibility(View.VISIBLE);
- line1.setVisibility(View.VISIBLE);
- line2.setVisibility(View.VISIBLE);
- // TODO Auto-generated method stub
- loader.setText("Getting those attractions..");
- }
- @Override
- protected Boolean doInBackground(String... params) {
- try {
- items = DownloadList();
- if (items != null)
- return true;
- } catch (Exception e) {
- e.printStackTrace();
- return false;
- }
- return false;
- }
- @Override
- protected void onPostExecute(Boolean res) {
- // TODO Auto-generated method stub
- if (res) {
- // m_ProgressDialog.dismiss();
- ArrangePutMarkers();
- loader.setVisibility(View.INVISIBLE);
- line1.setVisibility(View.INVISIBLE);
- line2.setVisibility(View.INVISIBLE);
- loadbar.setVisibility(View.INVISIBLE);
- Load.setVisibility(View.VISIBLE);
- // ToastLoadShout(datadata);
- } else {
- // m_ProgressDialog.dismiss();
- loader.setText("Oh snap. There was an error..");
- ToastLoadShout("Error");
- loadbar.setVisibility(View.INVISIBLE);
- Load.setVisibility(View.VISIBLE);
- // ToastLoadShout(datadata);
- }
- }
- }
- public List<List<String>> Download() {
- String data = null;
- // String res = "";
- try {
- client = new DefaultHttpClient();// Reference to the Internet
- httppost = new HttpPost(
- "http://apple.sourcherry.tk/freeapp/json.php");
- HttpResponse response = client.execute(httppost);
- HttpEntity entity = response.getEntity();// get the content of the
- // message
- InputStream webs = entity.getContent();
- BufferedReader in = new BufferedReader(new InputStreamReader(webs,
- "iso-8859-1"));
- StringBuffer sb = new StringBuffer("");
- String l = " ";
- // String nl=System.getProperty("line.separator");
- while ((l = in.readLine()) != null) {
- sb.append(l + "\n");
- }
- data = sb.toString();
- webs.close();
- List<List<String>> all = new ArrayList<List<String>>();
- all.add(new ArrayList<String>());// id
- all.add(new ArrayList<String>());// title
- all.add(new ArrayList<String>());// snippet
- all.add(new ArrayList<String>());// category
- all.add(new ArrayList<String>());// desc
- all.add(new ArrayList<String>());// lat
- all.add(new ArrayList<String>());// lon
- all.add(new ArrayList<String>());// pub
- all.add(new ArrayList<String>());// p
- all.add(new ArrayList<String>());// n
- all.add(new ArrayList<String>());// program
- all.add(new ArrayList<String>());// addr
- try {
- JSONObject json = new JSONObject(data);
- JSONArray jArray = json.getJSONArray("item");
- // id
- for (int i = 0; i < jArray.length(); i++) {
- JSONObject json_data = jArray.getJSONObject(i);
- all.get(0).add(json_data.getString("id"));
- }
- // title
- for (int i = 0; i < jArray.length(); i++) {
- JSONObject json_data = jArray.getJSONObject(i);
- all.get(1).add(json_data.getString("title"));
- }
- // snippet
- for (int i = 0; i < jArray.length(); i++) {
- JSONObject json_data = jArray.getJSONObject(i);
- all.get(2).add(json_data.getString("snippet"));
- }
- // category
- for (int i = 0; i < jArray.length(); i++) {
- JSONObject json_data = jArray.getJSONObject(i);
- all.get(3).add(json_data.getString("cat"));
- }
- // desc
- for (int i = 0; i < jArray.length(); i++) {
- JSONObject json_data = jArray.getJSONObject(i);
- all.get(4).add(json_data.getString("desc"));
- }
- // lat
- for (int i = 0; i < jArray.length(); i++) {
- JSONObject json_data = jArray.getJSONObject(i);
- all.get(5).add(json_data.getString("lat"));
- }
- // lon
- for (int i = 0; i < jArray.length(); i++) {
- JSONObject json_data = jArray.getJSONObject(i);
- all.get(6).add(json_data.getString("lon"));
- }
- // pub
- for (int i = 0; i < jArray.length(); i++) {
- JSONObject json_data = jArray.getJSONObject(i);
- all.get(7).add(json_data.getString("pub"));
- }
- // p
- for (int i = 0; i < jArray.length(); i++) {
- JSONObject json_data = jArray.getJSONObject(i);
- all.get(8).add(json_data.getString("p"));
- }
- // n
- for (int i = 0; i < jArray.length(); i++) {
- JSONObject json_data = jArray.getJSONObject(i);
- all.get(9).add(json_data.getString("n"));
- }
- // program
- for (int i = 0; i < jArray.length(); i++) {
- JSONObject json_data = jArray.getJSONObject(i);
- all.get(10).add(json_data.getString("program"));
- }
- // address
- for (int i = 0; i < jArray.length(); i++) {
- JSONObject json_data = jArray.getJSONObject(i);
- all.get(11).add(json_data.getString("addr"));
- }
- return all;
- } catch (JSONException e) {
- }
- } catch (Exception e) {
- int x = 3;
- // TODO: handle exception
- }
- return null;
- }
- public List<List<String>> DownloadList() {
- String data = null;
- // String res = "";
- try {
- client = new DefaultHttpClient();// Reference to the Internet
- httpget = new HttpGet(
- "http://apple.sourcherry.tk/freeapp/distance.php?lat="
- + lat + "&lon=" + lon + "&rad=5");
- HttpResponse response = client.execute(httpget);
- HttpEntity entity = response.getEntity();// get the content of the
- // message
- InputStream webs = entity.getContent();
- BufferedReader in = new BufferedReader(new InputStreamReader(webs,
- "UTF-8"));
- StringBuffer sb = new StringBuffer("");
- String l = " ";
- // String nl=System.getProperty("line.separator");
- while ((l = in.readLine()) != null) {
- sb.append(l + "\n");
- }
- data = sb.toString();
- // datadata=data;
- webs.close();
- List<List<String>> all = new ArrayList<List<String>>();
- all.add(new ArrayList<String>());// id
- all.add(new ArrayList<String>());// title
- all.add(new ArrayList<String>());// snippet
- all.add(new ArrayList<String>());// lat
- all.add(new ArrayList<String>());// lon
- all.add(new ArrayList<String>());// program
- try {
- JSONObject json = new JSONObject(data);
- JSONArray jArray = json.getJSONArray("item");
- // id
- for (int i = 0; i < jArray.length(); i++) {
- JSONObject json_data = jArray.getJSONObject(i);
- all.get(0).add(json_data.getString("id"));
- }
- // title
- for (int i = 0; i < jArray.length(); i++) {
- JSONObject json_data = jArray.getJSONObject(i);
- all.get(1).add(json_data.getString("title"));
- }
- // snippet
- for (int i = 0; i < jArray.length(); i++) {
- JSONObject json_data = jArray.getJSONObject(i);
- all.get(2).add(json_data.getString("snippet"));
- }
- // lat
- for (int i = 0; i < jArray.length(); i++) {
- JSONObject json_data = jArray.getJSONObject(i);
- all.get(3).add(json_data.getString("lat"));
- }
- // lon
- for (int i = 0; i < jArray.length(); i++) {
- JSONObject json_data = jArray.getJSONObject(i);
- all.get(4).add(json_data.getString("lon"));
- }
- // program
- for (int i = 0; i < jArray.length(); i++) {
- JSONObject json_data = jArray.getJSONObject(i);
- all.get(5).add(json_data.getString("program"));
- }
- return all;
- } catch (JSONException e) {
- }
- } catch (Exception e) {
- int x = 3;
- // TODO: handle exception
- }
- return null;
- }
- private void turnGPSOn() {
- String provider = android.provider.Settings.Secure.getString(
- getActivity().getContentResolver(),
- android.provider.Settings.Secure.LOCATION_PROVIDERS_ALLOWED);
- if (!provider.contains("gps")) { // if gps is disabled
- final Intent poke = new Intent();
- poke.setClassName("com.android.settings",
- "com.android.settings.widget.SettingsAppWidgetProvider");
- poke.addCategory(Intent.CATEGORY_ALTERNATIVE);
- poke.setData(Uri.parse("3"));
- getActivity().sendBroadcast(poke);
- ToastLoadShout("Turning GPS on");
- }
- }
- private void getLocation() {
- // Get the location manager
- LocationManager locationManager = (LocationManager) getActivity()
- .getSystemService(getActivity().LOCATION_SERVICE);
- Criteria criteria = new Criteria();
- String bestProvider = locationManager.getBestProvider(criteria, false);
- Location location = locationManager.getLastKnownLocation(bestProvider);
- LocationListener loc_listener = new LocationListener() {
- public void onLocationChanged(Location l) {
- }
- public void onProviderEnabled(String p) {
- }
- public void onProviderDisabled(String p) {
- }
- public void onStatusChanged(String p, int status, Bundle extras) {
- }
- };
- locationManager
- .requestLocationUpdates(bestProvider, 0, 0, loc_listener);
- location = locationManager.getLastKnownLocation(bestProvider);
- try {
- lat = location.getLatitude();
- lon = location.getLongitude();
- } catch (NullPointerException e) {
- // lat = 0;
- // lon = 0;
- }
- }
- public void ReNewCoordinates() {
- LocationManager locationManager = (LocationManager) getActivity()
- .getSystemService(Context.LOCATION_SERVICE);
- // Define a listener that responds to location updates
- LocationListener locationListener = new LocationListener() {
- public void onLocationChanged(Location location) {
- // Called when a new location is found by the network location
- // provider.
- lat = (location.getLatitude());
- lon = (location.getLongitude());
- }
- public void onProviderDisabled(String provider) {
- }
- public void onProviderEnabled(String provider) {
- }
- public void onStatusChanged(String provider, int status,
- Bundle extras) {
- }
- };
- locationManager.requestLocationUpdates(
- LocationManager.NETWORK_PROVIDER, 0, 0, locationListener);
- }
- private class ImageDownloader extends AsyncTask<String, String, Bitmap> {
- protected void onPreExecute(String res) {
- Log.i("Async-Example", "onPreExecute Called");
- }
- protected Bitmap doInBackground(String... param) {
- // TODO Auto-generated method stub
- return downloadBitmap(param[0]);
- }
- protected void onPostExecute(Bitmap result) {
- Log.i("Async-Example", "onPostExecute Called");
- view.setImageBitmap(result);
- Loadimg.setVisibility(View.INVISIBLE);
- }
- private Bitmap downloadBitmap(String url) {
- // initilize the default HTTP client object
- final DefaultHttpClient client = new DefaultHttpClient();
- // forming a HttoGet request
- final HttpGet getRequest = new HttpGet(url);
- try {
- HttpResponse response = client.execute(getRequest);
- // check 200 OK for success
- final int statusCode = response.getStatusLine().getStatusCode();
- if (statusCode != HttpStatus.SC_OK) {
- Log.w("ImageDownloader", "Error " + statusCode
- + " while retrieving bitmap from " + url);
- return null;
- }
- final HttpEntity entity = response.getEntity();
- if (entity != null) {
- InputStream inputStream = null;
- try {
- // getting contents from the stream
- inputStream = entity.getContent();
- // decoding stream data back into image Bitmap that
- // android understands
- final Bitmap bitmap = BitmapFactory
- .decodeStream(inputStream);
- return bitmap;
- } finally {
- if (inputStream != null) {
- inputStream.close();
- }
- entity.consumeContent();
- }
- }
- } catch (Exception e) {
- // You Could provide a more explicit error message for
- // IOException
- getRequest.abort();
- Log.e("ImageDownloader", "Something went wrong while"
- + " retrieving bitmap from " + url + e.toString());
- }
- return null;
- }
- }
- // class LoadAddress extends AsyncTask<String, Integer, Boolean>
- // {
- // @Override
- // protected void onPreExecute() {
- //
- // }
- // @Override
- // protected Boolean doInBackground(String... params) {
- //
- // try {
- // addrString = GetAddress(itemLat+"",itemLon+"");
- // if (addrString!="")
- // return true;
- // } catch (Exception e) {
- // e.printStackTrace();
- // return false;
- // }
- // return false;
- // }
- // @Override
- // protected void onPostExecute(Boolean res) {
- // // TODO Auto-generated method stub
- // if (res){
- // addr.setText(addrString);
- // }
- // else
- // addr.setText("Unable to fetch address.");
- // }
- // }
- public String GetAddress(String lat, String lon) {
- Geocoder geocoder = new Geocoder(getActivity(), Locale.ENGLISH);
- String ret = "";
- try {
- List<Address> addresses = geocoder.getFromLocation(
- Double.parseDouble(lat), Double.parseDouble(lon), 1);
- if (addresses != null) {
- Address returnedAddress = addresses.get(0);
- StringBuilder strReturnedAddress = new StringBuilder("");
- for (int i = 0; i < returnedAddress.getMaxAddressLineIndex(); i++) {
- strReturnedAddress
- .append(returnedAddress.getAddressLine(i)).append(
- "\n");
- }
- ret = strReturnedAddress.toString();
- ret = ret.substring(0, ret.length() - 1);
- } else {
- ret = "Unknown Address";
- }
- } catch (IOException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- ret = "Couldn't get Address";
- }
- return ret;
- }
- public void onBackPressed() {
- if (itemView.getVisibility() == View.VISIBLE) {
- itemView.setVisibility(View.INVISIBLE);
- closeItemView.setVisibility(View.INVISIBLE);
- line3.setVisibility(View.INVISIBLE);
- ImageDownloader loadimg = new ImageDownloader();
- if (loadimg.getStatus() == AsyncTask.Status.RUNNING) {
- loadimg.cancel(true);
- }
- } else {
- getActivity().finish();
- }
- }
- // <!!!!--------------------------------Adding To
- // database----------------------------------------!!!!>
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement