We are about to switch to a new forum software. Until then we have removed the registration on this forum.
I am running Processing Sketches on Android Studio. Did it through exporting the project from Processing to Android, checking all the libraries. Then started a new Android Project, added these libraries, and that's it.. Now the question is how to project them in a visually appealing way on the activity layout.. For instance, how can I control how big the area is a Processing Sketch is displayed on. Another question is how to load a number of Processing Sketches in different places on the Layout.
Does anyone have experience on this, can share some code, point me to some sketches...?
THANKS!!!!
public class MainActivity extends AppCompatActivity {
private PApplet sketch;
private PApplet secondsketch;
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 weatherBrussels();
PFragment fragment = new PFragment(sketch);
fragment.setView(frame, this);
}
public void onRequestPermissionsResult(int requestCode,
String permissions[],
int[] grantResults) {
if (sketch != null) {
sketch.onRequestPermissionsResult(requestCode, permissions, grantResults);
}
}
public void onNewIntent(Intent intent) {
if (sketch != null) {
sketch.onNewIntent(intent);
}
}
}
Answers
I have tried the following to load two Processing sketches underneath each other..
Layout file: two FrameLayouts, each for one Processing Sketch..
And the MainActivity..
I do not get an error message, but the Android Studio Project does not work either.
Any ideas?
@nvwingh===
So I can just treat PFragments as Fragments then, ok.. Since I want my sketches to be loaded when the page is loaded, just in different views, can I also use other View types, like CardView or ListView? Or with Processing sketches, am I obliged to use the PFragment (Fragment) approach?
Thanks for your help!
@nvwingh===
with P5 you are in a fragment; but you can add all kind of android views to this fragment: i have put in the forum many examples for that: textView, videoView; not tried with listView but it s probably the same. As for adding (not replacing) another fragments i dont think that it is possible, except perhaps using nested fragments: the first one is created by the main activity and it contains your first sketch; when it is created it creates a second fragment with another sketch using a fragment transaction with getChildFragmentManager(): i have not tested that but logically it could work...I ' ll have a look.
sounds great, where can I find these examples? I have checked your profile, but since you have over 1,5K posts it is a bit hard to find them.. :-)
I have found an answer to my questions.. Answer lie in setting a Static ID to my FrameLayouts and then losing the "SetContentView()" method..