diff options
Diffstat (limited to 'src')
11 files changed, 350 insertions, 293 deletions
diff --git a/src/com/cyngn/eleven/MediaButtonIntentReceiver.java b/src/com/cyngn/eleven/MediaButtonIntentReceiver.java index 6c7306a..2f2c6ae 100644 --- a/src/com/cyngn/eleven/MediaButtonIntentReceiver.java +++ b/src/com/cyngn/eleven/MediaButtonIntentReceiver.java @@ -11,7 +11,6 @@ package com.cyngn.eleven; -import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; import android.media.AudioManager; diff --git a/src/com/cyngn/eleven/appwidgets/AppWidgetLarge.java b/src/com/cyngn/eleven/appwidgets/AppWidgetLarge.java index 4cdc851..e313e98 100644 --- a/src/com/cyngn/eleven/appwidgets/AppWidgetLarge.java +++ b/src/com/cyngn/eleven/appwidgets/AppWidgetLarge.java @@ -22,8 +22,8 @@ import android.widget.RemoteViews; import com.cyngn.eleven.MusicPlaybackService; import com.cyngn.eleven.R; -import com.cyngn.eleven.ui.fragments.AudioPlayerFragment; import com.cyngn.eleven.ui.activities.HomeActivity; +import com.cyngn.eleven.ui.fragments.AudioPlayerFragment; import com.cyngn.eleven.utils.ApolloUtils; /** @@ -164,6 +164,7 @@ public class AppWidgetLarge extends AppWidgetBase { 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); @@ -171,6 +172,7 @@ public class AppWidgetLarge extends AppWidgetBase { // 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); diff --git a/src/com/cyngn/eleven/appwidgets/AppWidgetLargeAlternate.java b/src/com/cyngn/eleven/appwidgets/AppWidgetLargeAlternate.java index 729f7a0..36e66f4 100644 --- a/src/com/cyngn/eleven/appwidgets/AppWidgetLargeAlternate.java +++ b/src/com/cyngn/eleven/appwidgets/AppWidgetLargeAlternate.java @@ -22,8 +22,8 @@ import android.widget.RemoteViews; import com.cyngn.eleven.MusicPlaybackService; import com.cyngn.eleven.R; -import com.cyngn.eleven.ui.fragments.AudioPlayerFragment; import com.cyngn.eleven.ui.activities.HomeActivity; +import com.cyngn.eleven.ui.fragments.AudioPlayerFragment; import com.cyngn.eleven.utils.ApolloUtils; /** @@ -207,6 +207,7 @@ public class AppWidgetLargeAlternate extends AppWidgetBase { // 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); diff --git a/src/com/cyngn/eleven/appwidgets/AppWidgetSmall.java b/src/com/cyngn/eleven/appwidgets/AppWidgetSmall.java index 4c34542..560994e 100644 --- a/src/com/cyngn/eleven/appwidgets/AppWidgetSmall.java +++ b/src/com/cyngn/eleven/appwidgets/AppWidgetSmall.java @@ -24,8 +24,8 @@ import android.widget.RemoteViews; import com.cyngn.eleven.MusicPlaybackService; import com.cyngn.eleven.R; -import com.cyngn.eleven.ui.fragments.AudioPlayerFragment; import com.cyngn.eleven.ui.activities.HomeActivity; +import com.cyngn.eleven.ui.fragments.AudioPlayerFragment; import com.cyngn.eleven.utils.ApolloUtils; /** @@ -177,6 +177,7 @@ public class AppWidgetSmall extends AppWidgetBase { // 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); diff --git a/src/com/cyngn/eleven/appwidgets/RecentWidgetProvider.java b/src/com/cyngn/eleven/appwidgets/RecentWidgetProvider.java index 6d38a4f..c28f89c 100644 --- a/src/com/cyngn/eleven/appwidgets/RecentWidgetProvider.java +++ b/src/com/cyngn/eleven/appwidgets/RecentWidgetProvider.java @@ -28,8 +28,8 @@ import android.widget.RemoteViews; import com.cyngn.eleven.Config; import com.cyngn.eleven.MusicPlaybackService; import com.cyngn.eleven.R; -import com.cyngn.eleven.ui.fragments.AudioPlayerFragment; import com.cyngn.eleven.ui.activities.HomeActivity; +import com.cyngn.eleven.ui.fragments.AudioPlayerFragment; import com.cyngn.eleven.ui.activities.ProfileActivity; import com.cyngn.eleven.ui.activities.ShortcutActivity; import com.cyngn.eleven.utils.MusicUtils; @@ -258,12 +258,14 @@ public class RecentWidgetProvider extends AppWidgetBase { // Now playing if (playerActive) { action = new Intent(context, HomeActivity.class); + action.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP); action.setAction(HomeActivity.ACTION_VIEW_MUSIC_PLAYER); pendingIntent = PendingIntent.getActivity(context, 0, action, 0); views.setOnClickPendingIntent(R.id.app_widget_recents_action_bar, pendingIntent); } else { // Home action = new Intent(context, HomeActivity.class); + action.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP); action.setAction(HomeActivity.ACTION_VIEW_BROWSE); pendingIntent = PendingIntent.getActivity(context, 0, action, 0); views.setOnClickPendingIntent(R.id.app_widget_recents_action_bar, pendingIntent); diff --git a/src/com/cyngn/eleven/ui/activities/BaseActivity.java b/src/com/cyngn/eleven/ui/activities/BaseActivity.java index 5ed2511..6b2b1f3 100644 --- a/src/com/cyngn/eleven/ui/activities/BaseActivity.java +++ b/src/com/cyngn/eleven/ui/activities/BaseActivity.java @@ -55,7 +55,7 @@ import java.util.ArrayList; * A base {@link FragmentActivity} used to update the bottom bar and * bind to Apollo's service. * <p> - * {@link HomeActivity} extends from this skeleton. + * {@link SlidingPanelActivity} extends from this skeleton. * * @author Andrew Neal (andrewdneal@gmail.com) */ @@ -283,7 +283,7 @@ public abstract class BaseActivity extends FragmentActivity implements ServiceCo /** * Initializes the items in the bottom action bar. */ - private void initBottomActionBar() { + protected void initBottomActionBar() { // Play and pause button mPlayPauseProgressButton = (PlayPauseProgressButton)findViewById(R.id.playPauseProgressButton); mPlayPauseProgressButton.enableAndShow(); @@ -296,11 +296,6 @@ public abstract class BaseActivity extends FragmentActivity implements ServiceCo mAlbumArt = (ImageView)findViewById(R.id.bottom_action_bar_album_art); // Open to the currently playing album profile mAlbumArt.setOnClickListener(mOpenCurrentAlbumProfile); - // Bottom action bar - final LinearLayout bottomActionBar = (LinearLayout)findViewById(R.id.bottom_action_bar); - // Display the now playing screen or shuffle if this isn't anything - // playing - bottomActionBar.setOnClickListener(mOpenNowPlaying); } /** @@ -353,24 +348,6 @@ public abstract class BaseActivity extends FragmentActivity implements ServiceCo }; /** - * Opens the now playing screen - */ - private final View.OnClickListener mOpenNowPlaying = new View.OnClickListener() { - - /** - * {@inheritDoc} - */ - @Override - public void onClick(final View v) { - if (MusicUtils.getCurrentAudioId() != -1) { - NavUtils.openAudioPlayer(BaseActivity.this); - } else { - MusicUtils.shuffleAll(BaseActivity.this); - } - } - }; - - /** * Used to monitor the state of playback */ private final static class PlaybackStatus extends BroadcastReceiver { diff --git a/src/com/cyngn/eleven/ui/activities/HomeActivity.java b/src/com/cyngn/eleven/ui/activities/HomeActivity.java index 8111669..5d1447b 100644 --- a/src/com/cyngn/eleven/ui/activities/HomeActivity.java +++ b/src/com/cyngn/eleven/ui/activities/HomeActivity.java @@ -1,82 +1,40 @@ /* - * 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. + * Copyright (C) 2014 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.cyngn.eleven.ui.activities; import android.content.Intent; -import android.graphics.Color; import android.os.Bundle; -import android.support.v4.app.Fragment; -import android.support.v4.view.ViewPager; -import android.view.View; -import android.widget.ImageView; - import com.cyngn.eleven.R; -import com.cyngn.eleven.slidinguppanel.SlidingUpPanelLayout; -import com.cyngn.eleven.slidinguppanel.SlidingUpPanelLayout.SimplePanelSlideListener; -import com.cyngn.eleven.ui.HeaderBar; import com.cyngn.eleven.ui.fragments.AudioPlayerFragment; import com.cyngn.eleven.ui.fragments.phone.MusicBrowserPhoneFragment; -import com.cyngn.eleven.utils.ApolloUtils; -import com.cyngn.eleven.utils.MusicUtils; -import com.cyngn.eleven.widgets.BlurScrimImage; -/** - * This class is used to display the {@link ViewPager} used to swipe between the - * main {@link Fragment}s used to browse the user's music. - * - * @author Andrew Neal (andrewdneal@gmail.com) - */ -public class HomeActivity extends BaseActivity { +public class HomeActivity extends SlidingPanelActivity { + public static final String ACTION_VIEW_BROWSE = "com.cyngn.eleven.ui.activities.HomeActivity.view.Browse"; public static final String ACTION_VIEW_MUSIC_PLAYER = "com.cyngn.eleven.ui.activities.HomeActivity.view.MusicPlayer"; public static final String ACTION_VIEW_QUEUE = "com.cyngn.eleven.ui.activities.HomeActivity.view.Queue"; - enum Panel { - Browse, - MusicPlayer, - Queue, - None, - } - - private SlidingUpPanelLayout mFirstPanel; - private HeaderBar mFirstHeaderBar; - private SlidingUpPanelLayout mSecondPanel; - private HeaderBar mSecondHeaderBar; - private Panel mTargetNavigatePanel; - - // this is the blurred image that goes behind the now playing and queue fragments - private BlurScrimImage mBlurScrimImage; - - /** - * {@inheritDoc} - */ @Override - protected void onCreate(final Bundle savedInstanceState) { + protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); - if (savedInstanceState == null) { getSupportFragmentManager().beginTransaction() .replace(R.id.activity_base_content, new MusicBrowserPhoneFragment()).commit(); } - mTargetNavigatePanel = Panel.None; - - setupFirstPanel(); - setupSecondPanel(); - - // get the blur scrim image - findViewById(R.id.bottom_action_bar_parent).setBackgroundColor(Color.TRANSPARENT); - mBlurScrimImage = (BlurScrimImage)findViewById(R.id.blurScrimImage); - // if we've been launched by an intent, parse it Intent launchIntent = getIntent(); if (launchIntent != null) { @@ -84,83 +42,6 @@ public class HomeActivity extends BaseActivity { } } - private void setupFirstPanel() { - mFirstPanel = (SlidingUpPanelLayout)findViewById(R.id.sliding_layout); - mFirstPanel.setPanelSlideListener(new SimplePanelSlideListener() { - @Override - public void onPanelSlide(View panel, float slideOffset) { - if (slideOffset > 0.8f) { - getActionBar().hide(); - } else if (slideOffset < 0.75f) { - getActionBar().show(); - } - } - - @Override - public void onPanelExpanded(View panel) { - checkTargetNavigation(); - } - - @Override - public void onPanelCollapsed(View panel) { - checkTargetNavigation(); - } - }); - - // setup the header bar - mFirstHeaderBar = setupHeaderBar(R.id.firstHeaderBar, R.string.page_now_playing, - R.drawable.btn_queue_icon, - new View.OnClickListener() { - @Override - public void onClick(View v) { - showPanel(Panel.Queue); - } - }); - } - - private void setupSecondPanel() { - mSecondPanel = (SlidingUpPanelLayout)findViewById(R.id.sliding_layout2); - mSecondPanel.setPanelSlideListener(new SimplePanelSlideListener() { - @Override - public void onPanelSlide(View panel, float slideOffset) { - // if we are not going to a specific panel, then disable sliding to prevent - // the two sliding panels from fighting for touch input - if (mTargetNavigatePanel == Panel.None) { - mFirstPanel.setSlidingEnabled(false); - } - } - - @Override - public void onPanelExpanded(View panel) { - checkTargetNavigation(); - } - - @Override - public void onPanelCollapsed(View panel) { - // re-enable sliding when the second panel is collapsed - mFirstPanel.setSlidingEnabled(true); - checkTargetNavigation(); - } - }); - - // setup the header bar - mSecondHeaderBar = setupHeaderBar(R.id.secondHeaderBar, R.string.page_play_queue, - R.drawable.btn_playback_icon, - new View.OnClickListener() { - @Override - public void onClick(View v) { - showPanel(Panel.MusicPlayer); - } - }); - - // set the drag view offset to allow the panel to go past the top of the viewport - // since the previous view's is hiding the slide offset, we need to subtract that - // from action bat height - int slideOffset = getResources().getDimensionPixelOffset(R.dimen.sliding_panel_indicator_height); - slideOffset -= ApolloUtils.getActionBarHeight(this); - mSecondPanel.setSlidePanelOffset(slideOffset); - } - @Override protected void onNewIntent(Intent intent) { super.onNewIntent(intent); @@ -172,14 +53,7 @@ public class HomeActivity extends BaseActivity { Panel targetPanel = null; if (intent.getAction() != null) { - String action = intent.getAction(); - if (action.equals(ACTION_VIEW_BROWSE)) { - targetPanel = Panel.Browse; - } else if (action.equals(ACTION_VIEW_MUSIC_PLAYER)) { - targetPanel = Panel.MusicPlayer; - } if (action.equals(ACTION_VIEW_QUEUE)) { - targetPanel = Panel.Queue; - } + } else { AudioPlayerFragment player = getAudioPlayerFragment(); if (player != null && player.startPlayback()) { @@ -192,101 +66,5 @@ public class HomeActivity extends BaseActivity { } } - /** - * {@inheritDoc} - */ - @Override - public int setContentView() { - return R.layout.activity_base; - } - - @Override - public void onBackPressed() { - Panel panel = getCurrentPanel(); - switch (panel) { - case Browse: - super.onBackPressed(); - break; - case MusicPlayer: - showPanel(Panel.Browse); - break; - case Queue: - showPanel(Panel.MusicPlayer); - break; - } - } - - protected void showPanel(Panel panel) { - // TODO: Add ability to do this instantaneously as opposed to animate - switch (panel) { - case Browse: - // if we are two panels over, we need special logic to jump twice - mTargetNavigatePanel = panel; - mSecondPanel.collapsePanel(); - // re-enable sliding on first panel so we can collapse it - mFirstPanel.setSlidingEnabled(true); - mFirstPanel.collapsePanel(); - break; - case MusicPlayer: - mSecondPanel.collapsePanel(); - mFirstPanel.expandPanel(); - break; - case Queue: - // if we are two panels over, we need special logic to jump twice - mTargetNavigatePanel = panel; - mSecondPanel.expandPanel(); - mFirstPanel.expandPanel(); - break; - } - } - /** - * This checks if we are at our target panel and resets our flag if we are there - */ - protected void checkTargetNavigation() { - if (mTargetNavigatePanel == getCurrentPanel()) { - mTargetNavigatePanel = Panel.None; - } - } - - protected Panel getCurrentPanel() { - if (mSecondPanel.isPanelExpanded()) { - return Panel.Queue; - } else if (mFirstPanel.isPanelExpanded()) { - return Panel.MusicPlayer; - } else { - return Panel.Browse; - } - } - - @Override - protected void updateMetaInfo() { - super.updateMetaInfo(); - - // load the blurred image - mBlurScrimImage.loadBlurImage(ApolloUtils.getImageFetcher(this)); - - // Set the artist name - mFirstHeaderBar.setTitleText(MusicUtils.getArtistName()); - } - - protected AudioPlayerFragment getAudioPlayerFragment() { - return (AudioPlayerFragment)getSupportFragmentManager().findFragmentById(R.id.audioPlayerFragment); - } - - protected HeaderBar setupHeaderBar(final int containerId, final int textId, - final int customIconId, final View.OnClickListener listener) { - final HeaderBar headerBar = (HeaderBar) findViewById(containerId); - headerBar.setTitleText(textId); - headerBar.setupCustomButton(customIconId, listener); - headerBar.setBackgroundColor(Color.TRANSPARENT); - headerBar.setBackListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - showPanel(Panel.Browse); - } - }); - - return headerBar; - } } diff --git a/src/com/cyngn/eleven/ui/activities/ProfileActivity.java b/src/com/cyngn/eleven/ui/activities/ProfileActivity.java index 70886e7..41afdff 100644 --- a/src/com/cyngn/eleven/ui/activities/ProfileActivity.java +++ b/src/com/cyngn/eleven/ui/activities/ProfileActivity.java @@ -54,7 +54,7 @@ import com.cyngn.eleven.widgets.ProfileTabCarousel.Listener; * * @author Andrew Neal (andrewdneal@gmail.com) */ -public class ProfileActivity extends BaseActivity implements OnPageChangeListener, Listener { +public class ProfileActivity extends SlidingPanelActivity implements OnPageChangeListener, Listener { private static final int NEW_PHOTO = 1; @@ -224,21 +224,18 @@ public class ProfileActivity extends BaseActivity implements OnPageChangeListene mTabCarousel.setListener(this); } - /** - * {@inheritDoc} - */ @Override - protected void onPause() { - super.onPause(); - mImageFetcher.flush(); + protected int getLayoutToInflate() { + return R.layout.activity_profile_base; } /** * {@inheritDoc} */ @Override - public int setContentView() { - return R.layout.activity_profile_base; + protected void onPause() { + super.onPause(); + mImageFetcher.flush(); } /** @@ -413,7 +410,6 @@ public class ProfileActivity extends BaseActivity implements OnPageChangeListene @Override public void onBackPressed() { super.onBackPressed(); - goBack(); } /** diff --git a/src/com/cyngn/eleven/ui/activities/ShortcutActivity.java b/src/com/cyngn/eleven/ui/activities/ShortcutActivity.java index 08da62b..f6d3a9e 100644 --- a/src/com/cyngn/eleven/ui/activities/ShortcutActivity.java +++ b/src/com/cyngn/eleven/ui/activities/ShortcutActivity.java @@ -302,6 +302,7 @@ public class ShortcutActivity extends FragmentActivity implements ServiceConnect // 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); } diff --git a/src/com/cyngn/eleven/ui/activities/SlidingPanelActivity.java b/src/com/cyngn/eleven/ui/activities/SlidingPanelActivity.java new file mode 100644 index 0000000..784961b --- /dev/null +++ b/src/com/cyngn/eleven/ui/activities/SlidingPanelActivity.java @@ -0,0 +1,309 @@ +/* + * 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 android.content.BroadcastReceiver; +import android.content.Context; +import android.content.Intent; +import android.graphics.Color; +import android.os.Bundle; +import android.support.v4.app.Fragment; +import android.support.v4.view.ViewPager; +import android.view.View; +import android.view.ViewStub; +import android.widget.ImageView; + +import android.widget.LinearLayout; +import com.cyngn.eleven.R; +import com.cyngn.eleven.slidinguppanel.SlidingUpPanelLayout; +import com.cyngn.eleven.slidinguppanel.SlidingUpPanelLayout.SimplePanelSlideListener; +import com.cyngn.eleven.ui.HeaderBar; +import com.cyngn.eleven.ui.fragments.AudioPlayerFragment; +import com.cyngn.eleven.ui.fragments.phone.MusicBrowserPhoneFragment; +import com.cyngn.eleven.utils.ApolloUtils; +import com.cyngn.eleven.utils.MusicUtils; +import com.cyngn.eleven.utils.NavUtils; +import com.cyngn.eleven.widgets.BlurScrimImage; + +/** + * This class is used to display the {@link ViewPager} used to swipe between the + * main {@link Fragment}s used to browse the user's music. + * + * @author Andrew Neal (andrewdneal@gmail.com) + */ +public class SlidingPanelActivity extends BaseActivity { + + enum Panel { + Browse, + MusicPlayer, + Queue, + None, + } + + private SlidingUpPanelLayout mFirstPanel; + private HeaderBar mFirstHeaderBar; + private SlidingUpPanelLayout mSecondPanel; + private HeaderBar mSecondHeaderBar; + private Panel mTargetNavigatePanel; + + // this is the blurred image that goes behind the now playing and queue fragments + private BlurScrimImage mBlurScrimImage; + + /** + * Opens the now playing screen + */ + private final View.OnClickListener mOpenNowPlaying = new View.OnClickListener() { + + /** + * {@inheritDoc} + */ + @Override + public void onClick(final View v) { + if (MusicUtils.getCurrentAudioId() != -1) { + openAudioPlayer(); + } else { + MusicUtils.shuffleAll(SlidingPanelActivity.this); + } + } + }; + + @Override + protected void initBottomActionBar() { + super.initBottomActionBar(); + // Bottom action bar + final LinearLayout bottomActionBar = (LinearLayout)findViewById(R.id.bottom_action_bar); + // Display the now playing screen or shuffle if this isn't anything + // playing + bottomActionBar.setOnClickListener(mOpenNowPlaying); + } + + /** + * {@inheritDoc} + */ + @Override + protected void onCreate(final Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + + mTargetNavigatePanel = Panel.None; + + setupFirstPanel(); + setupSecondPanel(); + + // get the blur scrim image + findViewById(R.id.bottom_action_bar_parent).setBackgroundColor(Color.TRANSPARENT); + mBlurScrimImage = (BlurScrimImage)findViewById(R.id.blurScrimImage); + + if (getLayoutToInflate() != 0) { + ViewStub contentStub = (ViewStub) findViewById(R.id.content_stub); + if (contentStub != null) { + contentStub.setLayoutResource(getLayoutToInflate()); + contentStub.inflate(); + } + } + } + + protected int getLayoutToInflate() { + return 0; + } + + private void setupFirstPanel() { + mFirstPanel = (SlidingUpPanelLayout)findViewById(R.id.sliding_layout); + mFirstPanel.setPanelSlideListener(new SimplePanelSlideListener() { + @Override + public void onPanelSlide(View panel, float slideOffset) { + if (slideOffset > 0.8f) { + getActionBar().hide(); + } else if (slideOffset < 0.75f) { + getActionBar().show(); + } + } + + @Override + public void onPanelExpanded(View panel) { + checkTargetNavigation(); + } + + @Override + public void onPanelCollapsed(View panel) { + checkTargetNavigation(); + } + }); + + // setup the header bar + mFirstHeaderBar = setupHeaderBar(R.id.firstHeaderBar, R.string.page_now_playing, + R.drawable.btn_queue_icon, + new View.OnClickListener() { + @Override + public void onClick(View v) { + showPanel(Panel.Queue); + } + }); + } + + private void setupSecondPanel() { + mSecondPanel = (SlidingUpPanelLayout)findViewById(R.id.sliding_layout2); + mSecondPanel.setPanelSlideListener(new SimplePanelSlideListener() { + @Override + public void onPanelSlide(View panel, float slideOffset) { + // if we are not going to a specific panel, then disable sliding to prevent + // the two sliding panels from fighting for touch input + if (mTargetNavigatePanel == Panel.None) { + mFirstPanel.setSlidingEnabled(false); + } + } + + @Override + public void onPanelExpanded(View panel) { + checkTargetNavigation(); + } + + @Override + public void onPanelCollapsed(View panel) { + // re-enable sliding when the second panel is collapsed + mFirstPanel.setSlidingEnabled(true); + checkTargetNavigation(); + } + }); + + // setup the header bar + mSecondHeaderBar = setupHeaderBar(R.id.secondHeaderBar, R.string.page_play_queue, + R.drawable.btn_playback_icon, + new View.OnClickListener() { + @Override + public void onClick(View v) { + showPanel(Panel.MusicPlayer); + } + }); + + // set the drag view offset to allow the panel to go past the top of the viewport + // since the previous view's is hiding the slide offset, we need to subtract that + // from action bat height + int slideOffset = getResources().getDimensionPixelOffset(R.dimen.sliding_panel_indicator_height); + slideOffset -= ApolloUtils.getActionBarHeight(this); + mSecondPanel.setSlidePanelOffset(slideOffset); + } + + + + @Override + protected void onPause() { + super.onPause(); + } + + @Override + protected void onResume() { + super.onResume(); + } + + /** + * {@inheritDoc} + */ + @Override + public int setContentView() { + return R.layout.activity_base; + } + + @Override + public void onBackPressed() { + Panel panel = getCurrentPanel(); + switch (panel) { + case Browse: + super.onBackPressed(); + break; + default: + case MusicPlayer: + showPanel(Panel.Browse); + break; + case Queue: + showPanel(Panel.MusicPlayer); + break; + } + } + + public void openAudioPlayer() { + showPanel(Panel.MusicPlayer); + } + + protected void showPanel(Panel panel) { + // TODO: Add ability to do this instantaneously as opposed to animate + switch (panel) { + case Browse: + // if we are two panels over, we need special logic to jump twice + mTargetNavigatePanel = panel; + mSecondPanel.collapsePanel(); + // re-enable sliding on first panel so we can collapse it + mFirstPanel.setSlidingEnabled(true); + mFirstPanel.collapsePanel(); + break; + case MusicPlayer: + mSecondPanel.collapsePanel(); + mFirstPanel.expandPanel(); + break; + case Queue: + // if we are two panels over, we need special logic to jump twice + mTargetNavigatePanel = panel; + mSecondPanel.expandPanel(); + mFirstPanel.expandPanel(); + break; + } + } + + /** + * This checks if we are at our target panel and resets our flag if we are there + */ + protected void checkTargetNavigation() { + if (mTargetNavigatePanel == getCurrentPanel()) { + mTargetNavigatePanel = Panel.None; + } + } + + protected Panel getCurrentPanel() { + if (mSecondPanel.isPanelExpanded()) { + return Panel.Queue; + } else if (mFirstPanel.isPanelExpanded()) { + return Panel.MusicPlayer; + } else { + return Panel.Browse; + } + } + + @Override + protected void updateMetaInfo() { + super.updateMetaInfo(); + + // load the blurred image + mBlurScrimImage.loadBlurImage(ApolloUtils.getImageFetcher(this)); + + // Set the artist name + mFirstHeaderBar.setTitleText(MusicUtils.getArtistName()); + } + + protected AudioPlayerFragment getAudioPlayerFragment() { + return (AudioPlayerFragment)getSupportFragmentManager().findFragmentById(R.id.audioPlayerFragment); + } + + protected HeaderBar setupHeaderBar(final int containerId, final int textId, + final int customIconId, final View.OnClickListener listener) { + final HeaderBar headerBar = (HeaderBar) findViewById(containerId); + headerBar.setTitleText(textId); + headerBar.setupCustomButton(customIconId, listener); + headerBar.setBackgroundColor(Color.TRANSPARENT); + headerBar.setBackListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + showPanel(Panel.Browse); + } + }); + + return headerBar; + } +} diff --git a/src/com/cyngn/eleven/utils/NavUtils.java b/src/com/cyngn/eleven/utils/NavUtils.java index 9900989..ac1c4d1 100644 --- a/src/com/cyngn/eleven/utils/NavUtils.java +++ b/src/com/cyngn/eleven/utils/NavUtils.java @@ -21,8 +21,6 @@ import android.provider.MediaStore; import com.cyngn.eleven.Config; import com.cyngn.eleven.R; -import com.cyngn.eleven.model.Album; -import com.cyngn.eleven.ui.fragments.AudioPlayerFragment; import com.cyngn.eleven.ui.activities.HomeActivity; import com.cyngn.eleven.ui.activities.ProfileActivity; import com.cyngn.eleven.ui.activities.SearchActivity; @@ -53,6 +51,7 @@ public final class NavUtils { // Create the intent to launch the profile activity final Intent intent = new Intent(context, ProfileActivity.class); + intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); intent.putExtras(bundle); context.startActivity(intent); } @@ -78,6 +77,7 @@ public final class NavUtils { // Create the intent to launch the profile activity final Intent intent = new Intent(context, ProfileActivity.class); + intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); intent.putExtras(bundle); context.startActivity(intent); } @@ -109,17 +109,6 @@ public final class NavUtils { } /** - * Opens to {@link AudioPlayerFragment}. - * - * @param activity The {@link Activity} to use. - */ - public static void openAudioPlayer(final Activity activity) { - final Intent intent = new Intent(activity, HomeActivity.class); - intent.setAction(HomeActivity.ACTION_VIEW_MUSIC_PLAYER); - activity.startActivity(intent); - } - - /** * Opens to {@link SearchActivity}. * * @param activity The {@link Activity} to use. @@ -134,13 +123,15 @@ public final class NavUtils { } /** - * Opens to {@link HomeActivity}. + * Opens to {@link com.cyngn.eleven.ui.activities.HomeActivity}. * * @param activity The {@link Activity} to use. */ public static void goHome(final Activity activity) { final Intent intent = new Intent(activity, HomeActivity.class); intent.setAction(HomeActivity.ACTION_VIEW_BROWSE); + intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK + | Intent.FLAG_ACTIVITY_CLEAR_TOP); activity.startActivity(intent); } } |