mirror of
				https://github.com/SimpleMobileTools/Simple-Contacts.git
				synced 2025-06-05 21:59:27 +02:00 
			
		
		
		
	adding a shortcut for creating new contacts too
This commit is contained in:
		| @@ -254,24 +254,47 @@ 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) | ||||
|             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 | ||||
|             val shortcut = ShortcutInfo.Builder(this, "launch_dialpad") | ||||
|         return ShortcutInfo.Builder(this, "launch_dialpad") | ||||
|                 .setShortLabel(newEvent) | ||||
|                 .setLongLabel(newEvent) | ||||
|                 .setIcon(Icon.createWithBitmap(bmp)) | ||||
|                 .setIntent(intent) | ||||
|                 .build() | ||||
|  | ||||
|             manager.dynamicShortcuts = Arrays.asList(shortcut) | ||||
|             config.lastHandledShortcutColor = appIconColor | ||||
|     } | ||||
|  | ||||
|     @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? { | ||||
|   | ||||
							
								
								
									
										16
									
								
								app/src/main/res/drawable/shortcut_plus.xml
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										16
									
								
								app/src/main/res/drawable/shortcut_plus.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_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> | ||||
		Reference in New Issue
	
	Block a user