building timepiece

23
Building TimePiece Arpit Mathur http://twitter.com/arpit

Upload: arpit-mathur

Post on 10-May-2015

1.473 views

Category:

Technology


0 download

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

Page 1: Building TimePiece

Building TimePiece

Arpit Mathurhttp://twitter.com/arpit

Page 2: Building TimePiece

What is TimePiece

• World Time lookup without API calls

• Visually interesting (fun with animation)

• Open Source (under the MIT license)

Page 3: Building TimePiece

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

Page 4: Building TimePiece

Implementing ContentProviders with local SQLite databases

Page 5: Building TimePiece

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

Page 7: Building TimePiece

• 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

Page 8: Building TimePiece

Search config (in res/xml)

Page 9: Building TimePiece

Search Activity

Page 10: Building TimePiece

Integrate with Main Activity

Page 11: Building TimePiece

Mind the stacks!

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

Page 12: Building TimePiece

Replacing the Activity with Suggestions

CitySearchSuggestionProvider

res/searchable.xml

Page 13: Building TimePiece

Return format

Page 14: Building TimePiece

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

Page 16: Building TimePiece

A little deeper into Animation

Page 17: Building TimePiece

Loading Animation XMLs

Page 18: Building TimePiece

Creating animation objects at runtime

Page 19: Building TimePiece

Creating custom animations

• Extend Animation• Override applyTransform

Page 20: Building TimePiece
Page 21: Building TimePiece

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

Page 22: Building TimePiece

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)