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); } }
@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; }