Home > Mobile >  The ticket confirmation of custom view click regions in figure function as flash back
The ticket confirmation of custom view click regions in figure function as flash back

Time:11-05

This is my online to find a similar one, I changed, is that he will get the current state of the seat to a list, a list containing the number of the Point type, I give him to the first data is I * m + j, said the first row of the first j column, then the second data 1 is selected, this time with the picture of the green, 2 said confirmation has been selected, in red, images,
This seems to be updated in real time, then I create a rectangular section, instead of the confirm button to do the work, had been added a button component and then calls the function outside unsure (), the results not only change, should now feel I was unsure () and response way,,, here is a custom View class and I error related content, parameter definitions and some basic functions are actually I deleted
 package 

Public class MoveSeatView extends the View {

Private void init () {
Horizontal spacing//seat
Spacing=(int) dip2px (5);
//seat vertical spacing
Dip2px verSpacing=(int) (10);
//minimum width of the screen
Dip2px defaultScreenWidth=(int) (80);
//optional seat picture
SeatBitmap=BitmapFactory. DecodeResource (getResources (), R.d. Rawable seat_default);
XScalel=defaultImgW/seatBitmap getWidth ();
YScalel=defaultImgH/seatBitmap getHeight ();
CheckedSeatBitmap=BitmapFactory. DecodeResource (getResources (), R.d. Rawable seat_green);
UnsureSeatBitmap=BitmapFactory. DecodeResource (getResources (), R.d. Rawable seat_goal);
SeatBitmapWidth=(int) (column * seatBitmap getWidth () + (column 1) * * xScalel spacing);
SeatBitmapHeight=(int) (row * seatBitmap getHeight () + (row 1) * * yScalel verSpacing);
Paint. SetColor (Color. RED);
//line width
NumberWidth=(int) dip2px (20);
ScreenHeight=dip2px (20);
List=new ArrayList<& gt; (a);
Matrix. PostTranslate (numberWidth + spacing, + 1 + screenHeight verSpacing);
}

@ Override
Protected void ontouch (Canvas, Canvas) {
If (row & lt;=0 | | the column & lt;=0) {
The return;
}
/* if (mTouch)
{
Unsure ();
} */
Paint. SetColor (Color. RED);
Canvas. DrawRect (80100, 0280110, paint);
DrawSeat (canvas);
Super. Ontouch (canvas);
}
@ Override
Public Boolean onTouchEvent (MotionEvent event) {
Int x=(int) event. GetX ();
Int y=(int) event. GetY ();
GestureDetector. OnTouchEvent (event);
The switch (event. GetAction ())
{
Case MotionEvent. ACTION_DOWN:
If (x>=80 & amp; & x<=280 & amp; & Y>=1000 & amp; & Y
=1100){
Toast. MakeText (getContext (), "Hello," Toast. LENGTH_SHORT), show ();
Unsure ();
}
break;
Case MotionEvent. ACTION_UP:
break;
}
return true;
}


Private void drawSeat (Canvas, Canvas) {
Zoom=getMatrixScaleX ();
Float translateX=getTranslateX ();
Float translateY=getTranslateY ();
Float scaleX=zoom;
Float scaleY=zoom;
for (int i=0; I & lt; The row. I++) {
Float top=I * seatBitmap getHeight () * * scaleY yScalel verSpacing + I * * scaleY + translateY;
Float bottom=top + seatBitmap. GetHeight () * * scaleY yScalel;

For (int j=0; J & lt; The column; J++) {
Float left=j * seatBitmap getWidth () * * scaleX xScalel xScalel spacing + j * * * scaleX + translateX;
Float right=left + seatBitmap. GetWidth () * * scaleX xScalel;
TempMatrix. SetTranslate (left, top);
TempMatrix. PostScale (xScalel yScalel, left, top);
TempMatrix. PostScale (scaleX, scaleY, left, top);
If (isHave (I + j * column, 1)) {
Canvas. DrawBitmap (checkedSeatBitmap tempMatrix, paint);
//drawText (canvas, I, j, top, left);
} else if (isHave (I + j * column, 2)) {
Canvas. DrawBitmap (unsureSeatBitmap tempMatrix, paint);
} else {
Canvas. DrawBitmap (seatBitmap tempMatrix, paint);
}
}
}
}
GestureDetector GestureDetector=new GestureDetector (getContext (), new GestureDetector. SimpleOnGestureListener () {
@ Override
Public Boolean onSingleTapConfirmed (MotionEvent e) {
Int x=(int) um participant etX ();
Int y=(int) um participant etY ();
/* if (x==9 & amp; & Y==1)
{
Unsure ();
} else {*/
for (int i=0; I & lt; The row. I++) {
For (int j=0; J & lt; The column; J++) {
Int tempX=(int) (spacing) seatWidth + j (j * * * getMatrixScaleX () + getTranslateX ());
Int maxTempX=(int) (tempX + seatWidth * getMatrixScaleX ());
Int tempY=(int) ((I + seatHeight * I * verSpacing) * getMatrixScaleY () + getTranslateY ());
Int maxTempY=(int) (tempY + seatHeight * getMatrixScaleY ());
If (x & gt;=tempX & amp; & X & lt;=maxTempX & amp; & Y & gt;=tempY & amp; & Y & lt;={maxTempY)
If (isHave (I + j * column, 1)) {
Remove (I + j * column, 1);
} else {
List. The add (new Point (I + j * column, 1));
}
}
}
}
Invalidate ().
//}

return true;
}
});
Protected void unsure ()
{
For (Point Point: list) {
If (point. Y==1) {
List. The add (new Point (Point x, 2));
List. Remove (point);
}
}
The return;
}


Public void setData (int row, int column) {
Enclosing the row=row;
Enclosing the column=column;
init();
Invalidate ().
}

}



Here is the log:
The 2019-05-28 16:33:35. 138, 6504-6504/com. Example. Movieticket E/InputEventReceiver: Exception dispatching input event.
nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull
  • Related