Rewritten widget to record in a background
This commit is contained in:
parent
a6dbd976fd
commit
47392e13f4
|
@ -49,6 +49,10 @@
|
||||||
android:resource="@xml/widget_record_display" />
|
android:resource="@xml/widget_record_display" />
|
||||||
</receiver>
|
</receiver>
|
||||||
|
|
||||||
|
<activity
|
||||||
|
android:name=".activities.BackgroundRecordActivity"
|
||||||
|
android:theme="@android:style/Theme.NoDisplay" />
|
||||||
|
|
||||||
<activity
|
<activity
|
||||||
android:name=".activities.SplashActivity"
|
android:name=".activities.SplashActivity"
|
||||||
android:theme="@style/SplashTheme" />
|
android:theme="@style/SplashTheme" />
|
||||||
|
|
|
@ -0,0 +1,28 @@
|
||||||
|
package com.simplemobiletools.voicerecorder.activities
|
||||||
|
|
||||||
|
import android.content.Intent
|
||||||
|
import com.simplemobiletools.voicerecorder.services.RecorderService
|
||||||
|
|
||||||
|
class BackgroundRecordActivity : SimpleActivity() {
|
||||||
|
companion object {
|
||||||
|
const val RECORD_INTENT_ACTION = "RECORD_ACTION";
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onResume() {
|
||||||
|
super.onResume()
|
||||||
|
if (intent.action == RECORD_INTENT_ACTION) {
|
||||||
|
Intent(this@BackgroundRecordActivity, RecorderService::class.java).apply {
|
||||||
|
try {
|
||||||
|
if (RecorderService.isRunning) {
|
||||||
|
stopService(this)
|
||||||
|
} else {
|
||||||
|
startService(this)
|
||||||
|
}
|
||||||
|
} catch (ignored: Exception) {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
moveTaskToBack(true)
|
||||||
|
finish()
|
||||||
|
}
|
||||||
|
}
|
|
@ -18,10 +18,6 @@ import kotlinx.android.synthetic.main.activity_main.*
|
||||||
|
|
||||||
class MainActivity : SimpleActivity() {
|
class MainActivity : SimpleActivity() {
|
||||||
|
|
||||||
companion object {
|
|
||||||
const val RECORD_INTENT_ACTION = "RECORD_ACTION";
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun onCreate(savedInstanceState: Bundle?) {
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
super.onCreate(savedInstanceState)
|
super.onCreate(savedInstanceState)
|
||||||
setContentView(R.layout.activity_main)
|
setContentView(R.layout.activity_main)
|
||||||
|
@ -44,16 +40,6 @@ class MainActivity : SimpleActivity() {
|
||||||
super.onResume()
|
super.onResume()
|
||||||
getPagerAdapter()?.onResume()
|
getPagerAdapter()?.onResume()
|
||||||
setupTabColors()
|
setupTabColors()
|
||||||
|
|
||||||
if (intent.action == RECORD_INTENT_ACTION) {
|
|
||||||
view_pager.currentItem = 0
|
|
||||||
Intent(this@MainActivity, RecorderService::class.java).apply {
|
|
||||||
try {
|
|
||||||
startService(this)
|
|
||||||
} catch (ignored: Exception) {
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onDestroy() {
|
override fun onDestroy() {
|
||||||
|
|
|
@ -42,7 +42,7 @@ class WidgetRecordDisplayConfigureActivity : SimpleActivity() {
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun initVariables() {
|
private fun initVariables() {
|
||||||
mWidgetColor = config.widgetBgColor
|
mWidgetColor = resources.getColor(R.color.color_primary)
|
||||||
mWidgetAlpha = if (mWidgetColor == DEFAULT_WIDGET_BG_COLOR) {
|
mWidgetAlpha = if (mWidgetColor == DEFAULT_WIDGET_BG_COLOR) {
|
||||||
1f
|
1f
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -26,6 +26,8 @@ class RecorderFragment(context: Context, attributeSet: AttributeSet) : MyViewPag
|
||||||
|
|
||||||
override fun onResume() {
|
override fun onResume() {
|
||||||
setupColors()
|
setupColors()
|
||||||
|
if (!RecorderService.isRunning) status = RECORDING_STOPPED
|
||||||
|
refreshView()
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onDestroy() {
|
override fun onDestroy() {
|
||||||
|
@ -127,14 +129,7 @@ class RecorderFragment(context: Context, attributeSet: AttributeSet) : MyViewPag
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Subscribe(threadMode = ThreadMode.MAIN)
|
private fun refreshView() {
|
||||||
fun gotDurationEvent(event: Events.RecordingDuration) {
|
|
||||||
updateRecordingDuration(event.duration)
|
|
||||||
}
|
|
||||||
|
|
||||||
@Subscribe(threadMode = ThreadMode.MAIN)
|
|
||||||
fun gotStatusEvent(event: Events.RecordingStatus) {
|
|
||||||
status = event.status
|
|
||||||
toggle_recording_button.setImageDrawable(getToggleButtonIcon())
|
toggle_recording_button.setImageDrawable(getToggleButtonIcon())
|
||||||
toggle_pause_button.beVisibleIf(status != RECORDING_STOPPED && isNougatPlus())
|
toggle_pause_button.beVisibleIf(status != RECORDING_STOPPED && isNougatPlus())
|
||||||
if (status == RECORDING_PAUSED) {
|
if (status == RECORDING_PAUSED) {
|
||||||
|
@ -149,6 +144,17 @@ class RecorderFragment(context: Context, attributeSet: AttributeSet) : MyViewPag
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Subscribe(threadMode = ThreadMode.MAIN)
|
||||||
|
fun gotDurationEvent(event: Events.RecordingDuration) {
|
||||||
|
updateRecordingDuration(event.duration)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Subscribe(threadMode = ThreadMode.MAIN)
|
||||||
|
fun gotStatusEvent(event: Events.RecordingStatus) {
|
||||||
|
status = event.status
|
||||||
|
refreshView()
|
||||||
|
}
|
||||||
|
|
||||||
@Subscribe(threadMode = ThreadMode.MAIN)
|
@Subscribe(threadMode = ThreadMode.MAIN)
|
||||||
fun gotAmplitudeEvent(event: Events.RecordingAmplitude) {
|
fun gotAmplitudeEvent(event: Events.RecordingAmplitude) {
|
||||||
val amplitude = event.amplitude
|
val amplitude = event.amplitude
|
||||||
|
|
|
@ -11,8 +11,8 @@ import android.graphics.Color
|
||||||
import android.widget.RemoteViews
|
import android.widget.RemoteViews
|
||||||
import com.simplemobiletools.commons.extensions.getColoredDrawableWithColor
|
import com.simplemobiletools.commons.extensions.getColoredDrawableWithColor
|
||||||
import com.simplemobiletools.voicerecorder.R
|
import com.simplemobiletools.voicerecorder.R
|
||||||
|
import com.simplemobiletools.voicerecorder.activities.BackgroundRecordActivity
|
||||||
import com.simplemobiletools.voicerecorder.extensions.config
|
import com.simplemobiletools.voicerecorder.extensions.config
|
||||||
import com.simplemobiletools.voicerecorder.activities.MainActivity
|
|
||||||
import com.simplemobiletools.voicerecorder.extensions.drawableToBitmap
|
import com.simplemobiletools.voicerecorder.extensions.drawableToBitmap
|
||||||
|
|
||||||
class MyWidgetRecordDisplayProvider : AppWidgetProvider() {
|
class MyWidgetRecordDisplayProvider : AppWidgetProvider() {
|
||||||
|
@ -37,9 +37,9 @@ class MyWidgetRecordDisplayProvider : AppWidgetProvider() {
|
||||||
private fun getComponentName(context: Context) = ComponentName(context, MyWidgetRecordDisplayProvider::class.java)
|
private fun getComponentName(context: Context) = ComponentName(context, MyWidgetRecordDisplayProvider::class.java)
|
||||||
|
|
||||||
private fun setupAppOpenIntent(context: Context, views: RemoteViews) {
|
private fun setupAppOpenIntent(context: Context, views: RemoteViews) {
|
||||||
Intent(context, MainActivity::class.java).apply {
|
Intent(context, BackgroundRecordActivity::class.java).apply {
|
||||||
action = MainActivity.RECORD_INTENT_ACTION;
|
action = BackgroundRecordActivity.RECORD_INTENT_ACTION
|
||||||
val pendingIntent = PendingIntent.getActivity(context, OPEN_APP_INTENT_ID, this, PendingIntent.FLAG_CANCEL_CURRENT)
|
val pendingIntent = PendingIntent.getActivity(context, OPEN_APP_INTENT_ID, this, PendingIntent.FLAG_UPDATE_CURRENT)
|
||||||
views.setOnClickPendingIntent(R.id.record_display_btn, pendingIntent)
|
views.setOnClickPendingIntent(R.id.record_display_btn, pendingIntent)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -29,6 +29,10 @@ import java.io.File
|
||||||
import java.util.*
|
import java.util.*
|
||||||
|
|
||||||
class RecorderService : Service() {
|
class RecorderService : Service() {
|
||||||
|
companion object {
|
||||||
|
var isRunning = false
|
||||||
|
}
|
||||||
|
|
||||||
private val AMPLITUDE_UPDATE_MS = 75L
|
private val AMPLITUDE_UPDATE_MS = 75L
|
||||||
|
|
||||||
private var currFilePath = ""
|
private var currFilePath = ""
|
||||||
|
@ -56,10 +60,12 @@ class RecorderService : Service() {
|
||||||
override fun onDestroy() {
|
override fun onDestroy() {
|
||||||
super.onDestroy()
|
super.onDestroy()
|
||||||
stopRecording()
|
stopRecording()
|
||||||
|
isRunning = false
|
||||||
}
|
}
|
||||||
|
|
||||||
// mp4 output format with aac encoding should produce good enough m4a files according to https://stackoverflow.com/a/33054794/1967672
|
// mp4 output format with aac encoding should produce good enough m4a files according to https://stackoverflow.com/a/33054794/1967672
|
||||||
private fun startRecording() {
|
private fun startRecording() {
|
||||||
|
isRunning = true
|
||||||
if (status == RECORDING_RUNNING) {
|
if (status == RECORDING_RUNNING) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue