Skip to content

Commit

Permalink
Multiple changes (see details)
Browse files Browse the repository at this point in the history
Target Android Pie
Update Android Studio, Gradle, and Kotlin
Change Kotlin jdk7 to jdk8
Compile Java 1.8 (even though we're using Kotlin; it's just a config thing)
Renamed thunder.ogg to storm.ogg
Reformatted code
Renamed vals to lowercase to please Kotlin

Signed-off-by: Taco <[email protected]>
  • Loading branch information
TacoTheDank committed Mar 27, 2019
1 parent b46a2fe commit e18716e
Show file tree
Hide file tree
Showing 25 changed files with 426 additions and 396 deletions.
32 changes: 22 additions & 10 deletions app/build.gradle
Original file line number Diff line number Diff line change
@@ -1,35 +1,47 @@
apply plugin: 'com.android.application'

apply plugin: 'kotlin-android'

apply plugin: 'kotlin-android-extensions'

android {
compileSdkVersion 27
compileSdkVersion 28

defaultConfig {
applicationId "org.mcxa.softsound"
minSdkVersion 16
targetSdkVersion 27
targetSdkVersion 28
versionCode 1
versionName "1.0"

testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}

buildTypes {
release {
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}

compileOptions {
encoding = 'UTF-8'
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}

lintOptions {
disable 'GoogleAppIndexingWarning'
}
}

dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation 'com.android.support:appcompat-v7:27.1.1'
implementation 'com.google.android.exoplayer:exoplayer-core:2.8.4'
implementation 'com.android.support:design:27.1.1'
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version"

implementation 'com.android.support:design:28.0.0'
implementation 'com.android.support:appcompat-v7:28.0.0'

implementation 'com.google.android.exoplayer:exoplayer-core:2.8.4' //2.9.6

testImplementation 'junit:junit:4.12'
testImplementation 'junit:junit:4.13-beta-2'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
}
File renamed without changes.
28 changes: 14 additions & 14 deletions app/src/main/java/org/mcxa/softsound/MainActivity.kt
Original file line number Diff line number Diff line change
@@ -1,26 +1,26 @@
package org.mcxa.softsound

import android.content.Intent
import android.os.Bundle
import android.support.v7.app.AppCompatActivity
import kotlinx.android.synthetic.main.activity_main.*
import android.app.NotificationManager
import android.app.NotificationChannel
import android.app.NotificationManager
import android.content.ComponentName
import android.content.Context
import android.content.Intent
import android.content.ServiceConnection
import android.os.Build
import android.os.Bundle
import android.os.IBinder
import android.support.v7.app.AppCompatActivity
import android.view.View
import android.widget.ProgressBar
import android.widget.SeekBar
import kotlinx.android.synthetic.main.activity_main.*


