1 PackageCom.sixin.view;2 3 ImportCom.sixin.utile.FaceDataUtil;4 ImportAndroid.annotation.SuppressLint;5 ImportAndroid.content.Context;6 Importandroid.text.Editable;7 ImportAndroid.util.AttributeSet;8 ImportAndroid.widget.EditText;9 Ten Public classCustomeditviewextendsEditText { One Private Static Final intId_paste =Android. R.id.paste; A - PublicCustomeditview (Context context, AttributeSet attrs) { - Super(context, attrs); the } - -@SuppressLint ("Newapi") - @Override + Public BooleanOntextcontextmenuitem (intID) { - if(id = =id_paste) { + Try { A intCurrentapiversion =Android.os.Build.VERSION.SDK_INT; at if(Currentapiversion >=Android.os.Build.VERSION_CODES. Honeycomb) { -Android.content.ClipboardManager Clipboard =(Android.content.ClipboardManager) GetContext (). Getsystemservice (Context.clipboard_service); -String value =Clipboard.gettext (). toString (); -Editable edit =Geteditabletext (); - //edit.clear (); - intindex = This. Getselectionstart (); in if(Index < 0 | | | Index >=edit.length ()) { -Edit.append (Facedatautil.getins (GetContext ()). Getexpressionstring (GetContext (), Value, 0.7f)); to}Else { +Edit.insert (Index, Facedatautil.getins (GetContext ()). Getexpressionstring (GetContext (), value, 0.7f));//Insert text where the cursor is located - } the *}Else { $Android.text.ClipboardManager Clipboard =(Android.text.ClipboardManager) GetContext (). Getsystemservice (Context.clipboard_service);Panax NotoginsengString value =Clipboard.gettext (). toString (); -Editable edit =Geteditabletext (); the //edit.clear (); + intindex = This. Getselectionstart (); A if(Index < 0 | | | Index >=edit.length ()) { theEdit.append (Facedatautil.getins (GetContext ()). Getexpressionstring (GetContext (), Value, 0.7f)); +}Else { -Edit.insert (Index, Facedatautil.getins (GetContext ()). Getexpressionstring (GetContext (), value, 0.7f));//Insert text where the cursor is located $ } $ } - return true; -}Catch(Exception e) { the e.printstacktrace (); - }Wuyi } the return Super. Ontextcontextmenuitem (ID); - } Wu -}
EditText Implement paste Expression