teaching machines

U And I:: Adam King

September 21, 2012 by . Filed under cs491 mobile, fall 2012, postmortems.

Are you tired of having TOO many paint tools at your disposal?  Do you scoff at the mention of Fireworks, Photoshop, or Flash?  Do you wish you could revert back to the days of fingerpainting?  There’s an app for that.  Introducing Paint–™.

I wanted to write a paint app as a way to work with touch event tracking and management of variables between activities, while being able to use a fairly wide range of widgets.  The MainActivity is the canvas that allows the drawing of paths.  A second activity, the Brush Settings activity, contains a progress bar that allows you to adjust the brush width, a spinner which allows you to select a color, and a toggle button that lets you toggle the blurring mask for the brush (textfields separate these and provide information).  I used a RelativeLayout to set these, mostly to play around with this type of layout; the setup is probably the same as a LinearLayout would be, but I feel like I have more control with the RelativeLayout.  The four buttons on the bottom (Accept, Cancel, Save, Load) are within a LinearLayout nested in the RelativeLayout.

I lied.  There are a few extraneous paint tools such as blurring and saving/loading; creating the blur mask was simple to do, but finding how to save bitmaps to the gallery took many attempts before finding a way that worked – once finding a way, it was a bit easier learning to load images from the gallery as well.  Most of the lessons with this file I/O; the list is rather long and painful, but I’ll boil it down to some of the essentials:

FileOutputStream fos = this.openFileOutput("screenSave.JPEG", 
Context.MODE_PRIVATE);
screenSave.compress(Bitmap.CompressFormat.JPEG, 100, fos);

Overall, I’m sure it’s still not the most efficient way to write a painting app, but a lot was learned in passing data and having data persist when working between activities and a fair amount was learned about saving and loading files.

Side note: Originally, I was rotating images 90 degrees when loading them in, but when loading in an image saved with the painting app it was then loading in incorrectly; I could be way off base, but I think the emulator camera may save images in landscape orientation.  Regardless, it’s not a huge issue and I’d need a device to truly debug everything that’s going on, so maybe if I come back to the project someday to build on it it’s something to be fixed.