Improve code / xml formatting, closes #54

This commit is contained in:
Emux
2016-07-09 19:45:22 +03:00
parent 7919d0ab9c
commit e793e8851b
458 changed files with 58405 additions and 63062 deletions

View File

@@ -1,20 +0,0 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<launchConfiguration type="org.eclipse.ant.AntBuilderLaunchConfigurationType">
<booleanAttribute key="org.eclipse.ui.externaltools.ATTR_BUILDER_ENABLED" value="false"/>
<stringAttribute key="org.eclipse.ui.externaltools.ATTR_DISABLED_BUILDER" value="org.eclipse.cdt.managedbuilder.core.genmakebuilder"/>
<mapAttribute key="org.eclipse.ui.externaltools.ATTR_TOOL_ARGUMENTS">
<mapEntry key="?children?" value="?name?=outputEntries\|?children?=?name?=entry\\\\\\\|\\\|?name?=entry\\\\\\\|\\\|\||"/>
<mapEntry key="?name?" value=""/>
<mapEntry key="org.eclipse.cdt.make.core.append_environment" value="true"/>
<mapEntry key="org.eclipse.cdt.make.core.buildArguments" value=""/>
<mapEntry key="org.eclipse.cdt.make.core.buildCommand" value="ndk-build"/>
<mapEntry key="org.eclipse.cdt.make.core.cleanBuildTarget" value="clean"/>
<mapEntry key="org.eclipse.cdt.make.core.contents" value="org.eclipse.cdt.make.core.activeConfigSettings"/>
<mapEntry key="org.eclipse.cdt.make.core.enableAutoBuild" value="false"/>
<mapEntry key="org.eclipse.cdt.make.core.enableCleanBuild" value="true"/>
<mapEntry key="org.eclipse.cdt.make.core.enableFullBuild" value="true"/>
<mapEntry key="org.eclipse.cdt.make.core.stopOnError" value="true"/>
<mapEntry key="org.eclipse.cdt.make.core.useDefaultBuildCmd" value="true"/>
</mapAttribute>
<booleanAttribute key="org.eclipse.ui.externaltools.ATTR_TRIGGERS_CONFIGURED" value="true"/>
</launchConfiguration>

View File

@@ -6,4 +6,4 @@
android:minSdkVersion="10"
android:targetSdkVersion="22" />
</manifest>
</manifest>

View File

@@ -1,18 +0,0 @@
# This file is used to override default values used by the Ant build system.
#
# This file must be checked in Version Control Systems, as it is
# integral to the build system of your project.
# This file is only used by the Ant script.
# You can use this to override default values such as
# 'source.dir' for the location of your java source folder and
# 'out.dir' for the location of your output folder.
# You can also use it define how the release builds are signed by declaring
# the following properties:
# 'key.store' for the location of your keystore and
# 'key.alias' for the name of the key to use.
# The password will be asked during the build when you use the 'release' target.
#jar.libs.dir=

View File

@@ -1,85 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project name="VectorTileMap" default="help">
<!-- The local.properties file is created and updated by the 'android' tool.
It contains the path to the SDK. It should *NOT* be checked into
Version Control Systems. -->
<loadproperties srcFile="local.properties" />
<!-- The ant.properties file can be created by you. It is only edited by the
'android' tool to add properties to it.
This is the place to change some Ant specific build properties.
Here are some properties you may want to change/update:
source.dir
The name of the source directory. Default is 'src'.
out.dir
The name of the output directory. Default is 'bin'.
For other overridable properties, look at the beginning of the rules
files in the SDK, at tools/ant/build.xml
Properties related to the SDK location or the project target should
be updated using the 'android' tool with the 'update' action.
This file is an integral part of the build system for your
application and should be checked into Version Control Systems.
-->
<property file="ant.properties" />
<!-- The project.properties file is created and updated by the 'android'
tool, as well as ADT.
This contains project specific properties such as project target, and library
dependencies. Lower level build properties are stored in ant.properties
(or in .classpath for Eclipse projects).
This file is an integral part of the build system for your
application and should be checked into Version Control Systems. -->
<loadproperties srcFile="project.properties" />
<!-- quick check on sdk.dir -->
<fail
message="sdk.dir is missing. Make sure to generate local.properties using 'android update project'"
unless="sdk.dir"
/>
<!-- extension targets. Uncomment the ones where you want to do custom work
in between standard targets -->
<!--
<target name="-pre-build">
</target>
<target name="-pre-compile">
</target>
/* This is typically used for code obfuscation.
Compiled code location: ${out.classes.absolute.dir}
If this is not done in place, override ${out.dex.input.absolute.dir} */
<target name="-post-compile">
</target>
-->
<!-- Import the actual build file.
To customize existing targets, there are two options:
- Customize only one target:
- copy/paste the target into this file, *before* the
<import> task.
- customize it to your needs.
- Customize the whole content of build.xml
- copy/paste the content of the rules files (minus the top node)
into this file, replacing the <import> task.
- customize to your needs.
***********************
****** IMPORTANT ******
***********************
In all cases you must update the value of version-tag below to read 'custom' instead of an integer,
in order to avoid having your file be overridden by tools such as "android update project"
-->
<!-- version-tag: 1 -->
<import file="${sdk.dir}/tools/ant/build.xml" />
</project>

View File

@@ -1,4 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<lint>
<issue id="MissingTranslation" severity="warning" />
</lint>

View File

@@ -1,44 +0,0 @@
-optimizationpasses 5
-dontusemixedcaseclassnames
-dontskipnonpubliclibraryclasses
-dontskipnonpubliclibraryclassmembers
-dontpreverify
-verbose
-libraryjars lib/postgresql-9.0-801.jdbc4.jar
-ignorewarnings
-optimizations !code/simplification/arithmetic,!field/*,!class/merging/*
-keep public class * extends android.app.Activity
-keep public class * extends android.app.Application
-keep public class * extends android.app.Service
-keep public class * extends android.content.BroadcastReceiver
-keep public class * extends android.content.ContentProvider
-keep public class * extends android.app.backup.BackupAgentHelper
-keep public class * extends android.preference.Preference
-keep public class com.android.vending.licensing.ILicensingService
-keepclasseswithmembernames class * {
native <methods>;
}
-keepclasseswithmembers class * {
public <init>(android.content.Context, android.util.AttributeSet);
}
-keepclasseswithmembers class * {
public <init>(android.content.Context, android.util.AttributeSet, int);
}
-keepclassmembers class * extends android.app.Activity {
public void *(android.view.View);
}
-keepclassmembers enum * {
public static **[] values();
public static ** valueOf(java.lang.String);
}
-keep class * implements android.os.Parcelable {
public static final android.os.Parcelable$Creator *;
}

View File

@@ -3,15 +3,12 @@
#
# This file must be checked in Version Control Systems.
#
# To customize properties used by the Ant build system use,
# To customize properties used by the Ant build system edit
# "ant.properties", and override values to adapt the script to your
# project structure.
#
# To enable ProGuard to shrink and obfuscate your code, uncomment this (available properties: sdk.dir, user.home):
#proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt:proguard-project.txt
# Indicates whether an apk should be generated for each density.
split.density=false
# Project target.
target=android-21
#proguard.config=proguard.cfg
android.library=true
android.library.reference.1=../appcompat
target=android-23

View File

@@ -16,31 +16,31 @@
*/
package org.oscim.android;
import java.io.IOException;
import java.io.InputStream;
import android.content.Context;
import org.oscim.backend.AssetAdapter;
import android.content.Context;
import java.io.IOException;
import java.io.InputStream;
public class AndroidAssets extends AssetAdapter {
Context mContext;
Context mContext;
public static void init(Context ctx) {
AssetAdapter.init(new AndroidAssets(ctx));
}
public static void init(Context ctx) {
AssetAdapter.init(new AndroidAssets(ctx));
}
private AndroidAssets(Context ctx) {
mContext = ctx;
}
private AndroidAssets(Context ctx) {
mContext = ctx;
}
@Override
public InputStream openFileAsStream(String fileName) {
try {
return mContext.getAssets().open(fileName);
} catch (IOException e) {
e.printStackTrace();
return null;
}
}
@Override
public InputStream openFileAsStream(String fileName) {
try {
return mContext.getAssets().open(fileName);
} catch (IOException e) {
e.printStackTrace();
return null;
}
}
}

View File

@@ -16,56 +16,56 @@
*/
package org.oscim.android;
import org.oscim.map.Map;
import android.content.Context;
import android.hardware.Sensor;
import android.hardware.SensorEvent;
import android.hardware.SensorEventListener;
import android.hardware.SensorManager;
import org.oscim.map.Map;
public class Compass {
private final SensorEventListener mListener = new SensorEventListener() {
@Override
public void onSensorChanged(SensorEvent event) {
if (Math.abs(event.values[0] - mAngle) > 0.25) {
mAngle = event.values[0];
private final SensorEventListener mListener = new SensorEventListener() {
@Override
public void onSensorChanged(SensorEvent event) {
if (Math.abs(event.values[0] - mAngle) > 0.25) {
mAngle = event.values[0];
if (mMap != null) {
mMap.viewport().setRotation(-mAngle);
mMap.updateMap(true);
}
}
}
if (mMap != null) {
mMap.viewport().setRotation(-mAngle);
mMap.updateMap(true);
}
}
}
@Override
public void onAccuracyChanged(Sensor sensor, int accuracy) {
}
};
@Override
public void onAccuracyChanged(Sensor sensor, int accuracy) {
}
};
/* package */float mAngle = 0;
/* package */Map mMap;
/* package */ float mAngle = 0;
/* package */ Map mMap;
private final SensorManager mSensorManager;
private final Sensor mSensor;
private final SensorManager mSensorManager;
private final Sensor mSensor;
@SuppressWarnings("deprecation")
public Compass(Context context, Map map) {
mMap = map;
mSensorManager = (SensorManager) context
.getSystemService(Context.SENSOR_SERVICE);
@SuppressWarnings("deprecation")
public Compass(Context context, Map map) {
mMap = map;
mSensorManager = (SensorManager) context
.getSystemService(Context.SENSOR_SERVICE);
mSensor = mSensorManager.getDefaultSensor(Sensor.TYPE_ORIENTATION);
}
mSensor = mSensorManager.getDefaultSensor(Sensor.TYPE_ORIENTATION);
}
public void enable() {
mSensorManager.registerListener(mListener, mSensor,
SensorManager.SENSOR_DELAY_UI);
}
public void enable() {
mSensorManager.registerListener(mListener, mSensor,
SensorManager.SENSOR_DELAY_UI);
}
public void disable() {
mSensorManager.unregisterListener(mListener);
mMap.viewport().setRotation(0);
}
public void disable() {
mSensorManager.unregisterListener(mListener);
mMap.viewport().setRotation(0);
}
}

