aboutsummaryrefslogtreecommitdiffstats
path: root/src/main/java/de/pixart
diff options
context:
space:
mode:
authorChristian Schneppe <christian@pix-art.de>2016-09-17 22:43:24 +0200
committerChristian Schneppe <christian@pix-art.de>2016-09-17 22:43:24 +0200
commit1c38d17fef7c1d5481a40162999e9f30349fa48f (patch)
tree3969c79c839aea464bde3b5423956a4cce79389c /src/main/java/de/pixart
parentbaf43ba41ad2e8382cc294153ebce37b0f6a5f97 (diff)
some more changes to location activities
* show actionbar home as up * fix permission issue on devices < Android M * show buildings in map
Diffstat (limited to 'src/main/java/de/pixart')
-rw-r--r--src/main/java/de/pixart/messenger/ui/ShareLocationActivity.java195
-rw-r--r--src/main/java/de/pixart/messenger/ui/ShowLocationActivity.java13
2 files changed, 117 insertions, 91 deletions
diff --git a/src/main/java/de/pixart/messenger/ui/ShareLocationActivity.java b/src/main/java/de/pixart/messenger/ui/ShareLocationActivity.java
index d20981ac3..03258712e 100644
--- a/src/main/java/de/pixart/messenger/ui/ShareLocationActivity.java
+++ b/src/main/java/de/pixart/messenger/ui/ShareLocationActivity.java
@@ -1,9 +1,11 @@
package de.pixart.messenger.ui;
+import android.Manifest;
import android.annotation.TargetApi;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
+import android.content.pm.PackageManager;
import android.location.Address;
import android.location.Geocoder;
import android.location.Location;
@@ -11,6 +13,7 @@ import android.os.AsyncTask;
import android.os.Build;
import android.os.Bundle;
import android.provider.Settings;
+import android.support.v4.app.ActivityCompat;
import android.text.TextUtils;
import android.util.Log;
import android.view.View;
@@ -37,106 +40,126 @@ import de.pixart.messenger.Config;
import de.pixart.messenger.R;
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;
+ 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;
private RelativeLayout mLocationInfo;
private TextView mSnackbarLocation;
private TextView mSnackbarAction;
- @Override
- public void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_share_locaction);
- 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);
+ @Override
+ public void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ if (getActionBar() != null) {
+ getActionBar().setHomeButtonEnabled(true);
+ getActionBar().setDisplayHomeAsUpEnabled(true);
+ }
+ setContentView(R.layout.activity_share_locaction);
+ 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);
mLocationInfo = (RelativeLayout) findViewById(R.id.snackbar_location);
mSnackbarLocation = (TextView) findViewById(R.id.snackbar_location_message);
- mSnackbarAction = (TextView) findViewById(R.id.snackbar_action);
- mSnackbarAction.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View view) {
- startActivity(new Intent(android.provider.Settings.ACTION_LOCATION_SOURCE_SETTINGS));
- }
- });
- }
+ mSnackbarAction = (TextView) findViewById(R.id.snackbar_action);
+ mSnackbarAction.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 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
+ protected void onPause() {
+ mGoogleApiClient.disconnect();
+ super.onPause();
+ }
- @Override
- public void onMapReady(GoogleMap googleMap) {
- this.mGoogleMap = googleMap;
- this.mGoogleMap.setMyLocationEnabled(true);
- }
+ @Override
+ public void onMapReady(GoogleMap googleMap) {
+ this.mGoogleMap = googleMap;
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
+ if (checkSelfPermission(Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED
+ || checkSelfPermission(Manifest.permission.ACCESS_COARSE_LOCATION) == PackageManager.PERMISSION_GRANTED) {
+ this.mGoogleMap.setBuildingsEnabled(true);
+ this.mGoogleMap.setMyLocationEnabled(true);
+ }
+ } else {
+ this.mGoogleMap.setBuildingsEnabled(true);
+ this.mGoogleMap.setMyLocationEnabled(true);
+ }
+ }
- private void centerOnLocation(LatLng location) {
- this.mGoogleMap.animateCamera(CameraUpdateFactory.newLatLngZoom(location, Config.DEFAULT_ZOOM));
- }
+ private void centerOnLocation(LatLng location) {
+ this.mGoogleMap.animateCamera(CameraUpdateFactory.newLatLngZoom(location, Config.DEFAULT_ZOOM));
+ }
- @Override
- public void onConnected(Bundle bundle) {
- mLocationRequest = LocationRequest.create();
+ @Override
+ public void onConnected(Bundle bundle) {
+ mLocationRequest = LocationRequest.create();
mLocationRequest.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY);
mLocationRequest.setInterval(1000);
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
+ if (checkSelfPermission(Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED
+ || checkSelfPermission(Manifest.permission.ACCESS_COARSE_LOCATION) == PackageManager.PERMISSION_GRANTED) {
+ LocationServices.FusedLocationApi.requestLocationUpdates(mGoogleApiClient, mLocationRequest, this);
+ }
+ } else {
+ LocationServices.FusedLocationApi.requestLocationUpdates(mGoogleApiClient, mLocationRequest, this);
+ }
- LocationServices.FusedLocationApi.requestLocationUpdates(mGoogleApiClient, mLocationRequest, this);
- }
+ }
@Override
public void onConnectionSuspended(int i) {
diff --git a/src/main/java/de/pixart/messenger/ui/ShowLocationActivity.java b/src/main/java/de/pixart/messenger/ui/ShowLocationActivity.java
index 643cd6211..d9b71a8da 100644
--- a/src/main/java/de/pixart/messenger/ui/ShowLocationActivity.java
+++ b/src/main/java/de/pixart/messenger/ui/ShowLocationActivity.java
@@ -11,7 +11,6 @@ import android.location.Geocoder;
import android.os.AsyncTask;
import android.os.Build;
import android.os.Bundle;
-import android.util.Log;
import android.view.MenuItem;
import android.view.View;
import android.widget.TextView;
@@ -66,10 +65,10 @@ public class ShowLocationActivity extends Activity implements OnMapReadyCallback
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
- ActionBar actionBar = getActionBar();
- if (actionBar != null) {
- actionBar.setDisplayHomeAsUpEnabled(true);
- }
+ if (getActionBar() != null) {
+ getActionBar().setHomeButtonEnabled(true);
+ getActionBar().setDisplayHomeAsUpEnabled(true);
+ }
setContentView(R.layout.activity_show_locaction);
MapFragment fragment = (MapFragment) getFragmentManager().findFragmentById(R.id.map_fragment);
@@ -114,8 +113,12 @@ public class ShowLocationActivity extends Activity implements OnMapReadyCallback
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
if (checkSelfPermission(Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED
|| checkSelfPermission(Manifest.permission.ACCESS_COARSE_LOCATION) == PackageManager.PERMISSION_GRANTED) {
+ this.mGoogleMap.setBuildingsEnabled(true);
this.mGoogleMap.setMyLocationEnabled(true);
}
+ } else {
+ this.mGoogleMap.setBuildingsEnabled(true);
+ this.mGoogleMap.setMyLocationEnabled(true);
}
if (this.mLocation != null) {
this.markAndCenterOnLocation(this.mLocation,this.mLocationName);