Code Monkey home page Code Monkey logo

Comments (16)

vanous avatar vanous commented on May 23, 2024 1

Thank you very much! now i am tempted not to look at the todo and try it myself first :))

from beeware-android-template.

eliasdorneles avatar eliasdorneles commented on May 23, 2024 1

@vanous I'm going to close this ticket, since there is a complete working example for sqlite in the Todo app. Thanks!

from beeware-android-template.

eliasdorneles avatar eliasdorneles commented on May 23, 2024

Hello @vanous !
Thanks, cool to know you're trying out this stuff! :)

There really isn't much documentation just yet, I've been writing these example apps with the goal of both dogfooding VOC for Android apps and bootstrapping documentation for this approach.

Essentially, what exists so far are these example apps I've been building (besides the template) and Toga-Android's source code.

VOC doesn't have much documentation on this Java-interoperability stuff yet, I've just opened a ticket for it: beeware/voc#689

About your specific problem: to use a sqlite database within Android, instead of managing creating/opening the file in your code, I think you'd be better using the SQLiteOpenHelper class which does that for you, you just provide a name for the DB -- that's what I intend to do for that little todo app.

from beeware-android-template.

vanous avatar vanous commented on May 23, 2024

Thank you very much. I will try this.

from beeware-android-template.

vanous avatar vanous commented on May 23, 2024

I have to admit, i have no idea what i am even attempting... :) :(

I can imagine i must create a new class to extend the SQLiteOpenHelper, then create methods top onCreate or onOpen but... :/

class DBHelper(implements=android.database.sqlite.SQLiteOpenHelper):
    def __init__(self, callback, *args, **kwargs):
        self.callback = callback
        self.args = args
        self.kwargs = kwargs

    def onOpen(self,db:android.database.sqlite.SQLiteDatabase) -> db:

i have been searching for some docs, examples etc... but I will probably have to wait for your todo app :)))

from beeware-android-template.

eliasdorneles avatar eliasdorneles commented on May 23, 2024

Hey @vanous -- haha, yeah, I'm very familiar with that feeling, as you might imagine! :)

You're in the right direction, but there are some things missing:

  1. SQLiteOpenHelper is an abstract class, not an interface, so you have to use extend instead of implements

  2. To generate the proper constructor, you gotta used the @super trick that generates a Java-compatible constructor. This trick is maybe best documented currently in a comment section in the code.

Essentially, you'll want something looking like this:

class DBHelper(extends=android.database.sqlite.SQLiteOpenHelper):

    # use the @super trick to create a Java constructor that passes
    # some hardcoded values to the parent constructor
    @super({
        context: android.content.Context,
        "com.example.vanous": java.lang.String,
        None: android.database.sqlite.SQLiteDatabase[CursorFactory],
        1: int
    })
    def __init__(self, context):
        print('starting DBHelper')

You'll also want to implement the onCreate and onUpgrade methods that are required by that abstract class:

def onCreate(self, db: android.database.sqlite.SQLiteDatabase) -> void:
    # some code here...

def onUpgrade(self, db: android.database.sqlite.SQLiteDatabase,
              oldVersion: int, newVersion: int) -> void:
    pass

I'll try to incorporate something like this to that todo app, but you can keep digging this if you want. =)

To have a look what the implementations of those methods may look like, if you're not scared of a little Java, you may have a look at this tutorial: https://www.sitepoint.com/starting-android-development-creating-todo-app/

from beeware-android-template.

eliasdorneles avatar eliasdorneles commented on May 23, 2024

I've just commited a working example to the todo app: https://github.com/eliasdorneles/todoapp-voc/blob/aa9794cf5e93174d932751808a3789309e8bec42/todoapp/app.py#L88-L156

Let me know how it goes for you!

from beeware-android-template.

eliasdorneles avatar eliasdorneles commented on May 23, 2024

now i am tempted not to look at the todo and try it myself first :))

it'll be a valid learning experience, go for it!

If you do that, it would really awesome if you could also take notes of the problems you face and register here later.
It would be great for documentation. :)

Here, I'll start, two problems I run into often are:

  1. forgetting to put the self in the method declaration and then getting an error saying the method doesn't exist or something weird like that -- this is because the signatures didn't match, so Java doesn't find the method

  2. forgetting to pass the AndroidContext (self._activity) to a class that needs it, and then getting a fun error like Caused by: RuntimeError: No candidate constructor found for signature (); tried []

from beeware-android-template.

vanous avatar vanous commented on May 23, 2024

do you always have to rerun gradle and install apk or can you somehow run python code directly? (i can imagine you have to re-voc-transpile, but i rather ask)...

from beeware-android-template.

eliasdorneles avatar eliasdorneles commented on May 23, 2024

Sadly there is no way to eval Python code directly in Android, no.

What I do is, after I run python setup.py android the first time (which builds the android/ directory and everything), I just run yes N | python setup.py android --start the next times.
With the --start flag, it will run gradle for you.

from beeware-android-template.

vanous avatar vanous commented on May 23, 2024

Nice trick with the --start, i just run gradlew, but had to tweak some stuff around. One more question please: is it possible to use any python imports in briefcase converted app? Not even compiled ones, but stuff like json or requests? Obviously it doesn't work for me so perhaps there is a trick for this? Thank you very much.

from beeware-android-template.

eliasdorneles avatar eliasdorneles commented on May 23, 2024

Hi there!
Currently the list of imports that you can use is seriously limited, because VOC still doesn't support the full standard library (tbh, i think not even half of it).
So at the moment, your best bet would be to do requests and JSON handling through Java libraries and Android APIs -- at least until we can compile and run more of the stdlib with VOC.

from beeware-android-template.

vanous avatar vanous commented on May 23, 2024

Thank you very much! This explains what role briefcase plays in the packaging and voc, included in by briefcase, in compiling :)

from beeware-android-template.

eliasdorneles avatar eliasdorneles commented on May 23, 2024

@vanous you got it :)

from beeware-android-template.

rsemenoff avatar rsemenoff commented on May 23, 2024

I just discovered this, sorry if this is a naive question...but is there a way to know what has yet to be implemented? I'm using Sympy and Numpy intended to be incorporate into an android studio project rather than create whole app in python. Will VOC as it stands now, work for me ?

from beeware-android-template.

eliasdorneles avatar eliasdorneles commented on May 23, 2024

@rsemenoff Numpy would not work w/ VOC, because it's not pure Python.
VOC needs pure Python code to compile into JVM bytecode.

from beeware-android-template.

Related Issues (6)

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.