From 1970a946955d95a5c3d78910f24f5d82dd1ab1b9 Mon Sep 17 00:00:00 2001 From: Ivo van Dongen Date: Wed, 1 Nov 2017 11:43:27 +0200 Subject: [android] test app - texture view test activities --- .../src/main/AndroidManifest.xml | 23 ++ .../textureview/TextureViewAnimationActivity.java | 157 +++++++++++ .../textureview/TextureViewDebugModeActivity.java | 293 +++++++++++++++++++++ .../textureview/TextureViewResizeActivity.java | 107 ++++++++ .../res/layout/activity_textureview_animate.xml | 29 ++ .../res/layout/activity_textureview_debug_mode.xml | 98 +++++++ .../res/layout/activity_textureview_resize.xml | 29 ++ .../src/main/res/values/categories.xml | 1 + .../src/main/res/values/descriptions.xml | 3 + .../src/main/res/values/titles.xml | 3 + 10 files changed, 743 insertions(+) create mode 100644 platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/textureview/TextureViewAnimationActivity.java create mode 100644 platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/textureview/TextureViewDebugModeActivity.java create mode 100644 platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/textureview/TextureViewResizeActivity.java create mode 100644 platform/android/MapboxGLAndroidSDKTestApp/src/main/res/layout/activity_textureview_animate.xml create mode 100644 platform/android/MapboxGLAndroidSDKTestApp/src/main/res/layout/activity_textureview_debug_mode.xml create mode 100644 platform/android/MapboxGLAndroidSDKTestApp/src/main/res/layout/activity_textureview_resize.xml diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/AndroidManifest.xml b/platform/android/MapboxGLAndroidSDKTestApp/src/main/AndroidManifest.xml index 7f955cb45c..ee26f39f57 100644 --- a/platform/android/MapboxGLAndroidSDKTestApp/src/main/AndroidManifest.xml +++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/AndroidManifest.xml @@ -728,6 +728,29 @@ android:value="@string/category_maplayout"/> + + + + + + + + + + + layerList) { + final LayerListAdapter adapter = new LayerListAdapter(this, layerList); + ListView listView = (ListView) findViewById(R.id.listView); + listView.setAdapter(adapter); + listView.setOnItemClickListener(new AdapterView.OnItemClickListener() { + @Override + public void onItemClick(AdapterView parent, View view, int position, long id) { + Layer clickedLayer = adapter.getItem(position); + toggleLayerVisibility(clickedLayer); + closeNavigationView(); + } + }); + } + + private void toggleLayerVisibility(Layer layer) { + boolean isVisible = layer.getVisibility().getValue().equals(Property.VISIBLE); + layer.setProperties( + visibility( + isVisible ? Property.NONE : Property.VISIBLE + ) + ); + } + + private void closeNavigationView() { + DrawerLayout drawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout); + drawerLayout.closeDrawers(); + } + + private void setupZoomView() { + final TextView textView = (TextView) findViewById(R.id.textZoom); + mapboxMap.setOnCameraChangeListener(new MapboxMap.OnCameraChangeListener() { + @Override + public void onCameraChange(CameraPosition position) { + textView.setText(String.format(getString(R.string.debug_zoom), position.zoom)); + } + }); + } + + private void setupDebugChangeView() { + FloatingActionButton fabDebug = (FloatingActionButton) findViewById(R.id.fabDebug); + fabDebug.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + if (mapboxMap != null) { + Timber.d("Debug FAB: isDebug Active? %s", mapboxMap.isDebugActive()); + mapboxMap.cycleDebugOptions(); + } + } + }); + } + + private void setupStyleChangeView() { + FloatingActionButton fabStyles = (FloatingActionButton) findViewById(R.id.fabStyles); + fabStyles.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + if (mapboxMap != null) { + currentStyleIndex++; + if (currentStyleIndex == STYLES.length) { + currentStyleIndex = 0; + } + mapboxMap.setStyleUrl(STYLES[currentStyleIndex], new MapboxMap.OnStyleLoadedListener() { + @Override + public void onStyleLoaded(String style) { + Timber.d("Style loaded %s", style); + } + }); + } + } + }); + } + + @Override + public boolean onOptionsItemSelected(MenuItem item) { + return actionBarDrawerToggle.onOptionsItemSelected(item) || super.onOptionsItemSelected(item); + } + + @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 + protected void onSaveInstanceState(Bundle outState) { + super.onSaveInstanceState(outState); + mapView.onSaveInstanceState(outState); + } + + @Override + protected void onDestroy() { + super.onDestroy(); + mapView.onDestroy(); + } + + @Override + public void onLowMemory() { + super.onLowMemory(); + mapView.onLowMemory(); + } + + private static class LayerListAdapter extends BaseAdapter { + + private LayoutInflater layoutInflater; + private List layers; + + LayerListAdapter(Context context, List layers) { + this.layoutInflater = LayoutInflater.from(context); + this.layers = layers; + } + + @Override + public int getCount() { + return layers.size(); + } + + @Override + public Layer getItem(int position) { + return layers.get(position); + } + + @Override + public long getItemId(int position) { + return position; + } + + @Override + public View getView(int position, View convertView, ViewGroup parent) { + Layer layer = layers.get(position); + View view = convertView; + if (view == null) { + view = layoutInflater.inflate(android.R.layout.simple_list_item_2, parent, false); + ViewHolder holder = new ViewHolder( + (TextView) view.findViewById(android.R.id.text1), + (TextView) view.findViewById(android.R.id.text2) + ); + view.setTag(holder); + } + ViewHolder holder = (ViewHolder) view.getTag(); + holder.text.setText(layer.getClass().getSimpleName()); + holder.subText.setText(layer.getId()); + return view; + } + + private static class ViewHolder { + final TextView text; + final TextView subText; + + ViewHolder(TextView text, TextView subText) { + this.text = text; + this.subText = subText; + } + } + } +} diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/textureview/TextureViewResizeActivity.java b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/textureview/TextureViewResizeActivity.java new file mode 100644 index 0000000000..388774e6c8 --- /dev/null +++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/textureview/TextureViewResizeActivity.java @@ -0,0 +1,107 @@ +package com.mapbox.mapboxsdk.testapp.activity.textureview; + +import android.os.Bundle; +import android.support.design.widget.CoordinatorLayout; +import android.support.design.widget.FloatingActionButton; +import android.support.v7.app.ActionBar; +import android.support.v7.app.AppCompatActivity; +import android.view.View; + +import com.mapbox.mapboxsdk.maps.MapView; +import com.mapbox.mapboxsdk.maps.MapboxMap; +import com.mapbox.mapboxsdk.maps.OnMapReadyCallback; +import com.mapbox.mapboxsdk.testapp.R; + +/** + * Test resizing a {@link android.view.TextureView} backed map on the fly. + */ +public class TextureViewResizeActivity extends AppCompatActivity { + + private MapView mapView; + private MapboxMap mapboxMap; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_textureview_resize); + setupToolbar(); + setupMapView(savedInstanceState); + setupFab(); + } + + private void setupToolbar() { + ActionBar actionBar = getSupportActionBar(); + if (actionBar != null) { + getSupportActionBar().setDisplayHomeAsUpEnabled(true); + getSupportActionBar().setHomeButtonEnabled(true); + } + } + + private void setupMapView(Bundle savedInstanceState) { + mapView = (MapView) findViewById(R.id.mapView); + mapView.getMapAsync(new OnMapReadyCallback() { + @Override + public void onMapReady(MapboxMap mapboxMap) { + TextureViewResizeActivity.this.mapboxMap = mapboxMap; + } + }); + } + + private void setupFab() { + FloatingActionButton fabDebug = (FloatingActionButton) findViewById(R.id.fabResize); + fabDebug.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + if (mapView != null) { + View parent = findViewById(R.id.coordinator_layout); + int width = parent.getWidth() == mapView.getWidth() ? parent.getWidth() / 2 : parent.getWidth(); + int height = parent.getHeight() == mapView.getHeight() ? parent.getHeight() / 2 : parent.getHeight(); + mapView.setLayoutParams(new CoordinatorLayout.LayoutParams(width, height)); + } + } + }); + } + + @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 + protected void onSaveInstanceState(Bundle outState) { + super.onSaveInstanceState(outState); + mapView.onSaveInstanceState(outState); + } + + @Override + protected void onDestroy() { + super.onDestroy(); + mapView.onDestroy(); + } + + @Override + public void onLowMemory() { + super.onLowMemory(); + mapView.onLowMemory(); + } + +} diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/layout/activity_textureview_animate.xml b/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/layout/activity_textureview_animate.xml new file mode 100644 index 0000000000..de0ef0ef36 --- /dev/null +++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/layout/activity_textureview_animate.xml @@ -0,0 +1,29 @@ + + + + + + + + + + diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/layout/activity_textureview_debug_mode.xml b/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/layout/activity_textureview_debug_mode.xml new file mode 100644 index 0000000000..480de550ad --- /dev/null +++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/layout/activity_textureview_debug_mode.xml @@ -0,0 +1,98 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/layout/activity_textureview_resize.xml b/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/layout/activity_textureview_resize.xml new file mode 100644 index 0000000000..2baa3d39dd --- /dev/null +++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/layout/activity_textureview_resize.xml @@ -0,0 +1,29 @@ + + + + + + + + + + diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/values/categories.xml b/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/values/categories.xml index 9ade28ae8d..dbc6b59db6 100644 --- a/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/values/categories.xml +++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/values/categories.xml @@ -14,4 +14,5 @@ Styling Features Storage + Texture View \ No newline at end of file diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/values/descriptions.xml b/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/values/descriptions.xml index a2bf1d8596..33d9638712 100644 --- a/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/values/descriptions.xml +++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/values/descriptions.xml @@ -64,4 +64,7 @@ Show how to add a marker to a Snapshot Use Android SDK Animators to animate camera position changes Use Android SDK Views as symbols + Use TextureView to render the map + Resize a map rendered on a TextureView + Animate a map rendered on a TextureView \ No newline at end of file diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/values/titles.xml b/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/values/titles.xml index 1fb2f6ba7f..b90cedc518 100644 --- a/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/values/titles.xml +++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/values/titles.xml @@ -64,4 +64,7 @@ Map Snapshot with marker Animator animation SymbolGenerator + TextureView debug + TextureView resize + TextureView animation \ No newline at end of file -- cgit v1.2.1