Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

Make Your Sketch app using PApplet in Android Studio

Following are the Sketch code, for example:


package my.androidworld.com;

import processing.core.PApplet;

public class Sketch extends PApplet {
  public void settings() {
    size(500, 500);
  }

  public void setup() { }

  public void draw() {
    if (mousePressed) {
      ellipse(mouseX, mouseY, 70, 70);
    }
  }
}
//Initialize the sketch in the main activity:


package my.androidworld.com;

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 MainActivity extends AppCompatActivity {
  private PApplet sketch;

  @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();
    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);
    }
  }
}

// Finally, create a simple layout for the main activity:


    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/drawer_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity" >

            android:layout_width="match_parent"
        android:layout_height="match_parent" />

   


This post first appeared on Android Technology, please read the originial post: here

Share the post

Make Your Sketch app using PApplet in Android Studio

×

Subscribe to Android Technology

Get updates delivered right to your inbox!

Thank you for your subscription

×