Skip to content

Commit

Permalink
Show online map license
Browse files Browse the repository at this point in the history
  • Loading branch information
andreynovikov committed Feb 12, 2024
1 parent 1cf48c8 commit 9c4b98f
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 26 deletions.
43 changes: 30 additions & 13 deletions app/src/main/java/mobi/maptrek/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@
import androidx.work.WorkManager;

import android.text.Html;
import android.text.Spanned;
import android.text.method.LinkMovementMethod;
import android.transition.AutoTransition;
import android.transition.Fade;
Expand Down Expand Up @@ -248,6 +249,7 @@
import mobi.maptrek.location.NavigationService;
import mobi.maptrek.maps.MapWorker;
import mobi.maptrek.maps.maptrek.MapTrekDatabaseHelper;
import mobi.maptrek.maps.plugin.PluginOnlineTileSource;
import mobi.maptrek.plugin.PluginRepository;
import mobi.maptrek.util.ContextUtils;
import mobi.maptrek.util.SafeResultReceiver;
Expand Down Expand Up @@ -989,18 +991,8 @@ public void onTargetDismissed(TapTargetView view, boolean userInitiated) {
updateLocationDrawable();
adjustCompass(mMap.getMapPosition().bearing);

mViews.license.setText(Html.fromHtml(getString(R.string.osmLicense)));
mViews.license.setVisibility(View.VISIBLE);
final Message m = Message.obtain(mMainHandler,
() -> mViews.license.animate().alpha(0f).setDuration(MAP_POSITION_ANIMATION_DURATION).setListener(new AnimatorListenerAdapter() {
@Override
public void onAnimationEnd(Animator animation) {
mViews.license.setVisibility(View.GONE);
mViews.license.animate().setListener(null);
}
}));
m.what = R.id.msgRemoveLicense;
mMainHandler.sendMessageDelayed(m, 120000);
if ("".contentEquals(mViews.license.getText()))
showLicense(null);

String userNotification = MapTrek.getApplication().getUserNotification();
if (userNotification != null)
Expand Down Expand Up @@ -3078,6 +3070,7 @@ public void onMapSelected(MapFile mapFile) {
if (current) {
showHideMapObjects(false);
mMap.updateMap(true);
showLicense(null);
return;
}
}
Expand All @@ -3091,8 +3084,10 @@ public void onExtraMapSelected(MapFile mapFile) {
mMap.layers().remove(mapFile.tileLayer);
mapFile.tileSource.close();
mBitmapLayerMaps.remove(mapFile);
if (mBitmapLayerMaps.isEmpty())
if (mBitmapLayerMaps.isEmpty()) {
showHideMapObjects(false);
showLicense(null);
}
mMap.updateMap(true);
} else {
showBitmapMap(mapFile, mBitmapLayerMaps.isEmpty());
Expand Down Expand Up @@ -3251,6 +3246,12 @@ private void showBitmapMap(MapFile mapFile, boolean reposition) {
mapFile.tileLayer = new BitmapTileLayer(mMap, mapFile.tileSource, 1 - mBitmapMapTransparency * 0.01f);
}
mMap.layers().add(mapFile.tileLayer, MAP_MAPS);
if (mapFile.tileSource instanceof PluginOnlineTileSource) {
PluginOnlineTileSource tileSource = (PluginOnlineTileSource) mapFile.tileSource;
String license = tileSource.getLicense();
if (license != null)
showLicense(license);
}
if (!reposition)
return;

Expand Down Expand Up @@ -4674,6 +4675,22 @@ private void showSystemUI() {
mMap.updateMap();
}

private void showLicense(String license) {
Spanned html = Html.fromHtml(license != null ? license : getString(R.string.osmLicense));
mViews.license.setText(html);
mViews.license.setVisibility(View.VISIBLE);
final Message m = Message.obtain(mMainHandler,
() -> mViews.license.animate().alpha(0f).setDuration(MAP_POSITION_ANIMATION_DURATION).setListener(new AnimatorListenerAdapter() {
@Override
public void onAnimationEnd(Animator animation) {
mViews.license.setVisibility(View.GONE);
mViews.license.animate().setListener(null);
}
}));
m.what = R.id.msgRemoveLicense;
mMainHandler.sendMessageDelayed(m, 120000);
}

public boolean isOnline() {
// FIXME temporary
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,15 @@ public static Builder<?> builder(Context context) {
private final String mProviderAuthority;
private final String mSourceId;

private final String mLicense;

protected PluginOnlineTileSource(Builder<?> builder) {
super(builder);
mContext = builder.context;
mMapId = builder.mapId;
mProviderAuthority = builder.providerAuthority;
mSourceId = "content://" + builder.providerAuthority + "/" + builder.mapId;
mLicense = builder.license;
}

@Override
Expand Down Expand Up @@ -105,4 +108,8 @@ public String getMapId() {
public String getSourceId() {
return mSourceId;
}

public String getLicense() {
return mLicense;
}
}
22 changes: 9 additions & 13 deletions app/src/main/java/mobi/maptrek/view/BitmapTileMapPreviewView.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@
import static org.oscim.tiling.QueryResult.FAILED;
import static org.oscim.tiling.QueryResult.SUCCESS;

import androidx.annotation.NonNull;

public class BitmapTileMapPreviewView extends TextureView implements SurfaceTextureListener {
private static final Logger logger = LoggerFactory.getLogger(BitmapTileMapPreviewView.class);

Expand Down Expand Up @@ -111,7 +113,7 @@ public BitmapTileMapPreviewView(Context context, AttributeSet attrs) {
* Listener tells us when the texture has been created and is ready to be drawn on.
*/
@Override
public void onSurfaceTextureAvailable(SurfaceTexture surface, int width, int height) {
public void onSurfaceTextureAvailable(@NonNull SurfaceTexture surface, int width, int height) {
logger.debug("onSurfaceTextureAvailable({},{})", width, height);
if (!mActive)
mTileSource.open();
Expand Down Expand Up @@ -172,7 +174,7 @@ public void onSurfaceTextureAvailable(SurfaceTexture surface, int width, int hei
* is called.
*/
@Override
public boolean onSurfaceTextureDestroyed(SurfaceTexture surface) {
public boolean onSurfaceTextureDestroyed(@NonNull SurfaceTexture surface) {
logger.debug("onSurfaceTextureDestroyed()");

// Stop tile loader
Expand Down Expand Up @@ -221,7 +223,7 @@ public boolean onSurfaceTextureDestroyed(SurfaceTexture surface) {
* Listener calls when the texture changes buffer size.
*/
@Override
public void onSurfaceTextureSizeChanged(SurfaceTexture surface, int width, int height) {
public void onSurfaceTextureSizeChanged(@NonNull SurfaceTexture surface, int width, int height) {
logger.debug("onSurfaceTextureSizeChanged({},{})", width, height);
//TODO Handle view resize
}
Expand All @@ -230,7 +232,7 @@ public void onSurfaceTextureSizeChanged(SurfaceTexture surface, int width, int h
* Listener calls when the texture is updated by updateTexImage()
*/
@Override
public void onSurfaceTextureUpdated(SurfaceTexture surface) {
public void onSurfaceTextureUpdated(@NonNull SurfaceTexture surface) {
logger.debug("onSurfaceTextureUpdated");
//Do nothing.
}
Expand Down Expand Up @@ -395,14 +397,8 @@ class BitmapTileLoader extends PausableThread implements ITileDataSink {
THREAD_NAME = "BitmapTileLoader";
}

boolean loadTile(MapTile tile) {
try {
mTileSource.getDataSource().query(tile, this);
} catch (Exception e) {
logger.error("{}: {}", tile, e.getMessage());
return false;
}
return true;
void loadTile(MapTile tile) {
mTileSource.getDataSource().query(tile, this);
}

void go() {
Expand All @@ -422,7 +418,7 @@ protected void doWork() {
logger.debug("{} : {} {}", mTileSource.getOption("path"), mTile, mTile.state());
loadTile(mTile);
} catch (Exception e) {
e.printStackTrace();
logger.error("Failed to load tile {}: ", mTile, e);
completed(FAILED);
}
}
Expand Down

0 comments on commit 9c4b98f

Please sign in to comment.