Signin/Signup with: 
Welcome, Guest
Username: Password: Remember me
Questions about Android development and PDF
  • Page:
  • 1

TOPIC:

Touch events are not passed onto parents 9 years 10 months ago #6454

  • exit_music
  • exit_music's Avatar Topic Author
  • Offline
  • New Member
  • New Member
  • Posts: 5
  • Thank you received: 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?

Please Log in or Create an account to join the conversation.

Last edit: by liyanli.

Touch events are not passed onto parents 9 years 10 months ago #6460

  • radaee
  • radaee's Avatar
  • Offline
  • Moderator
  • Moderator
  • Posts: 1123
  • Thank you received: 73
return true shall be OK.

Please Log in or Create an account to join the conversation.

Touch events are not passed onto parents 9 years 10 months ago #6461

  • exit_music
  • exit_music's Avatar Topic Author
  • Offline
  • New Member
  • New Member
  • Posts: 5
  • Thank you received: 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?

Please Log in or Create an account to join the conversation.

Touch events are not passed onto parents 9 years 10 months ago #6470

  • nermeen
  • nermeen's Avatar
  • Offline
  • Platinum Member
  • Platinum Member
  • Posts: 962
  • Thank you received: 87
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 following user(s) said Thank You: liyanli

Please Log in or Create an account to join the conversation.

  • Page:
  • 1
Powered by Kunena Forum