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
fe9b65af
Commit
fe9b65af
authored
13 years ago
by
Tadashi G. Takaoka
Browse files
Options
Downloads
Patches
Plain Diff
Calculate text width more conservatively
Change-Id: If937ca0d05d50def115f6d275ed4b727c71e7bf4
parent
f008ae9e
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
java/src/com/android/inputmethod/latin/CandidateView.java
+15
-13
15 additions, 13 deletions
java/src/com/android/inputmethod/latin/CandidateView.java
with
15 additions
and
13 deletions
java/src/com/android/inputmethod/latin/CandidateView.java
+
15
−
13
View file @
fe9b65af
...
...
@@ -104,7 +104,7 @@ public class CandidateView extends LinearLayout implements OnClickListener, OnLo
private
final
CandidateViewLayoutParams
mParams
;
private
static
final
int
PUNCTUATIONS_IN_STRIP
=
6
;
private
static
final
float
MIN_TEXT_XSCALE
=
0.
8
f
;
private
static
final
float
MIN_TEXT_XSCALE
=
0.
75
f
;
private
final
UiHandler
mHandler
=
new
UiHandler
(
this
);
...
...
@@ -177,12 +177,12 @@ public class CandidateView extends LinearLayout implements OnClickListener, OnLo
public
int
mVariableWidthForWords
;
public
float
mScaleX
;
public
CandidateViewLayoutParams
(
Resources
res
,
View
divider
,
View
control
,
public
CandidateViewLayoutParams
(
Resources
res
,
TextView
word
,
View
divider
,
View
control
,
int
autoCorrectHighlight
)
{
mPaint
=
new
TextPaint
();
final
float
textSize
=
res
.
getDimension
(
R
.
dimen
.
candidate_text_size
);
mPaint
.
setTextSize
(
textSize
);
mPadding
=
res
.
getDimensionPixelSize
(
R
.
dimen
.
candidate_padding
);
mPadding
=
word
.
getCompoundPaddingLeft
()
+
word
.
getCompoundPaddingRight
(
);
divider
.
measure
(
WRAP_CONTENT
,
MATCH_PARENT
);
mDividerWidth
=
divider
.
getMeasuredWidth
();
mDividerHeight
=
divider
.
getMeasuredHeight
();
...
...
@@ -224,11 +224,11 @@ public class CandidateView extends LinearLayout implements OnClickListener, OnLo
public
void
tryLayout
()
{
final
int
maxCount
=
mCountInStrip
;
final
int
dividers
=
mDividerWidth
*
(
maxCount
-
1
);
mConstantWidthForPaddings
=
dividers
+
mPadding
*
maxCount
*
2
;
mConstantWidthForPaddings
=
dividers
+
mPadding
*
maxCount
;
mAvailableWidthForWords
=
mMaxWidth
-
mConstantWidthForPaddings
;
mPaint
.
setTextScaleX
(
mScaleX
);
final
int
maxFixedWidthForWord
=
(
mMaxWidth
-
dividers
)
/
maxCount
-
mPadding
*
2
;
final
int
maxFixedWidthForWord
=
(
mMaxWidth
-
dividers
)
/
maxCount
-
mPadding
;
mCanUseFixedWidthColumns
=
true
;
mVariableWidthForWords
=
0
;
for
(
int
i
=
0
;
i
<
maxCount
;
i
++)
{
...
...
@@ -349,8 +349,8 @@ public class CandidateView extends LinearLayout implements OnClickListener, OnLo
});
mCandidatesPaneControl
.
measure
(
WRAP_CONTENT
,
WRAP_CONTENT
);
mParams
=
new
CandidateViewLayoutParams
(
res
,
mDividers
.
get
(
0
),
mCandidatesPaneControl
,
mAutoCorrectHighlight
);
mParams
=
new
CandidateViewLayoutParams
(
res
,
mWords
.
get
(
0
)
,
mDividers
.
get
(
0
),
mCandidatesPaneControl
,
mAutoCorrectHighlight
);
}
/**
...
...
@@ -493,7 +493,7 @@ public class CandidateView extends LinearLayout implements OnClickListener, OnLo
if
(
params
.
mCanUseFixedWidthColumns
)
{
setLayoutWeight
(
word
,
1.0f
,
mCandidateStripHeight
);
}
else
{
final
int
width
=
getTextWidth
(
text
,
paint
)
+
params
.
mPadding
*
2
;
final
int
width
=
getTextWidth
(
text
,
paint
)
+
params
.
mPadding
;
setLayoutWeight
(
word
,
width
,
mCandidateStripHeight
);
}
if
(
info
!=
null
)
{
...
...
@@ -507,7 +507,7 @@ public class CandidateView extends LinearLayout implements OnClickListener, OnLo
}
else
{
paint
.
setTextScaleX
(
1.0f
);
final
int
textWidth
=
getTextWidth
(
styled
,
paint
);
int
available
=
paneWidth
-
x
-
params
.
mPadding
*
2
;
int
available
=
paneWidth
-
x
-
params
.
mPadding
;
if
(
textWidth
>=
available
)
{
// Needs new row, centering previous row.
centeringCandidates
(
centeringFrom
,
lastView
,
x
,
paneWidth
);
...
...
@@ -523,7 +523,7 @@ public class CandidateView extends LinearLayout implements OnClickListener, OnLo
params
.
mDividerWidth
,
params
.
mDividerHeight
);
x
+=
params
.
mDividerWidth
;
}
available
=
paneWidth
-
x
-
params
.
mPadding
*
2
;
available
=
paneWidth
-
x
-
params
.
mPadding
;
text
=
getEllipsizedText
(
styled
,
available
,
paint
);
scaleX
=
paint
.
getTextScaleX
();
word
.
setText
(
text
);
...
...
@@ -604,15 +604,17 @@ public class CandidateView extends LinearLayout implements OnClickListener, OnLo
private
static
int
getTextWidth
(
CharSequence
text
,
TextPaint
paint
)
{
if
(
TextUtils
.
isEmpty
(
text
))
return
0
;
final
Typeface
savedTypeface
=
paint
.
getTypeface
();
paint
.
setTypeface
(
getTextTypeface
(
text
));
final
int
len
=
text
.
length
();
final
float
[]
widths
=
new
float
[
len
];
final
int
count
=
paint
.
getTextWidths
(
text
,
0
,
len
,
widths
);
floa
t
width
=
0
;
in
t
width
=
0
;
for
(
int
i
=
0
;
i
<
count
;
i
++)
{
width
+=
widths
[
i
];
width
+=
Math
.
round
(
widths
[
i
]
+
0.5f
)
;
}
return
(
int
)
Math
.
round
(
width
+
0.5
);
paint
.
setTypeface
(
savedTypeface
);
return
width
;
}
private
static
Typeface
getTextTypeface
(
CharSequence
text
)
{
...
...
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