Esempio n. 1
0
 public void fillView(int id) {
   switch (id) {
     case PlaylistsFragment.CREATE_PLAYLIST_BUTTON_ID:
       View v = mRootView.findViewById(R.id.imageview_grid_one);
       if (v != null) {
         v.setVisibility(View.GONE);
       }
       v = mRootView.findViewById(R.id.imageview_grid_two);
       if (v != null) {
         v.setVisibility(View.GONE);
       }
       v = mRootView.findViewById(R.id.imageview_grid_three);
       if (v != null) {
         v.setVisibility(View.GONE);
       }
       TomahawkUtils.ensureInflation(
           mRootView, R.id.imageview_create_playlist_stub, R.id.imageview_create_playlist);
       findViewById(R.id.imageview_create_playlist).setVisibility(View.VISIBLE);
       TextView textView1 = (TextView) findViewById(R.id.textview1);
       textView1.setText(
           TomahawkApp.getContext().getString(R.string.create_playlist).toUpperCase());
       TextView textView2 = (TextView) findViewById(R.id.textview2);
       textView2.setVisibility(View.GONE);
       TextView textView3 = (TextView) findViewById(R.id.textview3);
       textView3.setVisibility(View.GONE);
       break;
   }
 }
 /**
  * Load a {@link android.graphics.Bitmap} asynchronously
  *
  * @param context the context needed for fetching resources
  * @param imageView the {@link android.widget.ImageView}, which will be used to show the {@link
  *     android.graphics.Bitmap}
  * @param image the path to load the image from
  * @param width the width in pixels to scale the image down to
  */
 public static void loadImageIntoImageView(
     Context context,
     ImageView imageView,
     Image image,
     int width,
     boolean fit,
     boolean isArtistImage) {
   int placeHolder =
       isArtistImage ? R.drawable.artist_placeholder_grid : R.drawable.album_placeholder_grid;
   if (image != null && !TextUtils.isEmpty(image.getImagePath())) {
     String imagePath = buildImagePath(image, width);
     RequestCreator creator =
         Picasso.with(context)
             .load(TomahawkUtils.preparePathForPicasso(imagePath))
             .placeholder(placeHolder)
             .error(placeHolder);
     if (fit) {
       creator.resize(width, width);
     }
     creator.into(imageView);
   } else {
     RequestCreator creator =
         Picasso.with(context).load(placeHolder).placeholder(placeHolder).error(placeHolder);
     if (fit) {
       creator.resize(width, width);
     }
     creator.into(imageView);
   }
 }
Esempio n. 3
0
 public void fillView(final Album album, Collection collection) {
   if (collection == null) {
     collection = CollectionManager.getInstance().getCollection(TomahawkApp.PLUGINNAME_HATCHET);
   }
   TextView textView1 = (TextView) findViewById(R.id.textview1);
   textView1.setText(album.getPrettyName());
   TextView textView2 = (TextView) findViewById(R.id.textview2);
   textView2.setText(album.getArtist().getPrettyName());
   ImageView imageView1 = (ImageView) findViewById(R.id.imageview1);
   TomahawkUtils.loadImageIntoImageView(
       TomahawkApp.getContext(), imageView1, album.getImage(), Image.getSmallImageSize(), false);
   final TextView textView3 = (TextView) findViewById(R.id.textview3);
   textView3.setVisibility(View.INVISIBLE);
   collection
       .getAlbumTracks(album)
       .done(
           new DoneCallback<CollectionCursor<Query>>() {
             @Override
             public void onDone(CollectionCursor<Query> cursor) {
               int size = 0;
               if (cursor != null) {
                 size = cursor.size();
                 cursor.close();
               }
               textView3.setVisibility(View.VISIBLE);
               textView3.setText(
                   TomahawkApp.getContext()
                       .getResources()
                       .getQuantityString(R.plurals.songs_with_count, size, size));
             }
           });
 }
