Fixed widget operation when Ultrasonic is stopped
This commit is contained in:
parent
7f5ff00237
commit
2ff0151e8c
|
@ -17,6 +17,7 @@ import org.moire.ultrasonic.R;
|
||||||
import org.moire.ultrasonic.activity.DownloadActivity;
|
import org.moire.ultrasonic.activity.DownloadActivity;
|
||||||
import org.moire.ultrasonic.activity.MainActivity;
|
import org.moire.ultrasonic.activity.MainActivity;
|
||||||
import org.moire.ultrasonic.domain.MusicDirectory;
|
import org.moire.ultrasonic.domain.MusicDirectory;
|
||||||
|
import org.moire.ultrasonic.receiver.MediaButtonIntentReceiver;
|
||||||
import org.moire.ultrasonic.service.MediaPlayerController;
|
import org.moire.ultrasonic.service.MediaPlayerController;
|
||||||
import org.moire.ultrasonic.util.Constants;
|
import org.moire.ultrasonic.util.Constants;
|
||||||
import org.moire.ultrasonic.util.FileUtil;
|
import org.moire.ultrasonic.util.FileUtil;
|
||||||
|
@ -199,19 +200,22 @@ public class UltraSonicAppWidgetProvider extends AppWidgetProvider
|
||||||
|
|
||||||
// Emulate media button clicks.
|
// Emulate media button clicks.
|
||||||
intent = new Intent(Constants.CMD_PROCESS_KEYCODE);
|
intent = new Intent(Constants.CMD_PROCESS_KEYCODE);
|
||||||
intent.setPackage(context.getPackageName());
|
//intent.setPackage(context.getPackageName());
|
||||||
|
intent.setComponent(new ComponentName(context, MediaButtonIntentReceiver.class));
|
||||||
intent.putExtra(Intent.EXTRA_KEY_EVENT, new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE));
|
intent.putExtra(Intent.EXTRA_KEY_EVENT, new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE));
|
||||||
pendingIntent = PendingIntent.getBroadcast(context, 11, intent, 0);
|
pendingIntent = PendingIntent.getBroadcast(context, 11, intent, 0);
|
||||||
views.setOnClickPendingIntent(R.id.control_play, pendingIntent);
|
views.setOnClickPendingIntent(R.id.control_play, pendingIntent);
|
||||||
|
|
||||||
intent = new Intent(Constants.CMD_PROCESS_KEYCODE);
|
intent = new Intent(Constants.CMD_PROCESS_KEYCODE);
|
||||||
intent.setPackage(context.getPackageName());
|
//intent.setPackage(context.getPackageName());
|
||||||
|
intent.setComponent(new ComponentName(context, MediaButtonIntentReceiver.class));
|
||||||
intent.putExtra(Intent.EXTRA_KEY_EVENT, new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_MEDIA_NEXT));
|
intent.putExtra(Intent.EXTRA_KEY_EVENT, new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_MEDIA_NEXT));
|
||||||
pendingIntent = PendingIntent.getBroadcast(context, 12, intent, 0);
|
pendingIntent = PendingIntent.getBroadcast(context, 12, intent, 0);
|
||||||
views.setOnClickPendingIntent(R.id.control_next, pendingIntent);
|
views.setOnClickPendingIntent(R.id.control_next, pendingIntent);
|
||||||
|
|
||||||
intent = new Intent(Constants.CMD_PROCESS_KEYCODE);
|
intent = new Intent(Constants.CMD_PROCESS_KEYCODE);
|
||||||
intent.setPackage(context.getPackageName());
|
//intent.setPackage(context.getPackageName());
|
||||||
|
intent.setComponent(new ComponentName(context, MediaButtonIntentReceiver.class));
|
||||||
intent.putExtra(Intent.EXTRA_KEY_EVENT, new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_MEDIA_PREVIOUS));
|
intent.putExtra(Intent.EXTRA_KEY_EVENT, new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_MEDIA_PREVIOUS));
|
||||||
pendingIntent = PendingIntent.getBroadcast(context, 13, intent, 0);
|
pendingIntent = PendingIntent.getBroadcast(context, 13, intent, 0);
|
||||||
views.setOnClickPendingIntent(R.id.control_previous, pendingIntent);
|
views.setOnClickPendingIntent(R.id.control_previous, pendingIntent);
|
||||||
|
|
|
@ -44,37 +44,40 @@ public class MediaButtonIntentReceiver extends BroadcastReceiver
|
||||||
@Override
|
@Override
|
||||||
public void onReceive(Context context, Intent intent)
|
public void onReceive(Context context, Intent intent)
|
||||||
{
|
{
|
||||||
if (Util.getMediaButtonsPreference(context))
|
String intentAction = intent.getAction();
|
||||||
|
|
||||||
|
// If media button are turned off and we received a media button, exit
|
||||||
|
if (!Util.getMediaButtonsPreference(context) &&
|
||||||
|
Intent.ACTION_MEDIA_BUTTON.equals(intentAction)) return;
|
||||||
|
|
||||||
|
// Only process media buttons and CMD_PROCESS_KEYCODE, which is received from the widgets
|
||||||
|
if (!Intent.ACTION_MEDIA_BUTTON.equals(intentAction) &&
|
||||||
|
!Constants.CMD_PROCESS_KEYCODE.equals(intentAction)) return;
|
||||||
|
|
||||||
|
Bundle extras = intent.getExtras();
|
||||||
|
|
||||||
|
if (extras == null)
|
||||||
{
|
{
|
||||||
String intentAction = intent.getAction();
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (!Intent.ACTION_MEDIA_BUTTON.equals(intentAction)) return;
|
Parcelable event = (Parcelable) extras.get(Intent.EXTRA_KEY_EVENT);
|
||||||
|
Log.i(TAG, "Got MEDIA_BUTTON key event: " + event);
|
||||||
|
|
||||||
Bundle extras = intent.getExtras();
|
try
|
||||||
|
{
|
||||||
|
Intent serviceIntent = new Intent(Constants.CMD_PROCESS_KEYCODE);
|
||||||
|
serviceIntent.putExtra(Intent.EXTRA_KEY_EVENT, event);
|
||||||
|
lifecycleSupport.getValue().receiveIntent(serviceIntent);
|
||||||
|
|
||||||
if (extras == null)
|
if (isOrderedBroadcast())
|
||||||
{
|
{
|
||||||
return;
|
abortBroadcast();
|
||||||
}
|
|
||||||
|
|
||||||
Parcelable event = (Parcelable) extras.get(Intent.EXTRA_KEY_EVENT);
|
|
||||||
Log.i(TAG, "Got MEDIA_BUTTON key event: " + event);
|
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
Intent serviceIntent = new Intent(Constants.CMD_PROCESS_KEYCODE);
|
|
||||||
serviceIntent.putExtra(Intent.EXTRA_KEY_EVENT, event);
|
|
||||||
lifecycleSupport.getValue().receiveIntent(serviceIntent);
|
|
||||||
|
|
||||||
if (isOrderedBroadcast())
|
|
||||||
{
|
|
||||||
abortBroadcast();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
catch (Exception x)
|
|
||||||
{
|
|
||||||
// Ignored.
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
catch (Exception x)
|
||||||
|
{
|
||||||
|
// Ignored.
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue