import android.app.Activity;
import android.app.AlertDialog;
+import android.app.KeyguardManager;
import android.app.SearchManager;
import android.content.BroadcastReceiver;
import android.content.ComponentName;
import android.content.IntentFilter;
import android.content.ServiceConnection;
import android.content.res.Configuration;
-import android.content.res.Resources;
import android.database.Cursor;
import android.graphics.Bitmap;
import android.media.AudioManager;
-import android.media.MediaFile;
import android.net.Uri;
import android.os.Bundle;
-import android.os.RemoteException;
import android.os.Handler;
import android.os.IBinder;
import android.os.Looper;
import android.os.Message;
+import android.os.RemoteException;
import android.os.SystemClock;
import android.provider.MediaStore;
import android.text.Layout;
private boolean mOneShot = false;
private boolean mSeeking = false;
- private boolean mDeviceHasNoDpad;
+ private boolean mDeviceHasDpad;
private long mStartSeekPos = 0;
private long mLastSeekEventTime;
private IMediaPlaybackService mService = null;
mNextButton.setRepeatListener(mFfwdListener, 260);
seekmethod = 1;
- mDeviceHasNoDpad = (getResources().getConfiguration().navigation !=
+ mDeviceHasDpad = (getResources().getConfiguration().navigation ==
Configuration.NAVIGATION_DPAD);
mQueueButton = (ImageButton) findViewById(R.id.curplaylist);
audioid = mService.getAudioId();
} catch (RemoteException ex) {
return true;
+ } catch (NullPointerException ex) {
+ // we might not actually have the service yet
+ return true;
}
- if (MediaFile.UNKNOWN_STRING.equals(album) &&
- MediaFile.UNKNOWN_STRING.equals(artist) &&
+ if (MediaStore.UNKNOWN_STRING.equals(album) &&
+ MediaStore.UNKNOWN_STRING.equals(artist) &&
song != null &&
song.startsWith("recording")) {
// not music
return false;
}
+
+ if (audioid < 0) {
+ return false;
+ }
+
Cursor c = MusicUtils.query(this,
ContentUris.withAppendedId(MediaStore.Audio.Media.EXTERNAL_CONTENT_URI, audioid),
new String[] {MediaStore.Audio.Media.IS_MUSIC}, null, null, null);
}
boolean knownartist =
- (artist != null) && !MediaFile.UNKNOWN_STRING.equals(artist);
+ (artist != null) && !MediaStore.UNKNOWN_STRING.equals(artist);
boolean knownalbum =
- (album != null) && !MediaFile.UNKNOWN_STRING.equals(album);
+ (album != null) && !MediaStore.UNKNOWN_STRING.equals(album);
if (knownartist && view.equals(mArtistName.getParent())) {
title = artist;
}
mime = MediaStore.Audio.Albums.ENTRY_CONTENT_TYPE;
} else if (view.equals(mTrackName.getParent()) || !knownartist || !knownalbum) {
- if ((song == null) || MediaFile.UNKNOWN_STRING.equals(song)) {
+ if ((song == null) || MediaStore.UNKNOWN_STRING.equals(song)) {
// A popup of the form "Search for null/'' using ..." is pretty
// unhelpful, plus, we won't find any way to buy it anyway.
return true;
menu.add(0, PARTY_SHUFFLE, 0, R.string.party_shuffle); // icon will be set in onPrepareOptionsMenu()
SubMenu sub = menu.addSubMenu(0, ADD_TO_PLAYLIST, 0,
R.string.add_to_playlist).setIcon(android.R.drawable.ic_menu_add);
- MusicUtils.makePlaylistMenu(this, sub);
- menu.add(0, USE_AS_RINGTONE, 0, R.string.ringtone_menu_short).setIcon(R.drawable.ic_menu_set_as_ringtone);
- menu.add(0, DELETE_ITEM, 0, R.string.delete_item).setIcon(R.drawable.ic_menu_delete);
+ // these next two are in a separate group, so they can be shown/hidden as needed
+ // based on the keyguard state
+ menu.add(1, USE_AS_RINGTONE, 0, R.string.ringtone_menu_short)
+ .setIcon(R.drawable.ic_menu_set_as_ringtone);
+ menu.add(1, DELETE_ITEM, 0, R.string.delete_item)
+ .setIcon(R.drawable.ic_menu_delete);
return true;
}
return false;
item.setTitle(R.string.party_shuffle);
}
}
+
+ item = menu.findItem(ADD_TO_PLAYLIST);
+ if (item != null) {
+ SubMenu sub = item.getSubMenu();
+ MusicUtils.makePlaylistMenu(this, sub);
+ }
+
+ KeyguardManager km = (KeyguardManager) getSystemService(Context.KEYGUARD_SERVICE);
+ menu.setGroupVisible(1, !km.inKeyguardRestrictedInputMode());
+
return true;
}
case GOTO_START:
intent = new Intent();
intent.setClass(this, MusicBrowserActivity.class);
- intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK
- | Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(intent);
+ finish();
break;
case USE_AS_RINGTONE: {
// Set the system setting to make this the current ringtone
return true;
}
case PARTY_SHUFFLE:
- if (mService != null) {
- int shuffle = mService.getShuffleMode();
- if (shuffle == MediaPlaybackService.SHUFFLE_AUTO) {
- mService.setShuffleMode(MediaPlaybackService.SHUFFLE_NONE);
- } else {
- mService.setShuffleMode(MediaPlaybackService.SHUFFLE_AUTO);
- }
- }
+ MusicUtils.togglePartyShuffle();
setShuffleButtonImage();
break;
private boolean seekMethod1(int keyCode)
{
+ if (mService == null) return false;
for(int x=0;x<10;x++) {
for(int y=0;y<3;y++) {
if(keyboard[y][x] == keyCode) {
switch(keyCode)
{
case KeyEvent.KEYCODE_DPAD_LEFT:
- if (mDeviceHasNoDpad) {
+ if (!useDpadMusicControl()) {
break;
}
if (mService != null) {
mPosOverride = -1;
return true;
case KeyEvent.KEYCODE_DPAD_RIGHT:
- if (mDeviceHasNoDpad) {
+ if (!useDpadMusicControl()) {
break;
}
if (mService != null) {
return super.onKeyUp(keyCode, event);
}
+ private boolean useDpadMusicControl() {
+ if (mDeviceHasDpad && (mPrevButton.isFocused() ||
+ mNextButton.isFocused() ||
+ mPauseButton.isFocused())) {
+ return true;
+ }
+ return false;
+ }
+
@Override
public boolean onKeyDown(int keyCode, KeyEvent event)
{
return true;
case KeyEvent.KEYCODE_DPAD_LEFT:
- if (mDeviceHasNoDpad) {
+ if (!useDpadMusicControl()) {
break;
}
if (!mPrevButton.hasFocus()) {
scanBackward(repcnt, event.getEventTime() - event.getDownTime());
return true;
case KeyEvent.KEYCODE_DPAD_RIGHT:
- if (mDeviceHasNoDpad) {
+ if (!useDpadMusicControl()) {
break;
}
if (!mNextButton.hasFocus()) {
((View) mArtistName.getParent()).setVisibility(View.VISIBLE);
((View) mAlbumName.getParent()).setVisibility(View.VISIBLE);
String artistName = mService.getArtistName();
- if (MediaFile.UNKNOWN_STRING.equals(artistName)) {
+ if (MediaStore.UNKNOWN_STRING.equals(artistName)) {
artistName = getString(R.string.unknown_artist_name);
}
mArtistName.setText(artistName);
String albumName = mService.getAlbumName();
long albumid = mService.getAlbumId();
- if (MediaFile.UNKNOWN_STRING.equals(albumName)) {
+ if (MediaStore.UNKNOWN_STRING.equals(albumName)) {
albumName = getString(R.string.unknown_album_name);
albumid = -1;
}