-
-
Notifications
You must be signed in to change notification settings - Fork 238
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
catch and show exceptions thrown at querying alarms
- Loading branch information
Showing
2 changed files
with
31 additions
and
24 deletions.
There are no files selected for viewing
31 changes: 31 additions & 0 deletions
31
app/src/main/kotlin/com/simplemobiletools/clock/extensions/Activity.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,42 @@ | ||
package com.simplemobiletools.clock.extensions | ||
|
||
import android.app.Activity | ||
import android.media.RingtoneManager | ||
import android.view.WindowManager | ||
import com.simplemobiletools.clock.models.AlarmSound | ||
import com.simplemobiletools.commons.extensions.showErrorToast | ||
import java.util.* | ||
|
||
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) | ||
} | ||
|
||
fun Activity.getAlarms(): ArrayList<AlarmSound> { | ||
val alarms = ArrayList<AlarmSound>() | ||
val manager = RingtoneManager(this) | ||
manager.setType(RingtoneManager.TYPE_ALARM) | ||
|
||
try { | ||
val cursor = manager.cursor | ||
val defaultAlarm = AlarmSound(getDefaultAlarmTitle(), getDefaultAlarmUri().toString()) | ||
alarms.add(defaultAlarm) | ||
|
||
while (cursor.moveToNext()) { | ||
val title = cursor.getString(RingtoneManager.TITLE_COLUMN_INDEX) | ||
var uri = cursor.getString(RingtoneManager.URI_COLUMN_INDEX) | ||
val id = cursor.getString(RingtoneManager.ID_COLUMN_INDEX) | ||
if (!uri.endsWith(id)) { | ||
uri += "/$id" | ||
} | ||
val alarmSound = AlarmSound(title, uri) | ||
alarms.add(alarmSound) | ||
} | ||
} catch (e: Exception) { | ||
showErrorToast(e) | ||
} | ||
|
||
return alarms | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters