am aef4f906: Merge "Move themeId and touch correction data to Keyboard style"

* commit 'aef4f906ff1330042a06a7d9697b27b5db2bb121':
  Move themeId and touch correction data to Keyboard style
main
Tadashi G. Takaoka 2011-09-30 20:04:05 -07:00 committed by Android Git Automerger
commit 10d90a227d
9 changed files with 50 additions and 46 deletions

View File

@ -16,7 +16,6 @@
<resources> <resources>
<declare-styleable name="KeyboardTheme"> <declare-styleable name="KeyboardTheme">
<attr name="themeId" format="integer" />
<!-- Keyboard style --> <!-- Keyboard style -->
<attr name="keyboardStyle" format="reference" /> <attr name="keyboardStyle" format="reference" />
<!-- LatinKeyboard style --> <!-- LatinKeyboard style -->
@ -34,8 +33,6 @@
<attr name="moreSuggestionsViewStyle" format="reference" /> <attr name="moreSuggestionsViewStyle" format="reference" />
<attr name="suggestionBackgroundStyle" format="reference" /> <attr name="suggestionBackgroundStyle" format="reference" />
<attr name="suggestionPreviewBackgroundStyle" format="reference" /> <attr name="suggestionPreviewBackgroundStyle" format="reference" />
<!-- Touch position correction -->
<attr name="touchPositionCorrectionData" format="reference" />
</declare-styleable> </declare-styleable>
<declare-styleable name="KeyboardView"> <declare-styleable name="KeyboardView">
@ -140,6 +137,9 @@
</declare-styleable> </declare-styleable>
<declare-styleable name="Keyboard"> <declare-styleable name="Keyboard">
<attr name="themeId" format="integer" />
<!-- Touch position correction -->
<attr name="touchPositionCorrectionData" format="reference" />
<!-- Default keyboard height --> <!-- Default keyboard height -->
<attr name="keyboardHeight" format="dimension|fraction" /> <attr name="keyboardHeight" format="dimension|fraction" />
<!-- Maximum keyboard height, in pixels or percentage of display height --> <!-- Maximum keyboard height, in pixels or percentage of display height -->

View File

