split up
This commit is contained in:
117
vtm-android/src/org/oscim/android/canvas/AndroidGraphics.java
Normal file
117
vtm-android/src/org/oscim/android/canvas/AndroidGraphics.java
Normal file
@@ -0,0 +1,117 @@
|
||||
/*
|
||||
* Copyright 2010, 2011, 2012 mapsforge.org
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify it under the
|
||||
* terms of the GNU Lesser General Public License as published by the Free Software
|
||||
* Foundation, either version 3 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT ANY
|
||||
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
|
||||
* PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License along with
|
||||
* this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package org.oscim.android.canvas;
|
||||
|
||||
import java.io.InputStream;
|
||||
|
||||
import org.oscim.backend.CanvasAdapter;
|
||||
import org.oscim.backend.canvas.Bitmap;
|
||||
import org.oscim.backend.canvas.Canvas;
|
||||
import org.oscim.backend.canvas.Paint;
|
||||
import org.oscim.layers.overlay.OverlayItem.HotspotPlace;
|
||||
import org.oscim.layers.overlay.OverlayMarker;
|
||||
|
||||
import android.content.res.Resources;
|
||||
import android.graphics.Bitmap.Config;
|
||||
import android.graphics.drawable.BitmapDrawable;
|
||||
import android.graphics.drawable.Drawable;
|
||||
|
||||
public final class AndroidGraphics extends CanvasAdapter {
|
||||
public static final AndroidGraphics INSTANCE = new AndroidGraphics();
|
||||
|
||||
// public static android.graphics.Bitmap getAndroidBitmap(Bitmap bitmap) {
|
||||
// return ((AndroidBitmap) bitmap).bitmap;
|
||||
// }
|
||||
|
||||
public static android.graphics.Paint getAndroidPaint(Paint paint) {
|
||||
return ((AndroidPaint) paint).mPaint;
|
||||
}
|
||||
|
||||
private AndroidGraphics() {
|
||||
// do nothing
|
||||
}
|
||||
|
||||
@Override
|
||||
public Bitmap decodeBitmap(InputStream inputStream) {
|
||||
return new AndroidBitmap(inputStream);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getColor(Color color) {
|
||||
switch (color) {
|
||||
case BLACK:
|
||||
return android.graphics.Color.BLACK;
|
||||
|
||||
case CYAN:
|
||||
return android.graphics.Color.CYAN;
|
||||
|
||||
case TRANSPARENT:
|
||||
return android.graphics.Color.TRANSPARENT;
|
||||
|
||||
case WHITE:
|
||||
return android.graphics.Color.WHITE;
|
||||
}
|
||||
|
||||
throw new IllegalArgumentException("unknown color value: " + color);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Paint getPaint() {
|
||||
return new AndroidPaint();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int parseColor(String colorString) {
|
||||
return android.graphics.Color.parseColor(colorString);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Bitmap getBitmap(int width, int height, int format) {
|
||||
return new AndroidBitmap(width, height, format);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Canvas getCanvas() {
|
||||
return new AndroidCanvas();
|
||||
}
|
||||
|
||||
//-------------------------------------
|
||||
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.Canvas canvas = new android.graphics.Canvas(bitmap);
|
||||
drawable.setBounds(0, 0, canvas.getWidth(), canvas.getHeight());
|
||||
drawable.draw(canvas);
|
||||
|
||||
return new AndroidBitmap(bitmap);
|
||||
}
|
||||
|
||||
public static OverlayMarker makeMarker(Resources res, int id, HotspotPlace place) {
|
||||
|
||||
if (place == null)
|
||||
place = HotspotPlace.CENTER;
|
||||
|
||||
Drawable drawable = res.getDrawable(id);
|
||||
|
||||
return new OverlayMarker(drawableToBitmap(drawable), place);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user