Skip to content

Commit

Permalink
upgrade to gradle 7.4.1, fix "uninitialized wai" bug
Browse files Browse the repository at this point in the history
  • Loading branch information
tschudin committed Jul 29, 2024
1 parent 2b46cdc commit e445c8c
Show file tree
Hide file tree
Showing 7 changed files with 77 additions and 75 deletions.
6 changes: 5 additions & 1 deletion android/tinySSB/app/build.gradle
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
apply plugin: 'kotlin-kapt'

android {
namespace "tremolavossbol"
compileSdk 30
buildToolsVersion "30.0.3"

buildFeatures {
viewBinding = true
}

defaultConfig {
applicationId "nz.scuttlebutt.tremolavossbol"
minSdkVersion 26
Expand Down
3 changes: 1 addition & 2 deletions android/tinySSB/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="tremolavossbol">
xmlns:tools="http://schemas.android.com/tools">

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,10 +80,6 @@ class MainActivity : Activity() {
// tremolaState = TremolaState(this)
idStore = IdStore(this)

// upgrades repo filesystem if necessary
tinyRepo.upgrade_repo()


// wifiManager = applicationContext.getSystemService(WIFI_SERVICE) as WifiManager
// mlock = wifiManager?.createMulticastLock("lock")
// if (!mlock!!.isHeld) mlock!!.acquire()
Expand All @@ -93,6 +89,8 @@ class MainActivity : Activity() {

val webView = findViewById<WebView>(R.id.webView)
wai = WebAppInterface(this, webView)
// upgrades repo filesystem if necessary
tinyRepo.upgrade_repo()
tinyIO = IO(this, wai)
tinyGoset._include_key(idStore.identity.verifyKey) // make sure our local key is in
tinyRepo.load()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,21 +11,21 @@ import android.view.View.VISIBLE
import android.widget.*
import androidx.appcompat.app.AppCompatActivity
import androidx.core.content.res.ResourcesCompat
import kotlinx.android.synthetic.main.activity_play.*
import nz.scuttlebutt.tremolavossbol.audio.Codec2
import nz.scuttlebutt.tremolavossbol.audio.Codec2Player
import nz.scuttlebutt.tremolavossbol.audio.Wav
import tremolavossbol.R
import tremolavossbol.databinding.ActivityPlayBinding
import java.io.ByteArrayInputStream
import java.io.File
import java.io.FileOutputStream
import java.io.OutputStream
import java.text.SimpleDateFormat
import java.util.*


class PlayActivity: AppCompatActivity(), AdapterView.OnItemSelectedListener {

private lateinit var binding: ActivityPlayBinding
private val refreshRate = 60L
private lateinit var runnable : Runnable
private lateinit var handler : Handler
Expand All @@ -37,12 +37,15 @@ class PlayActivity: AppCompatActivity(), AdapterView.OnItemSelectedListener {

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_play)
binding = ActivityPlayBinding.inflate(layoutInflater)
val view = binding.root
// setContentView(R.layout.activity_play)
setContentView(view)

setSupportActionBar(toolbar)
setSupportActionBar(binding.toolbar)
supportActionBar?.setDisplayHomeAsUpEnabled(true)
supportActionBar?.setDisplayShowHomeEnabled(true)
toolbar.setNavigationOnClickListener {
binding.toolbar.setNavigationOnClickListener {
onBackPressed()
}

Expand Down Expand Up @@ -72,34 +75,34 @@ class PlayActivity: AppCompatActivity(), AdapterView.OnItemSelectedListener {
}
var from = intent.getStringExtra("from")
var date = intent.getStringExtra("date")
playerFrom.text = if (from == null) "" else from
playerWhen.text = if (date == null) "" else date
binding.playerFrom.text = if (from == null) "" else from
binding.playerWhen.text = if (date == null) "" else date

handler = Handler(Looper.getMainLooper())

btnPlay.setOnClickListener {
binding.btnPlay.setOnClickListener {
playPausePlayer()
}

btnForward.setOnClickListener {
binding.btnForward.setOnClickListener {
if (mediaPlayer.isPlaying) freeze()
mediaPlayer.seekTo(mediaPlayer.currentPosition() + 1000)
seekBar.progress = mediaPlayer.currentPosition()
binding.seekBar.progress = mediaPlayer.currentPosition()
}

btnBackward.setOnClickListener {
binding.btnBackward.setOnClickListener {
if (mediaPlayer.isPlaying) freeze()
mediaPlayer.seekTo(mediaPlayer.currentPosition() - 1000)
seekBar.progress = mediaPlayer.currentPosition()
binding.seekBar.progress = mediaPlayer.currentPosition()
}

seekBar.setOnSeekBarChangeListener(object: SeekBar.OnSeekBarChangeListener{
binding.seekBar.setOnSeekBarChangeListener(object: SeekBar.OnSeekBarChangeListener{
override fun onProgressChanged(p0: SeekBar?, p1: Int, p2: Boolean) {}
override fun onStartTrackingTouch(p0: SeekBar?) {
if (mediaPlayer.isPlaying) freeze()
}
override fun onStopTrackingTouch(p0: SeekBar?) {
mediaPlayer.seekTo(seekBar.progress)
mediaPlayer.seekTo(binding.seekBar.progress)
}
})

Expand Down Expand Up @@ -137,7 +140,7 @@ class PlayActivity: AppCompatActivity(), AdapterView.OnItemSelectedListener {
return fname
}

btnSave.setOnClickListener {
binding.btnSave.setOnClickListener {
/*
Log.d("player", "done")
val voice = Codec2.makeHeader(c2mode) + c2data!!
Expand Down Expand Up @@ -185,19 +188,19 @@ class PlayActivity: AppCompatActivity(), AdapterView.OnItemSelectedListener {
mediaPlayer?.prepare()

val millis = mediaPlayer.duration()
seekBar.max = millis
totalTime.text = String.format("%02d:%02d.%1d",
binding.seekBar.max = millis
binding.totalTime.text = String.format("%02d:%02d.%1d",
millis/60/1000, (millis/1000)%60, (millis/100)%10)
if (c2data!!.size >= 1000)
totalBytes.text = String.format("%.1f KB", c2data!!.size/1024.0)
binding.totalBytes.text = String.format("%.1f KB", c2data!!.size/1024.0)
else
totalBytes.text = String.format("%d B", c2data!!.size)
binding.totalBytes.text = String.format("%d B", c2data!!.size)
}

private fun freeze() {
handler.removeCallbacks(runnable)
mediaPlayer.pause()
btnPlay.background = ResourcesCompat.getDrawable(resources, R.drawable.ic_play_circle, theme)
binding.btnPlay.background = ResourcesCompat.getDrawable(resources, R.drawable.ic_play_circle, theme)
}

private fun playPausePlayer(){
Expand All @@ -206,21 +209,21 @@ class PlayActivity: AppCompatActivity(), AdapterView.OnItemSelectedListener {
else {
if (mediaPlayer.currentPosition() >= mediaPlayer.duration()) {
mediaPlayer.seekTo(0)
seekBar.progress = 0
binding.seekBar.progress = 0
}
mediaPlayer.start()
btnPlay.background = ResourcesCompat.getDrawable(resources,
binding.btnPlay.background = ResourcesCompat.getDrawable(resources,
R.drawable.ic_pause_circle, theme)

runnable = Runnable {
var progress = mediaPlayer.currentPosition()
seekBar.progress = progress
binding.seekBar.progress = progress
if (progress >= mediaPlayer.duration()) {
btnPlay.background =
binding.btnPlay.background =
ResourcesCompat.getDrawable(resources, R.drawable.ic_play_circle, theme)
} else {
val amp = mediaPlayer.getAmplitude()
playerView.updateAmps(amp)
binding.playerView.updateAmps(amp)
handler.postDelayed(runnable, refreshRate)
}
}
Expand All @@ -234,10 +237,10 @@ class PlayActivity: AppCompatActivity(), AdapterView.OnItemSelectedListener {
mediaPlayer.stop()
mediaPlayer.release()

btnSave.visibility = VISIBLE
binding.btnSave.visibility = VISIBLE
// findViewById<Spinner>(R.id.c2modeSpinner).isClickable = true
(findViewById<Spinner>(R.id.c2modeSelect) as Spinner).setEnabled(true)
fileNameView.text = ""
binding.fileNameView.text = ""

super.onBackPressed()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,19 @@ import android.provider.MediaStore
import android.text.method.ScrollingMovementMethod
import android.util.Log
import android.view.View
import android.widget.Toast
import androidx.appcompat.app.AppCompatActivity
import androidx.core.app.ActivityCompat
import kotlinx.android.synthetic.main.activity_record.*
import nz.scuttlebutt.tremolavossbol.audio.Codec2
import nz.scuttlebutt.tremolavossbol.audio.PCMRecorder
import nz.scuttlebutt.tremolavossbol.audio.Timer
import tremolavossbol.R
import tremolavossbol.databinding.ActivityRecordBinding
import java.io.ByteArrayOutputStream


class RecordActivity : AppCompatActivity(), Timer.OnTimerUpdateListener {
private lateinit var binding: ActivityRecordBinding

private val PERMISSION_REQUEST = 789
private val CHOOSEFILE_REQUEST = 987

Expand All @@ -42,10 +43,13 @@ class RecordActivity : AppCompatActivity(), Timer.OnTimerUpdateListener {

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_record)
binding = ActivityRecordBinding.inflate(layoutInflater)
val view = binding.root
setContentView(view)
// setContentView(R.layout.activity_record)

aboutView.setMovementMethod(ScrollingMovementMethod())
aboutView.text = """
binding.aboutView.setMovementMethod(ScrollingMovementMethod())
binding.aboutView.text = """
-- About Codec2 Recorder --
This app records voice and compresses it using Codec2: You can listen to the compression result before saving the file. This app also permits to play back Codec2 files.
Expand All @@ -67,26 +71,26 @@ Save icon by Zwoelf, http://www.zwoelf.hu/, free for commercial use license, con

handler = Handler(Looper.myLooper()!!)

titleTextView.setOnClickListener {
mainLayout.visibility = View.GONE
aboutView.visibility = View.VISIBLE
binding.titleTextView.setOnClickListener {
binding.mainLayout.visibility = View.GONE
binding.aboutView.visibility = View.VISIBLE
}

recordBtn.setOnClickListener {
binding.recordBtn.setOnClickListener {
if (recording)
stopRecording()
else
startRecording()
}

btnLoad.setOnClickListener {
binding.btnLoad.setOnClickListener {
if (recording)
stopRecording()
reset()
load_file()
}

doneBtn.setOnClickListener {
binding.doneBtn.setOnClickListener {
stopRecording()
val _result = intent // Intent(this, MainActivity::class.java) // intent
val c2mode = Codec2.CODEC2_MODE_1300
Expand All @@ -98,13 +102,13 @@ Save icon by Zwoelf, http://www.zwoelf.hu/, free for commercial use license, con
// reset()
}

deleteBtn.setOnClickListener {
binding.deleteBtn.setOnClickListener {
stopRecording()
reset()
}

timer = Timer(this)
timerView.text = "00:00.0"
binding.timerView.text = "00:00.0"

Log.d("recorder", "start recording now")
}
Expand All @@ -117,17 +121,17 @@ Save icon by Zwoelf, http://www.zwoelf.hu/, free for commercial use license, con
private fun reset() {
pcmData = ShortArray(0)

doneBtn.visibility = View.INVISIBLE
doneBtn.isClickable = false
deleteBtn.visibility = View.INVISIBLE
deleteBtn.isClickable = false
recordBtn.setImageResource(R.drawable.ic_record)
binding.doneBtn.visibility = View.INVISIBLE
binding.doneBtn.isClickable = false
binding.deleteBtn.visibility = View.INVISIBLE
binding.deleteBtn.isClickable = false
binding.recordBtn.setImageResource(R.drawable.ic_record)

try {
timer.stop()
} catch (e: Exception){}
timer = Timer(this)
timerView.text = "00:00.0"
binding.timerView.text = "00:00.0"
}

override fun onRequestPermissionsResult(
Expand All @@ -152,11 +156,11 @@ Save icon by Zwoelf, http://www.zwoelf.hu/, free for commercial use license, con
return
}

doneBtn.visibility = View.VISIBLE
doneBtn.isClickable = true
deleteBtn.visibility = View.VISIBLE
deleteBtn.isClickable = true
recordBtn.setImageResource(R.drawable.ic_pause)
binding.doneBtn.visibility = View.VISIBLE
binding.doneBtn.isClickable = true
binding.deleteBtn.visibility = View.VISIBLE
binding.deleteBtn.isClickable = true
binding.recordBtn.setImageResource(R.drawable.ic_pause)

recording = true
timer.start()
Expand All @@ -179,7 +183,7 @@ Save icon by Zwoelf, http://www.zwoelf.hu/, free for commercial use license, con
private fun animatePlayerView(){
if(recording){
var amp = recorder!!.maxAmplitude.toInt()
recorderView.updateAmps(amp/4)
binding.recorderView.updateAmps(amp/4)
handler.postDelayed(
Runnable {
kotlin.run { animatePlayerView() }
Expand All @@ -195,9 +199,9 @@ Save icon by Zwoelf, http://www.zwoelf.hu/, free for commercial use license, con
// release()
}
recorder = null
recordBtn.setImageResource(R.drawable.ic_record)
binding.recordBtn.setImageResource(R.drawable.ic_record)

recorderView.reset()
binding.recorderView.reset()
timer.pause()
}

Expand Down Expand Up @@ -287,14 +291,14 @@ Save icon by Zwoelf, http://www.zwoelf.hu/, free for commercial use license, con
override fun onTimerUpdate(duration: String) {
runOnUiThread {
if (recording)
timerView.text = duration.subSequence(0..6)
binding.timerView.text = duration.subSequence(0..6)
}
}

override fun onBackPressed() {
if (aboutView.visibility == View.VISIBLE) {
aboutView.visibility = View.GONE
mainLayout.visibility = View.VISIBLE
if (binding.aboutView.visibility == View.VISIBLE) {
binding.aboutView.visibility = View.GONE
binding.mainLayout.visibility = View.VISIBLE
return
}
super.onBackPressed()
Expand Down
Loading

0 comments on commit e445c8c

Please sign in to comment.