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 From a6bdf0783d252174d7fe8ed9b9ab4e85d64dee3a Mon Sep 17 00:00:00 2001 From: Scott Jackson Date: Tue, 22 Jul 2014 19:16:52 -0700 Subject: More work on adding a custom tasker plugin --- res/menu/tasker_configuration.xml | 16 ++++++++ res/values/strings.xml | 3 +- .../dsub/activity/EditPlayActionActivity.java | 43 ++++++++++++++++++++-- 3 files changed, 58 insertions(+), 4 deletions(-) create mode 100644 res/menu/tasker_configuration.xml (limited to 'src/github') diff --git a/res/menu/tasker_configuration.xml b/res/menu/tasker_configuration.xml new file mode 100644 index 00000000..07613640 --- /dev/null +++ b/res/menu/tasker_configuration.xml @@ -0,0 +1,16 @@ + + + + + + + diff --git a/res/values/strings.xml b/res/values/strings.xml index 1de825ea..5d5f832e 100644 --- a/res/values/strings.xml +++ b/res/values/strings.xml @@ -531,7 +531,8 @@ Version %s Start playing DSub - Tasker -> Start Playing DSub + Start playing DSub in Shuffle Mode + Tasker -> Start DSub Start in shuffle mode: diff --git a/src/github/daneren2005/dsub/activity/EditPlayActionActivity.java b/src/github/daneren2005/dsub/activity/EditPlayActionActivity.java index 3ae62f5f..b7f9de94 100644 --- a/src/github/daneren2005/dsub/activity/EditPlayActionActivity.java +++ b/src/github/daneren2005/dsub/activity/EditPlayActionActivity.java @@ -18,29 +18,66 @@ package github.daneren2005.dsub.activity; import android.app.Activity; import android.content.Intent; import android.os.Bundle; +import android.support.v4.widget.DrawerLayout; +import android.view.Menu; +import android.view.MenuInflater; +import android.view.MenuItem; import android.widget.CheckBox; import github.daneren2005.dsub.R; import github.daneren2005.dsub.util.Constants; public class EditPlayActionActivity extends SubsonicActivity { + private CheckBox checkBox; + @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); + setTitle(R.string.tasker_start_playing_title); setContentView(R.layout.edit_play_action); + + checkBox = (CheckBox) findViewById(R.id.edit_shuffle_checkbox); + if(getIntent().getBundleExtra(Constants.TASKER_EXTRA_BUNDLE) != null && getIntent().getBundleExtra(Constants.TASKER_EXTRA_BUNDLE).getBoolean(Constants.INTENT_EXTRA_NAME_SHUFFLE)) { + checkBox.setChecked(true); + } + + drawer.setDrawerLockMode(DrawerLayout.LOCK_MODE_LOCKED_CLOSED); + } + + @Override + public boolean onCreateOptionsMenu(Menu menu) { + MenuInflater menuInflater = getMenuInflater(); + menuInflater.inflate(R.menu.tasker_configuration, menu); + return true; + } + + @Override + public boolean onOptionsItemSelected(MenuItem item) { + if(item.getItemId() == android.R.id.home) { + cancel(); + return true; + } else if(item.getItemId() == R.id.menu_accept) { + accept(); + return true; + } else if(item.getItemId() == R.id.menu_cancel) { + cancel(); + return true; + } + + return false; } 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); + String blurb = getResources().getString(checkBox.isChecked() ? R.string.tasker_start_playing_shuffled : R.string.tasker_start_playing); + intent.putExtra("com.twofortyfouram.locale.intent.extra.BLURB", blurb); Bundle data = new Bundle(); data.putBoolean(Constants.INTENT_EXTRA_NAME_SHUFFLE, checkBox.isChecked()); intent.putExtra(Constants.TASKER_EXTRA_BUNDLE, data); - setResult(Activity.RESULT_OK); + setResult(Activity.RESULT_OK, intent); finish(); } private void cancel() { -- cgit v1.2.3 From 3fbc5a1bd5d56fecca9b3339bec04d1d9cd476ed Mon Sep 17 00:00:00 2001 From: Scott Jackson Date: Tue, 22 Jul 2014 19:27:19 -0700 Subject: Fix DownloadService.START_PLAY not going anywhere --- src/github/daneren2005/dsub/receiver/PlayActionReceiver.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'src/github') diff --git a/src/github/daneren2005/dsub/receiver/PlayActionReceiver.java b/src/github/daneren2005/dsub/receiver/PlayActionReceiver.java index a5f4f561..60814cc6 100644 --- a/src/github/daneren2005/dsub/receiver/PlayActionReceiver.java +++ b/src/github/daneren2005/dsub/receiver/PlayActionReceiver.java @@ -19,18 +19,22 @@ import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; import android.os.Bundle; +import android.util.Log; import github.daneren2005.dsub.service.DownloadService; import github.daneren2005.dsub.util.Constants; public class PlayActionReceiver extends BroadcastReceiver { + private static final String TAG = PlayActionReceiver.class.getSimpleName(); + @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); + Intent start = new Intent(context, DownloadService.class); + start.setAction(DownloadService.START_PLAY); start.putExtra(Constants.INTENT_EXTRA_NAME_SHUFFLE, startShuffled); context.startService(start); } -- cgit v1.2.3