My WebView loads a web page and this web page contains some images. Are there any ways to get coordinates of these images on screen when they is clicked ?
I need the coordinates of these images because I want to play some animations when people click on them but now i'm totally stuck with getting image's location :(.
Any helps will be appreciated. Thanks so much!
Since the website is also yours, you can use a javascript bridge to determine when an image was clicked, and in combination with dispatchTouchEvent you can get the exact tap location on the screen. The steps that you could take are:
monitor all tap events on the screen in the dispatchTouchEvent method of your activity
save the last touch on the screen
monitor image clicks using your javascript interface
when an image is clicked, use the last saved tap location you got in dispatchTouchEvent
Related
hello guys I need your help I need to save progress data in my app . I created an App for letter tracing and I want to save the progress of the which letter is done tracing . like the color of image will be change if the letter is done tracing. or it will have star and when the app is close I want the progress is still there and not to start all over again. please help me guys this the screenshots of my app.
When user swipes the finger on the screen you get (x,y) points of the touch events, so you can save the array of the (x,y) points the moment the user lifts his finger of the screen. As there may be a lot of points to save, you can decrease data by saving every second or third point in the array. Doing so will decrease the data you will work with but it also decrease the precision of the user line.
I want to create an interactive graphic for my app. It will essentially be a simple picture of a bus line where users can select 2 stops at a time (one for departure times and another for arrivals) I'm not sure how to create this image though, and have it have 20 or so different clickable points. Is there a framework I could use for this? Or is there a way to do this in pure android?
Thanks for the help.
I would suggest writing an onClick listener and using a collection of Rect instances to manage the collision/position of the 'click'. Check out the on click page and the rect page.
One thing to keep in mind are the origin point of your clicks, I'd assume you'll want to use one corner of your image as the point (0,0) and reference everything (clicks and rects) from there.
I would say try to create an ImageView to load your image and set a touch event listener or a click listener to that view. Hard code all places that you want your image to react upon a click.
Check click using an event listener would require you to handle both ACTION_DOWN and ACTION_UP in the MotionEvent object passed in. But it's easier to grab the coordinate of where the user clicks on the page, so you only need one listener but needs to put more work on handling the conversion from the coordinate passed in by MotionEvent to the coordinate on image. This is particular a major issue when your image can be sized larger than the screen size.
Using a click listener would save you from this trouble. As #smitec said, you need to overlay rectangles on your image as "buttons", so you can react to user input based on which buttons they pressed. This way you need to bind listeners to all of them (I suppose) and hard code their positions on your image. But, as mentioned earlier, it saves you from dealing with coordinates later on.
Is there any way to create a 360 degree object view from photos? I have a set of 71 photos of a single car viewed from different angles. I want to combine them and be able to rotate the car when touching the screen seeing it from different angles.
I've done researching but I couldn't find anything done in android. One example is found here
This example is made with Jquery. What I need is to implement it directly inside an android app. How can I do this?
Edit1: Until now I managed to create an animation between images in this way:
The problem is that the animation starts on click and works by itself. I want to be able to move the car from left to right and right to left when keeping the finger pressed and moving to right or left. How can I do that so I can see the car from the angle I want?
I just tested that Jquery plugin page on my device and it seems to work alright. So you could still presumeably use that plugin to make some html content that you could then load into a WebView. That would give the rotation thing inside of your application.
If you don't want to use html/javascript to do it you'll have to use an ImageView with a TouchListener attached to it that handles the drag events by swapping to the next image at the appropriate interval.
Or probably somehow with Canvas, though I am not as familiar with that, I would knot how to describe what you'd need to do to make it work this way.
After hours of trying to accomplish this task I stopped using the Drawable animation method because at point I was loading the images the app would of crashed because was out of memory.
Instead I found another way to do it which I use it right now. Example
I changed the .html with the images I need and the layout I want then I implement it inside my app using a webview. Is working pretty well.
I'm trying to combine the capability of doing image zoom/panning
inside of a Gallery view. The problem is controlling which touch
events are processed by each. In a horizontal drag on the image, the
ImageView needs to process the drag in order to pan, up until the edge
of the image is reached then the gallery view needs to process the
touch event so that it can swipe over to the next photo.
It seems that if I return false from the imageview's ontouchevent,
then I won't be notified of the panning-drag move events.
What I tried to do was return true from the imageview's ontouchevent
until the edge of the image was hit then return false. However I
believe that this doesn't cause the Gallery to begin processing these
events, as it missed the initial touchdown event.
My next thought is to somehow turn the containing activity into the
touch handler, and somehow stop the Gallery and ImageView from getting
touch events normally, and have the activity forward the touch event's
manually. Not sure if this is possible or if there is an example.
My last resort will be to simply not use the android.widget.Gallery,
which I want to avoid because I want the widget to "feel" the same as
other places on the phone, and I like code re-use. Unfortunately I
might have to do this, as I see all other apps that have this zoom/pan
capability don't seem to use the Gallery widget (Gallery3D etc).
My question is, what's the best way to design for this situation where
motionevents need to split between two views? Any ideas would be
greatly appreciated thank you.
please follow the links here.
http://jmsliu.com/138/android-infinite-loop-gallery.html
I'm loading floor plans into an Android application. I need the user to be able to identify problem areas on the floor plan with a single click. My thought process is to identify the click action, reload the html of the webview adding my marker asset to it at the specified location.
I've loaded the image into a webview to take advantage of zoom capabilities. I can get the X,Y coordinates of the webview where the click occurred, but I can't figure out how to get the current zoom level. Also, I'm not sure what math will be required to translate the X,Y,scale to actual pixel coordinates.
Is the webview the right view for me to use?
EDIT:
Using the link suggested below, I got the zoom functionality working. I still can't figure out how to place a drawable marker on top of the TouchImageView, much less get the coordinates that were actually touched on the image.
For your zoom question as well as coor, How can I get zoom functionality for images? should help you
The accepted answer does use a WebView, but the other answer uses a better approach for enabling zoom. It also provides the necessary math required for translating your X and Y coordinates into usable points.