Skip to content

Commit 7435c6c

Browse files
authored
Merge pull request #795 from wordpress-mobile/issue/fix-for-samsung-custom-cliboard-android-8
Fix for crash on Samsung Clipboard ListView on Android 8.X
2 parents cc3789a + 4c56f8c commit 7435c6c

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

aztec/src/main/kotlin/org/wordpress/aztec/AztecText.kt

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ import android.view.WindowManager
5555
import android.view.inputmethod.BaseInputConnection
5656
import android.widget.CheckBox
5757
import android.widget.EditText
58+
import android.widget.Toast
5859
import kotlinx.coroutines.Dispatchers
5960
import kotlinx.coroutines.runBlocking
6061
import kotlinx.coroutines.withContext
@@ -1384,6 +1385,8 @@ open class AztecText : AppCompatEditText, TextWatcher, UnknownHtmlSpan.OnUnknown
13841385
max = Math.max(0, Math.max(selectionStart, selectionEnd))
13851386
}
13861387

1388+
var clipboardIdentifier = resources.getIdentifier("android:id/clipboard", "id", context.packageName)
1389+
13871390
when (id) {
13881391
android.R.id.paste -> paste(text, min, max)
13891392
android.R.id.pasteAsPlainText -> paste(text, min, max, true)
@@ -1400,7 +1403,17 @@ open class AztecText : AppCompatEditText, TextWatcher, UnknownHtmlSpan.OnUnknown
14001403
deleteInlineStyleFromTheBeginning()
14011404
}
14021405
}
1403-
else -> return super.onTextContextMenuItem(id)
1406+
// Fix for crash when pasting text on Samsung Devices running Android 8.
1407+
// Ref: https://github.com/wordpress-mobile/WordPress-Android/issues/8827
1408+
clipboardIdentifier -> {
1409+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O && Build.VERSION.SDK_INT < 28
1410+
&& Build.MANUFACTURER.toLowerCase().equals("samsung")) {
1411+
// Nope return true
1412+
Toast.makeText(context, R.string.samsung_disabled_custom_clipboard, Toast.LENGTH_LONG).show()
1413+
} else {
1414+
return super.onTextContextMenuItem(id)
1415+
}
1416+
} else -> return super.onTextContextMenuItem(id)
14041417
}
14051418

14061419
return true

aztec/src/main/res/values/strings.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
<!-- GENERAL -->
44
<string name="cursor_moved">Cursor moved</string>
5+
<string name="samsung_disabled_custom_clipboard">Sorry, this feature is disabled on Android 8. Please use the Paste action instead.</string>
56

67
<!-- LINK DIALOG -->
78
<string name="link_dialog_title">Insert link</string>

0 commit comments

Comments
 (0)