Android adds broadcasts to custom keys and assigns values to the current focus input box by broadcasting

Source: Internet
Author: User

Add a broadcast to a custom button

Modifying the Interceptkeybeforedispatching method in Phonewindowmanager.java

/frameworks/base/policy/src/com/android/internal/policy/impl/phonewindowmanager.java

1 @Override2      Public LongInterceptkeybeforedispatching (WindowState win, KeyEvent event,intpolicyflags) {3         Final BooleanKeyguardon =Keyguardon ();4         Final intKeyCode =Event.getkeycode ();5         Final intRepeatCount =Event.getrepeatcount ();6         Final intMetaState =event.getmetastate ();7         Final intFlags =event.getflags ();8         Final BooleanDown = event.getaction () = =Keyevent.action_down;9         Final BooleanCanceled =event.iscanceled ();Ten         Final BooleanLongpress = (Flags & keyevent.flag_long_press)! = 0; One         Final BooleanVirtualkey = Event.getdeviceid () = =Keycharactermap.virtual_keyboard; A         FinalString iscitkeytest=systemproperties.get ("Persist.sys.startCitKeyTest"); -  -  the          -         //To add a custom keystroke broadcast----start -         Switch(keycode) -             { +                  Case135: -                  Case136: +                  Case137: A                  Case139: at                 { -                     if(RepeatCount = = 0) { -                          -Intent mykeyintent =NewIntent (); -                          -                          in                         if(down) -                         { toMykeyintent.setaction ("Com.rscja.android.KEY_DOWN"); +                         } -                         Else the                         { *Mykeyintent.setaction ("Com.rscja.android.KEY_UP"); $                         }Panax Notoginseng                          -                      theMykeyintent.putextra ("KeyCode", keycode); +                          A Mcontext.sendbroadcastasuser (mykeyintent, userhandle.all); the                          +                          -                      $                     } $                 } -                  -                  the                  -                      Break;Wuyi             } the              -             //Add a custom key broadcast----End Wu  -  About  $  - ... - ... - ... A ... +  the}

Ii. assigning values to the current focus input box by broadcasting

Modifying the OnCreate () method in Inputmethodservice.java

/frameworks/base/core/java/android/inputmethodservice/inputmethodservice.java

1@Override Public voidonCreate () {2Mtheme =Resources.selectsystemtheme (Mtheme,3 getapplicationinfo (). Targetsdkversion,4 Android. R.style.theme_inputmethod,5 Android. R.style.theme_holo_inputmethod,6 Android. R.style.theme_devicedefault_inputmethod,7 Android. R.style.theme_devicedefault_inputmethod);8         Super. SetTheme (mtheme);9         Super. OnCreate ();TenMimm =(Inputmethodmanager) Getsystemservice (input_method_service); OneMinflater =(Layoutinflater) Getsystemservice ( A context.layout_inflater_service); -Mwindow =NewSoftinputwindow ( This, "Inputmethod", Mtheme,NULL,NULL, Mdispatcherstate, -WindowManager.LayoutParams.TYPE_INPUT_METHOD, Gravity.bottom,false); the         if(mhardwareaccelerated) { - Mwindow.getwindow (). Addflags (WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED); -         } - initviews (); + Mwindow.getwindow (). setlayout (Match_parent, wrap_content); -          +          A         //register for broadcast monitoring atIntentfilter Barcodecheckfilter =NewIntentfilter ("Com.rscja.android.DATA_RESULT"); - Mrootview.getcontext (). Registerreceiver (m_barcodecheckreciever,barcodecheckfilter); -          -     } -      -      in     //Add a custom broadcast -      PrivateBroadcastreceiver M_barcodecheckreciever =NewBroadcastreceiver () { to  + @Override -          Public voidOnReceive (Context context, Intent Intent) { theInputconnection conn =getcurrentinputconnection (); *  $String Intent_data=intent.getstringextra ("Data");Panax Notoginseng  -  the         if(Intent_data.charat (Intent_data.length ()-1) = = ' \ n ') +         { A             if(Conn! =NULL) { theConn.committext (Intent_data.substring (0,intent_data.length ()-1), 1); +             } -Sendkeychar (' \ n '); $         } $         Else -         { -             if(Conn! =NULL) { theConn.committext (Intent_data, 1); -                 }Wuyi             } the         } -};

Android adds broadcasts to custom keys and assigns values to the current focus input box by broadcasting

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.