List of usage examples for android.view View FOCUS_RIGHT
int FOCUS_RIGHT
To view the source code for android.view View FOCUS_RIGHT.
Click Source Link
From source file:com.missionhub.ui.widget.LockableViewPager.java
@Override public boolean arrowScroll(int direction) { View currentFocused = findFocus(); if (currentFocused == this) currentFocused = null;/*from ww w. ja va 2 s . c om*/ boolean locked = false; View nextFocused = FocusFinder.getInstance().findNextFocus(this, currentFocused, direction); if (nextFocused != null && nextFocused != currentFocused) { if (direction == View.FOCUS_LEFT) { if (currentFocused != null && nextFocused.getLeft() >= currentFocused.getLeft()) { if (mLock == LOCK_BOTH || mLock == LOCK_BACKWARD) { locked = true; } } } else if (direction == View.FOCUS_RIGHT) { if (currentFocused != null && nextFocused.getLeft() <= currentFocused.getLeft()) { if (mLock == LOCK_BOTH || mLock == LOCK_FORWARD) { locked = true; } } } } else if (direction == FOCUS_LEFT || direction == FOCUS_BACKWARD) { if (mLock == LOCK_BOTH || mLock == LOCK_BACKWARD) { locked = true; } } else if (direction == FOCUS_RIGHT || direction == FOCUS_FORWARD) { if (mLock == LOCK_BOTH || mLock == LOCK_FORWARD) { locked = true; } } return locked || super.arrowScroll(direction); }
From source file:com.vuze.android.remote.AndroidUtilsUI.java
public static boolean handleCommonKeyDownEvents(Activity a, int keyCode, KeyEvent event) { if (event.getAction() != KeyEvent.ACTION_DOWN) { return false; }/*from w w w .j a v a 2 s . c o m*/ switch (keyCode) { case KeyEvent.KEYCODE_MEDIA_NEXT: case KeyEvent.KEYCODE_MEDIA_FAST_FORWARD: { ViewGroup vg = (ViewGroup) a.findViewById(android.R.id.content); ArrayList list = AndroidUtilsUI.findByClass(vg, ViewPager.class, new ArrayList<View>(0)); if (list.size() > 0) { ViewPager viewPager = (ViewPager) list.get(0); viewPager.arrowScroll(View.FOCUS_RIGHT); } break; } case KeyEvent.KEYCODE_MEDIA_PREVIOUS: case KeyEvent.KEYCODE_MEDIA_REWIND: { ViewGroup vg = (ViewGroup) a.findViewById(android.R.id.content); ArrayList list = AndroidUtilsUI.findByClass(vg, ViewPager.class, new ArrayList<View>(0)); if (list.size() > 0) { ViewPager viewPager = (ViewPager) list.get(0); viewPager.arrowScroll(View.FOCUS_LEFT); } break; } case KeyEvent.KEYCODE_DPAD_LEFT: { if (a instanceof DrawerActivity) { DrawerActivity da = (DrawerActivity) a; DrawerLayout drawerLayout = da.getDrawerLayout(); View viewFocus = a.getCurrentFocus(); boolean canOpenDrawer = viewFocus != null && "leftmost".equals(viewFocus.getTag()); if (canOpenDrawer) { drawerLayout.openDrawer(Gravity.LEFT); drawerLayout.requestFocus(); return true; } } break; } } return false; }
From source file:com.fuzz.android.limelight.LimeLight.java
private static void createDelayedRecordingWindow(Activity activity, int delay) { activity.getWindow().getDecorView().postDelayed(new Runnable() { @Override/*from w ww . j a v a2s. c om*/ public void run() { if (book != null) { book.refreshWindow(); } if (!mRecorderWindow.isShowing()) { mRecorderWindow.show(getRootView()); } updateScrubber(View.FOCUS_RIGHT); LimeLightLog.i("Created recording window."); } }, delay); }
From source file:com.fuzz.android.limelight.LimeLight.java
static public PopupWindow createRecordingWindow(Activity activity) { if (activity != null) { mRecorderWindow = new RecorderWindow(activity); }/* ww w . j av a 2 s. co m*/ if (!mRecorderWindow.isShowing()) { mRecorderWindow.show(getRootView()); } updateScrubber(View.FOCUS_RIGHT); return mRecorderWindow; }
From source file:com.numix.calculator.EventListener.java
@Override public void onClick(View view) { View v;//from w ww . j av a2s . c o m EditText active; int id = view.getId(); switch (id) { case R.id.del: mHandler.onDelete(); break; case R.id.clear: if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { deleteAnimation(view); } break; case R.id.equal: if (mHandler.getText().contains(mX) || mHandler.getText().contains(mY)) { if (!mHandler.getText().contains("=")) { mHandler.insert("="); returnToBasic(); } break; } mHandler.onEnter(); break; case R.id.hex: mHandler.setText(mHandler.mBaseModule.setMode(Mode.HEXADECIMAL)); view.setSelected(true); ((View) view.getParent()).findViewById(R.id.bin).setSelected(false); ((View) view.getParent()).findViewById(R.id.dec).setSelected(false); applyAllBannedResources(mHandler.mBaseModule, Mode.HEXADECIMAL); break; case R.id.bin: mHandler.setText(mHandler.mBaseModule.setMode(Mode.BINARY)); view.setSelected(true); ((View) view.getParent()).findViewById(R.id.hex).setSelected(false); ((View) view.getParent()).findViewById(R.id.dec).setSelected(false); applyAllBannedResources(mHandler.mBaseModule, Mode.BINARY); break; case R.id.dec: mHandler.setText(mHandler.mBaseModule.setMode(Mode.DECIMAL)); view.setSelected(true); ((View) view.getParent()).findViewById(R.id.bin).setSelected(false); ((View) view.getParent()).findViewById(R.id.hex).setSelected(false); applyAllBannedResources(mHandler.mBaseModule, Mode.DECIMAL); break; case R.id.matrix: mHandler.insert(MatrixView.getPattern(mContext)); returnToBasic(); break; case R.id.matrix_inverse: mHandler.insert(MatrixInverseView.PATTERN); returnToBasic(); break; case R.id.matrix_transpose: mHandler.insert(MatrixTransposeView.PATTERN); returnToBasic(); break; case R.id.plus_row: v = mHandler.mDisplay.getActiveEditText(); if (v instanceof MatrixEditText) ((MatrixEditText) v).getMatrixView().addRow(); break; case R.id.minus_row: v = mHandler.mDisplay.getActiveEditText(); if (v instanceof MatrixEditText) ((MatrixEditText) v).getMatrixView().removeRow(); break; case R.id.plus_col: v = mHandler.mDisplay.getActiveEditText(); if (v instanceof MatrixEditText) ((MatrixEditText) v).getMatrixView().addColumn(); break; case R.id.minus_col: v = mHandler.mDisplay.getActiveEditText(); if (v instanceof MatrixEditText) ((MatrixEditText) v).getMatrixView().removeColumn(); break; case R.id.next: if (mHandler.getText().equals(mErrorString)) mHandler.setText(""); active = mHandler.mDisplay.getActiveEditText(); if (active.getSelectionStart() == active.getText().length()) { v = mHandler.mDisplay.getActiveEditText().focusSearch(View.FOCUS_RIGHT); if (v != null) v.requestFocus(); active = mHandler.mDisplay.getActiveEditText(); active.setSelection(0); } else { active.setSelection(active.getSelectionStart() + 1); } break; // +/-, changes the sign of the current number. Might be useful later // (but removed for now) // case R.id.sign: // if(mHandler.getText().equals(mErrorString)) mHandler.setText(""); // active = mHandler.mDisplay.getActiveEditText(); // int selection = active.getSelectionStart(); // if(active.getText().toString().matches(Logic.NUMBER)) { // if(active.getText().toString().startsWith(String.valueOf(Logic.MINUS))) // { // active.setText(active.getText().toString().substring(1)); // selection--; // } // else { // active.setText(Logic.MINUS + active.getText().toString()); // selection++; // } // if(selection > active.length()) selection--; // if(selection < 0) selection = 0; // active.setSelection(selection); // } // break; case R.id.parentheses: if (mHandler.getText().equals(mErrorString)) mHandler.setText(""); if (mHandler.getText().contains("=")) { String[] equation = mHandler.getText().split("="); if (equation.length > 1) { mHandler.setText(equation[0] + "=(" + equation[1] + ")"); } else { mHandler.setText(equation[0] + "=()"); } } else { mHandler.setText("(" + mHandler.getText() + ")"); } returnToBasic(); break; case R.id.mod: if (mHandler.getText().equals(mErrorString)) mHandler.setText(""); if (mHandler.getText().contains("=")) { String[] equation = mHandler.getText().split("="); if (equation.length > 1) { mHandler.setText(equation[0] + "=" + mModString + "(" + equation[1] + ","); } else { mHandler.insert(mModString + "("); } } else { if (mHandler.getText().length() > 0) { mHandler.setText(mModString + "(" + mHandler.getText() + ","); } else { mHandler.insert(mModString + "("); } } returnToBasic(); break; case R.id.easter: Toast.makeText(mContext, R.string.easter_egg, Toast.LENGTH_SHORT).show(); break; default: if (view instanceof Button) { String text = ((Button) view).getText().toString(); if (text.equals(mDX) || text.equals(mDY)) { // Do nothing } else if (text.length() >= 2) { // Add paren after sin, cos, ln, etc. from buttons text += "("; } mHandler.insert(text); returnToBasic(); } } }
From source file:com.hippo.widget.BothScrollView.java
/** * You can call this function yourself to have the scroll view perform * scrolling from a key event, just as if the event had been dispatched to * it by the view hierarchy.// w ww.j av a 2 s . com * * @param event The key event to execute. * @return Return true if the event was handled, else false. */ public boolean executeKeyEvent(KeyEvent event) { mTempRect.setEmpty(); if (!canScrollHorizontally()) { if (isFocused() && event.getKeyCode() != KeyEvent.KEYCODE_BACK) { View currentFocused = findFocus(); if (currentFocused == this) { currentFocused = null; } View nextFocused = FocusFinder.getInstance().findNextFocus(this, currentFocused, View.FOCUS_RIGHT); return nextFocused != null && nextFocused != this && nextFocused.requestFocus(View.FOCUS_RIGHT); } return false; } if (!canScrollVertically()) { if (isFocused() && event.getKeyCode() != KeyEvent.KEYCODE_BACK) { View currentFocused = findFocus(); if (currentFocused == this) { currentFocused = null; } View nextFocused = FocusFinder.getInstance().findNextFocus(this, currentFocused, View.FOCUS_DOWN); return nextFocused != null && nextFocused != this && nextFocused.requestFocus(View.FOCUS_DOWN); } return false; } boolean handled = false; if (event.getAction() == KeyEvent.ACTION_DOWN) { switch (event.getKeyCode()) { case KeyEvent.KEYCODE_DPAD_LEFT: if (!event.isAltPressed()) { handled = arrowScrollHorizontally(View.FOCUS_LEFT); } else { handled = fullScroll(View.FOCUS_LEFT); } break; case KeyEvent.KEYCODE_DPAD_RIGHT: if (!event.isAltPressed()) { handled = arrowScrollHorizontally(View.FOCUS_RIGHT); } else { handled = fullScroll(View.FOCUS_RIGHT); } break; case KeyEvent.KEYCODE_DPAD_UP: if (!event.isAltPressed()) { handled = arrowScrollVertically(View.FOCUS_UP); } else { handled = fullScroll(View.FOCUS_UP); } break; case KeyEvent.KEYCODE_DPAD_DOWN: if (!event.isAltPressed()) { handled = arrowScrollVertically(View.FOCUS_DOWN); } else { handled = fullScroll(View.FOCUS_DOWN); } break; case KeyEvent.KEYCODE_SPACE: if (event.isCtrlPressed()) { pageScroll(event.isShiftPressed() ? View.FOCUS_LEFT : View.FOCUS_RIGHT); } else { pageScroll(event.isShiftPressed() ? View.FOCUS_UP : View.FOCUS_DOWN); } break; } } return handled; }
From source file:com.oguzbabaoglu.cardpager.CardPager.java
void populate(int newCurrentItem) { ItemInfo oldCurInfo = null;//from w w w. j av a 2 s . c o m int focusDirection = View.FOCUS_FORWARD; if (currentItem != newCurrentItem) { focusDirection = currentItem < newCurrentItem ? View.FOCUS_RIGHT : View.FOCUS_LEFT; oldCurInfo = infoForPosition(currentItem); currentItem = newCurrentItem; } if (pagerAdapter == null) { sortChildDrawingOrder(); return; } // Bail now if we are waiting to populate. This is to hold off // on creating views from the time the user releases their finger to // fling to a new position until we have finished the scroll to // that position, avoiding glitches from happening at that point. if (populatePending) { sortChildDrawingOrder(); return; } // Also, don't populate until we are attached to a window. This is to // avoid trying to populate before we have restored our view hierarchy // state and conflicting with what is restored. if (getWindowToken() == null) { return; } pagerAdapter.startUpdate(this); final int pageLimit = offscreenPageLimit; final int startPos = Math.max(0, currentItem - pageLimit); final int adapterCount = pagerAdapter.getCount(); final int endPos = Math.min(adapterCount - 1, currentItem + pageLimit); // Locate the currently focused item or add it if needed. int curIndex; ItemInfo curItem = null; for (curIndex = 0; curIndex < items.size(); curIndex++) { final ItemInfo ii = items.get(curIndex); if (ii.position == currentItem) { curItem = ii; break; } } if (curItem == null && adapterCount > 0) { curItem = addNewItem(currentItem, curIndex); } // Fill 3x the available width or up to the number of offscreen // pages requested to either side, whichever is larger. // If we have no current item we have no work to do. if (curItem != null) { float extraWidthLeft = 0.f; int itemIndex = curIndex - 1; ItemInfo ii = itemIndex >= 0 ? items.get(itemIndex) : null; final int clientWidth = getClientWidth(); final float leftWidthNeeded = clientWidth <= 0 ? 0 : 2.f - curItem.widthFactor + (float) getPaddingLeft() / (float) clientWidth; for (int pos = currentItem - 1; pos >= 0; pos--) { if (extraWidthLeft >= leftWidthNeeded && pos < startPos) { if (ii == null) { break; } if (pos == ii.position && !ii.scrolling) { items.remove(itemIndex); pagerAdapter.destroyItem(this, pos, ii.object); itemIndex--; curIndex--; ii = itemIndex >= 0 ? items.get(itemIndex) : null; } } else if (ii != null && pos == ii.position) { extraWidthLeft += ii.widthFactor; itemIndex--; ii = itemIndex >= 0 ? items.get(itemIndex) : null; } else { ii = addNewItem(pos, itemIndex + 1); extraWidthLeft += ii.widthFactor; curIndex++; ii = itemIndex >= 0 ? items.get(itemIndex) : null; } } float extraWidthRight = curItem.widthFactor; itemIndex = curIndex + 1; if (extraWidthRight < 2.f) { ii = itemIndex < items.size() ? items.get(itemIndex) : null; final float rightWidthNeeded = clientWidth <= 0 ? 0 : (float) getPaddingRight() / (float) clientWidth + 2.f; for (int pos = currentItem + 1; pos < adapterCount; pos++) { if (extraWidthRight >= rightWidthNeeded && pos > endPos) { if (ii == null) { break; } if (pos == ii.position && !ii.scrolling) { items.remove(itemIndex); pagerAdapter.destroyItem(this, pos, ii.object); ii = itemIndex < items.size() ? items.get(itemIndex) : null; } } else if (ii != null && pos == ii.position) { extraWidthRight += ii.widthFactor; itemIndex++; ii = itemIndex < items.size() ? items.get(itemIndex) : null; } else { ii = addNewItem(pos, itemIndex); itemIndex++; extraWidthRight += ii.widthFactor; ii = itemIndex < items.size() ? items.get(itemIndex) : null; } } } calculatePageOffsets(curItem, curIndex, oldCurInfo); } pagerAdapter.setPrimaryItem(this, currentItem, curItem != null ? curItem.object : null); pagerAdapter.finishUpdate(this); // Check width measurement of current pages and drawing sort order. // Update LayoutParams as needed. final int childCount = getChildCount(); for (int i = 0; i < childCount; i++) { final View child = getChildAt(i); final LayoutParams lp = (LayoutParams) child.getLayoutParams(); lp.childIndex = i; if (lp.widthFactor == 0.f) { // 0 means requery the adapter for this, it doesn't have a valid width. final ItemInfo ii = infoForChild(child); if (ii != null) { lp.widthFactor = ii.widthFactor; lp.position = ii.position; } } } sortChildDrawingOrder(); checkFocus(focusDirection); }
From source file:com.android.talkback.controller.CursorControllerAppTest.java
@MediumTest public void testPrevious_horizontal() { setContentView(R.layout.cursor_horizontal_test); // Scroll to the very right to reach the last items before beginning test. getInstrumentation().runOnMainSync(new Runnable() { @Override//from w w w. jav a 2 s . com public void run() { HorizontalScrollView scroller = (HorizontalScrollView) getViewForId(R.id.horiz_scroller); scroller.fullScroll(View.FOCUS_RIGHT); } }); getInstrumentation().waitForIdleSync(); waitForAccessibilityIdleSync(); AccessibilityNodeInfoCompat firstLabel = getNodeForId(R.id.text_first_item); AccessibilityNodeInfoCompat lastLabel = getNodeForId(R.id.text_last_item); AccessibilityNodeInfoCompat horizScroller = getNodeForId(R.id.horiz_scroller); mCursorController.setCursor(lastLabel); waitForAccessibilityIdleSync(); // This is the expected traversal: // (Initial focus) text_last_item // 1-7. horiz_scroller - all items // 8. text_first_item final int traversals = 8; List<AccessibilityNodeInfoCompat> nodes = navigate(TraversalStrategy.SEARCH_FOCUS_BACKWARD, traversals, true, true, true); assertHasParent(horizScroller, nodes.subList(0, traversals - 1)); assertEquals(firstLabel, nodes.get(traversals - 1)); }
From source file:com.aviary.android.feather.sdk.widget.AviaryWorkspace.java
@Override public boolean dispatchUnhandledMove(View focused, int direction) { if (direction == View.FOCUS_LEFT) { if (getCurrentScreen() > 0) { snapToScreen(getCurrentScreen() - 1); return true; }//w w w .j av a 2 s. c om } else if (direction == View.FOCUS_RIGHT) { if (getCurrentScreen() < mItemCount - 1) { snapToScreen(getCurrentScreen() + 1); return true; } } return super.dispatchUnhandledMove(focused, direction); }
From source file:com.aviary.android.feather.sdk.widget.AviaryWorkspace.java
@Override public void addFocusables(ArrayList<View> views, int direction, int focusableMode) { if (isEnabled()) { View child = getChildAt(mCurrentScreen); if (null != child) { child.addFocusables(views, direction); }//w ww . j a va 2 s . c o m if (direction == View.FOCUS_LEFT) { if (mCurrentScreen > 0) { child = getChildAt(mCurrentScreen - 1); if (null != child) { child.addFocusables(views, direction); } } } else if (direction == View.FOCUS_RIGHT) { if (mCurrentScreen < mItemCount - 1) { child = getChildAt(mCurrentScreen + 1); if (null != child) { child.addFocusables(views, direction); } } } } }