11package cosine .boat .version3 ;
22
33import android .content .Context ;
4+ import android .content .Intent ;
45import android .graphics .drawable .GradientDrawable ;
6+ import android .text .method .Touch ;
57import android .util .Log ;
68import android .view .MotionEvent ;
79import android .os .Bundle ;
@@ -78,7 +80,7 @@ public class BoatClientActivity extends NativeActivity implements View.OnClickL
7880private HashMap <Object ,int []> layoutsPos ;
7981private CrossButton [] crosskeychildren ;
8082private int [] tempCrossKey ;
81- private CheckBox checkbox_qwertkeyboard ,checkbox_crosskey ,checkbox_mousekey ,checkbox_virtualkeyboard ,checkbox_otg ,checkbox_joystick ,checkbox_lock ;
83+ private CheckBox checkbox_qwertkeyboard ,checkbox_crosskey ,checkbox_mousekey ,checkbox_virtualkeyboard ,checkbox_otg ,checkbox_joystick ,checkbox_lock , checkbox_edittext ;
8284private CheckBox [] toolerBarChildren ;
8385private HorizontalScrollView SwitcherBar_container ;
8486private ImageButton SwitcherBar_switcher ;
@@ -90,6 +92,7 @@ public class BoatClientActivity extends NativeActivity implements View.OnClickL
9092private Button qwertkeyboard_move ;
9193private Button mousekey_move ;
9294private Button crosskey_move ;
95+ private HashMap <GameButton ,Boolean > autoKeep = new HashMap <GameButton ,Boolean >();
9396
9497private long TOUCH_DOWN_TIME ;
9598private long TOUCH_UP_TIME ;
@@ -373,7 +376,8 @@ public void InitWindowsAndScreenKeyboard(){
373376checkbox_joystick = SwitcherBar .findViewById (R .id .checkbox_Joystick );
374377checkbox_otg = SwitcherBar .findViewById (R .id .checkbox_Otg );
375378checkbox_lock = SwitcherBar .findViewById (R .id .checkbox_Lock );
376- toolerBarChildren = new CheckBox []{checkbox_qwertkeyboard ,checkbox_crosskey ,checkbox_mousekey ,checkbox_virtualkeyboard ,checkbox_otg ,checkbox_joystick ,checkbox_lock };
379+ checkbox_edittext = SwitcherBar .findViewById (R .id .checkbox_Edittext );
380+ toolerBarChildren = new CheckBox []{checkbox_qwertkeyboard ,checkbox_crosskey ,checkbox_mousekey ,checkbox_virtualkeyboard ,checkbox_otg ,checkbox_joystick ,checkbox_lock ,checkbox_edittext };
377381SwitcherBar_container = SwitcherBar .findViewById (R .id .switchbar_container );
378382SwitcherBar_switcher = SwitcherBar .findViewById (R .id .switchbar_switcher );
379383SwitcherBar_switcher .setOnTouchListener (this );
@@ -440,19 +444,19 @@ public void InitWindowsAndScreenKeyboard(){
440444 }
441445 }
442446
443- //设定CrossKey十字键的监听
444- for (int i = 0 ;i < ((LinearLayout )base .findViewById (R .id .CrossKey )).getChildCount ();i ++){
445- if (((LinearLayout )base .findViewById (R .id .CrossKey )).getChildAt (i ) instanceof Button ){
446- ((LinearLayout )base .findViewById (R .id .CrossKey )).getChildAt (i ).setOnTouchListener (this );
447- }else {
448- for (int a = 0 ;a < ((LinearLayout )((LinearLayout )base .findViewById (R .id .CrossKey )).getChildAt (i )).getChildCount ();a ++){
449- for (int b = 0 ;b < ((LinearLayout )(((LinearLayout )((LinearLayout )base .findViewById (R .id .CrossKey )).getChildAt (i )).getChildAt (a ))).getChildCount ();b ++){
450- ((LinearLayout )(((LinearLayout )((LinearLayout )base .findViewById (R .id .CrossKey )).getChildAt (i )).getChildAt (a ))).getChildAt (b ).setOnTouchListener (this );
451- ((LinearLayout )(((LinearLayout )((LinearLayout )base .findViewById (R .id .CrossKey )).getChildAt (i )).getChildAt (a ))).getChildAt (b ).getBackground ().setAlpha (100 );
452- }
453- }
454- }
455- }
447+ //设定CrossKey十字键的监听
448+ for (int i = 0 ;i < ((LinearLayout )base .findViewById (R .id .CrossKey )).getChildCount ();i ++){
449+ if (((LinearLayout )base .findViewById (R .id .CrossKey )).getChildAt (i ) instanceof Button ){
450+ ((LinearLayout )base .findViewById (R .id .CrossKey )).getChildAt (i ).setOnTouchListener (this );
451+ }else {
452+ for (int a = 0 ;a < ((LinearLayout )((LinearLayout )base .findViewById (R .id .CrossKey )).getChildAt (i )).getChildCount ();a ++){
453+ for (int b = 0 ;b < ((LinearLayout )(((LinearLayout )((LinearLayout )base .findViewById (R .id .CrossKey )).getChildAt (i )).getChildAt (a ))).getChildCount ();b ++){
454+ ((LinearLayout )(((LinearLayout )((LinearLayout )base .findViewById (R .id .CrossKey )).getChildAt (i )).getChildAt (a ))).getChildAt (b ).setOnTouchListener (this );
455+ ((LinearLayout )(((LinearLayout )((LinearLayout )base .findViewById (R .id .CrossKey )).getChildAt (i )).getChildAt (a ))).getChildAt (b ).getBackground ().setAlpha (150 );
456+ }
457+ }
458+ }
459+ }
456460
457461
458462 //显示布局到悬浮窗
@@ -538,18 +542,26 @@ public GameButton GetButtonFromModel(String KeyName, int KeySizeW,int KeySizeH,
538542 return KeyButton ;
539543 }
540544
541- public static float getPxFromDp (Context context , float dpValue ) {
542- final float scale = context .getResources ().getDisplayMetrics ().density ;
543- return (dpValue * scale );
544- }
545+ public static float getPxFromDp (Context context , float dpValue ) {
546+ final float scale = context .getResources ().getDisplayMetrics ().density ;
547+ return (float ) ( dpValue * scale + 0.5f );
548+ }
545549
546- public static float getDpFromPx (Context context , float pxValue ){
547- final float scale = context .getResources ().getDisplayMetrics ().density ;
548- return (pxValue / scale );
549- }
550+ public static float getDpFromPx (Context context , float pxValue ){
551+ final float scale = context .getResources ().getDisplayMetrics ().density ;
552+ return (( float ) (( pxValue - 0.5f )/ scale ))+ 1 ;
553+ }
550554
551555 private void OnTouchVirtualKeyboard (GameButton gameButton ,MotionEvent p2 ){
552556 if (p2 .getActionMasked () == MotionEvent .ACTION_DOWN ){
557+ if (gameButton .isKeep ()){
558+ if (autoKeep .containsKey (gameButton )){
559+ autoKeep .remove (gameButton );
560+ return ;
561+ }else {
562+ autoKeep .put (gameButton ,true );
563+ }
564+ }
553565 if (gameButton .isMult ()){
554566 Log .e ("VirtualKey-Mult" ,"KeyName: " + gameButton .getKeyMain () + " " + gameButton .getSpecialOne () + " " + gameButton .getSpecialTwo () +" KeyIndex: " + gameButton .getMainIndex () + " " + gameButton .getSpecialOneIndex () + " " + gameButton .getSpecialTwoIndex () + " Status: " + "pressed" );
555567 BoatInputEventSender .setKey (gameButton .getMainIndex (), true , 0 );
@@ -651,7 +663,7 @@ private void OnTouchCrossKey(View p1,MotionEvent p2){
651663 Log .e ("OnTouchCrossKey" ,"Release Index: " +temp );
652664 BoatInputEventSender .setKey (temp ,false ,0 );
653665
654- //TODO: 时序
666+ //时序
655667 try {
656668 Thread .sleep (0 );
657669 } catch (InterruptedException e ) {
@@ -881,7 +893,7 @@ private void SendDownOrUpToInput(int[] recordKeys,int[] downKeys,int mode){
881893 Log .e ("DnOrUpInput" , "Catch Index: " + temp );
882894 BoatInputEventSender .setKey (temp , true , 0 );
883895
884- //TODO: 时序
896+ //时序
885897 try {
886898 Thread .sleep (0 );
887899 } catch (InterruptedException e ) {
@@ -897,7 +909,7 @@ private void SendDownOrUpToInput(int[] recordKeys,int[] downKeys,int mode){
897909 Log .e ("DnOrUpInput" ,"Release Index: " +temp );
898910 BoatInputEventSender .setKey (temp ,false ,0 );
899911
900- //TODO: 时序
912+ //时序
901913 try {
902914 Thread .sleep (0 );
903915 } catch (InterruptedException e ) {
@@ -970,6 +982,12 @@ public void onCheckedChanged(CompoundButton v,boolean ischecked){
970982mousekey_move .setVisibility (View .INVISIBLE );
971983crosskey_move .setVisibility (View .INVISIBLE );
972984}
985+ }else if (v == checkbox_edittext ){
986+ if (ischecked ){
987+ inputScanner .setVisibility (View .VISIBLE );
988+ }else {
989+ inputScanner .setVisibility (View .INVISIBLE );
990+ }
973991}
974992}
975993};
@@ -1000,7 +1018,7 @@ public void onFinish() {
10001018Log .e ("JoyStick" ,"Release Index " + temp );
10011019BoatInputEventSender .setKey (temp ,false ,0 );
10021020
1003- //TODO: 时序
1021+ //时序
10041022 try {
10051023 Thread .sleep (0 );
10061024 } catch (InterruptedException e ) {
@@ -1060,37 +1078,9 @@ private void OnClickTouchPad(MotionEvent p1){
10601078 //捕获模式
10611079 switch (p1 .getAction ()){
10621080 case MotionEvent .ACTION_DOWN :
1063- /*TOUCH_DOWN_TIME = p1.getDownTime();
1064- if(layoutsPos.containsKey(touchpad)){
1065- layoutsPos.remove(touchpad);
1066- layoutsPos.put(touchpad,new int[] {(int) p1.getRawX(),(int) p1.getRawY()});
1067- }else{
1068- layoutsPos.put(touchpad,new int[] {(int) p1.getRawX(),(int) p1.getRawY()});
1069- }*/
10701081 break ;
10711082 case MotionEvent .ACTION_MOVE :
10721083 TOUCH_IS_MOVED = true ;
1073- //int[] temp = layoutsPos.get(touchpad);
1074- /*if(!TOUCH_LONG_APPLY && !TOUCH_IS_OUTLIMITION) {
1075- if (Math.abs(temp[0] - p1.getRawX()) >= MAX_MOVE_LIMITION && Math.abs(temp[1] - p1.getRawY()) >= MAX_MOVE_LIMITION) {
1076- Log.e("Location","X轴偏移: " + Math.abs(temp[0] - p1.getRawX()) + " Y轴偏移: " + Math.abs(temp[1] - p1.getRawY()));
1077- Log.e("Screen","触摸位置超出限制!");
1078- TOUCH_IS_OUTLIMITION = true;
1079- } else {
1080- Log.e("Location","X轴偏移: " + Math.abs(temp[0] - p1.getRawX()) + " Y轴偏移: " + Math.abs(temp[1] - p1.getRawY()));
1081- Log.e("Screen","触摸位置未超出限制!");
1082- TOUCH_IS_OUTLIMITION = false;
1083- }
1084- if(p1.getEventTime() - TOUCH_DOWN_TIME > MAX_CLICK_TIME){
1085- Log.e("Screen","触摸达到长按阀值!");
1086- TOUCH_IS_LONGCLICK = true;
1087- }
1088- if(TOUCH_IS_LONGCLICK && !TOUCH_IS_OUTLIMITION){
1089- Log.e("Screen","长按事件被激活!");
1090- //mInputEventSender.setMouseButton((byte)1,true);
1091- TOUCH_LONG_APPLY = true;
1092- }
1093- }*/
10941084 break ;
10951085 case MotionEvent .ACTION_UP :
10961086 //TOUCH_UP_TIME = p1.getEventTime();
0 commit comments