示例#1
1
  /** {@inheritDoc} */
  @Override
  public void onListItemClick(ListView l, View v, int position, long id) {
    final Cursor cursor = (Cursor) mAdapter.getItem(position);
    final String trackId;

    if (cursor != null) {
      trackId = cursor.getString(TracksAdapter.TracksQuery.TRACK_ID);
    } else {
      trackId = CoscupContract.Tracks.ALL_TRACK_ID;
    }

    final Intent intent = new Intent(Intent.ACTION_VIEW);
    final Uri trackUri = CoscupContract.Tracks.buildTrackUri(trackId);
    intent.putExtra(SessionDetailFragment.EXTRA_TRACK, trackUri);

    if (cursor == null) {
      intent.setData(CoscupContract.Sessions.CONTENT_URI);
    } else {
      intent.setData(CoscupContract.Tracks.buildSessionsUri(trackId));
    }

    ((BaseActivity) getActivity()).openActivityOrFragment(intent);

    getListView().setItemChecked(position, true);
  }
示例#2
0
  /** {@inheritDoc} */
  public void onQueryComplete(int token, Object cookie, Cursor cursor) {
    if (getActivity() == null) {
      return;
    }

    getActivity().startManagingCursor(cursor);
    mAdapter.setHasAllItem(true);
    mAdapter.changeCursor(cursor);
  }
示例#3
0
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    mMediaPlayer = new MediaPlayer();
    mMediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
    mMediaPlayer.setOnPreparedListener(
        new MediaPlayer.OnPreparedListener() {
          @Override
          public void onPrepared(MediaPlayer mp) {
            togglePlayPauseState();
          }
        });
    mMediaPlayer.setOnCompletionListener(
        new MediaPlayer.OnCompletionListener() {
          @Override
          public void onCompletion(MediaPlayer mp) {
            mPlayerState.setImageResource(R.drawable.ic_play);
          }
        });

    SoundCloudService service = Soundcloud.getService();
    service.getRecentSongs(
        new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()),
        new Callback<List<Track>>() {
          @Override
          public void success(List<Track> tracks, Response response) {
            getTracks(tracks);
          }

          @Override
          public void failure(RetrofitError error) {}
        });

    RecyclerView recyclerView = (RecyclerView) findViewById(R.id.songs_list);
    recyclerView.setLayoutManager(new LinearLayoutManager(this));
    mTracks = new ArrayList<Track>();
    mAdapter = new TracksAdapter(mTracks, this);
    mAdapter.setmOnItemClickListener(
        new AdapterView.OnItemClickListener() {
          @Override
          public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            Track selectedTrack = mTracks.get(position);
            mCurrentTrackTitle.setText(selectedTrack.getmTitle());
            Picasso.with(MainActivity.this)
                .load(selectedTrack.getArtworkURL())
                .into(mCurrentTrackArtwork);

            if (mMediaPlayer.isPlaying()) {
              mMediaPlayer.stop();
              mMediaPlayer.reset();
            }

            try {
              mMediaPlayer.setDataSource(
                  selectedTrack.getmTrackURL() + "?client_id=" + SoundCloudService.CLIENT_ID);
              mMediaPlayer.prepareAsync();
            } catch (IOException e) {
              e.printStackTrace();
            }

            mSoundcloudLink.setText(selectedTrack.getmLink());
          }
        });
    recyclerView.setAdapter(mAdapter);

    android.support.v7.widget.Toolbar toolbar =
        (android.support.v7.widget.Toolbar) findViewById(R.id.player_toolbar);
    mCurrentTrackTitle = (TextView) findViewById(R.id.current_track_title);
    mCurrentTrackArtwork = (ImageView) findViewById(R.id.current_track_artwork);
    mPlayerState = (ImageView) toolbar.findViewById(R.id.player_state);
    mPlayerState.setOnClickListener(
        new View.OnClickListener() {
          @Override
          public void onClick(View v) {
            togglePlayPauseState();
          }
        });

    Button emailButton = (Button) findViewById(R.id.email_button);
    emailButton.setOnClickListener(
        new View.OnClickListener() {
          @Override
          public void onClick(View v) {
            Context context = getApplicationContext();
            if (!mCurrentTrackTitle.getText().equals("")) {
              Intent sendEmail = new Intent(Intent.ACTION_SEND);
              sendEmail.setData(Uri.parse("mailto:"));
              sendEmail.setType("text/plain");
              sendEmail.putExtra(Intent.EXTRA_SUBJECT, "I want to share a track!");
              sendEmail.putExtra(
                  Intent.EXTRA_TEXT,
                  "I really like this song I found on Soundcloud via my Soundroid App: "
                      + mCurrentTrackTitle.getText()
                      + "\nClick on the link below to listen!\n"
                      + mSoundcloudLink.getText());
              try {
                releaseMediaPlayer();
                startActivity(Intent.createChooser(sendEmail, "Send mail..."));
                finish();
                Toast emailSent = Toast.makeText(context, "Email sent", Toast.LENGTH_SHORT);
              } catch (Exception e) {
                Toast noEmailClient =
                    Toast.makeText(context, "No email client installed", Toast.LENGTH_LONG);
                noEmailClient.show();
              }
            } else {
              Toast noTrackPlayed = Toast.makeText(context, "Play a song!", Toast.LENGTH_SHORT);
              noTrackPlayed.show();
            }
          }
        });
  }
示例#4
0
 private void getTracks(List<Track> tracks) {
   mTracks.clear();
   mTracks.addAll(tracks);
   mAdapter.notifyDataSetChanged();
 }