- Posts: 5
- Thank you received: 0
Microsoft Windows Phone 8.1 support ends (13 Jul 2017)
Microsoft has ended support for Windows Phone 8.1
Questions about Android development and PDF
Touch events are not passed onto parents
- exit_music
- Topic Author
- Offline
- New Member
-
Less
More
IP: 192.168.0.71
11 years 10 months ago - 11 years 10 months ago #6454
by exit_music
Touch events are not passed onto parents was created by exit_music
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
to this:
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?
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
Code:
@Override
public boolean onTouchEvent(MotionEvent event)
{
if( m_pdv != null )
{
return m_pdv.vTouchEvent(event);
}
else
{
return true;
}
}
Code:
@Override
public boolean onTouchEvent(MotionEvent event)
{
if( m_pdv != null )
{
m_pdv.vTouchEvent(event);
}
return false;
}
How do I get the PDFView to pass the touch event up to the parent in the view stack?
Last edit: 11 years 10 months ago by liyanli.
IP: 192.168.0.71
11 years 10 months ago #6460
by radaee
Replied by radaee on topic Touch events are not passed onto parents
return true shall be OK.
- exit_music
- Topic Author
- Offline
- New Member
-
Less
More
- Posts: 5
- Thank you received: 0
IP: 192.168.0.71
11 years 10 months ago #6461
by exit_music
Replied by exit_music on topic Touch events are not passed onto parents
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:
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:
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?
Here is my main activity's layout:
Code:
<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:
Code:
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?
IP: 192.168.0.158
11 years 10 months ago #6470
by nermeen
Replied by nermeen on topic Touch events are not passed onto parents
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)
Time to create page: 0.515 seconds