[android] #5801 - add setMediaOverlay example for a secondary SurfaceView

This commit is contained in:
Tobrun
2016-08-02 16:53:19 -04:00
parent 6016b2981e
commit 533a3edb9c
4 changed files with 185 additions and 3 deletions

View File

@@ -316,11 +316,18 @@
android:name="@string/category"
android:value="@string/category_imagegenerator" />
</activity>
<activity
android:name=".activity.maplayout.SurfaceViewMediaControlActivity"
android:description="@string/description_surfaceview_mediacontrols"
android:label="@string/activity_surfaceview_overlay">
<meta-data
android:name="@string/category"
android:value="@string/category_maplayout" />
</activity>
<!-- For Unit tests -->
<activity android:name=".activity.style.RuntimeStyleTestActivity"/>
<activity android:name=".activity.style.RuntimeStyleTimingTestActivity"/>
<activity android:name=".activity.style.RuntimeStyleTestActivity" />
<activity android:name=".activity.style.RuntimeStyleTimingTestActivity" />
<!-- Configuration Settings -->
<meta-data

View File

@@ -0,0 +1,142 @@
package com.mapbox.mapboxsdk.testapp.activity.maplayout;
import android.content.Context;
import android.opengl.GLSurfaceView;
import android.os.Bundle;
import android.support.v7.app.ActionBar;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.Menu;
import android.view.MenuItem;
import android.view.MotionEvent;
import android.widget.FrameLayout;
import com.mapbox.mapboxsdk.maps.MapView;
import com.mapbox.mapboxsdk.testapp.R;
import javax.microedition.khronos.egl.EGLConfig;
import javax.microedition.khronos.opengles.GL10;
public class SurfaceViewMediaControlActivity extends AppCompatActivity {
private MapView mMapView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_surfaceview_mediacontrols);
final Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
ActionBar actionBar = getSupportActionBar();
if (actionBar != null) {
actionBar.setDisplayHomeAsUpEnabled(true);
actionBar.setDisplayShowHomeEnabled(true);
}
mMapView = (MapView) findViewById(R.id.mapView);
mMapView.onCreate(savedInstanceState);
// add another SurfaceView to the Layout
FrameLayout container = (FrameLayout) findViewById(R.id.container);
GLSurfaceView mediaControlSurfaceView = new ClearGLSurfaceView(this);
mediaControlSurfaceView.setZOrderMediaOverlay(true);
container.addView(mediaControlSurfaceView);
}
@Override
public void onResume() {
super.onResume();
mMapView.onResume();
}
@Override
public void onPause() {
super.onPause();
mMapView.onPause();
}
@Override
protected void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
mMapView.onSaveInstanceState(outState);
}
@Override
protected void onDestroy() {
super.onDestroy();
mMapView.onDestroy();
}
@Override
public void onLowMemory() {
super.onLowMemory();
mMapView.onLowMemory();
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.menu_padding, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case android.R.id.home:
onBackPressed();
return true;
default:
return super.onOptionsItemSelected(item);
}
}
class ClearGLSurfaceView extends GLSurfaceView {
private ClearRenderer mRenderer;
public ClearGLSurfaceView(Context context) {
super(context);
mRenderer = new ClearRenderer();
setRenderer(mRenderer);
}
public boolean onTouchEvent(final MotionEvent event) {
queueEvent(new Runnable() {
public void run() {
mRenderer.setColor(event.getRawX() / getWidth(),
event.getRawY() / getHeight(), 1.0f);
}
});
return true;
}
}
class ClearRenderer implements GLSurfaceView.Renderer {
private float mRed;
private float mGreen;
private float mBlue;
public void onSurfaceCreated(GL10 gl, EGLConfig config) {
// Do nothing special.
}
public void onSurfaceChanged(GL10 gl, int w, int h) {
gl.glViewport(0, 0, w, h);
}
public void onDrawFrame(GL10 gl) {
gl.glClearColor(mRed, mGreen, mBlue, 1.0f);
gl.glClear(GL10.GL_COLOR_BUFFER_BIT | GL10.GL_DEPTH_BUFFER_BIT);
}
public void setColor(float r, float g, float b) {
mRed = r;
mGreen = g;
mBlue = b;
}
}
}

View File

@@ -0,0 +1,31 @@
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="@color/primary"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar" />
<com.mapbox.mapboxsdk.maps.MapView
android:id="@+id/mapView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/toolbar"
app:style_url="@string/style_light" />
<FrameLayout
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="128dp"
android:layout_alignParentBottom="true"
android:paddingBottom="48dp"
android:paddingLeft="16dp"
android:paddingRight="16dp" />
</RelativeLayout>

View File

@@ -55,6 +55,7 @@
<string name="activity_viewpager">ViewPager</string>
<string name="activity_runtime_style">Runtime Style</string>
<string name="activity_print">Print a map</string>
<string name="activity_surfaceview_overlay">SurfaceView MediaOverlay</string>
<string name="title_activity_navigation_drawer">Android SDK View integration</string>
<!-- Description -->
@@ -96,6 +97,7 @@
<string name="description_runtime_style">Adopt the map style on the fly</string>
<string name="description_print">Shows how to print a map</string>
<string name="description_navigation_drawer">Test animation of Android SDK View components</string>
<string name="description_surfaceview_mediacontrols">Test overlaying SurfaceView</string>
<string name="menuitem_title_concurrent_infowindow">Concurrent Open InfoWindows</string>
<string name="menuitem_title_deselect_markers_on_tap">Deselect Markers On Tap</string>