package Ġcom . hus se in . startup Ċ Ċ import Ġandroid . content . Context Ċ import Ġandroid . hardware . Sensor Ċ import Ġandroid . hardware . Sensor Event Ċ import Ġandroid . hardware . Sensor EventListener Ċ import Ġandroid . hardware . Sensor Manager Ċ import Ġandroidx . appcompat . app . AppCompatActivity Ċ import Ġandroid . os . Bundle Ċ import Ġandroid . os . V ibr ator Ċ import Ġandroid . widget . Toast Ċ import Ġ Ġkotlinx . android . synt hetic . main . activity _ main .* Ċ class ĠMainActivity Ġ: ĠAppCompatActivity (), Sensor EventListener Ġ{ ĊĠĠĠ Ġvar Ġsensor : Sensor ?= null ĊĠĠĠ Ġvar Ġsensor Manager : Sensor Manager ?= null ĊĠĠĠ Ġoverride Ġfun Ġon Accuracy Changed ( p 0 : ĠSensor ?, Ġp 1 : ĠInt ) Ġ{ ĊĠĠĠĠĠĠ Ġ} ĊĊĊĠĠĠ Ġvar Ġx old = 0 . 0 ĊĠĠĠ Ġvar Ġy old = 0 . 0 ĊĠĠĠ Ġvar Ġz old = 0 . 0 ĊĠĠ Ġvar Ġthread Should = 3 0 0 0 . 0 ĊĠĠĠ Ġvar Ġold time : Long = 0 ĊĠĠĠ Ġoverride Ġfun Ġon Sensor Changed ( event : ĠSensor Event ?) Ġ{ ĊĠĠĠĠĠĠĠ Ġvar Ġx = event !!. values [ 0 ] ĊĠĠĠĠĠĠĠ Ġvar Ġy = event !!. values [ 1 ] ĊĠĠĠĠĠĠĠ Ġvar Ġz = event !!. values [ 2 ] ĊĠĠĠĠĠĠĠ Ġvar ĠcurrentTime = System . currentTimeMillis () ĊĠĠĠĠĠĠĠ Ġif (( currentTime - old time )> 1 0 0 ){ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġvar Ġtime Diff = currentTime - old time ĊĠĠĠĠĠĠĠĠĠĠĠ Ġold time = currentTime ĊĠĠĠĠĠĠĠĠĠĠĠ Ġvar Ġspeed = Math . abs ( x + y + z - x old - y old - z old )/ time Diff * 1 0 0 0 0 ĊĠĠĠĠĠĠĠĠĠĠĠ Ġif ( speed > thread Should ){ ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġvar Ġv = getSystem Service ( Context . V IB R ATOR _ SERVICE ) Ġas ĠV ibr ator ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġv . vi br ate ( 5 0 0 ) ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ ĠToast . makeText ( application Context ," sh ock ", Toast . LENGTH _ LONG ). show () ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ} ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠĠ Ġ} ĊĊĠĠĠ Ġoverride Ġfun ĠonCreate ( savedInstanceState : ĠBundle ?) Ġ{ ĊĠĠĠĠĠĠĠ Ġsuper . onCreate ( savedInstanceState ) ĊĠĠĠĠĠĠĠ ĠsetContentView ( R . layout . activity _ main ) ĊĠĠĠĠĠĠĠ Ġsensor Manager = getSystem Service ( Context . SENSOR _ SERVICE ) as ĠSensor Manager ĊĠĠĠĠĠĠĠ Ġsensor = sensor Manager !!. getDefault Sensor ( Sensor . TYPE _ AC CEL ERO METER ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġoverride Ġfun Ġon Resume () Ġ{ ĊĠĠĠĠĠĠĠ Ġsuper . on Resume () ĊĠĠĠĠĠĠĠ Ġsensor Manager !!. register Listener ( this , sensor , Sensor Manager . SENSOR _ DELAY _ NORMAL ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġoverride Ġfun Ġon Pause () Ġ{ ĊĠĠĠĠĠĠĠ Ġsuper . on Pause () ĊĠĠĠĠĠĠĠ Ġsensor Manager !!. unregister Listener ( this ) ĊĠĠĠ Ġ} Ċ Ċ } Ċ