Esempio n. 4
0
 public void fillView(Artist artist) {
   TextView textView1 = (TextView) findViewById(R.id.textview1);
   textView1.setText(artist.getPrettyName());
   ImageView imageView1 = (ImageView) findViewById(R.id.imageview1);
   TomahawkUtils.loadImageIntoImageView(
       TomahawkApp.getContext(), imageView1, artist.getImage(), Image.getSmallImageSize(), true);
 }
Esempio n. 5
0
 /**
  * Returns the {@link Artist} with the given id. If none exists in our static {@link
  * ConcurrentHashMap} yet, construct and add it.
  *
  * @return {@link Artist} with the given id
  */
 public static Artist get(String artistName) {
   Artist artist = new Artist(artistName);
   String key = TomahawkUtils.getCacheKey(artist);
   if (!sArtists.containsKey(key)) {
     sArtists.put(key, artist);
   }
   return sArtists.get(key);
 }
Esempio n. 6
0
 /**
  * Add an {@link Album} to this object
  *
  * @param album the {@link Album} to be added
  */
 public void addAlbum(Album album, boolean isLocalAlbum) {
   String key = TomahawkUtils.getCacheKey(album);
   synchronized (this) {
     if (!mAlbums.containsKey(key)) {
       mAlbums.put(key, album);
       if (isLocalAlbum) {
         mLocalAlbums.put(key, album);
       }
     }
   }
 }
 /**
  * Load a {@link android.graphics.Bitmap} asynchronously
  *
  * @param context the context needed for fetching resources
  * @param image the path to load the image from
  * @param target the Target which the loaded image will be pushed to
  * @param width the width in pixels to scale the image down to
  */
 public static void loadImageIntoBitmap(
     Context context, Image image, Target target, int width, boolean isArtistImage) {
   int placeHolder =
       isArtistImage ? R.drawable.artist_placeholder_grid : R.drawable.album_placeholder_grid;
   if (image != null && !TextUtils.isEmpty(image.getImagePath())) {
     String imagePath = buildImagePath(image, width);
     Picasso.with(context)
         .load(TomahawkUtils.preparePathForPicasso(imagePath))
         .resize(width, width)
         .into(target);
   } else {
     Picasso.with(context).load(placeHolder).resize(width, width).into(target);
   }
 }
Esempio n. 8
0
 /** @param query the {@link org.tomahawk.libtomahawk.resolver.Query} to be added */
 public void addQuery(Query query) {
   String key = TomahawkUtils.getCacheKey(query);
   synchronized (this) {
     if (!mQueries.containsKey(key)) {
       mQueries.put(key, query);
       boolean isLocalQuery =
           query.getPreferredTrackResult() != null
               && query.getPreferredTrackResult().getResolvedBy() instanceof DataBaseResolver;
       if (isLocalQuery) {
         mLocalQueries.put(key, query);
       }
     }
   }
 }
Esempio n. 9
0
 public void fillView(User user) {
   TextView textView1 = (TextView) findViewById(R.id.textview1);
   textView1.setText(user.getName());
   if (mLayoutId == R.layout.list_item_user) {
     TextView textView2 = (TextView) findViewById(R.id.textview2);
     textView2.setText(
         TomahawkApp.getContext()
             .getString(
                 R.string.followers_count, user.getFollowersCount(), user.getFollowCount()));
   }
   TextView userTextView1 = (TextView) findViewById(R.id.usertextview1);
   ImageView userImageView1 = (ImageView) findViewById(R.id.userimageview1);
   TomahawkUtils.loadUserImageIntoImageView(
       TomahawkApp.getContext(), userImageView1, user, Image.getSmallImageSize(), userTextView1);
 }
