mirror of
https://github.com/SimpleMobileTools/Simple-Dialer.git
synced 2025-03-25 15:50:14 +01:00
allow creating a dialpad shortcut of the app
This commit is contained in:
parent
b38b4f1046
commit
c38ee53de9
@ -1,10 +1,15 @@
|
||||
package com.simplemobiletools.dialer.activities
|
||||
|
||||
import android.annotation.SuppressLint
|
||||
import android.app.SearchManager
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.content.pm.ShortcutInfo
|
||||
import android.content.pm.ShortcutManager
|
||||
import android.graphics.drawable.ColorDrawable
|
||||
import android.graphics.drawable.Drawable
|
||||
import android.graphics.drawable.Icon
|
||||
import android.graphics.drawable.LayerDrawable
|
||||
import android.os.Bundle
|
||||
import android.os.Handler
|
||||
import android.view.Menu
|
||||
@ -24,6 +29,7 @@ import com.simplemobiletools.dialer.helpers.tabsList
|
||||
import kotlinx.android.synthetic.main.activity_main.*
|
||||
import kotlinx.android.synthetic.main.fragment_contacts.*
|
||||
import kotlinx.android.synthetic.main.fragment_recents.*
|
||||
import java.util.*
|
||||
|
||||
class MainActivity : SimpleActivity() {
|
||||
private var storedTextColor = 0
|
||||
@ -80,6 +86,7 @@ class MainActivity : SimpleActivity() {
|
||||
refreshItems()
|
||||
}
|
||||
|
||||
checkShortcuts()
|
||||
isFirstResume = false
|
||||
}
|
||||
|
||||
@ -178,6 +185,37 @@ class MainActivity : SimpleActivity() {
|
||||
})
|
||||
}
|
||||
|
||||
@SuppressLint("NewApi")
|
||||
private fun checkShortcuts() {
|
||||
val appIconColor = config.appIconColor
|
||||
if (isNougatMR1Plus() && config.lastHandledShortcutColor != appIconColor) {
|
||||
val launchDialpad = getLaunchDialpadShortcut(appIconColor)
|
||||
|
||||
try {
|
||||
getSystemService(ShortcutManager::class.java)!!.dynamicShortcuts = listOf(launchDialpad)
|
||||
config.lastHandledShortcutColor = appIconColor
|
||||
} catch (ignored: Exception) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@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()
|
||||
}
|
||||
|
||||
private fun setupTabColors() {
|
||||
val lastUsedPage = config.lastUsedViewPagerPage
|
||||
main_tabs_holder.apply {
|
||||
|
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_vector"
|
||||
android:left="@dimen/medium_margin"
|
||||
android:right="@dimen/medium_margin"
|
||||
android:top="@dimen/medium_margin" />
|
||||
|
||||
</layer-list>
|
Loading…
x
Reference in New Issue
Block a user