Make SongSelector an Activity again
This commit is contained in:
parent
c7e10009c2
commit
2ca9c39f1c
@ -15,6 +15,9 @@
|
|||||||
<category android:name="android.intent.category.LAUNCHER" />
|
<category android:name="android.intent.category.LAUNCHER" />
|
||||||
</intent-filter>
|
</intent-filter>
|
||||||
</activity>
|
</activity>
|
||||||
|
<activity
|
||||||
|
android:name="SongSelector"
|
||||||
|
android:theme="@android:style/Theme.Black.NoTitleBar" />
|
||||||
<activity
|
<activity
|
||||||
android:name="MiniPlaybackActivity"
|
android:name="MiniPlaybackActivity"
|
||||||
android:theme="@android:style/Theme.Dialog"
|
android:theme="@android:style/Theme.Dialog"
|
||||||
|
@ -137,11 +137,15 @@ public final class CoverView extends View implements Handler.Callback {
|
|||||||
public void setPlaybackService(IPlaybackService service)
|
public void setPlaybackService(IPlaybackService service)
|
||||||
{
|
{
|
||||||
mService = service;
|
mService = service;
|
||||||
|
|
||||||
|
if (mService != null) {
|
||||||
try {
|
try {
|
||||||
mTimelinePos = mService.getTimelinePos();
|
mTimelinePos = mService.getTimelinePos();
|
||||||
} catch (RemoteException e) {
|
} catch (RemoteException e) {
|
||||||
mService = null;
|
mService = null;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
refreshSongs();
|
refreshSongs();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -428,7 +432,6 @@ public final class CoverView extends View implements Handler.Callback {
|
|||||||
if (mCallback != null)
|
if (mCallback != null)
|
||||||
mCallback.songChanged(mSongs[STORE_SIZE / 2]);
|
mCallback.songChanged(mSongs[STORE_SIZE / 2]);
|
||||||
|
|
||||||
mHandler.sendMessage(mHandler.obtainMessage(SET_SONG, delta, 0));
|
|
||||||
mHandler.sendEmptyMessage(i);
|
mHandler.sendEmptyMessage(i);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -563,6 +566,7 @@ public final class CoverView extends View implements Handler.Callback {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public void computeScroll()
|
public void computeScroll()
|
||||||
{
|
{
|
||||||
if (mScroller.computeScrollOffset()) {
|
if (mScroller.computeScrollOffset()) {
|
||||||
@ -575,21 +579,14 @@ public final class CoverView extends View implements Handler.Callback {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private static final int GO = 10;
|
private static final int GO = 10;
|
||||||
private static final int SET_SONG = 11;
|
|
||||||
|
|
||||||
public boolean handleMessage(Message message)
|
public boolean handleMessage(Message message)
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
switch (message.what) {
|
switch (message.what) {
|
||||||
case GO:
|
case GO:
|
||||||
if (message.arg1 == 0)
|
|
||||||
mService.toggleFlag(PlaybackService.FLAG_PLAYING);
|
|
||||||
else
|
|
||||||
shiftCover(message.arg1);
|
shiftCover(message.arg1);
|
||||||
break;
|
break;
|
||||||
case SET_SONG:
|
|
||||||
mService.setCurrentSong(message.arg1);
|
|
||||||
break;
|
|
||||||
default:
|
default:
|
||||||
int i = message.what;
|
int i = message.what;
|
||||||
if (message.obj == null)
|
if (message.obj == null)
|
||||||
|
@ -21,12 +21,10 @@ package org.kreed.vanilla;
|
|||||||
import org.kreed.vanilla.IPlaybackService;
|
import org.kreed.vanilla.IPlaybackService;
|
||||||
import org.kreed.vanilla.R;
|
import org.kreed.vanilla.R;
|
||||||
|
|
||||||
import android.app.Dialog;
|
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.content.SharedPreferences;
|
import android.content.SharedPreferences;
|
||||||
import android.graphics.Color;
|
import android.graphics.Color;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.os.Handler;
|
|
||||||
import android.os.Message;
|
import android.os.Message;
|
||||||
import android.os.RemoteException;
|
import android.os.RemoteException;
|
||||||
import android.preference.PreferenceManager;
|
import android.preference.PreferenceManager;
|
||||||
@ -40,12 +38,8 @@ import android.widget.LinearLayout;
|
|||||||
import android.widget.RelativeLayout;
|
import android.widget.RelativeLayout;
|
||||||
import android.widget.SeekBar;
|
import android.widget.SeekBar;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
import android.widget.Toast;
|
|
||||||
|
|
||||||
public class FullPlaybackActivity extends PlaybackActivity implements View.OnClickListener, SeekBar.OnSeekBarChangeListener, Handler.Callback, CoverView.Callback {
|
|
||||||
private IPlaybackService mService;
|
|
||||||
private Handler mHandler = new Handler(this);
|
|
||||||
|
|
||||||
|
public class FullPlaybackActivity extends PlaybackActivity implements View.OnClickListener, SeekBar.OnSeekBarChangeListener, CoverView.Callback {
|
||||||
private RelativeLayout mMessageOverlay;
|
private RelativeLayout mMessageOverlay;
|
||||||
private View mControlsTop;
|
private View mControlsTop;
|
||||||
private View mControlsBottom;
|
private View mControlsBottom;
|
||||||
@ -60,17 +54,6 @@ public class FullPlaybackActivity extends PlaybackActivity implements View.OnCli
|
|||||||
private boolean mSeekBarTracking;
|
private boolean mSeekBarTracking;
|
||||||
private boolean mPaused;
|
private boolean mPaused;
|
||||||
|
|
||||||
private static final int SONG_SELECTOR = 8;
|
|
||||||
|
|
||||||
private static final int MENU_QUIT = 0;
|
|
||||||
private static final int MENU_DISPLAY = 1;
|
|
||||||
private static final int MENU_PREFS = 2;
|
|
||||||
private static final int MENU_LIBRARY = 3;
|
|
||||||
private static final int MENU_SHUFFLE = 4;
|
|
||||||
private static final int MENU_PLAYBACK = 5;
|
|
||||||
private static final int MENU_REPEAT = 6;
|
|
||||||
public static final int MENU_SEARCH = 7;
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCreate(Bundle icicle)
|
public void onCreate(Bundle icicle)
|
||||||
{
|
{
|
||||||
@ -78,7 +61,7 @@ public class FullPlaybackActivity extends PlaybackActivity implements View.OnCli
|
|||||||
|
|
||||||
SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(this);
|
SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(this);
|
||||||
if (icicle == null && settings.getBoolean("selector_on_startup", false))
|
if (icicle == null && settings.getBoolean("selector_on_startup", false))
|
||||||
showDialog(SONG_SELECTOR);
|
startActivity(new Intent(this, SongSelector.class));
|
||||||
|
|
||||||
setContentView(R.layout.full_playback);
|
setContentView(R.layout.full_playback);
|
||||||
|
|
||||||
@ -162,8 +145,6 @@ public class FullPlaybackActivity extends PlaybackActivity implements View.OnCli
|
|||||||
{
|
{
|
||||||
super.setService(service);
|
super.setService(service);
|
||||||
|
|
||||||
mService = service;
|
|
||||||
|
|
||||||
if (service != null) {
|
if (service != null) {
|
||||||
try {
|
try {
|
||||||
mDuration = service.getDuration();
|
mDuration = service.getDuration();
|
||||||
@ -180,96 +161,47 @@ public class FullPlaybackActivity extends PlaybackActivity implements View.OnCli
|
|||||||
if (mService != null) {
|
if (mService != null) {
|
||||||
try {
|
try {
|
||||||
mDuration = mService.getDuration();
|
mDuration = mService.getDuration();
|
||||||
mHandler.sendEmptyMessage(UPDATE_PROGRESS);
|
mHandler.sendEmptyMessage(MSG_UPDATE_PROGRESS);
|
||||||
} catch (RemoteException e) {
|
} catch (RemoteException e) {
|
||||||
setService(null);
|
setService(null);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mSongSelector != null)
|
if (mSongSelector != null)
|
||||||
mSongSelector.change(intent);
|
mSongSelector.onServiceChange(intent);
|
||||||
}
|
|
||||||
|
|
||||||
public void fillMenu(Menu menu, boolean fromDialog)
|
|
||||||
{
|
|
||||||
if (fromDialog) {
|
|
||||||
menu.add(0, MENU_PLAYBACK, 0, R.string.playback_view).setIcon(android.R.drawable.ic_menu_gallery);
|
|
||||||
menu.add(0, MENU_SEARCH, 0, R.string.search).setIcon(android.R.drawable.ic_menu_search);
|
|
||||||
} else {
|
|
||||||
menu.add(0, MENU_LIBRARY, 0, R.string.library).setIcon(android.R.drawable.ic_menu_add);
|
|
||||||
menu.add(0, MENU_DISPLAY, 0, R.string.display_mode).setIcon(android.R.drawable.ic_menu_gallery);
|
|
||||||
}
|
|
||||||
menu.add(0, MENU_PREFS, 0, R.string.settings).setIcon(android.R.drawable.ic_menu_preferences);
|
|
||||||
menu.add(0, MENU_SHUFFLE, 0, R.string.shuffle_enable).setIcon(R.drawable.ic_menu_shuffle);
|
|
||||||
menu.add(0, MENU_REPEAT, 0, R.string.repeat_enable).setIcon(R.drawable.ic_menu_refresh);
|
|
||||||
menu.add(0, MENU_QUIT, 0, R.string.quit).setIcon(android.R.drawable.ic_menu_close_clear_cancel);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onCreateOptionsMenu(Menu menu)
|
public boolean onCreateOptionsMenu(Menu menu)
|
||||||
{
|
{
|
||||||
fillMenu(menu, false);
|
menu.add(0, MENU_LIBRARY, 0, R.string.library).setIcon(android.R.drawable.ic_menu_add);
|
||||||
return true;
|
menu.add(0, MENU_DISPLAY, 0, R.string.display_mode).setIcon(android.R.drawable.ic_menu_gallery);
|
||||||
}
|
return super.onCreateOptionsMenu(menu);
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean onPrepareOptionsMenu(Menu menu)
|
|
||||||
{
|
|
||||||
boolean isShuffling = (mState & PlaybackService.FLAG_SHUFFLE) != 0;
|
|
||||||
menu.findItem(MENU_SHUFFLE).setTitle(isShuffling ? R.string.shuffle_disable : R.string.shuffle_enable);
|
|
||||||
boolean isRepeating = (mState & PlaybackService.FLAG_REPEAT) != 0;
|
|
||||||
menu.findItem(MENU_REPEAT).setTitle(isRepeating ? R.string.repeat_disable : R.string.repeat_enable);
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onOptionsItemSelected(MenuItem item)
|
public boolean onOptionsItemSelected(MenuItem item)
|
||||||
{
|
{
|
||||||
switch (item.getItemId()) {
|
switch (item.getItemId()) {
|
||||||
case MENU_QUIT:
|
|
||||||
ContextApplication.quit(this);
|
|
||||||
break;
|
|
||||||
case MENU_SHUFFLE:
|
|
||||||
mHandler.sendMessage(mHandler.obtainMessage(TOGGLE_FLAG, PlaybackService.FLAG_SHUFFLE, 0));
|
|
||||||
break;
|
|
||||||
case MENU_REPEAT:
|
|
||||||
mHandler.sendMessage(mHandler.obtainMessage(TOGGLE_FLAG, PlaybackService.FLAG_REPEAT, 0));
|
|
||||||
break;
|
|
||||||
case MENU_PREFS:
|
|
||||||
startActivity(new Intent(this, PreferencesActivity.class));
|
|
||||||
break;
|
|
||||||
case MENU_PLAYBACK:
|
|
||||||
dismissDialog(SONG_SELECTOR);
|
|
||||||
break;
|
|
||||||
case MENU_LIBRARY:
|
case MENU_LIBRARY:
|
||||||
showDialog(SONG_SELECTOR);
|
startActivity(new Intent(this, SongSelector.class));
|
||||||
break;
|
return true;
|
||||||
case MENU_DISPLAY:
|
case MENU_DISPLAY:
|
||||||
mCoverView.toggleDisplayMode();
|
mCoverView.toggleDisplayMode();
|
||||||
mHandler.sendEmptyMessage(SAVE_DISPLAY_MODE);
|
mHandler.sendEmptyMessage(MSG_SAVE_DISPLAY_MODE);
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
default:
|
||||||
|
return super.onOptionsItemSelected(item);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onSearchRequested()
|
public boolean onSearchRequested()
|
||||||
{
|
{
|
||||||
showDialog(SONG_SELECTOR);
|
startActivity(new Intent(this, SongSelector.class));
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public Dialog onCreateDialog(int id)
|
|
||||||
{
|
|
||||||
if (id == SONG_SELECTOR) {
|
|
||||||
mSongSelector = new SongSelector(this);
|
|
||||||
return mSongSelector;
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onKeyUp(int keyCode, KeyEvent event)
|
public boolean onKeyUp(int keyCode, KeyEvent event)
|
||||||
{
|
{
|
||||||
@ -283,6 +215,9 @@ public class FullPlaybackActivity extends PlaybackActivity implements View.OnCli
|
|||||||
return super.onKeyUp(keyCode, event);
|
return super.onKeyUp(keyCode, event);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Converts a duration in milliseconds to [HH:]MM:SS
|
||||||
|
*/
|
||||||
private String stringForTime(int ms)
|
private String stringForTime(int ms)
|
||||||
{
|
{
|
||||||
int seconds = ms / 1000;
|
int seconds = ms / 1000;
|
||||||
@ -298,6 +233,9 @@ public class FullPlaybackActivity extends PlaybackActivity implements View.OnCli
|
|||||||
return String.format("%02d:%02d", minutes, seconds);
|
return String.format("%02d:%02d", minutes, seconds);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Update seek bar progress and schedule another update in one second
|
||||||
|
*/
|
||||||
private void updateProgress()
|
private void updateProgress()
|
||||||
{
|
{
|
||||||
if (mPaused || mControlsTop.getVisibility() != View.VISIBLE || (mState & PlaybackService.FLAG_PLAYING) == 0)
|
if (mPaused || mControlsTop.getVisibility() != View.VISIBLE || (mState & PlaybackService.FLAG_PLAYING) == 0)
|
||||||
@ -315,11 +253,13 @@ public class FullPlaybackActivity extends PlaybackActivity implements View.OnCli
|
|||||||
mSeekBar.setProgress(mDuration == 0 ? 0 : (int)(1000 * position / mDuration));
|
mSeekBar.setProgress(mDuration == 0 ? 0 : (int)(1000 * position / mDuration));
|
||||||
mSeekText.setText(stringForTime((int)position) + " / " + stringForTime(mDuration));
|
mSeekText.setText(stringForTime((int)position) + " / " + stringForTime(mDuration));
|
||||||
|
|
||||||
|
// Try to update right when the duration increases by one second
|
||||||
long next = 1000 - position % 1000;
|
long next = 1000 - position % 1000;
|
||||||
mHandler.removeMessages(UPDATE_PROGRESS);
|
mHandler.removeMessages(MSG_UPDATE_PROGRESS);
|
||||||
mHandler.sendEmptyMessageDelayed(UPDATE_PROGRESS, next);
|
mHandler.sendEmptyMessageDelayed(MSG_UPDATE_PROGRESS, next);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public void onClick(View view)
|
public void onClick(View view)
|
||||||
{
|
{
|
||||||
if (view == mCoverView) {
|
if (view == mCoverView) {
|
||||||
@ -339,45 +279,25 @@ public class FullPlaybackActivity extends PlaybackActivity implements View.OnCli
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static final int UPDATE_PROGRESS = 1;
|
private static final int MSG_UPDATE_PROGRESS = 10;
|
||||||
private static final int SAVE_DISPLAY_MODE = 2;
|
private static final int MSG_SAVE_DISPLAY_MODE = 11;
|
||||||
private static final int TOGGLE_FLAG = 3;
|
|
||||||
|
|
||||||
|
@Override
|
||||||
public boolean handleMessage(Message message)
|
public boolean handleMessage(Message message)
|
||||||
{
|
{
|
||||||
switch (message.what) {
|
switch (message.what) {
|
||||||
case UPDATE_PROGRESS:
|
case MSG_UPDATE_PROGRESS:
|
||||||
updateProgress();
|
updateProgress();
|
||||||
break;
|
return true;
|
||||||
case SAVE_DISPLAY_MODE:
|
case MSG_SAVE_DISPLAY_MODE:
|
||||||
SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(FullPlaybackActivity.this);
|
SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(FullPlaybackActivity.this);
|
||||||
SharedPreferences.Editor editor = settings.edit();
|
SharedPreferences.Editor editor = settings.edit();
|
||||||
editor.putBoolean("separate_info", mCoverView.hasSeparateInfo());
|
editor.putBoolean("separate_info", mCoverView.hasSeparateInfo());
|
||||||
editor.commit();
|
editor.commit();
|
||||||
break;
|
|
||||||
case TOGGLE_FLAG:
|
|
||||||
int flag = message.arg1;
|
|
||||||
boolean enabling = (mState & flag) == 0;
|
|
||||||
int text = -1;
|
|
||||||
if (flag == PlaybackService.FLAG_SHUFFLE)
|
|
||||||
text = enabling ? R.string.shuffle_enabling : R.string.shuffle_disabling;
|
|
||||||
else if (flag == PlaybackService.FLAG_REPEAT)
|
|
||||||
text = enabling ? R.string.repeat_enabling : R.string.repeat_disabling;
|
|
||||||
|
|
||||||
if (text != -1)
|
|
||||||
Toast.makeText(FullPlaybackActivity.this, text, Toast.LENGTH_SHORT).show();
|
|
||||||
|
|
||||||
try {
|
|
||||||
mService.toggleFlag(flag);
|
|
||||||
} catch (RemoteException e) {
|
|
||||||
setService(null);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
default:
|
||||||
|
return super.handleMessage(message);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser)
|
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser)
|
||||||
|
@ -29,9 +29,11 @@ import android.view.ViewGroup;
|
|||||||
import android.view.Window;
|
import android.view.Window;
|
||||||
import android.widget.ImageView;
|
import android.widget.ImageView;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Playback activity that displays itself like a dialog, i.e. as a small window
|
||||||
|
* with a border. Includes a CoverView and control buttons.
|
||||||
|
*/
|
||||||
public class MiniPlaybackActivity extends PlaybackActivity implements View.OnClickListener {
|
public class MiniPlaybackActivity extends PlaybackActivity implements View.OnClickListener {
|
||||||
private View mOpenButton;
|
|
||||||
private View mKillButton;
|
|
||||||
private ImageView mPlayPauseButton;
|
private ImageView mPlayPauseButton;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -44,10 +46,10 @@ public class MiniPlaybackActivity extends PlaybackActivity implements View.OnCli
|
|||||||
|
|
||||||
mCoverView = (CoverView)findViewById(R.id.cover_view);
|
mCoverView = (CoverView)findViewById(R.id.cover_view);
|
||||||
|
|
||||||
mOpenButton = findViewById(R.id.open_button);
|
View openButton = findViewById(R.id.open_button);
|
||||||
mOpenButton.setOnClickListener(this);
|
openButton.setOnClickListener(this);
|
||||||
mKillButton = findViewById(R.id.kill_button);
|
View killButton = findViewById(R.id.kill_button);
|
||||||
mKillButton.setOnClickListener(this);
|
killButton.setOnClickListener(this);
|
||||||
View previousButton = findViewById(R.id.previous);
|
View previousButton = findViewById(R.id.previous);
|
||||||
previousButton.setOnClickListener(this);
|
previousButton.setOnClickListener(this);
|
||||||
mPlayPauseButton = (ImageView)findViewById(R.id.play_pause);
|
mPlayPauseButton = (ImageView)findViewById(R.id.play_pause);
|
||||||
@ -65,23 +67,28 @@ public class MiniPlaybackActivity extends PlaybackActivity implements View.OnCli
|
|||||||
mPlayPauseButton.setImageResource((state & PlaybackService.FLAG_PLAYING) == 0 ? R.drawable.play : R.drawable.pause);
|
mPlayPauseButton.setImageResource((state & PlaybackService.FLAG_PLAYING) == 0 ? R.drawable.play : R.drawable.pause);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public void onClick(View view)
|
public void onClick(View view)
|
||||||
{
|
{
|
||||||
if (view == mKillButton) {
|
switch (view.getId()) {
|
||||||
|
case R.id.kill_button:
|
||||||
ContextApplication.quit(this);
|
ContextApplication.quit(this);
|
||||||
} else if (view == mOpenButton) {
|
break;
|
||||||
|
case R.id.open_button:
|
||||||
startActivity(new Intent(this, FullPlaybackActivity.class));
|
startActivity(new Intent(this, FullPlaybackActivity.class));
|
||||||
finish();
|
finish();
|
||||||
} else {
|
break;
|
||||||
|
default:
|
||||||
super.onClick(view);
|
super.onClick(view);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/**
|
||||||
* Custom layout that acts like a very simple vertical LinearLayout with
|
* Custom layout that acts like a very simple vertical LinearLayout with
|
||||||
* special case: CoverViews will be made square at all costs.
|
* special case: CoverViews will be made square at all costs.
|
||||||
*
|
*/
|
||||||
|
/*
|
||||||
* I would prefer this to be a nested class, but it does not seem like
|
* I would prefer this to be a nested class, but it does not seem like
|
||||||
* Android's layout inflater supports referencing nested classes in XML.
|
* Android's layout inflater supports referencing nested classes in XML.
|
||||||
*/
|
*/
|
||||||
|
@ -26,14 +26,23 @@ import android.content.Intent;
|
|||||||
import android.content.IntentFilter;
|
import android.content.IntentFilter;
|
||||||
import android.content.ServiceConnection;
|
import android.content.ServiceConnection;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
|
import android.os.Handler;
|
||||||
import android.os.IBinder;
|
import android.os.IBinder;
|
||||||
|
import android.os.Message;
|
||||||
import android.os.RemoteException;
|
import android.os.RemoteException;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
import android.view.KeyEvent;
|
import android.view.KeyEvent;
|
||||||
|
import android.view.Menu;
|
||||||
|
import android.view.MenuItem;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
|
import android.widget.Toast;
|
||||||
|
|
||||||
|
public class PlaybackActivity extends Activity implements ServiceConnection, Handler.Callback {
|
||||||
|
Handler mHandler = new Handler(this);
|
||||||
|
|
||||||
public abstract class PlaybackActivity extends Activity implements ServiceConnection {
|
|
||||||
CoverView mCoverView;
|
CoverView mCoverView;
|
||||||
|
IPlaybackService mService;
|
||||||
|
int mState;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCreate(Bundle state)
|
public void onCreate(Bundle state)
|
||||||
@ -103,13 +112,17 @@ public abstract class PlaybackActivity extends Activity implements ServiceConnec
|
|||||||
try {
|
try {
|
||||||
switch (view.getId()) {
|
switch (view.getId()) {
|
||||||
case R.id.next:
|
case R.id.next:
|
||||||
|
if (mCoverView != null)
|
||||||
mCoverView.go(1);
|
mCoverView.go(1);
|
||||||
|
mHandler.sendMessage(mHandler.obtainMessage(MSG_SET_SONG, 1, 0));
|
||||||
break;
|
break;
|
||||||
case R.id.play_pause:
|
case R.id.play_pause:
|
||||||
mCoverView.go(0);
|
mHandler.sendMessage(mHandler.obtainMessage(MSG_TOGGLE_FLAG, PlaybackService.FLAG_PLAYING, 0));
|
||||||
break;
|
break;
|
||||||
case R.id.previous:
|
case R.id.previous:
|
||||||
|
if (mCoverView != null)
|
||||||
mCoverView.go(-1);
|
mCoverView.go(-1);
|
||||||
|
mHandler.sendMessage(mHandler.obtainMessage(MSG_SET_SONG, -1, 0));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
} catch (RemoteException e) {
|
} catch (RemoteException e) {
|
||||||
@ -118,12 +131,31 @@ public abstract class PlaybackActivity extends Activity implements ServiceConnec
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected abstract void setState(int state);
|
/**
|
||||||
|
* Sets <code>mState</code> to <code>state</code>. Override to implement
|
||||||
|
* further behavior in subclasses.
|
||||||
|
*
|
||||||
|
* @param state PlaybackService state
|
||||||
|
*/
|
||||||
|
protected void setState(int state)
|
||||||
|
{
|
||||||
|
mState = state;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets up components when the PlaybackService is bound to. Override to
|
||||||
|
* implement further post-connection behavior.
|
||||||
|
*
|
||||||
|
* @param service PlaybackService interface
|
||||||
|
*/
|
||||||
protected void setService(IPlaybackService service)
|
protected void setService(IPlaybackService service)
|
||||||
{
|
{
|
||||||
if (service != null) {
|
mService = service;
|
||||||
|
|
||||||
|
if (mCoverView != null)
|
||||||
mCoverView.setPlaybackService(service);
|
mCoverView.setPlaybackService(service);
|
||||||
|
|
||||||
|
if (service != null) {
|
||||||
try {
|
try {
|
||||||
setState(service.getState());
|
setState(service.getState());
|
||||||
} catch (RemoteException e) {
|
} catch (RemoteException e) {
|
||||||
@ -150,9 +182,105 @@ public abstract class PlaybackActivity extends Activity implements ServiceConnec
|
|||||||
@Override
|
@Override
|
||||||
public void onReceive(Context context, Intent intent)
|
public void onReceive(Context context, Intent intent)
|
||||||
{
|
{
|
||||||
|
if (mCoverView != null)
|
||||||
mCoverView.onReceive(intent);
|
mCoverView.onReceive(intent);
|
||||||
if (PlaybackService.EVENT_CHANGED.equals(intent.getAction()))
|
if (PlaybackService.EVENT_CHANGED.equals(intent.getAction()))
|
||||||
onServiceChange(intent);
|
onServiceChange(intent);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
static final int MENU_QUIT = 0;
|
||||||
|
static final int MENU_DISPLAY = 1;
|
||||||
|
static final int MENU_PREFS = 2;
|
||||||
|
static final int MENU_LIBRARY = 3;
|
||||||
|
static final int MENU_SHUFFLE = 4;
|
||||||
|
static final int MENU_PLAYBACK = 5;
|
||||||
|
static final int MENU_REPEAT = 6;
|
||||||
|
static final int MENU_SEARCH = 7;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean onCreateOptionsMenu(Menu menu)
|
||||||
|
{
|
||||||
|
menu.add(0, MENU_PREFS, 0, R.string.settings).setIcon(android.R.drawable.ic_menu_preferences);
|
||||||
|
menu.add(0, MENU_SHUFFLE, 0, R.string.shuffle_enable).setIcon(R.drawable.ic_menu_shuffle);
|
||||||
|
menu.add(0, MENU_REPEAT, 0, R.string.repeat_enable).setIcon(R.drawable.ic_menu_refresh);
|
||||||
|
menu.add(0, MENU_QUIT, 0, R.string.quit).setIcon(android.R.drawable.ic_menu_close_clear_cancel);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean onPrepareOptionsMenu(Menu menu)
|
||||||
|
{
|
||||||
|
boolean isShuffling = (mState & PlaybackService.FLAG_SHUFFLE) != 0;
|
||||||
|
menu.findItem(MENU_SHUFFLE).setTitle(isShuffling ? R.string.shuffle_disable : R.string.shuffle_enable);
|
||||||
|
boolean isRepeating = (mState & PlaybackService.FLAG_REPEAT) != 0;
|
||||||
|
menu.findItem(MENU_REPEAT).setTitle(isRepeating ? R.string.repeat_disable : R.string.repeat_enable);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean onOptionsItemSelected(MenuItem item)
|
||||||
|
{
|
||||||
|
switch (item.getItemId()) {
|
||||||
|
case MENU_QUIT:
|
||||||
|
ContextApplication.quit(this);
|
||||||
|
return true;
|
||||||
|
case MENU_SHUFFLE:
|
||||||
|
mHandler.sendMessage(mHandler.obtainMessage(MSG_TOGGLE_FLAG, PlaybackService.FLAG_SHUFFLE, 0));
|
||||||
|
return true;
|
||||||
|
case MENU_REPEAT:
|
||||||
|
mHandler.sendMessage(mHandler.obtainMessage(MSG_TOGGLE_FLAG, PlaybackService.FLAG_REPEAT, 0));
|
||||||
|
return true;
|
||||||
|
case MENU_PREFS:
|
||||||
|
startActivity(new Intent(this, PreferencesActivity.class));
|
||||||
|
return true;
|
||||||
|
default:
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Tell PlaybackService to toggle a state flag (passed as arg1) and display
|
||||||
|
* a message notifying that the flag was toggled.
|
||||||
|
*/
|
||||||
|
static final int MSG_TOGGLE_FLAG = 0;
|
||||||
|
/**
|
||||||
|
* Tell PlaybackService to move to a song a position delta (passed as arg1).
|
||||||
|
*/
|
||||||
|
static final int MSG_SET_SONG = 1;
|
||||||
|
|
||||||
|
public boolean handleMessage(Message message)
|
||||||
|
{
|
||||||
|
switch (message.what) {
|
||||||
|
case MSG_TOGGLE_FLAG:
|
||||||
|
int flag = message.arg1;
|
||||||
|
boolean enabling = (mState & flag) == 0;
|
||||||
|
int text = -1;
|
||||||
|
if (flag == PlaybackService.FLAG_SHUFFLE)
|
||||||
|
text = enabling ? R.string.shuffle_enabling : R.string.shuffle_disabling;
|
||||||
|
else if (flag == PlaybackService.FLAG_REPEAT)
|
||||||
|
text = enabling ? R.string.repeat_enabling : R.string.repeat_disabling;
|
||||||
|
|
||||||
|
if (text != -1)
|
||||||
|
Toast.makeText(this, text, Toast.LENGTH_SHORT).show();
|
||||||
|
|
||||||
|
try {
|
||||||
|
mService.toggleFlag(flag);
|
||||||
|
} catch (RemoteException e) {
|
||||||
|
setService(null);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case MSG_SET_SONG:
|
||||||
|
try {
|
||||||
|
mService.setCurrentSong(message.arg1);
|
||||||
|
} catch (RemoteException e) {
|
||||||
|
setService(null);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
@ -20,9 +20,7 @@ package org.kreed.vanilla;
|
|||||||
|
|
||||||
import org.kreed.vanilla.R;
|
import org.kreed.vanilla.R;
|
||||||
|
|
||||||
import android.app.Dialog;
|
|
||||||
import android.content.ContentResolver;
|
import android.content.ContentResolver;
|
||||||
import android.content.Context;
|
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.content.SharedPreferences;
|
import android.content.SharedPreferences;
|
||||||
import android.content.res.Resources;
|
import android.content.res.Resources;
|
||||||
@ -31,9 +29,7 @@ import android.graphics.Color;
|
|||||||
import android.graphics.drawable.PaintDrawable;
|
import android.graphics.drawable.PaintDrawable;
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.os.Handler;
|
|
||||||
import android.os.Message;
|
import android.os.Message;
|
||||||
import android.os.RemoteException;
|
|
||||||
import android.preference.PreferenceManager;
|
import android.preference.PreferenceManager;
|
||||||
import android.provider.MediaStore;
|
import android.provider.MediaStore;
|
||||||
import android.text.Editable;
|
import android.text.Editable;
|
||||||
@ -47,7 +43,6 @@ import android.view.MenuItem;
|
|||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
import android.view.ViewStub;
|
import android.view.ViewStub;
|
||||||
import android.view.Window;
|
|
||||||
import android.widget.AdapterView;
|
import android.widget.AdapterView;
|
||||||
import android.widget.Filter;
|
import android.widget.Filter;
|
||||||
import android.widget.LinearLayout;
|
import android.widget.LinearLayout;
|
||||||
@ -56,11 +51,7 @@ import android.widget.TabHost;
|
|||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
import android.widget.Toast;
|
import android.widget.Toast;
|
||||||
|
|
||||||
public class SongSelector extends Dialog implements AdapterView.OnItemClickListener, TextWatcher, View.OnClickListener, TabHost.OnTabChangeListener, Filter.FilterListener, Handler.Callback {
|
public class SongSelector extends PlaybackActivity implements AdapterView.OnItemClickListener, TextWatcher, View.OnClickListener, TabHost.OnTabChangeListener, Filter.FilterListener {
|
||||||
private static final int MSG_INIT = 0;
|
|
||||||
|
|
||||||
private Handler mHandler = new Handler(this);
|
|
||||||
|
|
||||||
private TabHost mTabHost;
|
private TabHost mTabHost;
|
||||||
|
|
||||||
private View mSearchBox;
|
private View mSearchBox;
|
||||||
@ -74,7 +65,6 @@ public class SongSelector extends Dialog implements AdapterView.OnItemClickListe
|
|||||||
|
|
||||||
private ViewGroup mLimiterViews;
|
private ViewGroup mLimiterViews;
|
||||||
|
|
||||||
private boolean mOnStartUp;
|
|
||||||
private int mDefaultAction;
|
private int mDefaultAction;
|
||||||
private boolean mDefaultIsLastAction;
|
private boolean mDefaultIsLastAction;
|
||||||
|
|
||||||
@ -91,24 +81,21 @@ public class SongSelector extends Dialog implements AdapterView.OnItemClickListe
|
|||||||
ListView view = (ListView)findViewById(id);
|
ListView view = (ListView)findViewById(id);
|
||||||
view.setOnItemClickListener(this);
|
view.setOnItemClickListener(this);
|
||||||
view.setOnCreateContextMenuListener(this);
|
view.setOnCreateContextMenuListener(this);
|
||||||
view.setAdapter(new MediaAdapter(getContext(), store, fields, fieldKeys, true));
|
view.setAdapter(new MediaAdapter(this, store, fields, fieldKeys, true));
|
||||||
}
|
|
||||||
|
|
||||||
public SongSelector(Context context)
|
|
||||||
{
|
|
||||||
super(context, android.R.style.Theme_NoTitleBar);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCreate(Bundle state)
|
public void onCreate(Bundle state)
|
||||||
{
|
{
|
||||||
|
super.onCreate(state);
|
||||||
|
|
||||||
setContentView(R.layout.song_selector);
|
setContentView(R.layout.song_selector);
|
||||||
|
|
||||||
mTabHost = (TabHost)findViewById(android.R.id.tabhost);
|
mTabHost = (TabHost)findViewById(android.R.id.tabhost);
|
||||||
mTabHost.setup();
|
mTabHost.setup();
|
||||||
mTabHost.setOnTabChangedListener(this);
|
mTabHost.setOnTabChangedListener(this);
|
||||||
|
|
||||||
Resources res = getContext().getResources();
|
Resources res = getResources();
|
||||||
mTabHost.addTab(mTabHost.newTabSpec("tab_artists").setIndicator(res.getText(R.string.artists), res.getDrawable(R.drawable.tab_artists)).setContent(R.id.artist_list));
|
mTabHost.addTab(mTabHost.newTabSpec("tab_artists").setIndicator(res.getText(R.string.artists), res.getDrawable(R.drawable.tab_artists)).setContent(R.id.artist_list));
|
||||||
mTabHost.addTab(mTabHost.newTabSpec("tab_albums").setIndicator(res.getText(R.string.albums), res.getDrawable(R.drawable.tab_albums)).setContent(R.id.album_list));
|
mTabHost.addTab(mTabHost.newTabSpec("tab_albums").setIndicator(res.getText(R.string.albums), res.getDrawable(R.drawable.tab_albums)).setContent(R.id.album_list));
|
||||||
mTabHost.addTab(mTabHost.newTabSpec("tab_songs").setIndicator(res.getText(R.string.songs), res.getDrawable(R.drawable.tab_songs)).setContent(R.id.song_list));
|
mTabHost.addTab(mTabHost.newTabSpec("tab_songs").setIndicator(res.getText(R.string.songs), res.getDrawable(R.drawable.tab_songs)).setContent(R.id.song_list));
|
||||||
@ -129,21 +116,12 @@ public class SongSelector extends Dialog implements AdapterView.OnItemClickListe
|
|||||||
@Override
|
@Override
|
||||||
public void onStart()
|
public void onStart()
|
||||||
{
|
{
|
||||||
// reset queue pos
|
super.onStart();
|
||||||
Context context = getContext();
|
|
||||||
context.startService(new Intent(context, PlaybackService.class));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(this);
|
||||||
public void onWindowFocusChanged(boolean hasFocus)
|
|
||||||
{
|
|
||||||
if (hasFocus) {
|
|
||||||
SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(getContext());
|
|
||||||
int inputType = settings.getBoolean("filter_suggestions", false) ? InputType.TYPE_CLASS_TEXT : InputType.TYPE_TEXT_VARIATION_FILTER;
|
int inputType = settings.getBoolean("filter_suggestions", false) ? InputType.TYPE_CLASS_TEXT : InputType.TYPE_TEXT_VARIATION_FILTER;
|
||||||
mTextFilter.setInputType(inputType);
|
mTextFilter.setInputType(inputType);
|
||||||
|
|
||||||
mOnStartUp = settings.getBoolean("selector_on_startup", false);
|
|
||||||
|
|
||||||
boolean status = settings.getBoolean("selector_status", false);
|
boolean status = settings.getBoolean("selector_status", false);
|
||||||
if (status && mStatus == null) {
|
if (status && mStatus == null) {
|
||||||
mStatus = findViewById(R.id.status);
|
mStatus = findViewById(R.id.status);
|
||||||
@ -155,10 +133,6 @@ public class SongSelector extends Dialog implements AdapterView.OnItemClickListe
|
|||||||
|
|
||||||
mPlayPauseButton.setOnClickListener(this);
|
mPlayPauseButton.setOnClickListener(this);
|
||||||
next.setOnClickListener(this);
|
next.setOnClickListener(this);
|
||||||
|
|
||||||
FullPlaybackActivity owner = (FullPlaybackActivity)getOwnerActivity();
|
|
||||||
updateState(owner.mState);
|
|
||||||
updateSong(owner.mCoverView.getCurrentSong());
|
|
||||||
} else if (!status && mStatus != null) {
|
} else if (!status && mStatus != null) {
|
||||||
mStatus.setVisibility(View.GONE);
|
mStatus.setVisibility(View.GONE);
|
||||||
mStatus = null;
|
mStatus = null;
|
||||||
@ -167,7 +141,6 @@ public class SongSelector extends Dialog implements AdapterView.OnItemClickListe
|
|||||||
mDefaultAction = Integer.parseInt(settings.getString("default_action_int", "0"));
|
mDefaultAction = Integer.parseInt(settings.getString("default_action_int", "0"));
|
||||||
mLastActedId = 0;
|
mLastActedId = 0;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onKeyDown(int keyCode, KeyEvent event)
|
public boolean onKeyDown(int keyCode, KeyEvent event)
|
||||||
@ -177,10 +150,8 @@ public class SongSelector extends Dialog implements AdapterView.OnItemClickListe
|
|||||||
if (mSearchBoxVisible) {
|
if (mSearchBoxVisible) {
|
||||||
mTextFilter.setText("");
|
mTextFilter.setText("");
|
||||||
setSearchBoxVisible(false);
|
setSearchBoxVisible(false);
|
||||||
} else if (mOnStartUp) {
|
|
||||||
getOwnerActivity().finish();
|
|
||||||
} else {
|
} else {
|
||||||
dismiss();
|
finish();
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
case KeyEvent.KEYCODE_SEARCH:
|
case KeyEvent.KEYCODE_SEARCH:
|
||||||
@ -205,17 +176,17 @@ public class SongSelector extends Dialog implements AdapterView.OnItemClickListe
|
|||||||
private void sendSongIntent(MediaAdapter.MediaView view, int action)
|
private void sendSongIntent(MediaAdapter.MediaView view, int action)
|
||||||
{
|
{
|
||||||
int res = action == PlaybackService.ACTION_PLAY ? R.string.playing : R.string.enqueued;
|
int res = action == PlaybackService.ACTION_PLAY ? R.string.playing : R.string.enqueued;
|
||||||
String text = getContext().getResources().getString(res, view.getTitle());
|
String text = getResources().getString(res, view.getTitle());
|
||||||
Toast.makeText(getContext(), text, Toast.LENGTH_SHORT).show();
|
Toast.makeText(this, text, Toast.LENGTH_SHORT).show();
|
||||||
|
|
||||||
long id = view.getMediaId();
|
long id = view.getMediaId();
|
||||||
int field = view.getFieldCount();
|
int field = view.getFieldCount();
|
||||||
|
|
||||||
Intent intent = new Intent(getContext(), PlaybackService.class);
|
Intent intent = new Intent(this, PlaybackService.class);
|
||||||
intent.putExtra("type", field);
|
intent.putExtra("type", field);
|
||||||
intent.putExtra("action", action);
|
intent.putExtra("action", action);
|
||||||
intent.putExtra("id", id);
|
intent.putExtra("id", id);
|
||||||
getContext().startService(intent);
|
startService(intent);
|
||||||
|
|
||||||
mLastActedId = id;
|
mLastActedId = id;
|
||||||
}
|
}
|
||||||
@ -237,7 +208,7 @@ public class SongSelector extends Dialog implements AdapterView.OnItemClickListe
|
|||||||
if (mediaView.isExpanderPressed())
|
if (mediaView.isExpanderPressed())
|
||||||
expand(mediaView);
|
expand(mediaView);
|
||||||
else if (id == mLastActedId)
|
else if (id == mLastActedId)
|
||||||
dismiss();
|
finish();
|
||||||
else
|
else
|
||||||
sendSongIntent(mediaView, mDefaultAction);
|
sendSongIntent(mediaView, mDefaultAction);
|
||||||
}
|
}
|
||||||
@ -278,7 +249,7 @@ public class SongSelector extends Dialog implements AdapterView.OnItemClickListe
|
|||||||
PaintDrawable background = new PaintDrawable(Color.GRAY);
|
PaintDrawable background = new PaintDrawable(Color.GRAY);
|
||||||
background.setCornerRadius(5);
|
background.setCornerRadius(5);
|
||||||
|
|
||||||
TextView view = new TextView(getContext());
|
TextView view = new TextView(this);
|
||||||
view.setSingleLine();
|
view.setSingleLine();
|
||||||
view.setEllipsize(TextUtils.TruncateAt.MARQUEE);
|
view.setEllipsize(TextUtils.TruncateAt.MARQUEE);
|
||||||
view.setText(limiter[i] + " | X");
|
view.setText(limiter[i] + " | X");
|
||||||
@ -297,25 +268,15 @@ public class SongSelector extends Dialog implements AdapterView.OnItemClickListe
|
|||||||
updateLimiterViews();
|
updateLimiterViews();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public void onClick(View view)
|
public void onClick(View view)
|
||||||
{
|
{
|
||||||
int id = view.getId();
|
|
||||||
if (view == mClearButton) {
|
if (view == mClearButton) {
|
||||||
if (mTextFilter.getText().length() == 0)
|
if (mTextFilter.getText().length() == 0)
|
||||||
setSearchBoxVisible(false);
|
setSearchBoxVisible(false);
|
||||||
else
|
else
|
||||||
mTextFilter.setText("");
|
mTextFilter.setText("");
|
||||||
} else if (id == R.id.play_pause) {
|
} else if (view.getTag() != null) {
|
||||||
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();
|
int i = (Integer)view.getTag();
|
||||||
String[] limiter;
|
String[] limiter;
|
||||||
if (i == 0) {
|
if (i == 0) {
|
||||||
@ -333,6 +294,8 @@ public class SongSelector extends Dialog implements AdapterView.OnItemClickListe
|
|||||||
}
|
}
|
||||||
|
|
||||||
updateLimiterViews();
|
updateLimiterViews();
|
||||||
|
} else {
|
||||||
|
super.onClick(view);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -377,39 +340,23 @@ public class SongSelector extends Dialog implements AdapterView.OnItemClickListe
|
|||||||
@Override
|
@Override
|
||||||
public boolean onCreateOptionsMenu(Menu menu)
|
public boolean onCreateOptionsMenu(Menu menu)
|
||||||
{
|
{
|
||||||
((FullPlaybackActivity)getOwnerActivity()).fillMenu(menu, true);
|
menu.add(0, MENU_PLAYBACK, 0, R.string.playback_view).setIcon(android.R.drawable.ic_menu_gallery);
|
||||||
return true;
|
menu.add(0, MENU_SEARCH, 0, R.string.search).setIcon(android.R.drawable.ic_menu_search);
|
||||||
}
|
return super.onCreateOptionsMenu(menu);
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean onPrepareOptionsMenu(Menu menu)
|
|
||||||
{
|
|
||||||
return ((FullPlaybackActivity)getOwnerActivity()).onPrepareOptionsMenu(menu);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onOptionsItemSelected(MenuItem item)
|
public boolean onOptionsItemSelected(MenuItem item)
|
||||||
{
|
{
|
||||||
if (item.getItemId() == FullPlaybackActivity.MENU_SEARCH) {
|
switch (item.getItemId()) {
|
||||||
|
case MENU_SEARCH:
|
||||||
setSearchBoxVisible(!mSearchBoxVisible);
|
setSearchBoxVisible(!mSearchBoxVisible);
|
||||||
return true;
|
return true;
|
||||||
}
|
case MENU_PLAYBACK:
|
||||||
|
startActivity(new Intent(this, FullPlaybackActivity.class));
|
||||||
return ((FullPlaybackActivity)getOwnerActivity()).onOptionsItemSelected(item);
|
return true;
|
||||||
}
|
|
||||||
|
|
||||||
// onContextItemSelected and friends are not called when they should be. Do
|
|
||||||
// so here to work around this bug.
|
|
||||||
@Override
|
|
||||||
public boolean onMenuItemSelected(int featureId, MenuItem item)
|
|
||||||
{
|
|
||||||
switch (featureId) {
|
|
||||||
case Window.FEATURE_CONTEXT_MENU:
|
|
||||||
return onContextItemSelected(item);
|
|
||||||
case Window.FEATURE_OPTIONS_PANEL:
|
|
||||||
return onOptionsItemSelected(item);
|
|
||||||
default:
|
default:
|
||||||
return super.onMenuItemSelected(featureId, item);
|
return super.onOptionsItemSelected(item);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -423,9 +370,12 @@ public class SongSelector extends Dialog implements AdapterView.OnItemClickListe
|
|||||||
@Override
|
@Override
|
||||||
public boolean onKeyLongPress(int keyCode, KeyEvent event)
|
public boolean onKeyLongPress(int keyCode, KeyEvent event)
|
||||||
{
|
{
|
||||||
return PlaybackActivity.handleKeyLongPress(getContext(), keyCode);
|
return PlaybackActivity.handleKeyLongPress(this, keyCode);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static final int MSG_INIT = 10;
|
||||||
|
|
||||||
|
@Override
|
||||||
public boolean handleMessage(Message message)
|
public boolean handleMessage(Message message)
|
||||||
{
|
{
|
||||||
switch (message.what) {
|
switch (message.what) {
|
||||||
@ -436,9 +386,9 @@ public class SongSelector extends Dialog implements AdapterView.OnItemClickListe
|
|||||||
ListView view = (ListView)findViewById(R.id.song_list);
|
ListView view = (ListView)findViewById(R.id.song_list);
|
||||||
view.setOnItemClickListener(SongSelector.this);
|
view.setOnItemClickListener(SongSelector.this);
|
||||||
view.setOnCreateContextMenuListener(SongSelector.this);
|
view.setOnCreateContextMenuListener(SongSelector.this);
|
||||||
view.setAdapter(new SongMediaAdapter(getContext()));
|
view.setAdapter(new SongMediaAdapter(this));
|
||||||
|
|
||||||
ContentResolver resolver = ContextApplication.getContext().getContentResolver();
|
ContentResolver resolver = getContentResolver();
|
||||||
resolver.registerContentObserver(MediaStore.Audio.Media.EXTERNAL_CONTENT_URI, true, mObserver);
|
resolver.registerContentObserver(MediaStore.Audio.Media.EXTERNAL_CONTENT_URI, true, mObserver);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
@ -457,28 +407,6 @@ public class SongSelector extends Dialog implements AdapterView.OnItemClickListe
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
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));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void setSearchBoxVisible(boolean visible)
|
private void setSearchBoxVisible(boolean visible)
|
||||||
{
|
{
|
||||||
mSearchBoxVisible = visible;
|
mSearchBoxVisible = visible;
|
||||||
@ -486,4 +414,22 @@ public class SongSelector extends Dialog implements AdapterView.OnItemClickListe
|
|||||||
if (visible)
|
if (visible)
|
||||||
mSearchBox.requestFocus();
|
mSearchBox.requestFocus();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onServiceChange(Intent intent)
|
||||||
|
{
|
||||||
|
if (mStatusText != null) {
|
||||||
|
Song song = intent.getParcelableExtra("song");
|
||||||
|
mStatusText.setText(song == null ? getResources().getText(R.string.none) : song.title);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void setState(int state)
|
||||||
|
{
|
||||||
|
if (mPlayPauseButton != null) {
|
||||||
|
boolean playing = (state & PlaybackService.FLAG_PLAYING) != 0;
|
||||||
|
mPlayPauseButton.setImageResource(playing ? R.drawable.pause : R.drawable.play);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user