View File

@@ -16,80 +16,80 @@
*/
package org.oscim.android;
import org.oscim.core.MapPosition;
import org.oscim.map.Map;
import android.app.Activity;
import android.content.Context;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import org.oscim.core.MapPosition;
import org.oscim.map.Map;
public class MapPreferences {
private static final String KEY_LATITUDE = "latitude";
private static final String KEY_LONGITUDE = "longitude";
private static final String KEY_SCALE = "scale";
private static final String KEY_LATITUDE = "latitude";
private static final String KEY_LONGITUDE = "longitude";
private static final String KEY_SCALE = "scale";
private final String PREFERENCES_FILE;
Context ctx;
private final String PREFERENCES_FILE;
Context ctx;
public MapPreferences(String name, Context ctx) {
this.ctx = ctx;
this.PREFERENCES_FILE = name;
}
public MapPreferences(String name, Context ctx) {
this.ctx = ctx;
this.PREFERENCES_FILE = name;
}
public void clear() {
Editor editor = ctx.getSharedPreferences(PREFERENCES_FILE, Activity.MODE_PRIVATE).edit();
editor.clear();
editor.apply();
}
public void clear() {
Editor editor = ctx.getSharedPreferences(PREFERENCES_FILE, Activity.MODE_PRIVATE).edit();
editor.clear();
editor.apply();
}
private void putDouble(Editor editor, String key, double value) {
editor.putLong(key, Double.doubleToLongBits(value));
}
private void putDouble(Editor editor, String key, double value) {
editor.putLong(key, Double.doubleToLongBits(value));
}
private double getDouble(SharedPreferences prefs, String key) {
return Double.longBitsToDouble(prefs.getLong(key, 0));
}
private double getDouble(SharedPreferences prefs, String key) {
return Double.longBitsToDouble(prefs.getLong(key, 0));
}
public void save(Map map) {
save(map.getMapPosition());
}
public void save(Map map) {
save(map.getMapPosition());
}
public void save(MapPosition pos) {
Editor editor = ctx.getSharedPreferences(PREFERENCES_FILE,
Activity.MODE_PRIVATE).edit();
editor.clear();
putDouble(editor, KEY_LATITUDE, pos.y);
putDouble(editor, KEY_LONGITUDE, pos.x);
putDouble(editor, KEY_SCALE, pos.scale);
editor.apply();
}
public void save(MapPosition pos) {
Editor editor = ctx.getSharedPreferences(PREFERENCES_FILE,
Activity.MODE_PRIVATE).edit();
editor.clear();
putDouble(editor, KEY_LATITUDE, pos.y);
putDouble(editor, KEY_LONGITUDE, pos.x);
putDouble(editor, KEY_SCALE, pos.scale);
editor.apply();
}
private static boolean containsViewport(SharedPreferences prefs) {
return prefs.contains(KEY_LATITUDE)
&& prefs.contains(KEY_LONGITUDE)
&& prefs.contains(KEY_SCALE);
}
private static boolean containsViewport(SharedPreferences prefs) {
return prefs.contains(KEY_LATITUDE)
&& prefs.contains(KEY_LONGITUDE)
&& prefs.contains(KEY_SCALE);
}
public boolean load(Map map) {
MapPosition pos = map.getMapPosition();
if (load(pos)) {
map.setMapPosition(pos);
return true;
}
return false;
}
public boolean load(Map map) {
MapPosition pos = map.getMapPosition();
if (load(pos)) {
map.setMapPosition(pos);
return true;
}
return false;
}
public boolean load(MapPosition pos) {
SharedPreferences prefs = ctx.getSharedPreferences(PREFERENCES_FILE,
Activity.MODE_PRIVATE);
public boolean load(MapPosition pos) {
SharedPreferences prefs = ctx.getSharedPreferences(PREFERENCES_FILE,
Activity.MODE_PRIVATE);
if (containsViewport(prefs)) {
pos.x = getDouble(prefs, KEY_LONGITUDE);
pos.y = getDouble(prefs, KEY_LATITUDE);
pos.scale = getDouble(prefs, KEY_SCALE);
return true;
}
return false;
}
if (containsViewport(prefs)) {
pos.x = getDouble(prefs, KEY_LONGITUDE);
pos.y = getDouble(prefs, KEY_LATITUDE);
pos.scale = getDouble(prefs, KEY_SCALE);
return true;
}
return false;
}
}

View File

