-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4 from MelleDijkstra/grpc
gRPC Implementation
- Loading branch information
Showing
47 changed files
with
2,107 additions
and
1,695 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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' | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
52 changes: 2 additions & 50 deletions
52
app/src/main/java/nl/melledijkstra/musicplayerclient/App.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
|
||
} |
Oops, something went wrong.