App

- Main Page
- Related Pages
- Namespaces
- Classes
- Files

- Class List
- Class Index
- Class Hierarchy
- Class Members

Classes | Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
mhr.appandroid.views.CropPicker Class Reference
Inheritance diagram for mhr.appandroid.views.CropPicker:

## Classes
interface | CropPickerEventListener

## Public Member Functions
| CropPicker (Context context)
| CropPicker (Context context, AttributeSet attrs)
| CropPicker (Context context, AttributeSet attrs, int defStyle)
void | setListener (CropPickerEventListener l)
RectF | getCrop ()
void | setCrop (RectF crop)
void | resetCrop ()
void | onMeasure (int widthMeasureSpec, int heightMeasureSpec)
boolean | onTouchEvent (MotionEvent ev)

## Protected Member Functions
void | init ()
void | updateRects ()
void | onSizeChanged (int w, int h, int oldw, int oldh)
| Voláno v okamžiku, kdy view dostane rozměry.
void | onDraw (Canvas canvas)
| Provádí vykreslení dle stavu.

## Protected Attributes
Bitmap | cPressed
Bitmap | cNormal
Rect | cRect
Paint | bgPaint
Paint | lnPaint
Rect[] | curs
Rect | selCur = null
int | selCutIndex
RectF | crop
RectF | maxRect
float | lastX
float | lastY
int | cWidth
int | cHeight
int | cXCenter
int | cYCenter
CropPickerEventListener | listener = null

## Detailed Description

Definition at line 22 of file CropPicker.java.

## Constructor & Destructor Documentation

mhr.appandroid.views.CropPicker.CropPicker | ( | Context | context | ) |
| inline

Definition at line 88 of file CropPicker.java.

{
super(context);
init();
}

mhr.appandroid.views.CropPicker.CropPicker | ( | Context | context,
|  | AttributeSet | attrs
| ) |  |
| inline

Definition at line 93 of file CropPicker.java.

{
super(context, attrs);
init();
}

mhr.appandroid.views.CropPicker.CropPicker | ( | Context | context,
|  | AttributeSet | attrs,
|  | int | defStyle
| ) |  |
| inline

Definition at line 98 of file CropPicker.java.

{
super(context, attrs, defStyle);
init();
}

## Member Function Documentation

RectF mhr.appandroid.views.CropPicker.getCrop | ( |  | ) |
| inline

Definition at line 140 of file CropPicker.java.

{
return new RectF(crop);
}

void mhr.appandroid.views.CropPicker.init | ( |  | ) |
| inlineprotected

Definition at line 65 of file CropPicker.java.

{
setLayerType(View.LAYER_TYPE_SOFTWARE, null);
cPressed = BitmapFactory.decodeResource(getResources(), R.drawable.scrubber_control_pressed_bw);
cNormal = BitmapFactory.decodeResource(getResources(), R.drawable.scrubber_control_normal_bw);
bgPaint = new Paint();
bgPaint.setColor(0xFF545454);
lnPaint = new Paint();
lnPaint.setColor(0xFFFFFFFF);
lnPaint.setStyle(Style.STROKE);
lnPaint.setStrokeWidth(5);
lnPaint.setAntiAlias(true);
cWidth = cNormal.getWidth();
cHeight = cNormal.getHeight();
cXCenter = cWidth / 2;
cYCenter = cHeight / 2;
cRect = new Rect(0, 0, cNormal.getWidth(), cNormal.getHeight());
}

void mhr.appandroid.views.CropPicker.onDraw | ( | Canvas | canvas | ) |
| inlineprotected

Provádí vykreslení dle stavu.

Definition at line 173 of file CropPicker.java.