@ -17,6 +17,8 @@
<resources> <resources>
<!-- Theme "Basic" --> <!-- Theme "Basic" -->
<style name="Keyboard"> <style name="Keyboard">
<item name="themeId">0</item>
<item name="touchPositionCorrectionData">@array/touch_position_correction_data_empty</item>
<item name="rowHeight">25%p</item> <item name="rowHeight">25%p</item>
<item name="keyboardHeight">@dimen/keyboardHeight</item> <item name="keyboardHeight">@dimen/keyboardHeight</item>
<item name="maxKeyboardHeight">@fraction/maxKeyboardHeight</item> <item name="maxKeyboardHeight">@fraction/maxKeyboardHeight</item>
@ -118,6 +120,12 @@
<item name="android:background">@drawable/suggestion_feedback_background</item> <item name="android:background">@drawable/suggestion_feedback_background</item>
</style> </style>
<!-- Theme "Basic high contrast" --> <!-- Theme "Basic high contrast" -->
<style
name="Keyboard.HighContrast"
parent="Keyboard"
>
<item name="themeId">1</item>
</style>
<style <style
name="KeyboardView.HighContrast" name="KeyboardView.HighContrast"
parent="KeyboardView" parent="KeyboardView"
@ -130,6 +138,7 @@
name="Keyboard.Stone" name="Keyboard.Stone"
parent="Keyboard" parent="Keyboard"
> >
<item name="themeId">6</item>
<item name="keyboardHeight">@dimen/keyboardHeight_stone</item> <item name="keyboardHeight">@dimen/keyboardHeight_stone</item>
<item name="keyboardTopPadding">@fraction/keyboard_top_padding_stone</item> <item name="keyboardTopPadding">@fraction/keyboard_top_padding_stone</item>
<item name="keyboardBottomPadding">@fraction/keyboard_bottom_padding_stone</item> <item name="keyboardBottomPadding">@fraction/keyboard_bottom_padding_stone</item>
@ -173,6 +182,12 @@
<item name="shadowColor">#FFFFFFFF</item> <item name="shadowColor">#FFFFFFFF</item>
</style> </style>
<!-- Theme "Stone bold" --> <!-- Theme "Stone bold" -->
<style
name="Keyboard.Stone.Bold"
parent="Keyboard.Stone"
>
<item name="themeId">7</item>
</style>
<style <style
name="KeyboardView.Stone.Bold" name="KeyboardView.Stone.Bold"
parent="KeyboardView.Stone" parent="KeyboardView.Stone"
@ -184,6 +199,8 @@
name="Keyboard.Gingerbread" name="Keyboard.Gingerbread"
parent="Keyboard" parent="Keyboard"
> >
<item name="themeId">8</item>
<item name="touchPositionCorrectionData">@array/touch_position_correction_data_gingerbread</item>
<item name="horizontalGap">@fraction/key_horizontal_gap_gb</item> <item name="horizontalGap">@fraction/key_horizontal_gap_gb</item>
<item name="verticalGap">@fraction/key_bottom_gap_gb</item> <item name="verticalGap">@fraction/key_bottom_gap_gb</item>
</style> </style>
@ -214,10 +231,12 @@
name="Keyboard.IceCreamSandwich" name="Keyboard.IceCreamSandwich"
parent="Keyboard" parent="Keyboard"
> >
<item name="themeId">5</item>
<item name="keyboardTopPadding">@fraction/keyboard_top_padding_ics</item> <item name="keyboardTopPadding">@fraction/keyboard_top_padding_ics</item>
<item name="keyboardBottomPadding">@fraction/keyboard_bottom_padding_ics</item> <item name="keyboardBottomPadding">@fraction/keyboard_bottom_padding_ics</item>
<item name="horizontalGap">@fraction/key_horizontal_gap_ics</item> <item name="horizontalGap">@fraction/key_horizontal_gap_ics</item>
<item name="verticalGap">@fraction/key_bottom_gap_ics</item> <item name="verticalGap">@fraction/key_bottom_gap_ics</item>
<item name="touchPositionCorrectionData">@array/touch_position_correction_data_ice_cream_sandwich</item>
</style> </style>
<style <style
name="LatinKeyboard.IceCreamSandwich" name="LatinKeyboard.IceCreamSandwich"

View File

@ -16,8 +16,7 @@
<resources> <resources>
<style name="KeyboardTheme.HighContrast" parent="KeyboardIcons"> <style name="KeyboardTheme.HighContrast" parent="KeyboardIcons">
<item name="themeId">1</item> <item name="keyboardStyle">@style/Keyboard.HighContrast</item>
<item name="keyboardStyle">@style/Keyboard</item>
<item name="latinKeyboardStyle">@style/LatinKeyboard</item> <item name="latinKeyboardStyle">@style/LatinKeyboard</item>
<item name="keyboardViewStyle">@style/KeyboardView.HighContrast</item> <item name="keyboardViewStyle">@style/KeyboardView.HighContrast</item>
<item name="miniKeyboardStyle">@style/MiniKeyboard</item> <item name="miniKeyboardStyle">@style/MiniKeyboard</item>
@ -28,6 +27,5 @@
<item name="moreSuggestionsViewStyle">@style/MoreSuggestionsViewStyle</item> <item name="moreSuggestionsViewStyle">@style/MoreSuggestionsViewStyle</item>
<item name="suggestionBackgroundStyle">@style/SuggestionBackgroundStyle</item> <item name="suggestionBackgroundStyle">@style/SuggestionBackgroundStyle</item>
<item name="suggestionPreviewBackgroundStyle">@style/SuggestionPreviewBackgroundStyle</item> <item name="suggestionPreviewBackgroundStyle">@style/SuggestionPreviewBackgroundStyle</item>
<item name="touchPositionCorrectionData">@array/touch_position_correction_data_empty</item>
</style> </style>
</resources> </resources>

View File

@ -16,7 +16,6 @@
<resources> <resources>
<style name="KeyboardTheme" parent="KeyboardIcons"> <style name="KeyboardTheme" parent="KeyboardIcons">
<item name="themeId">0</item>
<item name="keyboardStyle">@style/Keyboard</item> <item name="keyboardStyle">@style/Keyboard</item>
<item name="latinKeyboardStyle">@style/LatinKeyboard</item> <item name="latinKeyboardStyle">@style/LatinKeyboard</item>
<item name="keyboardViewStyle">@style/KeyboardView</item> <item name="keyboardViewStyle">@style/KeyboardView</item>
@ -28,6 +27,5 @@
<item name="moreSuggestionsViewStyle">@style/MoreSuggestionsViewStyle</item> <item name="moreSuggestionsViewStyle">@style/MoreSuggestionsViewStyle</item>
<item name="suggestionBackgroundStyle">@style/SuggestionBackgroundStyle</item> <item name="suggestionBackgroundStyle">@style/SuggestionBackgroundStyle</item>
<item name="suggestionPreviewBackgroundStyle">@style/SuggestionPreviewBackgroundStyle</item> <item name="suggestionPreviewBackgroundStyle">@style/SuggestionPreviewBackgroundStyle</item>
<item name="touchPositionCorrectionData">@array/touch_position_correction_data_empty</item>
</style> </style>
</resources> </resources>

View File

@ -16,7 +16,6 @@
<resources> <resources>
<style name="KeyboardTheme.Gingerbread" parent="KeyboardIcons"> <style name="KeyboardTheme.Gingerbread" parent="KeyboardIcons">
<item name="themeId">8</item>
<item name="keyboardStyle">@style/Keyboard.Gingerbread</item> <item name="keyboardStyle">@style/Keyboard.Gingerbread</item>
<item name="latinKeyboardStyle">@style/LatinKeyboard</item> <item name="latinKeyboardStyle">@style/LatinKeyboard</item>
<item name="keyboardViewStyle">@style/KeyboardView.Gingerbread</item> <item name="keyboardViewStyle">@style/KeyboardView.Gingerbread</item>
@ -28,6 +27,5 @@
<item name="moreSuggestionsViewStyle">@style/MoreSuggestionsViewStyle</item> <item name="moreSuggestionsViewStyle">@style/MoreSuggestionsViewStyle</item>
<item name="suggestionBackgroundStyle">@style/SuggestionBackgroundStyle</item> <item name="suggestionBackgroundStyle">@style/SuggestionBackgroundStyle</item>
<item name="suggestionPreviewBackgroundStyle">@style/SuggestionPreviewBackgroundStyle</item> <item name="suggestionPreviewBackgroundStyle">@style/SuggestionPreviewBackgroundStyle</item>
<item name="touchPositionCorrectionData">@array/touch_position_correction_data_gingerbread</item>
</style> </style>
</resources> </resources>

View File

@ -16,7 +16,6 @@
<resources> <resources>
<style name="KeyboardTheme.IceCreamSandwich" parent="KeyboardIcons.IceCreamSandwich"> <style name="KeyboardTheme.IceCreamSandwich" parent="KeyboardIcons.IceCreamSandwich">
<item name="themeId">5</item>
<item name="keyboardStyle">@style/Keyboard.IceCreamSandwich</item> <item name="keyboardStyle">@style/Keyboard.IceCreamSandwich</item>
<item name="latinKeyboardStyle">@style/LatinKeyboard.IceCreamSandwich</item> <item name="latinKeyboardStyle">@style/LatinKeyboard.IceCreamSandwich</item>
<item name="keyboardViewStyle">@style/KeyboardView.IceCreamSandwich</item> <item name="keyboardViewStyle">@style/KeyboardView.IceCreamSandwich</item>
@ -28,6 +27,5 @@
<item name="moreSuggestionsViewStyle">@style/MoreSuggestionsViewStyle.IceCreamSandwich</item> <item name="moreSuggestionsViewStyle">@style/MoreSuggestionsViewStyle.IceCreamSandwich</item>
<item name="suggestionBackgroundStyle">@style/SuggestionBackgroundStyle.IceCreamSandwich</item> <item name="suggestionBackgroundStyle">@style/SuggestionBackgroundStyle.IceCreamSandwich</item>
<item name="suggestionPreviewBackgroundStyle">@style/SuggestionPreviewBackgroundStyle.IceCreamSandwich</item> <item name="suggestionPreviewBackgroundStyle">@style/SuggestionPreviewBackgroundStyle.IceCreamSandwich</item>
<item name="touchPositionCorrectionData">@array/touch_position_correction_data_ice_cream_sandwich</item>
</style> </style>
</resources> </resources>

