I'm developing an app which is designed to capture writing on the canvas. The app is designed for use with HTC Flyer (Android 2.3.3).
This device already has Scribbler installed, so I have disabled "Auto launch Scribbler mode" but left "Pen history for each app" checked.
In my tests, I have found the app can detect my fingers on the touchscreen but not the stylus. I pressed a combination of buttons on stylus to no avail.
I have based the code on TouchPaint from Android Developers: http://developer.android.com/resources/samples/ApiDemos/src/com/example/android/apis/graphics/TouchPaint.html
I did not import the package as described in the above code
com.example.android.apis.graphics;
In my Eclipse IDE, it reported the following as a problem suggesting I should remove the Override attribute.
#Override
public boolean onHoverEvent(MotionEvent event) {
return onTouchOrHoverEvent(event, false /*isTouch*/);
}
So I did.
I have added the following to the manifest.
<uses-configuration android:reqTouchScreen="stylus"/>
<uses-configuration android:reqTouchScreen="finger"/>
The app can detect my finger movements on the touchscreen but never my stylus. Why?
I also noted that in Android Developers guide the MotionEvents refers to getToolType but I cannot see it in my "Intellisense" in Eclipse.
http://developer.android.com/reference/android/view/MotionEvent.html#getToolType%28int%29
The method getToolType is not available in my Android code. I thought I could use this method to check the type of the touch input e.g a finger or a stylus.
I also added a onTouchListener for the PaintView (based on TouchPaint code).
this.setOnTouchListener(new View.OnTouchListener() {
#Override
public boolean onTouch(View v, MotionEvent event) {
return touchSurface(v, event);
}
});
touchSurface code
private boolean touchSurface(View v, MotionEvent event) {
boolean complete = true;
int pAction = event.getAction();
int pActionIndex = event.getActionIndex();
Log.i("SignName", "touchSurface event fired.");
Log.i("SignName", "Pointer Action: " + pAction + ", pActionIndex: " + pActionIndex);
return complete;
}
When I use my finger, the above event is fired. When I use a stylus, it's not fired. Why?
I wonder if this problem is isolated to the HTC Flyer, it's because it has a Scribbler app which overrides my app settings or my code is wrong.
Can you please help me?
(Update: 27th April 2012)
I found what the problem was. It was the dedicated stylus HTC Flyer that caused the confusion.
I thought if this stylus didn't work, then any other stylus won't work too. However, I did try a different stylus and it worked.
Thanks for your help, though.
first off, you should update your Flyer to Honeycomb (Android 3.2), also this example is specific to ICS (Android 4), but you can run this example by using a compatibility library and making some minor changes to code, more information will be available at http://htcdev.com
Related
I have not been able to replicate this, but is anyone aware of what might cause the entire screen on an Android device to go light blue? It seems related to selecting a radio buttons and then scrolling. It happens on Nexus 5x with Android 8.
Here is what it looks like:
I have only heard of one other instance of this occurring. Could it be device specific? Strangely enough, once it happens it seem to stay this way, though the user says it is somewhat intermittent.
Update:
This only seems to happen on Android 8, if that helps anyone...
So, I eventually found the offending code. I verified this is only happening on Android 8 devices, maybe only Samsung? The offending code was:
mFormScrollView.setDescendantFocusability(ViewGroup.FOCUS_BEFORE_DESCENDANTS);
mFormScrollView.setFocusable(true);
mFormScrollView.setFocusableInTouchMode(true);
// Hide the keyboard when moving the screen up or down. This should only
// be an issue when
// on a text edit field. Also disable focus jump using
// "requestFocusFromTouch"
mFormScrollView.setOnTouchListener(new OnTouchListener() {
public boolean onTouch(View view, MotionEvent event) {
if (event.getAction() == MotionEvent.ACTION_UP || event.getAction() == MotionEvent.ACTION_DOWN) {
Utilities.hideKeyBoard(FormActivity.this, view);
}
// Keeps screen from jumping to nearest EditText
// view.requestFocusFromTouch();
return false;
}
});
The offending line is commented out - the view.requestFocusFromTouch() method, which was meant to keep the screen from auto jumping to the next text field when the keyboard was hidden and focus lost. On Android 8 this is not happening, but I need to verify with older versions.
The App currently runs in IMMERSIVE_STICKY mode, but when user swipes from the side - OS shows menu and home/back buttons. So user can turn my app off or run some other stuff which is unacceptable. Therefore, I need to disable touchscreen device completely on android to prevent any taps and swipes.
If i cant disable it via official API, can i disable touchpad using console? Android will be rooted.
I found that my touchpad device is /sys/devices/virtual/input/input1 but still cant find where can I disable it. /power/control takes only 'on' or 'auto'.
I found other solution with xinput but on android there is no one.
I think you can override the function onTouchEvent.
private boolean touch_disabled=true;
#Override
public boolean onTouchEvent(MotionEvent e) {
if (touch_disabled){
return true;
}else {
//do something here if your touch screen is activated
}
}
public disable_touch(boolean b) {
touch_disabled=b; //function to activate or desactivate touch screen
}
I'm trying to troubleshoot a tricky, difficult to reproduce (therefore possibly hardware related) problem for the open source Panic Button application I'm working on for Amnesty. There's an issue on github about it.
The issue is with a LinearLayout View with Buttons. When displayed in this fragment, when I try to hold a button, it just unpresses itself after one second exactly. When logging the onClick event, it triggers itself automatically even though I haven't released my finger from the screen.
This happens on the Cherry Gem phone, and I wasn't able to reproduce the problem on other phones.
I've been removing a lot of code and adding lots of logging statements to try and isolate the bug when I discovered the strangest thing, which led me to post this on Stack Overflow since it's strange enough that maybe someone will recognise the pattern:
When I drag my finger on the screen, then the bug goes away! More precisely, after confirming on the screen that the button unpresses itself a few times, if I hold and drag my finger around, then release it, after that I can hold buttons pressed without them unpressing themselves. Wat?
Please note that I'm not asking to solve the problem of trying to detect a long press (which this leads to of course), but trying to understand this problem of unwanted unpressing before I move on to implement a workaround. Therefore I'd also would prefer not to move the events to onTouch listeners, because I'm worried it would not address the root cause of the problem and I'd like to understand why this is happening first.
I'm not a 100% sure if there could be an unwanted interaction with the rest of the code and will also try to create a minimalistic project from scratch with only that code, if no-one recognises the pattern here.
I can also post a small video of the problem if that helps. I'm also happy to post code excerpts or logcat results.
Thanks for your time!
Jun
Update
I've looked at the adb shell getevent log which confirms that after .9 seconds there is an EV_KEY BTN_TOUCH UP
event. Does this confirm that from the OS's standpoint, it's receiving an event from the hardware about a button up? I guess this might be also triggered by software.
This led me to look into software that is installed on the phone and could interfere with the input devices. I've deactivated the Google voice typing, and then holding buttons worked again. Reactivating Google voice typing didn't make the bug reappear. Rebooting the phone then makes the bug reappear.
I tried to look at whether only some applications were affected. The pre-installed calculator was also affected. When using the default virtual keyboard the bug didn't happen. But then when returning to my app the bug had gone away again. Rebooted again. Calculator still affected. Go back to using the virtual keyboard in the browser. Now the bug stays... Wat?
After a while, I removed the Google voice typing input device again and the bug disappeared once more.
I have tracked a forum where there seems to be a rom for this phone, I'm trying to find out whether it's more recent than the version I have, or if anyone else with this phone experienced that problem as well.
(I also updated the relevant github issue)
Update 2
I noticed the following in the logcat:
04-01 12:05:30.484: V/PhoneWindow(2749): DecorView setVisiblity: visibility = 0
04-01 12:05:30.525: V/InputMethodManager(2749): onWindowFocus: null softInputMode=288 first=true flags=#1810100
04-01 12:05:30.528: V/InputMethodManager(2749): START INPUT: com.android.internal.policy.impl.PhoneWindow$DecorView{41aa5ef8 V.E..... R.....ID 0,0-480,800} ic=null tba=android.view.inputmethod.EditorInfo#41a3fef8 controlFlags=#104
04-01 12:05:30.530: V/InputMethodManager(2749): Starting input: Bind result=InputBindResult{com.android.internal.view.IInputMethodSession$Stub$Proxy#41a48da8 com.android.inputmethod.latin/.LatinIME #45}
04-01 12:05:30.608: I/InputMethodManager(2749): handleMessage: MSG_SET_ACTIVE true, was false
Could this be part of the problem?
For odd problems such as this, I think it's useful to override the onTouchEvent listener, and observe which MotionEvent is triggered (like ACTION_MOVE, ACTION_UP/DOWN). The root problem may be the touch screen driver of the device. So it may be good to test that driver with onTouchEvent.
There is, I think, a good webpage # Touch Device Configuration. Search text for "Driver reports signal strength as pressure". I think this is interesting and perhaps you could simply change the values for touch.pressure.calibration or/and scale for troubleshooting. This file has extension of idc, should reside on system subdirectory.
I want to provide sample code to override mouse/swiping events:
#Override
public boolean onInterceptTouchEvent(MotionEvent ev) {
switch (ev.getAction() & MotionEvent.ACTION_MASK) {
// Make sure ACTION_DOWN is dispatched to children view
case MotionEvent.ACTION_DOWN:
onTouchEvent(ev);
// Allow the children view to process this action
return false; // skip calling onInterceptTouchEvent
case MotionEvent.ACTION_MOVE:
onTouchEvent(ev);
return false;
default:
break;
}
return super.onInterceptTouchEvent(ev);
}
#Override
public boolean onTouchEvent (MotionEvent event) {
switch (event.getAction() & MotionEvent.ACTION_MASK) {
case MotionEvent.ACTION_DOWN:
mDownX = (int)event.getX();
mDownY = (int)event.getY();
break;
case MotionEvent.ACTION_MOVE:
...
Notes:
Method onInterceptTouchEvent occurs before onTouchEvent.
This method intercepts all touch screen motion events. This allows you to watch events as they are dispatched to your children.
Is there an opportunity to implement an element that is able to get pressed longer then 30 sec until the MotionEvent Action_up timeout gets automatically fired?
Maybe an other concept of doing that job?
At the moment i have changed the image of an ImageButton by using the onTouchListener and the action_up and action_down define. But this concept is getting ruined by the auto action_up from android.
Edit:
The problem could be caused by samsungs android mod. It occurs on the Galaxy Tab2 7.0 Wifionly edition but not on the HTC Sensation XE. Does anyone got an Galaxy Tab2 to cross check this behavior?
Try this code for your solution i suppose this will help you.
#Override
public boolean onKeyLongPress(int keyCode, KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_CALL) {
// a long press of the call key.
// do our work, returning true to consume it. by
// returning true, the framework knows an action has
// been performed on the long press, so will set the
// canceled flag for the following up event.
return true;
}
return super.onKeyLongPress(keyCode, event);
}
The following Link will lead you to the correct result with other uses of Hard Keys.The link is as follows:-Imp Link
I tested this issue on other samsung tablets. The result is that there is no problem at all. Just the Tablet i am using Samsung Galaxy Tab 2 WiFi 7.0 (P3110) got that issue.
I'm looking for an example of how to use MotionEventCompat in Android. I'm using API level 10, which doesn't support if a finger is 'hovering' or 'dragging' onto a view. I need to detect this, preferably from the view itself. Here's some code snippets regarding how I'm trying to use this:
**my class:**
import android.support.v4.view.MotionEventCompat;
public class GridButton extends View
overriding onTouchEvent:
#Override
public boolean onTouchEvent(MotionEvent event) {
super.onTouchEvent(event);
switch (event.getAction() & MotionEventCompat.ACTION_MASK) {
case (MotionEvent.ACTION_DOWN): {
set_active(true);
return true;
}
case (MotionEventCompat.ACTION_HOVER_ENTER): {
set_active(true);
break;
}
}
return false;
}
I based the MotionEventCompat.ACTION_MASK off an example I found somewhere, but it doesn't trigger my code for set_active().
Any help on using this would be appreciated. There's very little about this on the web.
Hover events are sent when the device supports a mouse or touchpad. When the cursor hovers over a view these events are sent to onGenericMotionEvent, not onTouchEvent. They won't help you detect a finger that isn't touching the surface of a capacitive touchscreen or a finger that touched down in a different position and then slid over the view in question. They will never be sent on an API 10 (Android 2.3) device.