mirror of
https://github.com/SimpleMobileTools/Simple-Notes.git
synced 2025-03-20 10:30:07 +01:00
Merge pull request #599 from Aga-C/add-create-shortcut
Added create shortcut option (#598)
This commit is contained in:
commit
a24aefcb42
@ -6,6 +6,7 @@ import android.content.ActivityNotFoundException
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.content.pm.ShortcutInfo
|
||||
import android.content.pm.ShortcutManager
|
||||
import android.graphics.drawable.Icon
|
||||
import android.graphics.drawable.LayerDrawable
|
||||
import android.net.Uri
|
||||
@ -43,6 +44,7 @@ import com.simplemobiletools.notes.pro.fragments.TextFragment
|
||||
import com.simplemobiletools.notes.pro.helpers.*
|
||||
import com.simplemobiletools.notes.pro.models.Note
|
||||
import kotlinx.android.synthetic.main.activity_main.*
|
||||
import kotlinx.android.synthetic.main.item_checklist.*
|
||||
import java.io.File
|
||||
import java.io.FileOutputStream
|
||||
import java.io.OutputStream
|
||||
@ -213,6 +215,7 @@ class MainActivity : SimpleActivity() {
|
||||
R.id.new_note -> displayNewNoteDialog()
|
||||
R.id.rename_note -> fragment?.handleUnlocking { displayRenameDialog() }
|
||||
R.id.share -> fragment?.handleUnlocking { shareText() }
|
||||
R.id.cab_create_shortcut -> createShortcut()
|
||||
R.id.lock_note -> lockNote()
|
||||
R.id.unlock_note -> unlockNote()
|
||||
R.id.open_file -> tryOpenFile()
|
||||
@ -1339,6 +1342,30 @@ class MainActivity : SimpleActivity() {
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressLint("NewApi")
|
||||
private fun createShortcut() {
|
||||
val manager = getSystemService(ShortcutManager::class.java)
|
||||
if (manager.isRequestPinShortcutSupported) {
|
||||
val note = mCurrentNote
|
||||
val drawable = resources.getDrawable(R.drawable.shortcut_note).mutate()
|
||||
val appIconColor = baseConfig.appIconColor
|
||||
(drawable as LayerDrawable).findDrawableByLayerId(R.id.shortcut_plus_background).applyColorFilter(appIconColor)
|
||||
|
||||
val intent = Intent(this, SplashActivity::class.java)
|
||||
intent.action = Intent.ACTION_VIEW
|
||||
intent.putExtra(OPEN_NOTE_ID, note.id)
|
||||
intent.flags = intent.flags or Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_CLEAR_TASK or Intent.FLAG_ACTIVITY_NO_HISTORY
|
||||
|
||||
val shortcut = ShortcutInfo.Builder(this, note.hashCode().toString())
|
||||
.setShortLabel(mCurrentNote.title)
|
||||
.setIcon(Icon.createWithBitmap(drawable.convertToBitmap()))
|
||||
.setIntent(intent)
|
||||
.build()
|
||||
|
||||
manager.requestPinShortcut(shortcut, null)
|
||||
}
|
||||
}
|
||||
|
||||
private fun lockNote() {
|
||||
ConfirmationDialog(this, "", R.string.locking_warning, R.string.ok, R.string.cancel) {
|
||||
SecurityDialog(this, "", SHOW_ALL_TABS) { hash, type, success ->
|
||||
|
3
app/src/main/res/drawable/ic_shortcut_icon.xml
Normal file
3
app/src/main/res/drawable/ic_shortcut_icon.xml
Normal file
@ -0,0 +1,3 @@
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android" android:width="108dp" android:height="108dp" android:viewportWidth="108" android:viewportHeight="108">
|
||||
<path android:pathData="M83.383 37.813l-19.6-19.442H24.618v71.26H83.225V37.813zm-2.87 0h-16.73v-16.572zm-45.658-2.87v-1.96h26.967v3.92H34.855zm17.185 43.242h-17.168v-3.92h17.168zm21.088-12.355v1.96H34.855v-3.92h38.273zm0-10.237v1.96H34.855v-3.92h38.273zm0-10.255v1.96H34.855v-3.92h38.273z" android:fillColor="#FFFFFFFF"/>
|
||||
</vector>
|
9
app/src/main/res/drawable/shortcut_note.xml
Normal file
9
app/src/main/res/drawable/shortcut_note.xml
Normal file
@ -0,0 +1,9 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<item android:id="@+id/shortcut_plus_background">
|
||||
<shape android:shape="oval">
|
||||
<solid android:color="@color/color_primary"/>
|
||||
</shape>
|
||||
</item>
|
||||
<item android:bottom="@dimen/medium_margin" android:drawable="@drawable/ic_shortcut_icon" android:left="@dimen/medium_margin" android:right="@dimen/medium_margin" android:top="@dimen/medium_margin" />
|
||||
</layer-list>
|
@ -50,6 +50,10 @@
|
||||
android:icon="@drawable/ic_share_vector"
|
||||
android:title="@string/share"
|
||||
app:showAsAction="ifRoom" />
|
||||
<item
|
||||
android:id="@+id/cab_create_shortcut"
|
||||
android:title="@string/create_shortcut"
|
||||
app:showAsAction="never" />
|
||||
<item
|
||||
android:id="@+id/lock_note"
|
||||
android:title="@string/lock_note"
|
||||
|
Loading…
x
Reference in New Issue
Block a user