/**
  * @param context The {@link Context} to use.
  * @param albumId The Id of the album the songs belong to.
  * @return The {@link Cursor} used to run the query.
  */
 public static final Cursor makeAlbumSongCursor(final Context context, final Long albumId) {
   // Match the songs up with the artist
   final StringBuilder selection = new StringBuilder();
   selection.append(AudioColumns.IS_MUSIC + "=1");
   selection.append(" AND " + MediaColumns.TITLE + " != ''");
   selection.append(" AND " + AudioColumns.ALBUM_ID + "=" + albumId);
   return context
       .getContentResolver()
       .query(
           MediaStore.Audio.Media.EXTERNAL_CONTENT_URI,
           new String[] {
             /* 0 */
             BaseColumns._ID,
             /* 1 */
             MediaColumns.TITLE,
             /* 2 */
             AudioColumns.ARTIST,
             /* 3 */
             AudioColumns.ALBUM,
             /* 4 */
             AudioColumns.DURATION
           },
           selection.toString(),
           null,
           PreferenceUtils.getInstace(context).getAlbumSongSortOrder());
 }
  /** {@inheritDoc} */
  @Override
  public View onCreateView(
      final LayoutInflater inflater, final ViewGroup container, final Bundle savedInstanceState) {
    // The View for the fragment's UI
    final ViewGroup rootView =
        (ViewGroup) inflater.inflate(R.layout.fragment_music_browser_phone, container, false);

    // Initialize the adapter
    mPagerAdapter = new PagerAdapter(getActivity());
    final MusicFragments[] mFragments = MusicFragments.values();
    for (final MusicFragments mFragment : mFragments) {
      mPagerAdapter.add(mFragment.getFragmentClass(), null);
    }

    // Initialize the ViewPager
    mViewPager = (ViewPager) rootView.findViewById(R.id.fragment_home_phone_pager);
    // Attch the adapter
    mViewPager.setAdapter(mPagerAdapter);
    // Offscreen pager loading limit
    mViewPager.setOffscreenPageLimit(mPagerAdapter.getCount() - 1);
    // Start on the last page the user was on
    mViewPager.setCurrentItem(mPreferences.getStartPage());

    // Initialze the TPI
    final TitlePageIndicator pageIndicator =
        (TitlePageIndicator) rootView.findViewById(R.id.fragment_home_phone_pager_titles);
    // Attach the ViewPager
    pageIndicator.setViewPager(mViewPager);
    // Scroll to the current artist, album, or song
    pageIndicator.setOnCenterItemClickListener(this);
    return rootView;
  }
  /** {@inheritDoc} */
  @Override
  protected void onCreate(final Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    // Fade it in
    overridePendingTransition(android.R.anim.fade_in, android.R.anim.fade_out);

    // Get the preferences
    mPreferences = PreferenceUtils.getInstace(this);

    // Initialze the image cache
    mImageCache = ImageCache.getInstance(this);

    // UP
    getActionBar().setDisplayHomeAsUpEnabled(true);

    // Add the preferences
    addPreferencesFromResource(R.xml.settings);

    // Interface settings
    initInterface();
    // Date settings
    initData();
    // Removes the cache entries
    deleteCache();
    // About
    showOpenSourceLicenses();
    // Update the version number
    try {
      final PackageInfo packageInfo = getPackageManager().getPackageInfo(getPackageName(), 0);
      findPreference("version").setSummary(packageInfo.versionName);
    } catch (final NameNotFoundException e) {
      findPreference("version").setSummary("?");
    }
  }
