[android] #5888 - handle location permissions for non User Location category features
[android] #5888 - setZMediaOverlay on overlain SurfaceView
This commit is contained in:
@@ -6,7 +6,6 @@ import android.content.Intent;
|
||||
import android.content.pm.ActivityInfo;
|
||||
import android.content.pm.PackageInfo;
|
||||
import android.content.pm.PackageManager;
|
||||
|
||||
import android.content.res.Resources;
|
||||
import android.os.AsyncTask;
|
||||
import android.os.Bundle;
|
||||
@@ -66,14 +65,11 @@ public class FeatureOverviewActivity extends AppCompatActivity {
|
||||
@Override
|
||||
public void onItemClicked(RecyclerView recyclerView, int position, View v) {
|
||||
if (!sectionAdapter.isSectionHeaderPosition(position)) {
|
||||
int realPosition = sectionAdapter.getConvertedPosition(position);
|
||||
Feature feature = features.get(realPosition);
|
||||
if (feature.getCategory().equals(getString(R.string.category_userlocation))) {
|
||||
if ((ContextCompat.checkSelfPermission(FeatureOverviewActivity.this, Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) ||
|
||||
(ContextCompat.checkSelfPermission(FeatureOverviewActivity.this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED)) {
|
||||
ActivityCompat.requestPermissions(FeatureOverviewActivity.this, new String[]{Manifest.permission.ACCESS_COARSE_LOCATION, Manifest.permission.ACCESS_FINE_LOCATION}, realPosition);
|
||||
return;
|
||||
}
|
||||
int itemPosition = sectionAdapter.getConvertedPosition(position);
|
||||
Feature feature = features.get(itemPosition);
|
||||
if (feature.isRequiresLocationPermission()) {
|
||||
requestLocationPermission(itemPosition);
|
||||
return;
|
||||
}
|
||||
startFeature(feature);
|
||||
}
|
||||
@@ -115,22 +111,28 @@ public class FeatureOverviewActivity extends AppCompatActivity {
|
||||
recyclerView.setAdapter(sectionAdapter);
|
||||
}
|
||||
|
||||
private void startFeature(Feature feature) {
|
||||
Intent intent = new Intent();
|
||||
intent.setComponent(new ComponentName(getPackageName(), feature.getName()));
|
||||
startActivity(intent);
|
||||
}
|
||||
|
||||
private void requestLocationPermission(final int positionInList) {
|
||||
if ((ContextCompat.checkSelfPermission(FeatureOverviewActivity.this, Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) ||
|
||||
(ContextCompat.checkSelfPermission(FeatureOverviewActivity.this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED)) {
|
||||
ActivityCompat.requestPermissions(FeatureOverviewActivity.this, new String[]{Manifest.permission.ACCESS_COARSE_LOCATION, Manifest.permission.ACCESS_FINE_LOCATION}, positionInList);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onRequestPermissionsResult(int requestCode, @NonNull String permissions[], @NonNull int[] grantResults) {
|
||||
if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
|
||||
startFeature(features.get(requestCode));
|
||||
} else {
|
||||
Snackbar.make(findViewById(android.R.id.content), "Can't open without the location permission.", Snackbar.LENGTH_SHORT).show();
|
||||
Snackbar.make(findViewById(android.R.id.content), "Can't open without accepting the location permission.", Snackbar.LENGTH_SHORT).show();
|
||||
}
|
||||
}
|
||||
|
||||
private void startFeature(Feature feature) {
|
||||
Intent intent = new Intent();
|
||||
intent.setComponent(new ComponentName(getPackageName(), feature.getName()));
|
||||
startActivity(intent);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onSaveInstanceState(Bundle outState) {
|
||||
super.onSaveInstanceState(outState);
|
||||
@@ -151,7 +153,8 @@ public class FeatureOverviewActivity extends AppCompatActivity {
|
||||
String label = getString(info.labelRes);
|
||||
String description = resolveString(info.descriptionRes);
|
||||
String category = resolveMetaData(info.metaData, metaDataKey);
|
||||
features.add(new Feature(info.name, label, description, category));
|
||||
boolean requiresLocationPermission = requiresLocationPermission(label, category);
|
||||
features.add(new Feature(info.name, label, description, category, requiresLocationPermission));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -159,7 +162,11 @@ public class FeatureOverviewActivity extends AppCompatActivity {
|
||||
Comparator<Feature> comparator = new Comparator<Feature>() {
|
||||
@Override
|
||||
public int compare(Feature lhs, Feature rhs) {
|
||||
return lhs.getCategory().compareToIgnoreCase(rhs.getCategory());
|
||||
int result = lhs.getCategory().compareToIgnoreCase(rhs.getCategory());
|
||||
if (result == 0) {
|
||||
result = lhs.getLabel().compareToIgnoreCase(rhs.getLabel());
|
||||
}
|
||||
return result;
|
||||
}
|
||||
};
|
||||
Collections.sort(features, comparator);
|
||||
@@ -184,6 +191,25 @@ public class FeatureOverviewActivity extends AppCompatActivity {
|
||||
}
|
||||
}
|
||||
|
||||
private boolean requiresLocationPermission(String name, String category) {
|
||||
final Resources resources = getResources();
|
||||
|
||||
List<String> requiresPermissionCategories = new ArrayList<String>() {
|
||||
{
|
||||
add(resources.getString(R.string.category_userlocation));
|
||||
}
|
||||
};
|
||||
|
||||
List<String> requiresPermissionActvities = new ArrayList<String>() {
|
||||
{
|
||||
add(resources.getString(R.string.activity_double_map));
|
||||
add(getString(R.string.activity_location_picker));
|
||||
}
|
||||
};
|
||||
|
||||
return requiresPermissionCategories.contains(category) || requiresPermissionActvities.contains(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPostExecute(List<Feature> features) {
|
||||
super.onPostExecute(features);
|
||||
|
||||
@@ -10,6 +10,7 @@ import android.support.v7.app.AppCompatActivity;
|
||||
import android.support.v7.widget.Toolbar;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.MenuItem;
|
||||
import android.view.SurfaceView;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
|
||||
@@ -117,6 +118,9 @@ public class DoubleMapActivity extends AppCompatActivity {
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
SurfaceView surfaceViewMini = (SurfaceView) mMapViewMini.findViewById(R.id.surfaceView);
|
||||
surfaceViewMini.setZOrderMediaOverlay(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -3,18 +3,20 @@ package com.mapbox.mapboxsdk.testapp.model.activity;
|
||||
import android.os.Parcel;
|
||||
import android.os.Parcelable;
|
||||
|
||||
public class Feature implements Parcelable{
|
||||
public class Feature implements Parcelable {
|
||||
|
||||
private String name;
|
||||
private String label;
|
||||
private String description;
|
||||
private String category;
|
||||
private boolean requiresLocationPermission;
|
||||
|
||||
public Feature(String name, String label, String description, String category) {
|
||||
public Feature(String name, String label, String description, String category, boolean requiresLocationPermission) {
|
||||
this.name = name;
|
||||
this.label = label;
|
||||
this.description = description;
|
||||
this.category = category;
|
||||
this.requiresLocationPermission = requiresLocationPermission;
|
||||
}
|
||||
|
||||
private Feature(Parcel in) {
|
||||
@@ -22,6 +24,7 @@ public class Feature implements Parcelable{
|
||||
label = in.readString();
|
||||
description = in.readString();
|
||||
category = in.readString();
|
||||
requiresLocationPermission = in.readByte() != 0;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
@@ -45,6 +48,10 @@ public class Feature implements Parcelable{
|
||||
return category;
|
||||
}
|
||||
|
||||
public boolean isRequiresLocationPermission() {
|
||||
return requiresLocationPermission;
|
||||
}
|
||||
|
||||
public int describeContents() {
|
||||
return 0;
|
||||
}
|
||||
@@ -54,6 +61,7 @@ public class Feature implements Parcelable{
|
||||
out.writeString(label);
|
||||
out.writeString(description);
|
||||
out.writeString(category);
|
||||
out.writeByte((byte) (requiresLocationPermission ? 1 : 0));
|
||||
}
|
||||
|
||||
public static final Parcelable.Creator<Feature> CREATOR
|
||||
|
||||
Reference in New Issue
Block a user