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).
|
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
|
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_descr">Select Driving Region : US, Europe, UK, Asia and Others</string>
|
||||||
<string name="driving_region">Driving Region</string>
|
<string name="driving_region">Driving Region</string>
|
||||||
<string name="driving_region_japan">Japan</string>
|
<string name="driving_region_japan">Japan</string>
|
||||||
|
|
|
@ -1,10 +1,18 @@
|
||||||
package net.osmand.plus.development;
|
package net.osmand.plus.development;
|
||||||
|
|
||||||
|
import java.util.EnumSet;
|
||||||
|
|
||||||
|
import net.osmand.plus.ApplicationMode;
|
||||||
import net.osmand.plus.OsmandApplication;
|
import net.osmand.plus.OsmandApplication;
|
||||||
import net.osmand.plus.OsmandPlugin;
|
import net.osmand.plus.OsmandPlugin;
|
||||||
import net.osmand.plus.R;
|
import net.osmand.plus.R;
|
||||||
import net.osmand.plus.activities.MapActivity;
|
import net.osmand.plus.activities.MapActivity;
|
||||||
import net.osmand.plus.activities.SettingsActivity;
|
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.content.Intent;
|
||||||
import android.preference.Preference;
|
import android.preference.Preference;
|
||||||
import android.preference.Preference.OnPreferenceClickListener;
|
import android.preference.Preference.OnPreferenceClickListener;
|
||||||
|
@ -13,6 +21,7 @@ import android.preference.PreferenceScreen;
|
||||||
public class OsmandDevelopmentPlugin extends OsmandPlugin {
|
public class OsmandDevelopmentPlugin extends OsmandPlugin {
|
||||||
private static final String ID = "osmand.development";
|
private static final String ID = "osmand.development";
|
||||||
private OsmandApplication app;
|
private OsmandApplication app;
|
||||||
|
private TextInfoWidget fps;
|
||||||
|
|
||||||
public OsmandDevelopmentPlugin(OsmandApplication app) {
|
public OsmandDevelopmentPlugin(OsmandApplication app) {
|
||||||
this.app = app;
|
this.app = app;
|
||||||
|
@ -36,6 +45,33 @@ public class OsmandDevelopmentPlugin extends OsmandPlugin {
|
||||||
return app.getString(R.string.debugging_and_development);
|
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
|
@Override
|
||||||
public void settingsActivityCreate(final SettingsActivity activity, PreferenceScreen screen) {
|
public void settingsActivityCreate(final SettingsActivity activity, PreferenceScreen screen) {
|
||||||
Preference grp = new Preference(activity);
|
Preference grp = new Preference(activity);
|
||||||
|
@ -51,7 +87,4 @@ public class OsmandDevelopmentPlugin extends OsmandPlugin {
|
||||||
screen.addPreference(grp);
|
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 {
|
public class OsmandMapTileView extends SurfaceView implements IMapDownloaderCallback, Callback {
|
||||||
|
|
||||||
protected final static int LOWEST_ZOOM_TO_ROTATE = 10;
|
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 fpsMeasureCount = 0;
|
||||||
private int fpsMeasureMs = 0;
|
private int fpsMeasureMs = 0;
|
||||||
|
private long fpsFirstMeasurement = 0;
|
||||||
|
private float fps;
|
||||||
|
|
||||||
protected static final int emptyTileDivisor = 16;
|
protected static final int emptyTileDivisor = 16;
|
||||||
|
|
||||||
|
@ -494,8 +496,6 @@ public class OsmandMapTileView extends SurfaceView implements IMapDownloaderCall
|
||||||
private void refreshMapInternal(boolean updateVectorRendering) {
|
private void refreshMapInternal(boolean updateVectorRendering) {
|
||||||
handler.removeMessages(1);
|
handler.removeMessages(1);
|
||||||
long ms = SystemClock.elapsedRealtime();
|
long ms = SystemClock.elapsedRealtime();
|
||||||
// long time = System.currentTimeMillis();
|
|
||||||
|
|
||||||
boolean useInternet = getSettings().USE_INTERNET_TO_DOWNLOAD_TILES.get();
|
boolean useInternet = getSettings().USE_INTERNET_TO_DOWNLOAD_TILES.get();
|
||||||
if (useInternet) {
|
if (useInternet) {
|
||||||
if(application != null) {
|
if(application != null) {
|
||||||
|
@ -521,29 +521,41 @@ public class OsmandMapTileView extends SurfaceView implements IMapDownloaderCall
|
||||||
latlonRect.left = (float) MapUtils.getLongitudeFromTile(nzoom, tilesRect.left);
|
latlonRect.left = (float) MapUtils.getLongitudeFromTile(nzoom, tilesRect.left);
|
||||||
latlonRect.bottom = (float) MapUtils.getLatitudeFromTile(nzoom, tilesRect.bottom);
|
latlonRect.bottom = (float) MapUtils.getLatitudeFromTile(nzoom, tilesRect.bottom);
|
||||||
latlonRect.right = (float) MapUtils.getLongitudeFromTile(nzoom, tilesRect.right);
|
latlonRect.right = (float) MapUtils.getLongitudeFromTile(nzoom, tilesRect.right);
|
||||||
if(nightMode){
|
if (nightMode) {
|
||||||
canvas.drawARGB(255, 100, 100, 100);
|
canvas.drawARGB(255, 100, 100, 100);
|
||||||
} else {
|
} else {
|
||||||
canvas.drawARGB(255, 225, 225, 225);
|
canvas.drawARGB(255, 225, 225, 225);
|
||||||
}
|
}
|
||||||
drawOverMap(canvas, latlonRect, tilesRect, new DrawSettings(nightMode, updateVectorRendering));
|
drawOverMap(canvas, latlonRect, tilesRect, new DrawSettings(nightMode, updateVectorRendering));
|
||||||
// log.info("Draw with layers " + (System.currentTimeMillis() - time));
|
|
||||||
} finally {
|
} finally {
|
||||||
holder.unlockCanvasAndPost(canvas);
|
holder.unlockCanvasAndPost(canvas);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
if (MEASURE_FPS) {
|
||||||
if(MEASURE_FPS) {
|
fpsMeasureMs += SystemClock.elapsedRealtime() - ms;
|
||||||
fpsMeasureMs += SystemClock.elapsedRealtime() - ms;
|
fpsMeasureCount++;
|
||||||
fpsMeasureCount ++;
|
if (fpsMeasureCount > 10 || (ms - fpsFirstMeasurement) > 400) {
|
||||||
if(fpsMeasureCount > 4) {
|
fpsFirstMeasurement = ms;
|
||||||
log.debug("FPS speed " + (1000*fpsMeasureCount/fpsMeasureMs));
|
fps = (1000f * fpsMeasureCount / fpsMeasureMs);
|
||||||
fpsMeasureCount = 0;
|
fpsMeasureCount = 0;
|
||||||
fpsMeasureMs = 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) {
|
private void drawOverMap(Canvas canvas, RectF latlonRect, RectF tilesRect, DrawSettings drawSettings) {
|
||||||
int w = getCenterPointX();
|
int w = getCenterPointX();
|
||||||
int h = getCenterPointY();
|
int h = getCenterPointY();
|
||||||
|
|
Loading…
Reference in a new issue