Skip to content
This repository has been archived by the owner on Aug 8, 2023. It is now read-only.

Commit

Permalink
[android] Add Configuration hook for local ideograph font family and …
Browse files Browse the repository at this point in the history
…demo activity
  • Loading branch information
ChrisLoer committed Dec 15, 2017
1 parent 56f6077 commit 218dcf2
Show file tree
Hide file tree
Showing 14 changed files with 196 additions and 38 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@ public void onCreate(@Nullable Bundle savedInstanceState) {
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() {
Expand All @@ -315,7 +315,7 @@ public void run() {
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() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -157,6 +158,7 @@ private MapboxMapOptions(Parcel in) {
textureMode = in.readByte() != 0;
prefetchesTiles = in.readByte() != 0;
zMediaOverlay = in.readByte() != 0;
localIdeographFontFamily = in.readString();
}

static Bitmap getBitmapFromDrawable(Drawable drawable) {
Expand Down Expand Up @@ -304,6 +306,8 @@ public static MapboxMapOptions createFromAttributes(@NonNull Context context, @N
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();
}
Expand Down Expand Up @@ -733,6 +737,18 @@ public MapboxMapOptions setPrefetchesTiles(boolean enable) {
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 This
*/
public MapboxMapOptions localIdeographFontFamily(String fontFamily) {
this.localIdeographFontFamily = fontFamily;
return this;
}

/**
* Check whether tile pre-fetching is enabled.
*
Expand Down Expand Up @@ -1079,6 +1095,16 @@ public boolean getTextureMode() {
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);
Expand Down Expand Up @@ -1145,6 +1171,7 @@ public void writeToParcel(Parcel dest, int flags) {
dest.writeByte((byte) (textureMode ? 1 : 0));
dest.writeByte((byte) (prefetchesTiles ? 1 : 0));
dest.writeByte((byte) (zMediaOverlay ? 1 : 0));
dest.writeString(localIdeographFontFamily);
}

@Override
Expand Down Expand Up @@ -1274,6 +1301,9 @@ public boolean equals(Object o) {
if (zMediaOverlay != options.zMediaOverlay) {
return false;
}
if (localIdeographFontFamily != options.localIdeographFontFamily) {
return false;
}

return false;
}
Expand Down Expand Up @@ -1323,6 +1353,7 @@ public int hashCode() {
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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -112,7 +111,8 @@ void queueEvent(MapRendererRunnable runnable) {
private native void nativeInitialize(MapRenderer self,
FileSource fileSource,
float pixelRatio,
String programCacheDir);
String programCacheDir,
String localIdeographFontFamily);

@CallSuper
@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,10 @@ 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();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -367,29 +367,32 @@
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"/>
<meta-data
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"/>
<meta-data
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"/>
Expand Down Expand Up @@ -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"/>
Expand Down Expand Up @@ -720,36 +723,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
Expand Down
Original file line number Diff line number Diff line change
@@ -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_local_glyph);

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);
}
}
Original file line number Diff line number Diff line change
@@ -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>
Original file line number Diff line number Diff line change
Expand Up @@ -67,4 +67,5 @@
<string name="description_textureview_debug">Use TextureView to render the map</string>
<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_local_glyph">Suzhou using Droid Sans for Chinese glyphs</string>
</resources>
Loading

0 comments on commit 218dcf2

Please sign in to comment.