错误:MainActivity不是抽象的,并且不会覆盖FABProgressListener中的抽象方法onFABProgressAnimationEnd()

时间:2019-02-16 18:11:28

标签: java android

我是android的新手,不知道关于抽象类的错误

我试图找出解决问题的方法,我尝试实施this,但仍然无法正常工作。这是我的源代码。

package com.test.streaming;

import android.app.AlertDialog;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.DialogInterface;
import android.content.Intent;
import android.graphics.drawable.Drawable;
import android.net.Uri;
import android.os.Bundle;
import android.support.design.widget.FloatingActionButton;
import android.support.design.widget.Snackbar;
import android.support.v4.app.NotificationCompat;
import android.view.View;
import android.support.design.widget.NavigationView;
import android.support.v4.view.GravityCompat;
import android.support.v4.widget.DrawerLayout;
import android.support.v7.app.ActionBarDrawerToggle;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.Menu;
import android.view.MenuItem;

// need more lib
import android.media.MediaPlayer;
import android.util.Log;
import android.widget.Button;
import android.widget.ProgressBar;
import android.widget.TextView;

// loading
import com.github.jorgecastilloprz.FABProgressCircle;
import com.github.jorgecastilloprz.listeners.FABProgressListener;

import java.io.IOException;

我认为这是问题所在