@@ -16,7 +16,11 @@ package org.oscim.android;
* this program. If not, see <http://www.gnu.org/licenses/>.
*/
import java.util.HashMap;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Typeface;
import org.oscim.android.canvas.AndroidBitmap;
import org.oscim.core.MapPosition;
@@ -27,11 +31,7 @@ import org.oscim.map.Map;
import org.oscim.map.Map.UpdateListener;
import org.oscim.renderer.BitmapRenderer;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Typeface;
import java.util.HashMap;
/**
* A MapScaleBar displays the ratio of a distance on the map to the
@@ -39,244 +39,239 @@ import android.graphics.Typeface;
*/
public class MapScaleBar extends Layer implements UpdateListener {
private static final int BITMAP_HEIGHT = 64;
private static final int BITMAP_WIDTH = 128;
private static final double LATITUDE_REDRAW_THRESHOLD = 0.2;
// private static final int MARGIN_BOTTOM = 5;
// private static final int MARGIN_LEFT = 5;
private static final int BITMAP_HEIGHT = 64;
private static final int BITMAP_WIDTH = 128;
private static final double LATITUDE_REDRAW_THRESHOLD = 0.2;
// private static final int MARGIN_BOTTOM = 5;
// private static final int MARGIN_LEFT = 5;
private static final double METER_FOOT_RATIO = 0.3048;
private static final int ONE_KILOMETER = 1000;
private static final int ONE_MILE = 5280;
private static final double METER_FOOT_RATIO = 0.3048;
private static final int ONE_KILOMETER = 1000;
private static final int ONE_MILE = 5280;
private static final Paint SCALE_BAR = new Paint(Paint.ANTI_ALIAS_FLAG);
private static final Paint SCALE_BAR_STROKE = new Paint(Paint.ANTI_ALIAS_FLAG);
private static final Paint SCALE_TEXT = new Paint(Paint.ANTI_ALIAS_FLAG);
private static final Paint SCALE_TEXT_STROKE = new Paint(Paint.ANTI_ALIAS_FLAG);
private static final Paint SCALE_BAR = new Paint(Paint.ANTI_ALIAS_FLAG);
private static final Paint SCALE_BAR_STROKE = new Paint(Paint.ANTI_ALIAS_FLAG);
private static final Paint SCALE_TEXT = new Paint(Paint.ANTI_ALIAS_FLAG);
private static final Paint SCALE_TEXT_STROKE = new Paint(Paint.ANTI_ALIAS_FLAG);
private static final int[] SCALE_BAR_VALUES_IMPERIAL = {
26400000, 10560000, 5280000,
2640000, 1056000, 528000,
264000, 105600, 52800, 26400,
10560, 5280, 2000, 1000, 500,
200, 100, 50, 20,
10, 5, 2, 1 };
private static final int[] SCALE_BAR_VALUES_METRIC = {
10000000, 5000000, 2000000, 1000000,
500000, 200000, 100000, 50000,
20000, 10000, 5000, 2000, 1000,
500, 200, 100, 50, 20, 10, 5, 2, 1 };
private static final int[] SCALE_BAR_VALUES_IMPERIAL = {
26400000, 10560000, 5280000,
2640000, 1056000, 528000,
264000, 105600, 52800, 26400,
10560, 5280, 2000, 1000, 500,
200, 100, 50, 20,
10, 5, 2, 1};
private static final int[] SCALE_BAR_VALUES_METRIC = {
10000000, 5000000, 2000000, 1000000,
500000, 200000, 100000, 50000,
20000, 10000, 5000, 2000, 1000,
500, 200, 100, 50, 20, 10, 5, 2, 1};
private boolean mImperialUnits;
private final Canvas mMapScaleCanvas;
private boolean mRedrawNeeded;
private double mPrevLatitude = -1;
private final double mPrevScale = -1;
private final HashMap<TextField, String> mTextFields;
private boolean mImperialUnits;
private final Canvas mMapScaleCanvas;
private boolean mRedrawNeeded;
private double mPrevLatitude = -1;
private final double mPrevScale = -1;
private final HashMap<TextField, String> mTextFields;
private final Bitmap mBitmap;
// passed to BitmapRenderer - need to sync on this object.
private final AndroidBitmap mLayerBitmap;
private final BitmapRenderer mBitmapLayer;
private final Bitmap mBitmap;
// passed to BitmapRenderer - need to sync on this object.
private final AndroidBitmap mLayerBitmap;
private final BitmapRenderer mBitmapLayer;
public MapScaleBar(MapView map) {
super(map.map());
public MapScaleBar(MapView map) {
super(map.map());
mBitmap = Bitmap.createBitmap(BITMAP_WIDTH,
BITMAP_HEIGHT,
Bitmap.Config.ARGB_8888);
mBitmap = Bitmap.createBitmap(BITMAP_WIDTH,
BITMAP_HEIGHT,
Bitmap.Config.ARGB_8888);
mMapScaleCanvas = new Canvas(mBitmap);
mTextFields = new HashMap<TextField, String>();
mMapScaleCanvas = new Canvas(mBitmap);
mTextFields = new HashMap<TextField, String>();
setDefaultTexts();
configurePaints();
setDefaultTexts();
configurePaints();
mRedrawNeeded = true;
mRenderer = mBitmapLayer = new BitmapRenderer();
mLayerBitmap = new AndroidBitmap(mBitmap);
mBitmapLayer.setBitmap(mLayerBitmap,
BITMAP_WIDTH,
BITMAP_HEIGHT,
(int) (BITMAP_WIDTH * 1.2f),
(int) (BITMAP_HEIGHT * 1.2f));
}
mRedrawNeeded = true;
mRenderer = mBitmapLayer = new BitmapRenderer();
mLayerBitmap = new AndroidBitmap(mBitmap);
mBitmapLayer.setBitmap(mLayerBitmap,
BITMAP_WIDTH,
BITMAP_HEIGHT,
(int) (BITMAP_WIDTH * 1.2f),
(int) (BITMAP_HEIGHT * 1.2f));
}
@Override
@Override
public void onMapEvent(Event e, MapPosition mapPosition) {
if (e == Map.UPDATE_EVENT)
return;
if (e == Map.UPDATE_EVENT)
return;
double latitude = MercatorProjection.toLatitude(mapPosition.y);
double latitude = MercatorProjection.toLatitude(mapPosition.y);
if (!mRedrawNeeded) {
double scaleDiff = mPrevScale / mapPosition.scale;
if (scaleDiff < 1.1 && scaleDiff > 0.9) {
double latitudeDiff = Math.abs(mPrevLatitude - latitude);
if (latitudeDiff < LATITUDE_REDRAW_THRESHOLD)
return;
}
}
mPrevLatitude = latitude;
if (!mRedrawNeeded) {
double scaleDiff = mPrevScale / mapPosition.scale;
if (scaleDiff < 1.1 && scaleDiff > 0.9) {
double latitudeDiff = Math.abs(mPrevLatitude - latitude);
if (latitudeDiff < LATITUDE_REDRAW_THRESHOLD)
return;
}
}
mPrevLatitude = latitude;
double groundResolution = MercatorProjection
.groundResolution(latitude, mapPosition.scale);
double groundResolution = MercatorProjection
.groundResolution(latitude, mapPosition.scale);
int[] scaleBarValues;
if (mImperialUnits) {
groundResolution = groundResolution / METER_FOOT_RATIO;
scaleBarValues = SCALE_BAR_VALUES_IMPERIAL;
} else {
scaleBarValues = SCALE_BAR_VALUES_METRIC;
}
int[] scaleBarValues;
if (mImperialUnits) {
groundResolution = groundResolution / METER_FOOT_RATIO;
scaleBarValues = SCALE_BAR_VALUES_IMPERIAL;
} else {
scaleBarValues = SCALE_BAR_VALUES_METRIC;
}
float scaleBarLength = 0;
int mapScaleValue = 0;
float scaleBarLength = 0;
int mapScaleValue = 0;
for (int i = 0; i < scaleBarValues.length; ++i) {
mapScaleValue = scaleBarValues[i];
scaleBarLength = mapScaleValue / (float) groundResolution;
if (scaleBarLength < (BITMAP_WIDTH - 10)) {
break;
}
}
synchronized (mLayerBitmap) {
redrawMapScaleBitmap(scaleBarLength, mapScaleValue);
}
for (int i = 0; i < scaleBarValues.length; ++i) {
mapScaleValue = scaleBarValues[i];
scaleBarLength = mapScaleValue / (float) groundResolution;
if (scaleBarLength < (BITMAP_WIDTH - 10)) {
break;
}
}
synchronized (mLayerBitmap) {
redrawMapScaleBitmap(scaleBarLength, mapScaleValue);
}
mBitmapLayer.updateBitmap();
mBitmapLayer.updateBitmap();
mRedrawNeeded = false;
}
mRedrawNeeded = false;
}
/**
* @return true if imperial units are used, false otherwise.
*/
public boolean isImperialUnits() {
return mImperialUnits;
}
/**
* @return true if imperial units are used, false otherwise.
*/
public boolean isImperialUnits() {
return mImperialUnits;
}
/**
* @param imperialUnits
* true if imperial units should be used rather than metric
* units.
*/
public void setImperialUnits(boolean imperialUnits) {
mImperialUnits = imperialUnits;
mRedrawNeeded = true;
}
/**
* @param imperialUnits true if imperial units should be used rather than metric
* units.
*/
public void setImperialUnits(boolean imperialUnits) {
mImperialUnits = imperialUnits;
mRedrawNeeded = true;
}
/**
* Overrides the specified text field with the given string.
*
* @param textField
* the text field to override.
* @param value
* the new value of the text field.
*/
public void setText(TextField textField, String value) {
mTextFields.put(textField, value);
mRedrawNeeded = true;
}
/**
* Overrides the specified text field with the given string.
*
* @param textField the text field to override.
* @param value the new value of the text field.
*/
public void setText(TextField textField, String value) {
mTextFields.put(textField, value);
mRedrawNeeded = true;
}
private void drawScaleBar(float scaleBarLength, Paint paint) {
mMapScaleCanvas.drawLine(7, 25, scaleBarLength + 3, 25, paint);
mMapScaleCanvas.drawLine(5, 10, 5, 40, paint);
mMapScaleCanvas.drawLine(scaleBarLength + 5, 10, scaleBarLength + 5, 40, paint);
}
private void drawScaleBar(float scaleBarLength, Paint paint) {
mMapScaleCanvas.drawLine(7, 25, scaleBarLength + 3, 25, paint);
mMapScaleCanvas.drawLine(5, 10, 5, 40, paint);
mMapScaleCanvas.drawLine(scaleBarLength + 5, 10, scaleBarLength + 5, 40, paint);
}
private void drawScaleText(int scaleValue, String unitSymbol, Paint paint) {
mMapScaleCanvas.drawText(scaleValue + unitSymbol, 12, 18, paint);
}
private void drawScaleText(int scaleValue, String unitSymbol, Paint paint) {
mMapScaleCanvas.drawText(scaleValue + unitSymbol, 12, 18, paint);
}
/**
* Redraws the map scale bitmap with the given parameters.
*
* @param scaleBarLength
* the length of the map scale bar in pixels.
* @param mapScaleValue
* the map scale value in meters.
*/
private void redrawMapScaleBitmap(float scaleBarLength, int mapScaleValue) {
mBitmap.eraseColor(Color.TRANSPARENT);
/**
* Redraws the map scale bitmap with the given parameters.
*
* @param scaleBarLength the length of the map scale bar in pixels.
* @param mapScaleValue the map scale value in meters.
*/
private void redrawMapScaleBitmap(float scaleBarLength, int mapScaleValue) {
mBitmap.eraseColor(Color.TRANSPARENT);
// draw the scale bar
drawScaleBar(scaleBarLength, SCALE_BAR_STROKE);
drawScaleBar(scaleBarLength, SCALE_BAR);
// draw the scale bar
drawScaleBar(scaleBarLength, SCALE_BAR_STROKE);
drawScaleBar(scaleBarLength, SCALE_BAR);
int scaleValue;
String unitSymbol;
if (mImperialUnits) {
if (mapScaleValue < ONE_MILE) {
scaleValue = mapScaleValue;
unitSymbol = mTextFields.get(TextField.FOOT);
} else {
scaleValue = mapScaleValue / ONE_MILE;
unitSymbol = mTextFields.get(TextField.MILE);
}
} else {
if (mapScaleValue < ONE_KILOMETER) {
scaleValue = mapScaleValue;
unitSymbol = mTextFields.get(TextField.METER);
} else {
scaleValue = mapScaleValue / ONE_KILOMETER;
unitSymbol = mTextFields.get(TextField.KILOMETER);
}
}
int scaleValue;
String unitSymbol;
if (mImperialUnits) {
if (mapScaleValue < ONE_MILE) {
scaleValue = mapScaleValue;
unitSymbol = mTextFields.get(TextField.FOOT);
} else {
scaleValue = mapScaleValue / ONE_MILE;
unitSymbol = mTextFields.get(TextField.MILE);
}
} else {
if (mapScaleValue < ONE_KILOMETER) {
scaleValue = mapScaleValue;
unitSymbol = mTextFields.get(TextField.METER);
} else {
scaleValue = mapScaleValue / ONE_KILOMETER;
unitSymbol = mTextFields.get(TextField.KILOMETER);
}
}
// draw the scale text
drawScaleText(scaleValue, unitSymbol, SCALE_TEXT_STROKE);
drawScaleText(scaleValue, unitSymbol, SCALE_TEXT);
}
// draw the scale text
drawScaleText(scaleValue, unitSymbol, SCALE_TEXT_STROKE);
drawScaleText(scaleValue, unitSymbol, SCALE_TEXT);
}
private void setDefaultTexts() {
mTextFields.put(TextField.FOOT, " ft");
mTextFields.put(TextField.MILE, " mi");
private void setDefaultTexts() {
mTextFields.put(TextField.FOOT, " ft");
mTextFields.put(TextField.MILE, " mi");
mTextFields.put(TextField.METER, " m");
mTextFields.put(TextField.KILOMETER, " km");
}
mTextFields.put(TextField.METER, " m");
mTextFields.put(TextField.KILOMETER, " km");
}
private static void configurePaints() {
SCALE_BAR.setStrokeWidth(2);
SCALE_BAR.setStrokeCap(Paint.Cap.SQUARE);
SCALE_BAR.setColor(Color.BLACK);
SCALE_BAR_STROKE.setStrokeWidth(5);
SCALE_BAR_STROKE.setStrokeCap(Paint.Cap.SQUARE);
SCALE_BAR_STROKE.setColor(Color.WHITE);
private static void configurePaints() {
SCALE_BAR.setStrokeWidth(2);
SCALE_BAR.setStrokeCap(Paint.Cap.SQUARE);
SCALE_BAR.setColor(Color.BLACK);
SCALE_BAR_STROKE.setStrokeWidth(5);
SCALE_BAR_STROKE.setStrokeCap(Paint.Cap.SQUARE);
SCALE_BAR_STROKE.setColor(Color.WHITE);
SCALE_TEXT.setTypeface(Typeface.defaultFromStyle(Typeface.BOLD));
SCALE_TEXT.setTextSize(17);
SCALE_TEXT.setColor(Color.BLACK);
SCALE_TEXT_STROKE.setTypeface(Typeface.defaultFromStyle(Typeface.BOLD));
SCALE_TEXT_STROKE.setStyle(Paint.Style.STROKE);
SCALE_TEXT_STROKE.setColor(Color.WHITE);
SCALE_TEXT_STROKE.setStrokeWidth(2);
SCALE_TEXT_STROKE.setTextSize(17);
}
SCALE_TEXT.setTypeface(Typeface.defaultFromStyle(Typeface.BOLD));
SCALE_TEXT.setTextSize(17);
SCALE_TEXT.setColor(Color.BLACK);
SCALE_TEXT_STROKE.setTypeface(Typeface.defaultFromStyle(Typeface.BOLD));
SCALE_TEXT_STROKE.setStyle(Paint.Style.STROKE);
SCALE_TEXT_STROKE.setColor(Color.WHITE);
SCALE_TEXT_STROKE.setStrokeWidth(2);
SCALE_TEXT_STROKE.setTextSize(17);
}
/**
* Enumeration of all text fields.
*/
public enum TextField {
/**
* Unit symbol for one foot.
*/
FOOT,
/**
* Enumeration of all text fields.
*/
public enum TextField {
/**
* Unit symbol for one foot.
*/
FOOT,
/**
* Unit symbol for one kilometer.
*/
KILOMETER,
/**
* Unit symbol for one kilometer.
*/
KILOMETER,
/**
* Unit symbol for one meter.
*/
METER,
/**
* Unit symbol for one meter.
*/
METER,
/**
* Unit symbol for one mile.
*/
MILE;
}
/**
* Unit symbol for one mile.
*/
MILE;
}
}

