Drag and Drop on Disabled ImageButton - android

When I drag and drop something onto an image button, I want it to change colour.
This works fine when the button is enabled using this code:
DragEvent.ACTION_DRAG_DROP -> {
it.background.mutate().setColorFilter(ContextCompat.getColor(mContext, R.color.entered_zone), PorterDuff.Mode.SRC_IN)
return#OnDragListener true
}
However, if I do:
endorsedBtn.isEnabled = false
Then the button will not change colour.
Why is this and is there something I can do?

From the documentation:
Note that this step only occurs if the user drops the drag shadow within the bounding box of a View whose listener is registered to receive drag events. If the user releases the drag shadow in any other situation, no ACTION_DROP drag event is sent.
Disabling your image button also disables the listeners for it.
You can create a custom button and decide on your own inner disabling function.
More information here.

Related

Listening for touch events in background in an application

Is there any way to fire my applications's click event if user long pressed screen in chrome or other mobile application, while my application is not running.
you can use a floating view in service and override onTouch event in that floating view to listen touch event of screen. to make floatlistening not visible on screen set their size 1dp or set visibility to invisible.
here is link about floating view.
EDIT
here is another link for listening touch event in background.

Give notification for disabled button in Android

What to do to give a notification in android app, when user tries to click on the button which is currently disabled ? It will be enabled in future. Then it has to perform another operation.
Help me with the disabled case ...
You should try using onTouchListener. AFAIK,setEnabled(false) disables onClick, but it should leave the onTouchListener working. Just remember one thing, return false from the listener once your work is done(in order to consume the event allow other events after it to be fired)
I would overlay it with a transparent view, and add an OnClickListener to the transparent view.
At least this way you are using a pattern you are familiar with, and it will be easier when you update the app in the future.
once you disabled that button you can no longer perform or get any kind of listeners on that disabled button. So i suggest you use the following method
you will be having a specific condition to disable the button lets say that condition is "disCondition"
disCondition = true//button disabled
button onClick(){
if(disCondition){
//Show toast message
//and change the button background to disabled image
}else{
//perform the normal button click
}
}
now change the button background according to the disCondition.

how to get tag of focused content after drag finger from another

I want to implement something like this
Requirement-Image
Video_Requirement-1
Video_Requirement-2
You can install this application to know about actual requirement
Functionality
I need to handle a situation below :
1.) I have an open button, see image number-1
2.) On key down(MotionEvent.ACTION_UP of onTouch()), the two more buttons in a semicircle shown as in image number-2
3.) After put finger on open button, I drag my finger to new inflated buttons without remove my finger from screen(i.e. drag the finger to the new buttons), and on which button i drag my finger, being highlighted.
4.) How to perform a new task on behalf of on which button(new inflate) I have the focus.

Android Button performClick

In order to fudge multitouch buttons, I set a massive invisible imageView over top of everything. The I just poll for where it was touched and call performClick on the button in that area under it. Now my problem is that performClick only calls the onClick method, and doesn't actually perform a legitimate button press, so there's no animation (color change etc). I have a custom xml for the buttons, and it worked fine without the imageView. I try using setPressed and setEnabled, but the png never changes, and the button looks static. What am I missing?
How about tying a Boolean to each button. All the button logic does is flip flop the variable and maybe change an indicator (button color or text) to pushed/not pushed. Shouldn't be more than 3 or 4 lines of code executed per button press. Fire the heavy code when a 'do it' button is pressed. That would have to be faster than computing which button was pressed under the overlay...

Button Highlight

I have a keypad which i have created for my app. My problem is, I have to implement button highlight as the user slides his finger through the keys. I have tried several ways, but none works. By default when the user clicks on a new button, android highlights it for me, but when I try to move to the next button form the current button, the touch event is not working.
how to achieve this.
use the GestureDetector with onTouchEvent this solve your problem. And also use the canvas to highlight the specific location .This is done based on the values return by the MotionEvent.

Categories

Resources