Repository: kivy/kivy

Issue:
TextInput crashes while using clipboard bubble
After opening clipboard bubble, keyboard doesn't close anymore.
Moreover, when closing application, it gives:

```
I/python  ( 4932): [INFO              ] [Clipboard   ] Provider: dummy(['clipboard_android'] ignored)
I/python  ( 4932): [INFO              ] [Base        ] Leaving application in progress...
I/python  ( 4932): Python for android ended.
W/dalvikvm( 4932): threadid=10: thread exiting with uncaught exception (group=0x4001d560)
E/AndroidRuntime( 4932): FATAL EXCEPTION: Thread-11
E/AndroidRuntime( 4932): java.lang.NoClassDefFoundError: android.content.ClipData
E/AndroidRuntime( 4932):    at org.renpy.android.SDLSurfaceView.nativeInit(Native Method)
E/AndroidRuntime( 4932):    at org.renpy.android.SDLSurfaceView.run(SDLSurfaceView.java:725)
E/AndroidRuntime( 4932):    at java.lang.Thread.run(Thread.java:1019)
E/AndroidRuntime( 4932): Caused by: java.lang.ClassNotFoundException: android.content.ClipData in loader dalvik.system.PathClassLoader[/data/app/org.emanuele.LyricsDL-2.apk]
E/AndroidRuntime( 4932):    at dalvik.system.PathClassLoader.findClass(PathClassLoader.java:240)
E/AndroidRuntime( 4932):    at java.lang.ClassLoader.loadClass(ClassLoader.java:551)
E/AndroidRuntime( 4932):    at java.lang.ClassLoader.loadClass(ClassLoader.java:511)
E/AndroidRuntime( 4932):    ... 3 more
```

If specifing "use_bubble: False" it works correctly, but clipboard is obviously disabled.

android sdk 14
kivy 1.8.0
## <bountysource-plugin>

Want to back this issue? **[Post a bounty on it!](https://www.bountysource.com/issues/1436926-textinput-crashes-while-using-clipboard-bubble?utm_campaign=plugin&utm_content=tracker%2F42681&utm_medium=issues&utm_source=github)** We accept bounties via [Bountysource](https://www.bountysource.com/?utm_campaign=plugin&utm_content=tracker%2F42681&utm_medium=issues&utm_source=github).
</bountysource-plugin>



Discussion:
Which version of android did this crash on, are you sure you have the
latest py4a?

On Mon, Mar 10, 2014 at 12:09 AM, emanuele-f notifications@github.comwrote:

> After opening clipboard bubble, keyboard doesn't close anymore.
> Moreover, when closing application, it gives:
> 
> I/python  ( 4932): [INFO              ] [Clipboard   ] Provider: dummy(['clipboard_android'] ignored)
> I/python  ( 4932): [INFO              ] [Base        ] Leaving application in progress...
> I/python  ( 4932): Python for android ended.
> W/dalvikvm( 4932): threadid=10: thread exiting with uncaught exception (group=0x4001d560)
> E/AndroidRuntime( 4932): FATAL EXCEPTION: Thread-11
> E/AndroidRuntime( 4932): java.lang.NoClassDefFoundError: android.content.ClipData
> E/AndroidRuntime( 4932):    at org.renpy.android.SDLSurfaceView.nativeInit(Native Method)
> E/AndroidRuntime( 4932):    at org.renpy.android.SDLSurfaceView.run(SDLSurfaceView.java:725)
> E/AndroidRuntime( 4932):    at java.lang.Thread.run(Thread.java:1019)
> E/AndroidRuntime( 4932): Caused by: java.lang.ClassNotFoundException: android.content.ClipData in loader dalvik.system.PathClassLoader[/data/app/org.emanuele.LyricsDL-2.apk]
> E/AndroidRuntime( 4932):    at dalvik.system.PathClassLoader.findClass(PathClassLoader.java:240)
> E/AndroidRuntime( 4932):    at java.lang.ClassLoader.loadClass(ClassLoader.java:551)
> E/AndroidRuntime( 4932):    at java.lang.ClassLoader.loadClass(ClassLoader.java:511)
> E/AndroidRuntime( 4932):    ... 3 more
> 
> If specifing "use_bubble: False" it works correctly, but clipboard is
> obviously disabled.
> 
> android sdk 14
> kivy 1.8.0
> 
> —
> Reply to this email directly or view it on GitHubhttps://github.com/kivy/kivy/issues/1945
> .

It crashed on Android 2.3.6 Gingerbread.
My py4a is cloned from current git repository.

https://docs.google.com/file/d/0B1WO07-OL50_LVlhbE1MS3M5VjA/edit could you
test this and see if it works?

On Mon, Mar 10, 2014 at 2:09 AM, emanuele-f notifications@github.comwrote:

> It crashed on Android 2.3.6 Gingerbread.
> My py4a is cloned from current git repository.
> 
> —
> Reply to this email directly or view it on GitHubhttps://github.com/kivy/kivy/issues/1945#issuecomment-37138238
> .


Resolving patch:
diff --git a/kivy/core/clipboard/clipboard_android.py b/kivy/core/clipboard/clipboard_android.py
--- a/kivy/core/clipboard/clipboard_android.py
+++ b/kivy/core/clipboard/clipboard_android.py
@@ -14,8 +14,8 @@
 AndroidString = autoclass('java.lang.String')
 PythonActivity = autoclass('org.renpy.android.PythonActivity')
 Context = autoclass('android.content.Context')
-ClipData = autoclass('android.content.ClipData')
-ClipDescription = autoclass('android.content.ClipDescription')
+VER = autoclass('android.os.Build$VERSION')
+sdk = VER.SDK_INT
 
 
 class ClipboardAndroid(ClipboardBase):
@@ -56,19 +56,29 @@ def called(*args, **kargs):
     @_get_clipboard
     def _get(self, mimetype='text/plain'):
         clippy = PythonActivity._clipboard
-        primary_clip = clippy.getPrimaryClip()
-        if primary_clip and clippy.getPrimaryClipDescription().hasMimeType(
-                ClipDescription.MIMETYPE_TEXT_PLAIN):
-            data = primary_clip.getItemAt(0).getText().toString()
+        if sdk < 11:
+            data = clippy.getText().toString()
         else:
-            # TODO: non text data types Not yet implemented
-            data = ''
+            ClipDescription = autoclass('android.content.ClipDescription')
+            primary_clip = clippy.getPrimaryClip()
+            if primary_clip and clippy.getPrimaryClipDescription().hasMimeType(
+                    ClipDescription.MIMETYPE_TEXT_PLAIN):
+                data = primary_clip.getItemAt(0).getText().toString()
+            else:
+                # TODO: non text data types Not yet implemented
+                data = ''
         return data
 
     @_get_clipboard
     def _set(self, data, mimetype):
         clippy = PythonActivity._clipboard
-        new_clip = ClipData.newPlainText(AndroidString(""),
+
+        if sdk < 11:
+            #versions previous to honeycomb
+            clippy.setText(AndroidString(data))
+        else:
+            ClipData = autoclass('android.content.ClipData')
+            new_clip = ClipData.newPlainText(AndroidString(""),
                                          AndroidString(data))
-        # put text data onto clipboard
-        clippy.setPrimaryClip(new_clip)
+            # put text data onto clipboard
+            clippy.setPrimaryClip(new_clip)


Test patch: