Skip to content

Commit

Permalink
Fixes for Android 14
Browse files Browse the repository at this point in the history
  • Loading branch information
thetwom committed Oct 6, 2023
1 parent 4e9e660 commit 22d26e7
Show file tree
Hide file tree
Showing 13 changed files with 36 additions and 21 deletions.
2 changes: 1 addition & 1 deletion .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ Simple metronome app.
alt="Get it on Google Play"
height="80">](https://play.google.com/store/apps/details?id=de.moekadu.metronome)

|![screenshot-0](https://github.com/thetwom/toc2/blob/master/fastlane/metadata/android/en-US/images/phoneScreenshots/00.png) |![screenshot-1](https://github.com/thetwom/toc2/blob/master/fastlane/metadata/android/en-US/images/phoneScreenshots/01.png) |![screenshot-2](https://github.com/thetwom/toc2/blob/master/fastlane/metadata/android/en-US/images/phoneScreenshots/02.png) |![screenshot-3](https://github.com/thetwom/toc2/blob/master/fastlane/metadata/android/en-US/images/phoneScreenshots/03.png) |![screenshot-4](https://github.com/thetwom/toc2/blob/master/fastlane/metadata/android/en-US/images/phoneScreenshots/04.png)
|---|---|---|---|---|
| ![screenshot-0](https://github.com/thetwom/toc2/blob/master/fastlane/metadata/android/en-US/images/phoneScreenshots/00.png) | ![screenshot-1](https://github.com/thetwom/toc2/blob/master/fastlane/metadata/android/en-US/images/phoneScreenshots/01.png) | ![screenshot-2](https://github.com/thetwom/toc2/blob/master/fastlane/metadata/android/en-US/images/phoneScreenshots/02.png) | ![screenshot-3](https://github.com/thetwom/toc2/blob/master/fastlane/metadata/android/en-US/images/phoneScreenshots/03.png) | ![screenshot-4](https://github.com/thetwom/toc2/blob/master/fastlane/metadata/android/en-US/images/phoneScreenshots/04.png) |
|-----------------------------------------------------------------------------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------------------|

# Functionality

Expand Down
16 changes: 8 additions & 8 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@ apply plugin: 'kotlin-android'
apply plugin: 'kotlin-parcelize'

android {
compileSdkVersion 34
compileSdk 34
defaultConfig {
applicationId "de.moekadu.metronome"
minSdkVersion 23
targetSdkVersion 34
versionCode 57
versionName "4.10.0"
versionCode 58
versionName "4.11.0"

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
vectorDrawables.useSupportLibrary = true
Expand All @@ -34,20 +34,20 @@ android {
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'androidx.appcompat:appcompat:1.6.1'
implementation 'androidx.activity:activity-ktx:1.7.2'
implementation 'androidx.activity:activity-ktx:1.8.0'
implementation 'androidx.fragment:fragment-ktx:1.6.1'
implementation 'com.google.android.material:material:1.11.0-alpha02'
implementation 'com.google.android.material:material:1.11.0-alpha03'
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core:1.7.1'
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
implementation 'androidx.media:media:1.6.0'
implementation 'androidx.dynamicanimation:dynamicanimation:1.1.0-alpha03'
implementation 'androidx.preference:preference-ktx:1.2.1'
implementation 'androidx.lifecycle:lifecycle-runtime-ktx:2.6.1'
implementation 'androidx.lifecycle:lifecycle-service:2.6.1'
implementation 'androidx.lifecycle:lifecycle-runtime-ktx:2.6.2'
implementation 'androidx.lifecycle:lifecycle-service:2.6.2'
implementation "androidx.recyclerview:recyclerview:1.3.1"
implementation "androidx.viewpager2:viewpager2:1.1.0-beta02"
testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test:runner:1.5.2'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1'
implementation 'androidx.core:core-ktx:1.10.1'
implementation 'androidx.core:core-ktx:1.12.0'
}
2 changes: 2 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android">

<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
<uses-permission android:name="android.permission.FOREGROUND_SERVICE_MEDIA_PLAYBACK" />
<uses-permission android:name="android.permission.POST_NOTIFICATIONS" />
<uses-permission android:name="android.permission.VIBRATE"/>

Expand Down Expand Up @@ -56,6 +57,7 @@
<service
android:name="de.moekadu.metronome.services.PlayerService"
android:enabled="true"
android:foregroundServiceType="mediaPlayback"
android:exported="false" />
<!--
<receiver android:name=".MainActivity$NotificationReceiver" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ fun audioToPCM(id : Int, context : Context) : FloatArray {
)

if (!sawInputEOS)
mediaExtractor.advance()
mediaExtractor.advance()
}
}

Expand Down
5 changes: 2 additions & 3 deletions app/src/main/java/de/moekadu/metronome/audio/AudioMixer.kt
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ private data class SynchronizeTimeInfo(val referenceTimeNanos: Long, val beatDur
/** We use not the minimum buffer size but scale it with this integer value.
* A factor of 4 or larger seems to be necessary, to have noteStartedListeners registered early
* enough to get a correct vibration/visualization behavior. */
private const val minBufferSizeFactor = 4
private const val MIN_BUFFER_SIZE_FACTOR = 4

private val getLatencyMethod = try {
AudioTrack::class.java.getMethod("getLatency")
Expand Down Expand Up @@ -696,7 +696,7 @@ private class Mixer(context: Context, val scope: CoroutineScope) {
*/
private fun createPlayer(): AudioTrack {
val nativeSampleRate = AudioTrack.getNativeOutputSampleRate(AudioManager.STREAM_MUSIC)
val bufferSize = minBufferSizeFactor * AudioTrack.getMinBufferSize(nativeSampleRate, AudioFormat.CHANNEL_OUT_MONO, AudioFormat.ENCODING_PCM_FLOAT)
val bufferSize = MIN_BUFFER_SIZE_FACTOR * AudioTrack.getMinBufferSize(nativeSampleRate, AudioFormat.CHANNEL_OUT_MONO, AudioFormat.ENCODING_PCM_FLOAT)

return AudioTrack.Builder()
.setAudioAttributes(
Expand Down Expand Up @@ -735,7 +735,6 @@ private class Mixer(context: Context, val scope: CoroutineScope) {
* @param bpmQuarter Metronome speed in quarter notes per minute
* @param nextNoteInfo Info about the next note which is about to be queued
* @param sampleRate Sample rate in Hz
* @param delayInFrames Delay which is used for playing notes.
* @param alreadyQueuedFrames Frame number up to which we did already queued the notes.
* @param frameTimeConversion Conversion between uptime millis and frame number.
* @return Info about next notes to be played.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,18 @@

package de.moekadu.metronome.notification

import android.Manifest
import android.app.NotificationManager
import android.app.PendingIntent
import android.content.Context
import android.content.Intent
import android.content.pm.PackageManager
import android.os.Handler
import android.os.Looper
import android.os.Message
import android.support.v4.media.session.PlaybackStateCompat
import android.widget.RemoteViews
import androidx.core.app.ActivityCompat
import androidx.core.app.NotificationCompat
import androidx.core.app.NotificationManagerCompat
import de.moekadu.metronome.*
Expand Down Expand Up @@ -86,9 +89,12 @@ class PlayerNotification(val context: PlayerService) {
}
}

if (haveActiveNotification)
if (haveActiveNotification &&
ActivityCompat.checkSelfPermission(context, Manifest.permission.POST_NOTIFICATIONS) == PackageManager.PERMISSION_GRANTED
) {
NotificationManagerCompat.from(context)
.notify(NOTIFICATION_ID, notificationBuilder.build())
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,6 @@ class VibratingNote(context: Context) {

/** Vibrate.
* @param note Note which is played.
* @param noteStartTimeNanos Time in System.nanoTime() when note starts playing.
* @param noteDurationNanos Note duration as derived from note duration and bpm in nano seconds.
*/
fun vibrate(note: NoteListItem, noteDurationNanos: Long) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import android.os.IBinder
import android.support.v4.media.session.MediaSessionCompat
import android.support.v4.media.session.PlaybackStateCompat
import android.util.Log
import androidx.core.content.ContextCompat
import androidx.lifecycle.LifecycleService
import androidx.lifecycle.lifecycleScope
import androidx.preference.PreferenceManager
Expand Down Expand Up @@ -201,7 +202,8 @@ class PlayerService : LifecycleService() {
super.onCreate()

val filter = IntentFilter(BROADCAST_PLAYERACTION)
registerReceiver(actionReceiver, filter)

ContextCompat.registerReceiver(this, actionReceiver, filter, ContextCompat.RECEIVER_NOT_EXPORTED)

val sharedPreferences = PreferenceManager.getDefaultSharedPreferences(applicationContext)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ class GridSelection(val numRows: Int, val numCols: Int, val buttonSpacing: Int,
for (iRow in 0 until numRows) {
val h = if (iRow <= numHigherButtons) buttonHeightSpecHigh else buttonHeightSpec
for (iCol in 0 until numCols) {
val w = if (iCol <= numWiderButtons) buttonWidthSpecWide else buttonWidthSpec
val w = if (iCol <= numWiderButtons) buttonWidthSpecWide else buttonWidthSpec
buttons.forEach { it.measure(w, h) }
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,6 @@ class NoteViewVolume(context : Context) : View(context) {
path.lineTo(volumes.size * noteWidth, volumeMin)
path.close()

canvas?.drawPath(path, paint)
canvas.drawPath(path, paint)
}
}
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ buildscript {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:8.0.2'
classpath 'com.android.tools.build:gradle:8.1.2'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"


Expand Down
7 changes: 7 additions & 0 deletions fastlane/metadata/android/en-US/changelogs/58.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
v4.11.0:
- Make app work on Android 14

v4.10.0:
- Russian translations (Thanks to Aleksey)
- Update dependencies

0 comments on commit 22d26e7

Please sign in to comment.