From 997fb0736cd56a4d918b3f37fffdabc65c3e9086 Mon Sep 17 00:00:00 2001 From: Andrew Date: Mon, 16 Jan 2012 22:13:43 -0600 Subject: [PATCH] theme engine fixes --- .classpath | 9 + .project | 33 + project.properties | 11 + res/anim/anim_0.xml | 24 +- res/anim/anim_1.xml | 24 +- res/anim/anim_2.xml | 24 +- res/anim/anim_3.xml | 24 +- res/anim/anim_4.xml | 26 +- res/anim/anim_5.xml | 50 +- res/anim/fade_out_fast.xml | 44 +- res/anim/peak_meter.xml | 36 +- res/drawable/bg_stripes_repeat.xml | 42 +- res/drawable/group_text_color.xml | 10 +- res/drawable/list_selector_background.xml | 2 +- res/drawable/now_playing_selector.xml | 36 +- res/drawable/status_bg.xml | 8 +- res/drawable/tabs_bg.xml | 16 +- res/layout-land/audio_player.xml | 1 + res/layout-land/extra_controls.xml | 453 +++---- res/layout/album_appwidget1x1.xml | 40 +- res/layout/album_appwidget3x1.xml | 68 +- res/layout/audio_player.xml | 1 + res/layout/do_not_show.xml | 28 +- res/layout/extra_controls.xml | 454 +++---- res/layout/nowplaying.xml | 314 ++--- res/layout/statusbar.xml | 224 ++-- res/layout/track_list_item_common.xml | 184 +-- res/layout/track_list_item_common_child.xml | 168 +-- res/menu/action_menu.xml | 28 +- res/xml/appwidget3x1_info.xml | 34 +- res/xml/appwidget4x2_info.xml | 46 +- .../android/music/AlbumBrowserActivity.java | 36 +- .../music/ArtistAlbumBrowserActivity.java | 83 +- .../android/music/IMediaPlaybackService.aidl | 120 +- .../music/MediaAppWidgetProvider1x1.java | 364 +++--- .../music/MediaAppWidgetProvider3x1.java | 424 +++---- .../music/MediaAppWidgetProvider4x1.java | 562 ++++----- .../music/MediaAppWidgetProvider4x2.java | 698 +++++------ .../music/MediaButtonIntentReceiver.java | 340 +++--- .../android/music/MediaPlaybackActivity.java | 17 +- .../android/music/MediaPlaybackService.java | 5 +- .../android/music/MusicSettingsActivity.java | 1078 ++++++++--------- src/com/android/music/MusicViewPager.java | 80 +- .../music/PlaylistBrowserActivity.java | 34 +- src/com/android/music/Sensitivity.java | 226 ++-- src/com/android/music/Shaker.java | 178 +-- .../android/music/TrackBrowserActivity.java | 67 +- 47 files changed, 3481 insertions(+), 3293 deletions(-) create mode 100644 .classpath create mode 100644 .project create mode 100644 project.properties diff --git a/.classpath b/.classpath new file mode 100644 index 0000000..8531be1 --- /dev/null +++ b/.classpath @@ -0,0 +1,9 @@ + + + + + + + + + diff --git a/.project b/.project new file mode 100644 index 0000000..25e9b4c --- /dev/null +++ b/.project @@ -0,0 +1,33 @@ + + + Music + + + + + + com.android.ide.eclipse.adt.ResourceManagerBuilder + + + + + com.android.ide.eclipse.adt.PreCompilerBuilder + + + + + org.eclipse.jdt.core.javabuilder + + + + + com.android.ide.eclipse.adt.ApkBuilder + + + + + + com.android.ide.eclipse.adt.AndroidNature + org.eclipse.jdt.core.javanature + + diff --git a/project.properties b/project.properties new file mode 100644 index 0000000..8da376a --- /dev/null +++ b/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-15 diff --git a/res/anim/anim_0.xml b/res/anim/anim_0.xml index 3cf4b57..041113c 100644 --- a/res/anim/anim_0.xml +++ b/res/anim/anim_0.xml @@ -1,13 +1,13 @@ - - - - - + + + + + \ No newline at end of file diff --git a/res/anim/anim_1.xml b/res/anim/anim_1.xml index 490de90..ac13fce 100644 --- a/res/anim/anim_1.xml +++ b/res/anim/anim_1.xml @@ -1,13 +1,13 @@ - - - - - + + + + + \ No newline at end of file diff --git a/res/anim/anim_2.xml b/res/anim/anim_2.xml index b7c3e33..f1d15a6 100644 --- a/res/anim/anim_2.xml +++ b/res/anim/anim_2.xml @@ -1,13 +1,13 @@ - - - - - + + + + + \ No newline at end of file diff --git a/res/anim/anim_3.xml b/res/anim/anim_3.xml index 5777b1d..7bda84b 100644 --- a/res/anim/anim_3.xml +++ b/res/anim/anim_3.xml @@ -1,13 +1,13 @@ - - - - - + + + + + \ No newline at end of file diff --git a/res/anim/anim_4.xml b/res/anim/anim_4.xml index 8b33102..fda1a48 100644 --- a/res/anim/anim_4.xml +++ b/res/anim/anim_4.xml @@ -1,14 +1,14 @@ - - - - - - - + + + + + + + \ No newline at end of file diff --git a/res/anim/anim_5.xml b/res/anim/anim_5.xml index 29613ab..8326cf7 100644 --- a/res/anim/anim_5.xml +++ b/res/anim/anim_5.xml @@ -1,26 +1,26 @@ - - - - - - + + + + + + \ No newline at end of file diff --git a/res/anim/fade_out_fast.xml b/res/anim/fade_out_fast.xml index d946318..9d41aea 100644 --- a/res/anim/fade_out_fast.xml +++ b/res/anim/fade_out_fast.xml @@ -1,23 +1,23 @@ - - - - + + + \ No newline at end of file diff --git a/res/anim/peak_meter.xml b/res/anim/peak_meter.xml index e601eab..69b46a8 100644 --- a/res/anim/peak_meter.xml +++ b/res/anim/peak_meter.xml @@ -1,18 +1,18 @@ - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + diff --git a/res/drawable/bg_stripes_repeat.xml b/res/drawable/bg_stripes_repeat.xml index af192e0..1d6f83d 100644 --- a/res/drawable/bg_stripes_repeat.xml +++ b/res/drawable/bg_stripes_repeat.xml @@ -1,21 +1,21 @@ - - - - + + + + diff --git a/res/drawable/group_text_color.xml b/res/drawable/group_text_color.xml index 1020e42..6cc0130 100644 --- a/res/drawable/group_text_color.xml +++ b/res/drawable/group_text_color.xml @@ -1,6 +1,6 @@ - - - - - + + + + + \ No newline at end of file diff --git a/res/drawable/list_selector_background.xml b/res/drawable/list_selector_background.xml index 5389bc7..a0eab9f 100644 --- a/res/drawable/list_selector_background.xml +++ b/res/drawable/list_selector_background.xml @@ -27,7 +27,7 @@ android:drawable="@drawable/playlist_tile_normal" /> + android:drawable="@drawable/playlist_tile_normal" /> diff --git a/res/drawable/now_playing_selector.xml b/res/drawable/now_playing_selector.xml index 42df9bc..42512df 100644 --- a/res/drawable/now_playing_selector.xml +++ b/res/drawable/now_playing_selector.xml @@ -1,19 +1,19 @@ - - - - - - - - - + + + + + + + + + \ No newline at end of file diff --git a/res/drawable/status_bg.xml b/res/drawable/status_bg.xml index c2cdf2f..99e5ea6 100644 --- a/res/drawable/status_bg.xml +++ b/res/drawable/status_bg.xml @@ -1,4 +1,4 @@ - - + + diff --git a/res/drawable/tabs_bg.xml b/res/drawable/tabs_bg.xml index 260370d..bd717fb 100644 --- a/res/drawable/tabs_bg.xml +++ b/res/drawable/tabs_bg.xml @@ -1,9 +1,9 @@ - - - - - - - - + + + + + + + + \ No newline at end of file diff --git a/res/layout-land/audio_player.xml b/res/layout-land/audio_player.xml index b5ce353..4de244f 100644 --- a/res/layout-land/audio_player.xml +++ b/res/layout-land/audio_player.xml @@ -16,6 +16,7 @@ --> - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/res/layout/album_appwidget1x1.xml b/res/layout/album_appwidget1x1.xml index 5ab05f1..a46105e 100644 --- a/res/layout/album_appwidget1x1.xml +++ b/res/layout/album_appwidget1x1.xml @@ -1,21 +1,21 @@ - - - - - - - + + + + + + + \ No newline at end of file diff --git a/res/layout/album_appwidget3x1.xml b/res/layout/album_appwidget3x1.xml index f9ffde0..55aea60 100644 --- a/res/layout/album_appwidget3x1.xml +++ b/res/layout/album_appwidget3x1.xml @@ -1,35 +1,35 @@ - - - - - - - - - + + + + + + + + + \ No newline at end of file diff --git a/res/layout/audio_player.xml b/res/layout/audio_player.xml index 1f39ef1..b86cf90 100644 --- a/res/layout/audio_player.xml +++ b/res/layout/audio_player.xml @@ -16,6 +16,7 @@ --> - - - - + + + + + \ No newline at end of file diff --git a/res/layout/extra_controls.xml b/res/layout/extra_controls.xml index 574a950..4f85fdb 100644 --- a/res/layout/extra_controls.xml +++ b/res/layout/extra_controls.xml @@ -1,228 +1,228 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/res/layout/nowplaying.xml b/res/layout/nowplaying.xml index 762a5fa..54754e2 100644 --- a/res/layout/nowplaying.xml +++ b/res/layout/nowplaying.xml @@ -1,158 +1,158 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/res/layout/statusbar.xml b/res/layout/statusbar.xml index ce1a2cd..f53bf2a 100644 --- a/res/layout/statusbar.xml +++ b/res/layout/statusbar.xml @@ -1,113 +1,113 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/res/layout/track_list_item_common.xml b/res/layout/track_list_item_common.xml index 0bfea3d..6b9c959 100644 --- a/res/layout/track_list_item_common.xml +++ b/res/layout/track_list_item_common.xml @@ -1,93 +1,93 @@ - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/res/layout/track_list_item_common_child.xml b/res/layout/track_list_item_common_child.xml index 711578a..ec81ee3 100644 --- a/res/layout/track_list_item_common_child.xml +++ b/res/layout/track_list_item_common_child.xml @@ -1,85 +1,85 @@ - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/res/menu/action_menu.xml b/res/menu/action_menu.xml index 39d46d4..5aaa60d 100644 --- a/res/menu/action_menu.xml +++ b/res/menu/action_menu.xml @@ -1,15 +1,15 @@ - - - - - - + + + + + + \ No newline at end of file diff --git a/res/xml/appwidget3x1_info.xml b/res/xml/appwidget3x1_info.xml index 883f7a1..65c491c 100644 --- a/res/xml/appwidget3x1_info.xml +++ b/res/xml/appwidget3x1_info.xml @@ -1,18 +1,18 @@ - - - - - + + + + + \ No newline at end of file diff --git a/res/xml/appwidget4x2_info.xml b/res/xml/appwidget4x2_info.xml index 4653c8a..50094a3 100644 --- a/res/xml/appwidget4x2_info.xml +++ b/res/xml/appwidget4x2_info.xml @@ -1,23 +1,23 @@ - - - - - + + + + + diff --git a/src/com/android/music/AlbumBrowserActivity.java b/src/com/android/music/AlbumBrowserActivity.java index 751dca7..2045585 100644 --- a/src/com/android/music/AlbumBrowserActivity.java +++ b/src/com/android/music/AlbumBrowserActivity.java @@ -252,13 +252,9 @@ public boolean onTouch(View vee, MotionEvent nowplayingevent) { mButtonBarSong = (TextView) findViewById(R.id.songtab); mButtonBarPlaylist = (TextView) findViewById(R.id.playlisttab); mButtonBarNP = (TextView) findViewById(R.id.nowplayingtab); - mGroup = (RelativeLayout) findViewById(R.id.group_item); - mChild = (RelativeLayout) findViewById(R.id.child_item); ArtistAlbumBrowserActivity .loadThemeResource(themeResources, themePackage, "tab_album", mAlbumTab, THEME_ITEM_BACKGROUND); - ArtistAlbumBrowserActivity.loadThemeResource(themeResources, - themePackage, "child_bg", mChild, THEME_ITEM_BACKGROUND); ArtistAlbumBrowserActivity.loadThemeResource(themeResources, themePackage, "buttonbar", mButtonBar, THEME_ITEM_BACKGROUND); @@ -1175,6 +1171,9 @@ public View newView(Context context, Cursor cursor, ViewGroup parent) { if (line2 != 0) { vh.line2.setTextColor(themeResources.getColor(line2)); } + ArtistAlbumBrowserActivity.loadThemeResource(themeResources, + themePackage, "bt_context_menu", vh.mCM, + THEME_ITEM_FOREGROUND); } return v; } @@ -1182,6 +1181,23 @@ public View newView(Context context, Cursor cursor, ViewGroup parent) { @Override public void bindView(View view, Context context, Cursor cursor) { + // ADW: Load the specified theme + String themePackage = MusicUtils.getThemePackageName(context, + MusicSettingsActivity.THEME_DEFAULT); + PackageManager pm = context.getPackageManager(); + Resources themeResources = null; + if (!themePackage.equals(MusicSettingsActivity.THEME_DEFAULT)) { + try { + themeResources = pm + .getResourcesForApplication(themePackage); + } catch (NameNotFoundException e) { + // ADW The saved theme was uninstalled so we save the + // default one + MusicUtils.setThemePackageName(context, + MusicSettingsActivity.THEME_DEFAULT); + } + } + ViewHolder vh = (ViewHolder) view.getTag(); String name = cursor.getString(mAlbumIdx); @@ -1217,6 +1233,14 @@ public void bindView(View view, Context context, Cursor cursor) { iv.setBackgroundResource(R.anim.peak_meter); AnimationDrawable frameAnimation = (AnimationDrawable) iv .getBackground(); + if (themeResources != null) { + int peak = themeResources.getIdentifier("peak_meter", + "anim", themePackage); + if (peak != 0) { + iv.setBackgroundDrawable(themeResources + .getDrawable(peak)); + } + } // Start the animation (looped playback by default). frameAnimation.start(); iv.setVisibility(View.VISIBLE); @@ -1314,14 +1338,14 @@ private void setPauseButtonImage() { mPlay.setImageResource(R.drawable.ic_media_pause); if (themeResources != null) { ArtistAlbumBrowserActivity.loadThemeResource( - themeResources, themePackage, "np_pause", mPlay, + themeResources, themePackage, "snp_pause", mPlay, THEME_ITEM_FOREGROUND); } } else { mPlay.setImageResource(R.drawable.ic_appwidget_music_play); if (themeResources != null) { ArtistAlbumBrowserActivity.loadThemeResource( - themeResources, themePackage, "np_play", mPlay, + themeResources, themePackage, "snp_play", mPlay, THEME_ITEM_FOREGROUND); } } diff --git a/src/com/android/music/ArtistAlbumBrowserActivity.java b/src/com/android/music/ArtistAlbumBrowserActivity.java index 80ec0c2..63a414b 100644 --- a/src/com/android/music/ArtistAlbumBrowserActivity.java +++ b/src/com/android/music/ArtistAlbumBrowserActivity.java @@ -239,12 +239,8 @@ public boolean onTouch(View vee, MotionEvent nowplayingevent) { mButtonBarSong = (TextView) findViewById(R.id.songtab); mButtonBarPlaylist = (TextView) findViewById(R.id.playlisttab); mButtonBarNP = (TextView) findViewById(R.id.nowplayingtab); - mGroup = (RelativeLayout) findViewById(R.id.group_item); - mChild = (RelativeLayout) findViewById(R.id.child_item); loadThemeResource(themeResources, themePackage, "tab_artist", mArtistTab, THEME_ITEM_BACKGROUND); - loadThemeResource(themeResources, themePackage, "child_bg", mChild, - THEME_ITEM_BACKGROUND); loadThemeResource(themeResources, themePackage, "buttonbar", mButtonBar, THEME_ITEM_BACKGROUND); loadThemeResource(themeResources, themePackage, "tab_bg_artist", @@ -1074,6 +1070,8 @@ static class ViewHolder { ImageView play_indicator; ImageView icon; ImageView mCM; + RelativeLayout mGroup; + RelativeLayout mChild; FrameLayout mContextMenu; } @@ -1169,6 +1167,7 @@ public View newGroupView(Context context, Cursor cursor, vh.mContextMenu = (FrameLayout) v .findViewById(R.id.second_column_icon); vh.mContextMenu.setOnClickListener(mCML); + vh.mGroup = (RelativeLayout) v.findViewById(R.id.group_item); // ADW: Load the specified theme String themePackage = MusicUtils.getThemePackageName(context, @@ -1199,6 +1198,15 @@ public View newGroupView(Context context, Cursor cursor, if (line2 != 0) { vh.line2.setTextColor(themeResources.getColor(line2)); } + int mGroupItem = themeResources.getIdentifier("group_bg", + "drawable", themePackage); + if (mGroupItem != 0) { + vh.mGroup.setBackgroundDrawable(themeResources + .getDrawable(mGroupItem)); + } + loadThemeResource(themeResources, themePackage, + "bt_context_menu", vh.mCM, THEME_ITEM_FOREGROUND); + } return v; } @@ -1219,6 +1227,7 @@ public View newChildView(Context context, Cursor cursor, vh.mContextMenu = (FrameLayout) v .findViewById(R.id.second_column_icon); vh.mContextMenu.setOnClickListener(mCML); + vh.mChild = (RelativeLayout) v.findViewById(R.id.child_item); // ADW: Load the specified theme String themePackage = MusicUtils.getThemePackageName(context, MusicSettingsActivity.THEME_DEFAULT); @@ -1248,6 +1257,14 @@ public View newChildView(Context context, Cursor cursor, if (line2 != 0) { vh.line2.setTextColor(themeResources.getColor(line2)); } + int mChildItem = themeResources.getIdentifier("child_bg", + "drawable", themePackage); + if (mChildItem != 0) { + vh.mChild.setBackgroundDrawable(themeResources + .getDrawable(mChildItem)); + } + loadThemeResource(themeResources, themePackage, + "bt_context_menu", vh.mCM, THEME_ITEM_FOREGROUND); } return v; } @@ -1255,6 +1272,22 @@ public View newChildView(Context context, Cursor cursor, @Override public void bindGroupView(View view, Context context, Cursor cursor, boolean isexpanded) { + // ADW: Load the specified theme + String themePackage = MusicUtils.getThemePackageName(context, + MusicSettingsActivity.THEME_DEFAULT); + PackageManager pm = context.getPackageManager(); + Resources themeResources = null; + if (!themePackage.equals(MusicSettingsActivity.THEME_DEFAULT)) { + try { + themeResources = pm + .getResourcesForApplication(themePackage); + } catch (NameNotFoundException e) { + // ADW The saved theme was uninstalled so we save the + // default one + MusicUtils.setThemePackageName(context, + MusicSettingsActivity.THEME_DEFAULT); + } + } ViewHolder vh = (ViewHolder) view.getTag(); @@ -1282,6 +1315,15 @@ public void bindGroupView(View view, Context context, Cursor cursor, iv.setBackgroundResource(R.anim.peak_meter); AnimationDrawable frameAnimation = (AnimationDrawable) iv .getBackground(); + if (themeResources != null) { + int peak = themeResources.getIdentifier("peak_meter", + "anim", themePackage); + if (peak != 0) { + iv.setBackgroundDrawable(themeResources + .getDrawable(peak)); + frameAnimation.start(); + } + } // Start the animation (looped playback by default). frameAnimation.start(); iv.setVisibility(View.VISIBLE); @@ -1294,6 +1336,22 @@ public void bindGroupView(View view, Context context, Cursor cursor, @Override public void bindChildView(View view, Context context, Cursor cursor, boolean islast) { + // ADW: Load the specified theme + String themePackage = MusicUtils.getThemePackageName(context, + MusicSettingsActivity.THEME_DEFAULT); + PackageManager pm = context.getPackageManager(); + Resources themeResources = null; + if (!themePackage.equals(MusicSettingsActivity.THEME_DEFAULT)) { + try { + themeResources = pm + .getResourcesForApplication(themePackage); + } catch (NameNotFoundException e) { + // ADW The saved theme was uninstalled so we save the + // default one + MusicUtils.setThemePackageName(context, + MusicSettingsActivity.THEME_DEFAULT); + } + } ViewHolder vh = (ViewHolder) view.getTag(); @@ -1363,10 +1421,16 @@ public void bindChildView(View view, Context context, Cursor cursor, iv.setBackgroundResource(R.anim.peak_meter); AnimationDrawable frameAnimation = (AnimationDrawable) iv .getBackground(); - + if (themeResources != null) { + int peak = themeResources.getIdentifier("peak_meter", + "anim", themePackage); + if (peak != 0) { + iv.setBackgroundDrawable(themeResources + .getDrawable(peak)); + } + } // Start the animation (looped playback by default). frameAnimation.start(); - iv.setVisibility(View.VISIBLE); } else { iv.setVisibility(View.GONE); @@ -1523,12 +1587,13 @@ private void setPauseButtonImage() { try { if (mService != null && mService.isPlaying()) { mPlay.setImageResource(R.drawable.ic_media_pause); - ArtistAlbumBrowserActivity.loadThemeResource(themeResources, - themePackage, "np_pause", mPlay, THEME_ITEM_FOREGROUND); + ArtistAlbumBrowserActivity + .loadThemeResource(themeResources, themePackage, + "snp_pause", mPlay, THEME_ITEM_FOREGROUND); } else { mPlay.setImageResource(R.drawable.ic_appwidget_music_play); ArtistAlbumBrowserActivity.loadThemeResource(themeResources, - themePackage, "np_play", mPlay, THEME_ITEM_FOREGROUND); + themePackage, "snp_play", mPlay, THEME_ITEM_FOREGROUND); } } catch (RemoteException ex) { } diff --git a/src/com/android/music/IMediaPlaybackService.aidl b/src/com/android/music/IMediaPlaybackService.aidl index f816ab3..d92d369 100644 --- a/src/com/android/music/IMediaPlaybackService.aidl +++ b/src/com/android/music/IMediaPlaybackService.aidl @@ -1,60 +1,60 @@ -/* //device/samples/SampleCode/src/com/android/samples/app/RemoteServiceInterface.java -** -** Copyright 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. -*/ - -package com.android.music; - -import android.graphics.Bitmap; - -interface IMediaPlaybackService -{ - void openFile(String path); - void open(in long [] list, int position); - int getQueuePosition(); - boolean isPlaying(); - void stop(); - void pause(); - void play(); - void prev(); - void next(); - void cycleRepeat(); - void toggleShuffle(); - long duration(); - long position(); - long seek(long pos); - String getTrackName(); - String getAlbumName(); - long getAlbumId(); - String getArtistName(); - long getArtistId(); - String getAlbumartistName(); - long getAlbumartistId(); - void enqueue(in long [] list, int action); - long [] getQueue(); - void moveQueueItem(int from, int to); - void setQueuePosition(int index); - String getPath(); - long getAudioId(); - void setShuffleMode(int shufflemode); - int getShuffleMode(); - int removeTracks(int first, int last); - int removeTrack(long id); - void setRepeatMode(int repeatmode); - int getRepeatMode(); - int getMediaMountedCount(); - int getAudioSessionId(); -} - +/* //device/samples/SampleCode/src/com/android/samples/app/RemoteServiceInterface.java +** +** Copyright 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. +*/ + +package com.android.music; + +import android.graphics.Bitmap; + +interface IMediaPlaybackService +{ + void openFile(String path); + void open(in long [] list, int position); + int getQueuePosition(); + boolean isPlaying(); + void stop(); + void pause(); + void play(); + void prev(); + void next(); + void cycleRepeat(); + void toggleShuffle(); + long duration(); + long position(); + long seek(long pos); + String getTrackName(); + String getAlbumName(); + long getAlbumId(); + String getArtistName(); + long getArtistId(); + String getAlbumartistName(); + long getAlbumartistId(); + void enqueue(in long [] list, int action); + long [] getQueue(); + void moveQueueItem(int from, int to); + void setQueuePosition(int index); + String getPath(); + long getAudioId(); + void setShuffleMode(int shufflemode); + int getShuffleMode(); + int removeTracks(int first, int last); + int removeTrack(long id); + void setRepeatMode(int repeatmode); + int getRepeatMode(); + int getMediaMountedCount(); + int getAudioSessionId(); +} + diff --git a/src/com/android/music/MediaAppWidgetProvider1x1.java b/src/com/android/music/MediaAppWidgetProvider1x1.java index 977348b..9c5b113 100644 --- a/src/com/android/music/MediaAppWidgetProvider1x1.java +++ b/src/com/android/music/MediaAppWidgetProvider1x1.java @@ -1,182 +1,182 @@ -/* - * 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. - */ - -package com.android.music; - -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.net.Uri; -import android.view.View; -import android.widget.RemoteViews; - -/** - * Simple widget to show currently playing album art along with play/pause and - * next track buttons. - */ -public class MediaAppWidgetProvider1x1 extends AppWidgetProvider { - static final String TAG = "MusicAppWidgetProvider1x1"; - - public static final String CMDAPPWIDGETUPDATE = "appwidgetupdate1x1"; - - private static MediaAppWidgetProvider1x1 sInstance; - - static synchronized MediaAppWidgetProvider1x1 getInstance() { - if (sInstance == null) { - sInstance = new MediaAppWidgetProvider1x1(); - } - return sInstance; - } - - @Override - public void onUpdate(Context context, AppWidgetManager appWidgetManager, - int[] appWidgetIds) { - defaultAppWidget(context, appWidgetIds); - - // Send broadcast intent to any running MediaPlaybackService so it can - // wrap around with an immediate update. - Intent updateIntent = new Intent(MediaPlaybackService.SERVICECMD); - updateIntent.putExtra(MediaPlaybackService.CMDNAME, - MediaAppWidgetProvider1x1.CMDAPPWIDGETUPDATE); - updateIntent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_IDS, - appWidgetIds); - updateIntent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY); - context.sendBroadcast(updateIntent); - } - - /** - * Initialize given widgets to default state, where we launch Music on - * default click and hide actions if service not running. - */ - private void defaultAppWidget(Context context, int[] appWidgetIds) { - final RemoteViews views = new RemoteViews(context.getPackageName(), - R.layout.album_appwidget1x1); - - views.setImageViewResource(R.id.albumart, View.GONE); - - linkButtons(context, views, false /* not playing */); - 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 gm = AppWidgetManager.getInstance(context); - if (appWidgetIds != null) { - gm.updateAppWidget(appWidgetIds, views); - } else { - gm.updateAppWidget(new ComponentName(context, this.getClass()), - views); - } - } - - /** - * Check against {@link AppWidgetManager} if there are any instances of this - * widget. - */ - private boolean hasInstances(Context context) { - AppWidgetManager appWidgetManager = AppWidgetManager - .getInstance(context); - int[] appWidgetIds = appWidgetManager - .getAppWidgetIds(new ComponentName(context, this.getClass())); - return (appWidgetIds.length > 0); - } - - /** - * Handle a change notification coming over from - * {@link MediaPlaybackService} - */ - void notifyChange(MediaPlaybackService service, String what) { - if (hasInstances(service)) { - if (MediaPlaybackService.META_CHANGED.equals(what) - || MediaPlaybackService.PLAYSTATE_CHANGED.equals(what) - || MediaPlaybackService.REPEATMODE_CHANGED.equals(what) - || MediaPlaybackService.SHUFFLEMODE_CHANGED.equals(what)) { - performUpdate(service, null); - } - } - } - - /** - * Update all active widget instances by pushing changes - */ - void performUpdate(MediaPlaybackService service, int[] appWidgetIds) { - final RemoteViews views = new RemoteViews(service.getPackageName(), - R.layout.album_appwidget1x1); - - CharSequence titleName = service.getTrackName(); - CharSequence artistName = service.getArtistName(); - long albumId = service.getAlbumId(); - long songId = service.getAudioId(); - { - // No error, so show normal titles and artwork - views.setTextViewText(R.id.title, titleName); - views.setTextViewText(R.id.artist, artistName); - views.setViewVisibility(R.id.albumart, View.VISIBLE); - // Set album art - Uri uri = MusicUtils.getArtworkUri(service, songId, albumId); - if (uri != null) { - views.setImageViewUri(R.id.albumart, uri); - } else { - views.setImageViewResource(R.id.albumart, - R.drawable.albumart_mp_unknown); - } - } - // Set correct drawable for pause state - final boolean playing = service.isPlaying(); - if (playing) { - views.setImageViewResource(R.id.play_pause, - R.drawable.appwidget_pause_normal); - } else { - views.setImageViewResource(R.id.play_pause, - R.drawable.appwidget_play_normal); - } - - // Link actions buttons to intents - linkButtons(service, views, playing); - - pushUpdate(service, appWidgetIds, views); - } - - /** - * Link up various button actions using {@link PendingIntents}. - * - * @param playerActive - * True if player is active in background, which means widget - * click will launch {@link MediaPlaybackActivity}, otherwise we - * launch {@link MusicBrowserActivity}. - */ - private void linkButtons(Context context, RemoteViews views, - boolean playerActive) { - // Connect up various buttons and touch events - Intent intent; - PendingIntent pendingIntent; - - final ComponentName serviceName = new ComponentName(context, - MediaPlaybackService.class); - - intent = new Intent(MediaPlaybackService.TOGGLEPAUSE_ACTION); - intent.setComponent(serviceName); - pendingIntent = PendingIntent.getService(context, - 0 /* no requestCode */, intent, 0 /* no flags */); - views.setOnClickPendingIntent(R.id.albumart, pendingIntent); - - } -} +/* + * 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. + */ + +package com.android.music; + +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.net.Uri; +import android.view.View; +import android.widget.RemoteViews; + +/** + * Simple widget to show currently playing album art along with play/pause and + * next track buttons. + */ +public class MediaAppWidgetProvider1x1 extends AppWidgetProvider { + static final String TAG = "MusicAppWidgetProvider1x1"; + + public static final String CMDAPPWIDGETUPDATE = "appwidgetupdate1x1"; + + private static MediaAppWidgetProvider1x1 sInstance; + + static synchronized MediaAppWidgetProvider1x1 getInstance() { + if (sInstance == null) { + sInstance = new MediaAppWidgetProvider1x1(); + } + return sInstance; + } + + @Override + public void onUpdate(Context context, AppWidgetManager appWidgetManager, + int[] appWidgetIds) { + defaultAppWidget(context, appWidgetIds); + + // Send broadcast intent to any running MediaPlaybackService so it can + // wrap around with an immediate update. + Intent updateIntent = new Intent(MediaPlaybackService.SERVICECMD); + updateIntent.putExtra(MediaPlaybackService.CMDNAME, + MediaAppWidgetProvider1x1.CMDAPPWIDGETUPDATE); + updateIntent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_IDS, + appWidgetIds); + updateIntent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY); + context.sendBroadcast(updateIntent); + } + + /** + * Initialize given widgets to default state, where we launch Music on + * default click and hide actions if service not running. + */ + private void defaultAppWidget(Context context, int[] appWidgetIds) { + final RemoteViews views = new RemoteViews(context.getPackageName(), + R.layout.album_appwidget1x1); + + views.setImageViewResource(R.id.albumart, View.GONE); + + linkButtons(context, views, false /* not playing */); + 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 gm = AppWidgetManager.getInstance(context); + if (appWidgetIds != null) { + gm.updateAppWidget(appWidgetIds, views); + } else { + gm.updateAppWidget(new ComponentName(context, this.getClass()), + views); + } + } + + /** + * Check against {@link AppWidgetManager} if there are any instances of this + * widget. + */ + private boolean hasInstances(Context context) { + AppWidgetManager appWidgetManager = AppWidgetManager + .getInstance(context); + int[] appWidgetIds = appWidgetManager + .getAppWidgetIds(new ComponentName(context, this.getClass())); + return (appWidgetIds.length > 0); + } + + /** + * Handle a change notification coming over from + * {@link MediaPlaybackService} + */ + void notifyChange(MediaPlaybackService service, String what) { + if (hasInstances(service)) { + if (MediaPlaybackService.META_CHANGED.equals(what) + || MediaPlaybackService.PLAYSTATE_CHANGED.equals(what) + || MediaPlaybackService.REPEATMODE_CHANGED.equals(what) + || MediaPlaybackService.SHUFFLEMODE_CHANGED.equals(what)) { + performUpdate(service, null); + } + } + } + + /** + * Update all active widget instances by pushing changes + */ + void performUpdate(MediaPlaybackService service, int[] appWidgetIds) { + final RemoteViews views = new RemoteViews(service.getPackageName(), + R.layout.album_appwidget1x1); + + CharSequence titleName = service.getTrackName(); + CharSequence artistName = service.getArtistName(); + long albumId = service.getAlbumId(); + long songId = service.getAudioId(); + { + // No error, so show normal titles and artwork + views.setTextViewText(R.id.title, titleName); + views.setTextViewText(R.id.artist, artistName); + views.setViewVisibility(R.id.albumart, View.VISIBLE); + // Set album art + Uri uri = MusicUtils.getArtworkUri(service, songId, albumId); + if (uri != null) { + views.setImageViewUri(R.id.albumart, uri); + } else { + views.setImageViewResource(R.id.albumart, + R.drawable.albumart_mp_unknown); + } + } + // Set correct drawable for pause state + final boolean playing = service.isPlaying(); + if (playing) { + views.setImageViewResource(R.id.play_pause, + R.drawable.appwidget_pause_normal); + } else { + views.setImageViewResource(R.id.play_pause, + R.drawable.appwidget_play_normal); + } + + // Link actions buttons to intents + linkButtons(service, views, playing); + + pushUpdate(service, appWidgetIds, views); + } + + /** + * Link up various button actions using {@link PendingIntents}. + * + * @param playerActive + * True if player is active in background, which means widget + * click will launch {@link MediaPlaybackActivity}, otherwise we + * launch {@link MusicBrowserActivity}. + */ + private void linkButtons(Context context, RemoteViews views, + boolean playerActive) { + // Connect up various buttons and touch events + Intent intent; + PendingIntent pendingIntent; + + final ComponentName serviceName = new ComponentName(context, + MediaPlaybackService.class); + + intent = new Intent(MediaPlaybackService.TOGGLEPAUSE_ACTION); + intent.setComponent(serviceName); + pendingIntent = PendingIntent.getService(context, + 0 /* no requestCode */, intent, 0 /* no flags */); + views.setOnClickPendingIntent(R.id.albumart, pendingIntent); + + } +} diff --git a/src/com/android/music/MediaAppWidgetProvider3x1.java b/src/com/android/music/MediaAppWidgetProvider3x1.java index d00549b..699f0a1 100644 --- a/src/com/android/music/MediaAppWidgetProvider3x1.java +++ b/src/com/android/music/MediaAppWidgetProvider3x1.java @@ -1,212 +1,212 @@ -/* - * 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. - */ - -package com.android.music; - -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.net.Uri; -import android.os.Environment; -import android.view.View; -import android.widget.RemoteViews; - -/** - * Simple widget to show currently playing album art along with play/pause and - * next track buttons. - */ -public class MediaAppWidgetProvider3x1 extends AppWidgetProvider { - static final String TAG = "MusicAppWidgetProvider3x1"; - - public static final String CMDAPPWIDGETUPDATE = "appwidgetupdate3x1"; - - private static MediaAppWidgetProvider3x1 sInstance; - - static synchronized MediaAppWidgetProvider3x1 getInstance() { - if (sInstance == null) { - sInstance = new MediaAppWidgetProvider3x1(); - } - return sInstance; - } - - @Override - public void onUpdate(Context context, AppWidgetManager appWidgetManager, - int[] appWidgetIds) { - defaultAppWidget(context, appWidgetIds); - - // Send broadcast intent to any running MediaPlaybackService so it can - // wrap around with an immediate update. - Intent updateIntent = new Intent(MediaPlaybackService.SERVICECMD); - updateIntent.putExtra(MediaPlaybackService.CMDNAME, - MediaAppWidgetProvider3x1.CMDAPPWIDGETUPDATE); - updateIntent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_IDS, - appWidgetIds); - updateIntent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY); - context.sendBroadcast(updateIntent); - } - - /** - * Initialize given widgets to default state, where we launch Music on - * default click and hide actions if service not running. - */ - private void defaultAppWidget(Context context, int[] appWidgetIds) { - final RemoteViews views = new RemoteViews(context.getPackageName(), - R.layout.album_appwidget3x1); - - views.setViewVisibility(R.id.albumart, View.VISIBLE); - - linkButtons(context, views /* not playing */); - 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 gm = AppWidgetManager.getInstance(context); - if (appWidgetIds != null) { - gm.updateAppWidget(appWidgetIds, views); - } else { - gm.updateAppWidget(new ComponentName(context, this.getClass()), - views); - } - } - - /** - * Check against {@link AppWidgetManager} if there are any instances of this - * widget. - */ - private boolean hasInstances(Context context) { - AppWidgetManager appWidgetManager = AppWidgetManager - .getInstance(context); - int[] appWidgetIds = appWidgetManager - .getAppWidgetIds(new ComponentName(context, this.getClass())); - return (appWidgetIds.length > 0); - } - - /** - * Handle a change notification coming over from - * {@link MediaPlaybackService} - */ - void notifyChange(MediaPlaybackService service, String what) { - if (hasInstances(service)) { - if (MediaPlaybackService.META_CHANGED.equals(what) - || MediaPlaybackService.PLAYSTATE_CHANGED.equals(what)) { - performUpdate(service, null); - } - } - } - - /** - * Update all active widget instances by pushing changes - */ - void performUpdate(MediaPlaybackService service, int[] appWidgetIds) { - final Resources res = service.getResources(); - final RemoteViews views = new RemoteViews(service.getPackageName(), - R.layout.album_appwidget3x1); - - CharSequence titleName = service.getTrackName(); - CharSequence artistName = service.getArtistName(); - long albumId = service.getAlbumId(); - long songId = service.getAudioId(); - CharSequence errorState = null; - - // Format title string with track number, or show SD card message - String status = Environment.getExternalStorageState(); - if (status.equals(Environment.MEDIA_SHARED) - || status.equals(Environment.MEDIA_UNMOUNTED)) { - if (android.os.Environment.isExternalStorageRemovable()) { - errorState = res.getText(R.string.sdcard_busy_title); - } else { - errorState = res.getText(R.string.sdcard_busy_title_nosdcard); - } - } else if (status.equals(Environment.MEDIA_REMOVED)) { - if (android.os.Environment.isExternalStorageRemovable()) { - errorState = res.getText(R.string.sdcard_missing_title); - } else { - errorState = res - .getText(R.string.sdcard_missing_title_nosdcard); - } - } else if (titleName == null) { - errorState = res.getText(R.string.emptyplaylist); - } - - if (errorState != null) { - // Show error state to user - views.setViewVisibility(R.id.trackname, View.GONE); - views.setTextViewText(R.id.artist, errorState); - views.setViewVisibility(R.id.albumart, View.GONE); - } else { - // No error, so show normal titles and artwork - views.setViewVisibility(R.id.trackname, View.VISIBLE); - views.setTextViewText(R.id.trackname, titleName); - views.setTextViewText(R.id.artistname, artistName); - views.setViewVisibility(R.id.albumart, View.VISIBLE); - // Set album art - Uri uri = MusicUtils.getArtworkUri(service, songId, albumId); - if (uri != null) { - views.setImageViewUri(R.id.albumart, uri); - } else { - views.setImageViewResource(R.id.albumart, - R.drawable.albumart_mp_unknown); - } - } - - // Link actions buttons to intents - linkButtons(service, views); - - pushUpdate(service, appWidgetIds, views); - } - - /** - * Link up various button actions using {@link PendingIntents}. - * - * @param playerActive - * True if player is active in background, which means widget - * click will launch {@link MediaPlaybackActivity}, otherwise we - * launch {@link MusicBrowserActivity}. - */ - private void linkButtons(Context context, RemoteViews views) { - // Connect up various buttons and touch events - Intent intent; - PendingIntent pendingIntent; - - final ComponentName serviceName = new ComponentName(context, - MediaPlaybackService.class); - - intent = new Intent(MediaPlaybackService.TOGGLEPAUSE_ACTION); - intent.setComponent(serviceName); - pendingIntent = PendingIntent.getService(context, - 0 /* no requestCode */, intent, 0 /* no flags */); - views.setOnClickPendingIntent(R.id.albumart, pendingIntent); - - intent = new Intent(MediaPlaybackService.NEXT_ACTION); - intent.setComponent(serviceName); - pendingIntent = PendingIntent.getService(context, - 0 /* no requestCode */, intent, 0 /* no flags */); - views.setOnClickPendingIntent(R.id.next, pendingIntent); - - intent = new Intent(MediaPlaybackService.PREVIOUS_ACTION); - intent.setComponent(serviceName); - pendingIntent = PendingIntent.getService(context, - 0 /* no requestCode */, intent, 0 /* no flags */); - views.setOnClickPendingIntent(R.id.previous, pendingIntent); - } -} +/* + * 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. + */ + +package com.android.music; + +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.net.Uri; +import android.os.Environment; +import android.view.View; +import android.widget.RemoteViews; + +/** + * Simple widget to show currently playing album art along with play/pause and + * next track buttons. + */ +public class MediaAppWidgetProvider3x1 extends AppWidgetProvider { + static final String TAG = "MusicAppWidgetProvider3x1"; + + public static final String CMDAPPWIDGETUPDATE = "appwidgetupdate3x1"; + + private static MediaAppWidgetProvider3x1 sInstance; + + static synchronized MediaAppWidgetProvider3x1 getInstance() { + if (sInstance == null) { + sInstance = new MediaAppWidgetProvider3x1(); + } + return sInstance; + } + + @Override + public void onUpdate(Context context, AppWidgetManager appWidgetManager, + int[] appWidgetIds) { + defaultAppWidget(context, appWidgetIds); + + // Send broadcast intent to any running MediaPlaybackService so it can + // wrap around with an immediate update. + Intent updateIntent = new Intent(MediaPlaybackService.SERVICECMD); + updateIntent.putExtra(MediaPlaybackService.CMDNAME, + MediaAppWidgetProvider3x1.CMDAPPWIDGETUPDATE); + updateIntent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_IDS, + appWidgetIds); + updateIntent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY); + context.sendBroadcast(updateIntent); + } + + /** + * Initialize given widgets to default state, where we launch Music on + * default click and hide actions if service not running. + */ + private void defaultAppWidget(Context context, int[] appWidgetIds) { + final RemoteViews views = new RemoteViews(context.getPackageName(), + R.layout.album_appwidget3x1); + + views.setViewVisibility(R.id.albumart, View.VISIBLE); + + linkButtons(context, views /* not playing */); + 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 gm = AppWidgetManager.getInstance(context); + if (appWidgetIds != null) { + gm.updateAppWidget(appWidgetIds, views); + } else { + gm.updateAppWidget(new ComponentName(context, this.getClass()), + views); + } + } + + /** + * Check against {@link AppWidgetManager} if there are any instances of this + * widget. + */ + private boolean hasInstances(Context context) { + AppWidgetManager appWidgetManager = AppWidgetManager + .getInstance(context); + int[] appWidgetIds = appWidgetManager + .getAppWidgetIds(new ComponentName(context, this.getClass())); + return (appWidgetIds.length > 0); + } + + /** + * Handle a change notification coming over from + * {@link MediaPlaybackService} + */ + void notifyChange(MediaPlaybackService service, String what) { + if (hasInstances(service)) { + if (MediaPlaybackService.META_CHANGED.equals(what) + || MediaPlaybackService.PLAYSTATE_CHANGED.equals(what)) { + performUpdate(service, null); + } + } + } + + /** + * Update all active widget instances by pushing changes + */ + void performUpdate(MediaPlaybackService service, int[] appWidgetIds) { + final Resources res = service.getResources(); + final RemoteViews views = new RemoteViews(service.getPackageName(), + R.layout.album_appwidget3x1); + + CharSequence titleName = service.getTrackName(); + CharSequence artistName = service.getArtistName(); + long albumId = service.getAlbumId(); + long songId = service.getAudioId(); + CharSequence errorState = null; + + // Format title string with track number, or show SD card message + String status = Environment.getExternalStorageState(); + if (status.equals(Environment.MEDIA_SHARED) + || status.equals(Environment.MEDIA_UNMOUNTED)) { + if (android.os.Environment.isExternalStorageRemovable()) { + errorState = res.getText(R.string.sdcard_busy_title); + } else { + errorState = res.getText(R.string.sdcard_busy_title_nosdcard); + } + } else if (status.equals(Environment.MEDIA_REMOVED)) { + if (android.os.Environment.isExternalStorageRemovable()) { + errorState = res.getText(R.string.sdcard_missing_title); + } else { + errorState = res + .getText(R.string.sdcard_missing_title_nosdcard); + } + } else if (titleName == null) { + errorState = res.getText(R.string.emptyplaylist); + } + + if (errorState != null) { + // Show error state to user + views.setViewVisibility(R.id.trackname, View.GONE); + views.setTextViewText(R.id.artist, errorState); + views.setViewVisibility(R.id.albumart, View.GONE); + } else { + // No error, so show normal titles and artwork + views.setViewVisibility(R.id.trackname, View.VISIBLE); + views.setTextViewText(R.id.trackname, titleName); + views.setTextViewText(R.id.artistname, artistName); + views.setViewVisibility(R.id.albumart, View.VISIBLE); + // Set album art + Uri uri = MusicUtils.getArtworkUri(service, songId, albumId); + if (uri != null) { + views.setImageViewUri(R.id.albumart, uri); + } else { + views.setImageViewResource(R.id.albumart, + R.drawable.albumart_mp_unknown); + } + } + + // Link actions buttons to intents + linkButtons(service, views); + + pushUpdate(service, appWidgetIds, views); + } + + /** + * Link up various button actions using {@link PendingIntents}. + * + * @param playerActive + * True if player is active in background, which means widget + * click will launch {@link MediaPlaybackActivity}, otherwise we + * launch {@link MusicBrowserActivity}. + */ + private void linkButtons(Context context, RemoteViews views) { + // Connect up various buttons and touch events + Intent intent; + PendingIntent pendingIntent; + + final ComponentName serviceName = new ComponentName(context, + MediaPlaybackService.class); + + intent = new Intent(MediaPlaybackService.TOGGLEPAUSE_ACTION); + intent.setComponent(serviceName); + pendingIntent = PendingIntent.getService(context, + 0 /* no requestCode */, intent, 0 /* no flags */); + views.setOnClickPendingIntent(R.id.albumart, pendingIntent); + + intent = new Intent(MediaPlaybackService.NEXT_ACTION); + intent.setComponent(serviceName); + pendingIntent = PendingIntent.getService(context, + 0 /* no requestCode */, intent, 0 /* no flags */); + views.setOnClickPendingIntent(R.id.next, pendingIntent); + + intent = new Intent(MediaPlaybackService.PREVIOUS_ACTION); + intent.setComponent(serviceName); + pendingIntent = PendingIntent.getService(context, + 0 /* no requestCode */, intent, 0 /* no flags */); + views.setOnClickPendingIntent(R.id.previous, pendingIntent); + } +} diff --git a/src/com/android/music/MediaAppWidgetProvider4x1.java b/src/com/android/music/MediaAppWidgetProvider4x1.java index babd0ab..b9097f1 100644 --- a/src/com/android/music/MediaAppWidgetProvider4x1.java +++ b/src/com/android/music/MediaAppWidgetProvider4x1.java @@ -1,281 +1,281 @@ -/* - * 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. - */ - -package com.android.music; - -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.SharedPreferences; -import android.content.pm.PackageManager; -import android.content.pm.PackageManager.NameNotFoundException; -import android.content.res.Resources; -import android.graphics.Color; -import android.net.Uri; -import android.os.Environment; -import android.preference.PreferenceManager; -import android.view.View; -import android.widget.RemoteViews; - -/** - * Simple widget to show currently playing album art along with play/pause and - * next track buttons. - */ - -public class MediaAppWidgetProvider4x1 extends AppWidgetProvider { - static final String TAG = "MusicAppWidgetProvider"; - - public static final String CMDAPPWIDGETUPDATE = "appwidgetupdate"; - - private static MediaAppWidgetProvider4x1 sInstance; - - static synchronized MediaAppWidgetProvider4x1 getInstance() { - if (sInstance == null) { - sInstance = new MediaAppWidgetProvider4x1(); - } - return sInstance; - } - - @Override - public void onUpdate(Context context, AppWidgetManager appWidgetManager, - int[] appWidgetIds) { - defaultAppWidget(context, appWidgetIds); - - // Send broadcast intent to any running MediaPlaybackService so it can - // wrap around with an immediate update. - Intent updateIntent = new Intent(MediaPlaybackService.SERVICECMD); - updateIntent.putExtra(MediaPlaybackService.CMDNAME, - MediaAppWidgetProvider4x1.CMDAPPWIDGETUPDATE); - updateIntent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_IDS, - appWidgetIds); - updateIntent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY); - context.sendBroadcast(updateIntent); - } - - /** - * Initialize given widgets to default state, where we launch Music 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.album_appwidget4x1); - - views.setViewVisibility(R.id.title, View.GONE); - views.setTextViewText(R.id.artist, - res.getText(R.string.widget_initial_text)); - views.setViewVisibility(R.id.albumart, View.GONE); - - linkButtons(context, views, false /* not playing */); - 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 gm = AppWidgetManager.getInstance(context); - if (appWidgetIds != null) { - gm.updateAppWidget(appWidgetIds, views); - } else { - gm.updateAppWidget(new ComponentName(context, this.getClass()), - views); - } - } - - /** - * Check against {@link AppWidgetManager} if there are any instances of this - * widget. - */ - private boolean hasInstances(Context context) { - AppWidgetManager appWidgetManager = AppWidgetManager - .getInstance(context); - int[] appWidgetIds = appWidgetManager - .getAppWidgetIds(new ComponentName(context, this.getClass())); - return (appWidgetIds.length > 0); - } - - /** - * Handle a change notification coming over from - * {@link MediaPlaybackService} - */ - void notifyChange(MediaPlaybackService service, String what) { - if (hasInstances(service)) { - if (MediaPlaybackService.META_CHANGED.equals(what) - || MediaPlaybackService.PLAYSTATE_CHANGED.equals(what)) { - performUpdate(service, null); - } - } - } - - /** - * Update all active widget instances by pushing changes - */ - void performUpdate(MediaPlaybackService service, int[] appWidgetIds) { - final Resources res = service.getResources(); - final RemoteViews views = new RemoteViews(service.getPackageName(), - R.layout.album_appwidget4x1); - - CharSequence titleName = service.getTrackName(); - CharSequence artistName = service.getArtistName(); - long albumId = service.getAlbumId(); - long songId = service.getAudioId(); - CharSequence errorState = null; - - // Format title string with track number, or show SD card message - String status = Environment.getExternalStorageState(); - if (status.equals(Environment.MEDIA_SHARED) - || status.equals(Environment.MEDIA_UNMOUNTED)) { - if (android.os.Environment.isExternalStorageRemovable()) { - errorState = res.getText(R.string.sdcard_busy_title); - } else { - errorState = res.getText(R.string.sdcard_busy_title_nosdcard); - } - } else if (status.equals(Environment.MEDIA_REMOVED)) { - if (android.os.Environment.isExternalStorageRemovable()) { - errorState = res.getText(R.string.sdcard_missing_title); - } else { - errorState = res - .getText(R.string.sdcard_missing_title_nosdcard); - } - } else if (titleName == null) { - errorState = res.getText(R.string.emptyplaylist); - } - - SharedPreferences mPrefs = PreferenceManager - .getDefaultSharedPreferences(service); - int aColor = new Integer(mPrefs.getInt(null, - MusicSettingsActivity.DEFAULT_SCREENSAVER_COLOR_ALPHA)); - int rColor = new Integer(mPrefs.getInt(null, - MusicSettingsActivity.DEFAULT_SCREENSAVER_COLOR_RED)); - int gColor = new Integer(mPrefs.getInt(null, - MusicSettingsActivity.DEFAULT_SCREENSAVER_COLOR_GREEN)); - int bColor = new Integer(mPrefs.getInt(null, - MusicSettingsActivity.DEFAULT_SCREENSAVER_COLOR_BLUE)); - - int SCREEN_SAVER_COLOR_DIM = Color.argb(aColor, rColor, gColor, bColor); - if (errorState != null) { - // Show error state to user - views.setViewVisibility(R.id.title, View.GONE); - views.setTextViewText(R.id.artist, errorState); - views.setViewVisibility(R.id.albumart, View.GONE); - } else { - // No error, so show normal titles and artwork - views.setViewVisibility(R.id.title, View.VISIBLE); - views.setTextViewText(R.id.title, titleName); - views.setTextViewText(R.id.artist, artistName); - views.setViewVisibility(R.id.albumart, View.VISIBLE); - views.setTextColor(R.id.title, SCREEN_SAVER_COLOR_DIM); - views.setTextColor(R.id.artist, SCREEN_SAVER_COLOR_DIM); - // Set album art - Uri uri = MusicUtils.getArtworkUri(service, songId, albumId); - if (uri != null) { - views.setImageViewUri(R.id.albumart, uri); - } else { - views.setImageViewResource(R.id.albumart, - R.drawable.albumart_mp_unknown); - } - } - - // Set correct drawable for pause state - final boolean playing = service.isPlaying(); - if (playing) { - views.setImageViewResource(R.id.control_play, - R.drawable.ic_media_pause); - } else { - views.setImageViewResource(R.id.control_play, - R.drawable.ic_appwidget_music_play); - } - - // Link actions buttons to intents - linkButtons(service, views, playing); - - pushUpdate(service, appWidgetIds, views); - } - - /** - * Link up various button actions using {@link PendingIntents}. - * - * @param playerActive - * True if player is active in background, which means widget - * click will launch {@link MediaPlaybackActivity}, otherwise we - * launch {@link MusicBrowserActivity}. - */ - private void linkButtons(Context context, RemoteViews views, - boolean playerActive) { - - // ADW: Load the specified theme - String themePackage = MusicUtils.getThemePackageName(context, - MusicSettingsActivity.THEME_DEFAULT); - PackageManager pm = context.getPackageManager(); - Resources themeResources = null; - if (!themePackage.equals(MusicSettingsActivity.THEME_DEFAULT)) { - try { - themeResources = pm.getResourcesForApplication(themePackage); - } catch (NameNotFoundException e) { - // ADW The saved theme was uninstalled so we save the - // default one - MusicUtils.setThemePackageName(context, - MusicSettingsActivity.THEME_DEFAULT); - } - int trackName = themeResources.getIdentifier( - "four_by_one_track_name", "color", themePackage); - if (trackName != 0) { - views.setTextColor(R.id.trackname, - themeResources.getColor(trackName)); - } - int artistName = themeResources.getIdentifier( - "four_by_one_artist_name", "color", themePackage); - if (artistName != 0) { - views.setTextColor(R.id.artistname, - themeResources.getColor(artistName)); - } - } - // Connect up various buttons and touch events - Intent intent; - PendingIntent pendingIntent; - - final ComponentName serviceName = new ComponentName(context, - MediaPlaybackService.class); - - if (playerActive) { - intent = new Intent(context, MediaPlaybackActivity.class); - pendingIntent = PendingIntent.getActivity(context, 0, intent, 0); - views.setOnClickPendingIntent(R.id.album_appwidget, pendingIntent); - views.setOnClickPendingIntent(R.id.albumart, pendingIntent); - } else { - intent = new Intent(context, MusicBrowserActivity.class); - pendingIntent = PendingIntent.getActivity(context, 0, intent, 0); - views.setOnClickPendingIntent(R.id.album_appwidget, pendingIntent); - views.setOnClickPendingIntent(R.id.albumart, pendingIntent); - } - - intent = new Intent(MediaPlaybackService.TOGGLEPAUSE_ACTION); - intent.setComponent(serviceName); - pendingIntent = PendingIntent.getService(context, - 0 /* no requestCode */, intent, 0 /* no flags */); - views.setOnClickPendingIntent(R.id.control_play, pendingIntent); - - intent = new Intent(MediaPlaybackService.NEXT_ACTION); - intent.setComponent(serviceName); - pendingIntent = PendingIntent.getService(context, - 0 /* no requestCode */, intent, 0 /* no flags */); - views.setOnClickPendingIntent(R.id.control_next, pendingIntent); - } -} +/* + * 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. + */ + +package com.android.music; + +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.SharedPreferences; +import android.content.pm.PackageManager; +import android.content.pm.PackageManager.NameNotFoundException; +import android.content.res.Resources; +import android.graphics.Color; +import android.net.Uri; +import android.os.Environment; +import android.preference.PreferenceManager; +import android.view.View; +import android.widget.RemoteViews; + +/** + * Simple widget to show currently playing album art along with play/pause and + * next track buttons. + */ + +public class MediaAppWidgetProvider4x1 extends AppWidgetProvider { + static final String TAG = "MusicAppWidgetProvider"; + + public static final String CMDAPPWIDGETUPDATE = "appwidgetupdate"; + + private static MediaAppWidgetProvider4x1 sInstance; + + static synchronized MediaAppWidgetProvider4x1 getInstance() { + if (sInstance == null) { + sInstance = new MediaAppWidgetProvider4x1(); + } + return sInstance; + } + + @Override + public void onUpdate(Context context, AppWidgetManager appWidgetManager, + int[] appWidgetIds) { + defaultAppWidget(context, appWidgetIds); + + // Send broadcast intent to any running MediaPlaybackService so it can + // wrap around with an immediate update. + Intent updateIntent = new Intent(MediaPlaybackService.SERVICECMD); + updateIntent.putExtra(MediaPlaybackService.CMDNAME, + MediaAppWidgetProvider4x1.CMDAPPWIDGETUPDATE); + updateIntent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_IDS, + appWidgetIds); + updateIntent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY); + context.sendBroadcast(updateIntent); + } + + /** + * Initialize given widgets to default state, where we launch Music 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.album_appwidget4x1); + + views.setViewVisibility(R.id.title, View.GONE); + views.setTextViewText(R.id.artist, + res.getText(R.string.widget_initial_text)); + views.setViewVisibility(R.id.albumart, View.GONE); + + linkButtons(context, views, false /* not playing */); + 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 gm = AppWidgetManager.getInstance(context); + if (appWidgetIds != null) { + gm.updateAppWidget(appWidgetIds, views); + } else { + gm.updateAppWidget(new ComponentName(context, this.getClass()), + views); + } + } + + /** + * Check against {@link AppWidgetManager} if there are any instances of this + * widget. + */ + private boolean hasInstances(Context context) { + AppWidgetManager appWidgetManager = AppWidgetManager + .getInstance(context); + int[] appWidgetIds = appWidgetManager + .getAppWidgetIds(new ComponentName(context, this.getClass())); + return (appWidgetIds.length > 0); + } + + /** + * Handle a change notification coming over from + * {@link MediaPlaybackService} + */ + void notifyChange(MediaPlaybackService service, String what) { + if (hasInstances(service)) { + if (MediaPlaybackService.META_CHANGED.equals(what) + || MediaPlaybackService.PLAYSTATE_CHANGED.equals(what)) { + performUpdate(service, null); + } + } + } + + /** + * Update all active widget instances by pushing changes + */ + void performUpdate(MediaPlaybackService service, int[] appWidgetIds) { + final Resources res = service.getResources(); + final RemoteViews views = new RemoteViews(service.getPackageName(), + R.layout.album_appwidget4x1); + + CharSequence titleName = service.getTrackName(); + CharSequence artistName = service.getArtistName(); + long albumId = service.getAlbumId(); + long songId = service.getAudioId(); + CharSequence errorState = null; + + // Format title string with track number, or show SD card message + String status = Environment.getExternalStorageState(); + if (status.equals(Environment.MEDIA_SHARED) + || status.equals(Environment.MEDIA_UNMOUNTED)) { + if (android.os.Environment.isExternalStorageRemovable()) { + errorState = res.getText(R.string.sdcard_busy_title); + } else { + errorState = res.getText(R.string.sdcard_busy_title_nosdcard); + } + } else if (status.equals(Environment.MEDIA_REMOVED)) { + if (android.os.Environment.isExternalStorageRemovable()) { + errorState = res.getText(R.string.sdcard_missing_title); + } else { + errorState = res + .getText(R.string.sdcard_missing_title_nosdcard); + } + } else if (titleName == null) { + errorState = res.getText(R.string.emptyplaylist); + } + + SharedPreferences mPrefs = PreferenceManager + .getDefaultSharedPreferences(service); + int aColor = new Integer(mPrefs.getInt(null, + MusicSettingsActivity.DEFAULT_SCREENSAVER_COLOR_ALPHA)); + int rColor = new Integer(mPrefs.getInt(null, + MusicSettingsActivity.DEFAULT_SCREENSAVER_COLOR_RED)); + int gColor = new Integer(mPrefs.getInt(null, + MusicSettingsActivity.DEFAULT_SCREENSAVER_COLOR_GREEN)); + int bColor = new Integer(mPrefs.getInt(null, + MusicSettingsActivity.DEFAULT_SCREENSAVER_COLOR_BLUE)); + + int SCREEN_SAVER_COLOR_DIM = Color.argb(aColor, rColor, gColor, bColor); + if (errorState != null) { + // Show error state to user + views.setViewVisibility(R.id.title, View.GONE); + views.setTextViewText(R.id.artist, errorState); + views.setViewVisibility(R.id.albumart, View.GONE); + } else { + // No error, so show normal titles and artwork + views.setViewVisibility(R.id.title, View.VISIBLE); + views.setTextViewText(R.id.title, titleName); + views.setTextViewText(R.id.artist, artistName); + views.setViewVisibility(R.id.albumart, View.VISIBLE); + views.setTextColor(R.id.title, SCREEN_SAVER_COLOR_DIM); + views.setTextColor(R.id.artist, SCREEN_SAVER_COLOR_DIM); + // Set album art + Uri uri = MusicUtils.getArtworkUri(service, songId, albumId); + if (uri != null) { + views.setImageViewUri(R.id.albumart, uri); + } else { + views.setImageViewResource(R.id.albumart, + R.drawable.albumart_mp_unknown); + } + } + + // Set correct drawable for pause state + final boolean playing = service.isPlaying(); + if (playing) { + views.setImageViewResource(R.id.control_play, + R.drawable.ic_media_pause); + } else { + views.setImageViewResource(R.id.control_play, + R.drawable.ic_appwidget_music_play); + } + + // Link actions buttons to intents + linkButtons(service, views, playing); + + pushUpdate(service, appWidgetIds, views); + } + + /** + * Link up various button actions using {@link PendingIntents}. + * + * @param playerActive + * True if player is active in background, which means widget + * click will launch {@link MediaPlaybackActivity}, otherwise we + * launch {@link MusicBrowserActivity}. + */ + private void linkButtons(Context context, RemoteViews views, + boolean playerActive) { + + // ADW: Load the specified theme + String themePackage = MusicUtils.getThemePackageName(context, + MusicSettingsActivity.THEME_DEFAULT); + PackageManager pm = context.getPackageManager(); + Resources themeResources = null; + if (!themePackage.equals(MusicSettingsActivity.THEME_DEFAULT)) { + try { + themeResources = pm.getResourcesForApplication(themePackage); + } catch (NameNotFoundException e) { + // ADW The saved theme was uninstalled so we save the + // default one + MusicUtils.setThemePackageName(context, + MusicSettingsActivity.THEME_DEFAULT); + } + int trackName = themeResources.getIdentifier( + "four_by_one_track_name", "color", themePackage); + if (trackName != 0) { + views.setTextColor(R.id.trackname, + themeResources.getColor(trackName)); + } + int artistName = themeResources.getIdentifier( + "four_by_one_artist_name", "color", themePackage); + if (artistName != 0) { + views.setTextColor(R.id.artistname, + themeResources.getColor(artistName)); + } + } + // Connect up various buttons and touch events + Intent intent; + PendingIntent pendingIntent; + + final ComponentName serviceName = new ComponentName(context, + MediaPlaybackService.class); + + if (playerActive) { + intent = new Intent(context, MediaPlaybackActivity.class); + pendingIntent = PendingIntent.getActivity(context, 0, intent, 0); + views.setOnClickPendingIntent(R.id.album_appwidget, pendingIntent); + views.setOnClickPendingIntent(R.id.albumart, pendingIntent); + } else { + intent = new Intent(context, MusicBrowserActivity.class); + pendingIntent = PendingIntent.getActivity(context, 0, intent, 0); + views.setOnClickPendingIntent(R.id.album_appwidget, pendingIntent); + views.setOnClickPendingIntent(R.id.albumart, pendingIntent); + } + + intent = new Intent(MediaPlaybackService.TOGGLEPAUSE_ACTION); + intent.setComponent(serviceName); + pendingIntent = PendingIntent.getService(context, + 0 /* no requestCode */, intent, 0 /* no flags */); + views.setOnClickPendingIntent(R.id.control_play, pendingIntent); + + intent = new Intent(MediaPlaybackService.NEXT_ACTION); + intent.setComponent(serviceName); + pendingIntent = PendingIntent.getService(context, + 0 /* no requestCode */, intent, 0 /* no flags */); + views.setOnClickPendingIntent(R.id.control_next, pendingIntent); + } +} diff --git a/src/com/android/music/MediaAppWidgetProvider4x2.java b/src/com/android/music/MediaAppWidgetProvider4x2.java index 8dd335d..21c4420 100644 --- a/src/com/android/music/MediaAppWidgetProvider4x2.java +++ b/src/com/android/music/MediaAppWidgetProvider4x2.java @@ -1,349 +1,349 @@ -/* - * 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. - */ - -package com.android.music; - -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.SharedPreferences; -import android.content.pm.PackageManager; -import android.content.pm.PackageManager.NameNotFoundException; -import android.content.res.Resources; -import android.graphics.Color; -import android.net.Uri; -import android.os.Environment; -import android.preference.PreferenceManager; -import android.view.View; -import android.widget.RemoteViews; - -/** - * Simple widget to show currently playing album art along with play/pause and - * next track buttons. - */ -public class MediaAppWidgetProvider4x2 extends AppWidgetProvider { - static final String TAG = "MusicAppWidgetProvider4x2"; - - public static final String CMDAPPWIDGETUPDATE = "appwidgetupdate4x2"; - - // ADW Theme constants - public static final int THEME_ITEM_BACKGROUND = 0; - public static final int THEME_ITEM_FOREGROUND = 1; - private static MediaAppWidgetProvider4x2 sInstance; - - static synchronized MediaAppWidgetProvider4x2 getInstance() { - if (sInstance == null) { - sInstance = new MediaAppWidgetProvider4x2(); - } - return sInstance; - } - - @Override - public void onUpdate(Context context, AppWidgetManager appWidgetManager, - int[] appWidgetIds) { - defaultAppWidget(context, appWidgetIds); - - // Send broadcast intent to any running MediaPlaybackService so it can - // wrap around with an immediate update. - Intent updateIntent = new Intent(MediaPlaybackService.SERVICECMD); - updateIntent.putExtra(MediaPlaybackService.CMDNAME, - MediaAppWidgetProvider4x2.CMDAPPWIDGETUPDATE); - updateIntent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_IDS, - appWidgetIds); - updateIntent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY); - context.sendBroadcast(updateIntent); - } - - /** - * Initialize given widgets to default state, where we launch Music 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.album_appwidget4x2); - - views.setViewVisibility(R.id.albumname, View.GONE); - views.setViewVisibility(R.id.trackname, View.GONE); - views.setTextViewText(R.id.artistname, - res.getText(R.string.widget_initial_text)); - views.setImageViewResource(R.id.albumart, - R.drawable.albumart_mp_unknown); - - linkButtons(context, views, false /* not playing */); - 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 gm = AppWidgetManager.getInstance(context); - if (appWidgetIds != null) { - gm.updateAppWidget(appWidgetIds, views); - } else { - gm.updateAppWidget(new ComponentName(context, this.getClass()), - views); - } - } - - /** - * Check against {@link AppWidgetManager} if there are any instances of this - * widget. - */ - private boolean hasInstances(Context context) { - AppWidgetManager appWidgetManager = AppWidgetManager - .getInstance(context); - int[] appWidgetIds = appWidgetManager - .getAppWidgetIds(new ComponentName(context, this.getClass())); - return (appWidgetIds.length > 0); - } - - /** - * Handle a change notification coming over from - * {@link MediaPlaybackService} - */ - void notifyChange(MediaPlaybackService service, String what) { - if (hasInstances(service)) { - if (MediaPlaybackService.META_CHANGED.equals(what) - || MediaPlaybackService.PROGRESSBAR_CHANGED.equals(what) - || MediaPlaybackService.PLAYSTATE_CHANGED.equals(what) - || MediaPlaybackService.REPEATMODE_CHANGED.equals(what) - || MediaPlaybackService.SHUFFLEMODE_CHANGED.equals(what)) { - performUpdate(service, null); - } - } - } - - /** - * Update all active widget instances by pushing changes - */ - void performUpdate(MediaPlaybackService service, int[] appWidgetIds) { - final Resources res = service.getResources(); - final RemoteViews views = new RemoteViews(service.getPackageName(), - R.layout.album_appwidget4x2); - - CharSequence artistName = service.getArtistName(); - CharSequence albumName = service.getAlbumName(); - CharSequence trackName = service.getTrackName(); - long albumId = service.getAlbumId(); - long songId = service.getAudioId(); - long pos = service.position(); - long dur = service.duration(); - CharSequence errorState = null; - - // Format title string with track number, or show SD card message - String status = Environment.getExternalStorageState(); - if (status.equals(Environment.MEDIA_SHARED) - || status.equals(Environment.MEDIA_UNMOUNTED)) { - if (android.os.Environment.isExternalStorageRemovable()) { - errorState = res.getText(R.string.sdcard_busy_title); - } else { - errorState = res.getText(R.string.sdcard_busy_title_nosdcard); - } - } else if (status.equals(Environment.MEDIA_REMOVED)) { - if (android.os.Environment.isExternalStorageRemovable()) { - errorState = res.getText(R.string.sdcard_missing_title); - } else { - errorState = res - .getText(R.string.sdcard_missing_title_nosdcard); - } - } else if (trackName == null) { - errorState = res.getText(R.string.emptyplaylist); - } - SharedPreferences mPrefs = PreferenceManager - .getDefaultSharedPreferences(service); - int aColor = new Integer(mPrefs.getInt(null, - MusicSettingsActivity.DEFAULT_SCREENSAVER_COLOR_ALPHA)); - int rColor = new Integer(mPrefs.getInt(null, - MusicSettingsActivity.DEFAULT_SCREENSAVER_COLOR_RED)); - int gColor = new Integer(mPrefs.getInt(null, - MusicSettingsActivity.DEFAULT_SCREENSAVER_COLOR_GREEN)); - int bColor = new Integer(mPrefs.getInt(null, - MusicSettingsActivity.DEFAULT_SCREENSAVER_COLOR_BLUE)); - int SCREEN_SAVER_COLOR_DIM = Color.argb(aColor, rColor, gColor, bColor); - - if (errorState != null) { - // Show error state to user - views.setViewVisibility(R.id.albumname, View.GONE); - views.setViewVisibility(R.id.trackname, View.GONE); - views.setTextViewText(R.id.artistname, errorState); - views.setImageViewResource(R.id.albumart, - R.drawable.albumart_mp_unknown); - } else { - // No error, so show normal titles and artwork - views.setViewVisibility(R.id.albumname, View.VISIBLE); - views.setViewVisibility(R.id.trackname, View.VISIBLE); - views.setTextViewText(R.id.artistname, " " + artistName); - views.setTextViewText(R.id.albumname, " " + albumName); - views.setTextViewText(R.id.trackname, " " + trackName); - views.setTextColor(R.id.artistname, SCREEN_SAVER_COLOR_DIM); - views.setTextColor(R.id.albumname, SCREEN_SAVER_COLOR_DIM); - views.setTextColor(R.id.trackname, SCREEN_SAVER_COLOR_DIM); - views.setProgressBar(R.id.progress, 1000, (int) (1000 * pos / dur), - false); - - // Set album art - Uri uri = MusicUtils.getArtworkUri(service, songId, albumId); - if (uri != null) { - views.setImageViewUri(R.id.albumart, uri); - } else { - views.setImageViewResource(R.id.albumart, - R.drawable.albumart_mp_unknown); - } - } - - // Set correct drawable for pause state - final boolean playing = service.isPlaying(); - if (playing) { - views.setImageViewResource(R.id.control_play, - R.drawable.ic_media_pause); - } else { - views.setImageViewResource(R.id.control_play, - R.drawable.ic_appwidget_music_play); - } - - // Set correct drawable for repeat state - switch (service.getRepeatMode()) { - case MediaPlaybackService.REPEAT_ALL: - views.setImageViewResource(R.id.control_repeat, - R.drawable.ic_mp_repeat_all_btn); - break; - case MediaPlaybackService.REPEAT_CURRENT: - views.setImageViewResource(R.id.control_repeat, - R.drawable.ic_mp_repeat_once_btn); - break; - default: - views.setImageViewResource(R.id.control_repeat, - R.drawable.ic_mp_repeat_off_btn); - break; - } - - // Set correct drawable for shuffle state - switch (service.getShuffleMode()) { - case MediaPlaybackService.SHUFFLE_NONE: - views.setImageViewResource(R.id.control_shuffle, - R.drawable.ic_mp_shuffle_off_btn); - break; - case MediaPlaybackService.SHUFFLE_AUTO: - views.setImageViewResource(R.id.control_shuffle, - R.drawable.ic_mp_partyshuffle_on_btn); - break; - default: - views.setImageViewResource(R.id.control_shuffle, - R.drawable.ic_mp_shuffle_on_btn); - break; - } - // Link actions buttons to intents - linkButtons(service, views, playing); - - pushUpdate(service, appWidgetIds, views); - - } - - /** - * Link up various button actions using {@link PendingIntents}. - * - * @param playerActive - * True if player is active in background, which means widget - * click will launch {@link MediaPlaybackActivity}, otherwise we - * launch {@link MusicBrowserActivity}. - */ - private void linkButtons(Context context, RemoteViews views, - boolean playerActive) { - - // ADW: Load the specified theme - String themePackage = MusicUtils.getThemePackageName(context, - MusicSettingsActivity.THEME_DEFAULT); - PackageManager pm = context.getPackageManager(); - Resources themeResources = null; - if (!themePackage.equals(MusicSettingsActivity.THEME_DEFAULT)) { - try { - themeResources = pm.getResourcesForApplication(themePackage); - } catch (NameNotFoundException e) { - // ADW The saved theme was uninstalled so we save the - // default one - MusicUtils.setThemePackageName(context, - MusicSettingsActivity.THEME_DEFAULT); - } - int albumName = themeResources.getIdentifier( - "four_by_two_album_name", "color", themePackage); - if (albumName != 0) { - views.setTextColor(R.id.albumname, - themeResources.getColor(albumName)); - } - int trackName = themeResources.getIdentifier( - "four_by_two_track_name", "color", themePackage); - if (trackName != 0) { - views.setTextColor(R.id.trackname, - themeResources.getColor(trackName)); - } - int artistName = themeResources.getIdentifier( - "four_by_two_artist_name", "color", themePackage); - if (artistName != 0) { - views.setTextColor(R.id.artistname, - themeResources.getColor(artistName)); - } - } - - // Connect up various buttons and touch events - Intent intent; - PendingIntent pendingIntent; - - final ComponentName serviceName = new ComponentName(context, - MediaPlaybackService.class); - - if (playerActive) { - intent = new Intent(context, MediaPlaybackActivity.class); - pendingIntent = PendingIntent.getActivity(context, 0, intent, 0); - views.setOnClickPendingIntent(R.id.albumart, pendingIntent); - views.setOnClickPendingIntent(R.id.info, pendingIntent); - } else { - intent = new Intent(context, MusicBrowserActivity.class); - pendingIntent = PendingIntent.getActivity(context, 0, intent, 0); - views.setOnClickPendingIntent(R.id.albumart, pendingIntent); - views.setOnClickPendingIntent(R.id.info, pendingIntent); - } - - intent = new Intent(MediaPlaybackService.TOGGLEPAUSE_ACTION); - intent.setComponent(serviceName); - pendingIntent = PendingIntent.getService(context, 0, intent, 0); - views.setOnClickPendingIntent(R.id.control_play, pendingIntent); - - intent = new Intent(MediaPlaybackService.NEXT_ACTION); - intent.setComponent(serviceName); - pendingIntent = PendingIntent.getService(context, 0, intent, 0); - views.setOnClickPendingIntent(R.id.control_next, pendingIntent); - - intent = new Intent(MediaPlaybackService.PREVIOUS_ACTION); - intent.setComponent(serviceName); - pendingIntent = PendingIntent.getService(context, 0, intent, 0); - views.setOnClickPendingIntent(R.id.control_prev, pendingIntent); - - intent = new Intent(MediaPlaybackService.CYCLEREPEAT_ACTION); - intent.setComponent(serviceName); - pendingIntent = PendingIntent.getService(context, 0, intent, 0); - views.setOnClickPendingIntent(R.id.control_repeat, pendingIntent); - - intent = new Intent(MediaPlaybackService.TOGGLESHUFFLE_ACTION); - intent.setComponent(serviceName); - pendingIntent = PendingIntent.getService(context, 0, intent, 0); - views.setOnClickPendingIntent(R.id.control_shuffle, pendingIntent); - } -} +/* + * 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. + */ + +package com.android.music; + +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.SharedPreferences; +import android.content.pm.PackageManager; +import android.content.pm.PackageManager.NameNotFoundException; +import android.content.res.Resources; +import android.graphics.Color; +import android.net.Uri; +import android.os.Environment; +import android.preference.PreferenceManager; +import android.view.View; +import android.widget.RemoteViews; + +/** + * Simple widget to show currently playing album art along with play/pause and + * next track buttons. + */ +public class MediaAppWidgetProvider4x2 extends AppWidgetProvider { + static final String TAG = "MusicAppWidgetProvider4x2"; + + public static final String CMDAPPWIDGETUPDATE = "appwidgetupdate4x2"; + + // ADW Theme constants + public static final int THEME_ITEM_BACKGROUND = 0; + public static final int THEME_ITEM_FOREGROUND = 1; + private static MediaAppWidgetProvider4x2 sInstance; + + static synchronized MediaAppWidgetProvider4x2 getInstance() { + if (sInstance == null) { + sInstance = new MediaAppWidgetProvider4x2(); + } + return sInstance; + } + + @Override + public void onUpdate(Context context, AppWidgetManager appWidgetManager, + int[] appWidgetIds) { + defaultAppWidget(context, appWidgetIds); + + // Send broadcast intent to any running MediaPlaybackService so it can + // wrap around with an immediate update. + Intent updateIntent = new Intent(MediaPlaybackService.SERVICECMD); + updateIntent.putExtra(MediaPlaybackService.CMDNAME, + MediaAppWidgetProvider4x2.CMDAPPWIDGETUPDATE); + updateIntent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_IDS, + appWidgetIds); + updateIntent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY); + context.sendBroadcast(updateIntent); + } + + /** + * Initialize given widgets to default state, where we launch Music 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.album_appwidget4x2); + + views.setViewVisibility(R.id.albumname, View.GONE); + views.setViewVisibility(R.id.trackname, View.GONE); + views.setTextViewText(R.id.artistname, + res.getText(R.string.widget_initial_text)); + views.setImageViewResource(R.id.albumart, + R.drawable.albumart_mp_unknown); + + linkButtons(context, views, false /* not playing */); + 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 gm = AppWidgetManager.getInstance(context); + if (appWidgetIds != null) { + gm.updateAppWidget(appWidgetIds, views); + } else { + gm.updateAppWidget(new ComponentName(context, this.getClass()), + views); + } + } + + /** + * Check against {@link AppWidgetManager} if there are any instances of this + * widget. + */ + private boolean hasInstances(Context context) { + AppWidgetManager appWidgetManager = AppWidgetManager + .getInstance(context); + int[] appWidgetIds = appWidgetManager + .getAppWidgetIds(new ComponentName(context, this.getClass())); + return (appWidgetIds.length > 0); + } + + /** + * Handle a change notification coming over from + * {@link MediaPlaybackService} + */ + void notifyChange(MediaPlaybackService service, String what) { + if (hasInstances(service)) { + if (MediaPlaybackService.META_CHANGED.equals(what) + || MediaPlaybackService.PROGRESSBAR_CHANGED.equals(what) + || MediaPlaybackService.PLAYSTATE_CHANGED.equals(what) + || MediaPlaybackService.REPEATMODE_CHANGED.equals(what) + || MediaPlaybackService.SHUFFLEMODE_CHANGED.equals(what)) { + performUpdate(service, null); + } + } + } + + /** + * Update all active widget instances by pushing changes + */ + void performUpdate(MediaPlaybackService service, int[] appWidgetIds) { + final Resources res = service.getResources(); + final RemoteViews views = new RemoteViews(service.getPackageName(), + R.layout.album_appwidget4x2); + + CharSequence artistName = service.getArtistName(); + CharSequence albumName = service.getAlbumName(); + CharSequence trackName = service.getTrackName(); + long albumId = service.getAlbumId(); + long songId = service.getAudioId(); + long pos = service.position(); + long dur = service.duration(); + CharSequence errorState = null; + + // Format title string with track number, or show SD card message + String status = Environment.getExternalStorageState(); + if (status.equals(Environment.MEDIA_SHARED) + || status.equals(Environment.MEDIA_UNMOUNTED)) { + if (android.os.Environment.isExternalStorageRemovable()) { + errorState = res.getText(R.string.sdcard_busy_title); + } else { + errorState = res.getText(R.string.sdcard_busy_title_nosdcard); + } + } else if (status.equals(Environment.MEDIA_REMOVED)) { + if (android.os.Environment.isExternalStorageRemovable()) { + errorState = res.getText(R.string.sdcard_missing_title); + } else { + errorState = res + .getText(R.string.sdcard_missing_title_nosdcard); + } + } else if (trackName == null) { + errorState = res.getText(R.string.emptyplaylist); + } + SharedPreferences mPrefs = PreferenceManager + .getDefaultSharedPreferences(service); + int aColor = new Integer(mPrefs.getInt(null, + MusicSettingsActivity.DEFAULT_SCREENSAVER_COLOR_ALPHA)); + int rColor = new Integer(mPrefs.getInt(null, + MusicSettingsActivity.DEFAULT_SCREENSAVER_COLOR_RED)); + int gColor = new Integer(mPrefs.getInt(null, + MusicSettingsActivity.DEFAULT_SCREENSAVER_COLOR_GREEN)); + int bColor = new Integer(mPrefs.getInt(null, + MusicSettingsActivity.DEFAULT_SCREENSAVER_COLOR_BLUE)); + int SCREEN_SAVER_COLOR_DIM = Color.argb(aColor, rColor, gColor, bColor); + + if (errorState != null) { + // Show error state to user + views.setViewVisibility(R.id.albumname, View.GONE); + views.setViewVisibility(R.id.trackname, View.GONE); + views.setTextViewText(R.id.artistname, errorState); + views.setImageViewResource(R.id.albumart, + R.drawable.albumart_mp_unknown); + } else { + // No error, so show normal titles and artwork + views.setViewVisibility(R.id.albumname, View.VISIBLE); + views.setViewVisibility(R.id.trackname, View.VISIBLE); + views.setTextViewText(R.id.artistname, " " + artistName); + views.setTextViewText(R.id.albumname, " " + albumName); + views.setTextViewText(R.id.trackname, " " + trackName); + views.setTextColor(R.id.artistname, SCREEN_SAVER_COLOR_DIM); + views.setTextColor(R.id.albumname, SCREEN_SAVER_COLOR_DIM); + views.setTextColor(R.id.trackname, SCREEN_SAVER_COLOR_DIM); + views.setProgressBar(R.id.progress, 1000, (int) (1000 * pos / dur), + false); + + // Set album art + Uri uri = MusicUtils.getArtworkUri(service, songId, albumId); + if (uri != null) { + views.setImageViewUri(R.id.albumart, uri); + } else { + views.setImageViewResource(R.id.albumart, + R.drawable.albumart_mp_unknown); + } + } + + // Set correct drawable for pause state + final boolean playing = service.isPlaying(); + if (playing) { + views.setImageViewResource(R.id.control_play, + R.drawable.ic_media_pause); + } else { + views.setImageViewResource(R.id.control_play, + R.drawable.ic_appwidget_music_play); + } + + // Set correct drawable for repeat state + switch (service.getRepeatMode()) { + case MediaPlaybackService.REPEAT_ALL: + views.setImageViewResource(R.id.control_repeat, + R.drawable.ic_mp_repeat_all_btn); + break; + case MediaPlaybackService.REPEAT_CURRENT: + views.setImageViewResource(R.id.control_repeat, + R.drawable.ic_mp_repeat_once_btn); + break; + default: + views.setImageViewResource(R.id.control_repeat, + R.drawable.ic_mp_repeat_off_btn); + break; + } + + // Set correct drawable for shuffle state + switch (service.getShuffleMode()) { + case MediaPlaybackService.SHUFFLE_NONE: + views.setImageViewResource(R.id.control_shuffle, + R.drawable.ic_mp_shuffle_off_btn); + break; + case MediaPlaybackService.SHUFFLE_AUTO: + views.setImageViewResource(R.id.control_shuffle, + R.drawable.ic_mp_partyshuffle_on_btn); + break; + default: + views.setImageViewResource(R.id.control_shuffle, + R.drawable.ic_mp_shuffle_on_btn); + break; + } + // Link actions buttons to intents + linkButtons(service, views, playing); + + pushUpdate(service, appWidgetIds, views); + + } + + /** + * Link up various button actions using {@link PendingIntents}. + * + * @param playerActive + * True if player is active in background, which means widget + * click will launch {@link MediaPlaybackActivity}, otherwise we + * launch {@link MusicBrowserActivity}. + */ + private void linkButtons(Context context, RemoteViews views, + boolean playerActive) { + + // ADW: Load the specified theme + String themePackage = MusicUtils.getThemePackageName(context, + MusicSettingsActivity.THEME_DEFAULT); + PackageManager pm = context.getPackageManager(); + Resources themeResources = null; + if (!themePackage.equals(MusicSettingsActivity.THEME_DEFAULT)) { + try { + themeResources = pm.getResourcesForApplication(themePackage); + } catch (NameNotFoundException e) { + // ADW The saved theme was uninstalled so we save the + // default one + MusicUtils.setThemePackageName(context, + MusicSettingsActivity.THEME_DEFAULT); + } + int albumName = themeResources.getIdentifier( + "four_by_two_album_name", "color", themePackage); + if (albumName != 0) { + views.setTextColor(R.id.albumname, + themeResources.getColor(albumName)); + } + int trackName = themeResources.getIdentifier( + "four_by_two_track_name", "color", themePackage); + if (trackName != 0) { + views.setTextColor(R.id.trackname, + themeResources.getColor(trackName)); + } + int artistName = themeResources.getIdentifier( + "four_by_two_artist_name", "color", themePackage); + if (artistName != 0) { + views.setTextColor(R.id.artistname, + themeResources.getColor(artistName)); + } + } + + // Connect up various buttons and touch events + Intent intent; + PendingIntent pendingIntent; + + final ComponentName serviceName = new ComponentName(context, + MediaPlaybackService.class); + + if (playerActive) { + intent = new Intent(context, MediaPlaybackActivity.class); + pendingIntent = PendingIntent.getActivity(context, 0, intent, 0); + views.setOnClickPendingIntent(R.id.albumart, pendingIntent); + views.setOnClickPendingIntent(R.id.info, pendingIntent); + } else { + intent = new Intent(context, MusicBrowserActivity.class); + pendingIntent = PendingIntent.getActivity(context, 0, intent, 0); + views.setOnClickPendingIntent(R.id.albumart, pendingIntent); + views.setOnClickPendingIntent(R.id.info, pendingIntent); + } + + intent = new Intent(MediaPlaybackService.TOGGLEPAUSE_ACTION); + intent.setComponent(serviceName); + pendingIntent = PendingIntent.getService(context, 0, intent, 0); + views.setOnClickPendingIntent(R.id.control_play, pendingIntent); + + intent = new Intent(MediaPlaybackService.NEXT_ACTION); + intent.setComponent(serviceName); + pendingIntent = PendingIntent.getService(context, 0, intent, 0); + views.setOnClickPendingIntent(R.id.control_next, pendingIntent); + + intent = new Intent(MediaPlaybackService.PREVIOUS_ACTION); + intent.setComponent(serviceName); + pendingIntent = PendingIntent.getService(context, 0, intent, 0); + views.setOnClickPendingIntent(R.id.control_prev, pendingIntent); + + intent = new Intent(MediaPlaybackService.CYCLEREPEAT_ACTION); + intent.setComponent(serviceName); + pendingIntent = PendingIntent.getService(context, 0, intent, 0); + views.setOnClickPendingIntent(R.id.control_repeat, pendingIntent); + + intent = new Intent(MediaPlaybackService.TOGGLESHUFFLE_ACTION); + intent.setComponent(serviceName); + pendingIntent = PendingIntent.getService(context, 0, intent, 0); + views.setOnClickPendingIntent(R.id.control_shuffle, pendingIntent); + } +} diff --git a/src/com/android/music/MediaButtonIntentReceiver.java b/src/com/android/music/MediaButtonIntentReceiver.java index 9a8b810..fadda52 100644 --- a/src/com/android/music/MediaButtonIntentReceiver.java +++ b/src/com/android/music/MediaButtonIntentReceiver.java @@ -1,170 +1,170 @@ -/* - * 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. - */ - -package com.android.music; - -import android.content.BroadcastReceiver; -import android.content.Context; -import android.content.Intent; -import android.media.AudioManager; -import android.os.Handler; -import android.os.Message; -import android.view.KeyEvent; - -/** - * - */ -public class MediaButtonIntentReceiver extends BroadcastReceiver { - - private static final int MSG_LONGPRESS_TIMEOUT = 1; - - private static final int LONG_PRESS_DELAY = 1000; - - private static long mLastClickTime = 0; - private static boolean mDown = false; - private static boolean mLaunched = false; - - private static Handler mHandler = new Handler() { - @Override - public void handleMessage(Message msg) { - switch (msg.what) { - case MSG_LONGPRESS_TIMEOUT: - if (!mLaunched) { - Context context = (Context) msg.obj; - Intent i = new Intent(); - i.putExtra("autoshuffle", "true"); - i.setClass(context, MusicBrowserActivity.class); - i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK - | Intent.FLAG_ACTIVITY_CLEAR_TOP); - context.startActivity(i); - mLaunched = true; - } - break; - } - } - }; - - @Override - public void onReceive(Context context, Intent intent) { - String intentAction = intent.getAction(); - - if (AudioManager.ACTION_AUDIO_BECOMING_NOISY.equals(intentAction)) { - Intent i = new Intent(context, MediaPlaybackService.class); - i.setAction(MediaPlaybackService.SERVICECMD); - i.putExtra(MediaPlaybackService.CMDNAME, - MediaPlaybackService.CMDPAUSE); - context.startService(i); - } else if (Intent.ACTION_MEDIA_BUTTON.equals(intentAction)) { - KeyEvent event = (KeyEvent) intent - .getParcelableExtra(Intent.EXTRA_KEY_EVENT); - - if (event == null) { - return; - } - - int keycode = event.getKeyCode(); - int action = event.getAction(); - long eventtime = event.getEventTime(); - int buttonId = intent.getIntExtra(MediaPlaybackService.CMDNOTIF, 0); - - // single quick press: pause/resume. - // double press: next track - // long press: start auto-shuffle mode. - - String command = null; - switch (keycode) { - case KeyEvent.KEYCODE_MEDIA_STOP: - command = MediaPlaybackService.CMDSTOP; - break; - case KeyEvent.KEYCODE_HEADSETHOOK: - case KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE: - command = MediaPlaybackService.CMDTOGGLEPAUSE; - - break; - case KeyEvent.KEYCODE_MEDIA_NEXT: - command = MediaPlaybackService.CMDNEXT; - - break; - case KeyEvent.KEYCODE_MEDIA_PREVIOUS: - command = MediaPlaybackService.CMDPREVIOUS; - - break; - - } - - if (command != null) { - if (action == KeyEvent.ACTION_DOWN) { - if (mDown && (buttonId == 0)) { - if ((MediaPlaybackService.CMDTOGGLEPAUSE - .equals(command) || MediaPlaybackService.CMDPLAY - .equals(command)) - && mLastClickTime != 0 - && eventtime - mLastClickTime > LONG_PRESS_DELAY) { - mHandler.sendMessage(mHandler.obtainMessage( - MSG_LONGPRESS_TIMEOUT, context)); - - } - } else if (event.getRepeatCount() == 0) { - - // only consider the first event in a sequence, not the - // repeat events, - // so that we don't trigger in cases where the first - // event went to - // a different app (e.g. when the user ends a phone call - // by - // long pressing the headset button) - - // The service may or may not be running, but we need to - // send it - - // a command. - Intent i = new Intent(context, - MediaPlaybackService.class); - - i.setAction(MediaPlaybackService.SERVICECMD); - if (keycode == KeyEvent.KEYCODE_HEADSETHOOK - && eventtime - mLastClickTime < 300) { - i.putExtra(MediaPlaybackService.CMDNAME, - MediaPlaybackService.CMDNEXT); - - context.startService(i); - mLastClickTime = 0; - } else { - i.putExtra(MediaPlaybackService.CMDNAME, command); - context.startService(i); - mLastClickTime = eventtime; - - } - - mLaunched = false; - if (buttonId == 0) { - mDown = true; - - } - } - } else { - mHandler.removeMessages(MSG_LONGPRESS_TIMEOUT); - mDown = false; - - } - if (isOrderedBroadcast()) { - abortBroadcast(); - - } - } - } - } -} +/* + * 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. + */ + +package com.android.music; + +import android.content.BroadcastReceiver; +import android.content.Context; +import android.content.Intent; +import android.media.AudioManager; +import android.os.Handler; +import android.os.Message; +import android.view.KeyEvent; + +/** + * + */ +public class MediaButtonIntentReceiver extends BroadcastReceiver { + + private static final int MSG_LONGPRESS_TIMEOUT = 1; + + private static final int LONG_PRESS_DELAY = 1000; + + private static long mLastClickTime = 0; + private static boolean mDown = false; + private static boolean mLaunched = false; + + private static Handler mHandler = new Handler() { + @Override + public void handleMessage(Message msg) { + switch (msg.what) { + case MSG_LONGPRESS_TIMEOUT: + if (!mLaunched) { + Context context = (Context) msg.obj; + Intent i = new Intent(); + i.putExtra("autoshuffle", "true"); + i.setClass(context, MusicBrowserActivity.class); + i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK + | Intent.FLAG_ACTIVITY_CLEAR_TOP); + context.startActivity(i); + mLaunched = true; + } + break; + } + } + }; + + @Override + public void onReceive(Context context, Intent intent) { + String intentAction = intent.getAction(); + + if (AudioManager.ACTION_AUDIO_BECOMING_NOISY.equals(intentAction)) { + Intent i = new Intent(context, MediaPlaybackService.class); + i.setAction(MediaPlaybackService.SERVICECMD); + i.putExtra(MediaPlaybackService.CMDNAME, + MediaPlaybackService.CMDPAUSE); + context.startService(i); + } else if (Intent.ACTION_MEDIA_BUTTON.equals(intentAction)) { + KeyEvent event = (KeyEvent) intent + .getParcelableExtra(Intent.EXTRA_KEY_EVENT); + + if (event == null) { + return; + } + + int keycode = event.getKeyCode(); + int action = event.getAction(); + long eventtime = event.getEventTime(); + int buttonId = intent.getIntExtra(MediaPlaybackService.CMDNOTIF, 0); + + // single quick press: pause/resume. + // double press: next track + // long press: start auto-shuffle mode. + + String command = null; + switch (keycode) { + case KeyEvent.KEYCODE_MEDIA_STOP: + command = MediaPlaybackService.CMDSTOP; + break; + case KeyEvent.KEYCODE_HEADSETHOOK: + case KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE: + command = MediaPlaybackService.CMDTOGGLEPAUSE; + + break; + case KeyEvent.KEYCODE_MEDIA_NEXT: + command = MediaPlaybackService.CMDNEXT; + + break; + case KeyEvent.KEYCODE_MEDIA_PREVIOUS: + command = MediaPlaybackService.CMDPREVIOUS; + + break; + + } + + if (command != null) { + if (action == KeyEvent.ACTION_DOWN) { + if (mDown && (buttonId == 0)) { + if ((MediaPlaybackService.CMDTOGGLEPAUSE + .equals(command) || MediaPlaybackService.CMDPLAY + .equals(command)) + && mLastClickTime != 0 + && eventtime - mLastClickTime > LONG_PRESS_DELAY) { + mHandler.sendMessage(mHandler.obtainMessage( + MSG_LONGPRESS_TIMEOUT, context)); + + } + } else if (event.getRepeatCount() == 0) { + + // only consider the first event in a sequence, not the + // repeat events, + // so that we don't trigger in cases where the first + // event went to + // a different app (e.g. when the user ends a phone call + // by + // long pressing the headset button) + + // The service may or may not be running, but we need to + // send it + + // a command. + Intent i = new Intent(context, + MediaPlaybackService.class); + + i.setAction(MediaPlaybackService.SERVICECMD); + if (keycode == KeyEvent.KEYCODE_HEADSETHOOK + && eventtime - mLastClickTime < 300) { + i.putExtra(MediaPlaybackService.CMDNAME, + MediaPlaybackService.CMDNEXT); + + context.startService(i); + mLastClickTime = 0; + } else { + i.putExtra(MediaPlaybackService.CMDNAME, command); + context.startService(i); + mLastClickTime = eventtime; + + } + + mLaunched = false; + if (buttonId == 0) { + mDown = true; + + } + } + } else { + mHandler.removeMessages(MSG_LONGPRESS_TIMEOUT); + mDown = false; + + } + if (isOrderedBroadcast()) { + abortBroadcast(); + + } + } + } + } +} diff --git a/src/com/android/music/MediaPlaybackActivity.java b/src/com/android/music/MediaPlaybackActivity.java index 6b50845..5f9ef0b 100644 --- a/src/com/android/music/MediaPlaybackActivity.java +++ b/src/com/android/music/MediaPlaybackActivity.java @@ -85,7 +85,7 @@ public class MediaPlaybackActivity extends Activity implements MusicUtils.Defs, private Toast mToast; private int mTouchSlop; private ServiceToken mToken; - // Media buttons + // Media buttons and theme stuff private RepeatingImageButton mPrevButton; private ImageButton mPauseButton; private RepeatingImageButton mNextButton; @@ -109,6 +109,7 @@ public class MediaPlaybackActivity extends Activity implements MusicUtils.Defs, private LinearLayout mRingtone; private LinearLayout mShop; private LinearLayout mDelete; + private LinearLayout mNPBackground; // Screen on while playing/charging private boolean pluggedIn; // Animations @@ -253,6 +254,9 @@ public void onCreate(Bundle icicle) { } // Set Views for themes if (themeResources != null) { + bar = (ActionBar) getActionBar(); + + mNPBackground = (LinearLayout) findViewById(R.id.now_playing_bg); mShuffleButton = ((LinearLayout) findViewById(R.id.shuffle)); mShuffleButtonText = (TextView) findViewById(R.id.shuffle_text); mRepeatButton = ((LinearLayout) findViewById(R.id.repeat)); @@ -303,7 +307,7 @@ public void onCreate(Bundle icicle) { .loadThemeResource(themeResources, themePackage, "np_ring", mRingButton, THEME_ITEM_FOREGROUND); ArtistAlbumBrowserActivity.loadThemeResource(themeResources, - themePackage, "np_share", mShareButton, + themePackage, "np_share", mShareButtonImage, THEME_ITEM_FOREGROUND); ArtistAlbumBrowserActivity.loadThemeResource(themeResources, themePackage, "np_eq", mEQ, THEME_ITEM_FOREGROUND); @@ -316,6 +320,15 @@ public void onCreate(Bundle icicle) { ArtistAlbumBrowserActivity .loadThemeResource(themeResources, themePackage, "np_next", mPrevButton, THEME_ITEM_FOREGROUND); + // Now Playing bg + ArtistAlbumBrowserActivity + .loadThemeResource(themeResources, themePackage, "np_bg", + mNPBackground, THEME_ITEM_BACKGROUND); + int aBar = themeResources.getIdentifier("ab_bg", "drawable", + themePackage); + if (aBar != 0) { + bar.setBackgroundDrawable(themeResources.getDrawable(aBar)); + } int seeker = themeResources.getIdentifier("progress_horizontal", "drawable", themePackage); if (seeker != 0) { diff --git a/src/com/android/music/MediaPlaybackService.java b/src/com/android/music/MediaPlaybackService.java index 17f2e68..67ec62b 100644 --- a/src/com/android/music/MediaPlaybackService.java +++ b/src/com/android/music/MediaPlaybackService.java @@ -540,10 +540,6 @@ public void onCreate() { public void onDestroy() { sensorMan.unregisterListener(this); - if (shaker != null) - shaker.close(); - shaker = null; - // Check that we're not being destroyed while something is still // playing. if (isPlaying()) { @@ -1654,6 +1650,7 @@ private void stop(boolean remove_status_icon) { if (remove_status_icon) { mIsSupposedToBePlaying = false; } + } /** diff --git a/src/com/android/music/MusicSettingsActivity.java b/src/com/android/music/MusicSettingsActivity.java index 3a6cd7c..4ade0dc 100644 --- a/src/com/android/music/MusicSettingsActivity.java +++ b/src/com/android/music/MusicSettingsActivity.java @@ -1,539 +1,539 @@ -/* - * Copyright (C) 2011 The CyanogenMod 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. - */ - -package com.android.music; - -import java.io.File; -import java.io.FileInputStream; -import java.io.FileNotFoundException; -import java.io.FileOutputStream; -import java.io.IOException; -import java.nio.channels.FileChannel; -import java.util.List; - -import android.app.ActionBar; -import android.app.AlertDialog; -import android.app.WallpaperManager; -import android.content.ActivityNotFoundException; -import android.content.DialogInterface; -import android.content.Intent; -import android.content.SharedPreferences; -import android.content.SharedPreferences.OnSharedPreferenceChangeListener; -import android.content.pm.PackageInfo; -import android.content.pm.PackageManager; -import android.content.pm.PackageManager.NameNotFoundException; -import android.content.pm.ResolveInfo; -import android.content.res.Resources; -import android.graphics.Bitmap; -import android.graphics.BitmapFactory; -import android.media.audiofx.AudioEffect; -import android.net.Uri; -import android.os.Build; -import android.os.Bundle; -import android.os.Environment; -import android.os.SystemClock; -import android.preference.CheckBoxPreference; -import android.preference.ListPreference; -import android.preference.Preference; -import android.preference.Preference.OnPreferenceChangeListener; -import android.preference.Preference.OnPreferenceClickListener; -import android.preference.PreferenceActivity; -import android.preference.PreferenceManager; -import android.preference.PreferenceScreen; -import android.provider.MediaStore; -import android.util.Log; -import android.view.MenuItem; -import android.view.View; -import android.widget.ImageView; -import android.widget.LinearLayout; -import android.widget.Toast; - -public class MusicSettingsActivity extends PreferenceActivity implements - OnSharedPreferenceChangeListener, OnPreferenceChangeListener { - - static final String KEY_ENABLE_FOCUS_LOSS_DUCKING = "enable_focus_loss_ducking"; - static final String KEY_DUCK_ATTENUATION_DB = "duck_attenuation_db"; - static final String KEY_BACK_BUTTON_DB = "back_button_db"; - static final String KEY_ANIMATION_UI_DB = "animation_ui_db"; - static final String KEY_ENABLE_GESTURES = "enable_gestures"; - static final String KEY_ENABLE_HAPTIC_FEEDBACK = "enable_haptic_feedback"; - static final String KEY_HAS_CUSTOM_GESTURES = "has_custom_gestures"; - static final String KEY_ENABLE_SEARCH_BUTTON = "cbSearch"; - static final String KEY_ENABLE_PLAY_BUTTON = "cbPlay"; - static final String KEY_ENABLE_NEXT_BUTTON = "cbNext"; - static final String KEY_ENABLE_PREV_BUTTON = "cbPrev"; - static final String KEY_ENABLE_NEW_PLAYLIST_BUTTON = "cbPlaylist"; - static final String KEY_ENABLE_ALBUM_ART = "cbArt"; - static final String KEY_ENABLE_SONG_TEXT = "tvLine1"; - static final String KEY_ENABLE_ARTIST_TEXT = "tvLine2"; - static final String KEY_ENABLE_ALBUM_TEXT = "tvLine3"; - static final String KEY_COLOR_PREFERENCE_KEY = "color"; - static final String KEY_ENABLE_STATUS_PLAY_BUTTON = "cbStatusPlay"; - static final String KEY_ENABLE_SHARE_BUTTON = "cbShare"; - static final String KEY_ENABLE_PROGRESS_BAR = "cbProgress"; - static final String KEY_ENABLE_OVER_FLOW = "cbFlow"; - - static final String KEY_ENABLE_STATUS_NEXT_BUTTON = "cbStatusNext"; - static final String KEY_ENABLE_STATUS_PREV_BUTTON = "cbStatusPrev"; - static final String KEY_ENABLE_STATUS_ALBUM_ART = "cbStatusArt"; - static final String KEY_ENABLE_STATUS_SONG_TEXT = "tvStatusLine1"; - static final String KEY_ENABLE_STATUS_ARTIST_TEXT = "tvStatusLine2"; - static final String KEY_ENABLE_STATUS_ALBUM_TEXT = "tvStatusLine3"; - static final String KEY_ENABLE_MARKET_SERACH = "cbMarket"; - static final String KEY_ENABLE_STATUS_COLLAPSE = "cbStatusCollapse"; - static final String SCREENSAVER_COLOR = "screensaver_color"; - static final String SCREENSAVER_COLOR_ALPHA = "screensaver_color_alpha"; - static final String SCREENSAVER_COLOR_RED = "screensaver_color_red"; - static final String SCREENSAVER_COLOR_GREEN = "screensaver_color_green"; - static final String SCREENSAVER_COLOR_BLUE = "screensaver_color_blue"; - static final String KEY_ENTER_FULL_NOW_PLAYING = "cbEnterNowPlaying"; - static final String KEY_ENABLE_STATUS_TEXT_COLOR = "tvStatusColor"; - static final String KEY_ENABLE_HOME_ART = "cbHomeAlbumArt"; - static final String KEY_LOCK = "cbLock"; - public static final String THEME_DEFAULT = "Music"; - static final String THEME_KEY = "themePackageName"; - static final String SHAKE_SENSITIVITY = "shake_sensitivity"; - static final String FLIP_SENSITIVITY = "flip_sensitivity"; - - // This key has the gesture entry name (E.g. PAUSE) appended to it before - // use - static final String KEY_HAS_CUSTOM_GESTURE_XXX = "has_custom_gesture_"; - - static final String DEFAULT_DUCK_ATTENUATION_DB = "8"; - static final String DEFAULT_BACK_BUTTON_ACTION_DB = "0"; - - static final String ACTION_ENABLE_GESTURES_CHANGED = "com.android.music.enablegestureschanged"; - static final String ACTION_GESTURES_CHANGED = "com.android.music.gestureschanged"; - - static final String PREFERENCES_FILE = "settings"; - public static final String KEY_ENABLE_STATUS_NONYA = "cbStatusNonya"; - public static final String KEY_BUILD_VERSION = "build"; - public static final String KEY_SOUND_EFFECT = "eqEffects"; - public static final String KEY_FEEDBACK = "feedback"; - public static final String KEY_FLIP = "cbFlip"; - public static final String KEY_TICK = "cbStatusTicker"; - - long[] mHits = new long[3]; - private static final String LOG_TAG = "EasterEgg"; - private static final int EFFECTS_PANEL = 0; - - // Color to use for text & graphics in screen saver mode. - static final int DEFAULT_SCREENSAVER_COLOR_ALPHA = 230; - static final int DEFAULT_SCREENSAVER_COLOR_RED = 0; - static final int DEFAULT_SCREENSAVER_COLOR_GREEN = 192; - static final int DEFAULT_SCREENSAVER_COLOR_BLUE = 255; - // Custom wallpaper - static final String BG_PHOTO_FILE = "home_art"; - static final String TEMP_PHOTO_FILE = "home"; - private Bitmap bgBitmap = null; - // Shake and Flip sensitivity - static final double DEFAULT_SHAKE_SENS = 2; - static final int DEFAULT_FLIP_SENS = 10; - - public AlertDialog themeAlert; - public CheckBoxPreference cp; - - @Override - protected void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - - PreferenceManager preferenceManager = getPreferenceManager(); - preferenceManager.setSharedPreferencesName(PREFERENCES_FILE); - addPreferencesFromResource(R.xml.settings); - - ActionBar bar = getActionBar(); - bar.setDisplayHomeAsUpEnabled(true); - - PreferenceScreen screen; - screen = getPreferenceScreen(); - - cp = (CheckBoxPreference) screen.findPreference("cbHomeAlbumArt"); - - final CheckBoxPreference lk = (CheckBoxPreference) screen - .findPreference("cbLock"); - - AlertDialog.Builder builder = new AlertDialog.Builder(this); - builder.setTitle("Set Wallpaper"); - builder.setIcon(android.R.drawable.ic_menu_crop); - builder.setMessage( - "You should select a wallpaper to use when your music is paused.") - .setCancelable(false) - .setPositiveButton("Okay", - new DialogInterface.OnClickListener() { - public void onClick(DialogInterface dialog, int id) { - pickImage(); - } - }) - .setNegativeButton("Cancel", - new DialogInterface.OnClickListener() { - public void onClick(DialogInterface dialog, int id) { - dialog.cancel(); - cp.setChecked(false); - } - }); - final AlertDialog alert = builder.create(); - - AlertDialog.Builder lock = new AlertDialog.Builder(this); - lock.setTitle("Requires Restart"); - lock.setIcon(R.drawable.ic_dialog_alert_holo_dark); - lock.setMessage( - "Music needs to stop completely and restart to let the changes take effect") - .setCancelable(false) - .setPositiveButton("Okay", - new DialogInterface.OnClickListener() { - public void onClick(DialogInterface dialog, int id) { - // This isn't a good practice, but we need to - // restart the - // service completely to see the change - // immediately - System.exit(0); - } - }) - .setNegativeButton("Cancel", - new DialogInterface.OnClickListener() { - public void onClick(DialogInterface dialog, int id) { - dialog.cancel(); - if (lk.isChecked()) { - lk.setChecked(false); - } else { - lk.setChecked(true); - } - } - }); - final AlertDialog lockAlert = lock.create(); - - cp.setOnPreferenceClickListener(new OnPreferenceClickListener() { - public boolean onPreferenceClick(final Preference preference) { - CheckBoxPreference cbp = (CheckBoxPreference) preference; - if (cbp.isChecked()) { - alert.show(); - } else { - // We don't want the wall paper to remain the album art if - // they aren't using this. - setCustomBackground(); - } - return true; - } - }); - - lk.setOnPreferenceClickListener(new OnPreferenceClickListener() { - public boolean onPreferenceClick(final Preference preference) { - lockAlert.show(); - return true; - } - }); - - try { - PackageInfo packageInfo = getPackageManager().getPackageInfo( - getPackageName(), 0); - findPreference(KEY_BUILD_VERSION).setSummary( - Build.VERSION.RELEASE + " - " + packageInfo.versionName); - } catch (NameNotFoundException e) { - findPreference(KEY_BUILD_VERSION).setSummary("?"); - } - // ADW: theme settings - SharedPreferences sp = getPreferenceManager().getSharedPreferences(); - final String themePackage = sp.getString(THEME_KEY, THEME_DEFAULT); - ListPreference themeLp = (ListPreference) findPreference(THEME_KEY); - themeLp.setOnPreferenceChangeListener(new OnPreferenceChangeListener() { - public boolean onPreferenceChange(Preference preference, - Object newValue) { - PreviewPreference themePreview = (PreviewPreference) findPreference("themePreview"); - themePreview.setTheme(newValue.toString()); - return false; - } - }); - - Intent intent = new Intent("com.andrew.music.THEMES"); - intent.addCategory("android.intent.category.DEFAULT"); - PackageManager pm = getPackageManager(); - List themes = pm.queryIntentActivities(intent, 0); - String[] entries = new String[themes.size() + 1]; - String[] values = new String[themes.size() + 1]; - entries[0] = MusicSettingsActivity.THEME_DEFAULT; - values[0] = MusicSettingsActivity.THEME_DEFAULT; - for (int i = 0; i < themes.size(); i++) { - String appPackageName = (themes.get(i)).activityInfo.packageName - .toString(); - String themeName = (themes.get(i)).loadLabel(pm).toString(); - entries[i + 1] = themeName; - values[i + 1] = appPackageName; - } - themeLp.setEntries(entries); - themeLp.setEntryValues(values); - PreviewPreference themePreview = (PreviewPreference) findPreference("themePreview"); - themePreview.setTheme(themePackage); - } - - private void pickImage() { - Intent intent = new Intent(Intent.ACTION_GET_CONTENT); - intent.setType("image/*"); - - intent.putExtra("crop", "true"); - intent.putExtra("scale", true); - intent.putExtra("outputFormat", Bitmap.CompressFormat.PNG.toString()); - intent.putExtra(MediaStore.EXTRA_OUTPUT, getTempUri()); - intent.putExtra("noFaceDetection", true); - - startActivityForResult(intent, 0); - } - - private Uri getTempUri() { - return Uri.fromFile(getTempFile()); - } - - private File getTempFile() { - if (isSDCARDMounted()) { - - File f = new File(Environment.getExternalStorageDirectory(), - TEMP_PHOTO_FILE); - // try { - // f.createNewFile(); - // } catch (IOException e) { - // TODO Auto-generated catch block - // e.printStackTrace(); - // Toast.makeText(this, "Something Fucked Up", - // Toast.LENGTH_LONG).show(); - // } - return f; - } else { - return null; - } - } - - private boolean isSDCARDMounted() { - String status = Environment.getExternalStorageState(); - - if (status.equals(Environment.MEDIA_MOUNTED)) - return true; - return false; - } - - public static void copyFile(File src, File dst) throws IOException { - FileChannel inChannel = new FileInputStream(src).getChannel(); - FileChannel outChannel = new FileOutputStream(dst).getChannel(); - - try { - inChannel.transferTo(0, inChannel.size(), outChannel); - } finally { - - if (inChannel != null) - inChannel.close(); - if (outChannel != null) - outChannel.close(); - } - } - - protected void onActivityResult(int requestCode, int resultCode, Intent data) { - if (requestCode == 0) { - if (resultCode == RESULT_OK) { - try { - - File src = getTempFile(); - File dst = new File(getFilesDir(), BG_PHOTO_FILE); - copyFile(src, dst); - - } catch (FileNotFoundException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } catch (IOException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - } - } - } - - // Set Custom Background Image - public void setCustomBackground() { - - SharedPreferences preferences = getSharedPreferences( - MusicSettingsActivity.PREFERENCES_FILE, MODE_PRIVATE); - - preferences - .getBoolean(MusicSettingsActivity.KEY_ENABLE_HOME_ART, false); - - // First clean our old data - if (bgBitmap != null) { - bgBitmap.recycle(); - bgBitmap = null; - System.gc(); - } - // now load the proper bg - String BG_FILE = getFilesDir().toString() + File.separator - + MusicSettingsActivity.BG_PHOTO_FILE; - bgBitmap = BitmapFactory.decodeFile(BG_FILE); - - try { - WallpaperManager.getInstance(this).setBitmap(bgBitmap); - } catch (Exception e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - } - - public void applyTheme(View v) { - PreviewPreference themePreview = (PreviewPreference) findPreference("themePreview"); - String packageName = themePreview.getValue().toString(); - // this time we really save the themepackagename - SharedPreferences sp = getPreferenceManager().getSharedPreferences(); - final SharedPreferences.Editor editor = sp.edit(); - editor.putString("themePackageName", packageName); - // and update the preferences from the theme - // TODO:ADW maybe this should be optional for the user - if (!packageName.equals(MusicSettingsActivity.THEME_DEFAULT)) { - Resources themeResources = null; - try { - themeResources = getPackageManager() - .getResourcesForApplication(packageName.toString()); - } catch (NameNotFoundException e) { - // e.printStackTrace(); - } - } else { - - } - AlertDialog.Builder theme = new AlertDialog.Builder(this); - theme.setTitle("Requires Restart"); - theme.setIcon(R.drawable.ic_dialog_alert_holo_dark); - theme.setMessage( - "Music needs to stop completely and restart to let the changes take effect") - .setCancelable(false) - .setPositiveButton("Okay", - new DialogInterface.OnClickListener() { - public void onClick(DialogInterface dialog, int id) { - editor.commit(); - // This isn't a good practice, but we need to - // restart the - // service completely to see the change - // immediately - System.exit(0); - } - }) - .setNegativeButton("Cancel", - new DialogInterface.OnClickListener() { - public void onClick(DialogInterface dialog, int id) { - dialog.cancel(); - } - }); - themeAlert = theme.create(); - themeAlert.show(); - } - - public void getThemes(View v) { - // TODO:warn theme devs to use "MusicTheme" as keyword. - Uri marketUri = Uri.parse("market://search?q=MusicTheme"); - Intent marketIntent = new Intent(Intent.ACTION_VIEW).setData(marketUri); - try { - startActivity(marketIntent); - } catch (ActivityNotFoundException e) { - Toast.makeText(this, R.string.activity_not_found, - Toast.LENGTH_SHORT).show(); - } catch (SecurityException e) { - Toast.makeText(this, R.string.activity_not_found, - Toast.LENGTH_SHORT).show(); - Log.e("Music", "Get themes", e); - } - finish(); - } - - @Override - public boolean onOptionsItemSelected(MenuItem item) { - switch (item.getItemId()) { - case android.R.id.home: - super.onBackPressed(); - break; - } - return super.onOptionsItemSelected(item); - } - - @Override - public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, - String key) { - if (key.equals(KEY_ENABLE_GESTURES)) { - Intent intent = new Intent(ACTION_ENABLE_GESTURES_CHANGED); - sendBroadcast(intent); - } - } - - @Override - protected void onResume() { - super.onResume(); - getPreferenceScreen().getSharedPreferences() - .registerOnSharedPreferenceChangeListener(this); - } - - @Override - protected void onPause() { - super.onPause(); - getPreferenceScreen().getSharedPreferences() - .unregisterOnSharedPreferenceChangeListener(this); - } - - @Override - protected void onDestroy() { - super.onDestroy(); - - } - - @Override - public boolean onPreferenceChange(Preference arg0, Object arg1) { - // TODO Auto-generated method stub - return false; - } - - @Override - public boolean onPreferenceTreeClick(PreferenceScreen preferenceScreen, - Preference preference) { - try { - if (preference.getKey().equals(KEY_BUILD_VERSION)) { - System.arraycopy(mHits, 1, mHits, 0, mHits.length - 1); - mHits[mHits.length - 1] = SystemClock.uptimeMillis(); - if (mHits[0] >= (SystemClock.uptimeMillis() - 500)) { - Toast ImageToast = new Toast(getBaseContext()); - LinearLayout toastLayout = new LinearLayout( - getBaseContext()); - toastLayout.setOrientation(LinearLayout.HORIZONTAL); - ImageView image = new ImageView(getBaseContext()); - image.setImageResource(R.drawable.easter_egg); - toastLayout.addView(image); - ImageToast.setView(toastLayout); - ImageToast.setDuration(Toast.LENGTH_SHORT); - ImageToast.show(); - } - } - } catch (NullPointerException ee) { - - } - try { - if (preference.getKey().equals(KEY_SOUND_EFFECT)) { - Intent i = new Intent( - AudioEffect.ACTION_DISPLAY_AUDIO_EFFECT_CONTROL_PANEL); - try { - i.putExtra(AudioEffect.EXTRA_AUDIO_SESSION, - MusicUtils.sService.getAudioSessionId()); - } catch (Exception e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - startActivityForResult(i, EFFECTS_PANEL); - } - } catch (NullPointerException ee) { - - } - - return super.onPreferenceTreeClick(preferenceScreen, preference); - } -} +/* + * Copyright (C) 2011 The CyanogenMod 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. + */ + +package com.android.music; + +import java.io.File; +import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.io.FileOutputStream; +import java.io.IOException; +import java.nio.channels.FileChannel; +import java.util.List; + +import android.app.ActionBar; +import android.app.AlertDialog; +import android.app.WallpaperManager; +import android.content.ActivityNotFoundException; +import android.content.DialogInterface; +import android.content.Intent; +import android.content.SharedPreferences; +import android.content.SharedPreferences.OnSharedPreferenceChangeListener; +import android.content.pm.PackageInfo; +import android.content.pm.PackageManager; +import android.content.pm.PackageManager.NameNotFoundException; +import android.content.pm.ResolveInfo; +import android.content.res.Resources; +import android.graphics.Bitmap; +import android.graphics.BitmapFactory; +import android.media.audiofx.AudioEffect; +import android.net.Uri; +import android.os.Build; +import android.os.Bundle; +import android.os.Environment; +import android.os.SystemClock; +import android.preference.CheckBoxPreference; +import android.preference.ListPreference; +import android.preference.Preference; +import android.preference.Preference.OnPreferenceChangeListener; +import android.preference.Preference.OnPreferenceClickListener; +import android.preference.PreferenceActivity; +import android.preference.PreferenceManager; +import android.preference.PreferenceScreen; +import android.provider.MediaStore; +import android.util.Log; +import android.view.MenuItem; +import android.view.View; +import android.widget.ImageView; +import android.widget.LinearLayout; +import android.widget.Toast; + +public class MusicSettingsActivity extends PreferenceActivity implements + OnSharedPreferenceChangeListener, OnPreferenceChangeListener { + + static final String KEY_ENABLE_FOCUS_LOSS_DUCKING = "enable_focus_loss_ducking"; + static final String KEY_DUCK_ATTENUATION_DB = "duck_attenuation_db"; + static final String KEY_BACK_BUTTON_DB = "back_button_db"; + static final String KEY_ANIMATION_UI_DB = "animation_ui_db"; + static final String KEY_ENABLE_GESTURES = "enable_gestures"; + static final String KEY_ENABLE_HAPTIC_FEEDBACK = "enable_haptic_feedback"; + static final String KEY_HAS_CUSTOM_GESTURES = "has_custom_gestures"; + static final String KEY_ENABLE_SEARCH_BUTTON = "cbSearch"; + static final String KEY_ENABLE_PLAY_BUTTON = "cbPlay"; + static final String KEY_ENABLE_NEXT_BUTTON = "cbNext"; + static final String KEY_ENABLE_PREV_BUTTON = "cbPrev"; + static final String KEY_ENABLE_NEW_PLAYLIST_BUTTON = "cbPlaylist"; + static final String KEY_ENABLE_ALBUM_ART = "cbArt"; + static final String KEY_ENABLE_SONG_TEXT = "tvLine1"; + static final String KEY_ENABLE_ARTIST_TEXT = "tvLine2"; + static final String KEY_ENABLE_ALBUM_TEXT = "tvLine3"; + static final String KEY_COLOR_PREFERENCE_KEY = "color"; + static final String KEY_ENABLE_STATUS_PLAY_BUTTON = "cbStatusPlay"; + static final String KEY_ENABLE_SHARE_BUTTON = "cbShare"; + static final String KEY_ENABLE_PROGRESS_BAR = "cbProgress"; + static final String KEY_ENABLE_OVER_FLOW = "cbFlow"; + + static final String KEY_ENABLE_STATUS_NEXT_BUTTON = "cbStatusNext"; + static final String KEY_ENABLE_STATUS_PREV_BUTTON = "cbStatusPrev"; + static final String KEY_ENABLE_STATUS_ALBUM_ART = "cbStatusArt"; + static final String KEY_ENABLE_STATUS_SONG_TEXT = "tvStatusLine1"; + static final String KEY_ENABLE_STATUS_ARTIST_TEXT = "tvStatusLine2"; + static final String KEY_ENABLE_STATUS_ALBUM_TEXT = "tvStatusLine3"; + static final String KEY_ENABLE_MARKET_SERACH = "cbMarket"; + static final String KEY_ENABLE_STATUS_COLLAPSE = "cbStatusCollapse"; + static final String SCREENSAVER_COLOR = "screensaver_color"; + static final String SCREENSAVER_COLOR_ALPHA = "screensaver_color_alpha"; + static final String SCREENSAVER_COLOR_RED = "screensaver_color_red"; + static final String SCREENSAVER_COLOR_GREEN = "screensaver_color_green"; + static final String SCREENSAVER_COLOR_BLUE = "screensaver_color_blue"; + static final String KEY_ENTER_FULL_NOW_PLAYING = "cbEnterNowPlaying"; + static final String KEY_ENABLE_STATUS_TEXT_COLOR = "tvStatusColor"; + static final String KEY_ENABLE_HOME_ART = "cbHomeAlbumArt"; + static final String KEY_LOCK = "cbLock"; + public static final String THEME_DEFAULT = "Music"; + static final String THEME_KEY = "themePackageName"; + static final String SHAKE_SENSITIVITY = "shake_sensitivity"; + static final String FLIP_SENSITIVITY = "flip_sensitivity"; + + // This key has the gesture entry name (E.g. PAUSE) appended to it before + // use + static final String KEY_HAS_CUSTOM_GESTURE_XXX = "has_custom_gesture_"; + + static final String DEFAULT_DUCK_ATTENUATION_DB = "8"; + static final String DEFAULT_BACK_BUTTON_ACTION_DB = "0"; + + static final String ACTION_ENABLE_GESTURES_CHANGED = "com.android.music.enablegestureschanged"; + static final String ACTION_GESTURES_CHANGED = "com.android.music.gestureschanged"; + + static final String PREFERENCES_FILE = "settings"; + public static final String KEY_ENABLE_STATUS_NONYA = "cbStatusNonya"; + public static final String KEY_BUILD_VERSION = "build"; + public static final String KEY_SOUND_EFFECT = "eqEffects"; + public static final String KEY_FEEDBACK = "feedback"; + public static final String KEY_FLIP = "cbFlip"; + public static final String KEY_TICK = "cbStatusTicker"; + + long[] mHits = new long[3]; + private static final String LOG_TAG = "EasterEgg"; + private static final int EFFECTS_PANEL = 0; + + // Color to use for text & graphics in screen saver mode. + static final int DEFAULT_SCREENSAVER_COLOR_ALPHA = 230; + static final int DEFAULT_SCREENSAVER_COLOR_RED = 0; + static final int DEFAULT_SCREENSAVER_COLOR_GREEN = 192; + static final int DEFAULT_SCREENSAVER_COLOR_BLUE = 255; + // Custom wallpaper + static final String BG_PHOTO_FILE = "home_art"; + static final String TEMP_PHOTO_FILE = "home"; + private Bitmap bgBitmap = null; + // Shake and Flip sensitivity + static final double DEFAULT_SHAKE_SENS = 2; + static final int DEFAULT_FLIP_SENS = 10; + + public AlertDialog themeAlert; + public CheckBoxPreference cp; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + + PreferenceManager preferenceManager = getPreferenceManager(); + preferenceManager.setSharedPreferencesName(PREFERENCES_FILE); + addPreferencesFromResource(R.xml.settings); + + ActionBar bar = getActionBar(); + bar.setDisplayHomeAsUpEnabled(true); + + PreferenceScreen screen; + screen = getPreferenceScreen(); + + cp = (CheckBoxPreference) screen.findPreference("cbHomeAlbumArt"); + + final CheckBoxPreference lk = (CheckBoxPreference) screen + .findPreference("cbLock"); + + AlertDialog.Builder builder = new AlertDialog.Builder(this); + builder.setTitle("Set Wallpaper"); + builder.setIcon(android.R.drawable.ic_menu_crop); + builder.setMessage( + "You should select a wallpaper to use when your music is paused.") + .setCancelable(false) + .setPositiveButton("Okay", + new DialogInterface.OnClickListener() { + public void onClick(DialogInterface dialog, int id) { + pickImage(); + } + }) + .setNegativeButton("Cancel", + new DialogInterface.OnClickListener() { + public void onClick(DialogInterface dialog, int id) { + dialog.cancel(); + cp.setChecked(false); + } + }); + final AlertDialog alert = builder.create(); + + AlertDialog.Builder lock = new AlertDialog.Builder(this); + lock.setTitle("Requires Restart"); + lock.setIcon(R.drawable.ic_dialog_alert_holo_dark); + lock.setMessage( + "Music needs to stop completely and restart to let the changes take effect") + .setCancelable(false) + .setPositiveButton("Okay", + new DialogInterface.OnClickListener() { + public void onClick(DialogInterface dialog, int id) { + // This isn't a good practice, but we need to + // restart the + // service completely to see the change + // immediately + System.exit(0); + } + }) + .setNegativeButton("Cancel", + new DialogInterface.OnClickListener() { + public void onClick(DialogInterface dialog, int id) { + dialog.cancel(); + if (lk.isChecked()) { + lk.setChecked(false); + } else { + lk.setChecked(true); + } + } + }); + final AlertDialog lockAlert = lock.create(); + + cp.setOnPreferenceClickListener(new OnPreferenceClickListener() { + public boolean onPreferenceClick(final Preference preference) { + CheckBoxPreference cbp = (CheckBoxPreference) preference; + if (cbp.isChecked()) { + alert.show(); + } else { + // We don't want the wall paper to remain the album art if + // they aren't using this. + setCustomBackground(); + } + return true; + } + }); + + lk.setOnPreferenceClickListener(new OnPreferenceClickListener() { + public boolean onPreferenceClick(final Preference preference) { + lockAlert.show(); + return true; + } + }); + + try { + PackageInfo packageInfo = getPackageManager().getPackageInfo( + getPackageName(), 0); + findPreference(KEY_BUILD_VERSION).setSummary( + Build.VERSION.RELEASE + " - " + packageInfo.versionName); + } catch (NameNotFoundException e) { + findPreference(KEY_BUILD_VERSION).setSummary("?"); + } + // ADW: theme settings + SharedPreferences sp = getPreferenceManager().getSharedPreferences(); + final String themePackage = sp.getString(THEME_KEY, THEME_DEFAULT); + ListPreference themeLp = (ListPreference) findPreference(THEME_KEY); + themeLp.setOnPreferenceChangeListener(new OnPreferenceChangeListener() { + public boolean onPreferenceChange(Preference preference, + Object newValue) { + PreviewPreference themePreview = (PreviewPreference) findPreference("themePreview"); + themePreview.setTheme(newValue.toString()); + return false; + } + }); + + Intent intent = new Intent("com.andrew.music.THEMES"); + intent.addCategory("android.intent.category.DEFAULT"); + PackageManager pm = getPackageManager(); + List themes = pm.queryIntentActivities(intent, 0); + String[] entries = new String[themes.size() + 1]; + String[] values = new String[themes.size() + 1]; + entries[0] = MusicSettingsActivity.THEME_DEFAULT; + values[0] = MusicSettingsActivity.THEME_DEFAULT; + for (int i = 0; i < themes.size(); i++) { + String appPackageName = (themes.get(i)).activityInfo.packageName + .toString(); + String themeName = (themes.get(i)).loadLabel(pm).toString(); + entries[i + 1] = themeName; + values[i + 1] = appPackageName; + } + themeLp.setEntries(entries); + themeLp.setEntryValues(values); + PreviewPreference themePreview = (PreviewPreference) findPreference("themePreview"); + themePreview.setTheme(themePackage); + } + + private void pickImage() { + Intent intent = new Intent(Intent.ACTION_GET_CONTENT); + intent.setType("image/*"); + + intent.putExtra("crop", "true"); + intent.putExtra("scale", true); + intent.putExtra("outputFormat", Bitmap.CompressFormat.PNG.toString()); + intent.putExtra(MediaStore.EXTRA_OUTPUT, getTempUri()); + intent.putExtra("noFaceDetection", true); + + startActivityForResult(intent, 0); + } + + private Uri getTempUri() { + return Uri.fromFile(getTempFile()); + } + + private File getTempFile() { + if (isSDCARDMounted()) { + + File f = new File(Environment.getExternalStorageDirectory(), + TEMP_PHOTO_FILE); + // try { + // f.createNewFile(); + // } catch (IOException e) { + // TODO Auto-generated catch block + // e.printStackTrace(); + // Toast.makeText(this, "Something Fucked Up", + // Toast.LENGTH_LONG).show(); + // } + return f; + } else { + return null; + } + } + + private boolean isSDCARDMounted() { + String status = Environment.getExternalStorageState(); + + if (status.equals(Environment.MEDIA_MOUNTED)) + return true; + return false; + } + + public static void copyFile(File src, File dst) throws IOException { + FileChannel inChannel = new FileInputStream(src).getChannel(); + FileChannel outChannel = new FileOutputStream(dst).getChannel(); + + try { + inChannel.transferTo(0, inChannel.size(), outChannel); + } finally { + + if (inChannel != null) + inChannel.close(); + if (outChannel != null) + outChannel.close(); + } + } + + protected void onActivityResult(int requestCode, int resultCode, Intent data) { + if (requestCode == 0) { + if (resultCode == RESULT_OK) { + try { + + File src = getTempFile(); + File dst = new File(getFilesDir(), BG_PHOTO_FILE); + copyFile(src, dst); + + } catch (FileNotFoundException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + } + } + + // Set Custom Background Image + public void setCustomBackground() { + + SharedPreferences preferences = getSharedPreferences( + MusicSettingsActivity.PREFERENCES_FILE, MODE_PRIVATE); + + preferences + .getBoolean(MusicSettingsActivity.KEY_ENABLE_HOME_ART, false); + + // First clean our old data + if (bgBitmap != null) { + bgBitmap.recycle(); + bgBitmap = null; + System.gc(); + } + // now load the proper bg + String BG_FILE = getFilesDir().toString() + File.separator + + MusicSettingsActivity.BG_PHOTO_FILE; + bgBitmap = BitmapFactory.decodeFile(BG_FILE); + + try { + WallpaperManager.getInstance(this).setBitmap(bgBitmap); + } catch (Exception e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + + public void applyTheme(View v) { + PreviewPreference themePreview = (PreviewPreference) findPreference("themePreview"); + String packageName = themePreview.getValue().toString(); + // this time we really save the themepackagename + SharedPreferences sp = getPreferenceManager().getSharedPreferences(); + final SharedPreferences.Editor editor = sp.edit(); + editor.putString("themePackageName", packageName); + // and update the preferences from the theme + // TODO:ADW maybe this should be optional for the user + if (!packageName.equals(MusicSettingsActivity.THEME_DEFAULT)) { + Resources themeResources = null; + try { + themeResources = getPackageManager() + .getResourcesForApplication(packageName.toString()); + } catch (NameNotFoundException e) { + // e.printStackTrace(); + } + } else { + + } + AlertDialog.Builder theme = new AlertDialog.Builder(this); + theme.setTitle("Requires Restart"); + theme.setIcon(R.drawable.ic_dialog_alert_holo_dark); + theme.setMessage( + "Music needs to stop completely and restart to let the changes take effect") + .setCancelable(false) + .setPositiveButton("Okay", + new DialogInterface.OnClickListener() { + public void onClick(DialogInterface dialog, int id) { + editor.commit(); + // This isn't a good practice, but we need to + // restart the + // service completely to see the change + // immediately + System.exit(0); + } + }) + .setNegativeButton("Cancel", + new DialogInterface.OnClickListener() { + public void onClick(DialogInterface dialog, int id) { + dialog.cancel(); + } + }); + themeAlert = theme.create(); + themeAlert.show(); + } + + public void getThemes(View v) { + // TODO:warn theme devs to use "MusicTheme" as keyword. + Uri marketUri = Uri.parse("market://search?q=MusicTheme"); + Intent marketIntent = new Intent(Intent.ACTION_VIEW).setData(marketUri); + try { + startActivity(marketIntent); + } catch (ActivityNotFoundException e) { + Toast.makeText(this, R.string.activity_not_found, + Toast.LENGTH_SHORT).show(); + } catch (SecurityException e) { + Toast.makeText(this, R.string.activity_not_found, + Toast.LENGTH_SHORT).show(); + Log.e("Music", "Get themes", e); + } + finish(); + } + + @Override + public boolean onOptionsItemSelected(MenuItem item) { + switch (item.getItemId()) { + case android.R.id.home: + super.onBackPressed(); + break; + } + return super.onOptionsItemSelected(item); + } + + @Override + public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, + String key) { + if (key.equals(KEY_ENABLE_GESTURES)) { + Intent intent = new Intent(ACTION_ENABLE_GESTURES_CHANGED); + sendBroadcast(intent); + } + } + + @Override + protected void onResume() { + super.onResume(); + getPreferenceScreen().getSharedPreferences() + .registerOnSharedPreferenceChangeListener(this); + } + + @Override + protected void onPause() { + super.onPause(); + getPreferenceScreen().getSharedPreferences() + .unregisterOnSharedPreferenceChangeListener(this); + } + + @Override + protected void onDestroy() { + super.onDestroy(); + + } + + @Override + public boolean onPreferenceChange(Preference arg0, Object arg1) { + // TODO Auto-generated method stub + return false; + } + + @Override + public boolean onPreferenceTreeClick(PreferenceScreen preferenceScreen, + Preference preference) { + try { + if (preference.getKey().equals(KEY_BUILD_VERSION)) { + System.arraycopy(mHits, 1, mHits, 0, mHits.length - 1); + mHits[mHits.length - 1] = SystemClock.uptimeMillis(); + if (mHits[0] >= (SystemClock.uptimeMillis() - 500)) { + Toast ImageToast = new Toast(getBaseContext()); + LinearLayout toastLayout = new LinearLayout( + getBaseContext()); + toastLayout.setOrientation(LinearLayout.HORIZONTAL); + ImageView image = new ImageView(getBaseContext()); + image.setImageResource(R.drawable.easter_egg); + toastLayout.addView(image); + ImageToast.setView(toastLayout); + ImageToast.setDuration(Toast.LENGTH_SHORT); + ImageToast.show(); + } + } + } catch (NullPointerException ee) { + + } + try { + if (preference.getKey().equals(KEY_SOUND_EFFECT)) { + Intent i = new Intent( + AudioEffect.ACTION_DISPLAY_AUDIO_EFFECT_CONTROL_PANEL); + try { + i.putExtra(AudioEffect.EXTRA_AUDIO_SESSION, + MusicUtils.sService.getAudioSessionId()); + } catch (Exception e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + startActivityForResult(i, EFFECTS_PANEL); + } + } catch (NullPointerException ee) { + + } + + return super.onPreferenceTreeClick(preferenceScreen, preference); + } +} diff --git a/src/com/android/music/MusicViewPager.java b/src/com/android/music/MusicViewPager.java index 2ad1424..e8895aa 100644 --- a/src/com/android/music/MusicViewPager.java +++ b/src/com/android/music/MusicViewPager.java @@ -1,40 +1,40 @@ -/* - * Copyright (C) 2011 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. - */ - -package com.android.music; - -import android.content.Context; -import android.support.v4.view.ViewPager; -import android.util.AttributeSet; - -public class MusicViewPager extends ViewPager { - public MusicViewPager(Context context) { - super(context); - } - - public MusicViewPager(Context context, AttributeSet attrs) { - super(context, attrs); - } - - /** - * ViewPager inherits ViewGroup's default behavior of delayed clicks on its - * children, but in order to make the calc buttons more responsive we - * disable that here. - */ - public boolean shouldDelayChildPressedState() { - return false; - } -} +/* + * Copyright (C) 2011 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. + */ + +package com.android.music; + +import android.content.Context; +import android.support.v4.view.ViewPager; +import android.util.AttributeSet; + +public class MusicViewPager extends ViewPager { + public MusicViewPager(Context context) { + super(context); + } + + public MusicViewPager(Context context, AttributeSet attrs) { + super(context, attrs); + } + + /** + * ViewPager inherits ViewGroup's default behavior of delayed clicks on its + * children, but in order to make the calc buttons more responsive we + * disable that here. + */ + public boolean shouldDelayChildPressedState() { + return false; + } +} diff --git a/src/com/android/music/PlaylistBrowserActivity.java b/src/com/android/music/PlaylistBrowserActivity.java index 6764f8f..10eeaa1 100644 --- a/src/com/android/music/PlaylistBrowserActivity.java +++ b/src/com/android/music/PlaylistBrowserActivity.java @@ -311,15 +311,9 @@ public boolean onTouch(View vee, MotionEvent nowplayingevent) { mButtonBarSong = (TextView) findViewById(R.id.songtab); mButtonBarPlaylist = (TextView) findViewById(R.id.playlisttab); mButtonBarNP = (TextView) findViewById(R.id.nowplayingtab); - mGroup = (RelativeLayout) findViewById(R.id.group_item); - mChild = (RelativeLayout) findViewById(R.id.child_item); ArtistAlbumBrowserActivity.loadThemeResource(themeResources, themePackage, "tab_playlist", mPlaylistTab, THEME_ITEM_BACKGROUND); - ArtistAlbumBrowserActivity.loadThemeResource(themeResources, - themePackage, "group_bg", mGroup, THEME_ITEM_BACKGROUND); - ArtistAlbumBrowserActivity.loadThemeResource(themeResources, - themePackage, "child_bg", mChild, THEME_ITEM_BACKGROUND); ArtistAlbumBrowserActivity.loadThemeResource(themeResources, themePackage, "buttonbar", mButtonBar, THEME_ITEM_BACKGROUND); @@ -1127,22 +1121,7 @@ public void bindView(View view, Context context, Cursor cursor) { long id = cursor.getLong(mIdIdx); ImageView iv = (ImageView) view.findViewById(R.id.icon); - if (id == RECENTLY_ADDED_PLAYLIST) { - iv.setImageResource(R.drawable.ic_mp_playlist_recently_added_list); - if (themeResources != null) { - ArtistAlbumBrowserActivity.loadThemeResource( - themeResources, themePackage, - "playlist_recently_added", iv, - THEME_ITEM_FOREGROUND); - } - } else { - iv.setImageResource(R.drawable.ic_mp_playlist_list); - if (themeResources != null) { - ArtistAlbumBrowserActivity.loadThemeResource( - themeResources, themePackage, "playlist_list", iv, - THEME_ITEM_FOREGROUND); - } - } + ViewGroup.LayoutParams p = iv.getLayoutParams(); p.width = ViewGroup.LayoutParams.WRAP_CONTENT; p.height = ViewGroup.LayoutParams.WRAP_CONTENT; @@ -1156,6 +1135,7 @@ public void bindView(View view, Context context, Cursor cursor) { .findViewById(R.id.second_column_icon); iv.setVisibility(View.GONE); mContextMenu.setOnClickListener(mCML); + ImageView cM = (ImageView) view.findViewById(R.id.CM); if (themeResources != null) { int line1 = themeResources.getIdentifier( @@ -1164,6 +1144,9 @@ public void bindView(View view, Context context, Cursor cursor) { if (line1 != 0) { tv.setTextColor(themeResources.getColor(line1)); } + ArtistAlbumBrowserActivity.loadThemeResource(themeResources, + themePackage, "bt_context_menu", cM, + THEME_ITEM_FOREGROUND); } } @@ -1233,12 +1216,13 @@ private void setPauseButtonImage() { try { if (mService != null && mService.isPlaying()) { mPlay.setImageResource(R.drawable.ic_media_pause); - ArtistAlbumBrowserActivity.loadThemeResource(themeResources, - themePackage, "np_pause", mPlay, THEME_ITEM_FOREGROUND); + ArtistAlbumBrowserActivity + .loadThemeResource(themeResources, themePackage, + "snp_pause", mPlay, THEME_ITEM_FOREGROUND); } else { mPlay.setImageResource(R.drawable.ic_appwidget_music_play); ArtistAlbumBrowserActivity.loadThemeResource(themeResources, - themePackage, "np_play", mPlay, THEME_ITEM_FOREGROUND); + themePackage, "snp_play", mPlay, THEME_ITEM_FOREGROUND); } } catch (RemoteException ex) { } diff --git a/src/com/android/music/Sensitivity.java b/src/com/android/music/Sensitivity.java index 8113fc6..eca85af 100644 --- a/src/com/android/music/Sensitivity.java +++ b/src/com/android/music/Sensitivity.java @@ -1,113 +1,113 @@ -package com.android.music; - -import android.app.Activity; -import android.app.AlertDialog; -import android.content.DialogInterface; -import android.content.SharedPreferences; -import android.os.Bundle; -import android.preference.PreferenceManager; -import android.widget.ImageView; -import android.widget.SeekBar; -import android.widget.TextView; - -public class Sensitivity extends Activity implements - SeekBar.OnSeekBarChangeListener { - - private int shakeChange; - private int flipChange; - private int bool; - - SeekBar shake; - SeekBar flip; - TextView mProgressText; - ImageView mFlip; - ImageView mShake; - - SharedPreferences mPrefs; - - AlertDialog alert; - - @Override - protected void onCreate(Bundle savedInstanceState) { - // TODO Auto-generated method stub - super.onCreate(savedInstanceState); - setContentView(R.layout.sensitive); - - mPrefs = PreferenceManager.getDefaultSharedPreferences(this); - loadPreferences(); - - shake = (SeekBar) findViewById(R.id.shake_sens); - flip = (SeekBar) findViewById(R.id.flip_sens); - mShake = (ImageView) findViewById(R.id.iv_shake_sens); - mFlip = (ImageView) findViewById(R.id.iv_flip_sens); - - mShake.setImageResource(R.drawable.ic_shake); - mFlip.setImageResource(R.drawable.ic_flip); - - shake.setOnSeekBarChangeListener(this); - flip.setOnSeekBarChangeListener(this); - shake.setProgress(shakeChange); - flip.setProgress(flipChange); - - AlertDialog.Builder builder = new AlertDialog.Builder(this); - builder.setTitle("Restart Required"); - builder.setIcon(R.drawable.ic_dialog_alert_holo_dark); - builder.setMessage( - "Music will restart after you make your changes to use them immeditately.") - .setCancelable(false) - .setPositiveButton("Okay", - new DialogInterface.OnClickListener() { - public void onClick(DialogInterface dialog, int id) { - - } - }); - alert = builder.create(); - alert.show(); - } - - @Override - public void onStop() { - super.onStop(); - saveSens(); - System.exit(0); - - } - - private void saveSens() { - SharedPreferences.Editor editor = mPrefs.edit(); - editor.putInt(MusicSettingsActivity.SHAKE_SENSITIVITY, shakeChange); - editor.putInt(MusicSettingsActivity.FLIP_SENSITIVITY, flipChange); - editor.commit(); - } - - private void loadPreferences() { - shakeChange = new Integer(mPrefs.getInt( - MusicSettingsActivity.SHAKE_SENSITIVITY, - (int) (MusicSettingsActivity.DEFAULT_SHAKE_SENS))); - flipChange = new Integer(mPrefs.getInt( - MusicSettingsActivity.FLIP_SENSITIVITY, - MusicSettingsActivity.DEFAULT_FLIP_SENS)); - } - - public void onProgressChanged(SeekBar seekBar, int progress, - boolean fromUser) { - if (seekBar == shake) - shakeChange = progress; - else if (seekBar == flip) - flipChange = progress; - - } - - @Override - public void onStartTrackingTouch(SeekBar seekBar) { - // TODO Auto-generated method stub - - } - - @Override - public void onStopTrackingTouch(SeekBar seekBar) { - // TODO Auto-generated method stub - - } - -} +package com.android.music; + +import android.app.Activity; +import android.app.AlertDialog; +import android.content.DialogInterface; +import android.content.SharedPreferences; +import android.os.Bundle; +import android.preference.PreferenceManager; +import android.widget.ImageView; +import android.widget.SeekBar; +import android.widget.TextView; + +public class Sensitivity extends Activity implements + SeekBar.OnSeekBarChangeListener { + + private int shakeChange; + private int flipChange; + private int bool; + + SeekBar shake; + SeekBar flip; + TextView mProgressText; + ImageView mFlip; + ImageView mShake; + + SharedPreferences mPrefs; + + AlertDialog alert; + + @Override + protected void onCreate(Bundle savedInstanceState) { + // TODO Auto-generated method stub + super.onCreate(savedInstanceState); + setContentView(R.layout.sensitive); + + mPrefs = PreferenceManager.getDefaultSharedPreferences(this); + loadPreferences(); + + shake = (SeekBar) findViewById(R.id.shake_sens); + flip = (SeekBar) findViewById(R.id.flip_sens); + mShake = (ImageView) findViewById(R.id.iv_shake_sens); + mFlip = (ImageView) findViewById(R.id.iv_flip_sens); + + mShake.setImageResource(R.drawable.ic_shake); + mFlip.setImageResource(R.drawable.ic_flip); + + shake.setOnSeekBarChangeListener(this); + flip.setOnSeekBarChangeListener(this); + shake.setProgress(shakeChange); + flip.setProgress(flipChange); + + AlertDialog.Builder builder = new AlertDialog.Builder(this); + builder.setTitle("Restart Required"); + builder.setIcon(R.drawable.ic_dialog_alert_holo_dark); + builder.setMessage( + "Music will restart after you make your changes to use them immeditately.") + .setCancelable(false) + .setPositiveButton("Okay", + new DialogInterface.OnClickListener() { + public void onClick(DialogInterface dialog, int id) { + + } + }); + alert = builder.create(); + alert.show(); + } + + @Override + public void onStop() { + super.onStop(); + saveSens(); + System.exit(0); + + } + + private void saveSens() { + SharedPreferences.Editor editor = mPrefs.edit(); + editor.putInt(MusicSettingsActivity.SHAKE_SENSITIVITY, shakeChange); + editor.putInt(MusicSettingsActivity.FLIP_SENSITIVITY, flipChange); + editor.commit(); + } + + private void loadPreferences() { + shakeChange = new Integer(mPrefs.getInt( + MusicSettingsActivity.SHAKE_SENSITIVITY, + (int) (MusicSettingsActivity.DEFAULT_SHAKE_SENS))); + flipChange = new Integer(mPrefs.getInt( + MusicSettingsActivity.FLIP_SENSITIVITY, + MusicSettingsActivity.DEFAULT_FLIP_SENS)); + } + + public void onProgressChanged(SeekBar seekBar, int progress, + boolean fromUser) { + if (seekBar == shake) + shakeChange = progress; + else if (seekBar == flip) + flipChange = progress; + + } + + @Override + public void onStartTrackingTouch(SeekBar seekBar) { + // TODO Auto-generated method stub + + } + + @Override + public void onStopTrackingTouch(SeekBar seekBar) { + // TODO Auto-generated method stub + + } + +} diff --git a/src/com/android/music/Shaker.java b/src/com/android/music/Shaker.java index de72fcd..1805ae8 100644 --- a/src/com/android/music/Shaker.java +++ b/src/com/android/music/Shaker.java @@ -1,89 +1,91 @@ -package com.android.music; - -import android.content.Context; -import android.hardware.Sensor; -import android.hardware.SensorEvent; -import android.hardware.SensorEventListener; -import android.hardware.SensorManager; -import android.os.SystemClock; -import com.android.music.R; - -public class Shaker { - private SensorManager mgr = null; - private long lastShakeTimestamp = 0; - private double threshold = 1.0d; - private long gap = 0; - private Shaker.Callback cb = null; - - public Shaker(Context ctxt, double threshold, long gap, Shaker.Callback cb) { - this.threshold = threshold * threshold; - this.threshold = this.threshold * SensorManager.GRAVITY_EARTH - * SensorManager.GRAVITY_EARTH; - this.gap = gap; - this.cb = cb; - - mgr = (SensorManager) ctxt.getSystemService(Context.SENSOR_SERVICE); - mgr.registerListener(listener, - mgr.getDefaultSensor(Sensor.TYPE_ACCELEROMETER), - SensorManager.SENSOR_DELAY_UI); - } - - public void close() { - mgr.unregisterListener(listener); - } - - private void isShaking() { - long now = SystemClock.uptimeMillis(); - - if (lastShakeTimestamp == 0) { - lastShakeTimestamp = now; - - if (cb != null) { - cb.shakingStarted(); - } - } else { - lastShakeTimestamp = now; - } - } - - private void isNotShaking() { - long now = SystemClock.uptimeMillis(); - - if (lastShakeTimestamp > 0) { - if (now - lastShakeTimestamp > gap) { - lastShakeTimestamp = 0; - - if (cb != null) { - cb.shakingStopped(); - } - } - } - } - - public interface Callback { - void shakingStarted(); - - void shakingStopped(); - } - - private SensorEventListener listener = new SensorEventListener() { - public void onSensorChanged(SensorEvent e) { - if (e.sensor.getType() == Sensor.TYPE_ACCELEROMETER) { - double netForce = e.values[0] * e.values[0]; - - netForce += e.values[1] * e.values[1]; - netForce += e.values[2] * e.values[2]; - - if (threshold < netForce) { - isShaking(); - } else { - isNotShaking(); - } - } - } - - public void onAccuracyChanged(Sensor sensor, int accuracy) { - // unused - } - }; +package com.android.music; + +import android.content.Context; +import android.hardware.Sensor; +import android.hardware.SensorEvent; +import android.hardware.SensorEventListener; +import android.hardware.SensorManager; +import android.os.SystemClock; + +public class Shaker { + private SensorManager mgr = null; + private long lastShakeTimestamp = 0; + private double threshold = 1.0d; + private long gap = 0; + private Shaker.Callback cb = null; + + public Shaker(Context ctxt, double threshold, long gap, Shaker.Callback cb) { + this.threshold = threshold * threshold; + this.threshold = this.threshold * SensorManager.GRAVITY_EARTH + * SensorManager.GRAVITY_EARTH; + this.gap = gap; + this.cb = cb; + + mgr = (SensorManager) ctxt.getSystemService(Context.SENSOR_SERVICE); + mgr.registerListener(listener, + mgr.getDefaultSensor(Sensor.TYPE_ACCELEROMETER), + SensorManager.SENSOR_DELAY_UI); + } + + public void close() { + mgr.unregisterListener(listener); + } + + private void isShaking() { + long now = SystemClock.uptimeMillis(); + try { + if (lastShakeTimestamp == 0) { + lastShakeTimestamp = now; + + if (cb != null) { + cb.shakingStarted(); + } + } else { + lastShakeTimestamp = now; + } + } catch (NullPointerException e) { + + } + } + + private void isNotShaking() { + long now = SystemClock.uptimeMillis(); + + if (lastShakeTimestamp > 0) { + if (now - lastShakeTimestamp > gap) { + lastShakeTimestamp = 0; + + if (cb != null) { + cb.shakingStopped(); + } + } + } + } + + public interface Callback { + void shakingStarted(); + + void shakingStopped(); + } + + private SensorEventListener listener = new SensorEventListener() { + public void onSensorChanged(SensorEvent e) { + if (e.sensor.getType() == Sensor.TYPE_ACCELEROMETER) { + double netForce = e.values[0] * e.values[0]; + + netForce += e.values[1] * e.values[1]; + netForce += e.values[2] * e.values[2]; + + if (threshold < netForce) { + isShaking(); + } else { + isNotShaking(); + } + } + } + + public void onAccuracyChanged(Sensor sensor, int accuracy) { + // unused + } + }; } \ No newline at end of file diff --git a/src/com/android/music/TrackBrowserActivity.java b/src/com/android/music/TrackBrowserActivity.java index 8354487..2cf1705 100644 --- a/src/com/android/music/TrackBrowserActivity.java +++ b/src/com/android/music/TrackBrowserActivity.java @@ -235,6 +235,30 @@ public void onCreate(Bundle icicle) { ((TouchInterceptor) mTrackList).setRemoveListener(mRemoveListener); mTrackList.setDivider(null); mTrackList.setSelector(R.drawable.list_selector_background); + // ADW: Load the specified theme + String themePackage = MusicUtils.getThemePackageName(this, + MusicSettingsActivity.THEME_DEFAULT); + PackageManager pm = getPackageManager(); + Resources themeResources = null; + if (!themePackage.equals(MusicSettingsActivity.THEME_DEFAULT)) { + try { + themeResources = pm + .getResourcesForApplication(themePackage); + } catch (NameNotFoundException e) { + // ADW The saved theme was uninstalled so we save the + // default one + MusicUtils.setThemePackageName(this, + MusicSettingsActivity.THEME_DEFAULT); + } + } + // Set Views for themes + if (themeResources != null) { + int lS = themeResources.getIdentifier("queue_selector", + "drawable", themePackage); + if (lS != 0) { + mTrackList.setSelector(themeResources.getDrawable(lS)); + } + } } else { mTrackList.setTextFilterEnabled(true); } @@ -323,14 +347,8 @@ public boolean onTouch(View vee, MotionEvent nowplayingevent) { mButtonBarSong = (TextView) findViewById(R.id.songtab); mButtonBarPlaylist = (TextView) findViewById(R.id.playlisttab); mButtonBarNP = (TextView) findViewById(R.id.nowplayingtab); - mGroup = (RelativeLayout) findViewById(R.id.group_item); - mChild = (RelativeLayout) findViewById(R.id.child_item); ArtistAlbumBrowserActivity.loadThemeResource(themeResources, themePackage, "tab_song", mSongTab, THEME_ITEM_BACKGROUND); - ArtistAlbumBrowserActivity.loadThemeResource(themeResources, - themePackage, "group_bg", mGroup, THEME_ITEM_BACKGROUND); - ArtistAlbumBrowserActivity.loadThemeResource(themeResources, - themePackage, "child_bg", mChild, THEME_ITEM_BACKGROUND); ArtistAlbumBrowserActivity.loadThemeResource(themeResources, themePackage, "buttonbar", mButtonBar, THEME_ITEM_BACKGROUND); @@ -2072,12 +2090,31 @@ public View newView(Context context, Cursor cursor, ViewGroup parent) { if (duration != 0) { vh.duration.setTextColor(themeResources.getColor(duration)); } + ArtistAlbumBrowserActivity.loadThemeResource(themeResources, + themePackage, "bt_context_menu", vh.mCM, + THEME_ITEM_FOREGROUND); } return v; } @Override public void bindView(View view, Context context, Cursor cursor) { + // ADW: Load the specified theme + String themePackage = MusicUtils.getThemePackageName(context, + MusicSettingsActivity.THEME_DEFAULT); + PackageManager pm = context.getPackageManager(); + Resources themeResources = null; + if (!themePackage.equals(MusicSettingsActivity.THEME_DEFAULT)) { + try { + themeResources = pm + .getResourcesForApplication(themePackage); + } catch (NameNotFoundException e) { + // ADW The saved theme was uninstalled so we save the + // default one + MusicUtils.setThemePackageName(context, + MusicSettingsActivity.THEME_DEFAULT); + } + } ViewHolder vh = (ViewHolder) view.getTag(); @@ -2144,10 +2181,17 @@ public void bindView(View view, Context context, Cursor cursor) { iv.setBackgroundResource(R.anim.peak_meter); AnimationDrawable frameAnimation = (AnimationDrawable) iv .getBackground(); - + if (themeResources != null) { + int peak = themeResources.getIdentifier("peak_meter", + "anim", themePackage); + if (peak != 0) { + iv.setBackgroundDrawable(themeResources + .getDrawable(peak)); + frameAnimation.start(); + } + } // Start the animation (looped playback by default). frameAnimation.start(); - iv.setVisibility(View.VISIBLE); } else { iv.setVisibility(View.GONE); @@ -2239,12 +2283,13 @@ private void setPauseButtonImage() { try { if (mService != null && mService.isPlaying()) { mPlay.setImageResource(R.drawable.ic_media_pause); - ArtistAlbumBrowserActivity.loadThemeResource(themeResources, - themePackage, "np_pause", mPlay, THEME_ITEM_FOREGROUND); + ArtistAlbumBrowserActivity + .loadThemeResource(themeResources, themePackage, + "snp_pause", mPlay, THEME_ITEM_FOREGROUND); } else { mPlay.setImageResource(R.drawable.ic_appwidget_music_play); ArtistAlbumBrowserActivity.loadThemeResource(themeResources, - themePackage, "np_play", mPlay, THEME_ITEM_FOREGROUND); + themePackage, "snp_play", mPlay, THEME_ITEM_FOREGROUND); } } catch (RemoteException ex) { }