Add controls in the song selector
This is somewhat hackish.
This commit is contained in:
parent
7049755021
commit
e2889d3d25
@ -62,4 +62,9 @@
|
||||
android:layout_alignParentRight="true"
|
||||
android:src="@android:drawable/ic_menu_close_clear_cancel" />
|
||||
</RelativeLayout>
|
||||
</LinearLayout>
|
||||
<ViewStub
|
||||
android:id="@+id/status_stub"
|
||||
android:layout="@layout/song_status"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content" />
|
||||
</LinearLayout>
|
||||
|
25
res/layout/song_status.xml
Normal file
25
res/layout/song_status.xml
Normal file
@ -0,0 +1,25 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:id="@+id/status"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="horizontal">
|
||||
<TextView
|
||||
android:id="@+id/status_text"
|
||||
android:textSize="16sp"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center"
|
||||
android:layout_weight="1" />
|
||||
<org.kreed.vanilla.ControlButton
|
||||
android:id="@+id/play_pause"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:src="@drawable/play" />
|
||||
<org.kreed.vanilla.ControlButton
|
||||
android:id="@+id/next"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:src="@drawable/next" />
|
||||
</LinearLayout>
|
@ -33,6 +33,8 @@
|
||||
<string name="albums">Albums</string>
|
||||
<string name="songs">Songs</string>
|
||||
|
||||
<string name="none">None</string>
|
||||
|
||||
<!-- Preferences -->
|
||||
<string name="pref_output">Audio Output</string>
|
||||
<string name="volume_title">Volume</string>
|
||||
@ -55,6 +57,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="default_action_title">Default Action</string>
|
||||
<string name="default_action_summary">What to do when an item is tapped</string>
|
||||
|
||||
|
@ -48,6 +48,11 @@
|
||||
android:title="@string/selector_on_startup_title"
|
||||
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:defaultValue="false" />
|
||||
<ListPreference
|
||||
android:key="default_action_int"
|
||||
android:title="@string/default_action_title"
|
||||
@ -63,4 +68,4 @@
|
||||
android:defaultValue="true"
|
||||
android:summary="@string/scrobble_summary" />
|
||||
</PreferenceCategory>
|
||||
</PreferenceScreen>
|
||||
</PreferenceScreen>
|
||||
|
@ -43,6 +43,10 @@ import android.view.ViewConfiguration;
|
||||
import android.widget.Scroller;
|
||||
|
||||
public final class CoverView extends View implements Handler.Callback {
|
||||
public static interface Callback {
|
||||
void songChanged(Song song);
|
||||
};
|
||||
|
||||
private static final int STORE_SIZE = 3;
|
||||
private static int SNAP_VELOCITY = -1;
|
||||
|
||||
@ -58,6 +62,7 @@ public final class CoverView extends View implements Handler.Callback {
|
||||
private IPlaybackService mService;
|
||||
private Scroller mScroller;
|
||||
private Handler mHandler = new Handler(this);
|
||||
private Callback mCallback;
|
||||
|
||||
private Song[] mSongs = new Song[3];
|
||||
private Bitmap[] mBitmaps = new Bitmap[3];
|
||||
@ -109,11 +114,21 @@ public final class CoverView extends View implements Handler.Callback {
|
||||
bitmap.recycle();
|
||||
}
|
||||
|
||||
public Song getCurrentSong()
|
||||
{
|
||||
return mSongs[STORE_SIZE / 2];
|
||||
}
|
||||
|
||||
public boolean hasSeparateInfo()
|
||||
{
|
||||
return mSeparateInfo;
|
||||
}
|
||||
|
||||
public void setCallback(Callback callback)
|
||||
{
|
||||
mCallback = callback;
|
||||
}
|
||||
|
||||
public void setSeparateInfo(boolean separate)
|
||||
{
|
||||
mSeparateInfo = separate;
|
||||
@ -410,6 +425,9 @@ public final class CoverView extends View implements Handler.Callback {
|
||||
reset();
|
||||
invalidate();
|
||||
|
||||
if (mCallback != null)
|
||||
mCallback.songChanged(mSongs[STORE_SIZE / 2]);
|
||||
|
||||
mHandler.sendMessage(mHandler.obtainMessage(SET_SONG, delta, 0));
|
||||
mHandler.sendEmptyMessage(i);
|
||||
}
|
||||
|
@ -42,19 +42,20 @@ import android.widget.SeekBar;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
public class FullPlaybackActivity extends PlaybackActivity implements View.OnClickListener, SeekBar.OnSeekBarChangeListener, View.OnFocusChangeListener, Handler.Callback {
|
||||
public class FullPlaybackActivity extends PlaybackActivity implements View.OnClickListener, SeekBar.OnSeekBarChangeListener, View.OnFocusChangeListener, Handler.Callback, CoverView.Callback {
|
||||
private IPlaybackService mService;
|
||||
private Handler mHandler = new Handler(this);
|
||||
|
||||
private RelativeLayout mMessageOverlay;
|
||||
private View mControlsTop;
|
||||
private View mControlsBottom;
|
||||
private SongSelector mSongSelector;
|
||||
|
||||
private ImageView mPlayPauseButton;
|
||||
private SeekBar mSeekBar;
|
||||
private TextView mSeekText;
|
||||
|
||||
private int mState;
|
||||
int mState;
|
||||
private int mDuration;
|
||||
private boolean mSeekBarTracking;
|
||||
|
||||
@ -175,6 +176,9 @@ public class FullPlaybackActivity extends PlaybackActivity implements View.OnCli
|
||||
setService(null);
|
||||
}
|
||||
}
|
||||
|
||||
if (mSongSelector != null)
|
||||
mSongSelector.change(intent);
|
||||
}
|
||||
|
||||
public void fillMenu(Menu menu, boolean fromDialog)
|
||||
@ -249,8 +253,10 @@ public class FullPlaybackActivity extends PlaybackActivity implements View.OnCli
|
||||
@Override
|
||||
public Dialog onCreateDialog(int id)
|
||||
{
|
||||
if (id == SONG_SELECTOR)
|
||||
return new SongSelector(this);
|
||||
if (id == SONG_SELECTOR) {
|
||||
mSongSelector = new SongSelector(this);
|
||||
return mSongSelector;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@ -407,4 +413,10 @@ public class FullPlaybackActivity extends PlaybackActivity implements View.OnCli
|
||||
if (hasFocus)
|
||||
sendHideMessage();
|
||||
}
|
||||
|
||||
public void songChanged(Song song)
|
||||
{
|
||||
if (mSongSelector != null)
|
||||
mSongSelector.updateSong(song);
|
||||
}
|
||||
}
|
||||
|
@ -33,7 +33,7 @@ import android.view.KeyEvent;
|
||||
import android.view.View;
|
||||
|
||||
public abstract class PlaybackActivity extends Activity implements ServiceConnection {
|
||||
protected CoverView mCoverView;
|
||||
CoverView mCoverView;
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle state)
|
||||
@ -155,4 +155,4 @@ public abstract class PlaybackActivity extends Activity implements ServiceConnec
|
||||
onServiceChange(intent);
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
@ -33,6 +33,7 @@ import android.net.Uri;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.os.Message;
|
||||
import android.os.RemoteException;
|
||||
import android.preference.PreferenceManager;
|
||||
import android.provider.MediaStore;
|
||||
import android.text.Editable;
|
||||
@ -45,6 +46,7 @@ import android.view.Menu;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.view.ViewStub;
|
||||
import android.view.Window;
|
||||
import android.widget.AdapterView;
|
||||
import android.widget.Filter;
|
||||
@ -54,14 +56,19 @@ import android.widget.TabHost;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import android.util.Log;
|
||||
|
||||
public class SongSelector extends Dialog implements AdapterView.OnItemClickListener, TextWatcher, View.OnClickListener, TabHost.OnTabChangeListener, Filter.FilterListener, Handler.Callback {
|
||||
private static final int MSG_INIT = 0;
|
||||
|
||||
private Handler mHandler = new Handler(this);
|
||||
|
||||
private TabHost mTabHost;
|
||||
private TextView mTextFilter;
|
||||
private View mClearButton;
|
||||
private Handler mHandler = new Handler(this);
|
||||
|
||||
private View mStatus;
|
||||
private TextView mStatusText;
|
||||
private ControlButton mPlayPauseButton;
|
||||
private ViewGroup mLimiterViews;
|
||||
|
||||
private int mDefaultAction;
|
||||
@ -129,6 +136,26 @@ public class SongSelector extends Dialog implements AdapterView.OnItemClickListe
|
||||
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.status);
|
||||
if (mStatus == null)
|
||||
mStatus = ((ViewStub)findViewById(R.id.status_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);
|
||||
|
||||
mPlayPauseButton.setOnClickListener(this);
|
||||
next.setOnClickListener(this);
|
||||
|
||||
FullPlaybackActivity owner = (FullPlaybackActivity)getOwnerActivity();
|
||||
updateState(owner.mState);
|
||||
updateSong(owner.mCoverView.getCurrentSong());
|
||||
} else if (!status && mStatus != null) {
|
||||
mStatus.setVisibility(View.GONE);
|
||||
mStatus = null;
|
||||
}
|
||||
|
||||
mDefaultAction = Integer.parseInt(settings.getString("default_action_int", "0"));
|
||||
mLastActedId = 0;
|
||||
}
|
||||
@ -241,8 +268,19 @@ public class SongSelector extends Dialog implements AdapterView.OnItemClickListe
|
||||
|
||||
public void onClick(View view)
|
||||
{
|
||||
int id = view.getId();
|
||||
if (view == mClearButton) {
|
||||
mTextFilter.setText("");
|
||||
} else if (id == R.id.play_pause) {
|
||||
try {
|
||||
((FullPlaybackActivity)getOwnerActivity()).mCoverView.go(0);
|
||||
} catch (RemoteException e) {
|
||||
}
|
||||
} else if (id == R.id.next) {
|
||||
try {
|
||||
((FullPlaybackActivity)getOwnerActivity()).mCoverView.go(1);
|
||||
} catch (RemoteException e) {
|
||||
}
|
||||
} else {
|
||||
int i = (Integer)view.getTag();
|
||||
String[] limiter;
|
||||
@ -379,4 +417,26 @@ public class SongSelector extends Dialog implements AdapterView.OnItemClickListe
|
||||
getAdapter(i).requery();
|
||||
}
|
||||
};
|
||||
|
||||
public void updateSong(Song song)
|
||||
{
|
||||
if (mStatusText != null)
|
||||
mStatusText.setText(song == null ? getContext().getResources().getText(R.string.none) : song.title);
|
||||
}
|
||||
|
||||
public void updateState(int state)
|
||||
{
|
||||
if (mPlayPauseButton != null) {
|
||||
boolean playing = (state & PlaybackService.FLAG_PLAYING) != 0;
|
||||
mPlayPauseButton.setImageResource(playing ? R.drawable.pause : R.drawable.play);
|
||||
}
|
||||
}
|
||||
|
||||
public void change(Intent intent)
|
||||
{
|
||||
if (PlaybackService.EVENT_CHANGED.equals(intent.getAction())) {
|
||||
updateSong((Song)intent.getParcelableExtra("song"));
|
||||
updateState(intent.getIntExtra("state", 0));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user