0

I am following a book on "Rapid Android Development" with Processing 2.0.3 windows 7 64bit, having only api level 10 installed (android 2.3.3).

The example I am at, uses "motionPressure" which was dropped by 2.0b7 http://wiki.processing.org/w/Android#Mouse.2C_Motion.2C_Keys.2C_and_Input "The motionX, motionY, motionPressure, etc. variables have all been removed. This was sort of a kludge, and it'll be handled better by a later touch API. It should be easy to bring them back with a dozen lines of code in your sketch, if you were relying on them. Instead, just use mouseX/Y for now."

I found a fix here https://forums.pragprog.com/forums/209/topics/11348 but the code doesn't seem to work. When it reaches mouseDragged() "MotionEvent me = (MotionEvent) mouseEvent.getNative();" it stops at this line saying cannot find symbol.

How can I fix this in a simple way? I am just learning to code.

edit: I see motionPressure being used more and more throughout the book, so I am going to need a way of replicating that function that acts the same.

import android.view.MotionEvent;

float maxPressure;
float motionPressure;

void setup()
{
  noStroke();
  background(0);
}

void draw()
{
  fill(motionPressure/maxPressure * 255);

  ellipse(mouseX, mouseY, mouseX-pmouseX, mouseY-pmouseY);

  println(motionPressure);

  if(motionPressure > maxPressure)
    maxPressure = motionPressure;
}

void mouseDragged() {
  MotionEvent me = (MotionEvent) mouseEvent.getNative();
  motionPressure = me.getPressure();
  println (motionPressure);  // can do stuff with this float now -- mine ranges .4 - 3.6 -- not 0 -1
}
GANoob4eva
  • 13
  • 4
  • I'm not familiar with using Processing for android apps, but I don't see `mouseEvent` (the variable, not the class) defined anywhere. Have you looked at this page? http://wiki.processing.org/w/Android#Mouse.2C_Motion.2C_Keys.2C_and_Input – kevinsa5 Feb 10 '14 at 19:27
  • yes, I've seen the link but I don't quite understand what to make of it. I tried replacing `mouseEvent` with `MotionEvent` but I still get the `cannot find symbol` error at that line. – GANoob4eva Feb 11 '14 at 11:08
  • Could you copy/paste the exact error? What I meant was that you start using `mouseEvent`, the variable, before you declare it or give it any value. Just like you can't do something like `print(x);` without giving `x` a value first. – kevinsa5 Feb 11 '14 at 13:59
  • `cannot find symbol` & `BUILD FAILED C:\Users\username\AppData\Local\Android\android-sdk\tools\ant\build.xml:720: The following error occurred while executing this line: C:\Users\username\AppData\Local\Android\android-sdk\tools\ant\build.xml:734: Compile failed; see the compiler error output for details.` here's a screenshot: http://s29.postimg.org/baf9wa1vb/error.png – GANoob4eva Feb 12 '14 at 08:52
  • I understand what you are saying. Maybe the code snippet is for an older version of android.view.MotionEvent that had `mouseEvent` included? – GANoob4eva Feb 12 '14 at 08:59
  • thx, works with stripped code `import android.view.MotionEvent; //fix String touchEvent = ""; float pressure = 0.0; void setup() { noStroke(); background(0); } void draw() { } void mouseDragged() { fill(pressure * 255); ellipse(mouseX, mouseY, mouseX-pmouseX, mouseY-pmouseY); println(pressure); } //fix @Override public boolean dispatchTouchEvent(MotionEvent event) { pressure = event.getPressure(); int action = event.getActionMasked(); pressure = event.getPressure(); switch (action) {case MotionEvent.ACTION_UP: pressure = 0.0; break; } return super.dispatchTouchEvent(event); }` – GANoob4eva Feb 12 '14 at 13:30

1 Answers1

0

here's a stripped down version of the code from their wiki that seems to work. Thank you for pointing that out to me kevinsa5

import android.view.MotionEvent;

// fix prerequisite
String touchEvent = "";
float pressure = 0.0;

void setup()
{
    noStroke();
    background(0);
}

void draw()  { }

void mouseDragged()
{
    fill(pressure * 255);
    ellipse(mouseX, mouseY, mouseX-pmouseX, mouseY-pmouseY);
    println(pressure);
}

// fix
@Override
public boolean dispatchTouchEvent(MotionEvent event) {
    pressure = event.getPressure();
    int action = event.getActionMasked();
    pressure = event.getPressure();
    switch (action) {case MotionEvent.ACTION_UP: pressure = 0.0; break; }
    return super.dispatchTouchEvent(event);
}
GANoob4eva
  • 13
  • 4