Search in sources :

Example 1 with OutputResponseMenuHandler

use of org.gateshipone.malp.application.utils.OutputResponseMenuHandler 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());
}
Also used : CoverBitmapLoader(org.gateshipone.malp.application.utils.CoverBitmapLoader) Intent(android.content.Intent) OutputResponseMenuHandler(org.gateshipone.malp.application.utils.OutputResponseMenuHandler) VolumeButtonLongClickListener(org.gateshipone.malp.application.utils.VolumeButtonLongClickListener)

Aggregations

Intent (android.content.Intent)1 CoverBitmapLoader (org.gateshipone.malp.application.utils.CoverBitmapLoader)1 OutputResponseMenuHandler (org.gateshipone.malp.application.utils.OutputResponseMenuHandler)1 VolumeButtonLongClickListener (org.gateshipone.malp.application.utils.VolumeButtonLongClickListener)1