Esempio n. 10
0
 public void fillHeaderView(SocialAction socialAction, int segmentSize) {
   ImageView userImageView1 = (ImageView) findViewById(R.id.userimageview1);
   TextView userTextView = (TextView) findViewById(R.id.usertextview1);
   TomahawkUtils.loadUserImageIntoImageView(
       TomahawkApp.getContext(),
       userImageView1,
       socialAction.getUser(),
       Image.getSmallImageSize(),
       userTextView);
   Object targetObject = socialAction.getTargetObject();
   Resources resources = TomahawkApp.getContext().getResources();
   String userName = socialAction.getUser().getName();
   String phrase =
       "!FIXME! type: "
           + socialAction.getType()
           + ", action: "
           + socialAction.getAction()
           + ", user: "******":");
 }
 /**
  * Load a {@link android.graphics.Bitmap} asynchronously
  *
  * @param context the context needed for fetching resources
  * @param imageView the {@link android.widget.ImageView}, which will be used to show the {@link
  *     android.graphics.Bitmap}
  * @param image the path to load the image from
  * @param width the width in density independent pixels to scale the image down to
  */
 public static void loadBlurredImageIntoImageView(
     Context context, ImageView imageView, Image image, int width, int placeHolderResId) {
   if (image != null && !TextUtils.isEmpty(image.getImagePath())) {
     String imagePath = buildImagePath(image, width);
     RequestCreator creator =
         Picasso.with(context)
             .load(TomahawkUtils.preparePathForPicasso(imagePath))
             .resize(width, width);
     if (placeHolderResId > 0) {
       creator.placeholder(placeHolderResId);
       creator.error(placeHolderResId);
     }
     creator.transform(new BlurTransformation());
     creator.into(imageView);
   } else {
     RequestCreator creator =
         Picasso.with(context)
             .load(placeHolderResId)
             .placeholder(placeHolderResId)
             .error(placeHolderResId);
     creator.into(imageView);
   }
 }
 /**
  * Load a {@link android.graphics.Bitmap} asynchronously
  *
  * @param context the context needed for fetching resources
  * @param image the path to load the image from
  * @param width the width in pixels to scale the image down to
  */
 public static void loadImageIntoNotification(
     Context context,
     Image image,
     RemoteViews remoteViews,
     int viewId,
     int notificationId,
     Notification notification,
     int width,
     boolean isArtistImage) {
   int placeHolder =
       isArtistImage ? R.drawable.artist_placeholder_grid : R.drawable.album_placeholder_grid;
   if (image != null && !TextUtils.isEmpty(image.getImagePath())) {
     String imagePath = buildImagePath(image, width);
     Picasso.with(context)
         .load(TomahawkUtils.preparePathForPicasso(imagePath))
         .resize(width, width)
         .into(remoteViews, viewId, notificationId, notification);
   } else {
     Picasso.with(context)
         .load(placeHolder)
         .resize(width, width)
         .into(remoteViews, viewId, notificationId, notification);
   }
 }
 /**
  * Load a circle-shaped {@link android.graphics.Bitmap} asynchronously
  *
  * @param context the context needed for fetching resources
  * @param imageView the {@link android.widget.ImageView}, which will be used to show the {@link
  *     android.graphics.Bitmap}
  * @param user the user of which to load the data into the views
  * @param width the width in pixels to scale the image down to
  * @param textView the textview which is being used to display the first letter of the user's name
  *     in the placeholder image
  */
 public static void loadUserImageIntoImageView(
     Context context, ImageView imageView, User user, int width, TextView textView) {
   int placeHolder = R.drawable.circle_black;
   if (user.getImage() != null && !TextUtils.isEmpty(user.getImage().getImagePath())) {
     textView.setVisibility(View.GONE);
     String imagePath = buildImagePath(user.getImage(), width);
     Picasso.with(context)
         .load(TomahawkUtils.preparePathForPicasso(imagePath))
         .transform(new CircularImageTransformation())
         .placeholder(placeHolder)
         .error(placeHolder)
         .fit()
         .into(imageView);
   } else {
     textView.setVisibility(View.VISIBLE);
     textView.setText(user.getName().substring(0, 1).toUpperCase());
     Picasso.with(context)
         .load(placeHolder)
         .placeholder(placeHolder)
         .error(placeHolder)
         .fit()
         .into(imageView);
   }
 }
