You are here: Hello » Tutorials

Tutorials

Here is a list of tutorials written by me. Hope you will find something usefull

Android

Compile APK online

It was long time i was dreaming about ability to compile apk online. So this blog post (tutorial) will be how to prepare C9 or Goorm online IDE or any similar based on ubuntu linux to be able to develop online.

First of all, create new empty ubuntu box and resize it to 1Gb RAM and 5GB storage. Simple APK compile stull will require about 1GB of storage, but if you decide to go on gradle dependency management system- storage will grow to 2.5GB.

I prepending everyhing with sudo command, in case any permission will be missing.

→ Read more...

AppInventor

Multiple Screens

All Android graphical user inteface elements are fitted into Screens. Your simple application may have just one screen. More sophisticated apps may have multiple screens. For example About, Help or Settings screens together with main app screen. Sometimes you need to pass information from one screen to another. This tutorial will cover this. It is about screens usage and passing data between them.

→ Read more...

2014/02/04 20:18 · 1 Comment

Radio Button in AppInventor

screenshot.02-04-2012_2010.55.59.jpgThere is no RadioButton in AppInventor's components list, so you have to build it yourself. I've saw youtube tutorial how to build RadioButtons based on CheckBoxes. I didn't realy liked that work-a-round, though it works. But that tutorial trow me idea how to build more RadioButton looking ones, out from Images and regular Buttons

→ Read more...

Separator

separator2.jpg If your applications requires to separate different parts of GUI elements, you can use separator for this. AppInventor does not have this by default, so you have to work-a-round it. Here is how: To create a separator in your android app, just use simple Label component. Set BackgroundColor to black (or whatever else that fits your theme), empty the text field, width- Fill parent, and Height- 1 pixel. And here you have a separator in your application.

2014/02/04 20:18

Cordova

JQuery getScript not working in Cordova

Creating Cordova (formerly known as PhoneGap ) application aimed to work with 1.6+ Android I've faced strange problem. Android 4.0.* versions devices does not load script via jQuery command getScript. And this was only in 4.0.* version devices

→ Read more...

2014/02/05 16:31 · 0 Comments

Python

Pure python and very simple event management library

In event driven programming events are crucial. My requirements was Micropython platform on ESP32 micro-controller, so i could not use any other events library out-there. I've stumbled one very basic, very simple library and gave it a try… and it worked out-of-the-box for my case. When testing various event management libs out there I've stumbled on something similar, but it did not worked within classes. Python is nothing but classes everywhere :)

I was testing and extended this very simple python script, that perfectly works as main element in event driven development.

Strengths of library:

  • Observer can be declared before event type is created
  • Events can be fired even if there is no observers.
  • Works as pure python script
  • Works on micropython platform
  • Event name can be any string

I'm using this solution for event for timer, that fires each second and observe “ticker” where i need to update clock. I use clock in multiple places in my micropython script and i can get away with just one hardware timer used.

Honorable mentions goes to Pithikos from StackOverflow this answer

I have extended this library with possibility to forget event.

EventObserver.py
class Observer():
    _observers = []
 
    def __init__(self):
        self._observers.append(self)
        self._observed_events = []
 
    def observe(self, event_name, callback_fn):
        self._observed_events.append({'event_name': event_name, 'callback_fn': callback_fn})
 
    def forget(self, event_name):
        for dict_item in self._observed_events:
            for key, val in dict_item.items():
                if val == event_name:
                    self._observed_events.remove(dict_item)
 
 
class Event():
    def __init__(self, event_name, *callback_args):
        for observer in Observer._observers:
            for observable in observer._observed_events:
                if observable['event_name'] == event_name:
                    observable['callback_fn'](*callback_args)

Here is example of how to use this library

example.py
import EventObserver
 
# class object MUST inherit Observer object if you use it within class
class Room(Observer):
    def __init__(self):
        print("Room is ready.")
        Observer.__init__(self)  # DON'T FORGET THIS
        # observer can be declared already in class init method with following line
        # this.observe('someone sneezed', this.someone_sneezed)
 
    def someone_arrived(self, who):
        print(who + " has arrived!")
 
    def someone_sneezed(self, who):
        print(who + " has just sneezed!")
 
 
# Observe for specific event
room = Room()
room.observe('someone arrived', room.someone_arrived)
 
# Fire some events
Event('someone left', 'John')       # no events are attached to event "someone left" 
Event('someone arrived', 'Lenard')  # will output "Lenard has arrived!"
Event('someone sneezed', 'Jenny')   # will output "Jenny has just sneezed!"
 
# Remove known event
room.forget('someone arrived')
 
# no events based on 'someone arrived' will be fired
'''

Quick tips

2014/02/04 20:18  
Except where otherwise noted, content on this wiki is licensed under the following license: CC Attribution-Noncommercial-Share Alike 3.0 Unported

Hey.lt - Nemokamas lankytojų skaitliukas XHTML