@@ -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
@@ -214,6 +216,7 @@ class MainActivity : SimpleActivity() {
214216 R .id.new_note -> displayNewNoteDialog()
215217 R .id.rename_note -> fragment?.handleUnlocking { displayRenameDialog() }
216218 R .id.share -> fragment?.handleUnlocking { shareText() }
219+ R .id.cab_create_shortcut -> createShortcut()
217220 R .id.lock_note -> lockNote()
218221 R .id.unlock_note -> unlockNote()
219222 R .id.open_file -> tryOpenFile()
@@ -1320,6 +1323,30 @@ class MainActivity : SimpleActivity() {
13201323 }
13211324 }
13221325
1326+ @SuppressLint(" NewApi" )
1327+ private fun createShortcut () {
1328+ val manager = getSystemService(ShortcutManager ::class .java)
1329+ if (manager.isRequestPinShortcutSupported) {
1330+ val note = mCurrentNote
1331+ val drawable = resources.getDrawable(R .drawable.shortcut_note).mutate()
1332+ val appIconColor = baseConfig.appIconColor
1333+ (drawable as LayerDrawable ).findDrawableByLayerId(R .id.shortcut_plus_background).applyColorFilter(appIconColor)
1334+
1335+ val intent = Intent (this , SplashActivity ::class .java)
1336+ intent.action = Intent .ACTION_VIEW
1337+ intent.putExtra(OPEN_NOTE_ID , note.id)
1338+ intent.flags = intent.flags or Intent .FLAG_ACTIVITY_NEW_TASK or Intent .FLAG_ACTIVITY_CLEAR_TASK or Intent .FLAG_ACTIVITY_NO_HISTORY
1339+
1340+ val shortcut = ShortcutInfo .Builder (this , note.hashCode().toString())
1341+ .setShortLabel(mCurrentNote.title)
1342+ .setIcon(Icon .createWithBitmap(drawable.convertToBitmap()))
1343+ .setIntent(intent)
1344+ .build()
1345+
1346+ manager.requestPinShortcut(shortcut, null )
1347+ }
1348+ }
1349+
13231350 private fun lockNote () {
13241351 ConfirmationDialog (this , " " , R .string.locking_warning, R .string.ok, R .string.cancel) {
13251352 SecurityDialog (this , " " , SHOW_ALL_TABS ) { hash, type, success ->
0 commit comments