I'm trying to make an android app only for tablets, which will draw the lines as and where the user touches the screen. It is very simple and there are lot more apps like this. I have a doubt regarding the touch-screen technology. Is there any possibility that if the user touch the screen soft then the lines will be dull and if the user touch the screen harder then the lines drawn will be thicker? Is it even possible to do such things in tablet? I don't have info about the hardware and technology used in tablets, please guide me with a valid answers and please refer me to any blogs or docs which says about the touch sense technology.
Thank you
You can use the OnTouch() Input Event (http://developer.android.com/guide/topics/ui/ui-events.html) which is triggered when you touch the screen. So inside the VIEW in your application you should register an OnTouchListener using setOnTouchListener (setOnTouchListener) with a callback to the function that will handle the event.
Inside your callback get the pressure properties:
public float pressure
Added in API level 9 A normalized value that describes the pressure
applied to the device by a finger or other tool. The pressure
generally ranges from 0 (no pressure at all) to 1 (normal pressure),
although values higher than 1 may be generated depending on the
calibration of the input device.
http://developer.android.com/reference/android/view/MotionEvent.PointerCoords.html#pressure
When you touch the screen you get a MotionEvent which has many methods and one of them gives you the pressure
http://developer.android.com/reference/android/view/MotionEvent.html
final float getPressure() getPressure(int)
final float getPressure(int pointerIndex)
Related
I am using the getPressure(index) method from the MotionEvent instance to get a value of the pressure applied to screen.
I am trying to figure out how to convert that value to at least an approximation of a standard measurement unit.
in Android the pressure value is a float ranging from 0 to 1. I need to express it in Newtons in some way.
From what i understood this is different across devices so its not possible get a really precise unit measurement but i am fine with an approximation.
Like what amount in newtons is normal for a stylus touching the screen on full force (the device measuring 1.0f of pressure)
I think you can only guess, and know that the results will be affected by huge uncertainity. Solutions I see:
Put an object of appropriate, known weight on the screen. Don't know about screens, but if it needs human skin to trigger the event, you can put your finger on the screen (making no strength on it) and then put some object on your finger.
Take a stylus, and by debugging learn how much force you need to get a 0.5f result. Then take a scale (foreign speaker here; I mean the tool that measures weights..?) and apply the same pressure on it with the stylus, and read the results.
In both cases, you can have a single map point (e.g., 0.5f -> 10 N), and then assume a linear dependency (knowing also that 0f -> 0 N) to fill the whole range.
With some patience you can fill different values too - I would not expect the relation to be linear actually.
getPressure returns a value 0-1 because the way pressure is calculated is device-dependant. Some devices will calculate the value from how much of the area of your finger is touching the screen. So from that it's probably not possible to convert to newtons in a way which will work on multiple Android devices unless you write a solution for each one.
I have received requirement like this http://www.youtube.com/watch?v=7MYQicokwmY&feature=plcp I am reviewing this requirement.As per requirement we have to build touch detection like in video link for Android enabled Tablets.
In that video toys (toys with circular, star or rectangle shape) uses Conductive Silicone Sensors with that they are detecting touch on screen & deciding shape of external world object like triangle,circle or a star & further processing the shape.
I have to use same touch detection for android tablets.Can anybody help me to find the way to implement this on Android platform ? Is there any API or framework to implement it?
If you see the video around 1:13, they show what I am guessing are some prototypes, the circle has three points, the hexagon too...
My best guess is that the biggest part of the object is non-conductive and only has a few points that are conductive and would actually register as touch points on the screen. The key is that each of them will be different enough that you would be able to recognize them no matter what the orientation is, what the position (and depending on your requirements whether you have several of those objects at the same time on the screen).
You can also play with the area of each conductive points so in your code, you will get the touch information, you can get different pressure values from the MotionEvent
Now how you place the conductive points and how many on each shape is completely up to you and would really depend on what your requirements are (recognizing arbitrary shape is not an option...)
Most touch screens would reject the touch if the area is too large (that's palm rejection), so I don't think there are much other ways to do this...
Is there a way to determine how hard is button pressed on touch screen?
Maybe using accelerometer details.
You can get the pressure by MotionEvent.getPressure()
Note: pressure i.e. how much pixel covered by your fingure touch.
as more number pixel covered the more harder you touched.
Is it possible to detect every pixel being touched? More specifically, when the user touches the screen, is it possible to track all the x-y coordinates of the cluster of points touched by the user? How can I tell the difference between when users are drawing with their thumb and when they are drawing with the tip of a finger? I would like to reflect the brush difference depending on how users touch the screen, and would also like to track x-y coordinates of all the pixels being touched over time. Thanks so much in advance for any help.
This would be very tricky primarily because every android phone is going to behave differently. There are some touch screen devices that are very, very sensitive and some that are basically "dull" by comparison.
It also sounds more like you are wanting to track pressure - how hard is the user pushing on the screen - which is actually supported on android devices.
I think some of your answer may be found by monitoring all of the touch events - in practice, most applications ignore a great number of events or perform some kind of "smoothing" of the events since there is literally a deluge of touch events when the user is manipulating the screen. Doing this may negatively impact your applications performance though.
I would recommend that you look into pressure sensitivity and calculate a circular region around the primary touch point based on pressure, then build your brush around that.
Another idea would be to incorporate more of a gesture approach to what you are trying to do - for example, visualize touching the screen with the tip of two fingers together (index and middle) and rolling the middle finger around the index finger or simply moving the middle finger up and down in relation to the index finger. Both fingers would be moved together for painting. This could be used to manipulate drawing angle on the fly or perhaps even toggle between a set of pre-selected brushes or could change brush size on the fly as you are painting.
Some of the above ideas I would love to see implemented - let me know when you have your app ready.
Good luck!
Rodney
If you have a listener on your image it will respond that there was a touch within that bounding box, basically.
So, to get what you want, you could, but, I would never do this, create a box around every pixel, or small group of pixels, and listen for a touch.
Wherever you get a touch, it may fire off an event, then you can react accordingly.
I can't think of any other solution that will give you each pixel that a person touched, at one time.
You may want to read up on multitouch though, as there are some suggestions in here that my help you:
http://android-developers.blogspot.com/2010/06/making-sense-of-multitouch.html
If you're looking for a way to get your content view as a View after Activity#setContentView(int), then you can set an id on the outer-most element of your layout:
android:id="#+id/entire_view" and reference it in your onCreate() method after setContentView:
View view = getViewById(R.id.entire_view);
view.setOnTouchListener( ... );
i am trying to make a drawing application.
i want to draw a single-touch motion path in android - like the way the Swype keyboard does it.
And consequently i want to store x-y coordinates of EACH of the pixels of the motion path into a data structure.
How can i use the MotionEvent pointers to do this?
You probably don't have to store every pixel - just store a new one when certain parameters are met such as the pixel is further along or if the angle between one pixel and the next is greater than a certain threshold. From that you'll have a more compact poly line that will be easier to work with.
You should look how to handle touch events here : http://developer.android.com/guide/topics/ui/ui-events.html
The example in the documentation of MotionEvent ( http://developer.android.com/reference/android/view/MotionEvent.html ) shows you how to get the coordinates of the touch event motion.
Then all you have to do is draw it (and maybe smooth it up a little)