Pretty Painter is my first Android app.

    Pretty painter


    Hello! I would like to share with you my experience in creating the first Android application. And if you have been looking closely at this platform for a long time, but still for some reason do not dare to start developing your applications, then I hope my topic will push you to this. Under the cut, there are five reasons why you should not doubt, and it's time to act, and a few more interesting points.

    Initial data

    Creative web developer. Knowledge:
    • HTML / CSS - Above Average
    • JS - Medium
    • PHP - above average

    + very little knowledge in C #. Where does Java ask the reader? Alas, I could not boast of knowledge of this language before development. And here is the first reason for you to start development now - "It is not necessary to read a thick Java manual . "

    Book: “Google Android. Programming for mobile devices. " Sure No, if you are friends with English, enough documentation on the site. If all the same, everything is bad with English, as, for example, I have my advice to you, do not read the book from cover to cover, beat off all desire. Use as reference material - in this regard, it is very useful. The second reason: "It is not necessary to buy a book if you are fluent in English . "

    Device: HTC Desire Z. What can you do without it? I also thought so, so I saved some money and still bought it, but in the end my application started on the emulator and the final result was the same as on the smartphone. Therefore, the presence of the device is not critical, but if possible, it is better to purchase it. The third reason: "It is not necessary to buy a smartphone . "

    goal

    The goal of conquering the planet was not wondered, sorry. I wanted to make a simple graphic editor ala Paint and understand how android applications are arranged from the inside. I didn’t ask myself with any terms, but looking ahead I’ll say that it took me a little over a week to implement it together with the study.

    Process

    I will not describe the process of installing and setting up a workstation, since this question and its solution have been voiced more than once. To create an editor, I needed to understand how Android works with graphics. And the first thing that came to mind was the games. After all, there is ongoing work with graphics, which I began to study.

    The first request to google I came across such a simple game template . Having unpacked the archive, I began to study the source. Looking at bizarre super instead of parent, declaring classes in a class and overriding methods when creating objects, you involuntarily think about whether to turn back? But we just don't give up.

    Having figured out what's what, I created an application framework based on this template and started to create. Pretty quickly I found an article aboutinteraction with the touch screen and how the child was happy as circles appear under the fingers. I poked on the screen for about an hour, no less. Further, without hesitation, I removed the screen cleaning and left only the render, assuming that now the screen will not be cleaned and, accordingly, everything that the user will draw will be added to the already drawn one. In principle, it was so, but it was somehow strange. With a long press, the circles turned out to be dense, but with a light touch, the left circle flickered. As I understand it, the problem was related to the change of screen buffers, and such a clumsy approach like mine will not work here. Something else was needed.

    The solution was found very on time in the eye-catching source code of Sketcher. It consisted of drawing on a surface based on the image and its subsequent transfer to the working surface. This application was just a golden find, for which many thanks to the author ( WarGoth )! Later I worked on it. And also, without change, I used the color selection dialog. And here’s the fourth reason: “There are a lot of source codes of ready-made Android applications on the network and you won’t be left without food for the mind .

    In principle, half the work was done - the application was already able to draw, it remains to make the interface, menu and form work with the user, which I did for the next four days. I think it makes no sense to describe the whole process, there is really a lot of information about all this. It is not necessary to go far, almost all the necessary knowledge I got here on Habré. In the process, questions arose for which I almost always found answers to stackoverflow . And this is the fifth reason not to postpone the study of the platform in the long box “ Almost all questions arising during development can be answered .

    That’s basically all and I’ll probably become a Captain. But it is, and more often the authors of new articles tell already obvious things, which means that there is already enough information to start. Therefore, stop thinking - it's time to act! Of course, if the community will be interested in any specific points about the application, I can describe them in a separate article, but so far I see no reason for this.

    Total

    It took 8 days from the idea to the creation of the application, for another two days I was preparing the application for launch. During this time, I learned a lot of new things about the platform, language and subtleties of the application and I had a desire to write something else. Of course, my knowledge of layout and programming helped me a lot, but it seems to me that the main thing here, as in any business, is not knowledge, but desire.

    And finally, tips to help avoid a headache:
    • It is not worth storing important variables in threads; they die as soon as possible. I guess I would have known about it if I had read the same Java manual. The solution was to transfer variables to a class of the form
    • If you want your application to respond to screen rotation, think about it in advance, since when you turn the application restarts completely, decide how you will save the state
    • When you programmatically change a selected value in an element of the combiner box (Spinner), the onOptionsItemSelected event is raised and it is not clear where it comes from, from the user or from the application. The solution was to extend the Spinner class and override the OnClick method, which is called when the user selects an item
    • Use styles for layout, this can help a lot when changing the interface or, for example, when localizing, if the labels do not fit on the screen
    • Use resources to store string variables. Then localization will not cause any problems
    • Use the system resources of Android, so as not to produce icons, texts and more. I often met copies of system icons in source codes. Resources are available through android.R in code and android / in markup
    • When using animation, hide objects that require active redrawing, such as Surface, otherwise the animation will shamelessly slow down


    Now about the application itself. This is an ordinary “drawing machine” with the ability to customize brushes, save the result and share it with friends. It does not claim to be genius, but it seems to me that the right to be posted on the market is not devoid of. Please do not judge strictly, after all, the first-born. And now, a pleasant, I hope, surprise. The source code of the application is open . It is not perfect and poorly commented, but over time I will fix it all. Use for health! Thanks for attention. UPD In the comments, they complement me with interesting links and rakes. I think it's worth adding a post: Sources of code for how-it-is-done:

    Download









    Possible rake
    • SQLite is not as fast as it seems. On tens of thousands of records, it begins to shamelessly limp. Only the right indexes can help.

    Also popular now: