Category Archives: WSU CS

The basics of an Android app

Learning the structure of an Android app is overwhelming at first, but it’s not too difficult after some familiarization. I recommend using Lars Vogel’s excellent Android tutorials here. They are among the best tutorials I have found, and I am sure I will keep using them as a reference as this project continues.

An Android app is made up of two parts: the front end and the back end. The front end is the visual part of the app that the user interacts with, and the back end, which contains all the code that drives the app.

The front end is written using XML. I have never used XML before, but it is very similar to HTML in that it is a markup language that uses nested tags as its programming structure. Android uses several XML files to create the app’s front end. There is at least one XML layout file for each activity (or several if you are supporting multiple device sizes), as well as layout files for custom views. XML is also used to define constant strings that will be placed in the layouts, such as the text on a button.

The back end is written in Java, which is great because it is a language that I am very familiar with. You can use the Java standard library in addition to the Android library when coding your app. This gives you access to a ton of pre-made objects, and the APIs are thoroughly documented online by Oracle and Google.

Each screen in an app is known as an activity. Activities are classes that you extend from a base activity class. Each activity is tied to an XML layout file which provides the front end visuals. Activities are created, resumed, and closed by the Android OS through a series of callback methods, which are called automatically by the OS at the appropriate times. Some examples of callback methods: onCreate, onPause, onResume, onStop. These methods have to be overwritten for your activity to work correctly.

Information sent between activities is called an intent. Intents carry standard data like strings or can be modified to carry custom extra data. For example, our AddTaskActivity creates a new Task object, adds it to an intent, and sends it back to the MainActivity where it will be displayed for the user.

There are other basics, such as fragments, services, and notifications, but I don’t know enough about them yet. I’ll comment on those after I’ve learned them!

From the blog Code Your Enthusiasm » WSU CS by Jon and used with permission of the author. All other rights reserved by the author.

Code is live on Github

Now that the app is in development, our work is live on Github. Check it out by clicking the Github link at the top of my blog.

From the blog Code Your Enthusiasm » WSU CS by Jon and used with permission of the author. All other rights reserved by the author.

A focus on personal productivity

We’ve decided on the type of app we are going to develop. It will be a task organizer/to-do list, which personally is a crucial app for my phone to keep my life in order. I’ve tried several different task organization apps from the Play Store, but none of them did exactly what I wanted. I’m currently using Astrid Tasks, which is very popular and close to what I want, but full of feature bloat. So hopefully what we develop will eventually become my
full-time organization app.

Here is an early draft of features that I brainstormed and sent to James:

Task App Features
* Able to assign a due date/time
  – If no time specified, have the alarm go off at a default time (specified in options)
* Able to assign a priority (urgent, standard, trivial)
  – Priorities can change the font of the task (bold/regular/italics)?
* Able to create and categories (Bills, Shopping, Homework, etc)
  – Categories can color code the task background?
* Able to hide/display entire categories (Tabbed page for each category?)
* Able to sort list by name, due date, priority, or smart sort (combination of due date and priority)
* Able to make tasks once-only or recurring
  – Recur every X minutes/hours/days/months/years
* Alarm in the form of a persistent notification
   – Make optional: a popup (may be too intrusive for many)
   – Make optional: non-persistent notification
   – Ringtone, vibrate, LED flash on alarm
       * all able to be changed/turned off via options
   – Able to snooze alarm (by how much time specified at time of snooze or in options?)
   – Only way to get rid of persistent notification is to complete task or keep snoozing
* Optional: A secondary “You are out of time alarm”
   – For procrastinators like me
   – Optionally specificy a time where a task absolutely has to be done by
   – If not done by this time, a popup will appear every 15 minutes until task is completed
   – Cannot be turned off/snoozed without finishing the task
* Completing a task will mark it as completed
   – If a recurring task, immediately create a new task for the next recurrence
   – Give user the option to auto delete completed tasks or keep them
* Visually, each task in the list should show as much info as possible without being too cluttered
   – Name of task
   – Priority of task (font or icon?)
   – Category of task (as text and colored background?)
   – Due date/time of task
   – Whether or not it is recurring (icon?)
 – Whether or not it is overdue (icon or make the font red?)
   – Overdue tasks should always be at the top (user option?)

