Category Archives: WSU CS

JellyBean Notification with Backwards Compatibility

Using NotificationCompa from android.support.v4.app allows for backwards compatibility when creating notifications for your Android app. Bellow is a class that defines two basic methods for the notifications, however at this point it should be easy to go trough the documentation, and call the extra methods to set more things–even using the new android Jelly Bean notification goodies– for example the second method creates a persistent notification by setting onGoing flag true.

Speaking of flags:

//you can NOT set flags directly like
notification.flags |= Notification.FLAG_AUTO_CANCEL;
//you have to use the methods in NotificationCompat.Builder
builder.setAutoCancel(true); 

Things of note in the code is that in Notification notification = builder.getNotification(); notification is still a Notification object and not a NotificationCompat object, however the builder was defined as a NotificationCompat.Builder, this is helpful because the NotificationManager.notify() only accepts Notification objects.

package edu.worcester.cs499summer2012.service;

import edu.worcester.cs499summer2012.R;
import edu.worcester.cs499summer2012.activity.ViewTaskActivity;
import edu.worcester.cs499summer2012.task.Task;

import android.app.Notification;
import android.os.Build;
import android.support.v4.app.NotificationCompat;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;

/**
 * Creates Notifications using NotificationCompat to allow for
 * comparability though different API levels
 * 
 * @author Dhimitraq Jorgji
 *
 */
