Giter Site home page Giter Site logo

Comments (3)

Android-for-Python avatar Android-for-Python commented on August 20, 2024

Yes, that last sentence "You must.." says, perhaps not in the clearest way possible, what you did.

There is an example of this 3 subsections below https://github.com/Android-for-Python/Android-for-Python-Users#java-listener-class , at a minimum adding a reference would be a good idea.

That section in turn references a full BroadcastReceiver (!) example nearby.

EDIT: Users seem to make a mental distinction between implementing in Python and implementing in Java - using Pyjnius is viewed as implementing in Python. Implementing in Java is viewed as a different task - possibly unfamiliar language and buildozer options. So the intent here was dismiss that second task and deal with it separately. Writing this document I have learned to never underestimate the inexperience of the users.

from android-for-python-users.

Julian-O avatar Julian-O commented on August 20, 2024
  • I make a distinction between writing code that uses Python syntax and code that uses Java syntax (e.g. "public interface"). If you are suggesting that using pyjnius's autoclass and decorators is considered "writing the implementation in Java", then I think we need to edit the document to make the definitions clearer.

  • About 3 years ago, I implemented a number of Listeners.
    I did it differently to you. (I assume I pinched my approach from somewhere else online.) You have what is clearly Java code. I don't. I have some pyjnius references:

class OnAudioFocusChangeListener(PythonJavaClass):
    # https://developer.android.com/reference/android/media/
    #     AudioManager.OnAudioFocusChangeListener
    __javainterfaces__ = ("android/media/AudioManager$OnAudioFocusChangeListener",)

    def __init__(self, callback):
        super().__init__()
        self.callback = callback

    @java_method("(I)V")
    def onAudioFocusChange(self, focusChange):
        self.callback(focusChange)

This seems more straightforward than your approach (especially because I don't need to relearn Java syntax after successfully avoiding it since last century), but I know I am naïve in this domain, so I wonder if I am missing something!

  • After implementing several listener interfaces, I spent hours and hours on dealing with BroadcastReceiver, because it looks and acts like a Listener class, but for some reason it wasn't defined in Android like all the other Listener classes. My first attempts to treat it the same failed. I needed to take a novel implementation approach.

So, when you point me to the Listener implementation, I go "No! No! This is different. For reasons I don't remember well."

Aside: I have only just clicked that it is the same class as in p4a's undocumented android package, and I should have used that instead. I am a bit mad about that.

from android-for-python-users.

Android-for-Python avatar Android-for-Python commented on August 20, 2024

There is more than one way to skin a cat. The 'best' way is often subjective.

from android-for-python-users.

Related Issues (8)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.