use explicit intents
This commit is contained in:
parent
1a987168ad
commit
0037d32617
7 changed files with 20 additions and 18 deletions
|
@ -14,7 +14,7 @@ public class ControlActionsListener extends BroadcastReceiver {
|
|||
case Constants.NEXT:
|
||||
case Constants.STOP:
|
||||
case Constants.FINISH:
|
||||
context.startService(new Intent(action));
|
||||
Utils.sendIntent(context, action);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
|
|
|
@ -11,7 +11,7 @@ public class HeadsetPlugReceiver extends BroadcastReceiver {
|
|||
int state = intent.getIntExtra("state", -1);
|
||||
// we care only about the case where the headphone gets unplugged
|
||||
if (state == 0) {
|
||||
context.startService(new Intent(Constants.PAUSE));
|
||||
Utils.sendIntent(context, Constants.PAUSE);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
package musicplayer.simplemobiletools.com;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.telephony.PhoneStateListener;
|
||||
import android.telephony.TelephonyManager;
|
||||
|
||||
|
@ -17,9 +16,9 @@ public class IncomingCallReceiver extends PhoneStateListener {
|
|||
super.onCallStateChanged(state, incomingNumber);
|
||||
|
||||
if (state == TelephonyManager.CALL_STATE_RINGING) {
|
||||
cxt.startService(new Intent(Constants.CALL_START));
|
||||
Utils.sendIntent(cxt, Constants.CALL_START);
|
||||
} else if (state == TelephonyManager.CALL_STATE_IDLE || state == TelephonyManager.CALL_STATE_OFFHOOK) {
|
||||
cxt.startService(new Intent(Constants.CALL_STOP));
|
||||
Utils.sendIntent(cxt, Constants.CALL_STOP);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -33,12 +33,13 @@ public class MainActivity extends AppCompatActivity {
|
|||
ButterKnife.bind(this);
|
||||
bus = BusProvider.getInstance();
|
||||
bus.register(this);
|
||||
startService(new Intent(Constants.INIT));
|
||||
Utils.sendIntent(this, Constants.INIT);
|
||||
}
|
||||
|
||||
private void songPicked(int pos) {
|
||||
final Intent intent = new Intent(Constants.PLAYPOS);
|
||||
final Intent intent = new Intent(this, MusicService.class);
|
||||
intent.putExtra(Constants.SONG_POS, pos);
|
||||
intent.setAction(Constants.PLAYPOS);
|
||||
startService(intent);
|
||||
}
|
||||
|
||||
|
@ -68,22 +69,22 @@ public class MainActivity extends AppCompatActivity {
|
|||
|
||||
@OnClick(R.id.previousBtn)
|
||||
public void previousClicked() {
|
||||
startService(new Intent(Constants.PREVIOUS));
|
||||
Utils.sendIntent(this, Constants.PREVIOUS);
|
||||
}
|
||||
|
||||
@OnClick(R.id.playPauseBtn)
|
||||
public void playPauseClicked() {
|
||||
startService(new Intent(Constants.PLAYPAUSE));
|
||||
Utils.sendIntent(this, Constants.PLAYPAUSE);
|
||||
}
|
||||
|
||||
@OnClick(R.id.nextBtn)
|
||||
public void nextClicked() {
|
||||
startService(new Intent(Constants.NEXT));
|
||||
Utils.sendIntent(this, Constants.NEXT);
|
||||
}
|
||||
|
||||
@OnClick(R.id.stopBtn)
|
||||
public void stopClicked() {
|
||||
startService(new Intent(Constants.STOP));
|
||||
Utils.sendIntent(this, Constants.STOP);
|
||||
}
|
||||
|
||||
@Subscribe
|
||||
|
|
|
@ -170,7 +170,7 @@ public class MyWidgetProvider extends AppWidgetProvider {
|
|||
case Constants.PLAYPAUSE:
|
||||
case Constants.NEXT:
|
||||
case Constants.STOP:
|
||||
context.startService(new Intent(action));
|
||||
Utils.sendIntent(context, action);
|
||||
break;
|
||||
default:
|
||||
super.onReceive(context, intent);
|
||||
|
|
|
@ -37,11 +37,11 @@ public class RemoteControlReceiver extends BroadcastReceiver {
|
|||
return;
|
||||
|
||||
if (clicksCnt == 1) {
|
||||
cxt.startService(new Intent(Constants.PLAYPAUSE));
|
||||
Utils.sendIntent(cxt, Constants.PLAYPAUSE);
|
||||
} else if (clicksCnt == 2) {
|
||||
cxt.startService(new Intent(Constants.NEXT));
|
||||
Utils.sendIntent(cxt, Constants.NEXT);
|
||||
} else {
|
||||
cxt.startService(new Intent(Constants.PREVIOUS));
|
||||
Utils.sendIntent(cxt, Constants.PREVIOUS);
|
||||
}
|
||||
clicksCnt = 0;
|
||||
}
|
||||
|
|
|
@ -1,10 +1,12 @@
|
|||
package musicplayer.simplemobiletools.com;
|
||||
|
||||
import android.content.Context;
|
||||
import android.widget.Toast;
|
||||
import android.content.Intent;
|
||||
|
||||
public class Utils {
|
||||
public static void showToast(Context context, int msgId) {
|
||||
Toast.makeText(context, context.getResources().getString(msgId), Toast.LENGTH_SHORT).show();
|
||||
public static void sendIntent(Context context, String action) {
|
||||
Intent intent = new Intent(context, MusicService.class);
|
||||
intent.setAction(action);
|
||||
context.startService(intent);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue