Merge remote-tracking branch 'origin/master'
This commit is contained in:
commit
a8d3f9c19d
2 changed files with 36 additions and 7 deletions
|
@ -1,13 +1,17 @@
|
|||
package net.osmand.core.samples.android.sample1;
|
||||
|
||||
import android.Manifest;
|
||||
import android.annotation.SuppressLint;
|
||||
import android.app.Activity;
|
||||
import android.content.SharedPreferences;
|
||||
import android.content.SharedPreferences.Editor;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.graphics.PointF;
|
||||
import android.os.AsyncTask;
|
||||
import android.os.Bundle;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.v4.app.ActivityCompat;
|
||||
import android.support.v4.content.ContextCompat;
|
||||
import android.support.v4.view.ViewCompat;
|
||||
import android.support.v4.view.ViewPropertyAnimatorListener;
|
||||
import android.text.Editable;
|
||||
|
@ -137,6 +141,15 @@ public class MainActivity extends Activity {
|
|||
LANGUAGE = langCode;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) {
|
||||
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
|
||||
if(requestCode == SampleApplication.PERMISSIONS_REQUEST_WRITE_EXTERNAL_STORAGE &&
|
||||
grantResults[0] == PackageManager.PERMISSION_GRANTED) {
|
||||
getSampleApplication().initPoiTypes();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
@ -149,6 +162,13 @@ public class MainActivity extends Activity {
|
|||
// Inflate views
|
||||
setContentView(R.layout.activity_main);
|
||||
|
||||
if(ContextCompat.checkSelfPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE)
|
||||
!= PackageManager.PERMISSION_GRANTED) {
|
||||
ActivityCompat.requestPermissions(this,
|
||||
new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE},
|
||||
SampleApplication.PERMISSIONS_REQUEST_WRITE_EXTERNAL_STORAGE);
|
||||
}
|
||||
|
||||
// Get map view
|
||||
mapView = (AtlasMapRendererView) findViewById(R.id.mapRendererView);
|
||||
|
||||
|
@ -643,8 +663,8 @@ public class MainActivity extends Activity {
|
|||
public void onLongPress(MotionEvent e) {
|
||||
PointI point31 = new PointI();
|
||||
mapView.getLocationFromScreenPoint(new PointI((int) e.getX(), (int) e.getY()), point31);
|
||||
geocode(point31);
|
||||
Toast.makeText(MainActivity.this, "Geocoding...", Toast.LENGTH_SHORT).show();
|
||||
// geocode(point31);
|
||||
//Toast.makeText(MainActivity.this, "Geocoding...", Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -1,9 +1,13 @@
|
|||
package net.osmand.core.samples.android.sample1;
|
||||
|
||||
import android.Manifest;
|
||||
import android.app.Application;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.os.Environment;
|
||||
import android.os.Handler;
|
||||
import android.os.Message;
|
||||
import android.support.v4.app.ActivityCompat;
|
||||
import android.support.v4.content.ContextCompat;
|
||||
|
||||
import net.osmand.core.android.CoreResourcesFromAndroidAssets;
|
||||
import net.osmand.core.android.NativeCore;
|
||||
|
@ -15,8 +19,8 @@ import net.osmand.osm.MapPoiTypes;
|
|||
import java.io.File;
|
||||
import java.lang.reflect.Field;
|
||||
|
||||
public class SampleApplication extends Application
|
||||
{
|
||||
public class SampleApplication extends Application {
|
||||
public static final int PERMISSIONS_REQUEST_WRITE_EXTERNAL_STORAGE = 5 ;
|
||||
private CoreResourcesFromAndroidAssets assetsCustom;
|
||||
private MapPoiTypes poiTypes;
|
||||
private IconsCache iconsCache;
|
||||
|
@ -27,8 +31,13 @@ public class SampleApplication extends Application
|
|||
{
|
||||
super.onCreate();
|
||||
uiHandler = new Handler();
|
||||
|
||||
poiTypes = MapPoiTypes.getDefaultNoInit();
|
||||
if(ContextCompat.checkSelfPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE)
|
||||
== PackageManager.PERMISSION_GRANTED) {
|
||||
initPoiTypes();
|
||||
}
|
||||
|
||||
|
||||
|
||||
// Initialize native core
|
||||
if (NativeCore.isAvailable() && !NativeCore.isLoaded()) {
|
||||
|
@ -48,8 +57,8 @@ public class SampleApplication extends Application
|
|||
return iconsCache;
|
||||
}
|
||||
|
||||
private void initPoiTypes() {
|
||||
poiTypes = MapPoiTypes.getDefaultNoInit();
|
||||
public void initPoiTypes() {
|
||||
|
||||
poiTypes.init(Environment.getExternalStorageDirectory() + "/osmand/poi_types.xml");
|
||||
poiTypes.setPoiTranslator(new MapPoiTypes.PoiTranslator() {
|
||||
|
||||
|
|
Loading…
Reference in a new issue