Ejemplo n.º 1
0
  AlbumCoverHandler(final MPDroidService serviceContext) {
    super();

    mIsAlbumCacheEnabled =
        PreferenceManager.getDefaultSharedPreferences(serviceContext)
            .getBoolean(CoverManager.PREFERENCE_CACHE, true);

    mIconHeight =
        serviceContext
            .getResources()
            .getDimensionPixelSize(android.R.dimen.notification_large_icon_height);

    mIconWidth =
        serviceContext
            .getResources()
            .getDimensionPixelSize(android.R.dimen.notification_large_icon_width);

    if (mIsAlbumCacheEnabled) {
      final int maxSize = -1;
      mCoverAsyncHelper = new CoverAsyncHelper();
      mCoverAsyncHelper.setCachedCoverMaxSize(maxSize);
      mCoverAsyncHelper.setCoverMaxSize(maxSize);
      mCoverAsyncHelper.setCoverRetrieversFromPreferences();
      mCoverAsyncHelper.addCoverDownloadListener(this);
    }
  }
Ejemplo n.º 2
0
  /**
   * This method updates the service covers if the current cover path is different than currently
   * playing, if cache is enabled.
   */
  private void updateAlbumCoverWithCached(final AlbumInfo albumInfo) {
    if (DEBUG) {
      Log.d(TAG, "updateAlbumCoverWithCache(music): " + albumInfo);
    }
    final String coverArtPath = retrieveCoverArtPath(albumInfo);
    final boolean sameCover = coverArtPath != null && coverArtPath.equals(mAlbumCoverPath);
    final boolean fullCoverValid = mFullSizeAlbumCover != null && !mFullSizeAlbumCover.isRecycled();
    final boolean smallCoverValid = mNotificationCover != null && !mNotificationCover.isRecycled();

    if (coverArtPath == null) {
      if (DEBUG) {
        Log.d(TAG, "Cover not found, attempting download.");
      }

      mNotificationListener.onCoverUpdate(null);
      mFullSizeListener.onCoverUpdate(null);
      mCoverAsyncHelper.downloadCover(albumInfo);
    } else if (sameCover && fullCoverValid && smallCoverValid) {
      if (DEBUG) {
        Log.d(TAG, "Cover the same as last time, omitting.");
      }

      mNotificationListener.onCoverUpdate(mNotificationCover);
      mFullSizeListener.onCoverUpdate(mFullSizeAlbumCover);
    } else {
      if (DEBUG) {
        Log.d(TAG, "Cover found in cache, decoding.");
      }

      new DecodeAlbumCover().execute(coverArtPath);
    }
  }
Ejemplo n.º 3
0
  final void stop() {
    /** Don't recycle. Android can easily get out of state; let GC do it's magic. */
    mFullSizeListener = null;
    mNotificationListener = null;

    if (mCoverAsyncHelper != null) {
      mCoverAsyncHelper.removeCoverDownloadListener(this);
    }
  }
Ejemplo n.º 4
0
 @Override
 public void updateFromItems() {
   super.updateFromItems();
   if (items != null) {
     Music song;
     String lastArtist = null;
     for (Item item : items) {
       song = (Music) item;
       if (lastArtist == null) {
         lastArtist = song.getArtist();
         continue;
       }
     }
     if (lastArtist == null) {
       for (Item item : items) {
         song = (Music) item;
         if (lastArtist == null) {
           lastArtist = song.getArtist();
           continue;
         }
       }
     }
     String artistName = getArtistForTrackList();
     headerArtist.setText(artistName);
     headerInfo.setText(getHeaderInfoString());
     if (coverHelper != null) {
       String filename = null;
       String path = null;
       if (items.size() > 0) {
         song = (Music) items.get(0);
         filename = song.getFilename();
         path = song.getPath();
         artistName = song.getArtist();
       }
       coverArtProgress.setVisibility(ProgressBar.VISIBLE);
       coverHelper.downloadCover(artistName, album.getName(), path, filename);
     } else {
       coverArtListener.onCoverNotFound();
     }
   }
 }
