diff options
author | 2013-01-06 11:10:27 +0900 | |
---|---|---|
committer | 2013-01-07 12:13:42 +0900 | |
commit | b6ca354431367b625daf9fff5fbe4b1f5ef996ab (patch) | |
tree | 1358c683e123161cc04bc6ad83eb75c763ec53b3 /java/src/com/android/inputmethod/accessibility | |
parent | f677681330143e3e50871222d33ade594e6348ce (diff) | |
download | latinime-b6ca354431367b625daf9fff5fbe4b1f5ef996ab.tar.gz latinime-b6ca354431367b625daf9fff5fbe4b1f5ef996ab.tar.xz latinime-b6ca354431367b625daf9fff5fbe4b1f5ef996ab.zip |
Small code cleanups
Multi-project commit with I249d5fbe
Change-Id: Ia28c4e970992aa1299a30e604eaa5d096655c3a5
Diffstat (limited to 'java/src/com/android/inputmethod/accessibility')
4 files changed, 120 insertions, 145 deletions
diff --git a/java/src/com/android/inputmethod/accessibility/AccessibilityEntityProvider.java b/java/src/com/android/inputmethod/accessibility/AccessibilityEntityProvider.java index 0ab84f7b5..0576f666c 100644 --- a/java/src/com/android/inputmethod/accessibility/AccessibilityEntityProvider.java +++ b/java/src/com/android/inputmethod/accessibility/AccessibilityEntityProvider.java @@ -71,12 +71,11 @@ public final class AccessibilityEntityProvider extends AccessibilityNodeProvider /** The current keyboard view. */ private KeyboardView mKeyboardView; - public AccessibilityEntityProvider(KeyboardView keyboardView, InputMethodService inputMethod) { + public AccessibilityEntityProvider(final KeyboardView keyboardView, + final InputMethodService inputMethod) { mInputMethodService = inputMethod; - mKeyCodeDescriptionMapper = KeyCodeDescriptionMapper.getInstance(); mAccessibilityUtils = AccessibilityUtils.getInstance(); - setView(keyboardView); } @@ -85,21 +84,19 @@ public final class AccessibilityEntityProvider extends AccessibilityNodeProvider * * @param keyboardView The keyboard view to represent. */ - public void setView(KeyboardView keyboardView) { + public void setView(final KeyboardView keyboardView) { mKeyboardView = keyboardView; updateParentLocation(); // Since this class is constructed lazily, we might not get a subsequent // call to setKeyboard() and therefore need to call it now. - setKeyboard(mKeyboardView.getKeyboard()); + setKeyboard(); } /** * Sets the keyboard represented by this node provider. - * - * @param keyboard The keyboard to represent. */ - public void setKeyboard(Keyboard keyboard) { + public void setKeyboard() { assignVirtualViewIds(); } @@ -112,19 +109,16 @@ public final class AccessibilityEntityProvider extends AccessibilityNodeProvider * @return A populated {@link AccessibilityEvent} for the key. * @see AccessibilityEvent */ - public AccessibilityEvent createAccessibilityEvent(Key key, int eventType) { + public AccessibilityEvent createAccessibilityEvent(final Key key, final int eventType) { final int virtualViewId = generateVirtualViewIdForKey(key); final String keyDescription = getKeyDescription(key); - final AccessibilityEvent event = AccessibilityEvent.obtain(eventType); event.setPackageName(mKeyboardView.getContext().getPackageName()); event.setClassName(key.getClass().getName()); event.setContentDescription(keyDescription); event.setEnabled(true); - final AccessibilityRecordCompat record = new AccessibilityRecordCompat(event); record.setSource(mKeyboardView, virtualViewId); - return event; } @@ -145,68 +139,65 @@ public final class AccessibilityEntityProvider extends AccessibilityNodeProvider * </p> * * @param virtualViewId A client defined virtual view id. - * @return A populated {@link AccessibilityNodeInfoCompat} for a virtual - * descendant or the host View. + * @return A populated {@link AccessibilityNodeInfoCompat} for a virtual descendant or the host + * View. * @see AccessibilityNodeInfoCompat */ @Override - public AccessibilityNodeInfoCompat createAccessibilityNodeInfo(int virtualViewId) { - AccessibilityNodeInfoCompat info = null; - + public AccessibilityNodeInfoCompat createAccessibilityNodeInfo(final int virtualViewId) { if (virtualViewId == UNDEFINED) { return null; - } else if (virtualViewId == View.NO_ID) { + } + if (virtualViewId == View.NO_ID) { // We are requested to create an AccessibilityNodeInfo describing // this View, i.e. the root of the virtual sub-tree. - info = AccessibilityNodeInfoCompat.obtain(mKeyboardView); - ViewCompat.onInitializeAccessibilityNodeInfo(mKeyboardView, info); + final AccessibilityNodeInfoCompat rootInfo = + AccessibilityNodeInfoCompat.obtain(mKeyboardView); + ViewCompat.onInitializeAccessibilityNodeInfo(mKeyboardView, rootInfo); // Add the virtual children of the root View. final Keyboard keyboard = mKeyboardView.getKeyboard(); final Key[] keys = keyboard.mKeys; for (Key key : keys) { final int childVirtualViewId = generateVirtualViewIdForKey(key); - info.addChild(mKeyboardView, childVirtualViewId); - } - } else { - // Find the view that corresponds to the given id. - final Key key = mVirtualViewIdToKey.get(virtualViewId); - if (key == null) { - Log.e(TAG, "Invalid virtual view ID: " + virtualViewId); - return null; - } - - final String keyDescription = getKeyDescription(key); - final Rect boundsInParent = key.mHitBox; - - // Calculate the key's in-screen bounds. - mTempBoundsInScreen.set(boundsInParent); - mTempBoundsInScreen.offset( - CoordinateUtils.x(mParentLocation), CoordinateUtils.y(mParentLocation)); - - final Rect boundsInScreen = mTempBoundsInScreen; - - // Obtain and initialize an AccessibilityNodeInfo with - // information about the virtual view. - info = AccessibilityNodeInfoCompat.obtain(); - info.setPackageName(mKeyboardView.getContext().getPackageName()); - info.setClassName(key.getClass().getName()); - info.setContentDescription(keyDescription); - info.setBoundsInParent(boundsInParent); - info.setBoundsInScreen(boundsInScreen); - info.setParent(mKeyboardView); - info.setSource(mKeyboardView, virtualViewId); - info.setBoundsInScreen(boundsInScreen); - info.setEnabled(true); - info.setVisibleToUser(true); - - if (mAccessibilityFocusedView == virtualViewId) { - info.addAction(AccessibilityNodeInfoCompat.ACTION_CLEAR_ACCESSIBILITY_FOCUS); - } else { - info.addAction(AccessibilityNodeInfoCompat.ACTION_ACCESSIBILITY_FOCUS); + rootInfo.addChild(mKeyboardView, childVirtualViewId); } + return rootInfo; } + // Find the view that corresponds to the given id. + final Key key = mVirtualViewIdToKey.get(virtualViewId); + if (key == null) { + Log.e(TAG, "Invalid virtual view ID: " + virtualViewId); + return null; + } + final String keyDescription = getKeyDescription(key); + final Rect boundsInParent = key.mHitBox; + + // Calculate the key's in-screen bounds. + mTempBoundsInScreen.set(boundsInParent); + mTempBoundsInScreen.offset( + CoordinateUtils.x(mParentLocation), CoordinateUtils.y(mParentLocation)); + final Rect boundsInScreen = mTempBoundsInScreen; + + // Obtain and initialize an AccessibilityNodeInfo with information about the virtual view. + final AccessibilityNodeInfoCompat info = AccessibilityNodeInfoCompat.obtain(); + info.setPackageName(mKeyboardView.getContext().getPackageName()); + info.setClassName(key.getClass().getName()); + info.setContentDescription(keyDescription); + info.setBoundsInParent(boundsInParent); + info.setBoundsInScreen(boundsInScreen); + info.setParent(mKeyboardView); + info.setSource(mKeyboardView, virtualViewId); + info.setBoundsInScreen(boundsInScreen); + info.setEnabled(true); + info.setVisibleToUser(true); + + if (mAccessibilityFocusedView == virtualViewId) { + info.addAction(AccessibilityNodeInfoCompat.ACTION_CLEAR_ACCESSIBILITY_FOCUS); + } else { + info.addAction(AccessibilityNodeInfoCompat.ACTION_ACCESSIBILITY_FOCUS); + } return info; } @@ -216,7 +207,7 @@ public final class AccessibilityEntityProvider extends AccessibilityNodeProvider * * @param key The key to press. */ - void simulateKeyPress(Key key) { + void simulateKeyPress(final Key key) { final int x = key.mHitBox.centerX(); final int y = key.mHitBox.centerY(); final long downTime = SystemClock.uptimeMillis(); @@ -227,19 +218,17 @@ public final class AccessibilityEntityProvider extends AccessibilityNodeProvider mKeyboardView.onTouchEvent(downEvent); mKeyboardView.onTouchEvent(upEvent); - downEvent.recycle(); upEvent.recycle(); } @Override - public boolean performAction(int virtualViewId, int action, Bundle arguments) { + public boolean performAction(final int virtualViewId, final int action, + final Bundle arguments) { final Key key = mVirtualViewIdToKey.get(virtualViewId); - if (key == null) { return false; } - return performActionForKey(key, action, arguments); } @@ -249,10 +238,9 @@ public final class AccessibilityEntityProvider extends AccessibilityNodeProvider * @param key The on which to perform the action. * @param action The action to perform. * @param arguments The action's arguments. - * @return The result of performing the action, or false if the action is - * not supported. + * @return The result of performing the action, or false if the action is not supported. */ - boolean performActionForKey(Key key, int action, Bundle arguments) { + boolean performActionForKey(final Key key, final int action, final Bundle arguments) { final int virtualViewId = generateVirtualViewIdForKey(key); switch (action) { @@ -272,9 +260,9 @@ public final class AccessibilityEntityProvider extends AccessibilityNodeProvider sendAccessibilityEventForKey( key, AccessibilityEventCompat.TYPE_VIEW_ACCESSIBILITY_FOCUS_CLEARED); return true; + default: + return false; } - - return false; } /** @@ -283,7 +271,7 @@ public final class AccessibilityEntityProvider extends AccessibilityNodeProvider * @param key The key that's sending the event. * @param eventType The type of event to send. */ - void sendAccessibilityEventForKey(Key key, int eventType) { + void sendAccessibilityEventForKey(final Key key, final int eventType) { final AccessibilityEvent event = createAccessibilityEvent(key, eventType); mAccessibilityUtils.requestSendAccessibilityEvent(event); } @@ -294,12 +282,11 @@ public final class AccessibilityEntityProvider extends AccessibilityNodeProvider * @param key The key to describe. * @return The context-specific description of the key. */ - private String getKeyDescription(Key key) { + private String getKeyDescription(final Key key) { final EditorInfo editorInfo = mInputMethodService.getCurrentInputEditorInfo(); final boolean shouldObscure = mAccessibilityUtils.shouldObscureInput(editorInfo); final String keyDescription = mKeyCodeDescriptionMapper.getDescriptionForKey( mKeyboardView.getContext(), mKeyboardView.getKeyboard(), key, shouldObscure); - return keyDescription; } @@ -311,7 +298,6 @@ public final class AccessibilityEntityProvider extends AccessibilityNodeProvider if (keyboard == null) { return; } - mVirtualViewIdToKey.clear(); final Key[] keys = keyboard.mKeys; @@ -335,7 +321,7 @@ public final class AccessibilityEntityProvider extends AccessibilityNodeProvider * @param key The key to identify. * @return A virtual view identifier. */ - private static int generateVirtualViewIdForKey(Key key) { + private static int generateVirtualViewIdForKey(final Key key) { // The key x- and y-coordinates are stable between layout changes. // Generate an identifier by bit-shifting the x-coordinate to the // left-half of the integer and OR'ing with the y-coordinate. diff --git a/java/src/com/android/inputmethod/accessibility/AccessibilityUtils.java b/java/src/com/android/inputmethod/accessibility/AccessibilityUtils.java index 0a700bda4..bf1cea9c3 100644 --- a/java/src/com/android/inputmethod/accessibility/AccessibilityUtils.java +++ b/java/src/com/android/inputmethod/accessibility/AccessibilityUtils.java @@ -55,7 +55,7 @@ public final class AccessibilityUtils { */ private static final boolean ENABLE_ACCESSIBILITY = true; - public static void init(InputMethodService inputMethod) { + public static void init(final InputMethodService inputMethod) { if (!ENABLE_ACCESSIBILITY) return; // These only need to be initialized if the kill switch is off. @@ -72,7 +72,7 @@ public final class AccessibilityUtils { // This class is not publicly instantiable. } - private void initInternal(Context context) { + private void initInternal(final Context context) { mContext = context; mAccessibilityManager = (AccessibilityManager) context.getSystemService(Context.ACCESSIBILITY_SERVICE); @@ -100,9 +100,8 @@ public final class AccessibilityUtils { * @param event The event to check. * @return {@true} is the event is a touch exploration event */ - public boolean isTouchExplorationEvent(MotionEvent event) { + public boolean isTouchExplorationEvent(final MotionEvent event) { final int action = event.getAction(); - return action == MotionEvent.ACTION_HOVER_ENTER || action == MotionEvent.ACTION_HOVER_EXIT || action == MotionEvent.ACTION_HOVER_MOVE; @@ -114,7 +113,7 @@ public final class AccessibilityUtils { * * @return {@code true} if the device should obscure password characters. */ - public boolean shouldObscureInput(EditorInfo editorInfo) { + public boolean shouldObscureInput(final EditorInfo editorInfo) { if (editorInfo == null) return false; // The user can optionally force speaking passwords. @@ -140,7 +139,7 @@ public final class AccessibilityUtils { * @param view The source view. * @param text The text to speak. */ - public void announceForAccessibility(View view, CharSequence text) { + public void announceForAccessibility(final View view, final CharSequence text) { if (!mAccessibilityManager.isEnabled()) { Log.e(TAG, "Attempted to speak when accessibility was disabled!"); return; @@ -157,8 +156,9 @@ public final class AccessibilityUtils { event.setEnabled(true); event.getText().add(text); - // Platforms starting at SDK 16 should use announce events. - if (Build.VERSION.SDK_INT >= 16) { + // Platforms starting at SDK version 16 (Build.VERSION_CODES.JELLY_BEAN) should use + // announce events. + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { event.setEventType(AccessibilityEventCompat.TYPE_ANNOUNCEMENT); } else { event.setEventType(AccessibilityEvent.TYPE_VIEW_FOCUSED); @@ -181,7 +181,8 @@ public final class AccessibilityUtils { * @param editorInfo The input connection's editor info attribute. * @param restarting Whether the connection is being restarted. */ - public void onStartInputViewInternal(View view, EditorInfo editorInfo, boolean restarting) { + public void onStartInputViewInternal(final View view, final EditorInfo editorInfo, + final boolean restarting) { if (shouldObscureInput(editorInfo)) { final CharSequence text = mContext.getText(R.string.spoken_use_headphones); announceForAccessibility(view, text); @@ -194,7 +195,7 @@ public final class AccessibilityUtils { * * @param event The event to send. */ - public void requestSendAccessibilityEvent(AccessibilityEvent event) { + public void requestSendAccessibilityEvent(final AccessibilityEvent event) { if (mAccessibilityManager.isEnabled()) { mAccessibilityManager.sendAccessibilityEvent(event); } diff --git a/java/src/com/android/inputmethod/accessibility/AccessibleKeyboardViewProxy.java b/java/src/com/android/inputmethod/accessibility/AccessibleKeyboardViewProxy.java index fcfa6d4e4..d73924d92 100644 --- a/java/src/com/android/inputmethod/accessibility/AccessibleKeyboardViewProxy.java +++ b/java/src/com/android/inputmethod/accessibility/AccessibleKeyboardViewProxy.java @@ -42,12 +42,11 @@ public final class AccessibleKeyboardViewProxy extends AccessibilityDelegateComp private Key mLastHoverKey = null; /** - * Inset in pixels to look for keys when the user's finger exits the - * keyboard area. + * Inset in pixels to look for keys when the user's finger exits the keyboard area. */ private int mEdgeSlop; - public static void init(InputMethodService inputMethod) { + public static void init(final InputMethodService inputMethod) { sInstance.initInternal(inputMethod); } @@ -59,7 +58,7 @@ public final class AccessibleKeyboardViewProxy extends AccessibilityDelegateComp // Not publicly instantiable. } - private void initInternal(InputMethodService inputMethod) { + private void initInternal(final InputMethodService inputMethod) { mInputMethod = inputMethod; mEdgeSlop = inputMethod.getResources().getDimensionPixelSize( R.dimen.accessibility_edge_slop); @@ -70,61 +69,61 @@ public final class AccessibleKeyboardViewProxy extends AccessibilityDelegateComp * * @param view The view to wrap. */ - public void setView(MainKeyboardView view) { + public void setView(final MainKeyboardView view) { if (view == null) { // Ignore null views. return; } - mView = view; // Ensure that the view has an accessibility delegate. ViewCompat.setAccessibilityDelegate(view, this); - if (mAccessibilityNodeProvider != null) { - mAccessibilityNodeProvider.setView(view); + if (mAccessibilityNodeProvider == null) { + return; } + mAccessibilityNodeProvider.setView(view); } - public void setKeyboard(Keyboard keyboard) { - if (mAccessibilityNodeProvider != null) { - mAccessibilityNodeProvider.setKeyboard(keyboard); + public void setKeyboard() { + if (mAccessibilityNodeProvider == null) { + return; } + mAccessibilityNodeProvider.setKeyboard(); } /** - * Proxy method for View.getAccessibilityNodeProvider(). This method is - * called in SDK version 15 and higher to obtain the virtual node hierarchy - * provider. + * Proxy method for View.getAccessibilityNodeProvider(). This method is called in SDK + * version 15 (Build.VERSION_CODES.ICE_CREAM_SANDWICH_MR1) and higher to obtain the virtual + * node hierarchy provider. * * @return The accessibility node provider for the current keyboard. */ @Override - public AccessibilityEntityProvider getAccessibilityNodeProvider(View host) { + public AccessibilityEntityProvider getAccessibilityNodeProvider(final View host) { return getAccessibilityNodeProvider(); } /** - * Intercepts touch events before dispatch when touch exploration is turned - * on in ICS and higher. + * Intercepts touch events before dispatch when touch exploration is turned on in ICS and + * higher. * * @param event The motion event being dispatched. * @return {@code true} if the event is handled */ - public boolean dispatchTouchEvent(MotionEvent event) { + public boolean dispatchTouchEvent(final MotionEvent event) { // To avoid accidental key presses during touch exploration, always drop // touch events generated by the user. return false; } /** - * Receives hover events when touch exploration is turned on in SDK versions - * ICS and higher. + * Receives hover events when touch exploration is turned on in SDK versions ICS and higher. * * @param event The hover event. * @return {@code true} if the event is handled */ - public boolean dispatchHoverEvent(MotionEvent event, PointerTracker tracker) { + public boolean dispatchHoverEvent(final MotionEvent event, final PointerTracker tracker) { final int x = (int) event.getX(); final int y = (int) event.getY(); final Key previousKey = mLastHoverKey; @@ -135,7 +134,6 @@ public final class AccessibleKeyboardViewProxy extends AccessibilityDelegateComp } else { key = null; } - mLastHoverKey = key; switch (event.getAction()) { @@ -173,30 +171,29 @@ public final class AccessibleKeyboardViewProxy extends AccessibilityDelegateComp } /** - * Utility method to determine whether the given point, in local - * coordinates, is inside the view, where the area of the view is contracted - * by the edge slop factor. + * Utility method to determine whether the given point, in local coordinates, is inside the + * view, where the area of the view is contracted by the edge slop factor. * * @param localX The local x-coordinate. * @param localY The local y-coordinate. */ - private boolean pointInView(int localX, int localY) { + private boolean pointInView(final int localX, final int localY) { return (localX >= mEdgeSlop) && (localY >= mEdgeSlop) && (localX < (mView.getWidth() - mEdgeSlop)) && (localY < (mView.getHeight() - mEdgeSlop)); } /** - * Simulates a transition between two {@link Key}s by sending a HOVER_EXIT - * on the previous key, a HOVER_ENTER on the current key, and a HOVER_MOVE - * on the current key. + * Simulates a transition between two {@link Key}s by sending a HOVER_EXIT on the previous key, + * a HOVER_ENTER on the current key, and a HOVER_MOVE on the current key. * * @param currentKey The currently hovered key. * @param previousKey The previously hovered key. * @param event The event that triggered the transition. * @return {@code true} if the event was handled. */ - private boolean onTransitionKey(Key currentKey, Key previousKey, MotionEvent event) { + private boolean onTransitionKey(final Key currentKey, final Key previousKey, + final MotionEvent event) { final int savedAction = event.getAction(); event.setAction(MotionEvent.ACTION_HOVER_EXIT); @@ -214,19 +211,18 @@ public final class AccessibleKeyboardViewProxy extends AccessibilityDelegateComp } /** - * Handles a hover event on a key. If {@link Key} extended View, this would - * be analogous to calling View.onHoverEvent(MotionEvent). + * Handles a hover event on a key. If {@link Key} extended View, this would be analogous to + * calling View.onHoverEvent(MotionEvent). * * @param key The currently hovered key. * @param event The hover event. * @return {@code true} if the event was handled. */ - private boolean onHoverKey(Key key, MotionEvent event) { + private boolean onHoverKey(final Key key, final MotionEvent event) { // Null keys can't receive events. if (key == null) { return false; } - final AccessibilityEntityProvider provider = getAccessibilityNodeProvider(); switch (event.getAction()) { @@ -241,7 +237,6 @@ public final class AccessibleKeyboardViewProxy extends AccessibilityDelegateComp key, AccessibilityEventCompat.TYPE_VIEW_HOVER_EXIT); break; } - return true; } @@ -268,7 +263,6 @@ public final class AccessibleKeyboardViewProxy extends AccessibilityDelegateComp default: text = context.getText(R.string.spoken_description_shiftmode_off); } - AccessibilityUtils.getInstance().announceForAccessibility(mView, text); } @@ -307,7 +301,6 @@ public final class AccessibleKeyboardViewProxy extends AccessibilityDelegateComp if (resId < 0) { return; } - final String text = context.getString(resId); AccessibilityUtils.getInstance().announceForAccessibility(mView, text); } diff --git a/java/src/com/android/inputmethod/accessibility/KeyCodeDescriptionMapper.java b/java/src/com/android/inputmethod/accessibility/KeyCodeDescriptionMapper.java index b87ae3a15..6a01b0190 100644 --- a/java/src/com/android/inputmethod/accessibility/KeyCodeDescriptionMapper.java +++ b/java/src/com/android/inputmethod/accessibility/KeyCodeDescriptionMapper.java @@ -93,17 +93,17 @@ public final class KeyCodeDescriptionMapper { * @param keyboard The keyboard on which the key resides. * @param key The key from which to obtain a description. * @param shouldObscure {@true} if text (e.g. non-control) characters should be obscured. - * @return a character sequence describing the action performed by pressing - * the key + * @return a character sequence describing the action performed by pressing the key */ - public String getDescriptionForKey(Context context, Keyboard keyboard, Key key, - boolean shouldObscure) { + public String getDescriptionForKey(final Context context, final Keyboard keyboard, + final Key key, final boolean shouldObscure) { final int code = key.mCode; if (code == Constants.CODE_SWITCH_ALPHA_SYMBOL) { final String description = getDescriptionForSwitchAlphaSymbol(context, keyboard); - if (description != null) + if (description != null) { return description; + } } if (code == Constants.CODE_SHIFT) { @@ -127,7 +127,6 @@ public final class KeyCodeDescriptionMapper { if (key.mCode != Constants.CODE_UNSPECIFIED) { return getDescriptionForKeyCode(context, keyboard, key, shouldObscure); } - return null; } @@ -138,10 +137,10 @@ public final class KeyCodeDescriptionMapper { * * @param context The package's context. * @param keyboard The keyboard on which the key resides. - * @return a character sequence describing the action performed by pressing - * the key + * @return a character sequence describing the action performed by pressing the key */ - private String getDescriptionForSwitchAlphaSymbol(Context context, Keyboard keyboard) { + private String getDescriptionForSwitchAlphaSymbol(final Context context, + final Keyboard keyboard) { final KeyboardId keyboardId = keyboard.mId; final int elementId = keyboardId.mElementId; final int resId; @@ -168,7 +167,6 @@ public final class KeyCodeDescriptionMapper { Log.e(TAG, "Missing description for keyboard element ID:" + elementId); return null; } - return context.getString(resId); } @@ -179,7 +177,7 @@ public final class KeyCodeDescriptionMapper { * @param keyboard The keyboard on which the key resides. * @return A context-sensitive description of the "Shift" key. */ - private String getDescriptionForShiftKey(Context context, Keyboard keyboard) { + private String getDescriptionForShiftKey(final Context context, final Keyboard keyboard) { final KeyboardId keyboardId = keyboard.mId; final int elementId = keyboardId.mElementId; final int resId; @@ -197,7 +195,6 @@ public final class KeyCodeDescriptionMapper { default: resId = R.string.spoken_description_shift; } - return context.getString(resId); } @@ -207,10 +204,10 @@ public final class KeyCodeDescriptionMapper { * @param context The package's context. * @param keyboard The keyboard on which the key resides. * @param key The key to describe. - * @return Returns a context-sensitive description of the "Enter" action - * key. + * @return Returns a context-sensitive description of the "Enter" action key. */ - private String getDescriptionForActionKey(Context context, Keyboard keyboard, Key key) { + private String getDescriptionForActionKey(final Context context, final Keyboard keyboard, + final Key key) { final KeyboardId keyboardId = keyboard.mId; final int actionId = keyboardId.imeActionId(); final int resId; @@ -243,7 +240,6 @@ public final class KeyCodeDescriptionMapper { default: resId = R.string.spoken_description_return; } - return context.getString(resId); } @@ -265,11 +261,10 @@ public final class KeyCodeDescriptionMapper { * @param keyboard The keyboard on which the key resides. * @param key The key from which to obtain a description. * @param shouldObscure {@true} if text (e.g. non-control) characters should be obscured. - * @return a character sequence describing the action performed by pressing - * the key + * @return a character sequence describing the action performed by pressing the key */ - private String getDescriptionForKeyCode(Context context, Keyboard keyboard, Key key, - boolean shouldObscure) { + private String getDescriptionForKeyCode(final Context context, final Keyboard keyboard, + final Key key, final boolean shouldObscure) { final int code = key.mCode; // If the key description should be obscured, now is the time to do it. @@ -277,15 +272,15 @@ public final class KeyCodeDescriptionMapper { if (shouldObscure && isDefinedNonCtrl) { return context.getString(OBSCURED_KEY_RES_ID); } - if (mKeyCodeMap.indexOfKey(code) >= 0) { return context.getString(mKeyCodeMap.get(code)); - } else if (isDefinedNonCtrl) { + } + if (isDefinedNonCtrl) { return Character.toString((char) code); - } else if (!TextUtils.isEmpty(key.mLabel)) { + } + if (!TextUtils.isEmpty(key.mLabel)) { return key.mLabel; - } else { - return context.getString(R.string.spoken_description_unknown, code); } + return context.getString(R.string.spoken_description_unknown, code); } } |