@@ -6,7 +6,6 @@ import android.app.SearchManager
66import android.content.Context
77import android.content.Intent
88import android.content.pm.ShortcutInfo
9- import android.content.pm.ShortcutManager
109import android.graphics.drawable.ColorDrawable
1110import android.graphics.drawable.Icon
1211import android.graphics.drawable.LayerDrawable
@@ -387,29 +386,54 @@ class MainActivity : SimpleActivity(), RefreshRecyclerViewListener {
387386 private fun checkShortcuts () {
388387 val appIconColor = config.appIconColor
389388 if (isNougatMR1Plus() && config.lastHandledShortcutColor != appIconColor) {
390- val newEvent = getString(R .string.new_event)
391- val manager = getSystemService(ShortcutManager ::class .java)
392- val drawable = resources.getDrawable(R .drawable.shortcut_plus, theme)
393- (drawable as LayerDrawable ).findDrawableByLayerId(R .id.shortcut_plus_background).applyColorFilter(appIconColor)
394- val bmp = drawable.convertToBitmap()
395-
396- val intent = Intent (this , SplashActivity ::class .java)
397- intent.action = SHORTCUT_NEW_EVENT
398- val shortcut = ShortcutInfo .Builder (this , " new_event" )
399- .setShortLabel(newEvent)
400- .setLongLabel(newEvent)
401- .setIcon(Icon .createWithBitmap(bmp))
402- .setIntent(intent)
403- .build()
389+ val newEvent = getNewEventShortcut(appIconColor)
390+ val shortcuts = arrayListOf (newEvent)
391+
392+ if (config.allowCreatingTasks) {
393+ shortcuts.add(getNewTaskShortcut(appIconColor))
394+ }
404395
405396 try {
406- manager .dynamicShortcuts = Arrays .asList(shortcut)
397+ shortcutManager .dynamicShortcuts = shortcuts
407398 config.lastHandledShortcutColor = appIconColor
408399 } catch (ignored: Exception ) {
409400 }
410401 }
411402 }
412403
404+ @SuppressLint(" NewApi" )
405+ private fun getNewEventShortcut (appIconColor : Int ): ShortcutInfo {
406+ val newEvent = getString(R .string.new_event)
407+ val newEventDrawable = resources.getDrawable(R .drawable.shortcut_event, theme)
408+ (newEventDrawable as LayerDrawable ).findDrawableByLayerId(R .id.shortcut_event_background).applyColorFilter(appIconColor)
409+ val newEventBitmap = newEventDrawable.convertToBitmap()
410+
411+ val newEventIntent = Intent (this , SplashActivity ::class .java)
412+ newEventIntent.action = SHORTCUT_NEW_EVENT
413+ return ShortcutInfo .Builder (this , " new_event" )
414+ .setShortLabel(newEvent)
415+ .setLongLabel(newEvent)
416+ .setIcon(Icon .createWithBitmap(newEventBitmap))
417+ .setIntent(newEventIntent)
418+ .build()
419+ }
420+
421+ @SuppressLint(" NewApi" )
422+ private fun getNewTaskShortcut (appIconColor : Int ): ShortcutInfo {
423+ val newTask = getString(R .string.new_task)
424+ val newTaskDrawable = resources.getDrawable(R .drawable.shortcut_task, theme)
425+ (newTaskDrawable as LayerDrawable ).findDrawableByLayerId(R .id.shortcut_task_background).applyColorFilter(appIconColor)
426+ val newTaskBitmap = newTaskDrawable.convertToBitmap()
427+ val newTaskIntent = Intent (this , SplashActivity ::class .java)
428+ newTaskIntent.action = SHORTCUT_NEW_TASK
429+ return ShortcutInfo .Builder (this , " new_task" )
430+ .setShortLabel(newTask)
431+ .setLongLabel(newTask)
432+ .setIcon(Icon .createWithBitmap(newTaskBitmap))
433+ .setIntent(newTaskIntent)
434+ .build()
435+ }
436+
413437 private fun checkIsOpenIntent (): Boolean {
414438 val dayCodeToOpen = intent.getStringExtra(DAY_CODE ) ? : " "
415439 val viewToOpen = intent.getIntExtra(VIEW_TO_OPEN , DAILY_VIEW )
0 commit comments