From 856e2829ea93294447bf47a215b8db2c24708142 Mon Sep 17 00:00:00 2001 From: Scott Jackson Date: Sun, 20 Jul 2014 17:26:39 -0700 Subject: Start of basic Tasker plugin --- .../dsub/activity/EditPlayActionActivity.java | 50 ++++++++++++++++++++++ .../dsub/receiver/PlayActionReceiver.java | 38 ++++++++++++++++ .../daneren2005/dsub/service/DownloadService.java | 1 + .../service/DownloadServiceLifecycleSupport.java | 15 ++++--- src/github/daneren2005/dsub/util/Constants.java | 2 + 5 files changed, 100 insertions(+), 6 deletions(-) create mode 100644 src/github/daneren2005/dsub/activity/EditPlayActionActivity.java create mode 100644 src/github/daneren2005/dsub/receiver/PlayActionReceiver.java (limited to 'src/github') diff --git a/src/github/daneren2005/dsub/activity/EditPlayActionActivity.java b/src/github/daneren2005/dsub/activity/EditPlayActionActivity.java new file mode 100644 index 00000000..3ae62f5f --- /dev/null +++ b/src/github/daneren2005/dsub/activity/EditPlayActionActivity.java @@ -0,0 +1,50 @@ +/* + This file is part of Subsonic. + Subsonic is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + Subsonic is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + You should have received a copy of the GNU General Public License + along with Subsonic. If not, see . + Copyright 2014 (C) Scott Jackson +*/ + +package github.daneren2005.dsub.activity; + +import android.app.Activity; +import android.content.Intent; +import android.os.Bundle; +import android.widget.CheckBox; + +import github.daneren2005.dsub.R; +import github.daneren2005.dsub.util.Constants; + +public class EditPlayActionActivity extends SubsonicActivity { + @Override + public void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.edit_play_action); + } + + private void accept() { + Intent intent = new Intent(); + intent.putExtra("com.twofortyfouram.locale.intent.extra.BLURB", "Start DSub"); + + CheckBox checkBox = (CheckBox) findViewById(R.id.edit_shuffle_checkbox); + + Bundle data = new Bundle(); + data.putBoolean(Constants.INTENT_EXTRA_NAME_SHUFFLE, checkBox.isChecked()); + intent.putExtra(Constants.TASKER_EXTRA_BUNDLE, data); + + setResult(Activity.RESULT_OK); + finish(); + } + private void cancel() { + setResult(Activity.RESULT_CANCELED); + finish(); + } +} diff --git a/src/github/daneren2005/dsub/receiver/PlayActionReceiver.java b/src/github/daneren2005/dsub/receiver/PlayActionReceiver.java new file mode 100644 index 00000000..a5f4f561 --- /dev/null +++ b/src/github/daneren2005/dsub/receiver/PlayActionReceiver.java @@ -0,0 +1,38 @@ +/* + This file is part of Subsonic. + Subsonic is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + Subsonic is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + You should have received a copy of the GNU General Public License + along with Subsonic. If not, see . + Copyright 2014 (C) Scott Jackson +*/ + +package github.daneren2005.dsub.receiver; + +import android.content.BroadcastReceiver; +import android.content.Context; +import android.content.Intent; +import android.os.Bundle; + +import github.daneren2005.dsub.service.DownloadService; +import github.daneren2005.dsub.util.Constants; + +public class PlayActionReceiver extends BroadcastReceiver { + @Override + public void onReceive(Context context, Intent intent) { + if(intent.hasExtra(Constants.TASKER_EXTRA_BUNDLE)) { + Bundle data = intent.getBundleExtra(Constants.TASKER_EXTRA_BUNDLE); + Boolean startShuffled = data.getBoolean(Constants.INTENT_EXTRA_NAME_SHUFFLE); + + Intent start = new Intent(DownloadService.START_PLAY); + start.putExtra(Constants.INTENT_EXTRA_NAME_SHUFFLE, startShuffled); + context.startService(start); + } + } +} diff --git a/src/github/daneren2005/dsub/service/DownloadService.java b/src/github/daneren2005/dsub/service/DownloadService.java index f458379d..c4837260 100644 --- a/src/github/daneren2005/dsub/service/DownloadService.java +++ b/src/github/daneren2005/dsub/service/DownloadService.java @@ -91,6 +91,7 @@ public class DownloadService extends Service { public static final String CMD_PREVIOUS = "github.daneren2005.dsub.CMD_PREVIOUS"; public static final String CMD_NEXT = "github.daneren2005.dsub.CMD_NEXT"; public static final String CANCEL_DOWNLOADS = "github.daneren2005.dsub.CANCEL_DOWNLOADS"; + public static final String START_PLAY = "github.daneren2005.dsub.START_PLAYING"; public static final int FAST_FORWARD = 30000; public static final int REWIND = 10000; diff --git a/src/github/daneren2005/dsub/service/DownloadServiceLifecycleSupport.java b/src/github/daneren2005/dsub/service/DownloadServiceLifecycleSupport.java index 18502846..04a2535c 100644 --- a/src/github/daneren2005/dsub/service/DownloadServiceLifecycleSupport.java +++ b/src/github/daneren2005/dsub/service/DownloadServiceLifecycleSupport.java @@ -159,7 +159,15 @@ public class DownloadServiceLifecycleSupport { public void onStart(Intent intent) { if (intent != null) { - if(intent.getExtras() != null) { + String action = intent.getAction(); + if(DownloadService.START_PLAY.equals(action)) { + if(intent.getBooleanExtra(Constants.INTENT_EXTRA_NAME_SHUFFLE, false)) { + downloadService.setShufflePlayEnabled(true); + } + downloadService.play(); + } else if(DownloadService.CANCEL_DOWNLOADS.equals(action)) { + downloadService.clearBackground(); + } else if(intent.getExtras() != null) { final KeyEvent event = (KeyEvent) intent.getExtras().get(Intent.EXTRA_KEY_EVENT); if (event != null) { eventHandler.post(new Runnable() { @@ -173,11 +181,6 @@ public class DownloadServiceLifecycleSupport { } }); } - } else { - String action = intent.getAction(); - if(DownloadService.CANCEL_DOWNLOADS.equals(action)) { - downloadService.clearBackground(); - } } } } diff --git a/src/github/daneren2005/dsub/util/Constants.java b/src/github/daneren2005/dsub/util/Constants.java index f566c78c..0f9d78b9 100644 --- a/src/github/daneren2005/dsub/util/Constants.java +++ b/src/github/daneren2005/dsub/util/Constants.java @@ -174,6 +174,8 @@ public final class Constants { public static final String SYNC_ACCOUNT_STARRED_AUTHORITY = "github.daneren2005.dsub.starred.provider"; public static final String SYNC_ACCOUNT_MOST_RECENT_AUTHORITY = "github.daneren2005.dsub.mostrecent.provider"; + public static final String TASKER_EXTRA_BUNDLE = "com.twofortyfouram.locale.intent.extra.BUNDLE"; + // Number of free trial days for non-licensed servers. public static final int FREE_TRIAL_DAYS = 30; -- cgit v1.2.3