How android detect button positions and call appropriate handler? - java

I know this may not be an appropriate question, but I want to know how a touch enabled OS like
android detects a button in an app and calls the appropriate handler? When programming an app we just give the alignment information of a particular button. So, how android keeps the mapping between a button and screen position? I think this is kindof dynamic because if you change the screen orientation or use zoom or something like that the button positions are changed dynamically. So, android must look at the touch position and decide whether a button is there or not and call the appropriate handler. How this all things put together?
I appreciate any reply.

Related

Enable/Disable Touch Screen on Android

Is there any way of disabling / enabling the touch events in a certain activity
without disabling certain buttons. like if the phone is "frozen" on a certain activity page for limited time?
I need that the user wont be able to go back on page, slide out or any other events.
Is it possible? (I'm using android studio, java)
Thanks in advance!
Any answer would help :)
It's possible.
Actually there is no special function to make it.
To make it, you can make a full screen button with transparent background.
And you will define a function of the button.
Of course, it will be an empty function.
Well, you can do nothing on the screen.
and then you can hide or visible the button according to your necessary.

How to apply the one ripple drawable for multiple buttons dynamically in Java?

I want to apply the same ripple drawable properly on multiple buttons. But it's not happening because, the ripple effect is only getting applied on the last button. I have also used gradient drawable inside the ripple drawable. That works fine on every button. It just the ripple effect is not getting applied on any button except the last button. It is also not working on api level 8. I know that this method doesn't work on apis before api level 21. But I haven't found any tutorial on dynamic button design.
I'm doing everything inside the on-create event. I can't write the codes outside of the on-create event and also can't use any XML for this particular situation I'm in.
Here's the output:
Here's the code:
android.graphics.drawable.GradientDrawable gd_btone = new android.graphics.drawable.GradientDrawable();
gd_btone.setCornerRadius(4);
gd_btone.setStroke(2, Color.parseColor("#ffffff"));
gd_btone.setColor(Color.parseColor("#232323"));
android.graphics.drawable.RippleDrawable ripdr = new android.graphics.drawable.RippleDrawable(new android.content.res.ColorStateList(new int[][]{new int[]{}}, new int[]{ Color.parseColor("#888888")}), gd_btone, null);
button1.setBackground(ripdr);
button2.setBackground(ripdr);
button3.setBackground(ripdr);
button4.setBackground(ripdr);
Also, can anyone help me to make this piece of code back-compatible with api level 8 and how to set margin on this drawable?
I'm not a Android developer so I don't know much about it.
What I see is that the dripple effect is applied to the last button, even when the other buttons are clicked. Because of this, I am thinking that the RippleDrawable class does not support the kind of behavior you are looking for; a single instance can only be bound to one button at a time.
I would suggest simply creating four separate RippleDrawable instances.
Disclaimer: I have not worked with RippleDrawables, but this is purely based on the output you've provided and personal experience with Android development.

Corona SDK android keyboard and native textFields

I'm developing an app for iOS and Android using Corona SDK and have problems with managing native textFields in Android.
I'm trying to achieve the following effects:
tapping on textfield will animate its sliding with keyboard so it will be always on top of it while moving up.
Tapping on back button will dismiss the keyboard and slide textfield back with it
My problems are:
To know the height of the keyboard in order to know where to stop moving the textfield.
To catch back button tap in order to eliminate the textfield
What I am doing:
I've looked over the Internet to find out how to check keyboard height on Android. All solutions assume we have Activities.
We have registered onKey listener to catch back press in corona code, but it is not fired if keyboard shown.
Ok so I made this Draw & Guess Online game and I used Native TextFields as well. What I did is just set my device resolution to lets say 600x1024. Then I just tested on a few different devices, and just eyeballed where the keyboard was located. I'm afraid this is what your going to have to do. Just use a for loop to make around 10 small rectangles and print the pixel values next to each of them. Then take your test devices, and see where the keyboard lyes on each device. Then just animate them up.
There is no easy way to do it in Corona unfortunately. Also people could have custom keyboards which would make your life even more difficult. All I can recommend is to over estimate and release.

capture movements or keystrokes of a game like (Angry Bird) using touch screen of an Android

I basically need to find out if there is a way to capture movements or keystrokes of a game such as "Angry Birds" etc using the touch screen of an Android and save them to a file on the device.
I'm sure these phones have security issues and don't want native "keystroke logging", but if it's a layer that sits over the other game, it should be ok
Please let me is there any way to achieve the same. Your help would be appreciated. Thanks In Advance
You can cover the screen using a System Overlay, as shown in this answer.
However, keep in mind that either you can consume all the touch events, or you can let them through. You cannot first take the touch events, and then pass them onto the app or View below you.
Additionally, if the device has on screen system navigation buttons (home, back and recent apps) the overlay will not cover these.

Android button latency?

I've been working on a drum machine app, and the latency between the time you press the button and the time the sound plays is unbearable. I have seen some people use multitouch and gridviews, and make several buttons able to be pressed at the same time, but I honestly have no knowledge of those. How could I set up multitouch or gridviews to reduce the latency?
I would guess the multitouchable buttons are a very custom implementation. You won't ever be able to touch two ordinary buttons simultaneosly, since they are made for single touch and are based on focus gain etc.
Here's my idea behind a multitouchable implementation:
You create a very custom view which will draw all buttons you need. This view should override onTouchEvent and react on multitouch. I never tried that, but this is the only option I can think of.

Categories