Esempio n. 1
1
    def _choose_image(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(Intent.ACTION_PICK)
        intent.setType("image/jpeg")
        intent.putExtra(Intent.EXTRA_ALLOW_MULTIPLE, True)
        #intent.putExtra(Intent.EXTRA_LOCAL_ONLY, True)
        #intent.putExtra(Intent.CATEGORY_OPENABLE, True)
        PythonActivity.mActivity.startActivityForResult(
            Intent.createChooser(intent, autoclass(
                'java.lang.String')("Select Picture")), 0x100)
Esempio n. 2
0
    def on_activity_result(request_code, result_code, intent):
        if request_code != RESULT_LOAD_IMAGE:
            Logger.warning(
                'user_select_image: ignoring activity result that was not RESULT_LOAD_IMAGE'
            )
            return

        if result_code == Activity.RESULT_CANCELED:
            Clock.schedule_once(lambda dt: callback(None), 0)
            return

        if result_code != Activity.RESULT_OK:
            # This may just go into the void...
            raise NotImplementedError(
                'Unknown result_code "{}"'.format(result_code))

        selectedImage = intent.getData()
        # Uri
        filePathColumn = [MediaStore_Images_Media_DATA]
        # String[]
        # Cursor
        cursor = currentActivity.getContentResolver().query(
            selectedImage, filePathColumn, None, None, None)
        cursor.moveToFirst()

        # int
        columnIndex = cursor.getColumnIndex(filePathColumn[0])
        # String
        picturePath = cursor.getString(columnIndex)
        cursor.close()
        Logger.info('android_ui: user_select_image() selected %s', picturePath)

        # This is possibly in a different thread?
        Clock.schedule_once(lambda dt: callback(picturePath), 0)
        activity.unbind(on_activity_result=on_activity_result)
Esempio n. 3
0
    def on_activity_result(request_code, result_code, intent):
        if request_code != RESULT_LOAD_IMAGE:
            Logger.warning('user_select_image: ignoring activity result that was not RESULT_LOAD_IMAGE')
            return

        try:
            if result_code == Activity.RESULT_CANCELED:
                Clock.schedule_once(lambda dt: callback(None), 0)
                return

            if result_code != Activity.RESULT_OK:
                # This may just go into the void...
                raise NotImplementedError('Unknown result_code "{}"'.format(result_code))

            selectedImage = intent.getData()  # Uri
            filePathColumn = [MediaStore_Images_Media_DATA] # String[]
            # Cursor
            cursor = currentActivity.getContentResolver().query(selectedImage,
                    filePathColumn, None, None, None)
            cursor.moveToFirst()

            # int
            columnIndex = cursor.getColumnIndex(filePathColumn[0])
            # String
            picturePath = cursor.getString(columnIndex)
            cursor.close()
            Logger.info('android_ui: user_select_image() selected %s', picturePath)

            # This is possibly in a different thread?
            Clock.schedule_once(lambda dt: callback(picturePath), 0)

        finally:
            activity.unbind(on_activity_result=on_activity_result)
Esempio n. 4
0
 def _on_activity_result(self, request_code, result_code, intent):
     if request_code == 0x100:
         activity.unbind(on_activity_result=self._on_activity_result)
         if result_code != -1:
             return
         uri = intent.getData()
         fn = self._convert_uri_to_filename(uri)
         Clock.schedule_once(lambda *x: self.select([fn]), 0)
Esempio n. 5
0
 def _on_activity_result(self, request_code, result_code, intent):
     if request_code == 0x100:
         activity.unbind(on_activity_result=self._on_activity_result)
         if result_code != -1:
             return
         uri = intent.getData()
         fn = self._convert_uri_to_filename(uri)
         Clock.schedule_once(lambda *x: self.select([fn]), 0)
Esempio n. 6
0
 def on_activity_result(self, request_code, result_code, intent):
     #return self.image_path
   
     if request_code == self.CAMERA_REQUEST_CODE:
         activity.unbind(on_activity_result=self.on_activity_result)
         
         print(self.image_path)
         self.on_complete(file_path=self.image_path)
Esempio n. 7
0
 def on_qr_result(requestCode, resultCode, intent):
     try:
         if resultCode == -1:  # RESULT_OK:
             #  this doesn't work due to some bug in jnius:
             # contents = intent.getStringExtra("text")
             String = autoclass("java.lang.String")
             contents = intent.getStringExtra(String("text"))
             on_complete(contents)
     finally:
         activity.unbind(on_activity_result=on_qr_result)
Esempio n. 8
0
 def on_qr_result(requestCode, resultCode, intent):
     try:
         if resultCode == -1:  # RESULT_OK:
             #  this doesn't work due to some bug in jnius:
             # contents = intent.getStringExtra("text")
             String = autoclass("java.lang.String")
             contents = intent.getStringExtra(String("text"))
             on_complete(contents)
     finally:
         activity.unbind(on_activity_result=on_qr_result)
Esempio n. 9
0
 def on_qr_result(requestCode, resultCode, intent):
     try:
         if resultCode == -1:  # RESULT_OK:
             #  this doesn't work due to some bug in jnius:
             # contents = intent.getStringExtra("text")
             String = autoclass("java.lang.String")
             contents = intent.getStringExtra(String("text"))
             on_complete(contents)
     except Exception as e:  # exc would otherwise get lost
         send_exception_to_crash_reporter(e)
     finally:
         activity.unbind(on_activity_result=on_qr_result)
Esempio n. 10
0
 def on_qr_result(requestCode, resultCode, intent):
     try:
         if resultCode == -1:  # RESULT_OK:
             #  this doesn't work due to some bug in jnius:
             # contents = intent.getStringExtra("text")
             String = autoclass("java.lang.String")
             contents = intent.getStringExtra(String("text"))
             on_complete(contents)
     except Exception as e:  # exc would otherwise get lost
         send_exception_to_crash_reporter(e)
     finally:
         activity.unbind(on_activity_result=on_qr_result)
Esempio n. 11
0
    def _choose_image(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(Intent.ACTION_PICK)
        intent.setType("image/jpeg")
        intent.putExtra(Intent.EXTRA_ALLOW_MULTIPLE, True)
        #intent.putExtra(Intent.EXTRA_LOCAL_ONLY, True)
        #intent.putExtra(Intent.CATEGORY_OPENABLE, True)
        PythonActivity.mActivity.startActivityForResult(
            Intent.createChooser(
                intent,
                autoclass('java.lang.String')("Select Picture")), 0x100)
Esempio n. 12
0
    def _take_picture(self, on_complete, filename=None):
        assert (on_complete is not None)
        self.on_complete = on_complete
        self.filename = filename
        activity1.unbind(on_activity_result=self._on_activity_result)
        activity1.bind(on_activity_result=self._on_activity_result)
        intent = Intent(MediaStore.ACTION_IMAGE_CAPTURE)
        # OLD: uri = Uri.parse('file://' + filename)

        app_context = activity2.getApplication().getApplicationContext()
        uri = Fileprovider.getUriForFile(app_context,
                                         "de.adfcmuenchen.fileprovider",
                                         File(filename))
        print("filepath3", filename, uri, uri.toString())
        #content://de.adfcmuenchen.fileprovider/external/Android/data/de.adfc-muenchen.abstellanlagen/files/20200424_....jpg
        # same as /data/user/0/de.adfcmuenchen.abstellanlagen/files/IMG_20200424_....png
        app_context.grantUriPermission("de.adfcmuenchen", uri,
                                       Intent.FLAG_GRANT_WRITE_URI_PERMISSION)
        parcelable = cast('android.os.Parcelable', uri)
        intent.putExtra(MediaStore.EXTRA_OUTPUT, parcelable)
        activity2.startActivityForResult(intent, 0x123)
Esempio n. 13
0
    def take_picture(self, on_complete):

        self.on_complete = on_complete

        camera_intent = Intent(MediaStore.ACTION_IMAGE_CAPTURE)

        photo_file = self._create_image_file()

        if photo_file is not None:
            photo_uri = FileProvider.getUriForFile(
                self.currentActivity.getApplicationContext(),
                self.currentActivity.getApplicationContext().getPackageName(),
                photo_file)

            parcelable = cast('android.os.Parcelable', photo_uri)

            activity.unbind(on_activity_result=self.on_activity_result)
            activity.bind(on_activity_result=self.on_activity_result)

            camera_intent.putExtra(MediaStore.EXTRA_OUTPUT, parcelable)
            self.currentActivity.startActivityForResult(
                camera_intent, self.CAMERA_REQUEST_CODE)
Esempio n. 14
0
    def on_activity_result(self, requestCode, resultCode, intent):
        activity.unbind(on_activity_result=self.on_activity_result)

        if requestCode != 0x100:
            return

        if resultCode != -1:
            self.on_complete([], True)
            return

        uri = []
        data = intent.getClipData()
        if not data:
            return
        for x in range(data.getItemCount()):
            item = data.getItemAt(x)
            urI = item.getUri()
            uri.append(urI)

        PythonActivity.toastError("Loading {} image/s".format(len(uri)))
        print 'calling get path form uri ', uri
        th = threading.Thread(target=self._get_path_from_URI, args=[uri])
        th.start()
Esempio n. 15
0
    def on_activity_result(self, requestCode, resultCode, intent):
        activity.unbind(on_activity_result=self.on_activity_result)

        if requestCode != 0x100:
            return

        if resultCode != -1:
            self.on_complete([], True)
            return

        uri = []
        data = intent.getClipData()
        if not data:
            return
        for x in range(data.getItemCount()):
            item = data.getItemAt(x)
            urI = item.getUri()
            uri.append(urI)

        PythonActivity.toastError("Loading {} image/s".format(len(uri)))
        print 'calling get path form uri ', uri
        th = threading.Thread(target=self._get_path_from_URI, args=[uri])
        th.start()
Esempio n. 16
0
 def __del__(self):
     activity.unbind(on_activity_result=self.intent_callback)
Esempio n. 17
0
 def nfc_disable(self):
     print 'nfc_disable()'
     activity.unbind(on_new_intent=self.on_new_intent)
Esempio n. 18
0
 def _on_activity_result(self, requestCode, resultCode, intent):
     if requestCode != 0x123:
         return
     activity1.unbind(on_activity_result=self._on_activity_result)
     if self.on_complete(self.filename):
         self._remove(self.filename)
Esempio n. 19
0
def nfc_disable(self):
    activity.unbind(on_new_intent=self.on_new_intent)
    # ...