diff options
-rw-r--r-- | AndroidManifest.xml | 13 | ||||
-rw-r--r-- | src/com/cyngn/eleven/appwidgets/AppWidgetLarge.java | 33 | ||||
-rw-r--r-- | src/com/cyngn/eleven/appwidgets/AppWidgetLargeAlternate.java | 36 | ||||
-rw-r--r-- | src/com/cyngn/eleven/appwidgets/AppWidgetSmall.java | 32 | ||||
-rw-r--r-- | src/com/cyngn/eleven/ui/activities/HomeActivity.java | 3 | ||||
-rw-r--r-- | src/com/cyngn/eleven/ui/activities/ShortcutActivity.java | 312 | ||||
-rw-r--r-- | src/com/cyngn/eleven/utils/ApolloUtils.java | 1 | ||||
-rw-r--r-- | src/com/cyngn/eleven/utils/NavUtils.java | 1 |
8 files changed, 29 insertions, 402 deletions
diff --git a/AndroidManifest.xml b/AndroidManifest.xml index 7d8233e..c45c5b5 100644 --- a/AndroidManifest.xml +++ b/AndroidManifest.xml @@ -132,19 +132,6 @@ </intent-filter> </activity> - <!-- Shortcut launcher Activity --> - <activity - android:name=".ui.activities.ShortcutActivity" - android:excludeFromRecents="true" - android:exported="true" - android:theme="@style/Theme.Transparent" - android:screenOrientation="portrait"> - <intent-filter> - <action android:name="android.media.action.MEDIA_PLAY_FROM_SEARCH" /> - - <category android:name="android.intent.category.DEFAULT" /> - </intent-filter> - </activity> <!-- Search interface --> <activity android:name=".ui.activities.SearchActivity" diff --git a/src/com/cyngn/eleven/appwidgets/AppWidgetLarge.java b/src/com/cyngn/eleven/appwidgets/AppWidgetLarge.java index e313e98..b205879 100644 --- a/src/com/cyngn/eleven/appwidgets/AppWidgetLarge.java +++ b/src/com/cyngn/eleven/appwidgets/AppWidgetLarge.java @@ -66,7 +66,7 @@ public class AppWidgetLarge extends AppWidgetBase { private void defaultAppWidget(final Context context, final int[] appWidgetIds) { final RemoteViews appWidgetViews = new RemoteViews(context.getPackageName(), R.layout.app_widget_large); - linkButtons(context, appWidgetViews, false); + linkButtons(context, appWidgetViews); pushUpdate(context, appWidgetIds, appWidgetViews); } @@ -140,7 +140,7 @@ public class AppWidgetLarge extends AppWidgetBase { } // Link actions buttons to intents - linkButtons(service, appWidgetView, isPlaying); + linkButtons(service, appWidgetView); // Update the app-widget pushUpdate(service, appWidgetIds, appWidgetView); @@ -149,34 +149,19 @@ public class AppWidgetLarge extends AppWidgetBase { /** * Link up various button actions using {@link PendingIntents}. * - * @param playerActive True if player is active in background, which means - * widget click will launch {@link AudioPlayerFragment}, - * otherwise we launch {@link MusicBrowserActivity}. */ - private void linkButtons(final Context context, final RemoteViews views, - final boolean playerActive) { + private void linkButtons(final Context context, final RemoteViews views) { Intent action; PendingIntent pendingIntent; final ComponentName serviceName = new ComponentName(context, MusicPlaybackService.class); - // Now playing - if (playerActive) { - action = new Intent(context, HomeActivity.class); - action.setAction(HomeActivity.ACTION_VIEW_MUSIC_PLAYER); - action.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP); - pendingIntent = PendingIntent.getActivity(context, 0, action, 0); - views.setOnClickPendingIntent(R.id.app_widget_large_info_container, pendingIntent); - views.setOnClickPendingIntent(R.id.app_widget_large_image, pendingIntent); - } else { - // Home - action = new Intent(context, HomeActivity.class); - action.setAction(HomeActivity.ACTION_VIEW_BROWSE); - action.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP); - pendingIntent = PendingIntent.getActivity(context, 0, action, 0); - views.setOnClickPendingIntent(R.id.app_widget_large_info_container, pendingIntent); - views.setOnClickPendingIntent(R.id.app_widget_large_image, pendingIntent); - } + // Home + action = new Intent(context, HomeActivity.class); + action.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP); + pendingIntent = PendingIntent.getActivity(context, 0, action, 0); + views.setOnClickPendingIntent(R.id.app_widget_large_info_container, pendingIntent); + views.setOnClickPendingIntent(R.id.app_widget_large_image, pendingIntent); // Previous track pendingIntent = buildPendingIntent(context, MusicPlaybackService.PREVIOUS_ACTION, serviceName); diff --git a/src/com/cyngn/eleven/appwidgets/AppWidgetLargeAlternate.java b/src/com/cyngn/eleven/appwidgets/AppWidgetLargeAlternate.java index 4cea3ff..adfc568 100644 --- a/src/com/cyngn/eleven/appwidgets/AppWidgetLargeAlternate.java +++ b/src/com/cyngn/eleven/appwidgets/AppWidgetLargeAlternate.java @@ -69,7 +69,7 @@ public class AppWidgetLargeAlternate extends AppWidgetBase { private void defaultAppWidget(final Context context, final int[] appWidgetIds) { final RemoteViews appWidgetViews = new RemoteViews(context.getPackageName(), R.layout.app_widget_large_alternate); - linkButtons(context, appWidgetViews, false); + linkButtons(context, appWidgetViews); pushUpdate(context, appWidgetIds, appWidgetViews); } @@ -185,7 +185,7 @@ public class AppWidgetLargeAlternate extends AppWidgetBase { } // Link actions buttons to intents - linkButtons(service, appWidgetView, isPlaying); + linkButtons(service, appWidgetView); // Update the app-widget pushUpdate(service, appWidgetIds, appWidgetView); @@ -194,35 +194,21 @@ public class AppWidgetLargeAlternate extends AppWidgetBase { /** * Link up various button actions using {@link PendingIntents}. * - * @param playerActive True if player is active in background, which means - * widget click will launch {@link AudioPlayerFragment}, - * otherwise we launch {@link MusicBrowserActivity}. */ - private void linkButtons(final Context context, final RemoteViews views, - final boolean playerActive) { + private void linkButtons(final Context context, final RemoteViews views) { Intent action; PendingIntent pendingIntent; final ComponentName serviceName = new ComponentName(context, MusicPlaybackService.class); - // Now playing - if (playerActive) { - action = new Intent(context, HomeActivity.class); - action.setAction(HomeActivity.ACTION_VIEW_MUSIC_PLAYER); - pendingIntent = PendingIntent.getActivity(context, 0, action, 0); - views.setOnClickPendingIntent(R.id.app_widget_large_alternate_info_container, - pendingIntent); - views.setOnClickPendingIntent(R.id.app_widget_large_alternate_image, pendingIntent); - } else { - // Home - action = new Intent(context, HomeActivity.class); - action.setAction(HomeActivity.ACTION_VIEW_BROWSE); - action.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP); - pendingIntent = PendingIntent.getActivity(context, 0, action, 0); - views.setOnClickPendingIntent(R.id.app_widget_large_alternate_info_container, - pendingIntent); - views.setOnClickPendingIntent(R.id.app_widget_large_alternate_image, pendingIntent); - } + // Home + action = new Intent(context, HomeActivity.class); + action.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP); + pendingIntent = PendingIntent.getActivity(context, 0, action, 0); + views.setOnClickPendingIntent(R.id.app_widget_large_alternate_info_container, + pendingIntent); + views.setOnClickPendingIntent(R.id.app_widget_large_alternate_image, pendingIntent); + // Shuffle modes pendingIntent = buildPendingIntent(context, MusicPlaybackService.SHUFFLE_ACTION, serviceName); views.setOnClickPendingIntent(R.id.app_widget_large_alternate_shuffle, pendingIntent); diff --git a/src/com/cyngn/eleven/appwidgets/AppWidgetSmall.java b/src/com/cyngn/eleven/appwidgets/AppWidgetSmall.java index 560994e..31f8db2 100644 --- a/src/com/cyngn/eleven/appwidgets/AppWidgetSmall.java +++ b/src/com/cyngn/eleven/appwidgets/AppWidgetSmall.java @@ -69,7 +69,7 @@ public class AppWidgetSmall extends AppWidgetBase { final RemoteViews appWidgetViews = new RemoteViews(context.getPackageName(), R.layout.app_widget_small); appWidgetViews.setViewVisibility(R.id.app_widget_small_info_container, View.INVISIBLE); - linkButtons(context, appWidgetViews, false); + linkButtons(context, appWidgetViews); pushUpdate(context, appWidgetIds, appWidgetViews); } @@ -146,7 +146,7 @@ public class AppWidgetSmall extends AppWidgetBase { } // Link actions buttons to intents - linkButtons(service, appWidgetView, isPlaying); + linkButtons(service, appWidgetView); // Update the app-widget pushUpdate(service, appWidgetIds, appWidgetView); @@ -155,33 +155,19 @@ public class AppWidgetSmall extends AppWidgetBase { /** * Link up various button actions using {@link PendingIntents}. * - * @param playerActive True if player is active in background, which means - * widget click will launch {@link AudioPlayerFragment}, - * otherwise we launch {@link MusicBrowserActivity}. */ - private void linkButtons(final Context context, final RemoteViews views, - final boolean playerActive) { + private void linkButtons(final Context context, final RemoteViews views) { Intent action; PendingIntent pendingIntent; final ComponentName serviceName = new ComponentName(context, MusicPlaybackService.class); - // Now playing - if (playerActive) { - action = new Intent(context, HomeActivity.class); - action.setAction(HomeActivity.ACTION_VIEW_MUSIC_PLAYER); - pendingIntent = PendingIntent.getActivity(context, 0, action, 0); - views.setOnClickPendingIntent(R.id.app_widget_small_info_container, pendingIntent); - views.setOnClickPendingIntent(R.id.app_widget_small_image, pendingIntent); - } else { - // Home - action = new Intent(context, HomeActivity.class); - action.setAction(HomeActivity.ACTION_VIEW_BROWSE); - action.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP); - pendingIntent = PendingIntent.getActivity(context, 0, action, 0); - views.setOnClickPendingIntent(R.id.app_widget_small_info_container, pendingIntent); - views.setOnClickPendingIntent(R.id.app_widget_small_image, pendingIntent); - } + // Home + action = new Intent(context, HomeActivity.class); + action.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP); + pendingIntent = PendingIntent.getActivity(context, 0, action, 0); + views.setOnClickPendingIntent(R.id.app_widget_small_info_container, pendingIntent); + views.setOnClickPendingIntent(R.id.app_widget_small_image, pendingIntent); // Previous track pendingIntent = buildPendingIntent(context, MusicPlaybackService.PREVIOUS_ACTION, serviceName); diff --git a/src/com/cyngn/eleven/ui/activities/HomeActivity.java b/src/com/cyngn/eleven/ui/activities/HomeActivity.java index 4a5f08f..34f6c8b 100644 --- a/src/com/cyngn/eleven/ui/activities/HomeActivity.java +++ b/src/com/cyngn/eleven/ui/activities/HomeActivity.java @@ -44,9 +44,6 @@ import com.cyngn.eleven.utils.NavUtils; public class HomeActivity extends SlidingPanelActivity { private static final String ACTION_PREFIX = HomeActivity.class.getName(); - public static final String ACTION_VIEW_BROWSE = ACTION_PREFIX + ".view.Browse"; - public static final String ACTION_VIEW_MUSIC_PLAYER = ACTION_PREFIX + ".view.MusicPlayer"; - public static final String ACTION_VIEW_QUEUE = ACTION_PREFIX + ".view.Queue"; public static final String ACTION_VIEW_ARTIST_DETAILS = ACTION_PREFIX + ".view.ArtistDetails"; public static final String ACTION_VIEW_ALBUM_DETAILS = ACTION_PREFIX + ".view.AlbumDetails"; public static final String ACTION_VIEW_PLAYLIST_DETAILS = ACTION_PREFIX + ".view.PlaylistDetails"; diff --git a/src/com/cyngn/eleven/ui/activities/ShortcutActivity.java b/src/com/cyngn/eleven/ui/activities/ShortcutActivity.java deleted file mode 100644 index 79d3b57..0000000 --- a/src/com/cyngn/eleven/ui/activities/ShortcutActivity.java +++ /dev/null @@ -1,312 +0,0 @@ -/* - * Copyright (C) 2012 Andrew Neal 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.cyngn.eleven.ui.activities; - -import static com.cyngn.eleven.Config.MIME_TYPE; -import static com.cyngn.eleven.utils.MusicUtils.mService; - -import android.app.SearchManager; -import android.content.ComponentName; -import android.content.Intent; -import android.content.ServiceConnection; -import android.database.Cursor; -import android.os.Bundle; -import android.os.IBinder; -import android.provider.MediaStore; -import android.support.v4.app.FragmentActivity; -import android.support.v4.app.LoaderManager.LoaderCallbacks; -import android.support.v4.content.Loader; - -import com.cyngn.eleven.Config; -import com.cyngn.eleven.IElevenService; -import com.cyngn.eleven.R; -import com.cyngn.eleven.format.Capitalize; -import com.cyngn.eleven.loaders.AsyncHandler; -import com.cyngn.eleven.loaders.LastAddedLoader; -import com.cyngn.eleven.loaders.SearchLoader; -import com.cyngn.eleven.model.Song; -import com.cyngn.eleven.utils.Lists; -import com.cyngn.eleven.utils.MusicUtils; -import com.cyngn.eleven.utils.MusicUtils.ServiceToken; - -import java.util.ArrayList; -import java.util.List; - -/** - * This class is opened when the user touches a Home screen shortcut or album - * art in an app-wdget, and then carries out the proper action. It is also - * responsible for processing voice queries and playing the spoken artist, - * album, song, playlist, or genre. - * - * @author Andrew Neal (andrewdneal@gmail.com) - */ -public class ShortcutActivity extends FragmentActivity implements ServiceConnection { - - /** - * If true, this class will begin playback and open - * {@link AudioPlayerFragment}, false will close the class after playback, - * which is what happens when a user starts playing something from an - * app-widget - */ - public static final String OPEN_AUDIO_PLAYER = null; - - /** - * Service token - */ - private ServiceToken mToken; - - /** - * Gather the intent action and extras - */ - private Intent mIntent; - - /** - * The list of songs to play - */ - private long[] mList; - - /** - * Used to shuffle the tracks or play them in order - */ - private boolean mShouldShuffle; - - /** - * Search query from a voice action - */ - private String mVoiceQuery; - - /** - * Used with the loader and voice queries - */ - private final ArrayList<Song> mSong = Lists.newArrayList(); - - /** - * {@inheritDoc} - */ - @Override - protected void onCreate(final Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - // Fade it in - overridePendingTransition(android.R.anim.fade_in, android.R.anim.fade_out); - - // Bind Apollo's service - mToken = MusicUtils.bindToService(this, this); - - // Intiialize the intent - mIntent = getIntent(); - // Get the voice search query - mVoiceQuery = Capitalize.capitalize(mIntent.getStringExtra(SearchManager.QUERY)); - - } - - /** - * {@inheritDoc} - */ - @Override - public void onServiceConnected(final ComponentName name, final IBinder service) { - mService = IElevenService.Stub.asInterface(service); - - // Check for a voice query - if (mIntent.getAction().equals(Config.PLAY_FROM_SEARCH)) { - getSupportLoaderManager().initLoader(0, null, mSongAlbumArtistQuery); - } else if (mService != null) { - AsyncHandler.post(new Runnable() { - @Override - public void run() { - final String requestedMimeType = mIntent.getExtras().getString(MIME_TYPE); - - // First, check the artist MIME type - if (MediaStore.Audio.Artists.CONTENT_TYPE.equals(requestedMimeType)) { - - // Shuffle the artist track list - mShouldShuffle = true; - - // Get the artist song list - mList = MusicUtils.getSongListForArtist(ShortcutActivity.this, getId()); - } else - // Second, check the album MIME type - if (MediaStore.Audio.Albums.CONTENT_TYPE.equals(requestedMimeType)) { - - // Shuffle the album track list - mShouldShuffle = true; - - // Get the album song list - mList = MusicUtils.getSongListForAlbum(ShortcutActivity.this, getId()); - } else - // Third, check the genre MIME type - if (MediaStore.Audio.Genres.CONTENT_TYPE.equals(requestedMimeType)) { - - // Shuffle the genre track list - mShouldShuffle = true; - - // Get the genre song list - mList = MusicUtils.getSongListForGenre(ShortcutActivity.this, getId()); - } else - // Fourth, check the playlist MIME type - if (MediaStore.Audio.Playlists.CONTENT_TYPE.equals(requestedMimeType)) { - - // Don't shuffle the playlist track list - mShouldShuffle = false; - - // Get the playlist song list - mList = MusicUtils.getSongListForPlaylist(ShortcutActivity.this, getId()); - } else - // Check for the Last added playlist - if (getString(R.string.playlist_last_added).equals(requestedMimeType)) { - - // Don't shuffle the last added track list - mShouldShuffle = false; - - // Get the Last added song list - Cursor cursor = LastAddedLoader.makeLastAddedCursor(ShortcutActivity.this); - if (cursor != null) { - mList = MusicUtils.getSongListForCursor(cursor); - cursor.close(); - } - } - // Finish up - allDone(); - } - }); - } else { - // TODO Show and error explaining why - } - } - - /** - * {@inheritDoc} - */ - @Override - public void onServiceDisconnected(final ComponentName name) { - mService = null; - } - - /** - * {@inheritDoc} - */ - @Override - protected void onDestroy() { - super.onDestroy(); - // Unbind from the service - if (mService != null) { - MusicUtils.unbindFromService(mToken); - mToken = null; - } - } - - /** - * Uses the query from a voice search to try and play a song, then album, - * then artist. If all of those fail, it checks for playlists and genres via - * a {@link #mPlaylistGenreQuery}. - */ - private final LoaderCallbacks<List<Song>> mSongAlbumArtistQuery = new LoaderCallbacks<List<Song>>() { - - /** - * {@inheritDoc} - */ - @Override - public Loader<List<Song>> onCreateLoader(final int id, final Bundle args) { - return new SearchLoader(ShortcutActivity.this, mVoiceQuery); - } - - /** - * {@inheritDoc} - */ - @Override - public void onLoadFinished(final Loader<List<Song>> loader, final List<Song> data) { - // If the user searched for a playlist or genre, this list will - // return empty - if (data.isEmpty()) { - // Finish up - allDone(); - return; - } - - // Start fresh - mSong.clear(); - // Add the data to the adpater - for (final Song song : data) { - mSong.add(song); - } - - // What's about to happen is similar to the above process. Apollo - // runs a - // series of checks to see if anything comes up. When it does, it - // assumes (pretty accurately) that it should begin to play that - // thing. - // The fancy search query used in {@link SearchLoader} is the key to - // this. It allows the user to perform very specific queries. i.e. - // "Listen to Ethio - - final String song = mSong.get(0).mSongName; - final String album = mSong.get(0).mAlbumName; - final String artist = mSong.get(0).mArtistName; - // This tripes as the song, album, and artist Id - final long id = mSong.get(0).mSongId; - // First, try to play a song - if (mList == null && song != null) { - mList = new long[] { - id - }; - } else - // Second, try to play an album - if (mList == null && album != null) { - mList = MusicUtils.getSongListForAlbum(ShortcutActivity.this, id); - } else - // Third, try to play an artist - if (mList == null && artist != null) { - mList = MusicUtils.getSongListForArtist(ShortcutActivity.this, id); - } - // Finish up - allDone(); - } - - /** - * {@inheritDoc} - */ - @Override - public void onLoaderReset(final Loader<List<Song>> loader) { - // Clear the data - mSong.clear(); - } - }; - - /** - * Used to find the Id supplied - * - * @return The Id passed into the activity - */ - private long getId() { - return mIntent.getExtras().getLong(Config.ID); - } - - /** - * Starts playback, open {@link AudioPlayerFragment} and finishes this one - */ - private void allDone() { - final boolean shouldOpenAudioPlayer = mIntent.getBooleanExtra(OPEN_AUDIO_PLAYER, true); - // Play the list - if (mList != null && mList.length > 0) { - MusicUtils.playAll(this, mList, 0, -1, Config.IdType.NA, mShouldShuffle); - } - - // Open the now playing screen - if (shouldOpenAudioPlayer) { - final Intent intent = new Intent(this, HomeActivity.class); - intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP); - intent.setAction(HomeActivity.ACTION_VIEW_MUSIC_PLAYER); - startActivity(intent); - } - // All done - finish(); - } -} diff --git a/src/com/cyngn/eleven/utils/ApolloUtils.java b/src/com/cyngn/eleven/utils/ApolloUtils.java index b1abc0b..615940f 100644 --- a/src/com/cyngn/eleven/utils/ApolloUtils.java +++ b/src/com/cyngn/eleven/utils/ApolloUtils.java @@ -45,7 +45,6 @@ import com.cyngn.eleven.Config; import com.cyngn.eleven.R; import com.cyngn.eleven.cache.ImageCache; import com.cyngn.eleven.cache.ImageFetcher; -import com.cyngn.eleven.ui.activities.ShortcutActivity; import com.cyngn.eleven.widgets.ColorPickerView; import java.util.concurrent.RejectedExecutionHandler; diff --git a/src/com/cyngn/eleven/utils/NavUtils.java b/src/com/cyngn/eleven/utils/NavUtils.java index a19d226..afa54a4 100644 --- a/src/com/cyngn/eleven/utils/NavUtils.java +++ b/src/com/cyngn/eleven/utils/NavUtils.java @@ -154,7 +154,6 @@ public final class NavUtils { */ public static void goHome(final Activity activity, final int browseIndex) { final Intent intent = new Intent(activity, HomeActivity.class); - intent.setAction(HomeActivity.ACTION_VIEW_BROWSE); intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK); intent.putExtra(HomeActivity.EXTRA_BROWSE_PAGE_IDX, browseIndex); |