Code

Custom Alert View for iOS4

Hi everyone!

CustomAlertViewSampleProject Screen Shot

CustomAlertView Screen Shot

With some of the changes in iOS4, it has become more difficult to create UIAlertViews with UITextFields as subviews and have it look right.  So I went ahead and made a fully customizable alert view replica called CustomAlertView (clever huh?).

One thing I didn’t want to do was re-factor a bunch of my code, so I recreated most of the methods in UIAlertView based on the description of their functionality in the API.  Some of the names are slightly different, particularly in the CustomAlertViewDelegate.  I have attached a sample project that should show how to use it, but I’ll also paste it below.

Two things to note in the project are that I connected the UITextFields in Interface Builder and that I set the main view to be the RootViewController of the main window.  The code relies on being able to access the root view controller, you you need to make sure it is set.  Here’s how I did it in CustomAlertViewSampleAppDelegate.m:


- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {

// Override point for customization after application launch.

// Add the view controller’s view to the window and display.
[window setRootViewController:viewController];
[window makeKeyAndVisible];
return YES;
}


Also, be sure to get the images from the sample project as well if you want to use this as is.

I hope you find this useful!  Please let me know if you find any bugs or ways to clean this up!  Also, I didn’t include the animation to move the CustomAlertView up to make space for the keyboard, but I can if people want :)

Download: http://www.namazustudios.com/files/CustomAlertViewSample.zip

Share this:
  • Digg
  • del.icio.us
  • Facebook
  • Google Bookmarks
  • E-mail this story to a friend!
  • Reddit
  • Slashdot
  • Twitter

checkpasswd-imap – A mod_authnz_external style password checker.

For those of you who out there who have ever set up Trac in the past, you probably know that the out-of-the-box installation requires that you use some sort of external authentication mechanism to validate users who have access to Trac.  You’ll also know that if you use Google Accounts that and mod_auth_openid, it’s really difficult to authenticate users without adding a little bit of custom code to either Trac, mod_auth_openid, or both.  (Or if you don’t, I haven’t figured out a way to do it).   In the end I just ended up sidestepping the whole process and resorted to using mod_auth_imap against Google’s IMAP server.  Unfortunately, that lead to a second problem….it appears that mod_auth_imap validates users credentials against the server for each HTTP request resulting in lots and lots of unnecessary traffic, painfully slow HTTP requests and if the IMAP server happens to have rate-limiting  it’s an easy way to quickly lock out all your accounts.  So for anybody who is faced with a similar problem, I hacked this little checkpasswd style external authentication program.  Here’s a quick rundown of the features:

  • Configurable for multiple IMAP servers with filtering of users by regular expressions
  • Compatible with mod_authnz_external
  • Login credentials are cached with unrecoverable encryption and then stored to disk.  Optionally this can be configured to be put in a RAM drive and cleaned regularly with a cron job.
  • Portable, written in Python.  Tested on Gentoo Linux only with Python 2.6.
  • Can be used in conjunction with mod_dav_svn

If anybody has any questions or comments feel free to email me.  If you find bugs or issues, please wear the white hat and let me know so I can fix them immediately.  The code is released under GPL v3.

Download it Here

All the instructions are included in the archive.


Patrick “Invictvs” Twohig <invictvs@namazustudios.com> (A.K.A. “The Server Guy”)



Share this:
  • Digg
  • del.icio.us
  • Facebook
  • Google Bookmarks
  • E-mail this story to a friend!
  • Reddit
  • Slashdot
  • Twitter

Better Android Builds

While developing Guns of Legend for Android, we learned quite a few things about the Android build process.  Firstly, it’s not very well documented.  As far as we could tell, it didn’t perform much before-time optimizations on bytecode.  The dex compiler performs some optimizations, but we had observed a noticeable difference between debug and release builds made with Proguard.  Lastly, some common programming practices designed to improve code quality cause performance bottlenecks in unoptimized Java bytecode.  J2SE Virtual Machines solved this problem by implementing “just-in-time” compiling which performs whole program optimization while the bytecode loaded into memory.  We put together a set of Apache Ant build scripts to streamline the process of building, packaging, and fully optimizing an Android application before deployment.

Attached to this post is a copy of a template script designed to streamline your Android build process, protect your code from reverse engineering, and perform crucial optimizations on your code.  Additionally, Proguard can remove code that should only be left in for debugging.  It is common practice to write redundant checks for null arguments in functions.  Though these are often times handy in diagnosing problems, they can slow down performance.  If you were to isolate the checks to static methods in a single class, it is very easy to have Proguard simply throw out the class from the build all together.  It will make it more difficult to interpret crash stack traces but it will provide better performance.  When using this feature of Proguard, it is your responsibility to ensure that the removed code will not affect the normal behavior of the application. Only remove classes/methods which are well isolated from the rest of the program, or else you may find that obfuscated builds crash while debug builds don’t.

Lastly, please bear in mind that this script was originally written for pre-1.5 (Cupcake) releases of the Android SDK then later revised.  Parts of this script can be integrated into the ones auto-generated by the Android SDK, or you can use this with a little bit of modifications.  Please let me me know in the comments if you need help using this script or tailoring it to your particular application.  I hope that the Android community will find it useful in some way!

Download the Script

Share this:
  • Digg
  • del.icio.us
  • Facebook
  • Google Bookmarks
  • E-mail this story to a friend!
  • Reddit
  • Slashdot
  • Twitter