have textview change style/attribute on touch roll-off - android

Ok, I simply can't figure this out for the life of me. I created a custom textview and I basically want it to be a button. I have all my code working except that I can't get it to detect when touched, and then the touch event rolls out of its boundary. Say the textview lights up grey when touched, then if the user drags their finger away to the left or right, I want to have the grey disappear and reset to its normal background color.
I realize I can just use the standard android button, but I don't like how it delays on changing color for the touch event. Maybe someone knows where the stock Button.java class code is, for the android API so I can look at that for hints?
I have tried getting the dimensions of the button with an on global listener and then tracking user touch events to be within those dimensions. And the dimensions and touch location are reported correctly and works sometimes, but it simply doesn't work reliably, maybe due to the user moving too quickly, for example. Even if I set the touch boundary a few pixels inside of the actual boundary.

Related

How can I stop input from registering inside my game when I am dragging status bar from the top?

Basically on newer phones such as the ones with the notch at the top I have been able to play games where I swipe the top of my screen to access the status bar without any input impacting my game.
Games such as Circle and Jelly Jump) are examples that do this.
I basically want a similar sort of thing. Right now when I drag down my status bar from the top, my game ends up activating which is something I don't want.
My code to start the game is upon a very simple mouse down input which also registers as a touch on phones:
if (Input.GetMouseButtonDown(0))
{
Jump();
}
An example of what I want can be shown via this diagram I've
drawn here.
You could have an invisible UI panel in that area and then check using EventSystem.current.IsPointerOverGameObject() to check if the click/touch is over an UI element. Not that for touch, the function is IsPointerOverGameObject(touchID). Also you will need a graphic raycaster attached to the canvas.
Another option would be to check the x/y value (depending on orientation) of the touch position and to only register input if it's above a certain value.
if(Input.GetTouch(0).position.x < 20) return

Multi-touch drawing : action_cancel when the palm touches the screen

I'm working on an android application on tablet to draw every points touched by the finger or the hand. It is very important for the application to track not only the fingers but also the palm (even if it's not drawing the exact touched area but only a thin path, as long as we can see the movement of the palm it's fine). A good example of what I want to do is the "show pointer location" in the Android developer menu : if the drawing could be exactly like this, that would be perfect.
I managed to code a multi-touch drawing app, but the problem I have here is that every time the touched area is too wide (for example when I touch the screen with my entire palm), the application stops drawing (even the fingers drawings stops) and I have this error in the log : [ViewRootImpl] action cancel - 1, eccen:1.4225352 (the number after "eccen" changes depending on the size of my palm touch).
I'm quite new to android, I spent a lot of time searching how I could prevent this action_cancel but I couldn't find anything that makes it work... I tried to prevent the parent views from taking control of the onTouch events, but it didn't work. So if you have any idea of how I can manage that, it would be great :)
Thanks !
(English is not my native language, so don't hesitate to ask me to reformulate is something is not clear)

Draw over app and just manage scrolling events in Android

I'm trying to draw view over other apps with transparent theme filling width and height.
I need to pass my touch events to the app that i draw on. But there is a restriction -- only scrolling (up and down) has to pass to app, NOT clicks , double taps etc.
When user clicks something, there shouldnt be any action on the app that i draw on.
But, user can scroll up & down in the app so he can view what's going on.
How can i achieve this?

Unclamping X and Y values from android touch events, to detect movement outside a view

When a user starts a touch in a particular view and then moves the finger outside the view (while still in contact with the surface), the MotionEvent returned clamps the x/y value into coordinates inside the box.
That is, I won't get negative Y values if I move the finger above the view, for example.
Is there a way to get this raw value? getRawY seems to clamp the value as well.
I can't do anything with activities, since this is for an IME project, and the IME basically accepts a View from you and takes care of rendering etc.
Set the FLAG_WATCH_OUTSIDE_TOUCH on the window associated with your view. That should make it work.
I do have another way to do it, but you really don't want to use it (it involves the ugly hack of making a partially transparent full screen keyboard) so lets try this first.
Here's the horrible hack you don't want to use this method:
1)Add a transparent view above your keyboard, taking up the rest of the screen.
2)In onComputeInsets, define your touchable insets to be a REGION, and pass it a region made up of only your keyboard
3)In onTouchEvent, on a ACTION_DOWN set a flag that says we're in touch mode, and make sure to invalidate your view (this will cause onComputeInsets to be called again)
4)In onComputeInsets, look at the value of that touch mode flag. If false, use the insets set in 2. If true, set the entire screen as touchable
5)In onTouchEvent, on a ACTION_UP or ACTION_CANCEL clear that flag and call invalidate to reset the insets
What that will do is tell the framework that touches on that transparent view do no belong to the keyboard (so they'll be sent to the app) unless you're in touch mode in which case we tell the framework we want all touches anywhere. Its hacky, but I've done this kind of code before and it does work. It just requires you to play with onComputeInsets, which is almost undocumented (they added minimal documentation a few versions ago) and has been used by probably about 20 people in the world. Its an ugly api.

Android: Trigger redraw after a colour change

I am currently working on a Connect four game.
My game works by the user pressing the 'New game' button. This then draws 42 (7*6) green circles to screen. These circles are used to represent holes on the connect four board i.e. green circles currently do not contain a player's token/counter
At this moment in time I am working on adding the tokens/counters. I have got code working (to a certain point) that enables the user to pick a column. Using log.d() It seems that I am successful changing the colour value of the gaps. My problem is that I do not know how to send this changing in colour to the View i.e. so the gap actually changes from green to red (player's token colour).
How can I send a request to the View so the gap is re-drawn?
N.B. Sorry for the lack of code but it is currently messy and not fully working.
The View is controlled by a ConnectFourView.java (View), the game screen is Board.java (Model) and the code that works out which column has been selected Gaps.java (controller)
Just call invalidate() on your view and it will be redrawn

Categories

Resources