Monday, 27 July 2015

Checkboxes and scrollviews

The Udacity course took a swing into the Java side with explanations of variables and accessing the Views so as to manipulate them more programmatically. This to me was a welcome change of pace because I already have a fair understanding of Java. While XML has been a fun way to approach design, I'm happier when I'm making more unique code. The introduction to logic in this series has been with the use of a checkbox. Checking the state of the box also led to some details on inheritance. For the most part this is in explaining how to get a specific type of View by its ID rather than just the default View. What I found interesting was my ideas of how to handle the quantity picker and 0 or overly high values being selected. While at first I thought my  ode did a simple but effective job at preventing the variable from decreasing, I realized later that an if/else block actually gave me a much more elegant solution.

My original code simply had the following:

public void increment() {
     quantity++;

     if(quantity > 100){
          quantity = 100;
     }

     updateDisplay();
}

Not too pretty but it does the job needed. The tutorial suggests adding a Toast if the user attempts to increase the quantity above the limit (here set at 100). This idea seemed fun so I worked that into my code and came to the realization that if the incrementer is only ever going to respond to single digit changes, we could instead just never increment past the upper limit. My code instead now looks like this!

public void increment() {
     if(quantity == 100){
          Toast.makeText(this, "You cannot order more coffees",
          Toast.LENGTH_SHORT).show();
     } else {
          quantity++;
     }

     updateDisplay();
}

It is these little changes to the code that really give me a sense of satisfaction in my own ability. The code that the tutorial uses is a little more heavy but also does the task, but seeing my own implementation and its efficiency is one of those little wins.

The other aspect of the tutorials I have been introduced to is the use of a scrollview as the root view in the xml file. This is a welcome lesson as I have been attempting to move the Java utility I made for my work into an android setting (more as a test of my ability to port an existing app than anything else) and realized I quickly ran out of space on the screen if I had text at a decent size. While I am happy to read a book or website in tiny text, its important that if my app is to be used for quick sessions to check data, the display be a size that utilizes as much of the screen as possible.

Next steps are going to be looking at Intents basics and localization. Since I don't speak any foreign languages, I will be playing around with specific locations of English, such as En-GB and EN-US so that I can get accustomed to adding localization as I go, but also so I can dick around with stereotypical dialects :P

Sunday, 12 July 2015

Nerdy Relief Print

Just a proof for a  two color print I'm working on of R2-D2. Ink on newsprint

Review: Android Development for Beginners on Udacity

My self-learned programming education has always had some tangents, times when I wasn't sure that my current method of learning was not efficient. Lately my progress in Android has been stunted by a lack of the fundamentals that the book I was learning from assumed. My email inbox has also been barraged by a bunch of online learning platforms with all kinds of promotions, and from this I discovered the Udacity course Android Development for Beginners.

I started this course mid week and I have to say I'm hooked. The style of learning is very methodical, and definitely shows that the directors have considered their target audience. While I already have fair amount of familiarity with java, the Android platform has so many quirks that my progress was a little jagged. Going back to basics was a scary proposition, both because it meant having to sift through some basics that will seems ridiculously easy, but also because I didn't want to find out that I missed some super important things.

Either way, I jumped in and committed myself to thinking "no matter what, take every lesson as though you are a newbie". With the mindset of a newbie, it was much easier to listen to some of the explanations of important concepts that seem easy to me now.

I admit to not being very familiar with XML; I know that its a markup language and I have familiarity with HTML so it didn't seem too foreign. In all honesty, my belief going into the course was that XML for android was a cop-out, the easy drag and drop method of putting together an app. I wanted the Java, I wanted to learn how to do things the hard way because I thought that's what a real programmer would do. The flaw in my thinking was revealed right away when I saw how much coding went into the XML, and that the drag and drop option was being skipped over entirely for a real coding approach.

The first lesson does not even touch an IDE, but instead puts the learner in a position to test their knowledge using a custom browser IDE with a preview pane. The experience here was liberating as I didn't feel like I had to learn a whole new IDE and spend six hours just getting it installed before I even got to write some code. Having a custom work space in-browser meant I didn't have to worry about saving files, strange error messages or settings windows. The lessons give a sample piece of code to either analyse, edit, or extend, and this led to some great time had just moving things around.

The lessons also emphasize the importance of searching through documentation for new concepts and really expanding your own knowledge past that of the syllabus. Once the first lesson is done you finally start to work with the IDE, in this case Android Studio. Since Eclipse is not going to be updated as much with Android development, and the course on Udacity is led by Google professionals, it only makes sense to make the switch to Android Studio.

The first practice lesson actually leads to an app which simply displays a message over a birthday themed image, but gets you to practice all of the concepts covered so far. My app looked as follows.

While its not in fact Toby's birthday until December, he was next to me and was a suitable replacement for the lessons "Ben"(no offence Ben). The app focused on using a relative layout to position the Views around the screen and overlapping an image. Overall the lesson did not take long but gave a strong foundation both in putting together a project, and also in running it on my android device.

From there the next lesson stepped it up a notch and worked through creating an app that simulates a coffee ordering interface, nicknamed "Just Java". The app added interactivity with Java and taught me a lot about using the resources system to save strings and images for use later. With a little extra time on my hands while the instructors explained the basic concepts of variables, I managed to jazz up my app a little to be the final product listed here.

While the app itself does nothing beyond using a picker to increment a number and update a price field, I was able to learn how to work with currency Number Formatting, how to grab an XML element and work with it in the Java Activity, and also how to nest layouts to achieve the look and spacing I desired. Admittedly, some of these may have been easier for me than beginners as I already have a working knowledge of Data Types, OOP, Inheritance and Polymorphism, all of which are for now are just taken as truth for the students in the course.

Overall I am thoroughly impressed with the course so far and hope to get more done as soon as possible, my ideas for apps are coming through more frequently and with a larger range of inspirations and I hope to share some of the finished products here soon!