1
0

Add map (OSM)

This commit is contained in:
dump_stack() 2020-02-23 20:24:57 +00:00
parent 7f4b833496
commit b5abd01dd2
4 changed files with 35 additions and 11 deletions

View File

@ -23,6 +23,7 @@ dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar']) implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'androidx.appcompat:appcompat:1.0.2' implementation 'androidx.appcompat:appcompat:1.0.2'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3' implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
implementation 'org.osmdroid:osmdroid-android:6.1.5'
testImplementation 'junit:junit:4.12' testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test.ext:junit:1.1.0' androidTestImplementation 'androidx.test.ext:junit:1.1.0'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.1' androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.1'

View File

@ -24,4 +24,8 @@
</activity> </activity>
</application> </application>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
</manifest> </manifest>

View File

@ -2,20 +2,34 @@ package io.dumpstack.minimap;
import androidx.appcompat.app.AppCompatActivity; import androidx.appcompat.app.AppCompatActivity;
import android.content.Context;
import android.os.Bundle; import android.os.Bundle;
import android.preference.PreferenceManager;
import android.view.GestureDetector; import android.view.GestureDetector;
import android.view.MotionEvent; import android.view.MotionEvent;
import android.view.View; import android.view.View;
import org.osmdroid.config.Configuration;
import org.osmdroid.tileprovider.tilesource.TileSourceFactory;
import org.osmdroid.views.MapView;
public class MainActivity extends AppCompatActivity implements GestureDetector.OnGestureListener { public class MainActivity extends AppCompatActivity implements GestureDetector.OnGestureListener {
GestureDetector gestureDetector; private GestureDetector gestureDetector;
private MapView map;
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
Context ctx = getApplicationContext();
Configuration.getInstance().load(ctx, PreferenceManager.getDefaultSharedPreferences(ctx));
setContentView(R.layout.activity_main); setContentView(R.layout.activity_main);
map = findViewById(R.id.map);
map.setTileSource(TileSourceFactory.MAPNIK);
if (getSupportActionBar() != null) { if (getSupportActionBar() != null) {
getSupportActionBar().hide(); getSupportActionBar().hide();
} }
@ -26,6 +40,16 @@ public class MainActivity extends AppCompatActivity implements GestureDetector.O
this.gestureDetector = new GestureDetector(this, this); this.gestureDetector = new GestureDetector(this, this);
} }
public void onResume(){
super.onResume();
map.onResume();
}
public void onPause(){
super.onPause();
map.onPause();
}
@Override @Override
public boolean dispatchTouchEvent(MotionEvent ev) { public boolean dispatchTouchEvent(MotionEvent ev) {
if (gestureDetector.onTouchEvent(ev)) { if (gestureDetector.onTouchEvent(ev)) {

View File

@ -1,18 +1,13 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools" xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
tools:context=".MainActivity"> tools:context=".MainActivity">
<TextView <org.osmdroid.views.MapView android:id="@+id/map"
android:layout_width="wrap_content" android:layout_width="fill_parent"
android:layout_height="wrap_content" android:layout_height="fill_parent" />
android:text="Hello World!"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout> </LinearLayout>