detect if a touch event happens inside a shapeDrawable - android

I am drawing a number of ShapeDrawables through a canvas in a custom android view. I have an onTouchEvent method and it's working fine. Everything is working fine. Now I want to be able to detect if a touch event intersects (i.e. happens inside) a certain ShapeDrawable. Is there a way to do that?

I got the answer:
sd.getBounds().contains(x, y)

Related

Drag & Drop OnTouch irregular shaped images

I am working on a simple app, which will allow moving one ImageView & dropping it on another ImageView. I am having problems with how onTouch works. It seems that it always takes rectangular input.
Let's say I have a shape like that:
Link
All small dots represent places which will trigger onTouch. But only green ones should... So in other words, I do not want Drag to be triggered when I am touching transparent part of the image.
Is this possible?
BR,
Kuba
If anyone will stumble upon this question, here is an answer: You must extend the DragShadowBuilder class to achieve that. More details in below question:
Set custom anchor when dragging a View

How to send touch event equally to gesture Overlay view and Canvas

I do not know what is going on. I am hiding the gesture drawing , rather then this I am planning to show the the drawing drawn by the paint and canvas.I am using the drawing panel class which is working fine if used alone as shown in this question. It is drawing perfectly.
Now what I was thinking and tried is this , I have implemented the gesture overlay view alone and it was working and detecting gesture. But due to some reasons I am manipulating these two methods all together 1.Paint to draw on canvas 2 gesture to recognize user gesture while drawing on Canvas
Now what I am trying and expecting is , When user draw A on canvas the the canvas starting following the user finger and starts drawing but I think as when the gesture overlay starts detecting gesture, it looks like that the touch is passed to gesture overlay view where as the Paint and canvas stops further drawing.
What I want :
I want that the touch event should be received by the canvas and gesture overlay equally , so that they both work independently.
In simple Words , Do you have any idea how to send touch event to both of these equally ?
Ok there it is , I found the solution , if some one also trying to get it , I mean to use Gesture overlay view , while having other child. Just put the following line in the gesture overlay view xml
android:eventsInterceptionEnabled="false"
and it would start working .

android ImageView vs canvas for game

I´m new in android development. I want to create a game where the user needs to quickly drag and drop balls with the finger in the screen to specific locations in order to win.
I don´t know if i can do this with simple ImageViews or i need to use canvas or other thing to draw in the screen.
I have tried to drag and drop an ImageView on top of another ImageView but it does not seem to work very well and i'm hesitating if i need to do it drawing figures instead of using the ImageViews or to do something else.
Please advice. Any help is apreciated. Thank you.
ImageViews are Views designed to hold image drawables, which isn't really needed in your case - you can use a simple View with a color background or implemended onDraw method, you can use an ImageView just as well.
Asfor the drag and drop, what you need is any View with implemented onTouch method so that the view changes its position on screen with ACTION_MOVE touch events.
If you're interested, i have implemented a simple frame layout with drag and drop functionality. My layout requires long-click to start drag, but it can be easily modified so it won't. Check it out at my github page. You can clone the project and run demo activity to see how it works, and start from there.

how to use html5 canvas drag on android?

I want to use a WebView with a canvas, and to be able to use touch to drag items in the canvas. The canvas is displayed just fine, and clicking works, but moving only scrolls. I've disabled scrolling, but it still doesn't work. Any ideas?
I found working html here
http://developer.appcelerator.com/question/55121/html5-canvas-drawing-in-webview
It appears that I need to learn more about the difference between touch events and mouse events.

Android SDK: Create image on touch

I'm a bit stumped here, I'm trying to make it so an image (already in the drawable folder) gets created everytime you touch the screen and removed when the finger is lifted. I have the touch part coded already, overriding the onTouch method with a couple switch cases that handle each type of action (down, up, move, etc). But I can't for the life of me figure out how to make the image appear and then disappear with the coordinates (matrix?) of where the finger is.
Any help would be greatly appreciated!
You could use an object of the ImageView class to draw the image.
Get the co-ordinates of the touch event using the MotionEvent.getX(), MotionEvent.getY() or MotionEvent.getRawX(), MotionEvent.getRawY() functions (use the appropriate one depending on the kind of layout you are using, linear/relative). Use these co-ordinates as your ImageView object's left and top margins respectively.
Regrds,
Anirudh.

Categories

Resources