aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--res/layout/abstract_fragment_activity.xml3
-rw-r--r--res/layout/album_cell_item.xml3
-rw-r--r--res/layout/album_list_item.xml3
-rw-r--r--res/layout/select_album_header.xml1
-rw-r--r--res/xml/settings.xml6
-rw-r--r--src/github/daneren2005/dsub/activity/SettingsActivity.java20
-rw-r--r--src/github/daneren2005/dsub/fragments/MainFragment.java8
-rw-r--r--src/github/daneren2005/dsub/fragments/NowPlayingFragment.java1
-rw-r--r--src/github/daneren2005/dsub/fragments/SubsonicFragment.java2
-rw-r--r--src/github/daneren2005/dsub/util/FileUtil.java8
-rw-r--r--src/github/daneren2005/dsub/util/ImageLoader.java111
-rw-r--r--src/github/daneren2005/dsub/util/Notifications.java2
-rw-r--r--src/github/daneren2005/dsub/view/SongView.java4
13 files changed, 109 insertions, 63 deletions
diff --git a/res/layout/abstract_fragment_activity.xml b/res/layout/abstract_fragment_activity.xml
index 0702397f..0268ff87 100644
--- a/res/layout/abstract_fragment_activity.xml
+++ b/res/layout/abstract_fragment_activity.xml
@@ -23,8 +23,7 @@
android:layout_width="50dip"
android:layout_height="50dip"
android:layout_gravity="left|center"
- android:scaleType="fitStart"
- android:src="@drawable/unknown_album"/>
+ android:scaleType="fitStart"/>
<LinearLayout
android:layout_width="0dp"
diff --git a/res/layout/album_cell_item.xml b/res/layout/album_cell_item.xml
index 3dd79477..c1c8aa56 100644
--- a/res/layout/album_cell_item.xml
+++ b/res/layout/album_cell_item.xml
@@ -12,8 +12,7 @@
<github.daneren2005.dsub.view.SquareImageView
android:id="@+id/album_coverart"
android:layout_width="match_parent"
- android:layout_height="match_parent"
- android:src="@drawable/unknown_album"/>
+ android:layout_height="match_parent"/>
<RatingBar
android:id="@+id/album_rating"
diff --git a/res/layout/album_list_item.xml b/res/layout/album_list_item.xml
index 27ab3c63..f0d6eb97 100644
--- a/res/layout/album_list_item.xml
+++ b/res/layout/album_list_item.xml
@@ -13,8 +13,7 @@
android:id="@+id/album_coverart"
android:layout_width="@dimen/AlbumArt.Small"
android:layout_height="@dimen/AlbumArt.Small"
- android:layout_gravity="left|center_vertical"
- android:src="@drawable/unknown_album"/>
+ android:layout_gravity="left|center_vertical"/>
<RatingBar
android:id="@+id/album_rating"
diff --git a/res/layout/select_album_header.xml b/res/layout/select_album_header.xml
index a253aa31..8b13ee68 100644
--- a/res/layout/select_album_header.xml
+++ b/res/layout/select_album_header.xml
@@ -6,7 +6,6 @@
<ImageView
android:id="@+id/select_album_art"
- android:src="@drawable/unknown_album"
android:layout_width="@dimen/AlbumArt.Header"
android:layout_height="@dimen/AlbumArt.Header"
android:layout_alignParentTop="true"
diff --git a/res/xml/settings.xml b/res/xml/settings.xml
index 10ea66fe..f22a9c3f 100644
--- a/res/xml/settings.xml
+++ b/res/xml/settings.xml
@@ -215,13 +215,11 @@
<PreferenceCategory
android:title="@string/settings.cache_title">
- <github.daneren2005.dsub.view.SeekBarPreference
+ <EditTextPreference
android:title="@string/settings.cache_size"
android:key="cacheSize"
android:defaultValue="2000"
- android:dialogLayout="@layout/seekbar_preference"
- myns:max="20000"
- myns:display="%.0f MB"/>
+ android:digits="0123456789"/>
<EditTextPreference
android:title="@string/settings.cache_location"
diff --git a/src/github/daneren2005/dsub/activity/SettingsActivity.java b/src/github/daneren2005/dsub/activity/SettingsActivity.java
index 6218dd74..d8a938cd 100644
--- a/src/github/daneren2005/dsub/activity/SettingsActivity.java
+++ b/src/github/daneren2005/dsub/activity/SettingsActivity.java
@@ -60,6 +60,7 @@ import java.lang.reflect.Constructor;
import java.lang.reflect.Method;
import java.net.URL;
import java.security.acl.Group;
+import java.text.DecimalFormat;
import java.util.LinkedHashMap;
import java.util.Locale;
import java.util.Map;
@@ -94,9 +95,11 @@ public class SettingsActivity extends PreferenceActivity implements SharedPrefer
private Preference replayGainUntagged;
private String internalSSID;
private String internalSSIDDisplay;
+ private EditTextPreference cacheSize;
private int serverCount = 3;
private SharedPreferences settings;
+ private DecimalFormat megabyteFromat;
@TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH_MR1)
@Override
@@ -123,7 +126,7 @@ public class SettingsActivity extends PreferenceActivity implements SharedPrefer
tempLoss = (ListPreference) findPreference(Constants.PREFERENCES_KEY_TEMP_LOSS);
pauseDisconnect = (ListPreference) findPreference(Constants.PREFERENCES_KEY_PAUSE_DISCONNECT);
serversCategory = (PreferenceCategory) findPreference(Constants.PREFERENCES_KEY_SERVER_KEY);
- addServerPreference = (Preference) findPreference(Constants.PREFERENCES_KEY_SERVER_ADD);
+ addServerPreference = findPreference(Constants.PREFERENCES_KEY_SERVER_ADD);
videoPlayer = (ListPreference) findPreference(Constants.PREFERENCES_KEY_VIDEO_PLAYER);
syncInterval = (ListPreference) findPreference(Constants.PREFERENCES_KEY_SYNC_INTERVAL);
syncEnabled = (CheckBoxPreference) findPreference(Constants.PREFERENCES_KEY_SYNC_ENABLED);
@@ -133,8 +136,9 @@ public class SettingsActivity extends PreferenceActivity implements SharedPrefer
syncMostRecent = (CheckBoxPreference) findPreference(Constants.PREFERENCES_KEY_SYNC_MOST_RECENT);
replayGain = (CheckBoxPreference) findPreference(Constants.PREFERENCES_KEY_REPLAY_GAIN);
replayGainType = (ListPreference) findPreference(Constants.PREFERENCES_KEY_REPLAY_GAIN_TYPE);
- replayGainBump = (Preference) findPreference(Constants.PREFERENCES_KEY_REPLAY_GAIN_BUMP);
- replayGainUntagged = (Preference) findPreference(Constants.PREFERENCES_KEY_REPLAY_GAIN_UNTAGGED);
+ replayGainBump = findPreference(Constants.PREFERENCES_KEY_REPLAY_GAIN_BUMP);
+ replayGainUntagged = findPreference(Constants.PREFERENCES_KEY_REPLAY_GAIN_UNTAGGED);
+ cacheSize = (EditTextPreference) findPreference(Constants.PREFERENCES_KEY_CACHE_SIZE);
settings = Util.getPreferences(this);
serverCount = settings.getInt(Constants.PREFERENCES_KEY_SERVER_COUNT, 1);
@@ -318,6 +322,16 @@ public class SettingsActivity extends PreferenceActivity implements SharedPrefer
pauseDisconnect.setSummary(pauseDisconnect.getEntry());
videoPlayer.setSummary(videoPlayer.getEntry());
syncInterval.setSummary(syncInterval.getEntry());
+ try {
+ if(megabyteFromat == null) {
+ megabyteFromat = new DecimalFormat(getResources().getString(R.string.util_bytes_format_megabyte));
+ }
+
+ cacheSize.setSummary(megabyteFromat.format((double) Integer.parseInt(cacheSize.getText())).replace(".00", ""));
+ } catch(Exception e) {
+ Log.e(TAG, "Failed to format cache size", e);
+ cacheSize.setSummary(cacheSize.getText());
+ }
if(syncEnabled.isChecked()) {
if(!syncInterval.isEnabled()) {
syncInterval.setEnabled(true);
diff --git a/src/github/daneren2005/dsub/fragments/MainFragment.java b/src/github/daneren2005/dsub/fragments/MainFragment.java
index 403bad03..f6f7875c 100644
--- a/src/github/daneren2005/dsub/fragments/MainFragment.java
+++ b/src/github/daneren2005/dsub/fragments/MainFragment.java
@@ -374,10 +374,10 @@ public class MainFragment extends SubsonicFragment {
return getResources().getString(R.string.main_about_text,
context.getPackageManager().getPackageInfo(context.getPackageName(), 0).versionName,
used.getFirst(),
- Util.formatBytes(used.getSecond()),
- Util.formatBytes(Util.getCacheSizeMB(context) * 1024L * 1024L),
- Util.formatBytes(bytesAvailableFs),
- Util.formatBytes(bytesTotalFs));
+ Util.formatLocalizedBytes(used.getSecond(), context),
+ Util.formatLocalizedBytes(Util.getCacheSizeMB(context) * 1024L * 1024L, context),
+ Util.formatLocalizedBytes(bytesAvailableFs, context),
+ Util.formatLocalizedBytes(bytesTotalFs, context));
}
@Override
diff --git a/src/github/daneren2005/dsub/fragments/NowPlayingFragment.java b/src/github/daneren2005/dsub/fragments/NowPlayingFragment.java
index ce5b1281..942b0613 100644
--- a/src/github/daneren2005/dsub/fragments/NowPlayingFragment.java
+++ b/src/github/daneren2005/dsub/fragments/NowPlayingFragment.java
@@ -1023,6 +1023,7 @@ public class NowPlayingFragment extends SubsonicFragment implements OnGestureLis
public void onStopTrackingTouch(SeekBar seekBar) {
}
});
+ lengthBar.setProgress(length);
AlertDialog.Builder builder = new AlertDialog.Builder(context);
builder.setTitle(R.string.menu_set_timer)
diff --git a/src/github/daneren2005/dsub/fragments/SubsonicFragment.java b/src/github/daneren2005/dsub/fragments/SubsonicFragment.java
index 1856cc6a..5cb7c32f 100644
--- a/src/github/daneren2005/dsub/fragments/SubsonicFragment.java
+++ b/src/github/daneren2005/dsub/fragments/SubsonicFragment.java
@@ -1247,7 +1247,7 @@ public class SubsonicFragment extends Fragment implements SwipeRefreshLayout.OnR
msg += "\nCached Bitrate: " + bitrate + " kbps";
}
if(size != 0) {
- msg += "\nSize: " + Util.formatBytes(size);
+ msg += "\nSize: " + Util.formatLocalizedBytes(size, context);
}
if(song.getDuration() != null && song.getDuration() != 0) {
msg += "\nLength: " + Util.formatDuration(song.getDuration());
diff --git a/src/github/daneren2005/dsub/util/FileUtil.java b/src/github/daneren2005/dsub/util/FileUtil.java
index 7afeec93..ac2c080b 100644
--- a/src/github/daneren2005/dsub/util/FileUtil.java
+++ b/src/github/daneren2005/dsub/util/FileUtil.java
@@ -403,7 +403,13 @@ public class FileUtil {
public static File getDefaultMusicDirectory(Context context) {
if(DEFAULT_MUSIC_DIR == null) {
- File[] dirs = ContextCompat.getExternalFilesDirs(context, null);
+ File[] dirs;
+ if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
+ dirs = context.getExternalMediaDirs();
+ } else {
+ dirs = ContextCompat.getExternalFilesDirs(context, null);
+ }
+
for(int i = dirs.length - 1; i >= 0; i--) {
DEFAULT_MUSIC_DIR = new File(dirs[i], "music");
if(dirs[i] != null) {
diff --git a/src/github/daneren2005/dsub/util/ImageLoader.java b/src/github/daneren2005/dsub/util/ImageLoader.java
index ccdb3432..0342b6c9 100644
--- a/src/github/daneren2005/dsub/util/ImageLoader.java
+++ b/src/github/daneren2005/dsub/util/ImageLoader.java
@@ -18,8 +18,15 @@
*/
package github.daneren2005.dsub.util;
+import android.annotation.TargetApi;
import android.content.Context;
import android.graphics.Bitmap;
+import android.graphics.Canvas;
+import android.graphics.Color;
+import android.graphics.LinearGradient;
+import android.graphics.Paint;
+import android.graphics.Rect;
+import android.graphics.Shader;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.graphics.drawable.TransitionDrawable;
@@ -55,7 +62,8 @@ public class ImageLoader {
private final int imageSizeDefault;
private final int imageSizeLarge;
private final int avatarSizeDefault;
- private Drawable largeUnknownImage;
+
+ private final static int[] COLORS = {0xFF33B5E5, 0xFFAA66CC, 0xFF99CC00, 0xFFFFBB33, 0xFFFF4444};
public ImageLoader(Context context) {
this.context = context;
@@ -87,8 +95,6 @@ public class ImageLoader {
DisplayMetrics metrics = context.getResources().getDisplayMetrics();
imageSizeLarge = Math.round(Math.min(metrics.widthPixels, metrics.heightPixels));
avatarSizeDefault = context.getResources().getDrawable(R.drawable.ic_social_person).getIntrinsicHeight();
-
- createLargeUnknownImage(context);
}
public void clearCache() {
@@ -96,18 +102,59 @@ public class ImageLoader {
cache.evictAll();
}
- private void createLargeUnknownImage(Context context) {
- BitmapDrawable drawable = (BitmapDrawable) context.getResources().getDrawable(R.drawable.unknown_album_large);
- Bitmap bitmap = Bitmap.createScaledBitmap(drawable.getBitmap(), imageSizeLarge, imageSizeLarge, true);
- largeUnknownImage = Util.createDrawableFromBitmap(context, bitmap);
+ private Bitmap getUnknownImage(MusicDirectory.Entry entry, int size) {
+ String key;
+ int color;
+ if(entry == null) {
+ key = getKey("unknown", size);
+ color = COLORS[0];
+ } else {
+ key = getKey(entry.getId() + "unknown", size);
+ color = COLORS[Math.abs(entry.getAlbum().hashCode()) % COLORS.length];
+ }
+ Bitmap bitmap = cache.get(key);
+ if(bitmap == null) {
+ bitmap = createUnknownImage(entry, size, color);
+ cache.put(key, bitmap);
+ }
+
+ return bitmap;
+ }
+ private Bitmap createUnknownImage(MusicDirectory.Entry entry, int size, int primaryColor) {
+ Bitmap bitmap = Bitmap.createBitmap(size, size, Bitmap.Config.ARGB_8888);
+ Canvas canvas = new Canvas(bitmap);
+
+ Paint color = new Paint();
+ color.setColor(primaryColor);
+ canvas.drawRect(0, 0, size, size * 2.0f / 3.0f, color);
+
+ color.setShader(new LinearGradient(0, 0, 0, size / 3.0f, Color.rgb(82, 82, 82), Color.BLACK, Shader.TileMode.MIRROR));
+ canvas.drawRect(0, size * 2.0f / 3.0f, size, size, color);
+
+ if(entry != null) {
+ Paint font = new Paint();
+ font.setFlags(Paint.ANTI_ALIAS_FLAG);
+ font.setColor(Color.WHITE);
+ font.setTextSize(3.0f + size * 0.07f);
+
+ if(entry.getAlbum() != null) {
+ canvas.drawText(entry.getAlbum(), size * 0.05f, size * 0.6f, font);
+ }
+
+ if(entry.getArtist() != null) {
+ canvas.drawText(entry.getArtist(), size * 0.05f, size * 0.8f, font);
+ }
+ }
+
+ return bitmap;
}
public Bitmap getCachedImage(Context context, MusicDirectory.Entry entry, boolean large) {
+ int size = large ? imageSizeLarge : imageSizeDefault;
if(entry == null || entry.getCoverArt() == null) {
- return null;
+ return getUnknownImage(entry, size);
}
- int size = large ? imageSizeLarge : imageSizeDefault;
Bitmap bitmap = cache.get(getKey(entry.getCoverArt(), size));
if(bitmap == null || bitmap.isRecycled()) {
bitmap = FileUtil.getAlbumArtBitmap(context, entry, size);
@@ -120,10 +167,6 @@ public class ImageLoader {
}
public ImageTask loadImage(View view, MusicDirectory.Entry entry, boolean large, boolean crossfade) {
- if (largeUnknownImage != null && ((BitmapDrawable)largeUnknownImage).getBitmap().isRecycled()) {
- createLargeUnknownImage(view.getContext());
- }
-
if(entry != null && entry.getCoverArt() == null && entry.isDirectory() && !Util.isOffline(context)) {
// Try to lookup child cover art
MusicDirectory.Entry firstChild = FileUtil.lookupChild(context, entry, true);
@@ -131,13 +174,16 @@ public class ImageLoader {
entry.setCoverArt(firstChild.getCoverArt());
}
}
+
+ Bitmap bitmap;
+ int size = large ? imageSizeLarge : imageSizeDefault;
if (entry == null || entry.getCoverArt() == null) {
- setUnknownImage(view, large);
+ bitmap = getUnknownImage(entry, size);
+ setImage(view, Util.createDrawableFromBitmap(context, bitmap), crossfade);
return null;
}
- int size = large ? imageSizeLarge : imageSizeDefault;
- Bitmap bitmap = cache.get(getKey(entry.getCoverArt(), size));
+ bitmap = cache.get(getKey(entry.getCoverArt(), size));
if (bitmap != null && !bitmap.isRecycled()) {
final Drawable drawable = Util.createDrawableFromBitmap(this.context, bitmap);
setImage(view, drawable, crossfade);
@@ -148,7 +194,7 @@ public class ImageLoader {
}
if (!large) {
- setUnknownImage(view, large);
+ setImage(view, Util.createDrawableFromBitmap(context, null), false);
}
ImageTask task = new ViewImageTask(view.getContext(), entry, size, imageSizeLarge, large, view, crossfade);
task.execute();
@@ -156,23 +202,21 @@ public class ImageLoader {
}
public SilentBackgroundTask<Void> loadImage(Context context, RemoteControlClient remoteControl, MusicDirectory.Entry entry) {
- if (largeUnknownImage != null && ((BitmapDrawable)largeUnknownImage).getBitmap().isRecycled()) {
- createLargeUnknownImage(context);
- }
-
+ Bitmap bitmap;
if (entry == null || entry.getCoverArt() == null) {
- setUnknownImage(remoteControl);
+ bitmap = getUnknownImage(entry, imageSizeLarge);
+ setImage(remoteControl, Util.createDrawableFromBitmap(context, bitmap));
return null;
}
- Bitmap bitmap = cache.get(getKey(entry.getCoverArt(), imageSizeLarge));
+ bitmap = cache.get(getKey(entry.getCoverArt(), imageSizeLarge));
if (bitmap != null && !bitmap.isRecycled()) {
Drawable drawable = Util.createDrawableFromBitmap(this.context, bitmap);
setImage(remoteControl, drawable);
return null;
}
- setUnknownImage(remoteControl);
+ setImage(remoteControl, Util.createDrawableFromBitmap(context, null));
ImageTask task = new RemoteControlClientImageTask(context, entry, imageSizeLarge, imageSizeLarge, false, remoteControl);
task.execute();
return task;
@@ -239,10 +283,11 @@ public class ImageLoader {
}
}
+ @TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH)
private void setImage(RemoteControlClient remoteControl, Drawable drawable) {
if(remoteControl != null && drawable != null) {
Bitmap origBitmap = ((BitmapDrawable)drawable).getBitmap();
- if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) {
+ if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2 && origBitmap != null) {
origBitmap = origBitmap.copy(origBitmap.getConfig(), false);
}
if ( origBitmap != null && !origBitmap.isRecycled()) {
@@ -256,22 +301,6 @@ public class ImageLoader {
}
}
- private void setUnknownImage(View view, boolean large) {
- if (large) {
- setImage(view, largeUnknownImage, false);
- } else {
- if (view instanceof TextView) {
- ((TextView) view).setCompoundDrawablesWithIntrinsicBounds(R.drawable.unknown_album, 0, 0, 0);
- } else if (view instanceof ImageView) {
- ((ImageView) view).setImageResource(R.drawable.unknown_album);
- }
- }
- }
-
- private void setUnknownImage(RemoteControlClient remoteControl) {
- setImage(remoteControl, largeUnknownImage);
- }
-
public abstract class ImageTask extends SilentBackgroundTask<Void> {
private final Context mContext;
private final MusicDirectory.Entry mEntry;
diff --git a/src/github/daneren2005/dsub/util/Notifications.java b/src/github/daneren2005/dsub/util/Notifications.java
index 3eace1dd..330e14ec 100644
--- a/src/github/daneren2005/dsub/util/Notifications.java
+++ b/src/github/daneren2005/dsub/util/Notifications.java
@@ -231,7 +231,7 @@ public final class Notifications {
String currentDownloading, currentSize;
if(file != null) {
currentDownloading = file.getSong().getTitle();
- currentSize = Util.formatBytes(file.getEstimatedSize());
+ currentSize = Util.formatLocalizedBytes(file.getEstimatedSize(), context);
} else {
currentDownloading = "none";
currentSize = "0";
diff --git a/src/github/daneren2005/dsub/view/SongView.java b/src/github/daneren2005/dsub/view/SongView.java
index 630f747f..2fbaedc3 100644
--- a/src/github/daneren2005/dsub/view/SongView.java
+++ b/src/github/daneren2005/dsub/view/SongView.java
@@ -231,7 +231,9 @@ public class SongView extends UpdateView implements Checkable {
}
if (downloadFile.isDownloading() && !downloadFile.isDownloadCancelled() && partialFileExists) {
- statusTextView.setText(Util.formatLocalizedBytes(partialFile.length(), getContext()));
+ double percentage = (partialFile.length() * 100.0) / downloadFile.getEstimatedSize();
+ percentage = Math.min(percentage, 100);
+ statusTextView.setText((int)percentage + " %");
if(!rightImage) {
statusImageView.setVisibility(View.VISIBLE);
rightImage = true;