Skip to content

Commit

Permalink
曲线救国
Browse files Browse the repository at this point in the history
  • Loading branch information
ZTFtrue committed Feb 2, 2024
1 parent 76c32f4 commit 9bed317
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 13 deletions.
6 changes: 5 additions & 1 deletion app/src/main/java/com/ztftrue/music/ui/play/LyricsView.kt
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ import androidx.compose.ui.input.nestedscroll.nestedScroll
import androidx.compose.ui.input.pointer.motionEventSpy
import androidx.compose.ui.input.pointer.pointerInteropFilter
import androidx.compose.ui.layout.onSizeChanged
import androidx.compose.ui.platform.LocalClipboardManager
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.platform.LocalFocusManager
import androidx.compose.ui.platform.LocalTextToolbar
Expand Down Expand Up @@ -291,11 +292,14 @@ fun LyricsView(
CompositionLocalProvider(
LocalTextToolbar provides CustomTextToolbar(
LocalView.current,
musicViewModel.dictionaryAppList
musicViewModel.dictionaryAppList,
LocalFocusManager.current,
LocalClipboardManager.current
),
) {
val textToolbar = LocalTextToolbar.current
val focusManager = LocalFocusManager.current

SelectionContainer(
modifier = Modifier,
content = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,20 @@ import android.content.Intent
import android.view.ActionMode
import android.view.View
import androidx.annotation.DoNotInline
import androidx.compose.ui.focus.FocusManager
import androidx.compose.ui.geometry.Rect
import androidx.compose.ui.platform.ClipboardManager
import androidx.compose.ui.platform.TextToolbar
import androidx.compose.ui.platform.TextToolbarStatus
import androidx.compose.ui.text.buildAnnotatedString
import com.ztftrue.music.sqlData.model.DictionaryApp


internal class CustomTextToolbar(
private val view: View,
private val customApp: List<DictionaryApp>,
private val focusManager: FocusManager,
private val clipboardManager: ClipboardManager
) : TextToolbar {
private var actionMode: ActionMode? = null
private val textActionModeCallback: TextActionModeCallback = TextActionModeCallback()
Expand All @@ -21,6 +26,7 @@ internal class CustomTextToolbar(
private set

override fun hide() {
// focusManager.clearFocus()
status = TextToolbarStatus.Hidden
actionMode?.finish()
actionMode = null
Expand Down Expand Up @@ -48,7 +54,20 @@ internal class CustomTextToolbar(
textActionModeCallback.onSelectAllRequested = onSelectAllRequested
textActionModeCallback.customProcessTextApp = customApp
textActionModeCallback.onProcessAppItemClick = {
view.tooltipText
onCopyRequested?.invoke()
val t = clipboardManager.getText()
clipboardManager.setText(buildAnnotatedString { append("")})
val intent = Intent()
intent.setAction(Intent.ACTION_PROCESS_TEXT)
intent.setClassName(
it.packageName,
it.name
)
intent.putExtra(
Intent.EXTRA_PROCESS_TEXT,
t
)
view.context.startActivity(intent)
var min = 0
// var max: Int = view.getText().length()
// if (mTextView.isFocused()) {
Expand All @@ -60,17 +79,7 @@ internal class CustomTextToolbar(
// // Perform your definition lookup with the selected text
// // Perform your definition lookup with the selected text
// val selectedText: CharSequence = mTextView.getText().subSequence(min, max)
val intent = Intent()
intent.setAction(Intent.ACTION_PROCESS_TEXT)
intent.setClassName(
it.packageName,
it.name
)
intent.putExtra(
Intent.EXTRA_PROCESS_TEXT,
actionMode?.title
)
view.context.startActivity(intent)

}
status = TextToolbarStatus.Shown
if (actionMode == null) {
Expand Down

0 comments on commit 9bed317

Please sign in to comment.