Introduce @SoftInputModeFlags annotation

Doing this allows us to annotate integer values that should corresponds
to WindowManager.LayoutParams#softInputMode.

Test: There should be no behavior change.  RetentionPolicy.SOURCE
      annotation should change nothing in production code.
Test: checkbuild
Bug: 32784563
Bug: 35079353
Change-Id: I96300b090edce327d0515c740183abe91ded6bac
This commit is contained in:
Yohei Yukawa
2017-02-12 16:54:16 -08:00
parent 22a8923368
commit 22dac1c8df
9 changed files with 47 additions and 13 deletions

View File

@@ -824,6 +824,7 @@ public class ActivityInfo extends ComponentInfo
* WindowManager.LayoutParams.softInputMode}. If 0 (unspecified),
* the mode from the theme will be used.
*/
@android.view.WindowManager.LayoutParams.SoftInputModeFlags
public int softInputMode;
/**

View File

@@ -73,6 +73,7 @@ import android.util.TypedValue;
import android.view.Surface.OutOfResourcesException;
import android.view.View.AttachInfo;
import android.view.View.MeasureSpec;
import android.view.WindowManager.LayoutParams.SoftInputModeFlags;
import android.view.accessibility.AccessibilityEvent;
import android.view.accessibility.AccessibilityManager;
import android.view.accessibility.AccessibilityManager.AccessibilityStateChangeListener;
@@ -334,6 +335,7 @@ public final class ViewRootImpl implements ViewParent,
final Configuration mPendingConfiguration = new Configuration();
boolean mScrollMayChange;
@SoftInputModeFlags
int mSoftInputMode;
WeakReference<View> mLastScrolledFocus;
int mScrollY;

View File

@@ -16,6 +16,7 @@
package android.view;
import android.annotation.IntDef;
import android.annotation.NonNull;
import android.annotation.SystemApi;
import android.app.KeyguardManager;
@@ -30,6 +31,8 @@ import android.os.Parcelable;
import android.text.TextUtils;
import android.util.Log;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.util.List;
import java.util.Objects;
@@ -1539,6 +1542,27 @@ public interface WindowManager extends ViewManager {
*/
public static final int SOFT_INPUT_IS_FORWARD_NAVIGATION = 0x100;
/**
* An internal annotation for flags that can be specified to {@link #softInputMode}.
*
* @hide
*/
@Retention(RetentionPolicy.SOURCE)
@IntDef(flag = true, value = {
SOFT_INPUT_STATE_UNSPECIFIED,
SOFT_INPUT_STATE_UNCHANGED,
SOFT_INPUT_STATE_HIDDEN,
SOFT_INPUT_STATE_ALWAYS_HIDDEN,
SOFT_INPUT_STATE_VISIBLE,
SOFT_INPUT_STATE_ALWAYS_VISIBLE,
SOFT_INPUT_ADJUST_UNSPECIFIED,
SOFT_INPUT_ADJUST_RESIZE,
SOFT_INPUT_ADJUST_PAN,
SOFT_INPUT_ADJUST_NOTHING,
SOFT_INPUT_IS_FORWARD_NAVIGATION,
})
public @interface SoftInputModeFlags {}
/**
* Desired operating mode for any soft input area. May be any combination
* of:
@@ -1546,18 +1570,18 @@ public interface WindowManager extends ViewManager {
* <ul>
* <li> One of the visibility states
* {@link #SOFT_INPUT_STATE_UNSPECIFIED}, {@link #SOFT_INPUT_STATE_UNCHANGED},
* {@link #SOFT_INPUT_STATE_HIDDEN}, {@link #SOFT_INPUT_STATE_ALWAYS_VISIBLE}, or
* {@link #SOFT_INPUT_STATE_VISIBLE}.
* {@link #SOFT_INPUT_STATE_HIDDEN}, {@link #SOFT_INPUT_STATE_ALWAYS_HIDDEN},
* {@link #SOFT_INPUT_STATE_VISIBLE}, or {@link #SOFT_INPUT_STATE_ALWAYS_VISIBLE}.
* <li> One of the adjustment options
* {@link #SOFT_INPUT_ADJUST_UNSPECIFIED},
* {@link #SOFT_INPUT_ADJUST_RESIZE}, or
* {@link #SOFT_INPUT_ADJUST_PAN}.
* {@link #SOFT_INPUT_ADJUST_UNSPECIFIED}, {@link #SOFT_INPUT_ADJUST_RESIZE},
* {@link #SOFT_INPUT_ADJUST_PAN}, or {@link #SOFT_INPUT_ADJUST_NOTHING}.
* </ul>
*
*
* <p>This flag can be controlled in your theme through the
* {@link android.R.attr#windowSoftInputMode} attribute.</p>
*/
@SoftInputModeFlags
public int softInputMode;
/**

View File

@@ -47,6 +47,7 @@ import android.view.InputEventSender;
import android.view.KeyEvent;
import android.view.View;
import android.view.ViewRootImpl;
import android.view.WindowManager.LayoutParams.SoftInputModeFlags;
import com.android.internal.inputmethod.IInputContentUriToken;
import com.android.internal.os.SomeArgs;
@@ -1490,8 +1491,8 @@ public final class InputMethodManager {
* Called by ViewAncestor when its window gets input focus.
* @hide
*/
public void onPostWindowFocus(View rootView, View focusedView, int softInputMode,
boolean first, int windowFlags) {
public void onPostWindowFocus(View rootView, View focusedView,
@SoftInputModeFlags int softInputMode, boolean first, int windowFlags) {
boolean forceNewFocus = false;
synchronized (mH) {
if (DEBUG) Log.v(TAG, "onWindowFocus: " + focusedView

View File

@@ -54,6 +54,7 @@ import android.view.ViewTreeObserver.OnGlobalLayoutListener;
import android.view.ViewTreeObserver.OnScrollChangedListener;
import android.view.WindowManager;
import android.view.WindowManager.LayoutParams;
import android.view.WindowManager.LayoutParams.SoftInputModeFlags;
import com.android.internal.R;
@@ -162,6 +163,7 @@ public class PopupWindow {
private boolean mFocusable;
private int mInputMethodMode = INPUT_METHOD_FROM_FOCUSABLE;
@SoftInputModeFlags
private int mSoftInputMode = WindowManager.LayoutParams.SOFT_INPUT_STATE_UNCHANGED;
private boolean mTouchable = true;
private boolean mOutsideTouchable = false;
@@ -724,7 +726,7 @@ public class PopupWindow {
* @see android.view.WindowManager.LayoutParams#softInputMode
* @see #getSoftInputMode()
*/
public void setSoftInputMode(int mode) {
public void setSoftInputMode(@SoftInputModeFlags int mode) {
mSoftInputMode = mode;
}
@@ -734,6 +736,7 @@ public class PopupWindow {
* @see #setSoftInputMode(int)
* @see android.view.WindowManager.LayoutParams#softInputMode
*/
@SoftInputModeFlags
public int getSoftInputMode() {
return mSoftInputMode;
}

View File

@@ -58,8 +58,8 @@ interface IInputMethodManager {
InputBindResult startInputOrWindowGainedFocus(
/* @InputMethodClient.StartInputReason */ int startInputReason,
in IInputMethodClient client, in IBinder windowToken, int controlFlags,
int softInputMode, int windowFlags, in EditorInfo attribute,
IInputContext inputContext,
/* @android.view.WindowManager.LayoutParams.SoftInputModeFlags */ int softInputMode,
int windowFlags, in EditorInfo attribute, IInputContext inputContext,
/* @InputConnectionInspector.MissingMethodFlags */ int missingMethodFlags);
void showInputMethodPickerFromClient(in IInputMethodClient client,

View File

@@ -18,6 +18,7 @@ package com.android.internal.view;
import android.annotation.IntDef;
import android.view.WindowManager.LayoutParams;
import android.view.WindowManager.LayoutParams.SoftInputModeFlags;
import java.lang.annotation.Retention;
@@ -105,7 +106,7 @@ public final class InputMethodClient {
}
}
public static String softInputModeToString(final int softInputMode) {
public static String softInputModeToString(@SoftInputModeFlags final int softInputMode) {
final StringBuilder sb = new StringBuilder();
final int state = softInputMode & LayoutParams.SOFT_INPUT_MASK_STATE;
final int adjust = softInputMode & LayoutParams.SOFT_INPUT_MASK_ADJUST;

View File

@@ -2278,7 +2278,8 @@ public class InputMethodManagerService extends IInputMethodManager.Stub
private InputBindResult windowGainedFocus(
/* @InputMethodClient.StartInputReason */ final int startInputReason,
IInputMethodClient client, IBinder windowToken, int controlFlags, int softInputMode,
IInputMethodClient client, IBinder windowToken, int controlFlags,
/* @android.view.WindowManager.LayoutParams.SoftInputModeFlags */ int softInputMode,
int windowFlags, EditorInfo attribute, IInputContext inputContext,
/* @InputConnectionInspector.missingMethods */ final int missingMethods) {
// Needs to check the validity before clearing calling identity

View File

@@ -228,7 +228,8 @@ public class BridgeIInputMethodManager implements IInputMethodManager {
@Override
public InputBindResult startInputOrWindowGainedFocus(
/* @InputMethodClient.StartInputReason */ int startInputReason,
IInputMethodClient client, IBinder windowToken, int controlFlags, int softInputMode,
IInputMethodClient client, IBinder windowToken, int controlFlags,
/* @android.view.WindowManager.LayoutParams.SoftInputModeFlags */ int softInputMode,
int windowFlags, EditorInfo attribute, IInputContext inputContext,
/* @InputConnectionInspector.MissingMethodFlags */ int missingMethodFlags)
throws RemoteException {