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
ffe36cdc
Commit
ffe36cdc
authored
12 years ago
by
Tadashi G. Takaoka
Committed by
Android (Google) Code Review
12 years ago
Browse files
Options
Downloads
Plain Diff
Merge "Small cleanup for keyboard drawing code" into jb-mr1-dev
parents
76c242a1
8344259f
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/keyboard/KeyboardView.java
+46
-35
46 additions, 35 deletions
java/src/com/android/inputmethod/keyboard/KeyboardView.java
with
46 additions
and
35 deletions
java/src/com/android/inputmethod/keyboard/KeyboardView.java
+
46
−
35
View file @
ffe36cdc
...
@@ -25,7 +25,7 @@ import android.graphics.Paint;
...
@@ -25,7 +25,7 @@ import android.graphics.Paint;
import
android.graphics.Paint.Align
;
import
android.graphics.Paint.Align
;
import
android.graphics.PorterDuff
;
import
android.graphics.PorterDuff
;
import
android.graphics.Rect
;
import
android.graphics.Rect
;
import
android.graphics.Region
.Op
;
import
android.graphics.Region
;
import
android.graphics.Typeface
;
import
android.graphics.Typeface
;
import
android.graphics.drawable.Drawable
;
import
android.graphics.drawable.Drawable
;
import
android.os.Message
;
import
android.os.Message
;
...
@@ -120,12 +120,12 @@ public class KeyboardView extends View implements PointerTracker.DrawingProxy {
...
@@ -120,12 +120,12 @@ public class KeyboardView extends View implements PointerTracker.DrawingProxy {
private
boolean
mInvalidateAllKeys
;
private
boolean
mInvalidateAllKeys
;
/** The keys that should be drawn */
/** The keys that should be drawn */
private
final
HashSet
<
Key
>
mInvalidatedKeys
=
new
HashSet
<
Key
>();
private
final
HashSet
<
Key
>
mInvalidatedKeys
=
new
HashSet
<
Key
>();
/** The
region of invalidated keys
*/
/** The
working rectangle variable
*/
private
final
Rect
m
InvalidatedKeys
Rect
=
new
Rect
();
private
final
Rect
m
Working
Rect
=
new
Rect
();
/** The keyboard bitmap buffer for faster updates */
/** The keyboard bitmap buffer for faster updates */
private
Bitmap
mBuffer
;
private
Bitmap
m
Offscreen
Buffer
;
/** The canvas for the above mutable keyboard bitmap */
/** The canvas for the above mutable keyboard bitmap */
private
Canvas
mCanvas
;
private
Canvas
m
Offscreen
Canvas
;
private
final
Paint
mPaint
=
new
Paint
();
private
final
Paint
mPaint
=
new
Paint
();
private
final
Paint
.
FontMetrics
mFontMetrics
=
new
Paint
.
FontMetrics
();
private
final
Paint
.
FontMetrics
mFontMetrics
=
new
Paint
.
FontMetrics
();
// This sparse array caches key label text height in pixel indexed by key label text size.
// This sparse array caches key label text height in pixel indexed by key label text size.
...
@@ -457,46 +457,61 @@ public class KeyboardView extends View implements PointerTracker.DrawingProxy {
...
@@ -457,46 +457,61 @@ public class KeyboardView extends View implements PointerTracker.DrawingProxy {
@Override
@Override
public
void
onDraw
(
Canvas
canvas
)
{
public
void
onDraw
(
Canvas
canvas
)
{
super
.
onDraw
(
canvas
);
super
.
onDraw
(
canvas
);
if
(
mBufferNeedsUpdate
||
mBuffer
==
null
)
{
if
(
mBufferNeedsUpdate
||
m
Offscreen
Buffer
==
null
)
{
mBufferNeedsUpdate
=
false
;
mBufferNeedsUpdate
=
false
;
onBufferDraw
();
if
(
maybeAllocateOffscreenBuffer
())
{
mInvalidateAllKeys
=
true
;
if
(
mOffscreenCanvas
!=
null
)
{
mOffscreenCanvas
.
setBitmap
(
mOffscreenBuffer
);
}
else
{
mOffscreenCanvas
=
new
Canvas
(
mOffscreenBuffer
);
}
}
onDrawKeyboard
(
mOffscreenCanvas
);
}
}
canvas
.
drawBitmap
(
mBuffer
,
0
,
0
,
null
);
canvas
.
drawBitmap
(
m
Offscreen
Buffer
,
0
,
0
,
null
);
}
}
private
void
o
nBuffer
Draw
()
{
private
boolean
maybeAllocateOffscree
nBuffer
()
{
final
int
width
=
getWidth
();
final
int
width
=
getWidth
();
final
int
height
=
getHeight
();
final
int
height
=
getHeight
();
if
(
width
==
0
||
height
==
0
)
if
(
width
==
0
||
height
==
0
)
{
return
;
return
false
;
if
(
mBuffer
==
null
||
mBuffer
.
getWidth
()
!=
width
||
mBuffer
.
getHeight
()
!=
height
)
{
}
if
(
mBuffer
!=
null
)
if
(
mOffscreenBuffer
!=
null
&&
mOffscreenBuffer
.
getWidth
()
==
width
mBuffer
.
recycle
();
&&
mOffscreenBuffer
.
getHeight
()
==
height
)
{
mBuffer
=
Bitmap
.
createBitmap
(
width
,
height
,
Bitmap
.
Config
.
ARGB_8888
);
return
false
;
mInvalidateAllKeys
=
true
;
if
(
mCanvas
!=
null
)
{
mCanvas
.
setBitmap
(
mBuffer
);
}
else
{
mCanvas
=
new
Canvas
(
mBuffer
);
}
}
}
freeOffscreenBuffer
();
mOffscreenBuffer
=
Bitmap
.
createBitmap
(
width
,
height
,
Bitmap
.
Config
.
ARGB_8888
);
return
true
;
}
private
void
freeOffscreenBuffer
()
{
if
(
mOffscreenBuffer
!=
null
)
{
mOffscreenBuffer
.
recycle
();
mOffscreenBuffer
=
null
;
}
}
private
void
onDrawKeyboard
(
final
Canvas
canvas
)
{
if
(
mKeyboard
==
null
)
return
;
if
(
mKeyboard
==
null
)
return
;
final
Canvas
canvas
=
mCanvas
;
final
int
width
=
getWidth
();
final
int
height
=
getHeight
();
final
Paint
paint
=
mPaint
;
final
Paint
paint
=
mPaint
;
final
KeyDrawParams
params
=
mKeyDrawParams
;
final
KeyDrawParams
params
=
mKeyDrawParams
;
if
(
mInvalidateAllKeys
||
mInvalidatedKeys
.
isEmpty
())
{
if
(
mInvalidateAllKeys
||
mInvalidatedKeys
.
isEmpty
())
{
m
InvalidatedKeys
Rect
.
set
(
0
,
0
,
width
,
height
);
m
Working
Rect
.
set
(
0
,
0
,
width
,
height
);
canvas
.
clipRect
(
m
InvalidatedKeysRect
,
Op
.
REPLACE
);
canvas
.
clipRect
(
m
WorkingRect
,
Region
.
Op
.
REPLACE
);
canvas
.
drawColor
(
Color
.
BLACK
,
PorterDuff
.
Mode
.
CLEAR
);
canvas
.
drawColor
(
Color
.
BLACK
,
PorterDuff
.
Mode
.
CLEAR
);
// Draw all keys.
// Draw all keys.
for
(
final
Key
key
:
mKeyboard
.
mKeys
)
{
for
(
final
Key
key
:
mKeyboard
.
mKeys
)
{
onDrawKey
(
key
,
canvas
,
paint
,
params
);
onDrawKey
(
key
,
canvas
,
paint
,
params
);
}
}
if
(
mNeedsToDimEntireKeyboard
)
{
if
(
mNeedsToDimEntireKeyboard
)
{
drawDimRectangle
(
canvas
,
m
InvalidatedKeys
Rect
,
mBackgroundDimAlpha
,
paint
);
drawDimRectangle
(
canvas
,
m
Working
Rect
,
mBackgroundDimAlpha
,
paint
);
}
}
}
else
{
}
else
{
// Draw invalidated keys.
// Draw invalidated keys.
...
@@ -506,12 +521,12 @@ public class KeyboardView extends View implements PointerTracker.DrawingProxy {
...
@@ -506,12 +521,12 @@ public class KeyboardView extends View implements PointerTracker.DrawingProxy {
}
}
final
int
x
=
key
.
mX
+
getPaddingLeft
();
final
int
x
=
key
.
mX
+
getPaddingLeft
();
final
int
y
=
key
.
mY
+
getPaddingTop
();
final
int
y
=
key
.
mY
+
getPaddingTop
();
m
InvalidatedKeys
Rect
.
set
(
x
,
y
,
x
+
key
.
mWidth
,
y
+
key
.
mHeight
);
m
Working
Rect
.
set
(
x
,
y
,
x
+
key
.
mWidth
,
y
+
key
.
mHeight
);
canvas
.
clipRect
(
m
InvalidatedKeysRect
,
Op
.
REPLACE
);
canvas
.
clipRect
(
m
WorkingRect
,
Region
.
Op
.
REPLACE
);
canvas
.
drawColor
(
Color
.
BLACK
,
PorterDuff
.
Mode
.
CLEAR
);
canvas
.
drawColor
(
Color
.
BLACK
,
PorterDuff
.
Mode
.
CLEAR
);
onDrawKey
(
key
,
canvas
,
paint
,
params
);
onDrawKey
(
key
,
canvas
,
paint
,
params
);
if
(
mNeedsToDimEntireKeyboard
)
{
if
(
mNeedsToDimEntireKeyboard
)
{
drawDimRectangle
(
canvas
,
m
InvalidatedKeys
Rect
,
mBackgroundDimAlpha
,
paint
);
drawDimRectangle
(
canvas
,
m
Working
Rect
,
mBackgroundDimAlpha
,
paint
);
}
}
}
}
}
}
...
@@ -524,7 +539,6 @@ public class KeyboardView extends View implements PointerTracker.DrawingProxy {
...
@@ -524,7 +539,6 @@ public class KeyboardView extends View implements PointerTracker.DrawingProxy {
}
}
mInvalidatedKeys
.
clear
();
mInvalidatedKeys
.
clear
();
mInvalidatedKeysRect
.
setEmpty
();
mInvalidateAllKeys
=
false
;
mInvalidateAllKeys
=
false
;
}
}
...
@@ -1026,9 +1040,9 @@ public class KeyboardView extends View implements PointerTracker.DrawingProxy {
...
@@ -1026,9 +1040,9 @@ public class KeyboardView extends View implements PointerTracker.DrawingProxy {
mInvalidatedKeys
.
add
(
key
);
mInvalidatedKeys
.
add
(
key
);
final
int
x
=
key
.
mX
+
getPaddingLeft
();
final
int
x
=
key
.
mX
+
getPaddingLeft
();
final
int
y
=
key
.
mY
+
getPaddingTop
();
final
int
y
=
key
.
mY
+
getPaddingTop
();
m
InvalidatedKeysRect
.
union
(
x
,
y
,
x
+
key
.
mWidth
,
y
+
key
.
mHeight
);
m
WorkingRect
.
set
(
x
,
y
,
x
+
key
.
mWidth
,
y
+
key
.
mHeight
);
mBufferNeedsUpdate
=
true
;
mBufferNeedsUpdate
=
true
;
invalidate
(
m
InvalidatedKeys
Rect
);
invalidate
(
m
Working
Rect
);
}
}
public
void
closing
()
{
public
void
closing
()
{
...
@@ -1054,9 +1068,6 @@ public class KeyboardView extends View implements PointerTracker.DrawingProxy {
...
@@ -1054,9 +1068,6 @@ public class KeyboardView extends View implements PointerTracker.DrawingProxy {
super
.
onDetachedFromWindow
();
super
.
onDetachedFromWindow
();
closing
();
closing
();
mPreviewPlacerView
.
removeAllViews
();
mPreviewPlacerView
.
removeAllViews
();
if
(
mBuffer
!=
null
)
{
freeOffscreenBuffer
();
mBuffer
.
recycle
();
mBuffer
=
null
;
}
}
}
}
}
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