Esempio n. 1
0
    def _open_file(self, **kwargs):
        '''
        Running Android Activity is non-blocking and the only call
        that blocks is onActivityResult running in GUI thread

        .. versionadded:: 1.4.0
        '''

        # set up selection handler
        # startActivityForResult is async
        # onActivityResult is sync
        self._handle_selection = kwargs.pop(
            'on_selection', self._handle_selection
        )

        # create Intent for opening
        file_intent = Intent(Intent.ACTION_GET_CONTENT)
        file_intent.setType('*/*')
        file_intent.addCategory(
            Intent.CATEGORY_OPENABLE
        )

        # bind a function for a response from filechooser activity
        activity.bind(on_activity_result=self._on_activity_result)

        # start a new activity from PythonActivity
        # which creates a filechooser via intent
        mActivity.startActivityForResult(
            Intent.createChooser(file_intent, cast(
                'java.lang.CharSequence',
                String("FileChooser")
            )),
            self.select_code
        )
Esempio n. 2
0
    def capture(self):
        def create_img_file():
            File = autoclass('java.io.File')
            storageDir = Context.getExternalFilesDir(
                Environment.DIRECTORY_PICTURES)

            imageFile = File(storageDir,
                             f"{int(datetime.now().timestamp())}.png")
            imageFile.createNewFile()
            return imageFile

        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)

        photoFile = create_img_file()
        self.filepath = photoFile.getAbsolutePath()
        photoUri = FileProvider.getUriForFile(
            Context.getApplicationContext(),
            "com.heattheatr.kitchen_sink.fileprovider", photoFile)

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

        intent.putExtra(MediaStore.EXTRA_OUTPUT, parcelable)
        mActivity.startActivityForResult(intent, 0x123)
Esempio n. 3
0
 def take_picture(self):
     intent = Intent(MediaStore.ACTION_IMAGE_CAPTURE)
     self.last_fn = self.get_filename()
     self.uri = Uri.parse('file://' + self.last_fn)
     self.uri = cast('android.os.Parcelable', self.uri)
     intent.putExtra(MediaStore.EXTRA_OUTPUT, self.uri)
     mActivity.startActivityForResult(intent, 0x123)
Esempio n. 4
0
    def _open_file(self, **kwargs):
        '''
        Running Android Activity is non-blocking and the only call
        that blocks is onActivityResult running in GUI thread

        .. versionadded:: 1.4.0
        '''

        # set up selection handler
        # startActivityForResult is async
        # onActivityResult is sync
        self._handle_selection = kwargs.pop('on_selection',
                                            self._handle_selection)
        self.selected_mime_type = kwargs.pop(
            "filters")[0] if "filters" in kwargs else ""

        # create Intent for opening
        file_intent = Intent(Intent.ACTION_GET_CONTENT)
        if not self.selected_mime_type or type(self.selected_mime_type) != str or\
                self.selected_mime_type not in self.mime_type:
            file_intent.setType("*/*")
        else:
            file_intent.setType(self.mime_type[self.selected_mime_type])
        file_intent.addCategory(Intent.CATEGORY_OPENABLE)

        # start a new activity from PythonActivity
        # which creates a filechooser via intent
        mActivity.startActivityForResult(
            Intent.createChooser(
                file_intent,
                cast('java.lang.CharSequence', String("FileChooser"))),
            self.select_code)
Esempio n. 5
0
    def _open_file(self, **kwargs):
        '''
        Running Android Activity is non-blocking and the only call
        that blocks is onActivityResult running in GUI thread

        .. versionadded:: 1.4.0
        '''

        # set up selection handler
        # startActivityForResult is async
        # onActivityResult is sync
        self._handle_selection = kwargs.pop('on_selection',
                                            self._handle_selection)

        # create Intent for opening
        file_intent = Intent(Intent.ACTION_GET_CONTENT)
        file_intent.setType('*/*')
        file_intent.addCategory(Intent.CATEGORY_OPENABLE)

        # bind a function for a response from filechooser activity
        activity.bind(on_activity_result=self._on_activity_result)

        # start a new activity from PythonActivity
        # which creates a filechooser via intent
        mActivity.startActivityForResult(
            Intent.createChooser(
                file_intent,
                cast('java.lang.CharSequence', String("FileChooser"))),
            self.select_code)
