Introduce measure fps widget
This commit is contained in:
parent
879df0992e
commit
d183c2b8ae
3 changed files with 62 additions and 17 deletions
|
@ -9,7 +9,7 @@
|
|||
3. All your modified/created strings are in the top of the file (to make easier find what\'s translated).
|
||||
PLEASE: Have a look at http://code.google.com/p/osmand/wiki/UIConsistency, it may really improve your and our work :-) Thx - Hardy
|
||||
-->
|
||||
|
||||
<string name="map_widget_fps_info">FPS info</string>
|
||||
<string name="driving_region_descr">Select Driving Region : US, Europe, UK, Asia and Others</string>
|
||||
<string name="driving_region">Driving Region</string>
|
||||
<string name="driving_region_japan">Japan</string>
|
||||
|
|
|
@ -1,10 +1,18 @@
|
|||
package net.osmand.plus.development;
|
||||
|
||||
import java.util.EnumSet;
|
||||
|
||||
import net.osmand.plus.ApplicationMode;
|
||||
import net.osmand.plus.OsmandApplication;
|
||||
import net.osmand.plus.OsmandPlugin;
|
||||
import net.osmand.plus.R;
|
||||
import net.osmand.plus.activities.MapActivity;
|
||||
import net.osmand.plus.activities.SettingsActivity;
|
||||
import net.osmand.plus.audionotes.AudioNotesLayer;
|
||||
import net.osmand.plus.views.MapInfoLayer;
|
||||
import net.osmand.plus.views.OsmandMapLayer.DrawSettings;
|
||||
import net.osmand.plus.views.OsmandMapTileView;
|
||||
import net.osmand.plus.views.mapwidgets.TextInfoWidget;
|
||||
import android.content.Intent;
|
||||
import android.preference.Preference;
|
||||
import android.preference.Preference.OnPreferenceClickListener;
|
||||
|
@ -13,6 +21,7 @@ import android.preference.PreferenceScreen;
|
|||
public class OsmandDevelopmentPlugin extends OsmandPlugin {
|
||||
private static final String ID = "osmand.development";
|
||||
private OsmandApplication app;
|
||||
private TextInfoWidget fps;
|
||||
|
||||
public OsmandDevelopmentPlugin(OsmandApplication app) {
|
||||
this.app = app;
|
||||
|
@ -36,6 +45,33 @@ public class OsmandDevelopmentPlugin extends OsmandPlugin {
|
|||
return app.getString(R.string.debugging_and_development);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void registerLayers(MapActivity activity) {
|
||||
registerWidget(activity);
|
||||
}
|
||||
|
||||
|
||||
private void registerWidget(MapActivity activity) {
|
||||
MapInfoLayer mapInfoLayer = activity.getMapLayers().getMapInfoLayer();
|
||||
final OsmandMapTileView mv = activity.getMapView();
|
||||
if (mapInfoLayer != null) {
|
||||
fps = new TextInfoWidget(activity, 0, mapInfoLayer.getPaintText(), mapInfoLayer.getPaintSubText()) {
|
||||
@Override
|
||||
public boolean updateInfo(DrawSettings drawSettings) {
|
||||
if(!mv.isMeasureFPS()) {
|
||||
mv.setMeasureFPS(true);
|
||||
}
|
||||
setText(Float.toString(mv.getFPS()), "FPS");
|
||||
return true;
|
||||
}
|
||||
};
|
||||
mapInfoLayer.getMapInfoControls().registerSideWidget(fps, 0,
|
||||
R.string.map_widget_fps_info, "fps", false, EnumSet.allOf(ApplicationMode.class),
|
||||
EnumSet.noneOf(ApplicationMode.class), 30);
|
||||
mapInfoLayer.recreateControls();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void settingsActivityCreate(final SettingsActivity activity, PreferenceScreen screen) {
|
||||
Preference grp = new Preference(activity);
|
||||
|
@ -51,7 +87,4 @@ public class OsmandDevelopmentPlugin extends OsmandPlugin {
|
|||
screen.addPreference(grp);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void registerLayers(MapActivity activity) {
|
||||
}
|
||||
}
|
||||
|
|
|
@ -52,9 +52,11 @@ import android.widget.Toast;
|
|||
public class OsmandMapTileView extends SurfaceView implements IMapDownloaderCallback, Callback {
|
||||
|
||||
protected final static int LOWEST_ZOOM_TO_ROTATE = 10;
|
||||
private static boolean MEASURE_FPS = true;
|
||||
private boolean MEASURE_FPS = false;
|
||||
private int fpsMeasureCount = 0;
|
||||
private int fpsMeasureMs = 0;
|
||||
private long fpsFirstMeasurement = 0;
|
||||
private float fps;
|
||||
|
||||
protected static final int emptyTileDivisor = 16;
|
||||
|
||||
|
@ -494,8 +496,6 @@ public class OsmandMapTileView extends SurfaceView implements IMapDownloaderCall
|
|||
private void refreshMapInternal(boolean updateVectorRendering) {
|
||||
handler.removeMessages(1);
|
||||
long ms = SystemClock.elapsedRealtime();
|
||||
// long time = System.currentTimeMillis();
|
||||
|
||||
boolean useInternet = getSettings().USE_INTERNET_TO_DOWNLOAD_TILES.get();
|
||||
if (useInternet) {
|
||||
if(application != null) {
|
||||
|
@ -527,22 +527,34 @@ public class OsmandMapTileView extends SurfaceView implements IMapDownloaderCall
|
|||
canvas.drawARGB(255, 225, 225, 225);
|
||||
}
|
||||
drawOverMap(canvas, latlonRect, tilesRect, new DrawSettings(nightMode, updateVectorRendering));
|
||||
// log.info("Draw with layers " + (System.currentTimeMillis() - time));
|
||||
} finally {
|
||||
holder.unlockCanvasAndPost(canvas);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (MEASURE_FPS) {
|
||||
fpsMeasureMs += SystemClock.elapsedRealtime() - ms;
|
||||
fpsMeasureCount++;
|
||||
if(fpsMeasureCount > 4) {
|
||||
log.debug("FPS speed " + (1000*fpsMeasureCount/fpsMeasureMs));
|
||||
if (fpsMeasureCount > 10 || (ms - fpsFirstMeasurement) > 400) {
|
||||
fpsFirstMeasurement = ms;
|
||||
fps = (1000f * fpsMeasureCount / fpsMeasureMs);
|
||||
fpsMeasureCount = 0;
|
||||
fpsMeasureMs = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isMeasureFPS() {
|
||||
return MEASURE_FPS;
|
||||
}
|
||||
|
||||
public void setMeasureFPS(boolean measureFPS) {
|
||||
MEASURE_FPS = measureFPS;
|
||||
}
|
||||
|
||||
public float getFPS(){
|
||||
return fps;
|
||||
}
|
||||
|
||||
private void drawOverMap(Canvas canvas, RectF latlonRect, RectF tilesRect, DrawSettings drawSettings) {
|
||||
int w = getCenterPointX();
|
||||
|
|
Loading…
Reference in a new issue