Reading MotionEvent.getPressure() lazarus / 43-Android ---------------------------------------------------------------------- meanderix · 2012-06-22 13:04 Hi, I'm planning to write an app where I need to be able to read the pressure of at least one of the touch points. The MotionEvent class has a getPressure() method that allows you to retrieve this information. The way I'm thinking of reading this would be by modifying the LCLOnTouch JNI callback to include a third parameter, by making the following changes: Code: Text  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i     @Override public boolean onTouchEvent (MotionEvent event)    {      int eventResult = LCLOnTouch(event.getX(), event.getY(), event.getPressure(0), event.getAction());      if ((eventResult | 1) != 0) postInvalidate();      return true;    }     Code: Text  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i         function Java_com_pascal_lclproject_LCLActivity_LCLOnTouch(env:PJNIEnv ;this:jobject; x, y, pressure: single; action: jint): jint; cdecl;  Code: Text  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i         function Java_com_pascal_lclproject_LCLActivity_LCLOnTouch(env:PJNIEnv ;this:jobject; x, y, pressure: single; action: jint): jint; cdecl;var  lCurForm: TCDNonNativeForm;  lTarget: TWinControl;  lEventPos: TPoint;begin  {$ifdef VerboseCDEvents}  __android_log_write(ANDROID_LOG_INFO,'lclapp',PChar(Format('LCLOnTouch called x=%f y=%f action=%d', [x, y, action])));  {$endif}  eventResult := 0;   // Declare a global variable 'TouchPressure', e.g. in lazdeviceapis.pas  // read pressure value in MouseDown/MouseUp event handlers  TouchPressure := pressure;    lCurForm := GetCurrentForm();   case action of    ACTION_DOWN:    begin      CallbackMouseDown(lCurForm, Round(X), Round(Y), mbLeft, []);    end;  ACTION_UP:    begin      CallbackMouseUp(lCurForm, Round(X), Round(Y), mbLeft, []);    end;    ACTION_MOVE: CallbackMouseMove(lCurForm, Round(X), Round(Y), []);  end;   // This sends messages like Invalidate requests  Result := eventResult;end;  Some questions: Is this a good approach?Do I need to make any other changes besides the above? Thanks in advance. ---------------------------------------------------------------------- felipemdc · 2012-06-22 14:05 It is a good approach and will probably work. If you want to make a patch to be merged into the general codebase it would need to be refined, however. For example, send the entire object event and call getPressure in the Pascal side, since we might want to call other things from this object in the future. ---------------------------------------------------------------------- meanderix · 2012-06-22 14:37 Hi Felipe, Quote from: felipemdc on June 22, 2012, 04:05:54 pmIt is a good approach and will probably work. If you want to make a patch to be merged into the general codebase it would need to be refined, however. For example, send the entire object event and call getPressure in the Pascal side, since we might want to call other things from this object in the future. Is there any simple way to invoke a method of a java object on the pascal side? ---------------------------------------------------------------------- felipemdc · 2012-06-23 09:08 Quote from: meanderix on June 22, 2012, 04:37:46 pmIs there any simple way to invoke a method of a java object on the pascal side? Yes, JNI: http://wiki.lazarus.freepascal.org/Android_Programming#Example_1:_Crea ting_a_Java_object_and_calling_a_Java_method ---------------------------------------------------------------------- meanderix · 2012-06-23 20:03 Quote from: felipemdc on June 23, 2012, 11:08:46 amQuote from: meanderix on June 22, 2012, 04:37:46 pmIs there any simple way to invoke a method of a java object on the pascal side? Yes, JNI: http://wiki.lazarus.freepascal.org/Android_Programming#Example_1:_Crea ting_a_Java_object_and_calling_a_Java_method Excellent, I might do this later on -- for now on I've modified the function prototype.