View File

@@ -16,8 +16,12 @@
*/
package org.oscim.android;
import javax.microedition.khronos.egl.EGLConfig;
import javax.microedition.khronos.opengles.GL10;
import android.annotation.SuppressLint;
import android.content.Context;
import android.opengl.GLSurfaceView;
import android.util.AttributeSet;
import android.util.DisplayMetrics;
import android.view.GestureDetector;
import org.oscim.android.canvas.AndroidGraphics;
import org.oscim.android.gl.AndroidGL;
@@ -30,224 +34,220 @@ import org.oscim.map.Map;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import android.annotation.SuppressLint;
import android.content.Context;
import android.opengl.GLSurfaceView;
import android.util.AttributeSet;
import android.util.DisplayMetrics;
import android.view.GestureDetector;
import javax.microedition.khronos.egl.EGLConfig;
import javax.microedition.khronos.opengles.GL10;
/**
* The MapView,
*
* <p/>
* add it your App, have a map!
*
* <p/>
* Dont forget to call onPause / onResume!
*/
public class MapView extends GLSurfaceView {
static final Logger log = LoggerFactory.getLogger(MapView.class);
static final Logger log = LoggerFactory.getLogger(MapView.class);
static {
System.loadLibrary("vtm-jni");
}
static {
System.loadLibrary("vtm-jni");
}
protected final AndroidMap mMap;
protected final GestureDetector mGestureDetector;
protected final AndroidMotionEvent mMotionEvent;
protected final AndroidMap mMap;
protected final GestureDetector mGestureDetector;
protected final AndroidMotionEvent mMotionEvent;
public MapView(Context context) {
this(context, null);
}
public MapView(Context context) {
this(context, null);
}
public MapView(Context context, AttributeSet attributeSet) {
super(context, attributeSet);
public MapView(Context context, AttributeSet attributeSet) {
super(context, attributeSet);
/* Not sure if this makes sense */
this.setWillNotDraw(true);
this.setClickable(true);
this.setFocusable(true);
this.setFocusableInTouchMode(true);
this.setWillNotDraw(true);
this.setClickable(true);
this.setFocusable(true);
this.setFocusableInTouchMode(true);
/* Setup android backedn */
AndroidGraphics.init();
AndroidAssets.init(context);
GLAdapter.init(new AndroidGL());
AndroidGraphics.init();
AndroidAssets.init(context);
GLAdapter.init(new AndroidGL());
DisplayMetrics metrics = getResources().getDisplayMetrics();
CanvasAdapter.dpi = (int) Math.max(metrics.xdpi, metrics.ydpi);
DisplayMetrics metrics = getResources().getDisplayMetrics();
CanvasAdapter.dpi = (int) Math.max(metrics.xdpi, metrics.ydpi);
/* Initialize the Map */
mMap = new AndroidMap(this);
mMap = new AndroidMap(this);
/* Initialize Renderer */
setEGLConfigChooser(new GlConfigChooser());
setEGLContextClientVersion(2);
setEGLConfigChooser(new GlConfigChooser());
setEGLContextClientVersion(2);
if (GLAdapter.debug)
setDebugFlags(GLSurfaceView.DEBUG_CHECK_GL_ERROR
| GLSurfaceView.DEBUG_LOG_GL_CALLS);
if (GLAdapter.debug)
setDebugFlags(GLSurfaceView.DEBUG_CHECK_GL_ERROR
| GLSurfaceView.DEBUG_LOG_GL_CALLS);
setRenderer(new GLRenderer(mMap));
setRenderMode(GLSurfaceView.RENDERMODE_WHEN_DIRTY);
setRenderer(new GLRenderer(mMap));
setRenderMode(GLSurfaceView.RENDERMODE_WHEN_DIRTY);
mMap.clearMap();
mMap.updateMap(false);
mMap.clearMap();
mMap.updateMap(false);
GestureHandler gestureHandler = new GestureHandler(mMap);
mGestureDetector = new GestureDetector(context, gestureHandler);
mGestureDetector.setOnDoubleTapListener(gestureHandler);
GestureHandler gestureHandler = new GestureHandler(mMap);
mGestureDetector = new GestureDetector(context, gestureHandler);
mGestureDetector.setOnDoubleTapListener(gestureHandler);
mMotionEvent = new AndroidMotionEvent();
}
mMotionEvent = new AndroidMotionEvent();
}
public void onStop() {
public void onStop() {
}
}
public void onPause() {
mMap.pause(true);
}
public void onPause() {
mMap.pause(true);
}
public void onResume() {
mMap.pause(false);
}
public void onResume() {
mMap.pause(false);
}
@SuppressLint("ClickableViewAccessibility")
@Override
public boolean onTouchEvent(android.view.MotionEvent motionEvent) {
@SuppressLint("ClickableViewAccessibility")
@Override
public boolean onTouchEvent(android.view.MotionEvent motionEvent) {
if (!isClickable())
return false;
if (!isClickable())
return false;
if (mGestureDetector.onTouchEvent(motionEvent))
return true;
if (mGestureDetector.onTouchEvent(motionEvent))
return true;
mMap.input.fire(null, mMotionEvent.wrap(motionEvent));
return true;
}
mMap.input.fire(null, mMotionEvent.wrap(motionEvent));
return true;
}
@Override
protected void onSizeChanged(int width, int height,
int oldWidth, int oldHeight) {
@Override
protected void onSizeChanged(int width, int height,
int oldWidth, int oldHeight) {
super.onSizeChanged(width, height, oldWidth, oldHeight);
super.onSizeChanged(width, height, oldWidth, oldHeight);
if (width > 0 && height > 0)
mMap.viewport().setScreenSize(width, height);
}
if (width > 0 && height > 0)
mMap.viewport().setScreenSize(width, height);
}
public Map map() {
return mMap;
}
public Map map() {
return mMap;
}
static class AndroidMap extends Map {
static class AndroidMap extends Map {
private final MapView mMapView;
private final MapView mMapView;
private boolean mRenderRequest;
private boolean mRenderWait;
private boolean mPausing;
private boolean mRenderRequest;
private boolean mRenderWait;
private boolean mPausing;
public AndroidMap(MapView mapView) {
super();
mMapView = mapView;
}
public AndroidMap(MapView mapView) {
super();
mMapView = mapView;
}
@Override
public int getWidth() {
return mMapView.getWidth();
}
@Override
public int getWidth() {
return mMapView.getWidth();
}
@Override
public int getHeight() {
return mMapView.getHeight();
}
@Override
public int getHeight() {
return mMapView.getHeight();
}
private final Runnable mRedrawCb = new Runnable() {
@Override
public void run() {
prepareFrame();
mMapView.requestRender();
}
};
private final Runnable mRedrawCb = new Runnable() {
@Override
public void run() {
prepareFrame();
mMapView.requestRender();
}
};
@Override
public void updateMap(boolean redraw) {
synchronized (mRedrawCb) {
if (mPausing)
return;
@Override
public void updateMap(boolean redraw) {
synchronized (mRedrawCb) {
if (mPausing)
return;
if (!mRenderRequest) {
mRenderRequest = true;
mMapView.post(mRedrawCb);
} else {
mRenderWait = true;
}
}
}
if (!mRenderRequest) {
mRenderRequest = true;
mMapView.post(mRedrawCb);
} else {
mRenderWait = true;
}
}
}
@Override
public void render() {
if (mPausing)
return;
@Override
public void render() {
if (mPausing)
return;
/** TODO should not need to call prepareFrame in mRedrawCb */
updateMap(false);
}
/** TODO should not need to call prepareFrame in mRedrawCb */
updateMap(false);
}
@Override
public void beginFrame() {
}
@Override
public void beginFrame() {
}
@Override
public void doneFrame(boolean animate) {
synchronized (mRedrawCb) {
mRenderRequest = false;
if (animate || mRenderWait) {
mRenderWait = false;
render();
}
}
}
@Override
public void doneFrame(boolean animate) {
synchronized (mRedrawCb) {
mRenderRequest = false;
if (animate || mRenderWait) {
mRenderWait = false;
render();
}
}
}
@Override
public boolean post(Runnable runnable) {
return mMapView.post(runnable);
}
@Override
public boolean post(Runnable runnable) {
return mMapView.post(runnable);
}
@Override
public boolean postDelayed(Runnable action, long delay) {
return mMapView.postDelayed(action, delay);
}
@Override
public boolean postDelayed(Runnable action, long delay) {
return mMapView.postDelayed(action, delay);
}
public void pause(boolean pause) {
log.debug("pause... {}", pause);
mPausing = pause;
}
}
public void pause(boolean pause) {
log.debug("pause... {}", pause);
mPausing = pause;
}
}
static class GLRenderer extends org.oscim.renderer.MapRenderer
implements GLSurfaceView.Renderer {
static class GLRenderer extends org.oscim.renderer.MapRenderer
implements GLSurfaceView.Renderer {
public GLRenderer(Map map) {
super(map);
}
public GLRenderer(Map map) {
super(map);
}
@Override
public void onSurfaceCreated(GL10 gl, EGLConfig config) {
super.onSurfaceCreated();
}
@Override
public void onSurfaceCreated(GL10 gl, EGLConfig config) {
super.onSurfaceCreated();
}
@Override
public void onSurfaceChanged(GL10 gl, int width, int height) {
super.onSurfaceChanged(width, height);
@Override
public void onSurfaceChanged(GL10 gl, int width, int height) {
super.onSurfaceChanged(width, height);
}
}
@Override
public void onDrawFrame(GL10 gl) {
super.onDrawFrame();
}
}
@Override
public void onDrawFrame(GL10 gl) {
super.onDrawFrame();
}
}
}

