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
17f53103
Commit
17f53103
authored
13 years ago
by
Tadashi G. Takaoka
Browse files
Options
Downloads
Patches
Plain Diff
Fix KeyStyles to be able to override the value in style
Change-Id: Ib7476cdc0f81dfeb6292ef663e9dbab6d2b949ba
parent
4c5daa8a
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
java/src/com/android/inputmethod/keyboard/Key.java
+2
-2
2 additions, 2 deletions
java/src/com/android/inputmethod/keyboard/Key.java
java/src/com/android/inputmethod/keyboard/internal/KeyStyles.java
+58
-49
58 additions, 49 deletions
.../com/android/inputmethod/keyboard/internal/KeyStyles.java
with
60 additions
and
51 deletions
java/src/com/android/inputmethod/keyboard/Key.java
+
2
−
2
View file @
17f53103
...
@@ -228,9 +228,9 @@ public class Key {
...
@@ -228,9 +228,9 @@ public class Key {
mDisabledIconId
=
style
.
getInt
(
keyAttr
,
mDisabledIconId
=
style
.
getInt
(
keyAttr
,
R
.
styleable
.
Keyboard_Key_keyIconDisabled
,
KeyboardIconsSet
.
ICON_UNDEFINED
);
R
.
styleable
.
Keyboard_Key_keyIconDisabled
,
KeyboardIconsSet
.
ICON_UNDEFINED
);
mLabelFlags
=
style
.
getFlag
(
keyAttr
,
R
.
styleable
.
Keyboard_Key_keyLabelFlags
,
0
);
mLabelFlags
=
style
.
getFlag
(
keyAttr
,
R
.
styleable
.
Keyboard_Key_keyLabelFlags
);
final
boolean
preserveCase
=
(
mLabelFlags
&
LABEL_FLAGS_PRESERVE_CASE
)
!=
0
;
final
boolean
preserveCase
=
(
mLabelFlags
&
LABEL_FLAGS_PRESERVE_CASE
)
!=
0
;
int
actionFlags
=
style
.
getFlag
(
keyAttr
,
R
.
styleable
.
Keyboard_Key_keyActionFlags
,
0
);
int
actionFlags
=
style
.
getFlag
(
keyAttr
,
R
.
styleable
.
Keyboard_Key_keyActionFlags
);
final
String
[]
additionalMoreKeys
=
style
.
getStringArray
(
final
String
[]
additionalMoreKeys
=
style
.
getStringArray
(
keyAttr
,
R
.
styleable
.
Keyboard_Key_additionalMoreKeys
);
keyAttr
,
R
.
styleable
.
Keyboard_Key_additionalMoreKeys
);
final
String
[]
moreKeys
=
KeySpecParser
.
insertAddtionalMoreKeys
(
style
.
getStringArray
(
final
String
[]
moreKeys
=
KeySpecParser
.
insertAddtionalMoreKeys
(
style
.
getStringArray
(
...
...
This diff is collapsed.
Click to expand it.
java/src/com/android/inputmethod/keyboard/internal/KeyStyles.java
+
58
−
49
View file @
17f53103
...
@@ -40,17 +40,13 @@ public class KeyStyles {
...
@@ -40,17 +40,13 @@ public class KeyStyles {
public
String
[]
getStringArray
(
TypedArray
a
,
int
index
);
public
String
[]
getStringArray
(
TypedArray
a
,
int
index
);
public
String
getString
(
TypedArray
a
,
int
index
);
public
String
getString
(
TypedArray
a
,
int
index
);
public
int
getInt
(
TypedArray
a
,
int
index
,
int
defaultValue
);
public
int
getInt
(
TypedArray
a
,
int
index
,
int
defaultValue
);
public
int
getFlag
(
TypedArray
a
,
int
index
,
int
defaultValue
);
public
int
getFlag
(
TypedArray
a
,
int
index
);
}
}
private
static
class
EmptyKeyStyle
implements
KeyStyle
{
static
class
EmptyKeyStyle
implements
KeyStyle
{
EmptyKeyStyle
()
{
// Nothing to do.
}
@Override
@Override
public
String
[]
getStringArray
(
TypedArray
a
,
int
index
)
{
public
String
[]
getStringArray
(
TypedArray
a
,
int
index
)
{
return
parseStringArray
(
a
,
index
);
return
KeyStyles
.
parseStringArray
(
a
,
index
);
}
}
@Override
@Override
...
@@ -64,50 +60,47 @@ public class KeyStyles {
...
@@ -64,50 +60,47 @@ public class KeyStyles {
}
}
@Override
@Override
public
int
getFlag
(
TypedArray
a
,
int
index
,
int
defaultValue
)
{
public
int
getFlag
(
TypedArray
a
,
int
index
)
{
return
a
.
getInt
(
index
,
defaultValue
);
return
a
.
getInt
(
index
,
0
);
}
protected
static
String
[]
parseStringArray
(
TypedArray
a
,
int
index
)
{
if
(!
a
.
hasValue
(
index
))
return
null
;
return
KeySpecParser
.
parseCsvString
(
a
.
getString
(
index
),
a
.
getResources
(),
R
.
string
.
english_ime_name
);
}
}
}
}
private
static
class
DeclaredKeyStyle
ext
en
d
s
Empty
KeyStyle
{
static
class
DeclaredKeyStyle
implem
en
t
s
KeyStyle
{
private
final
HashMap
<
Integer
,
Object
>
mAttributes
=
new
HashMap
<
Integer
,
Object
>();
private
final
HashMap
<
Integer
,
Object
>
m
Style
Attributes
=
new
HashMap
<
Integer
,
Object
>();
@Override
@Override
public
String
[]
getStringArray
(
TypedArray
a
,
int
index
)
{
public
String
[]
getStringArray
(
TypedArray
a
,
int
index
)
{
return
a
.
hasValue
(
index
)
if
(
a
.
hasValue
(
index
))
{
?
super
.
getStringArray
(
a
,
index
)
:
(
String
[])
mAttributes
.
get
(
index
);
return
parseStringArray
(
a
,
index
);
}
return
(
String
[])
mStyleAttributes
.
get
(
index
);
}
}
@Override
@Override
public
String
getString
(
TypedArray
a
,
int
index
)
{
public
String
getString
(
TypedArray
a
,
int
index
)
{
return
a
.
hasValue
(
index
)
if
(
a
.
hasValue
(
index
))
{
?
super
.
getString
(
a
,
index
)
:
(
String
)
mAttributes
.
get
(
index
);
return
a
.
getString
(
index
);
}
return
(
String
)
mStyleAttributes
.
get
(
index
);
}
}
@Override
@Override
public
int
getInt
(
TypedArray
a
,
int
index
,
int
defaultValue
)
{
public
int
getInt
(
TypedArray
a
,
int
index
,
int
defaultValue
)
{
final
Integer
value
=
(
Integer
)
mAttributes
.
get
(
index
);
if
(
a
.
hasValue
(
index
))
{
return
super
.
getInt
(
a
,
index
,
(
value
!=
null
)
?
value
:
defaultValue
);
return
a
.
getInt
(
index
,
defaultValue
);
}
final
Integer
styleValue
=
(
Integer
)
mStyleAttributes
.
get
(
index
);
return
styleValue
!=
null
?
styleValue
:
defaultValue
;
}
}
@Override
@Override
public
int
getFlag
(
TypedArray
a
,
int
index
,
int
defaultValue
)
{
public
int
getFlag
(
TypedArray
a
,
int
index
)
{
final
Integer
value
=
(
Integer
)
mAttributes
.
get
(
index
);
final
int
value
=
a
.
getInt
(
index
,
0
);
return
super
.
getFlag
(
a
,
index
,
defaultValue
)
|
(
value
!=
null
?
value
:
0
);
final
Integer
styleValue
=
(
Integer
)
mStyleAttributes
.
get
(
index
);
}
return
(
styleValue
!=
null
?
styleValue
:
0
)
|
value
;
DeclaredKeyStyle
()
{
super
();
}
}
void
parseKeyStyle
Attributes
(
TypedArray
keyAttr
)
{
void
readKey
Attributes
(
TypedArray
keyAttr
)
{
// TODO: Currently not all Key attributes can be declared as style.
// TODO: Currently not all Key attributes can be declared as style.
readInt
(
keyAttr
,
R
.
styleable
.
Keyboard_Key_code
);
readInt
(
keyAttr
,
R
.
styleable
.
Keyboard_Key_code
);
readInt
(
keyAttr
,
R
.
styleable
.
Keyboard_Key_altCode
);
readInt
(
keyAttr
,
R
.
styleable
.
Keyboard_Key_altCode
);
...
@@ -126,52 +119,68 @@ public class KeyStyles {
...
@@ -126,52 +119,68 @@ public class KeyStyles {
}
}
private
void
readString
(
TypedArray
a
,
int
index
)
{
private
void
readString
(
TypedArray
a
,
int
index
)
{
if
(
a
.
hasValue
(
index
))
if
(
a
.
hasValue
(
index
))
{
mAttributes
.
put
(
index
,
a
.
getString
(
index
));
mStyleAttributes
.
put
(
index
,
a
.
getString
(
index
));
}
}
}
private
void
readInt
(
TypedArray
a
,
int
index
)
{
private
void
readInt
(
TypedArray
a
,
int
index
)
{
if
(
a
.
hasValue
(
index
))
if
(
a
.
hasValue
(
index
))
{
mAttributes
.
put
(
index
,
a
.
getInt
(
index
,
0
));
mStyleAttributes
.
put
(
index
,
a
.
getInt
(
index
,
0
));
}
}
}
private
void
readFlag
(
TypedArray
a
,
int
index
)
{
private
void
readFlag
(
TypedArray
a
,
int
index
)
{
final
Integer
value
=
(
Integer
)
mAttributes
.
get
(
index
);
final
Integer
value
=
(
Integer
)
mStyleAttributes
.
get
(
index
);
if
(
a
.
hasValue
(
index
))
if
(
a
.
hasValue
(
index
))
{
mAttributes
.
put
(
index
,
a
.
getInt
(
index
,
0
)
|
(
value
!=
null
?
value
:
0
));
mStyleAttributes
.
put
(
index
,
a
.
getInt
(
index
,
0
)
|
(
value
!=
null
?
value
:
0
));
}
}
}
private
void
readStringArray
(
TypedArray
a
,
int
index
)
{
private
void
readStringArray
(
TypedArray
a
,
int
index
)
{
final
String
[]
value
=
parseStringArray
(
a
,
index
);
final
String
[]
value
=
parseStringArray
(
a
,
index
);
if
(
value
!=
null
)
if
(
value
!=
null
)
{
mAttributes
.
put
(
index
,
value
);
mStyleAttributes
.
put
(
index
,
value
);
}
}
void
addParentStyleAttributes
(
DeclaredKeyStyle
parentStyle
)
{
mStyleAttributes
.
putAll
(
parentStyle
.
mStyleAttributes
);
}
}
}
void
addParent
(
DeclaredKeyStyle
parentStyle
)
{
static
String
[]
parseStringArray
(
TypedArray
a
,
int
index
)
{
mAttributes
.
putAll
(
parentStyle
.
mAttributes
);
if
(
a
.
hasValue
(
index
))
{
return
KeySpecParser
.
parseCsvString
(
a
.
getString
(
index
),
a
.
getResources
(),
R
.
string
.
english_ime_name
);
}
}
return
null
;
}
}
public
void
parseKeyStyleAttributes
(
TypedArray
keyStyleAttr
,
TypedArray
keyAttrs
,
public
void
parseKeyStyleAttributes
(
TypedArray
keyStyleAttr
,
TypedArray
keyAttrs
,
XmlPullParser
parser
)
throws
XmlPullParserException
{
XmlPullParser
parser
)
throws
XmlPullParserException
{
final
String
styleName
=
keyStyleAttr
.
getString
(
R
.
styleable
.
Keyboard_KeyStyle_styleName
);
final
String
styleName
=
keyStyleAttr
.
getString
(
R
.
styleable
.
Keyboard_KeyStyle_styleName
);
if
(
DEBUG
)
Log
.
d
(
TAG
,
String
.
format
(
"<%s styleName=%s />"
,
if
(
DEBUG
)
{
Keyboard
.
Builder
.
TAG_KEY_STYLE
,
styleName
));
Log
.
d
(
TAG
,
String
.
format
(
"<%s styleName=%s />"
,
if
(
mStyles
.
containsKey
(
styleName
))
Keyboard
.
Builder
.
TAG_KEY_STYLE
,
styleName
));
}
if
(
mStyles
.
containsKey
(
styleName
))
{
throw
new
XmlParseUtils
.
ParseException
(
throw
new
XmlParseUtils
.
ParseException
(
"duplicate key style declared: "
+
styleName
,
parser
);
"duplicate key style declared: "
+
styleName
,
parser
);
}
final
DeclaredKeyStyle
style
=
new
DeclaredKeyStyle
();
final
DeclaredKeyStyle
style
=
new
DeclaredKeyStyle
();
if
(
keyStyleAttr
.
hasValue
(
R
.
styleable
.
Keyboard_KeyStyle_parentStyle
))
{
if
(
keyStyleAttr
.
hasValue
(
R
.
styleable
.
Keyboard_KeyStyle_parentStyle
))
{
final
String
parentStyle
=
keyStyleAttr
.
getString
(
final
String
parentStyle
=
keyStyleAttr
.
getString
(
R
.
styleable
.
Keyboard_KeyStyle_parentStyle
);
R
.
styleable
.
Keyboard_KeyStyle_parentStyle
);
final
DeclaredKeyStyle
parent
=
mStyles
.
get
(
parentStyle
);
final
DeclaredKeyStyle
parent
=
mStyles
.
get
(
parentStyle
);
if
(
parent
==
null
)
if
(
parent
==
null
)
{
throw
new
XmlParseUtils
.
ParseException
(
throw
new
XmlParseUtils
.
ParseException
(
"Unknown parentStyle "
+
parentStyle
,
parser
);
"Unknown parentStyle "
+
parentStyle
,
parser
);
style
.
addParent
(
parent
);
}
style
.
addParentStyleAttributes
(
parent
);
}
}
style
.
parseKeyStyle
Attributes
(
keyAttrs
);
style
.
readKey
Attributes
(
keyAttrs
);
mStyles
.
put
(
styleName
,
style
);
mStyles
.
put
(
styleName
,
style
);
}
}
...
...
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