prompt: You will be provided with a partial code base and an issue statement explaining a problem to resolve.
  <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>
  
  
  </issue>
  <code>
  [start of kivy/core/clipboard/clipboard_android.py]
  1 '''
  2 Clipboard Android
  3 =================
  4 
  5 Android implementation of Clipboard provider, using Pyjnius.
  6 '''
  7 
  8 __all__ = ('ClipboardAndroid', )
  9 
  10 from kivy.core.clipboard import ClipboardBase
  11 from jnius import autoclass
  12 from android.runnable import run_on_ui_thread
  13 
  14 AndroidString = autoclass('java.lang.String')
  15 PythonActivity = autoclass('org.renpy.android.PythonActivity')
  16 Context = autoclass('android.content.Context')
  17 ClipData = autoclass('android.content.ClipData')
  18 ClipDescription = autoclass('android.content.ClipDescription')
  19 
  20 
  21 class ClipboardAndroid(ClipboardBase):
  22 
  23     def __init__(self):
  24         super(ClipboardAndroid, self).__init__()
  25         self._clipboard = None
  26         self._data = dict()
  27         self._data['text/plain'] = None
  28         self._data['application/data'] = None
  29         PythonActivity._clipboard = None
  30 
  31     def get(self, mimetype='text/plain'):
  32         return self._get(mimetype)
  33 
  34     def put(self, data, mimetype='text/plain'):
  35         self._set(data, mimetype)
  36 
  37     def get_types(self):
  38         return list(self._data.keys())
  39 
  40     @run_on_ui_thread
  41     def _initialize_clipboard(self):
  42         PythonActivity._clipboard = PythonActivity.getSystemService(
  43             Context.CLIPBOARD_SERVICE)
  44 
  45     def _get_clipboard(f):
  46         def called(*args, **kargs):
  47             self = args[0]
  48             if not PythonActivity._clipboard:
  49                 self._initialize_clipboard()
  50                 import time
  51                 while not PythonActivity._clipboard:
  52                     time.sleep(.01)
  53             return f(*args, **kargs)
  54         return called
  55 
  56     @_get_clipboard
  57     def _get(self, mimetype='text/plain'):
  58         clippy = PythonActivity._clipboard
  59         primary_clip = clippy.getPrimaryClip()
  60         if primary_clip and clippy.getPrimaryClipDescription().hasMimeType(
  61                 ClipDescription.MIMETYPE_TEXT_PLAIN):
  62             data = primary_clip.getItemAt(0).getText().toString()
  63         else:
  64             # TODO: non text data types Not yet implemented
  65             data = ''
  66         return data
  67 
  68     @_get_clipboard
  69     def _set(self, data, mimetype):
  70         clippy = PythonActivity._clipboard
  71         new_clip = ClipData.newPlainText(AndroidString(""),
  72                                          AndroidString(data))
  73         # put text data onto clipboard
  74         clippy.setPrimaryClip(new_clip)
  75
  [end of kivy/core/clipboard/clipboard_android.py]
  </code>
  
  I need you to solve this issue by generating a single patch file that I can apply directly to this repository using git apply. Please respond with a single patch file in the following format.
  <patch>
  diff --git a/file.py b/file.py
  --- a/file.py
  +++ b/file.py
  @@ -1,27 +1,35 @@
   def euclidean(a, b):
  -    while b:
  -        a, b = b, a % b
  -    return a
  +    if b == 0:
  +        return a
  +    return euclidean(b, a % b)
   
   
   def bresenham(x0, y0, x1, y1):
       points = []
       dx = abs(x1 - x0)
       dy = abs(y1 - y0)
  -    sx = 1 if x0 < x1 else -1
  -    sy = 1 if y0 < y1 else -1
  -    err = dx - dy
  +    x, y = x0, y0
  +    sx = -1 if x0 > x1 else 1
  +    sy = -1 if y0 > y1 else 1
   
  -    while True:
  -        points.append((x0, y0))
  -        if x0 == x1 and y0 == y1:
  -            break
  -        e2 = 2 * err
  -        if e2 > -dy:
  -            err -= dy
  -            x0 += sx
  -        if e2 < dx:
  -            err += dx
  -            y0 += sy
  +    if dx > dy:
  +        err = dx / 2.0
  +        while x != x1:
  +            points.append((x, y))
  +            err -= dy
  +            if err < 0:
  +                y += sy
  +                err += dx
  +            x += sx
  +    else:
  +        err = dy / 2.0
  +        while y != y1:
  +            points.append((x, y))
  +            err -= dx
  +            if err < 0:
  +                x += sx
  +                err += dy
  +            y += sy
  +
  +    points.append((x, y))
       return points
  
  </patch>
