diff --git a/app/src/main/kotlin/com/simplemobiletools/calendar/pro/activities/MainActivity.kt b/app/src/main/kotlin/com/simplemobiletools/calendar/pro/activities/MainActivity.kt
index 12a376357..e7c8bac27 100644
--- a/app/src/main/kotlin/com/simplemobiletools/calendar/pro/activities/MainActivity.kt
+++ b/app/src/main/kotlin/com/simplemobiletools/calendar/pro/activities/MainActivity.kt
@@ -6,7 +6,6 @@ import android.app.SearchManager
import android.content.Context
import android.content.Intent
import android.content.pm.ShortcutInfo
-import android.content.pm.ShortcutManager
import android.graphics.drawable.ColorDrawable
import android.graphics.drawable.Icon
import android.graphics.drawable.LayerDrawable
@@ -387,29 +386,54 @@ class MainActivity : SimpleActivity(), RefreshRecyclerViewListener {
private fun checkShortcuts() {
val appIconColor = config.appIconColor
if (isNougatMR1Plus() && config.lastHandledShortcutColor != appIconColor) {
- val newEvent = getString(R.string.new_event)
- val manager = getSystemService(ShortcutManager::class.java)
- val drawable = resources.getDrawable(R.drawable.shortcut_plus, theme)
- (drawable as LayerDrawable).findDrawableByLayerId(R.id.shortcut_plus_background).applyColorFilter(appIconColor)
- val bmp = drawable.convertToBitmap()
+ val newEvent = getNewEventShortcut(appIconColor)
+ val shortcuts = arrayListOf(newEvent)
- val intent = Intent(this, SplashActivity::class.java)
- intent.action = SHORTCUT_NEW_EVENT
- val shortcut = ShortcutInfo.Builder(this, "new_event")
- .setShortLabel(newEvent)
- .setLongLabel(newEvent)
- .setIcon(Icon.createWithBitmap(bmp))
- .setIntent(intent)
- .build()
+ if (config.allowCreatingTasks) {
+ shortcuts.add(getNewTaskShortcut(appIconColor))
+ }
try {
- manager.dynamicShortcuts = Arrays.asList(shortcut)
+ shortcutManager.dynamicShortcuts = shortcuts
config.lastHandledShortcutColor = appIconColor
} catch (ignored: Exception) {
}
}
}
+ @SuppressLint("NewApi")
+ private fun getNewEventShortcut(appIconColor: Int): ShortcutInfo {
+ val newEvent = getString(R.string.new_event)
+ val newEventDrawable = resources.getDrawable(R.drawable.shortcut_event, theme)
+ (newEventDrawable as LayerDrawable).findDrawableByLayerId(R.id.shortcut_event_background).applyColorFilter(appIconColor)
+ val newEventBitmap = newEventDrawable.convertToBitmap()
+
+ val newEventIntent = Intent(this, SplashActivity::class.java)
+ newEventIntent.action = SHORTCUT_NEW_EVENT
+ return ShortcutInfo.Builder(this, "new_event")
+ .setShortLabel(newEvent)
+ .setLongLabel(newEvent)
+ .setIcon(Icon.createWithBitmap(newEventBitmap))
+ .setIntent(newEventIntent)
+ .build()
+ }
+
+ @SuppressLint("NewApi")
+ private fun getNewTaskShortcut(appIconColor: Int): ShortcutInfo {
+ val newTask = getString(R.string.new_task)
+ val newTaskDrawable = resources.getDrawable(R.drawable.shortcut_task, theme)
+ (newTaskDrawable as LayerDrawable).findDrawableByLayerId(R.id.shortcut_task_background).applyColorFilter(appIconColor)
+ val newTaskBitmap = newTaskDrawable.convertToBitmap()
+ val newTaskIntent = Intent(this, SplashActivity::class.java)
+ newTaskIntent.action = SHORTCUT_NEW_TASK
+ return ShortcutInfo.Builder(this, "new_task")
+ .setShortLabel(newTask)
+ .setLongLabel(newTask)
+ .setIcon(Icon.createWithBitmap(newTaskBitmap))
+ .setIntent(newTaskIntent)
+ .build()
+ }
+
private fun checkIsOpenIntent(): Boolean {
val dayCodeToOpen = intent.getStringExtra(DAY_CODE) ?: ""
val viewToOpen = intent.getIntExtra(VIEW_TO_OPEN, DAILY_VIEW)
diff --git a/app/src/main/kotlin/com/simplemobiletools/calendar/pro/activities/SplashActivity.kt b/app/src/main/kotlin/com/simplemobiletools/calendar/pro/activities/SplashActivity.kt
index 3cb6b6ad4..873d9fba3 100644
--- a/app/src/main/kotlin/com/simplemobiletools/calendar/pro/activities/SplashActivity.kt
+++ b/app/src/main/kotlin/com/simplemobiletools/calendar/pro/activities/SplashActivity.kt
@@ -26,6 +26,13 @@ class SplashActivity : BaseSplashActivity() {
startActivity(this)
}
}
+ intent.action == SHORTCUT_NEW_TASK -> {
+ val dayCode = Formatter.getDayCodeFromDateTime(DateTime())
+ Intent(this, TaskActivity::class.java).apply {
+ putExtra(NEW_EVENT_START_TS, getNewEventTimestampFromCode(dayCode))
+ startActivity(this)
+ }
+ }
else -> startActivity(Intent(this, MainActivity::class.java))
}
finish()
diff --git a/app/src/main/kotlin/com/simplemobiletools/calendar/pro/helpers/Constants.kt b/app/src/main/kotlin/com/simplemobiletools/calendar/pro/helpers/Constants.kt
index 75755831b..1c5d0d2ee 100644
--- a/app/src/main/kotlin/com/simplemobiletools/calendar/pro/helpers/Constants.kt
+++ b/app/src/main/kotlin/com/simplemobiletools/calendar/pro/helpers/Constants.kt
@@ -21,6 +21,7 @@ const val YEAR_TO_OPEN = "year_to_open"
const val CALDAV = "Caldav"
const val VIEW_TO_OPEN = "view_to_open"
const val SHORTCUT_NEW_EVENT = "shortcut_new_event"
+const val SHORTCUT_NEW_TASK = "shortcut_new_task"
const val REGULAR_EVENT_TYPE_ID = 1L
const val TIME_ZONE = "time_zone"
const val CURRENT_TIME_ZONE = "current_time_zone"
diff --git a/app/src/main/res/drawable/shortcut_event.xml b/app/src/main/res/drawable/shortcut_event.xml
new file mode 100644
index 000000000..bf5404e4a
--- /dev/null
+++ b/app/src/main/res/drawable/shortcut_event.xml
@@ -0,0 +1,14 @@
+
+
+ -
+
+
+
+
+
+
diff --git a/app/src/main/res/drawable/shortcut_task.xml b/app/src/main/res/drawable/shortcut_task.xml
new file mode 100644
index 000000000..b680da51a
--- /dev/null
+++ b/app/src/main/res/drawable/shortcut_task.xml
@@ -0,0 +1,14 @@
+
+
+ -
+
+
+
+
+
+