-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- treasure editor screen
- Loading branch information
Showing
77 changed files
with
1,330 additions
and
648 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
210 changes: 105 additions & 105 deletions
210
...rc/classic/java/pl/marianjureczko/poszukiwacz/activity/treasureseditor/RecordingDialog.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,105 +1,105 @@ | ||
//package pl.marianjureczko.poszukiwacz.activity.treasureseditor | ||
// | ||
//import android.app.AlertDialog | ||
//import android.app.Dialog | ||
//import android.content.DialogInterface | ||
//import android.media.MediaRecorder | ||
//import android.os.Bundle | ||
//import android.util.Log | ||
//import android.view.Gravity | ||
//import android.widget.Chronometer | ||
//import android.widget.Toast | ||
//import androidx.fragment.app.DialogFragment | ||
//import pl.marianjureczko.poszukiwacz.R | ||
// | ||
//private const val FILENAME = "filename" | ||
//private const val CLOSED_AT = "closed_at" | ||
// | ||
//class RecordingDialog : DialogFragment() { | ||
// private val TAG = javaClass.simpleName | ||
// private var recorder: MediaRecorder? = null | ||
// private var chronometer: Chronometer? = null | ||
// private var dialog: AlertDialog? = null | ||
// | ||
// companion object { | ||
// fun newInstance(fileName: String): RecordingDialog { | ||
// val args = Bundle().apply { | ||
// putSerializable(FILENAME, fileName) | ||
// } | ||
// | ||
// return RecordingDialog().apply { | ||
// arguments = args | ||
// } | ||
// } | ||
// } | ||
// | ||
// override fun onStop() { | ||
// super.onStop() | ||
// stopRecording() | ||
// if (chronometer != null) { | ||
// arguments?.putString(CLOSED_AT, chronometer!!.text as String) | ||
// } | ||
// } | ||
// | ||
// override fun onResume() { | ||
// super.onResume() | ||
// val closedAt = arguments?.getSerializable(CLOSED_AT) as String? | ||
// if (closedAt != null) { | ||
// chronometer?.stop() | ||
// dialog?.getButton(DialogInterface.BUTTON_NEUTRAL)?.setText(R.string.close) | ||
// } | ||
// } | ||
// | ||
// override fun onCreateDialog(savedInstanceState: Bundle?): Dialog { | ||
// val fileName = arguments?.getSerializable(FILENAME) as String | ||
// val closedAt = arguments?.getSerializable(CLOSED_AT) as String? | ||
// val builder: AlertDialog.Builder = AlertDialog.Builder(activity) | ||
// chronometer = createChronometer() | ||
// if (closedAt != null) { | ||
// builder.setNeutralButton(R.string.close) { _, _ -> dismiss() } | ||
// chronometer?.text = closedAt | ||
// } else { | ||
// builder.setNeutralButton(R.string.stop_recording) { _, _ -> dismiss() } | ||
// chronometer?.setOnChronometerTickListener { | ||
// arguments?.putString(CLOSED_AT, it.text as String) | ||
// } | ||
// chronometer?.start() | ||
// startRecording(fileName) | ||
// } | ||
// builder.setView(chronometer) | ||
// dialog = builder.create() | ||
// return dialog!! | ||
// } | ||
// | ||
// private fun createChronometer(): Chronometer { | ||
// val chronometer = Chronometer(activity) | ||
// chronometer.textSize = 50.0f | ||
// chronometer.gravity = Gravity.CENTER | ||
// return chronometer | ||
// } | ||
// | ||
// private fun startRecording(fileName: String) { | ||
// recorder = MediaRecorder().apply { | ||
// setAudioSource(MediaRecorder.AudioSource.MIC) | ||
// setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP) | ||
// setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB) | ||
// setOutputFile(fileName) | ||
// try { | ||
// prepare() | ||
// start() | ||
// } catch (e: Exception) { | ||
// Log.e(TAG, "Audio recording failed ${e.message}", e) | ||
// Toast.makeText(activity, R.string.tip_recording_failed, Toast.LENGTH_SHORT).show() | ||
// } | ||
// } | ||
// } | ||
// | ||
// private fun stopRecording() { | ||
// recorder?.apply { | ||
// stop() | ||
// Toast.makeText(activity, R.string.tip_recorded, Toast.LENGTH_SHORT).show() | ||
// release() | ||
// } | ||
// recorder = null | ||
// } | ||
//} | ||
package pl.marianjureczko.poszukiwacz.activity.treasureseditor | ||
|
||
import android.app.AlertDialog | ||
import android.app.Dialog | ||
import android.content.DialogInterface | ||
import android.media.MediaRecorder | ||
import android.os.Bundle | ||
import android.util.Log | ||
import android.view.Gravity | ||
import android.widget.Chronometer | ||
import android.widget.Toast | ||
import androidx.fragment.app.DialogFragment | ||
import pl.marianjureczko.poszukiwacz.R | ||
|
||
private const val FILENAME = "filename" | ||
private const val CLOSED_AT = "closed_at" | ||
|
||
class RecordingDialog : DialogFragment() { | ||
private val TAG = javaClass.simpleName | ||
private var recorder: MediaRecorder? = null | ||
private var chronometer: Chronometer? = null | ||
private var dialog: AlertDialog? = null | ||
|
||
companion object { | ||
fun newInstance(fileName: String): RecordingDialog { | ||
val args = Bundle().apply { | ||
putSerializable(FILENAME, fileName) | ||
} | ||
|
||
return RecordingDialog().apply { | ||
arguments = args | ||
} | ||
} | ||
} | ||
|
||
override fun onStop() { | ||
super.onStop() | ||
stopRecording() | ||
if (chronometer != null) { | ||
arguments?.putString(CLOSED_AT, chronometer!!.text as String) | ||
} | ||
} | ||
|
||
override fun onResume() { | ||
super.onResume() | ||
val closedAt = arguments?.getSerializable(CLOSED_AT) as String? | ||
if (closedAt != null) { | ||
chronometer?.stop() | ||
dialog?.getButton(DialogInterface.BUTTON_NEUTRAL)?.setText(R.string.close) | ||
} | ||
} | ||
|
||
override fun onCreateDialog(savedInstanceState: Bundle?): Dialog { | ||
val fileName = arguments?.getSerializable(FILENAME) as String | ||
val closedAt = arguments?.getSerializable(CLOSED_AT) as String? | ||
val builder: AlertDialog.Builder = AlertDialog.Builder(activity) | ||
chronometer = createChronometer() | ||
if (closedAt != null) { | ||
builder.setNeutralButton(R.string.close) { _, _ -> dismiss() } | ||
chronometer?.text = closedAt | ||
} else { | ||
builder.setNeutralButton(R.string.stop_recording) { _, _ -> dismiss() } | ||
chronometer?.setOnChronometerTickListener { | ||
arguments?.putString(CLOSED_AT, it.text as String) | ||
} | ||
chronometer?.start() | ||
startRecording(fileName) | ||
} | ||
builder.setView(chronometer) | ||
dialog = builder.create() | ||
return dialog!! | ||
} | ||
|
||
private fun createChronometer(): Chronometer { | ||
val chronometer = Chronometer(activity) | ||
chronometer.textSize = 50.0f | ||
chronometer.gravity = Gravity.CENTER | ||
return chronometer | ||
} | ||
|
||
private fun startRecording(fileName: String) { | ||
recorder = MediaRecorder().apply { | ||
setAudioSource(MediaRecorder.AudioSource.MIC) | ||
setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP) | ||
setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB) | ||
setOutputFile(fileName) | ||
try { | ||
prepare() | ||
start() | ||
} catch (e: Exception) { | ||
Log.e(TAG, "Audio recording failed ${e.message}", e) | ||
Toast.makeText(activity, R.string.tip_recording_failed, Toast.LENGTH_SHORT).show() | ||
} | ||
} | ||
} | ||
|
||
private fun stopRecording() { | ||
recorder?.apply { | ||
stop() | ||
Toast.makeText(activity, R.string.tip_recorded, Toast.LENGTH_SHORT).show() | ||
release() | ||
} | ||
recorder = null | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
app/src/classic/java/pl/marianjureczko/poszukiwacz/activity/treasureseditor/formatTime.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package pl.marianjureczko.poszukiwacz.activity.treasureseditor | ||
|
||
import android.annotation.SuppressLint | ||
|
||
@SuppressLint("DefaultLocale") | ||
fun formatTime(ms:Long?): String { | ||
if (ms == null) { | ||
return "00:00" // Handle null input | ||
} | ||
|
||
val totalSeconds = ms / 1000 | ||
val minutes = totalSeconds / 60 | ||
val seconds = totalSeconds % 60 | ||
|
||
return String.format("%02d:%02d", minutes, seconds) | ||
} |
9 changes: 9 additions & 0 deletions
9
...c/classic/java/pl/marianjureczko/poszukiwacz/permissions/RequirementsForRecordingSound.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package pl.marianjureczko.poszukiwacz.permissions | ||
|
||
import android.Manifest | ||
import pl.marianjureczko.poszukiwacz.R | ||
|
||
object RequirementsForRecordingSound: Requirements { | ||
override fun getPermission(): String = Manifest.permission.RECORD_AUDIO | ||
override fun getMessage(): Int = R.string.missing_photo_and_audio_permission | ||
} |
2 changes: 1 addition & 1 deletion
2
app/src/classic/java/pl/marianjureczko/poszukiwacz/screen/main/CustomInitializerForRoute.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.