golden_diff: 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 @@
       @_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)
  
verification_info: {"golden_diff": "diff --git a/kivy/core/clipboard/clipboard_android.py b/kivy/core/clipboard/clipboard_android.py\n--- a/kivy/core/clipboard/clipboard_android.py\n+++ b/kivy/core/clipboard/clipboard_android.py\n@@ -14,8 +14,8 @@\n AndroidString = autoclass('java.lang.String')\n PythonActivity = autoclass('org.renpy.android.PythonActivity')\n Context = autoclass('android.content.Context')\n-ClipData = autoclass('android.content.ClipData')\n-ClipDescription = autoclass('android.content.ClipDescription')\n+VER = autoclass('android.os.Build$VERSION')\n+sdk = VER.SDK_INT\n \n \n class ClipboardAndroid(ClipboardBase):\n@@ -56,19 +56,29 @@\n     @_get_clipboard\n     def _get(self, mimetype='text/plain'):\n         clippy = PythonActivity._clipboard\n-        primary_clip = clippy.getPrimaryClip()\n-        if primary_clip and clippy.getPrimaryClipDescription().hasMimeType(\n-                ClipDescription.MIMETYPE_TEXT_PLAIN):\n-            data = primary_clip.getItemAt(0).getText().toString()\n+        if sdk < 11:\n+            data = clippy.getText().toString()\n         else:\n-            # TODO: non text data types Not yet implemented\n-            data = ''\n+            ClipDescription = autoclass('android.content.ClipDescription')\n+            primary_clip = clippy.getPrimaryClip()\n+            if primary_clip and clippy.getPrimaryClipDescription().hasMimeType(\n+                    ClipDescription.MIMETYPE_TEXT_PLAIN):\n+                data = primary_clip.getItemAt(0).getText().toString()\n+            else:\n+                # TODO: non text data types Not yet implemented\n+                data = ''\n         return data\n \n     @_get_clipboard\n     def _set(self, data, mimetype):\n         clippy = PythonActivity._clipboard\n-        new_clip = ClipData.newPlainText(AndroidString(\"\"),\n+\n+        if sdk < 11:\n+            #versions previous to honeycomb\n+            clippy.setText(AndroidString(data))\n+        else:\n+            ClipData = autoclass('android.content.ClipData')\n+            new_clip = ClipData.newPlainText(AndroidString(\"\"),\n                                          AndroidString(data))\n-        # put text data onto clipboard\n-        clippy.setPrimaryClip(new_clip)\n+            # put text data onto clipboard\n+            clippy.setPrimaryClip(new_clip)\n", "issue": "TextInput crashes while using clipboard bubble\nAfter opening clipboard bubble, keyboard doesn't close anymore.\nMoreover, when closing application, it gives:\n\n```\nI/python  ( 4932): [INFO              ] [Clipboard   ] Provider: dummy(['clipboard_android'] ignored)\nI/python  ( 4932): [INFO              ] [Base        ] Leaving application in progress...\nI/python  ( 4932): Python for android ended.\nW/dalvikvm( 4932): threadid=10: thread exiting with uncaught exception (group=0x4001d560)\nE/AndroidRuntime( 4932): FATAL EXCEPTION: Thread-11\nE/AndroidRuntime( 4932): java.lang.NoClassDefFoundError: android.content.ClipData\nE/AndroidRuntime( 4932):    at org.renpy.android.SDLSurfaceView.nativeInit(Native Method)\nE/AndroidRuntime( 4932):    at org.renpy.android.SDLSurfaceView.run(SDLSurfaceView.java:725)\nE/AndroidRuntime( 4932):    at java.lang.Thread.run(Thread.java:1019)\nE/AndroidRuntime( 4932): Caused by: java.lang.ClassNotFoundException: android.content.ClipData in loader dalvik.system.PathClassLoader[/data/app/org.emanuele.LyricsDL-2.apk]\nE/AndroidRuntime( 4932):    at dalvik.system.PathClassLoader.findClass(PathClassLoader.java:240)\nE/AndroidRuntime( 4932):    at java.lang.ClassLoader.loadClass(ClassLoader.java:551)\nE/AndroidRuntime( 4932):    at java.lang.ClassLoader.loadClass(ClassLoader.java:511)\nE/AndroidRuntime( 4932):    ... 3 more\n```\n\nIf specifing \"use_bubble: False\" it works correctly, but clipboard is obviously disabled.\n\nandroid sdk 14\nkivy 1.8.0\n## <bountysource-plugin>\n\nWant 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).\n</bountysource-plugin>\n\n", "before_files": [{"content": "'''\nClipboard Android\n=================\n\nAndroid implementation of Clipboard provider, using Pyjnius.\n'''\n\n__all__ = ('ClipboardAndroid', )\n\nfrom kivy.core.clipboard import ClipboardBase\nfrom jnius import autoclass\nfrom android.runnable import run_on_ui_thread\n\nAndroidString = autoclass('java.lang.String')\nPythonActivity = autoclass('org.renpy.android.PythonActivity')\nContext = autoclass('android.content.Context')\nClipData = autoclass('android.content.ClipData')\nClipDescription = autoclass('android.content.ClipDescription')\n\n\nclass ClipboardAndroid(ClipboardBase):\n\n    def __init__(self):\n        super(ClipboardAndroid, self).__init__()\n        self._clipboard = None\n        self._data = dict()\n        self._data['text/plain'] = None\n        self._data['application/data'] = None\n        PythonActivity._clipboard = None\n\n    def get(self, mimetype='text/plain'):\n        return self._get(mimetype)\n\n    def put(self, data, mimetype='text/plain'):\n        self._set(data, mimetype)\n\n    def get_types(self):\n        return list(self._data.keys())\n\n    @run_on_ui_thread\n    def _initialize_clipboard(self):\n        PythonActivity._clipboard = PythonActivity.getSystemService(\n            Context.CLIPBOARD_SERVICE)\n\n    def _get_clipboard(f):\n        def called(*args, **kargs):\n            self = args[0]\n            if not PythonActivity._clipboard:\n                self._initialize_clipboard()\n                import time\n                while not PythonActivity._clipboard:\n                    time.sleep(.01)\n            return f(*args, **kargs)\n        return called\n\n    @_get_clipboard\n    def _get(self, mimetype='text/plain'):\n        clippy = PythonActivity._clipboard\n        primary_clip = clippy.getPrimaryClip()\n        if primary_clip and clippy.getPrimaryClipDescription().hasMimeType(\n                ClipDescription.MIMETYPE_TEXT_PLAIN):\n            data = primary_clip.getItemAt(0).getText().toString()\n        else:\n            # TODO: non text data types Not yet implemented\n            data = ''\n        return data\n\n    @_get_clipboard\n    def _set(self, data, mimetype):\n        clippy = PythonActivity._clipboard\n        new_clip = ClipData.newPlainText(AndroidString(\"\"),\n                                         AndroidString(data))\n        # put text data onto clipboard\n        clippy.setPrimaryClip(new_clip)\n", "path": "kivy/core/clipboard/clipboard_android.py"}]}