diff options
author | tobrun <tobrun.van.nuland@gmail.com> | 2019-01-15 13:52:25 +0100 |
---|---|---|
committer | tobrun <tobrun.van.nuland@gmail.com> | 2019-01-15 13:54:52 +0100 |
commit | 58deb2c02e99824d67b7520c4a1cc4cee3249f90 (patch) | |
tree | 5e2abe78b51b62631b91450dd176e64df31dd59b | |
parent | e6e07a68094bb753da3714fdeb22d84760193d33 (diff) | |
download | qtlocation-mapboxgl-upstream/tvn-reset-fps.tar.gz |
[android] - allow reset fps listener, update debug mode activity withupstream/tvn-reset-fps
menu options
4 files changed, 70 insertions, 59 deletions
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/NativeMapView.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/NativeMapView.java index 3fe98efa34..894cbbf27b 100755 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/NativeMapView.java +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/NativeMapView.java @@ -1391,27 +1391,30 @@ final class NativeMapView implements NativeMap { } @Override - public void setOnFpsChangedListener(@NonNull final MapboxMap.OnFpsChangedListener listener) { + public void setOnFpsChangedListener(@Nullable final MapboxMap.OnFpsChangedListener listener) { final Handler handler = new Handler(); mapRenderer.queueEvent(new Runnable() { @Override public void run() { - mapRenderer.setOnFpsChangedListener(new MapboxMap.OnFpsChangedListener() { - @Override - public void onFpsChanged(final double fps) { - handler.post(new Runnable() { - - @Override - public void run() { - listener.onFpsChanged(fps); - } - - }); - } - }); + if (listener != null) { + mapRenderer.setOnFpsChangedListener(new MapboxMap.OnFpsChangedListener() { + @Override + public void onFpsChanged(final double fps) { + handler.post(new Runnable() { + + @Override + public void run() { + listener.onFpsChanged(fps); + } + + }); + } + }); + } else { + mapRenderer.setOnFpsChangedListener(null); + } } - }); } diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/maplayout/DebugModeActivity.java b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/maplayout/DebugModeActivity.java index 0add72ec2d..9d52798d00 100644 --- a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/maplayout/DebugModeActivity.java +++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/maplayout/DebugModeActivity.java @@ -9,6 +9,7 @@ import android.support.v7.app.ActionBar; import android.support.v7.app.ActionBarDrawerToggle; import android.support.v7.app.AppCompatActivity; import android.view.LayoutInflater; +import android.view.Menu; import android.view.MenuItem; import android.view.View; import android.view.ViewGroup; @@ -36,13 +37,14 @@ import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.visibility; /** * Test activity showcasing the different debug modes and allows to cycle between the default map styles. */ -public class DebugModeActivity extends AppCompatActivity implements OnMapReadyCallback { +public class DebugModeActivity extends AppCompatActivity implements OnMapReadyCallback, MapboxMap.OnFpsChangedListener { private MapView mapView; private MapboxMap mapboxMap; private ActionBarDrawerToggle actionBarDrawerToggle; private int currentStyleIndex; private IdleZoomListener idleZoomListener; + private boolean isReportFps = true; private static final String[] STYLES = new String[] { Style.MAPBOX_STREETS, @@ -54,6 +56,7 @@ public class DebugModeActivity extends AppCompatActivity implements OnMapReadyCa Style.TRAFFIC_DAY, Style.TRAFFIC_NIGHT }; + private TextView fpsView; @Override protected void onCreate(Bundle savedInstanceState) { @@ -63,7 +66,6 @@ public class DebugModeActivity extends AppCompatActivity implements OnMapReadyCa setupMapView(savedInstanceState); setupDebugChangeView(); setupStyleChangeView(); - setupFpsChangeView(); } private void setupToolbar() { @@ -113,10 +115,13 @@ public class DebugModeActivity extends AppCompatActivity implements OnMapReadyCa } private void setFpsView() { - final TextView fpsView = findViewById(R.id.fpsView); - mapboxMap.setOnFpsChangedListener(fps -> - fpsView.setText(String.format(Locale.US, "FPS: %4.2f", fps)) - ); + fpsView = findViewById(R.id.fpsView); + mapboxMap.setOnFpsChangedListener(this); + } + + @Override + public void onFpsChanged(double fps) { + fpsView.setText(String.format(Locale.US, "FPS: %4.2f", fps)); } private void setupNavigationView(List<Layer> layerList) { @@ -173,18 +178,26 @@ public class DebugModeActivity extends AppCompatActivity implements OnMapReadyCa }); } - private void setupFpsChangeView() { - findViewById(R.id.fps_30).setOnClickListener(view -> { + @Override + public boolean onOptionsItemSelected(MenuItem item) { + int itemId = item.getItemId(); + if (itemId == R.id.menu_action_toggle_report_fps) { + isReportFps = !isReportFps; + fpsView.setVisibility(isReportFps ? View.VISIBLE : View.GONE); + mapboxMap.setOnFpsChangedListener(isReportFps ? this : null); + } else if (itemId == R.id.menu_action_limit_to_30_fps) { mapView.setMaximumFps(30); - }); - findViewById(R.id.fps_60).setOnClickListener(view -> { + } else if (itemId == R.id.menu_action_limit_to_60_fps) { mapView.setMaximumFps(60); - }); + } + + return actionBarDrawerToggle.onOptionsItemSelected(item) || super.onOptionsItemSelected(item); } @Override - public boolean onOptionsItemSelected(MenuItem item) { - return actionBarDrawerToggle.onOptionsItemSelected(item) || super.onOptionsItemSelected(item); + public boolean onCreateOptionsMenu(Menu menu) { + getMenuInflater().inflate(R.menu.menu_debug, menu); + return true; } @Override diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/layout/activity_debug_mode.xml b/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/layout/activity_debug_mode.xml index 1b185ab9c8..af2123028b 100644 --- a/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/layout/activity_debug_mode.xml +++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/layout/activity_debug_mode.xml @@ -20,23 +20,24 @@ android:id="@+id/textZoom" android:layout_width="wrap_content" android:layout_height="wrap_content" - android:layout_gravity="bottom|start" android:layout_margin="8dp" + android:text="Zoom: 0.00" + android:paddingTop="4dp" android:textIsSelectable="true" - android:textSize="14sp" - app:layout_anchor="@id/bottom_sheet" - app:layout_anchorGravity="bottom|start"/> + android:textSize="14sp" /> <TextView android:id="@+id/fpsView" android:layout_width="wrap_content" android:layout_height="wrap_content" - android:layout_gravity="top|end" android:layout_margin="8dp" - android:textIsSelectable="true" - android:textSize="14sp" app:layout_anchor="@id/textZoom" - app:layout_anchorGravity="top"/> + app:layout_anchorGravity="bottom" + android:text="FPS: 60.00" + android:paddingTop="16dp" + android:layout_marginTop="64dp" + android:textIsSelectable="true" + android:textSize="14sp"/> <android.support.v4.widget.NestedScrollView android:id="@+id/bottom_sheet" @@ -71,29 +72,6 @@ app:layout_anchor="@id/bottom_sheet" app:layout_anchorGravity="bottom|end"/> - <Button - android:id="@+id/fps_60" - android:layout_width="wrap_content" - android:layout_height="wrap_content" - android:layout_gravity="end|start" - app:backgroundTint="@color/primary" - android:layout_margin="@dimen/fab_margin" - android:text="@string/fps60" - app:layout_anchor="@id/bottom_sheet" - app:layout_anchorGravity="top|end"/> - - <Button - android:id="@+id/fps_30" - android:layout_width="wrap_content" - android:layout_height="wrap_content" - android:layout_gravity="top|end" - android:layout_marginBottom="82dp" - app:backgroundTint="@color/primary" - android:layout_marginEnd="@dimen/fab_margin" - android:layout_marginRight="@dimen/fab_margin" - android:text="@string/fps30" - app:layout_anchor="@id/fps_60" - app:layout_anchorGravity="top"/> </android.support.design.widget.CoordinatorLayout> <android.support.design.widget.NavigationView diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/menu/menu_debug.xml b/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/menu/menu_debug.xml new file mode 100644 index 0000000000..fb6ac23ba5 --- /dev/null +++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/menu/menu_debug.xml @@ -0,0 +1,17 @@ +<?xml version="1.0" encoding="utf-8"?> +<menu xmlns:android="http://schemas.android.com/apk/res/android" + xmlns:app="http://schemas.android.com/apk/res-auto"> + <item + android:id="@+id/menu_action_toggle_report_fps" + android:title="Toggle report FPS" + app:showAsAction="never" /> + <item + android:id="@+id/menu_action_limit_to_30_fps" + android:title="Limit FPS to 30" + app:showAsAction="never" /> + <item + android:id="@+id/menu_action_limit_to_60_fps" + android:title="Limit FPS to 60" + app:showAsAction="never" /> + +</menu> |