Esempio n. 6
0
 def take_picture(self):
     intent = Intent(MediaStore.ACTION_IMAGE_CAPTURE)
     self.last_fn = self.get_filename()
     self.uri = Uri.parse('file://' + self.last_fn)
     self.uri = cast('android.os.Parcelable', self.uri)
     intent.putExtra(MediaStore.EXTRA_OUTPUT, self.uri)
     mActivity.startActivityForResult(intent, 0x123)
Esempio n. 7
0
    def _open_file(self, **kwargs):
        '''
        Running Android Activity is non-blocking and the only call
        that blocks is onActivityResult running in GUI thread

        .. versionadded:: 1.4.0
        '''

        # set up selection handler
        # startActivityForResult is async
        # onActivityResult is sync
        self._handle_selection = kwargs.pop(
            'on_selection', self._handle_selection
        )

        # create Intent for opening
        file_intent = Intent(Intent.ACTION_OPEN_DOCUMENT)
        file_intent.setType('*/*')
        file_intent.addCategory(
            Intent.CATEGORY_OPENABLE
        )
        if self.multiple:
            file_intent.putExtra(Intent.EXTRA_ALLOW_MULTIPLE, True)

        # start a new activity from PythonActivity
        # which creates a filechooser via intent
        mActivity.startActivityForResult(
            Intent.createChooser(file_intent, cast(
                'java.lang.CharSequence',
                String("FileChooser")
            )),
            self.select_code
        )
Esempio n. 8
0
 def take_shot(self, filename=''):
     self.shot_taken = False
     self.image_path = self.new_photo_path(self.folder_path, filename)
     intent = Intent(MediaStore.ACTION_IMAGE_CAPTURE)
     self.uri = Uri.parse('file://' + self.image_path)
     self.uri = cast('android.os.Parcelable', self.uri)
     intent.putExtra(MediaStore.EXTRA_OUTPUT, self.uri)
     mActivity.startActivityForResult(intent, 0x123)
Esempio n. 9
0
 def pick_file(self, MIME_type='*/*'):
     try:
         self.msg = "Choose a file"
         self.intent = Intent(Intent.ACTION_GET_CONTENT)
         self.intent.setType(MIME_type)
         self.intent2 = Intent.createChooser(self.intent, JString(self.msg))
         mActivity.startActivityForResult(self.intent2, self.REQUEST_CODE)
         Clock.schedule_once(self.begone_you_black_screen)
     except Exception as e:
         print('ERROR Picker.pick_file():\n' + str(e))
Esempio n. 10
0
 def take_picture(self):
     intent = Intent(MediaStore.ACTION_IMAGE_CAPTURE)
     self.last_fn = self.get_filename()
     self.uri = Uri.parse('file://' + self.last_fn)
     self.uri = cast('android.os.Parcelable', self.uri)
     # We can write to app folder or CACHE with:
     # https://stackoverflow.com/a/56946376
     # https://developer.android.com/Con/android/support/v4/content/FileProvider#GetUri
     # https://github.com/mobile-insight/mobileinsight-mobile/blob/master/app/check_update.py
     intent.putExtra(MediaStore.EXTRA_OUTPUT, self.uri)
     mActivity.startActivityForResult(intent, 0x123)
Esempio n. 11
0
    def take_picture(self):
        def create_img_file():
            File = autoclass('java.io.File')
            storageDir = Context.getExternalFilesDir(
                Environment.DIRECTORY_PICTURES)

            imageFile = File(storageDir, "temp.jpg")
            imageFile.createNewFile()
            return imageFile

        intent = Intent(MediaStore.ACTION_IMAGE_CAPTURE)

        photoFile = create_img_file()
        photoUri = FileProvider.getUriForFile(
            Context.getApplicationContext(),
            "org.test.takepicture.fileprovider", photoFile)

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

        intent.putExtra(MediaStore.EXTRA_OUTPUT, parcelable)
        mActivity.startActivityForResult(intent, 0x123)