public class MainActivity extends AppCompatActivity
        implements NavigationView.OnNavigationItemSelectedListener, View.OnClickListener,  FABProgressListener{

    // Deklarasi variable utama
    // alamat streaming controhnya
    //private String url_radio= "http://usa8-vn.mixstream.net:8138";
    //
    private String url_radio= "http://cloudstreaming.mramedia.com:8000/live";

    private FABProgressCircle fabProgressCircle;
    private ProgressBar playSeekBar;
    private TextView tvRadioUrl;
    private Button buttonPlay;
    private Button buttonStopPlay;
    private MediaPlayer player;




    @Override
    protected void onCreate(Bundle savedInstanceState) {

        fabProgressCircle = (FABProgressCircle) findViewById(R.id.fab);

        /* untuk membuat bar */
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
        setSupportActionBar(toolbar);

        FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
        fab.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG)
                        .setAction("Action", null).show();

                fabProgressCircle.show();
            }
        });

        DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
        ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
                this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
        drawer.addDrawerListener(toggle);
        toggle.syncState();

        NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
        navigationView.setNavigationItemSelectedListener(this);
        /* end untuk membuaat bar */

        // define our radio function
        initializeUIElements();
        initializeMediaPlayer();
    }
    // inisiasi UI ELEMET
    private void initializeUIElements() {

        playSeekBar = (ProgressBar) findViewById(R.id.progressBar1);
        playSeekBar.setMax(100);
        playSeekBar.setVisibility(View.INVISIBLE);
        playSeekBar.setIndeterminate(true);
        buttonPlay = (Button) findViewById(R.id.buttonPlay);
        buttonPlay.setOnClickListener(this);

        buttonStopPlay = (Button) findViewById(R.id.buttonStop);
        buttonStopPlay.setEnabled(false);
        buttonStopPlay.setOnClickListener(this);
        //tvRadioUrl = (TextView) findViewById(R.id.textViewRadioUrl);
        //tvRadioUrl.setText("Radio url : "+url_radio);
    }
    // button onClick
    public void onClick(View v) {
        if (v == buttonPlay) {
            startPlaying();
        } else if (v == buttonStopPlay) {
            stopPlaying();
        }
    }
    private void startPlaying() {
        buttonStopPlay.setEnabled(true);
        buttonPlay.setEnabled(false);

        playSeekBar.setVisibility(View.VISIBLE);

        player.prepareAsync();


        // loading (still not working yet)
//        mImageView = (ImageView) findViewById(R.id.imageLoadingPlayer);
//        Drawable mWaveDrawable = new WaveDrawable(this, R.drawable.ic_launcher_background);
//        // Use as common drawable
//        mImageView.setImageDrawable(mWaveDrawable);
//
//
//        mWaveDrawable.setLevel(1);
//        mWaveDrawable.setLevel(11);
        //mWaveDrawable.setLevel(500);
        // loading

        player.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {

            public void onPrepared(MediaPlayer mp) {

                player.start();
                sendNotif("Grey, LÉON", "Want You Back (feat. LÉON)");
                Log.d("MyDebug", "Notif Sent..");

                //

            }
        });

    }
    private void stopPlaying() {
        Log.d("MyDebug", "Stop Button Pressed.");

        if (player.isPlaying()) {
            player.stop();
            player.release();
            initializeMediaPlayer();
        }

        buttonPlay.setEnabled(true);
        buttonStopPlay.setEnabled(false);
        playSeekBar.setIndeterminate(true);
        playSeekBar.setVisibility(View.INVISIBLE);

    }
    private void initializeMediaPlayer() {
        player = new MediaPlayer();
        Log.d("MyDebug", "initializeMediaPlayer() " );

        try {
            player.setDataSource(url_radio);
        } catch (IllegalArgumentException e) {
            e.printStackTrace();
        } catch (IllegalStateException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }

        Log.d("MyDebug", "stream address set " );



        player.setOnBufferingUpdateListener(new MediaPlayer.OnBufferingUpdateListener() {
            @Override
            public void onBufferingUpdate(MediaPlayer mp, int percent) {
                // percent can be something awkward like "-2147483648" on a live source. Just clamp it.
                if (percent < 0) {
                    percent = 0;
                }
                else if (percent > 100) {
                    percent = 100;
                }

                // debug
                Log.d("MyDebug", "Buffering " + percent);

                playSeekBar.setIndeterminate(false);
                playSeekBar.setSecondaryProgress(100);

            }
        });
    }

    @Override
    protected void onPause() {
        super.onPause();
        if (player.isPlaying()) {
            //  player.stop();
        }
    }

    public void sendNotif(String artist, String song){

        NotificationCompat.Builder builder = new NotificationCompat.Builder(this);
        builder.setSmallIcon(android.R.drawable.ic_dialog_alert);

        Intent intent2 = new Intent(Intent.ACTION_VIEW, Uri.parse("https://www.journaldev.com/"));
        PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent2, 0);
        //HERE ARE YOUR BUTTONS
        builder.addAction(R.drawable.ic_audiotrack_black_24dp, "BUTTON 1",pendingIntent);
        builder.addAction(R.drawable.ic_audiotrack_black_24dp, "BUTTON 2",pendingIntent);
        // Apply the media style template
        //builder.setStyle(new Notification.MediaStyle());
        //        builder.setContentIntent(pendingIntent);


        builder.setContentTitle(artist);
        builder.setContentText(song);
        builder.setSubText("Now Playing");

        NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);

        // Will display the notification in the notification bar
        notificationManager.notify(1, builder.build());


    }

    /* fungsi bawaat template */
    @Override
    public void onBackPressed() {
        DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
        if (drawer.isDrawerOpen(GravityCompat.START)) {
            drawer.closeDrawer(GravityCompat.START);
        } else {
            super.onBackPressed();
        }
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.main, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        // Handle action bar item clicks here. The action bar will
        // automatically handle clicks on the Home/Up button, so long
        // as you specify a parent activity in AndroidManifest.xml.
        int id = item.getItemId();

        //noinspection SimplifiableIfStatement
        if (id == R.id.action_settings) {
            return true;
        }

        return super.onOptionsItemSelected(item);
    }

    @SuppressWarnings("StatementWithEmptyBody")
    @Override
    public boolean onNavigationItemSelected(MenuItem item) {
        // Handle navigation view item clicks here.
        int id = item.getItemId();

        if (id == R.id.nav_streaming) {
            // Handle the camera action
        } else if (id == R.id.nav_share) {

        }

        DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
        drawer.closeDrawer(GravityCompat.START);
        return true;
    }

    @Override
    public void onPointerCaptureChanged(boolean hasCapture) {

    }
}

给出错误:

error: MainActivity is not abstract and does not override abstract method onFABProgressAnimationEnd() in FABProgressListener

1 个答案:

答案 0 :(得分:1)

  

错误:MainActivity不是抽象的,并且不会覆盖抽象   FABProgressListener中的onFABProgressAnimationEnd()方法

=>因为您已经实现了FABProgressListener

public class MainActivity extends AppCompatActivity
        implements NavigationView.OnNavigationItemSelectedListener, View.OnClickListener,  FABProgressListener{

...
...

}

由于MainActivity类不是抽象类,但是您已经实现了FABProgressListner接口,因此您必须重写其所有方法:

public interface FABProgressListener {

  void onFABProgressAnimationEnd();
}

似乎您也是Java领域的新手,如果您仔细阅读库文档,还会得到另一条评论:

@Override public void onFABProgressAnimationEnd() {
    Snackbar.make(fabProgressCircle, R.string.cloud_upload_complete, Snackbar.LENGTH_LONG)
        .setAction("Action", null)
        .show();
}