{
updateRects();
canvas.drawColor(0x00000000);
Path pth = new Path();
pth.addRect(0, 0, maxRect.right, crop.top, Direction.CW);
pth.addRect(0, crop.top, crop.left, crop.bottom, Direction.CW);
pth.addRect(crop.right, crop.top, maxRect.right, crop.bottom, Direction.CW);
pth.addRect(0, crop.bottom, maxRect.right, maxRect.bottom, Direction.CW);
ShapeDrawable sdr = new ShapeDrawable(new PathShape(pth, maxRect.width(), maxRect.height()));
Paint paint = sdr.getPaint();
paint.setStyle(Style.FILL);
paint.setColor(0xAA000000);
sdr.setBounds((int)maxRect.left, (int)maxRect.top, (int)maxRect.right, (int)maxRect.bottom);
sdr.draw(canvas);
canvas.drawLines(new float[] {
crop.left, crop.top, crop.right, crop.top,
crop.left, crop.top, crop.left, crop.bottom,
crop.left, crop.bottom, crop.right, crop.bottom,
crop.right, crop.top, crop.right, crop.bottom,
}, lnPaint);
for (Rect r : curs) {
if (r == selCur) {
canvas.drawBitmap(cPressed, null, r, null);
} else {
canvas.drawBitmap(cNormal, null, r, null);
}
}
}

void mhr.appandroid.views.CropPicker.onMeasure | ( | int | widthMeasureSpec,
|  | int | heightMeasureSpec
| ) |  |
| inline

Definition at line 156 of file CropPicker.java.

{
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
}

void mhr.appandroid.views.CropPicker.onSizeChanged | ( | int | w,
|  | int | h,
|  | int | oldw,
|  | int | oldh
| ) |  |
| inlineprotected

Voláno v okamžiku, kdy view dostane rozměry.

Definition at line 162 of file CropPicker.java.

{
super.onSizeChanged(w, h, oldw, oldh);
maxRect = new RectF(0, 0, w, h);
crop = new RectF(w / 4, h / 4, 3 * w / 4, 3 * h / 4);
curs = new Rect[] { new Rect(), new Rect(),new Rect(),new Rect() };
}

boolean mhr.appandroid.views.CropPicker.onTouchEvent | ( | MotionEvent | ev | ) |
| inline

Definition at line 206 of file CropPicker.java.

{
float x = ev.getX();
float y = ev.getY();
switch (ev.getAction()) {
case MotionEvent.ACTION_DOWN:
for (int i = 0; i < curs.length; i++) {
if (curs[i].contains((int)x, (int)y)) {
selCur = curs[i];
selCutIndex = i;
break;
}
}
if (selCur != null) {
lastX = x;
lastY = y;
if (listener != null) {
listener.onStartTrackingCrop(this);
}
}
break;
case MotionEvent.ACTION_MOVE:
if (selCur != null) {
switch (selCutIndex) {
case 0:
crop.left += x - lastX;
crop.left = (crop.left < crop.right) ? crop.left : crop.right;
crop.top += y - lastY;
crop.top = (crop.top < crop.bottom) ? crop.top : crop.bottom;
break;
case 1:
crop.right += x - lastX;
crop.right = (crop.left < crop.right) ? crop.right : crop.left;
crop.top += y - lastY;
crop.top = (crop.top < crop.bottom) ? crop.top : crop.bottom;
break;
case 2:
crop.left += x - lastX;
crop.left = (crop.left < crop.right) ? crop.left : crop.right;
crop.bottom += y - lastY;
crop.bottom = (crop.top < crop.bottom) ? crop.bottom : crop.top;
break;
case 3:
crop.right += x - lastX;
crop.right = (crop.left < crop.right) ? crop.right : crop.left;
crop.bottom += y - lastY;
crop.bottom = (crop.top < crop.bottom) ? crop.bottom : crop.top;
break;
default:
break;
}
lastX = x;
lastY = y;
crop.setIntersect(maxRect, crop);
if (listener != null) {
listener.onCropChanged(this);
}
invalidate();
}
break;
case MotionEvent.ACTION_UP:
if (selCur != null) {
selCur = null;
if (listener != null) {
listener.onStopTrackingCrop(this);
}
invalidate();
}
break;
}
return true;
}

void mhr.appandroid.views.CropPicker.resetCrop | ( |  | ) |
| inline

Definition at line 149 of file CropPicker.java.