Esempio n. 14
0
  public void fillView(
      Query query,
      String numerationString,
      boolean showAsPlaying,
      View.OnClickListener swipeMenuButton1Listener,
      boolean showAsQueued) {
    TextView trackNameTextView = (TextView) findViewById(R.id.track_textview);
    trackNameTextView.setText(query.getPrettyName());
    setTextViewEnabled(trackNameTextView, query.isPlayable(), false);

    ImageView resolverImageView =
        (ImageView) ensureInflation(R.id.resolver_imageview_stub, R.id.resolver_imageview);
    TextView numerationTextView = (TextView) findViewById(R.id.numeration_textview);
    if (showAsQueued) {
      if (numerationTextView != null) {
        numerationTextView.setVisibility(View.GONE);
      }
      if (resolverImageView != null) {
        resolverImageView.setVisibility(View.VISIBLE);
        TomahawkUtils.loadDrawableIntoImageView(
            TomahawkApp.getContext(), resolverImageView, R.drawable.ic_action_queue_red);
      }
    } else if (showAsPlaying) {
      if (numerationTextView != null) {
        numerationTextView.setVisibility(View.GONE);
      }
      if (resolverImageView != null) {
        resolverImageView.setVisibility(View.VISIBLE);
        if (query.getPreferredTrackResult() != null) {
          Resolver resolver = query.getPreferredTrackResult().getResolvedBy();
          resolver.loadIcon(resolverImageView, false);
        }
      }
    } else if (numerationString != null) {
      if (resolverImageView != null) {
        resolverImageView.setVisibility(View.GONE);
      }
      if (numerationTextView != null) {
        numerationTextView.setVisibility(View.VISIBLE);
        numerationTextView.setText(numerationString);
        setTextViewEnabled(numerationTextView, query.isPlayable(), false);
      }
    }
    if (mLayoutId == R.layout.list_item_numeration_track_artist
        || mLayoutId == R.layout.list_item_track_artist) {
      TextView artistNameTextView = (TextView) findViewById(R.id.artist_textview);
      artistNameTextView.setText(query.getArtist().getPrettyName());
      setTextViewEnabled(artistNameTextView, query.isPlayable(), false);
    }
    if (mLayoutId == R.layout.list_item_numeration_track_duration) {
      TextView durationTextView = (TextView) findViewById(R.id.duration_textview);
      if (query.getPreferredTrack().getDuration() > 0) {
        durationTextView.setText(
            TomahawkUtils.durationToString((query.getPreferredTrack().getDuration())));
      } else {
        durationTextView.setText(PlaybackPanel.COMPLETION_STRING_DEFAULT);
      }
      setTextViewEnabled(durationTextView, query.isPlayable(), false);
    }
    ImageView swipeMenuButton;
    if (showAsQueued) {
      swipeMenuButton =
          (ImageView)
              ensureInflation(R.id.swipe_menu_button_dequeue_stub, R.id.swipe_menu_button_dequeue);
      swipeMenuButton.setVisibility(View.VISIBLE);
      swipeMenuButton.setImageResource(R.drawable.ic_player_exit_light);
      TomahawkUtils.setTint(swipeMenuButton.getDrawable(), R.color.tomahawk_red);
      ImageView swipeMenuButtonEnqueue = (ImageView) findViewById(R.id.swipe_menu_button_enqueue);
      if (swipeMenuButtonEnqueue != null) {
        swipeMenuButtonEnqueue.setVisibility(View.GONE);
      }
    } else {
      swipeMenuButton =
          (ImageView)
              ensureInflation(R.id.swipe_menu_button_enqueue_stub, R.id.swipe_menu_button_enqueue);
      swipeMenuButton.setVisibility(View.VISIBLE);
      ImageView swipeMenuButtonDequeue = (ImageView) findViewById(R.id.swipe_menu_button_dequeue);
      if (swipeMenuButtonDequeue != null) {
        swipeMenuButtonDequeue.setVisibility(View.GONE);
      }
    }
    swipeMenuButton.setOnClickListener(swipeMenuButton1Listener);
  }
