Hi , i have a qustion about onTouch event, I have a layout that
consist of 2 elements, a  WebView and on top of it a TextView and then
a custom view, that expand all over the screen and is transparent.
With these i want to carch touch events and delegate to the correct
widget either TextView or WebView depending on the touch event
position (MoseEvent).

[code]
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/
android"
        android:orientation="vertical" android:layout_width="fill_parent"
        android:layout_height="fill_parent">

        <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/
android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">

         <TextView
            android:id="@+id/label"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="Type here:"/>

                <WebView android:id="@+id/webview"
                        android:layout_width="fill_parent"
                        android:layout_height="fill_parent"
                        android:layout_below="@id/label"/>

         </RelativeLayout>
        <LinearLayout xmlns:android="http://schemas.android.com/apk/res/
android"
                android:layout_width="fill_parent"
                android:layout_height="fill_parent"
                android:orientation="vertical">

                <com.frame.TransparentPanel android:id="@+id/transparent_panel"
                        android:layout_width="fill_parent"
                        android:layout_height="fill_parent"/>

        </LinearLayout>

</FrameLayout>
[/code]


[code]
public class TransparentPanel extends LinearLayout
{
        private Paint   innerPaint, borderPaint ;
        private List<PointF> pointsToDraw = new ArrayList<PointF>();
        private WebView webview;
        private Paint   touchPaint;

        public TransparentPanel(Context context, AttributeSet attrs) {
                super(context, attrs);
                init();
        }

        public TransparentPanel(Context context) {
                super(context);
                init();
        }

        private void init() {
                touchPaint  = new Paint();
                touchPaint.setARGB(255, 0, 0, 255);
                touchPaint .setAntiAlias(true);
                touchPaint .setStyle(Style.STROKE);
                touchPaint .setStrokeWidth(2);

                innerPaint = new Paint();
                innerPaint.setARGB(0, 100, 75, 75); //gray
                innerPaint.setAntiAlias(true);

                borderPaint = new Paint();
                borderPaint.setARGB(255, 255, 255, 255);
                borderPaint.setAntiAlias(true);
                borderPaint.setStyle(Style.STROKE);
                borderPaint.setStrokeWidth(2);
        }

        public void setInnerPaint(Paint innerPaint) {
                this.innerPaint = innerPaint;
        }

        public void setBorderPaint(Paint borderPaint) {
                this.borderPaint = borderPaint;
        }

        @Override
    public boolean onTouchEvent(MotionEvent event) {
                int[] location = new int[2];
                System.out.println("Event:"+event.toString());
                webview.getLocationInWindow(location);
                System.out.println(webview.getTop());
                System.out.println(webview.getLeft());
                System.out.println(webview.getRight());
                System.out.println(webview.getBottom());

                System.out.println("Location:"+ String.valueOf(location[0]) +","
+String.valueOf(location[1]));

                if (event.getY()>=webview.getTop() && 
event.getY()<=webview.getBottom
()) {

                        webview.onTouchEvent(event);
                }

                pointsToDraw.add(new PointF(event.getX(), event.getY()));
                invalidate();
                return true;
        }

    @Override
    protected void dispatchDraw(Canvas canvas) {

        RectF drawRect = new RectF();
        drawRect.set(0,0, getMeasuredWidth(), getMeasuredHeight());
        System.out.println(getMeasuredWidth());
        System.out.println(getMeasuredHeight());

        canvas.drawRoundRect(drawRect, 5, 5, innerPaint);

                Iterator<PointF> iterator = pointsToDraw.iterator();
        while (iterator.hasNext()) {
                PointF p = iterator.next();
                canvas.drawCircle(p.x, p.y, 5, touchPaint);
        }

                super.dispatchDraw(canvas);
    }

        public void setWebView(WebView webview) {
                this.webview = webview;

        }
}
[/code]

Currently when the method webview.onTouchEvent(event); gets executed,
the click over the webview is not correct.
For example, if i'm looking at google.com.ar and touch near  e letter
Web link gets selected.
Is there something about position, measurements i have to take into
account when propagatin an event?

Thanks



-- 
You received this message because you are subscribed to the Google
Groups "Android Beginners" group.

NEW! Try asking and tagging your question on Stack Overflow at
http://stackoverflow.com/questions/tagged/android

To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-beginners?hl=en

Reply via email to