package Ġde . mark us fis ch . android . binary eye . activity Ċ Ċ import Ġandroid . content . Context Ċ import Ġandroid . content . Intent Ċ import Ġandroid . content . pm . PackageManager Ċ import Ġandroid . os . Build Ċ import Ġandroid . os . Bundle Ċ import Ġandroid . support . v 4 . app . Fragment Ċ import Ġandroid . support . v 7 . app . AppCompatActivity Ċ import Ġandroid . support . v 7 . widget . Toolbar Ċ import Ġde . mark us fis ch . android . binary eye . R Ċ import Ġde . mark us fis ch . android . binary eye . app .* Ċ import Ġde . mark us fis ch . android . binary eye . database . Scan Ċ import Ġde . mark us fis ch . android . binary eye . fragment . Decode Fragment Ċ import Ġde . mark us fis ch . android . binary eye . fragment . Encode Fragment Ċ import Ġde . mark us fis ch . android . binary eye . fragment . History Fragment Ċ import Ġde . mark us fis ch . android . binary eye . fragment . Preferences Fragment Ċ import Ġde . mark us fis ch . android . binary eye . view . color System And ToolBar s Ċ import Ġde . mark us fis ch . android . binary eye . view . init System Bars Ċ import Ġde . mark us fis ch . android . binary eye . view . record Toolbar Height Ċ Ċ class ĠMainActivity Ġ: ĠAppCompatActivity () Ġ{ Ċ ĉ override Ġfun Ġon Request Permissions Result ( Ċĉ ĉ request Code : ĠInt , Ċĉ ĉ permissions : ĠArray < String >, Ċĉ ĉ grant Results : ĠInt Array Ċ ĉ ) Ġ{ Ċĉ ĉ when Ġ( request Code ) Ġ{ Ċĉĉ ĉ PERMISSION _ LOCATION , ĠPER MISSION _ WRITE Ġ-> Ġif Ġ( grant Results . isNotEmpty () Ġ&& Ċĉĉĉ ĉ grant Results [ 0 ] Ġ== ĠPackage Manager . PERMISSION _ GRAN TED Ċĉĉ ĉ ) Ġ{ Ċĉĉĉ ĉ permission Granted Callback ?. invoke () Ċĉĉĉ ĉ permission Granted Callback Ġ= Ġnull Ċĉĉ ĉ } Ċĉ ĉ } Ċ ĉ } ĊĊ ĉ override Ġfun Ġon Support Navigate Up (): ĠBoolean Ġ{ Ċĉ ĉ val Ġfm Ġ= Ġsupport FragmentManager Ċĉ ĉ if Ġ( fm Ġ!= Ġnull Ġ&& Ġfm . back Stack Entry Count Ġ> Ġ 0 ) Ġ{ Ċĉĉ ĉ fm . pop Back Stack () Ċĉ ĉ } Ġelse Ġ{ Ċĉĉ ĉ finish () Ċĉ ĉ } Ċĉ ĉ return Ġtrue Ċ ĉ } ĊĊ ĉ override Ġfun Ġattach Base Context ( base : ĠContext ?) Ġ{ Ċĉ ĉ base ?. apply Locale ( prefs . custom Locale ) Ċĉ ĉ super . attach Base Context ( base ) Ċ ĉ } ĊĊ ĉ override Ġfun ĠonCreate ( state : ĠBundle ?) Ġ{ Ċĉ ĉ super . onCreate ( state ) Ċĉ ĉ set ContentView ( R . layout . activity _ main ) ĊĊĉ ĉ init System Bars ( this ) Ċĉ ĉ val Ġtoolbar Ġ= ĠfindViewById ( R . id . toolbar ) Ġas ĠToolbar Ċĉ ĉ record Toolbar Height ( toolbar ) Ċĉ ĉ set Support ActionBar ( toolbar ) Ċĉ ĉ support ActionBar ?. set Display Home As Up Enabled ( true ) ĊĊĉ ĉ support FragmentManager . add On Back Stack Changed Listener Ġ{ Ċĉĉ ĉ color System And ToolBar s ( this @ MainActivity ) Ċĉ ĉ } ĊĊĉ ĉ if Ġ( state Ġ== Ġnull ) Ġ{ Ċĉĉ ĉ set Fragment ( support FragmentManager , Ġget Fragment For Intent ( intent )) Ċĉ ĉ } Ċ ĉ } ĊĊ ĉ comp anion Ġobject Ġ{ Ċĉ ĉ private Ġconst Ġval ĠP REFER ENCES Ġ= Ġ" preferences " Ċĉ ĉ private Ġconst Ġval ĠHIST ORY Ġ= Ġ" history " Ċĉ ĉ private Ġconst Ġval ĠEN CODE Ġ= Ġ" encode " Ċĉ ĉ const Ġval ĠDE CODE D Ġ= Ġ" decoded " ĊĊĉ ĉ private Ġfun Ġget Fragment For Intent ( intent : ĠIntent ?): ĠFragment Ġ{ Ċĉĉ ĉ intent Ġ?: Ġreturn ĠPreferences Fragment () Ċĉĉ ĉ return Ġwhen Ġ{ Ċĉĉĉ ĉ intent . has Extra ( PREFER ENCES ) Ġ-> ĠPreferences Fragment () Ċĉĉĉ ĉ intent . has Extra ( HISTORY ) Ġ-> ĠHistory Fragment () Ċĉĉĉ ĉ intent . has Extra ( ENCODE ) Ġ-> ĠEncode Fragment . newInstance ( Ċĉĉĉĉ ĉ intent . getString Extra ( ENCODE ) !! Ċĉĉĉ ĉ ) Ċĉĉĉ ĉ intent . has Extra ( DECODE D ) Ġ-> ĠDecode Fragment . newInstance ( Ċĉĉĉĉ ĉ intent . get Parcelable Extra ( DECODE D ) !! Ċĉĉĉ ĉ ) Ċĉĉĉ ĉ else Ġ-> ĠPreferences Fragment () Ċĉĉ ĉ } Ċĉ ĉ } ĊĊĉ ĉ fun Ġget Preferences Intent ( context : ĠContext ): ĠIntent Ġ{ Ċĉĉ ĉ val Ġintent Ġ= ĠIntent ( context , ĠMainActivity :: class . java ) Ċĉĉ ĉ intent . putExtra ( PREFER ENCES , Ġtrue ) Ċĉĉ ĉ return Ġintent Ċĉ ĉ } ĊĊĉ ĉ fun Ġget History Intent ( context : ĠContext ): ĠIntent Ġ{ Ċĉĉ ĉ val Ġintent Ġ= ĠIntent ( context , ĠMainActivity :: class . java ) Ċĉĉ ĉ intent . putExtra ( HISTORY , Ġtrue ) Ċĉĉ ĉ return Ġintent Ċĉ ĉ } ĊĊĉ ĉ fun Ġget Encode Intent ( Ċĉĉ ĉ context : ĠContext , Ċĉĉ ĉ text : ĠString ? Ġ= Ġ"", Ċĉĉ ĉ is External : ĠBoolean Ġ= Ġfalse Ċĉ ĉ ): ĠIntent Ġ{ Ċĉĉ ĉ val Ġintent Ġ= ĠIntent ( context , ĠMainActivity :: class . java ) Ċĉĉ ĉ intent . putExtra ( ENCODE , Ġtext ) Ċĉĉ ĉ if Ġ( is External ) Ġ{ Ċĉĉĉ ĉ val Ġflag Activity Clear Task Ġ= Ċĉĉĉĉ ĉ if Ġ( Build . VERSION . SDK _ INT Ġ>= ĠBuild . VERSION _ CODES . H ONE Y COMB ) Ġ{ Ċĉĉĉĉĉ ĉ Intent . FLAG _ ACTIVITY _ CLEAR _ TASK Ċĉĉĉĉ ĉ } Ġelse Ġ 0 Ċĉĉĉ ĉ intent . add Flags ( Ċĉĉĉĉ ĉ Intent . FLAG _ ACTIVITY _ NO _ HISTORY Ġor Ċĉĉĉĉĉĉ ĉ flag Activity Clear Task Ġor Ċĉĉĉĉĉĉ ĉ Intent . FLAG _ ACTIVITY _ NEW _ TASK Ċĉĉĉ ĉ ) Ċĉĉ ĉ } Ċĉĉ ĉ return Ġintent Ċĉ ĉ } ĊĊĉ ĉ fun Ġget Decode Intent ( context : ĠContext , Ġscan : ĠScan ): ĠIntent Ġ{ Ċĉĉ ĉ val Ġintent Ġ= ĠIntent ( context , ĠMainActivity :: class . java ) Ċĉĉ ĉ intent . putExtra ( DECODE D , Ġscan ) Ċĉĉ ĉ return Ġintent Ċĉ ĉ } Ċ ĉ } Ċ } Ċ