Full Python app on Android
In this article I would like to tell you about how to create a full app in Python for Android. No, this is not another manual to create a script for sl4a, this tutorial on creating a complete application with the UI, possibility to build apk and put it on the Android Market. At the same time I would like to brag on my first app on google.play, it's not hello world, useful application for photographers, although narrowly specialized.
Start the story with perhaps the most application and complete stories about how it was done.
isortViewer
I as a photographer have to spend a lot of time sorting and selecting photos. Not always want to sit behind a computer when you have a laptop, smartphone or tablet, but to copy dozens of gigabytes of raw or jpeg files, and then sync with a work computer — a dubious pleasure. That's why I created a program isortManager and isortViewer, which greatly facilitated my work on sorting and selecting the pictures. Now to do the selection and sorting of photos I can lying on the
Copy-paste of the description and a couple of screenshots:
isortViewer program for photographers, which allows you to easily and quickly select and sort the thousands of photos (raw or jpg) with photo shoots on your android smartphones and tablets. Thus, there is no need to copy dozens of gigabytes of raw or jpg files to the device. Just use a free program isortManager for computer, which will save an all in one a small project file:
1. Download and run isortManager with official website;
2. Create a project and add the folder with photos. Supported formats: jpg and raw (cr2, nef, orf, etc.). In the end you'll have a small project file (about 150 MB for a few thousand pictures, whether JPEG or raw format);
3. Copy to your android device the project file, open in isortViewer. You can tag photos "for deletion", and also, to put ratings from 1 to 5 stars;
4. After that, copy the project file back and apply the changes to isortManager. Also delete the selected photos, you can copy or move selected photos. For example, a photo with "5 stars" you can copy the folder "masterpieces", and "1 star" move to folder "trash".
The application is absolutely free and available on google.play, however a donation is appreciated.
Sources are available on the official website!
How it was done
Because
isortManager
With isortManager for PC no problems, the creation of a GUI build on windows has long been tested and it works very simply: using dcraw rips the jpg previews from raw files, resized of using PIL and put it in a single file with a fairly simple structure. Was invented your isolated with a container for storing photos and metadata (the full path to the photo marked as "delete" and mark the rating), since, for example, zip or tar format, you can't change one file in the archive (metadata) require repackaging all the files. Files are simply written one after another in a row in the metadata block (repr ordinary Python dictionary) at the end preserved the offset of the beginning of the file, plus the end-of-file is written the size of the metadata block. GUI written in Tkinter (I love it for the speed of writing and for the small size of the final build), here's a screenshot:
And Yes, it works on linux, and even faster than on windows )
isortViewer for android
I just found two ways to make python app to run as a full app on android is pygame for android and project kivy.
Pygame is more low level, all the UI would have to draw manually, which was time-consuming, so I chose the kivy framework. So:
Kivy
This is a wonderful freimark to write an application for windows, linux, MacOS, android and iOS. Supported multi-touch UI reutersa using OpenGL, so should work with hardware acceleration. To see the widgets you need to install the demo application Kivy Showcase. It is possible to use some platform-specific functions, such as vibration or accelerometer, using the android module.
For development I would recommend to use linux, the more, apk going in this OS.
Hello World looks like this:
the
import kivy
kivy.require('1.0.6') # replace with your current kivy version !
from kivy.app import App
from kivy.uix.button import Button
class MyApp(App):
def build(self):
return Button(text='Hello World')
if __name__ == '__main__':
MyApp().run()
And this code will work on all announced platforms. No need to test the application in the emulator. Simply run the script in your favorite IDE and see the result on your computer screen, no delays on the compilation, emulator, etc. If you want to see how it will look directly on your device, just install Kivy Launcher, copy the project files to the memory card and start. Debit in this case you can use adb logcat.
If you use android, which is not on PC, but I want to launch an app not only for android, vospolzuytes this:
the
try:
import android
except ImportError:
android=None
...
if android:
android.vibrate(0.05)
Build apk is quite simple and is described on this page. After Assembly, release, enough to sign your app (I used this manual) and upload to google play.
Pros kivy:
the
-
the
- Fast development for various platforms, virtually without changes in the code. the
- Available widgets the
- High-speed operation. All resource-intensive made in the modules. The python interpreter runs native on android. the
- Framework includes many tools such as animation, caching, etc.
upd: Access camera, clipboard, microphone. Write your own video player can literally 20 lines.
Cons kivy:
the
-
the
- Large size apk file. A project with 300 KB of resources (scripts, graphics) is going to 7 MB apk. Although, I think, it is possible it as that to optimize. the
- and the Inability (yet) to restore after minimizing the app
In the next article, I will tell more about the process of writing applications from scratch, razzhevyvaya each line of code.
I would like to stop holivary on the topic "only for android java, python not needed." I believe no matter what technology is "under the hood", so that the main application was of high quality.
Scope kivy can be overwhelming. Now I have several applications written under the order where python with kivy framwork showed a good side. For example, in exactly one hour, was written an application for network service centers. The app runs in kiosk mode and installed on the cheap Chinese tablets that hang in the lobby. The customer dials the number of the order, then on the WiFi tablet connects to the server and reports the status of the order.
Комментарии
Отправить комментарий