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
class AudioPlayerUtil { | |
private var mediaPlayer: MediaPlayer? = null | |
/** | |
* | |
*/ | |
fun stop() { | |
if (mediaPlayer != null) { | |
mediaPlayer!!.release() | |
mediaPlayer = null |
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
abstract class VisualizerBase | |
@JvmOverloads | |
constructor( | |
context: Context, | |
attrs: AttributeSet? = null, | |
defStyleAttr: Int = 0 | |
) : View(context, attrs, defStyleAttr) { | |
protected var audioBytes: ByteArray? = null | |
private var visualizer: Visualizer? = null |
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
class WaveVisualizer | |
@JvmOverloads | |
constructor( | |
context: Context, | |
attrs: AttributeSet? = null, | |
defStyleAttr: Int = 0 | |
) : VisualizerBase(context, attrs, defStyleAttr) { | |
private var paint: Paint | |
private val waveformPath: Path = Path() |
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
/** | |
* Reduces drag sensitivity of [ViewPager2] widget | |
*/ | |
fun ViewPager2.reduceDragSensitivity() { | |
val recyclerViewField = ViewPager2::class.java.getDeclaredField("mRecyclerView") | |
recyclerViewField.isAccessible = true | |
val recyclerView = recyclerViewField.get(this) as RecyclerView | |
val touchSlopField = RecyclerView::class.java.getDeclaredField("mTouchSlop") | |
touchSlopField.isAccessible = true |
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
class ShakeDetector : SensorEventListener { | |
private companion object { | |
const val SHAKE_THRESHOLD_GRAVITY = 2.7f // In "Gs" (one Earth gravity unit) | |
const val SHAKE_SLOP_TIME = 500 // In [ms] | |
const val SHAKE_COUNT_RESET_TIME = 3000 | |
} | |
private var shakeListener: ((Int) -> Unit)? = null // argument - shakes count in a row |
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
class FeedbackService : Service() { | |
companion object { | |
fun start(appContext: Context) { | |
if(isRunning) { | |
return | |
} | |
appContext.startService(Intent(appContext, FeedbackService::class.java)) | |
} |
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
class FeedbackService : Service() { | |
companion object { | |
fun start(appContext: Context) { | |
if(isRunning) { | |
return | |
} | |
appContext.startService(Intent(appContext, FeedbackService::class.java)) | |
} |
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
class ActivitiesMonitor(private val appContext: Context): Application.ActivityLifecycleCallbacks { | |
private var activeActivities = 0 | |
init { | |
(appContext as Application).registerActivityLifecycleCallbacks(this) | |
} | |
override fun onActivityPaused(activity: Activity?) { | |
activeActivities-- |
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
class App : Application() { | |
private lateinit var activitiesMonitor: ActivitiesMonitor | |
override fun onCreate() { | |
super.onCreate() | |
activitiesMonitor = ActivitiesMonitor(this.applicationContext) | |
} | |
} |
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
class FeedbackFormActivity : AppCompatActivity() { | |
companion object { | |
private var isRunning = false | |
fun start(context: Context) { | |
if(isRunning) { | |
return | |
} | |
Intent(context, FeedbackFormActivity::class.java) |
OlderNewer