View File

@@ -16,17 +16,6 @@
*/
package org.oscim.android.cache;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.FileInputStream;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.ArrayList;
import org.oscim.core.Tile;
import org.oscim.tiling.ITileCache;
import org.slf4j.LoggerFactory;
import android.annotation.TargetApi;
import android.content.Context;
import android.database.Cursor;
@@ -37,247 +26,258 @@ import android.database.sqlite.SQLiteStatement;
import android.os.Build;
import android.os.ParcelFileDescriptor;
import org.oscim.core.Tile;
import org.oscim.tiling.ITileCache;
import org.slf4j.LoggerFactory;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.FileInputStream;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.ArrayList;
public class TileCache implements ITileCache {
final static org.slf4j.Logger log = LoggerFactory.getLogger(TileCache.class);
final static boolean dbg = false;
final static org.slf4j.Logger log = LoggerFactory.getLogger(TileCache.class);
final static boolean dbg = false;
class CacheTileReader implements TileReader {
final InputStream mInputStream;
final Tile mTile;
class CacheTileReader implements TileReader {
final InputStream mInputStream;
final Tile mTile;
public CacheTileReader(Tile tile, InputStream is) {
mTile = tile;
mInputStream = is;
}
public CacheTileReader(Tile tile, InputStream is) {
mTile = tile;
mInputStream = is;
}
@Override
public Tile getTile() {
return mTile;
}
@Override
public Tile getTile() {
return mTile;
}
@Override
public InputStream getInputStream() {
return mInputStream;
}
}
@Override
public InputStream getInputStream() {
return mInputStream;
}
}
class CacheTileWriter implements TileWriter {
final ByteArrayOutputStream mOutputStream;
final Tile mTile;
class CacheTileWriter implements TileWriter {
final ByteArrayOutputStream mOutputStream;
final Tile mTile;
CacheTileWriter(Tile tile, ByteArrayOutputStream os) {
mTile = tile;
mOutputStream = os;
}
CacheTileWriter(Tile tile, ByteArrayOutputStream os) {
mTile = tile;
mOutputStream = os;
}
@Override
public Tile getTile() {
return mTile;
}
@Override
public Tile getTile() {
return mTile;
}
@Override
public OutputStream getOutputStream() {
return mOutputStream;
}
@Override
public OutputStream getOutputStream() {
return mOutputStream;
}
@Override
public void complete(boolean success) {
saveTile(mTile, mOutputStream, success);
}
}
@Override
public void complete(boolean success) {
saveTile(mTile, mOutputStream, success);
}
}
private final ArrayList<ByteArrayOutputStream> mCacheBuffers;
private final SQLiteHelper dbHelper;
private final SQLiteDatabase mDatabase;
private final SQLiteStatement mStmtGetTile;
private final SQLiteStatement mStmtPutTile;
private final ArrayList<ByteArrayOutputStream> mCacheBuffers;
private final SQLiteHelper dbHelper;
private final SQLiteDatabase mDatabase;
private final SQLiteStatement mStmtGetTile;
private final SQLiteStatement mStmtPutTile;
//private final SQLiteStatement mStmtUpdateTile;
//private final SQLiteStatement mStmtUpdateTile;
public void dispose() {
if (mDatabase.isOpen())
mDatabase.close();
}
public void dispose() {
if (mDatabase.isOpen())
mDatabase.close();
}
@TargetApi(Build.VERSION_CODES.JELLY_BEAN)
public TileCache(Context context, String cacheDirectory, String dbName) {
if (dbg)
log.debug("open cache {}, {}", cacheDirectory, dbName);
@TargetApi(Build.VERSION_CODES.JELLY_BEAN)
public TileCache(Context context, String cacheDirectory, String dbName) {
if (dbg)
log.debug("open cache {}, {}", cacheDirectory, dbName);
dbHelper = new SQLiteHelper(context, dbName);
dbHelper = new SQLiteHelper(context, dbName);
if (Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.JELLY_BEAN)
dbHelper.setWriteAheadLoggingEnabled(true);
if (Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.JELLY_BEAN)
dbHelper.setWriteAheadLoggingEnabled(true);
mDatabase = dbHelper.getWritableDatabase();
mDatabase = dbHelper.getWritableDatabase();
mStmtGetTile = mDatabase.compileStatement("" +
"SELECT " + COLUMN_DATA +
" FROM " + TABLE_NAME +
" WHERE x=? AND y=? AND z = ?");
mStmtGetTile = mDatabase.compileStatement("" +
"SELECT " + COLUMN_DATA +
" FROM " + TABLE_NAME +
" WHERE x=? AND y=? AND z = ?");
mStmtPutTile = mDatabase.compileStatement("" +
"INSERT INTO " + TABLE_NAME +
" (x, y, z, time, last_access, data)" +
" VALUES(?,?,?,?,?,?)");
mStmtPutTile = mDatabase.compileStatement("" +
"INSERT INTO " + TABLE_NAME +
" (x, y, z, time, last_access, data)" +
" VALUES(?,?,?,?,?,?)");
//mStmtUpdateTile = mDatabase.compileStatement("" +
// "UPDATE " + TABLE_NAME +
// " SET last_access=?" +
// " WHERE x=? AND y=? AND z=?");
//mStmtUpdateTile = mDatabase.compileStatement("" +
// "UPDATE " + TABLE_NAME +
// " SET last_access=?" +
// " WHERE x=? AND y=? AND z=?");
mCacheBuffers = new ArrayList<ByteArrayOutputStream>();
}
mCacheBuffers = new ArrayList<ByteArrayOutputStream>();
}
@Override
public TileWriter writeTile(Tile tile) {
ByteArrayOutputStream os;
@Override
public TileWriter writeTile(Tile tile) {
ByteArrayOutputStream os;
synchronized (mCacheBuffers) {
if (mCacheBuffers.size() == 0)
os = new ByteArrayOutputStream(32 * 1024);
else
os = mCacheBuffers.remove(mCacheBuffers.size() - 1);
}
return new CacheTileWriter(tile, os);
}
synchronized (mCacheBuffers) {
if (mCacheBuffers.size() == 0)
os = new ByteArrayOutputStream(32 * 1024);
else
os = mCacheBuffers.remove(mCacheBuffers.size() - 1);
}
return new CacheTileWriter(tile, os);
}
static final String TABLE_NAME = "tiles";
static final String COLUMN_TIME = "time";
static final String COLUMN_ACCESS = "last_access";
static final String COLUMN_DATA = "data";
static final String TABLE_NAME = "tiles";
static final String COLUMN_TIME = "time";
static final String COLUMN_ACCESS = "last_access";
static final String COLUMN_DATA = "data";
//static final String COLUMN_SIZE = "size";
//static final String COLUMN_SIZE = "size";
class SQLiteHelper extends SQLiteOpenHelper {
class SQLiteHelper extends SQLiteOpenHelper {
//private static final String DATABASE_NAME = "tile.db";
private static final int DATABASE_VERSION = 1;
//private static final String DATABASE_NAME = "tile.db";
private static final int DATABASE_VERSION = 1;
private static final String TILE_SCHEMA =
"CREATE TABLE "
+ TABLE_NAME + "("
+ "x INTEGER NOT NULL,"
+ "y INTEGER NOT NULL,"
+ "z INTEGER NOT NULL,"
+ COLUMN_TIME + " LONG NOT NULL,"
//+ COLUMN_SIZE + " LONG NOT NULL,"
+ COLUMN_ACCESS + " LONG NOT NULL,"
+ COLUMN_DATA + " BLOB,"
+ "PRIMARY KEY(x,y,z));";
private static final String TILE_SCHEMA =
"CREATE TABLE "
+ TABLE_NAME + "("
+ "x INTEGER NOT NULL,"
+ "y INTEGER NOT NULL,"
+ "z INTEGER NOT NULL,"
+ COLUMN_TIME + " LONG NOT NULL,"
//+ COLUMN_SIZE + " LONG NOT NULL,"
+ COLUMN_ACCESS + " LONG NOT NULL,"
+ COLUMN_DATA + " BLOB,"
+ "PRIMARY KEY(x,y,z));";
public SQLiteHelper(Context context, String dbName) {
super(context, dbName, null, DATABASE_VERSION);
}
public SQLiteHelper(Context context, String dbName) {
super(context, dbName, null, DATABASE_VERSION);
}
@Override
public void onCreate(SQLiteDatabase db) {
log.debug("create table");
db.execSQL(TILE_SCHEMA);
}
@Override
public void onCreate(SQLiteDatabase db) {
log.debug("create table");
db.execSQL(TILE_SCHEMA);
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
log.debug("drop table");
db.execSQL("DROP TABLE IF EXISTS " + TABLE_NAME);
onCreate(db);
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
log.debug("drop table");
db.execSQL("DROP TABLE IF EXISTS " + TABLE_NAME);
onCreate(db);
}
@Override
public void onDowngrade(SQLiteDatabase db, int oldVersion, int newVersion) {
onUpgrade(db, oldVersion, newVersion);
}
}
@Override
public void onDowngrade(SQLiteDatabase db, int oldVersion, int newVersion) {
onUpgrade(db, oldVersion, newVersion);
}
}
public void saveTile(Tile tile, ByteArrayOutputStream data, boolean success) {
byte[] bytes = null;
public void saveTile(Tile tile, ByteArrayOutputStream data, boolean success) {
byte[] bytes = null;
if (success)
bytes = data.toByteArray();
if (success)
bytes = data.toByteArray();
synchronized (mCacheBuffers) {
data.reset();
mCacheBuffers.add(data);
}
synchronized (mCacheBuffers) {
data.reset();
mCacheBuffers.add(data);
}
if (dbg)
log.debug("store tile {} {}", tile, Boolean.valueOf(success));
if (dbg)
log.debug("store tile {} {}", tile, Boolean.valueOf(success));
if (!success)
return;
if (!success)
return;
synchronized (mStmtPutTile) {
mStmtPutTile.bindLong(1, tile.tileX);
mStmtPutTile.bindLong(2, tile.tileY);
mStmtPutTile.bindLong(3, tile.zoomLevel);
mStmtPutTile.bindLong(4, 0);
mStmtPutTile.bindLong(5, 0);
mStmtPutTile.bindBlob(6, bytes);
synchronized (mStmtPutTile) {
mStmtPutTile.bindLong(1, tile.tileX);
mStmtPutTile.bindLong(2, tile.tileY);
mStmtPutTile.bindLong(3, tile.zoomLevel);
mStmtPutTile.bindLong(4, 0);
mStmtPutTile.bindLong(5, 0);
mStmtPutTile.bindBlob(6, bytes);
mStmtPutTile.execute();
mStmtPutTile.clearBindings();
}
}
mStmtPutTile.execute();
mStmtPutTile.clearBindings();
}
}
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
public TileReader getTileApi11(Tile tile) {
InputStream in = null;
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
public TileReader getTileApi11(Tile tile) {
InputStream in = null;
mStmtGetTile.bindLong(1, tile.tileX);
mStmtGetTile.bindLong(2, tile.tileY);
mStmtGetTile.bindLong(3, tile.zoomLevel);
mStmtGetTile.bindLong(1, tile.tileX);
mStmtGetTile.bindLong(2, tile.tileY);
mStmtGetTile.bindLong(3, tile.zoomLevel);
try {
ParcelFileDescriptor result = mStmtGetTile.simpleQueryForBlobFileDescriptor();
in = new FileInputStream(result.getFileDescriptor());
} catch (SQLiteDoneException e) {
log.debug("not in cache {}", tile);
return null;
} finally {
mStmtGetTile.clearBindings();
}
try {
ParcelFileDescriptor result = mStmtGetTile.simpleQueryForBlobFileDescriptor();
in = new FileInputStream(result.getFileDescriptor());
} catch (SQLiteDoneException e) {
log.debug("not in cache {}", tile);
return null;
} finally {
mStmtGetTile.clearBindings();
}
if (dbg)
log.debug("load tile {}", tile);
if (dbg)
log.debug("load tile {}", tile);
return new CacheTileReader(tile, in);
}
return new CacheTileReader(tile, in);
}
private final String[] mQueryVals = new String[3];
private final String[] mQueryVals = new String[3];
@Override
public synchronized TileReader getTile(Tile tile) {
@Override
public synchronized TileReader getTile(Tile tile) {
//if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.HONEYCOMB)
// return getTileApi11(tile);
//if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.HONEYCOMB)
// return getTileApi11(tile);
mQueryVals[0] = String.valueOf(tile.zoomLevel);
mQueryVals[1] = String.valueOf(tile.tileX);
mQueryVals[2] = String.valueOf(tile.tileY);
mQueryVals[0] = String.valueOf(tile.zoomLevel);
mQueryVals[1] = String.valueOf(tile.tileX);
mQueryVals[2] = String.valueOf(tile.tileY);
Cursor cursor = mDatabase.rawQuery("SELECT " + COLUMN_DATA +
" FROM " + TABLE_NAME +
" WHERE z=? AND x=? AND y=?", mQueryVals);
Cursor cursor = mDatabase.rawQuery("SELECT " + COLUMN_DATA +
" FROM " + TABLE_NAME +
" WHERE z=? AND x=? AND y=?", mQueryVals);
if (!cursor.moveToFirst()) {
if (dbg)
log.debug("not in cache {}", tile);
if (!cursor.moveToFirst()) {
if (dbg)
log.debug("not in cache {}", tile);
cursor.close();
return null;
}
cursor.close();
return null;
}
InputStream in = new ByteArrayInputStream(cursor.getBlob(0));
cursor.close();
InputStream in = new ByteArrayInputStream(cursor.getBlob(0));
cursor.close();
if (dbg)
log.debug("load tile {}", tile);
if (dbg)
log.debug("load tile {}", tile);
return new CacheTileReader(tile, in);
}
return new CacheTileReader(tile, in);
}
@Override
public void setCacheSize(long size) {
}
@Override
public void setCacheSize(long size) {
}
}

