Building TimePiece

Post on 10-May-2015

1.473 views 0 download

Tags:

description

Code and patterns from building TimePiece: an Android World Clock application released under the Open Source MIT license. The talk was given at the Philly Android Alliance User Group meeting on 8/24

Transcript of Building TimePiece

Building TimePiece

Arpit Mathurhttp://twitter.com/arpit

What is TimePiece

• World Time lookup without API calls

• Visually interesting (fun with animation)

• Open Source (under the MIT license)

Technical breakdown

• Local SQLite database with City / Java TimeZone Id mappings

• JODA DateTime library• Search• Custom List Renderers• The usual app stuff:– User Preferences– Menus– Intro screens– Context menus

Implementing ContentProviders with local SQLite databases

Steps

• Add SQLite to your assets folder• Copy the database to your app’s

data folder• Open the database (extend

SQLiteOpenHelper)• Create a ContentProvider from this

Database

• Create a searchable config xml file• Create an Activity to handle the

search• Add the Search config and activity to

the activity that you want to trigger search on

Implementing Search

Search config (in res/xml)

Search Activity

Integrate with Main Activity

Mind the stacks!

• Activity LaunchModes declared in Activity:–multiple– singleTop– singleTask– singleInstance

Replacing the Activity with Suggestions

CitySearchSuggestionProvider

res/searchable.xml

Return format

Building Custom Lists

• Create a List View or a ListActivity• Create an Adapter for populating the

List• Populate the List Adapter• Refresh the Adapter every 60

seconds

A little deeper into Animation

Loading Animation XMLs

Creating animation objects at runtime

Creating custom animations

• Extend Animation• Override applyTransform

Remember:

• Animations only effect the rendering buffers so objects don’t actually change in position itself

• If you don’t set setFillAfter, the animated object will return to its location/transformation as before animation started

• Leverage LayoutAnimations as well as regular animations

Releasing to the Market

• Use Android Asset Studio to create your icons

• Broken Market search: Joining words is probably a bad idea

• When adding images to your app’s description, make sure the first one is most representative (for third party market indexers like Chomp)