View File

@ -16,7 +16,6 @@
<resources> <resources>
<style name="KeyboardTheme.Stone.Bold" parent="KeyboardIcons.Black"> <style name="KeyboardTheme.Stone.Bold" parent="KeyboardIcons.Black">
<item name="themeId">7</item>
<item name="keyboardStyle">@style/Keyboard.Stone</item> <item name="keyboardStyle">@style/Keyboard.Stone</item>
<item name="latinKeyboardStyle">@style/LatinKeyboard.Stone</item> <item name="latinKeyboardStyle">@style/LatinKeyboard.Stone</item>
<item name="keyboardViewStyle">@style/KeyboardView.Stone.Bold</item> <item name="keyboardViewStyle">@style/KeyboardView.Stone.Bold</item>
@ -28,6 +27,5 @@
<item name="moreSuggestionsViewStyle">@style/MoreSuggestionsViewStyle</item> <item name="moreSuggestionsViewStyle">@style/MoreSuggestionsViewStyle</item>
<item name="suggestionBackgroundStyle">@style/SuggestionBackgroundStyle</item> <item name="suggestionBackgroundStyle">@style/SuggestionBackgroundStyle</item>
<item name="suggestionPreviewBackgroundStyle">@style/SuggestionPreviewBackgroundStyle</item> <item name="suggestionPreviewBackgroundStyle">@style/SuggestionPreviewBackgroundStyle</item>
<item name="touchPositionCorrectionData">@array/touch_position_correction_data_empty</item>
</style> </style>
</resources> </resources>

View File

@ -16,7 +16,6 @@
<resources> <resources>
<style name="KeyboardTheme.Stone" parent="KeyboardIcons.Black"> <style name="KeyboardTheme.Stone" parent="KeyboardIcons.Black">
<item name="themeId">6</item>
<item name="keyboardStyle">@style/Keyboard.Stone</item> <item name="keyboardStyle">@style/Keyboard.Stone</item>
<item name="latinKeyboardStyle">@style/LatinKeyboard.Stone</item> <item name="latinKeyboardStyle">@style/LatinKeyboard.Stone</item>
<item name="keyboardViewStyle">@style/KeyboardView.Stone</item> <item name="keyboardViewStyle">@style/KeyboardView.Stone</item>
@ -28,6 +27,5 @@
<item name="moreSuggestionsViewStyle">@style/MoreSuggestionsViewStyle</item> <item name="moreSuggestionsViewStyle">@style/MoreSuggestionsViewStyle</item>
<item name="suggestionBackgroundStyle">@style/SuggestionBackgroundStyle</item> <item name="suggestionBackgroundStyle">@style/SuggestionBackgroundStyle</item>
<item name="suggestionPreviewBackgroundStyle">@style/SuggestionPreviewBackgroundStyle</item> <item name="suggestionPreviewBackgroundStyle">@style/SuggestionPreviewBackgroundStyle</item>
<item name="touchPositionCorrectionData">@array/touch_position_correction_data_empty</item>
</style> </style>
</resources> </resources>

View File

