From 30d10382905b5610848abe3d614dbc74c7708670 Mon Sep 17 00:00:00 2001 From: Adrian Ulrich Date: Sun, 30 Sep 2012 13:28:27 +0200 Subject: [PATCH] initial support for ShowQueueActivity --- AndroidManifest.xml | 5 + res/layout/showqueue_listview.xml | 10 ++ res/layout/showqueue_row.xml | 22 ++++ .../android/vanilla/FullPlaybackActivity.java | 4 + .../android/vanilla/PlaybackActivity.java | 1 + .../android/vanilla/ShowQueueActivity.java | 105 ++++++++++++++++++ .../android/vanilla/ShowQueueAdapter.java | 80 +++++++++++++ 7 files changed, 227 insertions(+) create mode 100644 res/layout/showqueue_listview.xml create mode 100644 res/layout/showqueue_row.xml create mode 100644 src/ch/blinkenlights/android/vanilla/ShowQueueActivity.java create mode 100644 src/ch/blinkenlights/android/vanilla/ShowQueueAdapter.java diff --git a/AndroidManifest.xml b/AndroidManifest.xml index e4ab3b64..4c366b64 100644 --- a/AndroidManifest.xml +++ b/AndroidManifest.xml @@ -59,6 +59,11 @@ THE SOFTWARE. android:theme="@style/Dialog" android:excludeFromRecents="true" android:launchMode="singleInstance" /> + diff --git a/res/layout/showqueue_listview.xml b/res/layout/showqueue_listview.xml new file mode 100644 index 00000000..4b3c8c89 --- /dev/null +++ b/res/layout/showqueue_listview.xml @@ -0,0 +1,10 @@ + + diff --git a/res/layout/showqueue_row.xml b/res/layout/showqueue_row.xml new file mode 100644 index 00000000..ab99b5cd --- /dev/null +++ b/res/layout/showqueue_row.xml @@ -0,0 +1,22 @@ + + + + + diff --git a/src/ch/blinkenlights/android/vanilla/FullPlaybackActivity.java b/src/ch/blinkenlights/android/vanilla/FullPlaybackActivity.java index 2a50b6df..35395305 100644 --- a/src/ch/blinkenlights/android/vanilla/FullPlaybackActivity.java +++ b/src/ch/blinkenlights/android/vanilla/FullPlaybackActivity.java @@ -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); } diff --git a/src/ch/blinkenlights/android/vanilla/PlaybackActivity.java b/src/ch/blinkenlights/android/vanilla/PlaybackActivity.java index 53faaa0a..cbd0ef5c 100644 --- a/src/ch/blinkenlights/android/vanilla/PlaybackActivity.java +++ b/src/ch/blinkenlights/android/vanilla/PlaybackActivity.java @@ -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) diff --git a/src/ch/blinkenlights/android/vanilla/ShowQueueActivity.java b/src/ch/blinkenlights/android/vanilla/ShowQueueActivity.java new file mode 100644 index 00000000..6d42171e --- /dev/null +++ b/src/ch/blinkenlights/android/vanilla/ShowQueueActivity.java @@ -0,0 +1,105 @@ +/* + * Copyright (C) 2012 Adrian Ulrich + * + * 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 + * + * 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 { + + 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; + } + +}