If you think the Android project android-maps-utils listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
Java Source Code
package com.google.maps.android.utils.demo;
//fromwww.java2s.comimport android.graphics.Canvas;
import android.graphics.ColorFilter;
import android.graphics.drawable.Drawable;
import java.util.List;
/**
* Draws up to four other drawables.
*/publicclass MultiDrawable extends Drawable {
privatefinal List<Drawable> mDrawables;
public MultiDrawable(List<Drawable> drawables) {
mDrawables = drawables;
}
@Override
publicvoid draw(Canvas canvas) {
if (mDrawables.size() == 1) {
mDrawables.get(0).draw(canvas);
return;
}
int width = getBounds().width();
int height = getBounds().height();
canvas.save();
canvas.clipRect(0, 0, width, height);
if (mDrawables.size() == 2 || mDrawables.size() == 3) {
// Paint left half
canvas.save();
canvas.clipRect(0, 0, width / 2, height);
canvas.translate(-width / 4, 0);
mDrawables.get(0).draw(canvas);
canvas.restore();
}
if (mDrawables.size() == 2) {
// Paint right half
canvas.save();
canvas.clipRect(width / 2, 0, width, height);
canvas.translate(width / 4, 0);
mDrawables.get(1).draw(canvas);
canvas.restore();
} else {
// Paint top right
canvas.save();
canvas.scale(.5f, .5f);
canvas.translate(width, 0);
mDrawables.get(1).draw(canvas);
// Paint bottom right
canvas.translate(0, height);
mDrawables.get(2).draw(canvas);
canvas.restore();
}
if (mDrawables.size() >= 4) {
// Paint top left
canvas.save();
canvas.scale(.5f, .5f);
mDrawables.get(0).draw(canvas);
// Paint bottom left
canvas.translate(0, height);
mDrawables.get(3).draw(canvas);
canvas.restore();
}
canvas.restore();
}
@Override
publicvoid setAlpha(int i) {
}
@Override
publicvoid setColorFilter(ColorFilter colorFilter) {
}
@Override
publicint getOpacity() {
return 0;
}
}