{
crop = new RectF(maxRect.right / 4, maxRect.bottom / 4, 3 * maxRect.right / 4, 3 * maxRect.bottom / 4);
invalidate();
}

void mhr.appandroid.views.CropPicker.setCrop | ( | RectF | crop | ) |
| inline

Definition at line 144 of file CropPicker.java.

{
this.crop = crop;
invalidate();
}

void mhr.appandroid.views.CropPicker.setListener | ( | CropPickerEventListener | l | ) |
| inline

Definition at line 136 of file CropPicker.java.

{
listener = l;
}

void mhr.appandroid.views.CropPicker.updateRects | ( |  | ) |
| inlineprotected

Definition at line 105 of file CropPicker.java.

{
Rect r;
r = curs[0];
r.left = (int)(crop.left - cXCenter);
r.top = (int)(crop.top - cYCenter);
r.right = (int)(crop.left + cWidth - cXCenter);
r.bottom = (int)(crop.top + cHeight - cYCenter);
r = curs[1];
r.left = (int)(crop.right - cXCenter);
r.top = (int)(crop.top - cYCenter);
r.right = (int)(crop.right + cWidth - cXCenter);
r.bottom = (int)(crop.top + cHeight - cYCenter);
r = curs[2];
r.left = (int)(crop.left - cXCenter);
r.top = (int)(crop.bottom - cYCenter);
r.right = (int)(crop.left + cWidth - cXCenter);
r.bottom = (int)(crop.bottom + cHeight - cYCenter);
r = curs[3];
r.left = (int)(crop.right - cXCenter);
r.top = (int)(crop.bottom - cYCenter);
r.right = (int)(crop.right + cWidth - cXCenter);
r.bottom = (int)(crop.bottom + cHeight - cYCenter);
}

## Member Data Documentation

Paint mhr.appandroid.views.CropPicker.bgPaint
| protected

Definition at line 41 of file CropPicker.java.

int mhr.appandroid.views.CropPicker.cHeight
| protected

Definition at line 55 of file CropPicker.java.

Bitmap mhr.appandroid.views.CropPicker.cNormal
| protected

Definition at line 38 of file CropPicker.java.

Bitmap mhr.appandroid.views.CropPicker.cPressed
| protected

Definition at line 37 of file CropPicker.java.

Rect mhr.appandroid.views.CropPicker.cRect
| protected

Definition at line 39 of file CropPicker.java.

RectF mhr.appandroid.views.CropPicker.crop
| protected

Definition at line 48 of file CropPicker.java.

Rect [] mhr.appandroid.views.CropPicker.curs
| protected

Definition at line 44 of file CropPicker.java.

int mhr.appandroid.views.CropPicker.cWidth
| protected

Definition at line 54 of file CropPicker.java.

int mhr.appandroid.views.CropPicker.cXCenter
| protected

Definition at line 56 of file CropPicker.java.

int mhr.appandroid.views.CropPicker.cYCenter
| protected

Definition at line 57 of file CropPicker.java.

float mhr.appandroid.views.CropPicker.lastX
| protected

Definition at line 51 of file CropPicker.java.

float mhr.appandroid.views.CropPicker.lastY
| protected

Definition at line 52 of file CropPicker.java.

CropPickerEventListener mhr.appandroid.views.CropPicker.listener = null
| protected

Definition at line 59 of file CropPicker.java.

Paint mhr.appandroid.views.CropPicker.lnPaint
| protected

Definition at line 42 of file CropPicker.java.

RectF mhr.appandroid.views.CropPicker.maxRect
| protected

Definition at line 49 of file CropPicker.java.

Rect mhr.appandroid.views.CropPicker.selCur = null
| protected

Definition at line 45 of file CropPicker.java.

int mhr.appandroid.views.CropPicker.selCutIndex
| protected

Definition at line 46 of file CropPicker.java.

The documentation for this class was generated from the following file:

- /home/xxx/eclipse_workspaces/app/appandroid/src/mhr/appandroid/views/CropPicker.java