Skip to content

Instantly share code, notes, and snippets.

@lintonye
Created November 29, 2012 04:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lintonye/4166873 to your computer and use it in GitHub Desktop.
Save lintonye/4166873 to your computer and use it in GitHub Desktop.
app script: flickr
def brick
app = App.new.config do
app_name 'Flickr'
package_name 'com.jimulabs.flickr'
end
app.add_part flickr = Flickr.new
photo_viewer = Screen.new('PhotoViewer') do
add_parts img = ImageView.new
args :photo_id=>:int
end
photo_layout = photo_grid_item_layout
tab_recent_photos = Screen.new('RecentPhotos') do
add_parts photo_grid = GridView.new('PhotoGrid'),
refresh_action = RefreshAction.new
photo_grid.data_source = flickr.recent_photos(:photo_thumb, :title)
photo_grid.item_layout = photo_layout
photo_grid.on(:item_selected) do |results|
z photo_viewer._launch_(1)
end
refresh_action.on(:clicked) do
z photo_grid.data_source._refresh_
end
on(:launched) do
z photo_grid.data_source._refresh_
end
end
place_layout = place_list_item_layout
tab_top_places = Screen.new('TopPlaces') do
add_parts place_list = ListView.new('PlaceList'),
refresh_action = RefreshAction.new
place_list.data_source = flickr.top_places(:place_id, :_content, :photo_count)
place_list.item_layout = place_layout
on(:launched) do
z place_list.data_source._refresh_
end
refresh_action.on(:clicked) do
z place_list.data_source._refresh_
end
end
main_screen = Screen.new('Main') do
on_launcher true
add_parts swipe = Swipe.new {style :tabs}
swipe.add_tabs 'Recent Photos'=>tab_recent_photos,
'Top Places'=>tab_top_places
end
app.add_parts main_screen, photo_viewer
app
end
def place_list_item_layout
%q{<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/activated_background_indicator"
android:minHeight="?android:attr/listPreferredItemHeight"
android:orientation="vertical"
android:padding="4dp">
<TextView
android:id="@+id/place_id"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:visibility="gone" />
<TextView
android:id="@+id/_content"
style="?android:attr/textAppearanceMedium"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView
android:text="Photo count:"
android:id="@+id/label_photo_count"
android:layout_below="@id/_content"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView
android:id="@+id/photo_count"
android:layout_below="@id/_content"
android:layout_toRightOf="@id/label_photo_count"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</RelativeLayout>
}
end
def photo_grid_item_layout
%q{<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="110dp"
android:background="@drawable/activated_background_indicator"
android:minHeight="?android:attr/listPreferredItemHeight"
android:padding="2dp"
android:orientation="vertical" >
<ImageView
android:id="@+id/photo_thumb"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="centerCrop" />
<TextView
android:id="@+id/title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:background="#40000000"
android:gravity="center"
android:singleLine="true"
android:textColor="#ffffff" />
</RelativeLayout>
}
end
brick
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment