Import Android. content. context;
Import Android. Graphics. Canvas;
Import Android. Graphics. color;
Import Android. Graphics. paint;
Import Android. Graphics. typeface;
Import Android. util. attributeset;
Import Android. View. motionevent;
Import Android. View. view;
Public class rightletterview extends view {
String [] letters = {"A", "B", "C", "D", "E", "F", "g", "H ", "I", "J", "K ",
"L", "M", "n", "O", "P", "Q", "r", "S", "T", "U ", "V", "W", "X ",
"Y", "Z "};
Paint paint = new paint ();
Ontouchingletterchangedlistener;
Boolean showbkg = false;
Int choose =-1;
Int letterslength;
Public rightletterview (context ){
Super (context );
}
Public rightletterview (context arg0, attributeset arg1, int arg2 ){
Super (arg0, arg1, arg2 );
}
Public rightletterview (context, attributeset attrs ){
Super (context, attrs );
}
@ Override
Protected void onattachedtowindow (){
// Todo auto-generated method stub
Super. onattachedtowindow ();
Letterslength = letters. length;
}
@ Override
Protected void ondraw (canvas ){
Super. ondraw (canvas );
If (showbkg ){
Canvas. drawcolor (color. parsecolor ("#10000000 "));//
Clear and black background
}
Int Height = getheight ();
Int width = getwidth ();
Int singleheight = height/letterslength;
For (INT I = 0; I <letterslength; I ++ ){
Paint. setcolor (color. Black );
Paint. settypeface (typeface. default_bold );
Paint. setantialias (true );//
Smooth
Paint. settextsize (50366f );
If (I = choose ){
Paint. setcolor (color. parsecolor ("# 3399ff "));
Paint. setfakeboldtext (true );
}
Float xpos = width/2-paint. measuretext (letters [I])/2;
Float ypos = singleheight * (I + 1 );
Canvas. drawtext (letters [I], xpos, ypos, paint );
Paint. Reset ();
}
}
@ Override
Public Boolean dispatchtouchevent (motionevent event ){
Final int action = event. getaction ();
Final float y = event. Gety ();
Final int oldchoose = choose;
Final ontouchingletterchangedlistener listener = ontouchingletterchangedlistener;
Final int c = (INT) (y/getheight () * letterslength );
Switch (Action ){
Case motionevent. action_down:
Showbkg = true;
If (oldchoose! = C & listener! = NULL ){
If (C> 0 & C <= letterslength ){
Listener. ontouchingletterchanged (letters [c]);
Choose = C;
Invalidate ();
}
}
Break;
Case motionevent. action_move:
If (oldchoose! = C & listener! = NULL ){
If (C> 0 & C <= letterslength ){
Listener. ontouchingletterchanged (letters [c]);
Choose = C;
Invalidate ();
}
}
Break;
Case motionevent. action_up:
Showbkg = false;
Choose =-1;
Invalidate ();
Break;
Default:
Break;
}
Return true;
}
@ Override
Public Boolean ontouchevent (motionevent arg0 ){
Return super. ontouchevent (arg0 );
}
Public void setontouchingletterchangedlistener (
Ontouchingletterchangedlistener ){
This. ontouchingletterchangedlistener = ontouchingletterchangedlistener;
}
Public interface ontouchingletterchangedlistener {
Public void ontouchingletterchanged (string S );
}
Public void setletters (string [] letters ){
This. Letters = letters;
}
}