예제 #4
0
 /**
  * Creates the {@link Cursor} used to run the query.
  *
  * @param context The {@link Context} to use.
  * @return The {@link Cursor} used to run the album query.
  */
 private Cursor makeAlbumCursor(final Context context) {
   return context
       .getContentResolver()
       .query(
           MediaStore.Audio.Albums.EXTERNAL_CONTENT_URI,
           new String[] {
             /* 0 */
             BaseColumns._ID,
             /* 1 */
             AlbumColumns.ALBUM,
             /* 2 */
             AlbumColumns.ARTIST,
             /* 3 */
             AlbumColumns.NUMBER_OF_SONGS,
             /* 4 */
             AlbumColumns.FIRST_YEAR
           },
           null,
           null,
           PreferenceUtils.getInstance(context).getAlbumSortOrder());
 }
 protected boolean isSimpleLayout() {
   return PreferenceUtils.getInstance(getActivity()).isSimpleLayout(ALBUM_LAYOUT, getActivity());
 }
 /** {@inheritDoc} */
 @Override
 public void onCreate(final Bundle savedInstanceState) {
   super.onCreate(savedInstanceState);
   // Get the preferences
   mPreferences = PreferenceUtils.getInstace(getActivity());
 }
 /** {@inheritDoc} */
 @Override
 public boolean onOptionsItemSelected(final MenuItem item) {
   switch (item.getItemId()) {
     case R.id.menu_shuffle:
       // Shuffle all the songs
       MusicUtils.shuffleAll(getActivity());
       return true;
     case R.id.menu_favorite:
       // Toggle the current track as a favorite and update the menu
       // item
       MusicUtils.toggleFavorite();
       getActivity().invalidateOptionsMenu();
       return true;
     case R.id.menu_sort_by_az:
       if (isArtistPage()) {
         mPreferences.setArtistSortOrder(SortOrder.ArtistSortOrder.ARTIST_A_Z);
         getArtistFragment().refresh();
       } else if (isAlbumPage()) {
         mPreferences.setAlbumSortOrder(SortOrder.AlbumSortOrder.ALBUM_A_Z);
         getAlbumFragment().refresh();
       } else if (isSongPage()) {
         mPreferences.setSongSortOrder(SortOrder.SongSortOrder.SONG_A_Z);
         getSongFragment().refresh();
       }
       return true;
     case R.id.menu_sort_by_za:
       if (isArtistPage()) {
         mPreferences.setArtistSortOrder(SortOrder.ArtistSortOrder.ARTIST_Z_A);
         getArtistFragment().refresh();
       } else if (isAlbumPage()) {
         mPreferences.setAlbumSortOrder(SortOrder.AlbumSortOrder.ALBUM_Z_A);
         getAlbumFragment().refresh();
       } else if (isSongPage()) {
         mPreferences.setSongSortOrder(SortOrder.SongSortOrder.SONG_Z_A);
         getSongFragment().refresh();
       }
       return true;
     case R.id.menu_sort_by_artist:
       if (isAlbumPage()) {
         mPreferences.setAlbumSortOrder(SortOrder.AlbumSortOrder.ALBUM_ARTIST);
         getAlbumFragment().refresh();
       } else if (isSongPage()) {
         mPreferences.setSongSortOrder(SortOrder.SongSortOrder.SONG_ARTIST);
         getSongFragment().refresh();
       }
       return true;
     case R.id.menu_sort_by_album:
       if (isSongPage()) {
         mPreferences.setSongSortOrder(SortOrder.SongSortOrder.SONG_ALBUM);
         getSongFragment().refresh();
       }
       return true;
     case R.id.menu_sort_by_year:
       if (isAlbumPage()) {
         mPreferences.setAlbumSortOrder(SortOrder.AlbumSortOrder.ALBUM_YEAR);
         getAlbumFragment().refresh();
       } else if (isSongPage()) {
         mPreferences.setSongSortOrder(SortOrder.SongSortOrder.SONG_YEAR);
         getSongFragment().refresh();
       }
       return true;
     case R.id.menu_sort_by_duration:
       if (isSongPage()) {
         mPreferences.setSongSortOrder(SortOrder.SongSortOrder.SONG_DURATION);
         getSongFragment().refresh();
       }
       return true;
     case R.id.menu_sort_by_number_of_songs:
       if (isArtistPage()) {
         mPreferences.setArtistSortOrder(SortOrder.ArtistSortOrder.ARTIST_NUMBER_OF_SONGS);
         getArtistFragment().refresh();
       } else if (isAlbumPage()) {
         mPreferences.setAlbumSortOrder(SortOrder.AlbumSortOrder.ALBUM_NUMBER_OF_SONGS);
         getAlbumFragment().refresh();
       }
       return true;
     case R.id.menu_sort_by_number_of_albums:
       if (isArtistPage()) {
         mPreferences.setArtistSortOrder(SortOrder.ArtistSortOrder.ARTIST_NUMBER_OF_ALBUMS);
         getArtistFragment().refresh();
       }
       return true;
     case R.id.menu_view_as_simple:
       if (isRecentPage()) {
         mPreferences.setRecentLayout("simple");
       } else if (isArtistPage()) {
         mPreferences.setArtistLayout("simple");
       } else if (isAlbumPage()) {
         mPreferences.setAlbumLayout("simple");
       }
       NavUtils.goHome(getActivity());
       return true;
     case R.id.menu_view_as_detailed:
       if (isRecentPage()) {
         mPreferences.setRecentLayout("detailed");
       } else if (isArtistPage()) {
         mPreferences.setArtistLayout("detailed");
       } else if (isAlbumPage()) {
         mPreferences.setAlbumLayout("detailed");
       }
       NavUtils.goHome(getActivity());
       return true;
     case R.id.menu_view_as_grid:
       if (isRecentPage()) {
         mPreferences.setRecentLayout("grid");
       } else if (isArtistPage()) {
         mPreferences.setArtistLayout("grid");
       } else if (isAlbumPage()) {
         mPreferences.setAlbumLayout("grid");
       }
       NavUtils.goHome(getActivity());
       return true;
     default:
       break;
   }
   return super.onOptionsItemSelected(item);
 }
 /** {@inheritDoc} */
 @Override
 public void onPause() {
   super.onPause();
   // Save the last page the use was on
   mPreferences.setStartPage(mViewPager.getCurrentItem());
 }