If you think the Android project DivisionByZero 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.ggstudios.divisionbyzero;
/*www.java2s.com*/import com.ggstudios.utils.BitmapUtils;
import com.ggstudios.utils.BufferUtils;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.RectF;
/**
* The main purpose of this class is to provide a way to draw attention
* to something on screen through the use of some UI element.
* @author iDunnololz
*
*/publicclass TargetRectangle extends PictureBox implements Updatable{
// used for animation...
privatestaticfinalfloat DURATION = 0.3f;
privateboolean state = false;
privatefloat time = 0f;
/**
* Used for drawing the rectangle...
*/
Paint paint;
public TargetRectangle() {
super(0, 0);
paint = new Paint();
}
publicvoid setColor(int c) {
paint.setColor(c);
}
publicvoid setStrokeWidth(float w) {
paint.setStrokeWidth(w);
}
publicvoid setBounds(RectF rect) {
w = rect.right - rect.left;
h = rect.bottom - rect.top;
x = rect.left + w/2f;
y = rect.top + h/2f;
}
publicvoid build() {
Bitmap bmp = Bitmap.createBitmap((int)w, (int)h, Bitmap.Config.ARGB_8888);
Canvas c = new Canvas(bmp);
paint.setStyle(Paint.Style.STROKE);
c.drawRect(0, 0, w, h, paint);
setTextureHandle(BitmapUtils.loadBitmap(bmp));
float halfW = w / 2f;
float halfH = h / 2f;
float[] rect = {
-halfW, -halfH,
halfW, -halfH,
-halfW, halfH,
halfW, halfH,
};
handle = BufferUtils.copyToBuffer(rect);
}
@Override
publicvoid draw(float _x, float _y) {
super.draw(0, 0);
}
@Override
publicboolean update(float dt) {
time += dt;
if(time > DURATION) {
state = !state;
if(state) {
setScale(1.05f);
} else {
setScale(1f);
}
time -= DURATION;
}
return true;
}
@Override
publicvoid refresh() {
build();
}
}