diff --git a/android/app/src/main/AndroidManifest.xml b/android/app/src/main/AndroidManifest.xml
index e87e005..83a4564 100644
--- a/android/app/src/main/AndroidManifest.xml
+++ b/android/app/src/main/AndroidManifest.xml
@@ -28,6 +28,8 @@
+
+
diff --git a/android/app/src/main/ic_launcher-playstore.png b/android/app/src/main/ic_launcher-playstore.png
new file mode 100644
index 0000000..baa20b1
Binary files /dev/null and b/android/app/src/main/ic_launcher-playstore.png differ
diff --git a/android/app/src/main/java/com/massive/AlarmActivity.java b/android/app/src/main/java/com/massive/AlarmActivity.java
new file mode 100644
index 0000000..d346f60
--- /dev/null
+++ b/android/app/src/main/java/com/massive/AlarmActivity.java
@@ -0,0 +1,33 @@
+package com.massive;
+
+import android.app.Activity;
+import android.app.PendingIntent;
+import android.content.BroadcastReceiver;
+import android.content.Context;
+import android.content.Intent;
+import android.os.Bundle;
+import android.util.AttributeSet;
+import android.util.Log;
+import android.view.View;
+
+import androidx.annotation.NonNull;
+import androidx.annotation.Nullable;
+
+public class AlarmActivity extends Activity {
+ @Override
+ protected void onCreate(@Nullable Bundle savedInstanceState) {
+ Log.d("AlarmActivity", "Call to AlarmActivity");
+ super.onCreate(savedInstanceState);
+ Context context = getApplicationContext();
+ context.stopService(new Intent(context, AlarmService.class));
+ Intent intent = new Intent(context, MainActivity.class);
+ intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
+ context.startActivity(intent);
+ }
+
+ @Nullable
+ @Override
+ public View onCreateView(@NonNull String name, @NonNull Context context, @NonNull AttributeSet attrs) {
+ return super.onCreateView(name, context, attrs);
+ }
+}
diff --git a/android/app/src/main/java/com/massive/AlarmModule.java b/android/app/src/main/java/com/massive/AlarmModule.java
index 600168d..8c13083 100644
--- a/android/app/src/main/java/com/massive/AlarmModule.java
+++ b/android/app/src/main/java/com/massive/AlarmModule.java
@@ -62,4 +62,12 @@ public class AlarmModule extends ReactContextBaseJavaModule {
AlarmManager.AlarmClockInfo info = new AlarmManager.AlarmClockInfo(System.currentTimeMillis() + milliseconds, pendingIntent);
alarmManager.setAlarmClock(info, pendingIntent);
}
+
+ @ReactMethod(isBlockingSynchronousMethod = true)
+ public void stop() {
+ Log.d("AlarmModule", "Request to stop timer.");
+ Intent intent = new Intent(getReactApplicationContext(), MyBroadcastReceiver.class);
+ intent.setAction("stop");
+ getReactApplicationContext().startActivity(intent);
+ }
}
diff --git a/android/app/src/main/java/com/massive/AlarmService.java b/android/app/src/main/java/com/massive/AlarmService.java
new file mode 100644
index 0000000..188ec92
--- /dev/null
+++ b/android/app/src/main/java/com/massive/AlarmService.java
@@ -0,0 +1,60 @@
+package com.massive;
+import android.app.Service;
+import android.content.Context;
+import android.content.Intent;
+import android.media.AudioAttributes;
+import android.media.MediaPlayer;
+import android.os.Build;
+import android.os.IBinder;
+import android.os.VibrationEffect;
+import android.os.Vibrator;
+import android.util.Log;
+
+import androidx.annotation.Nullable;
+import androidx.annotation.RequiresApi;
+
+public class AlarmService extends Service implements MediaPlayer.OnPreparedListener {
+ private static final String ACTION_PLAY = "com.example.action.PLAY";
+ MediaPlayer mediaPlayer = null;
+ private Vibrator vibrator;
+
+ @RequiresApi(api = Build.VERSION_CODES.O)
+ public int onStartCommand(Intent intent, int flags, int startId) {
+ Log.d("AlarmService", "Starting alarm: " + intent.getAction());
+ mediaPlayer = MediaPlayer.create(getApplicationContext(), R.raw.argon);
+ mediaPlayer.start();
+ mediaPlayer.setOnCompletionListener(mediaPlayer -> vibrator.cancel());
+ long[] pattern = {0, 300, 1300, 300, 1300, 300};
+ vibrator = (Vibrator) getApplicationContext().getSystemService(Context.VIBRATOR_SERVICE);
+ AudioAttributes audioAttributes = new AudioAttributes.Builder()
+ .setContentType(AudioAttributes.CONTENT_TYPE_SONIFICATION)
+ .setUsage(AudioAttributes.USAGE_ALARM)
+ .build();
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
+ vibrator.vibrate(VibrationEffect.createWaveform(pattern, 1), audioAttributes);
+ } else {
+ vibrator.vibrate(pattern, 1, audioAttributes);
+ }
+ return START_STICKY;
+ }
+
+ @Nullable
+ @Override
+ public IBinder onBind(Intent intent) {
+ return null;
+ }
+
+ /** Called when MediaPlayer is ready */
+ public void onPrepared(MediaPlayer player) {
+ player.start();
+ }
+
+
+
+ @Override
+ public void onDestroy() {
+ super.onDestroy();
+ if (mediaPlayer != null) mediaPlayer.release();
+ if (vibrator != null) vibrator.cancel();
+ }
+}
diff --git a/android/app/src/main/java/com/massive/MyBroadcastReceiver.java b/android/app/src/main/java/com/massive/MyBroadcastReceiver.java
index 33cc1f8..5fcc544 100644
--- a/android/app/src/main/java/com/massive/MyBroadcastReceiver.java
+++ b/android/app/src/main/java/com/massive/MyBroadcastReceiver.java
@@ -6,12 +6,10 @@ import android.app.PendingIntent;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
-import android.media.MediaPlayer;
import android.os.Build;
import android.os.VibrationEffect;
import android.os.Vibrator;
import android.util.Log;
-import android.widget.Toast;
import androidx.annotation.RequiresApi;
import androidx.core.app.NotificationCompat;
@@ -21,39 +19,12 @@ public class MyBroadcastReceiver extends BroadcastReceiver {
private static final String CHANNEL_ID = "MassiveAlarm";
private static final int ALARM_ID = 59;
- @RequiresApi(api = Build.VERSION_CODES.O)
+ @RequiresApi(api = Build.VERSION_CODES.M)
@Override
public void onReceive(Context context, Intent intent) {
Log.d("MyBroadcastReceiver", "Received intent for BroadcastReceiver.");
- long[] pattern = {0, 300, 200, 300, 200};
- int[] amplitudes = {VibrationEffect.DEFAULT_AMPLITUDE, VibrationEffect.DEFAULT_AMPLITUDE, VibrationEffect.DEFAULT_AMPLITUDE, VibrationEffect.DEFAULT_AMPLITUDE, VibrationEffect.DEFAULT_AMPLITUDE};
- Vibrator vibrator = (Vibrator) context.getSystemService(Context.VIBRATOR_SERVICE);
- if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
- vibrator.vibrate(VibrationEffect.createWaveform(pattern, amplitudes, 0));
- } else {
- //deprecated in API 26
- vibrator.vibrate(500);
- }
- createNotificationChannel(context);
-
- Intent contentIntent = new Intent(context.getApplicationContext(), MainActivity.class);
- PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, contentIntent, PendingIntent.FLAG_IMMUTABLE);
-
- NotificationCompat.Builder builder = new NotificationCompat.Builder(context, CHANNEL_ID)
- .setSmallIcon(R.drawable.rn_edit_text_material)
- .setContentTitle("Rest")
- .setContentText("Break times over!")
- .setContentIntent(pendingIntent)
- .setAutoCancel(true)
- .setCategory(NotificationCompat.CATEGORY_ALARM)
- .setPriority(NotificationCompat.PRIORITY_HIGH);
- NotificationManagerCompat notificationManager = NotificationManagerCompat.from(context);
- notificationManager.notify(ALARM_ID, builder.build());
- MediaPlayer mediaPlayer = MediaPlayer.create(context, R.raw.argon);
- mediaPlayer.start();
- }
-
- private void createNotificationChannel(Context context) {
+ String action = intent.getAction();
+ Log.d("MyBroadcastReceiver", "Action: " + action);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
int importance = NotificationManager.IMPORTANCE_HIGH;
NotificationChannel channel = new NotificationChannel(CHANNEL_ID, CHANNEL_ID, importance);
@@ -61,6 +32,24 @@ public class MyBroadcastReceiver extends BroadcastReceiver {
NotificationManager notificationManager = context.getSystemService(NotificationManager.class);
notificationManager.createNotificationChannel(channel);
}
+ context.startService(new Intent(context, AlarmService.class));
+ Intent contentIntent = new Intent(context.getApplicationContext(), AlarmActivity.class);
+ PendingIntent pendingContent = PendingIntent.getActivity(context, 0, contentIntent, PendingIntent.FLAG_IMMUTABLE);
+ long[] pattern = {0, 100, 1000, 200, 2000};
+ NotificationCompat.Builder builder = new NotificationCompat.Builder(context, CHANNEL_ID)
+ .setSmallIcon(R.drawable.rn_edit_text_material)
+ .setContentTitle("Rest")
+ .setContentText("Break times over!")
+ .setContentIntent(pendingContent)
+ .setAutoCancel(true)
+ .setVibrate(pattern)
+ .setCategory(NotificationCompat.CATEGORY_ALARM)
+ .setPriority(NotificationCompat.PRIORITY_HIGH);
+ NotificationManagerCompat notificationManager = NotificationManagerCompat.from(context);
+ notificationManager.notify(ALARM_ID, builder.build());
+ }
+
+ private void vibrate(Context context) {
}
}
diff --git a/android/app/src/main/res/drawable/ic_launcher_background.xml b/android/app/src/main/res/drawable/ic_launcher_background.xml
new file mode 100644
index 0000000..ca3826a
--- /dev/null
+++ b/android/app/src/main/res/drawable/ic_launcher_background.xml
@@ -0,0 +1,74 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/android/app/src/main/res/drawable/ic_launcher_foreground.xml b/android/app/src/main/res/drawable/ic_launcher_foreground.xml
new file mode 100644
index 0000000..6c5287b
--- /dev/null
+++ b/android/app/src/main/res/drawable/ic_launcher_foreground.xml
@@ -0,0 +1,15 @@
+
+
+
+
+
diff --git a/android/app/src/main/res/mipmap-hdpi/ic_launcher.png b/android/app/src/main/res/mipmap-hdpi/ic_launcher.png
index a2f5908..5a66713 100644
Binary files a/android/app/src/main/res/mipmap-hdpi/ic_launcher.png and b/android/app/src/main/res/mipmap-hdpi/ic_launcher.png differ
diff --git a/android/app/src/main/res/mipmap-hdpi/ic_launcher_round.png b/android/app/src/main/res/mipmap-hdpi/ic_launcher_round.png
index 1b52399..58522e8 100644
Binary files a/android/app/src/main/res/mipmap-hdpi/ic_launcher_round.png and b/android/app/src/main/res/mipmap-hdpi/ic_launcher_round.png differ
diff --git a/android/app/src/main/res/mipmap-mdpi/ic_launcher.png b/android/app/src/main/res/mipmap-mdpi/ic_launcher.png
index ff10afd..43922ed 100644
Binary files a/android/app/src/main/res/mipmap-mdpi/ic_launcher.png and b/android/app/src/main/res/mipmap-mdpi/ic_launcher.png differ
diff --git a/android/app/src/main/res/mipmap-mdpi/ic_launcher_round.png b/android/app/src/main/res/mipmap-mdpi/ic_launcher_round.png
index 115a4c7..e0b20d1 100644
Binary files a/android/app/src/main/res/mipmap-mdpi/ic_launcher_round.png and b/android/app/src/main/res/mipmap-mdpi/ic_launcher_round.png differ
diff --git a/android/app/src/main/res/mipmap-xhdpi/ic_launcher.png b/android/app/src/main/res/mipmap-xhdpi/ic_launcher.png
index dcd3cd8..a526917 100644
Binary files a/android/app/src/main/res/mipmap-xhdpi/ic_launcher.png and b/android/app/src/main/res/mipmap-xhdpi/ic_launcher.png differ
diff --git a/android/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png b/android/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png
index 459ca60..0bb803a 100644
Binary files a/android/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png and b/android/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png differ
diff --git a/android/app/src/main/res/mipmap-xxhdpi/ic_launcher.png b/android/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
index 8ca12fe..2bc028f 100644
Binary files a/android/app/src/main/res/mipmap-xxhdpi/ic_launcher.png and b/android/app/src/main/res/mipmap-xxhdpi/ic_launcher.png differ
diff --git a/android/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png b/android/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png
index 8e19b41..147812f 100644
Binary files a/android/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png and b/android/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png differ
diff --git a/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png b/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
index b824ebd..49030ea 100644
Binary files a/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png and b/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png differ
diff --git a/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png b/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png
index 4c19a13..c08a0f2 100644
Binary files a/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png and b/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png differ
diff --git a/android/app/src/main/res/values/ic_launcher_background.xml b/android/app/src/main/res/values/ic_launcher_background.xml
new file mode 100644
index 0000000..97e745e
--- /dev/null
+++ b/android/app/src/main/res/values/ic_launcher_background.xml
@@ -0,0 +1,4 @@
+
+
+ #1D1F21
+
\ No newline at end of file