use of org.moire.ultrasonic.activity.SubsonicTabActivity in project ultrasonic by ultrasonic.
the class FileUtil method getAlbumArtBitmap.
public static Bitmap getAlbumArtBitmap(Context context, MusicDirectory.Entry entry, int size, boolean highQuality) {
if (entry == null)
return null;
File albumArtFile = getAlbumArtFile(context, entry);
SubsonicTabActivity subsonicTabActivity = SubsonicTabActivity.getInstance();
Bitmap bitmap = null;
ImageLoader imageLoader = null;
if (subsonicTabActivity != null) {
imageLoader = subsonicTabActivity.getImageLoader();
if (imageLoader != null) {
bitmap = imageLoader.getImageBitmap(entry, true, size);
}
}
if (bitmap != null) {
return bitmap.copy(bitmap.getConfig(), false);
}
if (albumArtFile != null && albumArtFile.exists()) {
final BitmapFactory.Options opt = new BitmapFactory.Options();
if (size > 0) {
opt.inJustDecodeBounds = true;
BitmapFactory.decodeFile(albumArtFile.getPath(), opt);
if (highQuality) {
opt.inDither = true;
opt.inPreferQualityOverSpeed = true;
}
opt.inPurgeable = true;
opt.inSampleSize = Util.calculateInSampleSize(opt, size, Util.getScaledHeight(opt.outHeight, opt.outWidth, size));
opt.inJustDecodeBounds = false;
}
try {
bitmap = BitmapFactory.decodeFile(albumArtFile.getPath(), opt);
} catch (Exception ex) {
Log.e(TAG, "Exception in BitmapFactory.decodeFile()", ex);
}
Log.i("getAlbumArtBitmap", String.valueOf(size));
if (bitmap != null) {
if (imageLoader != null) {
imageLoader.addImageToCache(bitmap, entry, size);
}
}
return bitmap == null ? null : bitmap;
}
return null;
}
use of org.moire.ultrasonic.activity.SubsonicTabActivity in project ultrasonic by ultrasonic.
the class FileUtil method getAvatarBitmap.
public static Bitmap getAvatarBitmap(String username, int size, boolean highQuality) {
if (username == null)
return null;
File avatarFile = getAvatarFile(username);
SubsonicTabActivity subsonicTabActivity = SubsonicTabActivity.getInstance();
Bitmap bitmap = null;
ImageLoader imageLoader = null;
if (subsonicTabActivity != null) {
imageLoader = subsonicTabActivity.getImageLoader();
if (imageLoader != null) {
bitmap = imageLoader.getImageBitmap(username, size);
}
}
if (bitmap != null) {
return bitmap.copy(bitmap.getConfig(), false);
}
if (avatarFile != null && avatarFile.exists()) {
final BitmapFactory.Options opt = new BitmapFactory.Options();
if (size > 0) {
opt.inJustDecodeBounds = true;
BitmapFactory.decodeFile(avatarFile.getPath(), opt);
if (highQuality) {
opt.inDither = true;
opt.inPreferQualityOverSpeed = true;
}
opt.inPurgeable = true;
opt.inSampleSize = Util.calculateInSampleSize(opt, size, Util.getScaledHeight(opt.outHeight, opt.outWidth, size));
opt.inJustDecodeBounds = false;
}
try {
bitmap = BitmapFactory.decodeFile(avatarFile.getPath(), opt);
} catch (Exception ex) {
Log.e(TAG, "Exception in BitmapFactory.decodeFile()", ex);
}
Log.i("getAvatarBitmap", String.valueOf(size));
if (bitmap != null) {
if (imageLoader != null) {
imageLoader.addImageToCache(bitmap, username, size);
}
}
return bitmap == null ? null : bitmap;
}
return null;
}
use of org.moire.ultrasonic.activity.SubsonicTabActivity in project ultrasonic by ultrasonic.
the class DownloadServiceImpl method setPlayerState.
synchronized void setPlayerState(PlayerState playerState) {
Log.i(TAG, String.format("%s -> %s (%s)", this.playerState.name(), playerState.name(), currentPlaying));
this.playerState = playerState;
if (this.playerState == PAUSED) {
lifecycleSupport.serializeDownloadQueue();
}
if (this.playerState == PlayerState.STARTED) {
Util.requestAudioFocus(this);
}
boolean showWhenPaused = (this.playerState != PlayerState.STOPPED && Util.isNotificationAlwaysEnabled(this));
boolean show = this.playerState == PlayerState.STARTED || showWhenPaused;
Util.broadcastPlaybackStatusChange(this, this.playerState);
Util.broadcastA2dpPlayStatusChange(this, this.playerState, instance);
if (this.playerState == PlayerState.STARTED || this.playerState == PlayerState.PAUSED) {
// Set remote control
updateRemoteControl();
}
// Update widget
UltraSonicAppWidgetProvider4x1.getInstance().notifyChange(this, this, this.playerState == PlayerState.STARTED, false);
UltraSonicAppWidgetProvider4x2.getInstance().notifyChange(this, this, this.playerState == PlayerState.STARTED, true);
UltraSonicAppWidgetProvider4x3.getInstance().notifyChange(this, this, this.playerState == PlayerState.STARTED, false);
UltraSonicAppWidgetProvider4x4.getInstance().notifyChange(this, this, this.playerState == PlayerState.STARTED, false);
SubsonicTabActivity tabInstance = SubsonicTabActivity.getInstance();
if (show) {
if (tabInstance != null) {
// Only update notification is player state is one that will change the icon
if (this.playerState == PlayerState.STARTED || this.playerState == PlayerState.PAUSED) {
if (Util.isNotificationEnabled(this)) {
final NotificationManagerCompat notificationManager = NotificationManagerCompat.from(this);
notificationManager.notify(NOTIFICATION_ID, buildForegroundNotification());
}
tabInstance.showNowPlaying();
}
}
} else {
if (tabInstance != null) {
stopForeground(true);
tabInstance.hideNowPlaying();
}
}
if (this.playerState == STARTED) {
scrobbler.scrobble(this, currentPlaying, false);
} else if (this.playerState == COMPLETED) {
scrobbler.scrobble(this, currentPlaying, true);
}
if (playerState == STARTED && positionCache == null) {
positionCache = new PositionCache();
Thread thread = new Thread(positionCache);
thread.start();
} else if (playerState != STARTED && positionCache != null) {
positionCache.stop();
positionCache = null;
}
}
use of org.moire.ultrasonic.activity.SubsonicTabActivity in project ultrasonic by ultrasonic.
the class DownloadServiceImpl method setCurrentPlaying.
synchronized void setCurrentPlaying(DownloadFile currentPlaying) {
this.currentPlaying = currentPlaying;
if (currentPlaying != null) {
Util.broadcastNewTrackInfo(this, currentPlaying.getSong());
Util.broadcastA2dpMetaDataChange(this, instance);
} else {
Util.broadcastNewTrackInfo(this, null);
Util.broadcastA2dpMetaDataChange(this, null);
}
updateRemoteControl();
// Update widget
UltraSonicAppWidgetProvider4x1.getInstance().notifyChange(this, this, playerState == PlayerState.STARTED, false);
UltraSonicAppWidgetProvider4x2.getInstance().notifyChange(this, this, playerState == PlayerState.STARTED, true);
UltraSonicAppWidgetProvider4x3.getInstance().notifyChange(this, this, playerState == PlayerState.STARTED, false);
UltraSonicAppWidgetProvider4x4.getInstance().notifyChange(this, this, playerState == PlayerState.STARTED, false);
SubsonicTabActivity tabInstance = SubsonicTabActivity.getInstance();
if (currentPlaying != null) {
if (tabInstance != null) {
if (Util.isNotificationEnabled(this)) {
startForeground(NOTIFICATION_ID, buildForegroundNotification());
}
tabInstance.showNowPlaying();
}
} else {
if (tabInstance != null) {
stopForeground(true);
tabInstance.hideNowPlaying();
}
}
}
use of org.moire.ultrasonic.activity.SubsonicTabActivity in project ultrasonic by ultrasonic.
the class SettingsFragment method setImageLoaderConcurrency.
private static void setImageLoaderConcurrency(int concurrency) {
SubsonicTabActivity instance = SubsonicTabActivity.getInstance();
if (instance != null) {
ImageLoader imageLoader = instance.getImageLoader();
if (imageLoader != null) {
imageLoader.stopImageLoader();
imageLoader.setConcurrency(concurrency);
}
}
}
Aggregations