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;
55 private int mActionBarColor;
61 protected void onCreate(final Bundle savedInstanceState) {
62 super.onCreate(savedInstanceState);
64 if (savedInstanceState == null) {
65 getSupportFragmentManager().beginTransaction()
66 .replace(R.id.activity_base_content, new MusicBrowserPhoneFragment()).commit();
69 // set the action bar background color to be the background theme color
70 mActionBarColor = getResources().getColor(R.color.header_action_bar_color);
71 getActionBar().setBackgroundDrawable(new ColorDrawable(mActionBarColor));
76 // if we've been launched by an intent, parse it
77 Intent launchIntent = getIntent();
78 if (launchIntent != null) {
79 parseIntent(launchIntent);
83 private void setupFirstPanel() {
84 mFirstPanel = (SlidingUpPanelLayout)findViewById(R.id.sliding_layout);
85 mFirstPanel.setPanelSlideListener(new SimplePanelSlideListener() {
87 public void onPanelSlide(View panel, float slideOffset) {
88 if (slideOffset > 0.8f) {
89 getActionBar().hide();
90 } else if (slideOffset < 0.75f) {
91 getActionBar().show();
96 // setup the header bar
97 setupHeaderBar(R.id.firstHeaderBar, R.string.app_name_uppercase); //R.string.page_now_playing);
100 private void setupSecondPanel() {
101 mSecondPanel = (SlidingUpPanelLayout)findViewById(R.id.sliding_layout2);
102 mSecondPanel.setPanelSlideListener(new SimplePanelSlideListener() {
104 public void onPanelSlide(View panel, float slideOffset) {
105 mFirstPanel.setSlidingEnabled(false);
109 public void onPanelCollapsed(View panel) {
110 mFirstPanel.setSlidingEnabled(true);
114 // setup the header bar
115 setupHeaderBar(R.id.secondHeaderBar, R.string.page_play_queue);
117 // set the drag view offset to allow the panel to go past the top of the viewport
118 // since the previous view's is hiding the slide offset, we need to subtract that
119 // from action bat height
120 int slideOffset = getResources().getDimensionPixelOffset(R.dimen.sliding_panel_indicator_height);
121 slideOffset -= ApolloUtils.getActionBarHeight(this);
122 mSecondPanel.setSlidePanelOffset(slideOffset);
126 protected void onNewIntent(Intent intent) {
127 super.onNewIntent(intent);
132 private void parseIntent(Intent intent) {
133 Panel targetPanel = null;
135 if (intent.getAction() != null) {
136 String action = intent.getAction();
137 if (action.equals(ACTION_VIEW_BROWSE)) {
138 targetPanel = Panel.Browse;
139 } else if (action.equals(ACTION_VIEW_MUSIC_PLAYER)) {
140 targetPanel = Panel.MusicPlayer;
141 } if (action.equals(ACTION_VIEW_QUEUE)) {
142 targetPanel = Panel.Queue;
145 AudioPlayerFragment player = getAudioPlayerFragment();
146 if (player != null && player.startPlayback()) {
147 targetPanel = Panel.MusicPlayer;
151 if (targetPanel != null) {
152 showPanel(targetPanel);
160 public int setContentView() {
161 return R.layout.activity_base;
165 public void onBackPressed() {
166 Panel panel = getCurrentPanel();
169 super.onBackPressed();
172 showPanel(Panel.Browse);
175 showPanel(Panel.MusicPlayer);
180 protected void showPanel(Panel panel) {
181 // TODO: Add ability to do this instantaneously as opposed to animate
184 mSecondPanel.collapsePanel();
185 mFirstPanel.collapsePanel();
188 mSecondPanel.collapsePanel();
189 mFirstPanel.expandPanel();
192 mSecondPanel.expandPanel();
193 mFirstPanel.expandPanel();
198 protected Panel getCurrentPanel() {
199 if (mSecondPanel.isPanelExpanded()) {
201 } else if (mFirstPanel.isPanelExpanded()) {
202 return Panel.MusicPlayer;
208 protected AudioPlayerFragment getAudioPlayerFragment() {
209 return (AudioPlayerFragment)getSupportFragmentManager().findFragmentById(R.id.audioPlayerFragment);
212 protected QueueFragment getQueueFragment() {
213 return (QueueFragment)getSupportFragmentManager().findFragmentById(R.id.queueFragment);
216 protected void setupHeaderBar(final int containerId, final int textId) {
217 final HeaderBar headerBar = (HeaderBar)findViewById(containerId);
218 TextView textView = (TextView)headerBar.findViewById(R.id.header_bar_title);
219 textView.setText(textId);
221 headerBar.add(getAudioPlayerFragment());
222 headerBar.add(getQueueFragment());