mirror of
https://github.com/SimpleMobileTools/Simple-Calendar.git
synced 2025-03-18 04:10:15 +01:00
add a shortcut for creating new tasks
This commit is contained in:
parent
09ecb2cd3d
commit
db5fdcdb96
@ -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)
|
||||
|
@ -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()
|
||||
|
@ -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"
|
||||
|
14
app/src/main/res/drawable/shortcut_event.xml
Normal file
14
app/src/main/res/drawable/shortcut_event.xml
Normal file
@ -0,0 +1,14 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<item android:id="@+id/shortcut_event_background">
|
||||
<shape android:shape="oval">
|
||||
<solid android:color="@color/color_primary" />
|
||||
</shape>
|
||||
</item>
|
||||
<item
|
||||
android:bottom="@dimen/medium_margin"
|
||||
android:drawable="@drawable/ic_today_vector"
|
||||
android:left="@dimen/medium_margin"
|
||||
android:right="@dimen/medium_margin"
|
||||
android:top="@dimen/medium_margin" />
|
||||
</layer-list>
|
14
app/src/main/res/drawable/shortcut_task.xml
Normal file
14
app/src/main/res/drawable/shortcut_task.xml
Normal file
@ -0,0 +1,14 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<item android:id="@+id/shortcut_task_background">
|
||||
<shape android:shape="oval">
|
||||
<solid android:color="@color/color_primary" />
|
||||
</shape>
|
||||
</item>
|
||||
<item
|
||||
android:bottom="@dimen/medium_margin"
|
||||
android:drawable="@drawable/ic_task_vector"
|
||||
android:left="@dimen/medium_margin"
|
||||
android:right="@dimen/medium_margin"
|
||||
android:top="@dimen/medium_margin" />
|
||||
</layer-list>
|
Loading…
x
Reference in New Issue
Block a user