I am using css columns to display contents in android webview. I used longclicklistner {return true}; with this I was able to disable longclick in phones but it doesn't seem to work in tabs(eg galaxy tab 2). I'm also preventing touchmove event using jquery but the css columns are moving when swipe occurs as part of longclick. Any help is welcome. Thank you.
wbView.setOnLongClickListener(new View.OnLongClickListener() {
#Override
public boolean onLongClick(View v) {
return true;
}
});
wbView.setLongClickable(false);
jquery code:
document.getElementById("divIdToShowContent").ontouchmove = function(e){
e.preventDefault();
var touching = null;
}
You have to use a GestureDetector, the SimpleOnGestureListener has onSingleTapConfirmed() for click events and onFling() for swipe events.
Refer this
I avoided using GestureDetector and SimpleOnGestureListener, I done it with catching touch listnerby catching the position fron MotionEvent.ACTION_DOWN and MotionEvent.ACTION_UP
Try this :
_webview.setOnLongClickListener(new OnLongClickListener() {
#Override
public boolean onLongClick(View v) {
return true;
}
});
Related
I have a recyclerview with items inside, I would like to distinguish between swipe (I am moving the element horizontaly making some action and setting it back to its original place) singleTouch and longClick, what is the best Practice of achieving it?
I seen a lot of implementations here, but none that work\super messy(and also dont work properly), if i implement custom gestureDetector and switchcase inside it works but it takes the phone about a second to react, if i implement onTouch in only catches onTouch, if I dont the onClick and onLong work but not the swipe
currently only the swipe works:
item.setOnTouchListener(new View.OnTouchListener() {
#Override
public boolean onTouch(View v, MotionEvent event) {
logd("TAG","2");
return false;
}
});
}
item.setOnClickListener(v -> {
logd("TAG","1");
});
item.setOnLongClickListener(v -> {
logd("TAG","2");
});
any advice would be appreciated,
Thanks
I've been trying the ItemTouchHelper for Drag and Swipe actions in a RecyclerView List. I've used this guide and it's working perfectly, except that i can't make the swipe activate on LongClick. I've managed to do it for the Drag action:
textview.setOnLongClickListener(new View.OnLongClickListener() {
#Override
public boolean onLongClick(View v) {
dragStartListener.onStartDrag(holder);
return false;
}
});
I don't know how to do it for the swipe, since it doesn't have an onStartSwipe() interface and any of my attempts to implement one, by mimicking the onStartDrag() interface, has failed.
How it can be made? Thank you for your time.
I've managed to implement the onStartSwipe() interface and it works by itself. However once i try to implement both drag and swipe on the same view, it acts strangely. More precisely, once i touch the view, for the entire hold down, only the drag or only the swipe animation would be activated.
Not only that, it is difficult to chose between the two actions since, it will get the first mirco movement you do to chose between either one or another.
I tried to this code for the above description:
tv.setOnLongClickListener(new View.OnLongClickListener() {
#Override
public boolean onLongClick(View v) {
mDragStartListener.onStartDrag(holder);
return false;
}
});
tv.setOnLongClickListener(new View.OnLongClickListener() {
#Override
public boolean onLongClick(View v) {
mSwipeStartListener.onStartSwipe(holder);
return true;
}
});
I also tried to use a framelayout like this:
tv.setOnLongClickListener(new View.OnLongClickListener() {
#Override
public boolean onLongClick(View v) {
mDragStartListener.onStartDrag(holder);
return true;
}
});
fl.setOnLongClickListener(new View.OnLongClickListener() {
#Override
public boolean onLongClick(View v) {
mSwipeStartListener.onStartSwipe(holder);
return true;
}
});
Here i drag the TextView and i swipe the FrameLayout. But since the text view is on top of the framelayout, it would only work dragging, and sometimes swipe if you touch on the corners of the item.
Any ideas on how to make both of drag and swipe work on the same item? I want to be able to either drag or swipe, once an element is LongClicked. I could use a separate ImageView for swiping and the TextView for dragging, but i'd rather not have to do that since it would ruin my design.
I am not sure why you are using draghelpers in recyclerview.
You can use ItemTouchHelper instead
It allows both drag and drop and swipe.
ItemTouchHelper
SimpleCallBack
Tutorial for implementation
I am trying to make some field with text (no button) what I click on to open datepicker dialog.
I am totally begginer and I am trying it on easy example.
firstbirth.setOnTouchListener(new View.OnTouchListener() {
#Override
public boolean onTouch(View view, MotionEvent motionEvent) {
Toast.makeText(getApplicationContext(), "ahooj", Toast.LENGTH_LONG).show();
return false;
}
});
firstbirth is spinner, I tried it with Edittext and the result was same.
Can anybody help me?
Thanks in advance!
Use an OnClickListener instead.
setOnClickListener(View.OnClickListener l)
OnTouchListeners will trigger on multiple touch events (like touch down, touch up etc.) whereas the OnClickListener will only get fired once (onClick :) )
If you, for some reason, want to use an OnTochListener you can make sure that its only called once.
Try:
#Override
public boolean onTouch(View view, MotionEvent motionEvent) {
if (motionEvent.getAction() == MotionEvent.ACTION_UP { // another option would be ACTION_DOWN for example
Toast.makeText(getApplicationContext(), "ahooj", Toast.LENGTH_LONG).show();
return true;
}
return false;
}
Thanks it sounds logical but when I use OnClick event application felt down while initializing.
firstbirth.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
DialogFragment dd1 = new DatePickerFragment();
dd1.show(getFragmentManager(), "Select a date");
}
});
Problem is not with DialogFragment becasue it works when I use onTouch event.
Thanks :)
I have a ListView. Inside the cells, I have a custom view. (You can draw in it.)
When drawing, I turn off scrolling of the list ..
theListView.setOnTouchListener(new View.OnTouchListener()
{
public boolean onTouch(View v, MotionEvent event)
{
if (event.getAction() == MotionEvent.ACTION_MOVE)
{
if ( STATE.weAreDrawoning )
{
return true;
// so, do not forward and hence do not scroll the list
}
else
{
return false;
}
}
return false;
}
});
That's fine. But strangely, up-down touching in the custom View, is still passed on to the list and makes it scroll.
public class AmazingCustomView extends View
{
blah
#Override
public boolean onTouchEvent(MotionEvent event)
{
blah
return true;
}
}
notice in the custom view onTouchEvent is returning true (I also tried false! :) )
but the motion events appear to be still passed on .. what gives??
Is there another "on .. something" I'm missing in the custom view? Sorry, new to Android and lame. Thanks!
PS, I tried turning on "clickable" on the xml of the custom view, didn't help :O
--
Worse ...
I've just realised ALL controls in the ListView, say buttons, still "pass on scrolling"
I fear the system I use above for turning off scrolling is just no good. :/
important...
For anyone googling to here. The only real way I've found to turn off scrolling on an android listView ...
danosipov.com/?p=604
(don't forget to separately turn off your pull-to-refresh)
You may need to override onInterceptTouchEvent. Its an odd function, documentation here: http://developer.android.com/reference/android/view/ViewGroup.html#onInterceptTouchEvent%28android.view.MotionEvent%29
How can I turn on the "pen-only" mode programatically on the Lenovo Thinkpad Tablet running ICS 4.0.3?
I'm very sorry that I can't answer your question, though I think WebnetMobile might be right - there doesn't seem to be an API method for pen-only mode. However if you go to this article http://knowledge.lapasa.net/?p=490 it states that you should focus on the diameter of the input device (the touch diameter of a finger is much greater than that of a pen stylus).
As for WebnetMobile saying it is pointless to use a tablet in pen-only mode, I'd say that it is a longed for feature of any artist or note taker to be able to rest your hand on the surface upon which you're drawing/writing.
If you are developing an app, you can actually implement this. If your stylus can "hover" on your screen before it touches, you can add an OnHoverListener on the highest View in your activity to set a global variable isPen to true. Then override dispatchTouchEvent() in your activity and check the variable before passing on the event in your app.
rootView.setOnHoverListener(new View.OnHoverListener() {
#Override
public boolean onHover(View view,MotionEvent event) {
isPen = true;
return true;
}
});
And
#Override
public boolean dispatchTouchEvent(MotionEvent event) {
if(isPen) {
return super.dispatchTouchEvent(event);
} else {
return true;
}
}
I know this is old, but I found nothing else on this problem and I eventually come out with this solution: you need to extend your view and override onTouchEvent:
#Override
public boolean onTouchEvent(MotionEvent event) {
// Disable multitouch
if (event.getPointerCount() != 1)
return false;
// If not stylus return
MotionEvent.PointerProperties pp = new MotionEvent.PointerProperties();
event.getPointerProperties(0, pp);
if (pp.toolType != MotionEvent.TOOL_TYPE_STYLUS)
return false;
// Dispatch event to the original view
return super.onTouchEvent(event);
}