/** * Updates the editors being displayed to the user removing extra empty {@link Editor}s, so there * is only max 1 empty {@link Editor} view at a time. */ private void updateEmptyEditors() { List<View> emptyEditors = getEmptyEditors(); // If there is more than 1 empty editor, then remove it from the list of editors. if (emptyEditors.size() > 1) { for (View emptyEditorView : emptyEditors) { // If no child {@link View}s are being focused on within // this {@link View}, then remove this empty editor. if (emptyEditorView.findFocus() == null) { mEditors.removeView(emptyEditorView); } } } }
@Override public boolean dispatchKeyEvent(KeyEvent event) { final boolean handled = super.dispatchKeyEvent(event); // unhandled key ups change focus to tab indicator for embedded activities // when there is nothing that will take focus from default focus searching if (!handled && (event.getAction() == KeyEvent.ACTION_DOWN) && (event.getKeyCode() == KeyEvent.KEYCODE_DPAD_UP) && (mCurrentView.isRootNamespace()) && (mCurrentView.hasFocus()) && (mCurrentView.findFocus().focusSearch(View.FOCUS_UP) == null)) { mTabWidget.getChildTabViewAt(mCurrentTab).requestFocus(); playSoundEffect(SoundEffectConstants.NAVIGATION_UP); return true; } return handled; }
/** * Updates scrolling, creates views if necessary . * * @param layout whether we need to update layout (remeasure). */ private void update(boolean layout) { // Process data change. final int count = getCount(); if (dataChanged) { if (previousSelectedObject != null) for (int position = 0; position < count; position++) if (adapter.getItem(position).equals(previousSelectedObject)) { selectedPosition = position; if (LOG) LogManager.i(this, "Found selected position: " + selectedPosition); break; } selectedPosition = correntPosition(selectedPosition); } // Process scrolling. final int width = getWidth(); int scrollX = getScrollX(); if (width != 0) { while (scrollX >= width) { scrollX -= width; initialScrollX -= width; selectedPosition = correntPosition(selectedPosition + 1); if (LOG) LogManager.i(this, "scrollX >= width: " + selectedPosition); } while (scrollX <= -width) { scrollX += width; initialScrollX += width; selectedPosition = correntPosition(selectedPosition - 1); if (LOG) LogManager.i(this, "scrollX <= -width: " + selectedPosition); } } // Process low count. if (count < 2) { if (LOG) LogManager.i(this, "count < 2"); dragWasCanceled = true; isBeingDragged = false; if (!scroller.isFinished()) scroller.abortAnimation(); if (scrollX != 0) scrollX = 0; } // Store focus. final View focus; if (selectedView != null) focus = selectedView.findFocus(); else focus = null; // Process selected view. if (count == 0) { if (LOG) LogManager.i(this, "count == 0"); selectedPosition = -1; if (selectedView != null) { if (onSelectListener != null) onSelectListener.onUnselect(); adapter.saveState(selectedView); removeViewInLayout(selectedView); selectedView = null; // We must invalidate to update view. invalidate(); } } else { if (LOG) LogManager.i(this, "count > 0"); // Exchange visible and selected views and previous objects. final Object selectedObject = adapter.getItem(selectedPosition); final boolean exchange = previousSelectedObject != null && previousVisibleObject != null && !previousSelectedObject.equals(selectedObject) && previousVisibleObject.equals(selectedObject); if (exchange) { Object tempObject = previousSelectedObject; previousSelectedObject = previousVisibleObject; previousVisibleObject = tempObject; View view = selectedView; selectedView = visibleView; visibleView = view; } // Update view. final boolean update = dataChanged || previousSelectedObject == null || !previousSelectedObject.equals(selectedObject); selectedView = getView(selectedPosition, 0, selectedView, update, layout); previousSelectedObject = selectedObject; if (update || exchange) if (onSelectListener != null) onSelectListener.onSelect(); // Enable focusable. if (selectedView instanceof ViewGroup) ((ViewGroup) selectedView).setDescendantFocusability(ViewGroup.FOCUS_AFTER_DESCENDANTS); else selectedView.setFocusable(true); } // Process visible (not selected) view. if (count < 2) { if (LOG) LogManager.i(this, "count < 2 || scrollX == 0"); visiblePosition = -1; if (visibleView != null) { adapter.saveState(visibleView); removeViewInLayout(visibleView); visibleView = null; } } else { // Calculate position. final int visibleX; if (scrollX > 0) { if (LOG) LogManager.i(this, "scrollX > 0"); visiblePosition = correntPosition(selectedPosition + 1); visibleX = width; } else { if (LOG) LogManager.i(this, "scrollX < 0"); visiblePosition = correntPosition(selectedPosition - 1); visibleX = -width; } // Update view. final Object visibleObject = adapter.getItem(visiblePosition); final boolean update = dataChanged || previousVisibleObject == null || !previousVisibleObject.equals(visibleObject); visibleView = getView(visiblePosition, visibleX, visibleView, update, layout); previousVisibleObject = visibleObject; // Disable focusable. if (visibleView instanceof ViewGroup) ((ViewGroup) visibleView).setDescendantFocusability(ViewGroup.FOCUS_BLOCK_DESCENDANTS); else visibleView.setFocusable(false); } // Restore focus by ID. if (selectedView != null) { View target; if (focus == null || focus.getId() == View.NO_ID) target = null; else target = selectedView.findViewById(focus.getId()); if (target == null) target = selectedView.findViewById(R.id.chat_input); target.requestFocus(); } if (scrollX == 0) { if (LOG) LogManager.i(this, "Scroll X == 0"); hidePages(); } else { if (LOG) LogManager.i(this, "Scroll X != 0"); showPages(); } super.scrollTo(scrollX, 0); dataChanged = false; }