aboutsummaryrefslogtreecommitdiffstats
path: root/src/main
diff options
context:
space:
mode:
authorChristian Schneppe <christian@pix-art.de>2016-05-14 13:59:08 +0200
committerChristian Schneppe <christian@pix-art.de>2016-05-14 13:59:08 +0200
commit4fbbd10c6478687be081c220b9fbc194721b2b31 (patch)
tree6d606891165e23c47586264cfa13d896ad52cfba /src/main
parente7736881ee770c2e5c0fb774ebbb31efc60ecbe0 (diff)
show addresses in ShareLocation and ShowLocation
Diffstat (limited to 'src/main')
-rw-r--r--src/main/java/eu/siacs/conversations/ui/ShareLocationActivity.java32
-rw-r--r--src/main/java/eu/siacs/conversations/ui/ShowLocationActivity.java73
-rw-r--r--src/main/res/layout/share_locaction_activity.xml25
-rw-r--r--src/main/res/layout/show_location_infowindow.xml25
4 files changed, 142 insertions, 13 deletions
diff --git a/src/main/java/eu/siacs/conversations/ui/ShareLocationActivity.java b/src/main/java/eu/siacs/conversations/ui/ShareLocationActivity.java
index f532ab38c..cd1f8fca2 100644
--- a/src/main/java/eu/siacs/conversations/ui/ShareLocationActivity.java
+++ b/src/main/java/eu/siacs/conversations/ui/ShareLocationActivity.java
@@ -3,6 +3,8 @@ package eu.siacs.conversations.ui;
import android.annotation.TargetApi;
import android.app.Activity;
import android.content.Intent;
+import android.location.Address;
+import android.location.Geocoder;
import android.location.Location;
import android.os.Build;
import android.os.Bundle;
@@ -27,6 +29,9 @@ import com.google.android.gms.maps.MapFragment;
import com.google.android.gms.maps.OnMapReadyCallback;
import com.google.android.gms.maps.model.LatLng;
+import java.util.List;
+import java.util.Locale;
+
public class ShareLocationActivity extends Activity implements OnMapReadyCallback,
GoogleApiClient.ConnectionCallbacks,
GoogleApiClient.OnConnectionFailedListener,
@@ -39,6 +44,7 @@ public class ShareLocationActivity extends Activity implements OnMapReadyCallbac
private Button mCancelButton;
private Button mShareButton;
private RelativeLayout mSnackbar;
+ private RelativeLayout mLocationInfo;
@Override
protected void onCreate(Bundle savedInstanceState) {
@@ -136,11 +142,37 @@ public class ShareLocationActivity extends Activity implements OnMapReadyCallbac
@Override
public void onLocationChanged(Location location) {
+ double longitude = location.getLongitude();
+ double latitude = location.getLatitude();
+ if (latitude != 0 && longitude != 0) {
+ Geocoder geoCoder = new Geocoder(getBaseContext(), Locale.getDefault());
+ try {
+ List<Address> addresses = geoCoder.getFromLocation(latitude, longitude, 1);
+
+ String address = "";
+ if (addresses != null) {
+ Address Address = addresses.get(0);
+ StringBuilder strAddress = new StringBuilder("");
+
+ for (int i = 0; i < Address.getMaxAddressLineIndex(); i++) {
+ strAddress.append(Address.getAddressLine(i)).append("\n");
+ }
+ address = strAddress.toString();
+ address = address.substring(0, address.length()-1); //trim last \n
+ mLocationInfo = (RelativeLayout) findViewById(R.id.location);
+ TextView snackbarLocation = (TextView) findViewById(R.id.snackbar_message);
+ snackbarLocation.setText(address);
+ }
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
if (this.mLastLocation == null) {
centerOnLocation(new LatLng(location.getLatitude(), location.getLongitude()));
this.mShareButton.setEnabled(true);
this.mShareButton.setTextColor(0xde000000);
this.mShareButton.setText(R.string.share);
+ mLocationInfo.setVisibility(View.VISIBLE);
}
this.mLastLocation = location;
}
diff --git a/src/main/java/eu/siacs/conversations/ui/ShowLocationActivity.java b/src/main/java/eu/siacs/conversations/ui/ShowLocationActivity.java
index 79219a01c..d5103de9b 100644
--- a/src/main/java/eu/siacs/conversations/ui/ShowLocationActivity.java
+++ b/src/main/java/eu/siacs/conversations/ui/ShowLocationActivity.java
@@ -3,33 +3,58 @@ package eu.siacs.conversations.ui;
import android.app.ActionBar;
import android.app.Activity;
import android.content.Intent;
-import android.location.Location;
+import android.location.Address;
+import android.location.Geocoder;
import android.os.Bundle;
import android.view.MenuItem;
import android.view.View;
-import android.widget.Button;
+import android.widget.TextView;
import eu.siacs.conversations.Config;
import eu.siacs.conversations.R;
-import com.google.android.gms.common.ConnectionResult;
-import com.google.android.gms.common.api.GoogleApiClient;
-import com.google.android.gms.location.LocationListener;
-import com.google.android.gms.location.LocationRequest;
-import com.google.android.gms.location.LocationServices;
import com.google.android.gms.maps.CameraUpdateFactory;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.MapFragment;
import com.google.android.gms.maps.OnMapReadyCallback;
import com.google.android.gms.maps.model.LatLng;
+import com.google.android.gms.maps.model.Marker;
import com.google.android.gms.maps.model.MarkerOptions;
+import java.util.List;
+import java.util.Locale;
+
public class ShowLocationActivity extends Activity implements OnMapReadyCallback {
private GoogleMap mGoogleMap;
private LatLng mLocation;
private String mLocationName;
+ class InfoWindowAdapter implements GoogleMap.InfoWindowAdapter {
+
+ private final View InfoWindow;
+
+ InfoWindowAdapter() {
+ InfoWindow = getLayoutInflater().inflate(R.layout.show_location_infowindow, null);
+ }
+
+ @Override
+ public View getInfoWindow(Marker marker) {
+ return null;
+ }
+
+ @Override
+ public View getInfoContents(Marker marker) {
+
+ TextView Title = ((TextView) InfoWindow.findViewById(R.id.title));
+ Title.setText(marker.getTitle());
+ TextView Snippet = ((TextView) InfoWindow.findViewById(R.id.snippet));
+ Snippet.setText(marker.getSnippet());
+
+ return InfoWindow;
+ }
+ }
+
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
@@ -87,14 +112,36 @@ public class ShowLocationActivity extends Activity implements OnMapReadyCallback
private void markAndCenterOnLocation(LatLng location, String name) {
this.mGoogleMap.clear();
- MarkerOptions options = new MarkerOptions();
- options.position(location);
- if (name != null) {
+ MarkerOptions options = new MarkerOptions();
+ options.position(location);
+ double longitude = mLocation.longitude;
+ double latitude = mLocation.latitude;
+ if (latitude != 0 && longitude != 0) {
+ Geocoder geoCoder = new Geocoder(getBaseContext(), Locale.getDefault());
+ try {
+ List<Address> addresses = geoCoder.getFromLocation(latitude, longitude, 1);
+
+ String address = "";
+ if (addresses != null) {
+ Address Address = addresses.get(0);
+ StringBuilder strAddress = new StringBuilder("");
+
+ for (int i = 0; i < Address.getMaxAddressLineIndex(); i++) {
+ strAddress.append(Address.getAddressLine(i)).append("\n");
+ }
+ address = strAddress.toString();
+ address = address.substring(0, address.length()-1); //trim last \n
+ options.snippet(address);
+ }
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+ if (name != null) {
options.title(name);
- this.mGoogleMap.addMarker(options).showInfoWindow();
- } else {
- this.mGoogleMap.addMarker(options);
}
+ this.mGoogleMap.setInfoWindowAdapter(new InfoWindowAdapter());
+ this.mGoogleMap.addMarker(options).showInfoWindow();
this.mGoogleMap.animateCamera(CameraUpdateFactory.newLatLngZoom(location, Config.DEFAULT_ZOOM));
}
diff --git a/src/main/res/layout/share_locaction_activity.xml b/src/main/res/layout/share_locaction_activity.xml
index a52632666..131a51df2 100644
--- a/src/main/res/layout/share_locaction_activity.xml
+++ b/src/main/res/layout/share_locaction_activity.xml
@@ -62,6 +62,31 @@
android:layout_alignParentEnd="true"/>
</RelativeLayout>
+ <RelativeLayout
+ android:id="@+id/location"
+ android:layout_width="fill_parent"
+ android:layout_height="wrap_content"
+ android:layout_marginTop="4dp"
+ android:layout_marginBottom="4dp"
+ android:layout_marginLeft="8dp"
+ android:layout_marginRight="8dp"
+ android:layout_above="@+id/button_bar"
+ android:background="@drawable/snackbar"
+ android:minHeight="24dp"
+ android:visibility="gone" >
+
+ <TextView
+ android:id="@id/snackbar_message"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:layout_alignParentLeft="true"
+ android:paddingLeft="24dp"
+ android:textColor="@color/grey50"
+ android:textSize="?attr/TextSizeBody"
+ android:layout_centerVertical="true" />
+
+ </RelativeLayout>
+
<LinearLayout
android:id="@+id/button_bar"
android:layout_width="wrap_content"
diff --git a/src/main/res/layout/show_location_infowindow.xml b/src/main/res/layout/show_location_infowindow.xml
new file mode 100644
index 000000000..059fb20a8
--- /dev/null
+++ b/src/main/res/layout/show_location_infowindow.xml
@@ -0,0 +1,25 @@
+<?xml version="1.0" encoding="utf-8"?>
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:orientation="horizontal">
+
+ <LinearLayout
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:orientation="vertical">
+
+ <TextView
+ android:id="@+id/title"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:textSize="?attr/TextSizeBody"
+ android:textStyle="bold"/>
+ <TextView
+ android:id="@+id/snippet"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:textSize="?attr/TextSizeInfo"/>
+ </LinearLayout>
+
+</LinearLayout> \ No newline at end of file