Android Open Source - PlayTunes Navigation Fragment






From Project

Back to project page PlayTunes.

License

The source code is released under:

Copyright (c) 2014, Impeccable Labs, LLC. All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions ar...

If you think the Android project PlayTunes listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.ideabag.playtunes.fragment;
/*from w  ww. java2 s. c  o m*/
import com.ideabag.playtunes.PlaylistManager;
import com.ideabag.playtunes.R;
import com.ideabag.playtunes.activity.MainActivity;
import com.ideabag.playtunes.activity.SettingsActivity;
import com.ideabag.playtunes.fragment.search.SearchFragment;

import android.app.Activity;
import android.content.Intent;
import android.database.ContentObserver;
import android.os.Bundle;
import android.os.Handler;
import android.provider.MediaStore;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.view.GravityCompat;
import android.support.v7.app.ActionBar;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;


public class NavigationFragment extends Fragment implements View.OnClickListener {
  
  public static final String TAG = "NavigationFragment";
  
  protected MainActivity mActivity;
  protected FragmentManager mFragmentManager;
  protected ActionBar mActionBar;
  
  protected PlaylistManager mPlaylistManager;
  
  protected MusicBrowserFragment MusicBrowserFragment;
  
  // Have we warned the user that pressing Back will close the app?
  protected boolean mCloseWarningOn = false;
  
  public CharSequence mActionbarTitle, mActionbarSubtitle;
  
