mirror of
https://github.com/SimpleMobileTools/Simple-Contacts.git
synced 2025-06-05 21:59:27 +02:00
adding a shortcut for launching the dialpad
This commit is contained in:
@ -1,11 +1,16 @@
|
|||||||
package com.simplemobiletools.contacts.pro.activities
|
package com.simplemobiletools.contacts.pro.activities
|
||||||
|
|
||||||
|
import android.annotation.SuppressLint
|
||||||
import android.app.SearchManager
|
import android.app.SearchManager
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
|
import android.content.pm.ShortcutInfo
|
||||||
|
import android.content.pm.ShortcutManager
|
||||||
import android.graphics.Color
|
import android.graphics.Color
|
||||||
import android.graphics.drawable.ColorDrawable
|
import android.graphics.drawable.ColorDrawable
|
||||||
import android.graphics.drawable.Drawable
|
import android.graphics.drawable.Drawable
|
||||||
|
import android.graphics.drawable.Icon
|
||||||
|
import android.graphics.drawable.LayerDrawable
|
||||||
import android.net.Uri
|
import android.net.Uri
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import android.os.Handler
|
import android.os.Handler
|
||||||
@ -37,6 +42,7 @@ import kotlinx.android.synthetic.main.fragment_contacts.*
|
|||||||
import kotlinx.android.synthetic.main.fragment_favorites.*
|
import kotlinx.android.synthetic.main.fragment_favorites.*
|
||||||
import kotlinx.android.synthetic.main.fragment_groups.*
|
import kotlinx.android.synthetic.main.fragment_groups.*
|
||||||
import java.io.FileOutputStream
|
import java.io.FileOutputStream
|
||||||
|
import java.util.*
|
||||||
|
|
||||||
class MainActivity : SimpleActivity(), RefreshContactsListener {
|
class MainActivity : SimpleActivity(), RefreshContactsListener {
|
||||||
private var isSearchOpen = false
|
private var isSearchOpen = false
|
||||||
@ -155,6 +161,7 @@ class MainActivity : SimpleActivity(), RefreshContactsListener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
isFirstResume = false
|
isFirstResume = false
|
||||||
|
checkShortcuts()
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onPause() {
|
override fun onPause() {
|
||||||
@ -243,6 +250,30 @@ class MainActivity : SimpleActivity(), RefreshContactsListener {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressLint("NewApi")
|
||||||
|
private fun checkShortcuts() {
|
||||||
|
val appIconColor = config.appIconColor
|
||||||
|
if (isNougatMR1Plus() && config.lastHandledShortcutColor != appIconColor) {
|
||||||
|
val newEvent = getString(R.string.dialpad)
|
||||||
|
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)
|
||||||
|
config.lastHandledShortcutColor = appIconColor
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private fun getCurrentFragment(): MyViewPagerFragment? {
|
private fun getCurrentFragment(): MyViewPagerFragment? {
|
||||||
val showTabs = config.showTabs
|
val showTabs = config.showTabs
|
||||||
val fragments = arrayListOf<MyViewPagerFragment>()
|
val fragments = arrayListOf<MyViewPagerFragment>()
|
||||||
|
16
app/src/main/res/drawable/shortcut_dialpad.xml
Normal file
16
app/src/main/res/drawable/shortcut_dialpad.xml
Normal 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_dialpad_background">
|
||||||
|
<shape android:shape="oval">
|
||||||
|
<solid android:color="@color/color_primary"/>
|
||||||
|
</shape>
|
||||||
|
</item>
|
||||||
|
|
||||||
|
<item
|
||||||
|
android:bottom="@dimen/medium_margin"
|
||||||
|
android:drawable="@drawable/ic_dialpad"
|
||||||
|
android:left="@dimen/medium_margin"
|
||||||
|
android:right="@dimen/medium_margin"
|
||||||
|
android:top="@dimen/medium_margin"/>
|
||||||
|
|
||||||
|
</layer-list>
|
Reference in New Issue
Block a user