Skip to content

Instantly share code, notes, and snippets.

View kgilmer's full-sized avatar

Ken Gilmer kgilmer

View GitHub Profile
@kgilmer
kgilmer / RemoteJsonSource.java
Created August 22, 2018 00:19
uamp-java Load Music
public class RemoteJSONSource implements MusicProviderSource {
private static final String TAG = LogHelper.makeLogTag(RemoteJSONSource.class);
protected static final String CATALOG_URL =
"http://storage.googleapis.com/automotive-media/music.json";
private static final String JSON_MUSIC = "music";
private static final String JSON_TITLE = "title";
private static final String JSON_ALBUM = "album";
@kgilmer
kgilmer / MainActivity.kt
Created August 22, 2018 00:11
uamp Kotlin Version
class MainActivity : AppCompatActivity() {
private lateinit var viewModel: MainActivityViewModel
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
// Since UAMP is a music player, the volume controls should adjust the music volume while
// in the app.
volumeControlStream = AudioManager.STREAM_MUSIC
@kgilmer
kgilmer / MusicPlayerActivity.java
Created August 22, 2018 00:08
uamp-java Main Activity
public class MusicPlayerActivity extends BaseActivity
implements MediaBrowserFragment.MediaFragmentListener {
private static final String TAG = LogHelper.makeLogTag(MusicPlayerActivity.class);
private static final String SAVED_MEDIA_ID="com.example.android.uamp.MEDIA_ID";
private static final String FRAGMENT_TAG = "uamp_list_container";
public static final String EXTRA_START_FULLSCREEN =
"com.example.android.uamp.EXTRA_START_FULLSCREEN";
Language Command Output
Java time uamp-java/gradlew -b uamp-java/mobile/build.gradle clean assemble real 0m29.688s user 0m2.677s
Kotlin time uamp-java/gradlew -b uamp-kotlin/app/build.gradle clean assemble real 0m27.798s user 0m2.332s
@kgilmer
kgilmer / uamp-metrics.csv
Last active August 21, 2018 10:50
uamp Code Metrics
Metric Java Kotlin Difference Notes
Source Files 52 20 32 fewer files Using find and grepping on file extension
Lines of Code 3719 1084 2635 fewer LoC Using https://github.com/arturbosch/lloc
Class Count 63 29 34 fewer classes using find/grep
package org.uamp.server
import com.sun.net.httpserver.HttpExchange
import com.sun.net.httpserver.HttpServer
import java.io.File
import java.net.InetSocketAddress
import java.net.URI
fun main(args: Array<String>) {
...
/**
* Utility class to get a list of MusicTrack's based on a server-side JSON
* configuration.
*/
public class RemoteJSONSource implements MusicProviderSource {
private static final String TAG = LogHelper.makeLogTag(RemoteJSONSource.class);
import com.sun.net.httpserver.HttpExchange
import com.sun.net.httpserver.HttpServer
import java.io.File
import java.net.InetSocketAddress
import java.net.URI
fun main(args: Array<String>) {
val port = args[0].toIntOrNull() ?: 8080
val basePath = File(args.getOrElse(1, { System.getProperty("user.dir")!! }))
fun fetchFileOrNull(exchange: HttpExchange, basePath: File): File? =
when (validRequest(exchange)) {
true -> {
localFileFromRequestUri(basePath, exchange.requestURI).let { requestedFile ->
if (requestedFile.isFile) requestedFile else null
}
}
false -> null
}
fun fetchFileOrNull(exchange: HttpExchange, basePath: File): File? =
when (validRequest(exchange)) {
true -> {
val resource = localFileFromRequestUri(basePath, exchange.requestURI)
print("Seeking ${resource.absolutePath}...")
if (resource.isFile) resource else null
}
false -> null