Skip to content

Commit

Permalink
Merge pull request #4 from MelleDijkstra/grpc
Browse files Browse the repository at this point in the history
gRPC Implementation
  • Loading branch information
Melle Dijkstra authored Feb 25, 2018
2 parents 07f435a + 3e45241 commit 3ec4b29
Show file tree
Hide file tree
Showing 47 changed files with 2,107 additions and 1,695 deletions.
55 changes: 39 additions & 16 deletions app/app.iml
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,22 @@
</configuration>
</facet>
</component>
<component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_7">
<component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_8">
<output url="file://$MODULE_DIR$/build/intermediates/classes/debug" />
<output-test url="file://$MODULE_DIR$/build/intermediates/classes/test/debug" />
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/proto/debug/grpc" isTestSource="false" generated="true" />
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/proto/debug/javalite" isTestSource="false" generated="true" />
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/apt/debug" isTestSource="false" generated="true" />
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/r/debug" isTestSource="false" generated="true" />
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/aidl/debug" isTestSource="false" generated="true" />
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/buildConfig/debug" isTestSource="false" generated="true" />
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/rs/debug" isTestSource="false" generated="true" />
<sourceFolder url="file://$MODULE_DIR$/build/generated/res/rs/debug" type="java-resource" />
<sourceFolder url="file://$MODULE_DIR$/build/generated/res/resValues/debug" type="java-resource" />
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/proto/debugAndroidTest/grpc" isTestSource="true" generated="true" />
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/proto/debugAndroidTest/javalite" isTestSource="true" generated="true" />
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/apt/androidTest/debug" isTestSource="true" generated="true" />
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/r/androidTest/debug" isTestSource="true" generated="true" />
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/aidl/androidTest/debug" isTestSource="true" generated="true" />
Expand Down Expand Up @@ -84,28 +88,26 @@
<sourceFolder url="file://$MODULE_DIR$/src/test/java" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/test/rs" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/test/shaders" isTestSource="true" />
<excludeFolder url="file://$MODULE_DIR$/build/extracted-include-protos" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/assets" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/blame" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/build-info" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/builds" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/check-manifest" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/classes" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/dependency-cache" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/incremental" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/incremental-classes" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/incremental-runtime-classes" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/incremental-safeguard" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/incremental-verifier" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/instant-run-resources" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/instant-run-support" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/javaPrecompile" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/jniLibs" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/lint" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/manifests" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/pre-dexed" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/prebuild" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/processing-tools" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/reload-dex" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/res" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/restart-dex" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/rs" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/shaders" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/split-apk" />
Expand All @@ -116,16 +118,37 @@
<excludeFolder url="file://$MODULE_DIR$/build/outputs" />
<excludeFolder url="file://$MODULE_DIR$/build/tmp" />
</content>
<orderEntry type="jdk" jdkName="Android API 26 Platform" jdkType="Android SDK" />
<orderEntry type="jdk" jdkName="Android API 25 Platform" jdkType="Android SDK" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" name="com.android.support:support-annotations:23.4.0@jar" level="project" />
<orderEntry type="library" name="com.android.support:support-vector-drawable-23.4.0" level="project" />
<orderEntry type="library" name="com.android.support:support-v4-23.4.0" level="project" />
<orderEntry type="library" scope="TEST" name="org.hamcrest:hamcrest-core:1.3@jar" level="project" />
<orderEntry type="library" name="com.android.support:appcompat-v7-23.4.0" level="project" />
<orderEntry type="library" scope="TEST" name="junit:junit:4.12@jar" level="project" />
<orderEntry type="library" name="com.android.support:animated-vector-drawable-23.4.0" level="project" />
<orderEntry type="library" name="com.android.support:design-23.4.0" level="project" />
<orderEntry type="library" name="com.android.support:recyclerview-v7-23.4.0" level="project" />
<orderEntry type="library" name="org.glassfish:javax.annotation:10.0-b28@jar" level="project" />
<orderEntry type="library" name="com.google.guava:guava:19.0@jar" level="project" />
<orderEntry type="library" name="com.google.protobuf:protobuf-lite:3.0.1@jar" level="project" />
<orderEntry type="library" name="io.grpc:grpc-okhttp:1.9.0@jar" level="project" />
<orderEntry type="library" name="com.squareup.okhttp:okhttp:2.5.0@jar" level="project" />
<orderEntry type="library" name="com.android.support:support-core-ui-25.4.0" level="project" />
<orderEntry type="library" name="com.android.support:support-compat-25.4.0" level="project" />
<orderEntry type="library" name="com.google.code.findbugs:jsr305:3.0.0@jar" level="project" />
<orderEntry type="library" name="com.android.support:support-annotations:25.4.0@jar" level="project" />
<orderEntry type="library" name="com.android.support:support-core-utils-25.4.0" level="project" />
<orderEntry type="library" name="com.squareup.okio:okio:1.13.0@jar" level="project" />
<orderEntry type="library" name="com.android.support:support-v4-25.4.0" level="project" />
<orderEntry type="library" name="io.grpc:grpc-core:1.9.0@jar" level="project" />
<orderEntry type="library" name="com.android.support:support-fragment-25.4.0" level="project" />
<orderEntry type="library" name="com.android.support:support-media-compat-25.4.0" level="project" />
<orderEntry type="library" name="io.grpc:grpc-context:1.9.0@jar" level="project" />
<orderEntry type="library" name="com.google.instrumentation:instrumentation-api:0.4.3@jar" level="project" />
<orderEntry type="library" name="com.jakewharton:butterknife-8.8.1" level="project" />
<orderEntry type="library" name="com.jakewharton:butterknife-annotations:8.8.1@jar" level="project" />
<orderEntry type="library" name="com.android.support:animated-vector-drawable-25.4.0" level="project" />
<orderEntry type="library" name="com.google.errorprone:error_prone_annotations:2.1.2@jar" level="project" />
<orderEntry type="library" name="io.opencensus:opencensus-contrib-grpc-metrics:0.10.0@jar" level="project" />
<orderEntry type="library" name="com.android.support:design-25.4.0" level="project" />
<orderEntry type="library" name="com.android.support:transition-25.4.0" level="project" />
<orderEntry type="library" name="io.opencensus:opencensus-api:0.10.0@jar" level="project" />
<orderEntry type="library" name="com.android.support:appcompat-v7-25.4.0" level="project" />
<orderEntry type="library" name="io.grpc:grpc-protobuf-lite:1.9.0@jar" level="project" />
<orderEntry type="library" name="com.android.support:support-vector-drawable-25.4.0" level="project" />
<orderEntry type="library" name="com.android.support:recyclerview-v7-25.4.0" level="project" />
<orderEntry type="library" name="io.grpc:grpc-stub:1.9.0@jar" level="project" />
</component>
</module>
59 changes: 51 additions & 8 deletions app/build.gradle
Original file line number Diff line number Diff line change
@@ -1,28 +1,71 @@
apply plugin: 'com.android.application'
apply plugin: 'com.google.protobuf'

