Create a custom keypad in android -


i want create custom keypad in android app looks this:

https://www.dropbox.com/s/vwiz4o3pd8q4o81/2015-06-14%2014.53.02.jpg?dl=0

i have tried use keyboardview cannot want. have looked @ tutorials online on custom keypads none seems give hints on how make keypad desire. have tried putting png images backgrounds keypad has not helped. far have made this:

https://www.dropbox.com/s/xrm4v941ofecmut/2015-06-14%2014.54.10.jpg?dl=0

can or links tutorials , code solve problem.

this current code:

<?xml version="1.0" encoding="utf-8"?> <keyboard xmlns:android="http://schemas.android.com/apk/res/android"     android:keywidth="14.25%p"     android:hapticfeedbackenabled="true"     android:keyheight="8.5%p"> <!--     android:horizontalgap="0.50%p"     android:verticalgap="0.50%p"     note when add horizontalgap in pixels, interferes keywidth in percentages adding 100%     note when have horizontalgap (on keyboard level) of 0, make horizontalgap (on key level) move after key before key... (i consider bug)   -->     <row>             <key android:codes="-1"     android:keylabel="evaluate" android:keywidth="42.75%p"  android:keyedgeflags="left"   />             <key android:codes="-100"     android:keylabel="reset" android:keywidth="28.50%p"     />             <key android:codes="-1000"     android:keylabel="\u24d8" android:keywidth="28.50%p"    android:keyedgeflags="right"  />     </row>       <row>         <key android:codes="1"      android:keylabel="sin"     android:keyedgeflags="left" />         <key android:codes="2"      android:keylabel="cos"  />         <key android:codes="3"      android:keylabel="tan"  />         <key android:codes="36"     android:keylabel="sinh"        />         <key android:codes="37"     android:keylabel="cosh"     />         <key android:codes="38"     android:keylabel="tanh"   />         <key android:codes="-2"     android:keyicon="@drawable/delete_symbol"        android:isrepeatable="true"     android:keyedgeflags="right"/>     </row>         <row>         <key android:codes="4"      android:keylabel="asin"      android:keyedgeflags="left" />         <key android:codes="5"      android:keylabel="acos"    />         <key android:codes="6"      android:keylabel="atan"  />         <key android:codes="42"     android:keylabel="asinh"        />         <key android:codes="43"     android:keylabel="acosh"     />         <key android:codes="44"     android:keylabel="atanh"   />         <key android:codes="21"     android:keylabel="\u00f7"   android:keyedgeflags="right" />        </row>     <row>         <key android:codes="7"      android:keylabel="cosec"       android:keyedgeflags="left" />         <key android:codes="8"      android:keylabel="sec"      />         <key android:codes="9"      android:keylabel="cot"      />         <key android:codes="33"     android:keylabel="7"        />         <key android:codes="34"     android:keylabel="8"       />         <key android:codes="35"     android:keylabel="9"      />         <key android:codes="20"     android:keylabel="\u00d7"    android:keyedgeflags="right" />        </row>     <row>         <key android:codes="11"     android:keylabel="e^("    />         <key android:codes="12"     android:keylabel="ln("   />         <key android:codes="22"     android:keylabel="x\u207f" />         <key android:codes="30"     android:keylabel="4"       />         <key android:codes="31"     android:keylabel="5"        />         <key android:codes="32"     android:keylabel="6"     />         <key android:codes="19"     android:keylabel="\u2212"   android:keyedgeflags="right" />     </row>     <row>         <key android:codes="14"     android:keylabel="k"        android:keyedgeflags="left" />         <key android:codes="15"     android:keylabel="\u03c0"  />         <key android:codes="13"     android:keyicon="@drawable/italic_x"  />         <key android:codes="27"     android:keylabel="1"         />         <key android:codes="28"     android:keylabel="2"        />         <key android:codes="29"     android:keylabel="3"      />         <key android:codes="18"     android:keylabel="+"     android:keyedgeflags="right" />     </row>     <row>         <key android:codes="-3"     android:keyicon="@drawable/keyboard_done"  android:keywidth="28.5%p" android:keyedgeflags="left"   />            <key android:codes="10"     android:keylabel="\u221a"  />         <key android:codes="16"     android:keylabel="("         />         <key android:codes="26"     android:keylabel="0"      />         <key android:codes="17"     android:keylabel=")"   />           <key android:codes="23"     android:keylabel="." android:keyedgeflags="right" />     </row>  </keyboard> 

the code java handler xml file is:

