Advertisement
Guest User

Untitled

a guest
Jan 18th, 2018
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 4.58 KB | None | 0 0
  1.     {
  2.             @Override
  3.             public void onGlobalLayout()
  4.             {
  5.                 Log.debug("VK: onGlobalLayout " + bKeyboardShowing);
  6.  
  7.                 //String fullStackTrace = org.apache.commons.lang.exception.ExceptionUtils.getFullStackTrace(e);
  8.                 String fullStackTrace = buildStackTraceString(Thread.currentThread().getStackTrace());
  9.                 Log.debug("VK: stack: " + fullStackTrace);
  10.  
  11.                 if( bKeyboardShowing )
  12.                 {
  13.                     Rect visibleRect = new Rect();
  14.                     View visibleView = mainView.getRootView();
  15.  
  16.                     visibleView.getWindowVisibleDisplayFrame( visibleRect );
  17.  
  18.                     mainDecorView.getDrawingRect( mainDecorViewRect );
  19.  
  20.                     Log.debug("VK: onGlobalLayout visibleRect:(" +  visibleRect.left + ", " + visibleRect.top +", " + visibleRect.right +", " + visibleRect.bottom +")"+
  21.                             ", mainDecorViewRect:" +  mainDecorViewRect.left + ", " + mainDecorViewRect.top +", " + mainDecorViewRect.right +", " + mainDecorViewRect.bottom + ")" );
  22.  
  23.                     // determine which side of the screen the keyboard is covering
  24.                     int leftDiff = Math.abs( mainDecorViewRect.left - visibleRect.left );
  25.                     int topDiff = Math.abs( mainDecorViewRect.top - visibleRect.top );
  26.                     int rightDiff = Math.abs( mainDecorViewRect.right - visibleRect.right );
  27.                     int bottomDiff = Math.abs( mainDecorViewRect.bottom - visibleRect.bottom );
  28.  
  29.                     // Rect covered by the virtual keyboard
  30.                     Rect keyboardRect = new Rect();
  31.                     keyboardRect.left = ( rightDiff > 0 ) ? visibleRect.right : mainDecorViewRect.left; // keyboard is on the right
  32.                     keyboardRect.top = ( bottomDiff > 0 ) ? visibleRect.bottom : mainDecorViewRect.top; // keyboard is on the bottom
  33.                     keyboardRect.right = ( leftDiff > 0 ) ? visibleRect.left : mainDecorViewRect.right; // keyboard is on the left
  34.                     keyboardRect.bottom = ( topDiff > 0 ) ? visibleRect.top : mainDecorViewRect.bottom; // keyboard is on the top
  35.  
  36.                     //keyboard Y coord
  37.                     int keyboardYPos = visibleRect.bottom - newVirtualKeyboardInput.getHeight();
  38.  
  39.                     //avoid negative coords if the keyboard is shown on top of the screen
  40.                     if(keyboardYPos < 0)
  41.                         keyboardYPos = visibleRect.top + newVirtualKeyboardInput.getHeight();
  42.  
  43.                     int visibleScreenYOffset = Math.max(bottomDiff, topDiff);
  44.  
  45.                     nativeVirtualKeyboardShown( keyboardRect.left, keyboardRect.top, keyboardRect.right, keyboardRect.bottom );
  46.                     Log.debug("VK: show?" + visibleScreenYOffset + "," + newVirtualKeyboardInput.getY());
  47.                     if(visibleScreenYOffset > 200)
  48.                     {
  49.                         Log.debug("VK: show");
  50.                         //newVirtualKeyboardInput.setBackgroundColor(Color.WHITE);
  51.                         //newVirtualKeyboardInput.setCursorVisible(true);
  52.                         newVirtualKeyboardInput.setY(keyboardYPos);
  53.                         newVirtualKeyboardInput.setVisibility(View.VISIBLE);
  54.                         newVirtualKeyboardInput.requestFocus();
  55.  
  56.                         bNeedShowKeyboard = false;
  57.                     }
  58.                     else if(newVirtualKeyboardInput.getY() > 0)
  59.                     {
  60.                         Log.debug("VK: hide");
  61.                         newVirtualKeyboardInput.setVisibility(View.GONE);
  62.                         //set offscreen
  63.                         newVirtualKeyboardInput.setY(-1000);
  64.                     }
  65.                     else if( bNeedShowKeyboard )
  66.                     {
  67.                         Log.debug("VK: request");
  68.                         mainView.requestLayout();
  69.                     }
  70.  
  71.                     //                    else
  72.                     //                    {
  73.                     //                        Log.debug("VK: show");
  74.                     //                      //newVirtualKeyboardInput.setBackgroundColor(Color.WHITE);
  75.                     //                      //newVirtualKeyboardInput.setCursorVisible(true);
  76.                     //                      newVirtualKeyboardInput.setY(keyboardYPos);
  77.                     //                      newVirtualKeyboardInput.setVisibility(View.VISIBLE);
  78.                     //                      newVirtualKeyboardInput.requestFocus();  
  79.                     //                    }
  80.                 }
  81.             }
  82.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement