Skip to content

Commit

Permalink
Merge pull request #198 from SuhasDissa/full_screen_alarm
Browse files Browse the repository at this point in the history
feat: add full screen intent for alarm
  • Loading branch information
SuhasDissa authored Oct 31, 2023
2 parents 14078da + 4518758 commit 20b5543
Show file tree
Hide file tree
Showing 10 changed files with 433 additions and 94 deletions.
9 changes: 9 additions & 0 deletions .idea/inspectionProfiles/Project_Default.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

97 changes: 52 additions & 45 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,53 +1,60 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">
xmlns:tools="http://schemas.android.com/tools">

<uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="android.permission.POST_NOTIFICATIONS" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
<uses-permission android:name="android.permission.SCHEDULE_EXACT_ALARM" />
<uses-permission android:name="android.permission.USE_FULL_SCREEN_INTENT" />
<uses-permission android:name="android.permission.DISABLE_KEYGUARD" />

<application
android:name=".App"
android:allowBackup="true"
android:dataExtractionRules="@xml/data_extraction_rules"
android:fullBackupContent="@xml/backup_rules"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/Theme.ClockYou"
tools:targetApi="33">
android:name=".App"
android:allowBackup="true"
android:dataExtractionRules="@xml/data_extraction_rules"
android:fullBackupContent="@xml/backup_rules"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/Theme.ClockYou"
tools:targetApi="33">
<activity
android:name=".ui.MainActivity"
android:exported="true"
android:theme="@style/Theme.ClockYou">
android:name=".ui.MainActivity"
android:exported="true"
android:theme="@style/Theme.ClockYou">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>

<intent-filter>
<action android:name="android.intent.action.SET_ALARM" />
<action android:name="android.intent.action.SET_TIMER" />

<action android:name="android.intent.action.SHOW_ALARMS" />
<action android:name="android.intent.action.SHOW_TIMERS" />

<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity
android:name=".ui.AlarmActivity"
android:excludeFromRecents="true"
android:theme="@style/Theme.ClockYou"
android:launchMode="singleInstance"
android:taskAffinity=""
android:configChanges="orientation|keyboardHidden|keyboard|navigation" />

<receiver
android:name=".receivers.AlarmReceiver"
android:exported="false" />

android:name=".receivers.AlarmReceiver"
android:exported="false" />
<receiver
android:name=".receivers.BootReceiver"
android:directBootAware="true"
android:enabled="true"
android:exported="true">
android:name=".receivers.BootReceiver"
android:directBootAware="true"
android:enabled="true"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
</intent-filter>
Expand All @@ -57,50 +64,50 @@
</receiver>

<service
android:name=".services.StopwatchService"
android:exported="false" />

android:name=".services.StopwatchService"
android:exported="false" />
<service
android:name=".services.TimerService"
android:exported="false" />
<service
android:name=".services.TimerService"
android:exported="false" />
android:name=".services.AlarmService"
android:exported="false" />

<receiver
android:name=".widgets.DigitalClockWidget"
android:enabled="true"
android:exported="false">
android:name=".widgets.DigitalClockWidget"
android:enabled="true"
android:exported="false">
<intent-filter>
<action android:name="android.appwidget.action.APPWIDGET_UPDATE" />
</intent-filter>

<meta-data
android:name="android.appwidget.provider"
android:resource="@xml/digital_clock_widget" />
android:name="android.appwidget.provider"
android:resource="@xml/digital_clock_widget" />
</receiver>

<receiver
android:name=".widgets.VerticalClockWidget"
android:enabled="true"
android:exported="false">
android:name=".widgets.VerticalClockWidget"
android:enabled="true"
android:exported="false">
<intent-filter>
<action android:name="android.appwidget.action.APPWIDGET_UPDATE" />
</intent-filter>

<meta-data
android:name="android.appwidget.provider"
android:resource="@xml/vertical_clock_widget" />
android:name="android.appwidget.provider"
android:resource="@xml/vertical_clock_widget" />
</receiver>

