intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK);
finishAffinity()
finish();

ContentProvider

val scheduler = mContext.getSystemService(Context.JOB_SCHEDULER_SERVICE) as JobScheduler
for (jobInfo in scheduler.allPendingJobs)…

recyclerView.addOnScrollListener(object : RecyclerView.OnScrollListener() {

override fun onScrollStateChanged(recyclerView: RecyclerView, newState: Int) {
super.onScrollStateChanged(recyclerView, newState)
if (newState == RecyclerView.SCROLL_STATE_IDLE) {
Toast.makeText(applicationContext, "idle", Toast.LENGTH_SHORT).show()
} else if (newState == RecyclerView.SCROLL_STATE_SETTLING) {
Toast.makeText(applicationContext, "settling", Toast.LENGTH_SHORT).show()
} else if (newState == RecyclerView.SCROLL_STATE_DRAGGING) {
Toast.makeText(applicationContext, "dragging", Toast.LENGTH_SHORT).show()
}
}

})

private fun animationSet(v: View) {

val animSetXY = AnimatorSet()

val x: ObjectAnimator = ObjectAnimator.ofFloat(
v,
"alpha", 1.0f, 0.0f
)
val y: ObjectAnimator = ObjectAnimator.ofFloat(
v,
"translationX",0f, 150f
)
animSetXY.playTogether(x,y)
animSetXY.duration = 2000
animSetXY.setupStartValues()
animSetXY.start()

}

Here,

X is a animation and Y is an animation…..

plugins {
id ‘com.android.application’
id ‘kotlin-android’

}

or

apply plugin: ‘com.android.application’
apply plugin: ‘kotlin-android’

First, The Code For ….

private var count = 10val upCountDownTimer: CountDownTimer = object : CountDownTimer(Long.MAX_VALUE, 500) {
override fun onTick(l: Long) {
count++
}

override fun onFinish() {}
}
val downCountDownTimer: CountDownTimer = object : CountDownTimer(Long.MAX_VALUE, 500) {
override fun onTick(l: Long) {
count--
}

override fun onFinish() {}
}

Then,

up.setOnTouchListener { _, event ->
if (event.action == MotionEvent.ACTION_DOWN) {
upCountDownTimer.start();
}
if (event.action == MotionEvent.ACTION_UP) {
upCountDownTimer.cancel();
}
true
}
down.setOnTouchListener { _, event ->
if (event.action == MotionEvent.ACTION_DOWN) {
downCountDownTimer.start();
}
if (event.action == MotionEvent.ACTION_UP) {
downCountDownTimer.cancel();
}
true
}

The UP & Down are our Button’s in View …

Explanation: On the button touched we are starting the timer and on release we are stopping the timer… :-)

You Can Increase & Decrease the hold time delay in the code,

CountDownTimer(Long.MAX_VALUE, XXX)

Thank You!

Akhil Gattemaneni

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store