Location of my sketch (AndroidStudio)

I am a student and I don’t have any experience in Java/Processing. For a project I am making a Fitness Tracker. On the screen, I would like to to show data from the tracker (e.g. number of steps) and in the bottom right corner I want to show a sphere, which uses the quaternions from the tracker to rotate.

To draw the sphere, I used Processing. However, I am having problems chosing the location of my sketch. How can I put my sketch in the bottom right corner?

My sketch class (the sphere):

package processing.test.voorbeeld_sfeer;

import processing.core.*; 
import processing.data.*; 
import processing.event.*; 
import processing.opengl.*; 

import toxi.geom.*; 
import toxi.geom.mesh.*; 
import toxi.math.waves.*; 
import toxi.processing.*; 
//import processing.serial.*;

import java.util.HashMap; 
import java.util.ArrayList; 
import java.io.File; 
import java.io.BufferedReader; 
import java.io.PrintWriter; 
import java.io.InputStream; 
import java.io.OutputStream; 
import java.io.IOException; 

public class voorbeeld_sfeer extends PApplet {
    
ToxiclibsSupport gfx;

public void setup() {
  
  gfx=new ToxiclibsSupport(this);
  
  background(255);
  noStroke();
  fill(300,300,300);
}

public void draw() {
  
  Quaternion RotQ = new Quaternion(1,0,0,0);
  float qMatrix[] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
  PMatrix M1 = getMatrix();
  
  RotQ = new Quaternion(0.4f, 0.5f, 0.7f,0.316227766f);
  
  RotQ.toMatrix4x4().toFloatArray(qMatrix);
  
  M1.set(
      qMatrix[0], 
      qMatrix[1], 
      qMatrix[2], 
      qMatrix[3], 
      qMatrix[4], 
      qMatrix[5], 
      qMatrix[6], 
      qMatrix[7], 
      qMatrix[8], 
      qMatrix[9], 
      qMatrix[10], 
      qMatrix[11], 
      qMatrix[12], 
      qMatrix[13], 
      qMatrix[14], 
      qMatrix[15]
      );
      
      AABB cube;
      
      background(255);

      // Set some mood lighting
      ambientLight(128, 128, 128);
      directionalLight(128, 128, 128, 0, 0, 1);
      lightFalloff(1, 0, 0);
      lightSpecular(0, 0, 0);

      // Get to the middle of the screen
      translate(width/2,height/2,0);
      //translate(width/2,0,0);

      // Do some rotates to get oriented "behind" the device
      rotateX(-PI/2);

      // Apply the Matrix that we generated from our IMU Quaternion
      applyMatrix(M1);

      // Draw the Cube from a 3D Bounding Box
      //cube=new AABB(new Vec3D(0,0,0),new Vec3D(100,100,100));
      //gfx.box(cube);
      
      directionalLight(0, 255, 0, 0, -1, 0);
      
      sphere(100);
}
  
  public void settings() {  size(400,400,P3D); }
}

Main class:

package processing.test.voorbeeld_sfeer;

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

Main xml:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/drawer_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="tutorials.androidstudio.fragmentsv3.MainActivity" >

    <FrameLayout
        android:id="@+id/container"
        android:layout_width="177dp"
        android:layout_height="162dp"
        android:layout_alignParentTop="true"
        android:layout_alignParentEnd="true"
        android:layout_alignParentRight="true"
        android:layout_marginTop="521dp"
        android:layout_marginEnd="16dp"
        android:layout_marginRight="16dp" />

</RelativeLayout>

Maybe I can somehow link my sketch to this FrameLayout? How can I do this?

1 Like

I have found the solution to my problem myself.

1 Like

@bert_s ===
can yu exlain (for others) what you have done?
As for me the most simple way is to change the layout (frameLayout) in the main activity to WRAP_CONTENT then get it in the sketch and setX + setY (using displayWidth and displayHeight in order to avoid hardcoded values); it works…

1 Like
 @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.tracker);

        sketch = new sketch_sphere();

        FrameLayout frame1 = new FrameLayout(this);
        frame1.setId(R.id.sketch_sphere);

        PFragment fragment = new PFragment(sketch);
        fragment.setView(frame1, this);
    }

This way I made it link to the FrameLayout I made in the xml file. Somehow they didn’t connect with each other if I did it the other way.
(The names are different, since this code comes from my actual project: sketch_sphere is the ID of the FrameLayout in my xml file, which you can give a certain position on the screen).

So basically I made a FrameLayout in the xml file and this way, I put my sketch in this FrameLayout. And obviously, in the xml file you can change the position of the FrameLayout.

1 Like

@bert_s ===
Yes, that will work; yet i think that using hardcoded values is not good with android because display metrics can be very different from yours… Also, i dont understand why you are creating another layout, knowing that the standard P5 main has already created one that you can get and modify…But why not?

1 Like

Even I am also looking out for the same.I want to include with it that if any sort of assistance is required for handyman services which includes carpentry,electrical,plumbing,painting,masonry can directly contact with the most reliable maintenance company in dubai who provides 100% assistance with support across the globe for more than a decade.

@shanaya78 ===
ok, but what is more precisely your problem & what have you done till now?