Potential of processing on Android Studio for software in psychological field

Dear all,

I’m involved in a professional challenge for using processing on Android Studio in order to develop an Android App for neurophysiological research in clinical investigation in Besançon (France).

As a short introduction, I would share those links below on who am I and why I post it here.

https://fr.linkedin.com/in/maxime-kivy-33679054

https://fr.artquid.com/artist/maxime.kivy/maxime-kivy.html

And for who I’m working

http://gabrieldamien.free.fr/

I would know if this topic is interesting for you as a kind of marketing issue?

Regards,

Maxime

2 Likes

Hey There !

It very much so possible to use the processing core in Android studio. Or on the contrary you could just processing Android mode.

Hey ! Thanks for feedback :slight_smile:

Yes it’s possible, I would know on how both contribute to the community while doing my fulltime job, but I’m on this project only till beginning of august!

Do you think we can have a certain synergy ?

I already did it :slight_smile:

I’m sorry I do not know how use tools you’re using in your community, this below

I. How to transfer a Processing Web App to Android App?
First approach: transfer the Web on Processinginto IntelliJ

On the early beginning of the project I searched “how to do” into Google. I usedthose keywords: “install processing IntelliJ windows 10” and then look at the tutorialeditedby Margot Rutgers on June 3, 2016 through the link below:

How to develop an Android app with IntelliJ?

Used Google key-words : “intellij install android module”

Other issues investigated:

cordova
Mobile apps with HTML, CSS & JS

Target multiple platforms with one code base

Free and open source
First TO DO list
After those several searches, I arrived to this TO DO list:

  1. Configuration processing plugin on IntelliJ
  2. Implementation of existing JavaEE solutions on IntelliJ
  3. Transfer on Android App on IntelliJ
  4. Study the use of this application under Android Studio of JetBrains like IntelliJ
  5. Study the use of the open source solution Cordova
    Why my first TO DO list failed?
    Once I began to work with Processing, I discovered that the whole project can be export as an Android Project within few clicks.

And if I could finally use Processing directly into Android Studio?

Used Google key-words: “processing with android studio” Do
II. Studying the lead of this project with another point of view
Using processing directly for the transfer to Android App
Useful link:
What I did on June 11st 2019
⦁ Installations of all librariesrequired
⦁ Software isworking
⦁ Android extension install on Processing
⦁ Android projectbuilt on Processing
⦁ Download android studio
⦁ Transferedproject to android studio
⦁ I can work the project directly on android studio
Step-by-step: Initial code
We found below the folder containing Progessing code (Java languThese classes are well documented and represent tools of sketch_3615_neuro_vivo :
• Attractor
• Boundary
• Mover
• Surface
Commentas far as possiblesketch_3615_neuro_Vivoand do not use the parts of acquisition through webcam (it will be done if I have the time thereafter).
Once done I transferred to Android and open with Android Studio
This is great job! But as doing without the first TO DO list planned, I forget one important fact: how to use the software without keyboard?
Use Button with Android Studio directly
On our application it was impossible to deal with button on first plan and processing design on the second.
I tried several things such as below while using those kinds of link:

/**END OF VOID DRAW **/

  /**
   * START CUSTOMIZED THE APP BY MAXIME
   **/
  Button b1;
  Button b2;
  Button b3;
  Button b7;
  Button b9;
  /**STOP CUSTOMIZED THE APP BY MAXIME**/


  /**
   * STARTING VOID KEYRELEASED ie. what happened once we touch the keyboard
   **/
  void keyReleased() {
    if (key == 's' || key == 'S') saveFrame(timestamp() + "_##.png");
    switch (state) {
      case 0:
        // WAITING
        if (b1.isPressed()) {
          mode = 1;
          state = 10;
        } else if (b2.isPressed()) {
          mode = 2;
          state = 1;
        } else if (b3.isPressed()) {
          mode = 3;
          state = 1;
        }
        break;

      case 1:
        // IF NEEDED, CHOICE OF PARAMS
        // WAITING
        if (b1.isPressed()) {
          objectifValence= 25;
          objectifArousal= 25;
          state = 10;
        } else if (b3.isPressed()) {
          objectifValence= 75;
          objectifArousal= 25;
          state = 10;
        } else if (b7.isPressed()) {
          objectifValence= 25;
          objectifArousal= 75;
          state = 10;
        } else if (b9.isPressed()) {
          objectifValence= 75;
          objectifArousal= 75;
          state = 10;
        }
        break;

      case 20:
        if (key == ' ') state = 30;
        break;
    }
  }
/**END OF VOID KEY RELEASED **/

III. Implementation of processing code directly on Android studio

Search key-word on Google: “Use processing with android studio “

  1. Implementation of sketch module following tutorial linked below

I’m already at the step 6, right write Sketch and not sketch for the Java class: I lost almost the day before to deal with it !

Once done, processing library isn’t taking into account:
⦁ Go to file ??Project structure ??Modules ?? “+”?? import.JAR package?? set the .JAR of Processing module
Than “apply and “OK”

Once, the library is taken into account
IV. Make a button using processing

Key word on goggle : “create button processing for android”

Install a library ?

The code in the link above in Processing and transfer it into android studio and have on AVD such as below:

The “Special Sketch Android Button” is on Android Studio

Android Studio MainActivity is:

package processing.test.sketch_proto_button_android;

import android.os.Bundle;
import android.content.Intent;
import android.view.ViewGroup;
import android.widget.FrameLayout;
import android.support.v7.app.AppCompatActivity;

import processing.android.PFragment;
import processing.android.CompatUtils;
import processing.core.PApplet;

public class MainActivityextends AppCompatActivity {
  private PAppletsketch;
  
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    FrameLayout frame = new FrameLayout(this);
    frame.setId(CompatUtils.getUniqueViewId());
    setContentView(frame, new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, 
                                                     ViewGroup.LayoutParams.MATCH_PARENT));
    
    sketch = new sketch_proto_button_android();
    
    PFragment fragment = new PFragment(sketch);
    fragment.setView(frame, this);
  }
  
  @Override
  public void onRequestPermissionsResult(int requestCode, String permissions[], int[] grantResults) {
    if (sketch != null) {
      sketch.onRequestPermissionsResult(requestCode, permissions, grantResults);
    }
  }  
  
  @Override
  public void onNewIntent(Intent intent) {
    if (sketch != null) {
      sketch.onNewIntent(intent);
    }  
  }
  
  @Override
  public void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (sketch != null) {
      sketch.onActivityResult(requestCode, resultCode, data);
    }
  }  
  
  @Override
  public void onBackPressed() {
    if (sketch != null) {
      sketch.onBackPressed();
    }
  }
}

The special Sketch is:

package processing.test.sketch_proto_button_android;

import processing.core.*; 

public class sketch_proto_button_androidextends PApplet {

  /** PARAM NEEDED FOR THE BUTTON**/
int buttonX, buttonY;      // Position of button
int buttonSize= 90;     // Diameter of rect
int buttonColor;       //default color
int buttonHighlight;   //color once we on it
booleanbuttonOver= false; // We by definition outside the button

  /**VOID SETUP OF THE SKETCH**/
public void setup() {
  
  buttonColor= color(0); 
  buttonHighlight= color(255); 
  buttonX= width-width/2-buttonSize/2; //position X of button
  buttonY= height-height/2-buttonSize/2; //position Y
}

  /**VOID DRAW OF THE SKETCH**/
public void draw() {
  update(mouseX, mouseY);
  background(255);
  if (buttonOver) {
    fill(buttonHighlight);
  } else {
    fill(buttonColor);
  }
  stroke(0);
  rect(buttonX, buttonY, buttonSize, buttonSize);
}


