Slide to specific part of image in Android - java

I'm trying to build some kind of smart map. To do that I need to display specific part of picture (in this case floor plan). So we will have quite big picture (let's assume 3000x3000px) with some rooms (with irregular sizes and shapes) and if location changed we need to should smooth slide to this specific position. As I said before rooms will be with irregular sizes so also there should be an option to zoom out and zoom (programaticlly) in at specific position.
Use case how it should work.
App location changed
ImageView instead of displaying whole picture of floor plan smooth slide to specific coords and zoom this part of picture
Is this possible to do that on ImageView or something like PhotoView ?

Related

Straightforward way to place text on a specific location in an image?

Overhead schematic of Docks map in Modern Warfare
Overhead schematic of Docks with one callout name
I'm creating an app that will display names - "callouts" - for various specific areas of each map in the video game Modern Warfare. I want to be able to place the text (or a placeholder) in the same location, regardless of scale, transformations, etc. Is there a way to do this besides getting the (x,y) coordinates of each location in an image editor, then using those coordinates in my layout? That method seems extremely tedious because there's 10 - 20 callouts per map, and approximately 20 maps! I also want to avoid adding the text graphically so that I can change it as necessary in Android Studio.
If I place TextViews visually in the [Design] tab in Android Studio, will they stay in the same position relative to the background ImageView, regardless of scaling, transforms, etc.? Please advise, and I'll be happy to clarify if necessary. Thanks!
I think I've found the solution I'm looking for, folks:
Within a ConstraintLayout, have an ImageView to hold the map graphic, and TextViews for each callout label.
Constrain each TextView to the Start, End, Top, and Bottom of the ImageView.
Drag the TextViews to the desired location in the [Design] tab of the layout editor. This will automatically adjust the Horizontal and Vertical Bias, which is essentially a percentage of the parent's width and height, relative to the left and top of the parent.
In my preliminary testing, this seems to preserve the location of each callout label relative to the map, which is what I was hoping for. If anyone has anything to add, please do so!

Java - Screen Coordinates to Image Coordinates

I am using a Java application to display an image on the screen. I also am using an eye-tracker device which records the absolute pixel X,Y locations where the person is looking on the screen.
However, what I need to do is convert these X,Y coordinates from the screen positions into the X,Y locations of the image. In other words, somehow I need to figure out that (just an example) 482, 458 translates to pixel 1,1 (the upper left pixel) of the image.
How can I determine the image's placement on the screen (not relative to anything)?
I saw a few posts about "getComponentLocation" and some other APIs, but in my experimentation with these, they seem to be giving coordinates relative to the window. I have also had problems with that because the 1,1 coordinate that they give is within the window, and there is actually a bar at the top of the window (that has the title and the close and minimize buttons) whose width I do not know, so I cannot easily translate.
Surely there must be a way to get the absolute pixel location on the screen of a component?
If we are talking about Swing/AWT application than class java.awt.Component has method getLocationOnScreen which seemed to do what you want
And yes as #RealSkeptic mentioned in comments to question:
SwingUtilities.html#convertPointFromScreen
will do all this work for you considering components hierarchy

how can I create a custom clickable shape on an image in android?

I want to create a clickable image, my image has some different clickable parts in it, like this one:
I want to draw a custom shape like :
A,B,C,D,E,F
and make sure when user click on of this something happen.
the problem is I don't have any kind of idea to, how create shapes like the shapes in the image make sure it just fix on the image and in different screen size don't see a massed up thing.
Will there be more than many of such images?
If no I suggest you to create mask image for each region where black part of image represents the region and white part excludes rest.
To draw image:
create custom View
in constructor don't forget to use setWillNotDraw to true so you can do custom drawing
override View.onDraw method where you can draw main image and all others with some filters via setColorFilter.
To handle click events:
override onTouchEvent method
get touch position
compare touch position with point color in mask image
To optimise:
create mask image downscaled by some scale factor
during comparison divide touch position by scale factor
This is not ideal, but solution with vectors is non trivial I think
Take it as image and setOnclickListner for that image

Mapping coordinates with respect to different screen sizes

I heard SO people like diagrams so I took the time to draw one :D
I need to design an activity that roughly looks like the following:
The map is just an image file of city, terrain etc. Users are able to enter values inside the x-coord and y-coord textbox and when both of them have been entered, a triangular icon (also an image file) will appear on top of the map with respect to the coordinates on the map. The min,max of coordinates are fixed as 0,0 to 10000,10000 for all maps. Users can click the triangular icon (button) and it just takes them to another activity.
What is a sensible approach of designing something as above?
As far as I'm concerned, there are several things I need to take into consideration:
1)Mapping the coordinates with respect to the screen size. An obvious workaround for this is to use absolutelayout and use pixels for positioning the triangular icon, but this solution is terrible for obvious reasons.
2)Laying a button on top of the map (image file). After playing around with bunch of layouts, I couldn't figure out how to do this via Java.
I'm just looking for a really simple guidance, just to get myself going in the right direction.
I would use a SurfaceView. You can draw anything in the onDraw method. Youll get a Canvas object to draw on so it shouldn't be difficult to transform your coordinates and do what you want.
take a look at this tutorial:
http://www.mindfiresolutions.com/Using-Surface-View-for-Android-1659.php

dynamically position views (similar to markers in Google Maps) on top of large scrollable + zoomable imageview

i have an imageview containing a bitmap that can be zoomed into and scrolled. i've used the setImageBitmap() method instead of setting the image on a canvas. the imageview acts as a map which the user can browse through. now, my application is supposed to allow the user to marker points of interest with push-pins as done in Google Maps on a point selected on the imageview by the user. i've gotten the ability to pick up which point on the original bitmap was selected using a modified implementation of the OnTouch() method to work so i know where exactly the marker has to be placed.
i want to set a marker to this location and pass a string into a database to store information about the location so that when the marker is tapped, this information is shown in a bubble/toast notification.
as of now, i can scroll the image, sense a longTouch event on the imageview, save point of tap, move to new activity to collect information to add in the database. i can't seem to find a way to set up my markers on the original imageview.
also, i'm guessing i'd have to use an ArrayList implementation here to get markers with individual IDs that could be correlated to the ID in the database fields but i don't understand how to implement that.
i looked around the Internet for a solution or an idea and i've tried many things before posting here but nothing seems to work.
using a canvas' draw functions wouldn't allow for onTap functions to show info notifications. the drawn bitmaps also lose scale and quality while zooming. i tried making a custom class extending RelativeLayout to act an an invisible layer on my imageview but i don't know how to place markers in exact locations and also make the custom RelativeLayout easier. i tried placing a false transparent canvas of the same dimensions as my bitmap to get scaling to work and allow me to place markers at absolute locations but it didn't work. plus, using onTouch events on the custom RelativeLayout class meant i couldn't use the onTouch events on the lower imageview class.
i can't seem to come up with any solutions that can help me implement the mechanism as i want to, so i'm open to any sorta idea that can be thrown at me. i'd appreciate some help.

Categories

Resources