class MainActivity : AppCompatActivity() {
// handle binding to the player service
private var playerService: PlayerService? = null

private val serviceConnection = object: ServiceConnection {
private val serviceConnection = object : ServiceConnection {
override fun onServiceDisconnected(name: ComponentName?) {}

override fun onServiceConnected(name: ComponentName?, service: IBinder?) {
Expand All @@ -46,14 +46,14 @@ class MainActivity : AppCompatActivity() {
playerService?.toggleSound(PlayerService.Sound.RAIN)
toggleProgressBar(rain_volume)
}
play_storm.setOnClickListener {
playerService?.toggleSound(PlayerService.Sound.STORM)
toggleProgressBar(storm_volume)
}
play_water.setOnClickListener {
playerService?.toggleSound(PlayerService.Sound.WATER)
toggleProgressBar(water_volume)
}
play_storm.setOnClickListener {
playerService?.toggleSound(PlayerService.Sound.THUNDER)
toggleProgressBar(storm_volume)
}
play_fire.setOnClickListener {
playerService?.toggleSound(PlayerService.Sound.FIRE)
toggleProgressBar(fire_volume)
Expand All @@ -72,8 +72,8 @@ class MainActivity : AppCompatActivity() {
}

rain_volume.setOnSeekBarChangeListener(VolumeChangeListener(PlayerService.Sound.RAIN))
storm_volume.setOnSeekBarChangeListener(VolumeChangeListener(PlayerService.Sound.STORM))
water_volume.setOnSeekBarChangeListener(VolumeChangeListener(PlayerService.Sound.WATER))
storm_volume.setOnSeekBarChangeListener(VolumeChangeListener(PlayerService.Sound.THUNDER))
fire_volume.setOnSeekBarChangeListener(VolumeChangeListener(PlayerService.Sound.FIRE))
wind_volume.setOnSeekBarChangeListener(VolumeChangeListener(PlayerService.Sound.WIND))
night_volume.setOnSeekBarChangeListener(VolumeChangeListener(PlayerService.Sound.NIGHT))
Expand All @@ -83,8 +83,8 @@ class MainActivity : AppCompatActivity() {
playerService?.stopPlaying()
fab.hide()
// hide all volume bars
arrayOf(rain_volume,water_volume,storm_volume,fire_volume,wind_volume,night_volume,cat_volume).forEach {
bar -> bar.visibility = View.INVISIBLE
arrayOf(rain_volume, storm_volume, water_volume, fire_volume, wind_volume, night_volume, cat_volume).forEach { bar ->
bar.visibility = View.INVISIBLE
}
}
}
Expand All @@ -93,7 +93,7 @@ class MainActivity : AppCompatActivity() {
progressBar.visibility = if (progressBar.visibility == View.VISIBLE) View.INVISIBLE else View.VISIBLE
}

inner class VolumeChangeListener(val sound: PlayerService.Sound): SeekBar.OnSeekBarChangeListener {
inner class VolumeChangeListener(private val sound: PlayerService.Sound) : SeekBar.OnSeekBarChangeListener {
override fun onProgressChanged(seekBar: SeekBar?, progress: Int, fromUser: Boolean) {
playerService?.setVolume(sound, (progress + 1) / 20f)
}
Expand Down
39 changes: 20 additions & 19 deletions app/src/main/java/org/mcxa/softsound/PlayerService.kt
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
package org.mcxa.softsound

import android.app.PendingIntent
import android.app.Service
import android.content.Intent
import android.net.Uri
import android.os.Binder
import android.os.Build.VERSION.SDK_INT
import android.os.IBinder
import android.support.v4.app.NotificationCompat
import android.util.Log
import com.google.android.exoplayer2.DefaultRenderersFactory
import com.google.android.exoplayer2.ExoPlayerFactory
Expand All @@ -13,25 +17,21 @@ import com.google.android.exoplayer2.source.ExtractorMediaSource
import com.google.android.exoplayer2.trackselection.DefaultTrackSelector
import com.google.android.exoplayer2.upstream.DefaultDataSourceFactory
import com.google.android.exoplayer2.util.Util
import android.app.PendingIntent
import android.app.Service
import android.os.Binder
import android.support.v4.app.NotificationCompat

class PlayerService : Service() {
val NOTIFICATION_ID = 132
val TAG = "Player"
private val notificationID = 132
private val tag = "Player"

// called when sound is started or stopped
var playerChangeListener: (()->Unit)? = null
var playerChangeListener: (() -> Unit)? = null

inner class PlayerBinder: Binder() {
inner class PlayerBinder : Binder() {
fun getService(): PlayerService {
return this@PlayerService
}
}

val playerBinder = PlayerBinder()
private val playerBinder = PlayerBinder()

override fun onCreate() {
// load each player into the map
Expand All @@ -42,9 +42,9 @@ class PlayerService : Service() {

enum class Sound(val file: String) {
RAIN("rain.ogg"),
THUNDER("thunder.ogg"),
FIRE("fire.ogg"),
STORM("storm.ogg"),
WATER("water.ogg"),
FIRE("fire.ogg"),
WIND("wind.ogg"),
NIGHT("night.ogg"),
PURR("purr.ogg")
Expand All @@ -61,10 +61,11 @@ class PlayerService : Service() {
// load the media source
val dataSource = DefaultDataSourceFactory(this,
Util.getUserAgent(this, this.getString(R.string.app_name)))
val mediaSource = ExtractorMediaSource.Factory(dataSource).createMediaSource(Uri.parse("asset:///${soundFile}"))
val mediaSource = ExtractorMediaSource.Factory(dataSource)
.createMediaSource(Uri.parse("asset:///$soundFile"))

// load the media
Log.d("MAIN", "loading ${soundFile}")
Log.d("MAIN", "loading $soundFile")
exoPlayer.prepare(mediaSource)
// loop indefinitely
exoPlayer.repeatMode = Player.REPEAT_MODE_ALL
Expand All @@ -75,9 +76,9 @@ class PlayerService : Service() {
override fun onUnbind(intent: Intent?): Boolean {
// don't continue if we're not playing any sound and the main activity exits
playerChangeListener = null
if(!isPlaying()) {
if (!isPlaying()) {
stopSelf()
Log.d(TAG, "stopping service")
Log.d(tag, "stopping service")
}
return super.onUnbind(intent)
}
Expand All @@ -100,21 +101,21 @@ class PlayerService : Service() {
.setContentIntent(pendingIntent)
.build()

Log.d(TAG, "starting foreground service")
startForeground(NOTIFICATION_ID, notification)
Log.d(tag, "starting foreground service...")
startForeground(notificationID, notification)
}
}

fun stopForeground() {
// we don't need to be foreground anymore
if (SDK_INT >= 24) {
Log.d(TAG, "stopping foreground service")
Log.d(tag, "stopping foreground service...")
stopForeground(STOP_FOREGROUND_REMOVE)
}
}

fun stopPlaying() {
exoPlayers.values.forEach {it.playWhenReady = false }
exoPlayers.values.forEach { it.playWhenReady = false }
}

fun isPlaying(): Boolean {
Expand Down
12 changes: 6 additions & 6 deletions app/src/main/res/drawable-v24/ic_launcher_foreground.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@
xmlns:aapt="http://schemas.android.com/aapt"
android:width="108dp"
android:height="108dp"
android:viewportHeight="108"
android:viewportWidth="108">
android:viewportWidth="108"
android:viewportHeight="108">
<path
android:fillType="evenOdd"
android:pathData="M32,64C32,64 38.39,52.99 44.13,50.95C51.37,48.37 70.14,49.57 70.14,49.57L108.26,87.69L108,109.01L75.97,107.97L32,64Z"
android:strokeColor="#00000000"
android:strokeWidth="1">
android:strokeWidth="1"
android:strokeColor="#00000000">
<aapt:attr name="android:fillColor">
<gradient
android:endX="78.5885"
Expand All @@ -29,6 +29,6 @@
android:fillColor="#FFFFFF"
android:fillType="nonZero"
android:pathData="M66.94,46.02L66.94,46.02C72.44,50.07 76,56.61 76,64L32,64C32,56.61 35.56,50.11 40.98,46.06L36.18,41.19C35.45,40.45 35.45,39.3 36.18,38.56C36.91,37.81 38.05,37.81 38.78,38.56L44.25,44.05C47.18,42.57 50.48,41.71 54,41.71C57.48,41.71 60.78,42.57 63.68,44.05L69.11,38.56C69.84,37.81 70.98,37.81 71.71,38.56C72.44,39.3 72.44,40.45 71.71,41.19L66.94,46.02ZM62.94,56.92C64.08,56.92 65,56.01 65,54.88C65,53.76 64.08,52.85 62.94,52.85C61.8,52.85 60.88,53.76 60.88,54.88C60.88,56.01 61.8,56.92 62.94,56.92ZM45.06,56.92C46.2,56.92 47.13,56.01 47.13,54.88C47.13,53.76 46.2,52.85 45.06,52.85C43.92,52.85 43,53.76 43,54.88C43,56.01 43.92,56.92 45.06,56.92Z"
android:strokeColor="#00000000"
android:strokeWidth="1" />
android:strokeWidth="1"
android:strokeColor="#00000000" />
</vector>
8 changes: 5 additions & 3 deletions app/src/main/res/drawable/ic_cat.xml
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:height="24dp"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24">
<path android:fillColor="#283593" android:pathData="M12,8L10.67,8.09C9.81,7.07 7.4,4.5 5,4.5C5,4.5 3.03,7.46 4.96,11.41C4.41,12.24 4.07,12.67 4,13.66L2.07,13.95L2.28,14.93L4.04,14.67L4.18,15.38L2.61,16.32L3.08,17.21L4.53,16.32C5.68,18.76 8.59,20 12,20C15.41,20 18.32,18.76 19.47,16.32L20.92,17.21L21.39,16.32L19.82,15.38L19.96,14.67L21.72,14.93L21.93,13.95L20,13.66C19.93,12.67 19.59,12.24 19.04,11.41C20.97,7.46 19,4.5 19,4.5C16.6,4.5 14.19,7.07 13.33,8.09L12,8M9,11A1,1 0 0,1 10,12A1,1 0 0,1 9,13A1,1 0 0,1 8,12A1,1 0 0,1 9,11M15,11A1,1 0 0,1 16,12A1,1 0 0,1 15,13A1,1 0 0,1 14,12A1,1 0 0,1 15,11M11,14H13L12.3,15.39C12.5,16.03 13.06,16.5 13.75,16.5A1.5,1.5 0 0,0 15.25,15H15.75A2,2 0 0,1 13.75,17C13,17 12.35,16.59 12,16V16H12C11.65,16.59 11,17 10.25,17A2,2 0 0,1 8.25,15H8.75A1.5,1.5 0 0,0 10.25,16.5C10.94,16.5 11.5,16.03 11.7,15.39L11,14Z" />
</vector>
<path
android:fillColor="#283593"
android:pathData="M12,8L10.67,8.09C9.81,7.07 7.4,4.5 5,4.5C5,4.5 3.03,7.46 4.96,11.41C4.41,12.24 4.07,12.67 4,13.66L2.07,13.95L2.28,14.93L4.04,14.67L4.18,15.38L2.61,16.32L3.08,17.21L4.53,16.32C5.68,18.76 8.59,20 12,20C15.41,20 18.32,18.76 19.47,16.32L20.92,17.21L21.39,16.32L19.82,15.38L19.96,14.67L21.72,14.93L21.93,13.95L20,13.66C19.93,12.67 19.59,12.24 19.04,11.41C20.97,7.46 19,4.5 19,4.5C16.6,4.5 14.19,7.07 13.33,8.09L12,8M9,11A1,1 0 0,1 10,12A1,1 0 0,1 9,13A1,1 0 0,1 8,12A1,1 0 0,1 9,11M15,11A1,1 0 0,1 16,12A1,1 0 0,1 15,13A1,1 0 0,1 14,12A1,1 0 0,1 15,11M11,14H13L12.3,15.39C12.5,16.03 13.06,16.5 13.75,16.5A1.5,1.5 0 0,0 15.25,15H15.75A2,2 0 0,1 13.75,17C13,17 12.35,16.59 12,16V16H12C11.65,16.59 11,17 10.25,17A2,2 0 0,1 8.25,15H8.75A1.5,1.5 0 0,0 10.25,16.5C10.94,16.5 11.5,16.03 11.7,15.39L11,14Z" />
</vector>
8 changes: 5 additions & 3 deletions app/src/main/res/drawable/ic_fire.xml
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:height="24dp"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24">
<path android:fillColor="#283593" android:pathData="M11.71,19C9.93,19 8.5,17.59 8.5,15.86C8.5,14.24 9.53,13.1 11.3,12.74C13.07,12.38 14.9,11.53 15.92,10.16C16.31,11.45 16.5,12.81 16.5,14.2C16.5,16.84 14.36,19 11.71,19M13.5,0.67C13.5,0.67 14.24,3.32 14.24,5.47C14.24,7.53 12.89,9.2 10.83,9.2C8.76,9.2 7.2,7.53 7.2,5.47L7.23,5.1C5.21,7.5 4,10.61 4,14A8,8 0 0,0 12,22A8,8 0 0,0 20,14C20,8.6 17.41,3.8 13.5,0.67Z" />
</vector>
<path
android:fillColor="#283593"
android:pathData="M11.71,19C9.93,19 8.5,17.59 8.5,15.86C8.5,14.24 9.53,13.1 11.3,12.74C13.07,12.38 14.9,11.53 15.92,10.16C16.31,11.45 16.5,12.81 16.5,14.2C16.5,16.84 14.36,19 11.71,19M13.5,0.67C13.5,0.67 14.24,3.32 14.24,5.47C14.24,7.53 12.89,9.2 10.83,9.2C8.76,9.2 7.2,7.53 7.2,5.47L7.23,5.1C5.21,7.5 4,10.61 4,14A8,8 0 0,0 12,22A8,8 0 0,0 20,14C20,8.6 17.41,3.8 13.5,0.67Z" />
</vector>
Loading

0 comments on commit e18716e

Please sign in to comment.