Advanced Features
* Backup and restore task lists
– XML format
– Manual or automated backup, or both
* Integrate with the user’s Calendar
* Sync with their Google account
* Resizable, scrollable widget to list tasks

From the blog Code Your Enthusiasm » WSU CS by Jon and used with permission of the author. All other rights reserved by the author.

A quick note on Jelly Bean

With the release of the Android 4.1 Jelly Bean SDK, our project will now have a build target of 4.1 Jelly Bean and a minimum required version of 2.2 Froyo. Also, a lot of the problems experienced in my post about setting up the SDK have disappeared. The AVD location bug is gone, and the Eclipse ADT Plugin installs just fine from the online repository. It’s nice when things work!

From the blog Code Your Enthusiasm » WSU CS by Jon and used with permission of the author. All other rights reserved by the author.

The trickiness of using Git in an Eclipse project workspace

I know there is a Git plugin for Eclipse, but I prefer to do things the old school way with terminal commands. So when it came time to make sure my Eclipse project folder was being tracked by our remote repository on Github, I thought I could just clone our repository and then create a new Eclipse project in that same directory. Except Eclipse does not let you create a new project in a directory that already exists. And I wasn’t going to try to clone into a directory after it had already been populated by local Eclipse files; who knows what kind of problems that would have created.

If there is an elegant solution to this problem, I didn’t find it. I changed the name of the cloned directory, then created my Eclipse project using the original directory name now that it was unused and available. Then I moved all the Git files into the new directory, and deleted the now-empty one with the changed name. And everything works great.

From the blog Code Your Enthusiasm » WSU CS by Jon and used with permission of the author. All other rights reserved by the author.

Odd-sounding warning in Git is not a big deal

As I am preparing to make my first commits to our project, and I get bombarded with several of these warnings, one for every changed file:

warning: LF will be replaced by CRLF in res/layout/activity_main.xml.
The file will have its original line endings in your working directory.

I have no idea what this means. Luckily, Google had my answer here: LF stands for line feed, and is what Linux systems use to delineate newlines in files. CRLF stands for carriage return line feed, which is what Windows uses for newlines. That makes sense as I am working in Windows. It looks the impact of this change is pretty insignificant and the warnings can be disabled by entering the following in the Git shell:

git config core.autocrlf true

From the blog Code Your Enthusiasm » WSU CS by Jon and used with permission of the author. All other rights reserved by the author.

The Liberated Pixel Cup! – Dev Blog 2

It’s been a slow start, but hopefully things will start to move a bit faster. I am on vacation for the week and I have managed to get some work done.

I spent several days trying to figure out the best way to represent Actors on the world maps where the player can walk around. The Actors walk one tile at a time, fitting to the grid, rather than having “free” movement where Actors can move by any increment. It is much easier to implement free movement (which is what I’ve done in the past) than tile movement. I re-wrote the code that handles all of this several times before I found an implementation that was clean and functional enough.

In this screenshot there are several randomly spawned Actors that have walked to random places on the map. They do this by using the A* pathfinding algorithm I talked about in the previous post. There is an Action class that actually performs the walking animation. This Action is smart enough to re-route upon collision with another Actor.

The player can touch/click on a map tile to walk a path to it. For desktop users or certain Android devices, the D-pad can also be used to move the player around on a tile-by-tile basis.

I have also started work on an interaction and dialog system. In the screenshot, the text box shown is a result of the player interacting with the sign on the building. Right now the text box only displays one string of text, multiple strings and maybe even branching dialog paths still need to be done. Item chests are on the to-do list as well. Hopefully I can get them done soon.

From the blog David Thompson » WSU CS by davexunit and used with permission of the author. All other rights reserved by the author.

The Liberated Pixel Cup! – Dev Blog 1

Image

The time is finally upon us. The art portion of the Liberated Pixel Cup has reached its deadline, which means that the programming portion of the contest has begun! The competition is a month long in which us code monkeys need to use the art assets that were generated to make the best possible game that we can. Since this pixel cup is “liberated”, all of the source code will be available under the GPLv3.

