mathew-kurian / TextJustify-Android

:page_facing_up: Android Text Full Jusiftication / Wrapping / Justify / Hyphenate - V2.0
https://github.com/bluejamesbond/TextJustify-Android/wiki
Apache License 2.0
1.86k stars 370 forks source link

How to enable longClick functionality? #82

Closed sigrlami closed 9 years ago

sigrlami commented 9 years ago

I need my DocumentView to be handle long click by user. I tried to set in xml

android:longClickable="true"

and

docView.setLongClickable(true);

Still no result. OnTouchListener works fine. Am I missing something?

sigrlami commented 9 years ago

So, DocumentView is extending ScrollView which also doesn't catch onLongClockListener. But. there is the workaround which works fine

GestureDetector.OnGestureListener gestureOnDocListener = new GestureDetector.SimpleOnGestureListener()
{
    @Override
    public void onLongPress(MotionEvent e)
    {
        Toast.makeText(getActivity(), "LongClick", Toast.LENGTH_SHORT).show();
    }
};

...

 @Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        setRetainInstance(true);
...
final GestureDetector gestureDetector = new GestureDetector(getActivity(), gestureOnDocListener);
documentView.setOnTouchListener(new View.OnTouchListener()
{
    @Override
    public boolean onTouch(View v, MotionEvent event)
    {
        return gestureDetector.onTouchEvent(event);
    }
});
mathew-kurian commented 9 years ago

If you can make a PR and a test case, I will be happy to merge it.

sigrlami commented 9 years ago

I'll make PR this weekend