Android Development Imitation Salted Fish keyboard demo (modified version) _android

Source: Internet
Author: User
Tags delete key gettext stub stringbuffer

I'm not going to post the layout here

/** * Final Call Modification Price Dialog/protected void Editpricedialog () {//TODO auto-generated method Stub editpriceview = View 
. Inflate (this, r.layout.dialog_price_input_keyboard, null); 
Pricedialog = new Dialog (this, r.style.contactdialog); 
Pricedialog.requestwindowfeature (Window.feature_no_title); 
Window Pricedialogwindow = Pricedialog.getwindow (); 
Pricedialogwindow.setgravity (Gravity.bottom); 
Pricedialog.setcontentview (Editpriceview); 
Pricedialog.getwindow (). GetAttributes (). windowanimations = R.style.dialoganimation; 
Pricedialog.show (); 
Tv_softkb_point = (TextView) Editpriceview.findviewbyid (r.id.tv_softkb_point); 
Buffer = new StringBuffer (); 
StringBuffer = Buffer.tostring (); 
Buffer2 = new StringBuffer (); 
Stringbuffer2 = Buffer2.tostring (); 
Etgoodsprice = (edittext) Editpriceview.findviewbyid (R.id.et_goodsprice); 
Etgoodsprice.addtextchangedlistener (New Textwatcher () {private String Etpricetrim; @Override public void ontextchanged (charsequence s, int start, int before, INT count) {Etpricetrim = S.tostring (). Trim (); if (etpricetrim.length () = = 1 && s.tostring (). Equals (".") 
{//If the length of the EditText is 1 and the user has entered only one. Then buffer append "0" + "." Delete the points we entered//if not deleted in the buffer data will be. 0. Buffer.append ("0"). Append ("."). 
Deletecharat (0); 
Etgoodsprice.settext (Buffer.tostring ()); if (S.tostring (). Contains (".")) {//If s contains dot if (S.length ()-1-s.tostring (). IndexOf (".") > 2) {if (tv_softkb_point!=null) {Tv_softkb_point.setclic 
Kable (FALSE); 
} if (Buffer!=null&&buffer.length () >=1) {Buffer.deletecharat (Buffer.length ()-1); 
} s = s.tostring (). subsequence (0, S.tostring (). IndexOf (".") + 3); 
Etgoodsprice.settext (s); 
Etgoodsprice.setselection (S.length ()); else if (s.length () -1-s.tostring (). IndexOf (). 
<=2) {if (tv_softkb_point!=null) {tv_softkb_point.setclickable (false); 
}} else {if (tv_softkb_point!=null) {tv_softkb_point.setclickable (true); 
Tv_softkb_point.setenabled (TRUE); } if (S.tostring (). StartsWith ("0") && S.tostriNg (). Trim (). Length () > 1) {//If the beginning length of 0 is greater than 1 the second element is not. if (!s.tostring (). substring (1, 2). Equals (".") 
{Buffer.deletecharat (1); 
Etgoodsprice.settext (s.subsequence (0, 1)); 
Etgoodsprice.setselection (1); 
Return  @Override public void beforetextchanged (charsequence s, int start, int count, int in) {} @Override Public 
void Aftertextchanged (Editable s) {int length = Etpricetrim.length (); 
if (length >=1) {etgoodsprice.setselection (length); 
else {etgoodsprice.setselection (0); 
}//Toast.maketext (postissueactivity.this,s.tostring (), 0). Show (); if (s.tostring ()!=null&&s.tostring (). Contains (".")) {//through s out of the current editext to judge whether it contains. If included, set the Clickbale to false and not to be clickable if (tv_softkb_point!=null) {tv_softkb_ 
Point.setclickable (FALSE); 
Tv_softkb_point.setenabled (FALSE); }//if (s.tostring (). Length () ==1&&s.tostring (). Equals ("0")) {//If the length is 1 and the cursor is positioned at the beginning of 0 this time, delete the buffer///// 
The first char and set//////Buffer.deletecharat (0); Etgoodsprice.settexT (buffer.tostring ()); 
// 
// } 
} 
}); 
if (!ipriceedit.gettext (). ToString (). substring (1, ipriceedit.gettext (). Length ()). ToString (). Equals ("0.00")) { 
Etgoodsprice. SetText (Ipriceedit.gettext (). ToString (). substring (1, ipriceedit.gettext (). Length ()). ToString ()); 
Etgoodsprice.setselection (Etgoodsprice.length ()); 
Buffer.append (Ipriceedit.gettext (). ToString (). substring (1, ipriceedit.gettext (). Length ()). ToString ()); 
else {Etgoodsprice.settext (""); 
Etgoodsprice.sethint ("0.00"); 
Buffer.append (""); 
} Etoriginalprice = (edittext) Editpriceview.findviewbyid (R.id.et_originalprice); 
Etoriginalprice.addtextchangedlistener (New Textwatcher () {private String trim; 
@Override public void ontextchanged (charsequence s, int start, int before, int count) {trim = s.tostring (). Trim (); if (etoriginalprice.length () = = 1 && s.tostring (). Equals (".") {Buffer2.append ("0"). Append ("."). 
Deletecharat (0); 
Etoriginalprice.settext (Buffer2.tostring ()); if (S.tostring (). Contains (".")) {
if (S.length ()-1-s.tostring (). IndexOf (".") > 2) {if (tv_softkb_point!=null) {tv_softkb_point.setclickable (false) 
; 
} if (Buffer2!=null&&buffer2.length () >=1) {Buffer2.deletecharat (Buffer2.length ()-1); 
} s = s.tostring (). subsequence (0, S.tostring (). IndexOf (".") + 3); 
Etoriginalprice.settext (s); 
Etoriginalprice.setselection (S.length ()); else if (s.length () -1-s.tostring (). IndexOf (). 
<=2) {if (tv_softkb_point!=null) {tv_softkb_point.setclickable (false); 
}} else {if (tv_softkb_point!=null) {tv_softkb_point.setclickable (true); 
Tv_softkb_point.setenabled (TRUE); } if (S.tostring (). StartsWith ("0") && s.tostring (). Trim (). Length () > 1) {if (!s.tostring (). substring (1, 2 ). Equals (".")) 
{Buffer2.deletecharat (1); 
Etoriginalprice.settext (s.subsequence (0, 1)); 
Etoriginalprice.setselection (1); 
Return @Override public void beforetextchanged (charsequence s, int start, int count, int after) {//TODO Auto-generat 
Ed Method stub@Override public void aftertextchanged (Editable s) {//TODO auto-generated method Stub int length = Trim.length (); 
if (length >=1) {etoriginalprice.setselection (length); 
else {etoriginalprice.setselection (0); } if (S.tostring ()!=null&&s.tostring (). Contains (".")) 
{if (tv_softkb_point!=null) {tv_softkb_point.setclickable (false); 
Tv_softkb_point.setenabled (FALSE); }//if (s.tostring (). Length () ==1&&s.tostring (). Equals ("0")) {//If the length is 1 and the cursor is positioned at the beginning of 0 this time, delete the buffer///// 
The first char and set////Buffer2.deletecharat (0); 
Etoriginalprice.settext (Buffer2.tostring ()); 
// 
// } 
} 
}); 
Etoriginalprice.setselection (Etoriginalprice.length ()); 
if (!ioldpriceedit.gettext (). subsequence (1, Ioldpriceedit.gettext (). Length ()). ToString (). Equals ("0.00")) { 
Etoriginalprice. SetText (Ioldpriceedit.gettext (). subsequence (1, Ioldpriceedit.gettext (). Length ()). ToString ()); Buffer2.append (Ioldpriceedit.gettext (). subsequence (1, Ioldpriceedit.gettext (). Length ()). toStRing ()); 
else {Etoriginalprice.settext (""); 
Etoriginalprice.sethint ("0.00"); 
Buffer2.append (""); 
}//Etoriginalprice.requestfocus (); 
Etoriginalprice.setselection (Etgoodsprice.gettext (). Length ()); 
ImageView tv_softkb_hiddenkb = (imageview) Editpriceview.findviewbyid (r.id.tv_softkb_hiddenkb); 
ImageView Ivdelete = (imageview) Editpriceview.findviewbyid (r.id.iv_delete); Ivdelete.setonclicklistener (New Onclicklistener () {@Override public void OnClick (View v) {//Toast.maketext (postissue 
Activity.this, "dddd", 0). Show (); 
Delnumber (); 
} 
}); 
Long press DELETE key event Ivdelete.setonlongclicklistener (new Onlongclicklistener () {@Override public boolean onlongclick (View v) { 
if (Etgoodsprice.hasfocus ()) {buffer.delete (0, Etgoodsprice.gettext (). Length ()); 
if (Etgoodsprice.gettext (). Length () >=1) {//Buffer.deletecharat (Etgoodsprice.gettext (). Length ()-1); 
} StringBuffer = Buffer.tostring (); 
Etgoodsprice.settext (stringbuffer.substring (0, Stringbuffer.length ())); } if (Etoriginalprice.hasfocus ()) {buffer2.delete (0, Etoriginalprice.gettext (). Length ()); 
if (Etoriginalprice.gettext (). Length () >=1) {//Buffer2.deletecharat (Etoriginalprice.gettext (). Length ()-1); 
} Stringbuffer2 = Buffer2.tostring (); 
Etoriginalprice.settext (stringbuffer2.substring (0, Stringbuffer2.length ())); 
return false; 
} 
}); 
Setnumber (buffer, buffer2, Etgoodsprice, Etoriginalprice); Tv_softkb_hiddenkb.setonclicklistener (New Onclicklistener () {@Override public void OnClick (View v) {editpriceview.cle 
Aranimation (); 
Pricedialog.cancel (); 
} 
}); 
TextView CONFIRMKB = (TextView) Editpriceview.findviewbyid (R.ID.TV_CONFIRMKB); 
Hiddensoftkb (Etgoodsprice, Etoriginalprice); Confirmkb.setonclicklistener (New Onclicklistener () {@SuppressLint ("Newapi") @Override public void OnClick (View v) {/ 
/ipriceedit//Ioldpriceedit if (buffer!= null) {//Ipriceedit.settext ("¥" +buffer.tostring ()); 
Ipriceedit.settext ("¥" + etgoodsprice.gettext (). toString ()); if (etgoodsPrice.gettext (). toString (). Equals ("")) {Ipriceedit.settext ("¥" + "0.00"); 
} if (buffer2!= null) {//Ioldpriceedit.settext ("¥" +buffer2.tostring ()); 
Ioldpriceedit.settext ("¥" + etoriginalprice.gettext (). toString ()); 
if (Etoriginalprice.gettext (). toString (). Equals ("")) {Ioldpriceedit.settext ("¥" + "0.00"); 
} if (Etgoodsprice.gettext (). toString (). Equals ("")) {Etgoodsprice.settext ("0.00"); 
} if (Etoriginalprice.gettext (). toString (). Equals ("")) {Etoriginalprice.settext ("0.00"); } if (Double.valueof (Etgoodsprice.gettext (). ToString ()) >double.valueof (Etoriginalprice.gettext (). ToString ())) {//Toast.maketext (Postissueactivity.this, "The price is higher than the original price, is it confirmed?) 
", 0). Show (); Publicdialog Priceismaxdialog = Publicdialog.createdialog (postissueactivity.this, New DialogBtnClickListener () {@ Override public void OnClick (view view) {switch (View.getid ()) {case R.id.public_dialog_cancel:editpriceview.cleara 
Nimation (); 
Pricedialog.cancel (); 
Break 
Case R.ID.PUBLIC_DIALOG_CONFIRM:Editpriceview.clearanimation (); 
Pricedialog.cancel (); 
Break 
Default:break; 
} 
} 
}); 
Window Dialogwindow = Priceismaxdialog.getwindow (); 
Display display = Getwindowmanager (). Getdefaultdisplay (); 
Windowmanager.layoutparams LP = Dialogwindow.getattributes (); 
Lp.width = (int) (Display.getwidth () * 0.99); 
Dialogwindow.setattributes (LP); 
Priceismaxdialog.show (); 
LinearLayout llpublic = (linearlayout) Priceismaxdialog.findviewbyid (R.id.ll_public_dialog); 
Llpublic.setbackground (Getresources (). getdrawable (R.drawable.public_dialog_botom_corner_shape_wite)); 
Priceismaxdialog.onwindowfocuschanged (TRUE); 
View splitling = Priceismaxdialog.findviewbyid (r.id.v_line); 
Splitling.setbackgroundcolor (Color.color_eaeaea); 
Priceismaxdialog.setlinecolor (Color.parsecolor ("#E9E9EB")); 
Priceismaxdialog.settitle ("hint"); Priceismaxdialog.setcontent ("Bid above the original price, is it confirmed?") 
"); 
Priceismaxdialog.settitlevisibility (TRUE); 
TextView Contentview = Priceismaxdialog.getcontentview (); Contentview.settextsIze (16); 
Contentview.setgravity (Gravity.center); 
Contentview.setpadding (0, 0, 0, 10); 
Android.view.ViewGroup.LayoutParams layout = Contentview.getlayoutparams (); LAYOUT.WIDTH = LP. 
Match_parent; 
Layout.height = 120; 
Contentview.setlayoutparams (layout); 
TextView publicdialogcancle = (TextView) Priceismaxdialog.findviewbyid (r.id.public_dialog_cancel); 
Publicdialogcancle.settext ("no"); 
Priceismaxdialog.setcanceltextcolor (Color.parsecolor ("#037BFE")); 
Priceismaxdialog.setcancelbackground (Color.parsecolor ("#ffffff")); 
Publicdialogcancle.settextcolor (Color.app_green); 
TextView publicdialogconfirm = (TextView) Priceismaxdialog.findviewbyid (r.id.public_dialog_confirm); 
Publicdialogconfirm.settext ("yes"); 
Priceismaxdialog.setconfirmtextcolor (Color.parsecolor ("#037BFE")); 
Priceismaxdialog.setconfirmbackground (Color.parsecolor ("#ffffff")); 
Publicdialogconfirm.settextcolor (Color.app_green); Publicdialogconfirm.setbackground (Getresources (). Getdrawable (r.drawable.coners_sAVE_BG)); 
Priceismaxdialog.findviewbyid (R.id.vv_hor). setvisibility (view.visible); 
} editpriceview.clearanimation (); 
Pricedialog.cancel (); 
} 
}); /** * Delete the amount entered */protected void Delnumber () {if (Etgoodsprice.hasfocus ()) {//Buffer.delete (0, Etgoodsprice.gett 
Ext (). Length ()); 
if (Etgoodsprice.gettext (). Length () >= 1) {Buffer.deletecharat (Etgoodsprice.gettext (). Length ()-1); 
Buffer.deletecharat (Etgoodsprice.gettext (). Length ()); 
} StringBuffer = Buffer.tostring (); 
Etgoodsprice.settext (stringbuffer.substring (0, Stringbuffer.length ())); 
Etgoodsprice.setselection (Etgoodsprice.length ()); 
} if (Etoriginalprice.hasfocus ()) {//Buffer2.delete (0,etoriginalprice.gettext (). Length ()); 
if (Etoriginalprice.gettext (). Length () >= 1) {Buffer2.deletecharat (Etoriginalprice.gettext (). Length ()-1); 
Buffer2.deletecharat (Etoriginalprice.gettext (). Length ()); 
} Stringbuffer2 = Buffer2.tostring (); Etoriginalprice.settext (stringbuffer2.substring (0, Stringbuffer2.lengtH ())); 
Etoriginalprice.setselection (Etoriginalprice.length ());  }/** * Input amount * * @param buffer * @param buffer2 * @param etgoodsprice * @param etoriginalprice/private void Setnumber (final StringBuffer buffer, final StringBuffer buffer2, final EditText etgoodsprice, final edittext Etoriginalp 
Rice) {TextView tv_softkb_1 = (TextView) Editpriceview.findviewbyid (r.id.tv_softkb_1); Tv_softkb_1.setonclicklistener (New Onclicklistener () {@Override public void OnClick (View v) {if etgoodsprice.hasfocu 
S ()) {Buffer.append ("1"); 
Etgoodsprice.settext (Buffer.tostring ()); 
} if (Etoriginalprice.hasfocus ()) {Buffer2.append ("1"); 
Etoriginalprice.settext (Buffer2.tostring ()); 
} 
} 
}); 
TextView tv_softkb_2 = (TextView) Editpriceview.findviewbyid (r.id.tv_softkb_2); Tv_softkb_2.setonclicklistener (New Onclicklistener () {@Override public void OnClick (View v) {if etgoodsprice.hasfocu 
S ()) {Buffer.append ("2"); 
Etgoodsprice.settext (Buffer.tostring ()); } if (etoriginalPrice.hasfocus ()) {Buffer2.append ("2"); 
Etoriginalprice.settext (Buffer2.tostring ()); 
} 
} 
}); 
TextView tv_softkb_3 = (TextView) Editpriceview.findviewbyid (r.id.tv_softkb_3); Tv_softkb_3.setonclicklistener (New Onclicklistener () {@Override public void OnClick (View v) {if etgoodsprice.hasfocu 
S ()) {Buffer.append ("3"); 
Etgoodsprice.settext (Buffer.tostring ()); 
} if (Etoriginalprice.hasfocus ()) {Buffer2.append ("3"); 
Etoriginalprice.settext (Buffer2.tostring ()); 
} 
} 
}); 
TextView tv_softkb_4 = (TextView) Editpriceview.findviewbyid (r.id.tv_softkb_4); Tv_softkb_4.setonclicklistener (New Onclicklistener () {@Override public void OnClick (View v) {if etgoodsprice.hasfocu 
S ()) {Buffer.append ("4"); 
Etgoodsprice.settext (Buffer.tostring ()); 
} if (Etoriginalprice.hasfocus ()) {Buffer2.append ("4"); 
Etoriginalprice.settext (Buffer2.tostring ()); 
} 
} 
}); 
TextView tv_softkb_5 = (TextView) Editpriceview.findviewbyid (r.id.tv_softkb_5); Tv_softkb_5.setonclicklistener (New onClicklistener () {@Override public void OnClick (View v) {if (Etgoodsprice.hasfocus ()) {Buffer.append ("5"); 
Etgoodsprice.settext (Buffer.tostring ()); 
} if (Etoriginalprice.hasfocus ()) {Buffer2.append ("5"); 
Etoriginalprice.settext (Buffer2.tostring ()); 
} 
} 
}); 
TextView tv_softkb_6 = (TextView) Editpriceview.findviewbyid (r.id.tv_softkb_6); Tv_softkb_6.setonclicklistener (New Onclicklistener () {@Override public void OnClick (View v) {if etgoodsprice.hasfocu 
S ()) {Buffer.append ("6"); 
Etgoodsprice.settext (Buffer.tostring ()); 
} if (Etoriginalprice.hasfocus ()) {Buffer2.append ("6"); 
Etoriginalprice.settext (Buffer2.tostring ()); 
} 
} 
}); 
TextView tv_softkb_7 = (TextView) Editpriceview.findviewbyid (r.id.tv_softkb_7); Tv_softkb_7.setonclicklistener (New Onclicklistener () {@Override public void OnClick (View v) {if etgoodsprice.hasfocu 
S ()) {Buffer.append ("7"); 
Etgoodsprice.settext (Buffer.tostring ()); 
} if (Etoriginalprice.hasfocus ()) {Buffer2.append ("7"); EtOriginalprice.settext (Buffer2.tostring ()); 
} 
} 
}); 
TextView tv_softkb_8 = (TextView) Editpriceview.findviewbyid (r.id.tv_softkb_8); Tv_softkb_8.setonclicklistener (New Onclicklistener () {@Override public void OnClick (View v) {if etgoodsprice.hasfocu 
S ()) {Buffer.append ("8"); 
Etgoodsprice.settext (Buffer.tostring ()); 
} if (Etoriginalprice.hasfocus ()) {Buffer2.append ("8"); 
Etoriginalprice.settext (Buffer2.tostring ()); 
} 
} 
}); 
TextView tv_softkb_9 = (TextView) Editpriceview.findviewbyid (r.id.tv_softkb_9); Tv_softkb_9.setonclicklistener (New Onclicklistener () {@Override public void OnClick (View v) {if etgoodsprice.hasfocu 
S ()) {Buffer.append ("9"); 
Etgoodsprice.settext (Buffer.tostring ()); 
} if (Etoriginalprice.hasfocus ()) {Buffer2.append ("9"); 
Etoriginalprice.settext (Buffer2.tostring ()); 
} 
} 
}); 
TextView tv_softkb_0 = (TextView) Editpriceview.findviewbyid (R.ID.TV_SOFTKB_0); Tv_softkb_0.setonclicklistener (New Onclicklistener () {@Override public void OnCLick (View v) {if (Etgoodsprice.hasfocus ()) {Buffer.append ("0"); 
Etgoodsprice.settext (Buffer.tostring ()); 
} if (Etoriginalprice.hasfocus ()) {Buffer2.append ("0"); 
Etoriginalprice.settext (Buffer2.tostring ()); 
} 
} 
}); Tv_softkb_point.setonclicklistener (New Onclicklistener () {@Override public void OnClick (View v) {if Etgoodsprice.has 
Focus ()) {Buffer.append ("."); 
Etgoodsprice.settext (Buffer.tostring ()); 
} if (Etoriginalprice.hasfocus ()) {Buffer2.append ("."); 
Etoriginalprice.settext (Buffer2.tostring ()); 
} 
} 
}); /** * Use EditText to get focus can't bounce software keyboard * * @param etgoodsprice * @param etoriginalprice/private void Hiddensoftkb (final E Dittext Etgoodsprice, Final edittext etoriginalprice) {Etgoodsprice.setontouchlistener (new Ontouchlistener () {@Overri  De public boolean Ontouch (View V, motionevent event) {int intype = Etgoodsprice.getinputtype ();//backup the input// Type Etgoodsprice.setinputtype (inputtype.type_null); Disable soft//input EtgoodspricE.ontouchevent (event); Call native Handler Etgoodsprice.setinputtype (Intype); 
Restore input type etgoodsprice.setselection (Etgoodsprice.gettext (). Length ()); 
return true; 
} 
});  
Etoriginalprice.setontouchlistener (New Ontouchlistener () {@Override public boolean ontouch (View V, motionevent event) { int intype = Etoriginalprice.getinputtype (); Backup the input//type Etoriginalprice.setinputtype (Inputtype.type_null); Disable//Soft//Input etoriginalprice.ontouchevent (event); Call native Handler Etoriginalprice.setinputtype (Intype); 
Restore input type etoriginalprice.setselection (Etoriginalprice.gettext (). Length ()); 
return true; 
} 
}); /** * Input Original price and price dialog/private void Showmofityprice () {//TODO auto-generated method stub Mofityprice.setonclickl Istener (New Onclicklistener () {@Override public void OnClick (View v) {//Ipriceedit//Ioldpriceedit//Ipriceedit. 
Setfocusable (TRUE); 
Hiddenkeyboard (); 
Editpricedialog (); 
} 
}); }

The above is a small series to introduce the Android development imitation salted fish Keyboard modified version, I hope to help you, if you have any questions please give me a message, small series will promptly reply to everyone. Here also thank you very much for the cloud Habitat Community website support!

Related Article

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.