show an activity over the lockscreen at Timer notification, if screen is off
This commit is contained in:
parent
25fd5c5098
commit
472fc90d22
6 changed files with 54 additions and 7 deletions
|
@ -40,6 +40,8 @@
|
|||
android:name=".activities.MainActivity"
|
||||
android:launchMode="singleTask"/>
|
||||
|
||||
<activity android:name=".activities.ReminderActivity"/>
|
||||
|
||||
<activity
|
||||
android:name=".activities.SettingsActivity"
|
||||
android:label="@string/settings"
|
||||
|
|
|
@ -0,0 +1,14 @@
|
|||
package com.simplemobiletools.clock.activities
|
||||
|
||||
import android.os.Bundle
|
||||
import com.simplemobiletools.clock.R
|
||||
import com.simplemobiletools.clock.extensions.showOverLockscreen
|
||||
|
||||
class ReminderActivity : SimpleActivity() {
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
setContentView(R.layout.activity_reminder)
|
||||
showOverLockscreen()
|
||||
}
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
package com.simplemobiletools.clock.extensions
|
||||
|
||||
import android.app.Activity
|
||||
import android.view.WindowManager
|
||||
|
||||
fun Activity.showOverLockscreen() {
|
||||
window.addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON or
|
||||
WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD or
|
||||
WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED or
|
||||
WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON)
|
||||
}
|
|
@ -9,6 +9,7 @@ import android.content.ComponentName
|
|||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.media.RingtoneManager
|
||||
import android.os.PowerManager
|
||||
import android.provider.Settings
|
||||
import android.text.SpannableString
|
||||
import android.text.style.RelativeSizeSpan
|
||||
|
@ -217,3 +218,5 @@ fun Context.rescheduleEnabledAlarms() {
|
|||
scheduleNextAlarm(it, false)
|
||||
}
|
||||
}
|
||||
|
||||
fun Context.isScreenOn() = (getSystemService(Context.POWER_SERVICE) as PowerManager).isScreenOn
|
||||
|
|
|
@ -19,6 +19,7 @@ import android.view.LayoutInflater
|
|||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import com.simplemobiletools.clock.R
|
||||
import com.simplemobiletools.clock.activities.ReminderActivity
|
||||
import com.simplemobiletools.clock.activities.SimpleActivity
|
||||
import com.simplemobiletools.clock.activities.SplashActivity
|
||||
import com.simplemobiletools.clock.dialogs.MyTimePickerDialogDialog
|
||||
|
@ -26,6 +27,7 @@ import com.simplemobiletools.clock.dialogs.SelectAlarmSoundDialog
|
|||
import com.simplemobiletools.clock.extensions.colorLeftDrawable
|
||||
import com.simplemobiletools.clock.extensions.config
|
||||
import com.simplemobiletools.clock.extensions.hideNotification
|
||||
import com.simplemobiletools.clock.extensions.isScreenOn
|
||||
import com.simplemobiletools.clock.helpers.OPEN_TAB
|
||||
import com.simplemobiletools.clock.helpers.TAB_TIMER
|
||||
import com.simplemobiletools.clock.helpers.TIMER_NOTIF_ID
|
||||
|
@ -35,6 +37,7 @@ import com.simplemobiletools.commons.helpers.isLollipopPlus
|
|||
import com.simplemobiletools.commons.helpers.isOreoPlus
|
||||
import kotlinx.android.synthetic.main.fragment_timer.view.*
|
||||
|
||||
|
||||
class TimerFragment : Fragment() {
|
||||
private val UPDATE_INTERVAL = 1000L
|
||||
|
||||
|
@ -185,14 +188,20 @@ class TimerFragment : Fragment() {
|
|||
|
||||
view.timer_time.text = formattedDuration
|
||||
if (diff == 0) {
|
||||
val pendingIntent = getOpenAppIntent(context!!)
|
||||
val notification = getNotification(context!!, pendingIntent)
|
||||
val notificationManager = context!!.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
|
||||
notificationManager.notify(TIMER_NOTIF_ID, notification)
|
||||
if (context?.isScreenOn() == true) {
|
||||
val pendingIntent = getOpenAppIntent(context!!)
|
||||
val notification = getNotification(context!!, pendingIntent)
|
||||
val notificationManager = context!!.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
|
||||
notificationManager.notify(TIMER_NOTIF_ID, notification)
|
||||
|
||||
Handler().postDelayed({
|
||||
hideTimerNotification()
|
||||
}, context?.config!!.timerMaxReminderSecs * 1000L)
|
||||
Handler().postDelayed({
|
||||
hideTimerNotification()
|
||||
}, context?.config!!.timerMaxReminderSecs * 1000L)
|
||||
} else {
|
||||
Intent(context, ReminderActivity::class.java).apply {
|
||||
activity?.startActivity(this)
|
||||
}
|
||||
}
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
|
8
app/src/main/res/layout/activity_reminder.xml
Normal file
8
app/src/main/res/layout/activity_reminder.xml
Normal file
|
@ -0,0 +1,8 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<RelativeLayout
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:id="@+id/reminder_holder"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
|
||||
</RelativeLayout>
|
Loading…
Reference in a new issue