2 * Copyright (C) 2012 Andrew Neal Licensed under the Apache License, Version 2.0
3 * (the "License"); you may not use this file except in compliance with the
4 * License. You may obtain a copy of the License at
5 * http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law
6 * or agreed to in writing, software distributed under the License is
7 * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
8 * KIND, either express or implied. See the License for the specific language
9 * governing permissions and limitations under the License.
12 package com.cyngn.eleven.ui.activities;
14 import android.content.Intent;
15 import android.graphics.Color;
16 import android.os.Bundle;
17 import android.support.v4.app.Fragment;
18 import android.support.v4.view.ViewPager;
19 import android.view.View;
20 import android.widget.ImageView;
22 import com.cyngn.eleven.R;
23 import com.cyngn.eleven.slidinguppanel.SlidingUpPanelLayout;
24 import com.cyngn.eleven.slidinguppanel.SlidingUpPanelLayout.SimplePanelSlideListener;
25 import com.cyngn.eleven.ui.HeaderBar;
26 import com.cyngn.eleven.ui.fragments.AudioPlayerFragment;
27 import com.cyngn.eleven.ui.fragments.phone.MusicBrowserPhoneFragment;
28 import com.cyngn.eleven.utils.ApolloUtils;
29 import com.cyngn.eleven.utils.MusicUtils;
30 import com.cyngn.eleven.widgets.BlurScrimImage;
33 * This class is used to display the {@link ViewPager} used to swipe between the
34 * main {@link Fragment}s used to browse the user's music.
36 * @author Andrew Neal (andrewdneal@gmail.com)
38 public class HomeActivity extends BaseActivity {
39 public static final String ACTION_VIEW_BROWSE = "com.cyngn.eleven.ui.activities.HomeActivity.view.Browse";
40 public static final String ACTION_VIEW_MUSIC_PLAYER = "com.cyngn.eleven.ui.activities.HomeActivity.view.MusicPlayer";
41 public static final String ACTION_VIEW_QUEUE = "com.cyngn.eleven.ui.activities.HomeActivity.view.Queue";
50 private SlidingUpPanelLayout mFirstPanel;
51 private HeaderBar mFirstHeaderBar;
52 private SlidingUpPanelLayout mSecondPanel;
53 private HeaderBar mSecondHeaderBar;
54 private Panel mTargetNavigatePanel;
56 // this is the blurred image that goes behind the now playing and queue fragments
57 private BlurScrimImage mBlurScrimImage;
63 protected void onCreate(final Bundle savedInstanceState) {
64 super.onCreate(savedInstanceState);
66 if (savedInstanceState == null) {
67 getSupportFragmentManager().beginTransaction()
68 .replace(R.id.activity_base_content, new MusicBrowserPhoneFragment()).commit();
71 mTargetNavigatePanel = Panel.None;
76 // get the blur scrim image
77 findViewById(R.id.bottom_action_bar_parent).setBackgroundColor(Color.TRANSPARENT);
78 mBlurScrimImage = (BlurScrimImage)findViewById(R.id.blurScrimImage);
80 // if we've been launched by an intent, parse it
81 Intent launchIntent = getIntent();
82 if (launchIntent != null) {
83 parseIntent(launchIntent);
87 private void setupFirstPanel() {
88 mFirstPanel = (SlidingUpPanelLayout)findViewById(R.id.sliding_layout);
89 mFirstPanel.setPanelSlideListener(new SimplePanelSlideListener() {
91 public void onPanelSlide(View panel, float slideOffset) {
92 if (slideOffset > 0.8f) {
93 getActionBar().hide();
94 } else if (slideOffset < 0.75f) {
95 getActionBar().show();
100 public void onPanelExpanded(View panel) {
101 checkTargetNavigation();
105 public void onPanelCollapsed(View panel) {
106 checkTargetNavigation();
110 // setup the header bar
111 mFirstHeaderBar = setupHeaderBar(R.id.firstHeaderBar, R.string.page_now_playing,
112 R.drawable.btn_queue_icon,
113 new View.OnClickListener() {
115 public void onClick(View v) {
116 showPanel(Panel.Queue);
121 private void setupSecondPanel() {
122 mSecondPanel = (SlidingUpPanelLayout)findViewById(R.id.sliding_layout2);
123 mSecondPanel.setPanelSlideListener(new SimplePanelSlideListener() {
125 public void onPanelSlide(View panel, float slideOffset) {
126 mFirstPanel.setSlidingEnabled(false);
130 public void onPanelExpanded(View panel) {
131 checkTargetNavigation();
135 public void onPanelCollapsed(View panel) {
136 mFirstPanel.setSlidingEnabled(true);
137 checkTargetNavigation();
141 // setup the header bar
142 mSecondHeaderBar = setupHeaderBar(R.id.secondHeaderBar, R.string.page_play_queue,
143 R.drawable.btn_playback_icon,
144 new View.OnClickListener() {
146 public void onClick(View v) {
147 showPanel(Panel.MusicPlayer);
151 // set the drag view offset to allow the panel to go past the top of the viewport
152 // since the previous view's is hiding the slide offset, we need to subtract that
153 // from action bat height
154 int slideOffset = getResources().getDimensionPixelOffset(R.dimen.sliding_panel_indicator_height);
155 slideOffset -= ApolloUtils.getActionBarHeight(this);
156 mSecondPanel.setSlidePanelOffset(slideOffset);
160 protected void onNewIntent(Intent intent) {
161 super.onNewIntent(intent);
166 private void parseIntent(Intent intent) {
167 Panel targetPanel = null;
169 if (intent.getAction() != null) {
170 String action = intent.getAction();
171 if (action.equals(ACTION_VIEW_BROWSE)) {
172 targetPanel = Panel.Browse;
173 } else if (action.equals(ACTION_VIEW_MUSIC_PLAYER)) {
174 targetPanel = Panel.MusicPlayer;
175 } if (action.equals(ACTION_VIEW_QUEUE)) {
176 targetPanel = Panel.Queue;
179 AudioPlayerFragment player = getAudioPlayerFragment();
180 if (player != null && player.startPlayback()) {
181 targetPanel = Panel.MusicPlayer;
185 if (targetPanel != null) {
186 showPanel(targetPanel);
194 public int setContentView() {
195 return R.layout.activity_base;
199 public void onBackPressed() {
200 Panel panel = getCurrentPanel();
203 super.onBackPressed();
206 showPanel(Panel.Browse);
209 showPanel(Panel.MusicPlayer);
214 protected void showPanel(Panel panel) {
215 // TODO: Add ability to do this instantaneously as opposed to animate
218 // if we are two panels over, we need special logic to jump twice
219 mTargetNavigatePanel = panel;
220 mSecondPanel.collapsePanel();
221 mFirstPanel.collapsePanel();
224 mSecondPanel.collapsePanel();
225 mFirstPanel.expandPanel();
228 // if we are two panels over, we need special logic to jump twice
229 mTargetNavigatePanel = panel;
230 mSecondPanel.expandPanel();
231 mFirstPanel.expandPanel();
237 * This checks if we are at our target panel, and if not, continues the motion
239 protected void checkTargetNavigation() {
240 if (mTargetNavigatePanel != Panel.None) {
241 if (mTargetNavigatePanel == getCurrentPanel()) {
242 mTargetNavigatePanel = Panel.None;
244 showPanel(mTargetNavigatePanel);
249 protected Panel getCurrentPanel() {
250 if (mSecondPanel.isPanelExpanded()) {
252 } else if (mFirstPanel.isPanelExpanded()) {
253 return Panel.MusicPlayer;
260 protected void updateMetaInfo() {
261 super.updateMetaInfo();
263 // load the blurred image
264 mBlurScrimImage.loadBlurImage(ApolloUtils.getImageFetcher(this));
266 // Set the artist name
267 mFirstHeaderBar.setTitleText(MusicUtils.getArtistName());
270 protected AudioPlayerFragment getAudioPlayerFragment() {
271 return (AudioPlayerFragment)getSupportFragmentManager().findFragmentById(R.id.audioPlayerFragment);
274 protected HeaderBar setupHeaderBar(final int containerId, final int textId,
275 final int customIconId, final View.OnClickListener listener) {
276 final HeaderBar headerBar = (HeaderBar) findViewById(containerId);
277 headerBar.setTitleText(textId);
278 headerBar.setupCustomButton(customIconId, listener);
279 headerBar.setBackgroundColor(Color.TRANSPARENT);
280 headerBar.setBackListener(new View.OnClickListener() {
282 public void onClick(View v) {
283 showPanel(Panel.Browse);