13
Garage Buddy Tips, Hacks, and Lessons Learned

Garage Buddy for Android

Embed Size (px)

DESCRIPTION

Overview of things I learned while porting our Garage Buddy application from iOS to Android.

Citation preview

Page 1: Garage Buddy for Android

Garage Buddy

Tips, Hacks, and Lessons Learned

Page 2: Garage Buddy for Android

Who am I?

• Not much of a presentation wiz • Currently a programmer at Turtle Rock studios•  7 years of experience in game development for PCs

and console• Garage Buddy was my first Android application • Garage Buddy was also my first Java application• email: [email protected]

Page 3: Garage Buddy for Android

Why make Garage Buddy?

•  We're car guys!•  Wanted to learn about mobile development and

publishing• Sounded like an easy (spare-time) project

Page 4: Garage Buddy for Android

What is Garage Buddy?

• It is a multi-tool app for people that work on cars• Has various calculators and tables • We have both iOS and Android versions • Originally written for iOS• Original iPhone and G1 are both HVGA devices

(320x480), but this has gotten a lot messier• iPhone table data is in PList files, which is just XML.• iPhone strings are in a "Localizable.strings" file,

easily converted into a strings.xml file. 

Page 5: Garage Buddy for Android

Splash Screen

• Sends anonymous usage data to us for demographic tracking

• We track OS version, screen res, hardware model, and hash of device ID

• Uploading is slow! So do it in a thread.

• AsyncTask is a nice way of offloading work to another thread 

• I was going to pre-load other data app data here, but it didn't seem necessary.

Page 6: Garage Buddy for Android

Main Menu

• We needed a scrollable list that would contain icons and text, and launch other activities 

• The Main Menu is just a list view with an ArrayList<> back-end

• Doing it this way made the main menu (sort of) data driven.

• Array is populated like this:   mMainMenuItems.add(     new MainMenuItem(      R.string.ruler_button_label,       R.drawable.ruler_icon,      RulerActivity.class) );

Page 7: Garage Buddy for Android

Main Menu Items

• Uses the "Class" object, part of Java's support for Reflection

• Reflection is awesome! • Code is simple:

  public class MainMenuItem {    int mTitleRes;      // resource ID for the menu item string    int mImageRes;      // resource ID for the menu item drawable icon    Class mActivity;    // the class of the activity we should launch}

Page 8: Garage Buddy for Android

Menu Item Launching

mMainListView.setOnItemClickListener( new OnItemClickListener() {    public void onItemClick(AdapterView<?> parent, View view, int position, long id)     {        Class activity = mMainMenuItems.get(position).mActivity;        Intent intent = new Intent(               MainMenuActivity.this,               activity );                    MainMenuActivity.this.startActivity(intent);    }});

Being able to store a class type in a variable lets you do some fancy things:

Instead of:

Intent intent = new Intent(     MainMenuActivity.this,     RulerActivity.class );

Page 9: Garage Buddy for Android

Ruler

• In iOS, just a static image• In Android, numbers and

tick marks placed programatically. 

• Very easy thanks to Android support for "dimensions" which include real-world units (inches, millimeters)

Page 10: Garage Buddy for Android

Ruler - dimens.xml

<resources>    <dimen name="one_inch">1in</dimen>    <dimen name="one_millimeter">1mm</dimen>    <dimen name="one_centimeter">10mm</dimen></resources>

Page 11: Garage Buddy for Android

Ruler - RulerView.java

public class RulerView extends View {    public void onDraw(Canvas canvas)    {        float inchDim = getResources().getDimension(R.dimen.one_inch);        int screenHeight = getHeight();        int inchTicks = screenHeight / inchDim;        int tickWidth = 1;        int tickLength = 50;                Paint paintLargeTick = new Paint(Paint.ANTI_ALIAS_FLAG);        paintLargeTick.setColor(Color.BLACK);                for ( int i = 0; i <= inchTicks; i++ )        {            float xStart = 0;            float yStart = i*inchDim;                        canvas.drawRect(                    xStart, yStart,                     xStart + tickLength, yStart + tickWidth,                     paintLargeTick);        }    }}

Page 12: Garage Buddy for Android

Tables

• Large tables are slow on low-end devices • Maybe because a table contains N views, N = ROWs

x CELLs ?• In other words: ROWs x ROWs x COLs • I couldn't find a way around it:• Building programatically was slow (even in another

thread) • Putting the entire table in the layout.xml was slow

Page 13: Garage Buddy for Android

Questions? 

[email protected]