Run android keyboard

edited October 2015 in Android Mode

Good afternoon,

I'm designing an android app and do not know how I can use the virtual keyboard.

Is there a way to call android keyboard while the application is running? or Should I create a keyboard on my own?

Thanks in advance

Anthony20

Answers

  • edited June 2014 Answer ✓

    Processing doesn't behave like a native text-editable view, so Android won't show the keyboard unless it is specifically asked to. You can force the keyboard to show and hide, but you'll still have to handle key presses yourself (in the same way as Java mode):

    //We need this at the top of the sketch
    import android.view.inputmethod.InputMethodManager;
    
    //Call this to show the keyboard
    InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
    imm.toggleSoftInput(InputMethodManager.SHOW_FORCED, 0);
    
    //Call this to hide the keyboard
    InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
    imm.toggleSoftInput(InputMethodManager.HIDE_IMPLICIT_ONLY, 0);
    
  • edited June 2014

    Thanks so much, Calsing:

    is also necessary to import (import android.content.Context;)

    import android.view.inputmethod.InputMethodManager;
    import android.content.Context;
    
    
     void showVirtualKeyboard() 
    {
      InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
      imm.toggleSoftInput(InputMethodManager.SHOW_FORCED, 0);
    
    }
     void hideVirtualKeyboard() 
    {
      InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
      imm.toggleSoftInput(InputMethodManager.HIDE_IMPLICIT_ONLY, 0);
    }
    

    Thank you very much for helping to solve my problem.

    Anthony20

  • Answer ✓

    How the keyboard view toggles if I use only hideVirtualKeyboard()? firstrun, keyboard comes up, next run keyboard hides and so on

  • You you should be able to control this with a variable locking and a conditional with mousePressed

    if( x = 0 && mousePressed == true){x = 1; hideVirtualKeyboard(); }
    if( x = 1  && mousePressed == false){x = 2;}
    if( x = 2 && mousePressed == true){x = 3; showVirtualKeyboard(); }
    if( x = 3  && mousePressed == false){x = 0;}
    
  • Answer ✓

    This idea with a variable doesn't work if the keyboard is hide with the device back button or is shown by selecting a edit text field.

  • Answer ✓

    The base problem is that the function hideVirtualKeyboard is also show the keyboard if it was hidden. If this function ONLY hides the keyboard then there where no problem.

    Is there a way to get the status of the soft keyboard? If it is visible or hidden? This can solve the problem.

  • Is there a way to get the status of the soft keyboard? If it is visible or hidden? This can solve the problem.

    I also want to know that :D

  • Answer ✓

    At this time I have not found a solution.

  • @klsc Hi, I found an effective way to close the keyboard, I think that can help you: imm.hideSoftInputFromWindow(getWindow().getDecorView().getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS);

    Regards

    Anthony20

  • Answer ✓

    Thank you anthony, I will test it in future. At this time I don't work on this project. but I will remind me if I need it.

    at this time I have problems with starting processing 3.0 :(

  • i am getting an error while running this code on my Samsung galaxy s5 neo, the bootloader says "the function getsystem(string) does not exist, how do I solve this?

  • Can you post what code you are referring to? Please also add what Procession version and OS that you are suing.

    Kf

  • @electrosquid===

    i think that this code is for P2, not for P3.

  • edited February 2017

    @electrosquid

    Here's some new code for Android Mode 3.0 based on Ketai's keyboard implementation:

    void toggleSoftKeyboard() {
      android.view.inputmethod.InputMethodManager imm = (android.view.inputmethod.InputMethodManager) getActivity().getSystemService(android.content.Context.INPUT_METHOD_SERVICE);
      imm.toggleSoftInput(0, 0);
    }
    
    void showSoftKeyboard() {
      android.view.inputmethod.InputMethodManager imm = (android.view.inputmethod.InputMethodManager) getActivity().getSystemService(android.content.Context.INPUT_METHOD_SERVICE);
      imm.showSoftInput(getActivity().getCurrentFocus(), 0);
    }
    
    void hideSoftKeyboard() {
      android.view.inputmethod.InputMethodManager imm = (android.view.inputmethod.InputMethodManager) getActivity().getSystemService(android.content.Context.INPUT_METHOD_SERVICE);
      imm.hideSoftInputFromWindow(getActivity().getCurrentFocus().getWindowToken(), 0);
    }
    
  • @calsign===

    it seems to me that this code is what ketai is wrapping(knowing that we are in fragment)... if you are using ketai you write only:

        boolean s = false;
    
        void mouseReleased(){
          if(!s){
            s= true;
              KetaiKeyboard.show(this);
          }else{
           s= false; 
           KetaiKeyboard.hide(this);
          }
        }
    
Sign In or Register to comment.