@@ -6,6 +6,7 @@ import android.content.ActivityNotFoundException
66import android.content.Context
77import android.content.Intent
88import android.content.pm.ShortcutInfo
9+ import android.content.pm.ShortcutManager
910import android.graphics.drawable.Icon
1011import android.graphics.drawable.LayerDrawable
1112import android.net.Uri
@@ -43,6 +44,7 @@ import com.simplemobiletools.notes.pro.fragments.TextFragment
4344import com.simplemobiletools.notes.pro.helpers.*
4445import com.simplemobiletools.notes.pro.models.Note
4546import kotlinx.android.synthetic.main.activity_main.*
47+ import kotlinx.android.synthetic.main.item_checklist.*
4648import java.io.File
4749import java.io.FileOutputStream
4850import java.io.OutputStream
@@ -213,6 +215,7 @@ class MainActivity : SimpleActivity() {
213215 R .id.new_note -> displayNewNoteDialog()
214216 R .id.rename_note -> fragment?.handleUnlocking { displayRenameDialog() }
215217 R .id.share -> fragment?.handleUnlocking { shareText() }
218+ R .id.cab_create_shortcut -> createShortcut()
216219 R .id.lock_note -> lockNote()
217220 R .id.unlock_note -> unlockNote()
218221 R .id.open_file -> tryOpenFile()
@@ -1339,6 +1342,30 @@ class MainActivity : SimpleActivity() {
13391342 }
13401343 }
13411344
1345+ @SuppressLint(" NewApi" )
1346+ private fun createShortcut () {
1347+ val manager = getSystemService(ShortcutManager ::class .java)
1348+ if (manager.isRequestPinShortcutSupported) {
1349+ val note = mCurrentNote
1350+ val drawable = resources.getDrawable(R .drawable.shortcut_note).mutate()
1351+ val appIconColor = baseConfig.appIconColor
1352+ (drawable as LayerDrawable ).findDrawableByLayerId(R .id.shortcut_plus_background).applyColorFilter(appIconColor)
1353+
1354+ val intent = Intent (this , SplashActivity ::class .java)
1355+ intent.action = Intent .ACTION_VIEW
1356+ intent.putExtra(OPEN_NOTE_ID , note.id)
1357+ intent.flags = intent.flags or Intent .FLAG_ACTIVITY_NEW_TASK or Intent .FLAG_ACTIVITY_CLEAR_TASK or Intent .FLAG_ACTIVITY_NO_HISTORY
1358+
1359+ val shortcut = ShortcutInfo .Builder (this , note.hashCode().toString())
1360+ .setShortLabel(mCurrentNote.title)
1361+ .setIcon(Icon .createWithBitmap(drawable.convertToBitmap()))
1362+ .setIntent(intent)
1363+ .build()
1364+
1365+ manager.requestPinShortcut(shortcut, null )
1366+ }
1367+ }
1368+
13421369 private fun lockNote () {
13431370 ConfirmationDialog (this , " " , R .string.locking_warning, R .string.ok, R .string.cancel) {
13441371 SecurityDialog (this , " " , SHOW_ALL_TABS ) { hash, type, success ->
0 commit comments