View File

@@ -16,88 +16,88 @@
*/
package org.oscim.android.canvas;
import static android.graphics.Bitmap.Config.ARGB_8888;
import java.io.InputStream;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.opengl.GLES20;
import android.opengl.GLUtils;
import java.io.InputStream;
import static android.graphics.Bitmap.Config.ARGB_8888;
public class AndroidBitmap implements org.oscim.backend.canvas.Bitmap {
final Bitmap mBitmap;
final Bitmap mBitmap;
public AndroidBitmap(InputStream inputStream) {
Bitmap bitmap = BitmapFactory.decodeStream(inputStream);
try {
GLUtils.getType(bitmap);
} catch (IllegalArgumentException e) {
bitmap = bitmap.copy(ARGB_8888, false);
}
mBitmap = bitmap;
}
public AndroidBitmap(InputStream inputStream) {
Bitmap bitmap = BitmapFactory.decodeStream(inputStream);
try {
GLUtils.getType(bitmap);
} catch (IllegalArgumentException e) {
bitmap = bitmap.copy(ARGB_8888, false);
}
mBitmap = bitmap;
}
@Override
public boolean isValid() {
return mBitmap != null;
}
@Override
public boolean isValid() {
return mBitmap != null;
}
/**
* @param format ignored always ARGB8888
*/
public AndroidBitmap(int width, int height, int format) {
mBitmap = android.graphics.Bitmap
.createBitmap(width, height, ARGB_8888);
}
/**
* @param format ignored always ARGB8888
*/
public AndroidBitmap(int width, int height, int format) {
mBitmap = android.graphics.Bitmap
.createBitmap(width, height, ARGB_8888);
}
public AndroidBitmap(android.graphics.Bitmap bitmap) {
mBitmap = bitmap;
}
public AndroidBitmap(android.graphics.Bitmap bitmap) {
mBitmap = bitmap;
}
@Override
public int getWidth() {
return mBitmap.getWidth();
}
@Override
public int getWidth() {
return mBitmap.getWidth();
}
@Override
public int getHeight() {
return mBitmap.getHeight();
}
@Override
public int getHeight() {
return mBitmap.getHeight();
}
@Override
public int[] getPixels() {
int width = getWidth();
int height = getHeight();
int[] colors = new int[width * height];
mBitmap.getPixels(colors, 0, width, 0, 0, width, height);
return colors;
}
@Override
public int[] getPixels() {
int width = getWidth();
int height = getHeight();
int[] colors = new int[width * height];
mBitmap.getPixels(colors, 0, width, 0, 0, width, height);
return colors;
}
@Override
public void eraseColor(int color) {
//int a = android.graphics.Color.TRANSPARENT;
mBitmap.eraseColor(color);
}
@Override
public void eraseColor(int color) {
//int a = android.graphics.Color.TRANSPARENT;
mBitmap.eraseColor(color);
}
@Override
public void uploadToTexture(boolean replace) {
int format = GLUtils.getInternalFormat(mBitmap);
int type = GLUtils.getType(mBitmap);
@Override
public void uploadToTexture(boolean replace) {
int format = GLUtils.getInternalFormat(mBitmap);
int type = GLUtils.getType(mBitmap);
if (replace)
GLUtils.texSubImage2D(GLES20.GL_TEXTURE_2D, 0, 0, 0,
mBitmap, format, type);
else
GLUtils.texImage2D(GLES20.GL_TEXTURE_2D, 0, format,
mBitmap, type, 0);
}
if (replace)
GLUtils.texSubImage2D(GLES20.GL_TEXTURE_2D, 0, 0, 0,
mBitmap, format, type);
else
GLUtils.texImage2D(GLES20.GL_TEXTURE_2D, 0, format,
mBitmap, type, 0);
}
@Override
public void recycle() {
if (mBitmap == null)
return;
@Override
public void recycle() {
if (mBitmap == null)
return;
mBitmap.recycle();
}
mBitmap.recycle();
}
}

View File

@@ -21,31 +21,31 @@ import org.oscim.backend.canvas.Canvas;
import org.oscim.backend.canvas.Paint;
public class AndroidCanvas implements Canvas {
final android.graphics.Canvas canvas;
final android.graphics.Canvas canvas;
public AndroidCanvas() {
canvas = new android.graphics.Canvas();
}
public AndroidCanvas() {
canvas = new android.graphics.Canvas();
}
@Override
public void setBitmap(Bitmap bitmap) {
canvas.setBitmap(((AndroidBitmap) bitmap).mBitmap);
}
@Override
public void setBitmap(Bitmap bitmap) {
canvas.setBitmap(((AndroidBitmap) bitmap).mBitmap);
}
@Override
public void drawText(String string, float x, float y, Paint fill, Paint stroke) {
if (string != null) {
if (stroke != null)
canvas.drawText(string, x, y, ((AndroidPaint) stroke).mPaint);
@Override
public void drawText(String string, float x, float y, Paint fill, Paint stroke) {
if (string != null) {
if (stroke != null)
canvas.drawText(string, x, y, ((AndroidPaint) stroke).mPaint);
canvas.drawText(string, x, y, ((AndroidPaint) fill).mPaint);
}
}
canvas.drawText(string, x, y, ((AndroidPaint) fill).mPaint);
}
}
@Override
public void drawBitmap(Bitmap bitmap, float x, float y) {
canvas.drawBitmap(((AndroidBitmap) bitmap).mBitmap, x, y, null);
@Override
public void drawBitmap(Bitmap bitmap, float x, float y) {
canvas.drawBitmap(((AndroidBitmap) bitmap).mBitmap, x, y, null);
}
}
}

View File

