Android Softinput Related

Source: Internet
Author: User
Tags bit set

GetWindow (). Setsoftinputmode (WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN
| WindowManager.LayoutParams.SOFT_INPUT_ADJUST_UNSPECIFIED) where parameters can be adjusted according to individual needs, the parameters are as follows:
"A" stateunspecified: the state of the soft keyboard is not specified and the system will select an appropriate state or a theme-dependent setting
"B" stateunchanged: When this activity appears, the soft keyboard will remain in the previous activity, whether it is hidden or displayed
"C" Statehidden: When the user chooses activity, the soft keyboard is always hidden
"D" Statealwayshidden: When the Activity main window gets the focus, the soft keyboard is always hidden
"E" statevisible: Soft keyboard is usually visible
"F" statealwaysvisible: The state that the soft keyboard always displays when the user chooses activity
"G" adjustunspecified: The default setting, which is usually determined by the system to hide or show itself
"H" adjustresize: The activity always adjusts the size of the screen to allow space for the soft keyboard
"I" Adjustpan: The contents of the current window will automatically move so that the current focus is never covered by the keyboard and the user can always see the part of the input!

Body

First, the structure

Public final class Inputmethodmanager extends Object

Java.lang.Object

Android.view.inputmethod.InputMethodManager


Ii. Overview of the class

The core API for the entire Input method framework (IMF) architecture, which schedules and interacts with the current input methods between applications. You can use Context.getsystemservice () to get an instance of this interface.

Architecture Overview (Architecture Overview)

The Input Method framework (IMF) consists of three main parts:

* Input Method Manager, manage the interaction of each part. It is a client-side API that exists in the context of each application and is used to communicate global system services that manage interactions across all processes.

* Input Method (IME) to implement a separate interactive module that allows the user to generate text. The system binds a current input method. Make it create and build, determine when the input method hides or displays its UI. Only one IME can run at a time.

* Customer application that controls the input focus and IME status through the Input method manager. Only one client can use the IME at a time.

Applications (applications)

In most cases, an application that uses standard TextView or its subclasses can make the soft keyboard (soft input methods) work as long as it does a small amount of work. What you should pay attention to is:

* Set your editable text view InputType correctly so that the IME has enough context to help users enter text into it.

* Handle hidden screen space properly when input method is displayed. Ideally the application should handle the window to be smaller, if necessary you can take advantage of the system to perform the panning window. You should set the Windowsoftinputmode property in the activity or adjust the corresponding value of the Create window so that the system decides to pan or zoom (it will try to auto-Adjust but possibly error).

* You can also control the window's preferred soft keyboard status via the same Windowsoftinputmode (open, close, etc.).

Through the API can interact with the IMF and its IME to achieve more granular control, such as display or input area, the user selects an input method and so on.

When you write your own text editor, you implement Oncreateinputconnection (Editorinfo) to return your Inputconnection interface instance, which allows the IME to interact with your text editing domain.

Input Method (Methods)

An Input Method (IME) is an implementation of a service, usually inherited from Inputmethodservice. The IME provides the core Inputmethod interface, although providing inputmethod is usually handled by Inputmethodservice, and the IME implementation only needs to handle higher-level APIs.

See Inputmethodservice for more information.

Safety (Security)

Input methods are related to many security issues, because they basically drive the UI and monitor user input in a fundamentally unconstrained manner. The Android IME Framework also allows third-party IMEs to be dispatched, and must be careful to limit their choice and interaction.

Here are the key points behind the IMF security architecture:

* Only allow system access to the Inputmethod interface with Bind_input_method permission to access the IME. This is enforced by binding to a service that requires this permission. So the system can guarantee that no untrusted client is accessing the current input method outside of its control.

* There may be many client processes in the IMF, but only one is active at the same time. Inactive clients cannot interact with the IMF core through the following mechanisms.

* IME client only has access to the Inputmethodsession interface. Each client creates an interface instance, and only the call to the session associated with the active customer is processed by the IME. This is done through the abstractinputmethodservice of the ordinary IME, which must be handled explicitly by the IME, and the IME is the custom implementation of Inputmethodsession.

* Only active inputconnection accept the operation. The IMF notifies each client that the process is active and the IMF ignores the call of the inactive process to the current input join. This ensures that the current IME only delivers events and text edits to the UI for the user's visible focus.

* An IME can never interact with inputconnection when the screen is closed. This is done by invalidating all clients when the screen is turned off, and by preventing bad IMEs from driving the UI when the user cannot focus on their behavior.

* The customer application can ask the system to pick a new IME, but not one of the programmatic choices. This is to avoid malicious programs that select their own IME and keep running when the user navigates to another application. That is, the IME can programmatically require the system to select a different IME because it has full control over user input.

