Search in sources :

Example 1 with HowaboutApplication

use of io.recom.howabout.HowaboutApplication in project howabout-android by recomio.

the class MusicPlaylistActivity method onStart.

@Override
public void onStart() {
    super.onStart();
    HowaboutApplication application = (HowaboutApplication) getApplication();
    final int currentPosition = application.getPlaylistAdapter().getCurrentPosition();
    if (currentPosition >= 0) {
        listView.post(new Runnable() {

            @Override
            public void run() {
                listView.setSelection(currentPosition);
            }
        });
    }
}
Also used : HowaboutApplication(io.recom.howabout.HowaboutApplication)

Example 2 with HowaboutApplication

use of io.recom.howabout.HowaboutApplication in project howabout-android by recomio.

the class MusicPlaylistActivity method onOptionsItemSelected.

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch(item.getItemId()) {
        case android.R.id.home:
            finish();
            return true;
    }
    if (item.getItemId() == R.id.menu_clear) {
        HowaboutApplication application = (HowaboutApplication) getApplication();
        application.getPlaylistAdapter().clear();
        return true;
    }
    return super.onOptionsItemSelected(item);
}
Also used : HowaboutApplication(io.recom.howabout.HowaboutApplication)

Example 3 with HowaboutApplication

use of io.recom.howabout.HowaboutApplication in project howabout-android by recomio.

the class MusicPlaylistActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    imageLoader = ImageLoader.getInstance();
    final ActionBar actionBar = getSupportActionBar();
    actionBar.setDisplayHomeAsUpEnabled(true);
    setAdsContainer(R.id.adView);
    HowaboutApplication application = (HowaboutApplication) getApplication();
    playlistAdapter = application.getPlaylistAdapter();
    if (MusicPlayerService.isLoading()) {
        loadingProgressBar.setVisibility(View.VISIBLE);
        playPauseToggleButton.setVisibility(View.GONE);
    } else {
        if (MusicPlayerService.isPlaying()) {
            playPauseToggleButton.setImageDrawable(pauseIcon);
        } else {
            playPauseToggleButton.setImageDrawable(playIcon);
        }
        loadingProgressBar.setVisibility(View.GONE);
        playPauseToggleButton.setVisibility(View.VISIBLE);
    }
    listView.setAdapter(playlistAdapter);
    playlistAdapter.registerDataSetObserver(new DataSetObserver() {

        @Override
        public void onChanged() {
            try {
                Track track = playlistAdapter.getCurrentItem();
                actionBar.setTitle(track.getTrackTitle());
                actionBar.setSubtitle(track.getArtistName());
                if (MusicPlayerService.isLoading()) {
                    loadingProgressBar.setVisibility(View.VISIBLE);
                    playPauseToggleButton.setVisibility(View.GONE);
                } else {
                    if (MusicPlayerService.isPlaying()) {
                        playPauseToggleButton.setImageDrawable(pauseIcon);
                    } else {
                        playPauseToggleButton.setImageDrawable(playIcon);
                    }
                    loadingProgressBar.setVisibility(View.GONE);
                    playPauseToggleButton.setVisibility(View.VISIBLE);
                }
                imageLoader.displayImage(track.getThumbnailUrl(), songImageView, new ImageLoadingListener() {

                    @Override
                    public void onLoadingStarted(String imageUri, View view) {
                    }

                    @Override
                    public void onLoadingFailed(String imageUri, View view, FailReason failReason) {
                    }

                    @Override
                    public void onLoadingComplete(String imageUri, View view, Bitmap loadedImage) {
                    }

                    @Override
                    public void onLoadingCancelled(String imageUri, View view) {
                    }
                });
                String lyrics = playlistAdapter.getCurrentLyrics();
                if (lyrics == null) {
                    lyricsScrollView.setVisibility(View.GONE);
                    lyricsTextView.setText("");
                } else {
                    lyricsScrollView.setVisibility(View.VISIBLE);
                    lyricsTextView.setText(lyrics);
                }
                listView.invalidate();
            } catch (Exception e) {
            }
        }

        @Override
        public void onInvalidated() {
        }
    });
    playlistAdapter.notifyDataSetChanged();
    listView.setOnItemClickListener(new OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            playlistAdapter.play(position);
            playlistAdapter.notifyDataSetChanged();
        }
    });
    listView.setOnItemLongClickListener(new OnItemLongClickListener() {

        @Override
        public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) {
            playlistAdapter.remove(position);
            return true;
        }
    });
    playPauseToggleButton.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            playlistAdapter.playPauseToggle();
            if (MusicPlayerService.isPlaying()) {
                playPauseToggleButton.setImageDrawable(pauseIcon);
            } else {
                playPauseToggleButton.setImageDrawable(playIcon);
            }
        }
    });
    prevButton.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            playlistAdapter.playPrev();
        }
    });
    nextButton.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            playlistAdapter.playNext();
        }
    });
    UpdateCurrentPositionTask updateCurrentPositionTask = new UpdateCurrentPositionTask();
    updateCurrentPositionTimer.scheduleAtFixedRate(updateCurrentPositionTask, 0, 1000);
}
Also used : ImageLoadingListener(com.nostra13.universalimageloader.core.assist.ImageLoadingListener) OnItemClickListener(android.widget.AdapterView.OnItemClickListener) FailReason(com.nostra13.universalimageloader.core.assist.FailReason) HowaboutApplication(io.recom.howabout.HowaboutApplication) DataSetObserver(android.database.DataSetObserver) ContentView(roboguice.inject.ContentView) ImageView(android.widget.ImageView) View(android.view.View) AdapterView(android.widget.AdapterView) InjectView(roboguice.inject.InjectView) TextView(android.widget.TextView) ScrollView(android.widget.ScrollView) ListView(android.widget.ListView) OnItemLongClickListener(android.widget.AdapterView.OnItemLongClickListener) Bitmap(android.graphics.Bitmap) OnClickListener(android.view.View.OnClickListener) ActionBar(com.actionbarsherlock.app.ActionBar) Track(io.recom.howabout.category.music.model.Track)