I am working with someone that I only through IRC (#liberatedpixelcup on Freenode) with the nickname of fr33mind. We will be making a Pokemon inspired game where you control monsters to use in combat. The actual gameplay details will get fleshed out more as the competition goes forward.

We are using libGDX to make the game. LibGDX is a fantastic Java library that allows us to write a game that runs on the desktop (GNU/Linux, Mac, Windows) and on Android devices with very little platform specific code.

Above is a screenshot of my experiments with libGDX. Here you see a path of ghosts that was generated by my implementation of the A* pathfinding algorithm. It took a long time to wrap my head around it but it is a crucial element to the game considering that users will move across the map not only with arrow keys, but by touching/clicking areas on the map (my Android phone has no D-pad). This makes decent pathfinding a must have so I wanted to try to get it out of the way early. The code performs well on the desktop but for some reason takes about 3 seconds to run on my Android phone, which is a serious problem. My choice of data structures or too much memory allocation could be the problem and I need to investigate who the culprit is. I’m using a PriorityQueue and a HashMap to maintain lists, and a Pool (in libGDX) to minimize memory allocation, yet the problem persists.

I’m going to try to keep this development blog going over the course of the month with screenshot updates. Let’s see if I can manage to actually do that.

UPDATE:
Turns out the performance problem was because of how I was drawing the path on screen and NOT the algorithm itself. I have since abstracted away the things that are dependent upon a specific tile map implementation and have a rather generic set of classes to use for pathfinding.

From the blog David Thompson » WSU CS by davexunit and used with permission of the author. All other rights reserved by the author.

My First App

I never mentioned in my previous post that I have been watching www.thenewboston.org ‘s video series throughout the past few weeks.  He’s a young guy and it’s kind of funny learning from him sometimes, weird little things bother me sometimes, I’m weird, it’s weird.  But!

I wrote my first app, you can push a button to add or push a button to subtract! Can’t wait to publish it to Google play..  It’s a good building block to start from.

————————————-

<?xml version=”1.0″ encoding=”utf-8″?>
<LinearLayout xmlns:android=”http://schemas.android.com/apk/res/android&#8221;
android:layout_width=”fill_parent”
android:layout_height=”fill_parent”
android:orientation=”vertical” >

<TextView
android:id=”@+id/tvDisplay”
android:layout_width=”fill_parent”
android:layout_height=”wrap_content”
android:layout_gravity=”center”
android:gravity=”center”
android:text=”Total =”
android:textSize=”45dp” />

<Button
android:id=”@+id/addButton”
android:layout_width=”250dp”
android:layout_height=”wrap_content”
android:layout_gravity=”center”
android:text=”Add One”
android:textSize=”20dp” />
<Button
android:id=”@+id/subButton”
android:layout_width=”244dp”
android:layout_height=”wrap_content”
android:layout_gravity=”center”
android:text=”Subtract One”
android:textSize=”20dp” />

</LinearLayout>

——————–

Does wordpress not have a <code> tag? Gross.

But, that’s XML a lot of referencing android:layout, or just android in general, who would have thunk it?!  XML seems pretty straight forward, oddly enough the day after I learned some of it I had to write it a bit for my internship, which was pretty cool.

From the blog jamescelona » WSU CS by jamescelona and used with permission of the author. All other rights reserved by the author.

Keeping Scheduled Meet Times

I spoke with John this week, he works in Lowell and I live about 5 minutes or so from his work I we met for a quick meal and talked about what we’ve done.  I’m still trying to get in contact with Joe, I don’t know what he’s doing.  But, we both realized we were letting work take up a bit too much of our time we are going to start meeting at least once a week on a google+ hangout and teach each other what we’ve learned.

Also, I have set aside a few days a week a few hours after work to sit in my office and learn / write xlm/java to get some little android apps up and running.  Today is the first of the sit downs and it’s a lot better of an idea than “I’ll just do it when I get free time”  because summer has been itching for me to just go outside and hang with friends.

This idea of “class time” in my office is going to work out well.

From the blog jamescelona » WSU CS by jamescelona and used with permission of the author. All other rights reserved by the author.