2

I tried sra's workaround in a class that extends WebView. Unfortunately I am still seeing this error.

I verified that I am in fact using MyWebView by popping a Log.i(...) into MyWebView.java:

@Override
public boolean onTouchEvent(MotionEvent event) {

    if (event.getAction() == MotionEvent.ACTION_DOWN){
        Log.d("DEBUG ::: ", "in onTouchEvent() ---> ACTION_DOWN");

        int temp_ScrollY = getScrollY();
        scrollTo(getScrollX(), getScrollY() + 1);
        scrollTo(getScrollX(), temp_ScrollY);

    }

    return super.onTouchEvent(event);
}

I see "DEBUG :::" ... etc ... every time I swipe so I know that MyWebView is being used rather than WebView itself. Interestingly I only get the "Should not happen: no rect-based-test nodes found" message when I swipe Right->Left (swipe pages 1-N). I don't see the error when I swipe Left->Right (swipe pages N-1).

MyWebView in my fragment .xml:

<com.example.viewpager2.MyWebView
android:id="@+id/webView2"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true">
</com.example.viewpager2.MyWebView>

And MyWebView.java:

package com.example.viewpager2;

import android.content.Context;
import android.util.AttributeSet;
import android.util.Log;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnTouchListener;
import android.webkit.WebView;

public class MyWebView extends WebView  {

    public MyWebView(Context context) {
        super(context);
        // TODO Auto-generated constructor stub
    }

    public MyWebView(Context context, AttributeSet attrs) {
        super(context, attrs);
        // TODO Auto-generated constructor stub
    }

    public MyWebView(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
        // TODO Auto-generated constructor stub
    }

    @Override
    public boolean onTouchEvent(MotionEvent event) {

        if (event.getAction() == MotionEvent.ACTION_DOWN){
            Log.d("DEBUG ::: ", "in onTouchEvent() ---> ACTION_DOWN");

            int temp_ScrollY = getScrollY();
            scrollTo(getScrollX(), getScrollY() + 1);
            scrollTo(getScrollX(), temp_ScrollY);

        }

        return super.onTouchEvent(event);
    }
}

Not saying sra is wrong by any stretch but if I've done something wrong I'd love to be able to correct it! sra's workaround seems like a novel one and I wish it worked for me. :-(

BTW, I see this error whether in the Nexus 7 emulator or on my Nook Tab w/CM10.1

EDIT, 2013-03-29: I did some more digging last night and this morning, mainly because after some more futzing with screen touches and the emulator I found that [sra's workaround] was working for me sometimes but not always for Right->Left (swipe pages 1-N). I found that the workaround worked more frequently on my Nook Tab than it did on Nexus 7 emulator.

Inside of my onTouchEvent(...) method, first referenced above, I added another couple of Log.d(...), this time to tell me what the value of getScrollX() was:

@Override
public boolean onTouchEvent(MotionEvent event) {

if (event.getAction() == MotionEvent.ACTION_DOWN){
    Log.d("DEBUG ::: ", "in onTouchEvent() ---> ACTION_DOWN");

    int temp_ScrollY = getScrollY();

    int temp_ScrollX = getScrollX();
    if(temp_ScrollX > 0) {
        Log.d("RESET X COORD: WAS STARTING AT ", Integer.toString(temp_ScrollX));
        setScrollX(0);
    }
    scrollTo(getScrollX(), getScrollY() + 1);
    scrollTo(getScrollX(), temp_ScrollY);
    Log.d("  DEBUG COORDS::: ", "X=" + Integer.toString(getScrollX()) + " Y=" + Integer.toString(getScrollY()) + " Y2=" + Integer.toString(temp_ScrollY));
}

return super.onTouchEvent(event);

}

In my Trace Log this produced the following for 1-N (as noted previously I never saw any rect-based-test for N-1):

03-29 06:54:32.976: E/webcoreglue(9475): Should not happen: no rect-based-test nodes found
03-29 06:54:33.335: D/DEBUG :::(9475): in onTouchEvent() ---> ACTION_DOWN
03-29 06:54:33.335: D/RESET X COORD: WAS STARTING AT(9475): 1949
03-29 06:54:33.335: D/DEBUG COORDS:::(9475): X=0 Y=10 Y2=10
03-29 06:54:33.734: D/DEBUG :::(9475): in onTouchEvent() ---> ACTION_DOWN

On closer examination it looks like when I swipe cleanly from Right->Left (1-N), that is when I swipe exactly on the border for, sra's workaround always works. When I don't swipe exactly on the border, sra's workaround doesn't work. When I use the emulator more regular failures could be explained by poor mouse clicks and those happen more frequently than when I use touch to be sure.

So what I'm thinking about now -- and wondering if anybody here has any suggestions -- is if I should be trying to handle some kind of event additional to touches and that's why I'm seeing this problem when I swipe?

2

4

0 回答 0