dispatchTouchEvent

by Business Talk » Sat, 09 Jan 2010 02:15:29 GMT


Sponsored Links
 How can I programmatically press/release a button? I was playing with
the button.dispatchTouchEvent(motionEvent); but failed to
programmatically generate  the MotionEvent to be passed to the
dispatchTouchEvent



dispatchTouchEvent

by Business Talk » Sat, 09 Jan 2010 02:37:37 GMT


 I found the way to generate the MotionEvent, and it's
MotionEvent.obtain



> dispatchTouchEvent


Sponsored Links


dispatchTouchEvent

by jbo » Wed, 27 Jan 2010 04:28:07 GMT


 i , 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



Other Threads

1. Loading an image from a network stream

Hi!
I'm currently developing a software that should connect to IP cameras
and display the video. The stream the camera sends is just a lot of
images with a small HTTP header. I've made a code that works right,
but it is quite slow and freezes sometimes. It seems that the problem
is when the program tries to load de image, I guess, with
Drawable.createFromStream().
Is there any ways I could use to get the code to run faster?


Here is my current code:

// MJPEG.java
package eldomus.mjpeg;
import java.util.*;
import java.io.*;
import java.net.*;
import android.app.*;
import android.os.*;
import android.widget.*;
import android.widget.AdapterView.*;
import android.view.*;
import android.util.*;
import android.graphics.drawable.*;

public class MJPEG extends Activity {
  static private final int DELAY = 200;
  static public int x = 0;
  private IPCam camera = null;
  private ImageView img = null;
  private Handler handler = new Handler() {
    @Override public void handleMessage(Message msg) {
      try {
        Drawable x = camera.getImage();
        img.setImageDrawable(x);
      } catch(Exception e) {
        printf("Error: " + e);
      } finally {
        printf("LoL!\n");
        sleep();
      };
    };
    public void sleep() {
      this.removeMessages(0);
      sendMessageDelayed(obtainMessage(0), DELAY);
    };
  };
  @Override public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    try {
      camera = new IPCam("161.28.137.220", 80, "/axis-cgi/mjpg/
video.cgi?camera=&resolution=320x240");
      img = (ImageView)findViewById(R.id.image);
    } catch(Exception e) {
      printf("Error: " + e);
    } finally {
      printf("Start!");
    };
    handler.sendMessage(new Message());
  };
  private void printf(String str) {
    Toast.makeText(getApplicationContext(), str,
Toast.LENGTH_SHORT).show();
  };
};




// IPCam.java
package eldomus.mjpeg;
import java.util.*;
import java.io.*;
import java.net.*;
import android.app.*;
import android.os.*;
import android.widget.*;
import android.widget.AdapterView.*;
import android.view.*;
import android.util.*;
import android.graphics.drawable.*;

class ContinuedStream extends InputStream {
  private InputStream base = null;
  private Scanner scanner = null;
  ContinuedStream(InputStream x) {
    base = x;
    scanner = new Scanner(this);
  };
  public void close() {
    // Do nothing!
  };
  public int read(byte[] b, int offset, int len) throws IOException {
    return base.read(b, offset, len);
  };
  public int read(byte[] b) throws IOException {
    return base.read(b);
  };
  public int read() throws IOException {
    return base.read();
  };
  public String readLine() throws IOException {
    String result = "";
    char x = (char)read();
    main: while(true) {
      while(x == '\r') {
        x = (char)read();
        if(x == '\n') {
          break main;
        };
        result += x;
      };
      result += x;
      x = (char)read();
    };
    return result;
  };
  public String readHeader() throws IOException {
    String result = "";
    while(true) {
      String tmp = readLine();
      if(tmp.length() == 0) {
        break;
      };
      result += tmp;
      result += "\r\n";
    };
    return result;
  };
};
public class IPCam {
  private Socket socket = null;
  private PrintStream out = null;
  private ContinuedStream in = null;
  public IPCam(String host, int port, String file) throws Exception {
    socket = new Socket(host, port);
    out = new PrintStream(socket.getOutputStream());
    in = new ContinuedStream(socket.getInputStream());
    write("GET " + file + " HTTP/1.0\r\nKeep-Alive: 300\r\nConnection:
keep-alive\r\n");
    in.readHeader();
  };
  public Drawable getImage() throws Exception {
    String str = in.readHeader();
    MJPEG.x = str.length();
    Drawable img = Drawable.createFromStream(in, "src");
    return img;
  };
  private void write(String s) {
    out.print(s + "\r\n");
    out.flush();
  };
};




Thank you.

-- 

2. Android not taking up full screen size

Hey guys,

Tried to search for this one but the search terms I used didn't seem
to find worthwhile results. I'm creating an application to run on a
device with a 800x480 resolution (the archos 5) so I've created an AVD
in the emulator with that resolution. However, when I run my program
in the emulator it simply shows the program with the default android
size, centered in the 800x480 window. It is not stretched to cover the
whole screen. How can I fix this? I'm using Android 2.1.

-- 

3. Touch not working for listitem??

4. How to pass on extras to a custom intent?

5. Samsung Extravaganza plus plus on Mirdak Yogya @Starbucks Amplaz dimulai jam 16:00 hari Rab

6. sms pending tp terkirim

7. Attaching to DDMS