How to Avoid Click Event Trigger Multiple Times in Android Java code? - java

i am trying to add stylus button support into an archived - unmaintained github repository named gfxtablet
Basicly it turn android tablets into a digitizer as like wacom.
It has support for drawing, hovering and even stylus pressure. This is great. Only missing piece was stylus button and i cant use it on my tablet samsung galaxy note pro 12.2 which comes with samsung s-pen.
I tried to figure out stylus button event myself by searching online for a long time ( because i am not java nor c programmer.)
Gfxtablet android app communicate with linux with c programming application name networktablet.
I read their docs and learn that i could enable stylus button with extra codes.
I could successfully enable stylus button event trigered as right mouse button by adding :
if(event.getButtonState() == MotionEvent.BUTTON_SECONDARY)
{
netClient.getQueue().add(new NetEvent(Type.TYPE_BUTTON, nx, ny, (short) 0, 2, true));
netClient.getQueue().add(new NetEvent(Type.TYPE_BUTTON, nx, ny, (short)0, 2, false));;
}
inside
#Override
public boolean onGenericMotionEvent(MotionEvent event) {
...
My edit is this :
Original file is here ,line 110
i add code above after switch statement.
it works but the problem is , code fired multiple events and as a result it behave as like i right click mouse button around 5-10 times in a second when i click stylus s-pen button.
Main objective i am trying to achieve, is , i wished to use samsung s-pen 's button for right mouse click and use it on Krita painting app's popup palette.
As like you see pictures , button event trigger multiple times in terminal and in krita popup palette open and close many times in a second.
I need help to figure this out. Thanks

Related

Why sometimes my Android App restart without a logic explanation?

I'm developing a scientific app in Android Studio. It works smoothy.
The set of source code files is not small, but, as I don't have practically user interface, there is only one activity and there is no intent.
All initialization code is inside OnCreate. Most of times, my app preserves all data, when he gets out of the foreground.
However, maybe (I cannot find a pattern of this event) he loses all data and restart (shows a white screen for 2 / 3 seconds), even if the cell phone don't enter in lock screen and there are just 2 apps running.
There are situations that I comute for another app (like WhatsApp) and resumes for my app, and my data was gone. The app restart again.
There is no error message, no logcat. Nothing.
Mostly, when I lock the screen and enter again, all my app data is there.
PS: My orientation is locked.
PS 2: I've read all related question and there is no hint for me. Based in one answer, I've tried to put in onCreate the following code.
if (!isTaskRoot() {
&& getIntent().hasCategory(Intent.CATEGORY_LAUNCHER)
&& getIntent().getAction() != null
&& getIntent().getAction().equals(Intent.ACTION_MAIN)) {
finish();
return;
}
No changes for me.
Update:
I've stumbled in solution. it can be read in my own answer. it's related to undesired back button effect for one-activity-app (read here and here ).
For me, as my application has only one activity, back needs to be like a home button: exit the app but preserve all activity data. My app has a real exit button, where the user shows that really wants to do this.
It's my first app that I developing in mobile world and, for extension, Android world
Some problems seems to me like that it is only possible find the solution if one has a hint about its solution. it's a contradiction. One doesn't know but has to know to solve that don't know!
And, in this situation, it's not the case. No hints. Just question marks.
Before, I had not noticed any pattern. People sometimes act so automatically ... However, suddenly the penny dropped.
I've stumbled in solution. Fortunately!
Not in a million years could I suppose that if someone has an activity and presses Back button, (right button in the bottom), you practically quit the application, even if it remains as a running app for the left button in the bottom (app switcher button)
When I've noticed it, I start to research with another focus. And I've discovered two sources: Disable back button in android and Android - Simulate Home click
So the solution is simply to make the Back button act like the Home button (middle button in the bottom). Return to the home screen without losing application data.
And this is done simply by putting in the onCreate, for my only activity, the following code.
override fun onBackPressed() {
val i = Intent(Intent.ACTION_MAIN)
i.addCategory(Intent.CATEGORY_HOME)
startActivity(i)
}

Java SWT - Key pressed display filter

In my app I added a filter to the display that handles a KeyDown event.
It works just fine when the app is running on windows, but now that I'm trying to run it on Linux it doesn't detect the keypress event.
Any ideas what can be the problem?
The code is a bit messy so I'm adding only the outline for now.
answerListener = new Listener() {
#Override
public void handleEvent(Event event) {
...
};
Display.getDefault().addFilter(SWT.KeyDown, answerListener);
The app Is a trivia game, when I press a key in the game screen, I should get 4 sec to choose an answer. So the answers button is enabled only if a key is pressed before.
There are 3 main SWT composites on the screen. A group with the answers buttons, A list with text strings, and another group at the left of the screen.
When I press on the list of strings with the mouse and then I press a key, a small text box (you can see at the picture) with my pressed key char pops up, but the answers are still disabled.
The text box appears on the screen for 4 sec and then disappears.
When I click before on any other group, the small window don’t pop up, but the answer group are again disabled.
On Windows none of those symptoms occur. The game works as it should work.

Detecting whether the camera button has been pressed using J2ME

I am trying to develop an application in which I want to know when the camera button(if the phone has one),has been pressed for feature phones like Series60 using J2ME.I dont want to take a snapshot or take a video.I just want to know when the hardware button has been pressed.
I have been unable to find a proper way for this.Your help is greatly appreciated.
Create a canvas, listen for keypresses and output all events to the screen. If no event occurs when you press the camera key then you can't do it.

Android: Unexpectedly Quit When Trying to Switch Activity

I'm new to posting, but have been using the site for help for a while now. So thanks for that!
I'm working on a new app, got everything running well. It's a kids' soundboard. 2 pages of imagebuttons in a relative layout, with onclick listeners which triggers SoundPool.
My question is this:
in testing I've discovered if you're finger is anywhere on the screen where a button is not (say pressing on the background) and then you try to touch a button (multitouch) ... the button press doesn't register. Any way to fix this?
Thanks!
You have to cover additional event types for multi-touch, if you are not covering below Actions, you are not covering multi-touch
MotionEvent.ACTION_POINTER_DOWN: This event happens for any additional finger that
touches the screen after the first finger touches
MotionEvent.ACTION_POINTER_UP:This gets
fired when a finger is lifted up from the screen and more than one finger is touching
the screen.
The explanation is quite tedious. I suggest you to google multi-touch for android. One helpful link is: http://android-developers.blogspot.in/2010/06/making-sense-of-multitouch.html

Open menu for special symbols (accents etc) by "hold and slide" in android keyboard

I'm developing a soft keyboard for Android (respectively I'm trying ;)) and since I'm new to Android and Java it's not that easy.
The basic keyboard is working (thanks to examples in the web) and now I'm trying to create a sort of "popup" (with new buttons) which is evoked when you press and hold a button for a certain time (time should be open for customization). Then one should be able to drag the finger to the new buttons. For example: You hold e and then drag the finger to é etc.
My first attempt was to use something like:
<Key android:codes="101" android:keyLabel="e"
android:popupKeyboard="#layout/popup"
android:popupCharacters="eéè€"
/>
where popup.xml contains a seperate basic keyboard structure:
<Keyboard xmlns:android="http://schemas.android.com/apk/res/android"
android:keyWidth="10%p"
android:horizontalGap="0px"
android:verticalGap="0px"
android:keyHeight="30px" />
But there are several disadvantages:
I don't know how to tweak the position and appearance of the popup
the finger has to be lifted in order to press a new button (weird behaviour)
the time the user has to wait until the popup appears seems to be fixed
How would you solve this problem? An invisible key-row (absolute position) which is set to visible once a button is touched for a certain time (monitored with motion events etc.) ?
Do you know any tutorials which give information on this "press-hold-drag-button"-concept in keyboards? A code example would be very helpful. I looked through the LatinIME git project but unfortunately it's very overwhelming :/
This is a very, very old question, but this may help someone else like me. I am browsing the Android source code to see how to make the alt-key popup:
http://grepcode.com/file/repository.grepcode.com/java/ext/com.google.android/android/4.0.1_r1/android/inputmethodservice/KeyboardView.java#KeyboardView.onLongPress%28android.inputmethodservice.Keyboard.Key%29

Categories

Resources