adding a shortcut for creating new contacts too

This commit is contained in:
tibbi 2019-03-07 20:28:51 +01:00
parent 6b6b25f988
commit 1d877ff5bd
2 changed files with 54 additions and 15 deletions

View File

@ -254,26 +254,49 @@ class MainActivity : SimpleActivity(), RefreshContactsListener {
private fun checkShortcuts() {
val appIconColor = config.appIconColor
if (isNougatMR1Plus() && config.lastHandledShortcutColor != appIconColor) {
val newEvent = getString(R.string.dialpad)
val launchDialpad = getLaunchDialpadShortcut(appIconColor)
val createNewContact = getCreateNewContactShortcut(appIconColor)
val manager = getSystemService(ShortcutManager::class.java)
val drawable = resources.getDrawable(R.drawable.shortcut_dialpad)
(drawable as LayerDrawable).findDrawableByLayerId(R.id.shortcut_dialpad_background).applyColorFilter(appIconColor)
val bmp = drawable.convertToBitmap()
val intent = Intent(this, DialpadActivity::class.java)
intent.action = Intent.ACTION_VIEW
val shortcut = ShortcutInfo.Builder(this, "launch_dialpad")
.setShortLabel(newEvent)
.setLongLabel(newEvent)
.setIcon(Icon.createWithBitmap(bmp))
.setIntent(intent)
.build()
manager.dynamicShortcuts = Arrays.asList(shortcut)
manager.dynamicShortcuts = Arrays.asList(launchDialpad, createNewContact)
config.lastHandledShortcutColor = appIconColor
}
}
@SuppressLint("NewApi")
private fun getLaunchDialpadShortcut(appIconColor: Int): ShortcutInfo {
val newEvent = getString(R.string.dialpad)
val drawable = resources.getDrawable(R.drawable.shortcut_dialpad)
(drawable as LayerDrawable).findDrawableByLayerId(R.id.shortcut_dialpad_background).applyColorFilter(appIconColor)
val bmp = drawable.convertToBitmap()
val intent = Intent(this, DialpadActivity::class.java)
intent.action = Intent.ACTION_VIEW
return ShortcutInfo.Builder(this, "launch_dialpad")
.setShortLabel(newEvent)
.setLongLabel(newEvent)
.setIcon(Icon.createWithBitmap(bmp))
.setIntent(intent)
.build()
}
@SuppressLint("NewApi")
private fun getCreateNewContactShortcut(appIconColor: Int): ShortcutInfo {
val newEvent = getString(R.string.create_new_contact)
val drawable = resources.getDrawable(R.drawable.shortcut_plus)
(drawable as LayerDrawable).findDrawableByLayerId(R.id.shortcut_plus_background).applyColorFilter(appIconColor)
val bmp = drawable.convertToBitmap()
val intent = Intent(this, EditContactActivity::class.java)
intent.action = Intent.ACTION_VIEW
return ShortcutInfo.Builder(this, "create_new_contact")
.setShortLabel(newEvent)
.setLongLabel(newEvent)
.setIcon(Icon.createWithBitmap(bmp))
.setIntent(intent)
.build()
}
private fun getCurrentFragment(): MyViewPagerFragment? {
val showTabs = config.showTabs
val fragments = arrayListOf<MyViewPagerFragment>()

View File

@ -0,0 +1,16 @@
<?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_plus"
android:left="@dimen/medium_margin"
android:right="@dimen/medium_margin"
android:top="@dimen/medium_margin"/>
</layer-list>