summaryrefslogtreecommitdiffstats
path: root/core/java/android/inputmethodservice/InputMethodService.java
diff options
context:
space:
mode:
authorThe Android Open Source Project <initial-contribution@android.com>2009-01-20 14:03:58 -0800
committerThe Android Open Source Project <initial-contribution@android.com>2009-01-20 14:03:58 -0800
commit22f7dfd23490a3de2f21ff96949ba47003aac8f8 (patch)
tree41bc290bb2f1f08a0e37cfda4955742a85d42ecf /core/java/android/inputmethodservice/InputMethodService.java
parent9266c558bf1d21ff647525ff99f7dadbca417309 (diff)
downloadframeworks_base-22f7dfd23490a3de2f21ff96949ba47003aac8f8.zip
frameworks_base-22f7dfd23490a3de2f21ff96949ba47003aac8f8.tar.gz
frameworks_base-22f7dfd23490a3de2f21ff96949ba47003aac8f8.tar.bz2
auto import from //branches/cupcake/...@127101
Diffstat (limited to 'core/java/android/inputmethodservice/InputMethodService.java')
-rw-r--r--core/java/android/inputmethodservice/InputMethodService.java198
1 files changed, 155 insertions, 43 deletions
diff --git a/core/java/android/inputmethodservice/InputMethodService.java b/core/java/android/inputmethodservice/InputMethodService.java
index 21bb38e..1a7547d 100644
--- a/core/java/android/inputmethodservice/InputMethodService.java
+++ b/core/java/android/inputmethodservice/InputMethodService.java
@@ -33,6 +33,8 @@ import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewTreeObserver;
+import android.view.Window;
+import android.view.WindowManager;
import android.view.inputmethod.CompletionInfo;
import android.view.inputmethod.ExtractedText;
import android.view.inputmethod.ExtractedTextRequest;
@@ -197,6 +199,7 @@ public class InputMethodService extends AbstractInputMethodService {
EditorInfo mInputEditorInfo;
boolean mShowInputRequested;
+ boolean mLastShowInputRequested;
boolean mShowCandidatesRequested;
boolean mFullscreenApplied;
@@ -257,6 +260,8 @@ public class InputMethodService extends AbstractInputMethodService {
public void bindInput(InputBinding binding) {
mInputBinding = binding;
mInputConnection = binding.getConnection();
+ if (DEBUG) Log.v(TAG, "bindInput(): binding=" + binding
+ + " ic=" + mInputConnection);
onBindInput();
}
@@ -264,17 +269,22 @@ public class InputMethodService extends AbstractInputMethodService {
* Clear the current input binding.
*/
public void unbindInput() {
+ if (DEBUG) Log.v(TAG, "unbindInput(): binding=" + mInputBinding
+ + " ic=" + mInputConnection);
+ onUnbindInput();
mInputStarted = false;
mInputBinding = null;
mInputConnection = null;
}
public void startInput(EditorInfo attribute) {
+ if (DEBUG) Log.v(TAG, "startInput(): editor=" + attribute);
doStartInput(attribute, false);
}
public void restartInput(EditorInfo attribute) {
- doStartInput(attribute, false);
+ if (DEBUG) Log.v(TAG, "restartInput(): editor=" + attribute);
+ doStartInput(attribute, true);
}
/**
@@ -305,6 +315,7 @@ public class InputMethodService extends AbstractInputMethodService {
if (!isEnabled()) {
return;
}
+ if (DEBUG) Log.v(TAG, "finishInput() in " + this);
onFinishInput();
mInputStarted = false;
}
@@ -455,7 +466,7 @@ public class InputMethodService extends AbstractInputMethodService {
mIsInputViewShown = false;
mExtractFrame.setVisibility(View.GONE);
- mCandidatesFrame.setVisibility(View.GONE);
+ mCandidatesFrame.setVisibility(View.INVISIBLE);
mInputFrame.setVisibility(View.GONE);
}
@@ -469,6 +480,29 @@ public class InputMethodService extends AbstractInputMethodService {
}
/**
+ * Take care of handling configuration changes. Subclasses of
+ * InputMethodService generally don't need to deal directly with
+ * this on their own; the standard implementation here takes care of
+ * regenerating the input method UI as a result of the configuration
+ * change, so you can rely on your {@link #onCreateInputView} and
+ * other methods being called as appropriate due to a configuration change.
+ */
+ @Override public void onConfigurationChanged(Configuration newConfig) {
+ super.onConfigurationChanged(newConfig);
+
+ boolean visible = mWindowVisible;
+ boolean showingInput = mShowInputRequested;
+ boolean showingCandidates = mShowCandidatesRequested;
+ initViews();
+ if (visible) {
+ if (showingCandidates) {
+ setCandidatesViewShown(true);
+ }
+ showWindow(showingInput);
+ }
+ }
+
+ /**
* Implement to return our standard {@link InputMethodImpl}. Subclasses
* can override to provide their own customized version.
*/
@@ -493,6 +527,27 @@ public class InputMethodService extends AbstractInputMethodService {
}
/**
+ * Return the maximum width, in pixels, available the input method.
+ * Input methods are positioned at the bottom of the screen and, unless
+ * running in fullscreen, will generally want to be as short as possible
+ * so should compute their height based on their contents. However, they
+ * can stretch as much as needed horizontally. The function returns to
+ * you the maximum amount of space available horizontally, which you can
+ * use if needed for UI placement.
+ *
+ * <p>In many cases this is not needed, you can just rely on the normal
+ * view layout mechanisms to position your views within the full horizontal
+ * space given to the input method.
+ *
+ * <p>Note that this value can change dynamically, in particular when the
+ * screen orientation changes.
+ */
+ public int getMaxWidth() {
+ WindowManager wm = (WindowManager) getSystemService(Context.WINDOW_SERVICE);
+ return wm.getDefaultDisplay().getWidth();
+ }
+
+ /**
* Return the currently active InputBinding for the input method, or
* null if there is none.
*/
@@ -525,12 +580,19 @@ public class InputMethodService extends AbstractInputMethodService {
* is currently running in fullscreen mode.
*/
public void updateFullscreenMode() {
- boolean isFullscreen = onEvaluateFullscreenMode();
+ boolean isFullscreen = mShowInputRequested && onEvaluateFullscreenMode();
+ boolean changed = mLastShowInputRequested != mShowInputRequested;
if (mIsFullscreen != isFullscreen || !mFullscreenApplied) {
+ changed = true;
mIsFullscreen = isFullscreen;
mFullscreenApplied = true;
- mWindow.getWindow().setBackgroundDrawable(
- onCreateBackgroundDrawable());
+ Drawable bg = onCreateBackgroundDrawable();
+ if (bg == null) {
+ // We need to give the window a real drawable, so that it
+ // correctly sets its mode.
+ bg = getResources().getDrawable(android.R.color.transparent);
+ }
+ mWindow.getWindow().setBackgroundDrawable(bg);
mExtractFrame.setVisibility(isFullscreen ? View.VISIBLE : View.GONE);
if (isFullscreen) {
if (mExtractView == null) {
@@ -540,11 +602,39 @@ public class InputMethodService extends AbstractInputMethodService {
}
}
startExtractingText();
- mWindow.getWindow().setLayout(FILL_PARENT, FILL_PARENT);
- } else {
- mWindow.getWindow().setLayout(WRAP_CONTENT, WRAP_CONTENT);
}
}
+
+ if (changed) {
+ onConfigureWindow(mWindow.getWindow(), isFullscreen,
+ !mShowInputRequested);
+ mLastShowInputRequested = mShowInputRequested;
+ }
+ }
+
+ /**
+ * Update the given window's parameters for the given mode. This is called
+ * when the window is first displayed and each time the fullscreen or
+ * candidates only mode changes.
+ *
+ * <p>The default implementation makes the layout for the window
+ * FILL_PARENT x FILL_PARENT when in fullscreen mode, and
+ * FILL_PARENT x WRAP_CONTENT when in non-fullscreen mode.
+ *
+ * @param win The input method's window.
+ * @param isFullscreen If true, the window is running in fullscreen mode
+ * and intended to cover the entire application display.
+ * @param isCandidatesOnly If true, the window is only showing the
+ * candidates view and none of the rest of its UI. This is mutually
+ * exclusive with fullscreen mode.
+ */
+ public void onConfigureWindow(Window win, boolean isFullscreen,
+ boolean isCandidatesOnly) {
+ if (isFullscreen) {
+ mWindow.getWindow().setLayout(FILL_PARENT, FILL_PARENT);
+ } else {
+ mWindow.getWindow().setLayout(FILL_PARENT, WRAP_CONTENT);
+ }
}
/**
@@ -607,7 +697,7 @@ public class InputMethodService extends AbstractInputMethodService {
* is currently shown.
*/
public void updateInputViewShown() {
- boolean isShown = onEvaluateInputViewShown();
+ boolean isShown = mShowInputRequested && onEvaluateInputViewShown();
if (mIsInputViewShown != isShown && mWindowVisible) {
mIsInputViewShown = isShown;
mInputFrame.setVisibility(isShown ? View.VISIBLE : View.GONE);
@@ -650,18 +740,18 @@ public class InputMethodService extends AbstractInputMethodService {
public void setCandidatesViewShown(boolean shown) {
if (mShowCandidatesRequested != shown) {
mCandidatesFrame.setVisibility(shown ? View.VISIBLE : View.INVISIBLE);
- if (!mShowInputRequested) {
- // If we are being asked to show the candidates view while the app
- // has not asked for the input view to be shown, then we need
- // to update whether the window is shown.
- if (shown) {
- showWindow(false);
- } else {
- hideWindow();
- }
- }
mShowCandidatesRequested = shown;
}
+ if (!mShowInputRequested && mWindowVisible != shown) {
+ // If we are being asked to show the candidates view while the app
+ // has not asked for the input view to be shown, then we need
+ // to update whether the window is shown.
+ if (shown) {
+ showWindow(false);
+ } else {
+ hideWindow();
+ }
+ }
}
public void setStatusIcon(int iconResId) {
@@ -729,7 +819,7 @@ public class InputMethodService extends AbstractInputMethodService {
* Called by the framework to create a Drawable for the background of
* the input method window. May return null for no background. The default
* implementation returns a non-null standard background only when in
- * fullscreen mode.
+ * fullscreen mode. This is called each time the fullscreen mode changes.
*/
public Drawable onCreateBackgroundDrawable() {
if (isFullscreenMode()) {
@@ -789,22 +879,6 @@ public class InputMethodService extends AbstractInputMethodService {
public void onStartInputView(EditorInfo info, boolean restarting) {
}
- @Override
- public void onConfigurationChanged(Configuration newConfig) {
- super.onConfigurationChanged(newConfig);
-
- boolean visible = mWindowVisible;
- boolean showingInput = mShowInputRequested;
- boolean showingCandidates = mShowCandidatesRequested;
- initViews();
- if (visible) {
- if (showingCandidates) {
- setCandidatesViewShown(true);
- }
- showWindow(showingInput);
- }
- }
-
/**
* The system has decided that it may be time to show your input method.
* This is called due to a corresponding call to your
@@ -837,17 +911,17 @@ public class InputMethodService extends AbstractInputMethodService {
boolean wasVisible = mWindowVisible;
mWindowVisible = true;
if (!mShowInputRequested) {
- doShowInput = true;
- mShowInputRequested = true;
+ if (showInput) {
+ doShowInput = true;
+ mShowInputRequested = true;
+ }
} else {
showInput = true;
}
- if (doShowInput) {
- if (DEBUG) Log.v(TAG, "showWindow: updating UI");
- updateFullscreenMode();
- updateInputViewShown();
- }
+ if (DEBUG) Log.v(TAG, "showWindow: updating UI");
+ updateFullscreenMode();
+ updateInputViewShown();
if (!mWindowAdded || !mWindowCreated) {
mWindowAdded = true;
@@ -885,13 +959,44 @@ public class InputMethodService extends AbstractInputMethodService {
}
}
+ /**
+ * Called when a new client has bound to the input method. This
+ * may be followed by a series of {@link #onStartInput(EditorInfo, boolean)}
+ * and {@link #onFinishInput()} calls as the user navigates through its
+ * UI. Upon this call you know that {@link #getCurrentInputBinding}
+ * and {@link #getCurrentInputConnection} return valid objects.
+ */
public void onBindInput() {
}
+ /**
+ * Called when the previous bound client is no longer associated
+ * with the input method. After returning {@link #getCurrentInputBinding}
+ * and {@link #getCurrentInputConnection} will no longer return
+ * valid objects.
+ */
+ public void onUnbindInput() {
+ }
+
+ /**
+ * Called to inform the input method that text input has started in an
+ * editor. You should use this callback to initialize the state of your
+ * input to match the state of the editor given to it.
+ *
+ * @param attribute The attributes of the editor that input is starting
+ * in.
+ * @param restarting Set to true if input is restarting in the same
+ * editor such as because the application has changed the text in
+ * the editor. Otherwise will be false, indicating this is a new
+ * session with the editor.
+ */
public void onStartInput(EditorInfo attribute, boolean restarting) {
}
void doStartInput(EditorInfo attribute, boolean restarting) {
+ if (mInputStarted && !restarting) {
+ onFinishInput();
+ }
mInputStarted = true;
mInputEditorInfo = attribute;
onStartInput(attribute, restarting);
@@ -903,6 +1008,13 @@ public class InputMethodService extends AbstractInputMethodService {
}
}
+ /**
+ * Called to inform the input method that text input has finished in
+ * the last editor. At this point there may be a call to
+ * {@link #onStartInput(EditorInfo, boolean)} to perform input in a
+ * new editor, or the input method may be left idle. This method is
+ * <em>not</em> called when input restarts in the same editor.
+ */
public void onFinishInput() {
}