@ -247,54 +247,50 @@ public class KeyboardBuilder<KP extends KeyboardParams> {
mParams = params; mParams = params;
final TypedArray a = context.obtainStyledAttributes(R.styleable.KeyboardTheme); setTouchPositionCorrectionData(context, params);
mParams.mThemeId = a.getInt(R.styleable.KeyboardTheme_themeId, 0);
a.recycle();
if (!setTouchPositionCorrectionData(context)) { params.GRID_WIDTH = res.getInteger(R.integer.config_keyboard_grid_width);
// In the regression test, setTouchPositionCorrectionData() fails params.GRID_HEIGHT = res.getInteger(R.integer.config_keyboard_grid_height);
mParams.mTouchPositionCorrectionXs = null;
mParams.mTouchPositionCorrectionYs = null;
mParams.mTouchPositionCorrectionRadii = null;
}
mParams.GRID_WIDTH = res.getInteger(R.integer.config_keyboard_grid_width);
mParams.GRID_HEIGHT = res.getInteger(R.integer.config_keyboard_grid_height);
} }
private boolean setTouchPositionCorrectionData(Context context) { private static void setTouchPositionCorrectionData(Context context, KeyboardParams params) {
final TypedArray a = context.obtainStyledAttributes(R.styleable.KeyboardTheme); params.mTouchPositionCorrectionXs = null;
final int resourceId = a.getResourceId( params.mTouchPositionCorrectionYs = null;
R.styleable.KeyboardTheme_touchPositionCorrectionData, 0); params.mTouchPositionCorrectionRadii = null;
final TypedArray a = context.obtainStyledAttributes(R.styleable.Keyboard);
params.mThemeId = a.getInt(R.styleable.Keyboard_themeId, 0);
final int resourceId = a.getResourceId(R.styleable.Keyboard_touchPositionCorrectionData, 0);
if (resourceId == 0) { if (resourceId == 0) {
// In the regression test, we cannot use theme resources if (LatinImeLogger.sDBG)
// TODO: Fix this throw new RuntimeException("touchPositionCorrectionData is not defined");
return false; return;
} }
final String[] data = context.getResources().getStringArray(resourceId); final String[] data = context.getResources().getStringArray(resourceId);
a.recycle(); a.recycle();
final int dataLength = data.length; final int dataLength = data.length;
if (dataLength % TOUCH_POSITION_CORRECTION_RECORD_SIZE != 0) { if (dataLength % TOUCH_POSITION_CORRECTION_RECORD_SIZE != 0) {
if (LatinImeLogger.sDBG) { if (LatinImeLogger.sDBG)
throw new RuntimeException("the size of touch position correction data is invalid"); throw new RuntimeException("the size of touch position correction data is invalid");
} return;
return false;
} }
final int length = dataLength / TOUCH_POSITION_CORRECTION_RECORD_SIZE; final int length = dataLength / TOUCH_POSITION_CORRECTION_RECORD_SIZE;
mParams.mTouchPositionCorrectionXs = new float[length]; params.mTouchPositionCorrectionXs = new float[length];
mParams.mTouchPositionCorrectionYs = new float[length]; params.mTouchPositionCorrectionYs = new float[length];
mParams.mTouchPositionCorrectionRadii = new float[length]; params.mTouchPositionCorrectionRadii = new float[length];
try { try {
for (int i = 0; i < dataLength; ++i) { for (int i = 0; i < dataLength; ++i) {
final int type = i % TOUCH_POSITION_CORRECTION_RECORD_SIZE; final int type = i % TOUCH_POSITION_CORRECTION_RECORD_SIZE;
final int index = i / TOUCH_POSITION_CORRECTION_RECORD_SIZE; final int index = i / TOUCH_POSITION_CORRECTION_RECORD_SIZE;
final float value = Float.parseFloat(data[i]); final float value = Float.parseFloat(data[i]);
if (type == 0) { if (type == 0) {
mParams.mTouchPositionCorrectionXs[index] = value; params.mTouchPositionCorrectionXs[index] = value;
} else if (type == 1) { } else if (type == 1) {
mParams.mTouchPositionCorrectionYs[index] = value; params.mTouchPositionCorrectionYs[index] = value;
} else { } else {
mParams.mTouchPositionCorrectionRadii[index] = value; params.mTouchPositionCorrectionRadii[index] = value;
} }
} }
} catch (NumberFormatException e) { } catch (NumberFormatException e) {
@ -302,9 +298,10 @@ public class KeyboardBuilder<KP extends KeyboardParams> {
throw new RuntimeException( throw new RuntimeException(
"the number format for touch position correction data is invalid"); "the number format for touch position correction data is invalid");
} }
return false; params.mTouchPositionCorrectionXs = null;
params.mTouchPositionCorrectionYs = null;
params.mTouchPositionCorrectionRadii = null;
} }
return true;
} }
public KeyboardBuilder<KP> load(KeyboardId id) { public KeyboardBuilder<KP> load(KeyboardId id) {