Before a user can switch to a new IME, it must be explicitly enabled to confirm that the system is aware of it and that it is in a usable state.

Three, constant

public static final int hide_implicit_only

A flag in Hidesoftinputfromwindow (ibinder, int) that indicates that the window is hidden if the user does not explicitly display the soft-keyboard window.

Constant value: 1 (0x00000001)

public static final int hide_not_always

A flag in Hidesoftinputfromwindow (ibinder, int) that indicates that the Soft keyboard window is always hidden, unless it starts with a show_forced display.

Constant value: 2 (0x00000002)

public static final int Result_hidden

Showsoftinput (View, int, resultreceiver) and Hidesoftinputfromwindow (ibinder, int, resultreceiver) Resultreceiver result code flag: The soft keyboard window transitions from display to hidden state.

Constant value: 3 (0x00000003)

public static final int Result_shown

Showsoftinput (View, int, resultreceiver) and Hidesoftinputfromwindow (ibinder, int, resultreceiver) Resultreceiver result code flag: Soft Keyboard window switches from hidden to displayed state.

Constant value: 2 (0x00000002)

public static final int Result_unchanged_hidden

Showsoftinput (View, int, resultreceiver) and Hidesoftinputfromwindow (ibinder, int, resultreceiver) Resultreceiver result code flag: The soft keyboard window remains hidden when it is not changed.

Constant value: 1 (0x00000001)

public static final int Result_unchanged_shown

Showsoftinput (View, int, resultreceiver) and Hidesoftinputfromwindow (ibinder, int, resultreceiver) Resultreceiver result code flag: The soft keyboard window remains in the state when it is displayed.

Constant value: 0 (0x00000000)

public static final int show_forced

The Showsoftinput (View, int) flag, which means that the user forces the input method to open (such as long press the menu key) and remains open until it is explicitly closed.

Constant value: 2 (0x00000002)

public static final int show_implicit

The Showsoftinput (View, int) flag, which indicates that an input window is implicitly displayed, is not directly required by the user. The window may not be displayed.

Constant value: 1 (0x00000001)

Iv. Public methods

public void displaycompletions (view view, completioninfo[] completions)

(Translator Note: Input method automatically completed)

Public Inputmethodsubtype Getcurrentinputmethodsubtype ()

(Translator Note: Get the current Input method type?) )

Public list<inputmethodinfo> getenabledinputmethodlist ()

(Translator Note: Get an enabled IME list?) )

Public list<inputmethodsubtype> getenabledinputmethodsubtypelist (Inputmethodinfo IMI, Boolean Allowsimplicitlyselectedsubtypes)

Public list<inputmethodinfo> getinputmethodlist ()

(Translator Note: Get Input Method list)

Public Map<inputmethodinfo, list<inputmethodsubtype>> getshortcutinputmethodsandsubtypes ()

public void Hidesoftinputfrominputmethod (IBinder token, int flags)

Close/Hide the Input Method soft keyboard area, which the user no longer sees or interacts with. Can only be called by the currently active input method, as required token (tokens) authentication.

Parameters

Tokens provide token validation when the input method is started, and can be manipulated after validation.

Flags provides additional operational flags. The current can be set to 0 or hide_implicit_only, hide_not_always, and so on.

public boolean Hidesoftinputfromwindow (IBinder windowtoken, int flags)

Hidesoftinputfromwindow (ibinder, int, resultreceiver) no return value version: Determines the currently received input window from the window context and hides its Input method window

Parameters

The Windowtoken is requested by the window View.getwindowtoken () to return the resulting token (token).

Flags provides additional operational flags. The current can be set to 0 or hide_implicit_only bits.

public boolean Hidesoftinputfromwindow (IBinder windowtoken, int flags, Resultreceiver resultreceiver)

The window that is currently receiving input is determined from the window context, requiring that its soft keyboard window be hidden. It can be called by the user and get results rather than explicitly requiring the IME window to be hidden.

Parameters

The Windowtoken is requested by the window View.getwindowtoken () to return the resulting token (token).

Flags provides additional operational flags. The current can be set to 0 or hide_implicit_only bits.

Resultreceiver is called when the IME processing request tells you to complete if it is not empty. The result code you receive can be Result_unchanged_shown, Result_unchanged_hidden, Result_shown, or Result_hidden.

public void Hidestatusicon (IBinder imetoken)

(Translator Note: Hide the status bar icon?) )

public boolean Isacceptingtext ()

The current service view accepts full-text editing returns true. No input method joins are false, at which point they can only handle the original key event.

public Boolean isActive (view view)

Returns True when the view is the active view of the current input.

