Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Activity
    Russell Keith-Magee
    @freakboy3742
    Sure - makes sense. We can wrap that in a Future, and provide an async API wrapper around the call.
    Tom
    @t-arn
    If you use this SAF (storage access framework) then you also need to use SAF for reading / writing the files. You'll find example code in the link I posted
    Tom
    @t-arn
    The URI for the file /storage/emulated/0/Download/toga.pdf is this: content://com.android.externalstorage.documents/document/primary%3ADownload%2Ftoga.pdf
    So, you will not be able to read this file using standard Python IO methods. Maybe, I should still follow my original idea and implement a pure Python file browser using DetailedList...
    Russell Keith-Magee
    @freakboy3742
    Sure, but it should be possible to convert the URI into a fixed filename right?
    Tom
    @t-arn
    I also don't know if the native file browser can be used to choose a directory intead of a file...
    Russell Keith-Magee
    @freakboy3742
    Android's file browser definitely does - I saw that as one of the options to the Intent.
    Also - Context.getContentResolver() would seem to be the place that can convert the URI into other forms
    Tom
    @t-arn
    ok, then this might be way to go. What do need to make this work?
    Russell Keith-Magee
    @freakboy3742
    In what sense? What are you looking for? Guidance on how to implement it?
    Tom
    @t-arn
    Is Toga ready for implementing this or is the async PR you mentioned a prerequisite?
    Russell Keith-Magee
    @freakboy3742
    It's ready to go right now. The async PR is more of a design decision where a decision is needed (although I think the decision has pretty much been made at this point). Android's existing dialogs are already async - that was one of the stimuli for that PR.
    Tom
    @t-arn
    I quickly checked the toga-android code: it seems that we haven't used any Intents so far. And: since we need to implement the onActivityResult method in MainActivity.java, we will also need to modify Briefcase, right?
    Russell Keith-Magee
    @freakboy3742
    I'm a little rusty on Android programming, so I'm not 100% sure - but we need to avoid that if at all possible.
    unless it's going to be a generic facility that can be used by any toolkit.
    Are you saying that the only way to capture the "activity finished" callback is with a method on MainActivity?
    Tom
    @t-arn
    Yes, that is pretty much my impression
    Russell Keith-Magee
    @freakboy3742
    Huh. So what happens if you fire 2 separate intents?
    How do you tell them apart on the return?
    Tom
    @t-arn
    Then, every Intent has its own code and you handle all the codes in the onActivityResult
    Russell Keith-Magee
    @freakboy3742
    What if you call 2 OPEN_REQUEST_CODE intents?
    Tom
    @t-arn
    see above if requestCode == OPEN_REQUEST_CODE
    OPEN_REQUEST_CODE is a static variable that you define yourself
    sorry, the code was not complete...
    Russell Keith-Magee
    @freakboy3742
    Ah - OK; so we can allocate anything static that we want; it's not a system constant.
    Tom
    @t-arn
    yes, exactly
    Russell Keith-Magee
    @freakboy3742
    ok - so it sounds like the Android backend is going to need a generic mechanism to invoke intents and register a callback.
    Tom
    @t-arn
    The Toga call open_file_dialog is synchronous, but the android implementation will be async. So we need some kind of async wrapper. Do you have example how to handle this?
    Yes, I thought about this generic approach as well
    Like having a map that you can fill and in onActivityResult you loop over this map
    Russell Keith-Magee
    @freakboy3742
    Yeah - hopefully a keyed lookup rather than a loop, but that's the idea.
    Tom
    @t-arn
    Yeah, with the generic approach, we could then handle any async Intent which will be a huge benefit on Android!
    How does Briefcase create the MainActivity.java? Seems to be app specific, not just some static code...
    Russell Keith-Magee
    @freakboy3742
    The actual java file is generated as part of the Briefcase template. It
    It's only application specific in the sense that references to the app name/bundle are replaced.
    It's only purpose is to bootstrap the Python code, and install hooks that have to be at the Activity level.
    Tom
    @t-arn
    ah ok. Not a big deal then to add some generic code there, right?
    Russell Keith-Magee
    @freakboy3742
    As long as it's generic and defers to the Python code ASAP, that's fine.
    (e.g., the mapping lookup should be python-side, not Java side)
    Tom
    @t-arn
    hmm...I can see the way how to do the hard-coded way with the request codes. As for the generic approach, I don't quite see yet how to do this, because I don't know how to pass a callable into MainActivity and have it executed when the request code matches.
    Russell Keith-Magee
    @freakboy3742
    Don't pass in anything to MainActivity.
    Tom
    @t-arn
    I've gotta go - talk to you later
    Russell Keith-Magee
    @freakboy3742
    On MainActivity, define a stub method that immediately defers to a Python method
    then do the lookup/callback on the Python side.
    Tom
    @t-arn
    ok, yes that sounds far easier. Will I be able to handle the returned Intent resultData in Python?
    Tom
    @t-arn

    so, for the generic Intent mechanism, we'd have something like this in MainActivity.java:

    public void onActivityResult(int requestCode, int resultCode, Intent resultData) 
    {
       super.onActivityResult(requestCode, resultCode, resultData);
       pythonApp.onActivityResult(requestCode, resultCode, resultData);
    }

    and in app.py:

    def onActivityResult(self, requestCode, resultcode, resultData):
       if resultCode == MainActivity.RESULT_OK:
          # lookup the requestCode to get the callable
          # call the callable and pass resultData to it

    and then use this mechanism to implement the open_file_dialog

    Tom
    @t-arn
    and we'd need a method in MainActivity.java which allows us to call any Intent:
    public void invokeIntent(Intent myIntent, int requestCode)
    {
       startActivityForResult(myIntent, requestCode);
    }
    Tom
    @t-arn
    maybe, invokeIntent is not needed at all - we could probably also call MainActivity.startActivityForResult directly from Python.
    @freakboy3742 How do handle the needed changes in MainActivity.java? Could you modify the Briefcase template as needed?