[android] Add Configuration hook for local ideograph font family and demo activity
This commit is contained in:
committed by
Chris Loer
parent
56aa7dad4f
commit
bee60130d3
@@ -293,7 +293,7 @@ public class MapView extends FrameLayout {
|
||||
private void initialiseDrawingSurface(MapboxMapOptions options) {
|
||||
if (options.getTextureMode()) {
|
||||
TextureView textureView = new TextureView(getContext());
|
||||
mapRenderer = new TextureViewMapRenderer(getContext(), textureView) {
|
||||
mapRenderer = new TextureViewMapRenderer(getContext(), textureView, options.getLocalIdeographFontFamily()) {
|
||||
@Override
|
||||
protected void onSurfaceCreated(GL10 gl, EGLConfig config) {
|
||||
MapView.this.post(new Runnable() {
|
||||
@@ -315,7 +315,7 @@ public class MapView extends FrameLayout {
|
||||
GLSurfaceView glSurfaceView = (GLSurfaceView) findViewById(R.id.surfaceView);
|
||||
glSurfaceView.setZOrderMediaOverlay(mapboxMapOptions.getRenderSurfaceOnTop());
|
||||
|
||||
mapRenderer = new GLSurfaceViewMapRenderer(getContext(), glSurfaceView) {
|
||||
mapRenderer = new GLSurfaceViewMapRenderer(getContext(), glSurfaceView, options.getLocalIdeographFontFamily()) {
|
||||
@Override
|
||||
public void onSurfaceCreated(GL10 gl, EGLConfig config) {
|
||||
MapView.this.post(new Runnable() {
|
||||
|
||||
@@ -82,6 +82,7 @@ public class MapboxMapOptions implements Parcelable {
|
||||
private float myLocationAccuracyThreshold;
|
||||
private boolean prefetchesTiles = true;
|
||||
private boolean zMediaOverlay = false;
|
||||
private String localIdeographFontFamily;
|
||||
|
||||
private String apiBaseUrl;
|
||||
|
||||
@@ -157,6 +158,7 @@ public class MapboxMapOptions implements Parcelable {
|
||||
textureMode = in.readByte() != 0;
|
||||
prefetchesTiles = in.readByte() != 0;
|
||||
zMediaOverlay = in.readByte() != 0;
|
||||
localIdeographFontFamily = in.readString();
|
||||
}
|
||||
|
||||
static Bitmap getBitmapFromDrawable(Drawable drawable) {
|
||||
@@ -304,6 +306,7 @@ public class MapboxMapOptions implements Parcelable {
|
||||
typedArray.getBoolean(R.styleable.mapbox_MapView_mapbox_enableTilePrefetch, true));
|
||||
mapboxMapOptions.renderSurfaceOnTop(
|
||||
typedArray.getBoolean(R.styleable.mapbox_MapView_mapbox_enableZMediaOverlay, false));
|
||||
mapboxMapOptions.localIdeographFontFamily(typedArray.getString(R.styleable.mapbox_MapView_mapbox_localIdeographFontFamily));
|
||||
} finally {
|
||||
typedArray.recycle();
|
||||
}
|
||||
@@ -733,6 +736,18 @@ public class MapboxMapOptions implements Parcelable {
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the font-family for generating glyphs locally for ideographs in the ‘CJK Unified Ideographs’
|
||||
* and ‘Hangul Syllables’ ranges.
|
||||
*
|
||||
* @param fontFamily font family for local ideograph generation.
|
||||
* @return
|
||||
*/
|
||||
public MapboxMapOptions localIdeographFontFamily(String fontFamily) {
|
||||
this.localIdeographFontFamily = fontFamily;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check whether tile pre-fetching is enabled.
|
||||
*
|
||||
@@ -1079,6 +1094,14 @@ public class MapboxMapOptions implements Parcelable {
|
||||
return textureMode;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the font-family for locally overriding generation of glyphs in the
|
||||
* ‘CJK Unified Ideographs’ and ‘Hangul Syllables’ ranges.
|
||||
*
|
||||
* @return Local ideograph font family name.
|
||||
*/
|
||||
public String getLocalIdeographFontFamily() { return localIdeographFontFamily; }
|
||||
|
||||
public static final Parcelable.Creator<MapboxMapOptions> CREATOR = new Parcelable.Creator<MapboxMapOptions>() {
|
||||
public MapboxMapOptions createFromParcel(Parcel in) {
|
||||
return new MapboxMapOptions(in);
|
||||
@@ -1145,6 +1168,7 @@ public class MapboxMapOptions implements Parcelable {
|
||||
dest.writeByte((byte) (textureMode ? 1 : 0));
|
||||
dest.writeByte((byte) (prefetchesTiles ? 1 : 0));
|
||||
dest.writeByte((byte) (zMediaOverlay ? 1 : 0));
|
||||
dest.writeString(localIdeographFontFamily);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -1274,6 +1298,9 @@ public class MapboxMapOptions implements Parcelable {
|
||||
if (zMediaOverlay != options.zMediaOverlay) {
|
||||
return false;
|
||||
}
|
||||
if (localIdeographFontFamily != options.localIdeographFontFamily) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
@@ -1323,6 +1350,7 @@ public class MapboxMapOptions implements Parcelable {
|
||||
result = 31 * result + (style != null ? style.hashCode() : 0);
|
||||
result = 31 * result + (prefetchesTiles ? 1 : 0);
|
||||
result = 31 * result + (zMediaOverlay ? 1 : 0);
|
||||
result = 31 * result + (localIdeographFontFamily != null ? localIdeographFontFamily.hashCode() : 0);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,14 +23,13 @@ public abstract class MapRenderer implements MapRendererScheduler {
|
||||
|
||||
private MapboxMap.OnFpsChangedListener onFpsChangedListener;
|
||||
|
||||
public MapRenderer(Context context) {
|
||||
public MapRenderer(Context context, String localIdeographFontFamily) {
|
||||
|
||||
FileSource fileSource = FileSource.getInstance(context);
|
||||
float pixelRatio = context.getResources().getDisplayMetrics().density;
|
||||
String programCacheDir = context.getCacheDir().getAbsolutePath();
|
||||
|
||||
// Initialise native peer
|
||||
nativeInitialize(this, fileSource, pixelRatio, programCacheDir);
|
||||
nativeInitialize(this, fileSource, pixelRatio, programCacheDir, localIdeographFontFamily);
|
||||
}
|
||||
|
||||
public void onStart() {
|
||||
@@ -112,7 +111,8 @@ public abstract class MapRenderer implements MapRendererScheduler {
|
||||
private native void nativeInitialize(MapRenderer self,
|
||||
FileSource fileSource,
|
||||
float pixelRatio,
|
||||
String programCacheDir);
|
||||
String programCacheDir,
|
||||
String localIdeographFontFamily);
|
||||
|
||||
@CallSuper
|
||||
@Override
|
||||
|
||||
@@ -21,8 +21,8 @@ public class GLSurfaceViewMapRenderer extends MapRenderer implements GLSurfaceVi
|
||||
|
||||
private final GLSurfaceView glSurfaceView;
|
||||
|
||||
public GLSurfaceViewMapRenderer(Context context, GLSurfaceView glSurfaceView) {
|
||||
super(context);
|
||||
public GLSurfaceViewMapRenderer(Context context, GLSurfaceView glSurfaceView, String localIdeographFontFamily) {
|
||||
super(context, localIdeographFontFamily);
|
||||
this.glSurfaceView = glSurfaceView;
|
||||
glSurfaceView.setEGLContextClientVersion(2);
|
||||
glSurfaceView.setEGLConfigChooser(new EGLConfigChooser());
|
||||
|
||||
@@ -24,8 +24,8 @@ public class TextureViewMapRenderer extends MapRenderer {
|
||||
* @param context the current Context
|
||||
* @param textureView the TextureView
|
||||
*/
|
||||
public TextureViewMapRenderer(@NonNull Context context, @NonNull TextureView textureView) {
|
||||
super(context);
|
||||
public TextureViewMapRenderer(@NonNull Context context, @NonNull TextureView textureView, String localIdeographFontFamily) {
|
||||
super(context, localIdeographFontFamily);
|
||||
renderThread = new TextureViewRenderThread(textureView, this);
|
||||
renderThread.start();
|
||||
}
|
||||
|
||||
@@ -11,6 +11,7 @@
|
||||
<!--Configuration-->
|
||||
<public name="mapbox_styleUrl" type="attr" />
|
||||
<public name="mapbox_apiBaseUrl" type="attr" />
|
||||
<public name="mapbox_localIdeographFontFamily" type="attr" />
|
||||
|
||||
<!--Camera-->
|
||||
<public name="mapbox_cameraTargetLng" type="attr" />
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
<!--Configuration-->
|
||||
<attr name="mapbox_styleUrl" format="string"/>
|
||||
<attr name="mapbox_apiBaseUrl" format="string"/>
|
||||
<attr name="mapbox_localIdeographFontFamily" format="string"/>
|
||||
|
||||
<!--Camera-->
|
||||
<attr name="mapbox_cameraTargetLat" format="float"/>
|
||||
|
||||
@@ -367,9 +367,10 @@
|
||||
android:name="android.support.PARENT_ACTIVITY"
|
||||
android:value=".activity.FeatureOverviewActivity"/>
|
||||
</activity>
|
||||
<activity android:name=".activity.snapshot.MapSnapshotterActivity"
|
||||
android:description="@string/description_map_snapshotter"
|
||||
android:label="@string/activity_map_snapshotter">
|
||||
<activity
|
||||
android:name=".activity.snapshot.MapSnapshotterActivity"
|
||||
android:description="@string/description_map_snapshotter"
|
||||
android:label="@string/activity_map_snapshotter">
|
||||
<meta-data
|
||||
android:name="@string/category"
|
||||
android:value="@string/category_imagegenerator"/>
|
||||
@@ -377,9 +378,10 @@
|
||||
android:name="android.support.PARENT_ACTIVITY"
|
||||
android:value=".activity.FeatureOverviewActivity"/>
|
||||
</activity>
|
||||
<activity android:name=".activity.snapshot.MapSnapshotterReuseActivity"
|
||||
android:description="@string/description_map_snapshotter_reuse"
|
||||
android:label="@string/activity_map_snapshotter_reuse">
|
||||
<activity
|
||||
android:name=".activity.snapshot.MapSnapshotterReuseActivity"
|
||||
android:description="@string/description_map_snapshotter_reuse"
|
||||
android:label="@string/activity_map_snapshotter_reuse">
|
||||
<meta-data
|
||||
android:name="@string/category"
|
||||
android:value="@string/category_imagegenerator"/>
|
||||
@@ -387,9 +389,10 @@
|
||||
android:name="android.support.PARENT_ACTIVITY"
|
||||
android:value=".activity.FeatureOverviewActivity"/>
|
||||
</activity>
|
||||
<activity android:name=".activity.snapshot.MapSnapshotterMarkerActivity"
|
||||
android:description="@string/description_map_snapshotter_marker"
|
||||
android:label="@string/activity_map_snapshotter_marker">
|
||||
<activity
|
||||
android:name=".activity.snapshot.MapSnapshotterMarkerActivity"
|
||||
android:description="@string/description_map_snapshotter_marker"
|
||||
android:label="@string/activity_map_snapshotter_marker">
|
||||
<meta-data
|
||||
android:name="@string/category"
|
||||
android:value="@string/category_imagegenerator"/>
|
||||
@@ -586,8 +589,8 @@
|
||||
</activity>
|
||||
<activity
|
||||
android:name=".activity.style.AnimatedImageSourceActivity"
|
||||
android:label="@string/activity_animated_image_source"
|
||||
android:description="@string/description_animated_image_source">
|
||||
android:description="@string/description_animated_image_source"
|
||||
android:label="@string/activity_animated_image_source">
|
||||
<meta-data
|
||||
android:name="@string/category"
|
||||
android:value="@string/category_style"/>
|
||||
@@ -597,8 +600,8 @@
|
||||
</activity>
|
||||
<activity
|
||||
android:name=".activity.style.GridSourceActivity"
|
||||
android:label="@string/title_activity_grid_source"
|
||||
android:description="@string/description_grid_source">
|
||||
android:description="@string/description_grid_source"
|
||||
android:label="@string/activity_grid_source">
|
||||
<meta-data
|
||||
android:name="@string/category"
|
||||
android:value="@string/category_style"/>
|
||||
@@ -730,36 +733,51 @@
|
||||
android:name="android.support.PARENT_ACTIVITY"
|
||||
android:value=".activity.FeatureOverviewActivity"/>
|
||||
</activity>
|
||||
<activity android:name=".activity.maplayout.BottomSheetActivity"
|
||||
android:description="@string/description_bottom_sheet"
|
||||
android:label="@string/activity_bottom_sheet">
|
||||
<activity
|
||||
android:name=".activity.maplayout.BottomSheetActivity"
|
||||
android:description="@string/description_bottom_sheet"
|
||||
android:label="@string/activity_bottom_sheet">
|
||||
<meta-data
|
||||
android:name="@string/category"
|
||||
android:value="@string/category_maplayout"/>
|
||||
</activity>
|
||||
|
||||
<!-- TextureView -->
|
||||
<activity android:name=".activity.textureview.TextureViewDebugModeActivity"
|
||||
android:description="@string/description_textureview_debug"
|
||||
android:label="@string/activity_textureview_debug">
|
||||
<activity
|
||||
android:name=".activity.textureview.TextureViewDebugModeActivity"
|
||||
android:description="@string/description_textureview_debug"
|
||||
android:label="@string/activity_textureview_debug">
|
||||
<meta-data
|
||||
android:name="@string/category"
|
||||
android:value="@string/category_textureview"/>
|
||||
</activity>
|
||||
<activity android:name=".activity.textureview.TextureViewResizeActivity"
|
||||
android:description="@string/description_textureview_resize"
|
||||
android:label="@string/activity_textureview_resize">
|
||||
<activity
|
||||
android:name=".activity.textureview.TextureViewResizeActivity"
|
||||
android:description="@string/description_textureview_resize"
|
||||
android:label="@string/activity_textureview_resize">
|
||||
<meta-data
|
||||
android:name="@string/category"
|
||||
android:value="@string/category_textureview"/>
|
||||
</activity>
|
||||
<activity android:name=".activity.textureview.TextureViewAnimationActivity"
|
||||
android:description="@string/description_textureview_animate"
|
||||
android:label="@string/activity_textureview_animate">
|
||||
<activity
|
||||
android:name=".activity.textureview.TextureViewAnimationActivity"
|
||||
android:description="@string/description_textureview_animate"
|
||||
android:label="@string/activity_textureview_animate">
|
||||
<meta-data
|
||||
android:name="@string/category"
|
||||
android:value="@string/category_textureview"/>
|
||||
</activity>
|
||||
<activity
|
||||
android:name=".activity.maplayout.LocalGlyphActivity"
|
||||
android:description="@string/description_local_glyph"
|
||||
android:label="@string/activity_local_glyph">
|
||||
<meta-data
|
||||
android:name="@string/category"
|
||||
android:value="@string/category_maplayout"/>
|
||||
<meta-data
|
||||
android:name="android.support.PARENT_ACTIVITY"
|
||||
android:value=".activity.FeatureOverviewActivity"/>
|
||||
</activity>
|
||||
|
||||
<!-- For Instrumentation tests -->
|
||||
<activity
|
||||
|
||||
@@ -0,0 +1,81 @@
|
||||
package com.mapbox.mapboxsdk.testapp.activity.maplayout;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.v7.app.AppCompatActivity;
|
||||
|
||||
import com.mapbox.mapboxsdk.camera.CameraPosition;
|
||||
import com.mapbox.mapboxsdk.camera.CameraUpdateFactory;
|
||||
import com.mapbox.mapboxsdk.geometry.LatLng;
|
||||
import com.mapbox.mapboxsdk.maps.MapView;
|
||||
import com.mapbox.mapboxsdk.maps.MapboxMap;
|
||||
import com.mapbox.mapboxsdk.maps.OnMapReadyCallback;
|
||||
import com.mapbox.mapboxsdk.testapp.R;
|
||||
|
||||
public class LocalGlyphActivity extends AppCompatActivity {
|
||||
private MapView mapView;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_map_simple);
|
||||
|
||||
mapView = (MapView) findViewById(R.id.mapView);
|
||||
mapView.onCreate(savedInstanceState);
|
||||
mapView.getMapAsync(new OnMapReadyCallback() {
|
||||
@Override
|
||||
public void onMapReady(@NonNull MapboxMap mapboxMap) {
|
||||
// Set initial position to Suzhou
|
||||
mapboxMap.moveCamera(CameraUpdateFactory.newCameraPosition(
|
||||
new CameraPosition.Builder()
|
||||
.target(new LatLng(31.3003, 120.7457))
|
||||
.zoom(11)
|
||||
.bearing(0)
|
||||
.tilt(0)
|
||||
.build()));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onStart() {
|
||||
super.onStart();
|
||||
mapView.onStart();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onResume() {
|
||||
super.onResume();
|
||||
mapView.onResume();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPause() {
|
||||
super.onPause();
|
||||
mapView.onPause();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onStop() {
|
||||
super.onStop();
|
||||
mapView.onStop();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onLowMemory() {
|
||||
super.onLowMemory();
|
||||
mapView.onLowMemory();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onDestroy() {
|
||||
super.onDestroy();
|
||||
mapView.onDestroy();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onSaveInstanceState(Bundle outState) {
|
||||
super.onSaveInstanceState(outState);
|
||||
mapView.onSaveInstanceState(outState);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:orientation="vertical"
|
||||
tools:context=".activity.maplayout.LocalGlyphActivity">
|
||||
|
||||
<com.mapbox.mapboxsdk.maps.MapView
|
||||
android:id="@id/mapView"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
app:mapbox_localIdeographFontFamily="Droid Sans" />
|
||||
|
||||
</LinearLayout>
|
||||
@@ -68,4 +68,5 @@
|
||||
<string name="description_textureview_resize">Resize a map rendered on a TextureView</string>
|
||||
<string name="description_textureview_animate">Animate a map rendered on a TextureView</string>
|
||||
<string name="description_grid_source">Example Custom Geometry Source</string>
|
||||
<string name="description_local_glyph">Test local glyph generation for CJK ideographs</string>
|
||||
</resources>
|
||||
@@ -1,5 +1,4 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<resources>
|
||||
<string name="app_name">Mapbox Android SDK TestApp</string>
|
||||
<string name="title_activity_grid_source">Grid Source</string>
|
||||
</resources>
|
||||
|
||||
@@ -67,4 +67,6 @@
|
||||
<string name="activity_textureview_debug">TextureView debug</string>
|
||||
<string name="activity_textureview_resize">TextureView resize</string>
|
||||
<string name="activity_textureview_animate">TextureView animation</string>
|
||||
<string name="activity_grid_source">Grid Source</string>
|
||||
<string name="activity_local_glyph">Local CJK glyph generation</string>
|
||||
</resources>
|
||||
@@ -16,10 +16,12 @@ namespace android {
|
||||
|
||||
MapRenderer::MapRenderer(jni::JNIEnv& _env, jni::Object<MapRenderer> obj,
|
||||
jni::Object<FileSource> _fileSource, jni::jfloat pixelRatio_,
|
||||
jni::String programCacheDir_)
|
||||
jni::String programCacheDir_,
|
||||
jni::String localIdeographFontFamily_)
|
||||
: javaPeer(SeizeGenericWeakRef(_env, jni::Object<MapRenderer>(jni::NewWeakGlobalRef(_env, obj.Get()).release()))), pixelRatio(pixelRatio_)
|
||||
, fileSource(FileSource::getDefaultFileSource(_env, _fileSource))
|
||||
, programCacheDir(jni::Make<std::string>(_env, programCacheDir_))
|
||||
, localIdeographFontFamily(localIdeographFontFamily_ == nullptr ? optional<std::string>{} : jni::Make<std::string>(_env, localIdeographFontFamily_ ))
|
||||
, threadPool(sharedThreadPool())
|
||||
, mailbox(std::make_shared<Mailbox>(*this)) {
|
||||
}
|
||||
@@ -145,7 +147,7 @@ void MapRenderer::onSurfaceCreated(JNIEnv&) {
|
||||
std::lock_guard<std::mutex> lock(initialisationMutex);
|
||||
|
||||
// The android system will have already destroyed the underlying
|
||||
// GL resources if this is not the first intialization and an
|
||||
// GL resources if this is not the first initialization and an
|
||||
// attempt to clean them up will fail
|
||||
if (backend) backend->markContextLost();
|
||||
if (renderer) renderer->markContextLost();
|
||||
@@ -157,7 +159,7 @@ void MapRenderer::onSurfaceCreated(JNIEnv&) {
|
||||
// Create the new backend and renderer
|
||||
backend = std::make_unique<AndroidRendererBackend>();
|
||||
renderer = std::make_unique<Renderer>(*backend, pixelRatio, fileSource, *threadPool,
|
||||
GLContextMode::Unique, programCacheDir);
|
||||
GLContextMode::Unique, programCacheDir, localIdeographFontFamily);
|
||||
rendererRef = std::make_unique<ActorRef<Renderer>>(*renderer, mailbox);
|
||||
|
||||
// Set the observer on the new Renderer implementation
|
||||
@@ -184,7 +186,7 @@ void MapRenderer::registerNative(jni::JNIEnv& env) {
|
||||
|
||||
// Register the peer
|
||||
jni::RegisterNativePeer<MapRenderer>(env, MapRenderer::javaClass, "nativePtr",
|
||||
std::make_unique<MapRenderer, JNIEnv&, jni::Object<MapRenderer>, jni::Object<FileSource>, jni::jfloat, jni::String>,
|
||||
std::make_unique<MapRenderer, JNIEnv&, jni::Object<MapRenderer>, jni::Object<FileSource>, jni::jfloat, jni::String, jni::String>,
|
||||
"nativeInitialize", "finalize",
|
||||
METHOD(&MapRenderer::render, "nativeRender"),
|
||||
METHOD(&MapRenderer::onSurfaceCreated,
|
||||
|
||||
@@ -48,7 +48,8 @@ public:
|
||||
jni::Object<MapRenderer>,
|
||||
jni::Object<FileSource>,
|
||||
jni::jfloat pixelRatio,
|
||||
jni::String programCacheDir);
|
||||
jni::String programCacheDir,
|
||||
jni::String localIdeographFontFamily);
|
||||
|
||||
~MapRenderer() override;
|
||||
|
||||
@@ -103,6 +104,7 @@ private:
|
||||
float pixelRatio;
|
||||
DefaultFileSource& fileSource;
|
||||
std::string programCacheDir;
|
||||
optional<std::string> localIdeographFontFamily;
|
||||
|
||||
std::shared_ptr<ThreadPool> threadPool;
|
||||
std::shared_ptr<Mailbox> mailbox;
|
||||
|
||||
Reference in New Issue
Block a user