  @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    
    return inflater.inflate( R.layout.fragment_navigation, container, false );
    
  }
  
  @Override public void onAttach( Activity activity ) {
    
    super.onAttach( activity );
    
    mActivity = ( MainActivity ) activity;
    
    mPlaylistManager = new PlaylistManager( getActivity() );
    
    mActionBar = mActivity.getSupportActionBar();
    
        //mActionBar.setLogo( R.drawable.ic_drawer );
    mActionBar.setDisplayHomeAsUpEnabled( true );
        mActionBar.setHomeButtonEnabled( true ); // Makes the drawer icon enabled
        //mActionBar.setDisplayUseLogoEnabled( true ); // Hides the icon
        //mActionBar.setDisplayShowHomeEnabled( true );
        //mActionBar.setIcon( android.R.color.transparent ); 
        mActionBar.setDisplayShowHomeEnabled( false );
        mFragmentManager = mActivity.getSupportFragmentManager();
    
        
  }
  
  
  @Override public void onActivityCreated( Bundle savedInstanceState ) {
    
    super.onActivityCreated( savedInstanceState );
    
    getView().findViewById( R.id.NavigationArtistsAll ).setOnClickListener( this );
    getView().findViewById( R.id.NavigationAlbumsAll ).setOnClickListener( this );
    getView().findViewById( R.id.NavigationGenresAll ).setOnClickListener( this );
    getView().findViewById( R.id.NavigationPlaylistsAll ).setOnClickListener( this );
    getView().findViewById( R.id.NavigationSearch ).setOnClickListener( this );
    getView().findViewById( R.id.NavigationStarred ).setOnClickListener( this );
    getView().findViewById( R.id.NavigationSongsAll ).setOnClickListener( this );
        
    
    View settingsButton = getView().findViewById( R.id.SettingsButton );
    if ( null != settingsButton ) {
      
      settingsButton.setOnClickListener( this );
      
    } else {
      
      // Add extra options into the app overflow menu
      
    }
    
    getActivity().getContentResolver().registerContentObserver(
        MediaStore.Audio.Media.EXTERNAL_CONTENT_URI, true, mediaStoreChanged );
    
    getActivity().getContentResolver().registerContentObserver(
        MediaStore.Audio.Playlists.Members.getContentUri( "external",
            Long.parseLong( mPlaylistManager.createStarredIfNotExist() ) ), true, mediaStoreChanged );
    
     
     MusicBrowserFragment = ( MusicBrowserFragment ) getActivity().getSupportFragmentManager().findFragmentById( R.id.MusicBrowserFragment );
     
     
  }
    
  
  @Override public void onPause() {
    super.onPause();
  }
  
  @Override public void onDestroy() {
    super.onDestroy();
    
    getActivity().getContentResolver().unregisterContentObserver( mediaStoreChanged );
    
  }
  
  @Override public void onClick( View v ) {
    
    int id = v.getId();
    load( id );
    
  }
  
  protected void load( int id ) {
    
    Fragment mNewFragment = null;
    
    switch ( id ) {
    
    case R.id.NavigationArtistsAll:
      mNewFragment = new ArtistsAllFragment();
      break;
      
    case R.id.NavigationAlbumsAll:
      mNewFragment = new AlbumsAllFragment();
      break;
      
    case R.id.NavigationGenresAll:
        mNewFragment = new GenresAllFragment();
      break;
      
    case R.id.NavigationSongsAll:
      
        mNewFragment = new SongsFragment();
      break;
    
    case R.id.NavigationStarred:
      
      mNewFragment = new PlaylistsOneFragment();
      ((PlaylistsOneFragment)mNewFragment).setMediaID( mPlaylistManager.createStarredIfNotExist() );
      
      break;
    
    case R.id.NavigationSearch:
      
      mNewFragment = new SearchFragment();
      
      break;
    case R.id.SettingsButton:
        
        Intent launchSettingsIntent = new Intent( getActivity(), SettingsActivity.class);
        getActivity().startActivity( launchSettingsIntent );
        
      break;
    default:
      
      mNewFragment = new PlaylistsAllFragment();
      break;
      
    }
    
    if ( null != mNewFragment ) {
      
      transactFragment( mNewFragment );
      
    }
    
  }
  
  ContentObserver mediaStoreChanged = new ContentObserver(new Handler()) {

        @Override public void onChange( boolean selfChange ) {
            
            mActivity.runOnUiThread( new Runnable() {

        @Override public void run() {
          
          //adapter.notifyDataSetChanged();
          
        }
              
            });
            
            super.onChange( selfChange );
            
        }

  };
  
    
    public void showNowPlaying() {
      
      MusicBrowserFragment.showNowPlaying();
      
    }
    
    public void showSearch() {
      
      Fragment mSearchFragment = new SearchFragment();
      
      transactFragment( mSearchFragment );
      
    }
    
    public void transactFragment( Fragment mFragment ) {
      
      MusicBrowserFragment.transactFragment( mFragment );
      
      mCloseWarningOn = false;
      
    }
    
    public boolean onKeyDown( int keycode, KeyEvent e ) {
      
      switch ( keycode ) {
          
          case KeyEvent.KEYCODE_SEARCH:
            
            showSearch();
            return true;
          
          case KeyEvent.KEYCODE_BACK:
            
            if ( mFragmentManager.getBackStackEntryCount() == 0 ) {
              
              if ( !mCloseWarningOn ) {
                
                android.widget.Toast.makeText( mActivity, getString( R.string.back_warning ), android.widget.Toast.LENGTH_LONG ).show();
                mCloseWarningOn = true;
                
                return true;
                
              }
              
            } else {
              
              mCloseWarningOn = false;
              
            }
            break;
      }
      
      return false;
      
    }
  
  public void setActionbarTitle( String titleString ) {
    
    mActionbarTitle = ( CharSequence ) titleString;
    
    mActionBar.setTitle( mActionbarTitle );
    
  }
  
  public void setActionbarSubtitle( String subtitleString ) {
    
    mActionbarSubtitle = ( CharSequence ) subtitleString;
    
    mActionBar.setSubtitle( mActionbarSubtitle );
    
  }
    
}




Java Source Code List

