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:visibility="invisible"
|
||||
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
|
||||
android:id="@+id/text"
|
||||
android:maxLines="2"
|
||||
|
@ -28,6 +28,7 @@ import android.widget.Checkable;
|
||||
|
||||
public class DraggableRow extends LinearLayout implements Checkable {
|
||||
private boolean mShowCheckBox;
|
||||
private boolean mShowCover;
|
||||
private boolean mHighlighted;
|
||||
private boolean mChecked;
|
||||
|
||||
@ -38,12 +39,14 @@ public class DraggableRow extends LinearLayout implements Checkable {
|
||||
private CheckedTextView mCheckBox;
|
||||
private View mPmark;
|
||||
private ImageView mDragger;
|
||||
private LazyCoverView mCoverView;
|
||||
|
||||
// Hardcoded sizes of elements in DPI
|
||||
// MUST match definition in draggable_row
|
||||
private final int DPI_PMARK = 4;
|
||||
private final int DPI_CHECKBOX = 44;
|
||||
private final int DPI_DRAGGER = 44;
|
||||
private final int DPI_COVER = 44;
|
||||
private final int DPI_SLACK = 1; // safety margin
|
||||
|
||||
|
||||
@ -55,10 +58,11 @@ public class DraggableRow extends LinearLayout implements Checkable {
|
||||
|
||||
@Override
|
||||
public void onFinishInflate() {
|
||||
mCheckBox = (CheckedTextView)this.findViewById(R.id.checkbox);
|
||||
mTextView = (TextView)this.findViewById(R.id.text);
|
||||
mPmark = (View)this.findViewById(R.id.pmark);
|
||||
mDragger = (ImageView)this.findViewById(R.id.dragger);
|
||||
mCheckBox = (CheckedTextView)this.findViewById(R.id.checkbox);
|
||||
mTextView = (TextView)this.findViewById(R.id.text);
|
||||
mPmark = (View)this.findViewById(R.id.pmark);
|
||||
mDragger = (ImageView)this.findViewById(R.id.dragger);
|
||||
mCoverView = (LazyCoverView)this.findViewById(R.id.cover);
|
||||
setupTextView(false);
|
||||
}
|
||||
|
||||
@ -79,7 +83,7 @@ public class DraggableRow extends LinearLayout implements Checkable {
|
||||
* @param redraw invalidates the current view if TRUE
|
||||
*/
|
||||
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;
|
||||
if (pixelFree > 0)
|
||||
mTextView.setWidth(pixelFree);
|
||||
@ -116,18 +120,33 @@ public class DraggableRow extends LinearLayout implements Checkable {
|
||||
|
||||
/**
|
||||
* Changes the visibility of the checkbox
|
||||
*
|
||||
* @param state show or destroy the checkbox
|
||||
*/
|
||||
public void showCheckBox(boolean state) {
|
||||
if (mShowCheckBox != state) {
|
||||
mCheckBox.setVisibility( state ? View.VISIBLE : View.GONE);
|
||||
mCheckBox.setVisibility( state ? View.VISIBLE : View.GONE );
|
||||
mShowCheckBox = state;
|
||||
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
|
||||
*
|
||||
* @param state shows or hides the dragger
|
||||
*/
|
||||
public void showDragger(boolean state) {
|
||||
@ -141,4 +160,11 @@ public class DraggableRow extends LinearLayout implements Checkable {
|
||||
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);
|
||||
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.setDropListener(onDrop);
|
||||
mListView.setRemoveListener(onRemove);
|
||||
|
@ -19,6 +19,7 @@ package ch.blinkenlights.android.vanilla;
|
||||
|
||||
import android.content.Context;
|
||||
import android.app.Activity;
|
||||
import android.os.Looper;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.ArrayAdapter;
|
||||
@ -35,14 +36,16 @@ public class ShowQueueAdapter
|
||||
extends ArrayAdapter<Song>
|
||||
{
|
||||
|
||||
int mResource;
|
||||
int mHighlightRow;
|
||||
Context mContext;
|
||||
private int mResource;
|
||||
private int mHighlightRow;
|
||||
private Context mContext;
|
||||
private Looper mLooper;
|
||||
|
||||
public ShowQueueAdapter(Context context, int resource) {
|
||||
public ShowQueueAdapter(Context context, int resource, Looper looper) {
|
||||
super(context, resource);
|
||||
mResource = resource;
|
||||
mContext = context;
|
||||
mLooper = looper;
|
||||
mHighlightRow = -1;
|
||||
}
|
||||
|
||||
@ -64,6 +67,8 @@ public class ShowQueueAdapter
|
||||
} else {
|
||||
LayoutInflater inflater = ((Activity)mContext).getLayoutInflater();
|
||||
row = (DraggableRow)inflater.inflate(mResource, parent, false);
|
||||
row.showCoverView(true);
|
||||
row.getCoverView().setup(mLooper);
|
||||
}
|
||||
|
||||
Song song = getItem(position);
|
||||
@ -74,6 +79,7 @@ public class ShowQueueAdapter
|
||||
sb.append(song.album+", "+song.artist);
|
||||
sb.setSpan(new ForegroundColorSpan(Color.GRAY), song.title.length() + 1, sb.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
|
||||
row.getTextView().setText(sb);
|
||||
row.getCoverView().setCover(MediaUtils.TYPE_ALBUM, song.albumId);
|
||||
}
|
||||
|
||||
row.highlightRow(position == mHighlightRow);
|
||||
|
Loading…
x
Reference in New Issue
Block a user