@@ -17,8 +17,10 @@
*/
package org.oscim.android.canvas;
import java.io.IOException;
import java.io.InputStream;
import android.content.res.Resources;
import android.graphics.Bitmap.Config;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import org.oscim.backend.CanvasAdapter;
import org.oscim.backend.canvas.Bitmap;
@@ -27,99 +29,97 @@ import org.oscim.backend.canvas.Paint;
import org.oscim.layers.marker.MarkerItem.HotspotPlace;
import org.oscim.layers.marker.MarkerSymbol;
import android.content.res.Resources;
import android.graphics.Bitmap.Config;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import java.io.IOException;
import java.io.InputStream;
public final class AndroidGraphics extends CanvasAdapter {
public static void init() {
CanvasAdapter.init(new AndroidGraphics());
}
public static void init() {
CanvasAdapter.init(new AndroidGraphics());
}
public static android.graphics.Paint getAndroidPaint(Paint paint) {
return ((AndroidPaint) paint).mPaint;
}
public static android.graphics.Paint getAndroidPaint(Paint paint) {
return ((AndroidPaint) paint).mPaint;
}
public static android.graphics.Bitmap getBitmap(Bitmap bitmap) {
return ((AndroidBitmap) bitmap).mBitmap;
}
public static android.graphics.Bitmap getBitmap(Bitmap bitmap) {
return ((AndroidBitmap) bitmap).mBitmap;
}
private AndroidGraphics() {
// do nothing
}
private AndroidGraphics() {
// do nothing
}
@Override
public Bitmap decodeBitmapImpl(InputStream inputStream) {
return new AndroidBitmap(inputStream);
}
@Override
public Bitmap decodeBitmapImpl(InputStream inputStream) {
return new AndroidBitmap(inputStream);
}
@Override
public Bitmap loadBitmapAssetImpl(String fileName) {
try {
return createBitmap(fileName);
} catch (IOException e) {
e.printStackTrace();
}
return null;
}
@Override
public Bitmap loadBitmapAssetImpl(String fileName) {
try {
return createBitmap(fileName);
} catch (IOException e) {
e.printStackTrace();
}
return null;
}
@Override
public Paint newPaintImpl() {
return new AndroidPaint();
}
@Override
public Paint newPaintImpl() {
return new AndroidPaint();
}
@Override
public Bitmap newBitmapImpl(int width, int height, int format) {
return new AndroidBitmap(width, height, format);
}
@Override
public Bitmap newBitmapImpl(int width, int height, int format) {
return new AndroidBitmap(width, height, format);
}
@Override
public Canvas newCanvasImpl() {
return new AndroidCanvas();
}
@Override
public Canvas newCanvasImpl() {
return new AndroidCanvas();
}
//-------------------------------------
public static Bitmap drawableToBitmap(Drawable drawable) {
if (drawable instanceof BitmapDrawable) {
return new AndroidBitmap(((BitmapDrawable) drawable).getBitmap());
}
//-------------------------------------
public static Bitmap drawableToBitmap(Drawable drawable) {
if (drawable instanceof BitmapDrawable) {
return new AndroidBitmap(((BitmapDrawable) drawable).getBitmap());
}
android.graphics.Bitmap bitmap = android.graphics.Bitmap
.createBitmap(drawable.getIntrinsicWidth(),
drawable.getIntrinsicHeight(),
Config.ARGB_8888);
android.graphics.Bitmap bitmap = android.graphics.Bitmap
.createBitmap(drawable.getIntrinsicWidth(),
drawable.getIntrinsicHeight(),
Config.ARGB_8888);
android.graphics.Canvas canvas = new android.graphics.Canvas(bitmap);
drawable.setBounds(0, 0, canvas.getWidth(), canvas.getHeight());
drawable.draw(canvas);
android.graphics.Canvas canvas = new android.graphics.Canvas(bitmap);
drawable.setBounds(0, 0, canvas.getWidth(), canvas.getHeight());
drawable.draw(canvas);
return new AndroidBitmap(bitmap);
}
return new AndroidBitmap(bitmap);
}
public static Bitmap drawableToBitmap(Resources res, int resId) {
return new AndroidBitmap(res.openRawResource(resId));
}
public static Bitmap drawableToBitmap(Resources res, int resId) {
return new AndroidBitmap(res.openRawResource(resId));
}
/**
* @deprecated
*/
public static MarkerSymbol makeMarker(Drawable drawable, HotspotPlace place) {
if (place == null)
place = HotspotPlace.CENTER;
/**
* @deprecated
*/
public static MarkerSymbol makeMarker(Drawable drawable, HotspotPlace place) {
if (place == null)
place = HotspotPlace.CENTER;
return new MarkerSymbol(drawableToBitmap(drawable), place);
}
return new MarkerSymbol(drawableToBitmap(drawable), place);
}
/**
* @deprecated
*/
public static MarkerSymbol makeMarker(Resources res, int resId, HotspotPlace place) {
if (place == null)
place = HotspotPlace.CENTER;
/**
* @deprecated
*/
public static MarkerSymbol makeMarker(Resources res, int resId, HotspotPlace place) {
if (place == null)
place = HotspotPlace.CENTER;
InputStream in = res.openRawResource(resId);
return new MarkerSymbol(new AndroidBitmap(in), place);
}
InputStream in = res.openRawResource(resId);
return new MarkerSymbol(new AndroidBitmap(in), place);
}
}

View File

