initial support for ShowQueueActivity
This commit is contained in:
parent
8004113518
commit
30d1038290
@ -59,6 +59,11 @@ THE SOFTWARE.
|
||||
android:theme="@style/Dialog"
|
||||
android:excludeFromRecents="true"
|
||||
android:launchMode="singleInstance" />
|
||||
<activity
|
||||
android:name="ShowQueueActivity"
|
||||
android:theme="@style/BackActionBar"
|
||||
android:excludeFromRecents="true"
|
||||
android:launchMode="singleInstance" />
|
||||
<receiver
|
||||
android:name=".OneCellWidget"
|
||||
android:label="Vanilla Music 1x1">
|
||||
|
10
res/layout/showqueue_listview.xml
Normal file
10
res/layout/showqueue_listview.xml
Normal file
@ -0,0 +1,10 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<ListView
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:id="@+id/list"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="fill_parent"
|
||||
android:divider="@color/divider_color"
|
||||
android:dividerHeight="1dip"
|
||||
android:listSelector="@drawable/selectable_item_bg"
|
||||
android:scrollbarStyle="outsideInset" />
|
22
res/layout/showqueue_row.xml
Normal file
22
res/layout/showqueue_row.xml
Normal file
@ -0,0 +1,22 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="fill_parent"
|
||||
android:orientation="horizontal">
|
||||
<View
|
||||
android:id="@+id/playmark"
|
||||
android:layout_width="4dip"
|
||||
android:layout_height="fill_parent"
|
||||
android:background="@android:color/holo_blue_dark" />
|
||||
<TextView
|
||||
android:id="@+id/text"
|
||||
android:background="@drawable/selectable_item_bg"
|
||||
android:maxLines="2"
|
||||
android:padding="3dip"
|
||||
android:textColor="#ffff"
|
||||
android:gravity="left|center_vertical"
|
||||
android:layout_width="0px"
|
||||
android:layout_height="44dip"
|
||||
android:layout_weight="1" />
|
||||
</LinearLayout>
|
@ -358,6 +358,7 @@ public class FullPlaybackActivity extends PlaybackActivity
|
||||
menu.add(0, MENU_ENQUEUE_ARTIST, 0, R.string.enqueue_current_artist).setIcon(R.drawable.ic_menu_add);
|
||||
menu.add(0, MENU_ENQUEUE_GENRE, 0, R.string.enqueue_current_genre).setIcon(R.drawable.ic_menu_add);
|
||||
menu.add(0, MENU_TOGGLE_CONTROLS, 0, R.string.toggle_controls);
|
||||
menu.add(0, MENU_SHOW_QUEUE, 0, "++ show queue ++");
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -385,6 +386,9 @@ public class FullPlaybackActivity extends PlaybackActivity
|
||||
setControlsVisible(!mControlsVisible);
|
||||
mHandler.sendEmptyMessage(MSG_SAVE_CONTROLS);
|
||||
break;
|
||||
case MENU_SHOW_QUEUE:
|
||||
startActivity(new Intent(this, ShowQueueActivity.class));
|
||||
break;
|
||||
default:
|
||||
return super.onOptionsItemSelected(item);
|
||||
}
|
||||
|
@ -323,6 +323,7 @@ public abstract class PlaybackActivity extends Activity
|
||||
static final int MENU_ENQUEUE_GENRE = 10;
|
||||
static final int MENU_CLEAR_QUEUE = 11;
|
||||
static final int MENU_TOGGLE_CONTROLS = 12;
|
||||
static final int MENU_SHOW_QUEUE = 13;
|
||||
|
||||
@Override
|
||||
public boolean onCreateOptionsMenu(Menu menu)
|
||||
|
105
src/ch/blinkenlights/android/vanilla/ShowQueueActivity.java
Normal file
105
src/ch/blinkenlights/android/vanilla/ShowQueueActivity.java
Normal file
@ -0,0 +1,105 @@
|
||||
/*
|
||||
* Copyright (C) 2012 Adrian Ulrich <adrian@blinkenlights.ch>
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
|
||||
package ch.blinkenlights.android.vanilla;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import android.app.Activity;
|
||||
import android.os.Bundle;
|
||||
import android.view.View;
|
||||
import android.widget.AdapterView;
|
||||
import android.widget.AdapterView.OnItemClickListener;
|
||||
import android.widget.AdapterView.OnItemLongClickListener;
|
||||
import android.widget.ListView;
|
||||
import android.util.Log;
|
||||
|
||||
public class ShowQueueActivity extends Activity {
|
||||
private ListView mListView;
|
||||
private ShowQueueAdapter listAdapter;
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
setContentView(R.layout.showqueue_listview);
|
||||
|
||||
mListView = (ListView) findViewById(R.id.list);
|
||||
listAdapter = new ShowQueueAdapter(this, R.layout.showqueue_row);
|
||||
mListView.setAdapter(listAdapter);
|
||||
|
||||
mListView.setOnItemClickListener(new OnItemClickListener() {
|
||||
@Override
|
||||
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
|
||||
jumpToSong(position);
|
||||
finish();
|
||||
}});
|
||||
mListView.setOnItemLongClickListener(new OnItemLongClickListener() {
|
||||
@Override
|
||||
public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) {
|
||||
jumpToSong(position);
|
||||
/* This activity will stay open on longpress, so we have
|
||||
* to update the playmerker ourselfs */
|
||||
listAdapter.highlightRow(position);
|
||||
listAdapter.notifyDataSetChanged();
|
||||
return true;
|
||||
}});
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
** Called when we are displayed (again)
|
||||
** This will always refresh the whole song list
|
||||
*/
|
||||
@Override
|
||||
public void onResume() {
|
||||
super.onResume();
|
||||
refreshSongQueueList();
|
||||
}
|
||||
|
||||
/*
|
||||
** Tells the playback service to jump to a specific song
|
||||
*/
|
||||
private void jumpToSong(int id) {
|
||||
PlaybackService service = PlaybackService.get(this);
|
||||
service.jumpToQueuePosition(id);
|
||||
}
|
||||
|
||||
private void refreshSongQueueList() {
|
||||
int i, stotal, spos;
|
||||
PlaybackService service = PlaybackService.get(this);
|
||||
|
||||
stotal = service.getTimelineLength(); /* Total number of songs in queue */
|
||||
spos = service.getTimelinePosition(); /* Current position in queue */
|
||||
|
||||
listAdapter.clear(); /* Flush all existing entries... */
|
||||
listAdapter.highlightRow(spos); /* and highlight current position */
|
||||
|
||||
for(i=0 ; i<stotal; i++) {
|
||||
listAdapter.add(service.getSongByQueuePosition(i));
|
||||
}
|
||||
mListView.setSelectionFromTop(spos, 0); /* scroll to currently playing song */
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
80
src/ch/blinkenlights/android/vanilla/ShowQueueAdapter.java
Normal file
80
src/ch/blinkenlights/android/vanilla/ShowQueueAdapter.java
Normal file
@ -0,0 +1,80 @@
|
||||
/*
|
||||
* Copyright (C) 2012 Adrian Ulrich <adrian@blinkenlights.ch>
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
|
||||
package ch.blinkenlights.android.vanilla;
|
||||
|
||||
import android.content.Context;
|
||||
import android.app.Activity;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.ArrayAdapter;
|
||||
import android.view.LayoutInflater;
|
||||
import android.widget.TextView;
|
||||
|
||||
import android.graphics.Color;
|
||||
import android.text.Spannable;
|
||||
import android.text.SpannableStringBuilder;
|
||||
import android.text.style.ForegroundColorSpan;
|
||||
import android.text.Spannable;
|
||||
import android.text.SpannableStringBuilder;
|
||||
|
||||
public class ShowQueueAdapter extends ArrayAdapter<Song> {
|
||||
|
||||
int resource;
|
||||
Context context;
|
||||
int hl_row;
|
||||
|
||||
public ShowQueueAdapter(Context context, int resource) {
|
||||
super(context, resource);
|
||||
this.resource = resource;
|
||||
this.context = context;
|
||||
this.hl_row = -1;
|
||||
}
|
||||
|
||||
/*
|
||||
** Tells the adapter to highlight a specific row id
|
||||
** Set this to -1 to disable the feature
|
||||
*/
|
||||
public void highlightRow(int pos) {
|
||||
this.hl_row = pos;
|
||||
}
|
||||
|
||||
@Override
|
||||
public View getView(int position, View convertView, ViewGroup parent) {
|
||||
LayoutInflater inflater = ((Activity)context).getLayoutInflater();
|
||||
View row = inflater.inflate(resource, parent, false);
|
||||
Song song = getItem(position);
|
||||
TextView target = ((TextView)row.findViewById(R.id.text));
|
||||
SpannableStringBuilder sb = new SpannableStringBuilder(song.title);
|
||||
sb.append('\n');
|
||||
sb.append(song.album);
|
||||
sb.setSpan(new ForegroundColorSpan(Color.GRAY), song.title.length() + 1, sb.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
|
||||
|
||||
target.setText(sb);
|
||||
|
||||
View pmark = ((View)row.findViewById(R.id.playmark));
|
||||
pmark.setVisibility( ( position == this.hl_row ? View.VISIBLE : View.INVISIBLE ));
|
||||
|
||||
return row;
|
||||
}
|
||||
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user