size of sketch in an processing 3 android app

edited December 2016 in Android Mode

Hi,

I'm trying to port a processing 2 android application to a processing 3 android application using android studio. So far I've been able to launch the app on my phone. However, the original sketch only appears within a 100 x 100 pixel square in the center of the screen (it should cover the whole screen).

This is what I got so far.

res/layout/activity_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/container"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="0dp"
    android:paddingLeft="0dp"
    android:paddingRight="0dp"
    android:paddingTop="0dp"
    tools:context=".MainActivity">
    <FrameLayout android:id="@+id/mysketch"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_alignParentBottom="true"
        android:layout_alignParentTop="true"
        android:layout_alignParentRight="true"
        android:layout_alignParentEnd="true"
        android:layout_marginBottom="0dp"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true" />
</RelativeLayout>

java/test/mysketch/MainActivity.java:

package test.mysketch;

import android.app.Activity;
import android.app.Fragment;
import android.app.FragmentManager;
import android.os.Bundle;
import android.view.WindowManager;

public class MainActivity extends Activity {
    private static final String TAG = "MainActivity";

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
        FragmentManager fragmentManager = getFragmentManager();
        Fragment fragment = new MySketch();
        fragmentManager.beginTransaction()
                .replace(R.id.mysketch, fragment)
                .commit();
    }
}

java/test/mysketch/MySketch.java:

package test.mysketch;

public class MySketch extends PApplet {
    static int width, height;
    private static String TAG = "MySketch";

    public void setup() {
        View view = this.getView();
        if (view != null) {
            width = view.getWidth();
            height = view.getHeight();
        }
        noStroke();
        fill(0);
    }

    public void draw() {
        // posted result seems to correctly reflect available screen width/height,
        // yet, sketch appears to be 100 x 100 pixels big 
        Log.d(TAG, "dimensions: " + width + ", " + height);
    }
}

Any clues?

Thanks very much,

Stefan

Answers

  • @5tefan===

    i don't understand; the code you put is somewhat for P3 (you are creating a fragment) and for P2 (you are extending Activity, not PApplet) if you want to work with P3 you put fullscreen in your void settings() or you use the standard native android way with flag fullscreen, before setContentview()::

    getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,        
                         WindowManager.LayoutParams.FLAG_FULLSCREEN);
    
  • Oh, damn, the code that I gave for MySketch.java was incorrect. Really I am extending PApplet, not Activity there. Your hint about calling setFlags brought me somewhat further, but didn't yet solve the problem: The default Android top bar (don't know what it's called right now) has disappeared (I can get it back by sliding down the screen), yet my original sketch still appears in a 100 x 100 pixel in the center of the screen.

  • @5tefan can you correct your code above so that it shows the code that is actually giving you the problem?

  • @5tefan===

    without seeing the code i cannot go further...

  • edited December 2016

    I have corrected my code (extend PApplet instead of Activity. I can't correct that <a href="/two/profile/Override">@Override</a> - that should of course just be @Override). The whole code of my app is defined in 7 classes which would probably be a bit to big to be posted here (I guess). Anyway, I thought I might have done something obviously wrong, so I posted this stripped down example. It may well be that there's something else in my code that causes the problem. Probably I'm gonna start again from scratch, starting with something simple. Maybe it's now time to really get into Android coding, using xml instead of pure java to create the GUI and position its elements (I wouldn't mind to get rid of some jaava code...).

    Thanks anyway! I'll get back if more processing related question come up.

  • edited December 2016

    @5tefan=== "obviously" you dont understand the difference between p52x && p53X: you have NOT to modify your main activity; when it launches it creates a new one and the fragment with your class extending Applet: here is the moment(fragment) to modify what you want...though, sometimes it is not possible! in order to understand create some new sketch with P3X...put an image or a text and see what happens... you cannot "adapt" in your way.... btx= what is new "VideoOSC()"?

  • Ok, "obviously" you did not get me... what made you think I changed my main activity? I added that setFlags portion to MainActivity.java (where else should have been added?). That's all. I haven't changed anything in my (old) P52x code. Adding the setFlags portion did neither fix the problem nor did it cause any problems. VideOSC() resp. videosc is a left over from my original p52x code - sorry. Should have read MySketch resp. mysketch. I think it's pretty clear how things are supposed to work. Yet I'll have to investigate my problem in depth.

  • Answer ✓

    @5Stefan=== try what i have said; forget your code P2; create a new sketch using a foo code, like this:

            void settings(){
              fullScreen();
            }
    
            void setup(){
              orientation (PORTRAIT);
              img = loadImage("myimage.png");
    
    
              background(255,0,0);
            }
    
            void draw(){
             image(img, 0,0); 
            }
    

    then, save it (of course your image is in the data folder); then export it as an android project then look at the created folders: in src you can find 2 files; one of them is called main activity and was created by P5 3x you can compare it with your own main activity and see what are the differences! That s why i have told to leave your "old" main activity: since the beginning you are in a fragment and have to code everything knowing that...

  • Cooool... thanks a lot @akenaton. In fact I was not sure where to put that settings() definition (didn't know about that from my p52x experience). Now I got my original sketch (that app that I wrote using p52x) running in fullscreen. Thanks a ton!

Sign In or Register to comment.