com.ideabag.playtunes.PlaylistManager.java
com.ideabag.playtunes.DragNDrop.DragListener.java
com.ideabag.playtunes.DragNDrop.DragNDropListView.java
com.ideabag.playtunes.DragNDrop.DropListener.java
com.ideabag.playtunes.DragNDrop.RemoveListener.java
com.ideabag.playtunes.activity.MainActivity.java
com.ideabag.playtunes.activity.NowPlayingActivity.java
com.ideabag.playtunes.activity.SettingsActivity.java
com.ideabag.playtunes.adapter.AlbumListAdapter.java
com.ideabag.playtunes.adapter.AlbumsAllAdapter.java
com.ideabag.playtunes.adapter.AlbumsOneAdapter.java
com.ideabag.playtunes.adapter.ArtistAlbumsAdapter.java
com.ideabag.playtunes.adapter.ArtistAllSongsAdapter.java
com.ideabag.playtunes.adapter.ArtistListAdapter.java
com.ideabag.playtunes.adapter.ArtistSinglesAdapter.java
com.ideabag.playtunes.adapter.ArtistsAllAdapter.java
com.ideabag.playtunes.adapter.AsyncQueryAdapter.java
com.ideabag.playtunes.adapter.GenresAllAdapter.java
com.ideabag.playtunes.adapter.GenresOneAdapter.java
com.ideabag.playtunes.adapter.NavigationListAdapter.java
com.ideabag.playtunes.adapter.PlaylistsAllAdapter.java
com.ideabag.playtunes.adapter.PlaylistsOneAdapter.java
com.ideabag.playtunes.adapter.SongListAdapter.java
com.ideabag.playtunes.adapter.SongsAllAdapter.java
com.ideabag.playtunes.adapter.search.SearchAlbumsAdapter.java
com.ideabag.playtunes.adapter.search.SearchArtistsAdapter.java
com.ideabag.playtunes.adapter.search.SearchSongsAdapter.java
com.ideabag.playtunes.database.MediaQuery.java
com.ideabag.playtunes.dialog.AddToPlaylistDialogFragment.java
com.ideabag.playtunes.dialog.CreatePlaylistDialogFragment.java
com.ideabag.playtunes.dialog.FeedbackDialogFragment.java
com.ideabag.playtunes.dialog.PlaylistDeleteDialogFragment.java
com.ideabag.playtunes.dialog.PlaylistMenuDialogFragment.java
com.ideabag.playtunes.dialog.PlaylistRenameDialogFragment.java
com.ideabag.playtunes.dialog.RateAppDialogFragment.java
com.ideabag.playtunes.dialog.SongMenuDialogFragment.java
com.ideabag.playtunes.fragment.AlbumsAllFragment.java
com.ideabag.playtunes.fragment.AlbumsOneFragment.java
com.ideabag.playtunes.fragment.ArtistSinglesFragment.java
com.ideabag.playtunes.fragment.ArtistsAllFragment.java
com.ideabag.playtunes.fragment.ArtistsOneFragment.java
com.ideabag.playtunes.fragment.FooterControlsFragment.java
com.ideabag.playtunes.fragment.GenresAllFragment.java
com.ideabag.playtunes.fragment.GenresOneFragment.java
com.ideabag.playtunes.fragment.MusicBrowserFragment.java
com.ideabag.playtunes.fragment.NavigationDrawerFragment.java
com.ideabag.playtunes.fragment.NavigationFragment.java
com.ideabag.playtunes.fragment.PlaylistsAllFragment.java
com.ideabag.playtunes.fragment.PlaylistsOneFragment.java
com.ideabag.playtunes.fragment.SaveScrollListFragment.java
com.ideabag.playtunes.fragment.SongsFragment.java
com.ideabag.playtunes.fragment.TrackProgressFragment.java
com.ideabag.playtunes.fragment.search.SearchAlbumsFragment.java
com.ideabag.playtunes.fragment.search.SearchAllFragment.java
com.ideabag.playtunes.fragment.search.SearchArtistsFragment.java
com.ideabag.playtunes.fragment.search.SearchFragment.java
com.ideabag.playtunes.fragment.search.SearchSongsFragment.java
com.ideabag.playtunes.fragment.search.SearchSuggestionsFragment.java
com.ideabag.playtunes.media.AudioFocusHelper.java
com.ideabag.playtunes.media.MusicFocusable.java
com.ideabag.playtunes.media.MusicIntentReceiver.java
com.ideabag.playtunes.media.PlaylistMediaPlayer.java
com.ideabag.playtunes.media.RemoteControlClientCompat.java
com.ideabag.playtunes.media.RemoteControlHelper.java
com.ideabag.playtunes.service.LockscreenManager.java
com.ideabag.playtunes.service.MusicPlayerService.java
com.ideabag.playtunes.service.PlaybackNotification.java
com.ideabag.playtunes.util.AdmobUtil.java
com.ideabag.playtunes.util.AlbumSongsCountTask.java
com.ideabag.playtunes.util.AsyncDrawable.java
com.ideabag.playtunes.util.BitmapWorkerTask.java
com.ideabag.playtunes.util.CheckRemoteVersionFileTask.java
com.ideabag.playtunes.util.DrawerLayout.java
com.ideabag.playtunes.util.GAEvent.java
com.ideabag.playtunes.util.IMusicBrowser.java
com.ideabag.playtunes.util.ISearchableAdapter.java
com.ideabag.playtunes.util.LoadAlbumStackTask.java
com.ideabag.playtunes.util.MergeAdapter.java
com.ideabag.playtunes.util.QueryCountTask.java
com.ideabag.playtunes.util.SackOfViewsAdapter.java
com.ideabag.playtunes.util.SearchHistory.java
com.ideabag.playtunes.util.StarToggleTask.java
com.ideabag.playtunes.util.TrackerSingleton.java