Back to project page PlayTunes.
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.
package com.ideabag.playtunes.fragment; //from w w w . j a v a 2 s . c o m import android.app.Activity; import android.database.ContentObserver; import android.database.Cursor; import android.os.Bundle; import android.os.Handler; import android.provider.MediaStore; import android.support.v4.app.ListFragment; import android.view.View; import android.widget.ListView; import com.google.android.gms.analytics.HitBuilders; import com.google.android.gms.analytics.Tracker; import com.ideabag.playtunes.R; import com.ideabag.playtunes.activity.MainActivity; import com.ideabag.playtunes.adapter.AlbumsAllAdapter; import com.ideabag.playtunes.database.MediaQuery; import com.ideabag.playtunes.util.GAEvent.Categories; import com.ideabag.playtunes.util.GAEvent.Playlist; import com.ideabag.playtunes.util.IMusicBrowser; import com.ideabag.playtunes.util.TrackerSingleton; public class AlbumsAllFragment extends SaveScrollListFragment implements IMusicBrowser { public static final String TAG = "All Albums Fragment"; AlbumsAllAdapter adapter; private MainActivity mActivity; private Tracker mTracker; @Override public void onAttach( Activity activity ) { super.onAttach( activity ); mActivity = ( MainActivity ) activity; mTracker = TrackerSingleton.getDefaultTracker( mActivity.getBaseContext() ); mTracker.setScreenName( TAG ); mActivity.setActionbarTitle( getString( R.string.albums_plural) ); } @Override public void onActivityCreated( Bundle savedInstanceState ) { super.onActivityCreated( savedInstanceState ); adapter = new AlbumsAllAdapter( getActivity(), new MediaQuery.OnQueryCompletedListener() { @Override public void onQueryCompleted( MediaQuery mQuery, Cursor mResult ) { mActivity.setActionbarSubtitle( mResult.getCount() + " " + ( mResult.getCount() == 1 ? getString( R.string.album_singular ) : getString( R.string.albums_plural ) ) ); restoreScrollPosition(); mTracker.send( new HitBuilders.EventBuilder() .setCategory( Categories.PLAYLIST ) .setAction( Playlist.ACTION_SHOWLIST ) .setValue( mResult.getCount() ) .build()); } }); //adapter.setOn getView().setBackgroundColor( getResources().getColor( android.R.color.white ) ); getListView().setDivider( getResources().getDrawable( R.drawable.list_divider ) ); getListView().setDividerHeight( 1 ); getListView().setSelector( R.drawable.list_item_background ); setListAdapter( adapter ); getActivity().getContentResolver().registerContentObserver( MediaStore.Audio.Albums.EXTERNAL_CONTENT_URI, true, mediaStoreChanged ); } @Override public void onResume() { super.onResume(); //mActivity.setActionbarTitle( getString( R.string.albums_plural) ); mActivity.setActionbarTitle( getString( R.string.albums_plural) ); // Set screen name. // Where path is a String representing the screen name. //t.set( "_count", ""+adapter.getCount() ); // Send a screen view. mTracker.send( new HitBuilders.AppViewBuilder().build() ); } @Override public void onPause() { super.onPause(); } @Override public void onDestroyView() { super.onDestroyView(); setListAdapter( null ); } @Override public void onDestroy() { super.onDestroy(); getActivity().getContentResolver().unregisterContentObserver( mediaStoreChanged ); } @Override public void onListItemClick( ListView l, View v, int position, long id ) { //convertView.setTag( R.id.tag_album_id, cursor.getString( cursor.getColumnIndexOrThrow( MediaStore.Audio.Albums.ALBUM ) ) ); String albumID = ( String ) v.getTag( R.id.tag_album_id ); AlbumsOneFragment albumFragment = new AlbumsOneFragment( ); albumFragment.setMediaID( albumID ); mActivity.transactFragment( albumFragment ); mTracker.send( new HitBuilders.EventBuilder() .setCategory( Categories.PLAYLIST ) .setAction( Playlist.ACTION_CLICK ) .setValue( position ) .build()); } ContentObserver mediaStoreChanged = new ContentObserver(new Handler()) { @Override public void onChange( boolean selfChange ) { mActivity.runOnUiThread( new Runnable() { @Override public void run() { saveScrollPosition(); adapter.requery(); // notifyDataSetChanged() gets called at the end of the asynchronous query } }); super.onChange( selfChange ); } }; // PlaylistBrowser interface methods @Override public void setMediaID(String media_id) { /* ... */ } @Override public String getMediaID() { return ""; } }