<receiver
android:name=".widgets.AnalogClockWidget"
android:enabled="true"
android:exported="false">
android:name=".widgets.AnalogClockWidget"
android:enabled="true"
android:exported="false">
<intent-filter>
<action android:name="android.appwidget.action.APPWIDGET_UPDATE" />
</intent-filter>

<meta-data
android:name="android.appwidget.provider"
android:resource="@xml/analog_clock_widget" />
android:name="android.appwidget.provider"
android:resource="@xml/analog_clock_widget" />
</receiver>
</application>

Expand Down
55 changes: 7 additions & 48 deletions app/src/main/java/com/bnyro/clock/receivers/AlarmReceiver.kt
Original file line number Diff line number Diff line change
@@ -1,22 +1,14 @@
package com.bnyro.clock.receivers

import android.Manifest
import android.app.PendingIntent
import android.content.BroadcastReceiver
import android.content.Context
import android.content.Intent
import android.content.pm.PackageManager
import android.util.Log
import android.widget.Toast
import androidx.core.app.ActivityCompat
import androidx.core.app.NotificationCompat
import androidx.core.app.NotificationManagerCompat
import androidx.core.net.toUri
import com.bnyro.clock.R
import androidx.core.content.ContextCompat
import com.bnyro.clock.db.DatabaseHolder
import com.bnyro.clock.obj.Alarm
import com.bnyro.clock.ui.MainActivity
import com.bnyro.clock.util.*
import com.bnyro.clock.services.AlarmService
import com.bnyro.clock.util.AlarmHelper
import com.bnyro.clock.util.TimeHelper
import kotlinx.coroutines.runBlocking

class AlarmReceiver : BroadcastReceiver() {
Expand All @@ -30,45 +22,12 @@ class AlarmReceiver : BroadcastReceiver() {
val currentDay = TimeHelper.getCurrentWeekDay()

if (currentDay - 1 in alarm.days) {
Toast.makeText(context, context.getString(R.string.alarm), Toast.LENGTH_LONG).show()
showNotification(context, alarm)
val playAlarm = Intent(context, AlarmService::class.java)
playAlarm.putExtra(AlarmHelper.EXTRA_ID, id)
ContextCompat.startForegroundService(context, playAlarm)
}

// re-enqueue the alarm for the next day
AlarmHelper.enqueue(context, alarm)
}

private fun showNotification(context: Context, alarm: Alarm) {
val pendingIntent = PendingIntent.getActivity(
context,
0,
Intent(context, MainActivity::class.java).apply {
addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
},
PendingIntent.FLAG_UPDATE_CURRENT or PendingIntent.FLAG_IMMUTABLE
)

NotificationHelper.createAlarmNotificationChannel(context, alarm)

val builder = NotificationCompat.Builder(context, NotificationHelper.ALARM_CHANNEL)
.setSmallIcon(R.drawable.ic_notification)
.setContentTitle(alarm.label ?: context.getString(R.string.alarm))
.setAutoCancel(true)
.setPriority(NotificationCompat.PRIORITY_HIGH)
.setCategory(NotificationCompat.CATEGORY_ALARM)
.setVibrate(if (alarm.vibrate) NotificationHelper.vibrationPattern else null)
.setFullScreenIntent(pendingIntent, true)
.setSound(alarm.soundUri?.toUri() ?: RingtoneHelper.getDefault(context))
val notification = builder.build().apply {
flags = NotificationCompat.FLAG_INSISTENT
}

if (ActivityCompat.checkSelfPermission(
context,
Manifest.permission.POST_NOTIFICATIONS
) == PackageManager.PERMISSION_GRANTED
) {
NotificationManagerCompat.from(context).notify(alarm.id.toInt(), notification)
}
}
}
Loading

0 comments on commit 20b5543

Please sign in to comment.