Example 4 with HowaboutApplication

use of io.recom.howabout.HowaboutApplication in project howabout-android by recomio.

the class RecommendedTrackListActivity method onOptionsItemSelected.

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    if (item.getTitle().equals(listenString)) {
        HowaboutApplication application = (HowaboutApplication) getApplication();
        Track track = new Track();
        track.setTrackTitle(trackTitle);
        track.setArtistName(artistName);
        track.setThumbnailUrl(thumbnailUrl);
        application.getPlaylistAdapter().play(track);
        return true;
    } else if (item.getTitle().equals(addString)) {
        HowaboutApplication application = (HowaboutApplication) getApplication();
        Track track = new Track();
        track.setTrackTitle(trackTitle);
        track.setArtistName(artistName);
        track.setThumbnailUrl(thumbnailUrl);
        application.getPlaylistAdapter().add(track);
        return true;
    }
    return super.onOptionsItemSelected(item);
}
Also used : HowaboutApplication(io.recom.howabout.HowaboutApplication) Track(io.recom.howabout.category.music.model.Track)

Example 5 with HowaboutApplication

use of io.recom.howabout.HowaboutApplication in project howabout-android by recomio.

the class MusicPlayerService method play.

@SuppressWarnings("deprecation")
private void play(final String trackTitle, final String artistName, String thumbnailUrl) {
    Notification notification = new Notification(R.drawable.ic_launcher, trackTitle + " - " + artistName, System.currentTimeMillis());
    Intent intent = new Intent(this, MusicPlaylistActivity.class);
    intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
    PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent, 0);
    notification.setLatestEventInfo(this, trackTitle, artistName, pendingIntent);
    notification.flags |= Notification.FLAG_NO_CLEAR;
    notification.flags |= Notification.FLAG_ONGOING_EVENT;
    startForeground(NOTIFICATION_ID, notification);
    playlistAdapter.setCurrentLyrics("");
    isLoaded = false;
    isLoading = true;
    mediaPlayer.stop();
    mediaPlayer.reset();
    if (playInfoRequest != null) {
        contentManager.cancel(playInfoRequest);
        playInfoRequest = null;
    }
    playInfoRequest = new PlayInfoRequest(trackTitle, artistName);
    contentManager.execute(playInfoRequest, new RequestListener<PlayInfo>() {

        @Override
        public void onRequestFailure(SpiceException e) {
            if (groovesharkStreamUrlGetter != null) {
                groovesharkStreamUrlGetter.isStopped(true);
            }
            if (e instanceof RequestCancelledException) {
                return;
            }
            isLoading = false;
            playlistAdapter.playNext();
            playlistAdapter.notifyDataSetChanged();
            Toast.makeText(MusicPlayerService.this, trackTitle + "(" + artistName + ")" + "\n 무료 스트리밍 음원을 찾지 못했습니다.", Toast.LENGTH_SHORT).show();
        }

        @Override
        public void onRequestSuccess(final PlayInfo playInfo) {
            playlistAdapter.setCurrentLyrics(playInfo.getLyrics());
            Log.i("grooveshark", playInfo.getTrackTitle());
            final String groovesharkSongId = playInfo.getTinysongId();
            if (groovesharkSongId != null) {
                HowaboutApplication application = (HowaboutApplication) getApplicationContext();
                try {
                    groovesharkStreamUrlGetter = new GroovesharkStreamUrlGetter(application, groovesharkSongId, new OnGetGroovesharkStreamKey() {

                        @Override
                        public void sucess(String streamUrl) {
                            playInfo.setGroovesharkSongID(groovesharkSongId);
                            playInfo.setGroovesharkStreamUrl(streamUrl);
                            playStream(playInfo);
                        }

                        @Override
                        public void error(Exception e) {
                            playStream(playInfo);
                        }
                    });
                    groovesharkStreamUrlGetter.getGroovesharkStreamUrlAsync();
                } catch (Exception e) {
                    playStream(playInfo);
                }
            } else {
                playStream(playInfo);
            }
        }
    });
}
Also used : GroovesharkStreamUrlGetter(io.recom.howabout.category.music.net.GroovesharkStreamUrlGetter) SpiceException(com.octo.android.robospice.persistence.exception.SpiceException) Intent(android.content.Intent) PendingIntent(android.app.PendingIntent) HowaboutApplication(io.recom.howabout.HowaboutApplication) Notification(android.app.Notification) RequestCancelledException(com.octo.android.robospice.exception.RequestCancelledException) SpiceException(com.octo.android.robospice.persistence.exception.SpiceException) PlayInfo(io.recom.howabout.category.music.model.PlayInfo) PendingIntent(android.app.PendingIntent) RequestCancelledException(com.octo.android.robospice.exception.RequestCancelledException) OnGetGroovesharkStreamKey(io.recom.howabout.category.music.net.GroovesharkStreamUrlGetter.OnGetGroovesharkStreamKey) PlayInfoRequest(io.recom.howabout.category.music.net.PlayInfoRequest)

Aggregations

HowaboutApplication (io.recom.howabout.HowaboutApplication)9 View (android.view.View)4 ImageView (android.widget.ImageView)4 TextView (android.widget.TextView)4 Track (io.recom.howabout.category.music.model.Track)4 Bitmap (android.graphics.Bitmap)3 OnClickListener (android.view.View.OnClickListener)3 FailReason (com.nostra13.universalimageloader.core.assist.FailReason)3 ImageLoadingListener (com.nostra13.universalimageloader.core.assist.ImageLoadingListener)3 Intent (android.content.Intent)2 DataSetObserver (android.database.DataSetObserver)2 MusicPlaylistAdapter (io.recom.howabout.category.music.adapter.MusicPlaylistAdapter)2 Notification (android.app.Notification)1 PendingIntent (android.app.PendingIntent)1 Bundle (android.os.Bundle)1 LayoutInflater (android.view.LayoutInflater)1 AdapterView (android.widget.AdapterView)1 OnItemClickListener (android.widget.AdapterView.OnItemClickListener)1 OnItemLongClickListener (android.widget.AdapterView.OnItemLongClickListener)1 Button (android.widget.Button)1