Android Open Source - audioplayer Widget View






From Project

Back to project page audioplayer.

License

The source code is released under:

GNU General Public License

If you think the Android project audioplayer listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package fr.julien_dumortier.simplemusicplayer.widget;
/* ww w . jav  a 2s . c  o  m*/
import fr.julien_dumortier.simplemusicplayer.MainActivity;
import fr.julien_dumortier.simplemusicplayer.R;
import android.app.PendingIntent;
import android.appwidget.AppWidgetManager;
import android.content.Context;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.Bitmap.Config;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.view.View;
import android.widget.RemoteViews;

public class WidgetView {

  public static final String WIDGET_ID = "widgetId", FUNCTION = "function", 
      INTENT_ON_CLICK_FORMAT = "fr.julien_dumortier.simplemusicplayer.widget.id.%d.click";
  public static final int ACTION_NEXT = 1, ACTION_LAST = 2;
  
  private int mWidgetId;
  private boolean mButtonVisible;
  
  public WidgetView(Context context, int widgetId) {
    mWidgetId = widgetId;
    drawWidget(context, null);
  }
  
  public void drawWidget(Context context, Bitmap bitmap) {
    mButtonVisible = ((AudioPlayerApplication)context.getApplicationContext()).isDisplayable();
    RemoteViews rviews = new RemoteViews(context.getPackageName(), R.layout.audio_player_widget_v2);
    rviews.setOnClickPendingIntent(R.id.fronground_widget, PendingIntent.getActivity(context, 17, new Intent(context, MainActivity.class)
        .setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP), PendingIntent.FLAG_CANCEL_CURRENT));
    if(mButtonVisible) {
      rviews.setViewVisibility(R.id.last_widget, View.VISIBLE);
      rviews.setViewVisibility(R.id.next_widget, View.VISIBLE);
      rviews.setOnClickPendingIntent(R.id.last_widget, prepareIntent(ACTION_LAST, context));
      rviews.setOnClickPendingIntent(R.id.next_widget, prepareIntent(ACTION_NEXT, context));
    } else {
      rviews.setViewVisibility(R.id.last_widget, View.INVISIBLE);
      rviews.setViewVisibility(R.id.next_widget, View.INVISIBLE);
    }
    if(bitmap!=null) {
      try {
        rviews.setImageViewBitmap(R.id.fronground_widget, combineImages(bitmap, BitmapFactory.decodeResource(context.getResources(), R.drawable.frontground_widget)));
      } catch(OutOfMemoryError e) {
        rviews.setImageViewResource(R.id.fronground_widget, R.drawable.frontground_widget);
      }
    }else 
      rviews.setImageViewResource(R.id.fronground_widget, R.drawable.frontground_widget);
    AppWidgetManager.getInstance(context).updateAppWidget(mWidgetId, rviews);
  }
  
  private PendingIntent prepareIntent(int action, Context context) {
    Intent intent = new Intent(String.format(INTENT_ON_CLICK_FORMAT, mWidgetId));
    intent.setClass(context, AudioPlayerWidgetProvider.class);
    intent.putExtra(WIDGET_ID, mWidgetId);
    intent.putExtra(FUNCTION, action);
    return PendingIntent.getBroadcast(context, action, intent, PendingIntent.FLAG_UPDATE_CURRENT);
  }

  public void switchVisibility(Context context, boolean visible, Bitmap bitmap) {
    mButtonVisible = visible;
    drawWidget(context, bitmap);
  }
  
  public Bitmap combineImages(Bitmap cover, Bitmap frontground) throws OutOfMemoryError { // can add a 3rd parameter 'String loc' if you want to save the new image - left some code to do that at the bottom 
      Bitmap bitmap = Bitmap.createBitmap(frontground.getWidth(), frontground.getHeight(), Config.ARGB_8888);
      
          Canvas c = new Canvas(bitmap);
  
  
          Drawable drawable1 = new BitmapDrawable(cover);
          Drawable drawable2 = new BitmapDrawable(frontground);
  
          int marge = getMargin(frontground.getWidth()); //image carr?e, une seule marge
          
          drawable1.setBounds(marge, marge, frontground.getWidth()-marge, frontground.getHeight()-marge);
          drawable2.setBounds(0, 0, frontground.getWidth(), frontground.getHeight());
          drawable1.draw(c);
          drawable2.draw(c);
          return bitmap;
  } 
  
  public int getMargin(int origin) {
    return (int)((origin*9.43f)/100);
  }
}




Java Source Code List

fr.julien_dumortier.simplemusicplayer.DevInfo.java
fr.julien_dumortier.simplemusicplayer.DrawerListAdapter.java
fr.julien_dumortier.simplemusicplayer.IMusicMediaControllerGetter.java
fr.julien_dumortier.simplemusicplayer.MainActivity.java
fr.julien_dumortier.simplemusicplayer.browsemanager.BrowseCover.java
fr.julien_dumortier.simplemusicplayer.browsemanager.BrowseManager.java
fr.julien_dumortier.simplemusicplayer.coveralbumeditor.CoverAlbumEditor.java
fr.julien_dumortier.simplemusicplayer.coveralbumeditor.CoverAlbumGetter.java
fr.julien_dumortier.simplemusicplayer.coveralbumeditor.PromptCovers.java
fr.julien_dumortier.simplemusicplayer.equalizer.EqualizerActivity.java
fr.julien_dumortier.simplemusicplayer.equalizer.EqualizerConfigurationDataBase.java
fr.julien_dumortier.simplemusicplayer.equalizer.VerticalSeekBar.java
fr.julien_dumortier.simplemusicplayer.equalizer.preset.Preset.java
fr.julien_dumortier.simplemusicplayer.item.Album.java
fr.julien_dumortier.simplemusicplayer.item.Artist.java
fr.julien_dumortier.simplemusicplayer.item.Genre.java
fr.julien_dumortier.simplemusicplayer.item.Item.java
fr.julien_dumortier.simplemusicplayer.item.Playlist.java
fr.julien_dumortier.simplemusicplayer.item.Track.java
fr.julien_dumortier.simplemusicplayer.item.itemadapter.AlbumAdapter.java
fr.julien_dumortier.simplemusicplayer.item.itemadapter.ArtistAdapter.java
fr.julien_dumortier.simplemusicplayer.item.itemadapter.CurrentPlayAnimationManager.java
fr.julien_dumortier.simplemusicplayer.item.itemadapter.GenreAdapter.java
fr.julien_dumortier.simplemusicplayer.item.itemadapter.ItemAdapter.java
fr.julien_dumortier.simplemusicplayer.item.itemadapter.ItemClicManager.java
fr.julien_dumortier.simplemusicplayer.item.itemadapter.OrganisableTrackAdapter.java
fr.julien_dumortier.simplemusicplayer.item.itemadapter.PlayListAdapter.java
fr.julien_dumortier.simplemusicplayer.item.itemadapter.TrackAdapter.java
fr.julien_dumortier.simplemusicplayer.notifynews.NotifyNews.java
fr.julien_dumortier.simplemusicplayer.playerview.FullScreenPlayerViewController.java
fr.julien_dumortier.simplemusicplayer.playerview.IPlayerViewController.java
fr.julien_dumortier.simplemusicplayer.playerview.MiniPlayerViewController.java
fr.julien_dumortier.simplemusicplayer.playerview.TimeFormater.java
fr.julien_dumortier.simplemusicplayer.playlistview.MultiSelectManager.java
fr.julien_dumortier.simplemusicplayer.playlistview.PlayListManagerActivity.java
fr.julien_dumortier.simplemusicplayer.playlistview.SaveManagerView.java
fr.julien_dumortier.simplemusicplayer.playlistview.SavedPlaylistManager.java
fr.julien_dumortier.simplemusicplayer.service.BackgroundBinder.java
fr.julien_dumortier.simplemusicplayer.service.MusicPlayerService.java
fr.julien_dumortier.simplemusicplayer.service.bluetoohactionmanager.BluetoothReceiver.java
fr.julien_dumortier.simplemusicplayer.service.notificationplayer.NotificationManagerService.java
fr.julien_dumortier.simplemusicplayer.service.notificationplayer.NotificationPlayer.java
fr.julien_dumortier.simplemusicplayer.service.phonestatemanager.PhoneCallStateManager.java
fr.julien_dumortier.simplemusicplayer.service.playlist.EndOfPlayListException.java
fr.julien_dumortier.simplemusicplayer.service.playlist.IMediaPlayerController.java
fr.julien_dumortier.simplemusicplayer.service.playlist.MusicMediaPlayer.java
fr.julien_dumortier.simplemusicplayer.service.playlist.PlayListManager.java
fr.julien_dumortier.simplemusicplayer.thememanager.ColorPreferences.java
fr.julien_dumortier.simplemusicplayer.thememanager.DisplayManager2.java
fr.julien_dumortier.simplemusicplayer.thememanager.ManageDisplayView.java
fr.julien_dumortier.simplemusicplayer.uiprompt.PromptActionByType.java
fr.julien_dumortier.simplemusicplayer.uiprompt.PromptActionPlaylist.java
fr.julien_dumortier.simplemusicplayer.uiprompt.PromptConfirmAddInNew.java
fr.julien_dumortier.simplemusicplayer.uiprompt.PromptConfirmDeletePlaylist.java
fr.julien_dumortier.simplemusicplayer.uiprompt.PromptConfirmExit.java
fr.julien_dumortier.simplemusicplayer.uiprompt.PromptConfirmReplacePlaylist.java
fr.julien_dumortier.simplemusicplayer.uiprompt.PromptDefineCoverAlbum.java
fr.julien_dumortier.simplemusicplayer.uiprompt.PromptGetTextName.java
fr.julien_dumortier.simplemusicplayer.uiprompt.PromptMoveTrack.java
fr.julien_dumortier.simplemusicplayer.uiprompt.PromptPlaylistName.java
fr.julien_dumortier.simplemusicplayer.uiprompt.PromptShowText.java
fr.julien_dumortier.simplemusicplayer.uiprompt.PromptSuppressConfirm.java
fr.julien_dumortier.simplemusicplayer.widget.AudioPlayerApplication.java
fr.julien_dumortier.simplemusicplayer.widget.AudioPlayerWidgetProvider.java
fr.julien_dumortier.simplemusicplayer.widget.AudioPlayerWidgetViewController.java
fr.julien_dumortier.simplemusicplayer.widget.WidgetView.java