示例#1
0
  public void download(final Context context) {

    String album = "*";
    String title = "*";
    String artist = "*";
    if (this instanceof Song) {
      Song song = (Song) this;
      title = song.getName();
      album = song.getAlbum().getName();
      artist = song.getArtist().getName();
    } else if (this instanceof Album) {
      Album a = (Album) this;
      if (a.getArtist().getName().trim().equals("") == false) {
        artist = a.getArtist().getName();
      }
      album = a.getName();
    } else if (this instanceof Artist) {
      Artist a = (Artist) this;
      artist = a.getName();
    }
    SyncTask task = new SyncTask(context, true);
    task.execute(
        "download",
        new BasicNameValuePair("name", title),
        new BasicNameValuePair("album", album),
        new BasicNameValuePair("artist", artist));
  }
 @Override
 public Promise<Integer, Throwable, Void> getAlbumTrackCount(final Album album) {
   Deferred<Integer, Throwable, Void> deferred = new ADeferredObject<>();
   if (mAlbumTracks.get(album) != null) {
     return deferred.resolve(mAlbumTracks.get(album).size());
   }
   return deferred.reject(
       new Throwable("Couldn't find album " + album.getName() + " in collection"));
 }
示例#3
0
 /**
  * @param name
  * @return associated album (case insensitive) or null if no match
  */
 public Album getAlbumByName(String name) {
   Album out = null;
   for (Album album : getAlbums()) {
     if (album.getName().trim().toLowerCase().matches(name.trim().toLowerCase())) {
       out = album;
       break;
     }
   }
   return out;
 }
示例#4
0
      @Override
      public void onClick(View v) {
        // TODO: Check flag
        final Album album = mAlbums.get(getAdapterPosition());
        mCountPhotos = mImageUris.size();
        if (mSendPhoto) {
          mProgressDialog.show();
          for (Uri imageUri : mImageUris) {
            try {
              final Bitmap bitmap =
                  MediaStore.Images.Media.getBitmap(
                      SearchableActivity.this.getContentResolver(), imageUri);

              ByteArrayOutputStream stream = new ByteArrayOutputStream();
              bitmap.compress(Bitmap.CompressFormat.JPEG, 20, stream);
              final byte[] data = stream.toByteArray();

              ParseFile file = new ParseFile("teste.jpg", data);

              file.saveInBackground(
                  new SaveCallback() {
                    public void done(ParseException e) {
                      // Handle success or failure here ...
                      mCountPhotos--;
                      if (mCountPhotos == 0) {
                        mProgressDialog.dismiss();
                      }
                    }
                  },
                  new ProgressCallback() {
                    public void done(Integer percentDone) {
                      // Update your progress spinner here. percentDone will be between 0 and 100.
                    }
                  });

              Photo photo = new Photo();
              photo.setImage(file);
              photo.setAlbum(album);
              photo.setAuthor(ParseUser.getCurrentUser());
              photo.saveInBackground();

            } catch (IOException e) {
              e.printStackTrace();
            }
            mSendPhoto = false;
          }

        } else {
          Intent intent = new Intent(SearchableActivity.this, AlbumDetailActivity.class);
          intent.putExtra(AlbumDetailActivity.ALBUM_ID_EXTRA, album.getObjectId());
          intent.putExtra(AlbumDetailActivity.ALBUM_NAME_EXTRA, album.getName());
          startActivity(intent);
        }
      }
示例#5
0
 /**
  * Gets the album by name.
  *
  * @param name DOCUMENT_ME
  * @return associated album (case insensitive) or null if no match
  */
 public Album getAlbumByName(String name) {
   Album out = null;
   for (ReadOnlyIterator<Album> it = getAlbumsIterator(); it.hasNext(); ) {
     Album album = it.next();
     if (album.getName().equalsIgnoreCase(name)) {
       out = album;
       break;
     }
   }
   return out;
 }
示例#6
0
  private List<Album> filter(List<Album> albums, String query) {
    query = query.toLowerCase();

    final List<Album> filteredAlbumsList = new ArrayList<>();
    for (Album album : albums) {
      final String text = album.getName().toLowerCase();
      if (text.contains(query)) {
        filteredAlbumsList.add(album);
      }
    }
    return filteredAlbumsList;
  }
示例#7
0
文件: Music.java 项目: hurzl/dmix
  /**
   * Adds metadata from the current track to a {@code MediaMetadata.Builder} object.
   *
   * @param metadata The constructed {@code MediaMetadata.Builder} object to add the current track
   *     metadata to.
   */
  @TargetApi(Build.VERSION_CODES.LOLLIPOP)
  public void getMediaMetadata(final MediaMetadata.Builder metadata) {
    final Album album = getAlbum();

    metadata
        .putLong(MediaMetadata.METADATA_KEY_DISC_NUMBER, (long) getDisc())
        .putLong(MediaMetadata.METADATA_KEY_DURATION, getTime())
        .putLong(MediaMetadata.METADATA_KEY_NUM_TRACKS, (long) getTotalTracks())
        .putLong(MediaMetadata.METADATA_KEY_TRACK_NUMBER, (long) getTrack())
        .putLong(MediaMetadata.METADATA_KEY_YEAR, album.getDate())
        .putString(MediaMetadata.METADATA_KEY_ALBUM, album.getName())
        .putString(MediaMetadata.METADATA_KEY_ALBUM_ARTIST, getAlbumArtistName())
        .putString(MediaMetadata.METADATA_KEY_ARTIST, getArtistName())
        .putString(MediaMetadata.METADATA_KEY_COMPOSER, getComposerName())
        .putString(MediaMetadata.METADATA_KEY_DATE, Long.toString(getDate()))
        .putString(MediaMetadata.METADATA_KEY_TITLE, getTitle());

    putResponseObject(metadata, MediaMetadata.METADATA_KEY_GENRE, getGenres());
  }
示例#8
0
  public void tagList(final Context context) {

    String album = "*";
    String title = "*";
    String artist = "*";
    if (this instanceof Song) {
      Song song = (Song) this;
      title = song.getName();
      album = song.getAlbum().getName();
      artist = song.getArtist().getName();
    } else if (this instanceof Album) {
      Album a = (Album) this;
      if (a.getArtist().getName().trim().equals("") == false) {
        artist = a.getArtist().getName();
      }
      album = a.getName();
    } else if (this instanceof Artist) {
      Artist a = (Artist) this;
      artist = a.getName();
    }
    showTagListDialog(context, title, album, artist);
  }
  @Test
  public void testModifyAlbum() throws Exception {
    Album album = new Album(TEST_ALBUM_NAME, TEST_ALBUM_DESCRIPTION);
    album.modifyUser(user);
    Album createdAlbum = repository.create(album);

    // Execute
    String modifiedName = "Modified Name";
    String modifiedDescription = "Modified Description";
    createdAlbum.setName(modifiedName);
    createdAlbum.setDescription(modifiedDescription);

    Album modifiedAlbum = repository.modify(createdAlbum);

    // Verify
    em.flush();
    em.clear();
    Album actualAlbum = em.find(Album.class, modifiedAlbum.getAlbumId());
    assertEquals(modifiedAlbum, actualAlbum);
    assertEquals(modifiedName, actualAlbum.getName());
    assertEquals(modifiedDescription, actualAlbum.getDescription());
    assertNull(actualAlbum.getCoverPhoto());
  }
示例#10
0
    @Override
    public void onBindViewHolder(final ViewHolder holder, int position) {
      final Album album = mAlbums.get(position);

      holder.mAlbumNameView.setText(album.getName());

      String facebookId = null;
      try {
        facebookId = album.getAuthor().fetchIfNeeded().getString("facebookId");

        ParseQuery<Photo> query = ParseQuery.getQuery(Photo.class);
        query.whereEqualTo("originAlbum", album);
        query.findInBackground(
            new FindCallback<Photo>() {
              public void done(List<Photo> scoreList, ParseException e) {
                if (e == null) {
                  if (!scoreList.isEmpty()) {
                    int width = holder.mThumbnailView.getWidth();
                    int height = holder.mThumbnailView.getHeight();
                    mBitmapDownloader.queueUrl(
                        holder.mThumbnailView,
                        scoreList.get(0).getImage().getUrl(),
                        new Size(width, height));
                  }
                } else {
                  e.printStackTrace();
                }
              }
            });

        AccessToken accessToken = AccessToken.getCurrentAccessToken();
        GraphRequest request =
            GraphRequest.newGraphPathRequest(
                accessToken,
                "/" + facebookId,
                new GraphRequest.Callback() {
                  @Override
                  public void onCompleted(GraphResponse response) {
                    JSONObject result = response.getJSONObject();
                    try {
                      String name = result.getString("name");
                      String pictureUrl =
                          result.getJSONObject("picture").getJSONObject("data").getString("url");
                      holder.mAuthorNameView.setText(name);
                      holder.mNumberCollaboratorsView.setText(
                          String.valueOf(album.getNumberOfCollaborators()));

                      int width = holder.mAuthorPictureView.getWidth();
                      int height = holder.mAuthorPictureView.getHeight();

                      mBitmapDownloader.queueUrl(
                          holder.mAuthorPictureView, pictureUrl, new Size(width, height));
                    } catch (JSONException e) {
                      e.printStackTrace();
                    }
                  }
                });

        Bundle parameters = new Bundle();
        parameters.putString("fields", "name,picture");
        request.setParameters(parameters);
        request.executeAsync();
      } catch (ParseException e) {
        e.printStackTrace();
      }
    }
示例#11
-1
  public void edit(final Context context) {

    String album = "*";
    String title = "*";
    String artist = "*";
    String editable = "";
    String typeName = "";
    if (this instanceof Song) {
      Song song = (Song) this;
      title = song.getName();
      album = song.getAlbum().getName();
      artist = song.getArtist().getName();
      editable = title;
      typeName = "track";
    } else if (this instanceof Album) {
      Album a = (Album) this;
      if (a.getArtist().getName().trim().equals("") == false) {
        artist = a.getArtist().getName();
      }
      album = a.getName();
      editable = album;
      typeName = "album";
    } else if (this instanceof Artist) {
      Artist a = (Artist) this;
      artist = a.getName();
      editable = artist;
      typeName = "artist";
    }
    showEditDialog(context, typeName, editable, title, album, artist);
  }