android find pressure on screen - android

I would like to roughly understand the amount of pressure the finger presses on the capacitive screen on android. My idea is to get the area covered by the finger when it is touched (maybe some extra parameters to get it more accurate, but thats the main idea).
So, is there any way to find the are covered? (for example get the number of pixels covered).

There is only MotionEvent.getPressure() (which you probably already found). I doubt that there is something that reports how many pixel are covered by the finger.

I do not really know but you have access to the following function :
MotionEvent e;
float press = e.getPressure(...);
press will be between 0 and 1, from 0 = no pressure, to 1 = normal pressure, however it can be more then 1...
Your thing is totally NIH... Use something that already exist ? Or maybe it doesn't cover your needs !

You can use MotionEvent.getSize() to get the normalized value (from 0 to 1) of the area of screen being pressed. This value is correlated with the number of pixels pressed.

Related

Android MotionEvent pressure unit of measurement

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.

Reverse Guess-Game tip between two numbers

I'd like to build a reverse guess-game. (The player has a number in his mind, and the program tries to guess the number. You have three buttons. One button for a smaller tip, one for a bigger and one for the correct.) My app is generating the numbers on keypress, but the problem, that it doesn't remember my buttons I pressed. So for example the program tips number 50. I click "Smaller" button, it generates a smaller number, for example 35. I click "Bigger" button, and it can generate 80 or 90, even if I pressed "Smaller" for 50. How could I make the program "remember" the choices? Thank you :) Best regards!Sorry if I'm unclear, but I'm beginner.
This is my onclick:public void lowerClick(View v) {
tip = randomGenerator.nextInt(( highest + 1 ) - lowest ) + lowest;
textTip.setText(Integer.toString(tip));
{
The only problem is how I am supposed to change the highest and lowest parts and if I have to add anything to the program. I hope It's clear now. :) And thank you for your cooperation and understanding.
Tip: In the future, you should post any code you already have to show effort and avoid downvotes. However, I'll interpret this post as a general algorithm question.
You'll want two variables:
High Range: The highest possible number the user can be thinking of.
Low Range: The lowest possible number the user can be thinking of.
If the program guesses 50 and the user clicks Smaller, set the high range to 50, as you know the number must be under 50 from that point on.
If the program guesses 35 next, and the user clicks Bigger, set the low range to 35.
Always guess only numbers between the low range and high range, updating at each step. It's probably best to guess the point halfway in between the high and low range to maximize your chances. This would be somewhat of a binary search approach for guessing a number.

Touchscreen sensitivity

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)

What's the default minimum distance to sucessfully swipe in View Pager?

I'm working on a project for my thesis in which I'm using an app for analyzing swipe gestures. There are a lot of questions and informations around about the view pager in general and even how to manipulate its settings, but until now, I couldn't find the specific default value (distance between finger down and finger up) baked into the pager itself. This would be very useful for me in order to see what value google deems to be appropriate and to compare it to other values.
Help would be much appreciated! :)
edit:
OK, found some clues myself. This is the code for ViewPager: searchco.de/codesearch/view/10066260 and there is a static variable namend MIN_DISTANCE_FOR_FLING which has a value of 25 (dip). This value gets multiplied with the density of the current display, which is done in in initViewPager(). This value in turn is then used in determineTargetPage to check if the user has swiped a greater distance than the value. What I don't get: If I multiply 25 by e.g. 160 (as an exemplary density), the value gets way too big, so I'm obviously interpreting the code wrong in some way. I would really appreciate an explanation.
To sum this up in case anyone else needs the information (my thanks to #Luksprog):
The minimum threshhold for a sucessful swipe in a ViewPager is a non-device-specific constant which is 25dip, adjusted to the current device by multiplying it with a device-specific value, namely the scale factor of the device's display.
You need import ViewPager.php in your project (File -> Import -> General -> File System -> with path-to-SDK/extras/android/support/v4/src/) and disable mTouchSlop variable in initViewPager() block.
mTouchSlop = 0;//ViewConfigurationCompat.getScaledPagingTouchSlop(configuration);
Then touch drag will be work immediately.

Detecting touch area on Android

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( ... );

Categories

Resources