aboutsummaryrefslogtreecommitdiffstats
path: root/src/main/java/eu/siacs/conversations
diff options
context:
space:
mode:
authorChristian S <christian@pix-art.de>2016-05-06 11:59:17 +0200
committerChristian S <christian@pix-art.de>2016-05-06 11:59:17 +0200
commitd56a6c3291073c81e60c77474983c0d837d27fb4 (patch)
tree21d18a074096a722b1cd146c811043b00e8e0f89 /src/main/java/eu/siacs/conversations
parent5d9f8c8361730d43ca4345897ae6c49e0156d4d3 (diff)
parent51b07efe2b7536259e93098b0d5e562de495087d (diff)
Merge remote-tracking branch 'refs/remotes/origin/share_location' into development
Diffstat (limited to 'src/main/java/eu/siacs/conversations')
-rw-r--r--src/main/java/eu/siacs/conversations/Config.java3
-rw-r--r--src/main/java/eu/siacs/conversations/ui/ShareLocationActivity.java171
-rw-r--r--src/main/java/eu/siacs/conversations/ui/ShowLocationActivity.java101
3 files changed, 274 insertions, 1 deletions
diff --git a/src/main/java/eu/siacs/conversations/Config.java b/src/main/java/eu/siacs/conversations/Config.java
index 810aab229..78067b905 100644
--- a/src/main/java/eu/siacs/conversations/Config.java
+++ b/src/main/java/eu/siacs/conversations/Config.java
@@ -6,7 +6,6 @@ import eu.siacs.conversations.xmpp.chatstate.ChatState;
public final class Config {
-
private static final int UNENCRYPTED = 1;
private static final int OPENPGP = 2;
private static final int OTR = 4;
@@ -75,6 +74,8 @@ public final class Config {
public static final int FILE_MAX_SIZE = 1048576; //1 MiB
+ public static final int DEFAULT_ZOOM = 15; //for locations
+
public static final int MESSAGE_MERGE_WINDOW = 20;
public static final int PAGE_SIZE = 20;
diff --git a/src/main/java/eu/siacs/conversations/ui/ShareLocationActivity.java b/src/main/java/eu/siacs/conversations/ui/ShareLocationActivity.java
new file mode 100644
index 000000000..f532ab38c
--- /dev/null
+++ b/src/main/java/eu/siacs/conversations/ui/ShareLocationActivity.java
@@ -0,0 +1,171 @@
+package eu.siacs.conversations.ui;
+
+import android.annotation.TargetApi;
+import android.app.Activity;
+import android.content.Intent;
+import android.location.Location;
+import android.os.Build;
+import android.os.Bundle;
+import android.provider.Settings;
+import android.text.TextUtils;
+import android.view.View;
+import android.widget.Button;
+import android.widget.RelativeLayout;
+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;
+
+public class ShareLocationActivity extends Activity implements OnMapReadyCallback,
+ GoogleApiClient.ConnectionCallbacks,
+ GoogleApiClient.OnConnectionFailedListener,
+ LocationListener{
+
+ private GoogleMap mGoogleMap;
+ private GoogleApiClient mGoogleApiClient;
+ private LocationRequest mLocationRequest;
+ private Location mLastLocation;
+ private Button mCancelButton;
+ private Button mShareButton;
+ private RelativeLayout mSnackbar;
+
+ @Override
+ protected void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ setContentView(R.layout.share_locaction_activity);
+ MapFragment fragment = (MapFragment) getFragmentManager().findFragmentById(R.id.map_fragment);
+ fragment.getMapAsync(this);
+ mGoogleApiClient = new GoogleApiClient.Builder(this)
+ .addApi(LocationServices.API)
+ .addConnectionCallbacks(this)
+ .addOnConnectionFailedListener(this)
+ .build();
+ mCancelButton = (Button) findViewById(R.id.cancel_button);
+ mCancelButton.setOnClickListener(new View.OnClickListener() {
+ @Override
+ public void onClick(View view) {
+ setResult(RESULT_CANCELED);
+ finish();
+ }
+ });
+ mShareButton = (Button) findViewById(R.id.share_button);
+ mShareButton.setOnClickListener(new View.OnClickListener() {
+ @Override
+ public void onClick(View view) {
+ if (mLastLocation != null) {
+ Intent result = new Intent();
+ result.putExtra("latitude",mLastLocation.getLatitude());
+ result.putExtra("longitude",mLastLocation.getLongitude());
+ result.putExtra("altitude",mLastLocation.getAltitude());
+ result.putExtra("accuracy",(int) mLastLocation.getAccuracy());
+ setResult(RESULT_OK, result);
+ finish();
+ }
+ }
+ });
+ mSnackbar = (RelativeLayout) findViewById(R.id.snackbar);
+ TextView snackbarAction = (TextView) findViewById(R.id.snackbar_action);
+ snackbarAction.setOnClickListener(new View.OnClickListener() {
+ @Override
+ public void onClick(View view) {
+ startActivity(new Intent(android.provider.Settings.ACTION_LOCATION_SOURCE_SETTINGS));
+ }
+ });
+ }
+
+ @Override
+ protected void onResume() {
+ super.onResume();
+ this.mLastLocation = null;
+ if (isLocationEnabled()) {
+ this.mSnackbar.setVisibility(View.GONE);
+ } else {
+ this.mSnackbar.setVisibility(View.VISIBLE);
+ }
+ mShareButton.setEnabled(false);
+ mShareButton.setTextColor(0x8a000000);
+ mShareButton.setText(R.string.locating);
+ mGoogleApiClient.connect();
+ }
+
+ @Override
+ protected void onPause() {
+ mGoogleApiClient.disconnect();
+ super.onPause();
+ }
+
+ @Override
+ public void onMapReady(GoogleMap googleMap) {
+ this.mGoogleMap = googleMap;
+ this.mGoogleMap.setMyLocationEnabled(true);
+ }
+
+ private void centerOnLocation(LatLng location) {
+ this.mGoogleMap.animateCamera(CameraUpdateFactory.newLatLngZoom(location, Config.DEFAULT_ZOOM));
+ }
+
+ @Override
+ public void onConnected(Bundle bundle) {
+ mLocationRequest = LocationRequest.create();
+ mLocationRequest.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY);
+ mLocationRequest.setInterval(1000);
+
+ LocationServices.FusedLocationApi.requestLocationUpdates(mGoogleApiClient, mLocationRequest, this);
+ }
+
+ @Override
+ public void onConnectionSuspended(int i) {
+
+ }
+
+ @Override
+ public void onConnectionFailed(ConnectionResult connectionResult) {
+
+ }
+
+ @Override
+ public void onLocationChanged(Location location) {
+ 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);
+ }
+ this.mLastLocation = location;
+ }
+
+ @TargetApi(Build.VERSION_CODES.KITKAT)
+ private boolean isLocationEnabledKitkat() {
+ try {
+ int locationMode = Settings.Secure.getInt(getContentResolver(), Settings.Secure.LOCATION_MODE);
+ return locationMode != Settings.Secure.LOCATION_MODE_OFF;
+ } catch (Settings.SettingNotFoundException e) {
+ return false;
+ }
+ }
+
+ @SuppressWarnings("deprecation")
+ private boolean isLocationEnabledLegacy() {
+ String locationProviders = Settings.Secure.getString(getContentResolver(), Settings.Secure.LOCATION_PROVIDERS_ALLOWED);
+ return !TextUtils.isEmpty(locationProviders);
+ }
+
+ private boolean isLocationEnabled() {
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT){
+ return isLocationEnabledKitkat();
+ }else{
+ return isLocationEnabledLegacy();
+ }
+ }
+}
diff --git a/src/main/java/eu/siacs/conversations/ui/ShowLocationActivity.java b/src/main/java/eu/siacs/conversations/ui/ShowLocationActivity.java
new file mode 100644
index 000000000..79219a01c
--- /dev/null
+++ b/src/main/java/eu/siacs/conversations/ui/ShowLocationActivity.java
@@ -0,0 +1,101 @@
+package eu.siacs.conversations.ui;
+
+import android.app.ActionBar;
+import android.app.Activity;
+import android.content.Intent;
+import android.location.Location;
+import android.os.Bundle;
+import android.view.MenuItem;
+import android.view.View;
+import android.widget.Button;
+
+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.MarkerOptions;
+
+public class ShowLocationActivity extends Activity implements OnMapReadyCallback {
+
+ private GoogleMap mGoogleMap;
+ private LatLng mLocation;
+ private String mLocationName;
+
+ @Override
+ protected void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+
+ ActionBar actionBar = getActionBar();
+ if (actionBar != null) {
+ actionBar.setDisplayHomeAsUpEnabled(true);
+ }
+
+ setContentView(R.layout.show_locaction_activity);
+ MapFragment fragment = (MapFragment) getFragmentManager().findFragmentById(R.id.map_fragment);
+ fragment.getMapAsync(this);
+ }
+
+ @Override
+ public boolean onOptionsItemSelected(MenuItem item) {
+ switch (item.getItemId()) {
+ case android.R.id.home:
+ finish();
+ return true;
+ }
+ return super.onOptionsItemSelected(item);
+ }
+
+ @Override
+ protected void onResume() {
+ super.onResume();
+ Intent intent = getIntent();
+
+ this.mLocationName = intent != null ? intent.getStringExtra("name") : null;
+
+ if (intent != null && intent.hasExtra("longitude") && intent.hasExtra("latitude")) {
+ double longitude = intent.getDoubleExtra("longitude",0);
+ double latitude = intent.getDoubleExtra("latitude",0);
+ this.mLocation = new LatLng(latitude,longitude);
+ if (this.mGoogleMap != null) {
+ markAndCenterOnLocation(this.mLocation, this.mLocationName);
+ }
+ }
+ }
+
+ @Override
+ protected void onPause() {
+ super.onPause();
+ }
+
+ @Override
+ public void onMapReady(GoogleMap googleMap) {
+ this.mGoogleMap = googleMap;
+ this.mGoogleMap.setMyLocationEnabled(true);
+ if (this.mLocation != null) {
+ this.markAndCenterOnLocation(this.mLocation,this.mLocationName);
+ }
+ }
+
+ private void markAndCenterOnLocation(LatLng location, String name) {
+ this.mGoogleMap.clear();
+ MarkerOptions options = new MarkerOptions();
+ options.position(location);
+ if (name != null) {
+ options.title(name);
+ this.mGoogleMap.addMarker(options).showInfoWindow();
+ } else {
+ this.mGoogleMap.addMarker(options);
+ }
+ this.mGoogleMap.animateCamera(CameraUpdateFactory.newLatLngZoom(location, Config.DEFAULT_ZOOM));
+ }
+
+}