Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
LatinIME
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
keyboard
LatinIME
Commits
22ba22f3
Commit
22ba22f3
authored
10 years ago
by
Yohei Yukawa
Committed by
Android (Google) Code Review
10 years ago
Browse files
Options
Downloads
Plain Diff
Merge "Add two convenient utility methods for L new API" into lmp-dev
parents
34da7494
5696ac95
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
java/src/com/android/inputmethod/compat/InputConnectionCompatUtils.java
+70
-6
70 additions, 6 deletions
...ndroid/inputmethod/compat/InputConnectionCompatUtils.java
with
70 additions
and
6 deletions
java/src/com/android/inputmethod/compat/InputConnectionCompatUtils.java
+
70
−
6
View file @
22ba22f3
...
...
@@ -16,12 +16,15 @@
package
com.android.inputmethod.compat
;
import
android.util.Log
;
import
android.view.inputmethod.InputConnection
;
import
java.lang.reflect.Constructor
;
import
java.lang.reflect.Method
;
public
final
class
InputConnectionCompatUtils
{
private
static
final
String
TAG
=
InputConnectionCompatUtils
.
class
.
getSimpleName
();
// Note that CursorAnchorInfoRequest is supposed to be available in API level 21 and later.
private
static
Class
<?>
getCursorAnchorInfoRequestClass
()
{
try
{
...
...
@@ -48,23 +51,84 @@ public final class InputConnectionCompatUtils {
}
/**
*
A l
ocal cop
y
of CursorAnchorInfoRequest
.RESULT_NOT_HANDLED
until the SDK becomes publicly
*
L
ocal cop
ies
of
some constants in
CursorAnchorInfoRequest until the SDK becomes publicly
* available.
*/
private
final
static
int
CURSOR_ANCHOR_INFO_REQUEST_RESULT_NOT_HANDLED
=
0
;
private
final
static
int
RESULT_NOT_HANDLED
=
0
;
private
final
static
int
RESULT_SCHEDULED
=
1
;
private
final
static
int
TYPE_CURSOR_ANCHOR_INFO
=
1
;
private
final
static
int
FLAG_CURSOR_ANCHOR_INFO_MONITOR
=
1
;
private
final
static
int
FLAG_CURSOR_ANCHOR_INFO_IMMEDIATE
=
2
;
private
final
static
int
TYPE_CURSOR_RECT
=
2
;
private
final
static
int
FLAG_CURSOR_RECT_MONITOR
=
1
;
private
final
static
int
FLAG_CURSOR_RECT_IN_SCREEN_COORDINATES
=
2
;
private
final
static
int
FLAG_CURSOR_RECT_WITH_VIEW_MATRIX
=
4
;
p
ublic
static
int
requestCursorAnchorInfo
(
final
InputConnection
inputConnection
,
p
rivate
static
int
requestCursorAnchorInfo
Impl
(
final
InputConnection
inputConnection
,
final
int
type
,
final
int
flags
)
{
if
(!
isRequestCursorAnchorInfoAvailable
())
{
return
CURSOR_ANCHOR_INFO_REQUEST_
RESULT_NOT_HANDLED
;
return
RESULT_NOT_HANDLED
;
}
final
Object
requestObject
=
CompatUtils
.
newInstance
(
CONSTRUCTOR_CursorAnchorInfoRequest
,
type
,
flags
);
if
(
requestObject
==
null
)
{
return
CURSOR_ANCHOR_INFO_REQUEST_
RESULT_NOT_HANDLED
;
return
RESULT_NOT_HANDLED
;
}
return
(
Integer
)
CompatUtils
.
invoke
(
inputConnection
,
CURSOR_ANCHOR_INFO_REQUEST_
RESULT_NOT_HANDLED
/* defaultValue */
,
RESULT_NOT_HANDLED
/* defaultValue */
,
METHOD_requestCursorAnchorInfo
,
requestObject
);
}
/**
* Requests the editor to call back {@link InputMethodManager#updateCursorAnchorInfo}.
* @param inputConnection the input connection to which the request is to be sent.
* @param enableMonitor {@code true} to request the editor to call back the method whenever the
* cursor/anchor position is changed.
* @param requestImmediateCallback {@code true} to request the editor to call back the method
* as soon as possible to notify the current cursor/anchor position to the input method.
* @return {@code false} if the request is not handled. Otherwise returns {@code true}.
*/
public
static
boolean
requestCursorAnchorInfo
(
final
InputConnection
inputConnection
,
final
boolean
enableMonitor
,
final
boolean
requestImmediateCallback
)
{
final
int
requestFlags
=
(
enableMonitor
?
FLAG_CURSOR_ANCHOR_INFO_MONITOR
:
0
)
|
(
requestImmediateCallback
?
FLAG_CURSOR_ANCHOR_INFO_IMMEDIATE
:
0
);
final
int
requestResult
=
requestCursorAnchorInfoImpl
(
inputConnection
,
TYPE_CURSOR_ANCHOR_INFO
,
requestFlags
);
switch
(
requestResult
)
{
case
RESULT_NOT_HANDLED:
return
false
;
case
RESULT_SCHEDULED:
return
true
;
default
:
Log
.
w
(
TAG
,
"requestCursorAnchorInfo returned unknown result="
+
requestResult
+
" for type=TYPE_CURSOR_ANCHOR_INFO flags="
+
requestFlags
);
return
true
;
}
}
/**
* Requests the editor to call back {@link InputMethodManager#updateCursor}.
* @param inputConnection the input connection to which the request is to be sent.
* @param enableMonitor {@code true} to request the editor to call back the method whenever the
* cursor position is changed.
* @return {@code false} if the request is not handled. Otherwise returns {@code true}.
*/
public
static
boolean
requestCursorRect
(
final
InputConnection
inputConnection
,
final
boolean
enableMonitor
)
{
final
int
requestFlags
=
enableMonitor
?
FLAG_CURSOR_RECT_MONITOR
|
FLAG_CURSOR_RECT_IN_SCREEN_COORDINATES
|
FLAG_CURSOR_RECT_WITH_VIEW_MATRIX
:
0
;
final
int
requestResult
=
requestCursorAnchorInfoImpl
(
inputConnection
,
TYPE_CURSOR_RECT
,
requestFlags
);
switch
(
requestResult
)
{
case
RESULT_NOT_HANDLED:
return
false
;
case
RESULT_SCHEDULED:
return
true
;
default
:
Log
.
w
(
TAG
,
"requestCursorAnchorInfo returned unknown result="
+
requestResult
+
" for type=TYPE_CURSOR_RECT flags="
+
requestFlags
);
return
true
;
}
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment