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
2f83e9e5
Commit
2f83e9e5
authored
12 years ago
by
Tadashi G. Takaoka
Browse files
Options
Downloads
Patches
Plain Diff
Can override key-style
Bug: 6412932 Change-Id: I9576ae5b42bcc54cfd8ede0bae5148f3b04c1978
parent
30ce0c4e
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
+1
-14
1 addition, 14 deletions
java/src/com/android/inputmethod/keyboard/Key.java
java/src/com/android/inputmethod/keyboard/internal/KeyStyles.java
+46
-42
46 additions, 42 deletions
.../com/android/inputmethod/keyboard/internal/KeyStyles.java
with
47 additions
and
56 deletions
java/src/com/android/inputmethod/keyboard/Key.java
+
1
−
14
View file @
2f83e9e5
...
...
@@ -33,12 +33,10 @@ import android.util.Xml;
import
com.android.inputmethod.keyboard.internal.KeySpecParser
;
import
com.android.inputmethod.keyboard.internal.KeySpecParser.MoreKeySpec
;
import
com.android.inputmethod.keyboard.internal.KeyStyles
;
import
com.android.inputmethod.keyboard.internal.KeyStyles.KeyStyle
;
import
com.android.inputmethod.keyboard.internal.KeyboardIconsSet
;
import
com.android.inputmethod.latin.R
;
import
com.android.inputmethod.latin.StringUtils
;
import
com.android.inputmethod.latin.XmlParseUtils
;
import
org.xmlpull.v1.XmlPullParser
;
import
org.xmlpull.v1.XmlPullParserException
;
...
...
@@ -201,7 +199,6 @@ public class Key {
*/
public
Key
(
Resources
res
,
Keyboard
.
Params
params
,
Keyboard
.
Builder
.
Row
row
,
XmlPullParser
parser
)
throws
XmlPullParserException
{
final
KeyStyles
keyStyles
=
params
.
mKeyStyles
;
final
float
horizontalGap
=
isSpacer
()
?
0
:
params
.
mHorizontalGap
;
final
int
keyHeight
=
row
.
mRowHeight
;
mVerticalGap
=
params
.
mVerticalGap
;
...
...
@@ -210,17 +207,7 @@ public class Key {
final
TypedArray
keyAttr
=
res
.
obtainAttributes
(
Xml
.
asAttributeSet
(
parser
),
R
.
styleable
.
Keyboard_Key
);
final
KeyStyle
style
;
if
(
keyAttr
.
hasValue
(
R
.
styleable
.
Keyboard_Key_keyStyle
))
{
String
styleName
=
keyAttr
.
getString
(
R
.
styleable
.
Keyboard_Key_keyStyle
);
style
=
keyStyles
.
getKeyStyle
(
styleName
);
if
(
style
==
null
)
{
throw
new
XmlParseUtils
.
ParseException
(
"Unknown key style: "
+
styleName
,
parser
);
}
}
else
{
style
=
keyStyles
.
getEmptyKeyStyle
();
}
final
KeyStyle
style
=
params
.
mKeyStyles
.
getKeyStyle
(
keyAttr
,
parser
);
final
float
keyXPos
=
row
.
getKeyX
(
keyAttr
);
final
float
keyWidth
=
row
.
getKeyWidth
(
keyAttr
,
keyXPos
);
final
int
keyYPos
=
row
.
getKeyY
();
...
...
This diff is collapsed.
Click to expand it.
java/src/com/android/inputmethod/keyboard/internal/KeyStyles.java
+
46
−
42
View file @
2f83e9e5
...
...
@@ -32,24 +32,19 @@ public class KeyStyles {
private
static
final
String
TAG
=
KeyStyles
.
class
.
getSimpleName
();
private
static
final
boolean
DEBUG
=
false
;
private
final
HashMap
<
String
,
DeclaredKeyStyle
>
mStyles
=
new
HashMap
<
String
,
DeclaredKeyStyle
>();
final
HashMap
<
String
,
KeyStyle
>
mStyles
=
new
HashMap
<
String
,
KeyStyle
>();
private
final
KeyboardTextsSet
mTextsSet
;
final
KeyboardTextsSet
mTextsSet
;
private
final
KeyStyle
mEmptyKeyStyle
;
private
static
final
String
EMPTY_STYLE_NAME
=
"<empty>"
;
public
KeyStyles
(
KeyboardTextsSet
textsSet
)
{
mTextsSet
=
textsSet
;
mEmptyKeyStyle
=
new
EmptyKeyStyle
(
textsSet
);
mEmptyKeyStyle
=
new
EmptyKeyStyle
();
mStyles
.
put
(
EMPTY_STYLE_NAME
,
mEmptyKeyStyle
);
}
public
static
abstract
class
KeyStyle
{
protected
final
KeyboardTextsSet
mTextsSet
;
public
KeyStyle
(
KeyboardTextsSet
textsSet
)
{
mTextsSet
=
textsSet
;
}
public
abstract
class
KeyStyle
{
public
abstract
String
[]
getStringArray
(
TypedArray
a
,
int
index
);
public
abstract
String
getString
(
TypedArray
a
,
int
index
);
public
abstract
int
getInt
(
TypedArray
a
,
int
index
,
int
defaultValue
);
...
...
@@ -70,11 +65,7 @@ public class KeyStyles {
}
}
private
static
class
EmptyKeyStyle
extends
KeyStyle
{
public
EmptyKeyStyle
(
KeyboardTextsSet
textsSet
)
{
super
(
textsSet
);
}
class
EmptyKeyStyle
extends
KeyStyle
{
@Override
public
String
[]
getStringArray
(
TypedArray
a
,
int
index
)
{
return
parseStringArray
(
a
,
index
);
...
...
@@ -96,11 +87,12 @@ public class KeyStyles {
}
}
private
static
class
DeclaredKeyStyle
extends
KeyStyle
{
private
class
DeclaredKeyStyle
extends
KeyStyle
{
private
final
String
mParentStyleName
;
private
final
HashMap
<
Integer
,
Object
>
mStyleAttributes
=
new
HashMap
<
Integer
,
Object
>();
public
DeclaredKeyStyle
(
KeyboardTextsSet
textsSet
)
{
super
(
textsSet
)
;
public
DeclaredKeyStyle
(
String
parentStyleName
)
{
mParentStyleName
=
parentStyleName
;
}
@Override
...
...
@@ -108,7 +100,11 @@ public class KeyStyles {
if
(
a
.
hasValue
(
index
))
{
return
parseStringArray
(
a
,
index
);
}
return
(
String
[])
mStyleAttributes
.
get
(
index
);
if
(
mStyleAttributes
.
containsKey
(
index
))
{
return
(
String
[])
mStyleAttributes
.
get
(
index
);
}
final
KeyStyle
parentStyle
=
mStyles
.
get
(
mParentStyleName
);
return
parentStyle
.
getStringArray
(
a
,
index
);
}
@Override
...
...
@@ -116,7 +112,11 @@ public class KeyStyles {
if
(
a
.
hasValue
(
index
))
{
return
parseString
(
a
,
index
);
}
return
(
String
)
mStyleAttributes
.
get
(
index
);
if
(
mStyleAttributes
.
containsKey
(
index
))
{
return
(
String
)
mStyleAttributes
.
get
(
index
);
}
final
KeyStyle
parentStyle
=
mStyles
.
get
(
mParentStyleName
);
return
parentStyle
.
getString
(
a
,
index
);
}
@Override
...
...
@@ -124,15 +124,21 @@ public class KeyStyles {
if
(
a
.
hasValue
(
index
))
{
return
a
.
getInt
(
index
,
defaultValue
);
}
final
Integer
styleValue
=
(
Integer
)
mStyleAttributes
.
get
(
index
);
return
styleValue
!=
null
?
styleValue
:
defaultValue
;
if
(
mStyleAttributes
.
containsKey
(
index
))
{
return
(
Integer
)
mStyleAttributes
.
get
(
index
);
}
final
KeyStyle
parentStyle
=
mStyles
.
get
(
mParentStyleName
);
return
parentStyle
.
getInt
(
a
,
index
,
defaultValue
);
}
@Override
public
int
getFlag
(
TypedArray
a
,
int
index
)
{
final
int
value
=
a
.
getInt
(
index
,
0
);
final
Integer
styleValue
=
(
Integer
)
mStyleAttributes
.
get
(
index
);
return
(
styleValue
!=
null
?
styleValue
:
0
)
|
value
;
int
value
=
a
.
getInt
(
index
,
0
);
if
(
mStyleAttributes
.
containsKey
(
index
))
{
value
|=
(
Integer
)
mStyleAttributes
.
get
(
index
);
}
final
KeyStyle
parentStyle
=
mStyles
.
get
(
mParentStyleName
);
return
value
|
parentStyle
.
getFlag
(
a
,
index
);
}
void
readKeyAttributes
(
TypedArray
keyAttr
)
{
...
...
@@ -177,10 +183,6 @@ public class KeyStyles {
mStyleAttributes
.
put
(
index
,
parseStringArray
(
a
,
index
));
}
}
void
addParentStyleAttributes
(
DeclaredKeyStyle
parentStyle
)
{
mStyleAttributes
.
putAll
(
parentStyle
.
mStyleAttributes
);
}
}
public
void
parseKeyStyleAttributes
(
TypedArray
keyStyleAttr
,
TypedArray
keyAttrs
,
...
...
@@ -195,26 +197,28 @@ public class KeyStyles {
}
}
final
DeclaredKeyStyle
style
=
new
DeclaredKeyStyle
(
mTextsSet
)
;
String
parentStyleName
=
EMPTY_STYLE_NAME
;
if
(
keyStyleAttr
.
hasValue
(
R
.
styleable
.
Keyboard_KeyStyle_parentStyle
))
{
final
String
parentStyle
=
keyStyleAttr
.
getString
(
R
.
styleable
.
Keyboard_KeyStyle_parentStyle
);
final
DeclaredKeyStyle
parent
=
mStyles
.
get
(
parentStyle
);
if
(
parent
==
null
)
{
parentStyleName
=
keyStyleAttr
.
getString
(
R
.
styleable
.
Keyboard_KeyStyle_parentStyle
);
if
(!
mStyles
.
containsKey
(
parentStyleName
))
{
throw
new
XmlParseUtils
.
ParseException
(
"Unknown parentStyle "
+
parentStyle
,
parser
);
"Unknown parentStyle "
+
parentStyle
Name
,
parser
);
}
style
.
addParentStyleAttributes
(
parent
);
}
final
DeclaredKeyStyle
style
=
new
DeclaredKeyStyle
(
parentStyleName
);
style
.
readKeyAttributes
(
keyAttrs
);
mStyles
.
put
(
styleName
,
style
);
}
public
KeyStyle
getKeyStyle
(
String
styleName
)
{
public
KeyStyle
getKeyStyle
(
TypedArray
keyAttr
,
XmlPullParser
parser
)
throws
XmlParseUtils
.
ParseException
{
if
(!
keyAttr
.
hasValue
(
R
.
styleable
.
Keyboard_Key_keyStyle
))
{
return
mEmptyKeyStyle
;
}
final
String
styleName
=
keyAttr
.
getString
(
R
.
styleable
.
Keyboard_Key_keyStyle
);
if
(!
mStyles
.
containsKey
(
styleName
))
{
throw
new
XmlParseUtils
.
ParseException
(
"Unknown key style: "
+
styleName
,
parser
);
}
return
mStyles
.
get
(
styleName
);
}
public
KeyStyle
getEmptyKeyStyle
()
{
return
mEmptyKeyStyle
;
}
}
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