how to use html5 canvas drag on android? - 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.

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.

detect if a touch event happens inside a shapeDrawable

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)

Reconciling scroll, fling, tap, zoom and pan on the same view in Android

I am working on an application that can read pdf documents and I am trying to implement zooming and panning on a pdf page.
The page is loaded as a bitmap and displayed in an ImageView. There are also some other functionalities already implemented such as navigating the pages in a document with a bottom custom navigation bar that can be scrolled.
Also, the bottom bar appears when the user taps on the page and disappears with the next tap and when flinging, users should be able to navigate to next/previous page in the document.
All functionality such as the scroll, tap and fling is handled by implementing OnGestureListener in the reader activity and I am trying to do the zoom and pan with an OnTouchListener implementation that is set on the ImageView containing the page.
The code seems to work, however it appears that some of the other events, especially the scroll, are interfering with it which makes it slow.
My question is if there is a better way to go about reconciling everything, since the OnGestureListener is used for the GestureDetector's handling of onFling, onTapUp and onScroll, but I can't find a good way to add the zoom/pan code in one of the methods supported by this.
So, if anyone has some experience on handling all these events for one view or some good suggestions/tutorials on this, I would very much appreciate it.
I'm not sure what you mean by 'some other events such as the scroll make it slow', could you elaborate?
You should be able to perform zoom and pan using onTouch fairly trivially, without scrolling being an issue if you choose to use Canvas. Full implementation code can be found at Touch and drag image in android for scrolling, and http://www.zdnet.com/blog/burnette/how-to-use-multi-touch-in-android-2-part-6-implementing-the-pinch-zoom-gesture/1847 for zooming.
It's generally not common to see advanced interactive features applied solely on an ImageView, but that doesn't mean people haven't done it (see How can I get zoom functionality for images? for zoom examples including support for multi-touch or Adding Fling Gesture to an image view - Android ).
Regardless of which way you do it, you'll probably want a GestureDetector in your onTouch function. You should be able to just cut and splice together sections of the tutorials I've linked to in order to get full gesture support + zoom/pan. However, if I were doing it, I would probably just use onTouch with Canvas (since Canvas will give better performance) and use the core MotionEvents such as DOWN MOVE UP for greater control, or if I was feeling lazy, use a GestureDetector for trickier bits like flinging.

Categories

Resources