feat: 优化代码

pull/115/head
kunfei 5 years ago
parent b924cff588
commit 8ad566b8be
  1. 8
      app/src/main/java/io/legado/app/ui/book/read/TextActionMenu.kt

@ -116,13 +116,13 @@ class TextActionMenu(private val context: Context, private val callBack: CallBac
} }
@RequiresApi(Build.VERSION_CODES.M) @RequiresApi(Build.VERSION_CODES.M)
private fun getSupportedActivities(): List<ResolveInfo?>? { private fun getSupportedActivities(): List<ResolveInfo> {
return context.packageManager return context.packageManager
.queryIntentActivities(createProcessTextIntent(), 0) .queryIntentActivities(createProcessTextIntent(), 0)
} }
@RequiresApi(Build.VERSION_CODES.M) @RequiresApi(Build.VERSION_CODES.M)
private fun createProcessTextIntentForResolveInfo(info: ResolveInfo): Intent? { private fun createProcessTextIntentForResolveInfo(info: ResolveInfo): Intent {
return createProcessTextIntent() return createProcessTextIntent()
.putExtra(Intent.EXTRA_PROCESS_TEXT_READONLY, false) .putExtra(Intent.EXTRA_PROCESS_TEXT_READONLY, false)
.setClassName(info.activityInfo.packageName, info.activityInfo.name) .setClassName(info.activityInfo.packageName, info.activityInfo.name)
@ -139,10 +139,10 @@ class TextActionMenu(private val context: Context, private val callBack: CallBac
// so that your "PROCESS_TEXT" menu items appear after the // so that your "PROCESS_TEXT" menu items appear after the
// standard selection menu items like Cut, Copy, Paste. // standard selection menu items like Cut, Copy, Paste.
var menuItemOrder = 100 var menuItemOrder = 100
for (resolveInfo in getSupportedActivities()!!) { for (resolveInfo in getSupportedActivities()) {
menu.add( menu.add(
Menu.NONE, Menu.NONE, Menu.NONE, Menu.NONE,
menuItemOrder++, resolveInfo!!.loadLabel(context.packageManager) menuItemOrder++, resolveInfo.loadLabel(context.packageManager)
).intent = createProcessTextIntentForResolveInfo(resolveInfo) ).intent = createProcessTextIntentForResolveInfo(resolveInfo)
} }
} }

Loading…
Cancel
Save