Monthly Archives: August 2012

Method chaining

While experimenting with adding context menus and alert dialogs to the app, I discovered a cool Java feature that I didn’t know existed: method chaining. By taking normally void methods and instead having them return a reference to their object, you can turn this:

Person p = new Person();
p.setName(“Bill”);
p.setAge(40);
p.setZip(01701);

into this:

Person p = new Person();
p.setName(“Bill”).setAge(40).setZip(01749);

As far as I can tell, efficiency doesn’t change when using method chaining vs. the traditional way. But it looks a lot cleaner and I may start using it.

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

My next feature: custom sort menu

I had a burst of inspiration while driving to work and drew this options menu with a Crayola marker when I got there. I will be implementing this shortly:

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

Progress pics

Some initial screen grabs of our app:

#1 shows the MainActivity with no tasks.

#2 shows the AddTaskActivity during keyboard input.

#3 shows the full AddTaskActivity.

#4 shows the MainActivity with displayed tasks. Bold tasks are unfinished, and italicized tasks are completed.

#5 is a peek at our text file which stores task data.

Layouts are quick and dirty for functionality and will be cleaned up before the app is finished. More screenshots soon!

MainActivity without tasks
AddTaskActivity
AddTaskActivity
MainActivity with tasks
Tasks file

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 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.