public boolean isActive ()

Returns True when any view in the input method is activated.

public boolean Isfullscreenmode ()

Determines whether the relevant input method runs in full-screen mode. When full screen, completely overwrite your UI, return True, otherwise return false.

public Boolean iswatchingcursor (view view)

Returns true if the current input method wants to see the input Editor's cursor position.

public void Restartinput (view view)

If an input method is joined to the view, restart the input to display the new content. This method can be called when the text of the view causes the input method appearance to change or has a key input stream, such as when the application calls Textview.settext ().

Parameters

View text that has changed.

public void Sendappprivatecommand (view view, String action, Bundle data)

Call Inputmethodsession.appprivatecommand () on the current input method.

Parameters

View Optional Send command views, such as if you want to send a command without regard to the view attached to the input method, this item can be empty.

The name of the command executed by the action. Must be the name of the scope, such as the prefix package name, so that different developers will not create conflicting commands.

Any data contained in the database command.

public boolean Setcurrentinputmethodsubtype (Inputmethodsubtype subtype)

(Translator Note: This method is the new method in 3.0)

public void Setinputmethod (IBinder token, String ID)

Forces a switch to the new IME part. Currently activated input methods can only be called by the token-holding application (application) or service.

Parameters

Tokens provide token validation when the input method is started, and can be manipulated after validation.

ID switch to the unique identity of the new IME.
public void Setinputmethodandsubtype (IBinder token, String ID, Inputmethodsubtype subtype)

Forces a switch to a new input method and the specified type. Currently activated input methods can only be called by the token-holding application (application) or service. (Translator Note: This method is the new method in 3.0)

Parameters

Tokens provide token validation when the input method is started, and can be manipulated after validation.

ID switch to the unique identity of the new IME.

Subtype switch to the new IME type.

public void Showinputmethodandsubtypeenabler (String topid)

(Translator Note: This method is the new method in 3.0)

public void Showinputmethodpicker ()

(Translator Note: Display the input menu list)

public Boolean showsoftinput (view view, int flags, Resultreceiver resultreceiver)

If required, explicitly require that the current input method's soft keyboard area be displayed to the user. This method can be called when the user interacts with the view and the user indicates that they want to start the input operation.

Parameters

View is currently in focus and can accept soft keyboard input.

Flags provides additional operational flags. The current can be a 0 or show_implicit bit setting.

Resultreceiver is called when the IME processing request tells you to complete if it is not empty. The result code you receive can be Result_unchanged_shown, Result_unchanged_hidden, Result_shown, or Result_hidden.

public Boolean showsoftinput (view view, int flags)

Showsoftinput (View, int, resultreceiver) with no return value version: explicitly requires that the soft keyboard area of the current input method be displayed to the user, if required.

Parameters

View is currently in focus and can accept soft keyboard input.

Flags provides additional operational flags. The current can be a 0 or show_implicit bit setting.

public void Showsoftinputfrominputmethod (IBinder token, int flags)

Displays the soft keyboard area of the input method so that the user can see the Input Method window and can interact with it. Can only be called by the currently active input method, as required token (tokens) authentication.

Parameters

Tokens provide token validation when the input method is started, and can be manipulated after validation.

Flags provides additional operational flags. can be 0 or show_implicit, show_forced bit set.

public void Showstatusicon (IBinder imetoken, String packagename, int iconid)

(Translator Note: Display the status bar icon?) )

public boolean Switchtolastinputmethod (IBinder imetoken)

public void Togglesoftinput (int showflags, int hideflags)

(Translator Note: Toggle soft keyboard)

public void Togglesoftinputfromwindow (IBinder windowtoken, int showflags, int hideflags)

This method toggles the window display of the IME. If the input window is already displayed, it is hidden. If no input window is displayed.

Parameters

The Windowtoken is requested by the window View.getwindowtoken () to return the resulting token (token).

The SHOWFLAGS provides additional operating flags. The current can be set to 0 or hide_implicit_only bits.

The HIDEFLAGS provides additional operating flags. can be 0 or hide_implicit_only, hide_not_always bit set.

public void Updatecursor (view view, int left, int top, int. right, int bottom)

Returns the current cursor position of the window.

public void Updateextractedtext (view view, int token, extractedtext text)

(Translator Note: When the content changes, the text editor calls this method, notifying it of its newly extracted text.) )

public void updateselection (view view, int selStart, int selend, int candidatesstart, int candidatesend)

Returns the current selection area.


How Android calls Show and hide system default IME

1. Call the display system default Input method

Method One,

Inputmethodmanager IMM = (inputmethodmanager) getsystemservice (Context.input_method_service);

