use of org.gateshipone.malp.application.utils.CoverBitmapLoader in project malp by gateship-one.
the class AlbumTracksFragment method onCreateView.
@Override
public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
// Inflate the layout for this fragment
View rootView = inflater.inflate(R.layout.listview_layout_refreshable, container, false);
// Get the main ListView of this fragment
mListView = rootView.findViewById(R.id.main_listview);
/* Check if an artistname/albumame was given in the extras */
Bundle args = getArguments();
if (null != args) {
mAlbum = args.getParcelable(BUNDLE_STRING_EXTRA_ALBUM);
mBitmap = args.getParcelable(BUNDLE_STRING_EXTRA_BITMAP);
}
// Create the needed adapter for the ListView
mFileAdapter = new FileAdapter(getActivity(), false, true);
// Combine the two to a happy couple
mListView.setAdapter(mFileAdapter);
registerForContextMenu(mListView);
mListView.setOnItemClickListener(this);
// get swipe layout
mSwipeRefreshLayout = rootView.findViewById(R.id.refresh_layout);
// set swipe colors
mSwipeRefreshLayout.setColorSchemeColors(ThemeUtils.getThemeColor(getContext(), R.attr.colorAccent), ThemeUtils.getThemeColor(getContext(), R.attr.colorPrimary));
// set swipe refresh listener
mSwipeRefreshLayout.setOnRefreshListener(this::refreshContent);
SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(getContext());
mClickAction = PreferenceHelper.getClickAction(sharedPref, getContext());
mUseArtistSort = sharedPref.getBoolean(getString(R.string.pref_use_artist_sort_key), getResources().getBoolean(R.bool.pref_use_artist_sort_default));
setHasOptionsMenu(true);
mBitmapLoader = new CoverBitmapLoader(getContext(), this);
// Return the ready inflated and configured fragment view.
return rootView;
}
use of org.gateshipone.malp.application.utils.CoverBitmapLoader in project malp by gateship-one.
the class AlbumsFragment method onCreateView.
@Override
public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(getContext());
String libraryView = sharedPref.getString(getString(R.string.pref_library_view_key), getString(R.string.pref_library_view_default));
if (libraryView.equals(getString(R.string.pref_library_view_list_key))) {
mUseList = true;
}
View rootView;
// get gridview
if (mUseList) {
rootView = inflater.inflate(R.layout.listview_layout_refreshable, container, false);
mAdapterView = (ListView) rootView.findViewById(R.id.main_listview);
} else {
// Inflate the layout for this fragment
rootView = inflater.inflate(R.layout.fragment_gridview, container, false);
mAdapterView = (GridView) rootView.findViewById(R.id.grid_refresh_gridview);
}
mSortOrder = PreferenceHelper.getMPDAlbumSortOrder(sharedPref, getContext());
mUseArtistSort = sharedPref.getBoolean(getString(R.string.pref_use_artist_sort_key), getResources().getBoolean(R.bool.pref_use_artist_sort_default));
mAlbumsAdapter = new AlbumsAdapter(getActivity(), mAdapterView, mUseList);
/* Check if an artistname was given in the extras */
Bundle args = getArguments();
if (null != args) {
mAlbumsPath = args.getString(BUNDLE_STRING_EXTRA_PATH);
mArtist = args.getParcelable(BUNDLE_STRING_EXTRA_ARTIST);
mBitmap = args.getParcelable(BUNDLE_STRING_EXTRA_BITMAP);
} else {
mAlbumsPath = "";
// Create dummy album
mArtist = new MPDArtist("");
}
mAdapterView.setAdapter(mAlbumsAdapter);
mAdapterView.setOnItemClickListener(this);
mAdapterView.setOnScrollListener(new ScrollSpeedListener(mAlbumsAdapter, mAdapterView));
// register for context menu
registerForContextMenu(mAdapterView);
setHasOptionsMenu(true);
// get swipe layout
mSwipeRefreshLayout = rootView.findViewById(R.id.refresh_layout);
// set swipe colors
mSwipeRefreshLayout.setColorSchemeColors(ThemeUtils.getThemeColor(getContext(), R.attr.colorAccent), ThemeUtils.getThemeColor(getContext(), R.attr.colorPrimary));
// set swipe refresh listener
mSwipeRefreshLayout.setOnRefreshListener(this::refreshContent);
mBitmapLoader = new CoverBitmapLoader(getContext(), this);
return rootView;
}
use of org.gateshipone.malp.application.utils.CoverBitmapLoader in project malp by gateship-one.
the class NowPlayingView method onFinishInflate.
/**
* Called after the layout inflater is finished.
* Sets all global view variables to the ones inflated.
*/
@Override
protected void onFinishInflate() {
super.onFinishInflate();
// Get both main views (header and bottom part)
mHeaderView = findViewById(R.id.now_playing_headerLayout);
mMainView = findViewById(R.id.now_playing_bodyLayout);
// header buttons
mTopPlayPauseButton = findViewById(R.id.now_playing_topPlayPauseButton);
mTopPlaylistButton = findViewById(R.id.now_playing_topPlaylistButton);
mTopMenuButton = findViewById(R.id.now_playing_topMenuButton);
// bottom buttons
mBottomRepeatButton = findViewById(R.id.now_playing_bottomRepeatButton);
mBottomPreviousButton = findViewById(R.id.now_playing_bottomPreviousButton);
mBottomPlayPauseButton = findViewById(R.id.now_playing_bottomPlayPauseButton);
mBottomStopButton = findViewById(R.id.now_playing_bottomStopButton);
mBottomNextButton = findViewById(R.id.now_playing_bottomNextButton);
mBottomRandomButton = findViewById(R.id.now_playing_bottomRandomButton);
// Main cover image
mCoverImage = findViewById(R.id.now_playing_cover);
// Small header cover image
mTopCoverImage = findViewById(R.id.now_playing_topCover);
// View with the ListView of the playlist
mPlaylistView = findViewById(R.id.now_playing_playlist);
// view switcher for cover and playlist view
mViewSwitcher = findViewById(R.id.now_playing_view_switcher);
// Button container for the buttons shown if dragged up
mDraggedUpButtons = findViewById(R.id.now_playing_layout_dragged_up);
// Button container for the buttons shown if dragged down
mDraggedDownButtons = findViewById(R.id.now_playing_layout_dragged_down);
// textviews
mTrackName = findViewById(R.id.now_playing_trackName);
// For marquee scrolling the TextView need selected == true
mTrackName.setSelected(true);
mTrackAdditionalInfo = findViewById(R.id.now_playing_track_additional_info);
// For marquee scrolling the TextView need selected == true
mTrackAdditionalInfo.setSelected(true);
mTrackNo = findViewById(R.id.now_playing_text_track_no);
mPlaylistNo = findViewById(R.id.now_playing_text_playlist_no);
mBitrate = findViewById(R.id.now_playing_text_bitrate);
mAudioProperties = findViewById(R.id.now_playing_text_audio_properties);
mTrackURI = findViewById(R.id.now_playing_text_track_uri);
// Textviews directly under the seekbar
mElapsedTime = findViewById(R.id.now_playing_elapsedTime);
mDuration = findViewById(R.id.now_playing_duration);
mHeaderTextLayout = findViewById(R.id.now_playing_header_textLayout);
// seekbar (position)
mPositionSeekbar = findViewById(R.id.now_playing_seekBar);
mPositionSeekbar.setOnSeekBarChangeListener(new PositionSeekbarListener());
mVolumeSeekbar = findViewById(R.id.volume_seekbar);
mVolumeIcon = findViewById(R.id.volume_icon);
mVolumeIcon.setOnClickListener(view -> MPDCommandHandler.setVolume(0));
mVolumeIcon.setOnLongClickListener(view -> {
MPDQueryHandler.getOutputs(new OutputResponseMenuHandler(getContext(), view));
return true;
});
mVolumeSeekbar.setMax(100);
mVolumeSeekbar.setOnSeekBarChangeListener(new VolumeSeekBarListener());
/* Volume control buttons */
mVolumeIconButtons = findViewById(R.id.volume_icon_buttons);
mVolumeIconButtons.setOnClickListener(view -> MPDCommandHandler.setVolume(0));
mVolumeIconButtons.setOnLongClickListener(view -> {
MPDQueryHandler.getOutputs(new OutputResponseMenuHandler(getContext(), view));
return true;
});
mVolumeText = findViewById(R.id.volume_button_text);
mVolumeMinus = findViewById(R.id.volume_button_minus);
mVolumeMinus.setOnClickListener(v -> MPDCommandHandler.decreaseVolume(mVolumeStepSize));
mVolumePlus = findViewById(R.id.volume_button_plus);
mVolumePlus.setOnClickListener(v -> MPDCommandHandler.increaseVolume(mVolumeStepSize));
/* Create two listeners that start a repeating timer task to repeat the volume plus/minus action */
mPlusListener = new VolumeButtonLongClickListener(VolumeButtonLongClickListener.LISTENER_ACTION.VOLUME_UP, mVolumeStepSize);
mMinusListener = new VolumeButtonLongClickListener(VolumeButtonLongClickListener.LISTENER_ACTION.VOLUME_DOWN, mVolumeStepSize);
/* Set the listener to the plus/minus button */
mVolumeMinus.setOnLongClickListener(mMinusListener);
mVolumeMinus.setOnTouchListener(mMinusListener);
mVolumePlus.setOnLongClickListener(mPlusListener);
mVolumePlus.setOnTouchListener(mPlusListener);
mVolumeSeekbarLayout = findViewById(R.id.volume_seekbar_layout);
mVolumeButtonLayout = findViewById(R.id.volume_button_layout);
// set dragging part default to bottom
mDragOffset = 1.0f;
mDraggedUpButtons.setVisibility(INVISIBLE);
mDraggedDownButtons.setVisibility(VISIBLE);
mDraggedUpButtons.setAlpha(0.0f);
// add listener to top playpause button
mTopPlayPauseButton.setOnClickListener(arg0 -> MPDCommandHandler.togglePause());
// Add listeners to top playlist button
mTopPlaylistButton.setOnClickListener(v -> {
// get color for playlist button
int color;
if (mViewSwitcher.getCurrentView() != mPlaylistView) {
color = ThemeUtils.getThemeColor(getContext(), R.attr.colorAccent);
} else {
color = ThemeUtils.getThemeColor(getContext(), R.attr.malp_color_text_accent);
}
// tint the button
mTopPlaylistButton.setImageTintList(ColorStateList.valueOf(color));
// toggle between cover and playlistview
mViewSwitcher.showNext();
// report the change of the view
if (mDragStatusReceiver != null) {
// set view status
if (mViewSwitcher.getDisplayedChild() == 0) {
// cover image is shown
mDragStatusReceiver.onSwitchedViews(NowPlayingDragStatusReceiver.VIEW_SWITCHER_STATUS.COVER_VIEW);
} else {
// playlist view is shown
mDragStatusReceiver.onSwitchedViews(NowPlayingDragStatusReceiver.VIEW_SWITCHER_STATUS.PLAYLIST_VIEW);
mPlaylistView.jumpToCurrentSong();
}
}
});
// Add listener to top menu button
mTopMenuButton.setOnClickListener(this::showAdditionalOptionsMenu);
// Add listener to bottom repeat button
mBottomRepeatButton.setOnClickListener(arg0 -> {
if (null != mLastStatus) {
if (mLastStatus.getRepeat() == 0) {
MPDCommandHandler.setRepeat(true);
} else {
MPDCommandHandler.setRepeat(false);
}
}
});
// Add listener to bottom previous button
mBottomPreviousButton.setOnClickListener(arg0 -> MPDCommandHandler.previousSong());
// Add listener to bottom playpause button
mBottomPlayPauseButton.setOnClickListener(arg0 -> MPDCommandHandler.togglePause());
mBottomStopButton.setOnClickListener(view -> MPDCommandHandler.stop());
// Add listener to bottom next button
mBottomNextButton.setOnClickListener(arg0 -> MPDCommandHandler.nextSong());
// Add listener to bottom random button
mBottomRandomButton.setOnClickListener(arg0 -> {
if (null != mLastStatus) {
if (mLastStatus.getRandom() == 0) {
MPDCommandHandler.setRandom(true);
} else {
MPDCommandHandler.setRandom(false);
}
}
});
mCoverImage.setOnClickListener(v -> {
Intent intent = new Intent(getContext(), FanartActivity.class);
getContext().startActivity(intent);
});
mCoverImage.setVisibility(INVISIBLE);
mCoverLoader = new CoverBitmapLoader(getContext(), new CoverReceiverClass());
}
use of org.gateshipone.malp.application.utils.CoverBitmapLoader in project malp by gateship-one.
the class WidgetProvider method onReceive.
/**
* This is the broadcast receiver for NowPlayingInformation objects sent by the PBS
*
* @param context Context used for this receiver
* @param intent Intent containing the NowPlayingInformation as a payload.
*/
@Override
public void onReceive(Context context, Intent intent) {
super.onReceive(context, intent);
// Type checks
if (intent.getAction().equals(BackgroundService.ACTION_STATUS_CHANGED)) {
// Extract the payload from the intent
MPDCurrentStatus status = intent.getParcelableExtra(BackgroundService.INTENT_EXTRA_STATUS);
// Check if a payload was sent
if (null != status) {
// Save the information for later usage (when the asynchronous bitmap loader finishes)
mLastStatus = status;
}
} else if (intent.getAction().equals(BackgroundService.ACTION_TRACK_CHANGED)) {
// Extract the payload from the intent
MPDTrack track = intent.getParcelableExtra(BackgroundService.INTENT_EXTRA_TRACK);
// Check if a payload was sent
if (null != track) {
boolean newImage = false;
// Check if new album is played and remove image if it is.
if (mLastTrack == null || !track.getTrackAlbum().equals(mLastTrack.getTrackAlbum()) || !track.getTrackAlbumMBID().equals(mLastTrack.getTrackAlbumMBID())) {
mLastCover = null;
newImage = true;
}
// Save the information for later usage (when the asynchronous bitmap loader finishes)
mLastTrack = track;
if (newImage) {
CoverBitmapLoader coverLoader = new CoverBitmapLoader(context, new CoverReceiver(context, this));
coverLoader.getImage(track, false, -1, -1);
}
}
} else if (intent.getAction().equals(BackgroundService.ACTION_SERVER_DISCONNECTED)) {
mLastStatus = null;
mLastTrack = null;
} else if (intent.getAction().equals(ArtworkManager.ACTION_NEW_ARTWORK_READY)) {
// Check if the new artwork matches the currently playing track. If so reload artwork
if (mLastTrack != null && mLastTrack.getTrackAlbum().equals(intent.getStringExtra(ArtworkManager.INTENT_EXTRA_KEY_ALBUM_NAME))) {
// Got new artwork
mLastCover = null;
CoverBitmapLoader coverLoader = new CoverBitmapLoader(context, new CoverReceiver(context, this));
coverLoader.getImage(mLastTrack, false, -1, -1);
}
}
// Refresh the widget with the new information
updateWidget(context);
}
Aggregations