Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

static_proxy button impossible?? #1121

Closed
lawiparadise opened this issue Mar 21, 2024 · 1 comment
Closed

static_proxy button impossible?? #1121

lawiparadise opened this issue Mar 21, 2024 · 1 comment

Comments

@lawiparadise
Copy link

I run demo app and I saw below MenuFragment is changed to java class(build/python/proxies/..)

class MenuFragment(static_proxy(PreferenceFragmentCompat)):

so I tried to make Button python class but failed

from android.content import Context
from android.widget import Button
from android.view import View
class PyBtn(static_proxy(Button, View.OnClickListener)):

    @constructor([Context])
    def __init__(self, context):
        pass

    @Override(jvoid, [View])
    def onClick(self, p0):
        pass

error message is here

D:\h\2023\dev\and\ws\CloiBlockCoding\app\build\python\proxies\debug\button\PyBtn.java:16: error: no suitable constructor found for Button(no arguments)
    public PyBtn(android.content.Context arg0) {
                                               ^
    constructor Button.Button(Context) is not applicable
      (actual and formal argument lists differ in length)
    constructor Button.Button(Context,AttributeSet) is not applicable
      (actual and formal argument lists differ in length)
    constructor Button.Button(Context,AttributeSet,int) is not applicable
      (actual and formal argument lists differ in length)
    constructor Button.Button(Context,AttributeSet,int,int) is not applicable
      (actual and formal argument lists differ in length)

maybe Context can not be passed to @constructor

but how other python class can be changed to java class??
they don't have init constructor

class MenuFragment(static_proxy(PreferenceFragmentCompat)):
    @Override(jvoid, [Bundle, String])
    def onCreatePreferences(self, state, rootKey):
        self.addPreferencesFromResource(R.xml.activity_ui_demo)

        from android.media import AudioManager, SoundPool
        self.sound_pool = SoundPool(1, AudioManager.STREAM_MUSIC, 0)
        self.sound_id = self.sound_pool.load(self.getActivity(), R.raw.sound, 1)

    @Override(jboolean, [Preference])
    def onPreferenceTreeClick(self, pref):
        method = getattr(self, pref.getKey())
        method(self.getActivity())
        return True

    def demo_dialog(self, activity):
         ColorDialog().show(self.getFragmentManager(), "color")

    def demo_toast(self, activity):
        from android.widget import Toast
        Toast.makeText(activity, R.string.demo_toast_text,
                       Toast.LENGTH_SHORT).show()

    def demo_sound(self, activity):
        self.sound_pool.play(self.sound_id, 1, 1, 0, 0, 1)

please help me..TT

thank you!!

@mhsmith
Copy link
Member

mhsmith commented Mar 21, 2024

Unfortunately it's not currently possible to implement a View in Python, because static_proxy can't pass through any constructor arguments. For updates on this, please subscribe to #10.

@mhsmith mhsmith closed this as completed Mar 31, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants