cover art support in queueview
This commit is contained in:
parent
54f17a27ce
commit
ea04fa9fb8
@ -34,6 +34,15 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|||||||
android:layout_height="44dip"
|
android:layout_height="44dip"
|
||||||
android:visibility="invisible"
|
android:visibility="invisible"
|
||||||
android:background="@color/now_playing_marker" />
|
android:background="@color/now_playing_marker" />
|
||||||
|
<ch.blinkenlights.android.vanilla.LazyCoverView
|
||||||
|
android:id="@+id/cover"
|
||||||
|
android:background="?android:attr/selectableItemBackground"
|
||||||
|
android:longClickable="true"
|
||||||
|
android:scaleType="fitCenter"
|
||||||
|
android:layout_width="44dip"
|
||||||
|
android:layout_height="44dip"
|
||||||
|
android:visibility="gone"
|
||||||
|
/>
|
||||||
<TextView
|
<TextView
|
||||||
android:id="@+id/text"
|
android:id="@+id/text"
|
||||||
android:maxLines="2"
|
android:maxLines="2"
|
||||||
|
@ -28,6 +28,7 @@ import android.widget.Checkable;
|
|||||||
|
|
||||||
public class DraggableRow extends LinearLayout implements Checkable {
|
public class DraggableRow extends LinearLayout implements Checkable {
|
||||||
private boolean mShowCheckBox;
|
private boolean mShowCheckBox;
|
||||||
|
private boolean mShowCover;
|
||||||
private boolean mHighlighted;
|
private boolean mHighlighted;
|
||||||
private boolean mChecked;
|
private boolean mChecked;
|
||||||
|
|
||||||
@ -38,12 +39,14 @@ public class DraggableRow extends LinearLayout implements Checkable {
|
|||||||
private CheckedTextView mCheckBox;
|
private CheckedTextView mCheckBox;
|
||||||
private View mPmark;
|
private View mPmark;
|
||||||
private ImageView mDragger;
|
private ImageView mDragger;
|
||||||
|
private LazyCoverView mCoverView;
|
||||||
|
|
||||||
// Hardcoded sizes of elements in DPI
|
// Hardcoded sizes of elements in DPI
|
||||||
// MUST match definition in draggable_row
|
// MUST match definition in draggable_row
|
||||||
private final int DPI_PMARK = 4;
|
private final int DPI_PMARK = 4;
|
||||||
private final int DPI_CHECKBOX = 44;
|
private final int DPI_CHECKBOX = 44;
|
||||||
private final int DPI_DRAGGER = 44;
|
private final int DPI_DRAGGER = 44;
|
||||||
|
private final int DPI_COVER = 44;
|
||||||
private final int DPI_SLACK = 1; // safety margin
|
private final int DPI_SLACK = 1; // safety margin
|
||||||
|
|
||||||
|
|
||||||
@ -55,10 +58,11 @@ public class DraggableRow extends LinearLayout implements Checkable {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onFinishInflate() {
|
public void onFinishInflate() {
|
||||||
mCheckBox = (CheckedTextView)this.findViewById(R.id.checkbox);
|
mCheckBox = (CheckedTextView)this.findViewById(R.id.checkbox);
|
||||||
mTextView = (TextView)this.findViewById(R.id.text);
|
mTextView = (TextView)this.findViewById(R.id.text);
|
||||||
mPmark = (View)this.findViewById(R.id.pmark);
|
mPmark = (View)this.findViewById(R.id.pmark);
|
||||||
mDragger = (ImageView)this.findViewById(R.id.dragger);
|
mDragger = (ImageView)this.findViewById(R.id.dragger);
|
||||||
|
mCoverView = (LazyCoverView)this.findViewById(R.id.cover);
|
||||||
setupTextView(false);
|
setupTextView(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -79,7 +83,7 @@ public class DraggableRow extends LinearLayout implements Checkable {
|
|||||||
* @param redraw invalidates the current view if TRUE
|
* @param redraw invalidates the current view if TRUE
|
||||||
*/
|
*/
|
||||||
private void setupTextView(boolean redraw) {
|
private void setupTextView(boolean redraw) {
|
||||||
int pixelUsed = (int)((DPI_SLACK + DPI_PMARK + DPI_DRAGGER + (mShowCheckBox ? DPI_CHECKBOX : 0)) * mDensity);
|
int pixelUsed = (int)((DPI_SLACK + DPI_PMARK + DPI_DRAGGER + (mShowCover ? DPI_COVER : 0) + (mShowCheckBox ? DPI_CHECKBOX : 0)) * mDensity);
|
||||||
int pixelFree = sWidth - pixelUsed;
|
int pixelFree = sWidth - pixelUsed;
|
||||||
if (pixelFree > 0)
|
if (pixelFree > 0)
|
||||||
mTextView.setWidth(pixelFree);
|
mTextView.setWidth(pixelFree);
|
||||||
@ -116,18 +120,33 @@ public class DraggableRow extends LinearLayout implements Checkable {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Changes the visibility of the checkbox
|
* Changes the visibility of the checkbox
|
||||||
|
*
|
||||||
* @param state show or destroy the checkbox
|
* @param state show or destroy the checkbox
|
||||||
*/
|
*/
|
||||||
public void showCheckBox(boolean state) {
|
public void showCheckBox(boolean state) {
|
||||||
if (mShowCheckBox != state) {
|
if (mShowCheckBox != state) {
|
||||||
mCheckBox.setVisibility( state ? View.VISIBLE : View.GONE);
|
mCheckBox.setVisibility( state ? View.VISIBLE : View.GONE );
|
||||||
mShowCheckBox = state;
|
mShowCheckBox = state;
|
||||||
setupTextView(true);
|
setupTextView(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Change the visibility of the cover view
|
||||||
|
*
|
||||||
|
* @param state show or hide the cover view
|
||||||
|
*/
|
||||||
|
public void showCoverView(boolean state) {
|
||||||
|
if (mShowCover != state) {
|
||||||
|
mCoverView.setVisibility( state ? View.VISIBLE : View.GONE );
|
||||||
|
mShowCover = state;
|
||||||
|
setupTextView(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Change visibility of dragger element
|
* Change visibility of dragger element
|
||||||
|
*
|
||||||
* @param state shows or hides the dragger
|
* @param state shows or hides the dragger
|
||||||
*/
|
*/
|
||||||
public void showDragger(boolean state) {
|
public void showDragger(boolean state) {
|
||||||
@ -141,4 +160,11 @@ public class DraggableRow extends LinearLayout implements Checkable {
|
|||||||
return mTextView;
|
return mTextView;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns an instance of our coverview
|
||||||
|
*/
|
||||||
|
public LazyCoverView getCoverView() {
|
||||||
|
return mCoverView;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -48,7 +48,7 @@ public class ShowQueueActivity extends PlaybackActivity
|
|||||||
|
|
||||||
mService = PlaybackService.get(this);
|
mService = PlaybackService.get(this);
|
||||||
mListView = (DragSortListView) findViewById(R.id.list);
|
mListView = (DragSortListView) findViewById(R.id.list);
|
||||||
listAdapter = new ShowQueueAdapter(this, R.layout.draggable_row);
|
listAdapter = new ShowQueueAdapter(this, R.layout.draggable_row, mHandler.getLooper());
|
||||||
mListView.setAdapter(listAdapter);
|
mListView.setAdapter(listAdapter);
|
||||||
mListView.setDropListener(onDrop);
|
mListView.setDropListener(onDrop);
|
||||||
mListView.setRemoveListener(onRemove);
|
mListView.setRemoveListener(onRemove);
|
||||||
|
@ -19,6 +19,7 @@ package ch.blinkenlights.android.vanilla;
|
|||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
|
import android.os.Looper;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
import android.widget.ArrayAdapter;
|
import android.widget.ArrayAdapter;
|
||||||
@ -35,14 +36,16 @@ public class ShowQueueAdapter
|
|||||||
extends ArrayAdapter<Song>
|
extends ArrayAdapter<Song>
|
||||||
{
|
{
|
||||||
|
|
||||||
int mResource;
|
private int mResource;
|
||||||
int mHighlightRow;
|
private int mHighlightRow;
|
||||||
Context mContext;
|
private Context mContext;
|
||||||
|
private Looper mLooper;
|
||||||
|
|
||||||
public ShowQueueAdapter(Context context, int resource) {
|
public ShowQueueAdapter(Context context, int resource, Looper looper) {
|
||||||
super(context, resource);
|
super(context, resource);
|
||||||
mResource = resource;
|
mResource = resource;
|
||||||
mContext = context;
|
mContext = context;
|
||||||
|
mLooper = looper;
|
||||||
mHighlightRow = -1;
|
mHighlightRow = -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -64,6 +67,8 @@ public class ShowQueueAdapter
|
|||||||
} else {
|
} else {
|
||||||
LayoutInflater inflater = ((Activity)mContext).getLayoutInflater();
|
LayoutInflater inflater = ((Activity)mContext).getLayoutInflater();
|
||||||
row = (DraggableRow)inflater.inflate(mResource, parent, false);
|
row = (DraggableRow)inflater.inflate(mResource, parent, false);
|
||||||
|
row.showCoverView(true);
|
||||||
|
row.getCoverView().setup(mLooper);
|
||||||
}
|
}
|
||||||
|
|
||||||
Song song = getItem(position);
|
Song song = getItem(position);
|
||||||
@ -74,6 +79,7 @@ public class ShowQueueAdapter
|
|||||||
sb.append(song.album+", "+song.artist);
|
sb.append(song.album+", "+song.artist);
|
||||||
sb.setSpan(new ForegroundColorSpan(Color.GRAY), song.title.length() + 1, sb.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
|
sb.setSpan(new ForegroundColorSpan(Color.GRAY), song.title.length() + 1, sb.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
|
||||||
row.getTextView().setText(sb);
|
row.getTextView().setText(sb);
|
||||||
|
row.getCoverView().setCover(MediaUtils.TYPE_ALBUM, song.albumId);
|
||||||
}
|
}
|
||||||
|
|
||||||
row.highlightRow(position == mHighlightRow);
|
row.highlightRow(position == mHighlightRow);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user