class customkeyboard {  private activity  mhostactivity;  private button donebutton = null; private button clearbutton = null; private button infobutton = null;  /** key (code) handler. */ private onkeyboardactionlistener monkeyboardactionlistener = new onkeyboardactionlistener() {  public final static int codeevaluate  = -1; public final static int codeclear  = -100; public final static int codeinfo  = -1000; public final static int codedelete    = -2; // keyboard.keycode_delete public final static int codehide      = -3; // keyboard.keycode_cancel  public final static int codeminimum   = 0; public final static int codesin       = 1; public final static int codecos       = 2; public final static int codetan       = 3; public final static int codeasin      = 4; public final static int codeacos      = 5; public final static int codeatan      = 6; public final static int codecosec     = 7; public final static int codesec       = 8; public final static int codecot       = 9; public final static int codesqrt      = 10; public final static int codeexp       = 11; public final static int codeln        = 12; public final static int codex         = 13; public final static int codek         = 14; public final static int codepi        = 15; public final static int codeopenb     = 16; public final static int codecloseb    = 17; public final static int codeplus      = 18; public final static int codeminus     = 19; public final static int codemultiply  = 20; public final static int codedivide    = 21; public final static int codepower     = 22; public final static int codepoint     = 23; public final static int codeabc       = 24; public final static int codespace     = 25;  public final static int codemaximum   = 50;   // maximum number of keys  public string[] keycodetotext = null;  public void keysinitialise() { if(keycodetotext==null) keycodetotext = new string[codemaximum]; keycodetotext[codesin]      = "sin("; keycodetotext[codecos]      = "cos("; keycodetotext[codetan]      = "tan("; keycodetotext[codeasin]     = "asin("; keycodetotext[codeacos]     = "acos("; keycodetotext[codeatan]     = "atan("; keycodetotext[codecosec]    = "cosec("; keycodetotext[codesec]      = "sec("; keycodetotext[codecot]      = "cot("; keycodetotext[codesqrt]     = "sqrt("; keycodetotext[codeexp]      = "e^("; keycodetotext[codeln]       = "ln("; keycodetotext[codex]        = "x"; keycodetotext[codek]        = "k"; keycodetotext[codepi]       = "pi"; keycodetotext[codeopenb]    = "("; keycodetotext[codecloseb]   = ")"; keycodetotext[codeplus]     = "+"; keycodetotext[codeminus]    = "-"; keycodetotext[codemultiply] = "*"; keycodetotext[codedivide]   = "/"; keycodetotext[codepower]    = "^"; keycodetotext[codepoint]    = "."; keycodetotext[codeabc  ]    = ""; }   @override  public void onkey(int primarycode, int[] keycodes) {  // edittext , editable view focuscurrent = mhostactivity.getwindow().getcurrentfocus(); if( focuscurrent==null || focuscurrent.getclass()!=edittext.class )    return;  edittext edittext = (edittext) focuscurrent; editable editable = edittext.gettext(); int start = edittext.getselectionstart();  keysinitialise();  // apply key edittext if(primarycode == codeevaluate) { if(donebutton != null) donebutton.performclick(); } else if (primarycode == codeclear){ if(clearbutton != null) clearbutton.performclick(); } else if (primarycode == codeinfo){ if(infobutton != null) infobutton.performclick(); } else if(primarycode ==codedelete) { if( editable!=null && start>0 ) editable.delete(start - 1, start); } else if(primarycode == codehide) { hidecustomkeyboard(); } else if(primarycode > codeminimum && primarycode < codemaximum) { editable.insert(start, keycodetotext[primarycode]); } else editable.insert(start, integer.tostring(primarycode)); }  @override public void onpress(int arg0) { }  @override public void onrelease(int primarycode) { }  @override public void ontext(charsequence text) { }  public customkeyboard(activity host, int viewid, int layoutid) { mhostactivity= host; mkeyboardview= (keyboardview)mhostactivity.findviewbyid(viewid); mkeyboardview.setkeyboard(new keyboard(mhostactivity, layoutid)); mkeyboardview.setpreviewenabled(false); // note not show preview balloons mkeyboardview.setonkeyboardactionlistener(monkeyboardactionlistener); }  /** returns whether customkeyboard visible. */ public boolean iscustomkeyboardvisible() {     return mkeyboardview.getvisibility() == view.visible; }  /** make customkeyboard visible, , hide system keyboard given view. */ public void showcustomkeyboard(view v) { mkeyboardview.setvisibility(view.visible); mkeyboardview.setenabled(true); }  /** make customkeyboard invisible. */ public void hidecustomkeyboard() { mkeyboardview.setvisibility(view.gone); mkeyboardview.setenabled(false); }  /** hide standard keyboard */ private void hidestandardkeyboard(view v) {     if(v != null) ((inputmethodmanager)mhostactivity.getsystemservice(activity.input_method_service)).hidesoftinputfromwindow(v.getwindowtoken(), 0); }  /** register donebutton donebutton.performclick()  *  called when "done" keypad-button clicked.  */ public void registerdonebutton (button donebutton) { this.donebutton = donebutton; } public void registerclearbutton (button clearbutton) { this.clearbutton = clearbutton; } public void registerinfobutton (button infobutton) { this.infobutton = infobutton; } /** * register <var>edittext<var> using custom keyboard. * * @param edittext registers custom keyboard. */ public void registeredittext(edittext edittext) {  // make custom keyboard appear or disappear edittext.setonfocuschangelistener(new onfocuschangelistener() { @override public void onfocuschange(view v, boolean hasfocus) { if(hasfocus) showcustomkeyboard(v); else hidecustomkeyboard(); } });  edittext.setonclicklistener(new onclicklistener() { @override public void onclick(view v) { showcustomkeyboard(v); } });  edittext.setontouchlistener(new ontouchlistener() { @override public boolean ontouch(view v, motionevent event) { ((edittext) v).ontouchevent(event); hidestandardkeyboard(v); return true; // consume touch event } }); } 

since have layout xml of keyboard, make keyboard equals 1 presented in first image. should have background of key view , add every key.


Comments

Popular posts from this blog

c# - Validate object ID from GET to POST -

node.js - Custom Model Validator SailsJS -

php - Find a regex to take part of Email -