android {
compileSdkVersion 26
compileSdkVersion 25
buildToolsVersion "27.0.3"

defaultConfig {
applicationId "nl.melledijkstra.musicplayerclient"
minSdkVersion 17
targetSdkVersion 26
targetSdkVersion 25
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
debug {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
versionNameSuffix '-dev'
applicationIdSuffix '.dev'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
}

protobuf {
protoc {
artifact = 'com.google.protobuf:protoc:3.5.0'
}
plugins {
javalite {
artifact = 'com.google.protobuf:protoc-gen-javalite:3.0.0'
}
grpc {
artifact = 'io.grpc:protoc-gen-grpc-java:1.9.0'
}
}
generateProtoTasks {
all().each { task ->
task.builtins {
remove java
}
task.plugins {
javalite {}
grpc {
// options added to --grpc-out
option 'lite'
}
}
}
}
}

dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.4.0'
compile 'com.android.support:support-v4:23.4.0'
compile 'com.android.support:design:23.4.0'
implementation 'com.android.support:appcompat-v7:25.4.0'
implementation 'com.android.support:recyclerview-v7:25.4.0'
implementation 'com.android.support:design:25.4.0'
implementation 'io.grpc:grpc-okhttp:1.9.0'
implementation 'io.grpc:grpc-protobuf-lite:1.9.0'
implementation 'io.grpc:grpc-stub:1.9.0'
implementation 'com.google.protobuf:protobuf-lite:3.0.1'
implementation 'org.glassfish:javax.annotation:10.0-b28'
implementation 'com.jakewharton:butterknife:8.8.1'
annotationProcessor 'com.jakewharton:butterknife-compiler:8.8.1'
}
9 changes: 9 additions & 0 deletions app/proguard-rules.pro
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,12 @@
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
# public *;
#}

-assumenosideeffects class android.util.Log {
public static boolean isLoggable(java.lang.String, int);
public static int v(...);
public static int i(...);
public static int w(...);
public static int d(...);
public static int e(...);
}
10 changes: 1 addition & 9 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -31,16 +31,8 @@
<activity
android:name=".ui.MainActivity"
android:screenOrientation="portrait"
android:launchMode="singleInstance"
android:theme="@style/AppTheme.NoActionBar">

<!--
SplashActivity is the Launch activity now
<intent-filter>
<action android:title="android.intent.action.MAIN" />
<category android:title="android.intent.category.LAUNCHER" />
</intent-filter>
-->
</activity>
<activity
android:name=".ui.SettingsActivity"
Expand Down
52 changes: 2 additions & 50 deletions app/src/main/java/nl/melledijkstra/musicplayerclient/App.java
Original file line number Diff line number Diff line change
@@ -1,86 +1,38 @@
package nl.melledijkstra.musicplayerclient;

import android.app.Application;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.SharedPreferences;
import android.preference.PreferenceManager;
import android.support.v4.content.LocalBroadcastManager;
import android.util.Log;

import org.json.JSONException;
import org.json.JSONObject;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;

import nl.melledijkstra.musicplayerclient.config.PreferenceKeys;
import nl.melledijkstra.musicplayerclient.melonplayer.MelonPlayer;

/**
* <p>Created by Melle Dijkstra on 19-4-2016</p>
*/
public class App extends Application {

public static final String TAG = "musicplayerclient";
public static MelonPlayer melonPlayer;
private HashSet<MessageReceiver> jsonReceivers;

/**
* If app is in DEBUG mode then no connection is needed and dummy data is used
*/
public static boolean DEBUG = false;

BroadcastReceiver receiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
String raw_json = intent.getStringExtra("msg");
if(raw_json != null) {
try {
JSONObject json = new JSONObject(raw_json);
if(json.has("mplayer")) melonPlayer.onReceive(json.getJSONObject("mplayer"));
for (MessageReceiver receiver : jsonReceivers) {
receiver.onReceive(json);
}
} catch (JSONException e) {
Log.e(TAG,"Incorrect json data: "+e.getMessage());
e.printStackTrace();
}
}
}
};

public App() {
melonPlayer = new MelonPlayer();
}
public App() {}

@Override
public void onCreate() {
super.onCreate();
jsonReceivers = new HashSet<>();
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
DEBUG = prefs.getBoolean(PreferenceKeys.DEBUG, false);
// the musicclient should be notified when message comes in. It can then update it's state
LocalBroadcastManager.getInstance(this).registerReceiver(receiver, new IntentFilter(MelonPlayerService.MESSAGERECEIVED));
}

/**
* Checks if the debug state has changed and sets the debug state for the application
*/
public void updateDebugState() {
public void checkDebugState() {
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
DEBUG = prefs.getBoolean(PreferenceKeys.DEBUG, false);
}

public void registerMessageReceiver(MessageReceiver receiver) {
jsonReceivers.add(receiver);
}

public void unRegisterMessageReceiver(MessageReceiver receiver) {
jsonReceivers.remove(receiver);
}

}
Loading

0 comments on commit 3ec4b29

Please sign in to comment.