prompt: You will be provided with a partial code base and an issue statement explaining a problem to resolve.
  <issue>
  kivy/examples/android/takepicture/ fails on Android
  Example cloned form GIT build with:
  buildozer android debug
  deployed to Android 4.4.4 crashes, from adb logcat output teh following lines seem to be relevant:
  
  I/python  (25790):  /data/data/org.test.takepicture/files/lib/python2.7/site-packages/kivy/core/image/img_pygame.py:13: RuntimeWarning: import cdrom: No module named cdrom
  
  I/python  (25790):  Traceback (most recent call last):
  I/python  (25790):    File "/home/jb/python/mread/.buildozer/android/app/main.py", line 32, in <module>
  I/python  (25790):  ImportError: No module named PIL
  I/python  (25790): Python for android ended.
  
  Second line indicates problem with image library, unfortunately I have no clue how to fix it.
  
  
  </issue>
  <code>
  [start of examples/android/takepicture/main.py]
  1 '''
  2 Take picture
  3 ============
  4 
  5 .. author:: Mathieu Virbel <mat@kivy.org>
  6 
  7 Little example to demonstrate how to start an Intent, and get the result.
  8 When you use the Android.startActivityForResult(), the result will be dispatched
  9 into onActivityResult. You can catch the event with the android.activity API
  10 from python-for-android project.
  11 
  12 If you want to compile it, don't forget to add the CAMERA permission::
  13 
  14     ./build.py --name 'TakePicture' --package org.test.takepicture \
  15             --permission CAMERA --version 1 \
  16             --private ~/code/kivy/examples/android/takepicture \
  17             debug installd
  18 
  19 '''
  20 
  21 __version__ = '0.1'
  22 
  23 from kivy.app import App
  24 from os.path import exists
  25 from jnius import autoclass, cast
  26 from android import activity
  27 from functools import partial
  28 from kivy.clock import Clock
  29 from kivy.uix.scatter import Scatter
  30 from kivy.properties import StringProperty
  31 
  32 from PIL import Image
  33 
  34 Intent = autoclass('android.content.Intent')
  35 PythonActivity = autoclass('org.renpy.android.PythonActivity')
  36 MediaStore = autoclass('android.provider.MediaStore')
  37 Uri = autoclass('android.net.Uri')
  38 Environment = autoclass('android.os.Environment')
  39 
  40 
  41 class Picture(Scatter):
  42     source = StringProperty(None)
  43 
  44 
  45 class TakePictureApp(App):
  46     def build(self):
  47         self.index = 0
  48         activity.bind(on_activity_result=self.on_activity_result)
  49 
  50     def get_filename(self):
  51         while True:
  52             self.index += 1
  53             fn = (Environment.getExternalStorageDirectory().getPath() +
  54                   '/takepicture{}.jpg'.format(self.index))
  55             if not exists(fn):
  56                 return fn
  57 
  58     def take_picture(self):
  59         intent = Intent(MediaStore.ACTION_IMAGE_CAPTURE)
  60         self.last_fn = self.get_filename()
  61         self.uri = Uri.parse('file://' + self.last_fn)
  62         self.uri = cast('android.os.Parcelable', self.uri)
  63         intent.putExtra(MediaStore.EXTRA_OUTPUT, self.uri)
  64         PythonActivity.mActivity.startActivityForResult(intent, 0x123)
  65 
  66     def on_activity_result(self, requestCode, resultCode, intent):
  67         if requestCode == 0x123:
  68             Clock.schedule_once(partial(self.add_picture, self.last_fn), 0)
  69 
  70     def add_picture(self, fn, *args):
  71         im = Image.open(fn)
  72         width, height = im.size
  73         im.thumbnail((width / 4, height / 4), Image.ANTIALIAS)
  74         im.save(fn, quality=95)
  75         self.root.add_widget(Picture(source=fn, center=self.root.center))
  76 
  77     def on_pause(self):
  78         return True
  79 
  80 TakePictureApp().run()
  81
  [end of examples/android/takepicture/main.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/examples/android/takepicture/main.py b/examples/android/takepicture/main.py
  --- a/examples/android/takepicture/main.py
  +++ b/examples/android/takepicture/main.py
  @@ -23,7 +23,7 @@
   from kivy.app import App
   from os.path import exists
   from jnius import autoclass, cast
  -from android import activity
  +from android import activity, mActivity
   from functools import partial
   from kivy.clock import Clock
   from kivy.uix.scatter import Scatter
  @@ -32,7 +32,6 @@
   from PIL import Image
   
   Intent = autoclass('android.content.Intent')
  -PythonActivity = autoclass('org.renpy.android.PythonActivity')
   MediaStore = autoclass('android.provider.MediaStore')
   Uri = autoclass('android.net.Uri')
   Environment = autoclass('android.os.Environment')
  @@ -61,7 +60,7 @@
           self.uri = Uri.parse('file://' + self.last_fn)
           self.uri = cast('android.os.Parcelable', self.uri)
           intent.putExtra(MediaStore.EXTRA_OUTPUT, self.uri)
  -        PythonActivity.mActivity.startActivityForResult(intent, 0x123)
  +        mActivity.startActivityForResult(intent, 0x123)
   
       def on_activity_result(self, requestCode, resultCode, intent):
           if requestCode == 0x123:
  
verification_info: {"golden_diff": "diff --git a/examples/android/takepicture/main.py b/examples/android/takepicture/main.py\n--- a/examples/android/takepicture/main.py\n+++ b/examples/android/takepicture/main.py\n@@ -23,7 +23,7 @@\n from kivy.app import App\n from os.path import exists\n from jnius import autoclass, cast\n-from android import activity\n+from android import activity, mActivity\n from functools import partial\n from kivy.clock import Clock\n from kivy.uix.scatter import Scatter\n@@ -32,7 +32,6 @@\n from PIL import Image\n \n Intent = autoclass('android.content.Intent')\n-PythonActivity = autoclass('org.renpy.android.PythonActivity')\n MediaStore = autoclass('android.provider.MediaStore')\n Uri = autoclass('android.net.Uri')\n Environment = autoclass('android.os.Environment')\n@@ -61,7 +60,7 @@\n         self.uri = Uri.parse('file://' + self.last_fn)\n         self.uri = cast('android.os.Parcelable', self.uri)\n         intent.putExtra(MediaStore.EXTRA_OUTPUT, self.uri)\n-        PythonActivity.mActivity.startActivityForResult(intent, 0x123)\n+        mActivity.startActivityForResult(intent, 0x123)\n \n     def on_activity_result(self, requestCode, resultCode, intent):\n         if requestCode == 0x123:\n", "issue": "kivy/examples/android/takepicture/ fails on Android\nExample cloned form GIT build with:\nbuildozer android debug\ndeployed to Android 4.4.4 crashes, from adb logcat output teh following lines seem to be relevant:\n\nI/python  (25790):  /data/data/org.test.takepicture/files/lib/python2.7/site-packages/kivy/core/image/img_pygame.py:13: RuntimeWarning: import cdrom: No module named cdrom\n\nI/python  (25790):  Traceback (most recent call last):\nI/python  (25790):    File \"/home/jb/python/mread/.buildozer/android/app/main.py\", line 32, in <module>\nI/python  (25790):  ImportError: No module named PIL\nI/python  (25790): Python for android ended.\n\nSecond line indicates problem with image library, unfortunately I have no clue how to fix it.\n\n", "before_files": [{"content": "'''\nTake picture\n============\n\n.. author:: Mathieu Virbel <mat@kivy.org>\n\nLittle example to demonstrate how to start an Intent, and get the result.\nWhen you use the Android.startActivityForResult(), the result will be dispatched\ninto onActivityResult. You can catch the event with the android.activity API\nfrom python-for-android project.\n\nIf you want to compile it, don't forget to add the CAMERA permission::\n\n    ./build.py --name 'TakePicture' --package org.test.takepicture \\\n            --permission CAMERA --version 1 \\\n            --private ~/code/kivy/examples/android/takepicture \\\n            debug installd\n\n'''\n\n__version__ = '0.1'\n\nfrom kivy.app import App\nfrom os.path import exists\nfrom jnius import autoclass, cast\nfrom android import activity\nfrom functools import partial\nfrom kivy.clock import Clock\nfrom kivy.uix.scatter import Scatter\nfrom kivy.properties import StringProperty\n\nfrom PIL import Image\n\nIntent = autoclass('android.content.Intent')\nPythonActivity = autoclass('org.renpy.android.PythonActivity')\nMediaStore = autoclass('android.provider.MediaStore')\nUri = autoclass('android.net.Uri')\nEnvironment = autoclass('android.os.Environment')\n\n\nclass Picture(Scatter):\n    source = StringProperty(None)\n\n\nclass TakePictureApp(App):\n    def build(self):\n        self.index = 0\n        activity.bind(on_activity_result=self.on_activity_result)\n\n    def get_filename(self):\n        while True:\n            self.index += 1\n            fn = (Environment.getExternalStorageDirectory().getPath() +\n                  '/takepicture{}.jpg'.format(self.index))\n            if not exists(fn):\n                return fn\n\n    def take_picture(self):\n        intent = Intent(MediaStore.ACTION_IMAGE_CAPTURE)\n        self.last_fn = self.get_filename()\n        self.uri = Uri.parse('file://' + self.last_fn)\n        self.uri = cast('android.os.Parcelable', self.uri)\n        intent.putExtra(MediaStore.EXTRA_OUTPUT, self.uri)\n        PythonActivity.mActivity.startActivityForResult(intent, 0x123)\n\n    def on_activity_result(self, requestCode, resultCode, intent):\n        if requestCode == 0x123:\n            Clock.schedule_once(partial(self.add_picture, self.last_fn), 0)\n\n    def add_picture(self, fn, *args):\n        im = Image.open(fn)\n        width, height = im.size\n        im.thumbnail((width / 4, height / 4), Image.ANTIALIAS)\n        im.save(fn, quality=95)\n        self.root.add_widget(Picture(source=fn, center=self.root.center))\n\n    def on_pause(self):\n        return True\n\nTakePictureApp().run()\n", "path": "examples/android/takepicture/main.py"}]}