Hi,
And sorry for not replying sooner i got stuck on other stuff but now that we are in covid-lockdown i have a chance to return to it.
I decided to approach this differently by importing the processing-core into Android Studio and creating a couple of test Apps.
I started by creating a simple alarm manger App that fires an alarm every minute (user settable) and this works fine. I then created an App that makes use of the processing-core library (imported the library as a jar dependency into android studio) and this also works.
The next step was to amalgamate the above and create an App that fires a sketch class from the broadcast receiver that includes some simple processing code but i am unsure as to how i do this.
My attempt at doing this is shown below. The only class that creates errors is the broadcast receiver class which creates errors related to frameLayout, setContentView and Fragment.setView.
I am a bit stuck, so any help with this is much appreciated.
Cheers.
All classes and XML file are shown below:
MainActivity.java
public class MainActivity extends AppCompatActivity {
private PApplet sketch;
Button start;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
start= findViewById(R.id.button);
start.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
startAlert();
}
});
}
public void startAlert(){
EditText text = findViewById(R.id.time);
int i = Integer.parseInt(text.getText().toString());
Intent intent = new Intent(this, MyBroadcastReceiver.class);
PendingIntent pendingIntent = PendingIntent.getBroadcast(
this.getApplicationContext(), 234324243, intent, 0);
AlarmManager alarmManager = (AlarmManager) getSystemService(ALARM_SERVICE);
alarmManager.set(AlarmManager.RTC_WAKEUP, System.currentTimeMillis()
+ (i * 1000), pendingIntent);
Toast.makeText(this, "Alarm set in " + i + " seconds",Toast.LENGTH_LONG).show();
}
}
Activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.alrmmngrplusprocsktch.MainActivity">
<Button
android:id="@+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Start"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_marginBottom="103dp" />
<EditText
android:id="@+id/time"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="22dp"
android:ems="10" />
</RelativeLayout>
MyBroadcastReceiver.java
public class MyBroadcastReceiver extends BroadcastReceiver {
private PApplet sketch;
@Override
public void onReceive(Context context, Intent intent) {
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);
}
}
Sketch.java
import processing.core.PApplet;
public class Sketch extends PApplet
{
int x = 0;
double h, h2;
public void settings()
{
fullScreen();
}
public void setup()
{
background(0);
noStroke();
fill(102);
}
public void draw()
{
//background(0);
h = height*0.2;
h2 = height*0.6;
rect(x, (float)h, 1, (float)h2);
x = x + 2;
}
}