Esempio n. 15
0
 public View ensureInflation(int stubResId, int inflatedId) {
   return TomahawkUtils.ensureInflation(mRootView, stubResId, inflatedId);
 }
Esempio n. 16
0
 private static void fillView(
     View view, List<Image> artistImages, int height, boolean isPagerFragment) {
   View v;
   int gridOneResId = isPagerFragment ? R.id.imageview_grid_one_pager : R.id.imageview_grid_one;
   int gridTwoResId = isPagerFragment ? R.id.imageview_grid_two_pager : R.id.imageview_grid_two;
   int gridThreeResId =
       isPagerFragment ? R.id.imageview_grid_three_pager : R.id.imageview_grid_three;
   int gridOneStubId =
       isPagerFragment ? R.id.imageview_grid_one_pager_stub : R.id.imageview_grid_one_stub;
   int gridTwoStubId =
       isPagerFragment ? R.id.imageview_grid_two_pager_stub : R.id.imageview_grid_two_stub;
   int gridThreeStubId =
       isPagerFragment ? R.id.imageview_grid_three_pager_stub : R.id.imageview_grid_three_stub;
   if (artistImages.size() > 2) {
     v = view.findViewById(gridOneResId);
     if (v != null) {
       v.setVisibility(View.GONE);
     }
     v = view.findViewById(gridTwoResId);
     if (v != null) {
       v.setVisibility(View.GONE);
     }
     v = TomahawkUtils.ensureInflation(view, gridThreeStubId, gridThreeResId);
     v.setVisibility(View.VISIBLE);
     TomahawkUtils.loadImageIntoImageView(
         TomahawkApp.getContext(),
         (ImageView) v.findViewById(R.id.imageview1),
         artistImages.get(0),
         Image.getLargeImageSize(),
         false);
     TomahawkUtils.loadImageIntoImageView(
         TomahawkApp.getContext(),
         (ImageView) v.findViewById(R.id.imageview2),
         artistImages.get(1),
         Image.getSmallImageSize(),
         false);
     TomahawkUtils.loadImageIntoImageView(
         TomahawkApp.getContext(),
         (ImageView) v.findViewById(R.id.imageview3),
         artistImages.get(2),
         Image.getSmallImageSize(),
         false);
   } else if (artistImages.size() > 1) {
     v = view.findViewById(gridOneResId);
     if (v != null) {
       v.setVisibility(View.GONE);
     }
     v = view.findViewById(gridThreeResId);
     if (v != null) {
       v.setVisibility(View.GONE);
     }
     v = TomahawkUtils.ensureInflation(view, gridTwoStubId, gridTwoResId);
     v.setVisibility(View.VISIBLE);
     TomahawkUtils.loadImageIntoImageView(
         TomahawkApp.getContext(),
         (ImageView) v.findViewById(R.id.imageview1),
         artistImages.get(0),
         Image.getLargeImageSize(),
         false);
     TomahawkUtils.loadImageIntoImageView(
         TomahawkApp.getContext(),
         (ImageView) v.findViewById(R.id.imageview2),
         artistImages.get(1),
         Image.getSmallImageSize(),
         false);
   } else {
     v = view.findViewById(gridTwoResId);
     if (v != null) {
       v.setVisibility(View.GONE);
     }
     v = view.findViewById(gridThreeResId);
     if (v != null) {
       v.setVisibility(View.GONE);
     }
     v = TomahawkUtils.ensureInflation(view, gridOneStubId, gridOneResId);
     v.setVisibility(View.VISIBLE);
     if (artistImages.size() > 0) {
       TomahawkUtils.loadImageIntoImageView(
           TomahawkApp.getContext(),
           (ImageView) v.findViewById(R.id.imageview1),
           artistImages.get(0),
           Image.getLargeImageSize(),
           false);
     } else {
       TomahawkUtils.loadDrawableIntoImageView(
           TomahawkApp.getContext(),
           (ImageView) v.findViewById(R.id.imageview1),
           R.drawable.album_placeholder_grid);
     }
   }
   if (height > 0) {
     v.getLayoutParams().height = height;
   }
 }