aboutsummaryrefslogtreecommitdiff
path: root/subsonic-android
diff options
context:
space:
mode:
Diffstat (limited to 'subsonic-android')
-rw-r--r--subsonic-android/AndroidManifest.xml117
-rw-r--r--subsonic-android/ant.properties20
-rw-r--r--subsonic-android/assets/fonts/Storopia.ttfbin0 -> 89888 bytes
-rw-r--r--subsonic-android/assets/html/en/index.html98
-rw-r--r--subsonic-android/assets/html/fr/index.html100
-rw-r--r--subsonic-android/assets/html/img/paypal.gifbin0 -> 2127 bytes
-rw-r--r--subsonic-android/assets/html/img/subsonic.pngbin0 -> 2084 bytes
-rw-r--r--subsonic-android/assets/html/style.css11
-rw-r--r--subsonic-android/build.xml85
-rw-r--r--subsonic-android/debug.keystorebin0 -> 1267 bytes
-rw-r--r--subsonic-android/patches/jukebox-patch.txt1234
-rw-r--r--subsonic-android/proguard.cfg40
-rw-r--r--subsonic-android/project.properties11
-rw-r--r--subsonic-android/res/anim/push_down_in.xml22
-rw-r--r--subsonic-android/res/anim/push_down_out.xml22
-rw-r--r--subsonic-android/res/anim/push_up_in.xml22
-rw-r--r--subsonic-android/res/anim/push_up_out.xml22
-rw-r--r--subsonic-android/res/drawable-hdpi-v4/action_play_all.pngbin0 -> 1340 bytes
-rw-r--r--subsonic-android/res/drawable-hdpi-v4/action_refresh.pngbin0 -> 2860 bytes
-rw-r--r--subsonic-android/res/drawable-hdpi-v4/action_search.pngbin0 -> 2291 bytes
-rw-r--r--subsonic-android/res/drawable-hdpi-v4/action_shuffle.pngbin0 -> 3411 bytes
-rw-r--r--subsonic-android/res/drawable-hdpi-v4/actionbar_button_normal.9.pngbin0 -> 208 bytes
-rw-r--r--subsonic-android/res/drawable-hdpi-v4/album_art_background.pngbin0 -> 9287 bytes
-rw-r--r--subsonic-android/res/drawable-hdpi-v4/appwidget_bg.9.pngbin0 -> 2909 bytes
-rw-r--r--subsonic-android/res/drawable-hdpi-v4/appwidget_divider.9.pngbin0 -> 2806 bytes
-rw-r--r--subsonic-android/res/drawable-hdpi-v4/appwidget_inner_focus_c.9.pngbin0 -> 221 bytes
-rw-r--r--subsonic-android/res/drawable-hdpi-v4/appwidget_inner_focus_l.9.pngbin0 -> 400 bytes
-rw-r--r--subsonic-android/res/drawable-hdpi-v4/appwidget_inner_focus_r.9.pngbin0 -> 423 bytes
-rw-r--r--subsonic-android/res/drawable-hdpi-v4/appwidget_inner_press_c.9.pngbin0 -> 223 bytes
-rw-r--r--subsonic-android/res/drawable-hdpi-v4/appwidget_inner_press_l.9.pngbin0 -> 408 bytes
-rw-r--r--subsonic-android/res/drawable-hdpi-v4/appwidget_inner_press_r.9.pngbin0 -> 419 bytes
-rw-r--r--subsonic-android/res/drawable-hdpi-v4/ic_appwidget_music_next.pngbin0 -> 489 bytes
-rw-r--r--subsonic-android/res/drawable-hdpi-v4/ic_appwidget_music_pause.pngbin0 -> 232 bytes
-rw-r--r--subsonic-android/res/drawable-hdpi-v4/ic_appwidget_music_play.pngbin0 -> 344 bytes
-rw-r--r--subsonic-android/res/drawable-hdpi-v4/ic_appwidget_music_previous.pngbin0 -> 666 bytes
-rw-r--r--subsonic-android/res/drawable-hdpi-v4/ic_menu_exit.pngbin0 -> 3820 bytes
-rw-r--r--subsonic-android/res/drawable-hdpi-v4/ic_menu_help.pngbin0 -> 3468 bytes
-rw-r--r--subsonic-android/res/drawable-hdpi-v4/ic_menu_remove_all.pngbin0 -> 2546 bytes
-rw-r--r--subsonic-android/res/drawable-hdpi-v4/ic_menu_save.pngbin0 -> 1899 bytes
-rw-r--r--subsonic-android/res/drawable-hdpi-v4/ic_menu_screen_on_off.pngbin0 -> 1497 bytes
-rw-r--r--subsonic-android/res/drawable-hdpi-v4/ic_menu_settings.pngbin0 -> 3812 bytes
-rw-r--r--subsonic-android/res/drawable-hdpi-v4/ic_menu_shuffle.pngbin0 -> 4445 bytes
-rw-r--r--subsonic-android/res/drawable-hdpi-v4/launch.pngbin0 -> 5436 bytes
-rw-r--r--subsonic-android/res/drawable-hdpi-v4/list_item_artist.9.pngbin0 -> 2505 bytes
-rw-r--r--subsonic-android/res/drawable-hdpi-v4/list_item_playlist.9.pngbin0 -> 2505 bytes
-rw-r--r--subsonic-android/res/drawable-hdpi-v4/main_exit.pngbin0 -> 4532 bytes
-rw-r--r--subsonic-android/res/drawable-hdpi-v4/main_header_icon.pngbin0 -> 5356 bytes
-rw-r--r--subsonic-android/res/drawable-hdpi-v4/main_help.pngbin0 -> 4123 bytes
-rw-r--r--subsonic-android/res/drawable-hdpi-v4/main_select_server.pngbin0 -> 4458 bytes
-rw-r--r--subsonic-android/res/drawable-hdpi-v4/main_settings.pngbin0 -> 3401 bytes
-rw-r--r--subsonic-android/res/drawable-hdpi-v4/main_shuffle.pngbin0 -> 4445 bytes
-rw-r--r--subsonic-android/res/drawable-hdpi-v4/media_backward_normal.pngbin0 -> 10535 bytes
-rw-r--r--subsonic-android/res/drawable-hdpi-v4/media_backward_pressed.pngbin0 -> 11104 bytes
-rw-r--r--subsonic-android/res/drawable-hdpi-v4/media_forward_normal.pngbin0 -> 10559 bytes
-rw-r--r--subsonic-android/res/drawable-hdpi-v4/media_forward_pressed.pngbin0 -> 11099 bytes
-rw-r--r--subsonic-android/res/drawable-hdpi-v4/media_pause_normal.pngbin0 -> 17952 bytes
-rw-r--r--subsonic-android/res/drawable-hdpi-v4/media_pause_pressed.pngbin0 -> 20352 bytes
-rw-r--r--subsonic-android/res/drawable-hdpi-v4/media_repeat_all.pngbin0 -> 1428 bytes
-rw-r--r--subsonic-android/res/drawable-hdpi-v4/media_repeat_off.pngbin0 -> 1552 bytes
-rw-r--r--subsonic-android/res/drawable-hdpi-v4/media_repeat_single.pngbin0 -> 1889 bytes
-rw-r--r--subsonic-android/res/drawable-hdpi-v4/media_shuffle_normal.pngbin0 -> 1775 bytes
-rw-r--r--subsonic-android/res/drawable-hdpi-v4/media_shuffle_pressed.pngbin0 -> 3704 bytes
-rw-r--r--subsonic-android/res/drawable-hdpi-v4/media_start_normal.pngbin0 -> 18382 bytes
-rw-r--r--subsonic-android/res/drawable-hdpi-v4/media_start_pressed.pngbin0 -> 20804 bytes
-rw-r--r--subsonic-android/res/drawable-hdpi-v4/media_stop_normal.pngbin0 -> 16316 bytes
-rw-r--r--subsonic-android/res/drawable-hdpi-v4/media_stop_pressed.pngbin0 -> 18653 bytes
-rw-r--r--subsonic-android/res/drawable-hdpi-v4/media_toggle_list_normal.pngbin0 -> 636 bytes
-rw-r--r--subsonic-android/res/drawable-hdpi-v4/media_toggle_list_pressed.pngbin0 -> 3383 bytes
-rw-r--r--subsonic-android/res/drawable-hdpi-v4/menu_browse.pngbin0 -> 4007 bytes
-rw-r--r--subsonic-android/res/drawable-hdpi-v4/menu_home.pngbin0 -> 3259 bytes
-rw-r--r--subsonic-android/res/drawable-hdpi-v4/menu_now_playing.pngbin0 -> 3192 bytes
-rw-r--r--subsonic-android/res/drawable-hdpi-v4/menu_playlists.pngbin0 -> 997 bytes
-rw-r--r--subsonic-android/res/drawable-hdpi-v4/menu_search.pngbin0 -> 3808 bytes
-rw-r--r--subsonic-android/res/drawable-hdpi-v4/menubar_button_disabled.9.pngbin0 -> 266 bytes
-rw-r--r--subsonic-android/res/drawable-hdpi-v4/menubar_button_normal.9.pngbin0 -> 234 bytes
-rw-r--r--subsonic-android/res/drawable-hdpi-v4/menubar_button_pressed.9.pngbin0 -> 312 bytes
-rw-r--r--subsonic-android/res/drawable-hdpi-v4/refresh.pngbin0 -> 3585 bytes
-rw-r--r--subsonic-android/res/drawable-hdpi-v4/search.pngbin0 -> 2940 bytes
-rw-r--r--subsonic-android/res/drawable-hdpi-v4/select_album_play_all_normal.pngbin0 -> 5059 bytes
-rw-r--r--subsonic-android/res/drawable-hdpi-v4/select_album_play_all_pressed.pngbin0 -> 4962 bytes
-rw-r--r--subsonic-android/res/drawable-hdpi-v4/select_artist_folder.pngbin0 -> 4458 bytes
-rw-r--r--subsonic-android/res/drawable-hdpi-v4/stat_notify_playing.pngbin0 -> 716 bytes
-rw-r--r--subsonic-android/res/drawable-hdpi-v4/unknown_album.pngbin0 -> 3059 bytes
-rw-r--r--subsonic-android/res/drawable-hdpi-v4/unknown_album_large.pngbin0 -> 48194 bytes
-rw-r--r--subsonic-android/res/drawable/action_play_all.pngbin0 -> 3475 bytes
-rw-r--r--subsonic-android/res/drawable/action_refresh.pngbin0 -> 4282 bytes
-rw-r--r--subsonic-android/res/drawable/action_search.pngbin0 -> 4098 bytes
-rw-r--r--subsonic-android/res/drawable/action_shuffle.pngbin0 -> 5044 bytes
-rw-r--r--subsonic-android/res/drawable/actionbar_button.xml18
-rw-r--r--subsonic-android/res/drawable/actionbar_button_normal.9.pngbin0 -> 208 bytes
-rw-r--r--subsonic-android/res/drawable/album_art_background.pngbin0 -> 9287 bytes
-rw-r--r--subsonic-android/res/drawable/appwidget_art_default.pngbin0 -> 3711 bytes
-rw-r--r--subsonic-android/res/drawable/appwidget_art_unknown.pngbin0 -> 3711 bytes
-rw-r--r--subsonic-android/res/drawable/appwidget_bg.9.pngbin0 -> 1784 bytes
-rw-r--r--subsonic-android/res/drawable/appwidget_button_background.9.pngbin0 -> 174 bytes
-rw-r--r--subsonic-android/res/drawable/appwidget_button_background_r.9.pngbin0 -> 638 bytes
-rw-r--r--subsonic-android/res/drawable/appwidget_button_center.xml27
-rw-r--r--subsonic-android/res/drawable/appwidget_button_left.xml27
-rw-r--r--subsonic-android/res/drawable/appwidget_button_right.xml27
-rw-r--r--subsonic-android/res/drawable/appwidget_divider.9.pngbin0 -> 2806 bytes
-rw-r--r--subsonic-android/res/drawable/appwidget_divider_horizontal.9.pngbin0 -> 182 bytes
-rw-r--r--subsonic-android/res/drawable/appwidget_divider_vertical.pngbin0 -> 112 bytes
-rw-r--r--subsonic-android/res/drawable/appwidget_inner_focus_c.9.pngbin0 -> 212 bytes
-rw-r--r--subsonic-android/res/drawable/appwidget_inner_focus_l.9.pngbin0 -> 325 bytes
-rw-r--r--subsonic-android/res/drawable/appwidget_inner_focus_r.9.pngbin0 -> 324 bytes
-rw-r--r--subsonic-android/res/drawable/appwidget_inner_press_c.9.pngbin0 -> 212 bytes
-rw-r--r--subsonic-android/res/drawable/appwidget_inner_press_l.9.pngbin0 -> 335 bytes
-rw-r--r--subsonic-android/res/drawable/appwidget_inner_press_r.9.pngbin0 -> 330 bytes
-rw-r--r--subsonic-android/res/drawable/appwidget_overlay.pngbin0 -> 118 bytes
-rw-r--r--subsonic-android/res/drawable/downloaded.pngbin0 -> 799 bytes
-rw-r--r--subsonic-android/res/drawable/downloading.pngbin0 -> 457 bytes
-rw-r--r--subsonic-android/res/drawable/ic_appwidget_music_next.pngbin0 -> 311 bytes
-rw-r--r--subsonic-android/res/drawable/ic_appwidget_music_pause.pngbin0 -> 180 bytes
-rw-r--r--subsonic-android/res/drawable/ic_appwidget_music_play.pngbin0 -> 317 bytes
-rw-r--r--subsonic-android/res/drawable/ic_appwidget_music_previous.pngbin0 -> 412 bytes
-rw-r--r--subsonic-android/res/drawable/ic_menu_exit.pngbin0 -> 5689 bytes
-rw-r--r--subsonic-android/res/drawable/ic_menu_help.pngbin0 -> 5250 bytes
-rw-r--r--subsonic-android/res/drawable/ic_menu_remove_all.pngbin0 -> 4375 bytes
-rw-r--r--subsonic-android/res/drawable/ic_menu_save.pngbin0 -> 1140 bytes
-rw-r--r--subsonic-android/res/drawable/ic_menu_screen_on_off.pngbin0 -> 982 bytes
-rw-r--r--subsonic-android/res/drawable/ic_menu_settings.pngbin0 -> 5455 bytes
-rw-r--r--subsonic-android/res/drawable/ic_menu_shuffle.pngbin0 -> 6130 bytes
-rw-r--r--subsonic-android/res/drawable/launch.pngbin0 -> 3073 bytes
-rw-r--r--subsonic-android/res/drawable/list_item_artist.9.pngbin0 -> 1167 bytes
-rw-r--r--subsonic-android/res/drawable/list_item_playlist.9.pngbin0 -> 1167 bytes
-rw-r--r--subsonic-android/res/drawable/main_exit.pngbin0 -> 5185 bytes
-rw-r--r--subsonic-android/res/drawable/main_header_icon.pngbin0 -> 3052 bytes
-rw-r--r--subsonic-android/res/drawable/main_help.pngbin0 -> 5166 bytes
-rw-r--r--subsonic-android/res/drawable/main_select_server.pngbin0 -> 5223 bytes
-rw-r--r--subsonic-android/res/drawable/main_settings.pngbin0 -> 2315 bytes
-rw-r--r--subsonic-android/res/drawable/main_shuffle.pngbin0 -> 2384 bytes
-rw-r--r--subsonic-android/res/drawable/media_backward.xml5
-rw-r--r--subsonic-android/res/drawable/media_backward_normal.pngbin0 -> 6601 bytes
-rw-r--r--subsonic-android/res/drawable/media_backward_pressed.pngbin0 -> 7533 bytes
-rw-r--r--subsonic-android/res/drawable/media_forward.xml5
-rw-r--r--subsonic-android/res/drawable/media_forward_normal.pngbin0 -> 6525 bytes
-rw-r--r--subsonic-android/res/drawable/media_forward_pressed.pngbin0 -> 7452 bytes
-rw-r--r--subsonic-android/res/drawable/media_pause.xml5
-rw-r--r--subsonic-android/res/drawable/media_pause_normal.pngbin0 -> 10847 bytes
-rw-r--r--subsonic-android/res/drawable/media_pause_pressed.pngbin0 -> 11110 bytes
-rw-r--r--subsonic-android/res/drawable/media_repeat_all.pngbin0 -> 933 bytes
-rw-r--r--subsonic-android/res/drawable/media_repeat_off.pngbin0 -> 976 bytes
-rw-r--r--subsonic-android/res/drawable/media_repeat_single.pngbin0 -> 1276 bytes
-rw-r--r--subsonic-android/res/drawable/media_shuffle.xml5
-rw-r--r--subsonic-android/res/drawable/media_shuffle_normal.pngbin0 -> 1264 bytes
-rw-r--r--subsonic-android/res/drawable/media_shuffle_pressed.pngbin0 -> 2101 bytes
-rw-r--r--subsonic-android/res/drawable/media_start.xml5
-rw-r--r--subsonic-android/res/drawable/media_start_normal.pngbin0 -> 10958 bytes
-rw-r--r--subsonic-android/res/drawable/media_start_pressed.pngbin0 -> 11391 bytes
-rw-r--r--subsonic-android/res/drawable/media_stop.xml5
-rw-r--r--subsonic-android/res/drawable/media_stop_normal.pngbin0 -> 10079 bytes
-rw-r--r--subsonic-android/res/drawable/media_stop_pressed.pngbin0 -> 10468 bytes
-rw-r--r--subsonic-android/res/drawable/media_toggle_list.xml5
-rw-r--r--subsonic-android/res/drawable/media_toggle_list_normal.pngbin0 -> 547 bytes
-rw-r--r--subsonic-android/res/drawable/media_toggle_list_pressed.pngbin0 -> 1923 bytes
-rw-r--r--subsonic-android/res/drawable/menu_browse.pngbin0 -> 2355 bytes
-rw-r--r--subsonic-android/res/drawable/menu_home.pngbin0 -> 2048 bytes
-rw-r--r--subsonic-android/res/drawable/menu_now_playing.pngbin0 -> 2078 bytes
-rw-r--r--subsonic-android/res/drawable/menu_playlists.pngbin0 -> 706 bytes
-rw-r--r--subsonic-android/res/drawable/menu_search.pngbin0 -> 5059 bytes
-rw-r--r--subsonic-android/res/drawable/menubar_button.xml14
-rw-r--r--subsonic-android/res/drawable/menubar_button_disabled.9.pngbin0 -> 266 bytes
-rw-r--r--subsonic-android/res/drawable/menubar_button_normal.9.pngbin0 -> 234 bytes
-rw-r--r--subsonic-android/res/drawable/menubar_button_pressed.9.pngbin0 -> 312 bytes
-rw-r--r--subsonic-android/res/drawable/refresh.pngbin0 -> 2296 bytes
-rw-r--r--subsonic-android/res/drawable/saved.pngbin0 -> 838 bytes
-rw-r--r--subsonic-android/res/drawable/search.pngbin0 -> 1390 bytes
-rw-r--r--subsonic-android/res/drawable/select_album_play_all.xml5
-rw-r--r--subsonic-android/res/drawable/select_album_play_all_normal.pngbin0 -> 2962 bytes
-rw-r--r--subsonic-android/res/drawable/select_album_play_all_pressed.pngbin0 -> 2948 bytes
-rw-r--r--subsonic-android/res/drawable/select_artist_folder.pngbin0 -> 2289 bytes
-rw-r--r--subsonic-android/res/drawable/slider_knob.pngbin0 -> 1125 bytes
-rw-r--r--subsonic-android/res/drawable/stat_notify_playing.pngbin0 -> 771 bytes
-rw-r--r--subsonic-android/res/drawable/toast_frame.9.pngbin0 -> 2461 bytes
-rw-r--r--subsonic-android/res/drawable/unknown_album.pngbin0 -> 1819 bytes
-rw-r--r--subsonic-android/res/drawable/unknown_album_large.pngbin0 -> 33912 bytes
-rw-r--r--subsonic-android/res/layout-land/download.xml207
-rw-r--r--subsonic-android/res/layout-port/download.xml198
-rw-r--r--subsonic-android/res/layout/action_bar.xml71
-rw-r--r--subsonic-android/res/layout/album_list_item.xml47
-rw-r--r--subsonic-android/res/layout/appwidget.xml97
-rw-r--r--subsonic-android/res/layout/artist_list_item.xml12
-rw-r--r--subsonic-android/res/layout/button_bar.xml61
-rw-r--r--subsonic-android/res/layout/download_button_bar_flipper.xml67
-rw-r--r--subsonic-android/res/layout/download_playlist.xml24
-rw-r--r--subsonic-android/res/layout/download_slider.xml13
-rw-r--r--subsonic-android/res/layout/equalizer.xml47
-rw-r--r--subsonic-android/res/layout/equalizer_bar.xml39
-rw-r--r--subsonic-android/res/layout/help.xml42
-rw-r--r--subsonic-android/res/layout/jukebox_volume.xml29
-rw-r--r--subsonic-android/res/layout/lyrics.xml57
-rw-r--r--subsonic-android/res/layout/main.xml34
-rw-r--r--subsonic-android/res/layout/main_buttons.xml119
-rw-r--r--subsonic-android/res/layout/notification.xml31
-rw-r--r--subsonic-android/res/layout/play_video.xml11
-rw-r--r--subsonic-android/res/layout/playlist_list_item.xml12
-rw-r--r--subsonic-android/res/layout/progress.xml20
-rw-r--r--subsonic-android/res/layout/save_playlist.xml17
-rw-r--r--subsonic-android/res/layout/search.xml26
-rw-r--r--subsonic-android/res/layout/search_buttons.xml85
-rw-r--r--subsonic-android/res/layout/select_album.xml73
-rw-r--r--subsonic-android/res/layout/select_album_footer.xml48
-rw-r--r--subsonic-android/res/layout/select_album_header.xml69
-rw-r--r--subsonic-android/res/layout/select_artist.xml26
-rw-r--r--subsonic-android/res/layout/select_artist_header.xml38
-rw-r--r--subsonic-android/res/layout/select_playlist.xml34
-rw-r--r--subsonic-android/res/layout/song_list_item.xml76
-rw-r--r--subsonic-android/res/layout/tab_progress.xml24
-rw-r--r--subsonic-android/res/menu/main.xml22
-rw-r--r--subsonic-android/res/menu/nowplaying.xml27
-rw-r--r--subsonic-android/res/menu/nowplaying_context.xml34
-rw-r--r--subsonic-android/res/menu/select_album_context.xml19
-rw-r--r--subsonic-android/res/menu/select_artist_context.xml19
-rw-r--r--subsonic-android/res/menu/select_song_context.xml19
-rw-r--r--subsonic-android/res/values-fr/strings.xml208
-rw-r--r--subsonic-android/res/values-v11/colors.xml5
-rw-r--r--subsonic-android/res/values/arrays.xml86
-rw-r--r--subsonic-android/res/values/colors.xml13
-rw-r--r--subsonic-android/res/values/strings.xml242
-rw-r--r--subsonic-android/res/values/styles.xml14
-rw-r--r--subsonic-android/res/xml/appwidget_info.xml6
-rw-r--r--subsonic-android/res/xml/searchable.xml9
-rw-r--r--subsonic-android/res/xml/settings.xml200
-rw-r--r--subsonic-android/src/net/sourceforge/subsonic/androidapp/activity/DownloadActivity.java874
-rw-r--r--subsonic-android/src/net/sourceforge/subsonic/androidapp/activity/EqualizerActivity.java181
-rw-r--r--subsonic-android/src/net/sourceforge/subsonic/androidapp/activity/HelpActivity.java117
-rw-r--r--subsonic-android/src/net/sourceforge/subsonic/androidapp/activity/LyricsActivity.java72
-rw-r--r--subsonic-android/src/net/sourceforge/subsonic/androidapp/activity/MainActivity.java258
-rw-r--r--subsonic-android/src/net/sourceforge/subsonic/androidapp/activity/PlayVideoActivity.java147
-rw-r--r--subsonic-android/src/net/sourceforge/subsonic/androidapp/activity/QueryReceiverActivity.java56
-rw-r--r--subsonic-android/src/net/sourceforge/subsonic/androidapp/activity/SearchActivity.java368
-rw-r--r--subsonic-android/src/net/sourceforge/subsonic/androidapp/activity/SelectAlbumActivity.java568
-rw-r--r--subsonic-android/src/net/sourceforge/subsonic/androidapp/activity/SelectArtistActivity.java228
-rw-r--r--subsonic-android/src/net/sourceforge/subsonic/androidapp/activity/SelectPlaylistActivity.java141
-rw-r--r--subsonic-android/src/net/sourceforge/subsonic/androidapp/activity/SettingsActivity.java297
-rw-r--r--subsonic-android/src/net/sourceforge/subsonic/androidapp/activity/SubsonicTabActivity.java383
-rw-r--r--subsonic-android/src/net/sourceforge/subsonic/androidapp/activity/VoiceQueryReceiverActivity.java59
-rw-r--r--subsonic-android/src/net/sourceforge/subsonic/androidapp/audiofx/EqualizerController.java138
-rw-r--r--subsonic-android/src/net/sourceforge/subsonic/androidapp/audiofx/VisualizerController.java90
-rw-r--r--subsonic-android/src/net/sourceforge/subsonic/androidapp/domain/Artist.java60
-rw-r--r--subsonic-android/src/net/sourceforge/subsonic/androidapp/domain/Indexes.java50
-rw-r--r--subsonic-android/src/net/sourceforge/subsonic/androidapp/domain/JukeboxStatus.java63
-rw-r--r--subsonic-android/src/net/sourceforge/subsonic/androidapp/domain/Lyrics.java55
-rw-r--r--subsonic-android/src/net/sourceforge/subsonic/androidapp/domain/MusicDirectory.java259
-rw-r--r--subsonic-android/src/net/sourceforge/subsonic/androidapp/domain/MusicFolder.java46
-rw-r--r--subsonic-android/src/net/sourceforge/subsonic/androidapp/domain/PlayerState.java34
-rw-r--r--subsonic-android/src/net/sourceforge/subsonic/androidapp/domain/Playlist.java56
-rw-r--r--subsonic-android/src/net/sourceforge/subsonic/androidapp/domain/RepeatMode.java28
-rw-r--r--subsonic-android/src/net/sourceforge/subsonic/androidapp/domain/SearchCritera.java55
-rw-r--r--subsonic-android/src/net/sourceforge/subsonic/androidapp/domain/SearchResult.java51
-rw-r--r--subsonic-android/src/net/sourceforge/subsonic/androidapp/domain/ServerInfo.java46
-rw-r--r--subsonic-android/src/net/sourceforge/subsonic/androidapp/domain/Version.java142
-rw-r--r--subsonic-android/src/net/sourceforge/subsonic/androidapp/provider/SearchSuggestionProvider.java36
-rw-r--r--subsonic-android/src/net/sourceforge/subsonic/androidapp/provider/SubsonicAppWidgetProvider.java238
-rw-r--r--subsonic-android/src/net/sourceforge/subsonic/androidapp/receiver/BluetoothIntentReceiver.java53
-rw-r--r--subsonic-android/src/net/sourceforge/subsonic/androidapp/receiver/MediaButtonIntentReceiver.java50
-rw-r--r--subsonic-android/src/net/sourceforge/subsonic/androidapp/service/CachedMusicService.java237
-rw-r--r--subsonic-android/src/net/sourceforge/subsonic/androidapp/service/DownloadFile.java323
-rw-r--r--subsonic-android/src/net/sourceforge/subsonic/androidapp/service/DownloadService.java112
-rw-r--r--subsonic-android/src/net/sourceforge/subsonic/androidapp/service/DownloadServiceImpl.java930
-rw-r--r--subsonic-android/src/net/sourceforge/subsonic/androidapp/service/DownloadServiceLifecycleSupport.java266
-rw-r--r--subsonic-android/src/net/sourceforge/subsonic/androidapp/service/JukeboxService.java356
-rw-r--r--subsonic-android/src/net/sourceforge/subsonic/androidapp/service/MediaStoreService.java109
-rw-r--r--subsonic-android/src/net/sourceforge/subsonic/androidapp/service/MusicService.java91
-rw-r--r--subsonic-android/src/net/sourceforge/subsonic/androidapp/service/MusicServiceFactory.java36
-rw-r--r--subsonic-android/src/net/sourceforge/subsonic/androidapp/service/OfflineException.java32
-rw-r--r--subsonic-android/src/net/sourceforge/subsonic/androidapp/service/OfflineMusicService.java244
-rw-r--r--subsonic-android/src/net/sourceforge/subsonic/androidapp/service/RESTMusicService.java768
-rw-r--r--subsonic-android/src/net/sourceforge/subsonic/androidapp/service/Scrobbler.java52
-rw-r--r--subsonic-android/src/net/sourceforge/subsonic/androidapp/service/ServerTooOldException.java51
-rw-r--r--subsonic-android/src/net/sourceforge/subsonic/androidapp/service/parser/AbstractParser.java138
-rw-r--r--subsonic-android/src/net/sourceforge/subsonic/androidapp/service/parser/AlbumListParser.java62
-rw-r--r--subsonic-android/src/net/sourceforge/subsonic/androidapp/service/parser/ErrorParser.java49
-rw-r--r--subsonic-android/src/net/sourceforge/subsonic/androidapp/service/parser/IndexesParser.java104
-rw-r--r--subsonic-android/src/net/sourceforge/subsonic/androidapp/service/parser/JukeboxStatusParser.java62
-rw-r--r--subsonic-android/src/net/sourceforge/subsonic/androidapp/service/parser/LicenseParser.java62
-rw-r--r--subsonic-android/src/net/sourceforge/subsonic/androidapp/service/parser/LyricsParser.java65
-rw-r--r--subsonic-android/src/net/sourceforge/subsonic/androidapp/service/parser/MusicDirectoryEntryParser.java59
-rw-r--r--subsonic-android/src/net/sourceforge/subsonic/androidapp/service/parser/MusicDirectoryParser.java71
-rw-r--r--subsonic-android/src/net/sourceforge/subsonic/androidapp/service/parser/MusicFoldersParser.java69
-rw-r--r--subsonic-android/src/net/sourceforge/subsonic/androidapp/service/parser/PlaylistParser.java62
-rw-r--r--subsonic-android/src/net/sourceforge/subsonic/androidapp/service/parser/PlaylistsParser.java67
-rw-r--r--subsonic-android/src/net/sourceforge/subsonic/androidapp/service/parser/RandomSongsParser.java62
-rw-r--r--subsonic-android/src/net/sourceforge/subsonic/androidapp/service/parser/SearchResult2Parser.java75
-rw-r--r--subsonic-android/src/net/sourceforge/subsonic/androidapp/service/parser/SearchResultParser.java67
-rw-r--r--subsonic-android/src/net/sourceforge/subsonic/androidapp/service/parser/SubsonicRESTException.java19
-rw-r--r--subsonic-android/src/net/sourceforge/subsonic/androidapp/service/parser/VersionParser.java47
-rw-r--r--subsonic-android/src/net/sourceforge/subsonic/androidapp/service/ssl/SSLSocketFactory.java497
-rw-r--r--subsonic-android/src/net/sourceforge/subsonic/androidapp/service/ssl/TrustManagerDecorator.java65
-rw-r--r--subsonic-android/src/net/sourceforge/subsonic/androidapp/service/ssl/TrustSelfSignedStrategy.java44
-rw-r--r--subsonic-android/src/net/sourceforge/subsonic/androidapp/service/ssl/TrustStrategy.java57
-rw-r--r--subsonic-android/src/net/sourceforge/subsonic/androidapp/util/AlbumView.java55
-rw-r--r--subsonic-android/src/net/sourceforge/subsonic/androidapp/util/ArtistAdapter.java78
-rw-r--r--subsonic-android/src/net/sourceforge/subsonic/androidapp/util/BackgroundTask.java96
-rw-r--r--subsonic-android/src/net/sourceforge/subsonic/androidapp/util/CacheCleaner.java171
-rw-r--r--subsonic-android/src/net/sourceforge/subsonic/androidapp/util/CancellableTask.java87
-rw-r--r--subsonic-android/src/net/sourceforge/subsonic/androidapp/util/Constants.java91
-rw-r--r--subsonic-android/src/net/sourceforge/subsonic/androidapp/util/EntryAdapter.java71
-rw-r--r--subsonic-android/src/net/sourceforge/subsonic/androidapp/util/ErrorDialog.java61
-rw-r--r--subsonic-android/src/net/sourceforge/subsonic/androidapp/util/FileUtil.java301
-rw-r--r--subsonic-android/src/net/sourceforge/subsonic/androidapp/util/HorizontalSlider.java141
-rw-r--r--subsonic-android/src/net/sourceforge/subsonic/androidapp/util/ImageLoader.java252
-rw-r--r--subsonic-android/src/net/sourceforge/subsonic/androidapp/util/LRUCache.java102
-rw-r--r--subsonic-android/src/net/sourceforge/subsonic/androidapp/util/MergeAdapter.java290
-rw-r--r--subsonic-android/src/net/sourceforge/subsonic/androidapp/util/ModalBackgroundTask.java139
-rw-r--r--subsonic-android/src/net/sourceforge/subsonic/androidapp/util/MyViewFlipper.java53
-rw-r--r--subsonic-android/src/net/sourceforge/subsonic/androidapp/util/Pair.java54
-rw-r--r--subsonic-android/src/net/sourceforge/subsonic/androidapp/util/PlaylistAdapter.java99
-rw-r--r--subsonic-android/src/net/sourceforge/subsonic/androidapp/util/ProgressListener.java27
-rw-r--r--subsonic-android/src/net/sourceforge/subsonic/androidapp/util/SackOfViewsAdapter.java181
-rw-r--r--subsonic-android/src/net/sourceforge/subsonic/androidapp/util/ShufflePlayBuffer.java109
-rw-r--r--subsonic-android/src/net/sourceforge/subsonic/androidapp/util/SilentBackgroundTask.java67
-rw-r--r--subsonic-android/src/net/sourceforge/subsonic/androidapp/util/SimpleServiceBinder.java37
-rw-r--r--subsonic-android/src/net/sourceforge/subsonic/androidapp/util/SongView.java178
-rw-r--r--subsonic-android/src/net/sourceforge/subsonic/androidapp/util/TabActivityBackgroundTask.java67
-rw-r--r--subsonic-android/src/net/sourceforge/subsonic/androidapp/util/TimeLimitedCache.java55
-rw-r--r--subsonic-android/src/net/sourceforge/subsonic/androidapp/util/Util.java829
-rw-r--r--subsonic-android/src/net/sourceforge/subsonic/androidapp/view/VisualizerView.java132
-rw-r--r--subsonic-android/subsonic.keystorebin0 -> 1204 bytes
-rw-r--r--subsonic-android/tests/AndroidManifest.xml21
-rw-r--r--subsonic-android/tests/build.properties15
-rw-r--r--subsonic-android/tests/build.xml61
-rw-r--r--subsonic-android/tests/default.properties11
323 files changed, 19274 insertions, 0 deletions
diff --git a/subsonic-android/AndroidManifest.xml b/subsonic-android/AndroidManifest.xml
new file mode 100644
index 00000000..914f02fb
--- /dev/null
+++ b/subsonic-android/AndroidManifest.xml
@@ -0,0 +1,117 @@
+<?xml version="1.0" encoding="utf-8"?>
+<manifest xmlns:android="http://schemas.android.com/apk/res/android"
+ package="net.sourceforge.subsonic.androidapp"
+ android:installLocation="auto"
+ android:versionCode="46"
+ android:versionName="3.3">
+
+ <uses-permission android:name="android.permission.INTERNET"/>
+ <uses-permission android:name="android.permission.READ_PHONE_STATE"/>
+ <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
+ <uses-permission android:name="android.permission.WAKE_LOCK"/>
+ <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
+ <uses-permission android:name="android.permission.RECORD_AUDIO"/>
+ <uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS"/>
+
+ <uses-sdk android:minSdkVersion="3" android:targetSdkVersion="10"/>
+
+ <supports-screens android:anyDensity="true" android:xlargeScreens="true" android:largeScreens="true" android:normalScreens="true" android:smallScreens="true"/>
+
+ <application android:label="@string/common.appname" android:icon="@drawable/launch" android:theme="@style/Wheat">
+
+ <activity android:name="net.sourceforge.subsonic.androidapp.activity.MainActivity"
+ android:label="Subsonic"
+ android:configChanges="orientation|keyboardHidden"
+ android:launchMode="standard">
+ <intent-filter>
+ <action android:name="android.intent.action.MAIN"/>
+ <category android:name="android.intent.category.LAUNCHER"/>
+ </intent-filter>
+ </activity>
+
+ <activity android:name="net.sourceforge.subsonic.androidapp.activity.SelectArtistActivity"
+ android:configChanges="orientation|keyboardHidden"
+ android:launchMode="standard"/>
+
+ <activity android:name="net.sourceforge.subsonic.androidapp.activity.SelectAlbumActivity"
+ android:configChanges="orientation|keyboardHidden"/>
+
+ <activity android:name="net.sourceforge.subsonic.androidapp.activity.SearchActivity"
+ android:label="@string/search.label"
+ android:configChanges="orientation|keyboardHidden"
+ android:launchMode="singleTask"/>
+
+ <activity android:name="net.sourceforge.subsonic.androidapp.activity.SelectPlaylistActivity"
+ android:label="@string/playlist.label"
+ android:configChanges="orientation|keyboardHidden"
+ android:launchMode="standard"/>
+
+ <activity android:name="net.sourceforge.subsonic.androidapp.activity.DownloadActivity"
+ android:configChanges="keyboardHidden"
+ android:launchMode="singleTask"/>
+
+ <activity android:name="net.sourceforge.subsonic.androidapp.activity.SettingsActivity"
+ android:theme="@android:style/Theme"
+ android:configChanges="orientation|keyboardHidden"
+ android:launchMode="singleTask"/>
+
+ <activity android:name="net.sourceforge.subsonic.androidapp.activity.HelpActivity"
+ android:label="@string/help.label"
+ android:launchMode="singleTask"/>
+
+ <activity android:name="net.sourceforge.subsonic.androidapp.activity.LyricsActivity"
+ android:configChanges="orientation|keyboardHidden"
+ android:launchMode="singleTask"/>
+
+ <activity android:name="net.sourceforge.subsonic.androidapp.activity.EqualizerActivity"
+ android:label="@string/equalizer.label"
+ android:configChanges="orientation|keyboardHidden"
+ android:launchMode="singleTask"/>
+
+ <activity android:name="net.sourceforge.subsonic.androidapp.activity.VoiceQueryReceiverActivity"
+ android:launchMode="singleTask">
+ <intent-filter>
+ <action android:name="android.media.action.MEDIA_PLAY_FROM_SEARCH" />
+ <category android:name="android.intent.category.DEFAULT" />
+ </intent-filter>
+ </activity>
+
+ <activity android:name="net.sourceforge.subsonic.androidapp.activity.QueryReceiverActivity"
+ android:launchMode="singleTask">
+ <intent-filter>
+ <action android:name="android.intent.action.SEARCH"/>
+ </intent-filter>
+ <meta-data android:name="android.app.searchable" android:resource="@xml/searchable"/>
+ </activity>
+
+ <service android:name="net.sourceforge.subsonic.androidapp.service.DownloadServiceImpl"
+ android:label="Subsonic Download Service"/>
+
+ <receiver android:name="net.sourceforge.subsonic.androidapp.receiver.MediaButtonIntentReceiver">
+ <intent-filter android:priority="999">
+ <action android:name="android.intent.action.MEDIA_BUTTON" />
+ </intent-filter>
+ </receiver>
+
+ <receiver android:name="net.sourceforge.subsonic.androidapp.receiver.BluetoothIntentReceiver">
+ <intent-filter>
+ <action android:name="android.bluetooth.a2dp.action.SINK_STATE_CHANGED"/>
+ </intent-filter>
+ </receiver>
+
+ <receiver android:name="net.sourceforge.subsonic.androidapp.provider.SubsonicAppWidgetProvider" >
+ <intent-filter>
+ <action android:name="android.appwidget.action.APPWIDGET_UPDATE"/>
+ </intent-filter>
+ <meta-data android:name="android.appwidget.provider" android:resource="@xml/appwidget_info"/>
+ </receiver>
+
+ <provider android:name="net.sourceforge.subsonic.androidapp.provider.SearchSuggestionProvider"
+ android:authorities="net.sourceforge.subsonic.androidapp.provider.SearchSuggestionProvider"/>
+
+ <meta-data android:name="android.app.default_searchable"
+ android:value="net.sourceforge.subsonic.androidapp.activity.QueryReceiverActivity"/>
+
+ </application>
+
+</manifest>
diff --git a/subsonic-android/ant.properties b/subsonic-android/ant.properties
new file mode 100644
index 00000000..fb0849b1
--- /dev/null
+++ b/subsonic-android/ant.properties
@@ -0,0 +1,20 @@
+# This file is used to override default values used by the Ant build system.
+#
+# This file must be checked in Version Control Systems, as it is
+# integral to the build system of your project.
+
+# This file is only used by the Ant script.
+
+# You can use this to override default values such as
+# 'source.dir' for the location of your java source folder and
+# 'out.dir' for the location of your output folder.
+
+# You can also use it define how the release builds are signed by declaring
+# the following properties:
+# 'key.store' for the location of your keystore and
+# 'key.alias' for the name of the key to use.
+# The password will be asked during the build when you use the 'release' target.
+
+key.store=subsonic.keystore
+key.alias=subsonic
+
diff --git a/subsonic-android/assets/fonts/Storopia.ttf b/subsonic-android/assets/fonts/Storopia.ttf
new file mode 100644
index 00000000..cbdc4c1f
--- /dev/null
+++ b/subsonic-android/assets/fonts/Storopia.ttf
Binary files differ
diff --git a/subsonic-android/assets/html/en/index.html b/subsonic-android/assets/html/en/index.html
new file mode 100644
index 00000000..6462ef1f
--- /dev/null
+++ b/subsonic-android/assets/html/en/index.html
@@ -0,0 +1,98 @@
+<html>
+<head>
+ <title>Subsonic Help</title>
+ <link rel="stylesheet" href="../style.css" type="text/css">
+
+</head>
+
+<body>
+
+<h3><img src="../img/subsonic.png" alt=""> Welcome to Subsonic</h3>
+
+<p>
+ With <b>Subsonic</b> you can easily stream or download music from your home computer to your Android phone
+ (and do lots of other cool stuff too).
+</p>
+
+<p>
+ To install the Subsonic server software on your computer, please visit <a href="http://subsonic.org">subsonic.org</a>.
+ It's available for Windows, Mac, Linux and Unix.
+</p>
+
+<p>
+ By default, this program is configured to use the <b>Subsonic demo server</b>. Once you've set up your own
+ server, please go to <b>Settings</b> and change the configuration so that it connects to your own computer.
+</p>
+
+<p>
+ You can use this program freely for 30 days. After that you will have to make a donation to the Subsonic project.
+ As a donor you get the following benefits:
+</p>
+<ul>
+ <li>Unlimited streaming and download to any number of iPhone and Android phones.</li>
+ <li>Video streaming.</li>
+ <li>A personal web address for your Subsonic server (<em>yourname</em>.subsonic.org).</li>
+ <li>No ads in the Subsonic web interface.</li>
+ <li>Free access to new premium features.</li>
+</ul>
+
+<p>
+ The suggested donation amount is <b>&euro;20</b>, but you can give any amount you like.
+</p>
+
+<p>
+ Click one of the buttons to go to PayPal where you can pay by credit card or by using your PayPal account.
+ Once the donation is processed, you will receive a license key by email.
+</p>
+
+<table>
+ <tr>
+ <td style="border:none;">
+ <table>
+ <tr>
+ <td style="border:none;padding:0;padding:0"><a href="https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=3RTGWJRNAW2PU"><img src="../img/paypal.gif" alt=""/></a> </td>
+ </tr>
+ <tr>
+ <td style="text-align:center;border:none;padding:0">&euro;10</td>
+ </tr>
+ </table>
+ </td>
+ <td style="border:none;">
+ <table>
+ <tr>
+ <td style="border:none;padding:0"><a href="https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=UCUUB2TYE4PGN"><img src="../img/paypal.gif" alt=""/></a> </td>
+ </tr>
+ <tr>
+ <td style="text-align:center;border:none;padding:0">&euro;20</td>
+ </tr>
+ </table>
+ </td>
+ <td style="border:none;">
+ <table>
+ <tr>
+ <td style="border:none;padding:0"><a href="https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=3M6TFHWEPSU44"><img src="../img/paypal.gif" alt=""/></a> </td>
+ </tr>
+ <tr>
+ <td style="text-align:center;border:none;padding:0">&euro;25</td>
+ </tr>
+ </table>
+ </td>
+ <td style="border:none;">
+ <table>
+ <tr>
+ <td style="border:none;padding:0"><a href="https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=5KP7LPQU77UAS"><img src="../img/paypal.gif" alt=""/></a> </td>
+ </tr>
+ <tr>
+ <td style="text-align:center;border:none;padding:0">&euro;30</td>
+ </tr>
+ </table>
+ </td>
+ </tr>
+</table>
+
+<p>
+ For more information, please visit <a href="http://subsonic.org/">subsonic.org</a>
+</p>
+
+</body>
+</html>
diff --git a/subsonic-android/assets/html/fr/index.html b/subsonic-android/assets/html/fr/index.html
new file mode 100644
index 00000000..4ac8c9c3
--- /dev/null
+++ b/subsonic-android/assets/html/fr/index.html
@@ -0,0 +1,100 @@
+<html>
+<head>
+ <title>Aide de Subsonic</title>
+ <link rel="stylesheet" href="../style.css" type="text/css">
+
+</head>
+
+<body>
+
+<h3><img src="../img/subsonic.png" alt=""> Bienvenue dans Subsonic</h3>
+
+<p>
+ Avec <b>Subsonic</b>, vous pouvez facilement &eacute;couter ou t&eacute;l&eacute;charger de la musique &agrave; partir de votre ordinateur personnel sur votre appareil Android
+ (et faire plein d'autres trucs cools aussi).
+</p>
+
+<p>
+ Pour installer le serveur Subsonic sur votre ordinateur, veuillez visiter <a href="http://subsonic.org">subsonic.org</a>.
+ Celui-ci est disponible pour Windows, Mac, Linux et Unix.
+</p>
+
+<p>
+ Par d&eacute;faut, cette application est configur&eacute; pour utiliser le <b>serveur d&eacute;mo Subsonic</b>.
+ Apr&egrave;s avoir configur&eacute; votre serveur personnel, veuillez acc&eacute;der aux <b>Param&egrave;tres</b> et modifier la configuration
+ afin de vous connecter &agrave; votre propre ordinateur.
+</p>
+
+<p>
+ Vous pouvez utiliser cette application gratuitement pendant 30 jours.
+ Ensuite, vous devrez effectuer un don au projet Subsonic.
+ En tant que donateur, vous obtiendrez les b&eacute;n&eacute;fices suivants:
+</p>
+<ul>
+ <li>&Eacute;coute et t&eacute;l&eacute;chargement illimit&eacute;s vers autant de iPhones et d'appareils Android que d&eacute;sir&eacute;.</li>
+ <li>&Eacute;coute de vid&eacute;os.</li>
+ <li>Une adresse web personnalis&eacute;e pour votre serveur Subsonic (<em>votrenom</em>.subsonic.org).</li>
+ <li>Aucune publicit&eacute; dans l'interface web de Subsonic.</li>
+ <li>Acc&egrave;s gratuit aux nouvelles fonctionnalit&eacute;s avanc&eacute;es.</li>
+</ul>
+
+<p>
+ Le montant sugg&eacute;r&eacute; pour le don est de <b>20&euro;</b>, mais n'importe quel montant fera l'affaire.
+</p>
+
+<p>
+ Cliquez l'un des boutons suivants pour acc&eacute;der &agrave; PayPal, d'o&ugrave; vous pourrez payer soit par carte de cr&eacute;dit ou en utilisant votre compte PayPal.
+ Une fois le don re&ccedil;u et trait&eacute;, vous recevrez votre cl&eacute; d'activation par courriel.
+</p>
+
+<table>
+ <tr>
+ <td style="border:none;">
+ <table>
+ <tr>
+ <td style="border:none;padding:0;padding:0"><a href="https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=3RTGWJRNAW2PU"><img src="../img/paypal.gif" alt=""/></a> </td>
+ </tr>
+ <tr>
+ <td style="text-align:center;border:none;padding:0">10&euro;</td>
+ </tr>
+ </table>
+ </td>
+ <td style="border:none;">
+ <table>
+ <tr>
+ <td style="border:none;padding:0"><a href="https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=UCUUB2TYE4PGN"><img src="../img/paypal.gif" alt=""/></a> </td>
+ </tr>
+ <tr>
+ <td style="text-align:center;border:none;padding:0">20&euro;</td>
+ </tr>
+ </table>
+ </td>
+ <td style="border:none;">
+ <table>
+ <tr>
+ <td style="border:none;padding:0"><a href="https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=3M6TFHWEPSU44"><img src="../img/paypal.gif" alt=""/></a> </td>
+ </tr>
+ <tr>
+ <td style="text-align:center;border:none;padding:0">25&euro;</td>
+ </tr>
+ </table>
+ </td>
+ <td style="border:none;">
+ <table>
+ <tr>
+ <td style="border:none;padding:0"><a href="https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=5KP7LPQU77UAS"><img src="../img/paypal.gif" alt=""/></a> </td>
+ </tr>
+ <tr>
+ <td style="text-align:center;border:none;padding:0">30&euro;</td>
+ </tr>
+ </table>
+ </td>
+ </tr>
+</table>
+
+<p>
+ Pour plus d'information, veuillez visiter <a href="http://subsonic.org/">subsonic.org</a>
+</p>
+
+</body>
+</html>
diff --git a/subsonic-android/assets/html/img/paypal.gif b/subsonic-android/assets/html/img/paypal.gif
new file mode 100644
index 00000000..d017250a
--- /dev/null
+++ b/subsonic-android/assets/html/img/paypal.gif
Binary files differ
diff --git a/subsonic-android/assets/html/img/subsonic.png b/subsonic-android/assets/html/img/subsonic.png
new file mode 100644
index 00000000..38c521c5
--- /dev/null
+++ b/subsonic-android/assets/html/img/subsonic.png
Binary files differ
diff --git a/subsonic-android/assets/html/style.css b/subsonic-android/assets/html/style.css
new file mode 100644
index 00000000..9c1d55f2
--- /dev/null
+++ b/subsonic-android/assets/html/style.css
@@ -0,0 +1,11 @@
+/*
+* Taken from http://yui.yahooapis.com/2.8.0r4/build/fonts/fonts.css
+*/
+body {
+ font: 13px / 1.231 arial, helvetica, clean, sans-serif;
+}
+
+table {
+ font-size:inherit;
+ font:100%;
+} \ No newline at end of file
diff --git a/subsonic-android/build.xml b/subsonic-android/build.xml
new file mode 100644
index 00000000..02e7d6ab
--- /dev/null
+++ b/subsonic-android/build.xml
@@ -0,0 +1,85 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project name="subsonic" default="help">
+
+ <!-- The local.properties file is created and updated by the 'android' tool.
+ It contains the path to the SDK. It should *NOT* be checked into
+ Version Control Systems. -->
+ <loadproperties srcFile="local.properties" />
+
+ <!-- The ant.properties file can be created by you. It is only edited by the
+ 'android' tool to add properties to it.
+ This is the place to change some Ant specific build properties.
+ Here are some properties you may want to change/update:
+
+ source.dir
+ The name of the source directory. Default is 'src'.
+ out.dir
+ The name of the output directory. Default is 'bin'.
+
+ For other overridable properties, look at the beginning of the rules
+ files in the SDK, at tools/ant/build.xml
+
+ Properties related to the SDK location or the project target should
+ be updated using the 'android' tool with the 'update' action.
+
+ This file is an integral part of the build system for your
+ application and should be checked into Version Control Systems.
+
+ -->
+ <property file="ant.properties" />
+
+ <!-- The project.properties file is created and updated by the 'android'
+ tool, as well as ADT.
+
+ This contains project specific properties such as project target, and library
+ dependencies. Lower level build properties are stored in ant.properties
+ (or in .classpath for Eclipse projects).
+
+ This file is an integral part of the build system for your
+ application and should be checked into Version Control Systems. -->
+ <loadproperties srcFile="project.properties" />
+
+ <!-- quick check on sdk.dir -->
+ <fail
+ message="sdk.dir is missing. Make sure to generate local.properties using 'android update project'"
+ unless="sdk.dir"
+ />
+
+
+<!-- extension targets. Uncomment the ones where you want to do custom work
+ in between standard targets -->
+<!--
+ <target name="-pre-build">
+ </target>
+ <target name="-pre-compile">
+ </target>
+
+ /* This is typically used for code obfuscation.
+ Compiled code location: ${out.classes.absolute.dir}
+ If this is not done in place, override ${out.dex.input.absolute.dir} */
+ <target name="-post-compile">
+ </target>
+-->
+
+ <!-- Import the actual build file.
+
+ To customize existing targets, there are two options:
+ - Customize only one target:
+ - copy/paste the target into this file, *before* the
+ <import> task.
+ - customize it to your needs.
+ - Customize the whole content of build.xml
+ - copy/paste the content of the rules files (minus the top node)
+ into this file, replacing the <import> task.
+ - customize to your needs.
+
+ ***********************
+ ****** IMPORTANT ******
+ ***********************
+ In all cases you must update the value of version-tag below to read 'custom' instead of an integer,
+ in order to avoid having your file be overridden by tools such as "android update project"
+ -->
+ <!-- version-tag: 1 -->
+ <import file="${sdk.dir}/tools/ant/build.xml" />
+
+</project>
diff --git a/subsonic-android/debug.keystore b/subsonic-android/debug.keystore
new file mode 100644
index 00000000..1cb2c3d1
--- /dev/null
+++ b/subsonic-android/debug.keystore
Binary files differ
diff --git a/subsonic-android/patches/jukebox-patch.txt b/subsonic-android/patches/jukebox-patch.txt
new file mode 100644
index 00000000..5bc92000
--- /dev/null
+++ b/subsonic-android/patches/jukebox-patch.txt
@@ -0,0 +1,1234 @@
+Index: AndroidManifest.xml
+===================================================================
+--- AndroidManifest.xml (revision 2441)
++++ AndroidManifest.xml (working copy)
+@@ -114,7 +114,8 @@
+ a:authorities="net.sourceforge.subsonic.androidapp.provider.SearchSuggestionProvider"/>
+
+ <meta-data a:name="android.app.default_searchable"
+- a:value="net.sourceforge.subsonic.androidapp.activity.QueryReceiverActivity"/>
++ a:value="net.sourceforge.subsonic.androidapp.activity.QueryReceiverActivity"/>
++ <activity a:name="net.sourceforge.subsonic.androidapp.activity.JukeboxActivity" a:launchMode="singleTask" a:configChanges="keyboardHidden"></activity>
+
+ </application>
+
+Index: res/drawable/menu_jukebox.png
+===================================================================
+Cannot display: file marked as a binary type.
+svn:mime-type = application/octet-stream
+
+Property changes on: res/drawable/menu_jukebox.png
+___________________________________________________________________
+Added: svn:mime-type
+ + application/octet-stream
+
+Index: res/drawable-hdpi-v4/menu_jukebox.png
+===================================================================
+Cannot display: file marked as a binary type.
+svn:mime-type = application/octet-stream
+
+Property changes on: res/drawable-hdpi-v4/menu_jukebox.png
+___________________________________________________________________
+Added: svn:mime-type
+ + application/octet-stream
+
+Index: res/layout/button_bar.xml
+===================================================================
+--- res/layout/button_bar.xml (revision 2441)
++++ res/layout/button_bar.xml (working copy)
+@@ -47,6 +47,14 @@
+ a:layout_weight="1"
+ a:layout_width="0dp"
+ a:layout_height="wrap_content"/>
++
++ <ImageButton a:id="@+id/button_bar_jukebox"
++ a:src="@drawable/menu_jukebox"
++ a:contentDescription="@string/button_bar.jukebox"
++ a:background="@drawable/menubar_button"
++ a:layout_weight="1"
++ a:layout_width="0dp"
++ a:layout_height="wrap_content"/>
+
+ <ImageButton a:id="@+id/button_bar_now_playing"
+ a:src="@drawable/menu_now_playing"
+Index: res/layout/jukebox.xml
+===================================================================
+--- res/layout/jukebox.xml (revision 0)
++++ res/layout/jukebox.xml (revision 0)
+@@ -0,0 +1,72 @@
++<?xml version="1.0" encoding="utf-8"?>
++<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
++ a:layout_width="fill_parent"
++ a:layout_height="fill_parent"
++ a:orientation="vertical" >
++
++ <include layout="@layout/tab_progress"/>
++
++ <ListView
++ a:id="@+id/jukebox_list"
++ a:layout_width="match_parent"
++ a:layout_height="0dp"
++ a:layout_weight="1" >
++ </ListView>
++
++ <LinearLayout
++ a:layout_width="fill_parent"
++ a:layout_height="wrap_content"
++ a:layout_marginTop="0dip"
++ a:background="@color/mediaControlBackground"
++ a:gravity="center"
++ a:orientation="horizontal"
++ a:paddingBottom="0dip"
++ a:paddingTop="0dip" >
++
++ <ImageButton
++ a:id="@+id/jukebox_shuffle"
++ a:layout_width="wrap_content"
++ a:layout_height="fill_parent"
++ a:background="@android:color/transparent"
++ a:src="@drawable/media_shuffle" />
++
++ <ImageButton
++ a:id="@+id/jukebox_previous"
++ a:layout_width="wrap_content"
++ a:layout_height="wrap_content"
++ a:background="@android:color/transparent"
++ a:padding="0dip"
++ a:src="@drawable/media_backward" />
++
++ <ImageButton
++ a:id="@+id/jukebox_stop"
++ a:layout_width="60dip"
++ a:layout_height="60dip"
++ a:padding="0dip"
++ a:background="@drawable/media_stop" />
++
++ <ImageButton
++ a:id="@+id/jukebox_start"
++ a:layout_width="60dip"
++ a:layout_height="60dip"
++ a:padding="0dip"
++ a:background="@drawable/media_start" />
++
++ <ImageButton
++ a:id="@+id/jukebox_next"
++ a:layout_width="wrap_content"
++ a:layout_height="wrap_content"
++ a:background="@android:color/transparent"
++ a:padding="0dip"
++ a:src="@drawable/media_forward" />
++ </LinearLayout>
++
++ <SeekBar
++ a:id="@+id/jukebox_seek"
++ a:background="@color/mediaControlBackground"
++ a:layout_width="match_parent"
++ a:layout_height="wrap_content" />
++
++ <include layout="@layout/button_bar" />
++
++</LinearLayout>
+\ No newline at end of file
+Index: res/menu/jukebox_context.xml
+===================================================================
+--- res/menu/jukebox_context.xml (revision 0)
++++ res/menu/jukebox_context.xml (revision 0)
+@@ -0,0 +1,8 @@
++<?xml version="1.0" encoding="utf-8"?>
++<menu xmlns:android="http://schemas.android.com/apk/res/android" >
++ <item android:id="@+id/jukebox_clear" android:title="@string/jukebox_clear"></item>
++ <item android:id="@+id/jukebox_remove" android:title="@string/jukebox_remove"></item>
++
++
++
++</menu>
+\ No newline at end of file
+Index: res/menu/select_album_context.xml
+===================================================================
+--- res/menu/select_album_context.xml (revision 2441)
++++ res/menu/select_album_context.xml (working copy)
+@@ -15,5 +15,6 @@
+ a:id="@+id/album_menu_pin"
+ a:title="@string/common.pin"
+ />
++ <item a:id="@+id/album_menu_jukebox_add" a:title="@string/jukebox_add"></item>
+
+ </menu>
+Index: res/menu/select_artist_context.xml
+===================================================================
+--- res/menu/select_artist_context.xml (revision 2441)
++++ res/menu/select_artist_context.xml (working copy)
+@@ -15,5 +15,6 @@
+ a:id="@+id/artist_menu_pin"
+ a:title="@string/common.pin"
+ />
++ <item a:id="@+id/artist_menu_jukebox_add" a:title="@string/jukebox_add"></item>
+
+ </menu>
+Index: res/menu/select_song_context.xml
+===================================================================
+--- res/menu/select_song_context.xml (revision 2441)
++++ res/menu/select_song_context.xml (working copy)
+@@ -15,5 +15,10 @@
+ a:id="@+id/song_menu_play_last"
+ a:title="@string/common.play_last"
+ />
++
++ <item
++ a:id="@+id/song_menu_jukebox_add"
++ a:title="@string/jukebox_add"
++ />
+
+ </menu>
+Index: res/values/strings.xml
+===================================================================
+--- res/values/strings.xml (revision 2441)
++++ res/values/strings.xml (working copy)
+@@ -226,6 +226,14 @@
+ <plurals name="select_album_donate_dialog_n_trial_days_left">
+ <item quantity="one">One day left of trial period</item>
+ <item quantity="other">%d days left of trial period</item>
+- </plurals>
++ </plurals>
++ <string name="button_bar.jukebox">Jukebox</string>
++ <string name="jukebox_start">Start</string>
++ <string name="jukebox_stop">Stop</string>
++ <string name="jukebox_next">Next</string>
++ <string name="jukebox_previous">Previous</string>
++ <string name="jukebox_clear">Clear</string>
++ <string name="jukebox_remove">Remove</string>
++ <string name="jukebox_add">Add to Jukebox</string>
+
+ </resources>
+Index: src/net/sourceforge/subsonic/androidapp/activity/JukeboxActivity.java
+===================================================================
+--- src/net/sourceforge/subsonic/androidapp/activity/JukeboxActivity.java (revision 0)
++++ src/net/sourceforge/subsonic/androidapp/activity/JukeboxActivity.java (revision 0)
+@@ -0,0 +1,235 @@
++/*
++ This file is part of Subsonic.
++
++ Subsonic is free software: you can redistribute it and/or modify
++ it under the terms of the GNU General Public License as published by
++ the Free Software Foundation, either version 3 of the License, or
++ (at your option) any later version.
++
++ Subsonic is distributed in the hope that it will be useful,
++ but WITHOUT ANY WARRANTY; without even the implied warranty of
++ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
++ GNU General Public License for more details.
++
++ You should have received a copy of the GNU General Public License
++ along with Subsonic. If not, see <http://www.gnu.org/licenses/>.
++
++ Copyright 2009 (C) Sindre Mehus
++ */
++
++package net.sourceforge.subsonic.androidapp.activity;
++
++import java.util.List;
++
++import net.sourceforge.subsonic.androidapp.R;
++import net.sourceforge.subsonic.androidapp.domain.Jukebox;
++import net.sourceforge.subsonic.androidapp.domain.MusicDirectory;
++import net.sourceforge.subsonic.androidapp.domain.MusicDirectory.Entry;
++import net.sourceforge.subsonic.androidapp.service.MusicService;
++import net.sourceforge.subsonic.androidapp.service.MusicServiceFactory;
++import net.sourceforge.subsonic.androidapp.util.BackgroundTask;
++import net.sourceforge.subsonic.androidapp.util.JukeboxSongView;
++import net.sourceforge.subsonic.androidapp.util.ProgressListener;
++import net.sourceforge.subsonic.androidapp.util.TabActivityBackgroundTask;
++import net.sourceforge.subsonic.androidapp.util.Util;
++import android.os.Bundle;
++import android.view.ContextMenu;
++import android.view.MenuInflater;
++import android.view.MenuItem;
++import android.view.View;
++import android.view.View.OnClickListener;
++import android.view.ViewGroup;
++import android.widget.AdapterView;
++import android.widget.AdapterView.OnItemClickListener;
++import android.widget.ArrayAdapter;
++import android.widget.ImageButton;
++import android.widget.ListView;
++import android.widget.SeekBar;
++import android.widget.SeekBar.OnSeekBarChangeListener;
++
++/**
++ * @author meld0
++ *
++ */
++public class JukeboxActivity extends SubsonicTabActivity implements ProgressListener, OnClickListener, OnSeekBarChangeListener, OnItemClickListener{
++
++ private ImageButton play, stop, next, prev, shuffle;
++ private ListView entryList;
++ private SeekBar gain;
++ private Jukebox jukebox;
++
++ @Override
++ public void onCreate(Bundle savedInstanceState){
++ super.onCreate(savedInstanceState);
++ setContentView(R.layout.jukebox);
++
++ jukebox = new Jukebox();
++
++ play = (ImageButton) findViewById(R.id.jukebox_start);
++ stop = (ImageButton) findViewById(R.id.jukebox_stop);
++ prev = (ImageButton) findViewById(R.id.jukebox_previous);
++ next = (ImageButton) findViewById(R.id.jukebox_next);
++ shuffle = (ImageButton) findViewById(R.id.jukebox_shuffle);
++ entryList = (ListView) findViewById(R.id.jukebox_list);
++
++ gain = (SeekBar) findViewById(R.id.jukebox_seek);
++ gain.setMax(100);
++
++ play.setOnClickListener(this);
++ stop.setOnClickListener(this);
++ next.setOnClickListener(this);
++ prev.setOnClickListener(this);
++ shuffle.setOnClickListener(this);
++ gain.setOnSeekBarChangeListener(this);
++ entryList.setOnItemClickListener(this);
++
++ registerForContextMenu(entryList);
++ load();
++ }
++
++ @Override
++ public void updateProgress(int messageId){
++
++ }
++
++ private void load(){
++ load(Jukebox.GET);
++ }
++
++ private void load(String action){
++ load(action, "");
++ }
++
++ private void load(final String action, final String additional){
++ BackgroundTask<Boolean> task = new TabActivityBackgroundTask<Boolean>(this){
++
++ protected Boolean doInBackground() throws Throwable{
++ boolean update = false;
++ if (!Util.isOffline(JukeboxActivity.this)) {
++ MusicService musicService = MusicServiceFactory.getMusicService(JukeboxActivity.this);
++ jukebox.lastAction = action;
++ jukebox = musicService.getJukebox(jukebox, JukeboxActivity.this, this, additional);
++ update = true;
++ }
++ return update;
++ }
++
++ protected void done(Boolean result){
++ if (jukebox.isSuccess()) {
++ if (jukebox.lastAction.equals(Jukebox.SET_GAIN)) {
++ jukebox.setGain((int) (Double.valueOf(additional.split("=")[1]) * 100));
++ gain.setProgress(jukebox.getGain());
++ } else if (jukebox.lastAction.equals(Jukebox.REMOVE_ITEM)) ((SongListAdapter) entryList.getAdapter()).remove((Entry) entryList.getAdapter().getItem(
++ Integer.valueOf(additional.split("=")[1])));
++ else if (jukebox.lastAction.equals(Jukebox.CLEAR_PLAYLIST)) ((SongListAdapter) entryList.getAdapter()).clear();
++ else if (jukebox.lastAction.equals(Jukebox.SKIP_TO_INDEX)) jukebox.setCurrentIndex(Integer.valueOf(additional.split("=")[1]));
++
++ if (jukebox.isNewPlaylist()) entryList.setAdapter(new SongListAdapter(jukebox.getChildren()));
++ }
++ }
++ };
++ task.execute();
++ }
++
++ @Override
++ public void onCreateContextMenu(ContextMenu menu, View view, ContextMenu.ContextMenuInfo menuInfo){
++ super.onCreateContextMenu(menu, view, menuInfo);
++ MenuInflater inflater = getMenuInflater();
++ inflater.inflate(R.menu.jukebox_context, menu);
++ }
++
++ @Override
++ public boolean onContextItemSelected(MenuItem menuItem){
++ AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo) menuItem.getMenuInfo();
++ switch (menuItem.getItemId()) {
++ case R.id.jukebox_remove:
++ load(Jukebox.REMOVE_ITEM, "index=" + info.position);
++ break;
++ case R.id.jukebox_clear:
++ load(Jukebox.CLEAR_PLAYLIST);
++ break;
++ default:
++ return super.onContextItemSelected(menuItem);
++ }
++ return true;
++ }
++
++ @Override
++ protected void onResume(){
++ super.onResume();
++ load();
++ }
++
++ @Override
++ public void onClick(View arg0){
++ if (arg0.equals(this.play)) {
++ load(Jukebox.START_PLAYBACK);
++ } else if (arg0.equals(this.stop)) {
++ load(Jukebox.STOP_PLAYBACK);
++ } else if (arg0.equals(this.prev)) {
++ loadW();
++ load(Jukebox.SKIP_TO_INDEX, "index=" + (jukebox.getCurrentIndex() - 1)); // TODO // MAYBE // BETTER // ?
++ } else if (arg0.equals(this.next)) {
++ loadW();
++ load(Jukebox.SKIP_TO_INDEX, "index=" + (jukebox.getCurrentIndex() + 1));
++ } else if (arg0.equals(this.shuffle)) {
++ load(Jukebox.SHUFFLE_PLAYLIST);
++ load();
++ }
++ }
++
++ @Override
++ public void onProgressChanged(SeekBar arg0, int arg1, boolean arg2){
++ }
++
++ @Override
++ public void onStartTrackingTouch(SeekBar arg0){
++ }
++
++ @Override
++ public void onStopTrackingTouch(SeekBar arg0){
++ load(Jukebox.SET_GAIN, "gain=" + ((double) arg0.getProgress() / 100));
++ }
++
++ private class SongListAdapter extends ArrayAdapter<MusicDirectory.Entry>{
++
++ public SongListAdapter(List<MusicDirectory.Entry> entries){
++ super(JukeboxActivity.this, android.R.layout.simple_list_item_1, entries);
++ }
++
++ @Override
++ public View getView(int position, View convertView, ViewGroup parent){
++ JukeboxSongView view;
++ if (convertView != null && convertView instanceof JukeboxSongView) {
++ view = (JukeboxSongView) convertView;
++ } else {
++ view = new JukeboxSongView(JukeboxActivity.this);
++ }
++ MusicDirectory.Entry entry = getItem(position);
++
++ if (position == jukebox.getCurrentIndex()) {
++ view.setSong(entry, false, true);
++ } else view.setSong(entry, false, false);
++ return view;
++ }
++ }
++
++ @Override
++ public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3){
++ load(Jukebox.SKIP_TO_INDEX, "index=" + arg3);
++ }
++
++ public void loadW(){
++ if (!Util.isOffline(JukeboxActivity.this)) {
++ MusicService musicService = MusicServiceFactory.getMusicService(JukeboxActivity.this);
++ jukebox.lastAction = Jukebox.GET;
++ try {
++ jukebox = musicService.getJukebox(jukebox, JukeboxActivity.this, this, "");
++ } catch (Exception e) {
++ // TODO Auto-generated catch block
++ e.printStackTrace();
++ }
++ }
++ }
++
++}
+Index: src/net/sourceforge/subsonic/androidapp/activity/SelectAlbumActivity.java
+===================================================================
+--- src/net/sourceforge/subsonic/androidapp/activity/SelectAlbumActivity.java (revision 2441)
++++ src/net/sourceforge/subsonic/androidapp/activity/SelectAlbumActivity.java (working copy)
+@@ -252,6 +252,9 @@
+ case R.id.album_menu_pin:
+ downloadRecursively(entry.getId(), true, true, false);
+ break;
++ case R.id.album_menu_jukebox_add:
++ addToJukebox(entry.getId());
++ break;
+ case R.id.song_menu_play_now:
+ getDownloadService().download(songs, false, true, true);
+ break;
+@@ -261,6 +264,8 @@
+ case R.id.song_menu_play_last:
+ getDownloadService().download(songs, false, false, false);
+ break;
++ case R.id.song_menu_jukebox_add:
++ addToJukebox(entry);
+ default:
+ return super.onContextItemSelected(menuItem);
+ }
+Index: src/net/sourceforge/subsonic/androidapp/activity/SelectArtistActivity.java
+===================================================================
+--- src/net/sourceforge/subsonic/androidapp/activity/SelectArtistActivity.java (revision 2441)
++++ src/net/sourceforge/subsonic/androidapp/activity/SelectArtistActivity.java (working copy)
+@@ -210,6 +210,9 @@
+ case R.id.artist_menu_pin:
+ downloadRecursively(artist.getId(), true, true, false);
+ break;
++ case R.id.artist_menu_jukebox_add:
++ addToJukebox(artist.getId());
++ break;
+ default:
+ return super.onContextItemSelected(menuItem);
+ }
+Index: src/net/sourceforge/subsonic/androidapp/activity/SubsonicTabActivity.java
+===================================================================
+--- src/net/sourceforge/subsonic/androidapp/activity/SubsonicTabActivity.java (revision 2441)
++++ src/net/sourceforge/subsonic/androidapp/activity/SubsonicTabActivity.java (working copy)
+@@ -23,6 +23,16 @@
+ import java.util.LinkedList;
+ import java.util.List;
+
++import net.sourceforge.subsonic.androidapp.R;
++import net.sourceforge.subsonic.androidapp.domain.MusicDirectory;
++import net.sourceforge.subsonic.androidapp.service.DownloadService;
++import net.sourceforge.subsonic.androidapp.service.DownloadServiceImpl;
++import net.sourceforge.subsonic.androidapp.service.MusicService;
++import net.sourceforge.subsonic.androidapp.service.MusicServiceFactory;
++import net.sourceforge.subsonic.androidapp.util.Constants;
++import net.sourceforge.subsonic.androidapp.util.ImageLoader;
++import net.sourceforge.subsonic.androidapp.util.ModalBackgroundTask;
++import net.sourceforge.subsonic.androidapp.util.Util;
+ import android.app.Activity;
+ import android.content.Context;
+ import android.content.Intent;
+@@ -39,16 +49,6 @@
+ import android.view.View;
+ import android.view.Window;
+ import android.widget.TextView;
+-import net.sourceforge.subsonic.androidapp.R;
+-import net.sourceforge.subsonic.androidapp.domain.MusicDirectory;
+-import net.sourceforge.subsonic.androidapp.service.DownloadService;
+-import net.sourceforge.subsonic.androidapp.service.DownloadServiceImpl;
+-import net.sourceforge.subsonic.androidapp.service.MusicService;
+-import net.sourceforge.subsonic.androidapp.service.MusicServiceFactory;
+-import net.sourceforge.subsonic.androidapp.util.Constants;
+-import net.sourceforge.subsonic.androidapp.util.ImageLoader;
+-import net.sourceforge.subsonic.androidapp.util.ModalBackgroundTask;
+-import net.sourceforge.subsonic.androidapp.util.Util;
+
+ /**
+ * @author Sindre Mehus
+@@ -63,6 +63,7 @@
+ private View musicButton;
+ private View searchButton;
+ private View playlistButton;
++ private View jukeboxButton;
+ private View nowPlayingButton;
+
+ @Override
+@@ -118,6 +119,14 @@
+ Util.startActivityWithoutTransition(SubsonicTabActivity.this, intent);
+ }
+ });
++
++ jukeboxButton = findViewById(R.id.button_bar_jukebox);
++ jukeboxButton.setOnClickListener(new View.OnClickListener() {
++ @Override
++ public void onClick(View view) {
++ Util.startActivityWithoutTransition(SubsonicTabActivity.this, JukeboxActivity.class);
++ }
++ });
+
+ nowPlayingButton = findViewById(R.id.button_bar_now_playing);
+ nowPlayingButton.setOnClickListener(new View.OnClickListener() {
+@@ -225,6 +234,22 @@
+ int visibility = Util.isOffline(this) ? View.GONE : View.VISIBLE;
+ searchButton.setVisibility(visibility);
+ playlistButton.setVisibility(visibility);
++ jukeboxButton.setVisibility(visibility);
++ /*
++ * The following block would check for valid Permissions
++ * but it is called too often -> network traffic/ problems ?
++ *
++ MusicService musicService = MusicServiceFactory.getMusicService(this);
++ try {
++ User user = musicService.getUser(this, null);
++ if(!user.isJukeboxControl()){
++ jukeboxButton.setVisibility(View.GONE);
++ }
++ } catch (Exception e) {
++ // TODO Auto-generated catch block
++ e.printStackTrace();
++ }
++ */
+ }
+
+ public void setProgressVisible(boolean visible) {
+@@ -363,5 +388,67 @@
+ }
+ }
+ }
++
++ protected void addToJukebox(String id) {
++
++ List<MusicDirectory.Entry> entries = new LinkedList<MusicDirectory.Entry>();
++ MusicService musicService = MusicServiceFactory.getMusicService(this);
++ MusicDirectory root;
++
++ try {
++ root = musicService.getMusicDirectory(id, false, SubsonicTabActivity.this, null);
++ collectEntries(root, entries);
++ } catch (Exception e) {
++ // TODO Auto-generated catch block
++ e.printStackTrace();
++ }
++
++
++ StringBuilder build = new StringBuilder();
++ build.append("action=add");
++ for(MusicDirectory.Entry entry2: entries){
++ build.append("&id=");
++ build.append(entry2.getId());
++ }
++ try {
++ musicService.getJukebox(null, this, null, build.toString());
++ } catch (Exception e) {
++ // TODO Auto-generated catch block
++ e.printStackTrace();
++ }
++
++ }
++
++ protected void addToJukebox(MusicDirectory.Entry entry) {
++ try {
++ MusicService musicService = MusicServiceFactory.getMusicService(this);
++ musicService.getJukebox(null, this, null, "action=add&id="+entry.getId());
++ } catch (Exception e) {
++ // TODO Auto-generated catch block
++ e.printStackTrace();
++ }
++ }
++
++ private List<MusicDirectory.Entry> collectEntries(MusicDirectory parent, List<MusicDirectory.Entry> songs){
++ for (MusicDirectory.Entry song : parent.getChildren(false, true)) {
++ if (!song.isVideo()) {
++ songs.add(song);
++ }
++ }
++ for (MusicDirectory.Entry dir : parent.getChildren(true, false)) {
++ MusicService musicService = MusicServiceFactory.getMusicService(SubsonicTabActivity.this);
++ try {
++ collectEntries(musicService.getMusicDirectory(dir.getId(), false, SubsonicTabActivity.this, null), songs);
++ } catch (Exception e) {
++ // TODO Auto-generated catch block
++ e.printStackTrace();
++ }
++ }
++
++ return songs;
++ }
++
++
++
+ }
+
+Index: src/net/sourceforge/subsonic/androidapp/domain/Jukebox.java
+===================================================================
+--- src/net/sourceforge/subsonic/androidapp/domain/Jukebox.java (revision 0)
++++ src/net/sourceforge/subsonic/androidapp/domain/Jukebox.java (revision 0)
+@@ -0,0 +1,113 @@
++/*
++ This file is part of Subsonic.
++
++ Subsonic is free software: you can redistribute it and/or modify
++ it under the terms of the GNU General Public License as published by
++ the Free Software Foundation, either version 3 of the License, or
++ (at your option) any later version.
++
++ Subsonic is distributed in the hope that it will be useful,
++ but WITHOUT ANY WARRANTY; without even the implied warranty of
++ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
++ GNU General Public License for more details.
++
++ You should have received a copy of the GNU General Public License
++ along with Subsonic. If not, see <http://www.gnu.org/licenses/>.
++
++ Copyright 2009 (C) Sindre Mehus
++ */
++
++package net.sourceforge.subsonic.androidapp.domain;
++
++import java.io.Serializable;
++import java.util.List;
++
++/**
++ * @author meld0
++ *
++ */
++public class Jukebox extends MusicDirectory implements Serializable{
++
++ public String lastAction;
++
++ //get, start, stop, skip, add, clear, remove, shuffle, setGain
++ public static final String GET = "get";
++ public static final String START_PLAYBACK = "start";
++ public static final String STOP_PLAYBACK = "stop";
++ public static final String SKIP_TO_INDEX = "skip";
++ public static final String ADD_TO_PLAYLIST = "add";
++ public static final String CLEAR_PLAYLIST = "clear";
++ public static final String REMOVE_ITEM = "remove";
++ public static final String SHUFFLE_PLAYLIST = "shuffle";
++ public static final String SET_GAIN = "setGain";
++
++ public Jukebox() {
++ super();
++ }
++
++ public boolean isPlaying() {
++ return playing;
++ }
++
++ public void setPlaying(boolean playing) {
++ this.playing = playing;
++ }
++
++ public int getGain() {
++ return gain;
++ }
++
++ public void setGain(int gain) {
++ this.gain = gain;
++ }
++
++ public int getCurrentIndex() {
++ return currentIndex;
++ }
++
++ public void setCurrentIndex(int currentIndex) {
++ this.currentIndex = currentIndex;
++ }
++
++ public boolean isAvailable() {
++ return available;
++ }
++
++ public boolean isSuccess() {
++ return success;
++ }
++
++ public void setAvailable(boolean available) {
++ this.available = available;
++ }
++
++ public void setSuccess(boolean success) {
++ this.success = success;
++ }
++
++ public boolean isNewPlaylist() {
++ return newPlaylist;
++ }
++
++ public void setNewPlaylist(boolean newPlaylist) {
++ this.newPlaylist = newPlaylist;
++ }
++
++ private boolean playing = false;
++ private int gain = 0;
++ private int currentIndex = 0;
++ private boolean available = false;
++ private boolean success = false;
++ private boolean newPlaylist = false;
++
++ public void addChildren(List<Entry> children){
++ super.addChildren(children);
++ }
++
++ public void reset(){
++ this.available = false;
++ this.success = false;
++ this.newPlaylist = false;
++ }
++
++}
+Index: src/net/sourceforge/subsonic/androidapp/domain/MusicDirectory.java
+===================================================================
+--- src/net/sourceforge/subsonic/androidapp/domain/MusicDirectory.java (revision 2441)
++++ src/net/sourceforge/subsonic/androidapp/domain/MusicDirectory.java (working copy)
+@@ -59,6 +59,13 @@
+ }
+ return result;
+ }
++
++ protected void addChildren(List<Entry> children){
++ if(!children.isEmpty()) {
++ this.children.clear();
++ this.children.addAll(children);
++ }
++ }
+
+ public static class Entry implements Serializable {
+ private String id;
+Index: src/net/sourceforge/subsonic/androidapp/domain/User.java
+===================================================================
+--- src/net/sourceforge/subsonic/androidapp/domain/User.java (revision 0)
++++ src/net/sourceforge/subsonic/androidapp/domain/User.java (revision 0)
+@@ -0,0 +1,43 @@
++/*
++ This file is part of Subsonic.
++
++ Subsonic is free software: you can redistribute it and/or modify
++ it under the terms of the GNU General Public License as published by
++ the Free Software Foundation, either version 3 of the License, or
++ (at your option) any later version.
++
++ Subsonic is distributed in the hope that it will be useful,
++ but WITHOUT ANY WARRANTY; without even the implied warranty of
++ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
++ GNU General Public License for more details.
++
++ You should have received a copy of the GNU General Public License
++ along with Subsonic. If not, see <http://www.gnu.org/licenses/>.
++
++ Copyright 2009 (C) Sindre Mehus
++ */
++
++package net.sourceforge.subsonic.androidapp.domain;
++
++import java.io.Serializable;
++
++/**
++ * @author meld0
++ *
++ */
++public class User implements Serializable{
++
++ //TODO implement missing user attributes
++
++ private boolean jukeboxControl;
++
++ public boolean isJukeboxControl() {
++ return jukeboxControl;
++ }
++
++ public void setJukeboxControl(boolean jukeboxControl) {
++ this.jukeboxControl = jukeboxControl;
++ }
++
++
++}
+Index: src/net/sourceforge/subsonic/androidapp/service/CachedMusicService.java
+===================================================================
+--- src/net/sourceforge/subsonic/androidapp/service/CachedMusicService.java (revision 2441)
++++ src/net/sourceforge/subsonic/androidapp/service/CachedMusicService.java (working copy)
+@@ -21,9 +21,11 @@
+ import android.content.Context;
+ import android.graphics.Bitmap;
+ import net.sourceforge.subsonic.androidapp.domain.Indexes;
++import net.sourceforge.subsonic.androidapp.domain.Jukebox;
+ import net.sourceforge.subsonic.androidapp.domain.MusicDirectory;
+ import net.sourceforge.subsonic.androidapp.domain.MusicFolder;
+ import net.sourceforge.subsonic.androidapp.domain.Playlist;
++import net.sourceforge.subsonic.androidapp.domain.User;
+ import net.sourceforge.subsonic.androidapp.domain.Version;
+ import net.sourceforge.subsonic.androidapp.domain.SearchResult;
+ import net.sourceforge.subsonic.androidapp.domain.SearchCritera;
+@@ -199,4 +201,17 @@
+ restUrl = newUrl;
+ }
+ }
++
++ @Override
++ public Jukebox getJukebox(Jukebox jukebox, Context context,
++ ProgressListener progressListener, String action) throws Exception {
++ return musicService.getJukebox(jukebox, context, progressListener, action);
++ }
++
++ @Override
++ public User getUser(Context context, ProgressListener progressListener)
++ throws Exception {
++ return musicService.getUser(context, progressListener);
++ }
++
+ }
+Index: src/net/sourceforge/subsonic/androidapp/service/MusicService.java
+===================================================================
+--- src/net/sourceforge/subsonic/androidapp/service/MusicService.java (revision 2441)
++++ src/net/sourceforge/subsonic/androidapp/service/MusicService.java (working copy)
+@@ -21,9 +21,11 @@
+ import android.content.Context;
+ import android.graphics.Bitmap;
+ import net.sourceforge.subsonic.androidapp.domain.Indexes;
++import net.sourceforge.subsonic.androidapp.domain.Jukebox;
+ import net.sourceforge.subsonic.androidapp.domain.MusicDirectory;
+ import net.sourceforge.subsonic.androidapp.domain.MusicFolder;
+ import net.sourceforge.subsonic.androidapp.domain.Playlist;
++import net.sourceforge.subsonic.androidapp.domain.User;
+ import net.sourceforge.subsonic.androidapp.domain.Version;
+ import net.sourceforge.subsonic.androidapp.domain.SearchResult;
+ import net.sourceforge.subsonic.androidapp.domain.SearchCritera;
+@@ -74,4 +76,8 @@
+ Version getLatestVersion(Context context, ProgressListener progressListener) throws Exception;
+
+ String getVideoUrl(Context context, String id);
++
++ Jukebox getJukebox(Jukebox jukebox, Context context, ProgressListener progressListener , String action) throws Exception;
++
++ User getUser(Context context, ProgressListener progressListener) throws Exception;
+ }
+\ No newline at end of file
+Index: src/net/sourceforge/subsonic/androidapp/service/RESTMusicService.java
+===================================================================
+--- src/net/sourceforge/subsonic/androidapp/service/RESTMusicService.java (revision 2441)
++++ src/net/sourceforge/subsonic/androidapp/service/RESTMusicService.java (working copy)
+@@ -28,6 +28,7 @@
+ import android.util.Log;
+ import net.sourceforge.subsonic.androidapp.R;
+ import net.sourceforge.subsonic.androidapp.domain.Indexes;
++import net.sourceforge.subsonic.androidapp.domain.Jukebox;
+ import net.sourceforge.subsonic.androidapp.domain.Lyrics;
+ import net.sourceforge.subsonic.androidapp.domain.MusicDirectory;
+ import net.sourceforge.subsonic.androidapp.domain.MusicFolder;
+@@ -35,10 +36,12 @@
+ import net.sourceforge.subsonic.androidapp.domain.SearchCritera;
+ import net.sourceforge.subsonic.androidapp.domain.SearchResult;
+ import net.sourceforge.subsonic.androidapp.domain.ServerInfo;
++import net.sourceforge.subsonic.androidapp.domain.User;
+ import net.sourceforge.subsonic.androidapp.domain.Version;
+ import net.sourceforge.subsonic.androidapp.service.parser.AlbumListParser;
+ import net.sourceforge.subsonic.androidapp.service.parser.ErrorParser;
+ import net.sourceforge.subsonic.androidapp.service.parser.IndexesParser;
++import net.sourceforge.subsonic.androidapp.service.parser.JukeboxParser;
+ import net.sourceforge.subsonic.androidapp.service.parser.LicenseParser;
+ import net.sourceforge.subsonic.androidapp.service.parser.LyricsParser;
+ import net.sourceforge.subsonic.androidapp.service.parser.MusicDirectoryParser;
+@@ -48,6 +51,7 @@
+ import net.sourceforge.subsonic.androidapp.service.parser.RandomSongsParser;
+ import net.sourceforge.subsonic.androidapp.service.parser.SearchResult2Parser;
+ import net.sourceforge.subsonic.androidapp.service.parser.SearchResultParser;
++import net.sourceforge.subsonic.androidapp.service.parser.UserParser;
+ import net.sourceforge.subsonic.androidapp.service.parser.VersionParser;
+ import net.sourceforge.subsonic.androidapp.service.ssl.SSLSocketFactory;
+ import net.sourceforge.subsonic.androidapp.service.ssl.TrustSelfSignedStrategy;
+@@ -195,6 +199,53 @@
+ Util.close(reader);
+ }
+ }
++
++ public Jukebox getJukebox(Jukebox jukebox, Context context, ProgressListener progressListener, String action) throws Exception {
++
++ List<String> parameterNames = new ArrayList<String>();
++ List<Object> parameterValues = new ArrayList<Object>();
++ if(jukebox != null){
++ parameterNames.add("action");
++ parameterValues.add(jukebox.lastAction);
++ }
++ if(!action.isEmpty()){
++ String[] names_values = action.split("&");
++ for(String name_value: names_values){
++ String[] pair = name_value.split("=");
++ parameterNames.add(pair[0]);
++ parameterValues.add(pair[1]);
++ }
++ }
++
++ Reader reader = getReader(context, progressListener, "jukeboxControl", null, parameterNames, parameterValues);
++
++ try {
++ return new JukeboxParser(context).parse(jukebox, reader, progressListener);
++ } finally {
++ Util.close(reader);
++ }
++ }
++
++ public User getUser(Context context, ProgressListener progressListener) throws Exception {
++
++ SharedPreferences prefs = Util.getPreferences(context);
++ int instance = prefs.getInt(Constants.PREFERENCES_KEY_SERVER_INSTANCE, 1);
++ String username = prefs.getString(Constants.PREFERENCES_KEY_USERNAME + instance, null);
++
++ List<String> parameterNames = new ArrayList<String>();
++ List<Object> parameterValues = new ArrayList<Object>();
++ parameterNames.add("username");
++ parameterValues.add(username);
++
++ Reader reader = getReader(context, progressListener, "getUser", null, parameterNames, parameterValues);
++
++ try {
++ return new UserParser(context).parse(reader, progressListener);
++ } finally {
++ Util.close(reader);
++ }
++ }
++
+
+ @Override
+ public Indexes getIndexes(String musicFolderId, boolean refresh, Context context, ProgressListener progressListener) throws Exception {
+Index: src/net/sourceforge/subsonic/androidapp/service/parser/AbstractParser.java
+===================================================================
+--- src/net/sourceforge/subsonic/androidapp/service/parser/AbstractParser.java (revision 2441)
++++ src/net/sourceforge/subsonic/androidapp/service/parser/AbstractParser.java (working copy)
+@@ -97,6 +97,11 @@
+ String s = get(name);
+ return s == null ? null : Long.valueOf(s);
+ }
++
++ protected Double getDouble(String name) {
++ String s = get(name);
++ return s == null ? null : Double.valueOf(s);
++ }
+
+ protected void init(Reader reader) throws Exception {
+ parser = Xml.newPullParser();
+Index: src/net/sourceforge/subsonic/androidapp/service/parser/JukeboxParser.java
+===================================================================
+--- src/net/sourceforge/subsonic/androidapp/service/parser/JukeboxParser.java (revision 0)
++++ src/net/sourceforge/subsonic/androidapp/service/parser/JukeboxParser.java (revision 0)
+@@ -0,0 +1,86 @@
++/*
++ This file is part of Subsonic.
++
++ Subsonic is free software: you can redistribute it and/or modify
++ it under the terms of the GNU General Public License as published by
++ the Free Software Foundation, either version 3 of the License, or
++ (at your option) any later version.
++
++ Subsonic is distributed in the hope that it will be useful,
++ but WITHOUT ANY WARRANTY; without even the implied warranty of
++ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
++ GNU General Public License for more details.
++
++ You should have received a copy of the GNU General Public License
++ along with Subsonic. If not, see <http://www.gnu.org/licenses/>.
++
++ Copyright 2009 (C) Sindre Mehus
++ */
++
++package net.sourceforge.subsonic.androidapp.service.parser;
++
++import java.io.Reader;
++
++import net.sourceforge.subsonic.androidapp.R;
++import net.sourceforge.subsonic.androidapp.domain.Jukebox;
++import net.sourceforge.subsonic.androidapp.domain.MusicDirectory;
++import net.sourceforge.subsonic.androidapp.util.ProgressListener;
++
++import org.xmlpull.v1.XmlPullParser;
++
++import android.content.Context;
++
++/**
++ * @author meld0
++ *
++ */
++public class JukeboxParser extends MusicDirectoryEntryParser {
++
++ public JukeboxParser(Context context) {
++ super(context);
++ }
++
++ public Jukebox parse(Jukebox jukebox, Reader reader,
++ ProgressListener progressListener) throws Exception {
++ updateProgress(progressListener, R.string.parser_reading);
++
++ if (jukebox == null)
++ jukebox = new Jukebox();
++ jukebox.reset();
++ init(reader);
++ jukebox.setAvailable(true);
++
++ MusicDirectory dir = new MusicDirectory();
++
++ int eventType;
++ do {
++ eventType = nextParseEvent();
++ if (eventType == XmlPullParser.START_TAG) {
++ String name = getElementName();
++ if ("entry".equals(name)) {
++ dir.addChild(parseEntry());
++ jukebox.setNewPlaylist(true);
++ } else if ("jukeboxPlaylist".equals(name)) {
++ jukebox.setPlaying(getBoolean("playing"));
++ jukebox.setGain((int) (getDouble("gain") * 100));
++ jukebox.setCurrentIndex(getInteger("currentIndex"));
++ } else if ("subsonic-response".equals(name)) {
++ if (get("status").equals("ok"))
++ jukebox.setSuccess(true);
++ } else if ("error".equals(name)) {
++ handleError();
++ }
++ }
++ } while (eventType != XmlPullParser.END_DOCUMENT);
++
++ if(jukebox.isNewPlaylist()) {
++ jukebox.addChildren(dir.getChildren());
++ }
++
++ validate();
++ updateProgress(progressListener, R.string.parser_reading_done);
++
++ return jukebox;
++ }
++
++}
+Index: src/net/sourceforge/subsonic/androidapp/service/parser/UserParser.java
+===================================================================
+--- src/net/sourceforge/subsonic/androidapp/service/parser/UserParser.java (revision 0)
++++ src/net/sourceforge/subsonic/androidapp/service/parser/UserParser.java (revision 0)
+@@ -0,0 +1,67 @@
++/*
++ This file is part of Subsonic.
++
++ Subsonic is free software: you can redistribute it and/or modify
++ it under the terms of the GNU General Public License as published by
++ the Free Software Foundation, either version 3 of the License, or
++ (at your option) any later version.
++
++ Subsonic is distributed in the hope that it will be useful,
++ but WITHOUT ANY WARRANTY; without even the implied warranty of
++ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
++ GNU General Public License for more details.
++
++ You should have received a copy of the GNU General Public License
++ along with Subsonic. If not, see <http://www.gnu.org/licenses/>.
++
++ Copyright 2009 (C) Sindre Mehus
++ */
++
++package net.sourceforge.subsonic.androidapp.service.parser;
++
++import java.io.Reader;
++
++import net.sourceforge.subsonic.androidapp.R;
++import net.sourceforge.subsonic.androidapp.domain.User;
++import net.sourceforge.subsonic.androidapp.util.ProgressListener;
++
++import org.xmlpull.v1.XmlPullParser;
++
++import android.content.Context;
++
++/**
++ * @author meld0
++ *
++ */
++public class UserParser extends AbstractParser{
++
++ public UserParser(Context context) {
++ super(context);
++ }
++
++ public User parse(Reader reader, ProgressListener progressListener) throws Exception {
++ updateProgress(progressListener, R.string.parser_reading);
++ init(reader);
++
++ User user = new User();
++ int eventType;
++ do {
++ eventType = nextParseEvent();
++ if (eventType == XmlPullParser.START_TAG) {
++ String name = getElementName();
++ if ("user".equals(name)) {
++ user.setJukeboxControl(getBoolean("jukeboxRole"));
++ } else if ("error".equals(name)) {
++ handleError();
++ }
++ }
++ } while (eventType != XmlPullParser.END_DOCUMENT);
++
++ validate();
++ updateProgress(progressListener, R.string.parser_reading_done);
++
++ return user;
++ }
++
++
++}
+Index: src/net/sourceforge/subsonic/androidapp/util/JukeboxSongView.java
+===================================================================
+--- src/net/sourceforge/subsonic/androidapp/util/JukeboxSongView.java (revision 0)
++++ src/net/sourceforge/subsonic/androidapp/util/JukeboxSongView.java (revision 0)
+@@ -0,0 +1,88 @@
++/*
++ This file is part of Subsonic.
++
++ Subsonic is free software: you can redistribute it and/or modify
++ it under the terms of the GNU General Public License as published by
++ the Free Software Foundation, either version 3 of the License, or
++ (at your option) any later version.
++
++ Subsonic is distributed in the hope that it will be useful,
++ but WITHOUT ANY WARRANTY; without even the implied warranty of
++ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
++ GNU General Public License for more details.
++
++ You should have received a copy of the GNU General Public License
++ along with Subsonic. If not, see <http://www.gnu.org/licenses/>.
++
++ Copyright 2009 (C) Sindre Mehus
++ */
++
++package net.sourceforge.subsonic.androidapp.util;
++
++import net.sourceforge.subsonic.androidapp.R;
++import net.sourceforge.subsonic.androidapp.domain.MusicDirectory;
++import android.content.Context;
++import android.view.LayoutInflater;
++import android.view.View;
++import android.widget.CheckedTextView;
++import android.widget.LinearLayout;
++import android.widget.TextView;
++
++/**
++ * @author meld0
++ *
++ */
++public class JukeboxSongView extends LinearLayout{
++
++ private CheckedTextView checkedTextView;
++ private TextView titleTextView;
++ private TextView artistTextView;
++ private TextView durationTextView;
++ private TextView statusTextView;
++ private MusicDirectory.Entry song;
++
++ public JukeboxSongView(Context context) {
++ super(context);
++ LayoutInflater.from(context).inflate(R.layout.song_list_item, this, true);
++
++ checkedTextView = (CheckedTextView) findViewById(R.id.song_check);
++ titleTextView = (TextView) findViewById(R.id.song_title);
++ artistTextView = (TextView) findViewById(R.id.song_artist);
++ durationTextView = (TextView) findViewById(R.id.song_duration);
++ statusTextView = (TextView) findViewById(R.id.song_status);
++
++ }
++
++ public void setSong(MusicDirectory.Entry song, boolean checkable, boolean playing) {
++ this.song = song;
++ StringBuilder artist = new StringBuilder(40);
++
++ String bitRate = null;
++ if (song.getBitRate() != null) {
++ bitRate = String.format(getContext().getString(R.string.song_details_kbps), song.getBitRate());
++ }
++
++ String fileFormat = null;
++ if (song.getTranscodedSuffix() != null && !song.getTranscodedSuffix().equals(song.getSuffix())) {
++ fileFormat = String.format("%s > %s", song.getSuffix(), song.getTranscodedSuffix());
++ } else {
++ fileFormat = song.getSuffix();
++ }
++
++ artist.append(song.getArtist()).append(" (")
++ .append(String.format(getContext().getString(R.string.song_details_all), bitRate == null ? "" : bitRate, fileFormat))
++ .append(")");
++
++ titleTextView.setText(song.getTitle());
++ artistTextView.setText(artist);
++ durationTextView.setText(Util.formatDuration(song.getDuration()));
++ checkedTextView.setVisibility(checkable && !song.isVideo() ? View.VISIBLE : View.GONE);
++
++ if(playing){
++ titleTextView.setCompoundDrawablesWithIntrinsicBounds(R.drawable.stat_notify_playing, 0, 0, 0);
++ }else{
++ titleTextView.setCompoundDrawablesWithIntrinsicBounds(0, 0, 0, 0);
++ }
++ }
++
++}
diff --git a/subsonic-android/proguard.cfg b/subsonic-android/proguard.cfg
new file mode 100644
index 00000000..f0b04dc3
--- /dev/null
+++ b/subsonic-android/proguard.cfg
@@ -0,0 +1,40 @@
+-optimizationpasses 5
+-dontusemixedcaseclassnames
+-dontskipnonpubliclibraryclasses
+-dontpreverify
+-verbose
+-optimizations !code/simplification/arithmetic,!field/*,!class/merging/*
+
+-keep public class * extends android.app.Activity
+-keep public class * extends android.app.Application
+-keep public class * extends android.app.Service
+-keep public class * extends android.content.BroadcastReceiver
+-keep public class * extends android.content.ContentProvider
+-keep public class * extends android.app.backup.BackupAgentHelper
+-keep public class * extends android.preference.Preference
+-keep public class com.android.vending.licensing.ILicensingService
+
+-keepclasseswithmembernames class * {
+ native <methods>;
+}
+
+-keepclasseswithmembers class * {
+ public <init>(android.content.Context, android.util.AttributeSet);
+}
+
+-keepclasseswithmembers class * {
+ public <init>(android.content.Context, android.util.AttributeSet, int);
+}
+
+-keepclassmembers class * extends android.app.Activity {
+ public void *(android.view.View);
+}
+
+-keepclassmembers enum * {
+ public static **[] values();
+ public static ** valueOf(java.lang.String);
+}
+
+-keep class * implements android.os.Parcelable {
+ public static final android.os.Parcelable$Creator *;
+}
diff --git a/subsonic-android/project.properties b/subsonic-android/project.properties
new file mode 100644
index 00000000..f049142c
--- /dev/null
+++ b/subsonic-android/project.properties
@@ -0,0 +1,11 @@
+# This file is automatically generated by Android Tools.
+# Do not modify this file -- YOUR CHANGES WILL BE ERASED!
+#
+# This file must be checked in Version Control Systems.
+#
+# To customize properties used by the Ant build system use,
+# "ant.properties", and override values to adapt the script to your
+# project structure.
+
+# Project target.
+target=android-10
diff --git a/subsonic-android/res/anim/push_down_in.xml b/subsonic-android/res/anim/push_down_in.xml
new file mode 100644
index 00000000..6ab9a047
--- /dev/null
+++ b/subsonic-android/res/anim/push_down_in.xml
@@ -0,0 +1,22 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2007 The Android Open Source Project
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+-->
+
+<set xmlns:android="http://schemas.android.com/apk/res/android">
+ <translate android:fromYDelta="-100%p" android:toYDelta="0"
+ android:duration="@android:integer/config_longAnimTime"/>
+ <alpha android:fromAlpha="0.0" android:toAlpha="1.0"
+ android:duration="@android:integer/config_longAnimTime" />
+</set>
diff --git a/subsonic-android/res/anim/push_down_out.xml b/subsonic-android/res/anim/push_down_out.xml
new file mode 100644
index 00000000..ce36458a
--- /dev/null
+++ b/subsonic-android/res/anim/push_down_out.xml
@@ -0,0 +1,22 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2007 The Android Open Source Project
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+-->
+
+<set xmlns:android="http://schemas.android.com/apk/res/android">
+ <translate android:fromYDelta="0" android:toYDelta="100%p"
+ android:duration="@android:integer/config_longAnimTime"/>
+ <alpha android:fromAlpha="1.0" android:toAlpha="0.0"
+ android:duration="@android:integer/config_longAnimTime" />
+</set>
diff --git a/subsonic-android/res/anim/push_up_in.xml b/subsonic-android/res/anim/push_up_in.xml
new file mode 100644
index 00000000..6ef582c4
--- /dev/null
+++ b/subsonic-android/res/anim/push_up_in.xml
@@ -0,0 +1,22 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2007 The Android Open Source Project
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+-->
+
+<set xmlns:android="http://schemas.android.com/apk/res/android">
+ <translate android:fromYDelta="100%p" android:toYDelta="0"
+ android:duration="@android:integer/config_longAnimTime"/>
+ <alpha android:fromAlpha="0.0" android:toAlpha="1.0"
+ android:duration="@android:integer/config_longAnimTime" />
+</set>
diff --git a/subsonic-android/res/anim/push_up_out.xml b/subsonic-android/res/anim/push_up_out.xml
new file mode 100644
index 00000000..2b267d59
--- /dev/null
+++ b/subsonic-android/res/anim/push_up_out.xml
@@ -0,0 +1,22 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2007 The Android Open Source Project
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+-->
+
+<set xmlns:android="http://schemas.android.com/apk/res/android">
+ <translate android:fromYDelta="0" android:toYDelta="-100%p"
+ android:duration="@android:integer/config_longAnimTime"/>
+ <alpha android:fromAlpha="1.0" android:toAlpha="0.0"
+ android:duration="@android:integer/config_longAnimTime" />
+</set>
diff --git a/subsonic-android/res/drawable-hdpi-v4/action_play_all.png b/subsonic-android/res/drawable-hdpi-v4/action_play_all.png
new file mode 100644
index 00000000..ff61f00d
--- /dev/null
+++ b/subsonic-android/res/drawable-hdpi-v4/action_play_all.png
Binary files differ
diff --git a/subsonic-android/res/drawable-hdpi-v4/action_refresh.png b/subsonic-android/res/drawable-hdpi-v4/action_refresh.png
new file mode 100644
index 00000000..e922c3f3
--- /dev/null
+++ b/subsonic-android/res/drawable-hdpi-v4/action_refresh.png
Binary files differ
diff --git a/subsonic-android/res/drawable-hdpi-v4/action_search.png b/subsonic-android/res/drawable-hdpi-v4/action_search.png
new file mode 100644
index 00000000..83933141
--- /dev/null
+++ b/subsonic-android/res/drawable-hdpi-v4/action_search.png
Binary files differ
diff --git a/subsonic-android/res/drawable-hdpi-v4/action_shuffle.png b/subsonic-android/res/drawable-hdpi-v4/action_shuffle.png
new file mode 100644
index 00000000..df145309
--- /dev/null
+++ b/subsonic-android/res/drawable-hdpi-v4/action_shuffle.png
Binary files differ
diff --git a/subsonic-android/res/drawable-hdpi-v4/actionbar_button_normal.9.png b/subsonic-android/res/drawable-hdpi-v4/actionbar_button_normal.9.png
new file mode 100644
index 00000000..385f751c
--- /dev/null
+++ b/subsonic-android/res/drawable-hdpi-v4/actionbar_button_normal.9.png
Binary files differ
diff --git a/subsonic-android/res/drawable-hdpi-v4/album_art_background.png b/subsonic-android/res/drawable-hdpi-v4/album_art_background.png
new file mode 100644
index 00000000..f0757695
--- /dev/null
+++ b/subsonic-android/res/drawable-hdpi-v4/album_art_background.png
Binary files differ
diff --git a/subsonic-android/res/drawable-hdpi-v4/appwidget_bg.9.png b/subsonic-android/res/drawable-hdpi-v4/appwidget_bg.9.png
new file mode 100644
index 00000000..3b29eae7
--- /dev/null
+++ b/subsonic-android/res/drawable-hdpi-v4/appwidget_bg.9.png
Binary files differ
diff --git a/subsonic-android/res/drawable-hdpi-v4/appwidget_divider.9.png b/subsonic-android/res/drawable-hdpi-v4/appwidget_divider.9.png
new file mode 100644
index 00000000..3445e842
--- /dev/null
+++ b/subsonic-android/res/drawable-hdpi-v4/appwidget_divider.9.png
Binary files differ
diff --git a/subsonic-android/res/drawable-hdpi-v4/appwidget_inner_focus_c.9.png b/subsonic-android/res/drawable-hdpi-v4/appwidget_inner_focus_c.9.png
new file mode 100644
index 00000000..a949bd2c
--- /dev/null
+++ b/subsonic-android/res/drawable-hdpi-v4/appwidget_inner_focus_c.9.png
Binary files differ
diff --git a/subsonic-android/res/drawable-hdpi-v4/appwidget_inner_focus_l.9.png b/subsonic-android/res/drawable-hdpi-v4/appwidget_inner_focus_l.9.png
new file mode 100644
index 00000000..4aaca6c5
--- /dev/null
+++ b/subsonic-android/res/drawable-hdpi-v4/appwidget_inner_focus_l.9.png
Binary files differ
diff --git a/subsonic-android/res/drawable-hdpi-v4/appwidget_inner_focus_r.9.png b/subsonic-android/res/drawable-hdpi-v4/appwidget_inner_focus_r.9.png
new file mode 100644
index 00000000..1fc0f900
--- /dev/null
+++ b/subsonic-android/res/drawable-hdpi-v4/appwidget_inner_focus_r.9.png
Binary files differ
diff --git a/subsonic-android/res/drawable-hdpi-v4/appwidget_inner_press_c.9.png b/subsonic-android/res/drawable-hdpi-v4/appwidget_inner_press_c.9.png
new file mode 100644
index 00000000..ca6f16cd
--- /dev/null
+++ b/subsonic-android/res/drawable-hdpi-v4/appwidget_inner_press_c.9.png
Binary files differ
diff --git a/subsonic-android/res/drawable-hdpi-v4/appwidget_inner_press_l.9.png b/subsonic-android/res/drawable-hdpi-v4/appwidget_inner_press_l.9.png
new file mode 100644
index 00000000..642eb3d3
--- /dev/null
+++ b/subsonic-android/res/drawable-hdpi-v4/appwidget_inner_press_l.9.png
Binary files differ
diff --git a/subsonic-android/res/drawable-hdpi-v4/appwidget_inner_press_r.9.png b/subsonic-android/res/drawable-hdpi-v4/appwidget_inner_press_r.9.png
new file mode 100644
index 00000000..5e1f70a3
--- /dev/null
+++ b/subsonic-android/res/drawable-hdpi-v4/appwidget_inner_press_r.9.png
Binary files differ
diff --git a/subsonic-android/res/drawable-hdpi-v4/ic_appwidget_music_next.png b/subsonic-android/res/drawable-hdpi-v4/ic_appwidget_music_next.png
new file mode 100644
index 00000000..99d28766
--- /dev/null
+++ b/subsonic-android/res/drawable-hdpi-v4/ic_appwidget_music_next.png
Binary files differ
diff --git a/subsonic-android/res/drawable-hdpi-v4/ic_appwidget_music_pause.png b/subsonic-android/res/drawable-hdpi-v4/ic_appwidget_music_pause.png
new file mode 100644
index 00000000..a05a8c50
--- /dev/null
+++ b/subsonic-android/res/drawable-hdpi-v4/ic_appwidget_music_pause.png
Binary files differ
diff --git a/subsonic-android/res/drawable-hdpi-v4/ic_appwidget_music_play.png b/subsonic-android/res/drawable-hdpi-v4/ic_appwidget_music_play.png
new file mode 100644
index 00000000..a754b920
--- /dev/null
+++ b/subsonic-android/res/drawable-hdpi-v4/ic_appwidget_music_play.png
Binary files differ
diff --git a/subsonic-android/res/drawable-hdpi-v4/ic_appwidget_music_previous.png b/subsonic-android/res/drawable-hdpi-v4/ic_appwidget_music_previous.png
new file mode 100644
index 00000000..7fb3921b
--- /dev/null
+++ b/subsonic-android/res/drawable-hdpi-v4/ic_appwidget_music_previous.png
Binary files differ
diff --git a/subsonic-android/res/drawable-hdpi-v4/ic_menu_exit.png b/subsonic-android/res/drawable-hdpi-v4/ic_menu_exit.png
new file mode 100644
index 00000000..28cad85e
--- /dev/null
+++ b/subsonic-android/res/drawable-hdpi-v4/ic_menu_exit.png
Binary files differ
diff --git a/subsonic-android/res/drawable-hdpi-v4/ic_menu_help.png b/subsonic-android/res/drawable-hdpi-v4/ic_menu_help.png
new file mode 100644
index 00000000..7e14e95d
--- /dev/null
+++ b/subsonic-android/res/drawable-hdpi-v4/ic_menu_help.png
Binary files differ
diff --git a/subsonic-android/res/drawable-hdpi-v4/ic_menu_remove_all.png b/subsonic-android/res/drawable-hdpi-v4/ic_menu_remove_all.png
new file mode 100644
index 00000000..112196be
--- /dev/null
+++ b/subsonic-android/res/drawable-hdpi-v4/ic_menu_remove_all.png
Binary files differ
diff --git a/subsonic-android/res/drawable-hdpi-v4/ic_menu_save.png b/subsonic-android/res/drawable-hdpi-v4/ic_menu_save.png
new file mode 100644
index 00000000..34f6e01a
--- /dev/null
+++ b/subsonic-android/res/drawable-hdpi-v4/ic_menu_save.png
Binary files differ
diff --git a/subsonic-android/res/drawable-hdpi-v4/ic_menu_screen_on_off.png b/subsonic-android/res/drawable-hdpi-v4/ic_menu_screen_on_off.png
new file mode 100644
index 00000000..db9235fc
--- /dev/null
+++ b/subsonic-android/res/drawable-hdpi-v4/ic_menu_screen_on_off.png
Binary files differ
diff --git a/subsonic-android/res/drawable-hdpi-v4/ic_menu_settings.png b/subsonic-android/res/drawable-hdpi-v4/ic_menu_settings.png
new file mode 100644
index 00000000..2ffcec52
--- /dev/null
+++ b/subsonic-android/res/drawable-hdpi-v4/ic_menu_settings.png
Binary files differ
diff --git a/subsonic-android/res/drawable-hdpi-v4/ic_menu_shuffle.png b/subsonic-android/res/drawable-hdpi-v4/ic_menu_shuffle.png
new file mode 100644
index 00000000..22ee1d50
--- /dev/null
+++ b/subsonic-android/res/drawable-hdpi-v4/ic_menu_shuffle.png
Binary files differ
diff --git a/subsonic-android/res/drawable-hdpi-v4/launch.png b/subsonic-android/res/drawable-hdpi-v4/launch.png
new file mode 100644
index 00000000..10693360
--- /dev/null
+++ b/subsonic-android/res/drawable-hdpi-v4/launch.png
Binary files differ
diff --git a/subsonic-android/res/drawable-hdpi-v4/list_item_artist.9.png b/subsonic-android/res/drawable-hdpi-v4/list_item_artist.9.png
new file mode 100644
index 00000000..7bddbcef
--- /dev/null
+++ b/subsonic-android/res/drawable-hdpi-v4/list_item_artist.9.png
Binary files differ
diff --git a/subsonic-android/res/drawable-hdpi-v4/list_item_playlist.9.png b/subsonic-android/res/drawable-hdpi-v4/list_item_playlist.9.png
new file mode 100644
index 00000000..7bddbcef
--- /dev/null
+++ b/subsonic-android/res/drawable-hdpi-v4/list_item_playlist.9.png
Binary files differ
diff --git a/subsonic-android/res/drawable-hdpi-v4/main_exit.png b/subsonic-android/res/drawable-hdpi-v4/main_exit.png
new file mode 100644
index 00000000..9a8b2a5e
--- /dev/null
+++ b/subsonic-android/res/drawable-hdpi-v4/main_exit.png
Binary files differ
diff --git a/subsonic-android/res/drawable-hdpi-v4/main_header_icon.png b/subsonic-android/res/drawable-hdpi-v4/main_header_icon.png
new file mode 100644
index 00000000..4252ba5b
--- /dev/null
+++ b/subsonic-android/res/drawable-hdpi-v4/main_header_icon.png
Binary files differ
diff --git a/subsonic-android/res/drawable-hdpi-v4/main_help.png b/subsonic-android/res/drawable-hdpi-v4/main_help.png
new file mode 100644
index 00000000..cb063b00
--- /dev/null
+++ b/subsonic-android/res/drawable-hdpi-v4/main_help.png
Binary files differ
diff --git a/subsonic-android/res/drawable-hdpi-v4/main_select_server.png b/subsonic-android/res/drawable-hdpi-v4/main_select_server.png
new file mode 100644
index 00000000..ccecc1d9
--- /dev/null
+++ b/subsonic-android/res/drawable-hdpi-v4/main_select_server.png
Binary files differ
diff --git a/subsonic-android/res/drawable-hdpi-v4/main_settings.png b/subsonic-android/res/drawable-hdpi-v4/main_settings.png
new file mode 100644
index 00000000..81bca4ae
--- /dev/null
+++ b/subsonic-android/res/drawable-hdpi-v4/main_settings.png
Binary files differ
diff --git a/subsonic-android/res/drawable-hdpi-v4/main_shuffle.png b/subsonic-android/res/drawable-hdpi-v4/main_shuffle.png
new file mode 100644
index 00000000..22ee1d50
--- /dev/null
+++ b/subsonic-android/res/drawable-hdpi-v4/main_shuffle.png
Binary files differ
diff --git a/subsonic-android/res/drawable-hdpi-v4/media_backward_normal.png b/subsonic-android/res/drawable-hdpi-v4/media_backward_normal.png
new file mode 100644
index 00000000..d2e44f1f
--- /dev/null
+++ b/subsonic-android/res/drawable-hdpi-v4/media_backward_normal.png
Binary files differ
diff --git a/subsonic-android/res/drawable-hdpi-v4/media_backward_pressed.png b/subsonic-android/res/drawable-hdpi-v4/media_backward_pressed.png
new file mode 100644
index 00000000..1ab22f24
--- /dev/null
+++ b/subsonic-android/res/drawable-hdpi-v4/media_backward_pressed.png
Binary files differ
diff --git a/subsonic-android/res/drawable-hdpi-v4/media_forward_normal.png b/subsonic-android/res/drawable-hdpi-v4/media_forward_normal.png
new file mode 100644
index 00000000..2b4a2eee
--- /dev/null
+++ b/subsonic-android/res/drawable-hdpi-v4/media_forward_normal.png
Binary files differ
diff --git a/subsonic-android/res/drawable-hdpi-v4/media_forward_pressed.png b/subsonic-android/res/drawable-hdpi-v4/media_forward_pressed.png
new file mode 100644
index 00000000..a6cd62a7
--- /dev/null
+++ b/subsonic-android/res/drawable-hdpi-v4/media_forward_pressed.png
Binary files differ
diff --git a/subsonic-android/res/drawable-hdpi-v4/media_pause_normal.png b/subsonic-android/res/drawable-hdpi-v4/media_pause_normal.png
new file mode 100644
index 00000000..c1eefc5b
--- /dev/null
+++ b/subsonic-android/res/drawable-hdpi-v4/media_pause_normal.png
Binary files differ
diff --git a/subsonic-android/res/drawable-hdpi-v4/media_pause_pressed.png b/subsonic-android/res/drawable-hdpi-v4/media_pause_pressed.png
new file mode 100644
index 00000000..f4de9fbd
--- /dev/null
+++ b/subsonic-android/res/drawable-hdpi-v4/media_pause_pressed.png
Binary files differ
diff --git a/subsonic-android/res/drawable-hdpi-v4/media_repeat_all.png b/subsonic-android/res/drawable-hdpi-v4/media_repeat_all.png
new file mode 100644
index 00000000..f8012f9f
--- /dev/null
+++ b/subsonic-android/res/drawable-hdpi-v4/media_repeat_all.png
Binary files differ
diff --git a/subsonic-android/res/drawable-hdpi-v4/media_repeat_off.png b/subsonic-android/res/drawable-hdpi-v4/media_repeat_off.png
new file mode 100644
index 00000000..caf2cdfb
--- /dev/null
+++ b/subsonic-android/res/drawable-hdpi-v4/media_repeat_off.png
Binary files differ
diff --git a/subsonic-android/res/drawable-hdpi-v4/media_repeat_single.png b/subsonic-android/res/drawable-hdpi-v4/media_repeat_single.png
new file mode 100644
index 00000000..99d534cb
--- /dev/null
+++ b/subsonic-android/res/drawable-hdpi-v4/media_repeat_single.png
Binary files differ
diff --git a/subsonic-android/res/drawable-hdpi-v4/media_shuffle_normal.png b/subsonic-android/res/drawable-hdpi-v4/media_shuffle_normal.png
new file mode 100644
index 00000000..18e69dea
--- /dev/null
+++ b/subsonic-android/res/drawable-hdpi-v4/media_shuffle_normal.png
Binary files differ
diff --git a/subsonic-android/res/drawable-hdpi-v4/media_shuffle_pressed.png b/subsonic-android/res/drawable-hdpi-v4/media_shuffle_pressed.png
new file mode 100644
index 00000000..4e2e77a2
--- /dev/null
+++ b/subsonic-android/res/drawable-hdpi-v4/media_shuffle_pressed.png
Binary files differ
diff --git a/subsonic-android/res/drawable-hdpi-v4/media_start_normal.png b/subsonic-android/res/drawable-hdpi-v4/media_start_normal.png
new file mode 100644
index 00000000..f987b1c2
--- /dev/null
+++ b/subsonic-android/res/drawable-hdpi-v4/media_start_normal.png
Binary files differ
diff --git a/subsonic-android/res/drawable-hdpi-v4/media_start_pressed.png b/subsonic-android/res/drawable-hdpi-v4/media_start_pressed.png
new file mode 100644
index 00000000..97edb4ab
--- /dev/null
+++ b/subsonic-android/res/drawable-hdpi-v4/media_start_pressed.png
Binary files differ
diff --git a/subsonic-android/res/drawable-hdpi-v4/media_stop_normal.png b/subsonic-android/res/drawable-hdpi-v4/media_stop_normal.png
new file mode 100644
index 00000000..6f03a5d3
--- /dev/null
+++ b/subsonic-android/res/drawable-hdpi-v4/media_stop_normal.png
Binary files differ
diff --git a/subsonic-android/res/drawable-hdpi-v4/media_stop_pressed.png b/subsonic-android/res/drawable-hdpi-v4/media_stop_pressed.png
new file mode 100644
index 00000000..7d76ec08
--- /dev/null
+++ b/subsonic-android/res/drawable-hdpi-v4/media_stop_pressed.png
Binary files differ
diff --git a/subsonic-android/res/drawable-hdpi-v4/media_toggle_list_normal.png b/subsonic-android/res/drawable-hdpi-v4/media_toggle_list_normal.png
new file mode 100644
index 00000000..05941b3d
--- /dev/null
+++ b/subsonic-android/res/drawable-hdpi-v4/media_toggle_list_normal.png
Binary files differ
diff --git a/subsonic-android/res/drawable-hdpi-v4/media_toggle_list_pressed.png b/subsonic-android/res/drawable-hdpi-v4/media_toggle_list_pressed.png
new file mode 100644
index 00000000..f1019360
--- /dev/null
+++ b/subsonic-android/res/drawable-hdpi-v4/media_toggle_list_pressed.png
Binary files differ
diff --git a/subsonic-android/res/drawable-hdpi-v4/menu_browse.png b/subsonic-android/res/drawable-hdpi-v4/menu_browse.png
new file mode 100644
index 00000000..70a59154
--- /dev/null
+++ b/subsonic-android/res/drawable-hdpi-v4/menu_browse.png
Binary files differ
diff --git a/subsonic-android/res/drawable-hdpi-v4/menu_home.png b/subsonic-android/res/drawable-hdpi-v4/menu_home.png
new file mode 100644
index 00000000..35cb52aa
--- /dev/null
+++ b/subsonic-android/res/drawable-hdpi-v4/menu_home.png
Binary files differ
diff --git a/subsonic-android/res/drawable-hdpi-v4/menu_now_playing.png b/subsonic-android/res/drawable-hdpi-v4/menu_now_playing.png
new file mode 100644
index 00000000..10af07fe
--- /dev/null
+++ b/subsonic-android/res/drawable-hdpi-v4/menu_now_playing.png
Binary files differ
diff --git a/subsonic-android/res/drawable-hdpi-v4/menu_playlists.png b/subsonic-android/res/drawable-hdpi-v4/menu_playlists.png
new file mode 100644
index 00000000..59345d5b
--- /dev/null
+++ b/subsonic-android/res/drawable-hdpi-v4/menu_playlists.png
Binary files differ
diff --git a/subsonic-android/res/drawable-hdpi-v4/menu_search.png b/subsonic-android/res/drawable-hdpi-v4/menu_search.png
new file mode 100644
index 00000000..f78234e4
--- /dev/null
+++ b/subsonic-android/res/drawable-hdpi-v4/menu_search.png
Binary files differ
diff --git a/subsonic-android/res/drawable-hdpi-v4/menubar_button_disabled.9.png b/subsonic-android/res/drawable-hdpi-v4/menubar_button_disabled.9.png
new file mode 100644
index 00000000..94a48f7d
--- /dev/null
+++ b/subsonic-android/res/drawable-hdpi-v4/menubar_button_disabled.9.png
Binary files differ
diff --git a/subsonic-android/res/drawable-hdpi-v4/menubar_button_normal.9.png b/subsonic-android/res/drawable-hdpi-v4/menubar_button_normal.9.png
new file mode 100644
index 00000000..9ce38a61
--- /dev/null
+++ b/subsonic-android/res/drawable-hdpi-v4/menubar_button_normal.9.png
Binary files differ
diff --git a/subsonic-android/res/drawable-hdpi-v4/menubar_button_pressed.9.png b/subsonic-android/res/drawable-hdpi-v4/menubar_button_pressed.9.png
new file mode 100644
index 00000000..4dff0907
--- /dev/null
+++ b/subsonic-android/res/drawable-hdpi-v4/menubar_button_pressed.9.png
Binary files differ
diff --git a/subsonic-android/res/drawable-hdpi-v4/refresh.png b/subsonic-android/res/drawable-hdpi-v4/refresh.png
new file mode 100644
index 00000000..2f887c26
--- /dev/null
+++ b/subsonic-android/res/drawable-hdpi-v4/refresh.png
Binary files differ
diff --git a/subsonic-android/res/drawable-hdpi-v4/search.png b/subsonic-android/res/drawable-hdpi-v4/search.png
new file mode 100644
index 00000000..43d8c87e
--- /dev/null
+++ b/subsonic-android/res/drawable-hdpi-v4/search.png
Binary files differ
diff --git a/subsonic-android/res/drawable-hdpi-v4/select_album_play_all_normal.png b/subsonic-android/res/drawable-hdpi-v4/select_album_play_all_normal.png
new file mode 100644
index 00000000..bcf0efe6
--- /dev/null
+++ b/subsonic-android/res/drawable-hdpi-v4/select_album_play_all_normal.png
Binary files differ
diff --git a/subsonic-android/res/drawable-hdpi-v4/select_album_play_all_pressed.png b/subsonic-android/res/drawable-hdpi-v4/select_album_play_all_pressed.png
new file mode 100644
index 00000000..31bbfff0
--- /dev/null
+++ b/subsonic-android/res/drawable-hdpi-v4/select_album_play_all_pressed.png
Binary files differ
diff --git a/subsonic-android/res/drawable-hdpi-v4/select_artist_folder.png b/subsonic-android/res/drawable-hdpi-v4/select_artist_folder.png
new file mode 100644
index 00000000..ccecc1d9
--- /dev/null
+++ b/subsonic-android/res/drawable-hdpi-v4/select_artist_folder.png
Binary files differ
diff --git a/subsonic-android/res/drawable-hdpi-v4/stat_notify_playing.png b/subsonic-android/res/drawable-hdpi-v4/stat_notify_playing.png
new file mode 100644
index 00000000..bfd3e6a5
--- /dev/null
+++ b/subsonic-android/res/drawable-hdpi-v4/stat_notify_playing.png
Binary files differ
diff --git a/subsonic-android/res/drawable-hdpi-v4/unknown_album.png b/subsonic-android/res/drawable-hdpi-v4/unknown_album.png
new file mode 100644
index 00000000..ba1e4e64
--- /dev/null
+++ b/subsonic-android/res/drawable-hdpi-v4/unknown_album.png
Binary files differ
diff --git a/subsonic-android/res/drawable-hdpi-v4/unknown_album_large.png b/subsonic-android/res/drawable-hdpi-v4/unknown_album_large.png
new file mode 100644
index 00000000..bd9c6cc9
--- /dev/null
+++ b/subsonic-android/res/drawable-hdpi-v4/unknown_album_large.png
Binary files differ
diff --git a/subsonic-android/res/drawable/action_play_all.png b/subsonic-android/res/drawable/action_play_all.png
new file mode 100644
index 00000000..dd718312
--- /dev/null
+++ b/subsonic-android/res/drawable/action_play_all.png
Binary files differ
diff --git a/subsonic-android/res/drawable/action_refresh.png b/subsonic-android/res/drawable/action_refresh.png
new file mode 100644
index 00000000..0aa88f5d
--- /dev/null
+++ b/subsonic-android/res/drawable/action_refresh.png
Binary files differ
diff --git a/subsonic-android/res/drawable/action_search.png b/subsonic-android/res/drawable/action_search.png
new file mode 100644
index 00000000..3fba5ec5
--- /dev/null
+++ b/subsonic-android/res/drawable/action_search.png
Binary files differ
diff --git a/subsonic-android/res/drawable/action_shuffle.png b/subsonic-android/res/drawable/action_shuffle.png
new file mode 100644
index 00000000..e1ed3177
--- /dev/null
+++ b/subsonic-android/res/drawable/action_shuffle.png
Binary files differ
diff --git a/subsonic-android/res/drawable/actionbar_button.xml b/subsonic-android/res/drawable/actionbar_button.xml
new file mode 100644
index 00000000..5445cdcb
--- /dev/null
+++ b/subsonic-android/res/drawable/actionbar_button.xml
@@ -0,0 +1,18 @@
+<?xml version="1.0" encoding="utf-8"?>
+<selector xmlns:android="http://schemas.android.com/apk/res/android">
+
+ <item
+ android:state_pressed="true"
+ android:drawable="@drawable/menubar_button_pressed"
+ />
+
+ <item
+ android:state_focused="true"
+ android:drawable="@drawable/menubar_button_pressed"
+ />
+
+ <item
+ android:drawable="@drawable/actionbar_button_normal"
+ />
+
+</selector> \ No newline at end of file
diff --git a/subsonic-android/res/drawable/actionbar_button_normal.9.png b/subsonic-android/res/drawable/actionbar_button_normal.9.png
new file mode 100644
index 00000000..385f751c
--- /dev/null
+++ b/subsonic-android/res/drawable/actionbar_button_normal.9.png
Binary files differ
diff --git a/subsonic-android/res/drawable/album_art_background.png b/subsonic-android/res/drawable/album_art_background.png
new file mode 100644
index 00000000..f0757695
--- /dev/null
+++ b/subsonic-android/res/drawable/album_art_background.png
Binary files differ
diff --git a/subsonic-android/res/drawable/appwidget_art_default.png b/subsonic-android/res/drawable/appwidget_art_default.png
new file mode 100644
index 00000000..5bd39cc2
--- /dev/null
+++ b/subsonic-android/res/drawable/appwidget_art_default.png
Binary files differ
diff --git a/subsonic-android/res/drawable/appwidget_art_unknown.png b/subsonic-android/res/drawable/appwidget_art_unknown.png
new file mode 100644
index 00000000..5bd39cc2
--- /dev/null
+++ b/subsonic-android/res/drawable/appwidget_art_unknown.png
Binary files differ
diff --git a/subsonic-android/res/drawable/appwidget_bg.9.png b/subsonic-android/res/drawable/appwidget_bg.9.png
new file mode 100644
index 00000000..afe41b67
--- /dev/null
+++ b/subsonic-android/res/drawable/appwidget_bg.9.png
Binary files differ
diff --git a/subsonic-android/res/drawable/appwidget_button_background.9.png b/subsonic-android/res/drawable/appwidget_button_background.9.png
new file mode 100644
index 00000000..b7d3b18f
--- /dev/null
+++ b/subsonic-android/res/drawable/appwidget_button_background.9.png
Binary files differ
diff --git a/subsonic-android/res/drawable/appwidget_button_background_r.9.png b/subsonic-android/res/drawable/appwidget_button_background_r.9.png
new file mode 100644
index 00000000..90e2cc82
--- /dev/null
+++ b/subsonic-android/res/drawable/appwidget_button_background_r.9.png
Binary files differ
diff --git a/subsonic-android/res/drawable/appwidget_button_center.xml b/subsonic-android/res/drawable/appwidget_button_center.xml
new file mode 100644
index 00000000..b6a3be4b
--- /dev/null
+++ b/subsonic-android/res/drawable/appwidget_button_center.xml
@@ -0,0 +1,27 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2009 The Android Open Source Project
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+-->
+
+<selector xmlns:android="http://schemas.android.com/apk/res/android">
+
+ <item android:state_pressed="true"
+ android:drawable="@drawable/appwidget_overlay" />
+
+ <item android:state_focused="true" android:state_enabled="true"
+ android:state_window_focused="true"
+ android:drawable="@drawable/appwidget_overlay" />
+
+ <item android:drawable="@drawable/appwidget_button_background" />
+</selector>
diff --git a/subsonic-android/res/drawable/appwidget_button_left.xml b/subsonic-android/res/drawable/appwidget_button_left.xml
new file mode 100644
index 00000000..5bfa124c
--- /dev/null
+++ b/subsonic-android/res/drawable/appwidget_button_left.xml
@@ -0,0 +1,27 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2009 The Android Open Source Project
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+-->
+
+<selector xmlns:android="http://schemas.android.com/apk/res/android">
+
+ <item android:state_pressed="true"
+ android:drawable="@drawable/appwidget_overlay" />
+
+ <item android:state_focused="true" android:state_enabled="true"
+ android:state_window_focused="true"
+ android:drawable="@drawable/appwidget_overlay" />
+
+ <item android:drawable="@android:color/transparent" />
+</selector>
diff --git a/subsonic-android/res/drawable/appwidget_button_right.xml b/subsonic-android/res/drawable/appwidget_button_right.xml
new file mode 100644
index 00000000..3d1181be
--- /dev/null
+++ b/subsonic-android/res/drawable/appwidget_button_right.xml
@@ -0,0 +1,27 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2009 The Android Open Source Project
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+-->
+
+<selector xmlns:android="http://schemas.android.com/apk/res/android">
+
+ <item android:state_pressed="true"
+ android:drawable="@drawable/appwidget_overlay" />
+
+ <item android:state_focused="true" android:state_enabled="true"
+ android:state_window_focused="true"
+ android:drawable="@drawable/appwidget_overlay" />
+
+ <item android:drawable="@drawable/appwidget_button_background_r" />
+</selector>
diff --git a/subsonic-android/res/drawable/appwidget_divider.9.png b/subsonic-android/res/drawable/appwidget_divider.9.png
new file mode 100644
index 00000000..3445e842
--- /dev/null
+++ b/subsonic-android/res/drawable/appwidget_divider.9.png
Binary files differ
diff --git a/subsonic-android/res/drawable/appwidget_divider_horizontal.9.png b/subsonic-android/res/drawable/appwidget_divider_horizontal.9.png
new file mode 100644
index 00000000..e2e80af9
--- /dev/null
+++ b/subsonic-android/res/drawable/appwidget_divider_horizontal.9.png
Binary files differ
diff --git a/subsonic-android/res/drawable/appwidget_divider_vertical.png b/subsonic-android/res/drawable/appwidget_divider_vertical.png
new file mode 100644
index 00000000..efe466a6
--- /dev/null
+++ b/subsonic-android/res/drawable/appwidget_divider_vertical.png
Binary files differ
diff --git a/subsonic-android/res/drawable/appwidget_inner_focus_c.9.png b/subsonic-android/res/drawable/appwidget_inner_focus_c.9.png
new file mode 100644
index 00000000..1450e65b
--- /dev/null
+++ b/subsonic-android/res/drawable/appwidget_inner_focus_c.9.png
Binary files differ
diff --git a/subsonic-android/res/drawable/appwidget_inner_focus_l.9.png b/subsonic-android/res/drawable/appwidget_inner_focus_l.9.png
new file mode 100644
index 00000000..6e8f100e
--- /dev/null
+++ b/subsonic-android/res/drawable/appwidget_inner_focus_l.9.png
Binary files differ
diff --git a/subsonic-android/res/drawable/appwidget_inner_focus_r.9.png b/subsonic-android/res/drawable/appwidget_inner_focus_r.9.png
new file mode 100644
index 00000000..bc8757b8
--- /dev/null
+++ b/subsonic-android/res/drawable/appwidget_inner_focus_r.9.png
Binary files differ
diff --git a/subsonic-android/res/drawable/appwidget_inner_press_c.9.png b/subsonic-android/res/drawable/appwidget_inner_press_c.9.png
new file mode 100644
index 00000000..bd542bac
--- /dev/null
+++ b/subsonic-android/res/drawable/appwidget_inner_press_c.9.png
Binary files differ
diff --git a/subsonic-android/res/drawable/appwidget_inner_press_l.9.png b/subsonic-android/res/drawable/appwidget_inner_press_l.9.png
new file mode 100644
index 00000000..575ecf4e
--- /dev/null
+++ b/subsonic-android/res/drawable/appwidget_inner_press_l.9.png
Binary files differ
diff --git a/subsonic-android/res/drawable/appwidget_inner_press_r.9.png b/subsonic-android/res/drawable/appwidget_inner_press_r.9.png
new file mode 100644
index 00000000..79eaea35
--- /dev/null
+++ b/subsonic-android/res/drawable/appwidget_inner_press_r.9.png
Binary files differ
diff --git a/subsonic-android/res/drawable/appwidget_overlay.png b/subsonic-android/res/drawable/appwidget_overlay.png
new file mode 100644
index 00000000..dfbbd3ec
--- /dev/null
+++ b/subsonic-android/res/drawable/appwidget_overlay.png
Binary files differ
diff --git a/subsonic-android/res/drawable/downloaded.png b/subsonic-android/res/drawable/downloaded.png
new file mode 100644
index 00000000..f854aaf4
--- /dev/null
+++ b/subsonic-android/res/drawable/downloaded.png
Binary files differ
diff --git a/subsonic-android/res/drawable/downloading.png b/subsonic-android/res/drawable/downloading.png
new file mode 100644
index 00000000..afff39a9
--- /dev/null
+++ b/subsonic-android/res/drawable/downloading.png
Binary files differ
diff --git a/subsonic-android/res/drawable/ic_appwidget_music_next.png b/subsonic-android/res/drawable/ic_appwidget_music_next.png
new file mode 100644
index 00000000..abc8e471
--- /dev/null
+++ b/subsonic-android/res/drawable/ic_appwidget_music_next.png
Binary files differ
diff --git a/subsonic-android/res/drawable/ic_appwidget_music_pause.png b/subsonic-android/res/drawable/ic_appwidget_music_pause.png
new file mode 100644
index 00000000..25a2d387
--- /dev/null
+++ b/subsonic-android/res/drawable/ic_appwidget_music_pause.png
Binary files differ
diff --git a/subsonic-android/res/drawable/ic_appwidget_music_play.png b/subsonic-android/res/drawable/ic_appwidget_music_play.png
new file mode 100644
index 00000000..52b8e452
--- /dev/null
+++ b/subsonic-android/res/drawable/ic_appwidget_music_play.png
Binary files differ
diff --git a/subsonic-android/res/drawable/ic_appwidget_music_previous.png b/subsonic-android/res/drawable/ic_appwidget_music_previous.png
new file mode 100644
index 00000000..55db16f7
--- /dev/null
+++ b/subsonic-android/res/drawable/ic_appwidget_music_previous.png
Binary files differ
diff --git a/subsonic-android/res/drawable/ic_menu_exit.png b/subsonic-android/res/drawable/ic_menu_exit.png
new file mode 100644
index 00000000..847a1ed3
--- /dev/null
+++ b/subsonic-android/res/drawable/ic_menu_exit.png
Binary files differ
diff --git a/subsonic-android/res/drawable/ic_menu_help.png b/subsonic-android/res/drawable/ic_menu_help.png
new file mode 100644
index 00000000..9f11f434
--- /dev/null
+++ b/subsonic-android/res/drawable/ic_menu_help.png
Binary files differ
diff --git a/subsonic-android/res/drawable/ic_menu_remove_all.png b/subsonic-android/res/drawable/ic_menu_remove_all.png
new file mode 100644
index 00000000..1a9f440b
--- /dev/null
+++ b/subsonic-android/res/drawable/ic_menu_remove_all.png
Binary files differ
diff --git a/subsonic-android/res/drawable/ic_menu_save.png b/subsonic-android/res/drawable/ic_menu_save.png
new file mode 100644
index 00000000..c2c5433b
--- /dev/null
+++ b/subsonic-android/res/drawable/ic_menu_save.png
Binary files differ
diff --git a/subsonic-android/res/drawable/ic_menu_screen_on_off.png b/subsonic-android/res/drawable/ic_menu_screen_on_off.png
new file mode 100644
index 00000000..0cf15235
--- /dev/null
+++ b/subsonic-android/res/drawable/ic_menu_screen_on_off.png
Binary files differ
diff --git a/subsonic-android/res/drawable/ic_menu_settings.png b/subsonic-android/res/drawable/ic_menu_settings.png
new file mode 100644
index 00000000..48775c1e
--- /dev/null
+++ b/subsonic-android/res/drawable/ic_menu_settings.png
Binary files differ
diff --git a/subsonic-android/res/drawable/ic_menu_shuffle.png b/subsonic-android/res/drawable/ic_menu_shuffle.png
new file mode 100644
index 00000000..2ba6c8c5
--- /dev/null
+++ b/subsonic-android/res/drawable/ic_menu_shuffle.png
Binary files differ
diff --git a/subsonic-android/res/drawable/launch.png b/subsonic-android/res/drawable/launch.png
new file mode 100644
index 00000000..b3befadf
--- /dev/null
+++ b/subsonic-android/res/drawable/launch.png
Binary files differ
diff --git a/subsonic-android/res/drawable/list_item_artist.9.png b/subsonic-android/res/drawable/list_item_artist.9.png
new file mode 100644
index 00000000..9967ecbd
--- /dev/null
+++ b/subsonic-android/res/drawable/list_item_artist.9.png
Binary files differ
diff --git a/subsonic-android/res/drawable/list_item_playlist.9.png b/subsonic-android/res/drawable/list_item_playlist.9.png
new file mode 100644
index 00000000..9967ecbd
--- /dev/null
+++ b/subsonic-android/res/drawable/list_item_playlist.9.png
Binary files differ
diff --git a/subsonic-android/res/drawable/main_exit.png b/subsonic-android/res/drawable/main_exit.png
new file mode 100644
index 00000000..d385b7a6
--- /dev/null
+++ b/subsonic-android/res/drawable/main_exit.png
Binary files differ
diff --git a/subsonic-android/res/drawable/main_header_icon.png b/subsonic-android/res/drawable/main_header_icon.png
new file mode 100644
index 00000000..f4f3ce9e
--- /dev/null
+++ b/subsonic-android/res/drawable/main_header_icon.png
Binary files differ
diff --git a/subsonic-android/res/drawable/main_help.png b/subsonic-android/res/drawable/main_help.png
new file mode 100644
index 00000000..2c825473
--- /dev/null
+++ b/subsonic-android/res/drawable/main_help.png
Binary files differ
diff --git a/subsonic-android/res/drawable/main_select_server.png b/subsonic-android/res/drawable/main_select_server.png
new file mode 100644
index 00000000..b9fc5fa3
--- /dev/null
+++ b/subsonic-android/res/drawable/main_select_server.png
Binary files differ
diff --git a/subsonic-android/res/drawable/main_settings.png b/subsonic-android/res/drawable/main_settings.png
new file mode 100644
index 00000000..60dbff6d
--- /dev/null
+++ b/subsonic-android/res/drawable/main_settings.png
Binary files differ
diff --git a/subsonic-android/res/drawable/main_shuffle.png b/subsonic-android/res/drawable/main_shuffle.png
new file mode 100644
index 00000000..cb7009de
--- /dev/null
+++ b/subsonic-android/res/drawable/main_shuffle.png
Binary files differ
diff --git a/subsonic-android/res/drawable/media_backward.xml b/subsonic-android/res/drawable/media_backward.xml
new file mode 100644
index 00000000..22db3dd0
--- /dev/null
+++ b/subsonic-android/res/drawable/media_backward.xml
@@ -0,0 +1,5 @@
+<?xml version="1.0" encoding="utf-8"?>
+<selector xmlns:android="http://schemas.android.com/apk/res/android">
+ <item android:state_pressed="true" android:drawable="@drawable/media_backward_pressed" />
+ <item android:drawable="@drawable/media_backward_normal" />
+</selector> \ No newline at end of file
diff --git a/subsonic-android/res/drawable/media_backward_normal.png b/subsonic-android/res/drawable/media_backward_normal.png
new file mode 100644
index 00000000..e5372389
--- /dev/null
+++ b/subsonic-android/res/drawable/media_backward_normal.png
Binary files differ
diff --git a/subsonic-android/res/drawable/media_backward_pressed.png b/subsonic-android/res/drawable/media_backward_pressed.png
new file mode 100644
index 00000000..82c421d0
--- /dev/null
+++ b/subsonic-android/res/drawable/media_backward_pressed.png
Binary files differ
diff --git a/subsonic-android/res/drawable/media_forward.xml b/subsonic-android/res/drawable/media_forward.xml
new file mode 100644
index 00000000..c6d1a0cd
--- /dev/null
+++ b/subsonic-android/res/drawable/media_forward.xml
@@ -0,0 +1,5 @@
+<?xml version="1.0" encoding="utf-8"?>
+<selector xmlns:android="http://schemas.android.com/apk/res/android">
+ <item android:state_pressed="true" android:drawable="@drawable/media_forward_pressed" />
+ <item android:drawable="@drawable/media_forward_normal" />
+</selector> \ No newline at end of file
diff --git a/subsonic-android/res/drawable/media_forward_normal.png b/subsonic-android/res/drawable/media_forward_normal.png
new file mode 100644
index 00000000..6cb93917
--- /dev/null
+++ b/subsonic-android/res/drawable/media_forward_normal.png
Binary files differ
diff --git a/subsonic-android/res/drawable/media_forward_pressed.png b/subsonic-android/res/drawable/media_forward_pressed.png
new file mode 100644
index 00000000..42ffbe4c
--- /dev/null
+++ b/subsonic-android/res/drawable/media_forward_pressed.png
Binary files differ
diff --git a/subsonic-android/res/drawable/media_pause.xml b/subsonic-android/res/drawable/media_pause.xml
new file mode 100644
index 00000000..750ba3f1
--- /dev/null
+++ b/subsonic-android/res/drawable/media_pause.xml
@@ -0,0 +1,5 @@
+<?xml version="1.0" encoding="utf-8"?>
+<selector xmlns:android="http://schemas.android.com/apk/res/android">
+ <item android:state_pressed="true" android:drawable="@drawable/media_pause_pressed" />
+ <item android:drawable="@drawable/media_pause_normal" />
+</selector> \ No newline at end of file
diff --git a/subsonic-android/res/drawable/media_pause_normal.png b/subsonic-android/res/drawable/media_pause_normal.png
new file mode 100644
index 00000000..4fc03eb2
--- /dev/null
+++ b/subsonic-android/res/drawable/media_pause_normal.png
Binary files differ
diff --git a/subsonic-android/res/drawable/media_pause_pressed.png b/subsonic-android/res/drawable/media_pause_pressed.png
new file mode 100644
index 00000000..dd9ae605
--- /dev/null
+++ b/subsonic-android/res/drawable/media_pause_pressed.png
Binary files differ
diff --git a/subsonic-android/res/drawable/media_repeat_all.png b/subsonic-android/res/drawable/media_repeat_all.png
new file mode 100644
index 00000000..6a5d4e41
--- /dev/null
+++ b/subsonic-android/res/drawable/media_repeat_all.png
Binary files differ
diff --git a/subsonic-android/res/drawable/media_repeat_off.png b/subsonic-android/res/drawable/media_repeat_off.png
new file mode 100644
index 00000000..a4417248
--- /dev/null
+++ b/subsonic-android/res/drawable/media_repeat_off.png
Binary files differ
diff --git a/subsonic-android/res/drawable/media_repeat_single.png b/subsonic-android/res/drawable/media_repeat_single.png
new file mode 100644
index 00000000..3dec6958
--- /dev/null
+++ b/subsonic-android/res/drawable/media_repeat_single.png
Binary files differ
diff --git a/subsonic-android/res/drawable/media_shuffle.xml b/subsonic-android/res/drawable/media_shuffle.xml
new file mode 100644
index 00000000..55d744cc
--- /dev/null
+++ b/subsonic-android/res/drawable/media_shuffle.xml
@@ -0,0 +1,5 @@
+<?xml version="1.0" encoding="utf-8"?>
+<selector xmlns:android="http://schemas.android.com/apk/res/android">
+ <item android:state_pressed="true" android:drawable="@drawable/media_shuffle_pressed" />
+ <item android:drawable="@drawable/media_shuffle_normal" />
+</selector> \ No newline at end of file
diff --git a/subsonic-android/res/drawable/media_shuffle_normal.png b/subsonic-android/res/drawable/media_shuffle_normal.png
new file mode 100644
index 00000000..dc6b8c8c
--- /dev/null
+++ b/subsonic-android/res/drawable/media_shuffle_normal.png
Binary files differ
diff --git a/subsonic-android/res/drawable/media_shuffle_pressed.png b/subsonic-android/res/drawable/media_shuffle_pressed.png
new file mode 100644
index 00000000..fb2639c8
--- /dev/null
+++ b/subsonic-android/res/drawable/media_shuffle_pressed.png
Binary files differ
diff --git a/subsonic-android/res/drawable/media_start.xml b/subsonic-android/res/drawable/media_start.xml
new file mode 100644
index 00000000..57117df7
--- /dev/null
+++ b/subsonic-android/res/drawable/media_start.xml
@@ -0,0 +1,5 @@
+<?xml version="1.0" encoding="utf-8"?>
+<selector xmlns:android="http://schemas.android.com/apk/res/android">
+ <item android:state_pressed="true" android:drawable="@drawable/media_start_pressed" />
+ <item android:drawable="@drawable/media_start_normal" />
+</selector> \ No newline at end of file
diff --git a/subsonic-android/res/drawable/media_start_normal.png b/subsonic-android/res/drawable/media_start_normal.png
new file mode 100644
index 00000000..a3775d43
--- /dev/null
+++ b/subsonic-android/res/drawable/media_start_normal.png
Binary files differ
diff --git a/subsonic-android/res/drawable/media_start_pressed.png b/subsonic-android/res/drawable/media_start_pressed.png
new file mode 100644
index 00000000..d7ace1ba
--- /dev/null
+++ b/subsonic-android/res/drawable/media_start_pressed.png
Binary files differ
diff --git a/subsonic-android/res/drawable/media_stop.xml b/subsonic-android/res/drawable/media_stop.xml
new file mode 100644
index 00000000..0cd2ff10
--- /dev/null
+++ b/subsonic-android/res/drawable/media_stop.xml
@@ -0,0 +1,5 @@
+<?xml version="1.0" encoding="utf-8"?>
+<selector xmlns:android="http://schemas.android.com/apk/res/android">
+ <item android:state_pressed="true" android:drawable="@drawable/media_stop_pressed" />
+ <item android:drawable="@drawable/media_stop_normal" />
+</selector> \ No newline at end of file
diff --git a/subsonic-android/res/drawable/media_stop_normal.png b/subsonic-android/res/drawable/media_stop_normal.png
new file mode 100644
index 00000000..120aecd0
--- /dev/null
+++ b/subsonic-android/res/drawable/media_stop_normal.png
Binary files differ
diff --git a/subsonic-android/res/drawable/media_stop_pressed.png b/subsonic-android/res/drawable/media_stop_pressed.png
new file mode 100644
index 00000000..b590abe8
--- /dev/null
+++ b/subsonic-android/res/drawable/media_stop_pressed.png
Binary files differ
diff --git a/subsonic-android/res/drawable/media_toggle_list.xml b/subsonic-android/res/drawable/media_toggle_list.xml
new file mode 100644
index 00000000..350818e7
--- /dev/null
+++ b/subsonic-android/res/drawable/media_toggle_list.xml
@@ -0,0 +1,5 @@
+<?xml version="1.0" encoding="utf-8"?>
+<selector xmlns:android="http://schemas.android.com/apk/res/android">
+ <item android:state_pressed="true" android:drawable="@drawable/media_toggle_list_pressed" />
+ <item android:drawable="@drawable/media_toggle_list_normal" />
+</selector> \ No newline at end of file
diff --git a/subsonic-android/res/drawable/media_toggle_list_normal.png b/subsonic-android/res/drawable/media_toggle_list_normal.png
new file mode 100644
index 00000000..cc269b65
--- /dev/null
+++ b/subsonic-android/res/drawable/media_toggle_list_normal.png
Binary files differ
diff --git a/subsonic-android/res/drawable/media_toggle_list_pressed.png b/subsonic-android/res/drawable/media_toggle_list_pressed.png
new file mode 100644
index 00000000..97b9a413
--- /dev/null
+++ b/subsonic-android/res/drawable/media_toggle_list_pressed.png
Binary files differ
diff --git a/subsonic-android/res/drawable/menu_browse.png b/subsonic-android/res/drawable/menu_browse.png
new file mode 100644
index 00000000..3f1de60d
--- /dev/null
+++ b/subsonic-android/res/drawable/menu_browse.png
Binary files differ
diff --git a/subsonic-android/res/drawable/menu_home.png b/subsonic-android/res/drawable/menu_home.png
new file mode 100644
index 00000000..34943f66
--- /dev/null
+++ b/subsonic-android/res/drawable/menu_home.png
Binary files differ
diff --git a/subsonic-android/res/drawable/menu_now_playing.png b/subsonic-android/res/drawable/menu_now_playing.png
new file mode 100644
index 00000000..22f203a8
--- /dev/null
+++ b/subsonic-android/res/drawable/menu_now_playing.png
Binary files differ
diff --git a/subsonic-android/res/drawable/menu_playlists.png b/subsonic-android/res/drawable/menu_playlists.png
new file mode 100644
index 00000000..c01733d9
--- /dev/null
+++ b/subsonic-android/res/drawable/menu_playlists.png
Binary files differ
diff --git a/subsonic-android/res/drawable/menu_search.png b/subsonic-android/res/drawable/menu_search.png
new file mode 100644
index 00000000..94446db9
--- /dev/null
+++ b/subsonic-android/res/drawable/menu_search.png
Binary files differ
diff --git a/subsonic-android/res/drawable/menubar_button.xml b/subsonic-android/res/drawable/menubar_button.xml
new file mode 100644
index 00000000..06c2c8e7
--- /dev/null
+++ b/subsonic-android/res/drawable/menubar_button.xml
@@ -0,0 +1,14 @@
+<?xml version="1.0" encoding="utf-8"?>
+<selector xmlns:android="http://schemas.android.com/apk/res/android">
+ 
+ <item android:state_pressed="true"
+ android:drawable="@drawable/menubar_button_pressed"/>
+
+ <item android:state_enabled="true"
+ android:drawable="@drawable/menubar_button_normal"/>
+
+ <item android:drawable="@drawable/menubar_button_disabled"/>
+
+</selector>
+
+ \ No newline at end of file
diff --git a/subsonic-android/res/drawable/menubar_button_disabled.9.png b/subsonic-android/res/drawable/menubar_button_disabled.9.png
new file mode 100644
index 00000000..94a48f7d
--- /dev/null
+++ b/subsonic-android/res/drawable/menubar_button_disabled.9.png
Binary files differ
diff --git a/subsonic-android/res/drawable/menubar_button_normal.9.png b/subsonic-android/res/drawable/menubar_button_normal.9.png
new file mode 100644
index 00000000..9ce38a61
--- /dev/null
+++ b/subsonic-android/res/drawable/menubar_button_normal.9.png
Binary files differ
diff --git a/subsonic-android/res/drawable/menubar_button_pressed.9.png b/subsonic-android/res/drawable/menubar_button_pressed.9.png
new file mode 100644
index 00000000..4dff0907
--- /dev/null
+++ b/subsonic-android/res/drawable/menubar_button_pressed.9.png
Binary files differ
diff --git a/subsonic-android/res/drawable/refresh.png b/subsonic-android/res/drawable/refresh.png
new file mode 100644
index 00000000..3838ba07
--- /dev/null
+++ b/subsonic-android/res/drawable/refresh.png
Binary files differ
diff --git a/subsonic-android/res/drawable/saved.png b/subsonic-android/res/drawable/saved.png
new file mode 100644
index 00000000..6c7c276f
--- /dev/null
+++ b/subsonic-android/res/drawable/saved.png
Binary files differ
diff --git a/subsonic-android/res/drawable/search.png b/subsonic-android/res/drawable/search.png
new file mode 100644
index 00000000..3f8913e2
--- /dev/null
+++ b/subsonic-android/res/drawable/search.png
Binary files differ
diff --git a/subsonic-android/res/drawable/select_album_play_all.xml b/subsonic-android/res/drawable/select_album_play_all.xml
new file mode 100644
index 00000000..7e6a81ac
--- /dev/null
+++ b/subsonic-android/res/drawable/select_album_play_all.xml
@@ -0,0 +1,5 @@
+<?xml version="1.0" encoding="utf-8"?>
+<selector xmlns:android="http://schemas.android.com/apk/res/android">
+ <item android:state_pressed="true" android:drawable="@drawable/select_album_play_all_pressed" />
+ <item android:drawable="@drawable/select_album_play_all_normal" />
+</selector> \ No newline at end of file
diff --git a/subsonic-android/res/drawable/select_album_play_all_normal.png b/subsonic-android/res/drawable/select_album_play_all_normal.png
new file mode 100644
index 00000000..1ec33286
--- /dev/null
+++ b/subsonic-android/res/drawable/select_album_play_all_normal.png
Binary files differ
diff --git a/subsonic-android/res/drawable/select_album_play_all_pressed.png b/subsonic-android/res/drawable/select_album_play_all_pressed.png
new file mode 100644
index 00000000..c3a18e77
--- /dev/null
+++ b/subsonic-android/res/drawable/select_album_play_all_pressed.png
Binary files differ
diff --git a/subsonic-android/res/drawable/select_artist_folder.png b/subsonic-android/res/drawable/select_artist_folder.png
new file mode 100644
index 00000000..5ae85406
--- /dev/null
+++ b/subsonic-android/res/drawable/select_artist_folder.png
Binary files differ
diff --git a/subsonic-android/res/drawable/slider_knob.png b/subsonic-android/res/drawable/slider_knob.png
new file mode 100644
index 00000000..ae21a4f9
--- /dev/null
+++ b/subsonic-android/res/drawable/slider_knob.png
Binary files differ
diff --git a/subsonic-android/res/drawable/stat_notify_playing.png b/subsonic-android/res/drawable/stat_notify_playing.png
new file mode 100644
index 00000000..fd92c188
--- /dev/null
+++ b/subsonic-android/res/drawable/stat_notify_playing.png
Binary files differ
diff --git a/subsonic-android/res/drawable/toast_frame.9.png b/subsonic-android/res/drawable/toast_frame.9.png
new file mode 100644
index 00000000..8f5d8119
--- /dev/null
+++ b/subsonic-android/res/drawable/toast_frame.9.png
Binary files differ
diff --git a/subsonic-android/res/drawable/unknown_album.png b/subsonic-android/res/drawable/unknown_album.png
new file mode 100644
index 00000000..c6e77088
--- /dev/null
+++ b/subsonic-android/res/drawable/unknown_album.png
Binary files differ
diff --git a/subsonic-android/res/drawable/unknown_album_large.png b/subsonic-android/res/drawable/unknown_album_large.png
new file mode 100644
index 00000000..50455c5d
--- /dev/null
+++ b/subsonic-android/res/drawable/unknown_album_large.png
Binary files differ
diff --git a/subsonic-android/res/layout-land/download.xml b/subsonic-android/res/layout-land/download.xml
new file mode 100644
index 00000000..79dcc650
--- /dev/null
+++ b/subsonic-android/res/layout-land/download.xml
@@ -0,0 +1,207 @@
+<?xml version="1.0" encoding="utf-8"?>
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+ android:orientation="vertical"
+ android:layout_width="fill_parent"
+ android:layout_height="fill_parent">
+
+ <RelativeLayout android:orientation="horizontal"
+ android:layout_width="fill_parent"
+ android:layout_height="0dip"
+ android:layout_weight="1">
+
+ <RelativeLayout
+ android:id="@+id/download_control_layout"
+ android:layout_width="wrap_content"
+ android:layout_height="fill_parent"
+ android:layout_alignParentRight="true"
+ android:background="@color/mediaControlBackground"
+ >
+
+ <LinearLayout
+ android:orientation="horizontal"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:layout_alignParentTop="true"
+ android:layout_alignParentLeft="true">
+
+ <ImageButton
+ android:id="@+id/download_previous"
+ android:src="@drawable/media_backward"
+ android:background="@android:color/transparent"
+ android:padding="0dip"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:layout_gravity="center_vertical"
+ />
+ <ImageButton
+ android:id="@+id/download_pause"
+ android:src="@drawable/media_pause"
+ android:background="@android:color/transparent"
+ android:padding="0dip"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:layout_gravity="center_vertical"
+ />
+ <ImageButton
+ android:id="@+id/download_stop"
+ android:src="@drawable/media_stop"
+ android:background="@android:color/transparent"
+ android:padding="0dip"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:layout_gravity="center_vertical"
+ />
+ <ImageButton
+ android:id="@+id/download_start"
+ android:src="@drawable/media_start"
+ android:background="@android:color/transparent"
+ android:padding="0dip"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:layout_gravity="center_vertical"
+ />
+ <ImageButton
+ android:id="@+id/download_next"
+ android:src="@drawable/media_forward"
+ android:background="@android:color/transparent"
+ android:padding="0dip"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:layout_gravity="center_vertical"
+ />
+ </LinearLayout>
+
+ <TextView
+ android:id="@+id/download_status"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:layout_alignParentBottom="true"
+ android:layout_centerHorizontal="true"
+ android:layout_marginBottom="8dip"
+ android:singleLine="true"
+ android:ellipsize="end"
+ android:textAppearance="?android:attr/textAppearanceSmall"
+ android:textColor="#c0c0c0"/>
+
+ <TextView
+ android:id="@+id/download_song_title"
+ android:layout_width="150dip"
+ android:layout_height="wrap_content"
+ android:layout_gravity="center_horizontal"
+ android:layout_above="@+id/download_status"
+ android:layout_centerHorizontal="true"
+ android:layout_marginLeft="12dip"
+ android:layout_marginRight="12dip"
+ android:maxLines="2"
+ android:ellipsize="end"
+ android:gravity="center_horizontal"
+ android:textAppearance="?android:attr/textAppearanceMedium"
+ android:textColor="@color/mediaControlForeground"/>
+
+ <LinearLayout
+ android:orientation="horizontal"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:layout_centerHorizontal="true"
+ android:layout_centerVertical="true">
+
+ <ImageButton
+ android:id="@+id/download_shuffle"
+ android:src="@drawable/media_shuffle"
+ android:background="@android:color/transparent"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:padding="9dip"/>
+ <ImageButton
+ android:id="@+id/download_repeat"
+ android:src="@drawable/media_repeat_off"
+ android:background="@android:color/transparent"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:padding="9dip"/>
+ <ImageButton
+ android:id="@+id/download_toggle_list"
+ android:src="@drawable/media_toggle_list"
+ android:background="@android:color/transparent"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:padding="9dip"/>
+ <Button
+ android:id="@+id/download_equalizer"
+ android:text="EQ"
+ android:textStyle="bold"
+ android:textSize="22sp"
+ android:visibility="gone"
+ android:background="@android:color/transparent"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:layout_marginTop="3dip"
+ android:padding="9dip"
+ />
+ <Button
+ android:id="@+id/download_jukebox"
+ android:text="RC"
+ android:textStyle="bold"
+ android:textSize="22sp"
+ android:background="@android:color/transparent"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:layout_marginTop="3dip"
+ android:padding="9dip"
+ />
+ <Button
+ android:id="@+id/download_visualizer"
+ android:text="VIS"
+ android:textStyle="bold"
+ android:textSize="22sp"
+ android:visibility="gone"
+ android:background="@android:color/transparent"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:layout_marginTop="3dip"
+ android:padding="9dip"
+ />
+ </LinearLayout>
+
+ </RelativeLayout>
+
+ <net.sourceforge.subsonic.androidapp.util.MyViewFlipper
+ android:id="@+id/download_playlist_flipper"
+ android:layout_width="wrap_content"
+ android:layout_height="fill_parent"
+ android:layout_alignParentLeft="true"
+ android:layout_toLeftOf="@+id/download_control_layout"
+ >
+
+ <FrameLayout
+ android:id="@+id/download_album_art_layout"
+ android:layout_width="fill_parent"
+ android:layout_height="fill_parent"
+ android:background="@drawable/album_art_background">
+ <ImageView
+ android:id="@+id/download_album_art_image"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:layout_gravity="center"
+ android:layout_marginTop="20dip"
+ android:scaleType="fitCenter"/>
+ <LinearLayout
+ android:id="@+id/download_visualizer_view_layout"
+ android:layout_width="fill_parent"
+ android:layout_height="60dip"
+ android:layout_marginLeft="60dip"
+ android:layout_marginRight="60dip"
+ android:layout_gravity="bottom|center_horizontal"/>
+ </FrameLayout>
+
+ <include layout="@layout/download_playlist"/>
+
+ </net.sourceforge.subsonic.androidapp.util.MyViewFlipper>
+
+ </RelativeLayout>
+
+ <include layout="@layout/download_slider"/>
+
+ <include layout="@layout/download_button_bar_flipper"/>
+
+</LinearLayout>
diff --git a/subsonic-android/res/layout-port/download.xml b/subsonic-android/res/layout-port/download.xml
new file mode 100644
index 00000000..73e94eb9
--- /dev/null
+++ b/subsonic-android/res/layout-port/download.xml
@@ -0,0 +1,198 @@
+<?xml version="1.0" encoding="utf-8"?>
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+ android:orientation="vertical"
+ android:layout_width="fill_parent"
+ android:layout_height="fill_parent">
+
+ <net.sourceforge.subsonic.androidapp.util.MyViewFlipper
+ android:id="@+id/download_playlist_flipper"
+ android:layout_width="fill_parent"
+ android:layout_height="0dip"
+ android:layout_weight="1">
+
+ <RelativeLayout
+ android:id="@+id/download_album_art_layout"
+ android:orientation="vertical"
+ android:layout_width="fill_parent"
+ android:layout_height="fill_parent"
+ android:layout_weight="1"
+ android:background="@drawable/album_art_background">
+
+ <ImageButton
+ android:id="@+id/download_repeat"
+ android:src="@drawable/media_repeat_off"
+ android:background="@android:color/transparent"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:layout_gravity="top|right"
+ android:paddingTop="24dip"
+ android:paddingLeft="8dip"
+ android:paddingBottom="12dip"/>
+
+ <Button
+ android:id="@+id/download_jukebox"
+ android:text="RC"
+ android:textStyle="bold"
+ android:textSize="22sp"
+ android:background="@android:color/transparent"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:layout_gravity="top|right"
+ android:layout_below="@+id/download_repeat"
+ android:paddingTop="12dip"
+ android:paddingLeft="14dip"
+ android:paddingBottom="15dip"/>
+
+ <Button
+ android:id="@+id/download_equalizer"
+ android:text="EQ"
+ android:textStyle="bold"
+ android:textSize="22sp"
+ android:background="@android:color/transparent"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:layout_gravity="top|right"
+ android:layout_alignParentRight="true"
+ android:paddingTop="24dip"
+ android:paddingRight="16dip"
+ android:paddingBottom="12dip"/>
+
+ <Button
+ android:id="@+id/download_visualizer"
+ android:text="VIS"
+ android:textStyle="bold"
+ android:textSize="22sp"
+ android:background="@android:color/transparent"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:layout_gravity="top|right"
+ android:layout_alignParentRight="true"
+ android:layout_below="@+id/download_equalizer"
+ android:layout_alignBottom="@+id/download_jukebox"
+ android:paddingTop="12dip"
+ android:paddingRight="12dip"
+ android:paddingBottom="12dip"/>
+
+ <ImageView
+ android:id="@+id/download_album_art_image"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:layout_centerHorizontal="true"
+ android:layout_alignParentTop="true"
+ android:layout_marginTop="24dip"
+ android:scaleType="fitCenter"/>
+
+ <TextView
+ android:id="@+id/download_status"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:layout_alignParentBottom="true"
+ android:layout_centerHorizontal="true"
+ android:singleLine="true"
+ android:ellipsize="end"
+ android:textAppearance="?android:attr/textAppearanceSmall"
+ android:textColor="#c0c0c0"/>
+
+ <TextView
+ android:id="@+id/download_song_title"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:layout_gravity="center_horizontal"
+ android:layout_above="@+id/download_status"
+ android:layout_centerHorizontal="true"
+ android:layout_marginLeft="16dip"
+ android:layout_marginRight="16dip"
+ android:singleLine="true"
+ android:textColor="@color/mediaControlForeground"
+ android:textStyle="bold"
+ android:textSize="18sp"
+ android:ellipsize="end"/>
+
+ <LinearLayout
+ android:id="@+id/download_visualizer_view_layout"
+ android:layout_width="fill_parent"
+ android:layout_height="60dip"
+ android:layout_marginLeft="80dip"
+ android:layout_marginRight="80dip"
+ android:layout_gravity="center_horizontal"
+ android:layout_above="@+id/download_song_title"/>
+
+ </RelativeLayout>
+
+ <include layout="@layout/download_playlist"/>
+
+ </net.sourceforge.subsonic.androidapp.util.MyViewFlipper>
+
+ <LinearLayout android:orientation="horizontal"
+ android:layout_width="fill_parent"
+ android:layout_height="wrap_content"
+ android:layout_marginTop="0dip"
+ android:background="@color/mediaControlBackground"
+ android:paddingTop="0dip"
+ android:paddingBottom="0dip">
+ <ImageButton
+ android:id="@+id/download_shuffle"
+ android:src="@drawable/media_shuffle"
+ android:background="@android:color/transparent"
+ android:layout_width="0dip"
+ android:layout_height="fill_parent"
+ android:layout_gravity="center_vertical|left"
+ android:layout_weight="1"
+ android:paddingLeft="4dip"/>
+ <ImageButton
+ android:id="@+id/download_previous"
+ android:src="@drawable/media_backward"
+ android:background="@android:color/transparent"
+ android:padding="0dip"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:layout_gravity="center_vertical"/>
+ <ImageButton
+ android:id="@+id/download_pause"
+ android:src="@drawable/media_pause"
+ android:background="@android:color/transparent"
+ android:padding="0dip"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:layout_gravity="center_vertical"/>
+ <ImageButton
+ android:id="@+id/download_stop"
+ android:src="@drawable/media_stop"
+ android:background="@android:color/transparent"
+ android:padding="0dip"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:layout_gravity="center_vertical"/>
+ <ImageButton
+ android:id="@+id/download_start"
+ android:src="@drawable/media_start"
+ android:background="@android:color/transparent"
+ android:padding="0dip"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:layout_gravity="center_vertical"/>
+ <ImageButton
+ android:id="@+id/download_next"
+ android:src="@drawable/media_forward"
+ android:background="@android:color/transparent"
+ android:padding="0dip"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:layout_gravity="center_vertical"/>
+ <ImageButton
+ android:id="@+id/download_toggle_list"
+ android:src="@drawable/media_toggle_list"
+ android:background="@android:color/transparent"
+ android:layout_width="0dip"
+ android:layout_height="fill_parent"
+ android:layout_gravity="center_vertical|right"
+ android:layout_weight="1"
+ android:paddingRight="4dip"/>
+ </LinearLayout>
+
+ <include layout="@layout/download_slider"/>
+
+ <include layout="@layout/download_button_bar_flipper"/>
+
+</LinearLayout>
+
diff --git a/subsonic-android/res/layout/action_bar.xml b/subsonic-android/res/layout/action_bar.xml
new file mode 100644
index 00000000..7439c0d8
--- /dev/null
+++ b/subsonic-android/res/layout/action_bar.xml
@@ -0,0 +1,71 @@
+<?xml version="1.0" encoding="utf-8"?>
+<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
+ android:layout_width="fill_parent"
+ android:layout_height="45dp"
+ android:background="@drawable/menubar_button_disabled">
+
+ <ImageView
+ android:id="@+id/actionbar_home_icon"
+ android:src="@drawable/main_header_icon"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:layout_gravity="center_vertical"
+ android:layout_alignParentTop="true"
+ android:layout_alignParentLeft="true"
+ android:layout_alignParentBottom="true"
+ android:paddingLeft="4dip"
+ android:paddingRight="4dip"
+ android:paddingTop="2dip"
+ android:paddingBottom="2dip"
+ android:scaleType="centerInside"
+ />
+
+ <ImageButton
+ android:id="@+id/action_button_2"
+ android:src="@drawable/action_search"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:layout_alignParentRight="true"
+ android:layout_alignParentTop="true"
+ android:layout_alignParentBottom="true"
+ android:scaleType="center"
+ android:padding="5dp"
+ android:background="@drawable/actionbar_button"
+ />
+
+ <ImageButton
+ android:id="@+id/action_button_1"
+ android:src="@drawable/action_shuffle"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:layout_alignParentTop="true"
+ android:layout_alignParentBottom="true"
+ android:layout_toLeftOf="@id/action_button_2"
+ android:scaleType="center"
+ android:padding="5dp"
+ android:background="@drawable/actionbar_button"
+ />
+
+ <TextView
+ android:id="@+id/actionbar_title_text"
+ android:text="Subsonic"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:layout_alignParentTop="true"
+ android:layout_alignParentBottom="true"
+ android:layout_toLeftOf="@id/action_button_1"
+ android:layout_toRightOf="@id/actionbar_home_icon"
+ android:gravity="center_vertical"
+ android:textColor="#FFFFFF"
+ android:textSize="18sp"
+ android:textStyle="bold"
+ android:shadowColor="#000000"
+ android:shadowDx="1"
+ android:shadowDy="1"
+ android:shadowRadius="1"
+ android:lineSpacingMultiplier="0.85"
+ android:ellipsize="middle"
+ android:inputType="none"
+ />
+
+</RelativeLayout>
diff --git a/subsonic-android/res/layout/album_list_item.xml b/subsonic-android/res/layout/album_list_item.xml
new file mode 100644
index 00000000..15d999c3
--- /dev/null
+++ b/subsonic-android/res/layout/album_list_item.xml
@@ -0,0 +1,47 @@
+<?xml version="1.0" encoding="utf-8"?>
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+ android:orientation="horizontal"
+ android:layout_width="fill_parent"
+ android:layout_height="?android:attr/listPreferredItemHeight">>
+
+ <ImageView
+ android:id="@+id/album_coverart"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:layout_gravity="left|center_vertical"
+ android:paddingLeft="6dip"/>
+
+ <LinearLayout
+ android:orientation="vertical"
+ android:layout_width="0dip"
+ android:layout_height="wrap_content"
+ android:layout_weight="1"
+ android:layout_gravity="left|center_vertical"
+ android:paddingLeft="6dip"
+ android:paddingRight="3dip">
+
+ <TextView
+ android:id="@+id/album_title"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:textAppearance="?android:attr/textAppearanceMedium"
+ android:singleLine="true"
+ android:ellipsize="marquee"/>
+
+ <TextView
+ android:id="@+id/album_artist"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:textAppearance="?android:attr/textAppearanceSmall"
+ android:singleLine="true"/>
+
+ </LinearLayout>
+
+ <ImageView
+ android:src="@drawable/list_item_artist"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:layout_gravity="right|center_vertical"
+ android:paddingRight="6dip"/>
+
+</LinearLayout>
diff --git a/subsonic-android/res/layout/appwidget.xml b/subsonic-android/res/layout/appwidget.xml
new file mode 100644
index 00000000..233bc93f
--- /dev/null
+++ b/subsonic-android/res/layout/appwidget.xml
@@ -0,0 +1,97 @@
+<?xml version="1.0" encoding="utf-8"?>
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+ android:layout_width="fill_parent"
+ android:layout_height="fill_parent"
+ android:orientation="horizontal"
+ android:background="@drawable/appwidget_bg">
+<ImageView
+ android:id="@+id/appwidget_coverart"
+ android:layout_height="fill_parent"
+ android:layout_width="81dip"
+ android:scaleType="fitXY"
+ android:src="@drawable/appwidget_art_default"
+ android:clickable="true"
+ android:focusable="true"
+ android:background="@drawable/appwidget_button_left"/>
+<ImageView
+ android:layout_width="2dip"
+ android:layout_height="fill_parent"
+ android:background="@drawable/appwidget_divider_vertical"/>
+<LinearLayout
+ android:id="@+id/appwidget_top"
+ android:layout_height="fill_parent"
+ android:layout_width="fill_parent"
+ android:orientation="vertical"
+ android:clickable="true"
+ android:focusable="true"
+ android:background="@drawable/appwidget_button_left">
+ <TextView
+ android:id="@+id/title"
+ android:layout_width="fill_parent"
+ android:layout_height="wrap_content"
+ android:minHeight="16sp"
+ android:textColor="@color/appwidget_text"
+ android:textStyle="bold"
+ android:textSize="16sp"
+ android:singleLine="true"
+ android:paddingLeft="5dip"
+ android:paddingRight="5dip"
+ android:fadingEdge="horizontal"
+ android:fadingEdgeLength="20dip"
+ android:ellipsize="none"/>
+ <TextView
+ android:id="@+id/artist"
+ android:layout_width="fill_parent"
+ android:layout_height="wrap_content"
+ android:textColor="@color/appwidget_text"
+ android:minHeight="12sp"
+ android:textSize="12sp"
+ android:singleLine="true"
+ android:paddingLeft="5dip"
+ android:paddingBottom="2dip"
+ android:fadingEdge="horizontal"
+ android:fadingEdgeLength="10dip"
+ android:ellipsize="none"/>
+ <ImageView
+ android:layout_width="fill_parent"
+ android:layout_height="2dip"
+ android:background="@drawable/appwidget_divider_horizontal"/>
+ <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+ android:layout_width="fill_parent"
+ android:layout_height="fill_parent"
+ android:orientation="horizontal">
+ <ImageButton
+ android:id="@+id/control_previous"
+ android:layout_width="0dip"
+ android:layout_weight="1"
+ android:layout_height="fill_parent"
+ android:src="@drawable/ic_appwidget_music_previous"
+ android:background="@drawable/appwidget_button_center"
+ android:scaleType="center"/>
+ <ImageView
+ android:layout_width="2dip"
+ android:layout_height="fill_parent"
+ android:background="@drawable/appwidget_divider_vertical"/>
+ <ImageButton
+ android:id="@+id/control_play"
+ android:layout_width="0dip"
+ android:layout_weight="1"
+ android:layout_height="fill_parent"
+ android:src="@drawable/ic_appwidget_music_play"
+ android:background="@drawable/appwidget_button_center"
+ android:scaleType="center"/>
+ <ImageView
+ android:layout_width="2dip"
+ android:layout_height="fill_parent"
+ android:background="@drawable/appwidget_divider_vertical"/>
+ <ImageButton
+ android:id="@+id/control_next"
+ android:layout_width="0dip"
+ android:layout_weight="1"
+ android:layout_height="fill_parent"
+ android:src="@drawable/ic_appwidget_music_next"
+ android:background="@drawable/appwidget_button_right"
+ android:scaleType="center"/>
+ </LinearLayout>
+ </LinearLayout>
+</LinearLayout>
diff --git a/subsonic-android/res/layout/artist_list_item.xml b/subsonic-android/res/layout/artist_list_item.xml
new file mode 100644
index 00000000..8aaa42d0
--- /dev/null
+++ b/subsonic-android/res/layout/artist_list_item.xml
@@ -0,0 +1,12 @@
+<?xml version="1.0" encoding="utf-8"?>
+<TextView xmlns:android="http://schemas.android.com/apk/res/android"
+ android:id="@android:id/text1"
+ android:drawableRight="@drawable/list_item_artist"
+ android:drawablePadding="6dip"
+ android:layout_width="fill_parent"
+ android:layout_height="wrap_content"
+ android:textAppearance="?android:attr/textAppearanceMedium"
+ android:gravity="center_vertical"
+ android:paddingLeft="6dip"
+ android:paddingRight="6dip"
+ android:minHeight="50dip"/> \ No newline at end of file
diff --git a/subsonic-android/res/layout/button_bar.xml b/subsonic-android/res/layout/button_bar.xml
new file mode 100644
index 00000000..59b18437
--- /dev/null
+++ b/subsonic-android/res/layout/button_bar.xml
@@ -0,0 +1,61 @@
+<?xml version="1.0" encoding="utf-8"?>
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+ android:id="@+id/button_bar"
+ android:orientation="vertical"
+ android:layout_gravity="bottom"
+ android:layout_width="fill_parent"
+ android:layout_height="wrap_content">
+
+ <View
+ android:layout_width="fill_parent"
+ android:layout_height="1px"
+ android:background="@color/dividerColor"/>
+
+ <LinearLayout android:orientation="horizontal"
+ android:layout_width="fill_parent"
+ android:layout_height="wrap_content"
+ android:gravity="center_horizontal">
+
+ <ImageButton android:id="@+id/button_bar_home"
+ android:src="@drawable/menu_home"
+ android:contentDescription="@string/button_bar.home"
+ android:background="@drawable/menubar_button"
+ android:layout_weight="1"
+ android:layout_width="0dp"
+ android:layout_height="wrap_content"/>
+
+ <ImageButton android:id="@+id/button_bar_music"
+ android:src="@drawable/menu_browse"
+ android:contentDescription="@string/button_bar.browse"
+ android:background="@drawable/menubar_button"
+ android:layout_weight="1"
+ android:layout_width="0dp"
+ android:layout_height="wrap_content"/>
+
+ <ImageButton android:id="@+id/button_bar_search"
+ android:src="@drawable/menu_search"
+ android:contentDescription="@string/button_bar.search"
+ android:background="@drawable/menubar_button"
+ android:layout_weight="1"
+ android:layout_width="0dp"
+ android:layout_height="wrap_content"/>
+
+ <ImageButton android:id="@+id/button_bar_playlists"
+ android:src="@drawable/menu_playlists"
+ android:contentDescription="@string/button_bar.playlists"
+ android:background="@drawable/menubar_button"
+ android:layout_weight="1"
+ android:layout_width="0dp"
+ android:layout_height="wrap_content"/>
+
+ <ImageButton android:id="@+id/button_bar_now_playing"
+ android:src="@drawable/menu_now_playing"
+ android:contentDescription="@string/button_bar.now_playing"
+ android:background="@drawable/menubar_button"
+ android:layout_weight="1"
+ android:layout_width="0dp"
+ android:layout_height="wrap_content"/>
+
+ </LinearLayout>
+</LinearLayout>
+
diff --git a/subsonic-android/res/layout/download_button_bar_flipper.xml b/subsonic-android/res/layout/download_button_bar_flipper.xml
new file mode 100644
index 00000000..216f5802
--- /dev/null
+++ b/subsonic-android/res/layout/download_button_bar_flipper.xml
@@ -0,0 +1,67 @@
+<?xml version="1.0" encoding="utf-8"?>
+<net.sourceforge.subsonic.androidapp.util.MyViewFlipper
+ xmlns:android="http://schemas.android.com/apk/res/android"
+ android:id="@+id/download_button_bar_flipper"
+ android:layout_width="fill_parent"
+ android:layout_height="wrap_content"
+ android:background="@android:color/black">
+
+ <RelativeLayout
+ android:layout_width="fill_parent"
+ android:layout_height="wrap_content"
+ android:background="@android:color/black"
+ android:paddingLeft="8dip"
+ android:paddingRight="8dip">
+
+ <TextView
+ android:id="@+id/download_position"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:layout_alignParentLeft="true"
+ android:layout_alignParentTop="true"
+ android:layout_marginRight="6dip"
+ android:text="0:00"
+ android:textAppearance="?android:attr/textAppearanceSmall"
+ android:textColor="@color/mediaControlForeground"/>
+ <TextView
+ android:id="@+id/download_duration"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:layout_alignParentRight="true"
+ android:layout_alignParentTop="true"
+ android:layout_marginLeft="6dip"
+ android:text="-:--"
+ android:textAppearance="?android:attr/textAppearanceSmall"
+ android:textColor="@color/mediaControlForeground"/>
+ <TextView
+ android:id="@+id/download_artist"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:layout_toRightOf="@+id/download_position"
+ android:layout_toLeftOf="@+id/download_duration"
+ android:layout_centerHorizontal="true"
+ android:layout_alignParentTop="true"
+ android:singleLine="true"
+ android:ellipsize="end"
+ android:gravity="center_horizontal"
+ android:textAppearance="?android:attr/textAppearanceSmall"
+ android:textColor="#c0c0c0"/>
+ <TextView
+ android:id="@+id/download_album"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:layout_centerHorizontal="true"
+ android:layout_below="@+id/download_artist"
+ android:singleLine="true"
+ android:ellipsize="end"
+ android:textAppearance="?android:attr/textAppearanceSmall"
+ android:textColor="#c0c0c0"/>
+ </RelativeLayout>
+
+ <include layout="@layout/button_bar"/>
+
+</net.sourceforge.subsonic.androidapp.util.MyViewFlipper>
+
+
+
+
diff --git a/subsonic-android/res/layout/download_playlist.xml b/subsonic-android/res/layout/download_playlist.xml
new file mode 100644
index 00000000..42daee00
--- /dev/null
+++ b/subsonic-android/res/layout/download_playlist.xml
@@ -0,0 +1,24 @@
+<?xml version="1.0" encoding="utf-8"?>
+
+<LinearLayout
+ xmlns:android="http://schemas.android.com/apk/res/android"
+ android:orientation="vertical"
+ android:layout_width="fill_parent"
+ android:layout_height="fill_parent"
+ android:layout_weight="1">
+
+ <TextView
+ android:id="@+id/download_empty"
+ android:text="@string/download.empty"
+ android:layout_width="fill_parent"
+ android:layout_height="wrap_content"
+ android:padding="10dip"/>
+
+ <ListView
+ android:id="@+id/download_list"
+ android:layout_width="fill_parent"
+ android:layout_height="fill_parent"
+ android:layout_weight="1"
+ android:cacheColorHint="#00000000"/>
+
+</LinearLayout> \ No newline at end of file
diff --git a/subsonic-android/res/layout/download_slider.xml b/subsonic-android/res/layout/download_slider.xml
new file mode 100644
index 00000000..a4c62ca2
--- /dev/null
+++ b/subsonic-android/res/layout/download_slider.xml
@@ -0,0 +1,13 @@
+<?xml version="1.0" encoding="utf-8"?>
+<net.sourceforge.subsonic.androidapp.util.HorizontalSlider
+ xmlns:android="http://schemas.android.com/apk/res/android"
+ style="?android:attr/progressBarStyleHorizontal"
+ android:id="@+id/download_progress_bar"
+ android:indeterminate="false"
+ android:background="@color/mediaControlBackground"
+ android:layout_width="fill_parent"
+ android:layout_height="wrap_content"
+ android:paddingLeft="7dip"
+ android:paddingRight="7dip"
+ android:paddingTop="3dip"
+ android:paddingBottom="7dip"/>
diff --git a/subsonic-android/res/layout/equalizer.xml b/subsonic-android/res/layout/equalizer.xml
new file mode 100644
index 00000000..ee1a9560
--- /dev/null
+++ b/subsonic-android/res/layout/equalizer.xml
@@ -0,0 +1,47 @@
+<?xml version="1.0" encoding="utf-8"?>
+<LinearLayout
+ xmlns:android="http://schemas.android.com/apk/res/android"
+ android:orientation="vertical"
+ android:layout_width="fill_parent"
+ android:layout_height="fill_parent"
+ android:background="@drawable/album_art_background"
+ android:padding="16dip">
+
+ <CheckBox
+ android:id="@+id/equalizer_enabled"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:text="@string/equalizer.enabled"
+ android:textColor="#c0c0c0"
+ android:textAppearance="?android:attr/textAppearanceMedium"/>
+
+ <ScrollView
+ android:layout_width="fill_parent"
+ android:layout_height="wrap_content">
+
+ <LinearLayout
+ android:orientation="vertical"
+ android:layout_width="fill_parent"
+ android:layout_height="wrap_content">
+
+ <LinearLayout
+ android:id="@+id/equalizer_layout"
+ android:orientation="vertical"
+ android:layout_width="fill_parent"
+ android:layout_height="wrap_content"/>
+
+ <Button
+ android:id="@+id/equalizer_preset"
+ android:text="@string/equalizer.preset"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:layout_gravity="center"
+ android:layout_marginTop="20dip"
+ android:paddingLeft="40dip"
+ android:paddingRight="40dip"/>
+
+ </LinearLayout>
+ </ScrollView>
+
+</LinearLayout>
+
diff --git a/subsonic-android/res/layout/equalizer_bar.xml b/subsonic-android/res/layout/equalizer_bar.xml
new file mode 100644
index 00000000..c34d1108
--- /dev/null
+++ b/subsonic-android/res/layout/equalizer_bar.xml
@@ -0,0 +1,39 @@
+<?xml version="1.0" encoding="utf-8"?>
+<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
+ android:orientation="vertical"
+ android:layout_width="fill_parent"
+ android:layout_height="wrap_content">
+
+ <TextView
+ android:id="@+id/equalizer.frequency"
+ android:textSize="12sp"
+ android:textColor="#c0c0c0"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:layout_marginTop="8dp"
+ android:layout_alignParentLeft="true"
+ />
+
+ <TextView
+ android:id="@+id/equalizer.level"
+ android:text="0 dB"
+ android:textSize="12sp"
+ android:textColor="#c0c0c0"
+ android:gravity="right"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:layout_marginTop="8dp"
+ android:layout_alignParentRight="true"
+ android:layout_toRightOf="@+id/equalizer.frequency"
+ />
+
+ <SeekBar
+ android:id="@+id/equalizer.bar"
+ android:layout_width="fill_parent"
+ android:layout_height="wrap_content"
+ android:layout_below="@+id/equalizer.frequency"
+ />
+
+
+</RelativeLayout>
+
diff --git a/subsonic-android/res/layout/help.xml b/subsonic-android/res/layout/help.xml
new file mode 100644
index 00000000..f22dee37
--- /dev/null
+++ b/subsonic-android/res/layout/help.xml
@@ -0,0 +1,42 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
+ android:layout_width="fill_parent"
+ android:layout_height="fill_parent">
+
+ <LinearLayout android:id="@+id/help_buttons"
+ android:layout_width="fill_parent"
+ android:layout_height="wrap_content"
+ android:layout_weight="0"
+ android:layout_alignParentBottom="true"
+ android:padding="4dip"
+ android:gravity="center_horizontal"
+ android:background="#ffcccccc">
+
+ <Button android:id="@+id/help_back"
+ android:text="@string/help.back"
+ android:layout_width="wrap_content"
+ android:layout_height="fill_parent"
+ android:layout_marginRight="5dip"
+ android:paddingLeft="25dip"
+ android:paddingRight="25dip"/>
+
+ <Button android:id="@+id/help_close"
+ android:text="@string/help.close"
+ android:layout_width="wrap_content"
+ android:layout_height="fill_parent"
+ android:layout_marginLeft="5dip"
+ android:paddingLeft="25dip"
+ android:paddingRight="25dip"/>
+ </LinearLayout>
+
+
+ <WebView
+ android:id="@+id/help_contents"
+ android:layout_width="fill_parent"
+ android:layout_height="wrap_content"
+ android:layout_above="@id/help_buttons"
+ android:layout_weight="1"
+ android:fadingEdge="vertical"
+ android:fadingEdgeLength="12dip"/>
+
+ </RelativeLayout>
diff --git a/subsonic-android/res/layout/jukebox_volume.xml b/subsonic-android/res/layout/jukebox_volume.xml
new file mode 100644
index 00000000..e124734b
--- /dev/null
+++ b/subsonic-android/res/layout/jukebox_volume.xml
@@ -0,0 +1,29 @@
+<?xml version="1.0" encoding="utf-8"?>
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+ android:id="@+id/toast_layout_root"
+ android:orientation="vertical"
+ android:layout_width="fill_parent"
+ android:layout_height="fill_parent"
+ android:background="@drawable/toast_frame">
+
+ <TextView
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:text="@string/download.jukebox_volume"
+ android:textAppearance="?android:attr/textAppearanceMedium"
+ android:textColor="#ffffffff"
+ android:shadowColor="#bb000000"
+ android:shadowRadius="2.75"
+ android:paddingLeft="32dp"
+ android:paddingRight="32dp"
+ android:paddingBottom="12dp"
+ />
+
+ <ProgressBar android:id="@+id/jukebox_volume_progress_bar"
+ style="@android:style/Widget.ProgressBar.Horizontal"
+ android:layout_width="fill_parent"
+ android:layout_height="wrap_content"
+ android:paddingBottom="3dp"
+ />
+
+</LinearLayout> \ No newline at end of file
diff --git a/subsonic-android/res/layout/lyrics.xml b/subsonic-android/res/layout/lyrics.xml
new file mode 100644
index 00000000..4307d8dd
--- /dev/null
+++ b/subsonic-android/res/layout/lyrics.xml
@@ -0,0 +1,57 @@
+<?xml version="1.0" encoding="utf-8"?>
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+ android:orientation="vertical"
+ android:layout_width="fill_parent"
+ android:layout_height="fill_parent">
+
+ <include layout="@layout/tab_progress"/>
+
+ <ScrollView
+ android:layout_width="fill_parent"
+ android:layout_height="0dip"
+ android:layout_weight="1.0">
+
+ <LinearLayout
+ android:orientation="vertical"
+ android:layout_width="fill_parent"
+ android:layout_height="fill_parent">
+ <TextView
+ android:id="@+id/lyrics_artist"
+ android:textAppearance="?android:attr/textAppearanceMedium"
+ android:gravity="center_horizontal"
+ android:layout_width="fill_parent"
+ android:layout_height="wrap_content"
+ android:paddingLeft="10dip"
+ android:paddingRight="10dip"
+ android:paddingTop="10dip"
+ android:paddingBottom="4dip"
+ />
+
+ <TextView
+ android:id="@+id/lyrics_title"
+ android:textAppearance="?android:attr/textAppearanceMedium"
+ android:gravity="center_horizontal"
+ android:layout_width="fill_parent"
+ android:layout_height="wrap_content"
+ android:paddingLeft="10dip"
+ android:paddingRight="10dip"
+ />
+
+ <TextView
+ android:id="@+id/lyrics_text"
+ android:textAppearance="?android:attr/textAppearanceSmall"
+ android:gravity="center_horizontal"
+ android:layout_width="fill_parent"
+ android:layout_height="wrap_content"
+ android:paddingLeft="10dip"
+ android:paddingRight="10dip"
+ />
+
+ </LinearLayout>
+
+ </ScrollView>
+
+ <include layout="@layout/button_bar"/>
+
+</LinearLayout>
+
diff --git a/subsonic-android/res/layout/main.xml b/subsonic-android/res/layout/main.xml
new file mode 100644
index 00000000..e151f319
--- /dev/null
+++ b/subsonic-android/res/layout/main.xml
@@ -0,0 +1,34 @@
+<?xml version="1.0" encoding="utf-8"?>
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+ android:orientation="vertical"
+ android:layout_width="fill_parent"
+ android:layout_height="fill_parent">
+
+ <include
+ layout="@layout/action_bar"
+ android:layout_width="fill_parent"
+ android:layout_height="45dp"
+ />
+
+ <View
+ android:layout_width="fill_parent"
+ android:layout_height="1px"
+ android:background="@color/dividerColor"/>
+
+ <ListView
+ android:id="@+id/main_list"
+ android:layout_width="fill_parent"
+ android:layout_height="0px"
+ android:layout_weight="1"/>
+
+ <View android:id="@+id/main_dummy"
+ android:layout_width="0px"
+ android:layout_height="0px"/>
+
+ <include
+ layout="@layout/button_bar"
+ android:layout_width="fill_parent"
+ android:layout_height="wrap_content"/>
+
+</LinearLayout>
+
diff --git a/subsonic-android/res/layout/main_buttons.xml b/subsonic-android/res/layout/main_buttons.xml
new file mode 100644
index 00000000..969ad99e
--- /dev/null
+++ b/subsonic-android/res/layout/main_buttons.xml
@@ -0,0 +1,119 @@
+<?xml version="1.0" encoding="utf-8"?>
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+ android:orientation="vertical"
+ android:layout_width="fill_parent"
+ android:layout_height="wrap_content">
+
+ <LinearLayout
+ android:id="@+id/main_select_server"
+ android:orientation="horizontal"
+ android:paddingTop="2dip"
+ android:paddingBottom="2dip"
+ android:paddingLeft="6dp"
+ android:layout_width="fill_parent"
+ android:layout_height="wrap_content"
+ android:minHeight="?android:attr/listPreferredItemHeight">
+
+ <ImageView
+ android:src="@drawable/main_select_server"
+ android:layout_gravity="center_vertical"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"/>
+
+ <LinearLayout
+ android:orientation="vertical"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content">
+
+ <TextView android:id="@+id/main.select_server_1"
+ android:text="@string/main.select_server"
+ android:layout_width="fill_parent"
+ android:layout_height="wrap_content"
+ android:layout_marginLeft="10dip"
+ android:layout_marginTop="6dip"
+ android:textAppearance="?android:attr/textAppearanceLarge"/>
+
+ <TextView android:id="@+id/main.select_server_2"
+ android:layout_width="fill_parent"
+ android:layout_height="wrap_content"
+ android:layout_marginLeft="10dip"
+ android:textAppearance="?android:attr/textAppearanceSmall"/>
+
+ </LinearLayout>
+ </LinearLayout>
+
+ <TextView
+ android:id="@+id/main_albums"
+ android:text="@string/main.albums_title"
+ android:layout_width="fill_parent"
+ android:layout_height="wrap_content"
+ android:textAppearance="?android:attr/textAppearanceSmall"
+ android:textColor="#EFEFEF"
+ android:textStyle="bold"
+ android:background="#A5A5A5"
+ android:gravity="center_vertical"
+ android:paddingLeft="4dp"/>
+
+ <TextView
+ android:id="@+id/main_albums_newest"
+ android:text="@string/main.albums_newest"
+ android:drawableRight="@drawable/list_item_artist"
+ android:drawablePadding="6dip"
+ android:layout_width="fill_parent"
+ android:layout_height="wrap_content"
+ android:textAppearance="?android:attr/textAppearanceMedium"
+ android:gravity="center_vertical"
+ android:paddingLeft="6dip"
+ android:paddingRight="6dip"
+ android:minHeight="50dip"/>
+ <TextView
+ android:id="@+id/main_albums_recent"
+ android:text="@string/main.albums_recent"
+ android:drawableRight="@drawable/list_item_artist"
+ android:drawablePadding="6dip"
+ android:layout_width="fill_parent"
+ android:layout_height="wrap_content"
+ android:textAppearance="?android:attr/textAppearanceMedium"
+ android:gravity="center_vertical"
+ android:paddingLeft="6dip"
+ android:paddingRight="6dip"
+ android:minHeight="50dip"/>
+ <TextView
+ android:id="@+id/main_albums_frequent"
+ android:text="@string/main.albums_frequent"
+ android:drawableRight="@drawable/list_item_artist"
+ android:drawablePadding="6dip"
+ android:layout_width="fill_parent"
+ android:layout_height="wrap_content"
+ android:textAppearance="?android:attr/textAppearanceMedium"
+ android:gravity="center_vertical"
+ android:paddingLeft="6dip"
+ android:paddingRight="6dip"
+ android:minHeight="50dip"/>
+ <TextView
+ android:id="@+id/main_albums_highest"
+ android:text="@string/main.albums_highest"
+ android:drawableRight="@drawable/list_item_artist"
+ android:drawablePadding="6dip"
+ android:layout_width="fill_parent"
+ android:layout_height="wrap_content"
+ android:textAppearance="?android:attr/textAppearanceMedium"
+ android:gravity="center_vertical"
+ android:paddingLeft="6dip"
+ android:paddingRight="6dip"
+ android:minHeight="50dip"/>
+ <TextView
+ android:id="@+id/main_albums_random"
+ android:text="@string/main.albums_random"
+ android:drawableRight="@drawable/list_item_artist"
+ android:drawablePadding="6dip"
+ android:layout_width="fill_parent"
+ android:layout_height="wrap_content"
+ android:textAppearance="?android:attr/textAppearanceMedium"
+ android:gravity="center_vertical"
+ android:paddingLeft="6dip"
+ android:paddingRight="6dip"
+ android:minHeight="50dip"/>
+
+</LinearLayout>
+
diff --git a/subsonic-android/res/layout/notification.xml b/subsonic-android/res/layout/notification.xml
new file mode 100644
index 00000000..c2edfb9b
--- /dev/null
+++ b/subsonic-android/res/layout/notification.xml
@@ -0,0 +1,31 @@
+<?xml version="1.0" encoding="utf-8"?>
+<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
+ android:layout_width="fill_parent"
+ android:layout_height="fill_parent"
+ android:padding="3dp">
+ <ImageView
+ android:id="@+id/notification_image"
+ android:layout_width="wrap_content"
+ android:layout_height="fill_parent"
+ android:layout_marginRight="10dp"
+ android:layout_marginLeft="5dp"/>
+ <TextView
+ android:id="@+id/notification_title"
+ android:layout_height="wrap_content"
+ android:layout_width="fill_parent"
+ android:textSize="16sp"
+ android:textStyle="bold"
+ android:textColor="@color/notificationTitle"
+ android:singleLine="true"
+ android:layout_toRightOf="@id/notification_image"
+ android:layout_alignParentTop="true"/>
+ <TextView
+ android:id="@+id/notification_artist"
+ android:layout_height="wrap_content"
+ android:layout_width="fill_parent"
+ android:textSize="15sp"
+ android:textColor="@color/notificationArtist"
+ android:singleLine="true"
+ android:layout_toRightOf="@id/notification_image"
+ android:layout_below="@id/notification_title"/>
+</RelativeLayout>
diff --git a/subsonic-android/res/layout/play_video.xml b/subsonic-android/res/layout/play_video.xml
new file mode 100644
index 00000000..6a9f3f74
--- /dev/null
+++ b/subsonic-android/res/layout/play_video.xml
@@ -0,0 +1,11 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
+ android:layout_width="fill_parent"
+ android:layout_height="fill_parent">
+
+ <WebView
+ android:id="@+id/play_video_contents"
+ android:layout_width="fill_parent"
+ android:layout_height="fill_parent"/>
+
+</FrameLayout>
diff --git a/subsonic-android/res/layout/playlist_list_item.xml b/subsonic-android/res/layout/playlist_list_item.xml
new file mode 100644
index 00000000..20706dc9
--- /dev/null
+++ b/subsonic-android/res/layout/playlist_list_item.xml
@@ -0,0 +1,12 @@
+<?xml version="1.0" encoding="utf-8"?>
+<TextView xmlns:android="http://schemas.android.com/apk/res/android"
+ android:id="@android:id/text1"
+ android:drawableRight="@drawable/list_item_playlist"
+ android:drawablePadding="6dip"
+ android:layout_width="fill_parent"
+ android:layout_height="wrap_content"
+ android:textAppearance="?android:attr/textAppearanceMedium"
+ android:gravity="center_vertical"
+ android:paddingLeft="6dip"
+ android:paddingRight="6dip"
+ android:minHeight="50dip"/> \ No newline at end of file
diff --git a/subsonic-android/res/layout/progress.xml b/subsonic-android/res/layout/progress.xml
new file mode 100644
index 00000000..4a693cb3
--- /dev/null
+++ b/subsonic-android/res/layout/progress.xml
@@ -0,0 +1,20 @@
+<?xml version="1.0" encoding="utf-8"?>
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+ android:orientation="horizontal"
+ android:layout_weight="1"
+ android:layout_width="0dip"
+ android:layout_height="fill_parent"
+ android:padding="10dp">
+
+ <ProgressBar
+ android:layout_width="wrap_content"
+ android:layout_height="fill_parent"
+ android:layout_marginRight="10dp"/>
+
+ <TextView
+ android:id="@+id/progress_message"
+ android:text="@string/progress.wait"
+ android:layout_width="wrap_content"
+ android:layout_height="fill_parent"/>
+
+</LinearLayout> \ No newline at end of file
diff --git a/subsonic-android/res/layout/save_playlist.xml b/subsonic-android/res/layout/save_playlist.xml
new file mode 100644
index 00000000..a0272f37
--- /dev/null
+++ b/subsonic-android/res/layout/save_playlist.xml
@@ -0,0 +1,17 @@
+<?xml version="1.0" encoding="utf-8"?>
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+ android:id="@+id/save_playlist_root"
+ android:padding="10dip"
+ android:orientation="vertical"
+ android:layout_width="fill_parent"
+ android:layout_height="fill_parent">
+
+ <EditText
+ android:id="@+id/save_playlist_name"
+ android:layout_width="fill_parent"
+ android:layout_height="wrap_content"
+ android:inputType="text"
+ android:singleLine="true"/>
+
+</LinearLayout>
+
diff --git a/subsonic-android/res/layout/search.xml b/subsonic-android/res/layout/search.xml
new file mode 100644
index 00000000..f65bcb36
--- /dev/null
+++ b/subsonic-android/res/layout/search.xml
@@ -0,0 +1,26 @@
+<?xml version="1.0" encoding="utf-8"?>
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+ android:orientation="vertical"
+ android:layout_width="fill_parent"
+ android:layout_height="fill_parent">
+
+ <include layout="@layout/action_bar"/>
+
+ <View
+ android:layout_width="fill_parent"
+ android:layout_height="1px"
+ android:background="@color/dividerColor"/>
+
+ <include layout="@layout/tab_progress"/>
+
+ <ListView
+ android:id="@+id/search_list"
+ android:layout_width="fill_parent"
+ android:layout_height="0dip"
+ android:layout_weight="1.0"
+ android:fastScrollEnabled="true"
+ />
+
+ <include layout="@layout/button_bar"/>
+
+</LinearLayout> \ No newline at end of file
diff --git a/subsonic-android/res/layout/search_buttons.xml b/subsonic-android/res/layout/search_buttons.xml
new file mode 100644
index 00000000..10b72166
--- /dev/null
+++ b/subsonic-android/res/layout/search_buttons.xml
@@ -0,0 +1,85 @@
+<?xml version="1.0" encoding="utf-8"?>
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+ android:orientation="vertical"
+ android:layout_width="fill_parent"
+ android:layout_height="wrap_content">
+
+ <TextView
+ android:id="@+id/search_search"
+ android:text="@string/search.search"
+ android:layout_width="fill_parent"
+ android:layout_height="wrap_content"
+ android:drawablePadding="0dp"
+ android:drawableLeft="@drawable/search"
+ android:textAppearance="?android:attr/textAppearanceMedium"
+ android:gravity="center"
+ android:padding="12dp"/>
+
+ <TextView
+ android:id="@+id/search_artists"
+ android:text="@string/search.artists"
+ android:layout_width="fill_parent"
+ android:layout_height="wrap_content"
+ android:textAppearance="?android:attr/textAppearanceSmall"
+ android:textColor="#EFEFEF"
+ android:textStyle="bold"
+ android:background="#A5A5A5"
+ android:gravity="center_vertical"
+ android:paddingLeft="4dp"/>
+
+ <TextView
+ android:id="@+id/search_albums"
+ android:text="@string/search.albums"
+ android:layout_width="fill_parent"
+ android:layout_height="wrap_content"
+ android:textAppearance="?android:attr/textAppearanceSmall"
+ android:textColor="#EFEFEF"
+ android:textStyle="bold"
+ android:background="#A5A5A5"
+ android:gravity="center_vertical"
+ android:paddingLeft="4dp"/>
+
+ <TextView
+ android:id="@+id/search_songs"
+ android:text="@string/search.songs"
+ android:layout_width="fill_parent"
+ android:layout_height="wrap_content"
+ android:textAppearance="?android:attr/textAppearanceSmall"
+ android:textColor="#EFEFEF"
+ android:textStyle="bold"
+ android:background="#A5A5A5"
+ android:gravity="center_vertical"
+ android:paddingLeft="4dp"/>
+
+ <TextView
+ android:id="@+id/search_more_artists"
+ android:text="@string/search.more"
+ android:layout_width="fill_parent"
+ android:layout_height="wrap_content"
+ android:textAppearance="?android:attr/textAppearanceSmall"
+ android:gravity="center"
+ android:paddingTop="8dp"
+ android:paddingBottom="8dp"/>
+
+ <TextView
+ android:id="@+id/search_more_albums"
+ android:text="@string/search.more"
+ android:layout_width="fill_parent"
+ android:layout_height="wrap_content"
+ android:textAppearance="?android:attr/textAppearanceSmall"
+ android:gravity="center"
+ android:paddingTop="8dp"
+ android:paddingBottom="8dp"/>
+
+ <TextView
+ android:id="@+id/search_more_songs"
+ android:text="@string/search.more"
+ android:layout_width="fill_parent"
+ android:layout_height="wrap_content"
+ android:textAppearance="?android:attr/textAppearanceSmall"
+ android:gravity="center"
+ android:paddingTop="8dp"
+ android:paddingBottom="8dp"/>
+
+</LinearLayout>
+
diff --git a/subsonic-android/res/layout/select_album.xml b/subsonic-android/res/layout/select_album.xml
new file mode 100644
index 00000000..54c4b74a
--- /dev/null
+++ b/subsonic-android/res/layout/select_album.xml
@@ -0,0 +1,73 @@
+<?xml version="1.0" encoding="utf-8"?>
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+ android:orientation="vertical"
+ android:layout_width="fill_parent"
+ android:layout_height="fill_parent">
+
+ <include layout="@layout/action_bar"/>
+
+ <View
+ android:layout_width="fill_parent"
+ android:layout_height="1px"
+ android:background="@color/dividerColor"/>
+
+ <include layout="@layout/tab_progress"/>
+
+ <TextView
+ android:id="@+id/select_album_empty"
+ android:text="@string/select_album.empty"
+ android:visibility="gone"
+ android:layout_width="fill_parent"
+ android:layout_height="wrap_content"
+ android:padding="10dip"/>
+
+ <ListView android:id="@+id/select_album_entries"
+ android:textFilterEnabled="true"
+ android:layout_width="fill_parent"
+ android:layout_height="0dip"
+ android:layout_weight="1.0"
+ android:fastScrollEnabled="true"
+ />
+
+ <LinearLayout android:orientation="horizontal"
+ android:layout_marginTop="6dp"
+ android:layout_marginBottom="3dp"
+ android:layout_width="fill_parent"
+ android:layout_height="wrap_content">
+
+ <Button android:id="@+id/select_album_select"
+ android:text="@string/select_album.select"
+ android:textAppearance="?android:attr/textAppearanceSmall"
+ android:visibility="gone"
+ android:layout_marginLeft="6dp"
+ android:layout_marginRight="3dp"
+ android:layout_weight="1"
+ android:layout_width="0dp"
+ android:layout_height="fill_parent"/>
+
+ <Button android:id="@+id/select_album_play_now"
+ android:text="@string/common.play_now"
+ android:textAppearance="?android:attr/textAppearanceSmall"
+ android:visibility="gone"
+ android:layout_marginLeft="3dp"
+ android:layout_marginRight="3dp"
+ android:layout_weight="1"
+ android:layout_width="0dp"
+ android:layout_height="fill_parent"/>
+
+ <Button android:id="@+id/select_album_play_last"
+ android:text="@string/common.play_last"
+ android:textAppearance="?android:attr/textAppearanceSmall"
+ android:visibility="gone"
+ android:layout_marginLeft="3dp"
+ android:layout_marginRight="6dp"
+ android:layout_weight="1"
+ android:layout_width="0dp"
+ android:layout_height="fill_parent"/>
+
+ </LinearLayout>
+
+ <include layout="@layout/button_bar"/>
+
+</LinearLayout>
+
diff --git a/subsonic-android/res/layout/select_album_footer.xml b/subsonic-android/res/layout/select_album_footer.xml
new file mode 100644
index 00000000..06727db4
--- /dev/null
+++ b/subsonic-android/res/layout/select_album_footer.xml
@@ -0,0 +1,48 @@
+<?xml version="1.0" encoding="utf-8"?>
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+ android:orientation="horizontal"
+ android:background="@android:color/transparent"
+ android:paddingTop="6dp"
+ android:paddingBottom="0dp"
+ android:layout_width="fill_parent"
+ android:layout_height="wrap_content">
+
+ <Button android:id="@+id/select_album_pin"
+ android:text="@string/common.pin"
+ android:textAppearance="?android:attr/textAppearanceSmall"
+ android:layout_marginLeft="6dp"
+ android:layout_marginRight="3dp"
+ android:layout_weight="1"
+ android:layout_width="0dp"
+ android:layout_height="fill_parent"/>
+
+ <Button android:id="@+id/select_album_unpin"
+ android:text="@string/common.unpin"
+ android:textAppearance="?android:attr/textAppearanceSmall"
+ android:layout_marginLeft="3dp"
+ android:layout_marginRight="3dp"
+ android:layout_weight="1"
+ android:layout_width="0dp"
+ android:layout_height="fill_parent"/>
+
+ <Button android:id="@+id/select_album_delete"
+ android:text="@string/common.delete"
+ android:textAppearance="?android:attr/textAppearanceSmall"
+ android:layout_marginLeft="3dp"
+ android:layout_marginRight="6dp"
+ android:layout_weight="1"
+ android:layout_width="0dp"
+ android:layout_height="fill_parent"/>
+
+ <Button android:id="@+id/select_album_more"
+ android:text="@string/select_album.more"
+ android:textAppearance="?android:attr/textAppearanceSmall"
+ android:visibility="gone"
+ android:layout_marginLeft="6dp"
+ android:layout_marginRight="6dp"
+ android:layout_weight="1"
+ android:layout_width="0dp"
+ android:layout_height="fill_parent"/>
+
+</LinearLayout>
+
diff --git a/subsonic-android/res/layout/select_album_header.xml b/subsonic-android/res/layout/select_album_header.xml
new file mode 100644
index 00000000..7f5fb767
--- /dev/null
+++ b/subsonic-android/res/layout/select_album_header.xml
@@ -0,0 +1,69 @@
+<?xml version="1.0" encoding="utf-8"?>
+
+<LinearLayout
+ xmlns:android="http://schemas.android.com/apk/res/android"
+ android:orientation="vertical"
+ android:layout_width="fill_parent"
+ android:layout_height="wrap_content">
+
+ <LinearLayout
+ android:orientation="horizontal"
+ android:background="@drawable/menubar_button_normal"
+ android:paddingTop="6dip"
+ android:paddingBottom="4dip"
+ android:paddingLeft="6dp"
+ android:paddingRight="6dp"
+ android:layout_weight="1"
+ android:layout_width="fill_parent"
+ android:layout_height="0dip">
+
+ <ImageView
+ android:id="@+id/select_album_cover_art"
+ android:layout_gravity="center_vertical"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"/>
+
+ <LinearLayout
+ android:orientation="vertical"
+ android:layout_weight="1"
+ android:layout_width="0dip"
+ android:layout_height="wrap_content">
+
+ <TextView
+ android:id="@+id/select_album_text1"
+ android:singleLine="true"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:layout_marginLeft="10dip"
+ android:layout_marginRight="10dip"
+ android:textColor="@android:color/primary_text_light"
+ android:textAppearance="?android:attr/textAppearanceMedium"/>
+
+ <TextView
+ android:id="@+id/select_album_text2"
+ android:singleLine="true"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:layout_marginLeft="10dip"
+ android:layout_marginRight="10dip"
+ android:textColor="@android:color/secondary_text_light"
+ android:textAppearance="?android:attr/textAppearanceSmall"/>
+
+ </LinearLayout>
+
+ <ImageButton
+ android:id="@+id/select_album_play_all"
+ android:src="@drawable/select_album_play_all"
+ android:background="@android:color/transparent"
+ android:layout_gravity="center_vertical"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"/>
+
+ </LinearLayout>
+
+ <View
+ android:layout_width="fill_parent"
+ android:layout_height="1px"
+ android:background="@color/dividerColor"/>
+
+</LinearLayout>
diff --git a/subsonic-android/res/layout/select_artist.xml b/subsonic-android/res/layout/select_artist.xml
new file mode 100644
index 00000000..7cf6fc77
--- /dev/null
+++ b/subsonic-android/res/layout/select_artist.xml
@@ -0,0 +1,26 @@
+<?xml version="1.0" encoding="utf-8"?>
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+ android:orientation="vertical"
+ android:layout_width="fill_parent"
+ android:layout_height="fill_parent">
+
+ <include layout="@layout/action_bar"/>
+
+ <View
+ android:layout_width="fill_parent"
+ android:layout_height="1px"
+ android:background="@color/dividerColor"/>
+
+ <include layout="@layout/tab_progress"/>
+
+ <ListView android:id="@+id/select_artist_list"
+ android:textFilterEnabled="true"
+ android:fastScrollEnabled="true"
+ android:layout_width="fill_parent"
+ android:layout_height="0dip"
+ android:layout_weight="1.0"/>
+
+ <include layout="@layout/button_bar"/>
+
+</LinearLayout>
+
diff --git a/subsonic-android/res/layout/select_artist_header.xml b/subsonic-android/res/layout/select_artist_header.xml
new file mode 100644
index 00000000..247eb806
--- /dev/null
+++ b/subsonic-android/res/layout/select_artist_header.xml
@@ -0,0 +1,38 @@
+<?xml version="1.0" encoding="utf-8"?>
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+ android:id="@+id/select_artist_folder"
+ android:orientation="horizontal"
+ android:paddingTop="2dip"
+ android:paddingBottom="2dip"
+ android:paddingLeft="6dp"
+ android:layout_width="fill_parent"
+ android:layout_height="wrap_content"
+ android:minHeight="?android:attr/listPreferredItemHeight">
+
+ <ImageView
+ android:src="@drawable/select_artist_folder"
+ android:layout_gravity="center_vertical"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"/>
+
+ <LinearLayout
+ android:orientation="vertical"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content">
+
+ <TextView android:id="@+id/select_artist_folder_1"
+ android:text="@string/select_artist.folder"
+ android:layout_width="fill_parent"
+ android:layout_height="wrap_content"
+ android:layout_marginLeft="10dip"
+ android:layout_marginTop="6dip"
+ android:textAppearance="?android:attr/textAppearanceLarge"/>
+
+ <TextView android:id="@+id/select_artist_folder_2"
+ android:layout_width="fill_parent"
+ android:layout_height="wrap_content"
+ android:layout_marginLeft="10dip"
+ android:textAppearance="?android:attr/textAppearanceSmall"/>
+
+ </LinearLayout>
+</LinearLayout> \ No newline at end of file
diff --git a/subsonic-android/res/layout/select_playlist.xml b/subsonic-android/res/layout/select_playlist.xml
new file mode 100644
index 00000000..c23e764b
--- /dev/null
+++ b/subsonic-android/res/layout/select_playlist.xml
@@ -0,0 +1,34 @@
+<?xml version="1.0" encoding="utf-8"?>
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+ android:orientation="vertical"
+ android:layout_width="fill_parent"
+ android:layout_height="fill_parent">
+
+ <include layout="@layout/action_bar"/>
+
+ <View
+ android:layout_width="fill_parent"
+ android:layout_height="1px"
+ android:background="@color/dividerColor"/>
+
+ <include layout="@layout/tab_progress"/>
+
+ <TextView
+ android:id="@+id/select_playlist_empty"
+ android:text="@string/select_playlist.empty"
+ android:layout_width="fill_parent"
+ android:layout_height="wrap_content"
+ android:padding="10dip"
+ android:visibility="gone"/>
+
+ <ListView android:id="@+id/select_playlist_list"
+ android:layout_width="fill_parent"
+ android:layout_height="0dip"
+ android:layout_weight="1.0"
+ android:fastScrollEnabled="true"
+ />
+
+ <include layout="@layout/button_bar"/>
+
+</LinearLayout>
+
diff --git a/subsonic-android/res/layout/song_list_item.xml b/subsonic-android/res/layout/song_list_item.xml
new file mode 100644
index 00000000..2163ef72
--- /dev/null
+++ b/subsonic-android/res/layout/song_list_item.xml
@@ -0,0 +1,76 @@
+<?xml version="1.0" encoding="utf-8"?>
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+ android:orientation="horizontal"
+ android:layout_width="fill_parent"
+ android:layout_height="?android:attr/listPreferredItemHeight">
+
+ <CheckedTextView
+ android:id="@+id/song_check"
+ android:layout_width="wrap_content"
+ android:layout_height="fill_parent"
+ android:gravity="center_vertical"
+ android:checkMark="?android:attr/textCheckMark"
+ android:paddingLeft="3dip"/>
+
+ <LinearLayout android:orientation="vertical"
+ android:layout_width="0dip"
+ android:layout_height="wrap_content"
+ android:layout_weight="1"
+ android:layout_gravity="center_vertical">
+
+ <LinearLayout android:orientation="horizontal"
+ android:layout_width="fill_parent"
+ android:layout_height="wrap_content"
+ android:layout_gravity="center_vertical">
+
+ <TextView
+ android:id="@+id/song_title"
+ android:layout_width="0dip"
+ android:layout_height="wrap_content"
+ android:layout_weight="1"
+ android:layout_gravity="left|center_vertical"
+ android:textAppearance="?android:attr/textAppearanceMedium"
+ android:singleLine="true"
+ android:ellipsize="marquee"
+ android:drawablePadding="6dip"
+ android:paddingLeft="6dip"
+ android:paddingRight="6dip"/>
+
+ <TextView
+ android:id="@+id/song_status"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:layout_gravity="right|center_vertical"
+ android:drawablePadding="1dip"
+ android:paddingRight="6dip"/>
+ </LinearLayout>
+
+ <LinearLayout android:orientation="horizontal"
+ android:layout_width="fill_parent"
+ android:layout_height="wrap_content"
+ android:layout_gravity="center_vertical">
+
+ <TextView
+ android:id="@+id/song_artist"
+ android:layout_width="0dip"
+ android:layout_height="wrap_content"
+ android:layout_weight="1"
+ android:layout_gravity="left|center_vertical"
+ android:textAppearance="?android:attr/textAppearanceSmall"
+ android:singleLine="true"
+ android:ellipsize="middle"
+ android:paddingLeft="6dip"/>
+
+ <TextView
+ android:id="@+id/song_duration"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:layout_gravity="right|center_vertical"
+ android:textAppearance="?android:attr/textAppearanceSmall"
+ android:singleLine="true"
+ android:paddingLeft="3dip"
+ android:paddingRight="9dip"/>
+
+ </LinearLayout>
+ </LinearLayout>
+</LinearLayout>
diff --git a/subsonic-android/res/layout/tab_progress.xml b/subsonic-android/res/layout/tab_progress.xml
new file mode 100644
index 00000000..6a88600c
--- /dev/null
+++ b/subsonic-android/res/layout/tab_progress.xml
@@ -0,0 +1,24 @@
+<?xml version="1.0" encoding="utf-8"?>
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+ android:id="@+id/tab_progress"
+ android:orientation="horizontal"
+ android:visibility="gone"
+ android:padding="10dp"
+ android:layout_gravity="top"
+ android:layout_width="fill_parent"
+ android:layout_height="wrap_content">
+
+ <ProgressBar
+ android:layout_width="16dp"
+ android:layout_height="16dp"
+ android:layout_gravity="center_vertical"
+ android:layout_marginRight="6dp"/>
+
+ <TextView
+ android:id="@+id/tab_progress_message"
+ android:text="@string/progress.wait"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:layout_gravity="center_vertical"/>
+
+</LinearLayout> \ No newline at end of file
diff --git a/subsonic-android/res/menu/main.xml b/subsonic-android/res/menu/main.xml
new file mode 100644
index 00000000..27698f81
--- /dev/null
+++ b/subsonic-android/res/menu/main.xml
@@ -0,0 +1,22 @@
+<?xml version="1.0" encoding="utf-8"?>
+<menu xmlns:android="http://schemas.android.com/apk/res/android">
+
+ <item
+ android:id="@+id/menu_exit"
+ android:icon="@drawable/ic_menu_exit"
+ android:title="@string/menu.exit"
+ />
+
+ <item
+ android:id="@+id/menu_settings"
+ android:icon="@drawable/ic_menu_settings"
+ android:title="@string/menu.settings"
+ />
+
+ <item
+ android:id="@+id/menu_help"
+ android:icon="@drawable/ic_menu_help"
+ android:title="@string/menu.help"
+ />
+
+</menu>
diff --git a/subsonic-android/res/menu/nowplaying.xml b/subsonic-android/res/menu/nowplaying.xml
new file mode 100644
index 00000000..28bcb5ef
--- /dev/null
+++ b/subsonic-android/res/menu/nowplaying.xml
@@ -0,0 +1,27 @@
+<?xml version="1.0" encoding="utf-8"?>
+<menu xmlns:android="http://schemas.android.com/apk/res/android">
+
+ <item
+ android:id="@+id/menu_shuffle"
+ android:icon="@drawable/ic_menu_shuffle"
+ android:title="@string/download.menu_shuffle"
+ />
+
+ <item
+ android:id="@+id/menu_save_playlist"
+ android:icon="@drawable/ic_menu_save"
+ android:title="@string/download.menu_save"
+ />
+
+ <item
+ android:id="@+id/menu_remove_all"
+ android:icon="@drawable/ic_menu_remove_all"
+ android:title="@string/download.menu_remove_all"
+ />
+
+ <item
+ android:id="@+id/menu_screen_on_off"
+ android:icon="@drawable/ic_menu_screen_on_off"
+ android:title="@string/download.menu_screen_on"
+ />
+</menu>
diff --git a/subsonic-android/res/menu/nowplaying_context.xml b/subsonic-android/res/menu/nowplaying_context.xml
new file mode 100644
index 00000000..16fb47d7
--- /dev/null
+++ b/subsonic-android/res/menu/nowplaying_context.xml
@@ -0,0 +1,34 @@
+<?xml version="1.0" encoding="utf-8"?>
+<menu xmlns:android="http://schemas.android.com/apk/res/android">
+
+ <item
+ android:id="@+id/menu_show_album"
+ android:title="@string/download.menu_show_album"
+ />
+
+ <item
+ android:id="@+id/menu_lyrics"
+ android:title="@string/download.menu_lyrics"
+ />
+
+ <item
+ android:id="@+id/menu_remove"
+ android:title="@string/download.menu_remove"
+ />
+
+ <item
+ android:id="@+id/menu_remove_all"
+ android:title="@string/download.menu_remove_all"
+ />
+
+ <item
+ android:id="@+id/menu_shuffle"
+ android:title="@string/download.menu_shuffle"
+ />
+
+ <item
+ android:id="@+id/menu_save_playlist"
+ android:title="@string/download.menu_save"
+ />
+
+</menu>
diff --git a/subsonic-android/res/menu/select_album_context.xml b/subsonic-android/res/menu/select_album_context.xml
new file mode 100644
index 00000000..299d4d01
--- /dev/null
+++ b/subsonic-android/res/menu/select_album_context.xml
@@ -0,0 +1,19 @@
+<?xml version="1.0" encoding="utf-8"?>
+<menu xmlns:android="http://schemas.android.com/apk/res/android">
+
+ <item
+ android:id="@+id/album_menu_play_now"
+ android:title="@string/common.play_now"
+ />
+
+ <item
+ android:id="@+id/album_menu_play_last"
+ android:title="@string/common.play_last"
+ />
+
+ <item
+ android:id="@+id/album_menu_pin"
+ android:title="@string/common.pin"
+ />
+
+</menu>
diff --git a/subsonic-android/res/menu/select_artist_context.xml b/subsonic-android/res/menu/select_artist_context.xml
new file mode 100644
index 00000000..fc4a45ba
--- /dev/null
+++ b/subsonic-android/res/menu/select_artist_context.xml
@@ -0,0 +1,19 @@
+<?xml version="1.0" encoding="utf-8"?>
+<menu xmlns:android="http://schemas.android.com/apk/res/android">
+
+ <item
+ android:id="@+id/artist_menu_play_now"
+ android:title="@string/common.play_now"
+ />
+
+ <item
+ android:id="@+id/artist_menu_play_last"
+ android:title="@string/common.play_last"
+ />
+
+ <item
+ android:id="@+id/artist_menu_pin"
+ android:title="@string/common.pin"
+ />
+
+</menu>
diff --git a/subsonic-android/res/menu/select_song_context.xml b/subsonic-android/res/menu/select_song_context.xml
new file mode 100644
index 00000000..c6393e77
--- /dev/null
+++ b/subsonic-android/res/menu/select_song_context.xml
@@ -0,0 +1,19 @@
+<?xml version="1.0" encoding="utf-8"?>
+<menu xmlns:android="http://schemas.android.com/apk/res/android">
+
+ <item
+ android:id="@+id/song_menu_play_now"
+ android:title="@string/common.play_now"
+ />
+
+ <item
+ android:id="@+id/song_menu_play_next"
+ android:title="@string/common.play_next"
+ />
+
+ <item
+ android:id="@+id/song_menu_play_last"
+ android:title="@string/common.play_last"
+ />
+
+</menu>
diff --git a/subsonic-android/res/values-fr/strings.xml b/subsonic-android/res/values-fr/strings.xml
new file mode 100644
index 00000000..a2e1f660
--- /dev/null
+++ b/subsonic-android/res/values-fr/strings.xml
@@ -0,0 +1,208 @@
+<?xml version="1.0" encoding="utf-8"?>
+<resources>
+
+ <string name="common.appname">Subsonic</string>
+ <string name="common.ok">OK</string>
+ <string name="common.save">Enregistrer</string>
+ <string name="common.cancel">Annuler</string>
+
+ <string name="main.welcome_title">Bienvenue!</string>
+ <string name="main.welcome_text">Bienvenue dans Subsonic! L\'application est configurée pour utiliser le serveur démo de Subsonic.
+ Après avoir configuré votre serveur personnel (disponible à partir de <b>subsonic.org</b>), veuillez accéder aux <b>Paramètres</b> et modifier la configuration pour vous y connecter.</string>
+ <string name="main.select_server">Sélectionner un serveur</string>
+ <string name="main.shuffle">Lecture aléatoire</string>
+ <string name="main.offline">Hors-ligne</string>
+ <string name="main.settings">Paramètres</string>
+ <string name="main.albums_title">Albums</string>
+ <string name="main.albums_newest">Plus récents</string>
+ <string name="main.albums_random">Aléatoire</string>
+ <string name="main.albums_highest">Mieux cotés</string>
+ <string name="main.albums_recent">Récemment joués</string>
+ <string name="main.albums_frequent">Fréquemment joués</string>
+
+ <!--<string name="menu.exit">TODO: Exit</string>-->
+ <!--<string name="menu.settings">TODO: Settings</string>-->
+ <!--<string name="menu.help">TODO: Help</string>-->
+
+ <string name="playlist.label">Playlists</string>
+
+ <string name="help.label">Aide</string>
+ <string name="help.title">Bienvenue dans Subsonic!</string>
+ <string name="help.back">Retour</string>
+ <string name="help.close">Fermer</string>
+ <string name="help.url">file:///android_asset/html/fr/index.html</string>
+ <string name="help.loading">Chargement...</string>
+
+ <string name="play_video.loading">Chargement de la vidéo...</string>
+ <string name="play_video.noplugin">Veuillez installer Adobe Flash Player à partir du marché Android.</string>
+
+ <string name="search.label">Recherche</string>
+ <string name="search.title">Recherche</string>
+ <string name="search.search">Cliquer pour rechercher</string>
+ <string name="search.no_match">Aucun résultat, veuillez essayer à nouveau</string>
+ <string name="search.artists">Artistes</string>
+ <string name="search.albums">Albums</string>
+ <string name="search.songs">Pièces</string>
+ <string name="search.more">Afficher plus</string>
+
+ <string name="progress.wait">Veuillez patienter...</string>
+
+ <string name="music_library.label">Bibliothèque musicale</string>
+ <string name="music_library.label_offline">Musique hors-ligne</string>
+
+ <string name="select_album.empty">Aucune musique trouvée</string>
+ <string name="select_album.select">Tout sélectionner</string>
+ <!--<string name="select_album.n_selected">TODO: %d tracks selected.</string>-->
+ <!--<string name="select_album.n_unselected">TODO: %d tracks unselected.</string>-->
+ <string name="select_album.more">Plus</string>
+ <string name="select_album.offline">Hors-ligne</string>
+ <string name="select_album.searching">Recherche en cours...</string>
+ <string name="select_album.no_sdcard">Erreur: Aucune carte SD disponible.</string>
+ <string name="select_album.no_network">Avis: Aucun réseau disponible.</string>
+ <string name="select_album.not_licensed">Serveur sans licence. %d jours d\'essai restant.</string>
+ <string name="select_album.donate_dialog_message">Obtenez des téléchargements illimités en donnant à Subsonic.</string>
+ <string name="select_album.donate_dialog_now">Maintenant</string>
+ <string name="select_album.donate_dialog_later">Plus tard</string>
+ <string name="select_album.donate_dialog_0_trial_days_left">La période d\'essai est terminée</string>
+
+ <string name="select_playlist.empty">Aucune playlist sur le serveur</string>
+
+ <string name="download.empty">Playlist vide</string>
+ <string name="download.playerstate_downloading">Téléchargement - %s</string>
+ <string name="download.playerstate_buffering">Mise en tampon</string>
+ <string name="download.playerstate_playing_shuffle">En jeu aléatoire</string>
+ <string name="download.menu_show_album">Afficher l\'album</string>
+ <string name="download.menu_lyrics">Paroles</string>
+ <string name="download.menu_remove">Retirer la pièce</string>
+ <string name="download.menu_remove_all">Retirer tout</string>
+ <string name="download.menu_shuffle">Mélanger</string>
+ <string name="download.menu_save">Enregistrer la playlist</string>
+ <string name="download.menu_shuffle_notification">Playlist mélangée</string>
+ <string name="download.playlist_title">Enregistrer la playlist</string>
+ <string name="download.playlist_name">Saisissez le nom de la playlist:</string>
+ <string name="download.playlist_saving">Enregistrement de la playlist \"%s\"...</string>
+ <string name="download.playlist_done">Playlist enregistrée avec succès.</string>
+ <string name="download.playlist_error">Échec de l\'enregistrement de la playlist, veuillez réessayer plus tard.</string>
+
+ <string name="song_details.all">%2$s, %1$s</string>
+ <string name="song_details.kbps">%d Kb/s</string>
+
+ <string name="lyrics.nomatch">Aucune parole trouvée</string>
+
+ <string name="error.label">Erreur</string>
+
+ <string name="settings.title">Paramètres de Subsonic</string>
+ <string name="settings.test_connection_title">Tester la connexion</string>
+ <string name="settings.servers_title">Serveurs</string>
+ <string name="settings.server_unused1">Inutilisé 1</string>
+ <string name="settings.server_unused2">Inutilisé 2</string>
+ <string name="settings.server_name">Nom</string>
+ <string name="settings.server_address">Adresse du serveur</string>
+ <string name="settings.server_username">Nom d\'usager</string>
+ <string name="settings.server_password">Mot de passe</string>
+ <string name="settings.cache_title">Cache musicale</string>
+ <string name="settings.preload">Pièces à pré-charger</string>
+ <string name="settings.cache_size">Taille de la cache</string>
+ <string name="settings.testing_connection">Connexion en cours de test...</string>
+ <string name="settings.testing_ok">Connexion correcte</string>
+ <string name="settings.testing_unlicensed">Connection correcte. Serveur sans licence.</string>
+ <string name="settings.connection_failure">Connection échouée.</string>
+ <string name="settings.invalid_url">Veuillez spécifier un URL valide.</string>
+ <string name="settings.invalid_username">Veuillez spécifier un nom d\'usager valide (sans espace à la fin).</string>
+ <string name="settings.appearance_title">Apparence</string>
+ <string name="settings.theme_title">Thème</string>
+ <string name="settings.theme_wheat">Blé</string>
+ <string name="settings.theme_light">Clair</string>
+ <string name="settings.theme_dark">Sombre</string>
+ <string name="settings.network_title">Réseau</string>
+ <string name="settings.max_bitrate_wifi">Débit maximal - Wi-Fi</string>
+ <string name="settings.max_bitrate_mobile">Débit maximal - Mobile</string>
+ <string name="settings.max_bitrate_32">32 Kb/s</string>
+ <string name="settings.max_bitrate_64">64 Kb/s</string>
+ <string name="settings.max_bitrate_80">80 Kb/s</string>
+ <string name="settings.max_bitrate_96">96 Kb/s</string>
+ <string name="settings.max_bitrate_112">112 Kb/s</string>
+ <string name="settings.max_bitrate_128">128 Kb/s</string>
+ <string name="settings.max_bitrate_160">160 Kb/s</string>
+ <string name="settings.max_bitrate_192">192 Kb/s</string>
+ <string name="settings.max_bitrate_256">256 Kb/s</string>
+ <string name="settings.max_bitrate_320">320 Kb/s</string>
+ <string name="settings.max_bitrate_unlimited">Illimité</string>
+ <string name="settings.preload_1">1 pièce</string>
+ <string name="settings.preload_2">2 pièces</string>
+ <string name="settings.preload_3">3 pièces</string>
+ <string name="settings.preload_5">5 pièces</string>
+ <string name="settings.preload_10">10 pièces</string>
+ <string name="settings.preload_unlimited">Illimité</string>
+ <string name="settings.cache_size_100">100 Mo</string>
+ <string name="settings.cache_size_200">200 Mo</string>
+ <string name="settings.cache_size_500">500 Mo</string>
+ <string name="settings.cache_size_1000">1 Go</string>
+ <string name="settings.cache_size_2000">2 Go</string>
+ <string name="settings.cache_size_5000">5 Go</string>
+ <string name="settings.cache_size_10000">10 Go</string>
+ <string name="settings.cache_size_20000">20 Go</string>
+ <string name="settings.cache_size_unlimited">Illimité</string>
+ <string name="settings.clear_search_history">Effacer l\'historique des recherches</string>
+ <string name="settings.search_history_cleared">Historique des recherches effacé</string>
+ <string name="settings.other_title">Autres paramètres</string>
+ <!--<string name="settings.scrobble_title">TODO: Scrobble to Last.fm</string>-->
+ <!--<string name="settings.scrobble_summary">TODO: Remember to set up your Last.fm user and password on the Subsonic server</string>-->
+ <string name="settings.hide_media_title">Masquer aux autres</string>
+ <string name="settings.hide_media_summary">Masquer les fichiers musicaux et les couvertures d\'album aux autres applis (Gallerie, Musique, etc.)</string>
+ <string name="settings.hide_media_toast">Prendra effet la prochaine fois qu\'Android recensera les médias disponibles sur l\'appareil.</string>
+ <string name="settings.media_button_title">Boutons média</string>
+ <string name="settings.media_button_summary">Répondre au boutons média de l\'appareil, du casque et du Bluetooth</string>
+ <!--<string name="settings.screen_lit_title">TODO: Keep screen on</string>-->
+ <!--<string name="settings.screen_lit_summary">TODO: Keeping the screen on when downloading may improve download speed</string>-->
+
+ <string name="music_service.retry">Une erreur de réseau s\'est produite. Essai %1$d de %2$d.</string>
+
+ <string name="background_task.wait">Veuillez patienter...</string>
+ <string name="background_task.loading">Chargement.</string>
+ <string name="background_task.no_network">Cette application requiert un accès au réseau. Veuillez activer le Wi-Fi ou le réseau mobile.</string>
+ <string name="background_task.network_error">Une erreur réseau est survenue. Veuillez vérifier l\'adresse du serveur ou réessayer plus tard.</string>
+ <string name="background_task.not_found">Ressource non trouvée. Veuillez vérifier l\'adresse du serveur.</string>
+ <string name="background_task.parse_error">Réplique incomprise. Veuillez vérifier l\'adresse du serveur.</string>
+
+ <string name="service.connecting">Contact du serveur, veuillez patienter.</string>
+
+ <string name="parser.reading">Lecture du serveur.</string>
+ <string name="parser.reading_done">Lecture du serveur. Terminé!</string>
+ <string name="parser.upgrade_client">Versions incompatible. Veuillez mette à jour l\'application Android Subsonic.</string>
+ <string name="parser.upgrade_server">Versions incompatible. Veuillez mette à jour le serveur Subsonic.</string>
+ <string name="parser.not_authenticated">Mauvais nom d\'usager ou mot de passe.</string>
+ <string name="parser.artist_count">%d artistes récupérés.</string>
+
+ <string name="select_artist.refresh">Rafraîchir</string>
+ <string name="select_artist.folder">Sélectionner le dossier</string>
+ <string name="select_artist.all_folders">Tous les dossiers</string>
+
+ <string name="widget.initial_text">Touchez pour sélectionner une pièce</string>
+ <string name="widget.sdcard_busy">Carte SD non disponible</string>
+ <string name="widget.sdcard_missing">Aucune carte SD</string>
+
+ <string name="util.bytes_format.gigabyte">0.00 Go</string>
+ <string name="util.bytes_format.megabyte">0.00 Mo</string>
+ <string name="util.bytes_format.kilobyte">0 Ko</string>
+ <string name="util.bytes_format.byte">0 o</string>
+
+ <plurals name="select_album_n_songs">
+ <item quantity="zero">Aucune pièce</item>
+ <item quantity="one">Une pièce</item>
+ <item quantity="other">%d pièces</item>
+ </plurals>
+ <plurals name="select_album_n_songs_downloading">
+ <item quantity="one">Une pièce prévue pour téléchargement.</item>
+ <item quantity="other">%d pièces prévues pour téléchargement.</item>
+ </plurals>
+ <plurals name="select_album_n_songs_added">
+ <item quantity="one">Une pièce ajoutée à la file de lecture.</item>
+ <item quantity="other">%d pièces ajoutées à la file de lecture.</item>
+ </plurals>
+ <plurals name="select_album_donate_dialog_n_trial_days_left">
+ <item quantity="one">Un jour restant à la période d\'essai</item>
+ <item quantity="other">%d jours restant à la période d\'essai</item>
+ </plurals>
+
+</resources>
diff --git a/subsonic-android/res/values-v11/colors.xml b/subsonic-android/res/values-v11/colors.xml
new file mode 100644
index 00000000..f5a422bb
--- /dev/null
+++ b/subsonic-android/res/values-v11/colors.xml
@@ -0,0 +1,5 @@
+<?xml version="1.0" encoding="utf-8"?>
+<resources>
+ <color name="notificationArtist">#bababa</color>
+ <color name="notificationTitle">#dddddd</color>
+</resources>
diff --git a/subsonic-android/res/values/arrays.xml b/subsonic-android/res/values/arrays.xml
new file mode 100644
index 00000000..0338997a
--- /dev/null
+++ b/subsonic-android/res/values/arrays.xml
@@ -0,0 +1,86 @@
+<?xml version="1.0" encoding="utf-8"?>
+<resources>
+
+ <string-array name="themeValues">
+ <item>wheat</item>
+ <item>light</item>
+ <item>dark</item>
+ </string-array>
+
+ <string-array name="themeNames">
+ <item>@string/settings.theme_wheat</item>
+ <item>@string/settings.theme_light</item>
+ <item>@string/settings.theme_dark</item>
+ </string-array>
+
+ <string-array name="preloadCountValues">
+ <item>1</item>
+ <item>2</item>
+ <item>3</item>
+ <item>5</item>
+ <item>10</item>
+ <item>-1</item>
+ </string-array>
+
+ <string-array name="preloadCountNames">
+ <item>@string/settings.preload_1</item>
+ <item>@string/settings.preload_2</item>
+ <item>@string/settings.preload_3</item>
+ <item>@string/settings.preload_5</item>
+ <item>@string/settings.preload_10</item>
+ <item>@string/settings.preload_unlimited</item>
+ </string-array>
+
+ <string-array name="cacheSizeValues">
+ <item>100</item>
+ <item>200</item>
+ <item>500</item>
+ <item>1000</item>
+ <item>2000</item>
+ <item>5000</item>
+ <item>10000</item>
+ <item>20000</item>
+ <item>-1</item>
+ </string-array>
+
+ <string-array name="cacheSizeNames">
+ <item>@string/settings.cache_size_100</item>
+ <item>@string/settings.cache_size_200</item>
+ <item>@string/settings.cache_size_500</item>
+ <item>@string/settings.cache_size_1000</item>
+ <item>@string/settings.cache_size_2000</item>
+ <item>@string/settings.cache_size_5000</item>
+ <item>@string/settings.cache_size_10000</item>
+ <item>@string/settings.cache_size_20000</item>
+ <item>@string/settings.cache_size_unlimited</item>
+ </string-array>
+
+ <string-array name="maxBitrateValues">
+ <item>32</item>
+ <item>64</item>
+ <item>80</item>
+ <item>96</item>
+ <item>112</item>
+ <item>128</item>
+ <item>160</item>
+ <item>192</item>
+ <item>256</item>
+ <item>320</item>
+ <item>0</item>
+ </string-array>
+
+ <string-array name="maxBitrateNames">
+ <item>@string/settings.max_bitrate_32</item>
+ <item>@string/settings.max_bitrate_64</item>
+ <item>@string/settings.max_bitrate_80</item>
+ <item>@string/settings.max_bitrate_96</item>
+ <item>@string/settings.max_bitrate_112</item>
+ <item>@string/settings.max_bitrate_128</item>
+ <item>@string/settings.max_bitrate_160</item>
+ <item>@string/settings.max_bitrate_192</item>
+ <item>@string/settings.max_bitrate_256</item>
+ <item>@string/settings.max_bitrate_320</item>
+ <item>@string/settings.max_bitrate_unlimited</item>
+ </string-array>
+
+</resources> \ No newline at end of file
diff --git a/subsonic-android/res/values/colors.xml b/subsonic-android/res/values/colors.xml
new file mode 100644
index 00000000..67bb3933
--- /dev/null
+++ b/subsonic-android/res/values/colors.xml
@@ -0,0 +1,13 @@
+<?xml version="1.0" encoding="utf-8"?>
+<resources>
+ <color name="mediaControlBackground">#000000</color>
+ <color name="mediaControlForeground">#F0F0F0</color>
+ <color name="dividerColor">#555555</color>
+ <color name="appwidget_text">#FFFFFF</color>
+ <color name="notificationArtist">#434343</color>
+ <color name="notificationTitle">#000000</color>
+
+ <color name="wheatBackground">#F1F0E6</color>
+ <color name="wheatForeground1">#494B26</color>
+ <color name="wheatForeground2">#830009</color>
+</resources> \ No newline at end of file
diff --git a/subsonic-android/res/values/strings.xml b/subsonic-android/res/values/strings.xml
new file mode 100644
index 00000000..c6a372c3
--- /dev/null
+++ b/subsonic-android/res/values/strings.xml
@@ -0,0 +1,242 @@
+<?xml version="1.0" encoding="utf-8"?>
+<resources>
+
+ <string name="common.appname">Subsonic</string>
+ <string name="common.ok">OK</string>
+ <string name="common.save">Save</string>
+ <string name="common.cancel">Cancel</string>
+ <string name="common.play_now">Play now</string>
+ <string name="common.play_next">Play next</string>
+ <string name="common.play_last">Play last</string>
+ <string name="common.pin">Pin</string>
+ <string name="common.unpin">Unpin</string>
+ <string name="common.delete">Delete</string>
+
+ <string name="button_bar.home">Subsonic home</string>
+ <string name="button_bar.browse">Media library</string>
+ <string name="button_bar.search">Search</string>
+ <string name="button_bar.playlists">Playlists</string>
+ <string name="button_bar.now_playing">Now playing</string>
+
+ <string name="main.welcome_title">Welcome!</string>
+ <string name="main.welcome_text">Welcome to Subsonic! The app is currently configured to use the Subsonic demo server. After you\'ve
+ set up your personal server (available from <b>subsonic.org</b>), please go to <b>Settings</b> and change the configuration to connect to it.</string>
+ <string name="main.select_server">Select server</string>
+ <string name="main.shuffle">Shuffle play</string>
+ <string name="main.offline">Offline</string>
+ <string name="main.settings">Settings</string>
+ <string name="main.albums_title">Albums</string>
+ <string name="main.albums_newest">Recently added</string>
+ <string name="main.albums_recent">Recently played</string>
+ <string name="main.albums_frequent">Most played</string>
+ <string name="main.albums_highest">Top rated</string>
+ <string name="main.albums_random">Random</string>
+
+ <string name="menu.exit">Exit</string>
+ <string name="menu.settings">Settings</string>
+ <string name="menu.help">Help</string>
+
+ <string name="playlist.label">Playlists</string>
+
+ <string name="help.label">Help</string>
+ <string name="help.title">Welcome to Subsonic!</string>
+ <string name="help.back">Back</string>
+ <string name="help.close">Close</string>
+ <string name="help.url">file:///android_asset/html/en/index.html</string>
+ <string name="help.loading">Loading...</string>
+
+ <string name="play_video.loading">Loading video...</string>
+ <string name="play_video.noplugin">Please install Adobe Flash Player from Android Market.</string>
+
+ <string name="search.label">Search</string>
+ <string name="search.title">Search</string>
+ <string name="search.search">Click to search</string>
+ <string name="search.no_match">No matches, please try again</string>
+ <string name="search.artists">Artists</string>
+ <string name="search.albums">Albums</string>
+ <string name="search.songs">Songs</string>
+ <string name="search.more">Show more</string>
+
+ <string name="progress.wait">Please wait...</string>
+
+ <string name="music_library.label">Media library</string>
+ <string name="music_library.label_offline">Offline media</string>
+
+ <string name="select_album.empty">No media found</string>
+ <string name="select_album.select">Select all</string>
+ <string name="select_album.n_selected">%d tracks selected.</string>
+ <string name="select_album.n_unselected">%d tracks unselected.</string>
+ <string name="select_album.more">More</string>
+ <string name="select_album.offline">Offline</string>
+ <string name="select_album.searching">Searching...</string>
+ <string name="select_album.no_sdcard">Error: No SD card available.</string>
+ <string name="select_album.no_network">Warning: No network available.</string>
+ <string name="select_album.not_licensed">Server not licensed. %d trial days left.</string>
+ <string name="select_album.donate_dialog_message">Get unlimited downloads by donating to Subsonic.</string>
+ <string name="select_album.donate_dialog_now">Now</string>
+ <string name="select_album.donate_dialog_later">Later</string>
+ <string name="select_album.donate_dialog_0_trial_days_left">Trial period is over</string>
+
+ <string name="select_playlist.empty">No saved playlists on server</string>
+
+ <string name="download.empty">Playlist is empty</string>
+ <string name="download.playerstate_downloading">Downloading - %s</string>
+ <string name="download.playerstate_buffering">Buffering</string>
+ <string name="download.playerstate_playing_shuffle">Playing shuffle</string>
+ <string name="download.menu_show_album">Show album</string>
+ <string name="download.menu_lyrics">Lyrics</string>
+ <string name="download.menu_remove">Remove song</string>
+ <string name="download.menu_remove_all">Remove all</string>
+ <string name="download.menu_screen_on">Screen on</string>
+ <string name="download.menu_screen_off">Screen off</string>
+ <string name="download.menu_shuffle">Shuffle</string>
+ <string name="download.menu_save">Save playlist</string>
+ <string name="download.menu_shuffle_notification">Playlist was shuffled</string>
+ <string name="download.playlist_title">Save playlist</string>
+ <string name="download.playlist_name">Enter the playlist name:</string>
+ <string name="download.playlist_saving">Saving playlist \"%s\"...</string>
+ <string name="download.playlist_done">Playlist was successfully saved.</string>
+ <string name="download.playlist_error">Failed to save playlist, please try later.</string>
+ <string name="download.repeat_off">Repeat off</string>
+ <string name="download.repeat_all">Repeat all</string>
+ <string name="download.repeat_single">Repeat song</string>
+ <string name="download.visualizer_on">Turned on visualizer.</string>
+ <string name="download.visualizer_off">Turned off visualizer.</string>
+ <string name="download.jukebox_on">Turned on remote control. Music is played on the computer.</string>
+ <string name="download.jukebox_off">Turned off remote control. Music is played on the phone.</string>
+ <string name="download.jukebox_volume">Remote volume</string>
+ <string name="download.jukebox_server_too_old">Remote control is not supported. Please upgrade your Subsonic server.</string>
+ <string name="download.jukebox_offline">Remote control is not available in offline mode.</string>
+ <string name="download.jukebox_not_authorized">Remote control is not allowed. Please enable jukebox mode in <b>Users &gt; Settings</b> on your Subsonic server.</string>
+
+ <string name="song_details.all">%1$s %2$s</string>
+ <string name="song_details.kbps">%d kbps</string>
+
+ <string name="lyrics.nomatch">No lyrics found</string>
+
+ <string name="error.label">Error</string>
+
+ <string name="settings.title">Subsonic settings</string>
+ <string name="settings.test_connection_title">Test connection</string>
+ <string name="settings.servers_title">Servers</string>
+ <string name="settings.server_unused1">Unused 1</string>
+ <string name="settings.server_unused2">Unused 2</string>
+ <string name="settings.server_name">Name</string>
+ <string name="settings.server_address">Server address</string>
+ <string name="settings.server_username">Username</string>
+ <string name="settings.server_password">Password</string>
+ <string name="settings.cache_title">Music cache</string>
+ <string name="settings.preload">Songs to preload</string>
+ <string name="settings.cache_size">Cache size</string>
+ <string name="settings.cache_location">Cache location</string>
+ <string name="settings.cache_location_error">Invalid cache location. Using default.</string>
+ <string name="settings.testing_connection">Testing connection...</string>
+ <string name="settings.testing_ok">Connection is OK</string>
+ <string name="settings.testing_unlicensed">Connection is OK. Server unlicensed.</string>
+ <string name="settings.connection_failure">Connection failure.</string>
+ <string name="settings.invalid_url">Please specify a valid URL.</string>
+ <string name="settings.invalid_username">Please specify a valid username (no trailing spaces).</string>
+ <string name="settings.appearance_title">Appearance</string>
+ <string name="settings.theme_title">Theme</string>
+ <string name="settings.theme_wheat">Wheat</string>
+ <string name="settings.theme_light">Light</string>
+ <string name="settings.theme_dark">Dark</string>
+ <string name="settings.network_title">Network</string>
+ <string name="settings.max_bitrate_wifi">Max bitrate - Wi-Fi</string>
+ <string name="settings.max_bitrate_mobile">Max bitrate - Mobile</string>
+ <string name="settings.max_bitrate_32">32 Kbps</string>
+ <string name="settings.max_bitrate_64">64 Kbps</string>
+ <string name="settings.max_bitrate_80">80 Kbps</string>
+ <string name="settings.max_bitrate_96">96 Kbps</string>
+ <string name="settings.max_bitrate_112">112 Kbps</string>
+ <string name="settings.max_bitrate_128">128 Kbps</string>
+ <string name="settings.max_bitrate_160">160 Kbps</string>
+ <string name="settings.max_bitrate_192">192 Kbps</string>
+ <string name="settings.max_bitrate_256">256 Kbps</string>
+ <string name="settings.max_bitrate_320">320 Kbps</string>
+ <string name="settings.max_bitrate_unlimited">Unlimited</string>
+ <string name="settings.wifi_required_title">Wi-Fi streaming only</string>
+ <string name="settings.wifi_required_summary">Only stream media if connected to Wi-Fi</string>
+ <string name="settings.preload_1">1 song</string>
+ <string name="settings.preload_2">2 songs</string>
+ <string name="settings.preload_3">3 songs</string>
+ <string name="settings.preload_5">5 songs</string>
+ <string name="settings.preload_10">10 songs</string>
+ <string name="settings.preload_unlimited">Unlimited</string>
+ <string name="settings.cache_size_100">100 MB</string>
+ <string name="settings.cache_size_200">200 MB</string>
+ <string name="settings.cache_size_500">500 MB</string>
+ <string name="settings.cache_size_1000">1 GB</string>
+ <string name="settings.cache_size_2000">2 GB</string>
+ <string name="settings.cache_size_5000">5 GB</string>
+ <string name="settings.cache_size_10000">10 GB</string>
+ <string name="settings.cache_size_20000">20 GB</string>
+ <string name="settings.cache_size_unlimited">Unlimited</string>
+ <string name="settings.clear_search_history">Clear search history</string>
+ <string name="settings.search_history_cleared">Search history cleared</string>
+ <string name="settings.other_title">Other settings</string>
+ <string name="settings.scrobble_title">Scrobble to Last.fm</string>
+ <string name="settings.scrobble_summary">Remember to set up your Last.fm user and password on the Subsonic server</string>
+ <string name="settings.hide_media_title">Hide from other</string>
+ <string name="settings.hide_media_summary">Hide music files from other apps.</string>
+ <string name="settings.hide_media_toast">Takes effect next time Android scans your phone for music.</string>
+ <string name="settings.media_button_title">Media buttons</string>
+ <string name="settings.media_button_summary">Respond to phone, headset and Bluetooth media buttons</string>
+ <string name="settings.screen_lit_title">Keep screen on</string>
+ <string name="settings.screen_lit_summary">Keeping the screen on while downloading improves download speed.</string>
+
+ <string name="music_service.retry">A network error occurred. Retrying %1$d of %2$d.</string>
+
+ <string name="background_task.wait">Please wait...</string>
+ <string name="background_task.loading">Loading.</string>
+ <string name="background_task.no_network">This program requires network access. Please turn on Wi-Fi or mobile network.</string>
+ <string name="background_task.network_error">A network error occurred. Please check the server address or try again later.</string>
+ <string name="background_task.not_found">Resource not found. Please check the server address.</string>
+ <string name="background_task.parse_error">Didn\'t understand the reply. Please check the server address.</string>
+
+ <string name="service.connecting">Contacting server, please wait.</string>
+
+ <string name="parser.reading">Reading from server.</string>
+ <string name="parser.reading_done">Reading from server. Done!</string>
+ <string name="parser.upgrade_client">Incompatible versions. Please upgrade Subsonic Android app.</string>
+ <string name="parser.upgrade_server">Incompatible versions. Please upgrade Subsonic server.</string>
+ <string name="parser.not_authenticated">Wrong username or password.</string>
+ <string name="parser.not_authorized">Not authorized. Check user permissions in Subsonic server.</string>
+ <string name="parser.artist_count">Got %d artists.</string>
+
+ <string name="select_artist.refresh">Refresh</string>
+ <string name="select_artist.folder">Select folder</string>
+ <string name="select_artist.all_folders">All folders</string>
+
+ <string name="equalizer.label">Equalizer</string>
+ <string name="equalizer.enabled">Enabled</string>
+ <string name="equalizer.preset">Select preset</string>
+
+ <string name="widget.initial_text">Touch to select music</string>
+ <string name="widget.sdcard_busy">SD card unavailable</string>
+ <string name="widget.sdcard_missing">No SD card</string>
+
+ <string name="util.bytes_format.gigabyte">0.00 GB</string>
+ <string name="util.bytes_format.megabyte">0.00 MB</string>
+ <string name="util.bytes_format.kilobyte">0 KB</string>
+ <string name="util.bytes_format.byte">0 B</string>
+
+ <plurals name="select_album_n_songs">
+ <item quantity="zero">No songs</item>
+ <item quantity="one">One song</item>
+ <item quantity="other">%d songs</item>
+ </plurals>
+ <plurals name="select_album_n_songs_downloading">
+ <item quantity="one">One song scheduled for download.</item>
+ <item quantity="other">%d songs scheduled for download.</item>
+ </plurals>
+ <plurals name="select_album_n_songs_added">
+ <item quantity="one">One song added to play queue.</item>
+ <item quantity="other">%d songs added to play queue.</item>
+ </plurals>
+ <plurals name="select_album_donate_dialog_n_trial_days_left">
+ <item quantity="one">One day left of trial period</item>
+ <item quantity="other">%d days left of trial period</item>
+ </plurals>
+
+</resources>
diff --git a/subsonic-android/res/values/styles.xml b/subsonic-android/res/values/styles.xml
new file mode 100644
index 00000000..a970fe1b
--- /dev/null
+++ b/subsonic-android/res/values/styles.xml
@@ -0,0 +1,14 @@
+<?xml version="1.0" encoding="utf-8"?>
+<resources>
+ <style name="Wheat" parent="android:Theme.Light">
+ <item name="android:windowBackground">@color/wheatBackground</item>
+ <item name="android:textColorPrimary">@color/wheatForeground1</item>
+ <item name="android:textColorSecondary">@color/wheatForeground2</item>
+ <item name="android:listViewStyle">@style/WheatListView</item>
+ </style>
+
+ <style name="WheatListView" parent="android:style/Widget.ListView.White">
+ <item name="android:cacheColorHint">@color/wheatBackground</item>
+ </style>
+
+</resources>
diff --git a/subsonic-android/res/xml/appwidget_info.xml b/subsonic-android/res/xml/appwidget_info.xml
new file mode 100644
index 00000000..f1e8e308
--- /dev/null
+++ b/subsonic-android/res/xml/appwidget_info.xml
@@ -0,0 +1,6 @@
+<?xml version="1.0" encoding="utf-8"?>
+<appwidget-provider xmlns:android="http://schemas.android.com/apk/res/android"
+ android:minWidth="294dip"
+ android:minHeight="72dip"
+ android:updatePeriodMillis="0"
+ android:initialLayout="@layout/appwidget"/> \ No newline at end of file
diff --git a/subsonic-android/res/xml/searchable.xml b/subsonic-android/res/xml/searchable.xml
new file mode 100644
index 00000000..7822e98c
--- /dev/null
+++ b/subsonic-android/res/xml/searchable.xml
@@ -0,0 +1,9 @@
+<?xml version="1.0" encoding="utf-8"?>
+<searchable xmlns:android="http://schemas.android.com/apk/res/android"
+ android:label="@string/common.appname"
+ android:hint="@string/search.title"
+ android:voiceSearchMode="showVoiceSearchButton|launchRecognizer"
+ android:voiceLanguageModel="web_search"
+ android:searchSuggestAuthority="net.sourceforge.subsonic.androidapp.provider.SearchSuggestionProvider"
+ android:searchSuggestSelection=" ?" >
+</searchable> \ No newline at end of file
diff --git a/subsonic-android/res/xml/settings.xml b/subsonic-android/res/xml/settings.xml
new file mode 100644
index 00000000..427826ac
--- /dev/null
+++ b/subsonic-android/res/xml/settings.xml
@@ -0,0 +1,200 @@
+<?xml version="1.0" encoding="utf-8"?>
+
+<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
+ android:title="@string/settings.title">
+
+ <PreferenceCategory
+ android:title="@string/settings.servers_title">
+
+ <PreferenceScreen
+ android:key="server1">
+
+ <EditTextPreference
+ android:key="serverName1"
+ android:title="@string/settings.server_name"
+ android:defaultValue="Subsonic demo"/>
+
+ <EditTextPreference
+ android:key="serverUrl1"
+ android:title="@string/settings.server_address"
+ android:defaultValue="http://demo.subsonic.org"
+ android:inputType="textUri"/>
+
+ <EditTextPreference
+ android:key="username1"
+ android:title="@string/settings.server_username"
+ android:defaultValue="android-guest"/>
+
+ <EditTextPreference
+ android:key="password1"
+ android:title="@string/settings.server_password"
+ android:password="true"
+ android:defaultValue="guest"
+ android:summary="****"/>
+
+ <Preference
+ android:key="testConnection1"
+ android:title="@string/settings.test_connection_title"
+ android:persistent="false"/>
+
+ </PreferenceScreen>
+
+ <PreferenceScreen
+ android:key="server2">
+
+ <EditTextPreference
+ android:key="serverName2"
+ android:title="@string/settings.server_name"
+ android:defaultValue="@string/settings.server_unused1"/>
+
+ <EditTextPreference
+ android:key="serverUrl2"
+ android:title="@string/settings.server_address"
+ android:defaultValue="http://yourhost"
+ android:inputType="textUri"/>
+
+ <EditTextPreference
+ android:key="username2"
+ android:title="@string/settings.server_username"/>
+
+ <EditTextPreference
+ android:key="password2"
+ android:title="@string/settings.server_password"
+ android:password="true"
+ android:summary="****"/>
+
+ <Preference
+ android:key="testConnection2"
+ android:title="@string/settings.test_connection_title"
+ android:persistent="false"/>
+
+ </PreferenceScreen>
+
+ <PreferenceScreen
+ android:key="server3">
+
+ <EditTextPreference
+ android:key="serverName3"
+ android:title="@string/settings.server_name"
+ android:defaultValue="@string/settings.server_unused2"/>
+
+ <EditTextPreference
+ android:key="serverUrl3"
+ android:title="@string/settings.server_address"
+ android:defaultValue="http://yourhost"
+ android:inputType="textUri"/>
+
+ <EditTextPreference
+ android:key="username3"
+ android:title="@string/settings.server_username"/>
+
+ <EditTextPreference
+ android:key="password3"
+ android:title="@string/settings.server_password"
+ android:password="true"
+ android:summary="****"/>
+
+ <Preference
+ android:key="testConnection3"
+ android:title="@string/settings.test_connection_title"
+ android:persistent="false"/>
+
+ </PreferenceScreen>
+
+ </PreferenceCategory>
+
+ <PreferenceCategory
+ android:title="@string/settings.appearance_title">
+
+ <ListPreference
+ android:title="@string/settings.theme_title"
+ android:key="theme"
+ android:defaultValue="wheat"
+ android:entryValues="@array/themeValues"
+ android:entries="@array/themeNames"/>
+
+ </PreferenceCategory>
+
+ <PreferenceCategory
+ android:title="@string/settings.network_title">
+
+ <ListPreference
+ android:title="@string/settings.max_bitrate_wifi"
+ android:key="maxBitrateWifi"
+ android:defaultValue="0"
+ android:entryValues="@array/maxBitrateValues"
+ android:entries="@array/maxBitrateNames"/>
+
+ <ListPreference
+ android:title="@string/settings.max_bitrate_mobile"
+ android:key="maxBitrateMobile"
+ android:defaultValue="0"
+ android:entryValues="@array/maxBitrateValues"
+ android:entries="@array/maxBitrateNames"/>
+
+ <CheckBoxPreference
+ android:title="@string/settings.wifi_required_title"
+ android:summary="@string/settings.wifi_required_summary"
+ android:key="wifiRequiredForDownload"
+ android:defaultValue="false"/>
+
+ </PreferenceCategory>
+
+ <PreferenceCategory
+ android:title="@string/settings.cache_title">
+
+ <ListPreference
+ android:title="@string/settings.cache_size"
+ android:key="cacheSize"
+ android:defaultValue="500"
+ android:entryValues="@array/cacheSizeValues"
+ android:entries="@array/cacheSizeNames"/>
+
+ <EditTextPreference
+ android:title="@string/settings.cache_location"
+ android:key="cacheLocation"/>
+
+ <ListPreference
+ android:title="@string/settings.preload"
+ android:key="preloadCount"
+ android:defaultValue="3"
+ android:entryValues="@array/preloadCountValues"
+ android:entries="@array/preloadCountNames"/>
+
+ </PreferenceCategory>
+
+ <PreferenceCategory
+ android:title="@string/settings.other_title">
+
+ <CheckBoxPreference
+ android:title="@string/settings.scrobble_title"
+ android:summary="@string/settings.scrobble_summary"
+ android:key="scrobble"
+ android:defaultValue="false"/>
+
+ <CheckBoxPreference
+ android:title="@string/settings.hide_media_title"
+ android:summary="@string/settings.hide_media_summary"
+ android:key="hideMedia"
+ android:defaultValue="false"/>
+
+ <CheckBoxPreference
+ android:title="@string/settings.media_button_title"
+ android:summary="@string/settings.media_button_summary"
+ android:key="mediaButtons"
+ android:defaultValue="true"/>
+
+ <CheckBoxPreference
+ android:title="@string/settings.screen_lit_title"
+ android:summary="@string/settings.screen_lit_summary"
+ android:key="screenLitOnDownload"
+ android:defaultValue="true"/>
+
+ <Preference
+ android:key="clearSearchHistory"
+ android:title="@string/settings.clear_search_history"
+ android:persistent="false"/>
+
+ </PreferenceCategory>
+
+</PreferenceScreen>
diff --git a/subsonic-android/src/net/sourceforge/subsonic/androidapp/activity/DownloadActivity.java b/subsonic-android/src/net/sourceforge/subsonic/androidapp/activity/DownloadActivity.java
new file mode 100644
index 00000000..68144481
--- /dev/null
+++ b/subsonic-android/src/net/sourceforge/subsonic/androidapp/activity/DownloadActivity.java
@@ -0,0 +1,874 @@
+/*
+ This file is part of Subsonic.
+
+ Subsonic is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ Subsonic is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with Subsonic. If not, see <http://www.gnu.org/licenses/>.
+
+ Copyright 2009 (C) Sindre Mehus
+ */
+package net.sourceforge.subsonic.androidapp.activity;
+
+import java.text.DateFormat;
+import java.text.SimpleDateFormat;
+import java.util.Date;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.concurrent.Executors;
+import java.util.concurrent.ScheduledExecutorService;
+import java.util.concurrent.TimeUnit;
+
+import android.app.AlertDialog;
+import android.app.Dialog;
+import android.content.DialogInterface;
+import android.content.Intent;
+import android.graphics.Color;
+import android.graphics.Typeface;
+import android.os.Bundle;
+import android.os.Handler;
+import android.view.ContextMenu;
+import android.view.Display;
+import android.view.GestureDetector;
+import android.view.GestureDetector.OnGestureListener;
+import android.view.LayoutInflater;
+import android.view.Menu;
+import android.view.MenuInflater;
+import android.view.MenuItem;
+import android.view.MotionEvent;
+import android.view.View;
+import android.view.ViewGroup;
+import android.view.WindowManager;
+import android.view.animation.AnimationUtils;
+import android.widget.AdapterView;
+import android.widget.ArrayAdapter;
+import android.widget.Button;
+import android.widget.EditText;
+import android.widget.ImageButton;
+import android.widget.ImageView;
+import android.widget.LinearLayout;
+import android.widget.ListView;
+import android.widget.TextView;
+import android.widget.ViewFlipper;
+import net.sourceforge.subsonic.androidapp.R;
+import net.sourceforge.subsonic.androidapp.domain.MusicDirectory;
+import net.sourceforge.subsonic.androidapp.domain.PlayerState;
+import net.sourceforge.subsonic.androidapp.domain.RepeatMode;
+import net.sourceforge.subsonic.androidapp.service.DownloadFile;
+import net.sourceforge.subsonic.androidapp.service.DownloadService;
+import net.sourceforge.subsonic.androidapp.service.MusicService;
+import net.sourceforge.subsonic.androidapp.service.MusicServiceFactory;
+import net.sourceforge.subsonic.androidapp.util.Constants;
+import net.sourceforge.subsonic.androidapp.util.HorizontalSlider;
+import net.sourceforge.subsonic.androidapp.util.SilentBackgroundTask;
+import net.sourceforge.subsonic.androidapp.util.SongView;
+import net.sourceforge.subsonic.androidapp.util.Util;
+import net.sourceforge.subsonic.androidapp.view.VisualizerView;
+
+import static net.sourceforge.subsonic.androidapp.domain.PlayerState.*;
+
+public class DownloadActivity extends SubsonicTabActivity implements OnGestureListener {
+
+ private static final int DIALOG_SAVE_PLAYLIST = 100;
+ private static final int PERCENTAGE_OF_SCREEN_FOR_SWIPE = 5;
+ private static final int COLOR_BUTTON_ENABLED = Color.rgb(129, 201, 54);
+ private static final int COLOR_BUTTON_DISABLED = Color.rgb(164, 166, 158);
+
+ private ViewFlipper playlistFlipper;
+ private ViewFlipper buttonBarFlipper;
+ private TextView emptyTextView;
+ private TextView songTitleTextView;
+ private TextView albumTextView;
+ private TextView artistTextView;
+ private ImageView albumArtImageView;
+ private ListView playlistView;
+ private TextView positionTextView;
+ private TextView durationTextView;
+ private TextView statusTextView;
+ private HorizontalSlider progressBar;
+ private View previousButton;
+ private View nextButton;
+ private View pauseButton;
+ private View stopButton;
+ private View startButton;
+ private View shuffleButton;
+ private ImageButton repeatButton;
+ private Button equalizerButton;
+ private Button visualizerButton;
+ private Button jukeboxButton;
+ private View toggleListButton;
+ private ScheduledExecutorService executorService;
+ private DownloadFile currentPlaying;
+ private long currentRevision;
+ private EditText playlistNameView;
+ private GestureDetector gestureScanner;
+ private int swipeDistance;
+ private int swipeVelocity;
+ private VisualizerView visualizerView;
+
+ /**
+ * Called when the activity is first created.
+ */
+ @Override
+ public void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ setContentView(R.layout.download);
+
+ WindowManager w = getWindowManager();
+ Display d = w.getDefaultDisplay();
+ swipeDistance = (d.getWidth() + d.getHeight()) * PERCENTAGE_OF_SCREEN_FOR_SWIPE / 100;
+ swipeVelocity = (d.getWidth() + d.getHeight()) * PERCENTAGE_OF_SCREEN_FOR_SWIPE / 100;
+ gestureScanner = new GestureDetector(this);
+
+ playlistFlipper = (ViewFlipper) findViewById(R.id.download_playlist_flipper);
+ buttonBarFlipper = (ViewFlipper) findViewById(R.id.download_button_bar_flipper);
+ emptyTextView = (TextView) findViewById(R.id.download_empty);
+ songTitleTextView = (TextView) findViewById(R.id.download_song_title);
+ albumTextView = (TextView) findViewById(R.id.download_album);
+ artistTextView = (TextView) findViewById(R.id.download_artist);
+ albumArtImageView = (ImageView) findViewById(R.id.download_album_art_image);
+ positionTextView = (TextView) findViewById(R.id.download_position);
+ durationTextView = (TextView) findViewById(R.id.download_duration);
+ statusTextView = (TextView) findViewById(R.id.download_status);
+ progressBar = (HorizontalSlider) findViewById(R.id.download_progress_bar);
+ playlistView = (ListView) findViewById(R.id.download_list);
+ previousButton = findViewById(R.id.download_previous);
+ nextButton = findViewById(R.id.download_next);
+ pauseButton = findViewById(R.id.download_pause);
+ stopButton = findViewById(R.id.download_stop);
+ startButton = findViewById(R.id.download_start);
+ shuffleButton = findViewById(R.id.download_shuffle);
+ repeatButton = (ImageButton) findViewById(R.id.download_repeat);
+ equalizerButton = (Button) findViewById(R.id.download_equalizer);
+ visualizerButton = (Button) findViewById(R.id.download_visualizer);
+ jukeboxButton = (Button) findViewById(R.id.download_jukebox);
+ LinearLayout visualizerViewLayout = (LinearLayout) findViewById(R.id.download_visualizer_view_layout);
+
+ toggleListButton = findViewById(R.id.download_toggle_list);
+
+ View.OnTouchListener touchListener = new View.OnTouchListener() {
+ @Override
+ public boolean onTouch(View v, MotionEvent me) {
+ return gestureScanner.onTouchEvent(me);
+ }
+ };
+ previousButton.setOnTouchListener(touchListener);
+ nextButton.setOnTouchListener(touchListener);
+ pauseButton.setOnTouchListener(touchListener);
+ stopButton.setOnTouchListener(touchListener);
+ startButton.setOnTouchListener(touchListener);
+ equalizerButton.setOnTouchListener(touchListener);
+ visualizerButton.setOnTouchListener(touchListener);
+ jukeboxButton.setOnTouchListener(touchListener);
+ buttonBarFlipper.setOnTouchListener(touchListener);
+ emptyTextView.setOnTouchListener(touchListener);
+ albumArtImageView.setOnTouchListener(touchListener);
+
+ albumArtImageView.setOnClickListener(new View.OnClickListener() {
+ @Override
+ public void onClick(View view) {
+ toggleFullscreenAlbumArt();
+ }
+ });
+
+ previousButton.setOnClickListener(new View.OnClickListener() {
+ @Override
+ public void onClick(View view) {
+ warnIfNetworkOrStorageUnavailable();
+ getDownloadService().previous();
+ onCurrentChanged();
+ onProgressChanged();
+ }
+ });
+
+ nextButton.setOnClickListener(new View.OnClickListener() {
+ @Override
+ public void onClick(View view) {
+ warnIfNetworkOrStorageUnavailable();
+ if (getDownloadService().getCurrentPlayingIndex() < getDownloadService().size() - 1) {
+ getDownloadService().next();
+ onCurrentChanged();
+ onProgressChanged();
+ }
+ }
+ });
+
+ pauseButton.setOnClickListener(new View.OnClickListener() {
+ @Override
+ public void onClick(View view) {
+ getDownloadService().pause();
+ onCurrentChanged();
+ onProgressChanged();
+ }
+ });
+
+ stopButton.setOnClickListener(new View.OnClickListener() {
+ @Override
+ public void onClick(View view) {
+ getDownloadService().reset();
+ onCurrentChanged();
+ onProgressChanged();
+ }
+ });
+
+ startButton.setOnClickListener(new View.OnClickListener() {
+ @Override
+ public void onClick(View view) {
+ warnIfNetworkOrStorageUnavailable();
+ start();
+ onCurrentChanged();
+ onProgressChanged();
+ }
+ });
+
+ shuffleButton.setOnClickListener(new View.OnClickListener() {
+ @Override
+ public void onClick(View view) {
+ getDownloadService().shuffle();
+ Util.toast(DownloadActivity.this, R.string.download_menu_shuffle_notification);
+ }
+ });
+
+ repeatButton.setOnClickListener(new View.OnClickListener() {
+ @Override
+ public void onClick(View view) {
+ RepeatMode repeatMode = getDownloadService().getRepeatMode().next();
+ getDownloadService().setRepeatMode(repeatMode);
+ onDownloadListChanged();
+ switch (repeatMode) {
+ case OFF:
+ Util.toast(DownloadActivity.this, R.string.download_repeat_off);
+ break;
+ case ALL:
+ Util.toast(DownloadActivity.this, R.string.download_repeat_all);
+ break;
+ case SINGLE:
+ Util.toast(DownloadActivity.this, R.string.download_repeat_single);
+ break;
+ default:
+ break;
+ }
+ }
+ });
+
+ equalizerButton.setOnClickListener(new View.OnClickListener() {
+ @Override
+ public void onClick(View view) {
+ startActivity(new Intent(DownloadActivity.this, EqualizerActivity.class));
+ }
+ });
+
+ visualizerButton.setOnClickListener(new View.OnClickListener() {
+ @Override
+ public void onClick(View view) {
+ boolean active = !visualizerView.isActive();
+ visualizerView.setActive(active);
+ getDownloadService().setShowVisualization(visualizerView.isActive());
+ updateButtons();
+ Util.toast(DownloadActivity.this, active ? R.string.download_visualizer_on : R.string.download_visualizer_off);
+ }
+ });
+
+ jukeboxButton.setOnClickListener(new View.OnClickListener() {
+ @Override
+ public void onClick(View view) {
+ boolean jukeboxEnabled = !getDownloadService().isJukeboxEnabled();
+ getDownloadService().setJukeboxEnabled(jukeboxEnabled);
+ updateButtons();
+ Util.toast(DownloadActivity.this, jukeboxEnabled ? R.string.download_jukebox_on : R.string.download_jukebox_off, false);
+ }
+ });
+
+ toggleListButton.setOnClickListener(new View.OnClickListener() {
+ @Override
+ public void onClick(View view) {
+ toggleFullscreenAlbumArt();
+ }
+ });
+
+ progressBar.setOnSliderChangeListener(new HorizontalSlider.OnSliderChangeListener() {
+ @Override
+ public void onSliderChanged(View view, int position, boolean inProgress) {
+ Util.toast(DownloadActivity.this, Util.formatDuration(position / 1000), true);
+ if (!inProgress) {
+ getDownloadService().seekTo(position);
+ onProgressChanged();
+ }
+ }
+ });
+ playlistView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
+ @Override
+ public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
+ warnIfNetworkOrStorageUnavailable();
+ getDownloadService().play(position);
+ onCurrentChanged();
+ onProgressChanged();
+ }
+ });
+
+ registerForContextMenu(playlistView);
+
+ DownloadService downloadService = getDownloadService();
+ if (downloadService != null && getIntent().getBooleanExtra(Constants.INTENT_EXTRA_NAME_SHUFFLE, false)) {
+ warnIfNetworkOrStorageUnavailable();
+ downloadService.setShufflePlayEnabled(true);
+ }
+
+ boolean visualizerAvailable = downloadService != null && downloadService.getVisualizerController() != null;
+ boolean equalizerAvailable = downloadService != null && downloadService.getEqualizerController() != null;
+
+ if (!equalizerAvailable) {
+ equalizerButton.setVisibility(View.GONE);
+ }
+ if (!visualizerAvailable) {
+ visualizerButton.setVisibility(View.GONE);
+ } else {
+ visualizerView = new VisualizerView(this);
+ visualizerViewLayout.addView(visualizerView, new LinearLayout.LayoutParams(LinearLayout.LayoutParams.FILL_PARENT, LinearLayout.LayoutParams.FILL_PARENT));
+
+ visualizerView.setOnTouchListener(new View.OnTouchListener() {
+ @Override
+ public boolean onTouch(View view, MotionEvent motionEvent) {
+ visualizerView.setActive(!visualizerView.isActive());
+ getDownloadService().setShowVisualization(visualizerView.isActive());
+ updateButtons();
+ return true;
+ }
+ });
+ }
+
+ // TODO: Extract to utility method and cache.
+ Typeface typeface = Typeface.createFromAsset(getAssets(), "fonts/Storopia.ttf");
+ equalizerButton.setTypeface(typeface);
+ visualizerButton.setTypeface(typeface);
+ jukeboxButton.setTypeface(typeface);
+ }
+
+ @Override
+ protected void onResume() {
+ super.onResume();
+
+ final Handler handler = new Handler();
+ Runnable runnable = new Runnable() {
+ @Override
+ public void run() {
+ handler.post(new Runnable() {
+ @Override
+ public void run() {
+ update();
+ }
+ });
+ }
+ };
+
+ executorService = Executors.newSingleThreadScheduledExecutor();
+ executorService.scheduleWithFixedDelay(runnable, 0L, 1000L, TimeUnit.MILLISECONDS);
+
+ DownloadService downloadService = getDownloadService();
+ if (downloadService == null || downloadService.getCurrentPlaying() == null) {
+ playlistFlipper.setDisplayedChild(1);
+ buttonBarFlipper.setDisplayedChild(1);
+ }
+
+ onDownloadListChanged();
+ onCurrentChanged();
+ onProgressChanged();
+ scrollToCurrent();
+ if (downloadService != null && downloadService.getKeepScreenOn()) {
+ getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
+ } else {
+ getWindow().clearFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
+ }
+
+ if (visualizerView != null) {
+ visualizerView.setActive(downloadService != null && downloadService.getShowVisualization());
+ }
+
+ updateButtons();
+ }
+
+ private void updateButtons() {
+ boolean eqEnabled = getDownloadService() != null && getDownloadService().getEqualizerController() != null &&
+ getDownloadService().getEqualizerController().isEnabled();
+ equalizerButton.setTextColor(eqEnabled ? COLOR_BUTTON_ENABLED : COLOR_BUTTON_DISABLED);
+
+ if (visualizerView != null) {
+ visualizerButton.setTextColor(visualizerView.isActive() ? COLOR_BUTTON_ENABLED : COLOR_BUTTON_DISABLED);
+ }
+
+ boolean jukeboxEnabled = getDownloadService() != null && getDownloadService().isJukeboxEnabled();
+ jukeboxButton.setTextColor(jukeboxEnabled ? COLOR_BUTTON_ENABLED : COLOR_BUTTON_DISABLED);
+ }
+
+ // Scroll to current playing/downloading.
+ private void scrollToCurrent() {
+ if (getDownloadService() == null) {
+ return;
+ }
+
+ for (int i = 0; i < playlistView.getAdapter().getCount(); i++) {
+ if (currentPlaying == playlistView.getItemAtPosition(i)) {
+ playlistView.setSelectionFromTop(i, 40);
+ return;
+ }
+ }
+ DownloadFile currentDownloading = getDownloadService().getCurrentDownloading();
+ for (int i = 0; i < playlistView.getAdapter().getCount(); i++) {
+ if (currentDownloading == playlistView.getItemAtPosition(i)) {
+ playlistView.setSelectionFromTop(i, 40);
+ return;
+ }
+ }
+ }
+
+ @Override
+ protected void onPause() {
+ super.onPause();
+ executorService.shutdown();
+ if (visualizerView != null) {
+ visualizerView.setActive(false);
+ }
+ }
+
+ @Override
+ protected Dialog onCreateDialog(int id) {
+ if (id == DIALOG_SAVE_PLAYLIST) {
+ AlertDialog.Builder builder;
+
+ LayoutInflater inflater = (LayoutInflater) getSystemService(LAYOUT_INFLATER_SERVICE);
+ final View layout = inflater.inflate(R.layout.save_playlist, (ViewGroup) findViewById(R.id.save_playlist_root));
+ playlistNameView = (EditText) layout.findViewById(R.id.save_playlist_name);
+
+ builder = new AlertDialog.Builder(this);
+ builder.setTitle(R.string.download_playlist_title);
+ builder.setMessage(R.string.download_playlist_name);
+ builder.setPositiveButton(R.string.common_save, new DialogInterface.OnClickListener() {
+ @Override
+ public void onClick(DialogInterface dialog, int id) {
+ savePlaylistInBackground(String.valueOf(playlistNameView.getText()));
+ }
+ });
+ builder.setNegativeButton(R.string.common_cancel, new DialogInterface.OnClickListener() {
+ @Override
+ public void onClick(DialogInterface dialog, int id) {
+ dialog.cancel();
+ }
+ });
+ builder.setView(layout);
+ builder.setCancelable(true);
+
+ return builder.create();
+ } else {
+ return super.onCreateDialog(id);
+ }
+ }
+
+ @Override
+ protected void onPrepareDialog(int id, Dialog dialog) {
+ if (id == DIALOG_SAVE_PLAYLIST) {
+ String playlistName = getDownloadService().getSuggestedPlaylistName();
+ if (playlistName != null) {
+ playlistNameView.setText(playlistName);
+ } else {
+ DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
+ playlistNameView.setText(dateFormat.format(new Date()));
+ }
+ }
+ }
+
+ @Override
+ public boolean onCreateOptionsMenu(Menu menu) {
+ MenuInflater inflater = getMenuInflater();
+ inflater.inflate(R.menu.nowplaying, menu);
+ return true;
+ }
+
+ @Override
+ public boolean onPrepareOptionsMenu(Menu menu) {
+ MenuItem savePlaylist = menu.findItem(R.id.menu_save_playlist);
+ boolean savePlaylistEnabled = !Util.isOffline(this);
+ savePlaylist.setEnabled(savePlaylistEnabled);
+ savePlaylist.setVisible(savePlaylistEnabled);
+ MenuItem screenOption = menu.findItem(R.id.menu_screen_on_off);
+ if (getDownloadService().getKeepScreenOn()) {
+ screenOption.setTitle(R.string.download_menu_screen_off);
+ } else {
+ screenOption.setTitle(R.string.download_menu_screen_on);
+ }
+ return super.onPrepareOptionsMenu(menu);
+ }
+
+ @Override
+ public void onCreateContextMenu(ContextMenu menu, View view, ContextMenu.ContextMenuInfo menuInfo) {
+ super.onCreateContextMenu(menu, view, menuInfo);
+ if (view == playlistView) {
+ AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo) menuInfo;
+ DownloadFile downloadFile = (DownloadFile) playlistView.getItemAtPosition(info.position);
+
+ MenuInflater inflater = getMenuInflater();
+ inflater.inflate(R.menu.nowplaying_context, menu);
+
+ if (downloadFile.getSong().getParent() == null) {
+ menu.findItem(R.id.menu_show_album).setVisible(false);
+ }
+ if (Util.isOffline(this)) {
+ menu.findItem(R.id.menu_lyrics).setVisible(false);
+ menu.findItem(R.id.menu_save_playlist).setVisible(false);
+ }
+ }
+ }
+
+ @Override
+ public boolean onContextItemSelected(MenuItem menuItem) {
+ AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo) menuItem.getMenuInfo();
+ DownloadFile downloadFile = (DownloadFile) playlistView.getItemAtPosition(info.position);
+ return menuItemSelected(menuItem.getItemId(), downloadFile) || super.onContextItemSelected(menuItem);
+ }
+
+ @Override
+ public boolean onOptionsItemSelected(MenuItem menuItem) {
+ return menuItemSelected(menuItem.getItemId(), null) || super.onOptionsItemSelected(menuItem);
+ }
+
+ private boolean menuItemSelected(int menuItemId, DownloadFile song) {
+ switch (menuItemId) {
+ case R.id.menu_show_album:
+ Intent intent = new Intent(this, SelectAlbumActivity.class);
+ intent.putExtra(Constants.INTENT_EXTRA_NAME_ID, song.getSong().getParent());
+ intent.putExtra(Constants.INTENT_EXTRA_NAME_NAME, song.getSong().getAlbum());
+ Util.startActivityWithoutTransition(this, intent);
+ return true;
+ case R.id.menu_lyrics:
+ intent = new Intent(this, LyricsActivity.class);
+ intent.putExtra(Constants.INTENT_EXTRA_NAME_ARTIST, song.getSong().getArtist());
+ intent.putExtra(Constants.INTENT_EXTRA_NAME_TITLE, song.getSong().getTitle());
+ Util.startActivityWithoutTransition(this, intent);
+ return true;
+ case R.id.menu_remove:
+ getDownloadService().remove(song);
+ onDownloadListChanged();
+ return true;
+ case R.id.menu_remove_all:
+ getDownloadService().setShufflePlayEnabled(false);
+ getDownloadService().clear();
+ onDownloadListChanged();
+ return true;
+ case R.id.menu_screen_on_off:
+ if (getDownloadService().getKeepScreenOn()) {
+ getWindow().clearFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
+ getDownloadService().setKeepScreenOn(false);
+ } else {
+ getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
+ getDownloadService().setKeepScreenOn(true);
+ }
+ return true;
+ case R.id.menu_shuffle:
+ getDownloadService().shuffle();
+ Util.toast(this, R.string.download_menu_shuffle_notification);
+ return true;
+ case R.id.menu_save_playlist:
+ showDialog(DIALOG_SAVE_PLAYLIST);
+ return true;
+ default:
+ return false;
+ }
+ }
+
+ private void update() {
+ if (getDownloadService() == null) {
+ return;
+ }
+
+ if (currentRevision != getDownloadService().getDownloadListUpdateRevision()) {
+ onDownloadListChanged();
+ }
+
+ if (currentPlaying != getDownloadService().getCurrentPlaying()) {
+ onCurrentChanged();
+ }
+
+ onProgressChanged();
+ }
+
+ private void savePlaylistInBackground(final String playlistName) {
+ Util.toast(DownloadActivity.this, getResources().getString(R.string.download_playlist_saving, playlistName));
+ getDownloadService().setSuggestedPlaylistName(playlistName);
+ new SilentBackgroundTask<Void>(this) {
+ @Override
+ protected Void doInBackground() throws Throwable {
+ List<MusicDirectory.Entry> entries = new LinkedList<MusicDirectory.Entry>();
+ for (DownloadFile downloadFile : getDownloadService().getDownloads()) {
+ entries.add(downloadFile.getSong());
+ }
+ MusicService musicService = MusicServiceFactory.getMusicService(DownloadActivity.this);
+ musicService.createPlaylist(null, playlistName, entries, DownloadActivity.this, null);
+ return null;
+ }
+
+ @Override
+ protected void done(Void result) {
+ Util.toast(DownloadActivity.this, R.string.download_playlist_done);
+ }
+
+ @Override
+ protected void error(Throwable error) {
+ String msg = getResources().getString(R.string.download_playlist_error) + " " + getErrorMessage(error);
+ Util.toast(DownloadActivity.this, msg);
+ }
+ }.execute();
+ }
+
+ private void toggleFullscreenAlbumArt() {
+ scrollToCurrent();
+ if (playlistFlipper.getDisplayedChild() == 1) {
+ playlistFlipper.setInAnimation(AnimationUtils.loadAnimation(this, R.anim.push_down_in));
+ playlistFlipper.setOutAnimation(AnimationUtils.loadAnimation(this, R.anim.push_down_out));
+ playlistFlipper.setDisplayedChild(0);
+ buttonBarFlipper.setInAnimation(AnimationUtils.loadAnimation(this, R.anim.push_down_in));
+ buttonBarFlipper.setOutAnimation(AnimationUtils.loadAnimation(this, R.anim.push_down_out));
+ buttonBarFlipper.setDisplayedChild(0);
+
+
+ } else {
+ playlistFlipper.setInAnimation(AnimationUtils.loadAnimation(this, R.anim.push_up_in));
+ playlistFlipper.setOutAnimation(AnimationUtils.loadAnimation(this, R.anim.push_up_out));
+ playlistFlipper.setDisplayedChild(1);
+ buttonBarFlipper.setInAnimation(AnimationUtils.loadAnimation(this, R.anim.push_up_in));
+ buttonBarFlipper.setOutAnimation(AnimationUtils.loadAnimation(this, R.anim.push_up_out));
+ buttonBarFlipper.setDisplayedChild(1);
+ }
+ }
+
+ private void start() {
+ DownloadService service = getDownloadService();
+ PlayerState state = service.getPlayerState();
+ if (state == PAUSED || state == COMPLETED) {
+ service.start();
+ } else if (state == STOPPED || state == IDLE) {
+ warnIfNetworkOrStorageUnavailable();
+ int current = service.getCurrentPlayingIndex();
+ // TODO: Use play() method.
+ if (current == -1) {
+ service.play(0);
+ } else {
+ service.play(current);
+ }
+ }
+ }
+
+ private void onDownloadListChanged() {
+ DownloadService downloadService = getDownloadService();
+ if (downloadService == null) {
+ return;
+ }
+
+ List<DownloadFile> list = downloadService.getDownloads();
+
+ playlistView.setAdapter(new SongListAdapter(list));
+ emptyTextView.setVisibility(list.isEmpty() ? View.VISIBLE : View.GONE);
+ currentRevision = downloadService.getDownloadListUpdateRevision();
+
+ switch (downloadService.getRepeatMode()) {
+ case OFF:
+ repeatButton.setImageResource(R.drawable.media_repeat_off);
+ break;
+ case ALL:
+ repeatButton.setImageResource(R.drawable.media_repeat_all);
+ break;
+ case SINGLE:
+ repeatButton.setImageResource(R.drawable.media_repeat_single);
+ break;
+ default:
+ break;
+ }
+ }
+
+ private void onCurrentChanged() {
+ if (getDownloadService() == null) {
+ return;
+ }
+
+ currentPlaying = getDownloadService().getCurrentPlaying();
+ if (currentPlaying != null) {
+ MusicDirectory.Entry song = currentPlaying.getSong();
+ songTitleTextView.setText(song.getTitle());
+ albumTextView.setText(song.getAlbum());
+ artistTextView.setText(song.getArtist());
+ getImageLoader().loadImage(albumArtImageView, song, true, true);
+ } else {
+ songTitleTextView.setText(null);
+ albumTextView.setText(null);
+ artistTextView.setText(null);
+ getImageLoader().loadImage(albumArtImageView, null, true, false);
+ }
+ }
+
+ private void onProgressChanged() {
+ if (getDownloadService() == null) {
+ return;
+ }
+
+ if (currentPlaying != null) {
+
+ int millisPlayed = Math.max(0, getDownloadService().getPlayerPosition());
+ Integer duration = getDownloadService().getPlayerDuration();
+ int millisTotal = duration == null ? 0 : duration;
+
+ positionTextView.setText(Util.formatDuration(millisPlayed / 1000));
+ durationTextView.setText(Util.formatDuration(millisTotal / 1000));
+ progressBar.setMax(millisTotal == 0 ? 100 : millisTotal); // Work-around for apparent bug.
+ progressBar.setProgress(millisPlayed);
+ progressBar.setSlidingEnabled(currentPlaying.isCompleteFileAvailable() || getDownloadService().isJukeboxEnabled());
+ } else {
+ positionTextView.setText("0:00");
+ durationTextView.setText("-:--");
+ progressBar.setProgress(0);
+ progressBar.setSlidingEnabled(false);
+ }
+
+ PlayerState playerState = getDownloadService().getPlayerState();
+
+ switch (playerState) {
+ case DOWNLOADING:
+ long bytes = currentPlaying.getPartialFile().length();
+ statusTextView.setText(getResources().getString(R.string.download_playerstate_downloading, Util.formatLocalizedBytes(bytes, this)));
+ break;
+ case PREPARING:
+ statusTextView.setText(R.string.download_playerstate_buffering);
+ break;
+ case STARTED:
+ if (getDownloadService().isShufflePlayEnabled()) {
+ statusTextView.setText(R.string.download_playerstate_playing_shuffle);
+ } else {
+ statusTextView.setText(null);
+ }
+ break;
+ default:
+ statusTextView.setText(null);
+ break;
+ }
+
+ switch (playerState) {
+ case STARTED:
+ pauseButton.setVisibility(View.VISIBLE);
+ stopButton.setVisibility(View.GONE);
+ startButton.setVisibility(View.GONE);
+ break;
+ case DOWNLOADING:
+ case PREPARING:
+ pauseButton.setVisibility(View.GONE);
+ stopButton.setVisibility(View.VISIBLE);
+ startButton.setVisibility(View.GONE);
+ break;
+ default:
+ pauseButton.setVisibility(View.GONE);
+ stopButton.setVisibility(View.GONE);
+ startButton.setVisibility(View.VISIBLE);
+ break;
+ }
+
+ jukeboxButton.setTextColor(getDownloadService().isJukeboxEnabled() ? COLOR_BUTTON_ENABLED : COLOR_BUTTON_DISABLED);
+ }
+
+ private class SongListAdapter extends ArrayAdapter<DownloadFile> {
+ public SongListAdapter(List<DownloadFile> entries) {
+ super(DownloadActivity.this, android.R.layout.simple_list_item_1, entries);
+ }
+
+ @Override
+ public View getView(int position, View convertView, ViewGroup parent) {
+ SongView view;
+ if (convertView != null && convertView instanceof SongView) {
+ view = (SongView) convertView;
+ } else {
+ view = new SongView(DownloadActivity.this);
+ }
+ DownloadFile downloadFile = getItem(position);
+ view.setSong(downloadFile.getSong(), false);
+ return view;
+ }
+ }
+
+ @Override
+ public boolean onTouchEvent(MotionEvent me) {
+ return gestureScanner.onTouchEvent(me);
+ }
+
+ @Override
+ public boolean onDown(MotionEvent me) {
+ return false;
+ }
+
+ @Override
+ public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) {
+
+ DownloadService downloadService = getDownloadService();
+ if (downloadService == null) {
+ return false;
+ }
+
+ // Right to Left swipe
+ if (e1.getX() - e2.getX() > swipeDistance && Math.abs(velocityX) > swipeVelocity) {
+ warnIfNetworkOrStorageUnavailable();
+ if (downloadService.getCurrentPlayingIndex() < downloadService.size() - 1) {
+ downloadService.next();
+ onCurrentChanged();
+ onProgressChanged();
+ }
+ return true;
+ }
+
+ // Left to Right swipe
+ if (e2.getX() - e1.getX() > swipeDistance && Math.abs(velocityX) > swipeVelocity) {
+ warnIfNetworkOrStorageUnavailable();
+ downloadService.previous();
+ onCurrentChanged();
+ onProgressChanged();
+ return true;
+ }
+
+ // Top to Bottom swipe
+ if (e2.getY() - e1.getY() > swipeDistance && Math.abs(velocityY) > swipeVelocity) {
+ warnIfNetworkOrStorageUnavailable();
+ downloadService.seekTo(downloadService.getPlayerPosition() + 30000);
+ onProgressChanged();
+ return true;
+ }
+
+ // Bottom to Top swipe
+ if (e1.getY() - e2.getY() > swipeDistance && Math.abs(velocityY) > swipeVelocity) {
+ warnIfNetworkOrStorageUnavailable();
+ downloadService.seekTo(downloadService.getPlayerPosition() - 8000);
+ onProgressChanged();
+ return true;
+ }
+
+ return false;
+ }
+
+ @Override
+ public void onLongPress(MotionEvent e) {
+ }
+
+ @Override
+ public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX, float distanceY) {
+ return false;
+ }
+
+ @Override
+ public void onShowPress(MotionEvent e) {
+ }
+
+ @Override
+ public boolean onSingleTapUp(MotionEvent e) {
+ return false;
+ }
+}
diff --git a/subsonic-android/src/net/sourceforge/subsonic/androidapp/activity/EqualizerActivity.java b/subsonic-android/src/net/sourceforge/subsonic/androidapp/activity/EqualizerActivity.java
new file mode 100644
index 00000000..daf6193e
--- /dev/null
+++ b/subsonic-android/src/net/sourceforge/subsonic/androidapp/activity/EqualizerActivity.java
@@ -0,0 +1,181 @@
+/*
+ This file is part of Subsonic.
+
+ Subsonic is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ Subsonic is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with Subsonic. If not, see <http://www.gnu.org/licenses/>.
+
+ Copyright 2011 (C) Sindre Mehus
+ */
+package net.sourceforge.subsonic.androidapp.activity;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import android.app.Activity;
+import android.media.audiofx.Equalizer;
+import android.os.Bundle;
+import android.view.ContextMenu;
+import android.view.LayoutInflater;
+import android.view.MenuItem;
+import android.view.View;
+import android.widget.CheckBox;
+import android.widget.CompoundButton;
+import android.widget.LinearLayout;
+import android.widget.SeekBar;
+import android.widget.TextView;
+import net.sourceforge.subsonic.androidapp.R;
+import net.sourceforge.subsonic.androidapp.audiofx.EqualizerController;
+import net.sourceforge.subsonic.androidapp.service.DownloadServiceImpl;
+
+/**
+ * Equalizer controls.
+ *
+ * @author Sindre Mehus
+ * @version $Id$
+ */
+public class EqualizerActivity extends Activity {
+
+ private static final int MENU_GROUP_PRESET = 100;
+
+ private final Map<Short, SeekBar> bars = new HashMap<Short, SeekBar>();
+ private EqualizerController equalizerController;
+ private Equalizer equalizer;
+
+ @Override
+ public void onCreate(Bundle bundle) {
+ super.onCreate(bundle);
+ setContentView(R.layout.equalizer);
+ equalizerController = DownloadServiceImpl.getInstance().getEqualizerController();
+ equalizer = equalizerController.getEqualizer();
+
+ initEqualizer();
+
+ final View presetButton = findViewById(R.id.equalizer_preset);
+ registerForContextMenu(presetButton);
+ presetButton.setOnClickListener(new View.OnClickListener() {
+ @Override
+ public void onClick(View view) {
+ presetButton.showContextMenu();
+ }
+ });
+
+ CheckBox enabledCheckBox = (CheckBox) findViewById(R.id.equalizer_enabled);
+ enabledCheckBox.setChecked(equalizer.getEnabled());
+ enabledCheckBox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
+ @Override
+ public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
+ setEqualizerEnabled(b);
+ }
+ });
+ }
+
+ @Override
+ protected void onPause() {
+ super.onPause();
+ equalizerController.saveSettings();
+ }
+
+ @Override
+ public void onCreateContextMenu(ContextMenu menu, View view, ContextMenu.ContextMenuInfo menuInfo) {
+ super.onCreateContextMenu(menu, view, menuInfo);
+
+ short currentPreset;
+ try {
+ currentPreset = equalizer.getCurrentPreset();
+ } catch (Exception x) {
+ currentPreset = -1;
+ }
+
+ for (short preset = 0; preset < equalizer.getNumberOfPresets(); preset++) {
+ MenuItem menuItem = menu.add(MENU_GROUP_PRESET, preset, preset, equalizer.getPresetName(preset));
+ if (preset == currentPreset) {
+ menuItem.setChecked(true);
+ }
+ }
+ menu.setGroupCheckable(MENU_GROUP_PRESET, true, true);
+ }
+
+ @Override
+ public boolean onContextItemSelected(MenuItem menuItem) {
+ short preset = (short) menuItem.getItemId();
+ equalizer.usePreset(preset);
+ updateBars();
+ return true;
+ }
+
+ private void setEqualizerEnabled(boolean enabled) {
+ equalizer.setEnabled(enabled);
+ updateBars();
+ }
+
+ private void updateBars() {
+
+ for (Map.Entry<Short, SeekBar> entry : bars.entrySet()) {
+ short band = entry.getKey();
+ SeekBar bar = entry.getValue();
+ bar.setEnabled(equalizer.getEnabled());
+ short minEQLevel = equalizer.getBandLevelRange()[0];
+ bar.setProgress(equalizer.getBandLevel(band) - minEQLevel);
+ }
+ }
+
+ private void initEqualizer() {
+ LinearLayout layout = (LinearLayout) findViewById(R.id.equalizer_layout);
+
+ final short minEQLevel = equalizer.getBandLevelRange()[0];
+ final short maxEQLevel = equalizer.getBandLevelRange()[1];
+
+ for (short i = 0; i < equalizer.getNumberOfBands(); i++) {
+ final short band = i;
+
+ View bandBar = LayoutInflater.from(this).inflate(R.layout.equalizer_bar, null);
+ TextView freqTextView = (TextView) bandBar.findViewById(R.id.equalizer_frequency);
+ final TextView levelTextView = (TextView) bandBar.findViewById(R.id.equalizer_level);
+ SeekBar bar = (SeekBar) bandBar.findViewById(R.id.equalizer_bar);
+
+ freqTextView.setText((equalizer.getCenterFreq(band) / 1000) + " Hz");
+
+ bars.put(band, bar);
+ bar.setMax(maxEQLevel - minEQLevel);
+ short level = equalizer.getBandLevel(band);
+ bar.setProgress(level - minEQLevel);
+ bar.setEnabled(equalizer.getEnabled());
+ updateLevelText(levelTextView, level);
+
+ bar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
+ @Override
+ public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
+ short level = (short) (progress + minEQLevel);
+ if (fromUser) {
+ equalizer.setBandLevel(band, level);
+ }
+ updateLevelText(levelTextView, level);
+ }
+
+ @Override
+ public void onStartTrackingTouch(SeekBar seekBar) {
+ }
+
+ @Override
+ public void onStopTrackingTouch(SeekBar seekBar) {
+ }
+ });
+ layout.addView(bandBar);
+ }
+ }
+
+ private void updateLevelText(TextView levelTextView, short level) {
+ levelTextView.setText((level > 0 ? "+" : "") + level / 100 + " dB");
+ }
+
+}
diff --git a/subsonic-android/src/net/sourceforge/subsonic/androidapp/activity/HelpActivity.java b/subsonic-android/src/net/sourceforge/subsonic/androidapp/activity/HelpActivity.java
new file mode 100644
index 00000000..4b2eb63b
--- /dev/null
+++ b/subsonic-android/src/net/sourceforge/subsonic/androidapp/activity/HelpActivity.java
@@ -0,0 +1,117 @@
+/*
+ This file is part of Subsonic.
+
+ Subsonic is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ Subsonic is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with Subsonic. If not, see <http://www.gnu.org/licenses/>.
+
+ Copyright 2009 (C) Sindre Mehus
+ */
+
+package net.sourceforge.subsonic.androidapp.activity;
+
+import android.app.Activity;
+import android.os.Bundle;
+import android.view.KeyEvent;
+import android.view.View;
+import android.view.Window;
+import android.webkit.WebView;
+import android.webkit.WebViewClient;
+import android.widget.Button;
+import net.sourceforge.subsonic.androidapp.R;
+import net.sourceforge.subsonic.androidapp.util.Util;
+
+/**
+ * An HTML-based help screen with Back and Done buttons at the bottom.
+ *
+ * @author Sindre Mehus
+ */
+public final class HelpActivity extends Activity {
+
+ private WebView webView;
+ private Button backButton;
+
+ @Override
+ protected void onCreate(Bundle bundle) {
+ super.onCreate(bundle);
+ getWindow().requestFeature(Window.FEATURE_INDETERMINATE_PROGRESS);
+
+ setContentView(R.layout.help);
+
+ webView = (WebView) findViewById(R.id.help_contents);
+ webView.getSettings().setJavaScriptEnabled(true);
+ webView.setWebViewClient(new HelpClient());
+ if (bundle != null) {
+ webView.restoreState(bundle);
+ } else {
+ webView.loadUrl(getResources().getString(R.string.help_url));
+ }
+
+ backButton = (Button) findViewById(R.id.help_back);
+ backButton.setOnClickListener(new Button.OnClickListener() {
+ @Override
+ public void onClick(View view) {
+ webView.goBack();
+ }
+ });
+
+ Button doneButton = (Button) findViewById(R.id.help_close);
+ doneButton.setOnClickListener(new Button.OnClickListener() {
+ @Override
+ public void onClick(View view) {
+ finish();
+ }
+ });
+ }
+
+ @Override
+ public void onResume() {
+ super.onResume();
+ }
+
+ @Override
+ protected void onSaveInstanceState(Bundle state) {
+ webView.saveState(state);
+ }
+
+ @Override
+ public boolean onKeyDown(int keyCode, KeyEvent event) {
+ if (keyCode == KeyEvent.KEYCODE_BACK) {
+ if (webView.canGoBack()) {
+ webView.goBack();
+ return true;
+ }
+ }
+ return super.onKeyDown(keyCode, event);
+ }
+
+ private final class HelpClient extends WebViewClient {
+ @Override
+ public void onLoadResource(WebView webView, String url) {
+ setProgressBarIndeterminateVisibility(true);
+ setTitle(getResources().getString(R.string.help_loading));
+ super.onLoadResource(webView, url);
+ }
+
+ @Override
+ public void onPageFinished(WebView view, String url) {
+ setProgressBarIndeterminateVisibility(false);
+ setTitle(view.getTitle());
+ backButton.setEnabled(view.canGoBack());
+ }
+
+ @Override
+ public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
+ Util.toast(HelpActivity.this, description);
+ }
+ }
+}
diff --git a/subsonic-android/src/net/sourceforge/subsonic/androidapp/activity/LyricsActivity.java b/subsonic-android/src/net/sourceforge/subsonic/androidapp/activity/LyricsActivity.java
new file mode 100644
index 00000000..0ec75e2c
--- /dev/null
+++ b/subsonic-android/src/net/sourceforge/subsonic/androidapp/activity/LyricsActivity.java
@@ -0,0 +1,72 @@
+/*
+ This file is part of Subsonic.
+
+ Subsonic is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ Subsonic is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with Subsonic. If not, see <http://www.gnu.org/licenses/>.
+
+ Copyright 2009 (C) Sindre Mehus
+ */
+
+package net.sourceforge.subsonic.androidapp.activity;
+
+import android.os.Bundle;
+import android.widget.TextView;
+import net.sourceforge.subsonic.androidapp.R;
+import net.sourceforge.subsonic.androidapp.domain.Lyrics;
+import net.sourceforge.subsonic.androidapp.service.MusicService;
+import net.sourceforge.subsonic.androidapp.service.MusicServiceFactory;
+import net.sourceforge.subsonic.androidapp.util.BackgroundTask;
+import net.sourceforge.subsonic.androidapp.util.Constants;
+import net.sourceforge.subsonic.androidapp.util.TabActivityBackgroundTask;
+
+/**
+ * Displays song lyrics.
+ *
+ * @author Sindre Mehus
+ */
+public final class LyricsActivity extends SubsonicTabActivity {
+
+ @Override
+ protected void onCreate(Bundle bundle) {
+ super.onCreate(bundle);
+ setContentView(R.layout.lyrics);
+ load();
+ }
+
+ private void load() {
+ BackgroundTask<Lyrics> task = new TabActivityBackgroundTask<Lyrics>(this) {
+ @Override
+ protected Lyrics doInBackground() throws Throwable {
+ String artist = getIntent().getStringExtra(Constants.INTENT_EXTRA_NAME_ARTIST);
+ String title = getIntent().getStringExtra(Constants.INTENT_EXTRA_NAME_TITLE);
+ MusicService musicService = MusicServiceFactory.getMusicService(LyricsActivity.this);
+ return musicService.getLyrics(artist, title, LyricsActivity.this, this);
+ }
+
+ @Override
+ protected void done(Lyrics result) {
+ TextView artistView = (TextView) findViewById(R.id.lyrics_artist);
+ TextView titleView = (TextView) findViewById(R.id.lyrics_title);
+ TextView textView = (TextView) findViewById(R.id.lyrics_text);
+ if (result != null && result.getArtist() != null) {
+ artistView.setText(result.getArtist());
+ titleView.setText(result.getTitle());
+ textView.setText(result.getText());
+ } else {
+ artistView.setText(R.string.lyrics_nomatch);
+ }
+ }
+ };
+ task.execute();
+ }
+} \ No newline at end of file
diff --git a/subsonic-android/src/net/sourceforge/subsonic/androidapp/activity/MainActivity.java b/subsonic-android/src/net/sourceforge/subsonic/androidapp/activity/MainActivity.java
new file mode 100644
index 00000000..c63a391b
--- /dev/null
+++ b/subsonic-android/src/net/sourceforge/subsonic/androidapp/activity/MainActivity.java
@@ -0,0 +1,258 @@
+/*
+ This file is part of Subsonic.
+
+ Subsonic is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ Subsonic is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with Subsonic. If not, see <http://www.gnu.org/licenses/>.
+
+ Copyright 2009 (C) Sindre Mehus
+ */
+
+package net.sourceforge.subsonic.androidapp.activity;
+
+import java.util.Arrays;
+
+import net.sourceforge.subsonic.androidapp.R;
+import net.sourceforge.subsonic.androidapp.service.DownloadService;
+import net.sourceforge.subsonic.androidapp.service.DownloadServiceImpl;
+import net.sourceforge.subsonic.androidapp.util.Constants;
+import net.sourceforge.subsonic.androidapp.util.MergeAdapter;
+import net.sourceforge.subsonic.androidapp.util.Util;
+import net.sourceforge.subsonic.androidapp.util.FileUtil;
+import android.content.Intent;
+import android.content.SharedPreferences;
+import android.os.Bundle;
+import android.preference.PreferenceManager;
+import android.view.ContextMenu;
+import android.view.LayoutInflater;
+import android.view.MenuItem;
+import android.view.View;
+import android.widget.AdapterView;
+import android.widget.ImageButton;
+import android.widget.ListView;
+import android.widget.TextView;
+
+public class MainActivity extends SubsonicTabActivity {
+
+ private static final int MENU_GROUP_SERVER = 10;
+ private static final int MENU_ITEM_SERVER_1 = 101;
+ private static final int MENU_ITEM_SERVER_2 = 102;
+ private static final int MENU_ITEM_SERVER_3 = 103;
+ private static final int MENU_ITEM_OFFLINE = 104;
+
+ private String theme;
+
+ private static boolean infoDialogDisplayed;
+
+ /**
+ * Called when the activity is first created.
+ */
+ @Override
+ public void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ if (getIntent().hasExtra(Constants.INTENT_EXTRA_NAME_EXIT)) {
+ exit();
+ }
+ setContentView(R.layout.main);
+
+ loadSettings();
+
+ View buttons = LayoutInflater.from(this).inflate(R.layout.main_buttons, null);
+
+ final View serverButton = buttons.findViewById(R.id.main_select_server);
+ final TextView serverTextView = (TextView) serverButton.findViewById(R.id.main_select_server_2);
+
+ final View albumsTitle = buttons.findViewById(R.id.main_albums);
+ final View albumsNewestButton = buttons.findViewById(R.id.main_albums_newest);
+ final View albumsRandomButton = buttons.findViewById(R.id.main_albums_random);
+ final View albumsHighestButton = buttons.findViewById(R.id.main_albums_highest);
+ final View albumsRecentButton = buttons.findViewById(R.id.main_albums_recent);
+ final View albumsFrequentButton = buttons.findViewById(R.id.main_albums_frequent);
+
+ final View dummyView = findViewById(R.id.main_dummy);
+
+ int instance = Util.getActiveServer(this);
+ String name = Util.getServerName(this, instance);
+ serverTextView.setText(name);
+
+ ListView list = (ListView) findViewById(R.id.main_list);
+
+ MergeAdapter adapter = new MergeAdapter();
+ adapter.addViews(Arrays.asList(serverButton), true);
+ if (!Util.isOffline(this)) {
+ adapter.addView(albumsTitle, false);
+ adapter.addViews(Arrays.asList(albumsNewestButton, albumsRandomButton, albumsHighestButton, albumsRecentButton, albumsFrequentButton), true);
+ }
+ list.setAdapter(adapter);
+ registerForContextMenu(dummyView);
+
+ list.setOnItemClickListener(new AdapterView.OnItemClickListener() {
+ @Override
+ public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
+ if (view == serverButton) {
+ dummyView.showContextMenu();
+ } else if (view == albumsNewestButton) {
+ showAlbumList("newest");
+ } else if (view == albumsRandomButton) {
+ showAlbumList("random");
+ } else if (view == albumsHighestButton) {
+ showAlbumList("highest");
+ } else if (view == albumsRecentButton) {
+ showAlbumList("recent");
+ } else if (view == albumsFrequentButton) {
+ showAlbumList("frequent");
+ }
+ }
+ });
+
+ // Title: Subsonic
+ setTitle(R.string.common_appname);
+
+ // Button 1: shuffle
+ ImageButton actionShuffleButton = (ImageButton)findViewById(R.id.action_button_1);
+ actionShuffleButton.setImageResource(R.drawable.action_shuffle);
+ actionShuffleButton.setOnClickListener(new View.OnClickListener() {
+ @Override
+ public void onClick(View view) {
+ Intent intent = new Intent(MainActivity.this, DownloadActivity.class);
+ intent.putExtra(Constants.INTENT_EXTRA_NAME_SHUFFLE, true);
+ Util.startActivityWithoutTransition(MainActivity.this, intent);
+ }
+ });
+
+ // Button 2: search
+ ImageButton actionSearchButton = (ImageButton)findViewById(R.id.action_button_2);
+ actionSearchButton.setImageResource(R.drawable.action_search);
+ actionSearchButton.setOnClickListener(new View.OnClickListener() {
+ @Override
+ public void onClick(View view) {
+ Intent intent = new Intent(MainActivity.this, SearchActivity.class);
+ intent.putExtra(Constants.INTENT_EXTRA_REQUEST_SEARCH, true);
+ Util.startActivityWithoutTransition(MainActivity.this, intent);
+ }
+ });
+
+ // Remember the current theme.
+ theme = Util.getTheme(this);
+
+ showInfoDialog();
+ }
+
+ private void loadSettings() {
+ PreferenceManager.setDefaultValues(this, R.xml.settings, false);
+ SharedPreferences prefs = Util.getPreferences(this);
+ if (!prefs.contains(Constants.PREFERENCES_KEY_CACHE_LOCATION)) {
+ SharedPreferences.Editor editor = prefs.edit();
+ editor.putString(Constants.PREFERENCES_KEY_CACHE_LOCATION, FileUtil.getDefaultMusicDirectory().getPath());
+ editor.commit();
+ }
+ }
+
+ @Override
+ protected void onResume() {
+ super.onResume();
+
+ // Restart activity if theme has changed.
+ if (theme != null && !theme.equals(Util.getTheme(this))) {
+ restart();
+ }
+ }
+
+ @Override
+ public void onCreateContextMenu(ContextMenu menu, View view, ContextMenu.ContextMenuInfo menuInfo) {
+ super.onCreateContextMenu(menu, view, menuInfo);
+
+ MenuItem menuItem1 = menu.add(MENU_GROUP_SERVER, MENU_ITEM_SERVER_1, MENU_ITEM_SERVER_1, Util.getServerName(this, 1));
+ MenuItem menuItem2 = menu.add(MENU_GROUP_SERVER, MENU_ITEM_SERVER_2, MENU_ITEM_SERVER_2, Util.getServerName(this, 2));
+ MenuItem menuItem3 = menu.add(MENU_GROUP_SERVER, MENU_ITEM_SERVER_3, MENU_ITEM_SERVER_3, Util.getServerName(this, 3));
+ MenuItem menuItem4 = menu.add(MENU_GROUP_SERVER, MENU_ITEM_OFFLINE, MENU_ITEM_OFFLINE, Util.getServerName(this, 0));
+ menu.setGroupCheckable(MENU_GROUP_SERVER, true, true);
+ menu.setHeaderTitle(R.string.main_select_server);
+
+ switch (Util.getActiveServer(this)) {
+ case 0:
+ menuItem4.setChecked(true);
+ break;
+ case 1:
+ menuItem1.setChecked(true);
+ break;
+ case 2:
+ menuItem2.setChecked(true);
+ break;
+ case 3:
+ menuItem3.setChecked(true);
+ break;
+ }
+ }
+
+ @Override
+ public boolean onContextItemSelected(MenuItem menuItem) {
+ switch (menuItem.getItemId()) {
+ case MENU_ITEM_OFFLINE:
+ setActiveServer(0);
+ break;
+ case MENU_ITEM_SERVER_1:
+ setActiveServer(1);
+ break;
+ case MENU_ITEM_SERVER_2:
+ setActiveServer(2);
+ break;
+ case MENU_ITEM_SERVER_3:
+ setActiveServer(3);
+ break;
+ default:
+ return super.onContextItemSelected(menuItem);
+ }
+
+ // Restart activity
+ restart();
+ return true;
+ }
+
+ private void setActiveServer(int instance) {
+ if (Util.getActiveServer(this) != instance) {
+ DownloadService service = getDownloadService();
+ if (service != null) {
+ service.clearIncomplete();
+ }
+ Util.setActiveServer(this, instance);
+ }
+ }
+
+ private void restart() {
+ Intent intent = new Intent(this, MainActivity.class);
+ intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
+ Util.startActivityWithoutTransition(this, intent);
+ }
+
+ private void exit() {
+ stopService(new Intent(this, DownloadServiceImpl.class));
+ finish();
+ }
+
+ private void showInfoDialog() {
+ if (!infoDialogDisplayed) {
+ infoDialogDisplayed = true;
+ if (Util.getRestUrl(this, null).contains("demo.subsonic.org")) {
+ Util.info(this, R.string.main_welcome_title, R.string.main_welcome_text);
+ }
+ }
+ }
+
+ private void showAlbumList(String type) {
+ Intent intent = new Intent(this, SelectAlbumActivity.class);
+ intent.putExtra(Constants.INTENT_EXTRA_NAME_ALBUM_LIST_TYPE, type);
+ intent.putExtra(Constants.INTENT_EXTRA_NAME_ALBUM_LIST_SIZE, 20);
+ intent.putExtra(Constants.INTENT_EXTRA_NAME_ALBUM_LIST_OFFSET, 0);
+ Util.startActivityWithoutTransition(this, intent);
+ }
+} \ No newline at end of file
diff --git a/subsonic-android/src/net/sourceforge/subsonic/androidapp/activity/PlayVideoActivity.java b/subsonic-android/src/net/sourceforge/subsonic/androidapp/activity/PlayVideoActivity.java
new file mode 100644
index 00000000..ea332ca0
--- /dev/null
+++ b/subsonic-android/src/net/sourceforge/subsonic/androidapp/activity/PlayVideoActivity.java
@@ -0,0 +1,147 @@
+/*
+ This file is part of Subsonic.
+
+ Subsonic is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ Subsonic is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with Subsonic. If not, see <http://www.gnu.org/licenses/>.
+
+ Copyright 2009 (C) Sindre Mehus
+ */
+
+package net.sourceforge.subsonic.androidapp.activity;
+
+import java.lang.reflect.Method;
+
+import android.app.Activity;
+import android.graphics.Bitmap;
+import android.media.AudioManager;
+import android.os.Bundle;
+import android.util.Log;
+import android.view.Window;
+import android.webkit.WebView;
+import android.webkit.WebViewClient;
+import android.content.pm.PackageInfo;
+import android.content.pm.PackageManager;
+import net.sourceforge.subsonic.androidapp.R;
+import net.sourceforge.subsonic.androidapp.service.MusicServiceFactory;
+import net.sourceforge.subsonic.androidapp.util.Constants;
+import net.sourceforge.subsonic.androidapp.util.Util;
+
+/**
+ * Plays videos in a web page.
+ *
+ * @author Sindre Mehus
+ */
+public final class PlayVideoActivity extends Activity {
+
+ private static final String TAG = PlayVideoActivity.class.getSimpleName();
+ private WebView webView;
+
+ @Override
+ protected void onCreate(Bundle bundle) {
+ super.onCreate(bundle);
+ getWindow().requestFeature(Window.FEATURE_NO_TITLE);
+ setVolumeControlStream(AudioManager.STREAM_MUSIC);
+
+ setContentView(R.layout.play_video);
+
+ webView = (WebView) findViewById(R.id.play_video_contents);
+ webView.getSettings().setJavaScriptEnabled(true);
+ webView.getSettings().setPluginsEnabled(true);
+ webView.getSettings().setAllowFileAccess(true);
+ webView.getSettings().setSupportZoom(true);
+ webView.getSettings().setBuiltInZoomControls(true);
+
+ webView.setWebViewClient(new Client());
+ if (bundle != null) {
+ webView.restoreState(bundle);
+ } else {
+ webView.loadUrl(getVideoUrl());
+ }
+
+ // Show warning if Flash plugin is not installed.
+ if (isFlashPluginInstalled()) {
+ Util.toast(this, R.string.play_video_loading, false);
+ } else {
+ Util.toast(this, R.string.play_video_noplugin, false);
+ }
+ }
+
+ @Override
+ protected void onPause() {
+ super.onPause();
+ callHiddenWebViewMethod("onPause");
+ }
+
+ @Override
+ protected void onResume() {
+ super.onResume();
+ callHiddenWebViewMethod("onResume");
+ }
+
+ private String getVideoUrl() {
+ String id = getIntent().getStringExtra(Constants.INTENT_EXTRA_NAME_ID);
+ return MusicServiceFactory.getMusicService(this).getVideoUrl(this, id);
+ }
+
+ @Override
+ protected void onSaveInstanceState(Bundle state) {
+ webView.saveState(state);
+ }
+
+ private void callHiddenWebViewMethod(String name){
+ if( webView != null ){
+ try {
+ Method method = WebView.class.getMethod(name);
+ method.invoke(webView);
+ } catch (Throwable x) {
+ Log.e(TAG, "Failed to invoke " + name, x);
+ }
+ }
+ }
+
+ private boolean isFlashPluginInstalled() {
+ try {
+ PackageInfo packageInfo = getPackageManager().getPackageInfo("com.adobe.flashplayer", 0);
+ return packageInfo != null;
+ } catch (PackageManager.NameNotFoundException x) {
+ return false;
+ }
+ }
+
+ private final class Client extends WebViewClient {
+
+ @Override
+ public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
+ Util.toast(PlayVideoActivity.this, description);
+ Log.e(TAG, "Error: " + description);
+ }
+
+ @Override
+ public void onLoadResource(WebView view, String url) {
+ super.onLoadResource(view, url);
+ Log.d(TAG, "onLoadResource: " + url);
+ }
+
+ @Override
+ public void onPageStarted(WebView view, String url, Bitmap favicon) {
+ super.onPageStarted(view, url, favicon);
+ Log.d(TAG, "onPageStarted: " + url);
+ }
+
+ @Override
+ public void onPageFinished(WebView view, String url) {
+ super.onPageFinished(view, url);
+ Log.d(TAG, "onPageFinished: " + url);
+ }
+ }
+}
diff --git a/subsonic-android/src/net/sourceforge/subsonic/androidapp/activity/QueryReceiverActivity.java b/subsonic-android/src/net/sourceforge/subsonic/androidapp/activity/QueryReceiverActivity.java
new file mode 100644
index 00000000..35b5ccaf
--- /dev/null
+++ b/subsonic-android/src/net/sourceforge/subsonic/androidapp/activity/QueryReceiverActivity.java
@@ -0,0 +1,56 @@
+/*
+ This file is part of Subsonic.
+
+ Subsonic is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ Subsonic is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with Subsonic. If not, see <http://www.gnu.org/licenses/>.
+
+ Copyright 2009 (C) Sindre Mehus
+ */
+
+package net.sourceforge.subsonic.androidapp.activity;
+
+import android.app.Activity;
+import android.app.SearchManager;
+import android.content.Intent;
+import android.os.Bundle;
+import android.provider.SearchRecentSuggestions;
+import net.sourceforge.subsonic.androidapp.util.Constants;
+import net.sourceforge.subsonic.androidapp.util.Util;
+import net.sourceforge.subsonic.androidapp.provider.SearchSuggestionProvider;
+
+/**
+ * Receives search queries and forwards to the SelectAlbumActivity.
+ *
+ * @author Sindre Mehus
+ */
+public class QueryReceiverActivity extends Activity {
+
+ @Override
+ public void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+
+ String query = getIntent().getStringExtra(SearchManager.QUERY);
+
+ if (query != null) {
+ SearchRecentSuggestions suggestions = new SearchRecentSuggestions(this, SearchSuggestionProvider.AUTHORITY,
+ SearchSuggestionProvider.MODE);
+ suggestions.saveRecentQuery(query, null);
+
+ Intent intent = new Intent(QueryReceiverActivity.this, SearchActivity.class);
+ intent.putExtra(Constants.INTENT_EXTRA_NAME_QUERY, query);
+ Util.startActivityWithoutTransition(QueryReceiverActivity.this, intent);
+ }
+ finish();
+ Util.disablePendingTransition(this);
+ }
+} \ No newline at end of file
diff --git a/subsonic-android/src/net/sourceforge/subsonic/androidapp/activity/SearchActivity.java b/subsonic-android/src/net/sourceforge/subsonic/androidapp/activity/SearchActivity.java
new file mode 100644
index 00000000..73b787a0
--- /dev/null
+++ b/subsonic-android/src/net/sourceforge/subsonic/androidapp/activity/SearchActivity.java
@@ -0,0 +1,368 @@
+/*
+ This file is part of Subsonic.
+
+ Subsonic is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ Subsonic is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with Subsonic. If not, see <http://www.gnu.org/licenses/>.
+
+ Copyright 2009 (C) Sindre Mehus
+ */
+
+package net.sourceforge.subsonic.androidapp.activity;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Arrays;
+
+import android.content.Intent;
+import android.os.Bundle;
+import android.view.ContextMenu;
+import android.view.LayoutInflater;
+import android.view.MenuInflater;
+import android.view.View;
+import android.view.MenuItem;
+import android.widget.AdapterView;
+import android.widget.ImageButton;
+import android.widget.ListAdapter;
+import android.widget.ListView;
+import android.widget.TextView;
+import android.net.Uri;
+import net.sourceforge.subsonic.androidapp.R;
+import net.sourceforge.subsonic.androidapp.domain.Artist;
+import net.sourceforge.subsonic.androidapp.domain.MusicDirectory;
+import net.sourceforge.subsonic.androidapp.domain.SearchCritera;
+import net.sourceforge.subsonic.androidapp.domain.SearchResult;
+import net.sourceforge.subsonic.androidapp.service.MusicService;
+import net.sourceforge.subsonic.androidapp.service.MusicServiceFactory;
+import net.sourceforge.subsonic.androidapp.service.DownloadService;
+import net.sourceforge.subsonic.androidapp.util.ArtistAdapter;
+import net.sourceforge.subsonic.androidapp.util.BackgroundTask;
+import net.sourceforge.subsonic.androidapp.util.Constants;
+import net.sourceforge.subsonic.androidapp.util.EntryAdapter;
+import net.sourceforge.subsonic.androidapp.util.MergeAdapter;
+import net.sourceforge.subsonic.androidapp.util.TabActivityBackgroundTask;
+import net.sourceforge.subsonic.androidapp.util.Util;
+
+/**
+ * Performs searches and displays the matching artists, albums and songs.
+ *
+ * @author Sindre Mehus
+ */
+public class SearchActivity extends SubsonicTabActivity {
+
+ private static final int DEFAULT_ARTISTS = 3;
+ private static final int DEFAULT_ALBUMS = 5;
+ private static final int DEFAULT_SONGS = 10;
+
+ private static final int MAX_ARTISTS = 10;
+ private static final int MAX_ALBUMS = 20;
+ private static final int MAX_SONGS = 25;
+ private ListView list;
+
+ private View artistsHeading;
+ private View albumsHeading;
+ private View songsHeading;
+ private TextView searchButton;
+ private View moreArtistsButton;
+ private View moreAlbumsButton;
+ private View moreSongsButton;
+ private SearchResult searchResult;
+ private MergeAdapter mergeAdapter;
+ private ArtistAdapter artistAdapter;
+ private ListAdapter moreArtistsAdapter;
+ private EntryAdapter albumAdapter;
+ private ListAdapter moreAlbumsAdapter;
+ private ListAdapter moreSongsAdapter;
+ private EntryAdapter songAdapter;
+
+ @Override
+ public void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ setContentView(R.layout.search);
+
+ setTitle(R.string.search_title);
+
+ View buttons = LayoutInflater.from(this).inflate(R.layout.search_buttons, null);
+
+ artistsHeading = buttons.findViewById(R.id.search_artists);
+ albumsHeading = buttons.findViewById(R.id.search_albums);
+ songsHeading = buttons.findViewById(R.id.search_songs);
+
+ searchButton = (TextView) buttons.findViewById(R.id.search_search);
+ moreArtistsButton = buttons.findViewById(R.id.search_more_artists);
+ moreAlbumsButton = buttons.findViewById(R.id.search_more_albums);
+ moreSongsButton = buttons.findViewById(R.id.search_more_songs);
+
+ list = (ListView) findViewById(R.id.search_list);
+
+ list.setOnItemClickListener(new AdapterView.OnItemClickListener() {
+ @Override
+ public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
+ if (view == searchButton) {
+ onSearchRequested();
+ } else if (view == moreArtistsButton) {
+ expandArtists();
+ } else if (view == moreAlbumsButton) {
+ expandAlbums();
+ } else if (view == moreSongsButton) {
+ expandSongs();
+ } else {
+ Object item = parent.getItemAtPosition(position);
+ if (item instanceof Artist) {
+ onArtistSelected((Artist) item);
+ } else if (item instanceof MusicDirectory.Entry) {
+ MusicDirectory.Entry entry = (MusicDirectory.Entry) item;
+ if (entry.isDirectory()) {
+ onAlbumSelected(entry, false);
+ } else if (entry.isVideo()) {
+ onVideoSelected(entry);
+ } else {
+ onSongSelected(entry, false, true, true, false);
+ }
+
+ }
+ }
+ }
+ });
+ registerForContextMenu(list);
+
+ // Button 1: gone
+ findViewById(R.id.action_button_1).setVisibility(View.GONE);
+
+ // Button 2: search
+ final ImageButton actionSearchButton = (ImageButton)findViewById(R.id.action_button_2);
+ actionSearchButton.setImageResource(R.drawable.action_search);
+ actionSearchButton.setOnClickListener(new View.OnClickListener() {
+ @Override
+ public void onClick(View view) {
+ onSearchRequested();
+ }
+ });
+
+ onNewIntent(getIntent());
+ }
+
+ @Override
+ protected void onNewIntent(Intent intent) {
+ super.onNewIntent(intent);
+ String query = intent.getStringExtra(Constants.INTENT_EXTRA_NAME_QUERY);
+ boolean autoplay = intent.getBooleanExtra(Constants.INTENT_EXTRA_NAME_AUTOPLAY, false);
+ boolean requestsearch = intent.getBooleanExtra(Constants.INTENT_EXTRA_REQUEST_SEARCH, false);
+
+ if (query != null) {
+ mergeAdapter = new MergeAdapter();
+ list.setAdapter(mergeAdapter);
+ search(query, autoplay);
+ } else {
+ populateList();
+ if (requestsearch)
+ onSearchRequested();
+ }
+ }
+
+ @Override
+ public void onCreateContextMenu(ContextMenu menu, View view, ContextMenu.ContextMenuInfo menuInfo) {
+ super.onCreateContextMenu(menu, view, menuInfo);
+
+ AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo) menuInfo;
+ Object selectedItem = list.getItemAtPosition(info.position);
+
+ boolean isArtist = selectedItem instanceof Artist;
+ boolean isAlbum = selectedItem instanceof MusicDirectory.Entry && ((MusicDirectory.Entry) selectedItem).isDirectory();
+ boolean isSong = selectedItem instanceof MusicDirectory.Entry && (!((MusicDirectory.Entry) selectedItem).isDirectory())
+ && (!((MusicDirectory.Entry) selectedItem).isVideo());
+
+ if (isArtist || isAlbum) {
+ MenuInflater inflater = getMenuInflater();
+ inflater.inflate(R.menu.select_album_context, menu);
+ } else if (isSong) {
+ MenuInflater inflater = getMenuInflater();
+ inflater.inflate(R.menu.select_song_context, menu);
+ }
+ }
+
+ @Override
+ public boolean onContextItemSelected(MenuItem menuItem) {
+ AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo) menuItem.getMenuInfo();
+ Object selectedItem = list.getItemAtPosition(info.position);
+
+ Artist artist = selectedItem instanceof Artist ? (Artist) selectedItem : null;
+ MusicDirectory.Entry entry = selectedItem instanceof MusicDirectory.Entry ? (MusicDirectory.Entry) selectedItem : null;
+ String id = artist != null ? artist.getId() : entry.getId();
+
+ switch (menuItem.getItemId()) {
+ case R.id.album_menu_play_now:
+ downloadRecursively(id, false, false, true);
+ break;
+ case R.id.album_menu_play_last:
+ downloadRecursively(id, false, true, false);
+ break;
+ case R.id.album_menu_pin:
+ downloadRecursively(id, true, true, false);
+ break;
+ case R.id.song_menu_play_now:
+ onSongSelected(entry, false, false, true, false);
+ break;
+ case R.id.song_menu_play_next:
+ onSongSelected(entry, false, true, false, true);
+ break;
+ case R.id.song_menu_play_last:
+ onSongSelected(entry, false, true, false, false);
+ break;
+ default:
+ return super.onContextItemSelected(menuItem);
+ }
+
+ return true;
+ }
+
+ private void search(final String query, final boolean autoplay) {
+ BackgroundTask<SearchResult> task = new TabActivityBackgroundTask<SearchResult>(this) {
+ @Override
+ protected SearchResult doInBackground() throws Throwable {
+ SearchCritera criteria = new SearchCritera(query, MAX_ARTISTS, MAX_ALBUMS, MAX_SONGS);
+ MusicService service = MusicServiceFactory.getMusicService(SearchActivity.this);
+ return service.search(criteria, SearchActivity.this, this);
+ }
+
+ @Override
+ protected void done(SearchResult result) {
+ searchResult = result;
+ populateList();
+ if (autoplay) {
+ autoplay();
+ }
+
+ }
+ };
+ task.execute();
+ }
+
+ private void populateList() {
+ mergeAdapter = new MergeAdapter();
+ mergeAdapter.addView(searchButton, true);
+
+ if (searchResult != null) {
+ List<Artist> artists = searchResult.getArtists();
+ if (!artists.isEmpty()) {
+ mergeAdapter.addView(artistsHeading);
+ List<Artist> displayedArtists = new ArrayList<Artist>(artists.subList(0, Math.min(DEFAULT_ARTISTS, artists.size())));
+ artistAdapter = new ArtistAdapter(this, displayedArtists);
+ mergeAdapter.addAdapter(artistAdapter);
+ if (artists.size() > DEFAULT_ARTISTS) {
+ moreArtistsAdapter = mergeAdapter.addView(moreArtistsButton, true);
+ }
+ }
+
+ List<MusicDirectory.Entry> albums = searchResult.getAlbums();
+ if (!albums.isEmpty()) {
+ mergeAdapter.addView(albumsHeading);
+ List<MusicDirectory.Entry> displayedAlbums = new ArrayList<MusicDirectory.Entry>(albums.subList(0, Math.min(DEFAULT_ALBUMS, albums.size())));
+ albumAdapter = new EntryAdapter(this, getImageLoader(), displayedAlbums, false);
+ mergeAdapter.addAdapter(albumAdapter);
+ if (albums.size() > DEFAULT_ALBUMS) {
+ moreAlbumsAdapter = mergeAdapter.addView(moreAlbumsButton, true);
+ }
+ }
+
+ List<MusicDirectory.Entry> songs = searchResult.getSongs();
+ if (!songs.isEmpty()) {
+ mergeAdapter.addView(songsHeading);
+ List<MusicDirectory.Entry> displayedSongs = new ArrayList<MusicDirectory.Entry>(songs.subList(0, Math.min(DEFAULT_SONGS, songs.size())));
+ songAdapter = new EntryAdapter(this, getImageLoader(), displayedSongs, false);
+ mergeAdapter.addAdapter(songAdapter);
+ if (songs.size() > DEFAULT_SONGS) {
+ moreSongsAdapter = mergeAdapter.addView(moreSongsButton, true);
+ }
+ }
+
+ boolean empty = searchResult.getArtists().isEmpty() && searchResult.getAlbums().isEmpty() && searchResult.getSongs().isEmpty();
+ searchButton.setText(empty ? R.string.search_no_match : R.string.search_search);
+ }
+
+ list.setAdapter(mergeAdapter);
+ }
+
+ private void expandArtists() {
+ artistAdapter.clear();
+ for (Artist artist : searchResult.getArtists()) {
+ artistAdapter.add(artist);
+ }
+ artistAdapter.notifyDataSetChanged();
+ mergeAdapter.removeAdapter(moreArtistsAdapter);
+ mergeAdapter.notifyDataSetChanged();
+ }
+
+ private void expandAlbums() {
+ albumAdapter.clear();
+ for (MusicDirectory.Entry album : searchResult.getAlbums()) {
+ albumAdapter.add(album);
+ }
+ albumAdapter.notifyDataSetChanged();
+ mergeAdapter.removeAdapter(moreAlbumsAdapter);
+ mergeAdapter.notifyDataSetChanged();
+ }
+
+ private void expandSongs() {
+ songAdapter.clear();
+ for (MusicDirectory.Entry song : searchResult.getSongs()) {
+ songAdapter.add(song);
+ }
+ songAdapter.notifyDataSetChanged();
+ mergeAdapter.removeAdapter(moreSongsAdapter);
+ mergeAdapter.notifyDataSetChanged();
+ }
+
+ private void onArtistSelected(Artist artist) {
+ Intent intent = new Intent(this, SelectAlbumActivity.class);
+ intent.putExtra(Constants.INTENT_EXTRA_NAME_ID, artist.getId());
+ intent.putExtra(Constants.INTENT_EXTRA_NAME_NAME, artist.getName());
+ Util.startActivityWithoutTransition(this, intent);
+ }
+
+ private void onAlbumSelected(MusicDirectory.Entry album, boolean autoplay) {
+ Intent intent = new Intent(SearchActivity.this, SelectAlbumActivity.class);
+ intent.putExtra(Constants.INTENT_EXTRA_NAME_ID, album.getId());
+ intent.putExtra(Constants.INTENT_EXTRA_NAME_NAME, album.getTitle());
+ intent.putExtra(Constants.INTENT_EXTRA_NAME_AUTOPLAY, autoplay);
+ Util.startActivityWithoutTransition(SearchActivity.this, intent);
+ }
+
+ private void onSongSelected(MusicDirectory.Entry song, boolean save, boolean append, boolean autoplay, boolean playNext) {
+ DownloadService downloadService = getDownloadService();
+ if (downloadService != null) {
+ if (!append) {
+ downloadService.clear();
+ }
+ downloadService.download(Arrays.asList(song), save, false, playNext);
+ if (autoplay) {
+ downloadService.play(downloadService.size() - 1);
+ }
+
+ Util.toast(SearchActivity.this, getResources().getQuantityString(R.plurals.select_album_n_songs_added, 1, 1));
+ }
+ }
+
+ private void onVideoSelected(MusicDirectory.Entry entry) {
+ Intent intent = new Intent(Intent.ACTION_VIEW);
+ intent.setData(Uri.parse(MusicServiceFactory.getMusicService(this).getVideoUrl(this, entry.getId())));
+ startActivity(intent);
+ }
+
+ private void autoplay() {
+ if (!searchResult.getSongs().isEmpty()) {
+ onSongSelected(searchResult.getSongs().get(0), false, false, true, false);
+ } else if (!searchResult.getAlbums().isEmpty()) {
+ onAlbumSelected(searchResult.getAlbums().get(0), true);
+ }
+ }
+} \ No newline at end of file
diff --git a/subsonic-android/src/net/sourceforge/subsonic/androidapp/activity/SelectAlbumActivity.java b/subsonic-android/src/net/sourceforge/subsonic/androidapp/activity/SelectAlbumActivity.java
new file mode 100644
index 00000000..b354599f
--- /dev/null
+++ b/subsonic-android/src/net/sourceforge/subsonic/androidapp/activity/SelectAlbumActivity.java
@@ -0,0 +1,568 @@
+/*
+ This file is part of Subsonic.
+
+ Subsonic is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ Subsonic is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with Subsonic. If not, see <http://www.gnu.org/licenses/>.
+
+ Copyright 2009 (C) Sindre Mehus
+ */
+package net.sourceforge.subsonic.androidapp.activity;
+
+import android.app.AlertDialog;
+import android.content.DialogInterface;
+import android.content.Intent;
+import android.net.Uri;
+import android.os.Bundle;
+import android.util.Log;
+import android.view.ContextMenu;
+import android.view.LayoutInflater;
+import android.view.MenuInflater;
+import android.view.MenuItem;
+import android.view.View;
+import android.widget.AdapterView;
+import android.widget.Button;
+import android.widget.ImageButton;
+import android.widget.ImageView;
+import android.widget.ListView;
+import net.sourceforge.subsonic.androidapp.R;
+import net.sourceforge.subsonic.androidapp.domain.MusicDirectory;
+import net.sourceforge.subsonic.androidapp.service.DownloadFile;
+import net.sourceforge.subsonic.androidapp.service.MusicService;
+import net.sourceforge.subsonic.androidapp.service.MusicServiceFactory;
+import net.sourceforge.subsonic.androidapp.util.Constants;
+import net.sourceforge.subsonic.androidapp.util.EntryAdapter;
+import net.sourceforge.subsonic.androidapp.util.Pair;
+import net.sourceforge.subsonic.androidapp.util.TabActivityBackgroundTask;
+import net.sourceforge.subsonic.androidapp.util.Util;
+
+import java.util.ArrayList;
+import java.util.List;
+
+public class SelectAlbumActivity extends SubsonicTabActivity {
+
+ private static final String TAG = SelectAlbumActivity.class.getSimpleName();
+
+ private ListView entryList;
+ private View footer;
+ private View emptyView;
+ private Button selectButton;
+ private Button playNowButton;
+ private Button playLastButton;
+ private Button pinButton;
+ private Button unpinButton;
+ private Button deleteButton;
+ private Button moreButton;
+ private ImageView coverArtView;
+ private boolean licenseValid;
+ private ImageButton playAllButton;
+
+ /**
+ * Called when the activity is first created.
+ */
+ @Override
+ public void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ setContentView(R.layout.select_album);
+
+ entryList = (ListView) findViewById(R.id.select_album_entries);
+
+ footer = LayoutInflater.from(this).inflate(R.layout.select_album_footer, entryList, false);
+ entryList.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE);
+ entryList.setOnItemClickListener(new AdapterView.OnItemClickListener() {
+ @Override
+ public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
+ if (position >= 0) {
+ MusicDirectory.Entry entry = (MusicDirectory.Entry) parent.getItemAtPosition(position);
+ if (entry.isDirectory()) {
+ Intent intent = new Intent(SelectAlbumActivity.this, SelectAlbumActivity.class);
+ intent.putExtra(Constants.INTENT_EXTRA_NAME_ID, entry.getId());
+ intent.putExtra(Constants.INTENT_EXTRA_NAME_NAME, entry.getTitle());
+ Util.startActivityWithoutTransition(SelectAlbumActivity.this, intent);
+ } else if (entry.isVideo()) {
+ playVideo(entry);
+ } else {
+ enableButtons();
+ }
+ }
+ }
+ });
+
+ coverArtView = (ImageView) findViewById(R.id.actionbar_home_icon);
+ selectButton = (Button) findViewById(R.id.select_album_select);
+ playNowButton = (Button) findViewById(R.id.select_album_play_now);
+ playLastButton = (Button) findViewById(R.id.select_album_play_last);
+ pinButton = (Button) footer.findViewById(R.id.select_album_pin);
+ unpinButton = (Button) footer.findViewById(R.id.select_album_unpin);
+ unpinButton = (Button) footer.findViewById(R.id.select_album_unpin);
+ deleteButton = (Button) footer.findViewById(R.id.select_album_delete);
+ moreButton = (Button) footer.findViewById(R.id.select_album_more);
+ emptyView = findViewById(R.id.select_album_empty);
+
+ selectButton.setOnClickListener(new View.OnClickListener() {
+ @Override
+ public void onClick(View view) {
+ selectAllOrNone();
+ }
+ });
+ playNowButton.setOnClickListener(new View.OnClickListener() {
+ @Override
+ public void onClick(View view) {
+ download(false, false, true, false);
+ selectAll(false, false);
+ }
+ });
+ playLastButton.setOnClickListener(new View.OnClickListener() {
+ @Override
+ public void onClick(View view) {
+ download(true, false, false, false);
+ selectAll(false, false);
+ }
+ });
+ pinButton.setOnClickListener(new View.OnClickListener() {
+ @Override
+ public void onClick(View view) {
+ download(true, true, false, false);
+ selectAll(false, false);
+ }
+ });
+ unpinButton.setOnClickListener(new View.OnClickListener() {
+ @Override
+ public void onClick(View view) {
+ unpin();
+ selectAll(false, false);
+ }
+ });
+ deleteButton.setOnClickListener(new View.OnClickListener() {
+ @Override
+ public void onClick(View view) {
+ delete();
+ selectAll(false, false);
+ }
+ });
+
+ registerForContextMenu(entryList);
+
+ enableButtons();
+
+ String id = getIntent().getStringExtra(Constants.INTENT_EXTRA_NAME_ID);
+ String name = getIntent().getStringExtra(Constants.INTENT_EXTRA_NAME_NAME);
+ String playlistId = getIntent().getStringExtra(Constants.INTENT_EXTRA_NAME_PLAYLIST_ID);
+ String playlistName = getIntent().getStringExtra(Constants.INTENT_EXTRA_NAME_PLAYLIST_NAME);
+ String albumListType = getIntent().getStringExtra(Constants.INTENT_EXTRA_NAME_ALBUM_LIST_TYPE);
+ int albumListSize = getIntent().getIntExtra(Constants.INTENT_EXTRA_NAME_ALBUM_LIST_SIZE, 0);
+ int albumListOffset = getIntent().getIntExtra(Constants.INTENT_EXTRA_NAME_ALBUM_LIST_OFFSET, 0);
+
+ if (playlistId != null) {
+ getPlaylist(playlistId, playlistName);
+ } else if (albumListType != null) {
+ getAlbumList(albumListType, albumListSize, albumListOffset);
+ } else {
+ getMusicDirectory(id, name);
+ }
+
+ // Button 1: play all
+ playAllButton = (ImageButton) findViewById(R.id.action_button_1);
+ playAllButton.setImageResource(R.drawable.action_play_all);
+ playAllButton.setVisibility(View.GONE);
+ playAllButton.setOnClickListener(new View.OnClickListener() {
+ @Override
+ public void onClick(View view) {
+ playAll();
+ }
+ });
+
+ // Button 2: refresh
+ ImageButton refreshButton = (ImageButton) findViewById(R.id.action_button_2);
+ refreshButton.setImageResource(R.drawable.action_refresh);
+ refreshButton.setOnClickListener(new View.OnClickListener() {
+ @Override
+ public void onClick(View view) {
+ refresh();
+ }
+ });
+ }
+
+ private void playAll() {
+ boolean hasSubFolders = false;
+ for (int i = 0; i < entryList.getCount(); i++) {
+ MusicDirectory.Entry entry = (MusicDirectory.Entry) entryList.getItemAtPosition(i);
+ if (entry != null && entry.isDirectory()) {
+ hasSubFolders = true;
+ break;
+ }
+ }
+
+ String id = getIntent().getStringExtra(Constants.INTENT_EXTRA_NAME_ID);
+ if (hasSubFolders && id != null) {
+ downloadRecursively(id, false, false, true);
+ } else {
+ selectAll(true, false);
+ download(false, false, true, false);
+ selectAll(false, false);
+ }
+ }
+
+ private void refresh() {
+ finish();
+ Intent intent = getIntent();
+ intent.putExtra(Constants.INTENT_EXTRA_NAME_REFRESH, true);
+ Util.startActivityWithoutTransition(this, intent);
+ }
+
+ @Override
+ public void onCreateContextMenu(ContextMenu menu, View view, ContextMenu.ContextMenuInfo menuInfo) {
+ super.onCreateContextMenu(menu, view, menuInfo);
+ AdapterView.AdapterContextMenuInfo info =
+ (AdapterView.AdapterContextMenuInfo) menuInfo;
+
+ MusicDirectory.Entry entry = (MusicDirectory.Entry) entryList.getItemAtPosition(info.position);
+
+ if (entry.isDirectory()) {
+ MenuInflater inflater = getMenuInflater();
+ inflater.inflate(R.menu.select_album_context, menu);
+ } else {
+ MenuInflater inflater = getMenuInflater();
+ inflater.inflate(R.menu.select_song_context, menu);
+ }
+ }
+
+ @Override
+ public boolean onContextItemSelected(MenuItem menuItem) {
+ AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo) menuItem.getMenuInfo();
+ MusicDirectory.Entry entry = (MusicDirectory.Entry) entryList.getItemAtPosition(info.position);
+ List<MusicDirectory.Entry> songs = new ArrayList<MusicDirectory.Entry>(10);
+ songs.add((MusicDirectory.Entry) entryList.getItemAtPosition(info.position));
+ switch (menuItem.getItemId()) {
+ case R.id.album_menu_play_now:
+ downloadRecursively(entry.getId(), false, false, true);
+ break;
+ case R.id.album_menu_play_last:
+ downloadRecursively(entry.getId(), false, true, false);
+ break;
+ case R.id.album_menu_pin:
+ downloadRecursively(entry.getId(), true, true, false);
+ break;
+ case R.id.song_menu_play_now:
+ getDownloadService().download(songs, false, true, true);
+ break;
+ case R.id.song_menu_play_next:
+ getDownloadService().download(songs, false, false, true);
+ break;
+ case R.id.song_menu_play_last:
+ getDownloadService().download(songs, false, false, false);
+ break;
+ default:
+ return super.onContextItemSelected(menuItem);
+ }
+ return true;
+ }
+
+ private void getMusicDirectory(final String id, String name) {
+ setTitle(name);
+
+ new LoadTask() {
+ @Override
+ protected MusicDirectory load(MusicService service) throws Exception {
+ boolean refresh = getIntent().getBooleanExtra(Constants.INTENT_EXTRA_NAME_REFRESH, false);
+ return service.getMusicDirectory(id, refresh, SelectAlbumActivity.this, this);
+ }
+ }.execute();
+ }
+
+ private void getPlaylist(final String playlistId, String playlistName) {
+ setTitle(playlistName);
+
+ new LoadTask() {
+ @Override
+ protected MusicDirectory load(MusicService service) throws Exception {
+ return service.getPlaylist(playlistId, SelectAlbumActivity.this, this);
+ }
+ }.execute();
+ }
+
+ private void getAlbumList(final String albumListType, final int size, final int offset) {
+
+ if ("newest".equals(albumListType)) {
+ setTitle(R.string.main_albums_newest);
+ } else if ("random".equals(albumListType)) {
+ setTitle(R.string.main_albums_random);
+ } else if ("highest".equals(albumListType)) {
+ setTitle(R.string.main_albums_highest);
+ } else if ("recent".equals(albumListType)) {
+ setTitle(R.string.main_albums_recent);
+ } else if ("frequent".equals(albumListType)) {
+ setTitle(R.string.main_albums_frequent);
+ }
+
+ new LoadTask() {
+ @Override
+ protected MusicDirectory load(MusicService service) throws Exception {
+ return service.getAlbumList(albumListType, size, offset, SelectAlbumActivity.this, this);
+ }
+
+ @Override
+ protected void done(Pair<MusicDirectory, Boolean> result) {
+ if (!result.getFirst().getChildren().isEmpty()) {
+ pinButton.setVisibility(View.GONE);
+ unpinButton.setVisibility(View.GONE);
+ deleteButton.setVisibility(View.GONE);
+ moreButton.setVisibility(View.VISIBLE);
+ entryList.addFooterView(footer);
+
+ moreButton.setOnClickListener(new View.OnClickListener() {
+ @Override
+ public void onClick(View view) {
+ Intent intent = new Intent(SelectAlbumActivity.this, SelectAlbumActivity.class);
+ String type = getIntent().getStringExtra(Constants.INTENT_EXTRA_NAME_ALBUM_LIST_TYPE);
+ int size = getIntent().getIntExtra(Constants.INTENT_EXTRA_NAME_ALBUM_LIST_SIZE, 0);
+ int offset = getIntent().getIntExtra(Constants.INTENT_EXTRA_NAME_ALBUM_LIST_OFFSET, 0) + size;
+
+ intent.putExtra(Constants.INTENT_EXTRA_NAME_ALBUM_LIST_TYPE, type);
+ intent.putExtra(Constants.INTENT_EXTRA_NAME_ALBUM_LIST_SIZE, size);
+ intent.putExtra(Constants.INTENT_EXTRA_NAME_ALBUM_LIST_OFFSET, offset);
+ Util.startActivityWithoutTransition(SelectAlbumActivity.this, intent);
+ }
+ });
+ }
+ super.done(result);
+ }
+ }.execute();
+ }
+
+ private void selectAllOrNone() {
+ boolean someUnselected = false;
+ int count = entryList.getCount();
+ for (int i = 0; i < count; i++) {
+ if (!entryList.isItemChecked(i) && entryList.getItemAtPosition(i) instanceof MusicDirectory.Entry) {
+ someUnselected = true;
+ break;
+ }
+ }
+ selectAll(someUnselected, true);
+ }
+
+ private void selectAll(boolean selected, boolean toast) {
+ int count = entryList.getCount();
+ int selectedCount = 0;
+ for (int i = 0; i < count; i++) {
+ MusicDirectory.Entry entry = (MusicDirectory.Entry) entryList.getItemAtPosition(i);
+ if (entry != null && !entry.isDirectory() && !entry.isVideo()) {
+ entryList.setItemChecked(i, selected);
+ selectedCount++;
+ }
+ }
+
+ // Display toast: N tracks selected / N tracks unselected
+ if (toast) {
+ int toastResId = selected ? R.string.select_album_n_selected
+ : R.string.select_album_n_unselected;
+ Util.toast(this, getString(toastResId, selectedCount));
+ }
+
+ enableButtons();
+ }
+
+ private void enableButtons() {
+ if (getDownloadService() == null) {
+ return;
+ }
+
+ List<MusicDirectory.Entry> selection = getSelectedSongs();
+ boolean enabled = !selection.isEmpty();
+ boolean unpinEnabled = false;
+ boolean deleteEnabled = false;
+
+ for (MusicDirectory.Entry song : selection) {
+ DownloadFile downloadFile = getDownloadService().forSong(song);
+ if (downloadFile.isCompleteFileAvailable()) {
+ deleteEnabled = true;
+ }
+ if (downloadFile.isSaved()) {
+ unpinEnabled = true;
+ }
+ }
+
+ playNowButton.setEnabled(enabled);
+ playLastButton.setEnabled(enabled);
+ pinButton.setEnabled(enabled && !Util.isOffline(this));
+ unpinButton.setEnabled(unpinEnabled);
+ deleteButton.setEnabled(deleteEnabled);
+ }
+
+ private List<MusicDirectory.Entry> getSelectedSongs() {
+ List<MusicDirectory.Entry> songs = new ArrayList<MusicDirectory.Entry>(10);
+ int count = entryList.getCount();
+ for (int i = 0; i < count; i++) {
+ if (entryList.isItemChecked(i)) {
+ songs.add((MusicDirectory.Entry) entryList.getItemAtPosition(i));
+ }
+ }
+ return songs;
+ }
+
+ private void download(final boolean append, final boolean save, final boolean autoplay, final boolean playNext) {
+ if (getDownloadService() == null) {
+ return;
+ }
+
+ final List<MusicDirectory.Entry> songs = getSelectedSongs();
+ Runnable onValid = new Runnable() {
+ @Override
+ public void run() {
+ if (!append) {
+ getDownloadService().clear();
+ }
+
+ warnIfNetworkOrStorageUnavailable();
+ getDownloadService().download(songs, save, autoplay, playNext);
+ String playlistName = getIntent().getStringExtra(Constants.INTENT_EXTRA_NAME_PLAYLIST_NAME);
+ if (playlistName != null) {
+ getDownloadService().setSuggestedPlaylistName(playlistName);
+ }
+ if (autoplay) {
+ Util.startActivityWithoutTransition(SelectAlbumActivity.this, DownloadActivity.class);
+ } else if (save) {
+ Util.toast(SelectAlbumActivity.this,
+ getResources().getQuantityString(R.plurals.select_album_n_songs_downloading, songs.size(), songs.size()));
+ } else if (append) {
+ Util.toast(SelectAlbumActivity.this,
+ getResources().getQuantityString(R.plurals.select_album_n_songs_added, songs.size(), songs.size()));
+ }
+ }
+ };
+
+ checkLicenseAndTrialPeriod(onValid);
+ }
+
+ private void delete() {
+ if (getDownloadService() != null) {
+ getDownloadService().delete(getSelectedSongs());
+ }
+ }
+
+ private void unpin() {
+ if (getDownloadService() != null) {
+ getDownloadService().unpin(getSelectedSongs());
+ }
+ }
+
+ private void playVideo(MusicDirectory.Entry entry) {
+ Intent intent = new Intent(Intent.ACTION_VIEW);
+ intent.setData(Uri.parse(MusicServiceFactory.getMusicService(this).getVideoUrl(this, entry.getId())));
+
+ startActivity(intent);
+ }
+
+ private void checkLicenseAndTrialPeriod(Runnable onValid) {
+ if (licenseValid) {
+ onValid.run();
+ return;
+ }
+
+ int trialDaysLeft = Util.getRemainingTrialDays(this);
+ Log.i(TAG, trialDaysLeft + " trial days left.");
+
+ if (trialDaysLeft == 0) {
+ showDonationDialog(trialDaysLeft, null);
+ } else if (trialDaysLeft < Constants.FREE_TRIAL_DAYS / 2) {
+ showDonationDialog(trialDaysLeft, onValid);
+ } else {
+ Util.toast(this, getResources().getString(R.string.select_album_not_licensed, trialDaysLeft));
+ onValid.run();
+ }
+ }
+
+ private void showDonationDialog(int trialDaysLeft, final Runnable onValid) {
+ AlertDialog.Builder builder = new AlertDialog.Builder(this);
+ builder.setIcon(android.R.drawable.ic_dialog_info);
+
+ if (trialDaysLeft == 0) {
+ builder.setTitle(R.string.select_album_donate_dialog_0_trial_days_left);
+ } else {
+ builder.setTitle(getResources().getQuantityString(R.plurals.select_album_donate_dialog_n_trial_days_left,
+ trialDaysLeft, trialDaysLeft));
+ }
+
+ builder.setMessage(R.string.select_album_donate_dialog_message);
+
+ builder.setPositiveButton(R.string.select_album_donate_dialog_now,
+ new DialogInterface.OnClickListener() {
+ @Override
+ public void onClick(DialogInterface dialogInterface, int i) {
+ startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(Constants.DONATION_URL)));
+ }
+ });
+
+ builder.setNegativeButton(R.string.select_album_donate_dialog_later,
+ new DialogInterface.OnClickListener() {
+ @Override
+ public void onClick(DialogInterface dialogInterface, int i) {
+ dialogInterface.dismiss();
+ if (onValid != null) {
+ onValid.run();
+ }
+ }
+ });
+
+ builder.create().show();
+ }
+
+ private abstract class LoadTask extends TabActivityBackgroundTask<Pair<MusicDirectory, Boolean>> {
+
+ public LoadTask() {
+ super(SelectAlbumActivity.this);
+ }
+
+ protected abstract MusicDirectory load(MusicService service) throws Exception;
+
+ @Override
+ protected Pair<MusicDirectory, Boolean> doInBackground() throws Throwable {
+ MusicService musicService = MusicServiceFactory.getMusicService(SelectAlbumActivity.this);
+ MusicDirectory dir = load(musicService);
+ boolean valid = musicService.isLicenseValid(SelectAlbumActivity.this, this);
+ return new Pair<MusicDirectory, Boolean>(dir, valid);
+ }
+
+ @Override
+ protected void done(Pair<MusicDirectory, Boolean> result) {
+ List<MusicDirectory.Entry> entries = result.getFirst().getChildren();
+
+ int songCount = 0;
+ for (MusicDirectory.Entry entry : entries) {
+ if (!entry.isDirectory()) {
+ songCount++;
+ }
+ }
+
+ if (songCount > 0) {
+ getImageLoader().loadImage(coverArtView, entries.get(0), false, true);
+ entryList.addFooterView(footer);
+ selectButton.setVisibility(View.VISIBLE);
+ playNowButton.setVisibility(View.VISIBLE);
+ playLastButton.setVisibility(View.VISIBLE);
+ }
+
+ boolean isAlbumList = getIntent().hasExtra(Constants.INTENT_EXTRA_NAME_ALBUM_LIST_TYPE);
+
+ emptyView.setVisibility(entries.isEmpty() ? View.VISIBLE : View.GONE);
+ playAllButton.setVisibility(isAlbumList || entries.isEmpty() ? View.GONE : View.VISIBLE);
+ entryList.setAdapter(new EntryAdapter(SelectAlbumActivity.this, getImageLoader(), entries, true));
+ licenseValid = result.getSecond();
+
+ boolean playAll = getIntent().getBooleanExtra(Constants.INTENT_EXTRA_NAME_AUTOPLAY, false);
+ if (playAll && songCount > 0) {
+ playAll();
+ }
+ }
+ }
+}
diff --git a/subsonic-android/src/net/sourceforge/subsonic/androidapp/activity/SelectArtistActivity.java b/subsonic-android/src/net/sourceforge/subsonic/androidapp/activity/SelectArtistActivity.java
new file mode 100644
index 00000000..959066ab
--- /dev/null
+++ b/subsonic-android/src/net/sourceforge/subsonic/androidapp/activity/SelectArtistActivity.java
@@ -0,0 +1,228 @@
+/*
+ This file is part of Subsonic.
+
+ Subsonic is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ Subsonic is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with Subsonic. If not, see <http://www.gnu.org/licenses/>.
+
+ Copyright 2009 (C) Sindre Mehus
+ */
+
+package net.sourceforge.subsonic.androidapp.activity;
+
+import android.content.Intent;
+import android.os.Bundle;
+import android.view.ContextMenu;
+import android.view.LayoutInflater;
+import android.view.MenuInflater;
+import android.view.MenuItem;
+import android.view.View;
+import android.widget.AdapterView;
+import android.widget.ImageButton;
+import android.widget.ListView;
+import android.widget.TextView;
+import net.sourceforge.subsonic.androidapp.R;
+import net.sourceforge.subsonic.androidapp.domain.Artist;
+import net.sourceforge.subsonic.androidapp.domain.Indexes;
+import net.sourceforge.subsonic.androidapp.domain.MusicFolder;
+import net.sourceforge.subsonic.androidapp.service.MusicService;
+import net.sourceforge.subsonic.androidapp.service.MusicServiceFactory;
+import net.sourceforge.subsonic.androidapp.util.ArtistAdapter;
+import net.sourceforge.subsonic.androidapp.util.BackgroundTask;
+import net.sourceforge.subsonic.androidapp.util.Constants;
+import net.sourceforge.subsonic.androidapp.util.TabActivityBackgroundTask;
+import net.sourceforge.subsonic.androidapp.util.Util;
+
+import java.util.ArrayList;
+import java.util.List;
+
+public class SelectArtistActivity extends SubsonicTabActivity implements AdapterView.OnItemClickListener {
+
+ private static final int MENU_GROUP_MUSIC_FOLDER = 10;
+
+ private ListView artistList;
+ private View folderButton;
+ private TextView folderName;
+ private List<MusicFolder> musicFolders;
+
+ /**
+ * Called when the activity is first created.
+ */
+ @Override
+ public void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ setContentView(R.layout.select_artist);
+
+ artistList = (ListView) findViewById(R.id.select_artist_list);
+ artistList.setOnItemClickListener(this);
+
+ folderButton = LayoutInflater.from(this).inflate(R.layout.select_artist_header, artistList, false);
+ folderName = (TextView) folderButton.findViewById(R.id.select_artist_folder_2);
+
+ if (!Util.isOffline(this)) {
+ artistList.addHeaderView(folderButton);
+ }
+
+ registerForContextMenu(artistList);
+
+ setTitle(Util.isOffline(this) ? R.string.music_library_label_offline : R.string.music_library_label);
+
+ // Button 1: shuffle
+ ImageButton shuffleButton = (ImageButton) findViewById(R.id.action_button_1);
+ shuffleButton.setImageResource(R.drawable.action_shuffle);
+ shuffleButton.setOnClickListener(new View.OnClickListener() {
+ @Override
+ public void onClick(View view) {
+ Intent intent = new Intent(SelectArtistActivity.this, DownloadActivity.class);
+ intent.putExtra(Constants.INTENT_EXTRA_NAME_SHUFFLE, true);
+ Util.startActivityWithoutTransition(SelectArtistActivity.this, intent);
+ }
+ });
+
+ // Button 2: refresh
+ ImageButton refreshButton = (ImageButton) findViewById(R.id.action_button_2);
+ refreshButton.setImageResource(R.drawable.action_refresh);
+ refreshButton.setOnClickListener(new View.OnClickListener() {
+ @Override
+ public void onClick(View view) {
+ refresh();
+ }
+ });
+
+ musicFolders = null;
+ load();
+ }
+
+ private void refresh() {
+ finish();
+ Intent intent = getIntent();
+ intent.putExtra(Constants.INTENT_EXTRA_NAME_REFRESH, true);
+ Util.startActivityWithoutTransition(this, intent);
+ }
+
+ private void selectFolder() {
+ folderButton.showContextMenu();
+ }
+
+ private void load() {
+ BackgroundTask<Indexes> task = new TabActivityBackgroundTask<Indexes>(this) {
+ @Override
+ protected Indexes doInBackground() throws Throwable {
+ boolean refresh = getIntent().getBooleanExtra(Constants.INTENT_EXTRA_NAME_REFRESH, false);
+ MusicService musicService = MusicServiceFactory.getMusicService(SelectArtistActivity.this);
+ if (!Util.isOffline(SelectArtistActivity.this)) {
+ musicFolders = musicService.getMusicFolders(refresh, SelectArtistActivity.this, this);
+ }
+ String musicFolderId = Util.getSelectedMusicFolderId(SelectArtistActivity.this);
+ return musicService.getIndexes(musicFolderId, refresh, SelectArtistActivity.this, this);
+ }
+
+ @Override
+ protected void done(Indexes result) {
+ List<Artist> artists = new ArrayList<Artist>(result.getShortcuts().size() + result.getArtists().size());
+ artists.addAll(result.getShortcuts());
+ artists.addAll(result.getArtists());
+ artistList.setAdapter(new ArtistAdapter(SelectArtistActivity.this, artists));
+
+ // Display selected music folder
+ if (musicFolders != null) {
+ String musicFolderId = Util.getSelectedMusicFolderId(SelectArtistActivity.this);
+ if (musicFolderId == null) {
+ folderName.setText(R.string.select_artist_all_folders);
+ } else {
+ for (MusicFolder musicFolder : musicFolders) {
+ if (musicFolder.getId().equals(musicFolderId)) {
+ folderName.setText(musicFolder.getName());
+ break;
+ }
+ }
+ }
+ }
+ }
+ };
+ task.execute();
+ }
+
+ @Override
+ public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
+ if (view == folderButton) {
+ selectFolder();
+ } else {
+ Artist artist = (Artist) parent.getItemAtPosition(position);
+ Intent intent = new Intent(this, SelectAlbumActivity.class);
+ intent.putExtra(Constants.INTENT_EXTRA_NAME_ID, artist.getId());
+ intent.putExtra(Constants.INTENT_EXTRA_NAME_NAME, artist.getName());
+ Util.startActivityWithoutTransition(this, intent);
+ }
+ }
+
+ @Override
+ public void onCreateContextMenu(ContextMenu menu, View view, ContextMenu.ContextMenuInfo menuInfo) {
+ super.onCreateContextMenu(menu, view, menuInfo);
+
+ AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo) menuInfo;
+
+ if (artistList.getItemAtPosition(info.position) instanceof Artist) {
+ MenuInflater inflater = getMenuInflater();
+ inflater.inflate(R.menu.select_artist_context, menu);
+ } else if (info.position == 0) {
+ String musicFolderId = Util.getSelectedMusicFolderId(this);
+ MenuItem menuItem = menu.add(MENU_GROUP_MUSIC_FOLDER, -1, 0, R.string.select_artist_all_folders);
+ if (musicFolderId == null) {
+ menuItem.setChecked(true);
+ }
+ if (musicFolders != null) {
+ for (int i = 0; i < musicFolders.size(); i++) {
+ MusicFolder musicFolder = musicFolders.get(i);
+ menuItem = menu.add(MENU_GROUP_MUSIC_FOLDER, i, i + 1, musicFolder.getName());
+ if (musicFolder.getId().equals(musicFolderId)) {
+ menuItem.setChecked(true);
+ }
+ }
+ }
+ menu.setGroupCheckable(MENU_GROUP_MUSIC_FOLDER, true, true);
+ }
+ }
+
+ @Override
+ public boolean onContextItemSelected(MenuItem menuItem) {
+ AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo) menuItem.getMenuInfo();
+
+ Artist artist = (Artist) artistList.getItemAtPosition(info.position);
+
+ if (artist != null) {
+ switch (menuItem.getItemId()) {
+ case R.id.artist_menu_play_now:
+ downloadRecursively(artist.getId(), false, false, true);
+ break;
+ case R.id.artist_menu_play_last:
+ downloadRecursively(artist.getId(), false, true, false);
+ break;
+ case R.id.artist_menu_pin:
+ downloadRecursively(artist.getId(), true, true, false);
+ break;
+ default:
+ return super.onContextItemSelected(menuItem);
+ }
+ } else if (info.position == 0) {
+ MusicFolder selectedFolder = menuItem.getItemId() == -1 ? null : musicFolders.get(menuItem.getItemId());
+ String musicFolderId = selectedFolder == null ? null : selectedFolder.getId();
+ String musicFolderName = selectedFolder == null ? getString(R.string.select_artist_all_folders)
+ : selectedFolder.getName();
+ Util.setSelectedMusicFolderId(this, musicFolderId);
+ folderName.setText(musicFolderName);
+ refresh();
+ }
+
+ return true;
+ }
+} \ No newline at end of file
diff --git a/subsonic-android/src/net/sourceforge/subsonic/androidapp/activity/SelectPlaylistActivity.java b/subsonic-android/src/net/sourceforge/subsonic/androidapp/activity/SelectPlaylistActivity.java
new file mode 100644
index 00000000..253124b5
--- /dev/null
+++ b/subsonic-android/src/net/sourceforge/subsonic/androidapp/activity/SelectPlaylistActivity.java
@@ -0,0 +1,141 @@
+/*
+ This file is part of Subsonic.
+
+ Subsonic is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ Subsonic is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with Subsonic. If not, see <http://www.gnu.org/licenses/>.
+
+ Copyright 2009 (C) Sindre Mehus
+ */
+
+package net.sourceforge.subsonic.androidapp.activity;
+
+import android.content.Intent;
+import android.os.Bundle;
+import android.view.ContextMenu;
+import android.view.Menu;
+import android.view.MenuItem;
+import android.view.View;
+import android.widget.AdapterView;
+import android.widget.ImageButton;
+import android.widget.ListView;
+import net.sourceforge.subsonic.androidapp.R;
+import net.sourceforge.subsonic.androidapp.domain.Playlist;
+import net.sourceforge.subsonic.androidapp.service.MusicServiceFactory;
+import net.sourceforge.subsonic.androidapp.service.MusicService;
+import net.sourceforge.subsonic.androidapp.util.BackgroundTask;
+import net.sourceforge.subsonic.androidapp.util.Constants;
+import net.sourceforge.subsonic.androidapp.util.PlaylistAdapter;
+import net.sourceforge.subsonic.androidapp.util.TabActivityBackgroundTask;
+import net.sourceforge.subsonic.androidapp.util.Util;
+
+import java.util.List;
+
+public class SelectPlaylistActivity extends SubsonicTabActivity implements AdapterView.OnItemClickListener {
+
+ private static final int MENU_ITEM_PLAY_ALL = 1;
+
+ private ListView list;
+ private View emptyTextView;
+
+ @Override
+ public void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ setContentView(R.layout.select_playlist);
+
+ list = (ListView) findViewById(R.id.select_playlist_list);
+ emptyTextView = findViewById(R.id.select_playlist_empty);
+ list.setOnItemClickListener(this);
+ registerForContextMenu(list);
+
+ // Title: Playlists
+ setTitle(R.string.playlist_label);
+
+ // Button 1: gone
+ ImageButton searchButton = (ImageButton)findViewById(R.id.action_button_1);
+ searchButton.setVisibility(View.GONE);
+
+ // Button 2: refresh
+ ImageButton refreshButton = (ImageButton) findViewById(R.id.action_button_2);
+ refreshButton.setImageResource(R.drawable.action_refresh);
+ refreshButton.setOnClickListener(new View.OnClickListener() {
+ @Override
+ public void onClick(View view) {
+ refresh();
+ }
+ });
+
+ load();
+ }
+
+ private void refresh() {
+ finish();
+ Intent intent = new Intent(this, SelectPlaylistActivity.class);
+ intent.putExtra(Constants.INTENT_EXTRA_NAME_REFRESH, true);
+ Util.startActivityWithoutTransition(this, intent);
+ }
+
+ private void load() {
+ BackgroundTask<List<Playlist>> task = new TabActivityBackgroundTask<List<Playlist>>(this) {
+ @Override
+ protected List<Playlist> doInBackground() throws Throwable {
+ MusicService musicService = MusicServiceFactory.getMusicService(SelectPlaylistActivity.this);
+ boolean refresh = getIntent().getBooleanExtra(Constants.INTENT_EXTRA_NAME_REFRESH, false);
+ return musicService.getPlaylists(refresh, SelectPlaylistActivity.this, this);
+ }
+
+ @Override
+ protected void done(List<Playlist> result) {
+ list.setAdapter(new PlaylistAdapter(SelectPlaylistActivity.this, PlaylistAdapter.PlaylistComparator.sort(result)));
+ emptyTextView.setVisibility(result.isEmpty() ? View.VISIBLE : View.GONE);
+ }
+ };
+ task.execute();
+ }
+
+ @Override
+ public void onCreateContextMenu(ContextMenu menu, View view, ContextMenu.ContextMenuInfo menuInfo) {
+ super.onCreateContextMenu(menu, view, menuInfo);
+ menu.add(Menu.NONE, MENU_ITEM_PLAY_ALL, MENU_ITEM_PLAY_ALL, R.string.common_play_now);
+ }
+
+ @Override
+ public boolean onContextItemSelected(MenuItem menuItem) {
+ AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo) menuItem.getMenuInfo();
+ Playlist playlist = (Playlist) list.getItemAtPosition(info.position);
+
+ switch (menuItem.getItemId()) {
+ case MENU_ITEM_PLAY_ALL:
+ Intent intent = new Intent(SelectPlaylistActivity.this, SelectAlbumActivity.class);
+ intent.putExtra(Constants.INTENT_EXTRA_NAME_PLAYLIST_ID, playlist.getId());
+ intent.putExtra(Constants.INTENT_EXTRA_NAME_PLAYLIST_NAME, playlist.getName());
+ intent.putExtra(Constants.INTENT_EXTRA_NAME_AUTOPLAY, true);
+ Util.startActivityWithoutTransition(SelectPlaylistActivity.this, intent);
+ break;
+ default:
+ return super.onContextItemSelected(menuItem);
+ }
+ return true;
+ }
+
+ @Override
+ public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
+
+ Playlist playlist = (Playlist) parent.getItemAtPosition(position);
+
+ Intent intent = new Intent(SelectPlaylistActivity.this, SelectAlbumActivity.class);
+ intent.putExtra(Constants.INTENT_EXTRA_NAME_PLAYLIST_ID, playlist.getId());
+ intent.putExtra(Constants.INTENT_EXTRA_NAME_PLAYLIST_NAME, playlist.getName());
+ Util.startActivityWithoutTransition(SelectPlaylistActivity.this, intent);
+ }
+
+} \ No newline at end of file
diff --git a/subsonic-android/src/net/sourceforge/subsonic/androidapp/activity/SettingsActivity.java b/subsonic-android/src/net/sourceforge/subsonic/androidapp/activity/SettingsActivity.java
new file mode 100644
index 00000000..f726a2af
--- /dev/null
+++ b/subsonic-android/src/net/sourceforge/subsonic/androidapp/activity/SettingsActivity.java
@@ -0,0 +1,297 @@
+/*
+ This file is part of Subsonic.
+
+ Subsonic is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ Subsonic is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with Subsonic. If not, see <http://www.gnu.org/licenses/>.
+
+ Copyright 2009 (C) Sindre Mehus
+ */
+package net.sourceforge.subsonic.androidapp.activity;
+
+import android.content.SharedPreferences;
+import android.os.Bundle;
+import android.preference.EditTextPreference;
+import android.preference.ListPreference;
+import android.preference.Preference;
+import android.preference.PreferenceActivity;
+import android.preference.PreferenceScreen;
+import android.provider.SearchRecentSuggestions;
+import android.util.Log;
+import net.sourceforge.subsonic.androidapp.R;
+import net.sourceforge.subsonic.androidapp.provider.SearchSuggestionProvider;
+import net.sourceforge.subsonic.androidapp.service.DownloadService;
+import net.sourceforge.subsonic.androidapp.service.DownloadServiceImpl;
+import net.sourceforge.subsonic.androidapp.service.MusicService;
+import net.sourceforge.subsonic.androidapp.service.MusicServiceFactory;
+import net.sourceforge.subsonic.androidapp.util.Constants;
+import net.sourceforge.subsonic.androidapp.util.ErrorDialog;
+import net.sourceforge.subsonic.androidapp.util.FileUtil;
+import net.sourceforge.subsonic.androidapp.util.ModalBackgroundTask;
+import net.sourceforge.subsonic.androidapp.util.Util;
+
+import java.io.File;
+import java.net.URL;
+import java.util.LinkedHashMap;
+import java.util.Map;
+
+public class SettingsActivity extends PreferenceActivity implements SharedPreferences.OnSharedPreferenceChangeListener {
+
+ private static final String TAG = SettingsActivity.class.getSimpleName();
+ private final Map<String, ServerSettings> serverSettings = new LinkedHashMap<String, ServerSettings>();
+ private boolean testingConnection;
+ private ListPreference theme;
+ private ListPreference maxBitrateWifi;
+ private ListPreference maxBitrateMobile;
+ private ListPreference cacheSize;
+ private EditTextPreference cacheLocation;
+ private ListPreference preloadCount;
+
+ @Override
+ public void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ addPreferencesFromResource(R.xml.settings);
+
+ theme = (ListPreference) findPreference(Constants.PREFERENCES_KEY_THEME);
+ maxBitrateWifi = (ListPreference) findPreference(Constants.PREFERENCES_KEY_MAX_BITRATE_WIFI);
+ maxBitrateMobile = (ListPreference) findPreference(Constants.PREFERENCES_KEY_MAX_BITRATE_MOBILE);
+ cacheSize = (ListPreference) findPreference(Constants.PREFERENCES_KEY_CACHE_SIZE);
+ cacheLocation = (EditTextPreference) findPreference(Constants.PREFERENCES_KEY_CACHE_LOCATION);
+ preloadCount = (ListPreference) findPreference(Constants.PREFERENCES_KEY_PRELOAD_COUNT);
+
+ findPreference("testConnection1").setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
+ @Override
+ public boolean onPreferenceClick(Preference preference) {
+ testConnection(1);
+ return false;
+ }
+ });
+
+ findPreference("testConnection2").setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
+ @Override
+ public boolean onPreferenceClick(Preference preference) {
+ testConnection(2);
+ return false;
+ }
+ });
+
+ findPreference("testConnection3").setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
+ @Override
+ public boolean onPreferenceClick(Preference preference) {
+ testConnection(3);
+ return false;
+ }
+ });
+
+ findPreference("clearSearchHistory").setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
+ @Override
+ public boolean onPreferenceClick(Preference preference) {
+ SearchRecentSuggestions suggestions = new SearchRecentSuggestions(SettingsActivity.this, SearchSuggestionProvider.AUTHORITY, SearchSuggestionProvider.MODE);
+ suggestions.clearHistory();
+ Util.toast(SettingsActivity.this, R.string.settings_search_history_cleared);
+ return false;
+ }
+ });
+
+ for (int i = 1; i <= 3; i++) {
+ String instance = String.valueOf(i);
+ serverSettings.put(instance, new ServerSettings(instance));
+ }
+
+ SharedPreferences prefs = Util.getPreferences(this);
+ prefs.registerOnSharedPreferenceChangeListener(this);
+
+ update();
+ }
+
+ @Override
+ protected void onDestroy() {
+ super.onDestroy();
+
+ SharedPreferences prefs = Util.getPreferences(this);
+ prefs.unregisterOnSharedPreferenceChangeListener(this);
+ }
+
+ @Override
+ public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
+ Log.d(TAG, "Preference changed: " + key);
+ update();
+
+ if (Constants.PREFERENCES_KEY_HIDE_MEDIA.equals(key)) {
+ setHideMedia(sharedPreferences.getBoolean(key, false));
+ }
+ else if (Constants.PREFERENCES_KEY_MEDIA_BUTTONS.equals(key)) {
+ setMediaButtonsEnabled(sharedPreferences.getBoolean(key, true));
+ }
+ else if (Constants.PREFERENCES_KEY_CACHE_LOCATION.equals(key)) {
+ setCacheLocation(sharedPreferences.getString(key, ""));
+ }
+ }
+
+ private void update() {
+ if (testingConnection) {
+ return;
+ }
+
+ theme.setSummary(theme.getEntry());
+ maxBitrateWifi.setSummary(maxBitrateWifi.getEntry());
+ maxBitrateMobile.setSummary(maxBitrateMobile.getEntry());
+ cacheSize.setSummary(cacheSize.getEntry());
+ cacheLocation.setSummary(cacheLocation.getText());
+ preloadCount.setSummary(preloadCount.getEntry());
+ for (ServerSettings ss : serverSettings.values()) {
+ ss.update();
+ }
+ }
+
+ private void setHideMedia(boolean hide) {
+ File nomediaDir = new File(FileUtil.getSubsonicDirectory(), ".nomedia");
+ if (hide && !nomediaDir.exists()) {
+ if (!nomediaDir.mkdir()) {
+ Log.w(TAG, "Failed to create " + nomediaDir);
+ }
+ } else if (nomediaDir.exists()) {
+ if (!nomediaDir.delete()) {
+ Log.w(TAG, "Failed to delete " + nomediaDir);
+ }
+ }
+ Util.toast(this, R.string.settings_hide_media_toast, false);
+ }
+
+ private void setMediaButtonsEnabled(boolean enabled) {
+ if (enabled) {
+ Util.registerMediaButtonEventReceiver(this);
+ } else {
+ Util.unregisterMediaButtonEventReceiver(this);
+ }
+ }
+
+ private void setCacheLocation(String path) {
+ File dir = new File(path);
+ if (!FileUtil.ensureDirectoryExistsAndIsReadWritable(dir)) {
+ Util.toast(this, R.string.settings_cache_location_error, false);
+
+ // Reset it to the default.
+ String defaultPath = FileUtil.getDefaultMusicDirectory().getPath();
+ if (!defaultPath.equals(path)) {
+ SharedPreferences prefs = Util.getPreferences(this);
+ SharedPreferences.Editor editor = prefs.edit();
+ editor.putString(Constants.PREFERENCES_KEY_CACHE_LOCATION, defaultPath);
+ editor.commit();
+ cacheLocation.setSummary(defaultPath);
+ cacheLocation.setText(defaultPath);
+ }
+
+ // Clear download queue.
+ DownloadService downloadService = DownloadServiceImpl.getInstance();
+ downloadService.clear();
+ }
+ }
+
+ private void testConnection(final int instance) {
+ ModalBackgroundTask<Boolean> task = new ModalBackgroundTask<Boolean>(this, false) {
+ private int previousInstance;
+
+ @Override
+ protected Boolean doInBackground() throws Throwable {
+ updateProgress(R.string.settings_testing_connection);
+
+ previousInstance = Util.getActiveServer(SettingsActivity.this);
+ testingConnection = true;
+ Util.setActiveServer(SettingsActivity.this, instance);
+ try {
+ MusicService musicService = MusicServiceFactory.getMusicService(SettingsActivity.this);
+ musicService.ping(SettingsActivity.this, this);
+ return musicService.isLicenseValid(SettingsActivity.this, null);
+ } finally {
+ Util.setActiveServer(SettingsActivity.this, previousInstance);
+ testingConnection = false;
+ }
+ }
+
+ @Override
+ protected void done(Boolean licenseValid) {
+ if (licenseValid) {
+ Util.toast(SettingsActivity.this, R.string.settings_testing_ok);
+ } else {
+ Util.toast(SettingsActivity.this, R.string.settings_testing_unlicensed);
+ }
+ }
+
+ @Override
+ protected void cancel() {
+ super.cancel();
+ Util.setActiveServer(SettingsActivity.this, previousInstance);
+ }
+
+ @Override
+ protected void error(Throwable error) {
+ Log.w(TAG, error.toString(), error);
+ new ErrorDialog(SettingsActivity.this, getResources().getString(R.string.settings_connection_failure) +
+ " " + getErrorMessage(error), false);
+ }
+ };
+ task.execute();
+ }
+
+ private class ServerSettings {
+ private EditTextPreference serverName;
+ private EditTextPreference serverUrl;
+ private EditTextPreference username;
+ private PreferenceScreen screen;
+
+ private ServerSettings(String instance) {
+
+ screen = (PreferenceScreen) findPreference("server" + instance);
+ serverName = (EditTextPreference) findPreference(Constants.PREFERENCES_KEY_SERVER_NAME + instance);
+ serverUrl = (EditTextPreference) findPreference(Constants.PREFERENCES_KEY_SERVER_URL + instance);
+ username = (EditTextPreference) findPreference(Constants.PREFERENCES_KEY_USERNAME + instance);
+
+ serverUrl.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
+ @Override
+ public boolean onPreferenceChange(Preference preference, Object value) {
+ try {
+ String url = (String) value;
+ new URL(url);
+ if (!url.equals(url.trim()) || url.contains("@")) {
+ throw new Exception();
+ }
+ } catch (Exception x) {
+ new ErrorDialog(SettingsActivity.this, R.string.settings_invalid_url, false);
+ return false;
+ }
+ return true;
+ }
+ });
+
+ username.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
+ @Override
+ public boolean onPreferenceChange(Preference preference, Object value) {
+ String username = (String) value;
+ if (username == null || !username.equals(username.trim())) {
+ new ErrorDialog(SettingsActivity.this, R.string.settings_invalid_username, false);
+ return false;
+ }
+ return true;
+ }
+ });
+ }
+
+ public void update() {
+ serverName.setSummary(serverName.getText());
+ serverUrl.setSummary(serverUrl.getText());
+ username.setSummary(username.getText());
+ screen.setSummary(serverUrl.getText());
+ screen.setTitle(serverName.getText());
+ }
+ }
+} \ No newline at end of file
diff --git a/subsonic-android/src/net/sourceforge/subsonic/androidapp/activity/SubsonicTabActivity.java b/subsonic-android/src/net/sourceforge/subsonic/androidapp/activity/SubsonicTabActivity.java
new file mode 100644
index 00000000..8c9c0687
--- /dev/null
+++ b/subsonic-android/src/net/sourceforge/subsonic/androidapp/activity/SubsonicTabActivity.java
@@ -0,0 +1,383 @@
+/*
+ This file is part of Subsonic.
+
+ Subsonic is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ Subsonic is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with Subsonic. If not, see <http://www.gnu.org/licenses/>.
+
+ Copyright 2009 (C) Sindre Mehus
+ */
+package net.sourceforge.subsonic.androidapp.activity;
+
+import java.io.File;
+import java.io.PrintWriter;
+import java.util.LinkedList;
+import java.util.List;
+
+import android.app.Activity;
+import android.content.Context;
+import android.content.Intent;
+import android.content.pm.PackageInfo;
+import android.graphics.Typeface;
+import android.media.AudioManager;
+import android.os.Build;
+import android.os.Bundle;
+import android.os.Environment;
+import android.util.Log;
+import android.view.KeyEvent;
+import android.view.Menu;
+import android.view.MenuInflater;
+import android.view.MenuItem;
+import android.view.View;
+import android.view.Window;
+import android.widget.TextView;
+import net.sourceforge.subsonic.androidapp.R;
+import net.sourceforge.subsonic.androidapp.domain.MusicDirectory;
+import net.sourceforge.subsonic.androidapp.service.DownloadService;
+import net.sourceforge.subsonic.androidapp.service.DownloadServiceImpl;
+import net.sourceforge.subsonic.androidapp.service.MusicService;
+import net.sourceforge.subsonic.androidapp.service.MusicServiceFactory;
+import net.sourceforge.subsonic.androidapp.util.Constants;
+import net.sourceforge.subsonic.androidapp.util.ImageLoader;
+import net.sourceforge.subsonic.androidapp.util.ModalBackgroundTask;
+import net.sourceforge.subsonic.androidapp.util.Util;
+
+/**
+ * @author Sindre Mehus
+ */
+public class SubsonicTabActivity extends Activity {
+
+ private static final String TAG = SubsonicTabActivity.class.getSimpleName();
+ private static ImageLoader IMAGE_LOADER;
+
+ private boolean destroyed;
+ private View homeButton;
+ private View musicButton;
+ private View searchButton;
+ private View playlistButton;
+ private View nowPlayingButton;
+
+ @Override
+ protected void onCreate(Bundle bundle) {
+ setUncaughtExceptionHandler();
+ applyTheme();
+ super.onCreate(bundle);
+ requestWindowFeature(Window.FEATURE_NO_TITLE);
+ startService(new Intent(this, DownloadServiceImpl.class));
+ setVolumeControlStream(AudioManager.STREAM_MUSIC);
+ }
+
+ @Override
+ protected void onPostCreate(Bundle bundle) {
+ super.onPostCreate(bundle);
+
+ homeButton = findViewById(R.id.button_bar_home);
+ homeButton.setOnClickListener(new View.OnClickListener() {
+ @Override
+ public void onClick(View view) {
+ Intent intent = new Intent(SubsonicTabActivity.this, MainActivity.class);
+ intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
+ Util.startActivityWithoutTransition(SubsonicTabActivity.this, intent);
+ }
+ });
+
+ musicButton = findViewById(R.id.button_bar_music);
+ musicButton.setOnClickListener(new View.OnClickListener() {
+ @Override
+ public void onClick(View view) {
+ Intent intent = new Intent(SubsonicTabActivity.this, SelectArtistActivity.class);
+ intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
+ Util.startActivityWithoutTransition(SubsonicTabActivity.this, intent);
+ }
+ });
+
+ searchButton = findViewById(R.id.button_bar_search);
+ searchButton.setOnClickListener(new View.OnClickListener() {
+ @Override
+ public void onClick(View view) {
+ Intent intent = new Intent(SubsonicTabActivity.this, SearchActivity.class);
+ intent.putExtra(Constants.INTENT_EXTRA_REQUEST_SEARCH, true);
+ Util.startActivityWithoutTransition(SubsonicTabActivity.this, intent);
+ }
+ });
+
+ playlistButton = findViewById(R.id.button_bar_playlists);
+ playlistButton.setOnClickListener(new View.OnClickListener() {
+ @Override
+ public void onClick(View view) {
+ Intent intent = new Intent(SubsonicTabActivity.this, SelectPlaylistActivity.class);
+ intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
+ Util.startActivityWithoutTransition(SubsonicTabActivity.this, intent);
+ }
+ });
+
+ nowPlayingButton = findViewById(R.id.button_bar_now_playing);
+ nowPlayingButton.setOnClickListener(new View.OnClickListener() {
+ @Override
+ public void onClick(View view) {
+ Util.startActivityWithoutTransition(SubsonicTabActivity.this, DownloadActivity.class);
+ }
+ });
+
+ if (this instanceof MainActivity) {
+ homeButton.setEnabled(false);
+ } else if (this instanceof SelectAlbumActivity || this instanceof SelectArtistActivity) {
+ musicButton.setEnabled(false);
+ } else if (this instanceof SearchActivity) {
+ searchButton.setEnabled(false);
+ } else if (this instanceof SelectPlaylistActivity) {
+ playlistButton.setEnabled(false);
+ } else if (this instanceof DownloadActivity || this instanceof LyricsActivity) {
+ nowPlayingButton.setEnabled(false);
+ }
+
+ updateButtonVisibility();
+ }
+
+ @Override
+ protected void onResume() {
+ super.onResume();
+ Util.registerMediaButtonEventReceiver(this);
+ }
+
+ @Override
+ public boolean onCreateOptionsMenu(Menu menu) {
+ MenuInflater inflater = getMenuInflater();
+ inflater.inflate(R.menu.main, menu);
+ return true;
+ }
+
+ @Override
+ public boolean onOptionsItemSelected(MenuItem item) {
+ switch (item.getItemId()) {
+
+ case R.id.menu_exit:
+ Intent intent = new Intent(this, MainActivity.class);
+ intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
+ intent.putExtra(Constants.INTENT_EXTRA_NAME_EXIT, true);
+ Util.startActivityWithoutTransition(this, intent);
+ return true;
+
+ case R.id.menu_settings:
+ startActivity(new Intent(this, SettingsActivity.class));
+ return true;
+
+ case R.id.menu_help:
+ startActivity(new Intent(this, HelpActivity.class));
+ return true;
+ }
+
+ return false;
+ }
+
+ @Override
+ protected void onDestroy() {
+ super.onDestroy();
+ destroyed = true;
+ getImageLoader().clear();
+ }
+
+
+ @Override
+ public boolean onKeyDown(int keyCode, KeyEvent event) {
+ boolean isVolumeDown = keyCode == KeyEvent.KEYCODE_VOLUME_DOWN;
+ boolean isVolumeUp = keyCode == KeyEvent.KEYCODE_VOLUME_UP;
+ boolean isVolumeAdjust = isVolumeDown || isVolumeUp;
+ boolean isJukebox = getDownloadService() != null && getDownloadService().isJukeboxEnabled();
+
+ if (isVolumeAdjust && isJukebox) {
+ getDownloadService().adjustJukeboxVolume(isVolumeUp);
+ return true;
+ }
+ return super.onKeyDown(keyCode, event);
+ }
+
+ @Override
+ public void finish() {
+ super.finish();
+ Util.disablePendingTransition(this);
+ }
+
+ @Override
+ public void setTitle(CharSequence title) {
+ super.setTitle(title);
+
+ // Set the font of title in the action bar.
+ TextView text = (TextView) findViewById(R.id.actionbar_title_text);
+ Typeface typeface = Typeface.createFromAsset(getAssets(), "fonts/Storopia.ttf");
+ text.setTypeface(typeface);
+
+ text.setText(title);
+ }
+
+ @Override
+ public void setTitle(int titleId) {
+ setTitle(getString(titleId));
+ }
+
+ private void applyTheme() {
+ String theme = Util.getTheme(this);
+ if ("dark".equals(theme)) {
+ setTheme(android.R.style.Theme);
+ } else if ("light".equals(theme)) {
+ setTheme(android.R.style.Theme_Light);
+ }
+ }
+
+ public boolean isDestroyed() {
+ return destroyed;
+ }
+
+ private void updateButtonVisibility() {
+ int visibility = Util.isOffline(this) ? View.GONE : View.VISIBLE;
+ searchButton.setVisibility(visibility);
+ playlistButton.setVisibility(visibility);
+ }
+
+ public void setProgressVisible(boolean visible) {
+ View view = findViewById(R.id.tab_progress);
+ if (view != null) {
+ view.setVisibility(visible ? View.VISIBLE : View.GONE);
+ }
+ }
+
+ public void updateProgress(String message) {
+ TextView view = (TextView) findViewById(R.id.tab_progress_message);
+ if (view != null) {
+ view.setText(message);
+ }
+ }
+
+ public DownloadService getDownloadService() {
+ // If service is not available, request it to start and wait for it.
+ for (int i = 0; i < 5; i++) {
+ DownloadService downloadService = DownloadServiceImpl.getInstance();
+ if (downloadService != null) {
+ return downloadService;
+ }
+ Log.w(TAG, "DownloadService not running. Attempting to start it.");
+ startService(new Intent(this, DownloadServiceImpl.class));
+ Util.sleepQuietly(50L);
+ }
+ return DownloadServiceImpl.getInstance();
+ }
+
+ protected void warnIfNetworkOrStorageUnavailable() {
+ if (!Util.isExternalStoragePresent()) {
+ Util.toast(this, R.string.select_album_no_sdcard);
+ } else if (!Util.isOffline(this) && !Util.isNetworkConnected(this)) {
+ Util.toast(this, R.string.select_album_no_network);
+ }
+ }
+
+ protected synchronized ImageLoader getImageLoader() {
+ if (IMAGE_LOADER == null) {
+ IMAGE_LOADER = new ImageLoader(this);
+ }
+ return IMAGE_LOADER;
+ }
+
+ protected void downloadRecursively(final String id, final boolean save, final boolean append, final boolean autoplay) {
+ ModalBackgroundTask<List<MusicDirectory.Entry>> task = new ModalBackgroundTask<List<MusicDirectory.Entry>>(this, false) {
+
+ private static final int MAX_SONGS = 500;
+
+ @Override
+ protected List<MusicDirectory.Entry> doInBackground() throws Throwable {
+ MusicService musicService = MusicServiceFactory.getMusicService(SubsonicTabActivity.this);
+ MusicDirectory root = musicService.getMusicDirectory(id, false, SubsonicTabActivity.this, this);
+ List<MusicDirectory.Entry> songs = new LinkedList<MusicDirectory.Entry>();
+ getSongsRecursively(root, songs);
+ return songs;
+ }
+
+ private void getSongsRecursively(MusicDirectory parent, List<MusicDirectory.Entry> songs) throws Exception {
+ if (songs.size() > MAX_SONGS) {
+ return;
+ }
+
+ for (MusicDirectory.Entry song : parent.getChildren(false, true)) {
+ if (!song.isVideo()) {
+ songs.add(song);
+ }
+ }
+ for (MusicDirectory.Entry dir : parent.getChildren(true, false)) {
+ MusicService musicService = MusicServiceFactory.getMusicService(SubsonicTabActivity.this);
+ getSongsRecursively(musicService.getMusicDirectory(dir.getId(), false, SubsonicTabActivity.this, this), songs);
+ }
+ }
+
+ @Override
+ protected void done(List<MusicDirectory.Entry> songs) {
+ DownloadService downloadService = getDownloadService();
+ if (!songs.isEmpty() && downloadService != null) {
+ if (!append) {
+ downloadService.clear();
+ }
+ warnIfNetworkOrStorageUnavailable();
+ downloadService.download(songs, save, autoplay, false);
+ Util.startActivityWithoutTransition(SubsonicTabActivity.this, DownloadActivity.class);
+ }
+ }
+ };
+
+ task.execute();
+ }
+
+ private void setUncaughtExceptionHandler() {
+ Thread.UncaughtExceptionHandler handler = Thread.getDefaultUncaughtExceptionHandler();
+ if (!(handler instanceof SubsonicUncaughtExceptionHandler)) {
+ Thread.setDefaultUncaughtExceptionHandler(new SubsonicUncaughtExceptionHandler(this));
+ }
+ }
+
+ /**
+ * Logs the stack trace of uncaught exceptions to a file on the SD card.
+ */
+ private static class SubsonicUncaughtExceptionHandler implements Thread.UncaughtExceptionHandler {
+
+ private final Thread.UncaughtExceptionHandler defaultHandler;
+ private final Context context;
+
+ private SubsonicUncaughtExceptionHandler(Context context) {
+ this.context = context;
+ defaultHandler = Thread.getDefaultUncaughtExceptionHandler();
+ }
+
+ @Override
+ public void uncaughtException(Thread thread, Throwable throwable) {
+ File file = null;
+ PrintWriter printWriter = null;
+ try {
+
+ PackageInfo packageInfo = context.getPackageManager().getPackageInfo("net.sourceforge.subsonic.androidapp", 0);
+ file = new File(Environment.getExternalStorageDirectory(), "subsonic-stacktrace.txt");
+ printWriter = new PrintWriter(file);
+ printWriter.println("Android API level: " + Build.VERSION.SDK);
+ printWriter.println("Subsonic version name: " + packageInfo.versionName);
+ printWriter.println("Subsonic version code: " + packageInfo.versionCode);
+ printWriter.println();
+ throwable.printStackTrace(printWriter);
+ Log.i(TAG, "Stack trace written to " + file);
+ } catch (Throwable x) {
+ Log.e(TAG, "Failed to write stack trace to " + file, x);
+ } finally {
+ Util.close(printWriter);
+ if (defaultHandler != null) {
+ defaultHandler.uncaughtException(thread, throwable);
+ }
+
+ }
+ }
+ }
+}
+
diff --git a/subsonic-android/src/net/sourceforge/subsonic/androidapp/activity/VoiceQueryReceiverActivity.java b/subsonic-android/src/net/sourceforge/subsonic/androidapp/activity/VoiceQueryReceiverActivity.java
new file mode 100644
index 00000000..205c2fe7
--- /dev/null
+++ b/subsonic-android/src/net/sourceforge/subsonic/androidapp/activity/VoiceQueryReceiverActivity.java
@@ -0,0 +1,59 @@
+/*
+ This file is part of Subsonic.
+
+ Subsonic is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ Subsonic is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with Subsonic. If not, see <http://www.gnu.org/licenses/>.
+
+ Copyright 2009 (C) Sindre Mehus
+ */
+
+package net.sourceforge.subsonic.androidapp.activity;
+
+import android.app.Activity;
+import android.app.SearchManager;
+import android.content.Intent;
+import android.os.Bundle;
+import android.provider.SearchRecentSuggestions;
+import net.sourceforge.subsonic.androidapp.util.Constants;
+import net.sourceforge.subsonic.androidapp.util.Util;
+import net.sourceforge.subsonic.androidapp.provider.SearchSuggestionProvider;
+
+/**
+ * Receives voice search queries and forwards to the SearchActivity.
+ *
+ * http://android-developers.blogspot.com/2010/09/supporting-new-music-voice-action.html
+ *
+ * @author Sindre Mehus
+ */
+public class VoiceQueryReceiverActivity extends Activity {
+
+ @Override
+ public void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+
+ String query = getIntent().getStringExtra(SearchManager.QUERY);
+
+ if (query != null) {
+ SearchRecentSuggestions suggestions = new SearchRecentSuggestions(this, SearchSuggestionProvider.AUTHORITY,
+ SearchSuggestionProvider.MODE);
+ suggestions.saveRecentQuery(query, null);
+
+ Intent intent = new Intent(VoiceQueryReceiverActivity.this, SearchActivity.class);
+ intent.putExtra(Constants.INTENT_EXTRA_NAME_QUERY, query);
+ intent.putExtra(Constants.INTENT_EXTRA_NAME_AUTOPLAY, true);
+ Util.startActivityWithoutTransition(VoiceQueryReceiverActivity.this, intent);
+ }
+ finish();
+ Util.disablePendingTransition(this);
+ }
+} \ No newline at end of file
diff --git a/subsonic-android/src/net/sourceforge/subsonic/androidapp/audiofx/EqualizerController.java b/subsonic-android/src/net/sourceforge/subsonic/androidapp/audiofx/EqualizerController.java
new file mode 100644
index 00000000..77a270ed
--- /dev/null
+++ b/subsonic-android/src/net/sourceforge/subsonic/androidapp/audiofx/EqualizerController.java
@@ -0,0 +1,138 @@
+/*
+ This file is part of Subsonic.
+
+ Subsonic is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ Subsonic is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with Subsonic. If not, see <http://www.gnu.org/licenses/>.
+
+ Copyright 2011 (C) Sindre Mehus
+ */
+package net.sourceforge.subsonic.androidapp.audiofx;
+
+import java.io.Serializable;
+
+import android.content.Context;
+import android.media.MediaPlayer;
+import android.media.audiofx.Equalizer;
+import android.util.Log;
+import net.sourceforge.subsonic.androidapp.util.FileUtil;
+
+/**
+ * Backward-compatible wrapper for {@link Equalizer}, which is API Level 9.
+ *
+ * @author Sindre Mehus
+ * @version $Id$
+ */
+public class EqualizerController {
+
+ private static final String TAG = EqualizerController.class.getSimpleName();
+
+ private final Context context;
+ private Equalizer equalizer;
+
+ // Class initialization fails when this throws an exception.
+ static {
+ try {
+ Class.forName("android.media.audiofx.Equalizer");
+ } catch (Exception ex) {
+ throw new RuntimeException(ex);
+ }
+ }
+
+ /**
+ * Throws an exception if the {@link Equalizer} class is not available.
+ */
+ public static void checkAvailable() throws Throwable {
+ // Calling here forces class initialization.
+ }
+
+ public EqualizerController(Context context, MediaPlayer mediaPlayer) {
+ this.context = context;
+ try {
+ equalizer = new Equalizer(0, mediaPlayer.getAudioSessionId());
+ } catch (Throwable x) {
+ Log.w(TAG, "Failed to create equalizer.", x);
+ }
+ }
+
+ public void saveSettings() {
+ try {
+ if (isAvailable()) {
+ FileUtil.serialize(context, new EqualizerSettings(equalizer), "equalizer.dat");
+ }
+ } catch (Throwable x) {
+ Log.w(TAG, "Failed to save equalizer settings.", x);
+ }
+ }
+
+ public void loadSettings() {
+ try {
+ if (isAvailable()) {
+ EqualizerSettings settings = FileUtil.deserialize(context, "equalizer.dat");
+ if (settings != null) {
+ settings.apply(equalizer);
+ }
+ }
+ } catch (Throwable x) {
+ Log.w(TAG, "Failed to load equalizer settings.", x);
+ }
+ }
+
+ public boolean isAvailable() {
+ return equalizer != null;
+ }
+
+ public boolean isEnabled() {
+ return isAvailable() && equalizer.getEnabled();
+ }
+
+ public void release() {
+ if (isAvailable()) {
+ equalizer.release();
+ }
+ }
+
+ public Equalizer getEqualizer() {
+ return equalizer;
+ }
+
+ private static class EqualizerSettings implements Serializable {
+
+ private final short[] bandLevels;
+ private short preset;
+ private final boolean enabled;
+
+ public EqualizerSettings(Equalizer equalizer) {
+ enabled = equalizer.getEnabled();
+ bandLevels = new short[equalizer.getNumberOfBands()];
+ for (short i = 0; i < equalizer.getNumberOfBands(); i++) {
+ bandLevels[i] = equalizer.getBandLevel(i);
+ }
+ try {
+ preset = equalizer.getCurrentPreset();
+ } catch (Exception x) {
+ preset = -1;
+ }
+ }
+
+ public void apply(Equalizer equalizer) {
+ for (short i = 0; i < bandLevels.length; i++) {
+ equalizer.setBandLevel(i, bandLevels[i]);
+ }
+ if (preset >= 0 && preset < equalizer.getNumberOfPresets()) {
+ equalizer.usePreset(preset);
+ }
+ equalizer.setEnabled(enabled);
+ }
+ }
+}
+
diff --git a/subsonic-android/src/net/sourceforge/subsonic/androidapp/audiofx/VisualizerController.java b/subsonic-android/src/net/sourceforge/subsonic/androidapp/audiofx/VisualizerController.java
new file mode 100644
index 00000000..9a211b58
--- /dev/null
+++ b/subsonic-android/src/net/sourceforge/subsonic/androidapp/audiofx/VisualizerController.java
@@ -0,0 +1,90 @@
+/*
+ This file is part of Subsonic.
+
+ Subsonic is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ Subsonic is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with Subsonic. If not, see <http://www.gnu.org/licenses/>.
+
+ Copyright 2011 (C) Sindre Mehus
+ */
+package net.sourceforge.subsonic.androidapp.audiofx;
+
+import android.content.Context;
+import android.media.MediaPlayer;
+import android.media.audiofx.Visualizer;
+import android.util.Log;
+
+/**
+ * Backward-compatible wrapper for {@link Visualizer}, which is API Level 9.
+ *
+ * @author Sindre Mehus
+ * @version $Id$
+ */
+public class VisualizerController {
+
+ private static final String TAG = VisualizerController.class.getSimpleName();
+ private static final int PREFERRED_CAPTURE_SIZE = 128; // Must be a power of two.
+
+ private final Context context;
+ private Visualizer visualizer;
+
+ // Class initialization fails when this throws an exception.
+ static {
+ try {
+ Class.forName("android.media.audiofx.Visualizer");
+ } catch (Exception ex) {
+ throw new RuntimeException(ex);
+ }
+ }
+
+ /**
+ * Throws an exception if the {@link Visualizer} class is not available.
+ */
+ public static void checkAvailable() throws Throwable {
+ // Calling here forces class initialization.
+ }
+
+ public VisualizerController(Context context, MediaPlayer mediaPlayer) {
+ this.context = context;
+ try {
+ visualizer = new Visualizer(mediaPlayer.getAudioSessionId());
+ } catch (Throwable x) {
+ Log.w(TAG, "Failed to create visualizer.", x);
+ }
+
+ if (visualizer != null) {
+ int[] captureSizeRange = Visualizer.getCaptureSizeRange();
+ int captureSize = Math.max(PREFERRED_CAPTURE_SIZE, captureSizeRange[0]);
+ captureSize = Math.min(captureSize, captureSizeRange[1]);
+ visualizer.setCaptureSize(captureSize);
+ }
+ }
+
+ public boolean isAvailable() {
+ return visualizer != null;
+ }
+
+ public boolean isEnabled() {
+ return isAvailable() && visualizer.getEnabled();
+ }
+
+ public void release() {
+ if (isAvailable()) {
+ visualizer.release();
+ }
+ }
+
+ public Visualizer getVisualizer() {
+ return visualizer;
+ }
+}
+
diff --git a/subsonic-android/src/net/sourceforge/subsonic/androidapp/domain/Artist.java b/subsonic-android/src/net/sourceforge/subsonic/androidapp/domain/Artist.java
new file mode 100644
index 00000000..fce7b628
--- /dev/null
+++ b/subsonic-android/src/net/sourceforge/subsonic/androidapp/domain/Artist.java
@@ -0,0 +1,60 @@
+/*
+ This file is part of Subsonic.
+
+ Subsonic is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ Subsonic is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with Subsonic. If not, see <http://www.gnu.org/licenses/>.
+
+ Copyright 2009 (C) Sindre Mehus
+ */
+package net.sourceforge.subsonic.androidapp.domain;
+
+import java.io.Serializable;
+
+/**
+ * @author Sindre Mehus
+ */
+public class Artist implements Serializable {
+
+ private String id;
+ private String name;
+ private String index;
+
+ public String getId() {
+ return id;
+ }
+
+ public void setId(String id) {
+ this.id = id;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public String getIndex() {
+ return index;
+ }
+
+ public void setIndex(String index) {
+ this.index = index;
+ }
+
+ @Override
+ public String toString() {
+ return name;
+ }
+} \ No newline at end of file
diff --git a/subsonic-android/src/net/sourceforge/subsonic/androidapp/domain/Indexes.java b/subsonic-android/src/net/sourceforge/subsonic/androidapp/domain/Indexes.java
new file mode 100644
index 00000000..f16861be
--- /dev/null
+++ b/subsonic-android/src/net/sourceforge/subsonic/androidapp/domain/Indexes.java
@@ -0,0 +1,50 @@
+/*
+ This file is part of Subsonic.
+
+ Subsonic is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ Subsonic is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with Subsonic. If not, see <http://www.gnu.org/licenses/>.
+
+ Copyright 2009 (C) Sindre Mehus
+ */
+package net.sourceforge.subsonic.androidapp.domain;
+
+import java.util.List;
+import java.io.Serializable;
+
+/**
+ * @author Sindre Mehus
+ */
+public class Indexes implements Serializable {
+
+ private final long lastModified;
+ private final List<Artist> shortcuts;
+ private final List<Artist> artists;
+
+ public Indexes(long lastModified, List<Artist> shortcuts, List<Artist> artists) {
+ this.lastModified = lastModified;
+ this.shortcuts = shortcuts;
+ this.artists = artists;
+ }
+
+ public long getLastModified() {
+ return lastModified;
+ }
+
+ public List<Artist> getShortcuts() {
+ return shortcuts;
+ }
+
+ public List<Artist> getArtists() {
+ return artists;
+ }
+} \ No newline at end of file
diff --git a/subsonic-android/src/net/sourceforge/subsonic/androidapp/domain/JukeboxStatus.java b/subsonic-android/src/net/sourceforge/subsonic/androidapp/domain/JukeboxStatus.java
new file mode 100644
index 00000000..53a901ad
--- /dev/null
+++ b/subsonic-android/src/net/sourceforge/subsonic/androidapp/domain/JukeboxStatus.java
@@ -0,0 +1,63 @@
+/*
+ This file is part of Subsonic.
+
+ Subsonic is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ Subsonic is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with Subsonic. If not, see <http://www.gnu.org/licenses/>.
+
+ Copyright 2009 (C) Sindre Mehus
+ */
+package net.sourceforge.subsonic.androidapp.domain;
+
+/**
+ * @author Sindre Mehus
+ * @version $Id$
+ */
+public class JukeboxStatus {
+
+ private Integer positionSeconds;
+ private Integer currentPlayingIndex;
+ private Float gain;
+ private boolean playing;
+
+ public Integer getPositionSeconds() {
+ return positionSeconds;
+ }
+
+ public void setPositionSeconds(Integer positionSeconds) {
+ this.positionSeconds = positionSeconds;
+ }
+
+ public Integer getCurrentPlayingIndex() {
+ return currentPlayingIndex;
+ }
+
+ public void setCurrentIndex(Integer currentPlayingIndex) {
+ this.currentPlayingIndex = currentPlayingIndex;
+ }
+
+ public boolean isPlaying() {
+ return playing;
+ }
+
+ public void setPlaying(boolean playing) {
+ this.playing = playing;
+ }
+
+ public Float getGain() {
+ return gain;
+ }
+
+ public void setGain(float gain) {
+ this.gain = gain;
+ }
+}
diff --git a/subsonic-android/src/net/sourceforge/subsonic/androidapp/domain/Lyrics.java b/subsonic-android/src/net/sourceforge/subsonic/androidapp/domain/Lyrics.java
new file mode 100644
index 00000000..c1a4c7c0
--- /dev/null
+++ b/subsonic-android/src/net/sourceforge/subsonic/androidapp/domain/Lyrics.java
@@ -0,0 +1,55 @@
+/*
+ This file is part of Subsonic.
+
+ Subsonic is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ Subsonic is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with Subsonic. If not, see <http://www.gnu.org/licenses/>.
+
+ Copyright 2010 (C) Sindre Mehus
+ */
+package net.sourceforge.subsonic.androidapp.domain;
+
+/**
+ * Song lyrics.
+ *
+ * @author Sindre Mehus
+ */
+public class Lyrics {
+
+ private String artist;
+ private String title;
+ private String text;
+
+ public String getArtist() {
+ return artist;
+ }
+
+ public void setArtist(String artist) {
+ this.artist = artist;
+ }
+
+ public String getTitle() {
+ return title;
+ }
+
+ public void setTitle(String title) {
+ this.title = title;
+ }
+
+ public String getText() {
+ return text;
+ }
+
+ public void setText(String text) {
+ this.text = text;
+ }
+}
diff --git a/subsonic-android/src/net/sourceforge/subsonic/androidapp/domain/MusicDirectory.java b/subsonic-android/src/net/sourceforge/subsonic/androidapp/domain/MusicDirectory.java
new file mode 100644
index 00000000..4d4d265b
--- /dev/null
+++ b/subsonic-android/src/net/sourceforge/subsonic/androidapp/domain/MusicDirectory.java
@@ -0,0 +1,259 @@
+/*
+ This file is part of Subsonic.
+
+ Subsonic is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ Subsonic is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with Subsonic. If not, see <http://www.gnu.org/licenses/>.
+
+ Copyright 2009 (C) Sindre Mehus
+ */
+package net.sourceforge.subsonic.androidapp.domain;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.io.Serializable;
+
+/**
+ * @author Sindre Mehus
+ */
+public class MusicDirectory {
+
+ private String name;
+ private final List<Entry> children = new ArrayList<Entry>();
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public void addChild(Entry child) {
+ children.add(child);
+ }
+
+ public List<Entry> getChildren() {
+ return getChildren(true, true);
+ }
+
+ public List<Entry> getChildren(boolean includeDirs, boolean includeFiles) {
+ if (includeDirs && includeFiles) {
+ return children;
+ }
+
+ List<Entry> result = new ArrayList<Entry>(children.size());
+ for (Entry child : children) {
+ if (child.isDirectory() && includeDirs || !child.isDirectory() && includeFiles) {
+ result.add(child);
+ }
+ }
+ return result;
+ }
+
+ public static class Entry implements Serializable {
+ private String id;
+ private String parent;
+ private boolean directory;
+ private String title;
+ private String album;
+ private String artist;
+ private Integer track;
+ private Integer year;
+ private String genre;
+ private String contentType;
+ private String suffix;
+ private String transcodedContentType;
+ private String transcodedSuffix;
+ private String coverArt;
+ private Long size;
+ private Integer duration;
+ private Integer bitRate;
+ private String path;
+ private boolean video;
+
+ public String getId() {
+ return id;
+ }
+
+ public void setId(String id) {
+ this.id = id;
+ }
+
+ public String getParent() {
+ return parent;
+ }
+
+ public void setParent(String parent) {
+ this.parent = parent;
+ }
+
+ public boolean isDirectory() {
+ return directory;
+ }
+
+ public void setDirectory(boolean directory) {
+ this.directory = directory;
+ }
+
+ public String getTitle() {
+ return title;
+ }
+
+ public void setTitle(String title) {
+ this.title = title;
+ }
+
+ public String getAlbum() {
+ return album;
+ }
+
+ public void setAlbum(String album) {
+ this.album = album;
+ }
+
+ public String getArtist() {
+ return artist;
+ }
+
+ public void setArtist(String artist) {
+ this.artist = artist;
+ }
+
+ public Integer getTrack() {
+ return track;
+ }
+
+ public void setTrack(Integer track) {
+ this.track = track;
+ }
+
+ public Integer getYear() {
+ return year;
+ }
+
+ public void setYear(Integer year) {
+ this.year = year;
+ }
+
+ public String getGenre() {
+ return genre;
+ }
+
+ public void setGenre(String genre) {
+ this.genre = genre;
+ }
+
+ public String getContentType() {
+ return contentType;
+ }
+
+ public void setContentType(String contentType) {
+ this.contentType = contentType;
+ }
+
+ public String getSuffix() {
+ return suffix;
+ }
+
+ public void setSuffix(String suffix) {
+ this.suffix = suffix;
+ }
+
+ public String getTranscodedContentType() {
+ return transcodedContentType;
+ }
+
+ public void setTranscodedContentType(String transcodedContentType) {
+ this.transcodedContentType = transcodedContentType;
+ }
+
+ public String getTranscodedSuffix() {
+ return transcodedSuffix;
+ }
+
+ public void setTranscodedSuffix(String transcodedSuffix) {
+ this.transcodedSuffix = transcodedSuffix;
+ }
+
+ public Long getSize() {
+ return size;
+ }
+
+ public void setSize(Long size) {
+ this.size = size;
+ }
+
+ public Integer getDuration() {
+ return duration;
+ }
+
+ public void setDuration(Integer duration) {
+ this.duration = duration;
+ }
+
+ public Integer getBitRate() {
+ return bitRate;
+ }
+
+ public void setBitRate(Integer bitRate) {
+ this.bitRate = bitRate;
+ }
+
+ public String getCoverArt() {
+ return coverArt;
+ }
+
+ public void setCoverArt(String coverArt) {
+ this.coverArt = coverArt;
+ }
+
+ public String getPath() {
+ return path;
+ }
+
+ public void setPath(String path) {
+ this.path = path;
+ }
+
+ public boolean isVideo() {
+ return video;
+ }
+
+ public void setVideo(boolean video) {
+ this.video = video;
+ }
+
+ @Override
+ public boolean equals(Object o) {
+ if (this == o) {
+ return true;
+ }
+ if (o == null || getClass() != o.getClass()) {
+ return false;
+ }
+
+ Entry entry = (Entry) o;
+ return id.equals(entry.id);
+ }
+
+ @Override
+ public int hashCode() {
+ return id.hashCode();
+ }
+
+ @Override
+ public String toString() {
+ return title;
+ }
+ }
+} \ No newline at end of file
diff --git a/subsonic-android/src/net/sourceforge/subsonic/androidapp/domain/MusicFolder.java b/subsonic-android/src/net/sourceforge/subsonic/androidapp/domain/MusicFolder.java
new file mode 100644
index 00000000..595f2b5e
--- /dev/null
+++ b/subsonic-android/src/net/sourceforge/subsonic/androidapp/domain/MusicFolder.java
@@ -0,0 +1,46 @@
+/*
+ This file is part of Subsonic.
+
+ Subsonic is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ Subsonic is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with Subsonic. If not, see <http://www.gnu.org/licenses/>.
+
+ Copyright 2009 (C) Sindre Mehus
+ */
+package net.sourceforge.subsonic.androidapp.domain;
+
+import java.io.Serializable;
+
+/**
+ * Represents a top level directory in which music or other media is stored.
+ *
+ * @author Sindre Mehus
+ * @version $Id$
+ */
+public class MusicFolder implements Serializable {
+
+ private final String id;
+ private final String name;
+
+ public MusicFolder(String id, String name) {
+ this.id = id;
+ this.name = name;
+ }
+
+ public String getId() {
+ return id;
+ }
+
+ public String getName() {
+ return name;
+ }
+}
diff --git a/subsonic-android/src/net/sourceforge/subsonic/androidapp/domain/PlayerState.java b/subsonic-android/src/net/sourceforge/subsonic/androidapp/domain/PlayerState.java
new file mode 100644
index 00000000..0e13159b
--- /dev/null
+++ b/subsonic-android/src/net/sourceforge/subsonic/androidapp/domain/PlayerState.java
@@ -0,0 +1,34 @@
+/*
+ This file is part of Subsonic.
+
+ Subsonic is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ Subsonic is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with Subsonic. If not, see <http://www.gnu.org/licenses/>.
+
+ Copyright 2009 (C) Sindre Mehus
+ */
+package net.sourceforge.subsonic.androidapp.domain;
+
+/**
+ * @author Sindre Mehus
+ * @version $Id$
+ */
+public enum PlayerState {
+ IDLE,
+ DOWNLOADING,
+ PREPARING,
+ PREPARED,
+ STARTED,
+ STOPPED,
+ PAUSED,
+ COMPLETED
+}
diff --git a/subsonic-android/src/net/sourceforge/subsonic/androidapp/domain/Playlist.java b/subsonic-android/src/net/sourceforge/subsonic/androidapp/domain/Playlist.java
new file mode 100644
index 00000000..8bb29f76
--- /dev/null
+++ b/subsonic-android/src/net/sourceforge/subsonic/androidapp/domain/Playlist.java
@@ -0,0 +1,56 @@
+/*
+ This file is part of Subsonic.
+
+ Subsonic is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ Subsonic is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with Subsonic. If not, see <http://www.gnu.org/licenses/>.
+
+ Copyright 2009 (C) Sindre Mehus
+ */
+package net.sourceforge.subsonic.androidapp.domain;
+
+import java.io.Serializable;
+
+/**
+ * @author Sindre Mehus
+ */
+public class Playlist implements Serializable {
+
+ private String id;
+ private String name;
+
+ public Playlist(String id, String name) {
+ this.id = id;
+ this.name = name;
+ }
+
+ public String getId() {
+ return id;
+ }
+
+ public void setId(String id) {
+ this.id = id;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ @Override
+ public String toString() {
+ return name;
+ }
+} \ No newline at end of file
diff --git a/subsonic-android/src/net/sourceforge/subsonic/androidapp/domain/RepeatMode.java b/subsonic-android/src/net/sourceforge/subsonic/androidapp/domain/RepeatMode.java
new file mode 100644
index 00000000..be2ad061
--- /dev/null
+++ b/subsonic-android/src/net/sourceforge/subsonic/androidapp/domain/RepeatMode.java
@@ -0,0 +1,28 @@
+package net.sourceforge.subsonic.androidapp.domain;
+
+/**
+ * @author Sindre Mehus
+ * @version $Id$
+ */
+public enum RepeatMode {
+ OFF {
+ @Override
+ public RepeatMode next() {
+ return ALL;
+ }
+ },
+ ALL {
+ @Override
+ public RepeatMode next() {
+ return SINGLE;
+ }
+ },
+ SINGLE {
+ @Override
+ public RepeatMode next() {
+ return OFF;
+ }
+ };
+
+ public abstract RepeatMode next();
+}
diff --git a/subsonic-android/src/net/sourceforge/subsonic/androidapp/domain/SearchCritera.java b/subsonic-android/src/net/sourceforge/subsonic/androidapp/domain/SearchCritera.java
new file mode 100644
index 00000000..8f944b1a
--- /dev/null
+++ b/subsonic-android/src/net/sourceforge/subsonic/androidapp/domain/SearchCritera.java
@@ -0,0 +1,55 @@
+/*
+ This file is part of Subsonic.
+
+ Subsonic is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ Subsonic is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with Subsonic. If not, see <http://www.gnu.org/licenses/>.
+
+ Copyright 2009 (C) Sindre Mehus
+ */
+package net.sourceforge.subsonic.androidapp.domain;
+
+/**
+ * The criteria for a music search.
+ *
+ * @author Sindre Mehus
+ */
+public class SearchCritera {
+
+ private final String query;
+ private final int artistCount;
+ private final int albumCount;
+ private final int songCount;
+
+ public SearchCritera(String query, int artistCount, int albumCount, int songCount) {
+ this.query = query;
+ this.artistCount = artistCount;
+ this.albumCount = albumCount;
+ this.songCount = songCount;
+ }
+
+ public String getQuery() {
+ return query;
+ }
+
+ public int getArtistCount() {
+ return artistCount;
+ }
+
+ public int getAlbumCount() {
+ return albumCount;
+ }
+
+ public int getSongCount() {
+ return songCount;
+ }
+} \ No newline at end of file
diff --git a/subsonic-android/src/net/sourceforge/subsonic/androidapp/domain/SearchResult.java b/subsonic-android/src/net/sourceforge/subsonic/androidapp/domain/SearchResult.java
new file mode 100644
index 00000000..54c91628
--- /dev/null
+++ b/subsonic-android/src/net/sourceforge/subsonic/androidapp/domain/SearchResult.java
@@ -0,0 +1,51 @@
+/*
+ This file is part of Subsonic.
+
+ Subsonic is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ Subsonic is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with Subsonic. If not, see <http://www.gnu.org/licenses/>.
+
+ Copyright 2009 (C) Sindre Mehus
+ */
+package net.sourceforge.subsonic.androidapp.domain;
+
+import java.util.List;
+
+/**
+ * The result of a search. Contains matching artists, albums and songs.
+ *
+ * @author Sindre Mehus
+ */
+public class SearchResult {
+
+ private final List<Artist> artists;
+ private final List<MusicDirectory.Entry> albums;
+ private final List<MusicDirectory.Entry> songs;
+
+ public SearchResult(List<Artist> artists, List<MusicDirectory.Entry> albums, List<MusicDirectory.Entry> songs) {
+ this.artists = artists;
+ this.albums = albums;
+ this.songs = songs;
+ }
+
+ public List<Artist> getArtists() {
+ return artists;
+ }
+
+ public List<MusicDirectory.Entry> getAlbums() {
+ return albums;
+ }
+
+ public List<MusicDirectory.Entry> getSongs() {
+ return songs;
+ }
+} \ No newline at end of file
diff --git a/subsonic-android/src/net/sourceforge/subsonic/androidapp/domain/ServerInfo.java b/subsonic-android/src/net/sourceforge/subsonic/androidapp/domain/ServerInfo.java
new file mode 100644
index 00000000..9212c585
--- /dev/null
+++ b/subsonic-android/src/net/sourceforge/subsonic/androidapp/domain/ServerInfo.java
@@ -0,0 +1,46 @@
+/*
+ This file is part of Subsonic.
+
+ Subsonic is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ Subsonic is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with Subsonic. If not, see <http://www.gnu.org/licenses/>.
+
+ Copyright 2010 (C) Sindre Mehus
+ */
+package net.sourceforge.subsonic.androidapp.domain;
+
+/**
+ * Information about the Subsonic server.
+ *
+ * @author Sindre Mehus
+ */
+public class ServerInfo {
+
+ private boolean isLicenseValid;
+ private Version restVersion;
+
+ public boolean isLicenseValid() {
+ return isLicenseValid;
+ }
+
+ public void setLicenseValid(boolean licenseValid) {
+ isLicenseValid = licenseValid;
+ }
+
+ public Version getRestVersion() {
+ return restVersion;
+ }
+
+ public void setRestVersion(Version restVersion) {
+ this.restVersion = restVersion;
+ }
+}
diff --git a/subsonic-android/src/net/sourceforge/subsonic/androidapp/domain/Version.java b/subsonic-android/src/net/sourceforge/subsonic/androidapp/domain/Version.java
new file mode 100644
index 00000000..bd1643b5
--- /dev/null
+++ b/subsonic-android/src/net/sourceforge/subsonic/androidapp/domain/Version.java
@@ -0,0 +1,142 @@
+/*
+ This file is part of Subsonic.
+
+ Subsonic is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ Subsonic is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with Subsonic. If not, see <http://www.gnu.org/licenses/>.
+
+ Copyright 2009 (C) Sindre Mehus
+ */
+package net.sourceforge.subsonic.androidapp.domain;
+
+/**
+ * Represents the version number of the Subsonic Android app.
+ *
+ * @author Sindre Mehus
+ * @version $Revision: 1.3 $ $Date: 2006/01/20 21:25:16 $
+ */
+public class Version implements Comparable<Version> {
+ private int major;
+ private int minor;
+ private int beta;
+ private int bugfix;
+
+ /**
+ * Creates a new version instance by parsing the given string.
+ * @param version A string of the format "1.27", "1.27.2" or "1.27.beta3".
+ */
+ public Version(String version) {
+ String[] s = version.split("\\.");
+ major = Integer.valueOf(s[0]);
+ minor = Integer.valueOf(s[1]);
+
+ if (s.length > 2) {
+ if (s[2].contains("beta")) {
+ beta = Integer.valueOf(s[2].replace("beta", ""));
+ } else {
+ bugfix = Integer.valueOf(s[2]);
+ }
+ }
+ }
+
+ public int getMajor() {
+ return major;
+ }
+
+ public int getMinor() {
+ return minor;
+ }
+
+ /**
+ * Return whether this object is equal to another.
+ * @param o Object to compare to.
+ * @return Whether this object is equals to another.
+ */
+ public boolean equals(Object o) {
+ if (this == o) return true;
+ if (o == null || getClass() != o.getClass()) return false;
+
+ final Version version = (Version) o;
+
+ if (beta != version.beta) return false;
+ if (bugfix != version.bugfix) return false;
+ if (major != version.major) return false;
+ return minor == version.minor;
+ }
+
+ /**
+ * Returns a hash code for this object.
+ * @return A hash code for this object.
+ */
+ public int hashCode() {
+ int result;
+ result = major;
+ result = 29 * result + minor;
+ result = 29 * result + beta;
+ result = 29 * result + bugfix;
+ return result;
+ }
+
+ /**
+ * Returns a string representation of the form "1.27", "1.27.2" or "1.27.beta3".
+ * @return A string representation of the form "1.27", "1.27.2" or "1.27.beta3".
+ */
+ public String toString() {
+ StringBuffer buf = new StringBuffer();
+ buf.append(major).append('.').append(minor);
+ if (beta != 0) {
+ buf.append(".beta").append(beta);
+ } else if (bugfix != 0) {
+ buf.append('.').append(bugfix);
+ }
+
+ return buf.toString();
+ }
+
+ /**
+ * Compares this object with the specified object for order.
+ * @param version The object to compare to.
+ * @return A negative integer, zero, or a positive integer as this object is less than, equal to, or
+ * greater than the specified object.
+ */
+ @Override
+ public int compareTo(Version version) {
+ if (major < version.major) {
+ return -1;
+ } else if (major > version.major) {
+ return 1;
+ }
+
+ if (minor < version.minor) {
+ return -1;
+ } else if (minor > version.minor) {
+ return 1;
+ }
+
+ if (bugfix < version.bugfix) {
+ return -1;
+ } else if (bugfix > version.bugfix) {
+ return 1;
+ }
+
+ int thisBeta = beta == 0 ? Integer.MAX_VALUE : beta;
+ int otherBeta = version.beta == 0 ? Integer.MAX_VALUE : version.beta;
+
+ if (thisBeta < otherBeta) {
+ return -1;
+ } else if (thisBeta > otherBeta) {
+ return 1;
+ }
+
+ return 0;
+ }
+} \ No newline at end of file
diff --git a/subsonic-android/src/net/sourceforge/subsonic/androidapp/provider/SearchSuggestionProvider.java b/subsonic-android/src/net/sourceforge/subsonic/androidapp/provider/SearchSuggestionProvider.java
new file mode 100644
index 00000000..d3ba4f5c
--- /dev/null
+++ b/subsonic-android/src/net/sourceforge/subsonic/androidapp/provider/SearchSuggestionProvider.java
@@ -0,0 +1,36 @@
+/*
+ This file is part of Subsonic.
+
+ Subsonic is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ Subsonic is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with Subsonic. If not, see <http://www.gnu.org/licenses/>.
+
+ Copyright 2010 (C) Sindre Mehus
+ */
+package net.sourceforge.subsonic.androidapp.provider;
+
+import android.content.SearchRecentSuggestionsProvider;
+
+/**
+ * Provides search suggestions based on recent searches.
+ *
+ * @author Sindre Mehus
+ */
+public class SearchSuggestionProvider extends SearchRecentSuggestionsProvider {
+
+ public static final String AUTHORITY = SearchSuggestionProvider.class.getName();
+ public static final int MODE = DATABASE_MODE_QUERIES;
+
+ public SearchSuggestionProvider() {
+ setupSuggestions(AUTHORITY, MODE);
+ }
+} \ No newline at end of file
diff --git a/subsonic-android/src/net/sourceforge/subsonic/androidapp/provider/SubsonicAppWidgetProvider.java b/subsonic-android/src/net/sourceforge/subsonic/androidapp/provider/SubsonicAppWidgetProvider.java
new file mode 100644
index 00000000..dba3bdcd
--- /dev/null
+++ b/subsonic-android/src/net/sourceforge/subsonic/androidapp/provider/SubsonicAppWidgetProvider.java
@@ -0,0 +1,238 @@
+/*
+ This file is part of Subsonic.
+
+ Subsonic is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ Subsonic is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with Subsonic. If not, see <http://www.gnu.org/licenses/>.
+
+ Copyright 2010 (C) Sindre Mehus
+ */
+package net.sourceforge.subsonic.androidapp.provider;
+
+import android.app.PendingIntent;
+import android.appwidget.AppWidgetManager;
+import android.appwidget.AppWidgetProvider;
+import android.content.ComponentName;
+import android.content.Context;
+import android.content.Intent;
+import android.content.res.Resources;
+import android.graphics.Bitmap;
+import android.graphics.Bitmap.Config;
+import android.graphics.Canvas;
+import android.graphics.Paint;
+import android.graphics.PorterDuff.Mode;
+import android.graphics.PorterDuffXfermode;
+import android.graphics.Rect;
+import android.graphics.RectF;
+import android.os.Environment;
+import android.util.Log;
+import android.view.KeyEvent;
+import android.widget.RemoteViews;
+import net.sourceforge.subsonic.androidapp.R;
+import net.sourceforge.subsonic.androidapp.activity.DownloadActivity;
+import net.sourceforge.subsonic.androidapp.activity.MainActivity;
+import net.sourceforge.subsonic.androidapp.domain.MusicDirectory;
+import net.sourceforge.subsonic.androidapp.service.DownloadService;
+import net.sourceforge.subsonic.androidapp.service.DownloadServiceImpl;
+import net.sourceforge.subsonic.androidapp.util.FileUtil;
+
+/**
+ * Simple widget to show currently playing album art along
+ * with play/pause and next track buttons.
+ * <p/>
+ * Based on source code from the stock Android Music app.
+ *
+ * @author Sindre Mehus
+ */
+public class SubsonicAppWidgetProvider extends AppWidgetProvider {
+
+ private static SubsonicAppWidgetProvider instance;
+ private static final String TAG = SubsonicAppWidgetProvider.class.getSimpleName();
+
+ public static synchronized SubsonicAppWidgetProvider getInstance() {
+ if (instance == null) {
+ instance = new SubsonicAppWidgetProvider();
+ }
+ return instance;
+ }
+
+ @Override
+ public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) {
+ defaultAppWidget(context, appWidgetIds);
+ }
+
+ /**
+ * Initialize given widgets to default state, where we launch Subsonic on default click
+ * and hide actions if service not running.
+ */
+ private void defaultAppWidget(Context context, int[] appWidgetIds) {
+ final Resources res = context.getResources();
+ final RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.appwidget);
+
+ views.setTextViewText(R.id.artist, res.getText(R.string.widget_initial_text));
+
+ linkButtons(context, views, false);
+ pushUpdate(context, appWidgetIds, views);
+ }
+
+ private void pushUpdate(Context context, int[] appWidgetIds, RemoteViews views) {
+ // Update specific list of appWidgetIds if given, otherwise default to all
+ final AppWidgetManager manager = AppWidgetManager.getInstance(context);
+ if (appWidgetIds != null) {
+ manager.updateAppWidget(appWidgetIds, views);
+ } else {
+ manager.updateAppWidget(new ComponentName(context, this.getClass()), views);
+ }
+ }
+
+ /**
+ * Handle a change notification coming over from {@link DownloadService}
+ */
+ public void notifyChange(Context context, DownloadService service, boolean playing) {
+ if (hasInstances(context)) {
+ performUpdate(context, service, null, playing);
+ }
+ }
+
+ /**
+ * Check against {@link AppWidgetManager} if there are any instances of this widget.
+ */
+ private boolean hasInstances(Context context) {
+ AppWidgetManager manager = AppWidgetManager.getInstance(context);
+ int[] appWidgetIds = manager.getAppWidgetIds(new ComponentName(context, getClass()));
+ return (appWidgetIds.length > 0);
+ }
+
+ /**
+ * Update all active widget instances by pushing changes
+ */
+ private void performUpdate(Context context, DownloadService service, int[] appWidgetIds, boolean playing) {
+ final Resources res = context.getResources();
+ final RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.appwidget);
+
+ MusicDirectory.Entry currentPlaying = service.getCurrentPlaying() == null ? null : service.getCurrentPlaying().getSong();
+ String title = currentPlaying == null ? null : currentPlaying.getTitle();
+ CharSequence artist = currentPlaying == null ? null : currentPlaying.getArtist();
+ CharSequence errorState = null;
+
+ // Show error message?
+ String status = Environment.getExternalStorageState();
+ if (status.equals(Environment.MEDIA_SHARED) ||
+ status.equals(Environment.MEDIA_UNMOUNTED)) {
+ errorState = res.getText(R.string.widget_sdcard_busy);
+ } else if (status.equals(Environment.MEDIA_REMOVED)) {
+ errorState = res.getText(R.string.widget_sdcard_missing);
+ } else if (currentPlaying == null) {
+ errorState = res.getText(R.string.widget_initial_text);
+ }
+
+ if (errorState != null) {
+ // Show error state to user
+ views.setTextViewText(R.id.title,null);
+ views.setTextViewText(R.id.artist, errorState);
+ views.setImageViewResource(R.id.appwidget_coverart, R.drawable.appwidget_art_default);
+ } else {
+ // No error, so show normal titles
+ views.setTextViewText(R.id.title, title);
+ views.setTextViewText(R.id.artist, artist);
+ }
+
+ // Set correct drawable for pause state
+ if (playing) {
+ views.setImageViewResource(R.id.control_play, R.drawable.ic_appwidget_music_pause);
+ } else {
+ views.setImageViewResource(R.id.control_play, R.drawable.ic_appwidget_music_play);
+ }
+
+ // Set the cover art
+ try {
+ int size = context.getResources().getDrawable(R.drawable.appwidget_art_default).getIntrinsicHeight();
+ Bitmap bitmap = currentPlaying == null ? null : FileUtil.getAlbumArtBitmap(context, currentPlaying, size);
+
+ if (bitmap == null) {
+ // Set default cover art
+ views.setImageViewResource(R.id.appwidget_coverart, R.drawable.appwidget_art_unknown);
+ } else {
+ bitmap = getRoundedCornerBitmap(bitmap);
+ views.setImageViewBitmap(R.id.appwidget_coverart, bitmap);
+ }
+ } catch (Exception x) {
+ Log.e(TAG, "Failed to load cover art", x);
+ views.setImageViewResource(R.id.appwidget_coverart, R.drawable.appwidget_art_unknown);
+ }
+
+ // Link actions buttons to intents
+ linkButtons(context, views, currentPlaying != null);
+
+ pushUpdate(context, appWidgetIds, views);
+ }
+
+ /**
+ * Round the corners of a bitmap for the cover art image
+ */
+ private static Bitmap getRoundedCornerBitmap(Bitmap bitmap) {
+ Bitmap output = Bitmap.createBitmap(bitmap.getWidth(), bitmap.getHeight(), Config.ARGB_8888);
+ Canvas canvas = new Canvas(output);
+
+ final int color = 0xff424242;
+ final Paint paint = new Paint();
+ final float roundPx = 10;
+
+ // Add extra width to the rect so the right side wont be rounded.
+ final Rect rect = new Rect(0, 0, bitmap.getWidth() + (int) roundPx, bitmap.getHeight());
+ final RectF rectF = new RectF(rect);
+
+ paint.setAntiAlias(true);
+ canvas.drawARGB(0, 0, 0, 0);
+ paint.setColor(color);
+ canvas.drawRoundRect(rectF, roundPx, roundPx, paint);
+
+ paint.setXfermode(new PorterDuffXfermode(Mode.SRC_IN));
+ canvas.drawBitmap(bitmap, rect, rect, paint);
+
+ return output;
+ }
+
+ /**
+ * Link up various button actions using {@link PendingIntent}.
+ *
+ * @param playerActive True if player is active in background, which means
+ * widget click will launch {@link DownloadActivity},
+ * otherwise we launch {@link MainActivity}.
+ */
+ private void linkButtons(Context context, RemoteViews views, boolean playerActive) {
+
+ Intent intent = new Intent(context, playerActive ? DownloadActivity.class : MainActivity.class);
+ PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, intent, 0);
+ views.setOnClickPendingIntent(R.id.appwidget_coverart, pendingIntent);
+ views.setOnClickPendingIntent(R.id.appwidget_top, pendingIntent);
+
+ // Emulate media button clicks.
+ intent = new Intent("1");
+ intent.setComponent(new ComponentName(context, DownloadServiceImpl.class));
+ intent.putExtra(Intent.EXTRA_KEY_EVENT, new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE));
+ pendingIntent = PendingIntent.getService(context, 0, intent, 0);
+ views.setOnClickPendingIntent(R.id.control_play, pendingIntent);
+
+ intent = new Intent("2"); // Use a unique action name to ensure a different PendingIntent to be created.
+ intent.setComponent(new ComponentName(context, DownloadServiceImpl.class));
+ intent.putExtra(Intent.EXTRA_KEY_EVENT, new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_MEDIA_NEXT));
+ pendingIntent = PendingIntent.getService(context, 0, intent, 0);
+ views.setOnClickPendingIntent(R.id.control_next, pendingIntent);
+
+ intent = new Intent("3"); // Use a unique action name to ensure a different PendingIntent to be created.
+ intent.setComponent(new ComponentName(context, DownloadServiceImpl.class));
+ intent.putExtra(Intent.EXTRA_KEY_EVENT, new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_MEDIA_PREVIOUS));
+ pendingIntent = PendingIntent.getService(context, 0, intent, 0);
+ views.setOnClickPendingIntent(R.id.control_previous, pendingIntent);
+ }
+}
diff --git a/subsonic-android/src/net/sourceforge/subsonic/androidapp/receiver/BluetoothIntentReceiver.java b/subsonic-android/src/net/sourceforge/subsonic/androidapp/receiver/BluetoothIntentReceiver.java
new file mode 100644
index 00000000..6bf17ac2
--- /dev/null
+++ b/subsonic-android/src/net/sourceforge/subsonic/androidapp/receiver/BluetoothIntentReceiver.java
@@ -0,0 +1,53 @@
+/*
+ This file is part of Subsonic.
+
+ Subsonic is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ Subsonic is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with Subsonic. If not, see <http://www.gnu.org/licenses/>.
+
+ Copyright 2010 (C) Sindre Mehus
+ */
+package net.sourceforge.subsonic.androidapp.receiver;
+
+import android.content.BroadcastReceiver;
+import android.content.Context;
+import android.content.Intent;
+import android.util.Log;
+import net.sourceforge.subsonic.androidapp.service.DownloadServiceImpl;
+import net.sourceforge.subsonic.androidapp.util.Util;
+
+/**
+ * Request media button focus when connected to Bluetooth A2DP.
+ *
+ * @author Sindre Mehus
+ */
+public class BluetoothIntentReceiver extends BroadcastReceiver {
+
+ private static final String TAG = BluetoothIntentReceiver.class.getSimpleName();
+
+ @Override
+ public void onReceive(Context context, Intent intent) {
+ int state = intent.getIntExtra("android.bluetooth.a2dp.extra.SINK_STATE", -1);
+ Log.i(TAG, "android.bluetooth.a2dp.extra.SINK_STATE, state = " + state);
+ boolean connected = state == 2; // android.bluetooth.BluetoothA2dp.STATE_CONNECTED
+ if (connected) {
+ Log.i(TAG, "Connected to Bluetooth A2DP, requesting media button focus.");
+ Util.registerMediaButtonEventReceiver(context);
+ }
+
+ boolean disconnected = state == 0; // android.bluetooth.BluetoothA2dp.STATE_DISCONNECTED
+ if (disconnected) {
+ Log.i(TAG, "Disconnected from Bluetooth A2DP, requesting pause.");
+ context.sendBroadcast(new Intent(DownloadServiceImpl.CMD_PAUSE));
+ }
+ }
+} \ No newline at end of file
diff --git a/subsonic-android/src/net/sourceforge/subsonic/androidapp/receiver/MediaButtonIntentReceiver.java b/subsonic-android/src/net/sourceforge/subsonic/androidapp/receiver/MediaButtonIntentReceiver.java
new file mode 100644
index 00000000..5287d933
--- /dev/null
+++ b/subsonic-android/src/net/sourceforge/subsonic/androidapp/receiver/MediaButtonIntentReceiver.java
@@ -0,0 +1,50 @@
+/*
+ This file is part of Subsonic.
+
+ Subsonic is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ Subsonic is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with Subsonic. If not, see <http://www.gnu.org/licenses/>.
+
+ Copyright 2010 (C) Sindre Mehus
+ */
+package net.sourceforge.subsonic.androidapp.receiver;
+
+import android.content.BroadcastReceiver;
+import android.content.Context;
+import android.content.Intent;
+import android.util.Log;
+import android.view.KeyEvent;
+import net.sourceforge.subsonic.androidapp.service.DownloadServiceImpl;
+
+/**
+ * @author Sindre Mehus
+ */
+public class MediaButtonIntentReceiver extends BroadcastReceiver {
+
+ private static final String TAG = MediaButtonIntentReceiver.class.getSimpleName();
+
+ @Override
+ public void onReceive(Context context, Intent intent) {
+ KeyEvent event = (KeyEvent) intent.getExtras().get(Intent.EXTRA_KEY_EVENT);
+ Log.i(TAG, "Got MEDIA_BUTTON key event: " + event);
+
+ Intent serviceIntent = new Intent(context, DownloadServiceImpl.class);
+ serviceIntent.putExtra(Intent.EXTRA_KEY_EVENT, event);
+ context.startService(serviceIntent);
+
+ try {
+ abortBroadcast();
+ } catch (Exception x) {
+ // Ignored.
+ }
+ }
+}
diff --git a/subsonic-android/src/net/sourceforge/subsonic/androidapp/service/CachedMusicService.java b/subsonic-android/src/net/sourceforge/subsonic/androidapp/service/CachedMusicService.java
new file mode 100644
index 00000000..a06f3995
--- /dev/null
+++ b/subsonic-android/src/net/sourceforge/subsonic/androidapp/service/CachedMusicService.java
@@ -0,0 +1,237 @@
+/*
+ This file is part of Subsonic.
+
+ Subsonic is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ Subsonic is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with Subsonic. If not, see <http://www.gnu.org/licenses/>.
+
+ Copyright 2009 (C) Sindre Mehus
+ */
+package net.sourceforge.subsonic.androidapp.service;
+
+import java.util.List;
+import java.util.concurrent.TimeUnit;
+
+import org.apache.http.HttpResponse;
+
+import android.content.Context;
+import android.graphics.Bitmap;
+import net.sourceforge.subsonic.androidapp.domain.Indexes;
+import net.sourceforge.subsonic.androidapp.domain.JukeboxStatus;
+import net.sourceforge.subsonic.androidapp.domain.Lyrics;
+import net.sourceforge.subsonic.androidapp.domain.MusicDirectory;
+import net.sourceforge.subsonic.androidapp.domain.MusicFolder;
+import net.sourceforge.subsonic.androidapp.domain.Playlist;
+import net.sourceforge.subsonic.androidapp.domain.SearchCritera;
+import net.sourceforge.subsonic.androidapp.domain.SearchResult;
+import net.sourceforge.subsonic.androidapp.domain.Version;
+import net.sourceforge.subsonic.androidapp.util.CancellableTask;
+import net.sourceforge.subsonic.androidapp.util.LRUCache;
+import net.sourceforge.subsonic.androidapp.util.ProgressListener;
+import net.sourceforge.subsonic.androidapp.util.TimeLimitedCache;
+import net.sourceforge.subsonic.androidapp.util.Util;
+
+/**
+ * @author Sindre Mehus
+ */
+public class CachedMusicService implements MusicService {
+
+ private static final int MUSIC_DIR_CACHE_SIZE = 20;
+ private static final int TTL_MUSIC_DIR = 5 * 60; // Five minutes
+
+ private final MusicService musicService;
+ private final LRUCache<String, TimeLimitedCache<MusicDirectory>> cachedMusicDirectories;
+ private final TimeLimitedCache<Boolean> cachedLicenseValid = new TimeLimitedCache<Boolean>(120, TimeUnit.SECONDS);
+ private final TimeLimitedCache<Indexes> cachedIndexes = new TimeLimitedCache<Indexes>(60 * 60, TimeUnit.SECONDS);
+ private final TimeLimitedCache<List<Playlist>> cachedPlaylists = new TimeLimitedCache<List<Playlist>>(60, TimeUnit.SECONDS);
+ private final TimeLimitedCache<List<MusicFolder>> cachedMusicFolders = new TimeLimitedCache<List<MusicFolder>>(10 * 3600, TimeUnit.SECONDS);
+ private String restUrl;
+
+ public CachedMusicService(MusicService musicService) {
+ this.musicService = musicService;
+ cachedMusicDirectories = new LRUCache<String, TimeLimitedCache<MusicDirectory>>(MUSIC_DIR_CACHE_SIZE);
+ }
+
+ @Override
+ public void ping(Context context, ProgressListener progressListener) throws Exception {
+ checkSettingsChanged(context);
+ musicService.ping(context, progressListener);
+ }
+
+ @Override
+ public boolean isLicenseValid(Context context, ProgressListener progressListener) throws Exception {
+ checkSettingsChanged(context);
+ Boolean result = cachedLicenseValid.get();
+ if (result == null) {
+ result = musicService.isLicenseValid(context, progressListener);
+ cachedLicenseValid.set(result, result ? 30L * 60L : 2L * 60L, TimeUnit.SECONDS);
+ }
+ return result;
+ }
+
+ @Override
+ public List<MusicFolder> getMusicFolders(boolean refresh, Context context, ProgressListener progressListener) throws Exception {
+ checkSettingsChanged(context);
+ if (refresh) {
+ cachedMusicFolders.clear();
+ }
+ List<MusicFolder> result = cachedMusicFolders.get();
+ if (result == null) {
+ result = musicService.getMusicFolders(refresh, context, progressListener);
+ cachedMusicFolders.set(result);
+ }
+ return result;
+ }
+
+ @Override
+ public Indexes getIndexes(String musicFolderId, boolean refresh, Context context, ProgressListener progressListener) throws Exception {
+ checkSettingsChanged(context);
+ if (refresh) {
+ cachedIndexes.clear();
+ cachedMusicFolders.clear();
+ cachedMusicDirectories.clear();
+ }
+ Indexes result = cachedIndexes.get();
+ if (result == null) {
+ result = musicService.getIndexes(musicFolderId, refresh, context, progressListener);
+ cachedIndexes.set(result);
+ }
+ return result;
+ }
+
+ @Override
+ public MusicDirectory getMusicDirectory(String id, boolean refresh, Context context, ProgressListener progressListener) throws Exception {
+ checkSettingsChanged(context);
+ TimeLimitedCache<MusicDirectory> cache = refresh ? null : cachedMusicDirectories.get(id);
+ MusicDirectory dir = cache == null ? null : cache.get();
+ if (dir == null) {
+ dir = musicService.getMusicDirectory(id, refresh, context, progressListener);
+ cache = new TimeLimitedCache<MusicDirectory>(TTL_MUSIC_DIR, TimeUnit.SECONDS);
+ cache.set(dir);
+ cachedMusicDirectories.put(id, cache);
+ }
+ return dir;
+ }
+
+ @Override
+ public SearchResult search(SearchCritera criteria, Context context, ProgressListener progressListener) throws Exception {
+ return musicService.search(criteria, context, progressListener);
+ }
+
+ @Override
+ public MusicDirectory getPlaylist(String id, Context context, ProgressListener progressListener) throws Exception {
+ return musicService.getPlaylist(id, context, progressListener);
+ }
+
+ @Override
+ public List<Playlist> getPlaylists(boolean refresh, Context context, ProgressListener progressListener) throws Exception {
+ checkSettingsChanged(context);
+ List<Playlist> result = refresh ? null : cachedPlaylists.get();
+ if (result == null) {
+ result = musicService.getPlaylists(refresh, context, progressListener);
+ cachedPlaylists.set(result);
+ }
+ return result;
+ }
+
+ @Override
+ public void createPlaylist(String id, String name, List<MusicDirectory.Entry> entries, Context context, ProgressListener progressListener) throws Exception {
+ musicService.createPlaylist(id, name, entries, context, progressListener);
+ }
+
+ @Override
+ public Lyrics getLyrics(String artist, String title, Context context, ProgressListener progressListener) throws Exception {
+ return musicService.getLyrics(artist, title, context, progressListener);
+ }
+
+ @Override
+ public void scrobble(String id, boolean submission, Context context, ProgressListener progressListener) throws Exception {
+ musicService.scrobble(id, submission, context, progressListener);
+ }
+
+ @Override
+ public MusicDirectory getAlbumList(String type, int size, int offset, Context context, ProgressListener progressListener) throws Exception {
+ return musicService.getAlbumList(type, size, offset, context, progressListener);
+ }
+
+ @Override
+ public MusicDirectory getRandomSongs(int size, Context context, ProgressListener progressListener) throws Exception {
+ return musicService.getRandomSongs(size, context, progressListener);
+ }
+
+ @Override
+ public Bitmap getCoverArt(Context context, MusicDirectory.Entry entry, int size, boolean saveToFile, ProgressListener progressListener) throws Exception {
+ return musicService.getCoverArt(context, entry, size, saveToFile, progressListener);
+ }
+
+ @Override
+ public HttpResponse getDownloadInputStream(Context context, MusicDirectory.Entry song, long offset, int maxBitrate, CancellableTask task) throws Exception {
+ return musicService.getDownloadInputStream(context, song, offset, maxBitrate, task);
+ }
+
+ @Override
+ public Version getLocalVersion(Context context) throws Exception {
+ return musicService.getLocalVersion(context);
+ }
+
+ @Override
+ public Version getLatestVersion(Context context, ProgressListener progressListener) throws Exception {
+ return musicService.getLatestVersion(context, progressListener);
+ }
+
+ @Override
+ public String getVideoUrl(Context context, String id) {
+ return musicService.getVideoUrl(context, id);
+ }
+
+ @Override
+ public JukeboxStatus updateJukeboxPlaylist(List<String> ids, Context context, ProgressListener progressListener) throws Exception {
+ return musicService.updateJukeboxPlaylist(ids, context, progressListener);
+ }
+
+ @Override
+ public JukeboxStatus skipJukebox(int index, int offsetSeconds, Context context, ProgressListener progressListener) throws Exception {
+ return musicService.skipJukebox(index, offsetSeconds, context, progressListener);
+ }
+
+ @Override
+ public JukeboxStatus stopJukebox(Context context, ProgressListener progressListener) throws Exception {
+ return musicService.stopJukebox(context, progressListener);
+ }
+
+ @Override
+ public JukeboxStatus startJukebox(Context context, ProgressListener progressListener) throws Exception {
+ return musicService.startJukebox(context, progressListener);
+ }
+
+ @Override
+ public JukeboxStatus getJukeboxStatus(Context context, ProgressListener progressListener) throws Exception {
+ return musicService.getJukeboxStatus(context, progressListener);
+ }
+
+ @Override
+ public JukeboxStatus setJukeboxGain(float gain, Context context, ProgressListener progressListener) throws Exception {
+ return musicService.setJukeboxGain(gain, context, progressListener);
+ }
+
+ private void checkSettingsChanged(Context context) {
+ String newUrl = Util.getRestUrl(context, null);
+ if (!Util.equals(newUrl, restUrl)) {
+ cachedMusicFolders.clear();
+ cachedMusicDirectories.clear();
+ cachedLicenseValid.clear();
+ cachedIndexes.clear();
+ cachedPlaylists.clear();
+ restUrl = newUrl;
+ }
+ }
+}
diff --git a/subsonic-android/src/net/sourceforge/subsonic/androidapp/service/DownloadFile.java b/subsonic-android/src/net/sourceforge/subsonic/androidapp/service/DownloadFile.java
new file mode 100644
index 00000000..46373afe
--- /dev/null
+++ b/subsonic-android/src/net/sourceforge/subsonic/androidapp/service/DownloadFile.java
@@ -0,0 +1,323 @@
+/*
+ This file is part of Subsonic.
+
+ Subsonic is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ Subsonic is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with Subsonic. If not, see <http://www.gnu.org/licenses/>.
+
+ Copyright 2009 (C) Sindre Mehus
+ */
+package net.sourceforge.subsonic.androidapp.service;
+
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+
+import android.content.Context;
+import android.os.PowerManager;
+import android.util.DisplayMetrics;
+import android.util.Log;
+import net.sourceforge.subsonic.androidapp.domain.MusicDirectory;
+import net.sourceforge.subsonic.androidapp.util.CancellableTask;
+import net.sourceforge.subsonic.androidapp.util.FileUtil;
+import net.sourceforge.subsonic.androidapp.util.Util;
+import net.sourceforge.subsonic.androidapp.util.CacheCleaner;
+
+import org.apache.http.HttpResponse;
+import org.apache.http.HttpStatus;
+
+/**
+ * @author Sindre Mehus
+ * @version $Id$
+ */
+public class DownloadFile {
+
+ private static final String TAG = DownloadFile.class.getSimpleName();
+ private final Context context;
+ private final MusicDirectory.Entry song;
+ private final File partialFile;
+ private final File completeFile;
+ private final File saveFile;
+
+ private final MediaStoreService mediaStoreService;
+ private CancellableTask downloadTask;
+ private boolean save;
+ private boolean failed;
+ private int bitRate;
+
+ public DownloadFile(Context context, MusicDirectory.Entry song, boolean save) {
+ this.context = context;
+ this.song = song;
+ this.save = save;
+ saveFile = FileUtil.getSongFile(context, song);
+ bitRate = Util.getMaxBitrate(context);
+ partialFile = new File(saveFile.getParent(), FileUtil.getBaseName(saveFile.getName()) +
+ "." + bitRate + ".partial." + FileUtil.getExtension(saveFile.getName()));
+ completeFile = new File(saveFile.getParent(), FileUtil.getBaseName(saveFile.getName()) +
+ ".complete." + FileUtil.getExtension(saveFile.getName()));
+ mediaStoreService = new MediaStoreService(context);
+ }
+
+ public MusicDirectory.Entry getSong() {
+ return song;
+ }
+
+ /**
+ * Returns the effective bit rate.
+ */
+ public int getBitRate() {
+ if (bitRate > 0) {
+ return bitRate;
+ }
+ return song.getBitRate() == null ? 160 : song.getBitRate();
+ }
+
+ public synchronized void download() {
+ FileUtil.createDirectoryForParent(saveFile);
+ failed = false;
+ downloadTask = new DownloadTask();
+ downloadTask.start();
+ }
+
+ public synchronized void cancelDownload() {
+ if (downloadTask != null) {
+ downloadTask.cancel();
+ }
+ }
+
+ public File getCompleteFile() {
+ if (saveFile.exists()) {
+ return saveFile;
+ }
+
+ if (completeFile.exists()) {
+ return completeFile;
+ }
+
+ return saveFile;
+ }
+
+ public File getPartialFile() {
+ return partialFile;
+ }
+
+ public boolean isSaved() {
+ return saveFile.exists();
+ }
+
+ public synchronized boolean isCompleteFileAvailable() {
+ return saveFile.exists() || completeFile.exists();
+ }
+
+ public synchronized boolean isWorkDone() {
+ return saveFile.exists() || (completeFile.exists() && !save);
+ }
+
+ public synchronized boolean isDownloading() {
+ return downloadTask != null && downloadTask.isRunning();
+ }
+
+ public synchronized boolean isDownloadCancelled() {
+ return downloadTask != null && downloadTask.isCancelled();
+ }
+
+ public boolean shouldSave() {
+ return save;
+ }
+
+ public boolean isFailed() {
+ return failed;
+ }
+
+ public void delete() {
+ cancelDownload();
+ Util.delete(partialFile);
+ Util.delete(completeFile);
+ Util.delete(saveFile);
+ mediaStoreService.deleteFromMediaStore(this);
+ }
+
+ public void unpin() {
+ if (saveFile.exists()) {
+ saveFile.renameTo(completeFile);
+ }
+ }
+
+ public boolean cleanup() {
+ boolean ok = true;
+ if (completeFile.exists() || saveFile.exists()) {
+ ok = Util.delete(partialFile);
+ }
+ if (saveFile.exists()) {
+ ok &= Util.delete(completeFile);
+ }
+ return ok;
+ }
+
+ // In support of LRU caching.
+ public void updateModificationDate() {
+ updateModificationDate(saveFile);
+ updateModificationDate(partialFile);
+ updateModificationDate(completeFile);
+ }
+
+ private void updateModificationDate(File file) {
+ if (file.exists()) {
+ boolean ok = file.setLastModified(System.currentTimeMillis());
+ if (!ok) {
+ Log.w(TAG, "Failed to set last-modified date on " + file);
+ }
+ }
+ }
+
+ @Override
+ public String toString() {
+ return "DownloadFile (" + song + ")";
+ }
+
+ private class DownloadTask extends CancellableTask {
+
+ @Override
+ public void execute() {
+
+ InputStream in = null;
+ FileOutputStream out = null;
+ PowerManager.WakeLock wakeLock = null;
+ try {
+
+ if (Util.isScreenLitOnDownload(context)) {
+ PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
+ wakeLock = pm.newWakeLock(PowerManager.SCREEN_DIM_WAKE_LOCK | PowerManager.ON_AFTER_RELEASE, toString());
+ wakeLock.acquire();
+ Log.i(TAG, "Acquired wake lock " + wakeLock);
+ }
+
+ if (saveFile.exists()) {
+ Log.i(TAG, saveFile + " already exists. Skipping.");
+ return;
+ }
+ if (completeFile.exists()) {
+ if (save) {
+ Util.atomicCopy(completeFile, saveFile);
+ } else {
+ Log.i(TAG, completeFile + " already exists. Skipping.");
+ }
+ return;
+ }
+
+ MusicService musicService = MusicServiceFactory.getMusicService(context);
+
+ // Attempt partial HTTP GET, appending to the file if it exists.
+ HttpResponse response = musicService.getDownloadInputStream(context, song, partialFile.length(), bitRate, DownloadTask.this);
+ in = response.getEntity().getContent();
+ boolean partial = response.getStatusLine().getStatusCode() == HttpStatus.SC_PARTIAL_CONTENT;
+ if (partial) {
+ Log.i(TAG, "Executed partial HTTP GET, skipping " + partialFile.length() + " bytes");
+ }
+
+ out = new FileOutputStream(partialFile, partial);
+ long n = copy(in, out);
+ Log.i(TAG, "Downloaded " + n + " bytes to " + partialFile);
+ out.flush();
+ out.close();
+
+ if (isCancelled()) {
+ throw new Exception("Download of '" + song + "' was cancelled");
+ }
+
+ downloadAndSaveCoverArt(musicService);
+
+ if (save) {
+ Util.atomicCopy(partialFile, saveFile);
+ mediaStoreService.saveInMediaStore(DownloadFile.this);
+ } else {
+ Util.atomicCopy(partialFile, completeFile);
+ }
+
+ } catch (Exception x) {
+ Util.close(out);
+ Util.delete(completeFile);
+ Util.delete(saveFile);
+ if (!isCancelled()) {
+ failed = true;
+ Log.w(TAG, "Failed to download '" + song + "'.", x);
+ }
+
+ } finally {
+ Util.close(in);
+ Util.close(out);
+ if (wakeLock != null) {
+ wakeLock.release();
+ Log.i(TAG, "Released wake lock " + wakeLock);
+ }
+ new CacheCleaner(context, DownloadServiceImpl.getInstance()).clean();
+ }
+ }
+
+ @Override
+ public String toString() {
+ return "DownloadTask (" + song + ")";
+ }
+
+ private void downloadAndSaveCoverArt(MusicService musicService) throws Exception {
+ try {
+ if (song.getCoverArt() != null) {
+ DisplayMetrics metrics = context.getResources().getDisplayMetrics();
+ int size = Math.min(metrics.widthPixels, metrics.heightPixels);
+ musicService.getCoverArt(context, song, size, true, null);
+ }
+ } catch (Exception x) {
+ Log.e(TAG, "Failed to get cover art.", x);
+ }
+ }
+
+ private long copy(final InputStream in, OutputStream out) throws IOException, InterruptedException {
+
+ // Start a thread that will close the input stream if the task is
+ // cancelled, thus causing the copy() method to return.
+ new Thread() {
+ @Override
+ public void run() {
+ while (true) {
+ Util.sleepQuietly(3000L);
+ if (isCancelled()) {
+ Util.close(in);
+ return;
+ }
+ if (!isRunning()) {
+ return;
+ }
+ }
+ }
+ }.start();
+
+ byte[] buffer = new byte[1024 * 16];
+ long count = 0;
+ int n;
+ long lastLog = System.currentTimeMillis();
+
+ while (!isCancelled() && (n = in.read(buffer)) != -1) {
+ out.write(buffer, 0, n);
+ count += n;
+
+ long now = System.currentTimeMillis();
+ if (now - lastLog > 3000L) { // Only every so often.
+ Log.i(TAG, "Downloaded " + Util.formatBytes(count) + " of " + song);
+ lastLog = now;
+ }
+ }
+ return count;
+ }
+ }
+}
diff --git a/subsonic-android/src/net/sourceforge/subsonic/androidapp/service/DownloadService.java b/subsonic-android/src/net/sourceforge/subsonic/androidapp/service/DownloadService.java
new file mode 100644
index 00000000..b136bdbc
--- /dev/null
+++ b/subsonic-android/src/net/sourceforge/subsonic/androidapp/service/DownloadService.java
@@ -0,0 +1,112 @@
+/*
+ This file is part of Subsonic.
+
+ Subsonic is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ Subsonic is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with Subsonic. If not, see <http://www.gnu.org/licenses/>.
+
+ Copyright 2009 (C) Sindre Mehus
+ */
+package net.sourceforge.subsonic.androidapp.service;
+
+import java.util.List;
+
+import net.sourceforge.subsonic.androidapp.audiofx.EqualizerController;
+import net.sourceforge.subsonic.androidapp.audiofx.VisualizerController;
+import net.sourceforge.subsonic.androidapp.domain.MusicDirectory;
+import net.sourceforge.subsonic.androidapp.domain.PlayerState;
+import net.sourceforge.subsonic.androidapp.domain.RepeatMode;
+
+/**
+ * @author Sindre Mehus
+ * @version $Id$
+ */
+public interface DownloadService {
+
+ void download(List<MusicDirectory.Entry> songs, boolean save, boolean autoplay, boolean playNext);
+
+ void setShufflePlayEnabled(boolean enabled);
+
+ boolean isShufflePlayEnabled();
+
+ void shuffle();
+
+ RepeatMode getRepeatMode();
+
+ void setRepeatMode(RepeatMode repeatMode);
+
+ boolean getKeepScreenOn();
+
+ void setKeepScreenOn(boolean screenOn);
+
+ boolean getShowVisualization();
+
+ void setShowVisualization(boolean showVisualization);
+
+ void clear();
+
+ void clearIncomplete();
+
+ int size();
+
+ void remove(DownloadFile downloadFile);
+
+ List<DownloadFile> getDownloads();
+
+ int getCurrentPlayingIndex();
+
+ DownloadFile getCurrentPlaying();
+
+ DownloadFile getCurrentDownloading();
+
+ void play(int index);
+
+ void seekTo(int position);
+
+ void previous();
+
+ void next();
+
+ void pause();
+
+ void start();
+
+ void reset();
+
+ PlayerState getPlayerState();
+
+ int getPlayerPosition();
+
+ int getPlayerDuration();
+
+ void delete(List<MusicDirectory.Entry> songs);
+
+ void unpin(List<MusicDirectory.Entry> songs);
+
+ DownloadFile forSong(MusicDirectory.Entry song);
+
+ long getDownloadListUpdateRevision();
+
+ void setSuggestedPlaylistName(String name);
+
+ String getSuggestedPlaylistName();
+
+ EqualizerController getEqualizerController();
+
+ VisualizerController getVisualizerController();
+
+ boolean isJukeboxEnabled();
+
+ void setJukeboxEnabled(boolean b);
+
+ void adjustJukeboxVolume(boolean up);
+}
diff --git a/subsonic-android/src/net/sourceforge/subsonic/androidapp/service/DownloadServiceImpl.java b/subsonic-android/src/net/sourceforge/subsonic/androidapp/service/DownloadServiceImpl.java
new file mode 100644
index 00000000..2e668fea
--- /dev/null
+++ b/subsonic-android/src/net/sourceforge/subsonic/androidapp/service/DownloadServiceImpl.java
@@ -0,0 +1,930 @@
+/*
+ This file is part of Subsonic.
+
+ Subsonic is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ Subsonic is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with Subsonic. If not, see <http://www.gnu.org/licenses/>.
+
+ Copyright 2009 (C) Sindre Mehus
+ */
+package net.sourceforge.subsonic.androidapp.service;
+
+import android.app.Service;
+import android.content.Context;
+import android.content.Intent;
+import android.media.AudioManager;
+import android.media.MediaPlayer;
+import android.os.Handler;
+import android.os.IBinder;
+import android.os.PowerManager;
+import android.util.Log;
+import net.sourceforge.subsonic.androidapp.audiofx.EqualizerController;
+import net.sourceforge.subsonic.androidapp.audiofx.VisualizerController;
+import net.sourceforge.subsonic.androidapp.domain.MusicDirectory;
+import net.sourceforge.subsonic.androidapp.domain.PlayerState;
+import net.sourceforge.subsonic.androidapp.domain.RepeatMode;
+import net.sourceforge.subsonic.androidapp.util.CancellableTask;
+import net.sourceforge.subsonic.androidapp.util.LRUCache;
+import net.sourceforge.subsonic.androidapp.util.ShufflePlayBuffer;
+import net.sourceforge.subsonic.androidapp.util.SimpleServiceBinder;
+import net.sourceforge.subsonic.androidapp.util.Util;
+
+import java.io.File;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Iterator;
+import java.util.List;
+
+import static net.sourceforge.subsonic.androidapp.domain.PlayerState.*;
+
+/**
+ * @author Sindre Mehus
+ * @version $Id$
+ */
+public class DownloadServiceImpl extends Service implements DownloadService {
+
+ private static final String TAG = DownloadServiceImpl.class.getSimpleName();
+
+ public static final String CMD_PLAY = "net.sourceforge.subsonic.androidapp.CMD_PLAY";
+ public static final String CMD_TOGGLEPAUSE = "net.sourceforge.subsonic.androidapp.CMD_TOGGLEPAUSE";
+ public static final String CMD_PAUSE = "net.sourceforge.subsonic.androidapp.CMD_PAUSE";
+ public static final String CMD_STOP = "net.sourceforge.subsonic.androidapp.CMD_STOP";
+ public static final String CMD_PREVIOUS = "net.sourceforge.subsonic.androidapp.CMD_PREVIOUS";
+ public static final String CMD_NEXT = "net.sourceforge.subsonic.androidapp.CMD_NEXT";
+
+ private final IBinder binder = new SimpleServiceBinder<DownloadService>(this);
+ private MediaPlayer mediaPlayer;
+ private final List<DownloadFile> downloadList = new ArrayList<DownloadFile>();
+ private final Handler handler = new Handler();
+ private final DownloadServiceLifecycleSupport lifecycleSupport = new DownloadServiceLifecycleSupport(this);
+ private final ShufflePlayBuffer shufflePlayBuffer = new ShufflePlayBuffer(this);
+
+ private final LRUCache<MusicDirectory.Entry, DownloadFile> downloadFileCache = new LRUCache<MusicDirectory.Entry, DownloadFile>(100);
+ private final List<DownloadFile> cleanupCandidates = new ArrayList<DownloadFile>();
+ private final Scrobbler scrobbler = new Scrobbler();
+ private final JukeboxService jukeboxService = new JukeboxService(this);
+ private DownloadFile currentPlaying;
+ private DownloadFile currentDownloading;
+ private CancellableTask bufferTask;
+ private PlayerState playerState = IDLE;
+ private boolean shufflePlay;
+ private long revision;
+ private static DownloadService instance;
+ private String suggestedPlaylistName;
+ private PowerManager.WakeLock wakeLock;
+ private boolean keepScreenOn = false;
+
+ private static boolean equalizerAvailable;
+ private static boolean visualizerAvailable;
+ private EqualizerController equalizerController;
+ private VisualizerController visualizerController;
+ private boolean showVisualization;
+ private boolean jukeboxEnabled;
+
+ static {
+ try {
+ EqualizerController.checkAvailable();
+ equalizerAvailable = true;
+ } catch (Throwable t) {
+ equalizerAvailable = false;
+ }
+ }
+ static {
+ try {
+ VisualizerController.checkAvailable();
+ visualizerAvailable = true;
+ } catch (Throwable t) {
+ visualizerAvailable = false;
+ }
+ }
+
+ @Override
+ public void onCreate() {
+ super.onCreate();
+
+ mediaPlayer = new MediaPlayer();
+ mediaPlayer.setWakeMode(this, PowerManager.PARTIAL_WAKE_LOCK);
+
+ mediaPlayer.setOnErrorListener(new MediaPlayer.OnErrorListener() {
+ @Override
+ public boolean onError(MediaPlayer mediaPlayer, int what, int more) {
+ handleError(new Exception("MediaPlayer error: " + what + " (" + more + ")"));
+ return false;
+ }
+ });
+
+ if (equalizerAvailable) {
+ equalizerController = new EqualizerController(this, mediaPlayer);
+ if (!equalizerController.isAvailable()) {
+ equalizerController = null;
+ } else {
+ equalizerController.loadSettings();
+ }
+ }
+ if (visualizerAvailable) {
+ visualizerController = new VisualizerController(this, mediaPlayer);
+ if (!visualizerController.isAvailable()) {
+ visualizerController = null;
+ }
+ }
+
+ PowerManager pm = (PowerManager)getSystemService(Context.POWER_SERVICE);
+ wakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, this.getClass().getName());
+ wakeLock.setReferenceCounted(false);
+
+ instance = this;
+ lifecycleSupport.onCreate();
+ }
+
+ @Override
+ public void onStart(Intent intent, int startId) {
+ super.onStart(intent, startId);
+ lifecycleSupport.onStart(intent);
+ }
+
+ @Override
+ public void onDestroy() {
+ super.onDestroy();
+ lifecycleSupport.onDestroy();
+ mediaPlayer.release();
+ shufflePlayBuffer.shutdown();
+ if (equalizerController != null) {
+ equalizerController.release();
+ }
+ if (visualizerController != null) {
+ visualizerController.release();
+ }
+
+ instance = null;
+ }
+
+ public static DownloadService getInstance() {
+ return instance;
+ }
+
+ @Override
+ public IBinder onBind(Intent intent) {
+ return binder;
+ }
+
+ @Override
+ public synchronized void download(List<MusicDirectory.Entry> songs, boolean save, boolean autoplay, boolean playNext) {
+ shufflePlay = false;
+ int offset = 1;
+
+ if (songs.isEmpty()) {
+ return;
+ }
+ if (playNext) {
+ if (autoplay && getCurrentPlayingIndex() >= 0) {
+ offset = 0;
+ }
+ for (MusicDirectory.Entry song : songs) {
+ DownloadFile downloadFile = new DownloadFile(this, song, save);
+ downloadList.add(getCurrentPlayingIndex() + offset, downloadFile);
+ offset++;
+ }
+ revision++;
+ } else {
+ for (MusicDirectory.Entry song : songs) {
+ DownloadFile downloadFile = new DownloadFile(this, song, save);
+ downloadList.add(downloadFile);
+ }
+ revision++;
+ }
+ updateJukeboxPlaylist();
+
+ if (autoplay) {
+ play(0);
+ } else {
+ if (currentPlaying == null) {
+ currentPlaying = downloadList.get(0);
+ }
+ checkDownloads();
+ }
+ lifecycleSupport.serializeDownloadQueue();
+ }
+
+ private void updateJukeboxPlaylist() {
+ if (jukeboxEnabled) {
+ jukeboxService.updatePlaylist();
+ }
+ }
+
+ public void restore(List<MusicDirectory.Entry> songs, int currentPlayingIndex, int currentPlayingPosition) {
+ download(songs, false, false, false);
+ if (currentPlayingIndex != -1) {
+ play(currentPlayingIndex, false);
+ if (currentPlaying.isCompleteFileAvailable()) {
+ doPlay(currentPlaying, currentPlayingPosition, false);
+ }
+ }
+ }
+
+ @Override
+ public synchronized void setShufflePlayEnabled(boolean enabled) {
+ if (shufflePlay == enabled) {
+ return;
+ }
+
+ shufflePlay = enabled;
+ if (shufflePlay) {
+ clear();
+ checkDownloads();
+ }
+ }
+
+ @Override
+ public synchronized boolean isShufflePlayEnabled() {
+ return shufflePlay;
+ }
+
+ @Override
+ public synchronized void shuffle() {
+ Collections.shuffle(downloadList);
+ if (currentPlaying != null) {
+ downloadList.remove(getCurrentPlayingIndex());
+ downloadList.add(0, currentPlaying);
+ }
+ revision++;
+ lifecycleSupport.serializeDownloadQueue();
+ updateJukeboxPlaylist();
+ }
+
+ @Override
+ public RepeatMode getRepeatMode() {
+ return Util.getRepeatMode(this);
+ }
+
+ @Override
+ public void setRepeatMode(RepeatMode repeatMode) {
+ Util.setRepeatMode(this, repeatMode);
+ }
+
+ @Override
+ public boolean getKeepScreenOn() {
+ return keepScreenOn;
+ }
+
+ @Override
+ public void setKeepScreenOn(boolean keepScreenOn) {
+ this.keepScreenOn = keepScreenOn;
+ }
+
+ @Override
+ public boolean getShowVisualization() {
+ return showVisualization;
+ }
+
+ @Override
+ public void setShowVisualization(boolean showVisualization) {
+ this.showVisualization = showVisualization;
+ }
+
+ @Override
+ public synchronized DownloadFile forSong(MusicDirectory.Entry song) {
+ for (DownloadFile downloadFile : downloadList) {
+ if (downloadFile.getSong().equals(song)) {
+ return downloadFile;
+ }
+ }
+
+ DownloadFile downloadFile = downloadFileCache.get(song);
+ if (downloadFile == null) {
+ downloadFile = new DownloadFile(this, song, false);
+ downloadFileCache.put(song, downloadFile);
+ }
+ return downloadFile;
+ }
+
+ @Override
+ public synchronized void clear() {
+ clear(true);
+ }
+
+ @Override
+ public synchronized void clearIncomplete() {
+ reset();
+ Iterator<DownloadFile> iterator = downloadList.iterator();
+ while (iterator.hasNext()) {
+ DownloadFile downloadFile = iterator.next();
+ if (!downloadFile.isCompleteFileAvailable()) {
+ iterator.remove();
+ }
+ }
+ lifecycleSupport.serializeDownloadQueue();
+ updateJukeboxPlaylist();
+ }
+
+ @Override
+ public synchronized int size() {
+ return downloadList.size();
+ }
+
+ public synchronized void clear(boolean serialize) {
+ reset();
+ downloadList.clear();
+ revision++;
+ if (currentDownloading != null) {
+ currentDownloading.cancelDownload();
+ currentDownloading = null;
+ }
+ setCurrentPlaying(null, false);
+
+ if (serialize) {
+ lifecycleSupport.serializeDownloadQueue();
+ }
+ updateJukeboxPlaylist();
+ }
+
+ @Override
+ public synchronized void remove(DownloadFile downloadFile) {
+ if (downloadFile == currentDownloading) {
+ currentDownloading.cancelDownload();
+ currentDownloading = null;
+ }
+ if (downloadFile == currentPlaying) {
+ reset();
+ setCurrentPlaying(null, false);
+ }
+ downloadList.remove(downloadFile);
+ revision++;
+ lifecycleSupport.serializeDownloadQueue();
+ updateJukeboxPlaylist();
+ }
+
+ @Override
+ public synchronized void delete(List<MusicDirectory.Entry> songs) {
+ for (MusicDirectory.Entry song : songs) {
+ forSong(song).delete();
+ }
+ }
+
+ @Override
+ public synchronized void unpin(List<MusicDirectory.Entry> songs) {
+ for (MusicDirectory.Entry song : songs) {
+ forSong(song).unpin();
+ }
+ }
+
+ synchronized void setCurrentPlaying(int currentPlayingIndex, boolean showNotification) {
+ try {
+ setCurrentPlaying(downloadList.get(currentPlayingIndex), showNotification);
+ } catch (IndexOutOfBoundsException x) {
+ // Ignored
+ }
+ }
+
+ synchronized void setCurrentPlaying(DownloadFile currentPlaying, boolean showNotification) {
+ this.currentPlaying = currentPlaying;
+
+ if (currentPlaying != null) {
+ Util.broadcastNewTrackInfo(this, currentPlaying.getSong());
+ } else {
+ Util.broadcastNewTrackInfo(this, null);
+ }
+
+ if (currentPlaying != null && showNotification) {
+ Util.showPlayingNotification(this, this, handler, currentPlaying.getSong());
+ } else {
+ Util.hidePlayingNotification(this, this, handler);
+ }
+ }
+
+ @Override
+ public synchronized int getCurrentPlayingIndex() {
+ return downloadList.indexOf(currentPlaying);
+ }
+
+ @Override
+ public DownloadFile getCurrentPlaying() {
+ return currentPlaying;
+ }
+
+ @Override
+ public DownloadFile getCurrentDownloading() {
+ return currentDownloading;
+ }
+
+ @Override
+ public synchronized List<DownloadFile> getDownloads() {
+ return new ArrayList<DownloadFile>(downloadList);
+ }
+
+ /** Plays either the current song (resume) or the first/next one in queue. */
+ public synchronized void play()
+ {
+ int current = getCurrentPlayingIndex();
+ if (current == -1) {
+ play(0);
+ } else {
+ play(current);
+ }
+ }
+
+ @Override
+ public synchronized void play(int index) {
+ play(index, true);
+ }
+
+ private synchronized void play(int index, boolean start) {
+ if (index < 0 || index >= size()) {
+ reset();
+ setCurrentPlaying(null, false);
+ } else {
+ setCurrentPlaying(index, start);
+ checkDownloads();
+ if (start) {
+ if (jukeboxEnabled) {
+ jukeboxService.skip(getCurrentPlayingIndex(), 0);
+ setPlayerState(STARTED);
+ } else {
+ bufferAndPlay();
+ }
+ }
+ }
+ }
+
+ /** Plays or resumes the playback, depending on the current player state. */
+ public synchronized void togglePlayPause()
+ {
+ if (playerState == PAUSED || playerState == COMPLETED) {
+ start();
+ } else if (playerState == STOPPED || playerState == IDLE) {
+ play();
+ } else if (playerState == STARTED) {
+ pause();
+ }
+ }
+
+ @Override
+ public synchronized void seekTo(int position) {
+ try {
+ if (jukeboxEnabled) {
+ jukeboxService.skip(getCurrentPlayingIndex(), position / 1000);
+ } else {
+ mediaPlayer.seekTo(position);
+ }
+ } catch (Exception x) {
+ handleError(x);
+ }
+ }
+
+ @Override
+ public synchronized void previous() {
+ int index = getCurrentPlayingIndex();
+ if (index == -1) {
+ return;
+ }
+
+ // Restart song if played more than five seconds.
+ if (getPlayerPosition() > 5000 || index == 0) {
+ play(index);
+ } else {
+ play(index - 1);
+ }
+ }
+
+ @Override
+ public synchronized void next() {
+ int index = getCurrentPlayingIndex();
+ if (index != -1) {
+ play(index + 1);
+ }
+ }
+
+ private void onSongCompleted() {
+ int index = getCurrentPlayingIndex();
+ if (index != -1) {
+ switch (getRepeatMode()) {
+ case OFF:
+ play(index + 1);
+ break;
+ case ALL:
+ play((index + 1) % size());
+ break;
+ case SINGLE:
+ play(index);
+ break;
+ default:
+ break;
+ }
+ }
+ }
+
+ @Override
+ public synchronized void pause() {
+ try {
+ if (playerState == STARTED) {
+ if (jukeboxEnabled) {
+ jukeboxService.stop();
+ } else {
+ mediaPlayer.pause();
+ }
+ setPlayerState(PAUSED);
+ }
+ } catch (Exception x) {
+ handleError(x);
+ }
+ }
+
+ @Override
+ public synchronized void start() {
+ try {
+ if (jukeboxEnabled) {
+ jukeboxService.start();
+ } else {
+ mediaPlayer.start();
+ }
+ setPlayerState(STARTED);
+ } catch (Exception x) {
+ handleError(x);
+ }
+ }
+
+ @Override
+ public synchronized void reset() {
+ if (bufferTask != null) {
+ bufferTask.cancel();
+ }
+ try {
+ mediaPlayer.reset();
+ setPlayerState(IDLE);
+ } catch (Exception x) {
+ handleError(x);
+ }
+ }
+
+ @Override
+ public synchronized int getPlayerPosition() {
+ try {
+ if (playerState == IDLE || playerState == DOWNLOADING || playerState == PREPARING) {
+ return 0;
+ }
+ if (jukeboxEnabled) {
+ return jukeboxService.getPositionSeconds() * 1000;
+ } else {
+ return mediaPlayer.getCurrentPosition();
+ }
+ } catch (Exception x) {
+ handleError(x);
+ return 0;
+ }
+ }
+
+ @Override
+ public synchronized int getPlayerDuration() {
+ if (currentPlaying != null) {
+ Integer duration = currentPlaying.getSong().getDuration();
+ if (duration != null) {
+ return duration * 1000;
+ }
+ }
+ if (playerState != IDLE && playerState != DOWNLOADING && playerState != PlayerState.PREPARING) {
+ try {
+ return mediaPlayer.getDuration();
+ } catch (Exception x) {
+ handleError(x);
+ }
+ }
+ return 0;
+ }
+
+ @Override
+ public PlayerState getPlayerState() {
+ return playerState;
+ }
+
+ synchronized void setPlayerState(PlayerState playerState) {
+ Log.i(TAG, this.playerState.name() + " -> " + playerState.name() + " (" + currentPlaying + ")");
+
+ if (playerState == PAUSED) {
+ lifecycleSupport.serializeDownloadQueue();
+ }
+
+ boolean show = this.playerState == PAUSED && playerState == PlayerState.STARTED;
+ boolean hide = this.playerState == STARTED && playerState == PlayerState.PAUSED;
+ Util.broadcastPlaybackStatusChange(this, playerState);
+
+ this.playerState = playerState;
+ if (show) {
+ Util.showPlayingNotification(this, this, handler, currentPlaying.getSong());
+ } else if (hide) {
+ Util.hidePlayingNotification(this, this, handler);
+ }
+
+ if (playerState == STARTED) {
+ scrobbler.scrobble(this, currentPlaying, false);
+ } else if (playerState == COMPLETED) {
+ scrobbler.scrobble(this, currentPlaying, true);
+ }
+ }
+
+ @Override
+ public void setSuggestedPlaylistName(String name) {
+ this.suggestedPlaylistName = name;
+ }
+
+ @Override
+ public String getSuggestedPlaylistName() {
+ return suggestedPlaylistName;
+ }
+
+ @Override
+ public EqualizerController getEqualizerController() {
+ return equalizerController;
+ }
+
+ @Override
+ public VisualizerController getVisualizerController() {
+ return visualizerController;
+ }
+
+ @Override
+ public boolean isJukeboxEnabled() {
+ return jukeboxEnabled;
+ }
+
+ @Override
+ public void setJukeboxEnabled(boolean jukeboxEnabled) {
+ this.jukeboxEnabled = jukeboxEnabled;
+ jukeboxService.setEnabled(jukeboxEnabled);
+ if (jukeboxEnabled) {
+ reset();
+
+ // Cancel current download, if necessary.
+ if (currentDownloading != null) {
+ currentDownloading.cancelDownload();
+ }
+ }
+ }
+
+ @Override
+ public void adjustJukeboxVolume(boolean up) {
+ jukeboxService.adjustVolume(up);
+ }
+
+ private synchronized void bufferAndPlay() {
+ reset();
+
+ bufferTask = new BufferTask(currentPlaying, 0);
+ bufferTask.start();
+ }
+
+ private synchronized void doPlay(final DownloadFile downloadFile, int position, boolean start) {
+ try {
+ final File file = downloadFile.isCompleteFileAvailable() ? downloadFile.getCompleteFile() : downloadFile.getPartialFile();
+ downloadFile.updateModificationDate();
+ mediaPlayer.setOnCompletionListener(null);
+ mediaPlayer.reset();
+ setPlayerState(IDLE);
+ mediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
+ mediaPlayer.setDataSource(file.getPath());
+ setPlayerState(PREPARING);
+ mediaPlayer.prepare();
+ setPlayerState(PREPARED);
+
+ mediaPlayer.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
+ @Override
+ public void onCompletion(MediaPlayer mediaPlayer) {
+
+ // Acquire a temporary wakelock, since when we return from
+ // this callback the MediaPlayer will release its wakelock
+ // and allow the device to go to sleep.
+ wakeLock.acquire(60000);
+
+ setPlayerState(COMPLETED);
+
+ // If COMPLETED and not playing partial file, we are *really" finished
+ // with the song and can move on to the next.
+ if (!file.equals(downloadFile.getPartialFile())) {
+ onSongCompleted();
+ return;
+ }
+
+ // If file is not completely downloaded, restart the playback from the current position.
+ int pos = mediaPlayer.getCurrentPosition();
+ synchronized (DownloadServiceImpl.this) {
+
+ // Work-around for apparent bug on certain phones: If close (less than ten seconds) to the end
+ // of the song, skip to the next rather than restarting it.
+ Integer duration = downloadFile.getSong().getDuration() == null ? null : downloadFile.getSong().getDuration() * 1000;
+ if (duration != null) {
+ if (Math.abs(duration - pos) < 10000) {
+ Log.i(TAG, "Skipping restart from " + pos + " of " + duration);
+ onSongCompleted();
+ return;
+ }
+ }
+
+ Log.i(TAG, "Requesting restart from " + pos + " of " + duration);
+ reset();
+ bufferTask = new BufferTask(downloadFile, pos);
+ bufferTask.start();
+ }
+ }
+ });
+
+ if (position != 0) {
+ Log.i(TAG, "Restarting player from position " + position);
+ mediaPlayer.seekTo(position);
+ }
+
+ if (start) {
+ mediaPlayer.start();
+ setPlayerState(STARTED);
+ } else {
+ setPlayerState(PAUSED);
+ }
+ lifecycleSupport.serializeDownloadQueue();
+
+ } catch (Exception x) {
+ handleError(x);
+ }
+ }
+
+ private void handleError(Exception x) {
+ Log.w(TAG, "Media player error: " + x, x);
+ mediaPlayer.reset();
+ setPlayerState(IDLE);
+ }
+
+ protected synchronized void checkDownloads() {
+
+ if (!Util.isExternalStoragePresent() || !lifecycleSupport.isExternalStorageAvailable()) {
+ return;
+ }
+
+ if (shufflePlay) {
+ checkShufflePlay();
+ }
+
+ if (jukeboxEnabled || !Util.isNetworkConnected(this)) {
+ return;
+ }
+
+ if (downloadList.isEmpty()) {
+ return;
+ }
+
+ // Need to download current playing?
+ if (currentPlaying != null &&
+ currentPlaying != currentDownloading &&
+ !currentPlaying.isCompleteFileAvailable()) {
+
+ // Cancel current download, if necessary.
+ if (currentDownloading != null) {
+ currentDownloading.cancelDownload();
+ }
+
+ currentDownloading = currentPlaying;
+ currentDownloading.download();
+ cleanupCandidates.add(currentDownloading);
+ }
+
+ // Find a suitable target for download.
+ else if (currentDownloading == null || currentDownloading.isWorkDone() || currentDownloading.isFailed()) {
+
+ int n = size();
+ if (n == 0) {
+ return;
+ }
+
+ int preloaded = 0;
+
+ int start = currentPlaying == null ? 0 : getCurrentPlayingIndex();
+ int i = start;
+ do {
+ DownloadFile downloadFile = downloadList.get(i);
+ if (!downloadFile.isWorkDone()) {
+ if (downloadFile.shouldSave() || preloaded < Util.getPreloadCount(this)) {
+ currentDownloading = downloadFile;
+ currentDownloading.download();
+ cleanupCandidates.add(currentDownloading);
+ break;
+ }
+ } else if (currentPlaying != downloadFile) {
+ preloaded++;
+ }
+
+ i = (i + 1) % n;
+ } while (i != start);
+ }
+
+ // Delete obsolete .partial and .complete files.
+ cleanup();
+ }
+
+ private synchronized void checkShufflePlay() {
+
+ final int listSize = 20;
+ boolean wasEmpty = downloadList.isEmpty();
+
+ long revisionBefore = revision;
+
+ // First, ensure that list is at least 20 songs long.
+ int size = size();
+ if (size < listSize) {
+ for (MusicDirectory.Entry song : shufflePlayBuffer.get(listSize - size)) {
+ DownloadFile downloadFile = new DownloadFile(this, song, false);
+ downloadList.add(downloadFile);
+ revision++;
+ }
+ }
+
+ int currIndex = currentPlaying == null ? 0 : getCurrentPlayingIndex();
+
+ // Only shift playlist if playing song #5 or later.
+ if (currIndex > 4) {
+ int songsToShift = currIndex - 2;
+ for (MusicDirectory.Entry song : shufflePlayBuffer.get(songsToShift)) {
+ downloadList.add(new DownloadFile(this, song, false));
+ downloadList.get(0).cancelDownload();
+ downloadList.remove(0);
+ revision++;
+ }
+ }
+
+ if (revisionBefore != revision) {
+ updateJukeboxPlaylist();
+ }
+
+ if (wasEmpty && !downloadList.isEmpty()) {
+ play(0);
+ }
+ }
+
+ public long getDownloadListUpdateRevision() {
+ return revision;
+ }
+
+ private synchronized void cleanup() {
+ Iterator<DownloadFile> iterator = cleanupCandidates.iterator();
+ while (iterator.hasNext()) {
+ DownloadFile downloadFile = iterator.next();
+ if (downloadFile != currentPlaying && downloadFile != currentDownloading) {
+ if (downloadFile.cleanup()) {
+ iterator.remove();
+ }
+ }
+ }
+ }
+
+ private class BufferTask extends CancellableTask {
+
+ private static final int BUFFER_LENGTH_SECONDS = 5;
+
+ private final DownloadFile downloadFile;
+ private final int position;
+ private final long expectedFileSize;
+ private final File partialFile;
+
+ public BufferTask(DownloadFile downloadFile, int position) {
+ this.downloadFile = downloadFile;
+ this.position = position;
+ partialFile = downloadFile.getPartialFile();
+
+ // Calculate roughly how many bytes BUFFER_LENGTH_SECONDS corresponds to.
+ int bitRate = downloadFile.getBitRate();
+ long byteCount = Math.max(100000, bitRate * 1024 / 8 * BUFFER_LENGTH_SECONDS);
+
+ // Find out how large the file should grow before resuming playback.
+ expectedFileSize = partialFile.length() + byteCount;
+ }
+
+ @Override
+ public void execute() {
+ setPlayerState(DOWNLOADING);
+
+ while (!bufferComplete()) {
+ Util.sleepQuietly(1000L);
+ if (isCancelled()) {
+ return;
+ }
+ }
+ doPlay(downloadFile, position, true);
+ }
+
+ private boolean bufferComplete() {
+ boolean completeFileAvailable = downloadFile.isCompleteFileAvailable();
+ long size = partialFile.length();
+
+ Log.i(TAG, "Buffering " + partialFile + " (" + size + "/" + expectedFileSize + ", " + completeFileAvailable + ")");
+ return completeFileAvailable || size >= expectedFileSize;
+ }
+
+ @Override
+ public String toString() {
+ return "BufferTask (" + downloadFile + ")";
+ }
+ }
+}
diff --git a/subsonic-android/src/net/sourceforge/subsonic/androidapp/service/DownloadServiceLifecycleSupport.java b/subsonic-android/src/net/sourceforge/subsonic/androidapp/service/DownloadServiceLifecycleSupport.java
new file mode 100644
index 00000000..2010a4a1
--- /dev/null
+++ b/subsonic-android/src/net/sourceforge/subsonic/androidapp/service/DownloadServiceLifecycleSupport.java
@@ -0,0 +1,266 @@
+/*
+ This file is part of Subsonic.
+
+ Subsonic is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ Subsonic is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with Subsonic. If not, see <http://www.gnu.org/licenses/>.
+
+ Copyright 2009 (C) Sindre Mehus
+ */
+package net.sourceforge.subsonic.androidapp.service;
+
+import java.io.Serializable;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.concurrent.Executors;
+import java.util.concurrent.ScheduledExecutorService;
+import java.util.concurrent.TimeUnit;
+
+import android.content.BroadcastReceiver;
+import android.content.Context;
+import android.content.Intent;
+import android.content.IntentFilter;
+import android.telephony.PhoneStateListener;
+import android.telephony.TelephonyManager;
+import android.util.Log;
+import android.view.KeyEvent;
+import net.sourceforge.subsonic.androidapp.domain.MusicDirectory;
+import net.sourceforge.subsonic.androidapp.domain.PlayerState;
+import net.sourceforge.subsonic.androidapp.util.CacheCleaner;
+import net.sourceforge.subsonic.androidapp.util.FileUtil;
+import net.sourceforge.subsonic.androidapp.util.Util;
+
+/**
+ * @author Sindre Mehus
+ */
+public class DownloadServiceLifecycleSupport {
+
+ private static final String TAG = DownloadServiceLifecycleSupport.class.getSimpleName();
+ private static final String FILENAME_DOWNLOADS_SER = "downloadstate.ser";
+
+ private final DownloadServiceImpl downloadService;
+ private ScheduledExecutorService executorService;
+ private BroadcastReceiver headsetEventReceiver;
+ private BroadcastReceiver ejectEventReceiver;
+ private PhoneStateListener phoneStateListener;
+ private boolean externalStorageAvailable= true;
+
+ /**
+ * This receiver manages the intent that could come from other applications.
+ */
+ private BroadcastReceiver intentReceiver = new BroadcastReceiver() {
+ @Override
+ public void onReceive(Context context, Intent intent) {
+ String action = intent.getAction();
+ Log.i(TAG, "intentReceiver.onReceive: " + action);
+ if (DownloadServiceImpl.CMD_PLAY.equals(action)) {
+ downloadService.play();
+ } else if (DownloadServiceImpl.CMD_NEXT.equals(action)) {
+ downloadService.next();
+ } else if (DownloadServiceImpl.CMD_PREVIOUS.equals(action)) {
+ downloadService.previous();
+ } else if (DownloadServiceImpl.CMD_TOGGLEPAUSE.equals(action)) {
+ downloadService.togglePlayPause();
+ } else if (DownloadServiceImpl.CMD_PAUSE.equals(action)) {
+ downloadService.pause();
+ } else if (DownloadServiceImpl.CMD_STOP.equals(action)) {
+ downloadService.pause();
+ downloadService.seekTo(0);
+ }
+ }
+ };
+
+
+ public DownloadServiceLifecycleSupport(DownloadServiceImpl downloadService) {
+ this.downloadService = downloadService;
+ }
+
+ public void onCreate() {
+ Runnable downloadChecker = new Runnable() {
+ @Override
+ public void run() {
+ try {
+ downloadService.checkDownloads();
+ } catch (Throwable x) {
+ Log.e(TAG, "checkDownloads() failed.", x);
+ }
+ }
+ };
+
+ executorService = Executors.newScheduledThreadPool(2);
+ executorService.scheduleWithFixedDelay(downloadChecker, 5, 5, TimeUnit.SECONDS);
+
+ // Pause when headset is unplugged.
+ headsetEventReceiver = new BroadcastReceiver() {
+ @Override
+ public void onReceive(Context context, Intent intent) {
+ Log.i(TAG, "Headset event for: " + intent.getExtras().get("name"));
+ if (intent.getExtras().getInt("state") == 0) {
+ downloadService.pause();
+ }
+ }
+ };
+ downloadService.registerReceiver(headsetEventReceiver, new IntentFilter(Intent.ACTION_HEADSET_PLUG));
+
+ // Stop when SD card is ejected.
+ ejectEventReceiver = new BroadcastReceiver() {
+ @Override
+ public void onReceive(Context context, Intent intent) {
+ externalStorageAvailable = Intent.ACTION_MEDIA_MOUNTED.equals(intent.getAction());
+ if (!externalStorageAvailable) {
+ Log.i(TAG, "External media is ejecting. Stopping playback.");
+ downloadService.reset();
+ } else {
+ Log.i(TAG, "External media is available.");
+ }
+ }
+ };
+ IntentFilter ejectFilter = new IntentFilter(Intent.ACTION_MEDIA_EJECT);
+ ejectFilter.addAction(Intent.ACTION_MEDIA_MOUNTED);
+ ejectFilter.addDataScheme("file");
+ downloadService.registerReceiver(ejectEventReceiver, ejectFilter);
+
+ // React to media buttons.
+ Util.registerMediaButtonEventReceiver(downloadService);
+
+ // Pause temporarily on incoming phone calls.
+ phoneStateListener = new MyPhoneStateListener();
+ TelephonyManager telephonyManager = (TelephonyManager) downloadService.getSystemService(Context.TELEPHONY_SERVICE);
+ telephonyManager.listen(phoneStateListener, PhoneStateListener.LISTEN_CALL_STATE);
+
+ // Register the handler for outside intents.
+ IntentFilter commandFilter = new IntentFilter();
+ commandFilter.addAction(DownloadServiceImpl.CMD_PLAY);
+ commandFilter.addAction(DownloadServiceImpl.CMD_TOGGLEPAUSE);
+ commandFilter.addAction(DownloadServiceImpl.CMD_PAUSE);
+ commandFilter.addAction(DownloadServiceImpl.CMD_STOP);
+ commandFilter.addAction(DownloadServiceImpl.CMD_PREVIOUS);
+ commandFilter.addAction(DownloadServiceImpl.CMD_NEXT);
+ downloadService.registerReceiver(intentReceiver, commandFilter);
+
+ deserializeDownloadQueue();
+
+ new CacheCleaner(downloadService, downloadService).clean();
+ }
+
+ public void onStart(Intent intent) {
+ if (intent != null && intent.getExtras() != null) {
+ KeyEvent event = (KeyEvent) intent.getExtras().get(Intent.EXTRA_KEY_EVENT);
+ if (event != null) {
+ handleKeyEvent(event);
+ }
+ }
+ }
+
+ public void onDestroy() {
+ executorService.shutdown();
+ serializeDownloadQueue();
+ downloadService.clear(false);
+ downloadService.unregisterReceiver(ejectEventReceiver);
+ downloadService.unregisterReceiver(headsetEventReceiver);
+ downloadService.unregisterReceiver(intentReceiver);
+
+ TelephonyManager telephonyManager = (TelephonyManager) downloadService.getSystemService(Context.TELEPHONY_SERVICE);
+ telephonyManager.listen(phoneStateListener, PhoneStateListener.LISTEN_NONE);
+ }
+
+ public boolean isExternalStorageAvailable() {
+ return externalStorageAvailable;
+ }
+
+ public void serializeDownloadQueue() {
+ State state = new State();
+ for (DownloadFile downloadFile : downloadService.getDownloads()) {
+ state.songs.add(downloadFile.getSong());
+ }
+ state.currentPlayingIndex = downloadService.getCurrentPlayingIndex();
+ state.currentPlayingPosition = downloadService.getPlayerPosition();
+
+ Log.i(TAG, "Serialized currentPlayingIndex: " + state.currentPlayingIndex + ", currentPlayingPosition: " + state.currentPlayingPosition);
+ FileUtil.serialize(downloadService, state, FILENAME_DOWNLOADS_SER);
+ }
+
+ private void deserializeDownloadQueue() {
+ State state = FileUtil.deserialize(downloadService, FILENAME_DOWNLOADS_SER);
+ if (state == null) {
+ return;
+ }
+ Log.i(TAG, "Deserialized currentPlayingIndex: " + state.currentPlayingIndex + ", currentPlayingPosition: " + state.currentPlayingPosition);
+ downloadService.restore(state.songs, state.currentPlayingIndex, state.currentPlayingPosition);
+
+ // Work-around: Serialize again, as the restore() method creates a serialization without current playing info.
+ serializeDownloadQueue();
+ }
+
+ private void handleKeyEvent(KeyEvent event) {
+ if (event.getAction() != KeyEvent.ACTION_DOWN || event.getRepeatCount() > 0) {
+ return;
+ }
+
+ switch (event.getKeyCode()) {
+ case KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE:
+ case KeyEvent.KEYCODE_HEADSETHOOK:
+ downloadService.togglePlayPause();
+ break;
+ case KeyEvent.KEYCODE_MEDIA_PREVIOUS:
+ downloadService.previous();
+ break;
+ case KeyEvent.KEYCODE_MEDIA_NEXT:
+ if (downloadService.getCurrentPlayingIndex() < downloadService.size() - 1) {
+ downloadService.next();
+ }
+ break;
+ case KeyEvent.KEYCODE_MEDIA_STOP:
+ downloadService.reset();
+ break;
+ default:
+ break;
+ }
+ }
+
+ /**
+ * Logic taken from packages/apps/Music. Will pause when an incoming
+ * call rings or if a call (incoming or outgoing) is connected.
+ */
+ private class MyPhoneStateListener extends PhoneStateListener {
+ private boolean resumeAfterCall;
+
+ @Override
+ public void onCallStateChanged(int state, String incomingNumber) {
+ switch (state) {
+ case TelephonyManager.CALL_STATE_RINGING:
+ case TelephonyManager.CALL_STATE_OFFHOOK:
+ if (downloadService.getPlayerState() == PlayerState.STARTED) {
+ resumeAfterCall = true;
+ downloadService.pause();
+ }
+ break;
+ case TelephonyManager.CALL_STATE_IDLE:
+ if (resumeAfterCall) {
+ resumeAfterCall = false;
+ downloadService.start();
+ }
+ break;
+ default:
+ break;
+ }
+ }
+ }
+
+ private static class State implements Serializable {
+ private static final long serialVersionUID = -6346438781062572270L;
+
+ private List<MusicDirectory.Entry> songs = new ArrayList<MusicDirectory.Entry>();
+ private int currentPlayingIndex;
+ private int currentPlayingPosition;
+ }
+} \ No newline at end of file
diff --git a/subsonic-android/src/net/sourceforge/subsonic/androidapp/service/JukeboxService.java b/subsonic-android/src/net/sourceforge/subsonic/androidapp/service/JukeboxService.java
new file mode 100644
index 00000000..e3145f4e
--- /dev/null
+++ b/subsonic-android/src/net/sourceforge/subsonic/androidapp/service/JukeboxService.java
@@ -0,0 +1,356 @@
+/*
+ This file is part of Subsonic.
+
+ Subsonic is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ Subsonic is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with Subsonic. If not, see <http://www.gnu.org/licenses/>.
+
+ Copyright 2009 (C) Sindre Mehus
+ */
+package net.sourceforge.subsonic.androidapp.service;
+
+import android.content.Context;
+import android.os.Handler;
+import android.util.Log;
+import android.view.Gravity;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.widget.ProgressBar;
+import android.widget.Toast;
+import net.sourceforge.subsonic.androidapp.R;
+import net.sourceforge.subsonic.androidapp.domain.JukeboxStatus;
+import net.sourceforge.subsonic.androidapp.domain.PlayerState;
+import net.sourceforge.subsonic.androidapp.service.parser.SubsonicRESTException;
+import net.sourceforge.subsonic.androidapp.util.Util;
+
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+import java.util.concurrent.Executors;
+import java.util.concurrent.LinkedBlockingQueue;
+import java.util.concurrent.ScheduledExecutorService;
+import java.util.concurrent.ScheduledFuture;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.atomic.AtomicLong;
+
+/**
+ * Provides an asynchronous interface to the remote jukebox on the Subsonic server.
+ *
+ * @author Sindre Mehus
+ * @version $Id$
+ */
+public class JukeboxService {
+
+ private static final String TAG = JukeboxService.class.getSimpleName();
+ private static final long STATUS_UPDATE_INTERVAL_SECONDS = 5L;
+
+ private final Handler handler = new Handler();
+ private final TaskQueue tasks = new TaskQueue();
+ private final DownloadServiceImpl downloadService;
+ private final ScheduledExecutorService executorService = Executors.newSingleThreadScheduledExecutor();
+ private ScheduledFuture<?> statusUpdateFuture;
+ private final AtomicLong timeOfLastUpdate = new AtomicLong();
+ private JukeboxStatus jukeboxStatus;
+ private float gain = 0.5f;
+ private VolumeToast volumeToast;
+
+ // TODO: Report warning if queue fills up.
+ // TODO: Create shutdown method?
+ // TODO: Disable repeat.
+ // TODO: Persist RC state?
+ // TODO: Minimize status updates.
+
+ public JukeboxService(DownloadServiceImpl downloadService) {
+ this.downloadService = downloadService;
+ new Thread() {
+ @Override
+ public void run() {
+ processTasks();
+ }
+ }.start();
+ }
+
+ private synchronized void startStatusUpdate() {
+ stopStatusUpdate();
+ Runnable updateTask = new Runnable() {
+ @Override
+ public void run() {
+ tasks.remove(GetStatus.class);
+ tasks.add(new GetStatus());
+ }
+ };
+ statusUpdateFuture = executorService.scheduleWithFixedDelay(updateTask, STATUS_UPDATE_INTERVAL_SECONDS,
+ STATUS_UPDATE_INTERVAL_SECONDS, TimeUnit.SECONDS);
+ }
+
+ private synchronized void stopStatusUpdate() {
+ if (statusUpdateFuture != null) {
+ statusUpdateFuture.cancel(false);
+ statusUpdateFuture = null;
+ }
+ }
+
+ private void processTasks() {
+ while (true) {
+ JukeboxTask task = null;
+ try {
+ task = tasks.take();
+ JukeboxStatus status = task.execute();
+ onStatusUpdate(status);
+ } catch (Throwable x) {
+ onError(task, x);
+ }
+ }
+ }
+
+ private void onStatusUpdate(JukeboxStatus jukeboxStatus) {
+ timeOfLastUpdate.set(System.currentTimeMillis());
+ this.jukeboxStatus = jukeboxStatus;
+
+ // Track change?
+ Integer index = jukeboxStatus.getCurrentPlayingIndex();
+ if (index != null && index != -1 && index != downloadService.getCurrentPlayingIndex()) {
+ downloadService.setCurrentPlaying(index, true);
+ }
+ }
+
+ private void onError(JukeboxTask task, Throwable x) {
+ if (x instanceof ServerTooOldException && !(task instanceof Stop)) {
+ disableJukeboxOnError(x, R.string.download_jukebox_server_too_old);
+ } else if (x instanceof OfflineException && !(task instanceof Stop)) {
+ disableJukeboxOnError(x, R.string.download_jukebox_offline);
+ } else if (x instanceof SubsonicRESTException && ((SubsonicRESTException) x).getCode() == 50 && !(task instanceof Stop)) {
+ disableJukeboxOnError(x, R.string.download_jukebox_not_authorized);
+ } else {
+ Log.e(TAG, "Failed to process jukebox task: " + x, x);
+ }
+ }
+
+ private void disableJukeboxOnError(Throwable x, final int resourceId) {
+ Log.w(TAG, x.toString());
+ handler.post(new Runnable() {
+ @Override
+ public void run() {
+ Util.toast(downloadService, resourceId, false);
+ }
+ });
+ downloadService.setJukeboxEnabled(false);
+ }
+
+ public void updatePlaylist() {
+ tasks.remove(Skip.class);
+ tasks.remove(Stop.class);
+ tasks.remove(Start.class);
+
+ List<String> ids = new ArrayList<String>();
+ for (DownloadFile file : downloadService.getDownloads()) {
+ ids.add(file.getSong().getId());
+ }
+ tasks.add(new SetPlaylist(ids));
+ }
+
+ public void skip(final int index, final int offsetSeconds) {
+ tasks.remove(Skip.class);
+ tasks.remove(Stop.class);
+ tasks.remove(Start.class);
+
+ startStatusUpdate();
+ if (jukeboxStatus != null) {
+ jukeboxStatus.setPositionSeconds(offsetSeconds);
+ }
+ tasks.add(new Skip(index, offsetSeconds));
+ downloadService.setPlayerState(PlayerState.STARTED);
+ }
+
+ public void stop() {
+ tasks.remove(Stop.class);
+ tasks.remove(Start.class);
+
+ stopStatusUpdate();
+ tasks.add(new Stop());
+ }
+
+ public void start() {
+ tasks.remove(Stop.class);
+ tasks.remove(Start.class);
+
+ startStatusUpdate();
+ tasks.add(new Start());
+ }
+
+ public synchronized void adjustVolume(boolean up) {
+ float delta = up ? 0.1f : -0.1f;
+ gain += delta;
+ gain = Math.max(gain, 0.0f);
+ gain = Math.min(gain, 1.0f);
+
+ tasks.remove(SetGain.class);
+ tasks.add(new SetGain(gain));
+
+ if (volumeToast == null) {
+ volumeToast = new VolumeToast(downloadService);
+ }
+ volumeToast.setVolume(gain);
+ }
+
+ private MusicService getMusicService() {
+ return MusicServiceFactory.getMusicService(downloadService);
+ }
+
+ public int getPositionSeconds() {
+ if (jukeboxStatus == null || jukeboxStatus.getPositionSeconds() == null || timeOfLastUpdate.get() == 0) {
+ return 0;
+ }
+
+ if (jukeboxStatus.isPlaying()) {
+ int secondsSinceLastUpdate = (int) ((System.currentTimeMillis() - timeOfLastUpdate.get()) / 1000L);
+ return jukeboxStatus.getPositionSeconds() + secondsSinceLastUpdate;
+ }
+
+ return jukeboxStatus.getPositionSeconds();
+ }
+
+ public void setEnabled(boolean enabled) {
+ tasks.clear();
+ if (enabled) {
+ updatePlaylist();
+ }
+ stop();
+ downloadService.setPlayerState(PlayerState.IDLE);
+ }
+
+ private static class TaskQueue {
+
+ private final LinkedBlockingQueue<JukeboxTask> queue = new LinkedBlockingQueue<JukeboxTask>();
+
+ void add(JukeboxTask jukeboxTask) {
+ queue.add(jukeboxTask);
+ }
+
+ JukeboxTask take() throws InterruptedException {
+ return queue.take();
+ }
+
+ void remove(Class<? extends JukeboxTask> clazz) {
+ try {
+ Iterator<JukeboxTask> iterator = queue.iterator();
+ while (iterator.hasNext()) {
+ JukeboxTask task = iterator.next();
+ if (clazz.equals(task.getClass())) {
+ iterator.remove();
+ }
+ }
+ } catch (Throwable x) {
+ Log.w(TAG, "Failed to clean-up task queue.", x);
+ }
+ }
+
+ void clear() {
+ queue.clear();
+ }
+ }
+
+ private abstract class JukeboxTask {
+
+ abstract JukeboxStatus execute() throws Exception;
+
+ @Override
+ public String toString() {
+ return getClass().getSimpleName();
+ }
+ }
+
+ private class GetStatus extends JukeboxTask {
+ @Override
+ JukeboxStatus execute() throws Exception {
+ return getMusicService().getJukeboxStatus(downloadService, null);
+ }
+ }
+
+ private class SetPlaylist extends JukeboxTask {
+
+ private final List<String> ids;
+
+ SetPlaylist(List<String> ids) {
+ this.ids = ids;
+ }
+
+ @Override
+ JukeboxStatus execute() throws Exception {
+ return getMusicService().updateJukeboxPlaylist(ids, downloadService, null);
+ }
+ }
+
+ private class Skip extends JukeboxTask {
+ private final int index;
+ private final int offsetSeconds;
+
+ Skip(int index, int offsetSeconds) {
+ this.index = index;
+ this.offsetSeconds = offsetSeconds;
+ }
+
+ @Override
+ JukeboxStatus execute() throws Exception {
+ return getMusicService().skipJukebox(index, offsetSeconds, downloadService, null);
+ }
+ }
+
+ private class Stop extends JukeboxTask {
+ @Override
+ JukeboxStatus execute() throws Exception {
+ return getMusicService().stopJukebox(downloadService, null);
+ }
+ }
+
+ private class Start extends JukeboxTask {
+ @Override
+ JukeboxStatus execute() throws Exception {
+ return getMusicService().startJukebox(downloadService, null);
+ }
+ }
+
+ private class SetGain extends JukeboxTask {
+
+ private final float gain;
+
+ private SetGain(float gain) {
+ this.gain = gain;
+ }
+
+ @Override
+ JukeboxStatus execute() throws Exception {
+ return getMusicService().setJukeboxGain(gain, downloadService, null);
+ }
+ }
+
+ private static class VolumeToast extends Toast {
+
+ private final ProgressBar progressBar;
+
+ public VolumeToast(Context context) {
+ super(context);
+ setDuration(Toast.LENGTH_SHORT);
+ LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
+ View view = inflater.inflate(R.layout.jukebox_volume, null);
+ progressBar = (ProgressBar) view.findViewById(R.id.jukebox_volume_progress_bar);
+
+ setView(view);
+ setGravity(Gravity.TOP, 0, 0);
+ }
+
+ public void setVolume(float volume) {
+ progressBar.setProgress(Math.round(100 * volume));
+ show();
+ }
+ }
+}
diff --git a/subsonic-android/src/net/sourceforge/subsonic/androidapp/service/MediaStoreService.java b/subsonic-android/src/net/sourceforge/subsonic/androidapp/service/MediaStoreService.java
new file mode 100644
index 00000000..775fa3f5
--- /dev/null
+++ b/subsonic-android/src/net/sourceforge/subsonic/androidapp/service/MediaStoreService.java
@@ -0,0 +1,109 @@
+/*
+ This file is part of Subsonic.
+
+ Subsonic is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ Subsonic is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with Subsonic. If not, see <http://www.gnu.org/licenses/>.
+
+ Copyright 2009 (C) Sindre Mehus
+ */
+package net.sourceforge.subsonic.androidapp.service;
+
+import java.io.File;
+
+import android.content.ContentResolver;
+import android.content.ContentValues;
+import android.content.Context;
+import android.database.Cursor;
+import android.net.Uri;
+import android.provider.MediaStore;
+import android.util.Log;
+import net.sourceforge.subsonic.androidapp.domain.MusicDirectory;
+import net.sourceforge.subsonic.androidapp.util.FileUtil;
+
+/**
+ * @author Sindre Mehus
+ */
+public class MediaStoreService {
+
+ private static final String TAG = MediaStoreService.class.getSimpleName();
+ private static final Uri ALBUM_ART_URI = Uri.parse("content://media/external/audio/albumart");
+
+ private final Context context;
+
+ public MediaStoreService(Context context) {
+ this.context = context;
+ }
+
+ public void saveInMediaStore(DownloadFile downloadFile) {
+ MusicDirectory.Entry song = downloadFile.getSong();
+ File songFile = downloadFile.getCompleteFile();
+
+ // Delete existing row in case the song has been downloaded before.
+ deleteFromMediaStore(downloadFile);
+
+ ContentResolver contentResolver = context.getContentResolver();
+ ContentValues values = new ContentValues();
+ values.put(MediaStore.MediaColumns.TITLE, song.getTitle());
+ values.put(MediaStore.Audio.AudioColumns.ARTIST, song.getArtist());
+ values.put(MediaStore.Audio.AudioColumns.ALBUM, song.getAlbum());
+ values.put(MediaStore.Audio.AudioColumns.TRACK, song.getTrack());
+ values.put(MediaStore.Audio.AudioColumns.YEAR, song.getYear());
+ values.put(MediaStore.MediaColumns.DATA, songFile.getAbsolutePath());
+ values.put(MediaStore.MediaColumns.MIME_TYPE, song.getContentType());
+ values.put(MediaStore.Audio.AudioColumns.IS_MUSIC, 1);
+
+ Uri uri = contentResolver.insert(MediaStore.Audio.Media.EXTERNAL_CONTENT_URI, values);
+
+ // Look up album, and add cover art if found.
+ Cursor cursor = contentResolver.query(uri, new String[]{MediaStore.Audio.AudioColumns.ALBUM_ID}, null, null, null);
+ if (cursor.moveToFirst()) {
+ int albumId = cursor.getInt(0);
+ insertAlbumArt(albumId, downloadFile);
+ }
+ cursor.close();
+ }
+
+ public void deleteFromMediaStore(DownloadFile downloadFile) {
+ ContentResolver contentResolver = context.getContentResolver();
+ MusicDirectory.Entry song = downloadFile.getSong();
+ File file = downloadFile.getCompleteFile();
+
+ int n = contentResolver.delete(MediaStore.Audio.Media.EXTERNAL_CONTENT_URI,
+ MediaStore.Audio.AudioColumns.TITLE_KEY + "=? AND " +
+ MediaStore.MediaColumns.DATA + "=?",
+ new String[]{MediaStore.Audio.keyFor(song.getTitle()), file.getAbsolutePath()});
+ if (n > 0) {
+ Log.i(TAG, "Deleting media store row for " + song);
+ }
+ }
+
+ private void insertAlbumArt(int albumId, DownloadFile downloadFile) {
+ ContentResolver contentResolver = context.getContentResolver();
+
+ Cursor cursor = contentResolver.query(Uri.withAppendedPath(ALBUM_ART_URI, String.valueOf(albumId)), null, null, null, null);
+ if (!cursor.moveToFirst()) {
+
+ // No album art found, add it.
+ File albumArtFile = FileUtil.getAlbumArtFile(context, downloadFile.getSong());
+ if (albumArtFile.exists()) {
+ ContentValues values = new ContentValues();
+ values.put(MediaStore.Audio.AlbumColumns.ALBUM_ID, albumId);
+ values.put(MediaStore.MediaColumns.DATA, albumArtFile.getPath());
+ contentResolver.insert(ALBUM_ART_URI, values);
+ Log.i(TAG, "Added album art: " + albumArtFile);
+ }
+ }
+ cursor.close();
+ }
+
+} \ No newline at end of file
diff --git a/subsonic-android/src/net/sourceforge/subsonic/androidapp/service/MusicService.java b/subsonic-android/src/net/sourceforge/subsonic/androidapp/service/MusicService.java
new file mode 100644
index 00000000..2acb4c65
--- /dev/null
+++ b/subsonic-android/src/net/sourceforge/subsonic/androidapp/service/MusicService.java
@@ -0,0 +1,91 @@
+/*
+ This file is part of Subsonic.
+
+ Subsonic is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ Subsonic is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with Subsonic. If not, see <http://www.gnu.org/licenses/>.
+
+ Copyright 2009 (C) Sindre Mehus
+ */
+package net.sourceforge.subsonic.androidapp.service;
+
+import java.util.List;
+
+import org.apache.http.HttpResponse;
+
+import android.content.Context;
+import android.graphics.Bitmap;
+import net.sourceforge.subsonic.androidapp.domain.Indexes;
+import net.sourceforge.subsonic.androidapp.domain.JukeboxStatus;
+import net.sourceforge.subsonic.androidapp.domain.Lyrics;
+import net.sourceforge.subsonic.androidapp.domain.MusicDirectory;
+import net.sourceforge.subsonic.androidapp.domain.MusicFolder;
+import net.sourceforge.subsonic.androidapp.domain.Playlist;
+import net.sourceforge.subsonic.androidapp.domain.SearchCritera;
+import net.sourceforge.subsonic.androidapp.domain.SearchResult;
+import net.sourceforge.subsonic.androidapp.domain.Version;
+import net.sourceforge.subsonic.androidapp.util.CancellableTask;
+import net.sourceforge.subsonic.androidapp.util.ProgressListener;
+
+/**
+ * @author Sindre Mehus
+ */
+public interface MusicService {
+
+ void ping(Context context, ProgressListener progressListener) throws Exception;
+
+ boolean isLicenseValid(Context context, ProgressListener progressListener) throws Exception;
+
+ List<MusicFolder> getMusicFolders(boolean refresh, Context context, ProgressListener progressListener) throws Exception;
+
+ Indexes getIndexes(String musicFolderId, boolean refresh, Context context, ProgressListener progressListener) throws Exception;
+
+ MusicDirectory getMusicDirectory(String id, boolean refresh, Context context, ProgressListener progressListener) throws Exception;
+
+ SearchResult search(SearchCritera criteria, Context context, ProgressListener progressListener) throws Exception;
+
+ MusicDirectory getPlaylist(String id, Context context, ProgressListener progressListener) throws Exception;
+
+ List<Playlist> getPlaylists(boolean refresh, Context context, ProgressListener progressListener) throws Exception;
+
+ void createPlaylist(String id, String name, List<MusicDirectory.Entry> entries, Context context, ProgressListener progressListener) throws Exception;
+
+ Lyrics getLyrics(String artist, String title, Context context, ProgressListener progressListener) throws Exception;
+
+ void scrobble(String id, boolean submission, Context context, ProgressListener progressListener) throws Exception;
+
+ MusicDirectory getAlbumList(String type, int size, int offset, Context context, ProgressListener progressListener) throws Exception;
+
+ MusicDirectory getRandomSongs(int size, Context context, ProgressListener progressListener) throws Exception;
+
+ Bitmap getCoverArt(Context context, MusicDirectory.Entry entry, int size, boolean saveToFile, ProgressListener progressListener) throws Exception;
+
+ HttpResponse getDownloadInputStream(Context context, MusicDirectory.Entry song, long offset, int maxBitrate, CancellableTask task) throws Exception;
+
+ Version getLocalVersion(Context context) throws Exception;
+
+ Version getLatestVersion(Context context, ProgressListener progressListener) throws Exception;
+
+ String getVideoUrl(Context context, String id);
+
+ JukeboxStatus updateJukeboxPlaylist(List<String> ids, Context context, ProgressListener progressListener) throws Exception;
+
+ JukeboxStatus skipJukebox(int index, int offsetSeconds, Context context, ProgressListener progressListener) throws Exception;
+
+ JukeboxStatus stopJukebox(Context context, ProgressListener progressListener) throws Exception;
+
+ JukeboxStatus startJukebox(Context context, ProgressListener progressListener) throws Exception;
+
+ JukeboxStatus getJukeboxStatus(Context context, ProgressListener progressListener) throws Exception;
+
+ JukeboxStatus setJukeboxGain(float gain, Context context, ProgressListener progressListener) throws Exception;
+} \ No newline at end of file
diff --git a/subsonic-android/src/net/sourceforge/subsonic/androidapp/service/MusicServiceFactory.java b/subsonic-android/src/net/sourceforge/subsonic/androidapp/service/MusicServiceFactory.java
new file mode 100644
index 00000000..552d1d32
--- /dev/null
+++ b/subsonic-android/src/net/sourceforge/subsonic/androidapp/service/MusicServiceFactory.java
@@ -0,0 +1,36 @@
+/*
+ This file is part of Subsonic.
+
+ Subsonic is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ Subsonic is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with Subsonic. If not, see <http://www.gnu.org/licenses/>.
+
+ Copyright 2009 (C) Sindre Mehus
+ */
+package net.sourceforge.subsonic.androidapp.service;
+
+import android.content.Context;
+import net.sourceforge.subsonic.androidapp.util.Util;
+
+/**
+ * @author Sindre Mehus
+ * @version $Id$
+ */
+public class MusicServiceFactory {
+
+ private static final MusicService REST_MUSIC_SERVICE = new CachedMusicService(new RESTMusicService());
+ private static final MusicService OFFLINE_MUSIC_SERVICE = new OfflineMusicService();
+
+ public static MusicService getMusicService(Context context) {
+ return Util.isOffline(context) ? OFFLINE_MUSIC_SERVICE : REST_MUSIC_SERVICE;
+ }
+}
diff --git a/subsonic-android/src/net/sourceforge/subsonic/androidapp/service/OfflineException.java b/subsonic-android/src/net/sourceforge/subsonic/androidapp/service/OfflineException.java
new file mode 100644
index 00000000..49c000bf
--- /dev/null
+++ b/subsonic-android/src/net/sourceforge/subsonic/androidapp/service/OfflineException.java
@@ -0,0 +1,32 @@
+/*
+ This file is part of Subsonic.
+
+ Subsonic is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ Subsonic is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with Subsonic. If not, see <http://www.gnu.org/licenses/>.
+
+ Copyright 2009 (C) Sindre Mehus
+ */
+package net.sourceforge.subsonic.androidapp.service;
+
+/**
+ * Thrown by service methods that are not available in offline mode.
+ *
+ * @author Sindre Mehus
+ * @version $Id$
+ */
+public class OfflineException extends Exception {
+
+ public OfflineException(String message) {
+ super(message);
+ }
+}
diff --git a/subsonic-android/src/net/sourceforge/subsonic/androidapp/service/OfflineMusicService.java b/subsonic-android/src/net/sourceforge/subsonic/androidapp/service/OfflineMusicService.java
new file mode 100644
index 00000000..6a8ad6d0
--- /dev/null
+++ b/subsonic-android/src/net/sourceforge/subsonic/androidapp/service/OfflineMusicService.java
@@ -0,0 +1,244 @@
+/*
+ This file is part of Subsonic.
+
+ Subsonic is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ Subsonic is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with Subsonic. If not, see <http://www.gnu.org/licenses/>.
+
+ Copyright 2009 (C) Sindre Mehus
+ */
+package net.sourceforge.subsonic.androidapp.service;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.InputStream;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Random;
+import java.util.Set;
+
+import android.content.Context;
+import android.graphics.Bitmap;
+import android.graphics.BitmapFactory;
+import net.sourceforge.subsonic.androidapp.domain.Artist;
+import net.sourceforge.subsonic.androidapp.domain.Indexes;
+import net.sourceforge.subsonic.androidapp.domain.JukeboxStatus;
+import net.sourceforge.subsonic.androidapp.domain.Lyrics;
+import net.sourceforge.subsonic.androidapp.domain.MusicDirectory;
+import net.sourceforge.subsonic.androidapp.domain.MusicFolder;
+import net.sourceforge.subsonic.androidapp.domain.Playlist;
+import net.sourceforge.subsonic.androidapp.domain.SearchCritera;
+import net.sourceforge.subsonic.androidapp.domain.SearchResult;
+import net.sourceforge.subsonic.androidapp.util.Constants;
+import net.sourceforge.subsonic.androidapp.util.FileUtil;
+import net.sourceforge.subsonic.androidapp.util.ProgressListener;
+import net.sourceforge.subsonic.androidapp.util.Util;
+
+/**
+ * @author Sindre Mehus
+ */
+public class OfflineMusicService extends RESTMusicService {
+
+ @Override
+ public boolean isLicenseValid(Context context, ProgressListener progressListener) throws Exception {
+ return true;
+ }
+
+ @Override
+ public Indexes getIndexes(String musicFolderId, boolean refresh, Context context, ProgressListener progressListener) throws Exception {
+ List<Artist> artists = new ArrayList<Artist>();
+ File root = FileUtil.getMusicDirectory(context);
+ for (File file : FileUtil.listFiles(root)) {
+ if (file.isDirectory()) {
+ Artist artist = new Artist();
+ artist.setId(file.getPath());
+ artist.setIndex(file.getName().substring(0, 1));
+ artist.setName(file.getName());
+ artists.add(artist);
+ }
+ }
+ return new Indexes(0L, Collections.<Artist>emptyList(), artists);
+ }
+
+ @Override
+ public MusicDirectory getMusicDirectory(String id, boolean refresh, Context context, ProgressListener progressListener) throws Exception {
+ File dir = new File(id);
+ MusicDirectory result = new MusicDirectory();
+ result.setName(dir.getName());
+
+ Set<String> names = new HashSet<String>();
+
+ for (File file : FileUtil.listMusicFiles(dir)) {
+ String name = getName(file);
+ if (name != null & !names.contains(name)) {
+ names.add(name);
+ result.addChild(createEntry(context, file, name));
+ }
+ }
+ return result;
+ }
+
+ private String getName(File file) {
+ String name = file.getName();
+ if (file.isDirectory()) {
+ return name;
+ }
+
+ if (name.endsWith(".partial") || name.contains(".partial.") || name.equals(Constants.ALBUM_ART_FILE)) {
+ return null;
+ }
+
+ name = name.replace(".complete", "");
+ return FileUtil.getBaseName(name);
+ }
+
+ private MusicDirectory.Entry createEntry(Context context, File file, String name) {
+ MusicDirectory.Entry entry = new MusicDirectory.Entry();
+ entry.setDirectory(file.isDirectory());
+ entry.setId(file.getPath());
+ entry.setParent(file.getParent());
+ entry.setSize(file.length());
+ String root = FileUtil.getMusicDirectory(context).getPath();
+ entry.setPath(file.getPath().replaceFirst("^" + root + "/" , ""));
+ if (file.isFile()) {
+ entry.setArtist(file.getParentFile().getParentFile().getName());
+ entry.setAlbum(file.getParentFile().getName());
+ }
+ entry.setTitle(name);
+ entry.setSuffix(FileUtil.getExtension(file.getName().replace(".complete", "")));
+
+ File albumArt = FileUtil.getAlbumArtFile(context, entry);
+ if (albumArt.exists()) {
+ entry.setCoverArt(albumArt.getPath());
+ }
+ return entry;
+ }
+
+ @Override
+ public Bitmap getCoverArt(Context context, MusicDirectory.Entry entry, int size, boolean saveToFile, ProgressListener progressListener) throws Exception {
+ InputStream in = new FileInputStream(entry.getCoverArt());
+ try {
+ byte[] bytes = Util.toByteArray(in);
+ Bitmap bitmap = BitmapFactory.decodeByteArray(bytes, 0, bytes.length);
+ return Bitmap.createScaledBitmap(bitmap, size, size, true);
+ } finally {
+ Util.close(in);
+ }
+ }
+
+ @Override
+ public List<MusicFolder> getMusicFolders(boolean refresh, Context context, ProgressListener progressListener) throws Exception {
+ throw new OfflineException("Music folders not available in offline mode");
+ }
+
+ @Override
+ public SearchResult search(SearchCritera criteria, Context context, ProgressListener progressListener) throws Exception {
+ throw new OfflineException("Search not available in offline mode");
+ }
+
+ @Override
+ public List<Playlist> getPlaylists(boolean refresh, Context context, ProgressListener progressListener) throws Exception {
+ throw new OfflineException("Playlists not available in offline mode");
+ }
+
+ @Override
+ public MusicDirectory getPlaylist(String id, Context context, ProgressListener progressListener) throws Exception {
+ throw new OfflineException("Playlists not available in offline mode");
+ }
+
+ @Override
+ public void createPlaylist(String id, String name, List<MusicDirectory.Entry> entries, Context context, ProgressListener progressListener) throws Exception {
+ throw new OfflineException("Playlists not available in offline mode");
+ }
+
+ @Override
+ public Lyrics getLyrics(String artist, String title, Context context, ProgressListener progressListener) throws Exception {
+ throw new OfflineException("Lyrics not available in offline mode");
+ }
+
+ @Override
+ public void scrobble(String id, boolean submission, Context context, ProgressListener progressListener) throws Exception {
+ throw new OfflineException("Scrobbling not available in offline mode");
+ }
+
+ @Override
+ public MusicDirectory getAlbumList(String type, int size, int offset, Context context, ProgressListener progressListener) throws Exception {
+ throw new OfflineException("Album lists not available in offline mode");
+ }
+
+ @Override
+ public String getVideoUrl(Context context, String id) {
+ return null;
+ }
+
+ @Override
+ public JukeboxStatus updateJukeboxPlaylist(List<String> ids, Context context, ProgressListener progressListener) throws Exception {
+ throw new OfflineException("Jukebox not available in offline mode");
+ }
+
+ @Override
+ public JukeboxStatus skipJukebox(int index, int offsetSeconds, Context context, ProgressListener progressListener) throws Exception {
+ throw new OfflineException("Jukebox not available in offline mode");
+ }
+
+ @Override
+ public JukeboxStatus stopJukebox(Context context, ProgressListener progressListener) throws Exception {
+ throw new OfflineException("Jukebox not available in offline mode");
+ }
+
+ @Override
+ public JukeboxStatus startJukebox(Context context, ProgressListener progressListener) throws Exception {
+ throw new OfflineException("Jukebox not available in offline mode");
+ }
+
+ @Override
+ public JukeboxStatus getJukeboxStatus(Context context, ProgressListener progressListener) throws Exception {
+ throw new OfflineException("Jukebox not available in offline mode");
+ }
+
+ @Override
+ public JukeboxStatus setJukeboxGain(float gain, Context context, ProgressListener progressListener) throws Exception {
+ throw new OfflineException("Jukebox not available in offline mode");
+ }
+
+ @Override
+ public MusicDirectory getRandomSongs(int size, Context context, ProgressListener progressListener) throws Exception {
+ File root = FileUtil.getMusicDirectory(context);
+ List<File> children = new LinkedList<File>();
+ listFilesRecursively(root, children);
+ MusicDirectory result = new MusicDirectory();
+
+ if (children.isEmpty()) {
+ return result;
+ }
+ Random random = new Random();
+ for (int i = 0; i < size; i++) {
+ File file = children.get(random.nextInt(children.size()));
+ result.addChild(createEntry(context, file, getName(file)));
+ }
+
+ return result;
+ }
+
+ private void listFilesRecursively(File parent, List<File> children) {
+ for (File file : FileUtil.listMusicFiles(parent)) {
+ if (file.isFile()) {
+ children.add(file);
+ } else {
+ listFilesRecursively(file, children);
+ }
+ }
+ }
+}
diff --git a/subsonic-android/src/net/sourceforge/subsonic/androidapp/service/RESTMusicService.java b/subsonic-android/src/net/sourceforge/subsonic/androidapp/service/RESTMusicService.java
new file mode 100644
index 00000000..1d99f2d9
--- /dev/null
+++ b/subsonic-android/src/net/sourceforge/subsonic/androidapp/service/RESTMusicService.java
@@ -0,0 +1,768 @@
+/*
+ This file is part of Subsonic.
+
+ Subsonic is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ Subsonic is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with Subsonic. If not, see <http://www.gnu.org/licenses/>.
+
+ Copyright 2009 (C) Sindre Mehus
+ */
+package net.sourceforge.subsonic.androidapp.service;
+
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.io.OutputStream;
+import java.io.Reader;
+import java.net.URLEncoder;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.concurrent.atomic.AtomicReference;
+
+import org.apache.http.Header;
+import org.apache.http.HttpEntity;
+import org.apache.http.HttpHost;
+import org.apache.http.HttpResponse;
+import org.apache.http.NameValuePair;
+import org.apache.http.auth.AuthScope;
+import org.apache.http.auth.UsernamePasswordCredentials;
+import org.apache.http.client.entity.UrlEncodedFormEntity;
+import org.apache.http.client.methods.HttpPost;
+import org.apache.http.client.methods.HttpUriRequest;
+import org.apache.http.conn.params.ConnManagerParams;
+import org.apache.http.conn.params.ConnPerRouteBean;
+import org.apache.http.conn.scheme.PlainSocketFactory;
+import org.apache.http.conn.scheme.Scheme;
+import org.apache.http.conn.scheme.SchemeRegistry;
+import org.apache.http.conn.scheme.SocketFactory;
+import org.apache.http.impl.client.DefaultHttpClient;
+import org.apache.http.impl.conn.tsccm.ThreadSafeClientConnManager;
+import org.apache.http.message.BasicHeader;
+import org.apache.http.message.BasicNameValuePair;
+import org.apache.http.params.BasicHttpParams;
+import org.apache.http.params.HttpConnectionParams;
+import org.apache.http.params.HttpParams;
+import org.apache.http.protocol.BasicHttpContext;
+import org.apache.http.protocol.ExecutionContext;
+import org.apache.http.protocol.HttpContext;
+
+import android.content.Context;
+import android.content.SharedPreferences;
+import android.content.pm.PackageInfo;
+import android.graphics.Bitmap;
+import android.graphics.BitmapFactory;
+import android.net.ConnectivityManager;
+import android.net.NetworkInfo;
+import android.util.Log;
+import net.sourceforge.subsonic.androidapp.R;
+import net.sourceforge.subsonic.androidapp.domain.Indexes;
+import net.sourceforge.subsonic.androidapp.domain.JukeboxStatus;
+import net.sourceforge.subsonic.androidapp.domain.Lyrics;
+import net.sourceforge.subsonic.androidapp.domain.MusicDirectory;
+import net.sourceforge.subsonic.androidapp.domain.MusicFolder;
+import net.sourceforge.subsonic.androidapp.domain.Playlist;
+import net.sourceforge.subsonic.androidapp.domain.SearchCritera;
+import net.sourceforge.subsonic.androidapp.domain.SearchResult;
+import net.sourceforge.subsonic.androidapp.domain.ServerInfo;
+import net.sourceforge.subsonic.androidapp.domain.Version;
+import net.sourceforge.subsonic.androidapp.service.parser.AlbumListParser;
+import net.sourceforge.subsonic.androidapp.service.parser.ErrorParser;
+import net.sourceforge.subsonic.androidapp.service.parser.IndexesParser;
+import net.sourceforge.subsonic.androidapp.service.parser.JukeboxStatusParser;
+import net.sourceforge.subsonic.androidapp.service.parser.LicenseParser;
+import net.sourceforge.subsonic.androidapp.service.parser.LyricsParser;
+import net.sourceforge.subsonic.androidapp.service.parser.MusicDirectoryParser;
+import net.sourceforge.subsonic.androidapp.service.parser.MusicFoldersParser;
+import net.sourceforge.subsonic.androidapp.service.parser.PlaylistParser;
+import net.sourceforge.subsonic.androidapp.service.parser.PlaylistsParser;
+import net.sourceforge.subsonic.androidapp.service.parser.RandomSongsParser;
+import net.sourceforge.subsonic.androidapp.service.parser.SearchResult2Parser;
+import net.sourceforge.subsonic.androidapp.service.parser.SearchResultParser;
+import net.sourceforge.subsonic.androidapp.service.parser.VersionParser;
+import net.sourceforge.subsonic.androidapp.service.ssl.SSLSocketFactory;
+import net.sourceforge.subsonic.androidapp.service.ssl.TrustSelfSignedStrategy;
+import net.sourceforge.subsonic.androidapp.util.CancellableTask;
+import net.sourceforge.subsonic.androidapp.util.Constants;
+import net.sourceforge.subsonic.androidapp.util.FileUtil;
+import net.sourceforge.subsonic.androidapp.util.ProgressListener;
+import net.sourceforge.subsonic.androidapp.util.Util;
+
+/**
+ * @author Sindre Mehus
+ */
+public class RESTMusicService implements MusicService {
+
+ private static final String TAG = RESTMusicService.class.getSimpleName();
+
+ private static final int SOCKET_CONNECT_TIMEOUT = 10 * 1000;
+ private static final int SOCKET_READ_TIMEOUT_DEFAULT = 10 * 1000;
+ private static final int SOCKET_READ_TIMEOUT_DOWNLOAD = 30 * 1000;
+ private static final int SOCKET_READ_TIMEOUT_GET_RANDOM_SONGS = 60 * 1000;
+ private static final int SOCKET_READ_TIMEOUT_GET_PLAYLIST = 60 * 1000;
+
+ // Allow 20 seconds extra timeout per MB offset.
+ private static final double TIMEOUT_MILLIS_PER_OFFSET_BYTE = 20000.0 / 1000000.0;
+
+ /**
+ * URL from which to fetch latest versions.
+ */
+ private static final String VERSION_URL = "http://subsonic.org/backend/version.view";
+
+ private static final int HTTP_REQUEST_MAX_ATTEMPTS = 5;
+ private static final long REDIRECTION_CHECK_INTERVAL_MILLIS = 60L * 60L * 1000L;
+
+ private final DefaultHttpClient httpClient;
+ private long redirectionLastChecked;
+ private int redirectionNetworkType = -1;
+ private String redirectFrom;
+ private String redirectTo;
+ private final ThreadSafeClientConnManager connManager;
+
+ public RESTMusicService() {
+
+ // Create and initialize default HTTP parameters
+ HttpParams params = new BasicHttpParams();
+ ConnManagerParams.setMaxTotalConnections(params, 20);
+ ConnManagerParams.setMaxConnectionsPerRoute(params, new ConnPerRouteBean(20));
+ HttpConnectionParams.setConnectionTimeout(params, SOCKET_CONNECT_TIMEOUT);
+ HttpConnectionParams.setSoTimeout(params, SOCKET_READ_TIMEOUT_DEFAULT);
+
+ // Turn off stale checking. Our connections break all the time anyway,
+ // and it's not worth it to pay the penalty of checking every time.
+ HttpConnectionParams.setStaleCheckingEnabled(params, false);
+
+ // Create and initialize scheme registry
+ SchemeRegistry schemeRegistry = new SchemeRegistry();
+ schemeRegistry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80));
+ schemeRegistry.register(new Scheme("https", createSSLSocketFactory(), 443));
+
+ // Create an HttpClient with the ThreadSafeClientConnManager.
+ // This connection manager must be used if more than one thread will
+ // be using the HttpClient.
+ connManager = new ThreadSafeClientConnManager(params, schemeRegistry);
+ httpClient = new DefaultHttpClient(connManager, params);
+ }
+
+ private SocketFactory createSSLSocketFactory() {
+ try {
+ return new SSLSocketFactory(new TrustSelfSignedStrategy(), SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);
+ } catch (Throwable x) {
+ Log.e(TAG, "Failed to create custom SSL socket factory, using default.", x);
+ return org.apache.http.conn.ssl.SSLSocketFactory.getSocketFactory();
+ }
+ }
+
+ @Override
+ public void ping(Context context, ProgressListener progressListener) throws Exception {
+ Reader reader = getReader(context, progressListener, "ping", null);
+ try {
+ new ErrorParser(context).parse(reader);
+ } finally {
+ Util.close(reader);
+ }
+ }
+
+ @Override
+ public boolean isLicenseValid(Context context, ProgressListener progressListener) throws Exception {
+ Reader reader = getReader(context, progressListener, "getLicense", null);
+ try {
+ ServerInfo serverInfo = new LicenseParser(context).parse(reader);
+ return serverInfo.isLicenseValid();
+ } finally {
+ Util.close(reader);
+ }
+ }
+
+ public List<MusicFolder> getMusicFolders(boolean refresh, Context context, ProgressListener progressListener) throws Exception {
+ List<MusicFolder> cachedMusicFolders = readCachedMusicFolders(context);
+ if (cachedMusicFolders != null && !refresh) {
+ return cachedMusicFolders;
+ }
+
+ Reader reader = getReader(context, progressListener, "getMusicFolders", null);
+ try {
+ List<MusicFolder> musicFolders = new MusicFoldersParser(context).parse(reader, progressListener);
+ writeCachedMusicFolders(context, musicFolders);
+ return musicFolders;
+ } finally {
+ Util.close(reader);
+ }
+ }
+
+ @Override
+ public Indexes getIndexes(String musicFolderId, boolean refresh, Context context, ProgressListener progressListener) throws Exception {
+ Indexes cachedIndexes = readCachedIndexes(context, musicFolderId);
+ if (cachedIndexes != null && !refresh) {
+ return cachedIndexes;
+ }
+
+ long lastModified = cachedIndexes == null ? 0L : cachedIndexes.getLastModified();
+
+ List<String> parameterNames = new ArrayList<String>();
+ List<Object> parameterValues = new ArrayList<Object>();
+
+ parameterNames.add("ifModifiedSince");
+ parameterValues.add(lastModified);
+
+ if (musicFolderId != null) {
+ parameterNames.add("musicFolderId");
+ parameterValues.add(musicFolderId);
+ }
+
+ Reader reader = getReader(context, progressListener, "getIndexes", null, parameterNames, parameterValues);
+ try {
+ Indexes indexes = new IndexesParser(context).parse(reader, progressListener);
+ if (indexes != null) {
+ writeCachedIndexes(context, indexes, musicFolderId);
+ return indexes;
+ }
+ return cachedIndexes;
+ } finally {
+ Util.close(reader);
+ }
+ }
+
+ private Indexes readCachedIndexes(Context context, String musicFolderId) {
+ String filename = getCachedIndexesFilename(context, musicFolderId);
+ return FileUtil.deserialize(context, filename);
+ }
+
+ private void writeCachedIndexes(Context context, Indexes indexes, String musicFolderId) {
+ String filename = getCachedIndexesFilename(context, musicFolderId);
+ FileUtil.serialize(context, indexes, filename);
+ }
+
+ private String getCachedIndexesFilename(Context context, String musicFolderId) {
+ String s = Util.getRestUrl(context, null) + musicFolderId;
+ return "indexes-" + Math.abs(s.hashCode()) + ".ser";
+ }
+
+ private ArrayList<MusicFolder> readCachedMusicFolders(Context context) {
+ String filename = getCachedMusicFoldersFilename(context);
+ return FileUtil.deserialize(context, filename);
+ }
+
+ private void writeCachedMusicFolders(Context context, List<MusicFolder> musicFolders) {
+ String filename = getCachedMusicFoldersFilename(context);
+ FileUtil.serialize(context, new ArrayList<MusicFolder>(musicFolders), filename);
+ }
+
+ private String getCachedMusicFoldersFilename(Context context) {
+ String s = Util.getRestUrl(context, null);
+ return "musicFolders-" + Math.abs(s.hashCode()) + ".ser";
+ }
+
+ @Override
+ public MusicDirectory getMusicDirectory(String id, boolean refresh, Context context, ProgressListener progressListener) throws Exception {
+ Reader reader = getReader(context, progressListener, "getMusicDirectory", null, "id", id);
+ try {
+ return new MusicDirectoryParser(context).parse(reader, progressListener);
+ } finally {
+ Util.close(reader);
+ }
+ }
+
+ @Override
+ public SearchResult search(SearchCritera critera, Context context, ProgressListener progressListener) throws Exception {
+ try {
+ return searchNew(critera, context, progressListener);
+ } catch (ServerTooOldException x) {
+ // Ensure backward compatibility with REST 1.3.
+ return searchOld(critera, context, progressListener);
+ }
+ }
+
+ /**
+ * Search using the "search" REST method.
+ */
+ private SearchResult searchOld(SearchCritera critera, Context context, ProgressListener progressListener) throws Exception {
+ List<String> parameterNames = Arrays.asList("any", "songCount");
+ List<Object> parameterValues = Arrays.<Object>asList(critera.getQuery(), critera.getSongCount());
+ Reader reader = getReader(context, progressListener, "search", null, parameterNames, parameterValues);
+ try {
+ return new SearchResultParser(context).parse(reader, progressListener);
+ } finally {
+ Util.close(reader);
+ }
+ }
+
+ /**
+ * Search using the "search2" REST method, available in 1.4.0 and later.
+ */
+ private SearchResult searchNew(SearchCritera critera, Context context, ProgressListener progressListener) throws Exception {
+ checkServerVersion(context, "1.4", null);
+
+ List<String> parameterNames = Arrays.asList("query", "artistCount", "albumCount", "songCount");
+ List<Object> parameterValues = Arrays.<Object>asList(critera.getQuery(), critera.getArtistCount(),
+ critera.getAlbumCount(), critera.getSongCount());
+ Reader reader = getReader(context, progressListener, "search2", null, parameterNames, parameterValues);
+ try {
+ return new SearchResult2Parser(context).parse(reader, progressListener);
+ } finally {
+ Util.close(reader);
+ }
+ }
+
+ @Override
+ public MusicDirectory getPlaylist(String id, Context context, ProgressListener progressListener) throws Exception {
+ HttpParams params = new BasicHttpParams();
+ HttpConnectionParams.setSoTimeout(params, SOCKET_READ_TIMEOUT_GET_PLAYLIST);
+
+ Reader reader = getReader(context, progressListener, "getPlaylist", params, "id", id);
+ try {
+ return new PlaylistParser(context).parse(reader, progressListener);
+ } finally {
+ Util.close(reader);
+ }
+ }
+
+ @Override
+ public List<Playlist> getPlaylists(boolean refresh, Context context, ProgressListener progressListener) throws Exception {
+ Reader reader = getReader(context, progressListener, "getPlaylists", null);
+ try {
+ return new PlaylistsParser(context).parse(reader, progressListener);
+ } finally {
+ Util.close(reader);
+ }
+ }
+
+ @Override
+ public void createPlaylist(String id, String name, List<MusicDirectory.Entry> entries, Context context, ProgressListener progressListener) throws Exception {
+ List<String> parameterNames = new LinkedList<String>();
+ List<Object> parameterValues = new LinkedList<Object>();
+
+ if (id != null) {
+ parameterNames.add("playlistId");
+ parameterValues.add(id);
+ }
+ if (name != null) {
+ parameterNames.add("name");
+ parameterValues.add(name);
+ }
+ for (MusicDirectory.Entry entry : entries) {
+ parameterNames.add("songId");
+ parameterValues.add(entry.getId());
+ }
+
+ Reader reader = getReader(context, progressListener, "createPlaylist", null, parameterNames, parameterValues);
+ try {
+ new ErrorParser(context).parse(reader);
+ } finally {
+ Util.close(reader);
+ }
+ }
+
+ @Override
+ public Lyrics getLyrics(String artist, String title, Context context, ProgressListener progressListener) throws Exception {
+ Reader reader = getReader(context, progressListener, "getLyrics", null, Arrays.asList("artist", "title"), Arrays.<Object>asList(artist, title));
+ try {
+ return new LyricsParser(context).parse(reader, progressListener);
+ } finally {
+ Util.close(reader);
+ }
+ }
+
+ @Override
+ public void scrobble(String id, boolean submission, Context context, ProgressListener progressListener) throws Exception {
+ checkServerVersion(context, "1.5", "Scrobbling not supported.");
+ Reader reader = getReader(context, progressListener, "scrobble", null, Arrays.asList("id", "submission"), Arrays.<Object>asList(id, submission));
+ try {
+ new ErrorParser(context).parse(reader);
+ } finally {
+ Util.close(reader);
+ }
+ }
+
+ @Override
+ public MusicDirectory getAlbumList(String type, int size, int offset, Context context, ProgressListener progressListener) throws Exception {
+ Reader reader = getReader(context, progressListener, "getAlbumList",
+ null, Arrays.asList("type", "size", "offset"), Arrays.<Object>asList(type, size, offset));
+ try {
+ return new AlbumListParser(context).parse(reader, progressListener);
+ } finally {
+ Util.close(reader);
+ }
+ }
+
+ @Override
+ public MusicDirectory getRandomSongs(int size, Context context, ProgressListener progressListener) throws Exception {
+ HttpParams params = new BasicHttpParams();
+ HttpConnectionParams.setSoTimeout(params, SOCKET_READ_TIMEOUT_GET_RANDOM_SONGS);
+
+ Reader reader = getReader(context, progressListener, "getRandomSongs", params, "size", size);
+ try {
+ return new RandomSongsParser(context).parse(reader, progressListener);
+ } finally {
+ Util.close(reader);
+ }
+ }
+
+ @Override
+ public Version getLocalVersion(Context context) throws Exception {
+ PackageInfo packageInfo = context.getPackageManager().getPackageInfo("net.sourceforge.subsonic.androidapp", 0);
+ return new Version(packageInfo.versionName);
+ }
+
+ @Override
+ public Version getLatestVersion(Context context, ProgressListener progressListener) throws Exception {
+ Reader reader = getReaderForURL(context, VERSION_URL, null, null, null, progressListener);
+ try {
+ return new VersionParser().parse(reader);
+ } finally {
+ Util.close(reader);
+ }
+ }
+
+ private void checkServerVersion(Context context, String version, String text) throws ServerTooOldException {
+ Version serverVersion = Util.getServerRestVersion(context);
+ Version requiredVersion = new Version(version);
+ boolean ok = serverVersion == null || serverVersion.compareTo(requiredVersion) >= 0;
+
+ if (!ok) {
+ throw new ServerTooOldException(text, serverVersion, requiredVersion);
+ }
+ }
+
+ @Override
+ public Bitmap getCoverArt(Context context, MusicDirectory.Entry entry, int size, boolean saveToFile, ProgressListener progressListener) throws Exception {
+
+ // Synchronize on the entry so that we don't download concurrently for the same song.
+ synchronized (entry) {
+
+ // Use cached file, if existing.
+ Bitmap bitmap = FileUtil.getAlbumArtBitmap(context, entry, size);
+ if (bitmap != null) {
+ return bitmap;
+ }
+
+ String url = Util.getRestUrl(context, "getCoverArt");
+
+ InputStream in = null;
+ try {
+ List<String> parameterNames = Arrays.asList("id", "size");
+ List<Object> parameterValues = Arrays.<Object>asList(entry.getCoverArt(), size);
+ HttpEntity entity = getEntityForURL(context, url, null, parameterNames, parameterValues, progressListener);
+ in = entity.getContent();
+
+ // If content type is XML, an error occured. Get it.
+ String contentType = Util.getContentType(entity);
+ if (contentType != null && contentType.startsWith("text/xml")) {
+ new ErrorParser(context).parse(new InputStreamReader(in, Constants.UTF_8));
+ return null; // Never reached.
+ }
+
+ byte[] bytes = Util.toByteArray(in);
+
+ if (saveToFile) {
+ OutputStream out = null;
+ try {
+ out = new FileOutputStream(FileUtil.getAlbumArtFile(context, entry));
+ out.write(bytes);
+ } finally {
+ Util.close(out);
+ }
+ }
+
+ return BitmapFactory.decodeByteArray(bytes, 0, bytes.length);
+
+ } finally {
+ Util.close(in);
+ }
+ }
+ }
+
+ @Override
+ public HttpResponse getDownloadInputStream(Context context, MusicDirectory.Entry song, long offset, int maxBitrate, CancellableTask task) throws Exception {
+
+ String url = Util.getRestUrl(context, "stream");
+
+ // Set socket read timeout. Note: The timeout increases as the offset gets larger. This is
+ // to avoid the thrashing effect seen when offset is combined with transcoding/downsampling on the server.
+ // In that case, the server uses a long time before sending any data, causing the client to time out.
+ HttpParams params = new BasicHttpParams();
+ int timeout = (int) (SOCKET_READ_TIMEOUT_DOWNLOAD + offset * TIMEOUT_MILLIS_PER_OFFSET_BYTE);
+ HttpConnectionParams.setSoTimeout(params, timeout);
+
+ // Add "Range" header if offset is given.
+ List<Header> headers = new ArrayList<Header>();
+ if (offset > 0) {
+ headers.add(new BasicHeader("Range", "bytes=" + offset + "-"));
+ }
+ List<String> parameterNames = Arrays.asList("id", "maxBitRate");
+ List<Object> parameterValues = Arrays.<Object>asList(song.getId(), maxBitrate);
+ HttpResponse response = getResponseForURL(context, url, params, parameterNames, parameterValues, headers, null, task);
+
+ // If content type is XML, an error occurred. Get it.
+ String contentType = Util.getContentType(response.getEntity());
+ if (contentType != null && contentType.startsWith("text/xml")) {
+ InputStream in = response.getEntity().getContent();
+ try {
+ new ErrorParser(context).parse(new InputStreamReader(in, Constants.UTF_8));
+ } finally {
+ Util.close(in);
+ }
+ }
+
+ return response;
+ }
+
+ @Override
+ public String getVideoUrl(Context context, String id) {
+ StringBuilder builder = new StringBuilder(Util.getRestUrl(context, "videoPlayer"));
+ builder.append("&id=").append(id);
+ builder.append("&maxBitRate=500");
+ builder.append("&autoplay=true");
+
+ String url = rewriteUrlWithRedirect(context, builder.toString());
+ Log.i(TAG, "Using video URL: " + url);
+ return url;
+ }
+
+ @Override
+ public JukeboxStatus updateJukeboxPlaylist(List<String> ids, Context context, ProgressListener progressListener) throws Exception {
+ int n = ids.size();
+ List<String> parameterNames = new ArrayList<String>(n + 1);
+ parameterNames.add("action");
+ for (int i = 0; i < n; i++) {
+ parameterNames.add("id");
+ }
+ List<Object> parameterValues = new ArrayList<Object>();
+ parameterValues.add("set");
+ parameterValues.addAll(ids);
+
+ return executeJukeboxCommand(context, progressListener, parameterNames, parameterValues);
+ }
+
+ @Override
+ public JukeboxStatus skipJukebox(int index, int offsetSeconds, Context context, ProgressListener progressListener) throws Exception {
+ List<String> parameterNames = Arrays.asList("action", "index", "offset");
+ List<Object> parameterValues = Arrays.<Object>asList("skip", index, offsetSeconds);
+ return executeJukeboxCommand(context, progressListener, parameterNames, parameterValues);
+ }
+
+ @Override
+ public JukeboxStatus stopJukebox(Context context, ProgressListener progressListener) throws Exception {
+ return executeJukeboxCommand(context, progressListener, Arrays.asList("action"), Arrays.<Object>asList("stop"));
+ }
+
+ @Override
+ public JukeboxStatus startJukebox(Context context, ProgressListener progressListener) throws Exception {
+ return executeJukeboxCommand(context, progressListener, Arrays.asList("action"), Arrays.<Object>asList("start"));
+ }
+
+ @Override
+ public JukeboxStatus getJukeboxStatus(Context context, ProgressListener progressListener) throws Exception {
+ return executeJukeboxCommand(context, progressListener, Arrays.asList("action"), Arrays.<Object>asList("status"));
+ }
+
+ @Override
+ public JukeboxStatus setJukeboxGain(float gain, Context context, ProgressListener progressListener) throws Exception {
+ List<String> parameterNames = Arrays.asList("action", "gain");
+ List<Object> parameterValues = Arrays.<Object>asList("setGain", gain);
+ return executeJukeboxCommand(context, progressListener, parameterNames, parameterValues);
+
+ }
+
+ private JukeboxStatus executeJukeboxCommand(Context context, ProgressListener progressListener, List<String> parameterNames, List<Object> parameterValues) throws Exception {
+ checkServerVersion(context, "1.7", "Jukebox not supported.");
+ Reader reader = getReader(context, progressListener, "jukeboxControl", null, parameterNames, parameterValues);
+ try {
+ return new JukeboxStatusParser(context).parse(reader);
+ } finally {
+ Util.close(reader);
+ }
+ }
+
+ private Reader getReader(Context context, ProgressListener progressListener, String method, HttpParams requestParams) throws Exception {
+ return getReader(context, progressListener, method, requestParams, Collections.<String>emptyList(), Collections.emptyList());
+ }
+
+ private Reader getReader(Context context, ProgressListener progressListener, String method,
+ HttpParams requestParams, String parameterName, Object parameterValue) throws Exception {
+ return getReader(context, progressListener, method, requestParams, Arrays.asList(parameterName), Arrays.<Object>asList(parameterValue));
+ }
+
+ private Reader getReader(Context context, ProgressListener progressListener, String method,
+ HttpParams requestParams, List<String> parameterNames, List<Object> parameterValues) throws Exception {
+
+ if (progressListener != null) {
+ progressListener.updateProgress(R.string.service_connecting);
+ }
+
+ String url = Util.getRestUrl(context, method);
+ return getReaderForURL(context, url, requestParams, parameterNames, parameterValues, progressListener);
+ }
+
+ private Reader getReaderForURL(Context context, String url, HttpParams requestParams, List<String> parameterNames,
+ List<Object> parameterValues, ProgressListener progressListener) throws Exception {
+ HttpEntity entity = getEntityForURL(context, url, requestParams, parameterNames, parameterValues, progressListener);
+ if (entity == null) {
+ throw new RuntimeException("No entity received for URL " + url);
+ }
+
+ InputStream in = entity.getContent();
+ return new InputStreamReader(in, Constants.UTF_8);
+ }
+
+ private HttpEntity getEntityForURL(Context context, String url, HttpParams requestParams, List<String> parameterNames,
+ List<Object> parameterValues, ProgressListener progressListener) throws Exception {
+ return getResponseForURL(context, url, requestParams, parameterNames, parameterValues, null, progressListener, null).getEntity();
+ }
+
+ private HttpResponse getResponseForURL(Context context, String url, HttpParams requestParams,
+ List<String> parameterNames, List<Object> parameterValues,
+ List<Header> headers, ProgressListener progressListener, CancellableTask task) throws Exception {
+ Log.d(TAG, "Connections in pool: " + connManager.getConnectionsInPool());
+
+ // If not too many parameters, extract them to the URL rather than relying on the HTTP POST request being
+ // received intact. Remember, HTTP POST requests are converted to GET requests during HTTP redirects, thus
+ // loosing its entity.
+ if (parameterNames != null && parameterNames.size() < 10) {
+ StringBuilder builder = new StringBuilder(url);
+ for (int i = 0; i < parameterNames.size(); i++) {
+ builder.append("&").append(parameterNames.get(i)).append("=");
+ builder.append(URLEncoder.encode(String.valueOf(parameterValues.get(i)), "UTF-8"));
+ }
+ url = builder.toString();
+ parameterNames = null;
+ parameterValues = null;
+ }
+
+ String rewrittenUrl = rewriteUrlWithRedirect(context, url);
+ return executeWithRetry(context, rewrittenUrl, url, requestParams, parameterNames, parameterValues, headers, progressListener, task);
+ }
+
+ private HttpResponse executeWithRetry(Context context, String url, String originalUrl, HttpParams requestParams,
+ List<String> parameterNames, List<Object> parameterValues,
+ List<Header> headers, ProgressListener progressListener, CancellableTask task) throws IOException {
+ Log.i(TAG, "Using URL " + url);
+
+ final AtomicReference<Boolean> cancelled = new AtomicReference<Boolean>(false);
+ int attempts = 0;
+ while (true) {
+ attempts++;
+ HttpContext httpContext = new BasicHttpContext();
+ final HttpPost request = new HttpPost(url);
+
+ if (task != null) {
+ // Attempt to abort the HTTP request if the task is cancelled.
+ task.setOnCancelListener(new CancellableTask.OnCancelListener() {
+ @Override
+ public void onCancel() {
+ cancelled.set(true);
+ request.abort();
+ }
+ });
+ }
+
+ if (parameterNames != null) {
+ List<NameValuePair> params = new ArrayList<NameValuePair>();
+ for (int i = 0; i < parameterNames.size(); i++) {
+ params.add(new BasicNameValuePair(parameterNames.get(i), String.valueOf(parameterValues.get(i))));
+ }
+ request.setEntity(new UrlEncodedFormEntity(params, Constants.UTF_8));
+ }
+
+ if (requestParams != null) {
+ request.setParams(requestParams);
+ Log.d(TAG, "Socket read timeout: " + HttpConnectionParams.getSoTimeout(requestParams) + " ms.");
+ }
+
+ if (headers != null) {
+ for (Header header : headers) {
+ request.addHeader(header);
+ }
+ }
+
+ // Set credentials to get through apache proxies that require authentication.
+ SharedPreferences prefs = Util.getPreferences(context);
+ int instance = prefs.getInt(Constants.PREFERENCES_KEY_SERVER_INSTANCE, 1);
+ String username = prefs.getString(Constants.PREFERENCES_KEY_USERNAME + instance, null);
+ String password = prefs.getString(Constants.PREFERENCES_KEY_PASSWORD + instance, null);
+ httpClient.getCredentialsProvider().setCredentials(new AuthScope(AuthScope.ANY_HOST, AuthScope.ANY_PORT),
+ new UsernamePasswordCredentials(username, password));
+
+ try {
+ HttpResponse response = httpClient.execute(request, httpContext);
+ detectRedirect(originalUrl, context, httpContext);
+ return response;
+ } catch (IOException x) {
+ request.abort();
+ if (attempts >= HTTP_REQUEST_MAX_ATTEMPTS || cancelled.get()) {
+ throw x;
+ }
+ if (progressListener != null) {
+ String msg = context.getResources().getString(R.string.music_service_retry, attempts, HTTP_REQUEST_MAX_ATTEMPTS - 1);
+ progressListener.updateProgress(msg);
+ }
+ Log.w(TAG, "Got IOException (" + attempts + "), will retry", x);
+ increaseTimeouts(requestParams);
+ Util.sleepQuietly(2000L);
+ }
+ }
+ }
+
+ private void increaseTimeouts(HttpParams requestParams) {
+ if (requestParams != null) {
+ int connectTimeout = HttpConnectionParams.getConnectionTimeout(requestParams);
+ if (connectTimeout != 0) {
+ HttpConnectionParams.setConnectionTimeout(requestParams, (int) (connectTimeout * 1.3F));
+ }
+ int readTimeout = HttpConnectionParams.getSoTimeout(requestParams);
+ if (readTimeout != 0) {
+ HttpConnectionParams.setSoTimeout(requestParams, (int) (readTimeout * 1.5F));
+ }
+ }
+ }
+
+ private void detectRedirect(String originalUrl, Context context, HttpContext httpContext) {
+ HttpUriRequest request = (HttpUriRequest) httpContext.getAttribute(ExecutionContext.HTTP_REQUEST);
+ HttpHost host = (HttpHost) httpContext.getAttribute(ExecutionContext.HTTP_TARGET_HOST);
+ String redirectedUrl = host.toURI() + request.getURI();
+
+ redirectFrom = originalUrl.substring(0, originalUrl.indexOf("/rest/"));
+ redirectTo = redirectedUrl.substring(0, redirectedUrl.indexOf("/rest/"));
+
+ Log.i(TAG, redirectFrom + " redirects to " + redirectTo);
+ redirectionLastChecked = System.currentTimeMillis();
+ redirectionNetworkType = getCurrentNetworkType(context);
+ }
+
+ private String rewriteUrlWithRedirect(Context context, String url) {
+
+ // Only cache for a certain time.
+ if (System.currentTimeMillis() - redirectionLastChecked > REDIRECTION_CHECK_INTERVAL_MILLIS) {
+ return url;
+ }
+
+ // Ignore cache if network type has changed.
+ if (redirectionNetworkType != getCurrentNetworkType(context)) {
+ return url;
+ }
+
+ if (redirectFrom == null || redirectTo == null) {
+ return url;
+ }
+
+ return url.replace(redirectFrom, redirectTo);
+ }
+
+ private int getCurrentNetworkType(Context context) {
+ ConnectivityManager manager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
+ NetworkInfo networkInfo = manager.getActiveNetworkInfo();
+ return networkInfo == null ? -1 : networkInfo.getType();
+ }
+}
diff --git a/subsonic-android/src/net/sourceforge/subsonic/androidapp/service/Scrobbler.java b/subsonic-android/src/net/sourceforge/subsonic/androidapp/service/Scrobbler.java
new file mode 100644
index 00000000..ce121a4b
--- /dev/null
+++ b/subsonic-android/src/net/sourceforge/subsonic/androidapp/service/Scrobbler.java
@@ -0,0 +1,52 @@
+package net.sourceforge.subsonic.androidapp.service;
+
+import android.content.Context;
+import android.util.Log;
+import net.sourceforge.subsonic.androidapp.util.Util;
+
+/**
+ * Scrobbles played songs to Last.fm.
+ *
+ * @author Sindre Mehus
+ * @version $Id$
+ */
+public class Scrobbler {
+
+ private static final String TAG = Scrobbler.class.getSimpleName();
+
+ private String lastSubmission;
+ private String lastNowPlaying;
+
+ public void scrobble(final Context context, final DownloadFile song, final boolean submission) {
+ if (song == null || !Util.isScrobblingEnabled(context)) {
+ return;
+ }
+ final String id = song.getSong().getId();
+
+ // Avoid duplicate registrations.
+ if (submission && id.equals(lastSubmission)) {
+ return;
+ }
+ if (!submission && id.equals(lastNowPlaying)) {
+ return;
+ }
+ if (submission) {
+ lastSubmission = id;
+ } else {
+ lastNowPlaying = id;
+ }
+
+ new Thread("Scrobble " + song) {
+ @Override
+ public void run() {
+ MusicService service = MusicServiceFactory.getMusicService(context);
+ try {
+ service.scrobble(id, submission, context, null);
+ Log.i(TAG, "Scrobbled '" + (submission ? "submission" : "now playing") + "' for " + song);
+ } catch (Exception x) {
+ Log.i(TAG, "Failed to scrobble'" + (submission ? "submission" : "now playing") + "' for " + song, x);
+ }
+ }
+ }.start();
+ }
+}
diff --git a/subsonic-android/src/net/sourceforge/subsonic/androidapp/service/ServerTooOldException.java b/subsonic-android/src/net/sourceforge/subsonic/androidapp/service/ServerTooOldException.java
new file mode 100644
index 00000000..9d433385
--- /dev/null
+++ b/subsonic-android/src/net/sourceforge/subsonic/androidapp/service/ServerTooOldException.java
@@ -0,0 +1,51 @@
+/*
+ This file is part of Subsonic.
+
+ Subsonic is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ Subsonic is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with Subsonic. If not, see <http://www.gnu.org/licenses/>.
+
+ Copyright 2009 (C) Sindre Mehus
+ */
+package net.sourceforge.subsonic.androidapp.service;
+
+import net.sourceforge.subsonic.androidapp.domain.Version;
+
+/**
+ * Thrown if the REST API version implemented by the server is too old.
+ *
+ * @author Sindre Mehus
+ * @version $Id$
+ */
+public class ServerTooOldException extends Exception {
+
+ private final String text;
+ private final Version serverVersion;
+ private final Version requiredVersion;
+
+ public ServerTooOldException(String text, Version serverVersion, Version requiredVersion) {
+ this.text = text;
+ this.serverVersion = serverVersion;
+ this.requiredVersion = requiredVersion;
+ }
+
+ @Override
+ public String toString() {
+ StringBuilder builder = new StringBuilder();
+ if (text != null) {
+ builder.append(text).append(" ");
+ }
+ builder.append("Server API version too old. ");
+ builder.append("Requires ").append(requiredVersion).append(" but is ").append(serverVersion).append(".");
+ return builder.toString();
+ }
+}
diff --git a/subsonic-android/src/net/sourceforge/subsonic/androidapp/service/parser/AbstractParser.java b/subsonic-android/src/net/sourceforge/subsonic/androidapp/service/parser/AbstractParser.java
new file mode 100644
index 00000000..4ddff7e9
--- /dev/null
+++ b/subsonic-android/src/net/sourceforge/subsonic/androidapp/service/parser/AbstractParser.java
@@ -0,0 +1,138 @@
+/*
+ This file is part of Subsonic.
+
+ Subsonic is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ Subsonic is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with Subsonic. If not, see <http://www.gnu.org/licenses/>.
+
+ Copyright 2009 (C) Sindre Mehus
+ */
+package net.sourceforge.subsonic.androidapp.service.parser;
+
+import java.io.Reader;
+
+import org.xmlpull.v1.XmlPullParser;
+
+import android.content.Context;
+import android.util.Xml;
+import net.sourceforge.subsonic.androidapp.R;
+import net.sourceforge.subsonic.androidapp.domain.Version;
+import net.sourceforge.subsonic.androidapp.util.ProgressListener;
+import net.sourceforge.subsonic.androidapp.util.Util;
+
+/**
+ * @author Sindre Mehus
+ */
+public abstract class AbstractParser {
+
+ private final Context context;
+ private XmlPullParser parser;
+ private boolean rootElementFound;
+
+ public AbstractParser(Context context) {
+ this.context = context;
+ }
+
+ protected Context getContext() {
+ return context;
+ }
+
+ protected void handleError() throws Exception {
+ int code = getInteger("code");
+ String message;
+ switch (code) {
+ case 20:
+ message = context.getResources().getString(R.string.parser_upgrade_client);
+ break;
+ case 30:
+ message = context.getResources().getString(R.string.parser_upgrade_server);
+ break;
+ case 40:
+ message = context.getResources().getString(R.string.parser_not_authenticated);
+ break;
+ case 50:
+ message = context.getResources().getString(R.string.parser_not_authorized);
+ break;
+ default:
+ message = get("message");
+ break;
+ }
+ throw new SubsonicRESTException(code, message);
+ }
+
+ protected void updateProgress(ProgressListener progressListener, int messageId) {
+ if (progressListener != null) {
+ progressListener.updateProgress(messageId);
+ }
+ }
+
+ protected void updateProgress(ProgressListener progressListener, String message) {
+ if (progressListener != null) {
+ progressListener.updateProgress(message);
+ }
+ }
+
+ protected String getText() {
+ return parser.getText();
+ }
+
+ protected String get(String name) {
+ return parser.getAttributeValue(null, name);
+ }
+
+ protected boolean getBoolean(String name) {
+ return "true".equals(get(name));
+ }
+
+ protected Integer getInteger(String name) {
+ String s = get(name);
+ return s == null ? null : Integer.valueOf(s);
+ }
+
+ protected Long getLong(String name) {
+ String s = get(name);
+ return s == null ? null : Long.valueOf(s);
+ }
+
+ protected Float getFloat(String name) {
+ String s = get(name);
+ return s == null ? null : Float.valueOf(s);
+ }
+
+ protected void init(Reader reader) throws Exception {
+ parser = Xml.newPullParser();
+ parser.setInput(reader);
+ rootElementFound = false;
+ }
+
+ protected int nextParseEvent() throws Exception {
+ return parser.next();
+ }
+
+ protected String getElementName() {
+ String name = parser.getName();
+ if ("subsonic-response".equals(name)) {
+ rootElementFound = true;
+ String version = get("version");
+ if (version != null) {
+ Util.setServerRestVersion(context, new Version(version));
+ }
+ }
+ return name;
+ }
+
+ protected void validate() throws Exception {
+ if (!rootElementFound) {
+ throw new Exception(context.getResources().getString(R.string.background_task_parse_error));
+ }
+ }
+} \ No newline at end of file
diff --git a/subsonic-android/src/net/sourceforge/subsonic/androidapp/service/parser/AlbumListParser.java b/subsonic-android/src/net/sourceforge/subsonic/androidapp/service/parser/AlbumListParser.java
new file mode 100644
index 00000000..298ef114
--- /dev/null
+++ b/subsonic-android/src/net/sourceforge/subsonic/androidapp/service/parser/AlbumListParser.java
@@ -0,0 +1,62 @@
+/*
+ This file is part of Subsonic.
+
+ Subsonic is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ Subsonic is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with Subsonic. If not, see <http://www.gnu.org/licenses/>.
+
+ Copyright 2009 (C) Sindre Mehus
+ */
+package net.sourceforge.subsonic.androidapp.service.parser;
+
+import android.content.Context;
+import net.sourceforge.subsonic.androidapp.R;
+import net.sourceforge.subsonic.androidapp.domain.MusicDirectory;
+import net.sourceforge.subsonic.androidapp.util.ProgressListener;
+import org.xmlpull.v1.XmlPullParser;
+
+import java.io.Reader;
+
+/**
+ * @author Sindre Mehus
+ */
+public class AlbumListParser extends MusicDirectoryEntryParser {
+
+ public AlbumListParser(Context context) {
+ super(context);
+ }
+
+ public MusicDirectory parse(Reader reader, ProgressListener progressListener) throws Exception {
+
+ updateProgress(progressListener, R.string.parser_reading);
+ init(reader);
+
+ MusicDirectory dir = new MusicDirectory();
+ int eventType;
+ do {
+ eventType = nextParseEvent();
+ if (eventType == XmlPullParser.START_TAG) {
+ String name = getElementName();
+ if ("album".equals(name)) {
+ dir.addChild(parseEntry());
+ } else if ("error".equals(name)) {
+ handleError();
+ }
+ }
+ } while (eventType != XmlPullParser.END_DOCUMENT);
+
+ validate();
+ updateProgress(progressListener, R.string.parser_reading_done);
+
+ return dir;
+ }
+} \ No newline at end of file
diff --git a/subsonic-android/src/net/sourceforge/subsonic/androidapp/service/parser/ErrorParser.java b/subsonic-android/src/net/sourceforge/subsonic/androidapp/service/parser/ErrorParser.java
new file mode 100644
index 00000000..b2c61c5b
--- /dev/null
+++ b/subsonic-android/src/net/sourceforge/subsonic/androidapp/service/parser/ErrorParser.java
@@ -0,0 +1,49 @@
+/*
+ This file is part of Subsonic.
+
+ Subsonic is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ Subsonic is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with Subsonic. If not, see <http://www.gnu.org/licenses/>.
+
+ Copyright 2009 (C) Sindre Mehus
+ */
+package net.sourceforge.subsonic.androidapp.service.parser;
+
+import android.content.Context;
+import org.xmlpull.v1.XmlPullParser;
+
+import java.io.Reader;
+
+/**
+ * @author Sindre Mehus
+ */
+public class ErrorParser extends AbstractParser {
+
+ public ErrorParser(Context context) {
+ super(context);
+ }
+
+ public void parse(Reader reader) throws Exception {
+
+ init(reader);
+
+ int eventType;
+ do {
+ eventType = nextParseEvent();
+ if (eventType == XmlPullParser.START_TAG && "error".equals(getElementName())) {
+ handleError();
+ }
+ } while (eventType != XmlPullParser.END_DOCUMENT);
+
+ validate();
+ }
+} \ No newline at end of file
diff --git a/subsonic-android/src/net/sourceforge/subsonic/androidapp/service/parser/IndexesParser.java b/subsonic-android/src/net/sourceforge/subsonic/androidapp/service/parser/IndexesParser.java
new file mode 100644
index 00000000..83ef3e77
--- /dev/null
+++ b/subsonic-android/src/net/sourceforge/subsonic/androidapp/service/parser/IndexesParser.java
@@ -0,0 +1,104 @@
+/*
+ This file is part of Subsonic.
+
+ Subsonic is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ Subsonic is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with Subsonic. If not, see <http://www.gnu.org/licenses/>.
+
+ Copyright 2009 (C) Sindre Mehus
+ */
+package net.sourceforge.subsonic.androidapp.service.parser;
+
+import java.io.Reader;
+import java.util.List;
+import java.util.ArrayList;
+
+import org.xmlpull.v1.XmlPullParser;
+
+import android.content.Context;
+import net.sourceforge.subsonic.androidapp.R;
+import net.sourceforge.subsonic.androidapp.domain.Artist;
+import net.sourceforge.subsonic.androidapp.domain.Indexes;
+import net.sourceforge.subsonic.androidapp.util.ProgressListener;
+import android.util.Log;
+
+/**
+ * @author Sindre Mehus
+ */
+public class IndexesParser extends AbstractParser {
+ private static final String TAG = IndexesParser.class.getSimpleName();
+
+ public IndexesParser(Context context) {
+ super(context);
+ }
+
+ public Indexes parse(Reader reader, ProgressListener progressListener) throws Exception {
+
+ long t0 = System.currentTimeMillis();
+ updateProgress(progressListener, R.string.parser_reading);
+ init(reader);
+
+ List<Artist> artists = new ArrayList<Artist>();
+ List<Artist> shortcuts = new ArrayList<Artist>();
+ Long lastModified = null;
+ int eventType;
+ String index = "#";
+ boolean changed = false;
+
+ do {
+ eventType = nextParseEvent();
+ if (eventType == XmlPullParser.START_TAG) {
+ String name = getElementName();
+ if ("indexes".equals(name)) {
+ changed = true;
+ lastModified = getLong("lastModified");
+ } else if ("index".equals(name)) {
+ index = get("name");
+
+ } else if ("artist".equals(name)) {
+ Artist artist = new Artist();
+ artist.setId(get("id"));
+ artist.setName(get("name"));
+ artist.setIndex(index);
+ artists.add(artist);
+
+ if (artists.size() % 10 == 0) {
+ String msg = getContext().getResources().getString(R.string.parser_artist_count, artists.size());
+ updateProgress(progressListener, msg);
+ }
+ } else if ("shortcut".equals(name)) {
+ Artist shortcut = new Artist();
+ shortcut.setId(get("id"));
+ shortcut.setName(get("name"));
+ shortcut.setIndex("*");
+ shortcuts.add(shortcut);
+ } else if ("error".equals(name)) {
+ handleError();
+ }
+ }
+ } while (eventType != XmlPullParser.END_DOCUMENT);
+
+ validate();
+
+ if (!changed) {
+ return null;
+ }
+
+ long t1 = System.currentTimeMillis();
+ Log.d(TAG, "Got " + artists.size() + " artist(s) in " + (t1 - t0) + "ms.");
+
+ String msg = getContext().getResources().getString(R.string.parser_artist_count, artists.size());
+ updateProgress(progressListener, msg);
+
+ return new Indexes(lastModified == null ? 0L : lastModified, shortcuts, artists);
+ }
+} \ No newline at end of file
diff --git a/subsonic-android/src/net/sourceforge/subsonic/androidapp/service/parser/JukeboxStatusParser.java b/subsonic-android/src/net/sourceforge/subsonic/androidapp/service/parser/JukeboxStatusParser.java
new file mode 100644
index 00000000..2a61508d
--- /dev/null
+++ b/subsonic-android/src/net/sourceforge/subsonic/androidapp/service/parser/JukeboxStatusParser.java
@@ -0,0 +1,62 @@
+/*
+ This file is part of Subsonic.
+
+ Subsonic is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ Subsonic is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with Subsonic. If not, see <http://www.gnu.org/licenses/>.
+
+ Copyright 2009 (C) Sindre Mehus
+ */
+package net.sourceforge.subsonic.androidapp.service.parser;
+
+import java.io.Reader;
+
+import org.xmlpull.v1.XmlPullParser;
+
+import android.content.Context;
+import net.sourceforge.subsonic.androidapp.domain.JukeboxStatus;
+
+/**
+ * @author Sindre Mehus
+ */
+public class JukeboxStatusParser extends AbstractParser {
+
+ public JukeboxStatusParser(Context context) {
+ super(context);
+ }
+
+ public JukeboxStatus parse(Reader reader) throws Exception {
+
+ init(reader);
+
+ JukeboxStatus jukeboxStatus = new JukeboxStatus();
+ int eventType;
+ do {
+ eventType = nextParseEvent();
+ if (eventType == XmlPullParser.START_TAG) {
+ String name = getElementName();
+ if ("jukeboxPlaylist".equals(name) || "jukeboxStatus".equals(name)) {
+ jukeboxStatus.setPositionSeconds(getInteger("position"));
+ jukeboxStatus.setCurrentIndex(getInteger("currentIndex"));
+ jukeboxStatus.setPlaying(getBoolean("playing"));
+ jukeboxStatus.setGain(getFloat("gain"));
+ } else if ("error".equals(name)) {
+ handleError();
+ }
+ }
+ } while (eventType != XmlPullParser.END_DOCUMENT);
+
+ validate();
+
+ return jukeboxStatus;
+ }
+} \ No newline at end of file
diff --git a/subsonic-android/src/net/sourceforge/subsonic/androidapp/service/parser/LicenseParser.java b/subsonic-android/src/net/sourceforge/subsonic/androidapp/service/parser/LicenseParser.java
new file mode 100644
index 00000000..636c3e6e
--- /dev/null
+++ b/subsonic-android/src/net/sourceforge/subsonic/androidapp/service/parser/LicenseParser.java
@@ -0,0 +1,62 @@
+/*
+ This file is part of Subsonic.
+
+ Subsonic is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ Subsonic is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with Subsonic. If not, see <http://www.gnu.org/licenses/>.
+
+ Copyright 2009 (C) Sindre Mehus
+ */
+package net.sourceforge.subsonic.androidapp.service.parser;
+
+import android.content.Context;
+import org.xmlpull.v1.XmlPullParser;
+
+import java.io.Reader;
+
+import net.sourceforge.subsonic.androidapp.domain.ServerInfo;
+import net.sourceforge.subsonic.androidapp.domain.Version;
+
+/**
+ * @author Sindre Mehus
+ */
+public class LicenseParser extends AbstractParser {
+
+ public LicenseParser(Context context) {
+ super(context);
+ }
+
+ public ServerInfo parse(Reader reader) throws Exception {
+
+ init(reader);
+
+ ServerInfo serverInfo = new ServerInfo();
+ int eventType;
+ do {
+ eventType = nextParseEvent();
+ if (eventType == XmlPullParser.START_TAG) {
+ String name = getElementName();
+ if ("subsonic-response".equals(name)) {
+ serverInfo.setRestVersion(new Version(get("version")));
+ } else if ("license".equals(name)) {
+ serverInfo.setLicenseValid(getBoolean("valid"));
+ } else if ("error".equals(name)) {
+ handleError();
+ }
+ }
+ } while (eventType != XmlPullParser.END_DOCUMENT);
+
+ validate();
+
+ return serverInfo;
+ }
+} \ No newline at end of file
diff --git a/subsonic-android/src/net/sourceforge/subsonic/androidapp/service/parser/LyricsParser.java b/subsonic-android/src/net/sourceforge/subsonic/androidapp/service/parser/LyricsParser.java
new file mode 100644
index 00000000..698fb4b8
--- /dev/null
+++ b/subsonic-android/src/net/sourceforge/subsonic/androidapp/service/parser/LyricsParser.java
@@ -0,0 +1,65 @@
+/*
+ This file is part of Subsonic.
+
+ Subsonic is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ Subsonic is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with Subsonic. If not, see <http://www.gnu.org/licenses/>.
+
+ Copyright 2010 (C) Sindre Mehus
+ */
+package net.sourceforge.subsonic.androidapp.service.parser;
+
+import android.content.Context;
+import net.sourceforge.subsonic.androidapp.R;
+import net.sourceforge.subsonic.androidapp.domain.Lyrics;
+import net.sourceforge.subsonic.androidapp.util.ProgressListener;
+import org.xmlpull.v1.XmlPullParser;
+
+import java.io.Reader;
+
+/**
+ * @author Sindre Mehus
+ */
+public class LyricsParser extends AbstractParser {
+
+ public LyricsParser(Context context) {
+ super(context);
+ }
+
+ public Lyrics parse(Reader reader, ProgressListener progressListener) throws Exception {
+ updateProgress(progressListener, R.string.parser_reading);
+ init(reader);
+
+ Lyrics lyrics = null;
+ int eventType;
+ do {
+ eventType = nextParseEvent();
+ if (eventType == XmlPullParser.START_TAG) {
+ String name = getElementName();
+ if ("lyrics".equals(name)) {
+ lyrics = new Lyrics();
+ lyrics.setArtist(get("artist"));
+ lyrics.setTitle(get("title"));
+ } else if ("error".equals(name)) {
+ handleError();
+ }
+ } else if (eventType == XmlPullParser.TEXT) {
+ if (lyrics != null && lyrics.getText() == null) {
+ lyrics.setText(getText());
+ }
+ }
+ } while (eventType != XmlPullParser.END_DOCUMENT);
+
+ validate();
+ return lyrics;
+ }
+}
diff --git a/subsonic-android/src/net/sourceforge/subsonic/androidapp/service/parser/MusicDirectoryEntryParser.java b/subsonic-android/src/net/sourceforge/subsonic/androidapp/service/parser/MusicDirectoryEntryParser.java
new file mode 100644
index 00000000..3da90613
--- /dev/null
+++ b/subsonic-android/src/net/sourceforge/subsonic/androidapp/service/parser/MusicDirectoryEntryParser.java
@@ -0,0 +1,59 @@
+/*
+ This file is part of Subsonic.
+
+ Subsonic is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ Subsonic is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with Subsonic. If not, see <http://www.gnu.org/licenses/>.
+
+ Copyright 2009 (C) Sindre Mehus
+ */
+package net.sourceforge.subsonic.androidapp.service.parser;
+
+import android.content.Context;
+import net.sourceforge.subsonic.androidapp.domain.MusicDirectory;
+
+/**
+ * @author Sindre Mehus
+ */
+public class MusicDirectoryEntryParser extends AbstractParser {
+
+ public MusicDirectoryEntryParser(Context context) {
+ super(context);
+ }
+
+ protected MusicDirectory.Entry parseEntry() {
+ MusicDirectory.Entry entry = new MusicDirectory.Entry();
+ entry.setId(get("id"));
+ entry.setParent(get("parent"));
+ entry.setTitle(get("title"));
+ entry.setDirectory(getBoolean("isDir"));
+ entry.setCoverArt(get("coverArt"));
+ entry.setArtist(get("artist"));
+
+ if (!entry.isDirectory()) {
+ entry.setAlbum(get("album"));
+ entry.setTrack(getInteger("track"));
+ entry.setYear(getInteger("year"));
+ entry.setGenre(get("genre"));
+ entry.setContentType(get("contentType"));
+ entry.setSuffix(get("suffix"));
+ entry.setTranscodedContentType(get("transcodedContentType"));
+ entry.setTranscodedSuffix(get("transcodedSuffix"));
+ entry.setSize(getLong("size"));
+ entry.setDuration(getInteger("duration"));
+ entry.setBitRate(getInteger("bitRate"));
+ entry.setPath(get("path"));
+ entry.setVideo(getBoolean("isVideo"));
+ }
+ return entry;
+ }
+} \ No newline at end of file
diff --git a/subsonic-android/src/net/sourceforge/subsonic/androidapp/service/parser/MusicDirectoryParser.java b/subsonic-android/src/net/sourceforge/subsonic/androidapp/service/parser/MusicDirectoryParser.java
new file mode 100644
index 00000000..b818fc3d
--- /dev/null
+++ b/subsonic-android/src/net/sourceforge/subsonic/androidapp/service/parser/MusicDirectoryParser.java
@@ -0,0 +1,71 @@
+/*
+ This file is part of Subsonic.
+
+ Subsonic is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ Subsonic is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with Subsonic. If not, see <http://www.gnu.org/licenses/>.
+
+ Copyright 2009 (C) Sindre Mehus
+ */
+package net.sourceforge.subsonic.androidapp.service.parser;
+
+import android.content.Context;
+import android.util.Log;
+import net.sourceforge.subsonic.androidapp.R;
+import net.sourceforge.subsonic.androidapp.domain.MusicDirectory;
+import net.sourceforge.subsonic.androidapp.util.ProgressListener;
+import org.xmlpull.v1.XmlPullParser;
+
+import java.io.Reader;
+
+/**
+ * @author Sindre Mehus
+ */
+public class MusicDirectoryParser extends MusicDirectoryEntryParser {
+
+ private static final String TAG = MusicDirectoryParser.class.getSimpleName();
+
+ public MusicDirectoryParser(Context context) {
+ super(context);
+ }
+
+ public MusicDirectory parse(Reader reader, ProgressListener progressListener) throws Exception {
+
+ long t0 = System.currentTimeMillis();
+ updateProgress(progressListener, R.string.parser_reading);
+ init(reader);
+
+ MusicDirectory dir = new MusicDirectory();
+ int eventType;
+ do {
+ eventType = nextParseEvent();
+ if (eventType == XmlPullParser.START_TAG) {
+ String name = getElementName();
+ if ("child".equals(name)) {
+ dir.addChild(parseEntry());
+ } else if ("directory".equals(name)) {
+ dir.setName(get("name"));
+ } else if ("error".equals(name)) {
+ handleError();
+ }
+ }
+ } while (eventType != XmlPullParser.END_DOCUMENT);
+
+ validate();
+ updateProgress(progressListener, R.string.parser_reading_done);
+
+ long t1 = System.currentTimeMillis();
+ Log.d(TAG, "Got music directory in " + (t1 - t0) + "ms.");
+
+ return dir;
+ }
+} \ No newline at end of file
diff --git a/subsonic-android/src/net/sourceforge/subsonic/androidapp/service/parser/MusicFoldersParser.java b/subsonic-android/src/net/sourceforge/subsonic/androidapp/service/parser/MusicFoldersParser.java
new file mode 100644
index 00000000..35057bd9
--- /dev/null
+++ b/subsonic-android/src/net/sourceforge/subsonic/androidapp/service/parser/MusicFoldersParser.java
@@ -0,0 +1,69 @@
+/*
+ This file is part of Subsonic.
+
+ Subsonic is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ Subsonic is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with Subsonic. If not, see <http://www.gnu.org/licenses/>.
+
+ Copyright 2009 (C) Sindre Mehus
+ */
+package net.sourceforge.subsonic.androidapp.service.parser;
+
+import java.io.Reader;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.xmlpull.v1.XmlPullParser;
+
+import android.content.Context;
+import net.sourceforge.subsonic.androidapp.R;
+import net.sourceforge.subsonic.androidapp.domain.MusicFolder;
+import net.sourceforge.subsonic.androidapp.domain.Playlist;
+import net.sourceforge.subsonic.androidapp.util.ProgressListener;
+
+/**
+ * @author Sindre Mehus
+ */
+public class MusicFoldersParser extends AbstractParser {
+
+ public MusicFoldersParser(Context context) {
+ super(context);
+ }
+
+ public List<MusicFolder> parse(Reader reader, ProgressListener progressListener) throws Exception {
+
+ updateProgress(progressListener, R.string.parser_reading);
+ init(reader);
+
+ List<MusicFolder> result = new ArrayList<MusicFolder>();
+ int eventType;
+ do {
+ eventType = nextParseEvent();
+ if (eventType == XmlPullParser.START_TAG) {
+ String tag = getElementName();
+ if ("musicFolder".equals(tag)) {
+ String id = get("id");
+ String name = get("name");
+ result.add(new MusicFolder(id, name));
+ } else if ("error".equals(tag)) {
+ handleError();
+ }
+ }
+ } while (eventType != XmlPullParser.END_DOCUMENT);
+
+ validate();
+ updateProgress(progressListener, R.string.parser_reading_done);
+
+ return result;
+ }
+
+} \ No newline at end of file
diff --git a/subsonic-android/src/net/sourceforge/subsonic/androidapp/service/parser/PlaylistParser.java b/subsonic-android/src/net/sourceforge/subsonic/androidapp/service/parser/PlaylistParser.java
new file mode 100644
index 00000000..ee829639
--- /dev/null
+++ b/subsonic-android/src/net/sourceforge/subsonic/androidapp/service/parser/PlaylistParser.java
@@ -0,0 +1,62 @@
+/*
+ This file is part of Subsonic.
+
+ Subsonic is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ Subsonic is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with Subsonic. If not, see <http://www.gnu.org/licenses/>.
+
+ Copyright 2009 (C) Sindre Mehus
+ */
+package net.sourceforge.subsonic.androidapp.service.parser;
+
+import android.content.Context;
+import net.sourceforge.subsonic.androidapp.R;
+import net.sourceforge.subsonic.androidapp.domain.MusicDirectory;
+import net.sourceforge.subsonic.androidapp.util.ProgressListener;
+import org.xmlpull.v1.XmlPullParser;
+
+import java.io.Reader;
+
+/**
+ * @author Sindre Mehus
+ */
+public class PlaylistParser extends MusicDirectoryEntryParser {
+
+ public PlaylistParser(Context context) {
+ super(context);
+ }
+
+ public MusicDirectory parse(Reader reader, ProgressListener progressListener) throws Exception {
+ updateProgress(progressListener, R.string.parser_reading);
+ init(reader);
+
+ MusicDirectory dir = new MusicDirectory();
+ int eventType;
+ do {
+ eventType = nextParseEvent();
+ if (eventType == XmlPullParser.START_TAG) {
+ String name = getElementName();
+ if ("entry".equals(name)) {
+ dir.addChild(parseEntry());
+ } else if ("error".equals(name)) {
+ handleError();
+ }
+ }
+ } while (eventType != XmlPullParser.END_DOCUMENT);
+
+ validate();
+ updateProgress(progressListener, R.string.parser_reading_done);
+
+ return dir;
+ }
+
+} \ No newline at end of file
diff --git a/subsonic-android/src/net/sourceforge/subsonic/androidapp/service/parser/PlaylistsParser.java b/subsonic-android/src/net/sourceforge/subsonic/androidapp/service/parser/PlaylistsParser.java
new file mode 100644
index 00000000..c1b88b8c
--- /dev/null
+++ b/subsonic-android/src/net/sourceforge/subsonic/androidapp/service/parser/PlaylistsParser.java
@@ -0,0 +1,67 @@
+/*
+ This file is part of Subsonic.
+
+ Subsonic is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ Subsonic is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with Subsonic. If not, see <http://www.gnu.org/licenses/>.
+
+ Copyright 2009 (C) Sindre Mehus
+ */
+package net.sourceforge.subsonic.androidapp.service.parser;
+
+import android.content.Context;
+import net.sourceforge.subsonic.androidapp.R;
+import net.sourceforge.subsonic.androidapp.domain.Playlist;
+import net.sourceforge.subsonic.androidapp.util.ProgressListener;
+import org.xmlpull.v1.XmlPullParser;
+
+import java.io.Reader;
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * @author Sindre Mehus
+ */
+public class PlaylistsParser extends AbstractParser {
+
+ public PlaylistsParser(Context context) {
+ super(context);
+ }
+
+ public List<Playlist> parse(Reader reader, ProgressListener progressListener) throws Exception {
+
+ updateProgress(progressListener, R.string.parser_reading);
+ init(reader);
+
+ List<Playlist> result = new ArrayList<Playlist>();
+ int eventType;
+ do {
+ eventType = nextParseEvent();
+ if (eventType == XmlPullParser.START_TAG) {
+ String tag = getElementName();
+ if ("playlist".equals(tag)) {
+ String id = get("id");
+ String name = get("name");
+ result.add(new Playlist(id, name));
+ } else if ("error".equals(tag)) {
+ handleError();
+ }
+ }
+ } while (eventType != XmlPullParser.END_DOCUMENT);
+
+ validate();
+ updateProgress(progressListener, R.string.parser_reading_done);
+
+ return result;
+ }
+
+} \ No newline at end of file
diff --git a/subsonic-android/src/net/sourceforge/subsonic/androidapp/service/parser/RandomSongsParser.java b/subsonic-android/src/net/sourceforge/subsonic/androidapp/service/parser/RandomSongsParser.java
new file mode 100644
index 00000000..0bf422b7
--- /dev/null
+++ b/subsonic-android/src/net/sourceforge/subsonic/androidapp/service/parser/RandomSongsParser.java
@@ -0,0 +1,62 @@
+/*
+ This file is part of Subsonic.
+
+ Subsonic is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ Subsonic is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with Subsonic. If not, see <http://www.gnu.org/licenses/>.
+
+ Copyright 2009 (C) Sindre Mehus
+ */
+package net.sourceforge.subsonic.androidapp.service.parser;
+
+import android.content.Context;
+import net.sourceforge.subsonic.androidapp.R;
+import net.sourceforge.subsonic.androidapp.domain.MusicDirectory;
+import net.sourceforge.subsonic.androidapp.util.ProgressListener;
+import org.xmlpull.v1.XmlPullParser;
+
+import java.io.Reader;
+
+/**
+ * @author Sindre Mehus
+ */
+public class RandomSongsParser extends MusicDirectoryEntryParser {
+
+ public RandomSongsParser(Context context) {
+ super(context);
+ }
+
+ public MusicDirectory parse(Reader reader, ProgressListener progressListener) throws Exception {
+ updateProgress(progressListener, R.string.parser_reading);
+ init(reader);
+
+ MusicDirectory dir = new MusicDirectory();
+ int eventType;
+ do {
+ eventType = nextParseEvent();
+ if (eventType == XmlPullParser.START_TAG) {
+ String name = getElementName();
+ if ("song".equals(name)) {
+ dir.addChild(parseEntry());
+ } else if ("error".equals(name)) {
+ handleError();
+ }
+ }
+ } while (eventType != XmlPullParser.END_DOCUMENT);
+
+ validate();
+ updateProgress(progressListener, R.string.parser_reading_done);
+
+ return dir;
+ }
+
+} \ No newline at end of file
diff --git a/subsonic-android/src/net/sourceforge/subsonic/androidapp/service/parser/SearchResult2Parser.java b/subsonic-android/src/net/sourceforge/subsonic/androidapp/service/parser/SearchResult2Parser.java
new file mode 100644
index 00000000..01052f25
--- /dev/null
+++ b/subsonic-android/src/net/sourceforge/subsonic/androidapp/service/parser/SearchResult2Parser.java
@@ -0,0 +1,75 @@
+/*
+ This file is part of Subsonic.
+
+ Subsonic is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ Subsonic is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with Subsonic. If not, see <http://www.gnu.org/licenses/>.
+
+ Copyright 2009 (C) Sindre Mehus
+ */
+package net.sourceforge.subsonic.androidapp.service.parser;
+
+import android.content.Context;
+import net.sourceforge.subsonic.androidapp.R;
+import net.sourceforge.subsonic.androidapp.domain.MusicDirectory;
+import net.sourceforge.subsonic.androidapp.domain.SearchResult;
+import net.sourceforge.subsonic.androidapp.domain.Artist;
+import net.sourceforge.subsonic.androidapp.util.ProgressListener;
+import org.xmlpull.v1.XmlPullParser;
+
+import java.io.Reader;
+import java.util.List;
+import java.util.ArrayList;
+
+/**
+ * @author Sindre Mehus
+ */
+public class SearchResult2Parser extends MusicDirectoryEntryParser {
+
+ public SearchResult2Parser(Context context) {
+ super(context);
+ }
+
+ public SearchResult parse(Reader reader, ProgressListener progressListener) throws Exception {
+ updateProgress(progressListener, R.string.parser_reading);
+ init(reader);
+
+ List<Artist> artists = new ArrayList<Artist>();
+ List<MusicDirectory.Entry> albums = new ArrayList<MusicDirectory.Entry>();
+ List<MusicDirectory.Entry> songs = new ArrayList<MusicDirectory.Entry>();
+ int eventType;
+ do {
+ eventType = nextParseEvent();
+ if (eventType == XmlPullParser.START_TAG) {
+ String name = getElementName();
+ if ("artist".equals(name)) {
+ Artist artist = new Artist();
+ artist.setId(get("id"));
+ artist.setName(get("name"));
+ artists.add(artist);
+ } else if ("album".equals(name)) {
+ albums.add(parseEntry());
+ } else if ("song".equals(name)) {
+ songs.add(parseEntry());
+ } else if ("error".equals(name)) {
+ handleError();
+ }
+ }
+ } while (eventType != XmlPullParser.END_DOCUMENT);
+
+ validate();
+ updateProgress(progressListener, R.string.parser_reading_done);
+
+ return new SearchResult(artists, albums, songs);
+ }
+
+} \ No newline at end of file
diff --git a/subsonic-android/src/net/sourceforge/subsonic/androidapp/service/parser/SearchResultParser.java b/subsonic-android/src/net/sourceforge/subsonic/androidapp/service/parser/SearchResultParser.java
new file mode 100644
index 00000000..c38b077f
--- /dev/null
+++ b/subsonic-android/src/net/sourceforge/subsonic/androidapp/service/parser/SearchResultParser.java
@@ -0,0 +1,67 @@
+/*
+ This file is part of Subsonic.
+
+ Subsonic is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ Subsonic is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with Subsonic. If not, see <http://www.gnu.org/licenses/>.
+
+ Copyright 2009 (C) Sindre Mehus
+ */
+package net.sourceforge.subsonic.androidapp.service.parser;
+
+import android.content.Context;
+import net.sourceforge.subsonic.androidapp.R;
+import net.sourceforge.subsonic.androidapp.domain.MusicDirectory;
+import net.sourceforge.subsonic.androidapp.domain.SearchResult;
+import net.sourceforge.subsonic.androidapp.domain.Artist;
+import net.sourceforge.subsonic.androidapp.util.ProgressListener;
+import org.xmlpull.v1.XmlPullParser;
+
+import java.io.Reader;
+import java.util.Collections;
+import java.util.List;
+import java.util.ArrayList;
+
+/**
+ * @author Sindre Mehus
+ */
+public class SearchResultParser extends MusicDirectoryEntryParser {
+
+ public SearchResultParser(Context context) {
+ super(context);
+ }
+
+ public SearchResult parse(Reader reader, ProgressListener progressListener) throws Exception {
+ updateProgress(progressListener, R.string.parser_reading);
+ init(reader);
+
+ List<MusicDirectory.Entry> songs = new ArrayList<MusicDirectory.Entry>();
+ int eventType;
+ do {
+ eventType = nextParseEvent();
+ if (eventType == XmlPullParser.START_TAG) {
+ String name = getElementName();
+ if ("match".equals(name)) {
+ songs.add(parseEntry());
+ } else if ("error".equals(name)) {
+ handleError();
+ }
+ }
+ } while (eventType != XmlPullParser.END_DOCUMENT);
+
+ validate();
+ updateProgress(progressListener, R.string.parser_reading_done);
+
+ return new SearchResult(Collections.<Artist>emptyList(), Collections.<MusicDirectory.Entry>emptyList(), songs);
+ }
+
+}
diff --git a/subsonic-android/src/net/sourceforge/subsonic/androidapp/service/parser/SubsonicRESTException.java b/subsonic-android/src/net/sourceforge/subsonic/androidapp/service/parser/SubsonicRESTException.java
new file mode 100644
index 00000000..b46b6f22
--- /dev/null
+++ b/subsonic-android/src/net/sourceforge/subsonic/androidapp/service/parser/SubsonicRESTException.java
@@ -0,0 +1,19 @@
+package net.sourceforge.subsonic.androidapp.service.parser;
+
+/**
+ * @author Sindre Mehus
+ * @version $Id$
+ */
+public class SubsonicRESTException extends Exception {
+
+ private final int code;
+
+ public SubsonicRESTException(int code, String message) {
+ super(message);
+ this.code = code;
+ }
+
+ public int getCode() {
+ return code;
+ }
+}
diff --git a/subsonic-android/src/net/sourceforge/subsonic/androidapp/service/parser/VersionParser.java b/subsonic-android/src/net/sourceforge/subsonic/androidapp/service/parser/VersionParser.java
new file mode 100644
index 00000000..b8a05531
--- /dev/null
+++ b/subsonic-android/src/net/sourceforge/subsonic/androidapp/service/parser/VersionParser.java
@@ -0,0 +1,47 @@
+/*
+ This file is part of Subsonic.
+
+ Subsonic is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ Subsonic is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with Subsonic. If not, see <http://www.gnu.org/licenses/>.
+
+ Copyright 2009 (C) Sindre Mehus
+ */
+package net.sourceforge.subsonic.androidapp.service.parser;
+
+import net.sourceforge.subsonic.androidapp.domain.Version;
+
+import java.io.BufferedReader;
+import java.io.Reader;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+/**
+ * @author Sindre Mehus
+ */
+public class VersionParser {
+
+ public Version parse(Reader reader) throws Exception {
+
+ BufferedReader bufferedReader = new BufferedReader(reader);
+ Pattern pattern = Pattern.compile("SUBSONIC_ANDROID_VERSION_BEGIN(.*)SUBSONIC_ANDROID_VERSION_END");
+ String line = bufferedReader.readLine();
+ while (line != null) {
+ Matcher finalMatcher = pattern.matcher(line);
+ if (finalMatcher.find()) {
+ return new Version(finalMatcher.group(1));
+ }
+ line = bufferedReader.readLine();
+ }
+ return null;
+ }
+} \ No newline at end of file
diff --git a/subsonic-android/src/net/sourceforge/subsonic/androidapp/service/ssl/SSLSocketFactory.java b/subsonic-android/src/net/sourceforge/subsonic/androidapp/service/ssl/SSLSocketFactory.java
new file mode 100644
index 00000000..0e146650
--- /dev/null
+++ b/subsonic-android/src/net/sourceforge/subsonic/androidapp/service/ssl/SSLSocketFactory.java
@@ -0,0 +1,497 @@
+/*
+ * ====================================================================
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation. For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ *
+ */
+
+package net.sourceforge.subsonic.androidapp.service.ssl;
+
+import org.apache.http.conn.ConnectTimeoutException;
+import org.apache.http.conn.scheme.HostNameResolver;
+import org.apache.http.conn.scheme.LayeredSocketFactory;
+import org.apache.http.conn.ssl.AllowAllHostnameVerifier;
+import org.apache.http.conn.ssl.BrowserCompatHostnameVerifier;
+import org.apache.http.conn.ssl.StrictHostnameVerifier;
+import org.apache.http.conn.ssl.X509HostnameVerifier;
+import org.apache.http.params.HttpConnectionParams;
+import org.apache.http.params.HttpParams;
+
+import javax.net.ssl.HttpsURLConnection;
+import javax.net.ssl.KeyManager;
+import javax.net.ssl.KeyManagerFactory;
+import javax.net.ssl.SSLContext;
+import javax.net.ssl.SSLSocket;
+import javax.net.ssl.TrustManager;
+import javax.net.ssl.TrustManagerFactory;
+import javax.net.ssl.X509TrustManager;
+
+import java.io.IOException;
+import java.net.InetAddress;
+import java.net.InetSocketAddress;
+import java.net.Socket;
+import java.net.SocketTimeoutException;
+import java.net.UnknownHostException;
+import java.security.KeyManagementException;
+import java.security.KeyStore;
+import java.security.KeyStoreException;
+import java.security.NoSuchAlgorithmException;
+import java.security.SecureRandom;
+import java.security.UnrecoverableKeyException;
+
+/**
+ * Layered socket factory for TLS/SSL connections.
+ * <p>
+ * SSLSocketFactory can be used to validate the identity of the HTTPS server against a list of
+ * trusted certificates and to authenticate to the HTTPS server using a private key.
+ * <p>
+ * SSLSocketFactory will enable server authentication when supplied with
+ * a {@link KeyStore trust-store} file containing one or several trusted certificates. The client
+ * secure socket will reject the connection during the SSL session handshake if the target HTTPS
+ * server attempts to authenticate itself with a non-trusted certificate.
+ * <p>
+ * Use JDK keytool utility to import a trusted certificate and generate a trust-store file:
+ * <pre>
+ * keytool -import -alias "my server cert" -file server.crt -keystore my.truststore
+ * </pre>
+ * <p>
+ * In special cases the standard trust verification process can be bypassed by using a custom
+ * {@link TrustStrategy}. This interface is primarily intended for allowing self-signed
+ * certificates to be accepted as trusted without having to add them to the trust-store file.
+ * <p>
+ * The following parameters can be used to customize the behavior of this
+ * class:
+ * <ul>
+ * <li>{@link org.apache.http.params.CoreConnectionPNames#CONNECTION_TIMEOUT}</li>
+ * <li>{@link org.apache.http.params.CoreConnectionPNames#SO_TIMEOUT}</li>
+ * </ul>
+ * <p>
+ * SSLSocketFactory will enable client authentication when supplied with
+ * a {@link KeyStore key-store} file containing a private key/public certificate
+ * pair. The client secure socket will use the private key to authenticate
+ * itself to the target HTTPS server during the SSL session handshake if
+ * requested to do so by the server.
+ * The target HTTPS server will in its turn verify the certificate presented
+ * by the client in order to establish client's authenticity
+ * <p>
+ * Use the following sequence of actions to generate a key-store file
+ * </p>
+ * <ul>
+ * <li>
+ * <p>
+ * Use JDK keytool utility to generate a new key
+ * <pre>keytool -genkey -v -alias "my client key" -validity 365 -keystore my.keystore</pre>
+ * For simplicity use the same password for the key as that of the key-store
+ * </p>
+ * </li>
+ * <li>
+ * <p>
+ * Issue a certificate signing request (CSR)
+ * <pre>keytool -certreq -alias "my client key" -file mycertreq.csr -keystore my.keystore</pre>
+ * </p>
+ * </li>
+ * <li>
+ * <p>
+ * Send the certificate request to the trusted Certificate Authority for signature.
+ * One may choose to act as her own CA and sign the certificate request using a PKI
+ * tool, such as OpenSSL.
+ * </p>
+ * </li>
+ * <li>
+ * <p>
+ * Import the trusted CA root certificate
+ * <pre>keytool -import -alias "my trusted ca" -file caroot.crt -keystore my.keystore</pre>
+ * </p>
+ * </li>
+ * <li>
+ * <p>
+ * Import the PKCS#7 file containg the complete certificate chain
+ * <pre>keytool -import -alias "my client key" -file mycert.p7 -keystore my.keystore</pre>
+ * </p>
+ * </li>
+ * <li>
+ * <p>
+ * Verify the content the resultant keystore file
+ * <pre>keytool -list -v -keystore my.keystore</pre>
+ * </p>
+ * </li>
+ * </ul>
+ *
+ * @since 4.0
+ */
+public class SSLSocketFactory implements LayeredSocketFactory {
+
+ public static final String TLS = "TLS";
+ public static final String SSL = "SSL";
+ public static final String SSLV2 = "SSLv2";
+
+ public static final X509HostnameVerifier ALLOW_ALL_HOSTNAME_VERIFIER
+ = new AllowAllHostnameVerifier();
+
+ public static final X509HostnameVerifier BROWSER_COMPATIBLE_HOSTNAME_VERIFIER
+ = new BrowserCompatHostnameVerifier();
+
+ public static final X509HostnameVerifier STRICT_HOSTNAME_VERIFIER
+ = new StrictHostnameVerifier();
+
+ /**
+ * The default factory using the default JVM settings for secure connections.
+ */
+ private static final SSLSocketFactory DEFAULT_FACTORY = new SSLSocketFactory();
+
+ /**
+ * Gets the default factory, which uses the default JVM settings for secure
+ * connections.
+ *
+ * @return the default factory
+ */
+ public static SSLSocketFactory getSocketFactory() {
+ return DEFAULT_FACTORY;
+ }
+
+ private final javax.net.ssl.SSLSocketFactory socketfactory;
+ private final HostNameResolver nameResolver;
+ // TODO: make final
+ private volatile X509HostnameVerifier hostnameVerifier;
+
+ private static SSLContext createSSLContext(
+ String algorithm,
+ final KeyStore keystore,
+ final String keystorePassword,
+ final KeyStore truststore,
+ final SecureRandom random,
+ final TrustStrategy trustStrategy)
+ throws NoSuchAlgorithmException, KeyStoreException, UnrecoverableKeyException, KeyManagementException {
+ if (algorithm == null) {
+ algorithm = TLS;
+ }
+ KeyManagerFactory kmfactory = KeyManagerFactory.getInstance(
+ KeyManagerFactory.getDefaultAlgorithm());
+ kmfactory.init(keystore, keystorePassword != null ? keystorePassword.toCharArray(): null);
+ KeyManager[] keymanagers = kmfactory.getKeyManagers();
+ TrustManagerFactory tmfactory = TrustManagerFactory.getInstance(
+ TrustManagerFactory.getDefaultAlgorithm());
+ tmfactory.init(keystore);
+ TrustManager[] trustmanagers = tmfactory.getTrustManagers();
+ if (trustmanagers != null && trustStrategy != null) {
+ for (int i = 0; i < trustmanagers.length; i++) {
+ TrustManager tm = trustmanagers[i];
+ if (tm instanceof X509TrustManager) {
+ trustmanagers[i] = new TrustManagerDecorator(
+ (X509TrustManager) tm, trustStrategy);
+ }
+ }
+ }
+
+ SSLContext sslcontext = SSLContext.getInstance(algorithm);
+ sslcontext.init(keymanagers, trustmanagers, random);
+ return sslcontext;
+ }
+
+ /**
+ * @deprecated Use {@link #SSLSocketFactory(String, KeyStore, String, KeyStore, SecureRandom, X509HostnameVerifier)}
+ */
+ @Deprecated
+ public SSLSocketFactory(
+ final String algorithm,
+ final KeyStore keystore,
+ final String keystorePassword,
+ final KeyStore truststore,
+ final SecureRandom random,
+ final HostNameResolver nameResolver)
+ throws NoSuchAlgorithmException, KeyManagementException, KeyStoreException, UnrecoverableKeyException {
+ this(createSSLContext(
+ algorithm, keystore, keystorePassword, truststore, random, null),
+ nameResolver);
+ }
+
+ /**
+ * @since 4.1
+ */
+ public SSLSocketFactory(
+ String algorithm,
+ final KeyStore keystore,
+ final String keystorePassword,
+ final KeyStore truststore,
+ final SecureRandom random,
+ final X509HostnameVerifier hostnameVerifier)
+ throws NoSuchAlgorithmException, KeyManagementException, KeyStoreException, UnrecoverableKeyException {
+ this(createSSLContext(
+ algorithm, keystore, keystorePassword, truststore, random, null),
+ hostnameVerifier);
+ }
+
+ /**
+ * @since 4.1
+ */
+ public SSLSocketFactory(
+ String algorithm,
+ final KeyStore keystore,
+ final String keystorePassword,
+ final KeyStore truststore,
+ final SecureRandom random,
+ final TrustStrategy trustStrategy,
+ final X509HostnameVerifier hostnameVerifier)
+ throws NoSuchAlgorithmException, KeyManagementException, KeyStoreException, UnrecoverableKeyException {
+ this(createSSLContext(
+ algorithm, keystore, keystorePassword, truststore, random, trustStrategy),
+ hostnameVerifier);
+ }
+
+ public SSLSocketFactory(
+ final KeyStore keystore,
+ final String keystorePassword,
+ final KeyStore truststore)
+ throws NoSuchAlgorithmException, KeyManagementException, KeyStoreException, UnrecoverableKeyException {
+ this(TLS, keystore, keystorePassword, truststore, null, null, BROWSER_COMPATIBLE_HOSTNAME_VERIFIER);
+ }
+
+ public SSLSocketFactory(
+ final KeyStore keystore,
+ final String keystorePassword)
+ throws NoSuchAlgorithmException, KeyManagementException, KeyStoreException, UnrecoverableKeyException{
+ this(TLS, keystore, keystorePassword, null, null, null, BROWSER_COMPATIBLE_HOSTNAME_VERIFIER);
+ }
+
+ public SSLSocketFactory(
+ final KeyStore truststore)
+ throws NoSuchAlgorithmException, KeyManagementException, KeyStoreException, UnrecoverableKeyException {
+ this(TLS, null, null, truststore, null, null, BROWSER_COMPATIBLE_HOSTNAME_VERIFIER);
+ }
+
+ /**
+ * @since 4.1
+ */
+ public SSLSocketFactory(
+ final TrustStrategy trustStrategy,
+ final X509HostnameVerifier hostnameVerifier)
+ throws NoSuchAlgorithmException, KeyManagementException, KeyStoreException, UnrecoverableKeyException {
+ this(TLS, null, null, null, null, trustStrategy, hostnameVerifier);
+ }
+
+ /**
+ * @since 4.1
+ */
+ public SSLSocketFactory(
+ final TrustStrategy trustStrategy)
+ throws NoSuchAlgorithmException, KeyManagementException, KeyStoreException, UnrecoverableKeyException {
+ this(TLS, null, null, null, null, trustStrategy, BROWSER_COMPATIBLE_HOSTNAME_VERIFIER);
+ }
+
+ public SSLSocketFactory(final SSLContext sslContext) {
+ this(sslContext, BROWSER_COMPATIBLE_HOSTNAME_VERIFIER);
+ }
+
+ /**
+ * @deprecated Use {@link #SSLSocketFactory(SSLContext)}
+ */
+ @Deprecated
+ public SSLSocketFactory(
+ final SSLContext sslContext, final HostNameResolver nameResolver) {
+ super();
+ this.socketfactory = sslContext.getSocketFactory();
+ this.hostnameVerifier = BROWSER_COMPATIBLE_HOSTNAME_VERIFIER;
+ this.nameResolver = nameResolver;
+ }
+
+ /**
+ * @since 4.1
+ */
+ public SSLSocketFactory(
+ final SSLContext sslContext, final X509HostnameVerifier hostnameVerifier) {
+ super();
+ this.socketfactory = sslContext.getSocketFactory();
+ this.hostnameVerifier = hostnameVerifier;
+ this.nameResolver = null;
+ }
+
+ private SSLSocketFactory() {
+ super();
+ this.socketfactory = HttpsURLConnection.getDefaultSSLSocketFactory();
+ this.hostnameVerifier = null;
+ this.nameResolver = null;
+ }
+
+ /**
+ * @param params Optional parameters. Parameters passed to this method will have no effect.
+ * This method will create a unconnected instance of {@link Socket} class
+ * using {@link javax.net.ssl.SSLSocketFactory#createSocket()} method.
+ * @since 4.1
+ */
+ @SuppressWarnings("cast")
+ public Socket createSocket(final HttpParams params) throws IOException {
+ // the cast makes sure that the factory is working as expected
+ return (SSLSocket) this.socketfactory.createSocket();
+ }
+
+ @SuppressWarnings("cast")
+ public Socket createSocket() throws IOException {
+ // the cast makes sure that the factory is working as expected
+ return (SSLSocket) this.socketfactory.createSocket();
+ }
+
+ /**
+ * @since 4.1
+ */
+ public Socket connectSocket(
+ final Socket sock,
+ final InetSocketAddress remoteAddress,
+ final InetSocketAddress localAddress,
+ final HttpParams params) throws IOException, UnknownHostException, ConnectTimeoutException {
+ if (remoteAddress == null) {
+ throw new IllegalArgumentException("Remote address may not be null");
+ }
+ if (params == null) {
+ throw new IllegalArgumentException("HTTP parameters may not be null");
+ }
+ SSLSocket sslsock = (SSLSocket) (sock != null ? sock : createSocket());
+ if (localAddress != null) {
+// sslsock.setReuseAddress(HttpConnectionParams.getSoReuseaddr(params));
+ sslsock.bind(localAddress);
+ }
+
+ int connTimeout = HttpConnectionParams.getConnectionTimeout(params);
+ int soTimeout = HttpConnectionParams.getSoTimeout(params);
+
+ try {
+ sslsock.connect(remoteAddress, connTimeout);
+ } catch (SocketTimeoutException ex) {
+ throw new ConnectTimeoutException("Connect to " + remoteAddress.getHostName() + "/"
+ + remoteAddress.getAddress() + " timed out");
+ }
+ sslsock.setSoTimeout(soTimeout);
+ if (this.hostnameVerifier != null) {
+ try {
+ this.hostnameVerifier.verify(remoteAddress.getHostName(), sslsock);
+ // verifyHostName() didn't blowup - good!
+ } catch (IOException iox) {
+ // close the socket before re-throwing the exception
+ try { sslsock.close(); } catch (Exception x) { /*ignore*/ }
+ throw iox;
+ }
+ }
+ return sslsock;
+ }
+
+
+ /**
+ * Checks whether a socket connection is secure.
+ * This factory creates TLS/SSL socket connections
+ * which, by default, are considered secure.
+ * <br/>
+ * Derived classes may override this method to perform
+ * runtime checks, for example based on the cypher suite.
+ *
+ * @param sock the connected socket
+ *
+ * @return <code>true</code>
+ *
+ * @throws IllegalArgumentException if the argument is invalid
+ */
+ public boolean isSecure(final Socket sock) throws IllegalArgumentException {
+ if (sock == null) {
+ throw new IllegalArgumentException("Socket may not be null");
+ }
+ // This instanceof check is in line with createSocket() above.
+ if (!(sock instanceof SSLSocket)) {
+ throw new IllegalArgumentException("Socket not created by this factory");
+ }
+ // This check is performed last since it calls the argument object.
+ if (sock.isClosed()) {
+ throw new IllegalArgumentException("Socket is closed");
+ }
+ return true;
+ }
+
+ /**
+ * @since 4.1
+ */
+ public Socket createLayeredSocket(
+ final Socket socket,
+ final String host,
+ final int port,
+ final boolean autoClose) throws IOException, UnknownHostException {
+ SSLSocket sslSocket = (SSLSocket) this.socketfactory.createSocket(
+ socket,
+ host,
+ port,
+ autoClose
+ );
+ if (this.hostnameVerifier != null) {
+ this.hostnameVerifier.verify(host, sslSocket);
+ }
+ // verifyHostName() didn't blowup - good!
+ return sslSocket;
+ }
+
+ @Deprecated
+ public void setHostnameVerifier(X509HostnameVerifier hostnameVerifier) {
+ if ( hostnameVerifier == null ) {
+ throw new IllegalArgumentException("Hostname verifier may not be null");
+ }
+ this.hostnameVerifier = hostnameVerifier;
+ }
+
+ public X509HostnameVerifier getHostnameVerifier() {
+ return this.hostnameVerifier;
+ }
+
+ /**
+ * @deprecated Use {@link #connectSocket(Socket, InetSocketAddress, InetSocketAddress, HttpParams)}
+ */
+ @Deprecated
+ public Socket connectSocket(
+ final Socket socket,
+ final String host, int port,
+ final InetAddress localAddress, int localPort,
+ final HttpParams params) throws IOException, UnknownHostException, ConnectTimeoutException {
+ InetSocketAddress local = null;
+ if (localAddress != null || localPort > 0) {
+ // we need to bind explicitly
+ if (localPort < 0) {
+ localPort = 0; // indicates "any"
+ }
+ local = new InetSocketAddress(localAddress, localPort);
+ }
+ InetAddress remoteAddress;
+ if (this.nameResolver != null) {
+ remoteAddress = this.nameResolver.resolve(host);
+ } else {
+ remoteAddress = InetAddress.getByName(host);
+ }
+ InetSocketAddress remote = new InetSocketAddress(remoteAddress, port);
+ return connectSocket(socket, remote, local, params);
+ }
+
+ /**
+ * @deprecated Use {@link #createLayeredSocket(Socket, String, int, boolean)}
+ */
+ @Deprecated
+ public Socket createSocket(
+ final Socket socket,
+ final String host, int port,
+ boolean autoClose) throws IOException, UnknownHostException {
+ return createLayeredSocket(socket, host, port, autoClose);
+ }
+
+}
diff --git a/subsonic-android/src/net/sourceforge/subsonic/androidapp/service/ssl/TrustManagerDecorator.java b/subsonic-android/src/net/sourceforge/subsonic/androidapp/service/ssl/TrustManagerDecorator.java
new file mode 100644
index 00000000..41d98249
--- /dev/null
+++ b/subsonic-android/src/net/sourceforge/subsonic/androidapp/service/ssl/TrustManagerDecorator.java
@@ -0,0 +1,65 @@
+/*
+ * ====================================================================
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation. For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ *
+ */
+package net.sourceforge.subsonic.androidapp.service.ssl;
+
+import java.security.cert.CertificateException;
+import java.security.cert.X509Certificate;
+
+import javax.net.ssl.X509TrustManager;
+
+
+/**
+ * @since 4.1
+ */
+class TrustManagerDecorator implements X509TrustManager {
+
+ private final X509TrustManager trustManager;
+ private final TrustStrategy trustStrategy;
+
+ TrustManagerDecorator(final X509TrustManager trustManager, final TrustStrategy trustStrategy) {
+ super();
+ this.trustManager = trustManager;
+ this.trustStrategy = trustStrategy;
+ }
+
+ public void checkClientTrusted(
+ final X509Certificate[] chain, final String authType) throws CertificateException {
+ this.trustManager.checkClientTrusted(chain, authType);
+ }
+
+ public void checkServerTrusted(
+ final X509Certificate[] chain, final String authType) throws CertificateException {
+ if (!this.trustStrategy.isTrusted(chain, authType)) {
+ this.trustManager.checkServerTrusted(chain, authType);
+ }
+ }
+
+ public X509Certificate[] getAcceptedIssuers() {
+ return this.trustManager.getAcceptedIssuers();
+ }
+
+}
diff --git a/subsonic-android/src/net/sourceforge/subsonic/androidapp/service/ssl/TrustSelfSignedStrategy.java b/subsonic-android/src/net/sourceforge/subsonic/androidapp/service/ssl/TrustSelfSignedStrategy.java
new file mode 100644
index 00000000..4fdaaba2
--- /dev/null
+++ b/subsonic-android/src/net/sourceforge/subsonic/androidapp/service/ssl/TrustSelfSignedStrategy.java
@@ -0,0 +1,44 @@
+/*
+ * ====================================================================
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation. For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ *
+ */
+package net.sourceforge.subsonic.androidapp.service.ssl;
+
+import java.security.cert.CertificateException;
+import java.security.cert.X509Certificate;
+
+/**
+ * A trust strategy that accepts self-signed certificates as trusted. Verification of all other
+ * certificates is done by the trust manager configured in the SSL context.
+ *
+ * @since 4.1
+ */
+public class TrustSelfSignedStrategy implements TrustStrategy {
+
+ public boolean isTrusted(final X509Certificate[] chain, final String authType) throws CertificateException {
+ return true;
+ }
+
+}
diff --git a/subsonic-android/src/net/sourceforge/subsonic/androidapp/service/ssl/TrustStrategy.java b/subsonic-android/src/net/sourceforge/subsonic/androidapp/service/ssl/TrustStrategy.java
new file mode 100644
index 00000000..3cf75b68
--- /dev/null
+++ b/subsonic-android/src/net/sourceforge/subsonic/androidapp/service/ssl/TrustStrategy.java
@@ -0,0 +1,57 @@
+/*
+ * ====================================================================
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation. For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ *
+ */
+package net.sourceforge.subsonic.androidapp.service.ssl;
+
+import java.security.cert.CertificateException;
+import java.security.cert.X509Certificate;
+
+/**
+ * A strategy to establish trustworthiness of certificates without consulting the trust manager
+ * configured in the actual SSL context. This interface can be used to override the standard
+ * JSSE certificate verification process.
+ *
+ * @since 4.1
+ */
+public interface TrustStrategy {
+
+ /**
+ * Determines whether the certificate chain can be trusted without consulting the trust manager
+ * configured in the actual SSL context. This method can be used to override the standard JSSE
+ * certificate verification process.
+ * <p>
+ * Please note that, if this method returns <code>false</code>, the trust manager configured
+ * in the actual SSL context can still clear the certificate as trusted.
+ *
+ * @param chain the peer certificate chain
+ * @param authType the authentication type based on the client certificate
+ * @return <code>true</code> if the certificate can be trusted without verification by
+ * the trust manager, <code>false</code> otherwise.
+ * @throws CertificateException thrown if the certificate is not trusted or invalid.
+ */
+ boolean isTrusted(X509Certificate[] chain, String authType) throws CertificateException;
+
+}
diff --git a/subsonic-android/src/net/sourceforge/subsonic/androidapp/util/AlbumView.java b/subsonic-android/src/net/sourceforge/subsonic/androidapp/util/AlbumView.java
new file mode 100644
index 00000000..a4dd3acd
--- /dev/null
+++ b/subsonic-android/src/net/sourceforge/subsonic/androidapp/util/AlbumView.java
@@ -0,0 +1,55 @@
+/*
+ This file is part of Subsonic.
+
+ Subsonic is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ Subsonic is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with Subsonic. If not, see <http://www.gnu.org/licenses/>.
+
+ Copyright 2009 (C) Sindre Mehus
+ */
+package net.sourceforge.subsonic.androidapp.util;
+
+import android.content.Context;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.widget.LinearLayout;
+import android.widget.TextView;
+import net.sourceforge.subsonic.androidapp.R;
+import net.sourceforge.subsonic.androidapp.domain.MusicDirectory;
+
+/**
+ * Used to display albums in a {@code ListView}.
+ *
+ * @author Sindre Mehus
+ */
+public class AlbumView extends LinearLayout {
+
+ private TextView titleView;
+ private TextView artistView;
+ private View coverArtView;
+
+ public AlbumView(Context context) {
+ super(context);
+ LayoutInflater.from(context).inflate(R.layout.album_list_item, this, true);
+
+ titleView = (TextView) findViewById(R.id.album_title);
+ artistView = (TextView) findViewById(R.id.album_artist);
+ coverArtView = findViewById(R.id.album_coverart);
+ }
+
+ public void setAlbum(MusicDirectory.Entry album, ImageLoader imageLoader) {
+ titleView.setText(album.getTitle());
+ artistView.setText(album.getArtist());
+ artistView.setVisibility(album.getArtist() == null ? View.GONE : View.VISIBLE);
+ imageLoader.loadImage(coverArtView, album, false, true);
+ }
+}
diff --git a/subsonic-android/src/net/sourceforge/subsonic/androidapp/util/ArtistAdapter.java b/subsonic-android/src/net/sourceforge/subsonic/androidapp/util/ArtistAdapter.java
new file mode 100644
index 00000000..98ed3c9b
--- /dev/null
+++ b/subsonic-android/src/net/sourceforge/subsonic/androidapp/util/ArtistAdapter.java
@@ -0,0 +1,78 @@
+/*
+ This file is part of Subsonic.
+
+ Subsonic is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ Subsonic is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with Subsonic. If not, see <http://www.gnu.org/licenses/>.
+
+ Copyright 2010 (C) Sindre Mehus
+ */
+package net.sourceforge.subsonic.androidapp.util;
+
+import net.sourceforge.subsonic.androidapp.domain.Artist;
+import net.sourceforge.subsonic.androidapp.R;
+import android.widget.ArrayAdapter;
+import android.widget.SectionIndexer;
+import android.content.Context;
+
+import java.util.List;
+import java.util.Set;
+import java.util.LinkedHashSet;
+import java.util.ArrayList;
+
+/**
+ * @author Sindre Mehus
+*/
+public class ArtistAdapter extends ArrayAdapter<Artist> implements SectionIndexer {
+
+ // Both arrays are indexed by section ID.
+ private final Object[] sections;
+ private final Integer[] positions;
+
+ public ArtistAdapter(Context context, List<Artist> artists) {
+ super(context, R.layout.artist_list_item, artists);
+
+ Set<String> sectionSet = new LinkedHashSet<String>(30);
+ List<Integer> positionList = new ArrayList<Integer>(30);
+ for (int i = 0; i < artists.size(); i++) {
+ Artist artist = artists.get(i);
+ String index = artist.getIndex();
+ if (!sectionSet.contains(index)) {
+ sectionSet.add(index);
+ positionList.add(i);
+ }
+ }
+ sections = sectionSet.toArray(new Object[sectionSet.size()]);
+ positions = positionList.toArray(new Integer[positionList.size()]);
+ }
+
+ @Override
+ public Object[] getSections() {
+ return sections;
+ }
+
+ @Override
+ public int getPositionForSection(int section) {
+ section = Math.min(section, positions.length - 1);
+ return positions[section];
+ }
+
+ @Override
+ public int getSectionForPosition(int pos) {
+ for (int i = 0; i < sections.length - 1; i++) {
+ if (pos < positions[i + 1]) {
+ return i;
+ }
+ }
+ return sections.length - 1;
+ }
+}
diff --git a/subsonic-android/src/net/sourceforge/subsonic/androidapp/util/BackgroundTask.java b/subsonic-android/src/net/sourceforge/subsonic/androidapp/util/BackgroundTask.java
new file mode 100644
index 00000000..1db2fdc1
--- /dev/null
+++ b/subsonic-android/src/net/sourceforge/subsonic/androidapp/util/BackgroundTask.java
@@ -0,0 +1,96 @@
+/*
+ This file is part of Subsonic.
+
+ Subsonic is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ Subsonic is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with Subsonic. If not, see <http://www.gnu.org/licenses/>.
+
+ Copyright 2009 (C) Sindre Mehus
+ */
+package net.sourceforge.subsonic.androidapp.util;
+
+import java.io.FileNotFoundException;
+import java.io.IOException;
+
+import org.xmlpull.v1.XmlPullParserException;
+
+import android.app.Activity;
+import android.os.Handler;
+import android.util.Log;
+import net.sourceforge.subsonic.androidapp.R;
+
+/**
+ * @author Sindre Mehus
+ */
+public abstract class BackgroundTask<T> implements ProgressListener {
+
+ private static final String TAG = BackgroundTask.class.getSimpleName();
+ private final Activity activity;
+ private final Handler handler;
+
+ public BackgroundTask(Activity activity) {
+ this.activity = activity;
+ handler = new Handler();
+ }
+
+ protected Activity getActivity() {
+ return activity;
+ }
+
+ protected Handler getHandler() {
+ return handler;
+ }
+
+ public abstract void execute();
+
+ protected abstract T doInBackground() throws Throwable;
+
+ protected abstract void done(T result);
+
+ protected void error(Throwable error) {
+ Log.w(TAG, "Got exception: " + error, error);
+ new ErrorDialog(activity, getErrorMessage(error), true);
+ }
+
+ protected String getErrorMessage(Throwable error) {
+
+ if (error instanceof IOException && !Util.isNetworkConnected(activity)) {
+ return activity.getResources().getString(R.string.background_task_no_network);
+ }
+
+ if (error instanceof FileNotFoundException) {
+ return activity.getResources().getString(R.string.background_task_not_found);
+ }
+
+ if (error instanceof IOException) {
+ return activity.getResources().getString(R.string.background_task_network_error);
+ }
+
+ if (error instanceof XmlPullParserException) {
+ return activity.getResources().getString(R.string.background_task_parse_error);
+ }
+
+ String message = error.getMessage();
+ if (message != null) {
+ return message;
+ }
+ return error.getClass().getSimpleName();
+ }
+
+ @Override
+ public abstract void updateProgress(final String message);
+
+ @Override
+ public void updateProgress(int messageId) {
+ updateProgress(activity.getResources().getString(messageId));
+ }
+} \ No newline at end of file
diff --git a/subsonic-android/src/net/sourceforge/subsonic/androidapp/util/CacheCleaner.java b/subsonic-android/src/net/sourceforge/subsonic/androidapp/util/CacheCleaner.java
new file mode 100644
index 00000000..46459571
--- /dev/null
+++ b/subsonic-android/src/net/sourceforge/subsonic/androidapp/util/CacheCleaner.java
@@ -0,0 +1,171 @@
+package net.sourceforge.subsonic.androidapp.util;
+
+import java.io.File;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Comparator;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+
+import android.content.Context;
+import android.util.Log;
+import android.os.StatFs;
+import net.sourceforge.subsonic.androidapp.service.DownloadFile;
+import net.sourceforge.subsonic.androidapp.service.DownloadService;
+
+/**
+ * @author Sindre Mehus
+ * @version $Id$
+ */
+public class CacheCleaner {
+
+ private static final String TAG = CacheCleaner.class.getSimpleName();
+ private static final double MAX_FILE_SYSTEM_USAGE = 0.95;
+
+ private final Context context;
+ private final DownloadService downloadService;
+
+ public CacheCleaner(Context context, DownloadService downloadService) {
+ this.context = context;
+ this.downloadService = downloadService;
+ }
+
+ public void clean() {
+
+ Log.i(TAG, "Starting cache cleaning.");
+
+ if (downloadService == null) {
+ Log.e(TAG, "DownloadService not set. Aborting cache cleaning.");
+ return;
+ }
+
+ try {
+
+ List<File> files = new ArrayList<File>();
+ List<File> dirs = new ArrayList<File>();
+
+ findCandidatesForDeletion(FileUtil.getMusicDirectory(context), files, dirs);
+ sortByAscendingModificationTime(files);
+
+ Set<File> undeletable = findUndeletableFiles();
+
+ deleteFiles(files, undeletable);
+ deleteEmptyDirs(dirs, undeletable);
+ Log.i(TAG, "Completed cache cleaning.");
+
+ } catch (RuntimeException x) {
+ Log.e(TAG, "Error in cache cleaning.", x);
+ }
+ }
+
+ private void deleteEmptyDirs(List<File> dirs, Set<File> undeletable) {
+ for (File dir : dirs) {
+ if (undeletable.contains(dir)) {
+ continue;
+ }
+
+ File[] children = dir.listFiles();
+
+ // Delete empty directory and associated album artwork.
+ if (children.length == 0) {
+ Util.delete(dir);
+ Util.delete(FileUtil.getAlbumArtFile(dir));
+ }
+ }
+ }
+
+ private void deleteFiles(List<File> files, Set<File> undeletable) {
+
+ if (files.isEmpty()) {
+ return;
+ }
+
+ long cacheSizeBytes = Util.getCacheSizeMB(context) * 1024L * 1024L;
+
+ long bytesUsedBySubsonic = 0L;
+ for (File file : files) {
+ bytesUsedBySubsonic += file.length();
+ }
+
+ // Ensure that file system is not more than 95% full.
+ StatFs stat = new StatFs(files.get(0).getPath());
+ long bytesTotalFs = (long) stat.getBlockCount() * (long) stat.getBlockSize();
+ long bytesAvailableFs = (long) stat.getAvailableBlocks() * (long) stat.getBlockSize();
+ long bytesUsedFs = bytesTotalFs - bytesAvailableFs;
+ long minFsAvailability = Math.round(MAX_FILE_SYSTEM_USAGE * (double) bytesTotalFs);
+
+ long bytesToDeleteCacheLimit = Math.max(bytesUsedBySubsonic - cacheSizeBytes, 0L);
+ long bytesToDeleteFsLimit = Math.max(bytesUsedFs - minFsAvailability, 0L);
+ long bytesToDelete = Math.max(bytesToDeleteCacheLimit, bytesToDeleteFsLimit);
+
+ Log.i(TAG, "File system : " + Util.formatBytes(bytesAvailableFs) + " of " + Util.formatBytes(bytesTotalFs) + " available");
+ Log.i(TAG, "Cache limit : " + Util.formatBytes(cacheSizeBytes));
+ Log.i(TAG, "Cache size before : " + Util.formatBytes(bytesUsedBySubsonic));
+ Log.i(TAG, "Minimum to delete : " + Util.formatBytes(bytesToDelete));
+
+ long bytesDeleted = 0L;
+ for (File file : files) {
+
+ if (file.getName().equals(Constants.ALBUM_ART_FILE)) {
+ // Move artwork to new folder.
+ file.renameTo(FileUtil.getAlbumArtFile(file.getParentFile()));
+
+ } else if (bytesToDelete > bytesDeleted || file.getName().endsWith(".partial") || file.getName().contains(".partial.")) {
+ if (!undeletable.contains(file)) {
+ long size = file.length();
+ if (Util.delete(file)) {
+ bytesDeleted += size;
+ }
+ }
+ }
+ }
+
+ Log.i(TAG, "Deleted : " + Util.formatBytes(bytesDeleted));
+ Log.i(TAG, "Cache size after : " + Util.formatBytes(bytesUsedBySubsonic - bytesDeleted));
+ }
+
+ private void findCandidatesForDeletion(File file, List<File> files, List<File> dirs) {
+ if (file.isFile()) {
+ String name = file.getName();
+ boolean isCacheFile = name.endsWith(".partial") || name.contains(".partial.") || name.endsWith(".complete") || name.contains(".complete.");
+ boolean isAlbumArtFile = name.equals(Constants.ALBUM_ART_FILE);
+ if (isCacheFile || isAlbumArtFile) {
+ files.add(file);
+ }
+ } else {
+ // Depth-first
+ for (File child : FileUtil.listFiles(file)) {
+ findCandidatesForDeletion(child, files, dirs);
+ }
+ dirs.add(file);
+ }
+ }
+
+ private void sortByAscendingModificationTime(List<File> files) {
+ Collections.sort(files, new Comparator<File>() {
+ @Override
+ public int compare(File a, File b) {
+ if (a.lastModified() < b.lastModified()) {
+ return -1;
+ }
+ if (a.lastModified() > b.lastModified()) {
+ return 1;
+ }
+ return 0;
+ }
+ });
+ }
+
+ private Set<File> findUndeletableFiles() {
+ Set<File> undeletable = new HashSet<File>(5);
+
+ for (DownloadFile downloadFile : downloadService.getDownloads()) {
+ undeletable.add(downloadFile.getPartialFile());
+ undeletable.add(downloadFile.getCompleteFile());
+ }
+
+ undeletable.add(FileUtil.getMusicDirectory(context));
+ return undeletable;
+ }
+}
diff --git a/subsonic-android/src/net/sourceforge/subsonic/androidapp/util/CancellableTask.java b/subsonic-android/src/net/sourceforge/subsonic/androidapp/util/CancellableTask.java
new file mode 100644
index 00000000..9c8b06e1
--- /dev/null
+++ b/subsonic-android/src/net/sourceforge/subsonic/androidapp/util/CancellableTask.java
@@ -0,0 +1,87 @@
+/*
+ This file is part of Subsonic.
+
+ Subsonic is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ Subsonic is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with Subsonic. If not, see <http://www.gnu.org/licenses/>.
+
+ Copyright 2009 (C) Sindre Mehus
+ */
+package net.sourceforge.subsonic.androidapp.util;
+
+import java.util.concurrent.atomic.AtomicBoolean;
+import java.util.concurrent.atomic.AtomicReference;
+
+import android.util.Log;
+
+/**
+ * @author Sindre Mehus
+ * @version $Id$
+ */
+public abstract class CancellableTask {
+
+ private static final String TAG = CancellableTask.class.getSimpleName();
+
+ private final AtomicBoolean running = new AtomicBoolean(false);
+ private final AtomicBoolean cancelled = new AtomicBoolean(false);
+ private final AtomicReference<Thread> thread = new AtomicReference<Thread>();
+ private final AtomicReference<OnCancelListener> cancelListener = new AtomicReference<OnCancelListener>();
+
+ public void cancel() {
+ Log.d(TAG, "Cancelling " + CancellableTask.this);
+ cancelled.set(true);
+
+ OnCancelListener listener = cancelListener.get();
+ if (listener != null) {
+ try {
+ listener.onCancel();
+ } catch (Throwable x) {
+ Log.w(TAG, "Error when invoking OnCancelListener.", x);
+ }
+ }
+ }
+
+ public boolean isCancelled() {
+ return cancelled.get();
+ }
+
+ public void setOnCancelListener(OnCancelListener listener) {
+ cancelListener.set(listener);
+ }
+
+ public boolean isRunning() {
+ return running.get();
+ }
+
+ public abstract void execute();
+
+ public void start() {
+ thread.set(new Thread() {
+ @Override
+ public void run() {
+ running.set(true);
+ Log.d(TAG, "Starting thread for " + CancellableTask.this);
+ try {
+ execute();
+ } finally {
+ running.set(false);
+ Log.d(TAG, "Stopping thread for " + CancellableTask.this);
+ }
+ }
+ });
+ thread.get().start();
+ }
+
+ public static interface OnCancelListener {
+ void onCancel();
+ }
+}
diff --git a/subsonic-android/src/net/sourceforge/subsonic/androidapp/util/Constants.java b/subsonic-android/src/net/sourceforge/subsonic/androidapp/util/Constants.java
new file mode 100644
index 00000000..bebe49ce
--- /dev/null
+++ b/subsonic-android/src/net/sourceforge/subsonic/androidapp/util/Constants.java
@@ -0,0 +1,91 @@
+/*
+ This file is part of Subsonic.
+
+ Subsonic is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ Subsonic is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with Subsonic. If not, see <http://www.gnu.org/licenses/>.
+
+ Copyright 2009 (C) Sindre Mehus
+ */
+package net.sourceforge.subsonic.androidapp.util;
+
+/**
+ * @author Sindre Mehus
+ * @version $Id$
+ */
+public final class Constants {
+
+ // Character encoding used throughout.
+ public static final String UTF_8 = "UTF-8";
+
+ // REST protocol version and client ID.
+ // Note: Keep it as low as possible to maintain compatibility with older servers.
+ public static final String REST_PROTOCOL_VERSION = "1.2.0";
+ public static final String REST_CLIENT_ID = "android";
+
+ // Names for intent extras.
+ public static final String INTENT_EXTRA_NAME_ID = "subsonic.id";
+ public static final String INTENT_EXTRA_NAME_NAME = "subsonic.name";
+ public static final String INTENT_EXTRA_NAME_ARTIST = "subsonic.artist";
+ public static final String INTENT_EXTRA_NAME_TITLE = "subsonic.title";
+ public static final String INTENT_EXTRA_NAME_AUTOPLAY = "subsonic.playall";
+ public static final String INTENT_EXTRA_NAME_ERROR = "subsonic.error";
+ public static final String INTENT_EXTRA_NAME_QUERY = "subsonic.query";
+ public static final String INTENT_EXTRA_NAME_PLAYLIST_ID = "subsonic.playlist.id";
+ public static final String INTENT_EXTRA_NAME_PLAYLIST_NAME = "subsonic.playlist.name";
+ public static final String INTENT_EXTRA_NAME_ALBUM_LIST_TYPE = "subsonic.albumlisttype";
+ public static final String INTENT_EXTRA_NAME_ALBUM_LIST_SIZE = "subsonic.albumlistsize";
+ public static final String INTENT_EXTRA_NAME_ALBUM_LIST_OFFSET = "subsonic.albumlistoffset";
+ public static final String INTENT_EXTRA_NAME_SHUFFLE = "subsonic.shuffle";
+ public static final String INTENT_EXTRA_NAME_REFRESH = "subsonic.refresh";
+ public static final String INTENT_EXTRA_REQUEST_SEARCH = "subsonic.requestsearch";
+ public static final String INTENT_EXTRA_NAME_EXIT = "subsonic.exit" ;
+
+ // Notification IDs.
+ public static final int NOTIFICATION_ID_PLAYING = 100;
+ public static final int NOTIFICATION_ID_ERROR = 101;
+
+ // Preferences keys.
+ public static final String PREFERENCES_KEY_SERVER_INSTANCE = "serverInstanceId";
+ public static final String PREFERENCES_KEY_SERVER_NAME = "serverName";
+ public static final String PREFERENCES_KEY_SERVER_URL = "serverUrl";
+ public static final String PREFERENCES_KEY_MUSIC_FOLDER_ID = "musicFolderId";
+ public static final String PREFERENCES_KEY_USERNAME = "username";
+ public static final String PREFERENCES_KEY_PASSWORD = "password";
+ public static final String PREFERENCES_KEY_INSTALL_TIME = "installTime";
+ public static final String PREFERENCES_KEY_THEME = "theme";
+ public static final String PREFERENCES_KEY_MAX_BITRATE_WIFI = "maxBitrateWifi";
+ public static final String PREFERENCES_KEY_MAX_BITRATE_MOBILE = "maxBitrateMobile";
+ public static final String PREFERENCES_KEY_CACHE_SIZE = "cacheSize";
+ public static final String PREFERENCES_KEY_CACHE_LOCATION = "cacheLocation";
+ public static final String PREFERENCES_KEY_PRELOAD_COUNT = "preloadCount";
+ public static final String PREFERENCES_KEY_HIDE_MEDIA = "hideMedia";
+ public static final String PREFERENCES_KEY_MEDIA_BUTTONS = "mediaButtons";
+ public static final String PREFERENCES_KEY_SCREEN_LIT_ON_DOWNLOAD = "screenLitOnDownload";
+ public static final String PREFERENCES_KEY_SCROBBLE = "scrobble";
+ public static final String PREFERENCES_KEY_REPEAT_MODE = "repeatMode";
+ public static final String PREFERENCES_KEY_WIFI_REQUIRED_FOR_DOWNLOAD = "wifiRequiredForDownload";
+
+ // Name of the preferences file.
+ public static final String PREFERENCES_FILE_NAME = "net.sourceforge.subsonic.androidapp_preferences";
+
+ // Number of free trial days for non-licensed servers.
+ public static final int FREE_TRIAL_DAYS = 30;
+
+ // URL for project donations.
+ public static final String DONATION_URL = "http://subsonic.org/pages/android-donation.jsp";
+
+ public static final String ALBUM_ART_FILE = "folder.jpeg";
+
+ private Constants() {
+ }
+}
diff --git a/subsonic-android/src/net/sourceforge/subsonic/androidapp/util/EntryAdapter.java b/subsonic-android/src/net/sourceforge/subsonic/androidapp/util/EntryAdapter.java
new file mode 100644
index 00000000..1b4d72cf
--- /dev/null
+++ b/subsonic-android/src/net/sourceforge/subsonic/androidapp/util/EntryAdapter.java
@@ -0,0 +1,71 @@
+/*
+ This file is part of Subsonic.
+
+ Subsonic is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ Subsonic is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with Subsonic. If not, see <http://www.gnu.org/licenses/>.
+
+ Copyright 2010 (C) Sindre Mehus
+ */
+package net.sourceforge.subsonic.androidapp.util;
+
+import java.util.List;
+
+import android.view.View;
+import android.view.ViewGroup;
+import android.widget.ArrayAdapter;
+import net.sourceforge.subsonic.androidapp.activity.SubsonicTabActivity;
+import net.sourceforge.subsonic.androidapp.domain.MusicDirectory;
+
+/**
+ * @author Sindre Mehus
+ */
+public class EntryAdapter extends ArrayAdapter<MusicDirectory.Entry> {
+
+ private final SubsonicTabActivity activity;
+ private final ImageLoader imageLoader;
+ private final boolean checkable;
+
+ public EntryAdapter(SubsonicTabActivity activity, ImageLoader imageLoader, List<MusicDirectory.Entry> entries, boolean checkable) {
+ super(activity, android.R.layout.simple_list_item_1, entries);
+ this.activity = activity;
+ this.imageLoader = imageLoader;
+ this.checkable = checkable;
+ }
+
+ @Override
+ public View getView(int position, View convertView, ViewGroup parent) {
+ MusicDirectory.Entry entry = getItem(position);
+
+ if (entry.isDirectory()) {
+ AlbumView view;
+ // TODO: Reuse AlbumView objects once cover art loading is working.
+// if (convertView != null && convertView instanceof AlbumView) {
+// view = (AlbumView) convertView;
+// } else {
+ view = new AlbumView(activity);
+// }
+ view.setAlbum(entry, imageLoader);
+ return view;
+
+ } else {
+ SongView view;
+ if (convertView != null && convertView instanceof SongView) {
+ view = (SongView) convertView;
+ } else {
+ view = new SongView(activity);
+ }
+ view.setSong(entry, checkable);
+ return view;
+ }
+ }
+}
diff --git a/subsonic-android/src/net/sourceforge/subsonic/androidapp/util/ErrorDialog.java b/subsonic-android/src/net/sourceforge/subsonic/androidapp/util/ErrorDialog.java
new file mode 100644
index 00000000..b1c51573
--- /dev/null
+++ b/subsonic-android/src/net/sourceforge/subsonic/androidapp/util/ErrorDialog.java
@@ -0,0 +1,61 @@
+/*
+ This file is part of Subsonic.
+
+ Subsonic is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ Subsonic is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with Subsonic. If not, see <http://www.gnu.org/licenses/>.
+
+ Copyright 2009 (C) Sindre Mehus
+ */
+package net.sourceforge.subsonic.androidapp.util;
+
+import android.app.Activity;
+import android.app.AlertDialog;
+import android.content.DialogInterface;
+import net.sourceforge.subsonic.androidapp.R;
+
+/**
+ * @author Sindre Mehus
+ */
+public class ErrorDialog {
+
+ public ErrorDialog(Activity activity, int messageId, boolean finishActivityOnCancel) {
+ this(activity, activity.getResources().getString(messageId), finishActivityOnCancel);
+ }
+
+ public ErrorDialog(final Activity activity, String message, final boolean finishActivityOnClose) {
+
+ AlertDialog.Builder builder = new AlertDialog.Builder(activity);
+ builder.setIcon(android.R.drawable.ic_dialog_alert);
+ builder.setTitle(R.string.error_label);
+ builder.setMessage(message);
+ builder.setCancelable(true);
+ builder.setOnCancelListener(new DialogInterface.OnCancelListener() {
+ @Override
+ public void onCancel(DialogInterface dialogInterface) {
+ if (finishActivityOnClose) {
+ activity.finish();
+ }
+ }
+ });
+ builder.setPositiveButton(R.string.common_ok, new DialogInterface.OnClickListener() {
+ @Override
+ public void onClick(DialogInterface dialogInterface, int i) {
+ if (finishActivityOnClose) {
+ activity.finish();
+ }
+ }
+ });
+
+ builder.create().show();
+ }
+}
diff --git a/subsonic-android/src/net/sourceforge/subsonic/androidapp/util/FileUtil.java b/subsonic-android/src/net/sourceforge/subsonic/androidapp/util/FileUtil.java
new file mode 100644
index 00000000..6cdd6fb1
--- /dev/null
+++ b/subsonic-android/src/net/sourceforge/subsonic/androidapp/util/FileUtil.java
@@ -0,0 +1,301 @@
+/*
+ This file is part of Subsonic.
+
+ Subsonic is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ Subsonic is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with Subsonic. If not, see <http://www.gnu.org/licenses/>.
+
+ Copyright 2009 (C) Sindre Mehus
+ */
+package net.sourceforge.subsonic.androidapp.util;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+import java.io.Serializable;
+import java.util.Arrays;
+import java.util.SortedSet;
+import java.util.TreeSet;
+import java.util.Iterator;
+import java.util.List;
+
+import android.content.Context;
+import android.graphics.Bitmap;
+import android.graphics.BitmapFactory;
+import android.os.Environment;
+import android.util.Log;
+import net.sourceforge.subsonic.androidapp.domain.MusicDirectory;
+
+/**
+ * @author Sindre Mehus
+ */
+public class FileUtil {
+
+ private static final String TAG = FileUtil.class.getSimpleName();
+ private static final String[] FILE_SYSTEM_UNSAFE = {"/", "\\", "..", ":", "\"", "?", "*", "<", ">"};
+ private static final String[] FILE_SYSTEM_UNSAFE_DIR = {"\\", "..", ":", "\"", "?", "*", "<", ">"};
+ private static final List<String> MUSIC_FILE_EXTENSIONS = Arrays.asList("mp3", "ogg", "aac", "flac", "m4a", "wav", "wma");
+ private static final File DEFAULT_MUSIC_DIR = createDirectory("music");
+
+ public static File getSongFile(Context context, MusicDirectory.Entry song) {
+ File dir = getAlbumDirectory(context, song);
+
+ StringBuilder fileName = new StringBuilder();
+ Integer track = song.getTrack();
+ if (track != null) {
+ if (track < 10) {
+ fileName.append("0");
+ }
+ fileName.append(track).append("-");
+ }
+
+ fileName.append(fileSystemSafe(song.getTitle())).append(".");
+
+ if (song.getTranscodedSuffix() != null) {
+ fileName.append(song.getTranscodedSuffix());
+ } else {
+ fileName.append(song.getSuffix());
+ }
+
+ return new File(dir, fileName.toString());
+ }
+
+ public static File getAlbumArtFile(Context context, MusicDirectory.Entry entry) {
+ File albumDir = getAlbumDirectory(context, entry);
+ return getAlbumArtFile(albumDir);
+ }
+
+ public static File getAlbumArtFile(File albumDir) {
+ File albumArtDir = getAlbumArtDirectory();
+ return new File(albumArtDir, Util.md5Hex(albumDir.getPath()) + ".jpeg");
+ }
+
+ public static Bitmap getAlbumArtBitmap(Context context, MusicDirectory.Entry entry, int size) {
+ File albumArtFile = getAlbumArtFile(context, entry);
+ if (albumArtFile.exists()) {
+ Bitmap bitmap = BitmapFactory.decodeFile(albumArtFile.getPath());
+ return bitmap == null ? null : Bitmap.createScaledBitmap(bitmap, size, size, true);
+ }
+ return null;
+ }
+
+ public static File getAlbumArtDirectory() {
+ File albumArtDir = new File(getSubsonicDirectory(), "artwork");
+ ensureDirectoryExistsAndIsReadWritable(albumArtDir);
+ ensureDirectoryExistsAndIsReadWritable(new File(albumArtDir, ".nomedia"));
+ return albumArtDir;
+ }
+
+ private static File getAlbumDirectory(Context context, MusicDirectory.Entry entry) {
+ File dir;
+ if (entry.getPath() != null) {
+ File f = new File(fileSystemSafeDir(entry.getPath()));
+ dir = new File(getMusicDirectory(context).getPath() + "/" + (entry.isDirectory() ? f.getPath() : f.getParent()));
+ } else {
+ String artist = fileSystemSafe(entry.getArtist());
+ String album = fileSystemSafe(entry.getAlbum());
+ dir = new File(getMusicDirectory(context).getPath() + "/" + artist + "/" + album);
+ }
+ return dir;
+ }
+
+ public static void createDirectoryForParent(File file) {
+ File dir = file.getParentFile();
+ if (!dir.exists()) {
+ if (!dir.mkdirs()) {
+ Log.e(TAG, "Failed to create directory " + dir);
+ }
+ }
+ }
+
+ private static File createDirectory(String name) {
+ File dir = new File(getSubsonicDirectory(), name);
+ if (!dir.exists() && !dir.mkdirs()) {
+ Log.e(TAG, "Failed to create " + name);
+ }
+ return dir;
+ }
+
+ public static File getSubsonicDirectory() {
+ return new File(Environment.getExternalStorageDirectory(), "subsonic");
+ }
+
+ public static File getDefaultMusicDirectory() {
+ return DEFAULT_MUSIC_DIR;
+ }
+
+ public static File getMusicDirectory(Context context) {
+ String path = Util.getPreferences(context).getString(Constants.PREFERENCES_KEY_CACHE_LOCATION, DEFAULT_MUSIC_DIR.getPath());
+ File dir = new File(path);
+ return ensureDirectoryExistsAndIsReadWritable(dir) ? dir : getDefaultMusicDirectory();
+ }
+
+ public static boolean ensureDirectoryExistsAndIsReadWritable(File dir) {
+ if (dir == null) {
+ return false;
+ }
+
+ if (dir.exists()) {
+ if (!dir.isDirectory()) {
+ Log.w(TAG, dir + " exists but is not a directory.");
+ return false;
+ }
+ } else {
+ if (dir.mkdirs()) {
+ Log.i(TAG, "Created directory " + dir);
+ } else {
+ Log.w(TAG, "Failed to create directory " + dir);
+ return false;
+ }
+ }
+
+ if (!dir.canRead()) {
+ Log.w(TAG, "No read permission for directory " + dir);
+ return false;
+ }
+
+ if (!dir.canWrite()) {
+ Log.w(TAG, "No write permission for directory " + dir);
+ return false;
+ }
+ return true;
+ }
+
+ /**
+ * Makes a given filename safe by replacing special characters like slashes ("/" and "\")
+ * with dashes ("-").
+ *
+ * @param filename The filename in question.
+ * @return The filename with special characters replaced by hyphens.
+ */
+ private static String fileSystemSafe(String filename) {
+ if (filename == null || filename.trim().length() == 0) {
+ return "unnamed";
+ }
+
+ for (String s : FILE_SYSTEM_UNSAFE) {
+ filename = filename.replace(s, "-");
+ }
+ return filename;
+ }
+
+ /**
+ * Makes a given filename safe by replacing special characters like colons (":")
+ * with dashes ("-").
+ *
+ * @param path The path of the directory in question.
+ * @return The the directory name with special characters replaced by hyphens.
+ */
+ private static String fileSystemSafeDir(String path) {
+ if (path == null || path.trim().length() == 0) {
+ return "";
+ }
+
+ for (String s : FILE_SYSTEM_UNSAFE_DIR) {
+ path = path.replace(s, "-");
+ }
+ return path;
+ }
+
+ /**
+ * Similar to {@link File#listFiles()}, but returns a sorted set.
+ * Never returns {@code null}, instead a warning is logged, and an empty set is returned.
+ */
+ public static SortedSet<File> listFiles(File dir) {
+ File[] files = dir.listFiles();
+ if (files == null) {
+ Log.w(TAG, "Failed to list children for " + dir.getPath());
+ return new TreeSet<File>();
+ }
+
+ return new TreeSet<File>(Arrays.asList(files));
+ }
+
+ public static SortedSet<File> listMusicFiles(File dir) {
+ SortedSet<File> files = listFiles(dir);
+ Iterator<File> iterator = files.iterator();
+ while (iterator.hasNext()) {
+ File file = iterator.next();
+ if (!file.isDirectory() && !isMusicFile(file)) {
+ iterator.remove();
+ }
+ }
+ return files;
+ }
+
+ private static boolean isMusicFile(File file) {
+ String extension = getExtension(file.getName());
+ return MUSIC_FILE_EXTENSIONS.contains(extension);
+ }
+
+ /**
+ * Returns the extension (the substring after the last dot) of the given file. The dot
+ * is not included in the returned extension.
+ *
+ * @param name The filename in question.
+ * @return The extension, or an empty string if no extension is found.
+ */
+ public static String getExtension(String name) {
+ int index = name.lastIndexOf('.');
+ return index == -1 ? "" : name.substring(index + 1).toLowerCase();
+ }
+
+ /**
+ * Returns the base name (the substring before the last dot) of the given file. The dot
+ * is not included in the returned basename.
+ *
+ * @param name The filename in question.
+ * @return The base name, or an empty string if no basename is found.
+ */
+ public static String getBaseName(String name) {
+ int index = name.lastIndexOf('.');
+ return index == -1 ? name : name.substring(0, index);
+ }
+
+ public static <T extends Serializable> boolean serialize(Context context, T obj, String fileName) {
+ File file = new File(context.getCacheDir(), fileName);
+ ObjectOutputStream out = null;
+ try {
+ out = new ObjectOutputStream(new FileOutputStream(file));
+ out.writeObject(obj);
+ Log.i(TAG, "Serialized object to " + file);
+ return true;
+ } catch (Throwable x) {
+ Log.w(TAG, "Failed to serialize object to " + file);
+ return false;
+ } finally {
+ Util.close(out);
+ }
+ }
+
+ public static <T extends Serializable> T deserialize(Context context, String fileName) {
+ File file = new File(context.getCacheDir(), fileName);
+ if (!file.exists() || !file.isFile()) {
+ return null;
+ }
+
+ ObjectInputStream in = null;
+ try {
+ in = new ObjectInputStream(new FileInputStream(file));
+ T result = (T) in.readObject();
+ Log.i(TAG, "Deserialized object from " + file);
+ return result;
+ } catch (Throwable x) {
+ Log.w(TAG, "Failed to deserialize object from " + file, x);
+ return null;
+ } finally {
+ Util.close(in);
+ }
+ }
+}
diff --git a/subsonic-android/src/net/sourceforge/subsonic/androidapp/util/HorizontalSlider.java b/subsonic-android/src/net/sourceforge/subsonic/androidapp/util/HorizontalSlider.java
new file mode 100644
index 00000000..6a79a0a0
--- /dev/null
+++ b/subsonic-android/src/net/sourceforge/subsonic/androidapp/util/HorizontalSlider.java
@@ -0,0 +1,141 @@
+/*
+ This file is part of Subsonic.
+
+ Subsonic is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ Subsonic is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with Subsonic. If not, see <http://www.gnu.org/licenses/>.
+
+ Copyright 2009 (C) Sindre Mehus
+ */
+package net.sourceforge.subsonic.androidapp.util;
+
+import android.content.Context;
+import android.graphics.Bitmap;
+import android.graphics.BitmapFactory;
+import android.graphics.Canvas;
+import android.util.AttributeSet;
+import android.view.MotionEvent;
+import android.view.View;
+import android.widget.ProgressBar;
+import net.sourceforge.subsonic.androidapp.R;
+
+/**
+ * @author Sindre Mehus
+ * @version $Id$
+ */
+public class HorizontalSlider extends ProgressBar {
+
+ private final Bitmap bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.slider_knob);
+ private boolean slidingEnabled;
+ private OnSliderChangeListener listener;
+ private static final int PADDING = 2;
+ private boolean sliding;
+ private int sliderPosition;
+ private int startPosition;
+
+ public interface OnSliderChangeListener {
+ void onSliderChanged(View view, int position, boolean inProgress);
+ }
+
+ public HorizontalSlider(Context context, AttributeSet attrs, int defStyle) {
+ super(context, attrs, defStyle);
+ }
+
+ public HorizontalSlider(Context context, AttributeSet attrs) {
+ super(context, attrs, android.R.attr.progressBarStyleHorizontal);
+ }
+
+ public HorizontalSlider(Context context) {
+ super(context);
+ }
+
+ public void setSlidingEnabled(boolean slidingEnabled) {
+ if (this.slidingEnabled != slidingEnabled) {
+ this.slidingEnabled = slidingEnabled;
+ invalidate();
+ }
+ }
+
+ public boolean isSlidingEnabled() {
+ return slidingEnabled;
+ }
+
+ public void setOnSliderChangeListener(OnSliderChangeListener listener) {
+ this.listener = listener;
+ }
+
+ @Override
+ protected void onDraw(Canvas canvas) {
+ super.onDraw(canvas);
+
+ int max = getMax();
+ if (!slidingEnabled || max == 0) {
+ return;
+ }
+
+ int paddingLeft = getPaddingLeft();
+ int paddingRight = getPaddingRight();
+ int paddingTop = getPaddingTop();
+ int paddingBottom = getPaddingBottom();
+
+ int w = getWidth() - paddingLeft - paddingRight;
+ int h = getHeight() - paddingTop - paddingBottom;
+ int position = sliding ? sliderPosition : getProgress();
+
+ int bitmapWidth = bitmap.getWidth();
+ int bitmapHeight = bitmap.getWidth();
+ float x = paddingLeft + w * ((float) position / max) - bitmapWidth / 2.0F;
+ x = Math.max(x, paddingLeft);
+ x = Math.min(x, paddingLeft + w - bitmapWidth);
+ float y = paddingTop + h / 2.0F - bitmapHeight / 2.0F;
+
+ canvas.drawBitmap(bitmap, x, y, null);
+ }
+
+ @Override
+ public boolean onTouchEvent(MotionEvent event) {
+ if (!slidingEnabled) {
+ return false;
+ }
+
+ int action = event.getAction();
+
+ if (action == MotionEvent.ACTION_DOWN || action == MotionEvent.ACTION_MOVE) {
+
+ if (action == MotionEvent.ACTION_DOWN) {
+ sliding = true;
+ startPosition = getProgress();
+ }
+
+ float x = event.getX() - PADDING;
+ float width = getWidth() - 2 * PADDING;
+ sliderPosition = Math.round((float) getMax() * (x / width));
+ sliderPosition = Math.max(sliderPosition, 0);
+
+ setProgress(Math.min(startPosition, sliderPosition));
+ setSecondaryProgress(Math.max(startPosition, sliderPosition));
+ if (listener != null) {
+ listener.onSliderChanged(this, sliderPosition, true);
+ }
+
+ } else if (action == MotionEvent.ACTION_UP) {
+ sliding = false;
+ setProgress(sliderPosition);
+ setSecondaryProgress(0);
+ if (listener != null) {
+ listener.onSliderChanged(this, sliderPosition, false);
+ }
+ }
+
+ return true;
+ }
+} \ No newline at end of file
diff --git a/subsonic-android/src/net/sourceforge/subsonic/androidapp/util/ImageLoader.java b/subsonic-android/src/net/sourceforge/subsonic/androidapp/util/ImageLoader.java
new file mode 100644
index 00000000..5cbd8c9f
--- /dev/null
+++ b/subsonic-android/src/net/sourceforge/subsonic/androidapp/util/ImageLoader.java
@@ -0,0 +1,252 @@
+/*
+ This file is part of Subsonic.
+
+ Subsonic is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ Subsonic is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with Subsonic. If not, see <http://www.gnu.org/licenses/>.
+
+ Copyright 2009 (C) Sindre Mehus
+ */
+package net.sourceforge.subsonic.androidapp.util;
+
+import android.content.Context;
+import android.graphics.Bitmap;
+import android.graphics.Canvas;
+import android.graphics.LinearGradient;
+import android.graphics.Matrix;
+import android.graphics.Paint;
+import android.graphics.Shader;
+import android.graphics.drawable.BitmapDrawable;
+import android.graphics.drawable.Drawable;
+import android.graphics.drawable.TransitionDrawable;
+import android.os.Handler;
+import android.util.DisplayMetrics;
+import android.util.Log;
+import android.view.View;
+import android.widget.ImageView;
+import android.widget.TextView;
+import net.sourceforge.subsonic.androidapp.R;
+import net.sourceforge.subsonic.androidapp.domain.MusicDirectory;
+import net.sourceforge.subsonic.androidapp.service.MusicService;
+import net.sourceforge.subsonic.androidapp.service.MusicServiceFactory;
+
+import java.util.concurrent.BlockingQueue;
+import java.util.concurrent.LinkedBlockingQueue;
+
+/**
+ * Asynchronous loading of images, with caching.
+ * <p/>
+ * There should normally be only one instance of this class.
+ *
+ * @author Sindre Mehus
+ */
+public class ImageLoader implements Runnable {
+
+ private static final String TAG = ImageLoader.class.getSimpleName();
+ private static final int CONCURRENCY = 5;
+
+ private final LRUCache<String, Drawable> cache = new LRUCache<String, Drawable>(100);
+ private final BlockingQueue<Task> queue;
+ private final int imageSizeDefault;
+ private final int imageSizeLarge;
+ private Drawable largeUnknownImage;
+
+ public ImageLoader(Context context) {
+ queue = new LinkedBlockingQueue<Task>(500);
+
+ // Determine the density-dependent image sizes.
+ imageSizeDefault = context.getResources().getDrawable(R.drawable.unknown_album).getIntrinsicHeight();
+ DisplayMetrics metrics = context.getResources().getDisplayMetrics();
+ imageSizeLarge = (int) Math.round(Math.min(metrics.widthPixels, metrics.heightPixels) * 0.6);
+
+ for (int i = 0; i < CONCURRENCY; i++) {
+ new Thread(this, "ImageLoader").start();
+ }
+
+ createLargeUnknownImage(context);
+ }
+
+ private void createLargeUnknownImage(Context context) {
+ BitmapDrawable drawable = (BitmapDrawable) context.getResources().getDrawable(R.drawable.unknown_album_large);
+ Bitmap bitmap = Bitmap.createScaledBitmap(drawable.getBitmap(), imageSizeLarge, imageSizeLarge, true);
+ bitmap = createReflection(bitmap);
+ largeUnknownImage = Util.createDrawableFromBitmap(context, bitmap);
+ }
+
+ public void loadImage(View view, MusicDirectory.Entry entry, boolean large, boolean crossfade) {
+ if (entry == null || entry.getCoverArt() == null) {
+ setUnknownImage(view, large);
+ return;
+ }
+
+ int size = large ? imageSizeLarge : imageSizeDefault;
+ Drawable drawable = cache.get(getKey(entry.getCoverArt(), size));
+ if (drawable != null) {
+ setImage(view, drawable, large);
+ return;
+ }
+
+ if (!large) {
+ setUnknownImage(view, large);
+ }
+ queue.offer(new Task(view, entry, size, large, large, crossfade));
+ }
+
+ private String getKey(String coverArtId, int size) {
+ return coverArtId + size;
+ }
+
+ private void setImage(View view, Drawable drawable, boolean crossfade) {
+ if (view instanceof TextView) {
+ // Cross-fading is not implemented for TextView since it's not in use. It would be easy to add it, though.
+ TextView textView = (TextView) view;
+ textView.setCompoundDrawablesWithIntrinsicBounds(drawable, null, null, null);
+ } else if (view instanceof ImageView) {
+ ImageView imageView = (ImageView) view;
+ if (crossfade) {
+
+ Drawable existingDrawable = imageView.getDrawable();
+ if (existingDrawable == null) {
+ Bitmap emptyImage = Bitmap.createBitmap(drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight(), Bitmap.Config.ARGB_8888);
+ existingDrawable = new BitmapDrawable(emptyImage);
+ }
+
+ Drawable[] layers = new Drawable[]{existingDrawable, drawable};
+
+ TransitionDrawable transitionDrawable = new TransitionDrawable(layers);
+ imageView.setImageDrawable(transitionDrawable);
+ transitionDrawable.startTransition(250);
+ } else {
+ imageView.setImageDrawable(drawable);
+ }
+ }
+ }
+
+ private void setUnknownImage(View view, boolean large) {
+ if (large) {
+ setImage(view, largeUnknownImage, false);
+ } else {
+ if (view instanceof TextView) {
+ ((TextView) view).setCompoundDrawablesWithIntrinsicBounds(R.drawable.unknown_album, 0, 0, 0);
+ } else if (view instanceof ImageView) {
+ ((ImageView) view).setImageResource(R.drawable.unknown_album);
+ }
+ }
+ }
+
+ public void clear() {
+ queue.clear();
+ }
+
+ @Override
+ public void run() {
+ while (true) {
+ try {
+ Task task = queue.take();
+ task.execute();
+ } catch (Throwable x) {
+ Log.e(TAG, "Unexpected exception in ImageLoader.", x);
+ }
+ }
+ }
+
+ private Bitmap createReflection(Bitmap originalImage) {
+
+ int width = originalImage.getWidth();
+ int height = originalImage.getHeight();
+
+ // The gap we want between the reflection and the original image
+ final int reflectionGap = 4;
+
+ // This will not scale but will flip on the Y axis
+ Matrix matrix = new Matrix();
+ matrix.preScale(1, -1);
+
+ // Create a Bitmap with the flip matix applied to it.
+ // We only want the bottom half of the image
+ Bitmap reflectionImage = Bitmap.createBitmap(originalImage, 0, height / 2, width, height / 2, matrix, false);
+
+ // Create a new bitmap with same width but taller to fit reflection
+ Bitmap bitmapWithReflection = Bitmap.createBitmap(width, (height + height / 2), Bitmap.Config.ARGB_8888);
+
+ // Create a new Canvas with the bitmap that's big enough for
+ // the image plus gap plus reflection
+ Canvas canvas = new Canvas(bitmapWithReflection);
+
+ // Draw in the original image
+ canvas.drawBitmap(originalImage, 0, 0, null);
+
+ // Draw in the gap
+ Paint defaultPaint = new Paint();
+ canvas.drawRect(0, height, width, height + reflectionGap, defaultPaint);
+
+ // Draw in the reflection
+ canvas.drawBitmap(reflectionImage, 0, height + reflectionGap, null);
+
+ // Create a shader that is a linear gradient that covers the reflection
+ Paint paint = new Paint();
+ LinearGradient shader = new LinearGradient(0, originalImage.getHeight(), 0,
+ bitmapWithReflection.getHeight() + reflectionGap, 0x70000000, 0xff000000,
+ Shader.TileMode.CLAMP);
+
+ // Set the paint to use this shader (linear gradient)
+ paint.setShader(shader);
+
+ // Draw a rectangle using the paint with our linear gradient
+ canvas.drawRect(0, height, width, bitmapWithReflection.getHeight() + reflectionGap, paint);
+
+ return bitmapWithReflection;
+ }
+
+ private class Task {
+ private final View view;
+ private final MusicDirectory.Entry entry;
+ private final Handler handler;
+ private final int size;
+ private final boolean reflection;
+ private final boolean saveToFile;
+ private final boolean crossfade;
+
+ public Task(View view, MusicDirectory.Entry entry, int size, boolean reflection, boolean saveToFile, boolean crossfade) {
+ this.view = view;
+ this.entry = entry;
+ this.size = size;
+ this.reflection = reflection;
+ this.saveToFile = saveToFile;
+ this.crossfade = crossfade;
+ handler = new Handler();
+ }
+
+ public void execute() {
+ try {
+ MusicService musicService = MusicServiceFactory.getMusicService(view.getContext());
+ Bitmap bitmap = musicService.getCoverArt(view.getContext(), entry, size, saveToFile, null);
+
+ if (reflection) {
+ bitmap = createReflection(bitmap);
+ }
+
+ final Drawable drawable = Util.createDrawableFromBitmap(view.getContext(), bitmap);
+ cache.put(getKey(entry.getCoverArt(), size), drawable);
+
+ handler.post(new Runnable() {
+ @Override
+ public void run() {
+ setImage(view, drawable, crossfade);
+ }
+ });
+ } catch (Throwable x) {
+ Log.e(TAG, "Failed to download album art.", x);
+ }
+ }
+ }
+}
diff --git a/subsonic-android/src/net/sourceforge/subsonic/androidapp/util/LRUCache.java b/subsonic-android/src/net/sourceforge/subsonic/androidapp/util/LRUCache.java
new file mode 100644
index 00000000..f6145fb7
--- /dev/null
+++ b/subsonic-android/src/net/sourceforge/subsonic/androidapp/util/LRUCache.java
@@ -0,0 +1,102 @@
+/*
+ This file is part of Subsonic.
+
+ Subsonic is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ Subsonic is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with Subsonic. If not, see <http://www.gnu.org/licenses/>.
+
+ Copyright 2009 (C) Sindre Mehus
+ */
+package net.sourceforge.subsonic.androidapp.util;
+
+import java.lang.ref.SoftReference;
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * @author Sindre Mehus
+ */
+public class LRUCache<K,V>{
+
+ private final int capacity;
+ private final Map<K, TimestampedValue> map;
+
+ public LRUCache(int capacity) {
+ map = new HashMap<K, TimestampedValue>(capacity);
+ this.capacity = capacity;
+ }
+
+ public synchronized V get(K key) {
+ TimestampedValue value = map.get(key);
+
+ V result = null;
+ if (value != null) {
+ value.updateTimestamp();
+ result = value.getValue();
+ }
+
+ return result;
+ }
+
+ public synchronized void put(K key, V value) {
+ if (map.size() >= capacity) {
+ removeOldest();
+ }
+ map.put(key, new TimestampedValue(value));
+ }
+
+ public void clear() {
+ map.clear();
+ }
+
+ private void removeOldest() {
+ K oldestKey = null;
+ long oldestTimestamp = Long.MAX_VALUE;
+
+ for (Map.Entry<K, TimestampedValue> entry : map.entrySet()) {
+ K key = entry.getKey();
+ TimestampedValue value = entry.getValue();
+ if (value.getTimestamp() < oldestTimestamp) {
+ oldestTimestamp = value.getTimestamp();
+ oldestKey = key;
+ }
+ }
+
+ if (oldestKey != null) {
+ map.remove(oldestKey);
+ }
+ }
+
+ private final class TimestampedValue {
+
+ private final SoftReference<V> value;
+ private long timestamp;
+
+ public TimestampedValue(V value) {
+ this.value = new SoftReference<V>(value);
+ updateTimestamp();
+ }
+
+ public V getValue() {
+ return value.get();
+ }
+
+ public long getTimestamp() {
+ return timestamp;
+ }
+
+ public void updateTimestamp() {
+ timestamp = System.currentTimeMillis();
+ }
+ }
+
+} \ No newline at end of file
diff --git a/subsonic-android/src/net/sourceforge/subsonic/androidapp/util/MergeAdapter.java b/subsonic-android/src/net/sourceforge/subsonic/androidapp/util/MergeAdapter.java
new file mode 100644
index 00000000..97dbc125
--- /dev/null
+++ b/subsonic-android/src/net/sourceforge/subsonic/androidapp/util/MergeAdapter.java
@@ -0,0 +1,290 @@
+/***
+ Copyright (c) 2008-2009 CommonsWare, LLC
+ Portions (c) 2009 Google, Inc.
+
+ Licensed under the Apache License, Version 2.0 (the "License"); you may
+ not use this file except in compliance with the License. You may obtain
+ a copy of the License at
+ http://www.apache.org/licenses/LICENSE-2.0
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+ */
+
+package net.sourceforge.subsonic.androidapp.util;
+
+import android.database.DataSetObserver;
+import android.view.View;
+import android.view.ViewGroup;
+import android.widget.BaseAdapter;
+import android.widget.ListAdapter;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Arrays;
+
+/**
+ * Adapter that merges multiple child adapters and views
+ * into a single contiguous whole.
+ * <p/>
+ * Adapters used as pieces within MergeAdapter must
+ * have view type IDs monotonically increasing from 0. Ideally,
+ * adapters also have distinct ranges for their row ids, as
+ * returned by getItemId().
+ */
+public class MergeAdapter extends BaseAdapter {
+
+ private final CascadeDataSetObserver observer = new CascadeDataSetObserver();
+ private final ArrayList<ListAdapter> pieces = new ArrayList<ListAdapter>();
+
+ /**
+ * Stock constructor, simply chaining to the superclass.
+ */
+ public MergeAdapter() {
+ super();
+ }
+
+ /**
+ * Adds a new adapter to the roster of things to appear
+ * in the aggregate list.
+ *
+ * @param adapter Source for row views for this section
+ */
+ public void addAdapter(ListAdapter adapter) {
+ pieces.add(adapter);
+ adapter.registerDataSetObserver(observer);
+ }
+
+ public void removeAdapter(ListAdapter adapter) {
+ adapter.unregisterDataSetObserver(observer);
+ pieces.remove(adapter);
+ }
+
+ /**
+ * Adds a new View to the roster of things to appear
+ * in the aggregate list.
+ *
+ * @param view Single view to add
+ */
+ public ListAdapter addView(View view) {
+ return addView(view, false);
+ }
+
+ /**
+ * Adds a new View to the roster of things to appear
+ * in the aggregate list.
+ *
+ * @param view Single view to add
+ * @param enabled false if views are disabled, true if enabled
+ */
+ public ListAdapter addView(View view, boolean enabled) {
+ return addViews(Arrays.asList(view), enabled);
+ }
+
+ /**
+ * Adds a list of views to the roster of things to appear
+ * in the aggregate list.
+ *
+ * @param views List of views to add
+ */
+ public ListAdapter addViews(List<View> views) {
+ return addViews(views, false);
+ }
+
+ /**
+ * Adds a list of views to the roster of things to appear
+ * in the aggregate list.
+ *
+ * @param views List of views to add
+ * @param enabled false if views are disabled, true if enabled
+ */
+ public ListAdapter addViews(List<View> views, boolean enabled) {
+ ListAdapter adapter = enabled ? new EnabledSackAdapter(views) : new SackOfViewsAdapter(views);
+ addAdapter(adapter);
+ return adapter;
+ }
+
+ /**
+ * Get the data item associated with the specified
+ * position in the data set.
+ *
+ * @param position Position of the item whose data we want
+ */
+ @Override
+ public Object getItem(int position) {
+ for (ListAdapter piece : pieces) {
+ int size = piece.getCount();
+
+ if (position < size) {
+ return (piece.getItem(position));
+ }
+
+ position -= size;
+ }
+
+ return (null);
+ }
+
+ /**
+ * How many items are in the data set represented by this
+ * Adapter.
+ */
+ @Override
+ public int getCount() {
+ int total = 0;
+
+ for (ListAdapter piece : pieces) {
+ total += piece.getCount();
+ }
+
+ return (total);
+ }
+
+ /**
+ * Returns the number of types of Views that will be
+ * created by getView().
+ */
+ @Override
+ public int getViewTypeCount() {
+ int total = 0;
+
+ for (ListAdapter piece : pieces) {
+ total += piece.getViewTypeCount();
+ }
+
+ return (Math.max(total, 1)); // needed for setListAdapter() before content add'
+ }
+
+ /**
+ * Get the type of View that will be created by getView()
+ * for the specified item.
+ *
+ * @param position Position of the item whose data we want
+ */
+ @Override
+ public int getItemViewType(int position) {
+ int typeOffset = 0;
+ int result = -1;
+
+ for (ListAdapter piece : pieces) {
+ int size = piece.getCount();
+
+ if (position < size) {
+ result = typeOffset + piece.getItemViewType(position);
+ break;
+ }
+
+ position -= size;
+ typeOffset += piece.getViewTypeCount();
+ }
+
+ return (result);
+ }
+
+ /**
+ * Are all items in this ListAdapter enabled? If yes it
+ * means all items are selectable and clickable.
+ */
+ @Override
+ public boolean areAllItemsEnabled() {
+ return (false);
+ }
+
+ /**
+ * Returns true if the item at the specified position is
+ * not a separator.
+ *
+ * @param position Position of the item whose data we want
+ */
+ @Override
+ public boolean isEnabled(int position) {
+ for (ListAdapter piece : pieces) {
+ int size = piece.getCount();
+
+ if (position < size) {
+ return (piece.isEnabled(position));
+ }
+
+ position -= size;
+ }
+
+ return (false);
+ }
+
+ /**
+ * Get a View that displays the data at the specified
+ * position in the data set.
+ *
+ * @param position Position of the item whose data we want
+ * @param convertView View to recycle, if not null
+ * @param parent ViewGroup containing the returned View
+ */
+ @Override
+ public View getView(int position, View convertView,
+ ViewGroup parent) {
+ for (ListAdapter piece : pieces) {
+ int size = piece.getCount();
+
+ if (position < size) {
+
+ return (piece.getView(position, convertView, parent));
+ }
+
+ position -= size;
+ }
+
+ return (null);
+ }
+
+ /**
+ * Get the row id associated with the specified position
+ * in the list.
+ *
+ * @param position Position of the item whose data we want
+ */
+ @Override
+ public long getItemId(int position) {
+ for (ListAdapter piece : pieces) {
+ int size = piece.getCount();
+
+ if (position < size) {
+ return (piece.getItemId(position));
+ }
+
+ position -= size;
+ }
+
+ return (-1);
+ }
+
+ private static class EnabledSackAdapter extends SackOfViewsAdapter {
+ public EnabledSackAdapter(List<View> views) {
+ super(views);
+ }
+
+ @Override
+ public boolean areAllItemsEnabled() {
+ return (true);
+ }
+
+ @Override
+ public boolean isEnabled(int position) {
+ return (true);
+ }
+ }
+
+ private class CascadeDataSetObserver extends DataSetObserver {
+ @Override
+ public void onChanged() {
+ notifyDataSetChanged();
+ }
+
+ @Override
+ public void onInvalidated() {
+ notifyDataSetInvalidated();
+ }
+ }
+}
+
diff --git a/subsonic-android/src/net/sourceforge/subsonic/androidapp/util/ModalBackgroundTask.java b/subsonic-android/src/net/sourceforge/subsonic/androidapp/util/ModalBackgroundTask.java
new file mode 100644
index 00000000..15e2add2
--- /dev/null
+++ b/subsonic-android/src/net/sourceforge/subsonic/androidapp/util/ModalBackgroundTask.java
@@ -0,0 +1,139 @@
+/*
+ This file is part of Subsonic.
+
+ Subsonic is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ Subsonic is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with Subsonic. If not, see <http://www.gnu.org/licenses/>.
+
+ Copyright 2009 (C) Sindre Mehus
+ */
+package net.sourceforge.subsonic.androidapp.util;
+
+import android.app.Activity;
+import android.app.AlertDialog;
+import android.content.DialogInterface;
+import android.util.Log;
+import net.sourceforge.subsonic.androidapp.R;
+
+/**
+ * @author Sindre Mehus
+ */
+public abstract class ModalBackgroundTask<T> extends BackgroundTask<T> {
+
+ private static final String TAG = ModalBackgroundTask.class.getSimpleName();
+
+ private final AlertDialog progressDialog;
+ private Thread thread;
+ private final boolean finishActivityOnCancel;
+ private boolean cancelled;
+
+ public ModalBackgroundTask(Activity activity, boolean finishActivityOnCancel) {
+ super(activity);
+ this.finishActivityOnCancel = finishActivityOnCancel;
+ progressDialog = createProgressDialog();
+ }
+
+ public ModalBackgroundTask(Activity activity) {
+ this(activity, true);
+ }
+
+ private AlertDialog createProgressDialog() {
+ AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
+ builder.setIcon(android.R.drawable.ic_dialog_info);
+ builder.setTitle(R.string.background_task_wait);
+ builder.setMessage(R.string.background_task_loading);
+ builder.setCancelable(true);
+ builder.setOnCancelListener(new DialogInterface.OnCancelListener() {
+ @Override
+ public void onCancel(DialogInterface dialogInterface) {
+ cancel();
+ }
+ });
+ builder.setPositiveButton(R.string.common_cancel, new DialogInterface.OnClickListener() {
+ @Override
+ public void onClick(DialogInterface dialogInterface, int i) {
+ cancel();
+ }
+ });
+
+ return builder.create();
+ }
+
+ public void execute() {
+ cancelled = false;
+ progressDialog.show();
+
+ thread = new Thread() {
+ @Override
+ public void run() {
+ try {
+ final T result = doInBackground();
+ if (cancelled) {
+ progressDialog.dismiss();
+ return;
+ }
+
+ getHandler().post(new Runnable() {
+ @Override
+ public void run() {
+ progressDialog.dismiss();
+ done(result);
+ }
+ });
+
+ } catch (final Throwable t) {
+ if (cancelled) {
+ return;
+ }
+ getHandler().post(new Runnable() {
+ @Override
+ public void run() {
+ progressDialog.dismiss();
+ error(t);
+ }
+ });
+ }
+ }
+ };
+ thread.start();
+ }
+
+ protected void cancel() {
+ cancelled = true;
+ if (thread != null) {
+ thread.interrupt();
+ }
+
+ if (finishActivityOnCancel) {
+ getActivity().finish();
+ }
+ }
+
+ protected boolean isCancelled() {
+ return cancelled;
+ }
+
+ protected void error(Throwable error) {
+ Log.w(TAG, "Got exception: " + error, error);
+ new ErrorDialog(getActivity(), getErrorMessage(error), finishActivityOnCancel);
+ }
+
+ @Override
+ public void updateProgress(final String message) {
+ getHandler().post(new Runnable() {
+ @Override
+ public void run() {
+ progressDialog.setMessage(message);
+ }
+ });
+ }
+}
diff --git a/subsonic-android/src/net/sourceforge/subsonic/androidapp/util/MyViewFlipper.java b/subsonic-android/src/net/sourceforge/subsonic/androidapp/util/MyViewFlipper.java
new file mode 100644
index 00000000..94f217ff
--- /dev/null
+++ b/subsonic-android/src/net/sourceforge/subsonic/androidapp/util/MyViewFlipper.java
@@ -0,0 +1,53 @@
+/*
+ This file is part of Subsonic.
+
+ Subsonic is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ Subsonic is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with Subsonic. If not, see <http://www.gnu.org/licenses/>.
+
+ Copyright 2009 (C) Sindre Mehus
+ */
+package net.sourceforge.subsonic.androidapp.util;
+
+import android.content.Context;
+import android.util.AttributeSet;
+import android.widget.ViewFlipper;
+
+/**
+ * Work-around for Android Issue 6191 (http://code.google.com/p/android/issues/detail?id=6191)
+ *
+ * @author Sindre Mehus
+ * @version $Id$
+ */
+public class MyViewFlipper extends ViewFlipper {
+
+ public MyViewFlipper(Context context) {
+ super(context);
+ }
+
+ public MyViewFlipper(Context context, AttributeSet attrs) {
+ super(context, attrs);
+ }
+
+
+ @Override
+ protected void onDetachedFromWindow() {
+ try {
+ super.onDetachedFromWindow();
+ }
+ catch (IllegalArgumentException e) {
+ // Call stopFlipping() in order to kick off updateRunning()
+ stopFlipping();
+ }
+ }
+}
+
diff --git a/subsonic-android/src/net/sourceforge/subsonic/androidapp/util/Pair.java b/subsonic-android/src/net/sourceforge/subsonic/androidapp/util/Pair.java
new file mode 100644
index 00000000..73dc3224
--- /dev/null
+++ b/subsonic-android/src/net/sourceforge/subsonic/androidapp/util/Pair.java
@@ -0,0 +1,54 @@
+/*
+ This file is part of Subsonic.
+
+ Subsonic is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ Subsonic is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with Subsonic. If not, see <http://www.gnu.org/licenses/>.
+
+ Copyright 2009 (C) Sindre Mehus
+ */
+package net.sourceforge.subsonic.androidapp.util;
+
+import java.io.Serializable;
+
+/**
+ * @author Sindre Mehus
+ */
+public class Pair<S, T> implements Serializable {
+
+ private S first;
+ private T second;
+
+ public Pair() {
+ }
+
+ public Pair(S first, T second) {
+ this.first = first;
+ this.second = second;
+ }
+
+ public S getFirst() {
+ return first;
+ }
+
+ public void setFirst(S first) {
+ this.first = first;
+ }
+
+ public T getSecond() {
+ return second;
+ }
+
+ public void setSecond(T second) {
+ this.second = second;
+ }
+}
diff --git a/subsonic-android/src/net/sourceforge/subsonic/androidapp/util/PlaylistAdapter.java b/subsonic-android/src/net/sourceforge/subsonic/androidapp/util/PlaylistAdapter.java
new file mode 100644
index 00000000..16028c12
--- /dev/null
+++ b/subsonic-android/src/net/sourceforge/subsonic/androidapp/util/PlaylistAdapter.java
@@ -0,0 +1,99 @@
+/*
+ This file is part of Subsonic.
+
+ Subsonic is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ Subsonic is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with Subsonic. If not, see <http://www.gnu.org/licenses/>.
+
+ Copyright 2009 (C) Sindre Mehus
+ */
+package net.sourceforge.subsonic.androidapp.util;
+
+import android.content.Context;
+import android.widget.ArrayAdapter;
+import android.widget.SectionIndexer;
+import net.sourceforge.subsonic.androidapp.R;
+import net.sourceforge.subsonic.androidapp.domain.Playlist;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Comparator;
+import java.util.LinkedHashSet;
+import java.util.List;
+import java.util.Set;
+
+/**
+* @author Sindre Mehus
+* @version $Id$
+*/
+public class PlaylistAdapter extends ArrayAdapter<Playlist> implements SectionIndexer {
+
+ // Both arrays are indexed by section ID.
+ private final Object[] sections;
+ private final Integer[] positions;
+
+ /**
+ * Note: playlists must be sorted alphabetically.
+ */
+ public PlaylistAdapter(Context context, List<Playlist> playlists) {
+ super(context, R.layout.playlist_list_item, playlists);
+
+ Set<String> sectionSet = new LinkedHashSet<String>(30);
+ List<Integer> positionList = new ArrayList<Integer>(30);
+ for (int i = 0; i < playlists.size(); i++) {
+ Playlist playlist = playlists.get(i);
+ if (playlist.getName().length() > 0) {
+ String index = playlist.getName().substring(0, 1).toUpperCase();
+ if (!sectionSet.contains(index)) {
+ sectionSet.add(index);
+ positionList.add(i);
+ }
+ }
+ }
+ sections = sectionSet.toArray(new Object[sectionSet.size()]);
+ positions = positionList.toArray(new Integer[positionList.size()]);
+ }
+
+ @Override
+ public Object[] getSections() {
+ return sections;
+ }
+
+ @Override
+ public int getPositionForSection(int section) {
+ section = Math.min(section, positions.length - 1);
+ return positions[section];
+ }
+
+ @Override
+ public int getSectionForPosition(int pos) {
+ for (int i = 0; i < sections.length - 1; i++) {
+ if (pos < positions[i + 1]) {
+ return i;
+ }
+ }
+ return sections.length - 1;
+ }
+
+ public static class PlaylistComparator implements Comparator<Playlist> {
+ @Override
+ public int compare(Playlist playlist1, Playlist playlist2) {
+ return playlist1.getName().compareToIgnoreCase(playlist2.getName());
+ }
+
+ public static List<Playlist> sort(List<Playlist> playlists) {
+ Collections.sort(playlists, new PlaylistComparator());
+ return playlists;
+ }
+
+ }
+}
diff --git a/subsonic-android/src/net/sourceforge/subsonic/androidapp/util/ProgressListener.java b/subsonic-android/src/net/sourceforge/subsonic/androidapp/util/ProgressListener.java
new file mode 100644
index 00000000..0d2924f7
--- /dev/null
+++ b/subsonic-android/src/net/sourceforge/subsonic/androidapp/util/ProgressListener.java
@@ -0,0 +1,27 @@
+/*
+ This file is part of Subsonic.
+
+ Subsonic is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ Subsonic is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with Subsonic. If not, see <http://www.gnu.org/licenses/>.
+
+ Copyright 2009 (C) Sindre Mehus
+ */
+package net.sourceforge.subsonic.androidapp.util;
+
+/**
+ * @author Sindre Mehus
+ */
+public interface ProgressListener {
+ void updateProgress(String message);
+ void updateProgress(int messageId);
+}
diff --git a/subsonic-android/src/net/sourceforge/subsonic/androidapp/util/SackOfViewsAdapter.java b/subsonic-android/src/net/sourceforge/subsonic/androidapp/util/SackOfViewsAdapter.java
new file mode 100644
index 00000000..ca825e55
--- /dev/null
+++ b/subsonic-android/src/net/sourceforge/subsonic/androidapp/util/SackOfViewsAdapter.java
@@ -0,0 +1,181 @@
+/***
+ Copyright (c) 2008-2009 CommonsWare, LLC
+ Portions (c) 2009 Google, Inc.
+
+ Licensed under the Apache License, Version 2.0 (the "License"); you may
+ not use this file except in compliance with the License. You may obtain
+ a copy of the License at
+ http://www.apache.org/licenses/LICENSE-2.0
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+ */
+package net.sourceforge.subsonic.androidapp.util;
+
+import android.view.View;
+import android.view.ViewGroup;
+import android.widget.BaseAdapter;
+import android.widget.ListView;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * Adapter that simply returns row views from a list.
+ * <p/>
+ * If you supply a size, you must implement newView(), to
+ * create a required view. The adapter will then cache these
+ * views.
+ * <p/>
+ * If you supply a list of views in the constructor, that
+ * list will be used directly. If any elements in the list
+ * are null, then newView() will be called just for those
+ * slots.
+ * <p/>
+ * Subclasses may also wish to override areAllItemsEnabled()
+ * (default: false) and isEnabled() (default: false), if some
+ * of their rows should be selectable.
+ * <p/>
+ * It is assumed each view is unique, and therefore will not
+ * get recycled.
+ * <p/>
+ * Note that this adapter is not designed for long lists. It
+ * is more for screens that should behave like a list. This
+ * is particularly useful if you combine this with other
+ * adapters (e.g., SectionedAdapter) that might have an
+ * arbitrary number of rows, so it all appears seamless.
+ */
+public class SackOfViewsAdapter extends BaseAdapter {
+ private List<View> views = null;
+
+ /**
+ * Constructor creating an empty list of views, but with
+ * a specified count. Subclasses must override newView().
+ */
+ public SackOfViewsAdapter(int count) {
+ super();
+
+ views = new ArrayList<View>(count);
+
+ for (int i = 0; i < count; i++) {
+ views.add(null);
+ }
+ }
+
+ /**
+ * Constructor wrapping a supplied list of views.
+ * Subclasses must override newView() if any of the elements
+ * in the list are null.
+ */
+ public SackOfViewsAdapter(List<View> views) {
+ for (View view : views) {
+ view.setLayoutParams(new ListView.LayoutParams(ViewGroup.LayoutParams.FILL_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT));
+ }
+ this.views = views;
+ }
+
+ /**
+ * Get the data item associated with the specified
+ * position in the data set.
+ *
+ * @param position Position of the item whose data we want
+ */
+ @Override
+ public Object getItem(int position) {
+ return (views.get(position));
+ }
+
+ /**
+ * How many items are in the data set represented by this
+ * Adapter.
+ */
+ @Override
+ public int getCount() {
+ return (views.size());
+ }
+
+ /**
+ * Returns the number of types of Views that will be
+ * created by getView().
+ */
+ @Override
+ public int getViewTypeCount() {
+ return (getCount());
+ }
+
+ /**
+ * Get the type of View that will be created by getView()
+ * for the specified item.
+ *
+ * @param position Position of the item whose data we want
+ */
+ @Override
+ public int getItemViewType(int position) {
+ return (position);
+ }
+
+ /**
+ * Are all items in this ListAdapter enabled? If yes it
+ * means all items are selectable and clickable.
+ */
+ @Override
+ public boolean areAllItemsEnabled() {
+ return (false);
+ }
+
+ /**
+ * Returns true if the item at the specified position is
+ * not a separator.
+ *
+ * @param position Position of the item whose data we want
+ */
+ @Override
+ public boolean isEnabled(int position) {
+ return (false);
+ }
+
+ /**
+ * Get a View that displays the data at the specified
+ * position in the data set.
+ *
+ * @param position Position of the item whose data we want
+ * @param convertView View to recycle, if not null
+ * @param parent ViewGroup containing the returned View
+ */
+ @Override
+ public View getView(int position, View convertView,
+ ViewGroup parent) {
+ View result = views.get(position);
+
+ if (result == null) {
+ result = newView(position, parent);
+ views.set(position, result);
+ }
+
+ return (result);
+ }
+
+ /**
+ * Get the row id associated with the specified position
+ * in the list.
+ *
+ * @param position Position of the item whose data we want
+ */
+ @Override
+ public long getItemId(int position) {
+ return (position);
+ }
+
+ /**
+ * Create a new View to go into the list at the specified
+ * position.
+ *
+ * @param position Position of the item whose data we want
+ * @param parent ViewGroup containing the returned View
+ */
+ protected View newView(int position, ViewGroup parent) {
+ throw new RuntimeException("You must override newView()!");
+ }
+}
diff --git a/subsonic-android/src/net/sourceforge/subsonic/androidapp/util/ShufflePlayBuffer.java b/subsonic-android/src/net/sourceforge/subsonic/androidapp/util/ShufflePlayBuffer.java
new file mode 100644
index 00000000..825fcc44
--- /dev/null
+++ b/subsonic-android/src/net/sourceforge/subsonic/androidapp/util/ShufflePlayBuffer.java
@@ -0,0 +1,109 @@
+/*
+ This file is part of Subsonic.
+
+ Subsonic is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ Subsonic is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with Subsonic. If not, see <http://www.gnu.org/licenses/>.
+
+ Copyright 2009 (C) Sindre Mehus
+ */
+package net.sourceforge.subsonic.androidapp.util;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.concurrent.Executors;
+import java.util.concurrent.ScheduledExecutorService;
+import java.util.concurrent.TimeUnit;
+
+import android.content.Context;
+import android.util.Log;
+import net.sourceforge.subsonic.androidapp.domain.MusicDirectory;
+import net.sourceforge.subsonic.androidapp.service.MusicService;
+import net.sourceforge.subsonic.androidapp.service.MusicServiceFactory;
+
+/**
+ * @author Sindre Mehus
+ * @version $Id$
+ */
+public class ShufflePlayBuffer {
+
+ private static final String TAG = ShufflePlayBuffer.class.getSimpleName();
+ private static final int CAPACITY = 50;
+ private static final int REFILL_THRESHOLD = 40;
+
+ private final ScheduledExecutorService executorService;
+ private final List<MusicDirectory.Entry> buffer = new ArrayList<MusicDirectory.Entry>();
+ private Context context;
+ private int currentServer;
+
+ public ShufflePlayBuffer(Context context) {
+ this.context = context;
+ executorService = Executors.newSingleThreadScheduledExecutor();
+ Runnable runnable = new Runnable() {
+ @Override
+ public void run() {
+ refill();
+ }
+ };
+ executorService.scheduleWithFixedDelay(runnable, 1, 10, TimeUnit.SECONDS);
+ }
+
+ public List<MusicDirectory.Entry> get(int size) {
+ clearBufferIfnecessary();
+
+ List<MusicDirectory.Entry> result = new ArrayList<MusicDirectory.Entry>(size);
+ synchronized (buffer) {
+ while (!buffer.isEmpty() && result.size() < size) {
+ result.add(buffer.remove(buffer.size() - 1));
+ }
+ }
+ Log.i(TAG, "Taking " + result.size() + " songs from shuffle play buffer. " + buffer.size() + " remaining.");
+ return result;
+ }
+
+ public void shutdown() {
+ executorService.shutdown();
+ }
+
+ private void refill() {
+
+ // Check if active server has changed.
+ clearBufferIfnecessary();
+
+ if (buffer.size() > REFILL_THRESHOLD || (!Util.isNetworkConnected(context) && !Util.isOffline(context))) {
+ return;
+ }
+
+ try {
+ MusicService service = MusicServiceFactory.getMusicService(context);
+ int n = CAPACITY - buffer.size();
+ MusicDirectory songs = service.getRandomSongs(n, context, null);
+
+ synchronized (buffer) {
+ buffer.addAll(songs.getChildren());
+ Log.i(TAG, "Refilled shuffle play buffer with " + songs.getChildren().size() + " songs.");
+ }
+ } catch (Exception x) {
+ Log.w(TAG, "Failed to refill shuffle play buffer.", x);
+ }
+ }
+
+ private void clearBufferIfnecessary() {
+ synchronized (buffer) {
+ if (currentServer != Util.getActiveServer(context)) {
+ currentServer = Util.getActiveServer(context);
+ buffer.clear();
+ }
+ }
+ }
+
+}
diff --git a/subsonic-android/src/net/sourceforge/subsonic/androidapp/util/SilentBackgroundTask.java b/subsonic-android/src/net/sourceforge/subsonic/androidapp/util/SilentBackgroundTask.java
new file mode 100644
index 00000000..7aa85d7c
--- /dev/null
+++ b/subsonic-android/src/net/sourceforge/subsonic/androidapp/util/SilentBackgroundTask.java
@@ -0,0 +1,67 @@
+/*
+ This file is part of Subsonic.
+
+ Subsonic is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ Subsonic is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with Subsonic. If not, see <http://www.gnu.org/licenses/>.
+
+ Copyright 2010 (C) Sindre Mehus
+ */
+package net.sourceforge.subsonic.androidapp.util;
+
+import android.app.Activity;
+
+/**
+ * @author Sindre Mehus
+ */
+public abstract class SilentBackgroundTask<T> extends BackgroundTask<T> {
+
+ public SilentBackgroundTask(Activity activity) {
+ super(activity);
+ }
+
+ @Override
+ public void execute() {
+ Thread thread = new Thread() {
+ @Override
+ public void run() {
+ try {
+ final T result = doInBackground();
+
+ getHandler().post(new Runnable() {
+ @Override
+ public void run() {
+ done(result);
+ }
+ });
+
+ } catch (final Throwable t) {
+ getHandler().post(new Runnable() {
+ @Override
+ public void run() {
+ error(t);
+ }
+ });
+ }
+ }
+ };
+ thread.start();
+ }
+
+ @Override
+ public void updateProgress(int messageId) {
+ }
+
+ @Override
+ public void updateProgress(String message) {
+ }
+}
diff --git a/subsonic-android/src/net/sourceforge/subsonic/androidapp/util/SimpleServiceBinder.java b/subsonic-android/src/net/sourceforge/subsonic/androidapp/util/SimpleServiceBinder.java
new file mode 100644
index 00000000..9ddf9903
--- /dev/null
+++ b/subsonic-android/src/net/sourceforge/subsonic/androidapp/util/SimpleServiceBinder.java
@@ -0,0 +1,37 @@
+/*
+ This file is part of Subsonic.
+
+ Subsonic is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ Subsonic is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with Subsonic. If not, see <http://www.gnu.org/licenses/>.
+
+ Copyright 2009 (C) Sindre Mehus
+ */
+package net.sourceforge.subsonic.androidapp.util;
+
+import android.os.Binder;
+
+/**
+ * @author Sindre Mehus
+ */
+public class SimpleServiceBinder<S> extends Binder {
+
+ private final S service;
+
+ public SimpleServiceBinder(S service) {
+ this.service = service;
+ }
+
+ public S getService() {
+ return service;
+ }
+}
diff --git a/subsonic-android/src/net/sourceforge/subsonic/androidapp/util/SongView.java b/subsonic-android/src/net/sourceforge/subsonic/androidapp/util/SongView.java
new file mode 100644
index 00000000..22902a11
--- /dev/null
+++ b/subsonic-android/src/net/sourceforge/subsonic/androidapp/util/SongView.java
@@ -0,0 +1,178 @@
+/*
+ This file is part of Subsonic.
+
+ Subsonic is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ Subsonic is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with Subsonic. If not, see <http://www.gnu.org/licenses/>.
+
+ Copyright 2009 (C) Sindre Mehus
+ */
+package net.sourceforge.subsonic.androidapp.util;
+
+import android.content.Context;
+import android.os.Handler;
+import android.util.Log;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.widget.Checkable;
+import android.widget.CheckedTextView;
+import android.widget.LinearLayout;
+import android.widget.TextView;
+import net.sourceforge.subsonic.androidapp.R;
+import net.sourceforge.subsonic.androidapp.domain.MusicDirectory;
+import net.sourceforge.subsonic.androidapp.service.DownloadService;
+import net.sourceforge.subsonic.androidapp.service.DownloadServiceImpl;
+import net.sourceforge.subsonic.androidapp.service.DownloadFile;
+
+import java.io.File;
+import java.util.WeakHashMap;
+
+/**
+ * Used to display songs in a {@code ListView}.
+ *
+ * @author Sindre Mehus
+ */
+public class SongView extends LinearLayout implements Checkable {
+
+ private static final String TAG = SongView.class.getSimpleName();
+ private static final WeakHashMap<SongView, ?> INSTANCES = new WeakHashMap<SongView, Object>();
+ private static Handler handler;
+
+ private CheckedTextView checkedTextView;
+ private TextView titleTextView;
+ private TextView artistTextView;
+ private TextView durationTextView;
+ private TextView statusTextView;
+ private MusicDirectory.Entry song;
+
+ public SongView(Context context) {
+ super(context);
+ LayoutInflater.from(context).inflate(R.layout.song_list_item, this, true);
+
+ checkedTextView = (CheckedTextView) findViewById(R.id.song_check);
+ titleTextView = (TextView) findViewById(R.id.song_title);
+ artistTextView = (TextView) findViewById(R.id.song_artist);
+ durationTextView = (TextView) findViewById(R.id.song_duration);
+ statusTextView = (TextView) findViewById(R.id.song_status);
+
+ INSTANCES.put(this, null);
+ int instanceCount = INSTANCES.size();
+ if (instanceCount > 50) {
+ Log.w(TAG, instanceCount + " live SongView instances");
+ }
+ startUpdater();
+ }
+
+ public void setSong(MusicDirectory.Entry song, boolean checkable) {
+ this.song = song;
+ StringBuilder artist = new StringBuilder(40);
+
+ String bitRate = null;
+ if (song.getBitRate() != null) {
+ bitRate = String.format(getContext().getString(R.string.song_details_kbps), song.getBitRate());
+ }
+
+ String fileFormat = null;
+ if (song.getTranscodedSuffix() != null && !song.getTranscodedSuffix().equals(song.getSuffix())) {
+ fileFormat = String.format("%s > %s", song.getSuffix(), song.getTranscodedSuffix());
+ } else {
+ fileFormat = song.getSuffix();
+ }
+
+ artist.append(song.getArtist()).append(" (")
+ .append(String.format(getContext().getString(R.string.song_details_all), bitRate == null ? "" : bitRate, fileFormat))
+ .append(")");
+
+ titleTextView.setText(song.getTitle());
+ artistTextView.setText(artist);
+ durationTextView.setText(Util.formatDuration(song.getDuration()));
+ checkedTextView.setVisibility(checkable && !song.isVideo() ? View.VISIBLE : View.GONE);
+
+ update();
+ }
+
+ private void update() {
+ DownloadService downloadService = DownloadServiceImpl.getInstance();
+ if (downloadService == null) {
+ return;
+ }
+
+ DownloadFile downloadFile = downloadService.forSong(song);
+ File completeFile = downloadFile.getCompleteFile();
+ File partialFile = downloadFile.getPartialFile();
+
+ int leftImage = 0;
+ int rightImage = 0;
+
+ if (completeFile.exists()) {
+ leftImage = downloadFile.isSaved() ? R.drawable.saved : R.drawable.downloaded;
+ }
+
+ if (downloadFile.isDownloading() && !downloadFile.isDownloadCancelled() && partialFile.exists()) {
+ statusTextView.setText(Util.formatLocalizedBytes(partialFile.length(), getContext()));
+ rightImage = R.drawable.downloading;
+ } else {
+ statusTextView.setText(null);
+ }
+ statusTextView.setCompoundDrawablesWithIntrinsicBounds(leftImage, 0, rightImage, 0);
+
+ boolean playing = downloadService.getCurrentPlaying() == downloadFile;
+ if (playing) {
+ titleTextView.setCompoundDrawablesWithIntrinsicBounds(R.drawable.stat_notify_playing, 0, 0, 0);
+ } else {
+ titleTextView.setCompoundDrawablesWithIntrinsicBounds(0, 0, 0, 0);
+ }
+ }
+
+ private static synchronized void startUpdater() {
+ if (handler != null) {
+ return;
+ }
+
+ handler = new Handler();
+ Runnable runnable = new Runnable() {
+ @Override
+ public void run() {
+ updateAll();
+ handler.postDelayed(this, 1000L);
+ }
+ };
+ handler.postDelayed(runnable, 1000L);
+ }
+
+ private static void updateAll() {
+ try {
+ for (SongView view : INSTANCES.keySet()) {
+ if (view.isShown()) {
+ view.update();
+ }
+ }
+ } catch (Throwable x) {
+ Log.w(TAG, "Error when updating song views.", x);
+ }
+ }
+
+ @Override
+ public void setChecked(boolean b) {
+ checkedTextView.setChecked(b);
+ }
+
+ @Override
+ public boolean isChecked() {
+ return checkedTextView.isChecked();
+ }
+
+ @Override
+ public void toggle() {
+ checkedTextView.toggle();
+ }
+}
diff --git a/subsonic-android/src/net/sourceforge/subsonic/androidapp/util/TabActivityBackgroundTask.java b/subsonic-android/src/net/sourceforge/subsonic/androidapp/util/TabActivityBackgroundTask.java
new file mode 100644
index 00000000..033a51ad
--- /dev/null
+++ b/subsonic-android/src/net/sourceforge/subsonic/androidapp/util/TabActivityBackgroundTask.java
@@ -0,0 +1,67 @@
+package net.sourceforge.subsonic.androidapp.util;
+
+import net.sourceforge.subsonic.androidapp.activity.SubsonicTabActivity;
+
+/**
+ * @author Sindre Mehus
+ * @version $Id$
+ */
+public abstract class TabActivityBackgroundTask<T> extends BackgroundTask<T> {
+
+ private final SubsonicTabActivity tabActivity;
+
+ public TabActivityBackgroundTask(SubsonicTabActivity activity) {
+ super(activity);
+ tabActivity = activity;
+ }
+
+ @Override
+ public void execute() {
+ tabActivity.setProgressVisible(true);
+
+ new Thread() {
+ @Override
+ public void run() {
+ try {
+ final T result = doInBackground();
+ if (isCancelled()) {
+ return;
+ }
+
+ getHandler().post(new Runnable() {
+ @Override
+ public void run() {
+ tabActivity.setProgressVisible(false);
+ done(result);
+ }
+ });
+ } catch (final Throwable t) {
+ if (isCancelled()) {
+ return;
+ }
+ getHandler().post(new Runnable() {
+ @Override
+ public void run() {
+ tabActivity.setProgressVisible(false);
+ error(t);
+ }
+ });
+ }
+ }
+ }.start();
+ }
+
+ private boolean isCancelled() {
+ return tabActivity.isDestroyed();
+ }
+
+ @Override
+ public void updateProgress(final String message) {
+ getHandler().post(new Runnable() {
+ @Override
+ public void run() {
+ tabActivity.updateProgress(message);
+ }
+ });
+ }
+}
diff --git a/subsonic-android/src/net/sourceforge/subsonic/androidapp/util/TimeLimitedCache.java b/subsonic-android/src/net/sourceforge/subsonic/androidapp/util/TimeLimitedCache.java
new file mode 100644
index 00000000..5df5901e
--- /dev/null
+++ b/subsonic-android/src/net/sourceforge/subsonic/androidapp/util/TimeLimitedCache.java
@@ -0,0 +1,55 @@
+/*
+ This file is part of Subsonic.
+
+ Subsonic is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ Subsonic is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with Subsonic. If not, see <http://www.gnu.org/licenses/>.
+
+ Copyright 2009 (C) Sindre Mehus
+ */
+package net.sourceforge.subsonic.androidapp.util;
+
+import java.lang.ref.SoftReference;
+import java.util.concurrent.TimeUnit;
+
+/**
+ * @author Sindre Mehus
+ * @version $Id$
+ */
+public class TimeLimitedCache<T> {
+
+ private SoftReference<T> value;
+ private final long ttlMillis;
+ private long expires;
+
+ public TimeLimitedCache(long ttl, TimeUnit timeUnit) {
+ this.ttlMillis = TimeUnit.MILLISECONDS.convert(ttl, timeUnit);
+ }
+
+ public T get() {
+ return System.currentTimeMillis() < expires ? value.get() : null;
+ }
+
+ public void set(T value) {
+ set(value, ttlMillis, TimeUnit.MILLISECONDS);
+ }
+
+ public void set(T value, long ttl, TimeUnit timeUnit) {
+ this.value = new SoftReference<T>(value);
+ expires = System.currentTimeMillis() + timeUnit.toMillis(ttl);
+ }
+
+ public void clear() {
+ expires = 0L;
+ value = null;
+ }
+}
diff --git a/subsonic-android/src/net/sourceforge/subsonic/androidapp/util/Util.java b/subsonic-android/src/net/sourceforge/subsonic/androidapp/util/Util.java
new file mode 100644
index 00000000..9a8c692d
--- /dev/null
+++ b/subsonic-android/src/net/sourceforge/subsonic/androidapp/util/Util.java
@@ -0,0 +1,829 @@
+/*
+ This file is part of Subsonic.
+
+ Subsonic is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ Subsonic is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with Subsonic. If not, see <http://www.gnu.org/licenses/>.
+
+ Copyright 2009 (C) Sindre Mehus
+ */
+package net.sourceforge.subsonic.androidapp.util;
+
+import android.app.Activity;
+import android.app.AlertDialog;
+import android.app.Notification;
+import android.app.NotificationManager;
+import android.app.PendingIntent;
+import android.app.Service;
+import android.content.ComponentName;
+import android.content.Context;
+import android.content.DialogInterface;
+import android.content.Intent;
+import android.content.SharedPreferences;
+import android.content.res.Resources;
+import android.graphics.Bitmap;
+import android.graphics.drawable.BitmapDrawable;
+import android.graphics.drawable.Drawable;
+import android.media.AudioManager;
+import android.net.ConnectivityManager;
+import android.net.NetworkInfo;
+import android.os.Environment;
+import android.os.Handler;
+import android.util.Log;
+import android.view.Gravity;
+import android.view.ViewGroup;
+import android.widget.LinearLayout;
+import android.widget.RemoteViews;
+import android.widget.TextView;
+import android.widget.Toast;
+import net.sourceforge.subsonic.androidapp.R;
+import net.sourceforge.subsonic.androidapp.activity.DownloadActivity;
+import net.sourceforge.subsonic.androidapp.domain.MusicDirectory;
+import net.sourceforge.subsonic.androidapp.domain.PlayerState;
+import net.sourceforge.subsonic.androidapp.domain.RepeatMode;
+import net.sourceforge.subsonic.androidapp.domain.Version;
+import net.sourceforge.subsonic.androidapp.provider.SubsonicAppWidgetProvider;
+import net.sourceforge.subsonic.androidapp.receiver.MediaButtonIntentReceiver;
+import net.sourceforge.subsonic.androidapp.service.DownloadServiceImpl;
+import org.apache.http.HttpEntity;
+
+import java.io.ByteArrayOutputStream;
+import java.io.Closeable;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.io.UnsupportedEncodingException;
+import java.lang.reflect.Constructor;
+import java.lang.reflect.Method;
+import java.security.MessageDigest;
+import java.text.DecimalFormat;
+import java.text.NumberFormat;
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+
+/**
+ * @author Sindre Mehus
+ * @version $Id$
+ */
+public final class Util {
+
+ private static final String TAG = Util.class.getSimpleName();
+
+ private static final DecimalFormat GIGA_BYTE_FORMAT = new DecimalFormat("0.00 GB");
+ private static final DecimalFormat MEGA_BYTE_FORMAT = new DecimalFormat("0.00 MB");
+ private static final DecimalFormat KILO_BYTE_FORMAT = new DecimalFormat("0 KB");
+
+ private static DecimalFormat GIGA_BYTE_LOCALIZED_FORMAT = null;
+ private static DecimalFormat MEGA_BYTE_LOCALIZED_FORMAT = null;
+ private static DecimalFormat KILO_BYTE_LOCALIZED_FORMAT = null;
+ private static DecimalFormat BYTE_LOCALIZED_FORMAT = null;
+
+ public static final String EVENT_META_CHANGED = "net.sourceforge.subsonic.androidapp.EVENT_META_CHANGED";
+ public static final String EVENT_PLAYSTATE_CHANGED = "net.sourceforge.subsonic.androidapp.EVENT_PLAYSTATE_CHANGED";
+
+ private static final Map<Integer, Version> SERVER_REST_VERSIONS = new ConcurrentHashMap<Integer, Version>();
+
+ // Used by hexEncode()
+ private static final char[] HEX_DIGITS = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f'};
+
+ private final static Pair<Integer, Integer> NOTIFICATION_TEXT_COLORS = new Pair<Integer, Integer>();
+ private static Toast toast;
+
+ private Util() {
+ }
+
+ public static boolean isOffline(Context context) {
+ return getActiveServer(context) == 0;
+ }
+
+ public static boolean isScreenLitOnDownload(Context context) {
+ SharedPreferences prefs = getPreferences(context);
+ return prefs.getBoolean(Constants.PREFERENCES_KEY_SCREEN_LIT_ON_DOWNLOAD, false);
+ }
+
+ public static RepeatMode getRepeatMode(Context context) {
+ SharedPreferences prefs = getPreferences(context);
+ return RepeatMode.valueOf(prefs.getString(Constants.PREFERENCES_KEY_REPEAT_MODE, RepeatMode.OFF.name()));
+ }
+
+ public static void setRepeatMode(Context context, RepeatMode repeatMode) {
+ SharedPreferences prefs = getPreferences(context);
+ SharedPreferences.Editor editor = prefs.edit();
+ editor.putString(Constants.PREFERENCES_KEY_REPEAT_MODE, repeatMode.name());
+ editor.commit();
+ }
+
+ public static boolean isScrobblingEnabled(Context context) {
+ if (isOffline(context)) {
+ return false;
+ }
+ SharedPreferences prefs = getPreferences(context);
+ return prefs.getBoolean(Constants.PREFERENCES_KEY_SCROBBLE, false);
+ }
+
+ public static void setActiveServer(Context context, int instance) {
+ SharedPreferences prefs = getPreferences(context);
+ SharedPreferences.Editor editor = prefs.edit();
+ editor.putInt(Constants.PREFERENCES_KEY_SERVER_INSTANCE, instance);
+ editor.commit();
+ }
+
+ public static int getActiveServer(Context context) {
+ SharedPreferences prefs = getPreferences(context);
+ return prefs.getInt(Constants.PREFERENCES_KEY_SERVER_INSTANCE, 1);
+ }
+
+ public static String getServerName(Context context, int instance) {
+ if (instance == 0) {
+ return context.getResources().getString(R.string.main_offline);
+ }
+ SharedPreferences prefs = getPreferences(context);
+ return prefs.getString(Constants.PREFERENCES_KEY_SERVER_NAME + instance, null);
+ }
+
+ public static void setServerRestVersion(Context context, Version version) {
+ SERVER_REST_VERSIONS.put(getActiveServer(context), version);
+ }
+
+ public static Version getServerRestVersion(Context context) {
+ return SERVER_REST_VERSIONS.get(getActiveServer(context));
+ }
+
+ public static void setSelectedMusicFolderId(Context context, String musicFolderId) {
+ int instance = getActiveServer(context);
+ SharedPreferences prefs = getPreferences(context);
+ SharedPreferences.Editor editor = prefs.edit();
+ editor.putString(Constants.PREFERENCES_KEY_MUSIC_FOLDER_ID + instance, musicFolderId);
+ editor.commit();
+ }
+
+ public static String getSelectedMusicFolderId(Context context) {
+ SharedPreferences prefs = getPreferences(context);
+ int instance = getActiveServer(context);
+ return prefs.getString(Constants.PREFERENCES_KEY_MUSIC_FOLDER_ID + instance, null);
+ }
+
+ public static String getTheme(Context context) {
+ SharedPreferences prefs = getPreferences(context);
+ return prefs.getString(Constants.PREFERENCES_KEY_THEME, null);
+ }
+
+ public static int getMaxBitrate(Context context) {
+ ConnectivityManager manager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
+ NetworkInfo networkInfo = manager.getActiveNetworkInfo();
+ if (networkInfo == null) {
+ return 0;
+ }
+
+ boolean wifi = networkInfo.getType() == ConnectivityManager.TYPE_WIFI;
+ SharedPreferences prefs = getPreferences(context);
+ return Integer.parseInt(prefs.getString(wifi ? Constants.PREFERENCES_KEY_MAX_BITRATE_WIFI : Constants.PREFERENCES_KEY_MAX_BITRATE_MOBILE, "0"));
+ }
+
+ public static int getPreloadCount(Context context) {
+ SharedPreferences prefs = getPreferences(context);
+ int preloadCount = Integer.parseInt(prefs.getString(Constants.PREFERENCES_KEY_PRELOAD_COUNT, "-1"));
+ return preloadCount == -1 ? Integer.MAX_VALUE : preloadCount;
+ }
+
+ public static int getCacheSizeMB(Context context) {
+ SharedPreferences prefs = getPreferences(context);
+ int cacheSize = Integer.parseInt(prefs.getString(Constants.PREFERENCES_KEY_CACHE_SIZE, "-1"));
+ return cacheSize == -1 ? Integer.MAX_VALUE : cacheSize;
+ }
+
+ public static String getRestUrl(Context context, String method) {
+ StringBuilder builder = new StringBuilder();
+
+ SharedPreferences prefs = getPreferences(context);
+
+ int instance = prefs.getInt(Constants.PREFERENCES_KEY_SERVER_INSTANCE, 1);
+ String serverUrl = prefs.getString(Constants.PREFERENCES_KEY_SERVER_URL + instance, null);
+ String username = prefs.getString(Constants.PREFERENCES_KEY_USERNAME + instance, null);
+ String password = prefs.getString(Constants.PREFERENCES_KEY_PASSWORD + instance, null);
+
+ // Slightly obfuscate password
+ password = "enc:" + Util.utf8HexEncode(password);
+
+ builder.append(serverUrl);
+ if (builder.charAt(builder.length() - 1) != '/') {
+ builder.append("/");
+ }
+ builder.append("rest/").append(method).append(".view");
+ builder.append("?u=").append(username);
+ builder.append("&p=").append(password);
+ builder.append("&v=").append(Constants.REST_PROTOCOL_VERSION);
+ builder.append("&c=").append(Constants.REST_CLIENT_ID);
+
+ return builder.toString();
+ }
+
+ public static SharedPreferences getPreferences(Context context) {
+ return context.getSharedPreferences(Constants.PREFERENCES_FILE_NAME, 0);
+ }
+
+ public static String getContentType(HttpEntity entity) {
+ if (entity == null || entity.getContentType() == null) {
+ return null;
+ }
+ return entity.getContentType().getValue();
+ }
+
+ public static int getRemainingTrialDays(Context context) {
+ SharedPreferences prefs = getPreferences(context);
+ long installTime = prefs.getLong(Constants.PREFERENCES_KEY_INSTALL_TIME, 0L);
+
+ if (installTime == 0L) {
+ installTime = System.currentTimeMillis();
+ SharedPreferences.Editor editor = prefs.edit();
+ editor.putLong(Constants.PREFERENCES_KEY_INSTALL_TIME, installTime);
+ editor.commit();
+ }
+
+ long now = System.currentTimeMillis();
+ long millisPerDay = 24L * 60L * 60L * 1000L;
+ int daysSinceInstall = (int) ((now - installTime) / millisPerDay);
+ return Math.max(0, Constants.FREE_TRIAL_DAYS - daysSinceInstall);
+ }
+
+ /**
+ * Get the contents of an <code>InputStream</code> as a <code>byte[]</code>.
+ * <p/>
+ * This method buffers the input internally, so there is no need to use a
+ * <code>BufferedInputStream</code>.
+ *
+ * @param input the <code>InputStream</code> to read from
+ * @return the requested byte array
+ * @throws NullPointerException if the input is null
+ * @throws IOException if an I/O error occurs
+ */
+ public static byte[] toByteArray(InputStream input) throws IOException {
+ ByteArrayOutputStream output = new ByteArrayOutputStream();
+ copy(input, output);
+ return output.toByteArray();
+ }
+
+ public static long copy(InputStream input, OutputStream output)
+ throws IOException {
+ byte[] buffer = new byte[1024 * 4];
+ long count = 0;
+ int n;
+ while (-1 != (n = input.read(buffer))) {
+ output.write(buffer, 0, n);
+ count += n;
+ }
+ return count;
+ }
+
+ public static void atomicCopy(File from, File to) throws IOException {
+ FileInputStream in = null;
+ FileOutputStream out = null;
+ File tmp = null;
+ try {
+ tmp = new File(to.getPath() + ".tmp");
+ in = new FileInputStream(from);
+ out = new FileOutputStream(tmp);
+ in.getChannel().transferTo(0, from.length(), out.getChannel());
+ out.close();
+ if (!tmp.renameTo(to)) {
+ throw new IOException("Failed to rename " + tmp + " to " + to);
+ }
+ Log.i(TAG, "Copied " + from + " to " + to);
+ } catch (IOException x) {
+ close(out);
+ delete(to);
+ throw x;
+ } finally {
+ close(in);
+ close(out);
+ delete(tmp);
+ }
+ }
+
+ public static void close(Closeable closeable) {
+ try {
+ if (closeable != null) {
+ closeable.close();
+ }
+ } catch (Throwable x) {
+ // Ignored
+ }
+ }
+
+ public static boolean delete(File file) {
+ if (file != null && file.exists()) {
+ if (!file.delete()) {
+ Log.w(TAG, "Failed to delete file " + file);
+ return false;
+ }
+ Log.i(TAG, "Deleted file " + file);
+ }
+ return true;
+ }
+
+ public static void toast(Context context, int messageId) {
+ toast(context, messageId, true);
+ }
+
+ public static void toast(Context context, int messageId, boolean shortDuration) {
+ toast(context, context.getString(messageId), shortDuration);
+ }
+
+ public static void toast(Context context, String message) {
+ toast(context, message, true);
+ }
+
+ public static void toast(Context context, String message, boolean shortDuration) {
+ if (toast == null) {
+ toast = Toast.makeText(context, message, shortDuration ? Toast.LENGTH_SHORT : Toast.LENGTH_LONG);
+ toast.setGravity(Gravity.CENTER, 0, 0);
+ } else {
+ toast.setText(message);
+ toast.setDuration(shortDuration ? Toast.LENGTH_SHORT : Toast.LENGTH_LONG);
+ }
+ toast.show();
+ }
+
+ /**
+ * Converts a byte-count to a formatted string suitable for display to the user.
+ * For instance:
+ * <ul>
+ * <li><code>format(918)</code> returns <em>"918 B"</em>.</li>
+ * <li><code>format(98765)</code> returns <em>"96 KB"</em>.</li>
+ * <li><code>format(1238476)</code> returns <em>"1.2 MB"</em>.</li>
+ * </ul>
+ * This method assumes that 1 KB is 1024 bytes.
+ * To get a localized string, please use formatLocalizedBytes instead.
+ *
+ * @param byteCount The number of bytes.
+ * @return The formatted string.
+ */
+ public static synchronized String formatBytes(long byteCount) {
+
+ // More than 1 GB?
+ if (byteCount >= 1024 * 1024 * 1024) {
+ NumberFormat gigaByteFormat = GIGA_BYTE_FORMAT;
+ return gigaByteFormat.format((double) byteCount / (1024 * 1024 * 1024));
+ }
+
+ // More than 1 MB?
+ if (byteCount >= 1024 * 1024) {
+ NumberFormat megaByteFormat = MEGA_BYTE_FORMAT;
+ return megaByteFormat.format((double) byteCount / (1024 * 1024));
+ }
+
+ // More than 1 KB?
+ if (byteCount >= 1024) {
+ NumberFormat kiloByteFormat = KILO_BYTE_FORMAT;
+ return kiloByteFormat.format((double) byteCount / 1024);
+ }
+
+ return byteCount + " B";
+ }
+
+ /**
+ * Converts a byte-count to a formatted string suitable for display to the user.
+ * For instance:
+ * <ul>
+ * <li><code>format(918)</code> returns <em>"918 B"</em>.</li>
+ * <li><code>format(98765)</code> returns <em>"96 KB"</em>.</li>
+ * <li><code>format(1238476)</code> returns <em>"1.2 MB"</em>.</li>
+ * </ul>
+ * This method assumes that 1 KB is 1024 bytes.
+ * This version of the method returns a localized string.
+ *
+ * @param byteCount The number of bytes.
+ * @return The formatted string.
+ */
+ public static synchronized String formatLocalizedBytes(long byteCount, Context context) {
+
+ // More than 1 GB?
+ if (byteCount >= 1024 * 1024 * 1024) {
+ if (GIGA_BYTE_LOCALIZED_FORMAT == null) {
+ GIGA_BYTE_LOCALIZED_FORMAT = new DecimalFormat(context.getResources().getString(R.string.util_bytes_format_gigabyte));
+ }
+
+ return GIGA_BYTE_LOCALIZED_FORMAT.format((double) byteCount / (1024 * 1024 * 1024));
+ }
+
+ // More than 1 MB?
+ if (byteCount >= 1024 * 1024) {
+ if (MEGA_BYTE_LOCALIZED_FORMAT == null) {
+ MEGA_BYTE_LOCALIZED_FORMAT = new DecimalFormat(context.getResources().getString(R.string.util_bytes_format_megabyte));
+ }
+
+ return MEGA_BYTE_LOCALIZED_FORMAT.format((double) byteCount / (1024 * 1024));
+ }
+
+ // More than 1 KB?
+ if (byteCount >= 1024) {
+ if (KILO_BYTE_LOCALIZED_FORMAT == null) {
+ KILO_BYTE_LOCALIZED_FORMAT = new DecimalFormat(context.getResources().getString(R.string.util_bytes_format_kilobyte));
+ }
+
+ return KILO_BYTE_LOCALIZED_FORMAT.format((double) byteCount / 1024);
+ }
+
+ if (BYTE_LOCALIZED_FORMAT == null) {
+ BYTE_LOCALIZED_FORMAT = new DecimalFormat(context.getResources().getString(R.string.util_bytes_format_byte));
+ }
+
+ return BYTE_LOCALIZED_FORMAT.format((double) byteCount);
+ }
+
+ public static String formatDuration(Integer seconds) {
+ if (seconds == null) {
+ return null;
+ }
+
+ int minutes = seconds / 60;
+ int secs = seconds % 60;
+
+ StringBuilder builder = new StringBuilder(6);
+ builder.append(minutes).append(":");
+ if (secs < 10) {
+ builder.append("0");
+ }
+ builder.append(secs);
+ return builder.toString();
+ }
+
+ public static boolean equals(Object object1, Object object2) {
+ if (object1 == object2) {
+ return true;
+ }
+ if (object1 == null || object2 == null) {
+ return false;
+ }
+ return object1.equals(object2);
+
+ }
+
+ /**
+ * Encodes the given string by using the hexadecimal representation of its UTF-8 bytes.
+ *
+ * @param s The string to encode.
+ * @return The encoded string.
+ */
+ public static String utf8HexEncode(String s) {
+ if (s == null) {
+ return null;
+ }
+ byte[] utf8;
+ try {
+ utf8 = s.getBytes(Constants.UTF_8);
+ } catch (UnsupportedEncodingException x) {
+ throw new RuntimeException(x);
+ }
+ return hexEncode(utf8);
+ }
+
+ /**
+ * Converts an array of bytes into an array of characters representing the hexadecimal values of each byte in order.
+ * The returned array will be double the length of the passed array, as it takes two characters to represent any
+ * given byte.
+ *
+ * @param data Bytes to convert to hexadecimal characters.
+ * @return A string containing hexadecimal characters.
+ */
+ public static String hexEncode(byte[] data) {
+ int length = data.length;
+ char[] out = new char[length << 1];
+ // two characters form the hex value.
+ for (int i = 0, j = 0; i < length; i++) {
+ out[j++] = HEX_DIGITS[(0xF0 & data[i]) >>> 4];
+ out[j++] = HEX_DIGITS[0x0F & data[i]];
+ }
+ return new String(out);
+ }
+
+ /**
+ * Calculates the MD5 digest and returns the value as a 32 character hex string.
+ *
+ * @param s Data to digest.
+ * @return MD5 digest as a hex string.
+ */
+ public static String md5Hex(String s) {
+ if (s == null) {
+ return null;
+ }
+
+ try {
+ MessageDigest md5 = MessageDigest.getInstance("MD5");
+ return hexEncode(md5.digest(s.getBytes(Constants.UTF_8)));
+ } catch (Exception x) {
+ throw new RuntimeException(x.getMessage(), x);
+ }
+ }
+
+ public static boolean isNetworkConnected(Context context) {
+ ConnectivityManager manager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
+ NetworkInfo networkInfo = manager.getActiveNetworkInfo();
+ boolean connected = networkInfo != null && networkInfo.isConnected();
+
+ boolean wifiConnected = connected && networkInfo.getType() == ConnectivityManager.TYPE_WIFI;
+ boolean wifiRequired = isWifiRequiredForDownload(context);
+
+ return connected && (!wifiRequired || wifiConnected);
+ }
+
+ public static boolean isExternalStoragePresent() {
+ return Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState());
+ }
+
+ private static boolean isWifiRequiredForDownload(Context context) {
+ SharedPreferences prefs = getPreferences(context);
+ return prefs.getBoolean(Constants.PREFERENCES_KEY_WIFI_REQUIRED_FOR_DOWNLOAD, false);
+ }
+
+ public static void info(Context context, int titleId, int messageId) {
+ showDialog(context, android.R.drawable.ic_dialog_info, titleId, messageId);
+ }
+
+ private static void showDialog(Context context, int icon, int titleId, int messageId) {
+ new AlertDialog.Builder(context)
+ .setIcon(icon)
+ .setTitle(titleId)
+ .setMessage(messageId)
+ .setPositiveButton(R.string.common_ok, new DialogInterface.OnClickListener() {
+ @Override
+ public void onClick(DialogInterface dialog, int i) {
+ dialog.dismiss();
+ }
+ })
+ .show();
+ }
+
+ public static void showPlayingNotification(final Context context, final DownloadServiceImpl downloadService, Handler handler, MusicDirectory.Entry song) {
+
+ // Use the same text for the ticker and the expanded notification
+ String title = song.getTitle();
+ String text = song.getArtist();
+
+ // Set the icon, scrolling text and timestamp
+ final Notification notification = new Notification(R.drawable.stat_notify_playing, title, System.currentTimeMillis());
+ notification.flags |= Notification.FLAG_NO_CLEAR | Notification.FLAG_ONGOING_EVENT;
+
+ RemoteViews contentView = new RemoteViews(context.getPackageName(), R.layout.notification);
+
+ // Set the album art.
+ try {
+ int size = context.getResources().getDrawable(R.drawable.unknown_album).getIntrinsicHeight();
+ Bitmap bitmap = FileUtil.getAlbumArtBitmap(context, song, size);
+ if (bitmap == null) {
+ // set default album art
+ contentView.setImageViewResource(R.id.notification_image, R.drawable.unknown_album);
+ } else {
+ contentView.setImageViewBitmap(R.id.notification_image, bitmap);
+ }
+ } catch (Exception x) {
+ Log.w(TAG, "Failed to get notification cover art", x);
+ contentView.setImageViewResource(R.id.notification_image, R.drawable.unknown_album);
+ }
+
+ // set the text for the notifications
+ contentView.setTextViewText(R.id.notification_title, title);
+ contentView.setTextViewText(R.id.notification_artist, text);
+
+ Pair<Integer, Integer> colors = getNotificationTextColors(context);
+ if (colors.getFirst() != null) {
+ contentView.setTextColor(R.id.notification_title, colors.getFirst());
+ }
+ if (colors.getSecond() != null) {
+ contentView.setTextColor(R.id.notification_artist, colors.getSecond());
+ }
+
+ notification.contentView = contentView;
+
+ Intent notificationIntent = new Intent(context, DownloadActivity.class);
+ notification.contentIntent = PendingIntent.getActivity(context, 0, notificationIntent, 0);
+
+ // Send the notification and put the service in the foreground.
+ handler.post(new Runnable() {
+ @Override
+ public void run() {
+ startForeground(downloadService, Constants.NOTIFICATION_ID_PLAYING, notification);
+ }
+ });
+
+ // Update widget
+ SubsonicAppWidgetProvider.getInstance().notifyChange(context, downloadService, true);
+ }
+
+ public static void hidePlayingNotification(final Context context, final DownloadServiceImpl downloadService, Handler handler) {
+
+ // Remove notification and remove the service from the foreground
+ handler.post(new Runnable() {
+ @Override
+ public void run() {
+ stopForeground(downloadService, true);
+ }
+ });
+
+ // Update widget
+ SubsonicAppWidgetProvider.getInstance().notifyChange(context, downloadService, false);
+ }
+
+ public static void sleepQuietly(long millis) {
+ try {
+ Thread.sleep(millis);
+ } catch (InterruptedException x) {
+ Log.w(TAG, "Interrupted from sleep.", x);
+ }
+ }
+
+ public static void startActivityWithoutTransition(Activity currentActivity, Class<? extends Activity> newActivitiy) {
+ startActivityWithoutTransition(currentActivity, new Intent(currentActivity, newActivitiy));
+ }
+
+ public static void startActivityWithoutTransition(Activity currentActivity, Intent intent) {
+ currentActivity.startActivity(intent);
+ disablePendingTransition(currentActivity);
+ }
+
+ public static void disablePendingTransition(Activity activity) {
+
+ // Activity.overridePendingTransition() was introduced in Android 2.0. Use reflection to maintain
+ // compatibility with 1.5.
+ try {
+ Method method = Activity.class.getMethod("overridePendingTransition", int.class, int.class);
+ method.invoke(activity, 0, 0);
+ } catch (Throwable x) {
+ // Ignored
+ }
+ }
+
+ public static Drawable createDrawableFromBitmap(Context context, Bitmap bitmap) {
+ // BitmapDrawable(Resources, Bitmap) was introduced in Android 1.6. Use reflection to maintain
+ // compatibility with 1.5.
+ try {
+ Constructor<BitmapDrawable> constructor = BitmapDrawable.class.getConstructor(Resources.class, Bitmap.class);
+ return constructor.newInstance(context.getResources(), bitmap);
+ } catch (Throwable x) {
+ return new BitmapDrawable(bitmap);
+ }
+ }
+
+ public static void registerMediaButtonEventReceiver(Context context) {
+
+ // Only do it if enabled in the settings.
+ SharedPreferences prefs = getPreferences(context);
+ boolean enabled = prefs.getBoolean(Constants.PREFERENCES_KEY_MEDIA_BUTTONS, true);
+
+ if (enabled) {
+
+ // AudioManager.registerMediaButtonEventReceiver() was introduced in Android 2.2.
+ // Use reflection to maintain compatibility with 1.5.
+ try {
+ AudioManager audioManager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);
+ ComponentName componentName = new ComponentName(context.getPackageName(), MediaButtonIntentReceiver.class.getName());
+ Method method = AudioManager.class.getMethod("registerMediaButtonEventReceiver", ComponentName.class);
+ method.invoke(audioManager, componentName);
+ } catch (Throwable x) {
+ // Ignored.
+ }
+ }
+ }
+
+ public static void unregisterMediaButtonEventReceiver(Context context) {
+ // AudioManager.unregisterMediaButtonEventReceiver() was introduced in Android 2.2.
+ // Use reflection to maintain compatibility with 1.5.
+ try {
+ AudioManager audioManager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);
+ ComponentName componentName = new ComponentName(context.getPackageName(), MediaButtonIntentReceiver.class.getName());
+ Method method = AudioManager.class.getMethod("unregisterMediaButtonEventReceiver", ComponentName.class);
+ method.invoke(audioManager, componentName);
+ } catch (Throwable x) {
+ // Ignored.
+ }
+ }
+
+ private static void startForeground(Service service, int notificationId, Notification notification) {
+ // Service.startForeground() was introduced in Android 2.0.
+ // Use reflection to maintain compatibility with 1.5.
+ try {
+ Method method = Service.class.getMethod("startForeground", int.class, Notification.class);
+ method.invoke(service, notificationId, notification);
+ Log.i(TAG, "Successfully invoked Service.startForeground()");
+ } catch (Throwable x) {
+ NotificationManager notificationManager = (NotificationManager) service.getSystemService(Context.NOTIFICATION_SERVICE);
+ notificationManager.notify(Constants.NOTIFICATION_ID_PLAYING, notification);
+ Log.i(TAG, "Service.startForeground() not available. Using work-around.");
+ }
+ }
+
+ private static void stopForeground(Service service, boolean removeNotification) {
+ // Service.stopForeground() was introduced in Android 2.0.
+ // Use reflection to maintain compatibility with 1.5.
+ try {
+ Method method = Service.class.getMethod("stopForeground", boolean.class);
+ method.invoke(service, removeNotification);
+ Log.i(TAG, "Successfully invoked Service.stopForeground()");
+ } catch (Throwable x) {
+ NotificationManager notificationManager = (NotificationManager) service.getSystemService(Context.NOTIFICATION_SERVICE);
+ notificationManager.cancel(Constants.NOTIFICATION_ID_PLAYING);
+ Log.i(TAG, "Service.stopForeground() not available. Using work-around.");
+ }
+ }
+
+ /**
+ * <p>Broadcasts the given song info as the new song being played.</p>
+ */
+ public static void broadcastNewTrackInfo(Context context, MusicDirectory.Entry song) {
+ Intent intent = new Intent(EVENT_META_CHANGED);
+
+ if (song != null) {
+ intent.putExtra("title", song.getTitle());
+ intent.putExtra("artist", song.getArtist());
+ intent.putExtra("album", song.getAlbum());
+
+ File albumArtFile = FileUtil.getAlbumArtFile(context, song);
+ intent.putExtra("coverart", albumArtFile.getAbsolutePath());
+ } else {
+ intent.putExtra("title", "");
+ intent.putExtra("artist", "");
+ intent.putExtra("album", "");
+ intent.putExtra("coverart", "");
+ }
+
+ context.sendBroadcast(intent);
+ }
+
+ /**
+ * <p>Broadcasts the given player state as the one being set.</p>
+ */
+ public static void broadcastPlaybackStatusChange(Context context, PlayerState state) {
+ Intent intent = new Intent(EVENT_PLAYSTATE_CHANGED);
+
+ switch (state) {
+ case STARTED:
+ intent.putExtra("state", "play");
+ break;
+ case STOPPED:
+ intent.putExtra("state", "stop");
+ break;
+ case PAUSED:
+ intent.putExtra("state", "pause");
+ break;
+ case COMPLETED:
+ intent.putExtra("state", "complete");
+ break;
+ default:
+ return; // No need to broadcast.
+ }
+
+ context.sendBroadcast(intent);
+ }
+
+ /**
+ * Resolves the default text color for notifications.
+ *
+ * Based on http://stackoverflow.com/questions/4867338/custom-notification-layouts-and-text-colors/7320604#7320604
+ */
+ private static Pair<Integer, Integer> getNotificationTextColors(Context context) {
+ if (NOTIFICATION_TEXT_COLORS.getFirst() == null && NOTIFICATION_TEXT_COLORS.getSecond() == null) {
+ try {
+ Notification notification = new Notification();
+ String title = "title";
+ String content = "content";
+ notification.setLatestEventInfo(context, title, content, null);
+ LinearLayout group = new LinearLayout(context);
+ ViewGroup event = (ViewGroup) notification.contentView.apply(context, group);
+ findNotificationTextColors(event, title, content);
+ group.removeAllViews();
+ } catch (Exception x) {
+ Log.w(TAG, "Failed to resolve notification text colors.", x);
+ }
+ }
+ return NOTIFICATION_TEXT_COLORS;
+ }
+
+ private static void findNotificationTextColors(ViewGroup group, String title, String content) {
+ for (int i = 0; i < group.getChildCount(); i++) {
+ if (group.getChildAt(i) instanceof TextView) {
+ TextView textView = (TextView) group.getChildAt(i);
+ String text = textView.getText().toString();
+ if (title.equals(text)) {
+ NOTIFICATION_TEXT_COLORS.setFirst(textView.getTextColors().getDefaultColor());
+ }
+ else if (content.equals(text)) {
+ NOTIFICATION_TEXT_COLORS.setSecond(textView.getTextColors().getDefaultColor());
+ }
+ }
+ else if (group.getChildAt(i) instanceof ViewGroup)
+ findNotificationTextColors((ViewGroup) group.getChildAt(i), title, content);
+ }
+ }
+}
diff --git a/subsonic-android/src/net/sourceforge/subsonic/androidapp/view/VisualizerView.java b/subsonic-android/src/net/sourceforge/subsonic/androidapp/view/VisualizerView.java
new file mode 100644
index 00000000..76a45253
--- /dev/null
+++ b/subsonic-android/src/net/sourceforge/subsonic/androidapp/view/VisualizerView.java
@@ -0,0 +1,132 @@
+/*
+ This file is part of Subsonic.
+
+ Subsonic is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ Subsonic is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with Subsonic. If not, see <http://www.gnu.org/licenses/>.
+
+ Copyright 2011 (C) Sindre Mehus
+ */
+package net.sourceforge.subsonic.androidapp.view;
+
+import android.content.Context;
+import android.graphics.Canvas;
+import android.graphics.Color;
+import android.graphics.Paint;
+import android.media.audiofx.Visualizer;
+import android.util.AttributeSet;
+import android.view.View;
+import net.sourceforge.subsonic.androidapp.audiofx.VisualizerController;
+import net.sourceforge.subsonic.androidapp.domain.PlayerState;
+import net.sourceforge.subsonic.androidapp.service.DownloadService;
+import net.sourceforge.subsonic.androidapp.service.DownloadServiceImpl;
+
+/**
+ * A simple class that draws waveform data received from a
+ * {@link Visualizer.OnDataCaptureListener#onWaveFormDataCapture}
+ *
+ * @author Sindre Mehus
+ * @version $Id$
+ */
+public class VisualizerView extends View {
+
+ private static final int PREFERRED_CAPTURE_RATE_MILLIHERTZ = 20000;
+
+ private final Paint paint = new Paint();
+
+ private byte[] data;
+ private float[] points;
+ private boolean active;
+
+ public VisualizerView(Context context) {
+ super(context);
+
+ paint.setStrokeWidth(2f);
+ paint.setAntiAlias(true);
+ paint.setColor(Color.rgb(129, 201, 54));
+ }
+
+ public boolean isActive() {
+ return active;
+ }
+
+ public void setActive(boolean active) {
+ this.active = active;
+ Visualizer visualizer = getVizualiser();
+ if (visualizer == null) {
+ return;
+ }
+
+ int captureRate = Math.min(PREFERRED_CAPTURE_RATE_MILLIHERTZ, Visualizer.getMaxCaptureRate());
+ if (active) {
+ visualizer.setDataCaptureListener(new Visualizer.OnDataCaptureListener() {
+ @Override
+ public void onWaveFormDataCapture(Visualizer visualizer, byte[] waveform, int samplingRate) {
+ updateVisualizer(waveform);
+ }
+
+ @Override
+ public void onFftDataCapture(Visualizer visualizer, byte[] fft, int samplingRate) {
+ }
+ }, captureRate, true, false);
+ } else {
+ visualizer.setDataCaptureListener(null, captureRate, false, false);
+ }
+
+ visualizer.setEnabled(active);
+ invalidate();
+ }
+
+ private Visualizer getVizualiser() {
+ DownloadService downloadService = DownloadServiceImpl.getInstance();
+ VisualizerController visualizerController = downloadService == null ? null : downloadService.getVisualizerController();
+ return visualizerController == null ? null : visualizerController.getVisualizer();
+ }
+
+ private void updateVisualizer(byte[] waveform) {
+ this.data = waveform;
+ invalidate();
+ }
+
+ @Override
+ protected void onDraw(Canvas canvas) {
+ super.onDraw(canvas);
+
+ if (!active) {
+ return;
+ }
+ DownloadService downloadService = DownloadServiceImpl.getInstance();
+ if (downloadService != null && downloadService.getPlayerState() != PlayerState.STARTED) {
+ return;
+ }
+
+ if (data == null) {
+ return;
+ }
+
+ if (points == null || points.length < data.length * 4) {
+ points = new float[data.length * 4];
+ }
+
+ int w = getWidth();
+ int h = getHeight();
+
+ for (int i = 0; i < data.length - 1; i++) {
+ points[i * 4] = w * i / (data.length - 1);
+ points[i * 4 + 1] = h / 2 + ((byte) (data[i] + 128)) * (h / 2) / 128;
+ points[i * 4 + 2] = w * (i + 1) / (data.length - 1);
+ points[i * 4 + 3] = h / 2 + ((byte) (data[i + 1] + 128)) * (h / 2) / 128;
+ }
+
+ canvas.drawLines(points, paint);
+ }
+}
diff --git a/subsonic-android/subsonic.keystore b/subsonic-android/subsonic.keystore
new file mode 100644
index 00000000..b6223fea
--- /dev/null
+++ b/subsonic-android/subsonic.keystore
Binary files differ
diff --git a/subsonic-android/tests/AndroidManifest.xml b/subsonic-android/tests/AndroidManifest.xml
new file mode 100644
index 00000000..58fb1e95
--- /dev/null
+++ b/subsonic-android/tests/AndroidManifest.xml
@@ -0,0 +1,21 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- package name must be unique so suffix with "tests" so package loader doesn't ignore us -->
+<manifest xmlns:android="http://schemas.android.com/apk/res/android"
+ package="net.sourceforge.subsonic.androidapp.tests"
+ android:versionCode="1"
+ android:versionName="1.0">
+ <!-- We add an application tag here just so that we can indicate that
+ this package needs to link against the android.test library,
+ which is needed when building test cases. -->
+ <application>
+ <uses-library android:name="android.test.runner" />
+ </application>
+ <!--
+ This declares that this application uses the instrumentation test runner targeting
+ the package of net.sourceforge.subsonic.android. To run the tests use the command:
+ "adb shell am instrument -w net.sourceforge.subsonic.android.tests/android.test.InstrumentationTestRunner"
+ -->
+ <instrumentation android:name="android.test.InstrumentationTestRunner"
+ android:targetPackage="net.sourceforge.subsonic.android"
+ android:label="Tests for SubsonicActivity"/>
+</manifest>
diff --git a/subsonic-android/tests/build.properties b/subsonic-android/tests/build.properties
new file mode 100644
index 00000000..a6504854
--- /dev/null
+++ b/subsonic-android/tests/build.properties
@@ -0,0 +1,15 @@
+# This file is used to override default values used by the Ant build system.
+#
+# This file must be checked in Version Control Systems, as it is
+# integral to the build system of your project.
+
+# The name of your application package as defined in the manifest.
+# Used by the 'uninstall' rule.
+#application-package=com.example.myproject
+
+# The name of the source folder.
+#source-folder=src
+
+# The name of the output folder.
+#out-folder=bin
+
diff --git a/subsonic-android/tests/build.xml b/subsonic-android/tests/build.xml
new file mode 100644
index 00000000..433559fa
--- /dev/null
+++ b/subsonic-android/tests/build.xml
@@ -0,0 +1,61 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project name="SubsonicActivity" default="help">
+
+ <!-- The local.properties file is created and updated by the 'android' tool.
+ It contain the path to the SDK. It should *NOT* be checked in in Version
+ Control Systems. -->
+ <property file="local.properties"/>
+
+ <!-- The build.properties file can be created by you and is never touched
+ by the 'android' tool. This is the place to change some of the default property values
+ used by the Ant rules.
+ Here are some properties you may want to change/update:
+
+ application-package
+ the name of your application package as defined in the manifest. Used by the
+ 'uninstall' rule.
+ source-folder
+ the name of the source folder. Default is 'src'.
+ out-folder
+ the name of the output folder. Default is 'bin'.
+
+ Properties related to the SDK location or the project target should be updated
+ using the 'android' tool with the 'update' action.
+
+ This file is an integral part of the build system for your application and
+ should be checked in in Version Control Systems.
+
+ -->
+ <property file="build.properties"/>
+
+ <!-- The default.properties file is created and updated by the 'android' tool, as well
+ as ADT.
+ This file is an integral part of the build system for your application and
+ should be checked in in Version Control Systems. -->
+ <property file="default.properties"/>
+
+ <!-- Custom Android task to deal with the project target, and import the proper rules.
+ This requires ant 1.6.0 or above. -->
+ <path id="android.antlibs">
+ <pathelement path="${sdk-location}/tools/lib/anttasks.jar" />
+ <pathelement path="${sdk-location}/tools/lib/sdklib.jar" />
+ <pathelement path="${sdk-location}/tools/lib/androidprefs.jar" />
+ <pathelement path="${sdk-location}/tools/lib/apkbuilder.jar" />
+ <pathelement path="${sdk-location}/tools/lib/jarutils.jar" />
+ </path>
+
+ <taskdef name="setup"
+ classname="com.android.ant.SetupTask"
+ classpathref="android.antlibs"/>
+
+ <!-- Execute the Android Setup task that will setup some properties specific to the target,
+ and import the rules files.
+ To customize the rules, copy/paste them below the task, and disable import by setting
+ the import attribute to false:
+ <setup import="false" />
+
+ This will ensure that the properties are setup correctly but that your customized
+ targets are used.
+ -->
+ <setup />
+</project>
diff --git a/subsonic-android/tests/default.properties b/subsonic-android/tests/default.properties
new file mode 100644
index 00000000..4513a1e4
--- /dev/null
+++ b/subsonic-android/tests/default.properties
@@ -0,0 +1,11 @@
+# This file is automatically generated by Android Tools.
+# Do not modify this file -- YOUR CHANGES WILL BE ERASED!
+#
+# This file must be checked in Version Control Systems.
+#
+# To customize properties used by the Ant build system use,
+# "build.properties", and override values to adapt the script to your
+# project structure.
+
+# Project target.
+target=android-3