  /**VOID UPDATE WHICH ALLOWS TO FOLLOWS IF BUTTON IS OVER OR NOT**/
public void update(int x, int y) {
if ( overButton(buttonX, buttonY, buttonSize, buttonSize) ) {
    buttonOver= true;
  }
else buttonOver= false;
}

/**BOOLEAN METHOD ALLOWING TO RETURN TRUE OR FALSE TO THE UPDATE VOID**/
public booleanoverButton(int x, int y, int width, int height)  {
  if (mouseX>= x &&mouseX<= x+width&&
      mouseY>= y &&mouseY<= y+height) {
    return true;
  } else {
    return false;
  }
}
}

Its main.xlm layout is

<fragment xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/fragment"
    android:name=".sketch_proto_button_android"
    tools:layout="@layout/fragment_main"
    android:layout_width="match_parent"
    android:layout_height="match_parent"

V. “Special Sketch Android Button”

Give functionalities to this button

The used Void keyReleased into software is as below, I need to base on it to transfer keyboard entries to custom made buttons.

/**STARTING VOID KEYRELEASED ie. what happened once we touch the keyboard**/
public void keyReleased() {
  if (key == 's' || key == 'S') saveFrame(timestamp()+"_##.png");

  /** Below is in comments as we do not use the camera for now**/
  /**if (key == 'c' || key == 'C') 
  {
   
    modeCamera = !modeCamera;
    if (modeCamera == false)
    {
      bg = loadImage("bg.png");
    }
   
  }**/
  
  switch (state)
  {
  case 0:
    // WAITING
    if (key == '1') 
    {
      mode = 1;
      state = 10;
    } else if (key == '2') 
    {
      mode = 2; 
      state = 1;
    } else if (key == '3') 
    {
      mode = 3; 
      state = 1;
    }
    break;

  case 1:
    // IF NEEDED, CHOICE OF PARAMS
    // WAITING
    if (key == '1') 
    {
      objectifValence= 25;
      objectifArousal= 25;
      state = 10;
    } else if (key == '3') 
    {
      objectifValence= 75;
      objectifArousal= 25;
      state = 10;
    } else if (key == '7') 
    {
      objectifValence= 25;
      objectifArousal= 75; 
      state = 10;
    } else if (key == '9') 
    {
      objectifValence= 75;
      objectifArousal= 75; 
      state = 10;
    }
    break;
    
  case 20:
  if (key ==' ') state = 30;
  break;
  }
}
/**END OF VOID KEY RELEASED **/

Hello, can you please edit your previous post, select each text block that contains Processing code and hit the </> button so this text blocks gets formatted properly in the forum? As it is right now, it is hard to read.

You wanted to do Android programming in IntelliJ. This is possible so I have read. You can also use Android Studio which it seems it is working for you.

You can use a keyboard in Android. You can explore examples provided by the Ketai library, which you can use by adding the library using the Contribution Manager in the Processing Development Editor(PDE). If you decide to explore buttons, you can implement your own button version in Processing Java and then, after the concept is implemented and tested (Faster doing it in Java), you can switch to Android mode in the PDE and it should work.

Then, you can export the sketch. Before you load the exported project in AS, become familiar with the file structure and the content of this exported project. If you have any questions, just asked.

You can open AS and then click export project. You search for the “exported” folder generated by the PDE when it was setup in Android mode. AS will loaded and it should run with minimal changes.

Now one thought is that you do not need to implement the buttons yourself. You can use Android Widgets available by the Android SDK in the PDE in android mode. I don’t think there is an example using buttons in the forum but you can see one using textView here. This is the official doc for TextView . Similarly, there is documentation for buttons. in short, you can use Android library in Processing Android Mode. However, you will not be able to run this version in Processing Java.

Kf

1 Like

Hi Kf,

Many thanks for your feedback !

I already use AS for several weeks.

It is easier to build your own button into the PDE and give them some actions than use PDE + AS widget…

I would delete all posts it will give confusion for everybody.

Regards,

Maxime