@@ -16,110 +16,110 @@
*/
package org.oscim.android.canvas;
import org.oscim.backend.canvas.Paint;
import android.graphics.Paint.FontMetrics;
import android.graphics.Typeface;
import org.oscim.backend.canvas.Paint;
class AndroidPaint implements Paint {
private static int getStyle(org.oscim.backend.canvas.Paint.FontStyle fontStyle) {
switch (fontStyle) {
case BOLD:
return 1;
case BOLD_ITALIC:
return 3;
case ITALIC:
return 2;
case NORMAL:
return 0;
}
private static int getStyle(org.oscim.backend.canvas.Paint.FontStyle fontStyle) {
switch (fontStyle) {
case BOLD:
return 1;
case BOLD_ITALIC:
return 3;
case ITALIC:
return 2;
case NORMAL:
return 0;
}
throw new IllegalArgumentException("unknown font style: " + fontStyle);
}
throw new IllegalArgumentException("unknown font style: " + fontStyle);
}
private static Typeface getTypeface(org.oscim.backend.canvas.Paint.FontFamily fontFamily) {
switch (fontFamily) {
case DEFAULT:
return Typeface.DEFAULT;
case DEFAULT_BOLD:
return Typeface.DEFAULT_BOLD;
case MONOSPACE:
return Typeface.MONOSPACE;
case SANS_SERIF:
return Typeface.SANS_SERIF;
case SERIF:
return Typeface.SERIF;
}
private static Typeface getTypeface(org.oscim.backend.canvas.Paint.FontFamily fontFamily) {
switch (fontFamily) {
case DEFAULT:
return Typeface.DEFAULT;
case DEFAULT_BOLD:
return Typeface.DEFAULT_BOLD;
case MONOSPACE:
return Typeface.MONOSPACE;
case SANS_SERIF:
return Typeface.SANS_SERIF;
case SERIF:
return Typeface.SERIF;
}
throw new IllegalArgumentException("unknown font family: " + fontFamily);
}
throw new IllegalArgumentException("unknown font family: " + fontFamily);
}
final android.graphics.Paint mPaint;
final android.graphics.Paint mPaint;
AndroidPaint() {
mPaint = new android.graphics.Paint(
android.graphics.Paint.ANTI_ALIAS_FLAG);
}
AndroidPaint() {
mPaint = new android.graphics.Paint(
android.graphics.Paint.ANTI_ALIAS_FLAG);
}
@Override
public int getColor() {
return mPaint.getColor();
}
@Override
public int getColor() {
return mPaint.getColor();
}
@Override
public void setColor(int color) {
mPaint.setColor(color);
}
@Override
public void setColor(int color) {
mPaint.setColor(color);
}
@Override
public void setStrokeCap(Cap cap) {
android.graphics.Paint.Cap androidCap = android.graphics.Paint.Cap
.valueOf(cap.name());
mPaint.setStrokeCap(androidCap);
}
@Override
public void setStrokeCap(Cap cap) {
android.graphics.Paint.Cap androidCap = android.graphics.Paint.Cap
.valueOf(cap.name());
mPaint.setStrokeCap(androidCap);
}
@Override
public void setStrokeWidth(float width) {
mPaint.setStrokeWidth(width);
}
@Override
public void setStrokeWidth(float width) {
mPaint.setStrokeWidth(width);
}
@Override
public void setStyle(Style style) {
mPaint.setStyle(android.graphics.Paint.Style.valueOf(style.name()));
}
@Override
public void setStyle(Style style) {
mPaint.setStyle(android.graphics.Paint.Style.valueOf(style.name()));
}
@Override
public void setTextAlign(Align align) {
//mPaint.setTextAlign(android.graphics.Paint.Align.valueOf(align.name()));
}
@Override
public void setTextAlign(Align align) {
//mPaint.setTextAlign(android.graphics.Paint.Align.valueOf(align.name()));
}
@Override
public void setTextSize(float textSize) {
mPaint.setTextSize(textSize);
}
@Override
public void setTextSize(float textSize) {
mPaint.setTextSize(textSize);
}
@Override
public void setTypeface(FontFamily fontFamily, FontStyle fontStyle) {
Typeface typeface = Typeface.create(getTypeface(fontFamily),
getStyle(fontStyle));
mPaint.setTypeface(typeface);
}
@Override
public void setTypeface(FontFamily fontFamily, FontStyle fontStyle) {
Typeface typeface = Typeface.create(getTypeface(fontFamily),
getStyle(fontStyle));
mPaint.setTypeface(typeface);
}
@Override
public float measureText(String text) {
return mPaint.measureText(text);
}
@Override
public float measureText(String text) {
return mPaint.measureText(text);
}
@Override
public float getFontHeight() {
FontMetrics fm = mPaint.getFontMetrics();
return (float) Math.ceil(Math.abs(fm.bottom) + Math.abs(fm.top));
}
@Override
public float getFontHeight() {
FontMetrics fm = mPaint.getFontMetrics();
return (float) Math.ceil(Math.abs(fm.bottom) + Math.abs(fm.top));
}
@Override
public float getFontDescent() {
FontMetrics fm = mPaint.getFontMetrics();
// //fontDescent = (float) Math.ceil(Math.abs(fm.descent));
return Math.abs(fm.bottom);
}
@Override
public float getFontDescent() {
FontMetrics fm = mPaint.getFontMetrics();
// //fontDescent = (float) Math.ceil(Math.abs(fm.descent));
return Math.abs(fm.bottom);
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -1,72 +1,72 @@
package org.oscim.android.gl;
import android.opengl.GLSurfaceView;
import javax.microedition.khronos.egl.EGL10;
import javax.microedition.khronos.egl.EGLConfig;
import javax.microedition.khronos.egl.EGLDisplay;
import android.opengl.GLSurfaceView;
public class GlConfigChooser implements GLSurfaceView.EGLConfigChooser {
@Override
public EGLConfig chooseConfig(EGL10 egl, EGLDisplay display) {
int[] val = new int[1];
@Override
public EGLConfig chooseConfig(EGL10 egl, EGLDisplay display) {
int[] val = new int[1];
// Try to find a normal multisample configuration first.
int[] configSpec = {
EGL10.EGL_RED_SIZE, 5,
EGL10.EGL_GREEN_SIZE, 6,
EGL10.EGL_BLUE_SIZE, 5,
EGL10.EGL_ALPHA_SIZE, 8,
EGL10.EGL_DEPTH_SIZE, 16,
// Requires that setEGLContextClientVersion(2) is called on the view.
EGL10.EGL_RENDERABLE_TYPE, 4 /* EGL_OPENGL_ES2_BIT */,
EGL10.EGL_STENCIL_SIZE, 8,
EGL10.EGL_NONE };
// Try to find a normal multisample configuration first.
int[] configSpec = {
EGL10.EGL_RED_SIZE, 5,
EGL10.EGL_GREEN_SIZE, 6,
EGL10.EGL_BLUE_SIZE, 5,
EGL10.EGL_ALPHA_SIZE, 8,
EGL10.EGL_DEPTH_SIZE, 16,
// Requires that setEGLContextClientVersion(2) is called on the view.
EGL10.EGL_RENDERABLE_TYPE, 4 /* EGL_OPENGL_ES2_BIT */,
EGL10.EGL_STENCIL_SIZE, 8,
EGL10.EGL_NONE};
if (!egl.eglChooseConfig(display, configSpec, null, 0, val)) {
throw new IllegalArgumentException("eglChooseConfig failed");
}
int numConfigs = val[0];
if (!egl.eglChooseConfig(display, configSpec, null, 0, val)) {
throw new IllegalArgumentException("eglChooseConfig failed");
}
int numConfigs = val[0];
if (numConfigs <= 0) {
if (numConfigs <= 0) {
configSpec = new int[] {
// EGL10.EGL_RENDERABLE_TYPE, 4, EGL10.EGL_NONE };
EGL10.EGL_RED_SIZE, 8,
EGL10.EGL_GREEN_SIZE, 8,
EGL10.EGL_BLUE_SIZE, 8,
EGL10.EGL_ALPHA_SIZE, 8,
EGL10.EGL_DEPTH_SIZE, 16,
EGL10.EGL_RENDERABLE_TYPE, 4 /* EGL_OPENGL_ES2_BIT */,
EGL10.EGL_STENCIL_SIZE, 8,
EGL10.EGL_NONE };
configSpec = new int[]{
// EGL10.EGL_RENDERABLE_TYPE, 4, EGL10.EGL_NONE };
EGL10.EGL_RED_SIZE, 8,
EGL10.EGL_GREEN_SIZE, 8,
EGL10.EGL_BLUE_SIZE, 8,
EGL10.EGL_ALPHA_SIZE, 8,
EGL10.EGL_DEPTH_SIZE, 16,
EGL10.EGL_RENDERABLE_TYPE, 4 /* EGL_OPENGL_ES2_BIT */,
EGL10.EGL_STENCIL_SIZE, 8,
EGL10.EGL_NONE};
if (!egl.eglChooseConfig(display, configSpec, null, 0, val)) {
throw new IllegalArgumentException("eglChooseConfig failed");
}
numConfigs = val[0];
if (!egl.eglChooseConfig(display, configSpec, null, 0, val)) {
throw new IllegalArgumentException("eglChooseConfig failed");
}
numConfigs = val[0];
if (numConfigs <= 0) {
throw new IllegalArgumentException("No configs match configSpec");
}
}
if (numConfigs <= 0) {
throw new IllegalArgumentException("No configs match configSpec");
}
}
// Get all matching configurations.
EGLConfig[] configs = new EGLConfig[numConfigs];
if (!egl.eglChooseConfig(display, configSpec, configs, numConfigs, val)) {
throw new IllegalArgumentException("data eglChooseConfig failed");
}
// Get all matching configurations.
EGLConfig[] configs = new EGLConfig[numConfigs];
if (!egl.eglChooseConfig(display, configSpec, configs, numConfigs, val)) {
throw new IllegalArgumentException("data eglChooseConfig failed");
}
// CAUTION! eglChooseConfigs returns configs with higher bit depth
// first: Even though we asked for rgb565 configurations, rgb888
// configurations are considered to be "better" and returned first.
// You need to explicitly filter the data returned by eglChooseConfig!
// CAUTION! eglChooseConfigs returns configs with higher bit depth
// first: Even though we asked for rgb565 configurations, rgb888
// configurations are considered to be "better" and returned first.
// You need to explicitly filter the data returned by eglChooseConfig!
EGLConfig config = configs.length > 0 ? configs[0] : null;
if (config == null) {
throw new IllegalArgumentException("No config chosen");
}
return config;
}
EGLConfig config = configs.length > 0 ? configs[0] : null;
if (config == null) {
throw new IllegalArgumentException("No config chosen");
}
return config;
}
}

View File

@@ -20,46 +20,46 @@ import org.oscim.event.MotionEvent;
public class AndroidMotionEvent extends MotionEvent {
android.view.MotionEvent mEvent;
android.view.MotionEvent mEvent;
public MotionEvent wrap(android.view.MotionEvent e) {
mEvent = e;
return this;
}
public MotionEvent wrap(android.view.MotionEvent e) {
mEvent = e;
return this;
}
@Override
public int getAction() {
return mEvent.getAction();
}
@Override
public int getAction() {
return mEvent.getAction();
}
@Override
public float getX() {
return mEvent.getX();
}
@Override
public float getX() {
return mEvent.getX();
}
@Override
public float getY() {
return mEvent.getY();
}
@Override
public float getY() {
return mEvent.getY();
}
@Override
public float getX(int pointer) {
return mEvent.getX(pointer);
}
@Override
public float getX(int pointer) {
return mEvent.getX(pointer);
}
@Override
public float getY(int pointer) {
return mEvent.getY(pointer);
}
@Override
public float getY(int pointer) {
return mEvent.getY(pointer);
}
@Override
public int getPointerCount() {
return mEvent.getPointerCount();
}
@Override
public int getPointerCount() {
return mEvent.getPointerCount();
}
@Override
public long getTime() {
return mEvent.getEventTime();
}
@Override
public long getTime() {
return mEvent.getEventTime();
}
}

View File

@@ -1,66 +1,66 @@
package org.oscim.android.input;
import org.oscim.event.Gesture;
import org.oscim.map.Map;
import android.view.GestureDetector.OnDoubleTapListener;
import android.view.GestureDetector.OnGestureListener;
import android.view.MotionEvent;
public class GestureHandler implements OnGestureListener, OnDoubleTapListener {
private final AndroidMotionEvent mMotionEvent;
private final Map mMap;
import org.oscim.event.Gesture;
import org.oscim.map.Map;
public GestureHandler(Map map) {
mMotionEvent = new AndroidMotionEvent();
mMap = map;
}
public class GestureHandler implements OnGestureListener, OnDoubleTapListener {
private final AndroidMotionEvent mMotionEvent;
private final Map mMap;
public GestureHandler(Map map) {
mMotionEvent = new AndroidMotionEvent();
mMap = map;
}
/* GesturListener */
@Override
public boolean onSingleTapUp(MotionEvent e) {
// return mMap.handleGesture(Gesture.TAP, mMotionEvent.wrap(e));
return false;
}
@Override
public boolean onSingleTapUp(MotionEvent e) {
// return mMap.handleGesture(Gesture.TAP, mMotionEvent.wrap(e));
return false;
}
@Override
public void onShowPress(MotionEvent e) {
}
@Override
public void onShowPress(MotionEvent e) {
}
@Override
public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX, float distanceY) {
return false;
}
@Override
public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX, float distanceY) {
return false;
}
@Override
public void onLongPress(MotionEvent e) {
mMap.handleGesture(Gesture.LONG_PRESS, mMotionEvent.wrap(e));
}
@Override
public void onLongPress(MotionEvent e) {
mMap.handleGesture(Gesture.LONG_PRESS, mMotionEvent.wrap(e));
}
@Override
public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) {
return false;
}
@Override
public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) {
return false;
}
@Override
public boolean onDown(MotionEvent e) {
return mMap.handleGesture(Gesture.PRESS, mMotionEvent.wrap(e));
}
@Override
public boolean onDown(MotionEvent e) {
return mMap.handleGesture(Gesture.PRESS, mMotionEvent.wrap(e));
}
/* DoubleTapListener */
@Override
public boolean onSingleTapConfirmed(MotionEvent e) {
return mMap.handleGesture(Gesture.TAP, mMotionEvent.wrap(e));
}
/* DoubleTapListener */
@Override
public boolean onSingleTapConfirmed(MotionEvent e) {
return mMap.handleGesture(Gesture.TAP, mMotionEvent.wrap(e));
}
@Override
public boolean onDoubleTapEvent(MotionEvent e) {
return false;
}
@Override
public boolean onDoubleTapEvent(MotionEvent e) {
return false;
}
@Override
public boolean onDoubleTap(MotionEvent e) {
return mMap.handleGesture(Gesture.DOUBLE_TAP, mMotionEvent.wrap(e));
}
@Override
public boolean onDoubleTap(MotionEvent e) {
return mMap.handleGesture(Gesture.DOUBLE_TAP, mMotionEvent.wrap(e));
}
}