======================
LOOK! LICENSING TERMS
======================
look! is licensed under the BSD 3-Clause (also known as "BSD New" or
"BSD Simplified"), as follows:
Copyright (c) 2010-2012, Look...
If you think the Android project Look 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
/**
*-----------------------------------------------------------------------------
* Copyright (c) 2012, Look! Development Team
* All rights reserved./*fromwww.java2s.com*/
*
* Distributed under the terms of the BSD Simplified License.
*
* The full license is in the LICENSE file, distributed with this software.
*-----------------------------------------------------------------------------
*/package es.ucm.look.ar.ar2D.drawables;
import java.util.ArrayList;
import java.util.List;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.Rect;
import es.ucm.look.ar.ar2D.Drawable2D;
publicclass Image2D implements Drawable2D {
private List<Bitmap> bitmaps;
privateint timePerFrame = 0;
privateint currentFrame = 0;
privateint elapsedTime = 0;
private Rect dst;
privateboolean loop;
public Image2D(Bitmap bitmap, int width, int height) {
this.bitmaps = new ArrayList<Bitmap>();
bitmaps.add(bitmap);
dst = new Rect();
dst.left = -width / 2;
dst.right = width / 2;
dst.top = -height / 2;
dst.bottom = height / 2;
}
public Image2D(Bitmap bitmap) {
this(bitmap, bitmap.getWidth(), bitmap.getHeight());
}
public Image2D(List<Bitmap> bitmaps, int timePerFrame, boolean loop) {
this.bitmaps = bitmaps;
this.timePerFrame = timePerFrame;
dst = new Rect();
int width = bitmaps.get(0).getWidth();
int height = bitmaps.get(0).getHeight();
dst.left = -width / 2;
dst.right = width / 2;
dst.top = -height / 2;
dst.bottom = height / 2;
this.loop = loop;
}
@Override
publicvoid draw(Canvas c) {
Bitmap bitmap = bitmaps.get(currentFrame);
c.drawBitmap(bitmap, null, dst, new Paint());
}
@Override
publicvoid update(long elapsed) {
elapsedTime += elapsed;
while (elapsedTime >= timePerFrame) {
currentFrame++;
elapsedTime -= timePerFrame;
}
if ( loop ){
if ( currentFrame >= bitmaps.size() ){
currentFrame = bitmaps.size() - 1;
}
}
else
currentFrame = currentFrame % bitmaps.size();
}
@Override
publicvoid drawTouchableArea(Canvas c, Paint p) {
c.drawRect(dst, p);
}
}