from os import unlink
from jnius import autoclass, cast
from plyer.facades import Camera
from plyer.platforms.android import activity

Intent = autoclass('android.content.Intent')
PythonActivity = autoclass('org.renpy.android.PythonActivity')
MediaStore = autoclass('android.provider.MediaStore')
Uri = autoclass('android.net.Uri')


class AndroidCamera(Camera):

    def _take_picture(self, on_complete, filename=None):
        assert(on_complete is not None)
        self.on_complete = on_complete
        self.filename = filename
        activity.unbind(on_activity_result=self._on_activity_result)
        activity.bind(on_activity_result=self._on_activity_result)
        intent = Intent(MediaStore.ACTION_IMAGE_CAPTURE)
        uri = Uri.parse('file://' + filename)
        parcelable = cast('android.os.Parcelable', uri)
        intent.putExtra(MediaStore.EXTRA_OUTPUT, parcelable)
        activity.startActivityForResult(intent, 0x123)

    def _on_activity_result(self, requestCode, resultCode, intent):
        if requestCode != 0x123:
            return
        activity.unbind(on_activity_result=self._on_activity_result)
        if self.on_complete(self.filename):
            self._unlink(self.filename)

    def _unlink(self, fn):
        try:
            unlink(fn)
        except:
            pass

def instance():
    return AndroidCamera()


import android
import android.activity
from os import unlink
from jnius import autoclass, cast
from plyer.facades import Camera
from plyer.platforms.android import activity

Intent = autoclass('android.content.Intent')
PythonActivity = autoclass('org.renpy.android.PythonActivity')
MediaStore = autoclass('android.provider.MediaStore')
Uri = autoclass('android.net.Uri')


class AndroidCamera(Camera):

    def _take_picture(self, on_complete, filename=None):
        assert(on_complete is not None)
        self.on_complete = on_complete
        self.filename = filename
        android.activity.unbind(on_activity_result=self._on_activity_result)
        android.activity.bind(on_activity_result=self._on_activity_result)
        intent = Intent(MediaStore.ACTION_IMAGE_CAPTURE)
        uri = Uri.parse('file://' + filename)
        parcelable = cast('android.os.Parcelable', uri)
        intent.putExtra(MediaStore.EXTRA_OUTPUT, parcelable)
        activity.startActivityForResult(intent, 0x123)

    def _on_activity_result(self, requestCode, resultCode, intent):
        if requestCode != 0x123:
            return
        android.activity.unbind(on_activity_result=self._on_activity_result)
        if self.on_complete(self.filename):
            self._unlink(self.filename)

    def _unlink(self, fn):
        try:
            unlink(fn)
        except:
            pass

def instance():
    return AndroidCamera()

Revert "Activity was imported twice"
Revert "Activity was imported twice"

This reverts commit a0600929774c1e90c7dc43043ff87b5ea84213b4.

+ 
+ import android
+ import android.activity
  from os import unlink
  from jnius import autoclass, cast
  from plyer.facades import Camera
  from plyer.platforms.android import activity
  
  Intent = autoclass('android.content.Intent')
  PythonActivity = autoclass('org.renpy.android.PythonActivity')
  MediaStore = autoclass('android.provider.MediaStore')
  Uri = autoclass('android.net.Uri')
  
  
  class AndroidCamera(Camera):
  
      def _take_picture(self, on_complete, filename=None):
          assert(on_complete is not None)
          self.on_complete = on_complete
          self.filename = filename
-         activity.unbind(on_activity_result=self._on_activity_result)
+         android.activity.unbind(on_activity_result=self._on_activity_result)
-         activity.bind(on_activity_result=self._on_activity_result)
+         android.activity.bind(on_activity_result=self._on_activity_result)
          intent = Intent(MediaStore.ACTION_IMAGE_CAPTURE)
          uri = Uri.parse('file://' + filename)
          parcelable = cast('android.os.Parcelable', uri)
          intent.putExtra(MediaStore.EXTRA_OUTPUT, parcelable)
          activity.startActivityForResult(intent, 0x123)
  
      def _on_activity_result(self, requestCode, resultCode, intent):
          if requestCode != 0x123:
              return
-         activity.unbind(on_activity_result=self._on_activity_result)
+         android.activity.unbind(on_activity_result=self._on_activity_result)
          if self.on_complete(self.filename):
              self._unlink(self.filename)
  
      def _unlink(self, fn):
          try:
              unlink(fn)
          except:
              pass
  
  def instance():
      return AndroidCamera()
  
Revert "Activity was imported twice"
## Code Before:
from os import unlink
from jnius import autoclass, cast
from plyer.facades import Camera
from plyer.platforms.android import activity

Intent = autoclass('android.content.Intent')
PythonActivity = autoclass('org.renpy.android.PythonActivity')
MediaStore = autoclass('android.provider.MediaStore')
Uri = autoclass('android.net.Uri')


class AndroidCamera(Camera):

    def _take_picture(self, on_complete, filename=None):
        assert(on_complete is not None)
        self.on_complete = on_complete
        self.filename = filename
        activity.unbind(on_activity_result=self._on_activity_result)
        activity.bind(on_activity_result=self._on_activity_result)
        intent = Intent(MediaStore.ACTION_IMAGE_CAPTURE)
        uri = Uri.parse('file://' + filename)
        parcelable = cast('android.os.Parcelable', uri)
        intent.putExtra(MediaStore.EXTRA_OUTPUT, parcelable)
        activity.startActivityForResult(intent, 0x123)

    def _on_activity_result(self, requestCode, resultCode, intent):
        if requestCode != 0x123:
            return
        activity.unbind(on_activity_result=self._on_activity_result)
        if self.on_complete(self.filename):
            self._unlink(self.filename)

    def _unlink(self, fn):
        try:
            unlink(fn)
        except:
            pass

def instance():
    return AndroidCamera()

## Instruction:
Revert "Activity was imported twice"
## Code After:

import android
import android.activity
from os import unlink
from jnius import autoclass, cast
from plyer.facades import Camera
from plyer.platforms.android import activity

Intent = autoclass('android.content.Intent')
PythonActivity = autoclass('org.renpy.android.PythonActivity')
MediaStore = autoclass('android.provider.MediaStore')
Uri = autoclass('android.net.Uri')


class AndroidCamera(Camera):

    def _take_picture(self, on_complete, filename=None):
        assert(on_complete is not None)
        self.on_complete = on_complete
        self.filename = filename
        android.activity.unbind(on_activity_result=self._on_activity_result)
        android.activity.bind(on_activity_result=self._on_activity_result)
        intent = Intent(MediaStore.ACTION_IMAGE_CAPTURE)
        uri = Uri.parse('file://' + filename)
        parcelable = cast('android.os.Parcelable', uri)
        intent.putExtra(MediaStore.EXTRA_OUTPUT, parcelable)
        activity.startActivityForResult(intent, 0x123)

    def _on_activity_result(self, requestCode, resultCode, intent):
        if requestCode != 0x123:
            return
        android.activity.unbind(on_activity_result=self._on_activity_result)
        if self.on_complete(self.filename):
            self._unlink(self.filename)

    def _unlink(self, fn):
        try:
            unlink(fn)
        except:
            pass

def instance():
    return AndroidCamera()
