Previously it used TabActivity which has been deprecated and no longer works. bug: 29045104 Change-Id: I207f0208b6dba47adfa0ffe7485800d1561af617
73 lines
1.8 KiB
Java
73 lines
1.8 KiB
Java
/*
|
|
* (c)Copyright 2011 Google, Inc
|
|
*/
|
|
|
|
package com.widevine.demo;
|
|
|
|
import android.widget.ImageButton;
|
|
import android.view.MotionEvent;
|
|
import android.content.Context;
|
|
import android.graphics.Bitmap;
|
|
import android.graphics.BitmapFactory;
|
|
import android.graphics.Canvas;
|
|
import android.graphics.Rect;
|
|
|
|
public class ClipImageView extends ImageButton {
|
|
|
|
private boolean touchedDown;
|
|
private float touchX, touchY, radius;
|
|
private boolean radiusInc;
|
|
|
|
private Bitmap selectCircle;
|
|
|
|
public ClipImageView(Context ctxt) {
|
|
super(ctxt);
|
|
|
|
touchedDown = false;
|
|
|
|
BitmapFactory.Options options = new BitmapFactory.Options();
|
|
options.inDither = true;
|
|
selectCircle = BitmapFactory.decodeResource(getResources(), R.drawable.selection_circle,
|
|
options);
|
|
}
|
|
|
|
@Override
|
|
public boolean onTouchEvent(MotionEvent e) {
|
|
|
|
if (e.getAction() == MotionEvent.ACTION_DOWN) {
|
|
touchX = e.getX();
|
|
touchY = e.getY();
|
|
radius = 60;
|
|
radiusInc = false;
|
|
touchedDown = true;
|
|
|
|
} else if (e.getAction() == MotionEvent.ACTION_UP) {
|
|
touchedDown = false;
|
|
|
|
}
|
|
// return true;
|
|
return super.onTouchEvent(e);
|
|
}
|
|
|
|
@Override
|
|
protected void onDraw(Canvas canvas) {
|
|
super.onDraw(canvas);
|
|
if (touchedDown) {
|
|
canvas.drawBitmap(selectCircle, null, new Rect((int) (touchX - radius),
|
|
(int) (touchY - radius), (int) (touchX + radius),
|
|
(int) (touchY + radius)), null);
|
|
if (radiusInc) {
|
|
radius += 5;
|
|
}
|
|
else {
|
|
radius -= 5;
|
|
}
|
|
if (radius >= 60 || radius <= 0) {
|
|
radiusInc = !radiusInc;
|
|
}
|
|
}
|
|
|
|
invalidate();
|
|
}
|
|
}
|