Ejemplo n.º 5
0
  @Override
  public View onCreateView(
      LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    final View view = inflater.inflate(R.layout.songs, container, false);
    list = (ListView) view.findViewById(R.id.list);
    registerForContextMenu(list);
    list.setOnItemClickListener(this);
    loadingView = view.findViewById(R.id.loadingLayout);
    loadingTextView = (TextView) view.findViewById(R.id.loadingText);
    noResultView = view.findViewById(R.id.noResultLayout);
    loadingTextView.setText(getLoadingText());

    final View headerView = inflater.inflate(R.layout.song_header, null, false);
    coverArt = (ImageView) view.findViewById(R.id.albumCover);
    if (coverArt != null) {
      headerArtist = (TextView) view.findViewById(R.id.tracks_artist);
      headerInfo = (TextView) view.findViewById(R.id.tracks_info);
      coverArtProgress = (ProgressBar) view.findViewById(R.id.albumCoverProgress);
      albumMenu = (ImageButton) view.findViewById(R.id.album_menu);
    } else {
      headerArtist = (TextView) headerView.findViewById(R.id.tracks_artist);
      headerInfo = (TextView) headerView.findViewById(R.id.tracks_info);
      coverArt = (ImageView) headerView.findViewById(R.id.albumCover);
      coverArtProgress = (ProgressBar) headerView.findViewById(R.id.albumCoverProgress);
      albumMenu = (ImageButton) headerView.findViewById(R.id.album_menu);

      final MPDApplication app = (MPDApplication) getActivity().getApplication();
      coverArtListener = new AlbumCoverDownloadListener(getActivity(), coverArt, coverArtProgress);
      coverHelper =
          new CoverAsyncHelper(app, PreferenceManager.getDefaultSharedPreferences(getActivity()));
      coverHelper.setCoverRetrieversFromPreferences();
      coverHelper.setCoverMaxSizeFromScreen(getActivity());
      coverHelper.setCachedCoverMaxSize(coverArt.getHeight());
      coverHelper.addCoverDownloadListener(coverArtListener);
    }
    ((TextView) headerView.findViewById(R.id.separator_title)).setText(R.string.songs);
    ((ListView) list).addHeaderView(headerView, null, false);

    albumMenu.setOnClickListener(
        new OnClickListener() {
          @Override
          public void onClick(View v) {
            popupMenu = new IcsListPopupWindow(getActivity());
            popupMenu.setAdapter(getPopupMenuAdapter(getActivity()));
            popupMenu.setModal(true);
            popupMenu.setOnItemClickListener(
                new OnItemClickListener() {
                  @Override
                  public void onItemClick(
                      AdapterView<?> adapterView, View view, int position, long id) {
                    final int action =
                        ((PopupMenuItem) adapterView.getAdapter().getItem(position)).actionId;

                    app.oMPDAsyncHelper.execAsync(
                        new Runnable() {
                          @Override
                          public void run() {
                            boolean replace = false;
                            boolean play = false;
                            switch (action) {
                              case ADDNREPLACEPLAY:
                                replace = true;
                                play = true;
                                break;
                              case ADDNREPLACE:
                                replace = true;
                                break;
                              case ADDNPLAY:
                                play = true;
                                break;
                            }
                            try {
                              app.oMPDAsyncHelper.oMPD.add(artist, album, replace, play);
                              Tools.notifyUser(
                                  String.format(
                                      getResources().getString(R.string.albumAdded), album),
                                  getActivity());
                            } catch (MPDServerException e) {
                              e.printStackTrace();
                            }
                          }
                        });

                    popupMenu.dismiss();
                  }
                });

            final DisplayMetrics displaymetrics = new DisplayMetrics();
            getActivity().getWindowManager().getDefaultDisplay().getMetrics(displaymetrics);
            popupMenu.setContentWidth(displaymetrics.widthPixels / 2);
            popupMenu.setAnchorView(v);
            popupMenu.show();
          }
        });

    return view;
  }