package Ġcom . nk ming . sys usage Ċ Ċ import Ġandroid . annotation . Target Api Ċ import Ġandroid . content . Intent Ċ import Ġandroid . content . SharedPreferences Ċ import Ġandroid . net . Uri Ċ import Ġandroid . os . Build Ċ import Ġandroid . os . Bundle Ċ import Ġandroid . preference . Preference Group Ċ import Ġandroid . provider . Settings Ċ import Ġandroid . view . View Ċ import Ġandroid . widget . TextView Ċ import Ġcom . nk ming . utils . Log Ċ import Ġcom . nk ming . utils . preference . Preference Fragment Ex Ċ import Ġcom . nk ming . utils . preference . Seek Bar Preference Ċ Ċ class ĠPreference Fragment Ġ: ĠPreference Fragment Ex (), Ċĉ ĉ SharedPreferences . On Shared Preference ChangeListener Ċ { Ċ ĉ comp anion Ġobject Ċ ĉ { Ċĉ ĉ @ Jvm Static Ċĉ ĉ fun Ġcreate (): ĠPreference Fragment Ċĉ ĉ { Ċĉĉ ĉ return ĠPreference Fragment () Ċĉ ĉ } ĊĊĉ ĉ private Ġval ĠLOG _ TAG Ġ= Ġ" Preference Fragment " Ċ ĉ } ĊĊ ĉ override Ġfun ĠonCreate ( savedInstanceState : ĠBundle ?) Ċ ĉ { Ċĉ ĉ super . onCreate ( savedInstanceState ) Ċĉ ĉ preference Manager . shared Preferences Name Ġ= ĠgetString ( R . string . pref _ file ) Ċĉ ĉ add Preferences From Resource ( R . xml . preference ) Ċ ĉ } ĊĊ ĉ override Ġfun Ġon Activity Created ( savedInstanceState : ĠBundle ?) Ċ ĉ { Ċĉ ĉ super . on Activity Created ( savedInstanceState ) Ċĉ ĉ init () Ċ ĉ } ĊĊ ĉ override Ġfun Ġon Resume () Ċ ĉ { Ċĉ ĉ super . on Resume () Ċĉ ĉ preference Manager . shared Preferences Ċĉĉĉ ĉ . register On Shared Preference ChangeListener ( this ) Ċ ĉ } ĊĊ ĉ override Ġfun Ġon Pause () Ċ ĉ { Ċĉ ĉ super . on Pause () Ċĉ ĉ preference Manager . shared Preferences Ċĉĉĉ ĉ . unregister On Shared Preference ChangeListener ( this ) Ċ ĉ } ĊĊ ĉ override Ġfun Ġon Shared Preference Changed ( pref : ĠSharedPreferences , Ġkey : ĠString ) Ċ ĉ { Ċĉ ĉ if Ġ( key Ġ== ĠgetString ( R . string . pref _ enable _ cpu _ notif _ key )) Ċĉ ĉ { Ċĉĉ ĉ on Enable Cpu Not if Change ( pref . getBoolean ( key , Ġtrue )) Ċĉ ĉ } Ċĉ ĉ else Ġif Ġ( key Ġ== ĠgetString ( R . string . pref _ enable _ mem _ notif _ key )) Ċĉ ĉ { Ċĉĉ ĉ on Enable Mem Not if Change ( pref . getBoolean ( key , Ġtrue )) Ċĉ ĉ } Ċĉ ĉ else Ġif Ġ( key Ġ== ĠgetString ( R . string . pref _ enable _ net _ notif _ key )) Ċĉ ĉ { Ċĉĉ ĉ on Enable Net Not if Change ( pref . getBoolean ( key , Ġtrue )) Ċĉ ĉ } Ċĉ ĉ else Ġif Ġ( key Ġ== ĠgetString ( R . string . pref _ net _ mobile _ template _ key )) Ċĉ ĉ { Ċĉĉ ĉ on Net Mobile Template Change ( pref . getString ( key , Ġ" LTE ")) Ċĉ ĉ } Ċĉ ĉ else Ġif Ġ( key Ġ== ĠgetString ( R . string . pref _ enable _ disk _ notif _ key )) Ċĉ ĉ { Ċĉĉ ĉ on Enable Disk Not if Change ( pref . getBoolean ( key , Ġtrue )) Ċĉ ĉ } Ċĉ ĉ else Ġif Ġ( key Ġ== ĠgetString ( R . string . pref _ enable _ storage _ notif _ key )) Ċĉ ĉ { Ċĉĉ ĉ on Enable Storage Not if Change ( pref . getBoolean ( key , Ġtrue )) Ċĉ ĉ } Ċĉ ĉ else Ġif Ġ( key Ġ== ĠgetString ( R . string . pref _ enable _ key )) Ċĉ ĉ { Ċĉĉ ĉ on Enable Change ( pref . getBoolean ( key , Ġtrue )) Ċĉ ĉ } Ċ ĉ } ĊĊ ĉ private Ġfun Ġinit () Ċ ĉ { Ċĉ ĉ init Cpu Pref () Ċĉ ĉ init Disk Pref () Ċĉ ĉ init Interval Mul Pref () Ċĉ ĉ init Priority Pref () Ċĉ ĉ init Lock Screen Pref () Ċĉ ĉ init About () Ċ ĉ } ĊĊ ĉ private Ġfun Ġinit Cpu Pref () Ċ ĉ { Ċĉ ĉ val Ġgroup Ġ= Ġpreference Screen . find Preference ( getString ( Ċĉĉĉ ĉ R . string . pref _ cpu _ notification _ category _ key )) Ġas ĠPreference Group Ċĉ ĉ if Ġ( Build . VERSION . SDK _ INT Ġ< ĠBuild . VERSION _ CODES . O ) Ċĉ ĉ { Ċĉĉ ĉ group . remove Preference ( find Preference ( getString ( Ċĉĉĉĉ ĉ R . string . pref _ cpu _ oreo _ note _ key ))) Ċĉ ĉ } Ċ ĉ } ĊĊ ĉ private Ġfun Ġinit Disk Pref () Ċ ĉ { Ċĉ ĉ val Ġgroup Ġ= Ġpreference Screen . find Preference ( getString ( Ċĉĉĉ ĉ R . string . pref _ disk _ notification _ category _ key )) Ġas ĠPreference Group Ċĉ ĉ val Ġnote Key Ġ= ĠgetString ( R . string . pref _ disk _ stat _ not _ supported _ key ) Ċĉ ĉ if Ġ( Build . VERSION . SDK _ INT Ġ>= ĠBuild . VERSION _ CODES . O ) Ċĉ ĉ { Ċĉĉ ĉ var Ġi Ġ= Ġ 0 Ċĉĉ ĉ while Ġ( i Ġ< Ġgroup . preference Count ) Ċĉĉ ĉ { Ċĉĉĉ ĉ val Ġp Ġ= Ġgroup . get Preference ( i ) Ċĉĉĉ ĉ if Ġ( p . key Ġ!= Ġnote Key ) Ċĉĉĉ ĉ { Ċĉĉĉĉ ĉ group . remove Preference ( p ) Ċĉĉĉ ĉ } Ċĉĉĉ ĉ else Ċĉĉĉ ĉ { Ċĉĉĉĉ ĉ p . isEnabled Ġ= Ġfalse Ċĉĉĉĉ ĉ ++ i Ċĉĉĉ ĉ } Ċĉĉ ĉ } Ċĉ ĉ } Ċĉ ĉ else Ċĉ ĉ { Ċĉĉ ĉ group . remove Preference ( find Preference ( note Key )) Ċĉ ĉ } Ċ ĉ } ĊĊ ĉ private Ġfun Ġinit Priority Pref () Ċ ĉ { Ċĉ ĉ val Ġpref Ġ= Ġfind Preference ( getString ( R . string . pref _ high _ priority _ key )) Ċĉ ĉ if Ġ( Build . VERSION . SDK _ INT Ġ>= ĠBuild . VERSION _ CODES . O ) Ċĉ ĉ { Ċĉĉ ĉ // ĠOn ĠO +, Ġuser Ġshould Ġconfig Ġvia Ġnotification Ġchannel Ċĉĉ ĉ preference Screen . remove Preference ( pref ) Ċĉ ĉ } Ċ ĉ } ĊĊ ĉ private Ġfun Ġinit Lock Screen Pref () Ċ ĉ { Ċĉ ĉ val Ġpref Ġ= Ġfind Preference ( getString ( R . string . pref _ lock _ screen _ key )) Ċĉ ĉ if Ġ( Build . VERSION . SDK _ INT Ġ< ĠBuild . VERSION _ CODES . M ) Ċĉ ĉ { Ċĉĉ ĉ pref . isEnabled Ġ= Ġfalse Ċĉ ĉ } Ċĉ ĉ else Ċĉ ĉ { Ċĉĉ ĉ pref . setOn Preference ClickListener { Ċĉĉĉ ĉ start Not if Setting () Ċĉĉĉ ĉ true Ċĉĉ ĉ } Ċĉ ĉ } Ċ ĉ } ĊĊ ĉ private Ġfun Ġinit Interval Mul Pref () Ċ ĉ { Ċĉ ĉ val Ġpref Ġ= Ġfind Preference ( getString ( R . string . pref _ interval _ mul _ key )) Ċĉĉĉ ĉ as ĠSeek Bar Preference Ċĉ ĉ pref . set Preview Listener ( object : ĠSeek Bar Preference . Default Preview Listener () Ċĉ ĉ { Ċĉĉ ĉ override Ġfun Ġon Preview Change ( preview : ĠView , Ġvalue : ĠInt ) Ċĉĉ ĉ { Ċĉĉĉ ĉ val Ġv Ġ= Ġpreview Ġas ĠTextView Ċĉĉĉ ĉ v . text Ġ= Ġ"% . 1 fs ". format ( value Ġ* Ġ 5 0 0 Ġ/ Ġ 1 0 0 0 . 0 ) Ċĉĉ ĉ } Ċĉ ĉ }) Ċĉ ĉ pref . set Summary Listener {" %. 1 fs ". format ( it Ġ* Ġ 5 0 0 Ġ/ Ġ 1 0 0 0 . 0 )} Ċ ĉ } ĊĊ ĉ private Ġfun Ġinit About () Ċ ĉ { Ċĉ ĉ val Ġabout Version Ġ= Ġfind Preference ( getString ( R . string . about _ version _ key )) Ċĉ ĉ about Version . summary Ġ= ĠBuild Config . VERSION _ NAME ĊĊĉ ĉ if Ġ( getString ( R . string . about _ translator _ credit ). isEmpty ()) Ċĉ ĉ { Ċĉĉ ĉ val Ġabout Translator Ġ= Ġfind Preference ( getString ( Ċĉĉĉĉ ĉ R . string . about _ translator _ key )) Ċĉĉ ĉ about Translator . summary Ġ= ĠgetString ( R . string . about _ translator _ help ) Ċĉĉ ĉ about Translator . on Preference ClickListener Ġ= Ċĉĉĉĉ ĉ android . preference . Preference . On Preference ClickListener { Ċĉĉĉĉĉ ĉ val Ġi Ġ= ĠIntent ( Intent . ACTION _ VIEW ) Ċĉĉĉĉĉ ĉ i . data Ġ= ĠUri . parse ( getString ( Ċĉĉĉĉĉĉĉ ĉ R . string . about _ translator _ help _ url )) Ċĉĉĉĉĉ ĉ startActivity ( i ) Ċĉĉĉĉĉ ĉ return @ On Preference ClickListener Ġtrue Ċĉĉĉĉ ĉ } Ċĉ ĉ } Ċ ĉ } ĊĊ ĉ private Ġfun Ġon Enable Cpu Not if Change ( v : ĠBoolean ) Ċ ĉ { Ċĉ ĉ if Ġ( v ) Ċĉ ĉ { Ċĉĉ ĉ Not if Service . start ( activity ) Ċĉ ĉ } Ċ ĉ } ĊĊ ĉ private Ġfun Ġon Enable Mem Not if Change ( v : ĠBoolean ) Ċ ĉ { Ċĉ ĉ if Ġ( v ) Ċĉ ĉ { Ċĉĉ ĉ Not if Service . start ( activity ) Ċĉ ĉ } Ċ ĉ } ĊĊ ĉ private Ġfun Ġon Enable Net Not if Change ( v : ĠBoolean ) Ċ ĉ { Ċĉ ĉ if Ġ( v ) Ċĉ ĉ { Ċĉĉ ĉ Not if Service . start ( activity ) Ċĉ ĉ } Ċ ĉ } ĊĊ ĉ private Ġfun Ġon Net Mobile Template Change ( v : ĠString ) Ċ ĉ { Ċĉ ĉ try Ċĉ ĉ { Ċĉĉ ĉ val Ġthroughput Ġ= ĠNet Utils . get Mobile Net Through put ( v ) Ċĉĉ ĉ _ net Mobile Dl Pref . setValue ( through put . first ) Ċĉĉ ĉ _ net Mobile Ul Pref . setValue ( through put . second ) Ċĉ ĉ } Ċĉ ĉ catch Ġ( e : ĠIllegalArgumentException ) Ċĉ ĉ { Ċĉĉ ĉ Log . e ("$ LOG _ TAG . on Net Mobile Template Change ", Ċĉĉĉĉ ĉ " Failed Ġwhile Ġget Mobile Net Through put ()", Ġe ) Ċĉ ĉ } Ċ ĉ } ĊĊ ĉ private Ġfun Ġon Enable Disk Not if Change ( v : ĠBoolean ) Ċ ĉ { Ċĉ ĉ if Ġ( v ) Ċĉ ĉ { Ċĉĉ ĉ Not if Service . start ( activity ) Ċĉ ĉ } Ċ ĉ } ĊĊ ĉ private Ġfun Ġon Enable Storage Not if Change ( v : ĠBoolean ) Ċ ĉ { Ċĉ ĉ if Ġ( v ) Ċĉ ĉ { Ċĉĉ ĉ Not if Service . start ( activity ) Ċĉ ĉ } Ċ ĉ } ĊĊ ĉ private Ġfun Ġon Enable Change ( v : ĠBoolean ) Ċ ĉ { Ċĉ ĉ if Ġ( v ) Ċĉ ĉ { Ċĉĉ ĉ val Ġpref Ġ= ĠPreference . from ( activity ) Ċĉĉ ĉ if Ġ( pref . is Enable Cpu Ġ|| Ġpref . is Enable Mem Ġ|| Ġpref . is Enable Net Ċĉĉĉĉ ĉ || Ġpref . is Enable Disk ) Ċĉĉ ĉ { Ċĉĉĉ ĉ Not if Service . start ( activity ) Ċĉĉ ĉ } Ċĉ ĉ } Ċ ĉ } ĊĊ ĉ private Ġfun Ġstart Not if Setting () Ċ ĉ { Ċĉ ĉ if Ġ( Build . VERSION . SDK _ INT Ġ>= ĠBuild . VERSION _ CODES . O ) Ċĉ ĉ { Ċĉĉ ĉ start Not if Setting O () Ċĉ ĉ } Ċĉ ĉ else Ġif Ġ( Build . VERSION . SDK _ INT Ċĉĉĉ ĉ in ĠBuild . VERSION _ CODES . LO L LI POP .. Build . VERSION _ CODES . N _ MR 1 ) Ċĉ ĉ { Ċĉĉ ĉ start Not if Setting L () Ċĉ ĉ } Ċ ĉ } ĊĊ ĉ @ Target Api ( Build . VERSION _ CODES . O ) Ċ ĉ private Ġfun Ġstart Not if Setting O () Ċ ĉ { Ċĉ ĉ val Ġintent Ġ= ĠIntent ( Settings . ACTION _ APP _ NOTIFICATION _ SETTINGS ) Ċĉ ĉ intent . putExtra ( Settings . EXTRA _ APP _ PACKAGE , ĠBuild Config . APPLICATION _ ID ) Ċĉ ĉ startActivity ( intent ) Ċ ĉ } ĊĊ ĉ private Ġfun Ġstart Not if Setting L () Ċ ĉ { Ċĉ ĉ try Ċĉ ĉ { Ċĉĉ ĉ // ĠUnd ocument ed Ċĉĉ ĉ val Ġintent Ġ= ĠIntent (" android . settings . APP _ NOTIFICATION _ SETTINGS ") Ċĉĉ ĉ intent . putExtra (" app _ package ", ĠBuild Config . APPLICATION _ ID ) Ċĉĉ ĉ intent . putExtra (" app _ uid ", Ġactivity . application Info . uid ) Ċĉĉ ĉ startActivity ( intent ) Ċĉ ĉ } Ċĉ ĉ catch Ġ( e : ĠThrowable ) Ċĉ ĉ { Ċĉĉ ĉ val Ġintent Ġ= ĠIntent ( Settings . ACTION _ APPLICATION _ DETAILS _ SETTINGS ) Ċĉĉ ĉ intent . data Ġ= ĠUri . parse (" package :${ Build Config . APPLICATION _ ID }") Ċĉĉ ĉ startActivity ( intent ) Ċĉ ĉ } Ċ ĉ } ĊĊ ĉ private Ġval Ġ_ net Mobile Dl Pref Ġby Ġview Aware Lazy ( Ċ ĉ { Ċĉ ĉ find Preference ( activity . getString ( R . string . pref _ net _ mobile _ dl _ key )) Ċĉĉĉ ĉ as ĠNet Through put Preference Ċ ĉ }) ĊĊ ĉ private Ġval Ġ_ net Mobile Ul Pref Ġby Ġview Aware Lazy ( Ċ ĉ { Ċĉ ĉ find Preference ( activity . getString ( R . string . pref _ net _ mobile _ ul _ key )) Ċĉĉĉ ĉ as ĠNet Through put Preference Ċ ĉ }) Ċ } Ċ