[android] - allow reset fps listener, update debug mode activity with
menu options
This commit is contained in:
@@ -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() {
|
||||
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);
|
||||
}
|
||||
@Override
|
||||
public void run() {
|
||||
listener.onFpsChanged(fps);
|
||||
}
|
||||
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
});
|
||||
} else {
|
||||
mapRenderer.setOnFpsChangedListener(null);
|
||||
}
|
||||
}
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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>
|
||||
Reference in New Issue
Block a user