RadaeePDF.com :: Topic: Touch events are not passed onto parents (1/1)
Welcome, Guest
Username: Password: Remember me

Signin/Signup with:

Questions about Android development and PDF

TOPIC: Touch events are not passed onto parents

Touch events are not passed onto parents 3 years 1 month ago #6454

  • exit_music
  • exit_music's Avatar
  • OFFLINE
  • Fresh Boarder
  • Posts: 5
  • Karma: 0
I want to hide the action bar, and show it when the user presses (but does not swipe) the screen. I have this working when I am not showing a pdf, but once I add the PDFView to the screen, this view then does not pass the onTouch event up the view stack.
I am copying the code from the PDFReader demo, using the ReaderController class as the view for my fragment. Everything works perfectly, except for the public boolean onTouchEvent(MotionEvent event) method.
I have tried changing the following code
@Override
public boolean onTouchEvent(MotionEvent event)
{
if( m_pdv != null )
{
return m_pdv.vTouchEvent(event);
}
else
{
return true;
}
}
to this:
@Override
public boolean onTouchEvent(MotionEvent event)
{
if( m_pdv != null )
{
m_pdv.vTouchEvent(event);
}
return false;
}
but then scrolling no longer works.
How do I get the PDFView to pass the touch event up to the parent in the view stack?
Last Edit: 3 years 1 month ago by liyanli.
The administrator has disabled public write access.

Touch events are not passed onto parents 3 years 1 month ago #6460

  • radaee
  • radaee's Avatar
  • OFFLINE
  • Moderator
  • Posts: 825
  • Thank you received: 10
  • Karma: 43
return true shall be OK.
The administrator has disabled public write access.

Touch events are not passed onto parents 3 years 1 month ago #6461

  • exit_music
  • exit_music's Avatar
  • OFFLINE
  • Fresh Boarder
  • Posts: 5
  • Karma: 0
No I need to return false, so that the parent view's onTouch event gets called. If I return true, then the event ends there and does not get passed up the view hierarchy.

Here is my main activity's layout:
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/activity_main"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#FfFfFf" >

    <FrameLayout
        android:id="@+id/content_frame"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="#ffffff"
        android:orientation="vertical" />

    <ProgressBar
        android:id="@+id/progress_indicator"
        android:layout_width="50dp"
        android:layout_height="50dp"
        android:layout_centerInParent="true"
        android:layout_margin="10dp"
        android:visibility="invisible" />

    <RelativeLayout
        android:id="@+id/drawhouse"
        android:layout_width="300dp"
        android:layout_height="match_parent"
        android:layout_alignParentTop="true"
        android:layout_gravity="start"
        android:background="#ffffff"
        android:orientation="vertical" >

        <ListView
            android:id="@+id/left_drawer"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_below="@+id/buttonrow"
            android:choiceMode="singleChoice"
            android:divider="#808080"
            android:dividerHeight="1dp" />

        <TextView
            android:id="@+id/empty_list_item"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:paddingBottom="2dp"
            android:paddingLeft="2dp"
            android:paddingRight="2dp"
            android:paddingTop="2dp"
            android:text="@string/emptyDrawer"
            android:textColor="#000000"
            android:textSize="18sp"
            android:textStyle="bold" />

        <RelativeLayout
            android:id="@+id/buttonrow"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_alignParentTop="true"
            android:background="#E6E6E6" >

            <Button
                android:id="@+id/refresh"
                android:layout_width="40dp"
                android:layout_height="40dp"
                android:layout_alignParentLeft="true"
                android:layout_alignParentTop="true"
                android:layout_marginBottom="2dp"
                android:layout_marginLeft="2dp"
                android:layout_marginTop="2dp"
                android:background="@drawable/ic_menu_refresh" >
            </Button>

            <Button
                android:id="@+id/search"
                android:layout_width="40dp"
                android:layout_height="40dp"
                android:layout_alignParentRight="true"
                android:layout_alignParentTop="true"
                android:layout_marginBottom="2dp"
                android:layout_marginLeft="2dp"
                android:layout_marginRight="2dp"
                android:layout_marginTop="2dp"
                android:background="@drawable/ic_btn_search" >
            </Button>

            <Button
                android:id="@+id/downloadFilter"
                android:layout_width="40dp"
                android:layout_height="40dp"
                android:layout_alignParentTop="true"
                android:layout_marginBottom="2dp"
                android:layout_marginLeft="2dp"
                android:layout_marginRight="2dp"
                android:layout_marginTop="2dp"
                android:layout_toLeftOf="@+id/search"
                android:background="@drawable/download" >
            </Button>
        </RelativeLayout>
    </RelativeLayout>

</android.support.v4.widget.DrawerLayout>



Now I want the actionbar to disappear when the user touches (but does not swipe) the screen. I have this code in my main activity's onCreate event:
mDrawerLayout = (DrawerLayout) findViewById(R.id.activity_main);

		mDrawerLayout.setOnTouchListener(new OnSwipeTouchListener(this)
		{
			
			 boolean isSwipe = false;

			    public void onSwipeRight() {
			    	isSwipe = true;
			    }

			    public void onSwipeLeft() {
			    	isSwipe = true;
			    }

			    public void onSwipeTop() {
			    	isSwipe = true;
			    }

			    public void onSwipeBottom() {
			    	isSwipe = true;
			    }
			
			
			
			@Override
			public boolean onTouch(View v, MotionEvent event)
			{
				super.onTouch(v, event);
				int eventaction = event.getAction();

				switch (eventaction)
				{
					case MotionEvent.ACTION_UP:
						if(!isSwipe)
						{
							if (isActionBarShown)
							{
								getActionBar().hide();
								isActionBarShown = false;
							}
							else
							{
								getActionBar().show();
								isActionBarShown = true;
	
							}
						}
						isSwipe= false;
						break;
						
						
				}
				return false;
			}
			
		});


Now this code works when I am not using AndroidPDF, but when I replace the content_frame in my layout with a ReaderController to show a pdf, the touch on the screen no longer goes to the mDrawerLayout because the ReaderController's onTouch returns true. I need it to return false so that the mDrawerLayout can receive a touch, but then the scrolling does not work.

I hope this makes it more clear. How does the PDFView's touch work? I'm guessing that the ViewGroup implements a strange onInterceptTouchEvent that makes this whole thing act weirdly. Is there any way that I can get the mDrawerLayout to receive onTouch events, while also keeping the PDFView's swipe-to-turn-a-page functionality?
The administrator has disabled public write access.

Touch events are not passed onto parents 3 years 1 month ago #6470

  • nermeen
  • nermeen's Avatar
  • OFFLINE
  • Moderator
  • Posts: 659
  • Thank you received: 38
  • Karma: 17
Try to handle the touch event yourself before passing it to the pdf viewer, the alternative will be to modify PDFView.vTounchEvent (but this requires at least the professional license)
The administrator has disabled public write access.
The following user(s) said Thank You: liyanli
Powered by Kunena Forum