Removed font onum
This commit is contained in:
parent
9b1e078c20
commit
bed8a7a9ad
32 changed files with 341 additions and 369 deletions
|
@ -15,7 +15,9 @@
|
|||
package code.name.monkey.retromusic.appwidgets
|
||||
|
||||
import android.app.PendingIntent
|
||||
import android.content.*
|
||||
import android.content.ComponentName
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.graphics.Bitmap
|
||||
import android.graphics.drawable.Drawable
|
||||
import android.text.TextUtils
|
||||
|
@ -31,201 +33,201 @@ import code.name.monkey.retromusic.service.MusicService.*
|
|||
import code.name.monkey.retromusic.util.RetroUtil
|
||||
import com.bumptech.glide.Glide
|
||||
import com.bumptech.glide.request.animation.GlideAnimation
|
||||
import com.bumptech.glide.request.target.*
|
||||
import com.bumptech.glide.request.target.SimpleTarget
|
||||
import com.bumptech.glide.request.target.Target
|
||||
|
||||
class AppWidgetBig : BaseAppWidget() {
|
||||
private var target: Target<Bitmap>? = null // for cancellation
|
||||
private var target: Target<Bitmap>? = null // for cancellation
|
||||
|
||||
/**
|
||||
* Initialize given widgets to default state, where we launch Music on default click and hide
|
||||
* actions if service not running.
|
||||
*/
|
||||
override fun defaultAppWidget(context: Context, appWidgetIds: IntArray) {
|
||||
val appWidgetView = RemoteViews(
|
||||
context.packageName, code.name.monkey.retromusic.R.layout.app_widget_big
|
||||
)
|
||||
/**
|
||||
* Initialize given widgets to default state, where we launch Music on default click and hide
|
||||
* actions if service not running.
|
||||
*/
|
||||
override fun defaultAppWidget(context: Context, appWidgetIds: IntArray) {
|
||||
val appWidgetView = RemoteViews(
|
||||
context.packageName, code.name.monkey.retromusic.R.layout.app_widget_big
|
||||
)
|
||||
|
||||
appWidgetView.setViewVisibility(
|
||||
code.name.monkey.retromusic.R.id.media_titles,
|
||||
View.INVISIBLE
|
||||
)
|
||||
appWidgetView.setImageViewResource(R.id.image, R.drawable.default_album_art)
|
||||
appWidgetView.setImageViewBitmap(
|
||||
R.id.button_next, BaseAppWidget.createBitmap(
|
||||
RetroUtil.getTintedVectorDrawable(
|
||||
context,
|
||||
code.name.monkey.retromusic.R.drawable.ic_skip_next_white_24dp,
|
||||
MaterialValueHelper.getPrimaryTextColor(context, false)
|
||||
)!!, 1f
|
||||
)
|
||||
)
|
||||
appWidgetView.setImageViewBitmap(
|
||||
R.id.button_prev, BaseAppWidget.Companion.createBitmap(
|
||||
RetroUtil.getTintedVectorDrawable(
|
||||
context,
|
||||
code.name.monkey.retromusic.R.drawable.ic_skip_previous_white_24dp,
|
||||
MaterialValueHelper.getPrimaryTextColor(context, false)
|
||||
)!!, 1f
|
||||
)
|
||||
)
|
||||
appWidgetView.setImageViewBitmap(
|
||||
R.id.button_toggle_play_pause, BaseAppWidget.Companion.createBitmap(
|
||||
RetroUtil.getTintedVectorDrawable(
|
||||
context,
|
||||
code.name.monkey.retromusic.R.drawable.ic_play_arrow_white_32dp,
|
||||
MaterialValueHelper.getPrimaryTextColor(context, false)
|
||||
)!!, 1f
|
||||
)
|
||||
)
|
||||
appWidgetView.setViewVisibility(
|
||||
code.name.monkey.retromusic.R.id.media_titles,
|
||||
View.INVISIBLE
|
||||
)
|
||||
appWidgetView.setImageViewResource(R.id.image, R.drawable.default_album_art)
|
||||
appWidgetView.setImageViewBitmap(
|
||||
R.id.button_next, BaseAppWidget.createBitmap(
|
||||
RetroUtil.getTintedVectorDrawable(
|
||||
context,
|
||||
code.name.monkey.retromusic.R.drawable.ic_skip_next_white_24dp,
|
||||
MaterialValueHelper.getPrimaryTextColor(context, false)
|
||||
)!!, 1f
|
||||
)
|
||||
)
|
||||
appWidgetView.setImageViewBitmap(
|
||||
R.id.button_prev, BaseAppWidget.Companion.createBitmap(
|
||||
RetroUtil.getTintedVectorDrawable(
|
||||
context,
|
||||
code.name.monkey.retromusic.R.drawable.ic_skip_previous_white_24dp,
|
||||
MaterialValueHelper.getPrimaryTextColor(context, false)
|
||||
)!!, 1f
|
||||
)
|
||||
)
|
||||
appWidgetView.setImageViewBitmap(
|
||||
R.id.button_toggle_play_pause, BaseAppWidget.Companion.createBitmap(
|
||||
RetroUtil.getTintedVectorDrawable(
|
||||
context,
|
||||
code.name.monkey.retromusic.R.drawable.ic_play_arrow_white_32dp,
|
||||
MaterialValueHelper.getPrimaryTextColor(context, false)
|
||||
)!!, 1f
|
||||
)
|
||||
)
|
||||
|
||||
linkButtons(context, appWidgetView)
|
||||
pushUpdate(context, appWidgetIds, appWidgetView)
|
||||
}
|
||||
linkButtons(context, appWidgetView)
|
||||
pushUpdate(context, appWidgetIds, appWidgetView)
|
||||
}
|
||||
|
||||
/**
|
||||
* Update all active widget instances by pushing changes
|
||||
*/
|
||||
override fun performUpdate(service: MusicService, appWidgetIds: IntArray?) {
|
||||
val appWidgetView = RemoteViews(
|
||||
service.packageName, code.name.monkey.retromusic.R.layout.app_widget_big
|
||||
)
|
||||
/**
|
||||
* Update all active widget instances by pushing changes
|
||||
*/
|
||||
override fun performUpdate(service: MusicService, appWidgetIds: IntArray?) {
|
||||
val appWidgetView = RemoteViews(
|
||||
service.packageName, code.name.monkey.retromusic.R.layout.app_widget_big
|
||||
)
|
||||
|
||||
val isPlaying = service.isPlaying
|
||||
val song = service.currentSong
|
||||
val isPlaying = service.isPlaying
|
||||
val song = service.currentSong
|
||||
|
||||
// Set the titles and artwork
|
||||
if (TextUtils.isEmpty(song.title) && TextUtils.isEmpty(song.artistName)) {
|
||||
appWidgetView.setViewVisibility(
|
||||
code.name.monkey.retromusic.R.id.media_titles,
|
||||
View.INVISIBLE
|
||||
)
|
||||
} else {
|
||||
appWidgetView.setViewVisibility(
|
||||
code.name.monkey.retromusic.R.id.media_titles,
|
||||
View.VISIBLE
|
||||
)
|
||||
appWidgetView.setTextViewText(code.name.monkey.retromusic.R.id.title, song.title)
|
||||
appWidgetView.setTextViewText(
|
||||
code.name.monkey.retromusic.R.id.text,
|
||||
getSongArtistAndAlbum(song)
|
||||
)
|
||||
}
|
||||
// Set the titles and artwork
|
||||
if (TextUtils.isEmpty(song.title) && TextUtils.isEmpty(song.artistName)) {
|
||||
appWidgetView.setViewVisibility(
|
||||
code.name.monkey.retromusic.R.id.media_titles,
|
||||
View.INVISIBLE
|
||||
)
|
||||
} else {
|
||||
appWidgetView.setViewVisibility(
|
||||
code.name.monkey.retromusic.R.id.media_titles,
|
||||
View.VISIBLE
|
||||
)
|
||||
appWidgetView.setTextViewText(code.name.monkey.retromusic.R.id.title, song.title)
|
||||
appWidgetView.setTextViewText(
|
||||
code.name.monkey.retromusic.R.id.text,
|
||||
getSongArtistAndAlbum(song)
|
||||
)
|
||||
}
|
||||
|
||||
// Set correct drawable for pause state
|
||||
val playPauseRes = if (isPlaying) code.name.monkey.retromusic.R.drawable.ic_pause_white_24dp else code.name.monkey.retromusic.R.drawable.ic_play_arrow_white_32dp
|
||||
appWidgetView.setImageViewBitmap(
|
||||
R.id.button_toggle_play_pause, BaseAppWidget.createBitmap(
|
||||
RetroUtil.getTintedVectorDrawable(
|
||||
service,
|
||||
playPauseRes,
|
||||
MaterialValueHelper.getPrimaryTextColor(service, false)
|
||||
)!!, 1f
|
||||
)
|
||||
)
|
||||
// Set correct drawable for pause state
|
||||
val playPauseRes = if (isPlaying) code.name.monkey.retromusic.R.drawable.ic_pause_white_24dp else code.name.monkey.retromusic.R.drawable.ic_play_arrow_white_32dp
|
||||
appWidgetView.setImageViewBitmap(
|
||||
R.id.button_toggle_play_pause, BaseAppWidget.createBitmap(
|
||||
RetroUtil.getTintedVectorDrawable(
|
||||
service,
|
||||
playPauseRes,
|
||||
MaterialValueHelper.getPrimaryTextColor(service, false)
|
||||
)!!, 1f
|
||||
)
|
||||
)
|
||||
|
||||
// Set prev/next button drawables
|
||||
appWidgetView.setImageViewBitmap(
|
||||
R.id.button_next, BaseAppWidget.Companion.createBitmap(
|
||||
RetroUtil.getTintedVectorDrawable(
|
||||
service,
|
||||
code.name.monkey.retromusic.R.drawable.ic_skip_next_white_24dp,
|
||||
MaterialValueHelper.getPrimaryTextColor(service, false)
|
||||
)!!, 1f
|
||||
)
|
||||
)
|
||||
appWidgetView.setImageViewBitmap(
|
||||
R.id.button_prev, BaseAppWidget.Companion.createBitmap(
|
||||
RetroUtil.getTintedVectorDrawable(
|
||||
service,
|
||||
code.name.monkey.retromusic.R.drawable.ic_skip_previous_white_24dp,
|
||||
MaterialValueHelper.getPrimaryTextColor(service, false)
|
||||
)!!, 1f
|
||||
)
|
||||
)
|
||||
// Set prev/next button drawables
|
||||
appWidgetView.setImageViewBitmap(
|
||||
R.id.button_next, BaseAppWidget.Companion.createBitmap(
|
||||
RetroUtil.getTintedVectorDrawable(
|
||||
service,
|
||||
code.name.monkey.retromusic.R.drawable.ic_skip_next_white_24dp,
|
||||
MaterialValueHelper.getPrimaryTextColor(service, false)
|
||||
)!!, 1f
|
||||
)
|
||||
)
|
||||
appWidgetView.setImageViewBitmap(
|
||||
R.id.button_prev, BaseAppWidget.Companion.createBitmap(
|
||||
RetroUtil.getTintedVectorDrawable(
|
||||
service,
|
||||
code.name.monkey.retromusic.R.drawable.ic_skip_previous_white_24dp,
|
||||
MaterialValueHelper.getPrimaryTextColor(service, false)
|
||||
)!!, 1f
|
||||
)
|
||||
)
|
||||
|
||||
// Link actions buttons to intents
|
||||
linkButtons(service, appWidgetView)
|
||||
// Link actions buttons to intents
|
||||
linkButtons(service, appWidgetView)
|
||||
|
||||
// Load the album cover async and push the update on completion
|
||||
val p = RetroUtil.getScreenSize(service)
|
||||
val widgetImageSize = Math.min(p.x, p.y)
|
||||
val appContext = service.applicationContext
|
||||
service.runOnUiThread {
|
||||
if (target != null) {
|
||||
Glide.clear(target)
|
||||
}
|
||||
target = SongGlideRequest.Builder.from(Glide.with(appContext), song)
|
||||
.checkIgnoreMediaStore(appContext).asBitmap().build()
|
||||
.into(object : SimpleTarget<Bitmap>(widgetImageSize, widgetImageSize) {
|
||||
override fun onResourceReady(
|
||||
resource: Bitmap,
|
||||
glideAnimation: GlideAnimation<in Bitmap>
|
||||
) {
|
||||
update(resource)
|
||||
}
|
||||
// Load the album cover async and push the update on completion
|
||||
val p = RetroUtil.getScreenSize(service)
|
||||
val widgetImageSize = Math.min(p.x, p.y)
|
||||
val appContext = service.applicationContext
|
||||
service.runOnUiThread {
|
||||
if (target != null) {
|
||||
Glide.clear(target)
|
||||
}
|
||||
target = SongGlideRequest.Builder.from(Glide.with(appContext), song)
|
||||
.checkIgnoreMediaStore(appContext).asBitmap().build()
|
||||
.into(object : SimpleTarget<Bitmap>(widgetImageSize, widgetImageSize) {
|
||||
override fun onResourceReady(
|
||||
resource: Bitmap,
|
||||
glideAnimation: GlideAnimation<in Bitmap>
|
||||
) {
|
||||
update(resource)
|
||||
}
|
||||
|
||||
override fun onLoadFailed(e: Exception?, errorDrawable: Drawable?) {
|
||||
super.onLoadFailed(e, errorDrawable)
|
||||
update(null)
|
||||
}
|
||||
override fun onLoadFailed(e: Exception?, errorDrawable: Drawable?) {
|
||||
super.onLoadFailed(e, errorDrawable)
|
||||
update(null)
|
||||
}
|
||||
|
||||
private fun update(bitmap: Bitmap?) {
|
||||
if (bitmap == null) {
|
||||
appWidgetView.setImageViewResource(
|
||||
R.id.image,
|
||||
R.drawable.default_album_art
|
||||
)
|
||||
} else {
|
||||
appWidgetView.setImageViewBitmap(R.id.image, bitmap)
|
||||
}
|
||||
pushUpdate(appContext, appWidgetIds, appWidgetView)
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
private fun update(bitmap: Bitmap?) {
|
||||
if (bitmap == null) {
|
||||
appWidgetView.setImageViewResource(
|
||||
R.id.image,
|
||||
R.drawable.default_album_art
|
||||
)
|
||||
} else {
|
||||
appWidgetView.setImageViewBitmap(R.id.image, bitmap)
|
||||
}
|
||||
pushUpdate(appContext, appWidgetIds, appWidgetView)
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Link up various button actions using [PendingIntent].
|
||||
*/
|
||||
private fun linkButtons(context: Context, views: RemoteViews) {
|
||||
val action = Intent(context, MainActivity::class.java).putExtra("expand", true)
|
||||
var pendingIntent: PendingIntent
|
||||
/**
|
||||
* Link up various button actions using [PendingIntent].
|
||||
*/
|
||||
private fun linkButtons(context: Context, views: RemoteViews) {
|
||||
val action = Intent(context, MainActivity::class.java).putExtra("expand", true)
|
||||
var pendingIntent: PendingIntent
|
||||
|
||||
val serviceName = ComponentName(context, MusicService::class.java)
|
||||
val serviceName = ComponentName(context, MusicService::class.java)
|
||||
|
||||
// Home
|
||||
action.flags = Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_CLEAR_TOP
|
||||
pendingIntent = PendingIntent.getActivity(context, 0, action, 0)
|
||||
views.setOnClickPendingIntent(R.id.clickable_area, pendingIntent)
|
||||
// Home
|
||||
action.flags = Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_CLEAR_TOP
|
||||
pendingIntent = PendingIntent.getActivity(context, 0, action, 0)
|
||||
views.setOnClickPendingIntent(R.id.clickable_area, pendingIntent)
|
||||
|
||||
// Previous track
|
||||
pendingIntent = buildPendingIntent(context, ACTION_REWIND, serviceName)
|
||||
views.setOnClickPendingIntent(R.id.button_prev, pendingIntent)
|
||||
// Previous track
|
||||
pendingIntent = buildPendingIntent(context, ACTION_REWIND, serviceName)
|
||||
views.setOnClickPendingIntent(R.id.button_prev, pendingIntent)
|
||||
|
||||
// Play and pause
|
||||
pendingIntent = buildPendingIntent(context, ACTION_TOGGLE_PAUSE, serviceName)
|
||||
views.setOnClickPendingIntent(R.id.button_toggle_play_pause, pendingIntent)
|
||||
// Play and pause
|
||||
pendingIntent = buildPendingIntent(context, ACTION_TOGGLE_PAUSE, serviceName)
|
||||
views.setOnClickPendingIntent(R.id.button_toggle_play_pause, pendingIntent)
|
||||
|
||||
// Next track
|
||||
pendingIntent = buildPendingIntent(context, ACTION_SKIP, serviceName)
|
||||
views.setOnClickPendingIntent(R.id.button_next, pendingIntent)
|
||||
// Next track
|
||||
pendingIntent = buildPendingIntent(context, ACTION_SKIP, serviceName)
|
||||
views.setOnClickPendingIntent(R.id.button_next, pendingIntent)
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
companion object {
|
||||
companion object {
|
||||
|
||||
const val NAME: String = "app_widget_big"
|
||||
private var mInstance: AppWidgetBig? = null
|
||||
const val NAME: String = "app_widget_big"
|
||||
private var mInstance: AppWidgetBig? = null
|
||||
|
||||
val instance: AppWidgetBig
|
||||
@Synchronized get() {
|
||||
if (mInstance == null) {
|
||||
mInstance = AppWidgetBig()
|
||||
}
|
||||
return mInstance!!
|
||||
}
|
||||
val instance: AppWidgetBig
|
||||
@Synchronized get() {
|
||||
if (mInstance == null) {
|
||||
mInstance = AppWidgetBig()
|
||||
}
|
||||
return mInstance!!
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -69,7 +69,7 @@ object MusicPlayerRemote {
|
|||
|
||||
val playingQueue: ArrayList<Song>
|
||||
get() = if (musicService != null) {
|
||||
musicService!!.playingQueue
|
||||
musicService?.playingQueue as ArrayList<Song>
|
||||
} else ArrayList()
|
||||
|
||||
val songProgressMillis: Int
|
||||
|
@ -153,11 +153,13 @@ object MusicPlayerRemote {
|
|||
}
|
||||
return null
|
||||
}
|
||||
|
||||
fun getQueueDurationSongs(): Int {
|
||||
return if (musicService != null) {
|
||||
musicService!!.playingQueue.size
|
||||
musicService!!.playingQueue!!.size
|
||||
} else -1
|
||||
}
|
||||
|
||||
/**
|
||||
* Async
|
||||
*/
|
||||
|
|
|
@ -747,12 +747,12 @@ public class MusicService extends Service implements
|
|||
uiThreadHandler.post(runnable);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@NonNull
|
||||
public Song getCurrentSong() {
|
||||
return getSongAt(getPosition());
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@NonNull
|
||||
public Song getSongAt(int position) {
|
||||
if (position >= 0 && getPlayingQueue() != null && position < getPlayingQueue().size()) {
|
||||
return getPlayingQueue().get(position);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue