Skip to content

Commit

Permalink
Adds support for lockscreen media button widget pre-Lollipop
Browse files Browse the repository at this point in the history
Moves the RemoteController thread to a single thread executor
Completely removes Crashlytics SDK from the application.
  • Loading branch information
kelsos committed Apr 20, 2015
1 parent 5540679 commit cea4284
Show file tree
Hide file tree
Showing 16 changed files with 226 additions and 57 deletions.
5 changes: 1 addition & 4 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,11 @@ buildscript {
mavenCentral()
mavenLocal()
jcenter()
maven { url 'https://maven.fabric.io/public' }
}

dependencies {
classpath 'com.android.tools.build:gradle:1.2.0-beta1'
classpath 'me.tatarka:gradle-retrolambda:3.0.0'
classpath 'io.fabric.tools:gradle:1.18.0'
classpath 'me.tatarka:gradle-retrolambda:3.0.1'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
Expand All @@ -20,7 +18,6 @@ buildscript {
allprojects {
repositories {
maven { url 'http://dl.bintray.com/kelsos/maven' }
maven { url 'https://maven.fabric.io/public' }
mavenCentral()
mavenLocal()
jcenter()
Expand Down
15 changes: 0 additions & 15 deletions remote/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import java.text.SimpleDateFormat

apply plugin: 'me.tatarka.retrolambda'
apply plugin: 'com.android.application'
apply plugin: 'io.fabric'
apply plugin: 'checkstyle'
apply plugin: 'findbugs'
apply plugin: 'pmd'
Expand All @@ -18,16 +17,6 @@ def gitHash() {
return "git -C ${rootDir} rev-parse --short HEAD".execute().text.trim()
}

// Load the fabric api key.
def fabricApiKey = ""
def crashProperties = file('fabric.properties')

if (crashProperties.exists()) {
def properties = new Properties()
properties.load(new FileInputStream(crashProperties))
fabricApiKey = properties.getAt('apiKey')
}

def hasModifiedDeletedOrOtherFiles() {
return !"git -C ${rootDir} ls-files -mdo --exclude-standard".execute().text.trim().isEmpty()
}
Expand Down Expand Up @@ -58,7 +47,6 @@ android {
versionName "0.10.0-rc.3"
buildConfigField "String", "GIT_SHA", "\"${gitHash()}\""
buildConfigField "String", "BUILD_TIME", "\"${buildTime()}\""
manifestPlaceholders = [fabricApiKey: fabricApiKey]
}

signingConfigs {
Expand Down Expand Up @@ -156,9 +144,6 @@ dependencies {
compile 'com.jakewharton:butterknife:6.1.0'
compile 'io.reactivex:rxandroid:0.24.0'
provided 'org.roboguice:roboblender:3.0.1'
compile('com.crashlytics.sdk.android:crashlytics:2.2.2@aar') {
transitive = true;
}
}

allprojects {
Expand Down
12 changes: 9 additions & 3 deletions remote/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -71,15 +71,21 @@
</intent-filter>
</service>

<receiver android:name=".utilities.MediaButtonReceiver">
<intent-filter>
<action android:name="android.media.AUDIO_BECOMING_NOISY" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.MEDIA_BUTTON" />
</intent-filter>
</receiver>

<meta-data
android:name="roboguice.modules"
android:value="com.kelsos.mbrc.RemoteModule" />
<meta-data
android:name="roboguice.annotations.packages"
android:value="roboguice,mbrc" />

<meta-data
android:name="io.fabric.ApiKey"
android:value="${fabricApiKey}" />
</application>
</manifest>
3 changes: 0 additions & 3 deletions remote/src/main/java/com/kelsos/mbrc/RemoteApplication.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,12 @@
import android.content.Intent;
import android.util.Log;
import android.view.ViewConfiguration;
import com.crashlytics.android.Crashlytics;
import com.kelsos.mbrc.controller.RemoteService;
import com.kelsos.mbrc.messaging.NotificationService;
import com.kelsos.mbrc.model.MainDataModel;
import com.kelsos.mbrc.services.ProtocolHandler;
import com.kelsos.mbrc.services.SocketService;
import com.kelsos.mbrc.utilities.RemoteBroadcastReceiver;
import io.fabric.sdk.android.Fabric;
import java.lang.reflect.Field;
import roboguice.RoboGuice;
import roboguice.inject.RoboInjector;
Expand All @@ -20,7 +18,6 @@ public class RemoteApplication extends Application {

public void onCreate() {
super.onCreate();
Fabric.with(this, new Crashlytics());
final RoboInjector injector = RoboGuice.getInjector(this);

startService(new Intent(this, RemoteService.class));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ public class ProcessUserAction implements ICommand {
}

@Override public void execute(IEvent e) {
socket.sendData(new SocketMessage(((UserAction) e.getData()).getContext(), ((UserAction) e.getData()).getData()));
socket.sendData(new SocketMessage(((UserAction) e.getData()).getContext(),
((UserAction) e.getData()).getData()));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import com.kelsos.mbrc.interfaces.ICommand;
import com.kelsos.mbrc.interfaces.IEvent;
import com.kelsos.mbrc.services.SocketService;
import com.kelsos.mbrc.utilities.RemoteUtils;

public class ProtocolPingHandle implements ICommand {
private final SocketService service;
Expand All @@ -16,6 +15,6 @@ public class ProtocolPingHandle implements ICommand {
}

@Override public void execute(IEvent e) {
service.sendData(new SocketMessage(Protocol.PONG, RemoteUtils.getUtcNow()));
service.sendData(new SocketMessage(Protocol.PONG, ""));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,8 @@ public static void unregister(RemoteController controller) {
controller.unregister(UserInputEventType.KeyVolumeUp, KeyVolumeUpCommand.class);
controller.unregister(UserInputEventType.KeyVolumeDown, KeyVolumeDownCommand.class);
controller.unregister(SocketEventType.SocketDataAvailable, SocketDataAvailableCommand.class);
controller.unregister(SocketEventType.SocketStatusChanged, ConnectionStatusChangedCommand.class);
controller.unregister(SocketEventType.SocketStatusChanged,
ConnectionStatusChangedCommand.class);
controller.unregister(SocketEventType.SocketHandshakeUpdate, HandleHandshake.class);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@ public synchronized void executeCommand(IEvent event) {
//noinspection InfiniteLoopStatement
while (true) {
executeCommand(eventQueue.take());
Ln.d("Executing");
}
} catch (InterruptedException e) {
Ln.d(e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
import com.kelsos.mbrc.constants.UserInputEventType;
import com.kelsos.mbrc.events.MessageEvent;
import com.squareup.otto.Subscribe;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import roboguice.service.RoboService;
import roboguice.util.Ln;

Expand All @@ -17,7 +19,7 @@
private final IBinder mBinder = new ControllerBinder();
@Inject
private RemoteController remoteController;
private Thread controllerThread;
private ExecutorService threadPoolExecutor;

public RemoteService() { }

Expand All @@ -37,18 +39,17 @@ public RemoteService() { }
@Override public int onStartCommand(Intent intent, int flags, int startId) {
Ln.d("Background Service::Started");
CommandRegistration.register(remoteController);
controllerThread = new Thread(remoteController);
controllerThread.start();
threadPoolExecutor = Executors.newSingleThreadExecutor();
threadPoolExecutor.execute(remoteController);
return super.onStartCommand(intent, flags, startId);
}

@Override public void onDestroy() {
remoteController.executeCommand(new MessageEvent(UserInputEventType.CancelNotification));
remoteController.executeCommand(new MessageEvent(UserInputEventType.TerminateConnection));
CommandRegistration.unregister(remoteController);
if (controllerThread != null && controllerThread.isAlive()) {
controllerThread.interrupt();
controllerThread = null;
if (threadPoolExecutor != null) {
threadPoolExecutor.shutdownNow();
}
Ln.d("Background Service::Destroyed");
super.onDestroy();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package com.kelsos.mbrc.events.ui;

import android.graphics.Bitmap;

public class RemoteClientMetaData {
private final String artist;
private final String title;
private final String album;
private final Bitmap cover;

public RemoteClientMetaData(String artist, String title, String album, Bitmap cover) {
this.artist = artist;
this.title = title;
this.album = album;
this.cover = cover;
}

public String getArtist() {
return artist;
}

public String getTitle() {
return title;
}

public String getAlbum() {
return album;
}

public Bitmap getCover() {
return cover;
}
}
8 changes: 8 additions & 0 deletions remote/src/main/java/com/kelsos/mbrc/model/MainDataModel.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import com.kelsos.mbrc.events.ui.OnMainFragmentOptionsInflated;
import com.kelsos.mbrc.events.ui.PlayStateChange;
import com.kelsos.mbrc.events.ui.RatingChanged;
import com.kelsos.mbrc.events.ui.RemoteClientMetaData;
import com.kelsos.mbrc.events.ui.RepeatChange;
import com.kelsos.mbrc.events.ui.ScrobbleChange;
import com.kelsos.mbrc.events.ui.ShuffleChange;
Expand Down Expand Up @@ -201,6 +202,11 @@ public void setTrackInfo(String artist, String album, String title, String year)
this.title = title;
bus.post(new TrackInfoChange(artist, title, album, year));
updateNotification();
updateRemoteClient();
}

private void updateRemoteClient() {
bus.post(new RemoteClientMetaData(artist, title, album, cover));
}

@Produce public TrackInfoChange produceTrackInfo() {
Expand Down Expand Up @@ -231,6 +237,7 @@ public void setCover(final String base64format) {
cover = null;
bus.post(new CoverAvailable());
updateNotification();
updateRemoteClient();
} else {
Observable.create((Subscriber<? super Bitmap> subscriber) -> {
byte[] decodedImage = Base64.decode(base64format, Base64.DEFAULT);
Expand All @@ -248,6 +255,7 @@ public void setAlbumCover(Bitmap cover) {
this.cover = cover;
bus.post(new CoverAvailable(cover));
updateNotification();
updateRemoteClient();
}

@Produce public CoverAvailable produceAvailableCover() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public void preProcessIncoming(final String incoming) {
} else if (context.contains(Protocol.ProtocolTag)) {

double protocolVersion;
try{
try {
protocolVersion = Double.parseDouble(node.path(Const.DATA).asText());
} catch (Exception ignore) {
protocolVersion = 2.0;
Expand Down
Loading

0 comments on commit cea4284

Please sign in to comment.