Show cover art in song selector controls
Also rename some things associated with the controls
This commit is contained in:
parent
a3a9a0fc21
commit
63b6435f96
@ -97,8 +97,8 @@
|
||||
<string name="filter_suggestions_summary">Use text suggestions when editing the filter text</string>
|
||||
<string name="selector_on_startup_title">Open on Startup</string>
|
||||
<string name="selector_on_startup_summary">Open song selector on startup</string>
|
||||
<string name="selector_status_title">Controls in Selector</string>
|
||||
<string name="selector_status_summary">Show the currently playing song and media controls in the selector window</string>
|
||||
<string name="controls_in_selector_title">Controls in Selector</string>
|
||||
<string name="controls_in_selector_summary">Show the currently playing song and media controls in the selector window</string>
|
||||
<string name="default_action_title">Default Action</string>
|
||||
<string name="default_action_summary">What to do when an item is tapped</string>
|
||||
|
||||
|
@ -66,9 +66,9 @@
|
||||
android:summary="@string/selector_on_startup_summary"
|
||||
android:defaultValue="false" />
|
||||
<CheckBoxPreference
|
||||
android:key="selector_status"
|
||||
android:title="@string/selector_status_title"
|
||||
android:summary="@string/selector_status_summary"
|
||||
android:key="controls_in_selector"
|
||||
android:title="@string/controls_in_selector_title"
|
||||
android:summary="@string/controls_in_selector_summary"
|
||||
android:defaultValue="false" />
|
||||
<ListPreference
|
||||
android:key="default_action_int"
|
||||
|
@ -101,6 +101,27 @@ public final class CoverBitmap {
|
||||
canvas.restore();
|
||||
}
|
||||
|
||||
/**
|
||||
* Scales a cover down to fit in a square of the specified size.
|
||||
*
|
||||
* @param song The Song to retrieve the cover from.
|
||||
* @param size The width/height of the square. Must be greater than zero.
|
||||
* @return The scaled Bitmap, or null if a cover could not be found.
|
||||
*/
|
||||
public static Bitmap createScaledBitmap(Song song, int size)
|
||||
{
|
||||
if (song == null || size < 1)
|
||||
return null;
|
||||
|
||||
Bitmap cover = song.getCover();
|
||||
int coverWidth = cover.getWidth();
|
||||
int coverHeight = cover.getHeight();
|
||||
float scale = coverWidth > coverHeight ? (float)size / coverWidth : (float)size / coverHeight;
|
||||
coverWidth *= scale;
|
||||
coverHeight *= scale;
|
||||
return Bitmap.createScaledBitmap(cover, coverWidth, coverHeight, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a compact image, displaying cover art with the song title
|
||||
* overlaid at the bottom edge.
|
||||
|
@ -25,6 +25,7 @@ import android.content.Intent;
|
||||
import android.content.SharedPreferences;
|
||||
import android.content.res.Resources;
|
||||
import android.database.ContentObserver;
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.Color;
|
||||
import android.graphics.drawable.PaintDrawable;
|
||||
import android.os.Bundle;
|
||||
@ -36,6 +37,8 @@ import android.text.Editable;
|
||||
import android.text.InputType;
|
||||
import android.text.TextUtils;
|
||||
import android.text.TextWatcher;
|
||||
import android.util.DisplayMetrics;
|
||||
import android.util.TypedValue;
|
||||
import android.view.ContextMenu;
|
||||
import android.view.KeyEvent;
|
||||
import android.view.Menu;
|
||||
@ -46,6 +49,7 @@ import android.view.ViewGroup;
|
||||
import android.view.ViewStub;
|
||||
import android.widget.AdapterView;
|
||||
import android.widget.Filter;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.ListView;
|
||||
import android.widget.TabHost;
|
||||
@ -60,8 +64,9 @@ public class SongSelector extends PlaybackActivity implements AdapterView.OnItem
|
||||
private TextView mTextFilter;
|
||||
private View mClearButton;
|
||||
|
||||
private View mStatus;
|
||||
private View mControls;
|
||||
TextView mStatusText;
|
||||
ImageView mCover;
|
||||
|
||||
private ViewGroup mLimiterViews;
|
||||
|
||||
@ -120,15 +125,18 @@ public class SongSelector extends PlaybackActivity implements AdapterView.OnItem
|
||||
int inputType = settings.getBoolean("filter_suggestions", false) ? InputType.TYPE_CLASS_TEXT : InputType.TYPE_TEXT_VARIATION_FILTER;
|
||||
mTextFilter.setInputType(inputType);
|
||||
|
||||
boolean status = settings.getBoolean("selector_status", false);
|
||||
if (status && mStatus == null) {
|
||||
mStatus = findViewById(R.id.controls);
|
||||
if (mStatus == null)
|
||||
mStatus = ((ViewStub)findViewById(R.id.controls_stub)).inflate();
|
||||
mStatusText = (TextView)mStatus.findViewById(R.id.status_text);
|
||||
mPlayPauseButton = (ControlButton)mStatus.findViewById(R.id.play_pause);
|
||||
ControlButton next = (ControlButton)mStatus.findViewById(R.id.next);
|
||||
boolean showControls = settings.getBoolean("controls_in_selector", false);
|
||||
if (showControls && mControls == null) {
|
||||
mControls = findViewById(R.id.controls);
|
||||
if (mControls == null)
|
||||
mControls = ((ViewStub)findViewById(R.id.controls_stub)).inflate();
|
||||
mStatusText = (TextView)mControls.findViewById(R.id.status_text);
|
||||
mCover = (ImageView)mControls.findViewById(R.id.cover);
|
||||
ControlButton previous = (ControlButton)mControls.findViewById(R.id.previous);
|
||||
mPlayPauseButton = (ControlButton)mControls.findViewById(R.id.play_pause);
|
||||
ControlButton next = (ControlButton)mControls.findViewById(R.id.next);
|
||||
|
||||
previous.setOnClickListener(this);
|
||||
mPlayPauseButton.setOnClickListener(this);
|
||||
next.setOnClickListener(this);
|
||||
|
||||
@ -137,9 +145,9 @@ public class SongSelector extends PlaybackActivity implements AdapterView.OnItem
|
||||
setState(service.getState());
|
||||
onSongChange(service.getSong(0));
|
||||
}
|
||||
} else if (!status && mStatus != null) {
|
||||
mStatus.setVisibility(View.GONE);
|
||||
mStatus = null;
|
||||
} else if (!showControls && mControls != null) {
|
||||
mControls.setVisibility(View.GONE);
|
||||
mControls = null;
|
||||
}
|
||||
|
||||
int action = Integer.parseInt(settings.getString("default_action_int", "0"));
|
||||
@ -565,38 +573,47 @@ public class SongSelector extends PlaybackActivity implements AdapterView.OnItem
|
||||
mSearchBox.requestFocus();
|
||||
}
|
||||
|
||||
private static int mCoverSize = -1;
|
||||
|
||||
/**
|
||||
* Call to update the status text for a newly-playing song.
|
||||
* Call to update the status text for a newly-playing song. Should only be
|
||||
* called after the controls have been initialized.
|
||||
*/
|
||||
private void onSongChange(final Song song)
|
||||
{
|
||||
if (mStatusText != null) {
|
||||
Resources res = getResources();
|
||||
CharSequence text;
|
||||
if (song == null) {
|
||||
text = res.getText(R.string.none);
|
||||
} else {
|
||||
String title = song.title == null ? res.getString(R.string.unknown) : song.title;
|
||||
String artist = song.artist == null ? res.getString(R.string.unknown) : song.artist;
|
||||
text = res.getString(R.string.title_by_artist, title, artist);
|
||||
}
|
||||
|
||||
final CharSequence result = text;
|
||||
runOnUiThread(new Runnable() {
|
||||
public void run()
|
||||
{
|
||||
mStatusText.setText(result);
|
||||
}
|
||||
});
|
||||
Resources res = getResources();
|
||||
CharSequence text;
|
||||
if (song == null) {
|
||||
text = res.getText(R.string.none);
|
||||
} else {
|
||||
String title = song.title == null ? res.getString(R.string.unknown) : song.title;
|
||||
String artist = song.artist == null ? res.getString(R.string.unknown) : song.artist;
|
||||
text = res.getString(R.string.title_by_artist, title, artist);
|
||||
}
|
||||
|
||||
if (mCoverSize == -1) {
|
||||
DisplayMetrics metrics = ContextApplication.getContext().getResources().getDisplayMetrics();
|
||||
mCoverSize = (int)TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 64, metrics);
|
||||
}
|
||||
|
||||
final CharSequence result = text;
|
||||
final Bitmap cover = CoverBitmap.createScaledBitmap(song, mCoverSize);
|
||||
runOnUiThread(new Runnable() {
|
||||
public void run()
|
||||
{
|
||||
mStatusText.setText(result);
|
||||
mCover.setImageBitmap(cover);
|
||||
mCover.setVisibility(cover == null ? View.GONE : View.VISIBLE);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void receive(Intent intent)
|
||||
{
|
||||
if (mStatusText != null) {
|
||||
Song song = intent.getParcelableExtra("song");
|
||||
onSongChange(song);
|
||||
}
|
||||
super.receive(intent);
|
||||
|
||||
if (mControls != null)
|
||||
onSongChange((Song)intent.getParcelableExtra("song"));
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user