Skip to content
Permalink
Browse files

Open Map: updates and cleanup (#1337)

* Remove version_code checks

version code is always > 11. I guess this was meant to be an API
check, which would also be obsolete by now.

* Fix typo in log file name

* Fix typo in method name

* Introduce consistent theming and generalize toolbar use

plus some minor cleanup and usage of appcompat in license view

* CacheAnalyzer: Switch to appcompat + minor layout tweaks

* Diagnostics: Switch to appcompat + minor layout tweaks

* StarterMap: use toolbar

* StarterMap: don't share mapview with activity

* StarterMap: remove samples from menu

starting the samples is handled in ExtraSamplesActivity

* Remove OpenStreetMapConstants

And get rid of handling of old preferences

* Update LeakCanary

Note that for LeakCanary to run during instrumentation tests, the
following has to be implemented:
https://github.com/square/leakcanary/wiki/Customizing-LeakCanary#running-leakcanary-in-instrumentation-tests

* Remove SampleExtensive

all features shown are already included in StarterMap

* Sample ItemizedOverlay: add toolbar and cleanup

* Remove SampleWithMinimapAndZoomcontrols

all features already in StarterMap

* Sample TileOverlay: add toolbar and cleanup

* Sample custom TileSource: add toolbar and cleanup
  • Loading branch information...
cbalster authored and spyhunter99 committed Sep 28, 2019
1 parent 4c96036 commit b7824d7212adc47f95eca692b5664cee774612a0
Showing with 485 additions and 757 deletions.
  1. +3 −3 OpenStreetMapViewer/build.gradle
  2. +1 −18 OpenStreetMapViewer/src/main/AndroidManifest.xml
  3. +10 −1 OpenStreetMapViewer/src/main/java/org/osmdroid/BugsTestingActivity.java
  4. +10 −1 OpenStreetMapViewer/src/main/java/org/osmdroid/ExtraSamplesActivity.java
  5. +17 −6 OpenStreetMapViewer/src/main/java/org/osmdroid/LicenseActivity.java
  6. +23 −45 OpenStreetMapViewer/src/main/java/org/osmdroid/MainActivity.java
  7. +5 −2 OpenStreetMapViewer/src/main/java/org/osmdroid/OsmApplication.java
  8. +10 −0 OpenStreetMapViewer/src/main/java/org/osmdroid/PreferenceActivity.java
  9. +22 −24 OpenStreetMapViewer/src/main/java/org/osmdroid/StarterMapActivity.java
  10. +25 −59 OpenStreetMapViewer/src/main/java/org/osmdroid/StarterMapFragment.java
  11. +0 −38 OpenStreetMapViewer/src/main/java/org/osmdroid/constants/OpenStreetMapConstants.java
  12. +17 −7 OpenStreetMapViewer/src/main/java/org/osmdroid/debug/CacheAnalyzerActivity.java
  13. +16 −3 OpenStreetMapViewer/src/main/java/org/osmdroid/debug/browser/CacheBrowserActivity.java
  14. +20 −12 OpenStreetMapViewer/src/main/java/org/osmdroid/diag/DiagnosticsActivity.java
  15. +1 −1 OpenStreetMapViewer/src/main/java/org/osmdroid/samplefragments/BaseSampleFragment.java
  16. +0 −198 OpenStreetMapViewer/src/main/java/org/osmdroid/samples/SampleExtensive.java
  17. +39 −63 OpenStreetMapViewer/src/main/java/org/osmdroid/samples/SampleWithMinimapItemizedoverlay.java
  18. +0 −89 OpenStreetMapViewer/src/main/java/org/osmdroid/samples/SampleWithMinimapZoomcontrols.java
  19. +38 −52 OpenStreetMapViewer/src/main/java/org/osmdroid/samples/SampleWithTilesOverlay.java
  20. +38 −35 ...StreetMapViewer/src/main/java/org/osmdroid/samples/SampleWithTilesOverlayAndCustomTileSource.java
  21. +30 −23 OpenStreetMapViewer/src/main/res/layout/activity_cache_analyzer.xml
  22. +25 −18 OpenStreetMapViewer/src/main/res/layout/activity_cache_browser.xml
  23. +10 −5 OpenStreetMapViewer/src/main/res/layout/activity_diag.xml
  24. +2 −6 OpenStreetMapViewer/src/main/res/layout/activity_extra_samples.xml
  25. +28 −18 OpenStreetMapViewer/src/main/res/layout/activity_license.xml
  26. +2 −6 OpenStreetMapViewer/src/main/res/layout/activity_main.xml
  27. +6 −9 OpenStreetMapViewer/src/main/res/layout/activity_prefs.xml
  28. +18 −0 OpenStreetMapViewer/src/main/res/layout/activity_samplewithminimapitemizedoverlay.xml
  29. +18 −0 OpenStreetMapViewer/src/main/res/layout/activity_samplewithtilesoverlay.xml
  30. +18 −0 OpenStreetMapViewer/src/main/res/layout/activity_samplewithtilesoverlayandcustomtilesource.xml
  31. +5 −0 OpenStreetMapViewer/src/main/res/layout/activity_starter_main.xml
  32. +11 −10 OpenStreetMapViewer/src/main/res/layout/item_cache.xml
  33. +15 −2 OpenStreetMapViewer/src/main/res/values/styles.xml
  34. +2 −3 osmdroid-android-it/src/main/java/org/osmdroid/views/OpenStreetMapViewTest.java
@@ -79,9 +79,9 @@ dependencies {
compile 'ch.acra:acra:4.7.0'

//memory leak testing
debugCompile 'com.squareup.leakcanary:leakcanary-android:1.4'
releaseCompile 'com.squareup.leakcanary:leakcanary-android-no-op:1.4'
testCompile 'com.squareup.leakcanary:leakcanary-android-no-op:1.4'
debugCompile 'com.squareup.leakcanary:leakcanary-android:1.6.3'
debugCompile 'com.squareup.leakcanary:leakcanary-support-fragment:1.6.3'
releaseCompile 'com.squareup.leakcanary:leakcanary-android-no-op:1.6.3'

//on device testing
androidTestCompile 'com.android.support.test:runner:0.4.+'
@@ -40,7 +40,7 @@
android:hardwareAccelerated="true"
android:largeHeap="true"
android:icon="@drawable/icon"
android:theme="@style/Theme.AppCompat.NoActionBar"
android:theme="@style/AppTheme"
android:networkSecurityConfig="@xml/network_security_config"
android:label="@string/app_name">

@@ -145,24 +145,7 @@
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity
android:name=".samples.SampleExtensive"
android:label="OSMapView with UI Tools">
<intent-filter>
<action android:name="android.intent.action.VIEW" />

<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity
android:name=".samples.SampleWithMinimapZoomcontrols"
android:label="OSMapView with MiniMap &amp; Zoom">
<intent-filter>
<action android:name="android.intent.action.VIEW" />

<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity
android:name=".samples.SampleWithTilesOverlay"
android:label="OSMapView with Tiles Overlay">
@@ -26,12 +26,16 @@
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
MainActivity.updateStoragePrefreneces(this); //needed for unit tests
MainActivity.updateStoragePreferences(this); //needed for unit tests
setContentView(R.layout.activity_extra_samples);

Toolbar myToolbar = findViewById(R.id.my_toolbar);
setSupportActionBar(myToolbar);

//noinspection ConstantConditions
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setDisplayShowHomeEnabled(true);

FragmentManager fm = this.getSupportFragmentManager();
if (fm.findFragmentByTag(SAMPLES_FRAGMENT_TAG) == null) {
List<IBaseActivity> extras = new ArrayList<>() ;
@@ -41,6 +45,11 @@ protected void onCreate(Bundle savedInstanceState) {
}
}

@Override
public boolean onSupportNavigateUp() {
onBackPressed();
return true;
}

@Override
public void onDestroy(){
@@ -22,19 +22,28 @@
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

MainActivity.updateStoragePrefreneces(this); //needed for unit tests
MainActivity.updateStoragePreferences(this); //needed for unit tests
setContentView(R.layout.activity_extra_samples);

Toolbar myToolbar = findViewById(R.id.my_toolbar);
setSupportActionBar(myToolbar);

//noinspection ConstantConditions
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setDisplayShowHomeEnabled(true);

FragmentManager fm = this.getSupportFragmentManager();
if (fm.findFragmentByTag(SAMPLES_FRAGMENT_TAG) == null) {
fragmentSamples = SamplesMenuFragment.newInstance(SampleFactory.getInstance(), Collections.EMPTY_LIST);
fm.beginTransaction().add(org.osmdroid.R.id.samples_container, fragmentSamples, SAMPLES_FRAGMENT_TAG).commit();
}
}

@Override
public boolean onSupportNavigateUp() {
onBackPressed();
return true;
}

@Override
public void onDestroy(){
@@ -1,7 +1,8 @@
package org.osmdroid;

import android.app.Activity;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
@@ -14,26 +15,38 @@
* @author Alex O'Ree
*/

public class LicenseActivity extends Activity implements AdapterView.OnItemSelectedListener {
public class LicenseActivity extends AppCompatActivity implements AdapterView.OnItemSelectedListener {
TextView license;
String[] values = new String[]{
"osmdroid", "geopackage",
"mapsforge", "ACRA", "leakcanary", "ormlite", "pngj"
};


@Override
public void onCreate(final Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_license);

Toolbar toolbar = findViewById(R.id.my_toolbar);
setSupportActionBar(toolbar);

//noinspection ConstantConditions
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setDisplayShowHomeEnabled(true);

Spinner spinner = findViewById(R.id.license_module_spinner);
ArrayAdapter<String> array = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, values);
ArrayAdapter<String> array = new ArrayAdapter<>(this, android.R.layout.simple_spinner_item, values);
array.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
spinner.setAdapter(array);
license = findViewById(R.id.license_body);
spinner.setOnItemSelectedListener(this);
}

@Override
public boolean onSupportNavigateUp() {
onBackPressed();
return true;
}

@Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
@@ -59,13 +72,11 @@ public void onItemSelected(AdapterView<?> parent, View view, int position, long
case 6:
license.setText(R.string.license_pngj);
break;

}
}

@Override
public void onNothingSelected(AdapterView<?> parent) {

}

}
@@ -25,9 +25,7 @@
import org.osmdroid.debug.CacheAnalyzerActivity;
import org.osmdroid.diag.DiagnosticsActivity;
import org.osmdroid.intro.IntroActivity;
import org.osmdroid.samples.SampleExtensive;
import org.osmdroid.samples.SampleWithMinimapItemizedoverlay;
import org.osmdroid.samples.SampleWithMinimapZoomcontrols;
import org.osmdroid.samples.SampleWithTilesOverlay;
import org.osmdroid.samples.SampleWithTilesOverlayAndCustomTileSource;
import org.osmdroid.tileprovider.modules.SqlTileWriter;
@@ -50,29 +48,25 @@ public void onCreate(final Bundle savedInstanceState) {
setSupportActionBar(myToolbar);
// Generate a ListView with Sample Maps
final ArrayList<String> list = new ArrayList<>();
list.add("OSMDroid Sample map (Start Here)");
list.add("OSMapView with Minimap, ZoomControls, Animations, Scale Bar and MyLocationOverlay");
list.add("OSMapView with ItemizedOverlay");
list.add("OSMapView with Minimap and ZoomControls");
list.add("Sample with tiles overlay");
list.add("Sample with tiles overlay and secondary tile overlay");
list.add("OSMDroid Sample Map (Start Here)");
list.add("Sample with ItemizedOverlay");
list.add("Sample with TilesOverlay");
list.add("Sample with TilesOverlay and custom TileSource");
list.add("More Samples");

list.add("Report a bug");
list.add("Report a Bug");
list.add("Settings");
list.add("Bug Drivers");
list.add("Diagnostics");
list.add("View the intro again");
list.add("View the Intro again");
list.add("Licenses");
if (BuildConfig.VERSION_CODE >= 11)
list.add("Cache Analyzer");
list.add("Cache Analyzer");

ListView lv = findViewById(R.id.activitylist);
ArrayAdapter adapter = new ArrayAdapter<>(this, android.R.layout.simple_list_item_1, list);

lv.setAdapter(adapter);
lv.setOnItemClickListener(this);

}

@Override
@@ -82,39 +76,33 @@ public void onItemClick(AdapterView<?> parent, View view, int position, long id)
this.startActivity(new Intent(this, StarterMapActivity.class));
break;
case 1:
this.startActivity(new Intent(this, SampleExtensive.class));
break;
case 2:
this.startActivity(new Intent(this, SampleWithMinimapItemizedoverlay.class));
break;
case 3:
this.startActivity(new Intent(this, SampleWithMinimapZoomcontrols.class));
break;
case 4:
case 2:
this.startActivity(new Intent(this, SampleWithTilesOverlay.class));
break;
case 5:
case 3:
this.startActivity(new Intent(this, SampleWithTilesOverlayAndCustomTileSource.class));
break;
case 6:
case 4:
this.startActivity(new Intent(this, ExtraSamplesActivity.class));
break;
case 7:
case 5:
Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("https://github.com/osmdroid/osmdroid/issues/new"));
startActivity(browserIntent);
break;
case 8:{
case 6:{
Intent i = new Intent(this,PreferenceActivity.class);
startActivity(i);
}
break;
case 9:
case 7:
this.startActivity(new Intent(this, BugsTestingActivity.class));
break;
case 10:
case 8:
this.startActivity(new Intent(this, DiagnosticsActivity.class));
break;
case 11:
case 9:
{
//skip this nonsense
SharedPreferences.Editor edit = PreferenceManager.getDefaultSharedPreferences(this).edit();
@@ -126,23 +114,18 @@ public void onItemClick(AdapterView<?> parent, View view, int position, long id)
finish();
break;
}
case 12:{
case 10:{
Intent i = new Intent(this,LicenseActivity.class);
startActivity(i);
break;
}
case 13:
{
if (BuildConfig.VERSION_CODE >= 11){
Intent starter = new Intent(this,CacheAnalyzerActivity.class);
startActivity(starter );
break;
}
}
case 11:
Intent starter = new Intent(this,CacheAnalyzerActivity.class);
startActivity(starter );
break;
}
}


public void onResume(){
super.onResume();
updateStorageInfo();
@@ -152,7 +135,7 @@ public void onResume(){
private void checkForCrashLogs() {
//look for osmdroid crash logs
File root = Environment.getExternalStorageDirectory();
String pathToMyAttachedFile = "/osmdroid/crash.lgo";
String pathToMyAttachedFile = "/osmdroid/crash.log";
final File file = new File(root, pathToMyAttachedFile);
if (!file.exists() || !file.canRead()) {
return;
@@ -191,9 +174,6 @@ public void onClick(DialogInterface dialog, int which) {
builder.setMessage("Sorry, it looks like we crashed at some point, would you mind sending us the" +
"crash log?").setPositiveButton("Yes", dialogClickListener)
.setNegativeButton("No", dialogClickListener).show();



}

/**
@@ -202,7 +182,7 @@ public void onClick(DialogInterface dialog, int which) {
* @param ctx
* @return current cache size in bytes
*/
public static long updateStoragePrefreneces(Context ctx){
public static long updateStoragePreferences(Context ctx){

//loads the osmdroid config from the shared preferences object.
//if this is the first time launching this app, all settings are set defaults with one exception,
@@ -226,7 +206,7 @@ public static long updateStoragePrefreneces(Context ctx){
*/
private void updateStorageInfo(){

long cacheSize = updateStoragePrefreneces(this);
long cacheSize = updateStoragePreferences(this);
//cache management ends here

TextView tv = findViewById(R.id.sdcardstate_value);
@@ -246,6 +226,4 @@ private void updateStorageInfo(){
tv.setText(Configuration.getInstance().getOsmdroidTileCache().getAbsolutePath() + "\n" +
"Cache size: " + Formatter.formatFileSize(this,cacheSize));
}


}
@@ -54,6 +54,11 @@ public void onCreate() {
}

try {
if (LeakCanary.isInAnalyzerProcess(this)) {
// This process is dedicated to LeakCanary for heap analysis.
// You should not init your app in this process.
return;
}
LeakCanary.install(this);
} catch (Throwable ex) {

@@ -119,8 +124,6 @@ protected void attachBaseContext(Context base) {
//this can happen on androidx86 getExternalStorageDir is not writable or if there is a
//permissions issue
}


}

public static class OsmUncaughtExceptionHandler implements Thread.UncaughtExceptionHandler {
@@ -75,6 +75,10 @@ public void onCreate(final Bundle savedInstanceState) {
Toolbar myToolbar = findViewById(R.id.my_toolbar);
setSupportActionBar(myToolbar);

//noinspection ConstantConditions
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setDisplayShowHomeEnabled(true);

checkBoxDebugTileProvider = findViewById(R.id.checkBoxDebugTileProvider);
checkBoxDebugMode = findViewById(R.id.checkBoxDebugMode);
checkBoxHardwareAcceleration = findViewById(R.id.checkBoxHardwareAcceleration);
@@ -132,6 +136,12 @@ public void onCreate(final Bundle savedInstanceState) {

}

@Override
public boolean onSupportNavigateUp() {
onBackPressed();
return true;
}

@Override
public void onResume() {
super.onResume();

0 comments on commit b7824d7

Please sign in to comment.
You can’t perform that action at this time.