public class NotificationHelper{
	/**
	 * Basic Text Notification for Task Butler, using NotificationCompat
	 * @param context 
	 * @param id id of task, call task.getID() and pass it to this parameter
	 */
	public void sendBasicNotification(Context context, Task task) {
		NotificationCompat.Builder builder = new NotificationCompat.Builder(context)
			.setContentText(task.getName())
			.setContentTitle(context.getText(R.string.app_name))
			.setSmallIcon(Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB ? 
					R.drawable.ic_notification : R.drawable.ic_notification_deprecated)
			.setAutoCancel(true)
			.setContentIntent(getPendingIntent(context, task.getID()))
			.setWhen(System.currentTimeMillis())
			.setDefaults(Notification.DEFAULT_ALL);
		Notification notification = builder.getNotification();
		NotificationManager notificationManager = getNotificationManager(context);
		notificationManager.notify(task.getID(), notification);
	}
	/**
	 * Basic Text Notification with Ongoing flag enabled for Task Butler, using NotificationCompat
	 * @param context 
	 * @param id id of task, call task.getID() and pass it to this parameter
	 */
	public void sendPersistentNotification(Context context, Task task) {
		NotificationCompat.Builder builder = new NotificationCompat.Builder(context)
			.setContentText(task.getName())
			.setContentTitle(context.getText(R.string.app_name))
			.setSmallIcon(Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB ? 
					R.drawable.ic_notification : R.drawable.ic_notification_deprecated)
			.setAutoCancel(true)
			.setContentIntent(getPendingIntent(context,task.getID()))
			.setWhen(System.currentTimeMillis())
			.setOngoing(true)
			.setDefaults(Notification.DEFAULT_ALL);
		Notification notification = builder.getNotification();
		NotificationManager notificationManager = getNotificationManager(context);
		notificationManager.notify(task.getID(), notification);
	}
	//get a PendingIntent
	PendingIntent getPendingIntent(Context context, int id) {
		Intent intent =  new Intent(context, ViewTaskActivity.class)
			.putExtra(Task.EXTRA_TASK_ID, id);
		return PendingIntent.getActivity(context, id, intent, 0);
	}
	//get a NotificationManager
	NotificationManager getNotificationManager(Context context) {
		return (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
	}
}

All of the source code for Task Butler can be found on GitHub, including the above code.

Any questions shoot away in the comments bellow.

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

Great Meeting the Other day

Synergy! haha, Jon Dhimitri and I met up on Thursday to discuss the final process in the app.  I figured since Dhimitri has that little netbook that he can’t do much with that I would bring a VGA cable to the library and set my laptop up on the big screen.  I’ll remember not to listen to Dhimitri though because the VGA cable wouldn’t fit so I had to run back and grab an HDMI, the result:

Look at him pointing, Synergy!

It actually worked out really well, and I wish we had started doing it earlier.  We used My/Jon’s laptop and were able to solve a problem in Dhimitri’s ViewCalendarActivity which turned out to be some weird problem with using .get__() (it was a call to a different class outside the package) which it didn’t like and wouldn’t allow the calendar to move more than a month away.

The meeting lasted a pretty long time where we discussed where the app was going and who was testing it.  I suggested we use r/androidDev from Reddit considering we would definitely get some feedback from knowledgeable app devs who are happy to help.  I think it might be a good idea to get some freshmen CS students into the testing too, I’ll email whomever is doing 101/140 this year and ask.

The app is looking awesome, excited for these next few weeks.

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

First Meet With Dhimitri

Jon, Dhimitri and I had a meeting today to catch Dhimitri up on what we have been doing and the plan for the next few months.  We met in the library and discussed how to set up Action Bar Sherlock and demo’d the app again.  We plan on following the style guide very thoroughly so the app will flow how normal Android apps work.  We also talked about trying the app done to a point where we could start field testing the app with students around campus and get a feel for what works and what will need improvement.

 

Everything seemed to go pretty well, I’ll be working on editing a task that has been previously made using ‘add task’ and I think I may just have the edit copy the old task and replace the new data instead of just updating, not too sure yet.

 

We talked about doing SQLite a little bit but the point still stands about leaving it out until later (if we want/need it).

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

Working on a facelift

Howdy all,

Jon and I aren’t graphic designers, actually I just ran into this problem at work,  and it’s pretty obvious this app isn’t going to be the prettiest bell at the ball.  Whatever, form follows function.  Right now I’m working on making the ‘create activity’ section contain everything we’re going to need Calendar style date picker, notes, title, priority radio buttons and that should be it for now.

I’ve ran into a bit of a problem with saving the tasks and I can’t figure out why they aren’t being recreated on restart for now I’m just leaving it alone (which is why nothing has been committed yet).  Since Jon built most of the onRestart() I’m sure he’ll know what’s wrong once we meet THIS SUNDAY FOR SURE so I’m not too concerned.  I found out today that the GUI for android dev is terrific, it really is.  I was fussing around with all the ugly xml and switched over only to see the GUI version was so smooth and easy to use.

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

Catching Up on GIT

Howdy all,

Luckily Jon and I have been working internships all summer using some sort of variation of a Version Control System.  I guess I didn’t learn as much as I thought in 401 for GIT as I really needed.  My git-foo has improved significantly (Jon’s is still way above mine, though. )  Right now I’m working on my james-dev branch (at least the one I push to) and usually branch when I’m trying something new.  I’m really digging the issue tracker but, I think one day this week I am going to take some time out, probably with Jon, and really get our Wiki in gear.

In other news, old news that I never mentioned, Joe was MIA for a while and I finally got in contact with him and he said he was too busy and couldn’t commit I emailed Karl about it but I never got a response, I’m sure he’s just enjoying summer.

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

Whoops.

(This blog post is a few weeks old and never was posted), I’ve been pecking away at the app, though.  Jon built a great foundation for our app and it’s time to get cracking and finish this bad boy.  Right now I’m playing catchup on all the documentation for Android (big thanks to Jon for meeting and walking me through).  TheNewBoston started to get too slow and I started using google development docs, big difference and ultimately better.

Finals are coming up for my summer class and then I can focus on this app.

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

Setting up your development environment

This is a guide for creating a new Android Eclipse project from source code on GitHub. It is tailored to my independent study project for the benefit of my partners, but it could be easily adapted to any Android project.

Note: This guide was created for Windows 7 64-bit. Other versions of Windows should be similar.

1. Download and install Java SE Development Kit for Windows x86

Note: I highly recommend NOT installing to the default C:\Program Files (x86)\Java\ folder. The Program Files folder has very restrictive permissions which may cause file writing/copying errors in the future. I chose to install to C:\Java\.

2. Download and install Android SDK for Windows

Note: Again I recommend NOT installing to the default folder. I chose to install to C:\Android\.

3. Run the Android SDK Manager and install the groups: Tools, Android 4.1 (API 16), and Android 2.2 (API 8).

4. Download either Eclipse Classic for Windows 32-bit or Eclipse for Java Developers for Windows 32-bit

5. Extract the downloaded eclipse\ folder into your Java\jdk*\ folder

6. Download and install GitHub for Windows

7. Run Eclipse, and choose your GitHub folder as your workspace

8. Install Eclipse ADT Plugin

Note: If you get an error after restarting Eclipse about not being able to find the Android SDK, just click the Preferences button and point to your Android\android-sdk\ folder.

9. Create a new Android project, and then close Eclipse afterwards

Name the project Task Butler, and name the package edu.worcester.cs499summer2012. The target SDK should be API 16 and the minimum required SDK should be API 8.

10. Clone the CS499Summer2012 repo to your local GitHub folder

11. Move the local repo files into your Task Butler folder

  • In your GitHub\Task Butler\ folder, delete everything EXCEPT .settings\, .project, and .classpath
  • Move everything from GitHub\CS499Summer2012\ into GitHub\Task Butler\
  • Note: Make sure “Show hidden files, folders, and drives” is enabled in Windows Explorer’s Folder options so you can see the hidden .git folder
  • Delete the now-empty \GitHub\CS499Summer2012\ folder

12. Reopen Eclipse, and the project should now have all of its files (and lots of errors!)

13. Download ActionBarSherlock and extract it somewhere

I chose C:\Android\

14. In Eclipse, import the library\ folder inside the ActionBarSherlock folder as a new project

15. Modify the library’s Android properties and Java Compiler properties to get rid of errors

Make sure the build target is set to 4.1 and the “Is library” checkbox is checked.

Make sure the Compiler compliance level is set to 1.6.

16. Modify Task Butler’s Android properties to include the new library

Make sure the build target is 4.1 and add ActionBarSherlock to Library (if there is one listed already with a question mark, remove it).

17. If necessary, clean the project and it should rebuild itself with no errors.

The project is now ready to be worked on!

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

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.