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.drawable.ColorDrawable;
16 import android.os.Bundle;
17 import android.support.v4.app.Fragment;
18 import android.support.v4.view.ViewPager;
19 import android.view.MenuInflater;
20 import android.view.View;
21 import android.widget.FrameLayout;
22 import android.widget.ImageView;
23 import android.widget.PopupMenu;
24 import android.widget.TextView;
26 import com.cyngn.eleven.R;
27 import com.cyngn.eleven.slidinguppanel.SlidingUpPanelLayout;
28 import com.cyngn.eleven.slidinguppanel.SlidingUpPanelLayout.SimplePanelSlideListener;
29 import com.cyngn.eleven.ui.HeaderBar;
30 import com.cyngn.eleven.ui.fragments.AudioPlayerFragment;
31 import com.cyngn.eleven.ui.fragments.QueueFragment;
32 import com.cyngn.eleven.ui.fragments.phone.MusicBrowserPhoneFragment;
33 import com.cyngn.eleven.utils.ApolloUtils;
34 import com.cyngn.eleven.widgets.theme.BottomActionBar;
37 * This class is used to display the {@link ViewPager} used to swipe between the
38 * main {@link Fragment}s used to browse the user's music.
40 * @author Andrew Neal (andrewdneal@gmail.com)
42 public class HomeActivity extends BaseActivity {
43 public static final String ACTION_VIEW_BROWSE = "com.cyngn.eleven.ui.activities.HomeActivity.view.Browse";
44 public static final String ACTION_VIEW_MUSIC_PLAYER = "com.cyngn.eleven.ui.activities.HomeActivity.view.MusicPlayer";
45 public static final String ACTION_VIEW_QUEUE = "com.cyngn.eleven.ui.activities.HomeActivity.view.Queue";
53 private SlidingUpPanelLayout mFirstPanel;
54 private SlidingUpPanelLayout mSecondPanel;
60 protected void onCreate(final Bundle savedInstanceState) {
61 super.onCreate(savedInstanceState);
63 if (savedInstanceState == null) {
64 getSupportFragmentManager().beginTransaction()
65 .replace(R.id.activity_base_content, new MusicBrowserPhoneFragment()).commit();
71 // if we've been launched by an intent, parse it
72 Intent launchIntent = getIntent();
73 if (launchIntent != null) {
74 parseIntent(launchIntent);
78 private void setupFirstPanel() {
79 mFirstPanel = (SlidingUpPanelLayout)findViewById(R.id.sliding_layout);
80 mFirstPanel.setPanelSlideListener(new SimplePanelSlideListener() {
82 public void onPanelSlide(View panel, float slideOffset) {
83 if (slideOffset > 0.8f) {
84 getActionBar().hide();
85 } else if (slideOffset < 0.75f) {
86 getActionBar().show();
91 // setup the header bar
92 setupHeaderBar(R.id.firstHeaderBar, R.string.app_name_uppercase); //R.string.page_now_playing);
95 private void setupSecondPanel() {
96 mSecondPanel = (SlidingUpPanelLayout)findViewById(R.id.sliding_layout2);
97 mSecondPanel.setPanelSlideListener(new SimplePanelSlideListener() {
99 public void onPanelSlide(View panel, float slideOffset) {
100 mFirstPanel.setSlidingEnabled(false);
104 public void onPanelCollapsed(View panel) {
105 mFirstPanel.setSlidingEnabled(true);
109 // setup the header bar
110 setupHeaderBar(R.id.secondHeaderBar, R.string.page_play_queue);
112 // set the drag view offset to allow the panel to go past the top of the viewport
113 // since the previous view's is hiding the slide offset, we need to subtract that
114 // from action bat height
115 int slideOffset = getResources().getDimensionPixelOffset(R.dimen.sliding_panel_indicator_height);
116 slideOffset -= ApolloUtils.getActionBarHeight(this);
117 mSecondPanel.setSlidePanelOffset(slideOffset);
121 protected void onNewIntent(Intent intent) {
122 super.onNewIntent(intent);
127 private void parseIntent(Intent intent) {
128 Panel targetPanel = null;
130 if (intent.getAction() != null) {
131 String action = intent.getAction();
132 if (action.equals(ACTION_VIEW_BROWSE)) {
133 targetPanel = Panel.Browse;
134 } else if (action.equals(ACTION_VIEW_MUSIC_PLAYER)) {
135 targetPanel = Panel.MusicPlayer;
136 } if (action.equals(ACTION_VIEW_QUEUE)) {
137 targetPanel = Panel.Queue;
140 AudioPlayerFragment player = getAudioPlayerFragment();
141 if (player != null && player.startPlayback()) {
142 targetPanel = Panel.MusicPlayer;
146 if (targetPanel != null) {
147 showPanel(targetPanel);
155 public int setContentView() {
156 return R.layout.activity_base;
160 public void onBackPressed() {
161 Panel panel = getCurrentPanel();
164 super.onBackPressed();
167 showPanel(Panel.Browse);
170 showPanel(Panel.MusicPlayer);
175 protected void showPanel(Panel panel) {
176 // TODO: Add ability to do this instantaneously as opposed to animate
179 mSecondPanel.collapsePanel();
180 mFirstPanel.collapsePanel();
183 mSecondPanel.collapsePanel();
184 mFirstPanel.expandPanel();
187 mSecondPanel.expandPanel();
188 mFirstPanel.expandPanel();
193 protected Panel getCurrentPanel() {
194 if (mSecondPanel.isPanelExpanded()) {
196 } else if (mFirstPanel.isPanelExpanded()) {
197 return Panel.MusicPlayer;
203 protected AudioPlayerFragment getAudioPlayerFragment() {
204 return (AudioPlayerFragment)getSupportFragmentManager().findFragmentById(R.id.audioPlayerFragment);
207 protected QueueFragment getQueueFragment() {
208 return (QueueFragment)getSupportFragmentManager().findFragmentById(R.id.queueFragment);
211 protected void setupHeaderBar(final int containerId, final int textId) {
212 final HeaderBar headerBar = (HeaderBar)findViewById(containerId);
213 TextView textView = (TextView)headerBar.findViewById(R.id.header_bar_title);
214 textView.setText(textId);
216 headerBar.add(getAudioPlayerFragment());
217 headerBar.add(getQueueFragment());