Imm.showsoftinput (M_receiverview (view) with soft keyboard input, inputmethodmanager.show_forced (provides markup for the current action, show_forced indicates force display) );

Method Two,

Inputmethodmanager m= (Inputmethodmanager) Getsystemservice (Context.input_method_service);
M.togglesoftinput (0, inputmethodmanager.hide_not_always); (This method can implement the input method to switch the display on the window, if the input method is already displayed on the window, then hide, if hidden, then display the input method to the window)

2. Call the hidden system default Input method

((Inputmethodmanager) Getsystemservice (Input_method_service)). Hidesoftinputfromwindow ( WidgetSearchActivity.this.getCurrentFocus (). Getwindowtoken (), inputmethodmanager.hide_not_always); (Widgetsearchactivity is the current activity)

3. Get the Input Method open state

Inputmethodmanager IMM = (inputmethodmanager) getsystemservice (Context.input_method_service);
Boolean isopen=imm.isactive ();
IsOpen returns true to indicate that the input method is open

1.//Hide Soft keyboard

((Inputmethodmanager) Getsystemservice (Input_method_service)). Hidesoftinputfromwindow ( WidgetSearchActivity.this.getCurrentFocus (). Getwindowtoken (), inputmethodmanager.hide_not_always);

2,//display soft keyboard, control ID can be Edittext,textview

((Inputmethodmanager) Getsystemservice (Input_method_service)). Showsoftinput (Control ID, 0);

3, does not automatically eject the keyboard:

With the EditText control, the first display will automatically get focus, and pop up the keyboard, if you do not want to automatically eject the keyboard, there are two ways:

Method One: In the Mainfest file, the corresponding activity settings

Android:windowsoftinputmode= "Statehidden" or android:windowsoftinputmode= "stateunchanged".

Method Two: You can put a hidden textview in the layout, and then Requsetfocus in the OnCreate.

Note TextView do not set visiable=gone, otherwise it will fail

, you can put a hidden TextView in the layout, and then Requsetfocus in the onCreate.

Note TextView do not set visiable=gone, otherwise it will fail

<textview

Android:id= "@+id/text_notuse"

Android:layout_width= "Wrap_content"

android:layout_height= "Wrap_content"

Android:focusable= "true"

Android:focusableintouchmode= "true"/>

TextView TextView = (TextView) Findviewbyid (r.id.text_notuse);

Textview.requestfocus ();

Android Soft Keyboard Learning Inputmethodmanager

When we click in the EditText provided by Android, we will automatically eject the soft keyboard, in fact, the control of the soft keyboard can be achieved by Inputmethodmanager this class. The way we need to control the soft keyboard is that two kinds of one are like edittext when the OnClick event occurs when a soft keyboard appears, and when a program is opened automatically pop-up soft keyboard.

public class Inputmethodmanagertest extends Activity implements onclicklistener{private button button; @Override protected void OnCreate (Bundle savedinstancestate) {//TODO auto-generated method stub s          Uper.oncreate (savedinstancestate);          LinearLayout layout=new LinearLayout (this); Linearlayout.layoutparams layoutparams=new linearlayout.layoutparams (LinearLayout.LayoutParams.WRAP_CONTENT,          LinearLayout.LayoutParams.WRAP_CONTENT);          Button=new Button (this);          Button.setid (123);          Button.settext ("Hello Gaomatrix");          Button.setonclicklistener (this);          Layout.addview (button, layoutparams);                    Setcontentview (layout);          /** * with a Timer control when the activity is turned on the soft keyboard */Timer timer=new timer (); Timer.schedule (New TimerTask () {@Override public void run () {Inputmethodmanag Er inputmethodmanager= (inputmethodmanager) Getsystemservice (Context.input_method_service);              Inputmethodmanager.togglesoftinput (0, inputmethodmanager.hide_not_always);      }}, 2000); }/** * Trigger display soft keyboard when clicking Event */@Override public void OnClick (View v) {Inputmethodmanager in          Putmethodmanager= (Inputmethodmanager) Getsystemservice (Context.input_method_service);      Inputmethodmanager.togglesoftinput (0, inputmethodmanager.hide_not_always);   }  }

The explanation in the API for the Togglesoftinput method inside the Inputmethodmanager class is:

This method toggles the Input Method window display. If the input window is already displayed, it gets hidden. If not the input window would be displayed.

This method in the interface to switch the function of the input method, if the input method out of the real state, he will hide, if in a hidden state, display input method.

For the second way into the activity, the soft keyboard is automatically displayed, in a timer, that is, executed in a thread, but only for a delay of 2 seconds, because the Android program in the OnCreate function does not complete the screen drawing.

Android Softinput Related

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.