標籤:inputmethod android view
介面
- InputConnection
- InputMethod
- InputMethod.SessionCallback
- InputMethodSession
- InputMethodSession.EventCallback
類
- BaseInputConnection
- CompletionInfo
- EditorInfo
- ExtractedText
- ExtractedTextRequest
- InputBinding
- InputConnectionWrapper
- InputMethodInfo
- InputMethodManager
inputmethod
結構繼承關係
public interface InputMethod extends Objectandroid.view.inputmethod.InputMethod
間接子類
- AbstractInputMethodService.AbstractInputMethodImpl,
- InputMethodService.InputMethodImpl
類概述InputMethod 介面代表了IME,它可產生按鍵事件,產生文本,如數字,email 地址,CJK 字元,其它語言字元等等。在處理輸入事件時,將文本返回至需要文本輸入的應用程式。InputMethodManager可得到更多關於架構的資訊。
應用程式通常不使用這個介面本身,而是依靠 TextView 和 EditText 提供的標準互動。
IME實現通常為 InputMethodService 及其子類的派生。在實現IME時,包含它的服務控制項必須提供SERVICE_META_DATA 中繼資料欄位,該中繼資料欄位聯結至一包含IME細節的 XML 資源。所有IME也必定要求用戶端包含BIND_INPUT_METHOD以便與服務控制項互動。如果不這樣,系統將無法使用IME,因其無法確認是否完整。
InputMethod 介面實際上分為兩部分:
- 介面是IME的最進階介面,提供所有的訪問,只有系統能訪問(需要 BIND_INPUT_METHOD 許可權)。
- 另外調用方法createSession(android.view.inputmethod.InputMethod.SessionCallback)可執行個體化InputMethodSession 副介面,用於與用戶端通訊。
內部類interface InputMethod.SessionCallback
常量public static final String SERVICE_INTERFACE介面名字,實現IME的服務應說明它支援IME,也就是它將用於意向過濾器(intent filter)服務還需要 BIND_INPUT_METHOD 許可權,這樣應用程式不會濫用它。
常量值: "android.view.InputMethod"
public static final String SERVICE_META_DATAIME通過此名字發布其自身資訊。此中繼資料必須引用一個包含< input-method>標籤的XML 資源。
常量值: "android.view.im"
public static final int SHOW_EXPLICIT用於 showSoftInput(int, ResultReceiver)的標誌:它表示使用者顯式地要求其(軟鍵盤)顯示。如果沒有設定,系統決定可能是一個好主意,顯示IME在使用者介面上的導航操作。
常量值: 1 (0x00000001)
public static final int SHOW_FORCED標誌用於 showSoftInput(int, ResultReceiver):表明使用者強制其(軟鍵盤)顯示。如設定,IME保持可見直至使用者在 UI 上取消。
常量值: 2 (0x00000002)
公用方法public abstract void attachToken (IBinder token)IME建立後首先被調用,它提供一個與系統服務會話的唯一令牌。它需要通過服務識別IME從而驗證其操作。令牌不能傳遞給應用程式,因其取得了應用程式不應得到的特殊許可權。
注意:為避免惡意用戶端傷害,你應只接收第一個令牌。其後可能來自用戶端。
public abstract void bindInput (InputBinding binding)將IME與新的應用程式環境綁定,以便稍後啟動、停止輸入處理。通常在應用程式第一次啟用IME時調用此方法。
參數binding 與IME綁定的應用程式視窗資訊。
public abstract void createSession (InputMethod.SessionCallback callback)建立一個新的 InputMethodSession,它可處理客戶應用程式與IME的互動。你可以隨後用 revokeSession(InputMethodSession)銷毀會話,這樣就不會有任何用戶端使用它。
參數callback 新建立會話調用的介面。
public abstract void hideSoftInput (int flags, ResultReceiver resultReceiver)將IME的軟鍵盤(soft input)部分對使用者隱藏。
參數
- flags 顯示要求的附加資訊。當前總是 0。
- resultReceiver 向要求顯示的用戶端通知結果。其結果可能為
- InputMethodManager.RESULT_UNCHANGED_SHOWN,
- InputMethodManager.RESULT_UNCHANGED_HIDDEN,
- InputMethodManager.RESULT_SHOWN,
- InputMethodManager.RESULT_HIDDEN
public abstract void restartInput (InputConnection inputConnection, EditorInfo attribute)IME需重設時調用此方法。通常輸入焦點從一個文字框移至另一個時調用此方法。
參數
- inputConnection 可選,確定與文字框通訊的輸入通訊通道;如為空白,你使用通常綁定的輸入通訊通道。
- attribute 文字框(通常是 EditText)需要輸入的屬性
public abstract void revokeSession (InputMethodSession session)關閉並銷毀先前由 createSession(android.view.inputmethod.InputMethod.SessionCallback)建立的會話。調用後,會話不再有效,對其的調用將失敗。
參數session 先前由 SessionCallback.sessionCreated()提供的 InputMethodSession 將被吊銷。
public abstract void setSessionEnabled (InputMethodSession session, boolean enabled).控制某特定IME會話是否啟用。
參數
- session 先前由 SessionCallback.sessionCreated()提供的 InputMethodSession 將改變。
public abstract void showSoftInput (int flags, ResultReceiver resultReceiver)將IME的軟鍵盤(soft input)部分對使用者顯示。
參數
- flags 提供顯示要求的附加資訊。當前為 0 或設定 SHOW_EXPLICIT 位。
- resultReceiver 向要求顯示的用戶端通知結果。其結果可能為
- InputMethodManager.RESULT_UNCHANGED_SHOWN,
- InputMethodManager.RESULT_UNCHANGED_HIDDEN
- InputMethodManager.RESULT_SHOWN
- InputMethodManager.RESULT_HIDDEN
public abstract void startInput (InputConnection inputConnection, EditorInfo info)應用程式開始接收文本,IME準備好為應用程式處理接收事件並返迴文本時調用本方法。
參數
- inputConnection 可選,確定與文字框通訊的輸入通訊通道;如為空白,你使用通常綁定的輸入通訊通道。
- info 需要輸入的文字框(通常是 EditText)資訊。
public abstract void unbindInput ()解除與應用程式的綁定,先前由 bindInput(InputBinding)設定的資訊對當前IME無效時調用。通常在應用程式變為非前台調用。
android.view.inputmethod