DonBrody/Android-CustomKeyboard - GitHub

文章推薦指數: 80 %
投票人數:10人

Android-CustomKeyboard. Fully customizable Android keyboard written in Kotlin. Deprecated. This package is no longer maintained. I'm no longer an Android ... Skiptocontent {{message}} DonBrody / Android-CustomKeyboard Public Notifications Star 73 Fork 9 FullycustomizableAndroidkeyboardwritteninKotlin. MITLicense 73 stars 9 forks Star Notifications Code Issues 5 Pullrequests 0 Actions Projects 0 Wiki Security Insights More Code Issues Pullrequests Actions Projects Wiki Security Insights master Branches Tags Couldnotloadbranches Nothingtoshow Loading {{refName}} default Couldnotloadtags Nothingtoshow {{refName}} default Loading 1 branch 0 tags Code Loading Latestcommit   Gitstats 20 commits Files Permalink Failedtoloadlatestcommitinformation. Type Name Latestcommitmessage Committime app     gradle/wrapper     .gitignore     CustomKeyboardLandscape.gif     CustomKeyboardPortrait.gif     LICENSE     README.md     build.gradle     gradle.properties     settings.gradle     Viewcode Android-CustomKeyboard Deprecated Prerequisites RunningtheDemo WhyIMadeIt HowItWorks AdvancedUse NextSteps Dependencies License README.md Android-CustomKeyboard FullycustomizableAndroidkeyboardwritteninKotlin. Deprecated Thispackageisnolongermaintained.I'mnolongeranAndroiddeveloperandhavenotcommittedanycodeinacoupleofyearsnow.Pleasefeelfreetoforkthisprojectandmakeimprovementsasneeded. Prerequisites MakesureyouhaveaversionofAndroidStudioinstalledthatsupportsKotlin(3+shouldbefine). RunningtheDemo Justdownloadtheproject,openitinAndroidStudio,connecttoavirtualorphysicaldevice,andrunit!Thereshouldn'tbeanyfurtherconfigurationrequired(unlessyouneedtodownloadbuildtools,etc.,butAndroidStudioshouldpromptyoutodothat). BelowareGIF'softhefunctionalityinbothladscapeandportrait.Noticethatinbothorientationsthekeyboardtakesupthefullscreenwidth,andthebuttonwidthschange(theyareapercentageofthescreenwidth).ThatisbecauseitextendstheResizableRelativeLayout.Additionally,thecomponentresponsiblefortheexpansionandcollapseofthekeyboardistheExpandableView.Pleasetakealookattheirdocumentationformoredetail.      WhyIMadeIt TheAndroidsystemkeyboardAPIislimitedanddifficulttoworkwith.Ispentmanyhoursresearchingdifferentwaystogainfullcontrolofthekeyboard,andendeduppiecingtogetherafewdifferentapproachesandaddingsomeofmyownflavortoit.IhopethatIcansave somebodyelsealotoftimeandheadache. HowItWorks TheCustomKeyboardViewcanbeinjectedwithanykeyboardlayoutandcontroller.AllyouneedtodoiscreateanEditText,passittotheCustomKeyboardView,andindicatewhatkeyboardtypeitshouldbeusing.BelowistheentireMainActivitydemoclass: classMainActivity:AppCompatActivity(){ privatelateinitvarkeyboard:CustomKeyboardView overridefunonCreate(savedInstanceState:Bundle?){ super.onCreate(savedInstanceState) setContentView(R.layout.activity_main) valnumberField:EditText=findViewById(R.id.testNumberField) valnumberDecimalField:EditText=findViewById(R.id.testNumberDecimalField) valqwertyField:EditText=findViewById(R.id.testQwertyField) keyboard=findViewById(R.id.customKeyboardView) keyboard.registerEditText(CustomKeyboardView.KeyboardType.NUMBER,numberField) keyboard.registerEditText(CustomKeyboardView.KeyboardType.NUMBER_DECIMAL,numberDecimalField) keyboard.registerEditText(CustomKeyboardView.KeyboardType.QWERTY,qwertyField) valswitchActivitiesButton:Button=findViewById(R.id.switchActivitiesButton) switchActivitiesButton.setOnClickListener{ startActivity(Intent(this@MainActivity,AdvancedFeaturesActivity::class.java)) } } overridefunonBackPressed(){ if(keyboard.isExpanded){ keyboard.translateLayout() }else{ super.onBackPressed() } } } TheEditText'sarestoredinamapbytheCustomKeyboardView: privatevalkeyboards=HashMap() Asyoucansee,theyaremappedtotheirKeyboardLayout,whichstoresitsowncontroller.Thisprocessisshownbelow: funregisterEditText(type:KeyboardType,field:EditText){ field.setRawInputType(InputType.TYPE_CLASS_TEXT) field.setTextIsSelectable(true) field.showSoftInputOnFocus=false field.isSoundEffectsEnabled=false field.isLongClickable=false valinputConnection=field.onCreateInputConnection(EditorInfo()) keyboards[field]=createKeyboardLayout(type,inputConnection) ... } privatefuncreateKeyboardLayout(type:KeyboardType,ic:InputConnection):KeyboardLayout?{ when(type){ KeyboardType.NUMBER->{ returnNumberKeyboardLayout(context,createKeyboardController(type,ic)) } KeyboardType.NUMBER_DECIMAL->{ returnNumberDecimalKeyboardLayout(context,createKeyboardController(type,ic)) } KeyboardType.QWERTY->{ returnQwertyKeyboardLayout(context,createKeyboardController(type,ic)) } else->return@createKeyboardLayoutnull//thisshouldneverhappen } } privatefuncreateKeyboardController(type:KeyboardType,ic:InputConnection):KeyboardController?{ when(type){ KeyboardType.NUMBER->{ returnDefaultKeyboardController(ic) } KeyboardType.NUMBER_DECIMAL->{ returnNumberDecimalKeyboardController(ic) } KeyboardType.QWERTY->{ returnDefaultKeyboardController(ic) } else->return@createKeyboardControllernull//thisshouldneverhappen } } YoumightalsonoticethattheCustomKeyboardViewiscurrentlyusingsomeverybasiccontrollers,sowhywouldweseparatethecontrollerlogicfromthelayout?Becausemorecomplicatedcontrollersmaybeneededinthefuture.Thisarchitectureallowsformorecomplexkeyboardlayoutstobecreated.Forexample,whatifweneedtocreateakeyboardthathandleslatitudes.Thatcangetprettycomplicated.NotonlydowehavetoconsiderthatlatitudescanonlyspanbetweenS90.0000andN90.0000degrees,butwhatifwewanttorepresentthosevaluesindegreesandminutes,ordegreesandminutesandseconds,orwhateverformattheuserchooses?Thearchitecturemightbealittleoverkillforsimplekeyboards,butitleavesopenthepossibilitytocreateanykeyboardwemayneedtointhefuturewithoutanysignificantchangestothearchitecture. AdvancedUse TheCustomKeyboardViewiscapableofautoregisteringallEditText'swithinaViewGroup.JustpassanyViewGrouptotheautoRegisterEditTextsmethodofanyCustomKeyboardViewinstance,anditwillrecursivelysearchtheViewtreeforEditText's,checktheirtype,andautomaticallybindtotheirInputConnection's. Additionally,thereisaCustomTextFieldcomponent.ThiscomponentisasimpleextensionoftheAndroidEditTextcomponent.Itautosetssimplesettingssuchasbackgroundcolor,maxcharacters,andtextsize.Themostimportantadditiontothisextensionisthekeyboardtypeproperty.Youcancreatethiscomponentprogrammaticaly,setit'stype,andpassit'scontainingViewGrouptotheCustomKeyboardViewtoautobindtoit'sInputConnection.ThisallowsyoutocreatekeyboardtypesthatarenotrecognizedbyAndroid,setthekeyboardtypeofthisnewcomponent,andhavethattypeautorecognizedbytheCustomKeyboardView. Note:TheCustomTextFieldisaverysimplecomponent,andlikethecustomkeyboard'sinthisrepository,it'sexpectedthatyou'lloverridetheirattributestofityourproject'sneeds. TakealookattheAdvancedFeaturesActivity.ktclasstoseeexamplesofadvanceduse. NextSteps AddtheCustomKeyboardViewtoany(andhopefullyall:)ofyourprojects,addanylayoutorcontrollersyou'dlike,modifytheUIinanywaythatfitsyourneeds,andenjoy! Dependencies ResizableRelativeLayout ExpandableView License ThisprojectislicensedundertheMITLicense-seetheLICENSEfilefordetails About FullycustomizableAndroidkeyboardwritteninKotlin. Topics android keyboard-layout kotlin-android android-architecture android-ui keyboards Resources Readme License MITLicense Releases Noreleasespublished Packages0 Nopackagespublished Languages Kotlin 100.0% Youcan’tperformthatactionatthistime. Yousignedinwithanothertaborwindow.Reloadtorefreshyoursession. Yousignedoutinanothertaborwindow.Reloadtorefreshyoursession.



請為這篇文章評分?