List of usage examples for android.view KeyEvent KEYCODE_DPAD_DOWN
int KEYCODE_DPAD_DOWN
To view the source code for android.view KeyEvent KEYCODE_DPAD_DOWN.
Click Source Link
From source file:com.appunite.list.ListView.java
private boolean commonKey(int keyCode, int count, KeyEvent event) { if (mAdapter == null || !mIsAttached) { return false; }/*from w w w . j av a2 s. co m*/ if (mDataChanged) { layoutChildren(); } boolean handled = false; int action = event.getAction(); if (action != KeyEvent.ACTION_UP) { switch (keyCode) { case KeyEvent.KEYCODE_DPAD_UP: if (KeyEventCompat.hasNoModifiers(event)) { handled = resurrectSelectionIfNeeded(); if (!handled) { while (count-- > 0) { if (arrowScroll(FOCUS_UP)) { handled = true; } else { break; } } } } else if (KeyEventCompat.hasModifiers(event, KeyEvent.META_ALT_ON)) { handled = resurrectSelectionIfNeeded() || fullScroll(FOCUS_UP); } break; case KeyEvent.KEYCODE_DPAD_DOWN: if (KeyEventCompat.hasNoModifiers(event)) { handled = resurrectSelectionIfNeeded(); if (!handled) { while (count-- > 0) { if (arrowScroll(FOCUS_DOWN)) { handled = true; } else { break; } } } } else if (KeyEventCompat.hasModifiers(event, KeyEvent.META_ALT_ON)) { handled = resurrectSelectionIfNeeded() || fullScroll(FOCUS_DOWN); } break; case KeyEvent.KEYCODE_DPAD_LEFT: if (KeyEventCompat.hasNoModifiers(event)) { handled = handleHorizontalFocusWithinListItem(View.FOCUS_LEFT); } break; case KeyEvent.KEYCODE_DPAD_RIGHT: if (KeyEventCompat.hasNoModifiers(event)) { handled = handleHorizontalFocusWithinListItem(View.FOCUS_RIGHT); } break; case KeyEvent.KEYCODE_DPAD_CENTER: case KeyEvent.KEYCODE_ENTER: if (KeyEventCompat.hasNoModifiers(event)) { handled = resurrectSelectionIfNeeded(); if (!handled && event.getRepeatCount() == 0 && getChildCount() > 0) { keyPressed(); handled = true; } } break; case KeyEvent.KEYCODE_SPACE: if (mPopup == null || !mPopup.isShowing()) { if (KeyEventCompat.hasNoModifiers(event)) { handled = resurrectSelectionIfNeeded() || pageScroll(FOCUS_DOWN); } else if (KeyEventCompat.hasModifiers(event, KeyEvent.META_SHIFT_ON)) { handled = resurrectSelectionIfNeeded() || pageScroll(FOCUS_UP); } handled = true; } break; case KeyEvent.KEYCODE_PAGE_UP: if (KeyEventCompat.hasNoModifiers(event)) { handled = resurrectSelectionIfNeeded() || pageScroll(FOCUS_UP); } else if (KeyEventCompat.hasModifiers(event, KeyEvent.META_ALT_ON)) { handled = resurrectSelectionIfNeeded() || fullScroll(FOCUS_UP); } break; case KeyEvent.KEYCODE_PAGE_DOWN: if (KeyEventCompat.hasNoModifiers(event)) { handled = resurrectSelectionIfNeeded() || pageScroll(FOCUS_DOWN); } else if (KeyEventCompat.hasModifiers(event, KeyEvent.META_ALT_ON)) { handled = resurrectSelectionIfNeeded() || fullScroll(FOCUS_DOWN); } break; case KeyEvent.KEYCODE_MOVE_HOME: if (KeyEventCompat.hasNoModifiers(event)) { handled = resurrectSelectionIfNeeded() || fullScroll(FOCUS_UP); } break; case KeyEvent.KEYCODE_MOVE_END: if (KeyEventCompat.hasNoModifiers(event)) { handled = resurrectSelectionIfNeeded() || fullScroll(FOCUS_DOWN); } break; case KeyEvent.KEYCODE_TAB: // XXX Sometimes it is useful to be able to TAB through the items in // a ListView sequentially. Unfortunately this can create an // asymmetry in TAB navigation order unless the list selection // always reverts to the top or bottom when receiving TAB focus from // another widget. Leaving this behavior disabled for now but // perhaps it should be configurable (and more comprehensive). if (false) { if (KeyEventCompat.hasNoModifiers(event)) { handled = resurrectSelectionIfNeeded() || arrowScroll(FOCUS_DOWN); } else if (KeyEventCompat.hasModifiers(event, KeyEvent.META_SHIFT_ON)) { handled = resurrectSelectionIfNeeded() || arrowScroll(FOCUS_UP); } } break; } } if (handled) { return true; } if (sendToTextFilter(keyCode, count, event)) { return true; } switch (action) { case KeyEvent.ACTION_DOWN: return super.onKeyDown(keyCode, event); case KeyEvent.ACTION_UP: return super.onKeyUp(keyCode, event); case KeyEvent.ACTION_MULTIPLE: return super.onKeyMultiple(keyCode, count, event); default: // shouldn't happen return false; } }
From source file:com.appunite.list.HorizontalListView.java
private boolean commonKey(int keyCode, int count, KeyEvent event) { if (mAdapter == null || !mIsAttached) { return false; }// w w w. j av a 2s. co m // TODO I stopped swaping heare (j.m.) if (mDataChanged) { layoutChildren(); } boolean handled = false; int action = event.getAction(); if (action != KeyEvent.ACTION_UP) { switch (keyCode) { case KeyEvent.KEYCODE_DPAD_RIGHT: if (KeyEventCompat.hasNoModifiers(event)) { handled = resurrectSelectionIfNeeded(); if (!handled) { while (count-- > 0) { if (arrowScroll(FOCUS_RIGHT)) { handled = true; } else { break; } } } } else if (KeyEventCompat.hasModifiers(event, KeyEvent.META_ALT_ON)) { handled = resurrectSelectionIfNeeded() || fullScroll(FOCUS_RIGHT); } break; case KeyEvent.KEYCODE_DPAD_LEFT: if (KeyEventCompat.hasNoModifiers(event)) { handled = resurrectSelectionIfNeeded(); if (!handled) { while (count-- > 0) { if (arrowScroll(FOCUS_LEFT)) { handled = true; } else { break; } } } } else if (KeyEventCompat.hasModifiers(event, KeyEvent.META_ALT_ON)) { handled = resurrectSelectionIfNeeded() || fullScroll(FOCUS_LEFT); } break; case KeyEvent.KEYCODE_DPAD_UP: if (KeyEventCompat.hasNoModifiers(event)) { handled = handleHorizontalFocusWithinListItem(View.FOCUS_UP); } break; case KeyEvent.KEYCODE_DPAD_DOWN: if (KeyEventCompat.hasNoModifiers(event)) { handled = handleHorizontalFocusWithinListItem(View.FOCUS_DOWN); } break; case KeyEvent.KEYCODE_DPAD_CENTER: case KeyEvent.KEYCODE_ENTER: if (KeyEventCompat.hasNoModifiers(event)) { handled = resurrectSelectionIfNeeded(); if (!handled && event.getRepeatCount() == 0 && getChildCount() > 0) { keyPressed(); handled = true; } } break; case KeyEvent.KEYCODE_SPACE: if (mPopup == null || !mPopup.isShowing()) { if (KeyEventCompat.hasNoModifiers(event)) { handled = resurrectSelectionIfNeeded() || pageScroll(FOCUS_RIGHT); } else if (KeyEventCompat.hasModifiers(event, KeyEvent.META_SHIFT_ON)) { handled = resurrectSelectionIfNeeded() || pageScroll(FOCUS_LEFT); } handled = true; } break; case KeyEvent.KEYCODE_PAGE_UP: if (KeyEventCompat.hasNoModifiers(event)) { handled = resurrectSelectionIfNeeded() || pageScroll(FOCUS_LEFT); } else if (KeyEventCompat.hasModifiers(event, KeyEvent.META_ALT_ON)) { handled = resurrectSelectionIfNeeded() || fullScroll(FOCUS_LEFT); } break; case KeyEvent.KEYCODE_PAGE_DOWN: if (KeyEventCompat.hasNoModifiers(event)) { handled = resurrectSelectionIfNeeded() || pageScroll(FOCUS_RIGHT); } else if (KeyEventCompat.hasModifiers(event, KeyEvent.META_ALT_ON)) { handled = resurrectSelectionIfNeeded() || fullScroll(FOCUS_RIGHT); } break; case KeyEvent.KEYCODE_MOVE_HOME: if (KeyEventCompat.hasNoModifiers(event)) { handled = resurrectSelectionIfNeeded() || fullScroll(FOCUS_LEFT); } break; case KeyEvent.KEYCODE_MOVE_END: if (KeyEventCompat.hasNoModifiers(event)) { handled = resurrectSelectionIfNeeded() || fullScroll(FOCUS_RIGHT); } break; case KeyEvent.KEYCODE_TAB: // XXX Sometimes it is useful to be able to TAB through the items in // a ListView sequentially. Unfortunately this can create an // asymmetry in TAB navigation order unless the list selection // always reverts to the top or bottom when receiving TAB focus from // another widget. Leaving this behavior disabled for now but // perhaps it should be configurable (and more comprehensive). if (false) { if (KeyEventCompat.hasNoModifiers(event)) { handled = resurrectSelectionIfNeeded() || arrowScroll(FOCUS_RIGHT); } else if (KeyEventCompat.hasModifiers(event, KeyEvent.META_SHIFT_ON)) { handled = resurrectSelectionIfNeeded() || arrowScroll(FOCUS_LEFT); } } break; } } if (handled) { return true; } if (sendToTextFilter(keyCode, count, event)) { return true; } switch (action) { case KeyEvent.ACTION_DOWN: return super.onKeyDown(keyCode, event); case KeyEvent.ACTION_UP: return super.onKeyUp(keyCode, event); case KeyEvent.ACTION_MULTIPLE: return super.onKeyMultiple(keyCode, count, event); default: // shouldn't happen return false; } }
From source file:com.zhongsou.souyue.ui.HListView.java
@TargetApi(11) private boolean commonKey(int keyCode, int count, KeyEvent event) { if (mAdapter == null || !mIsAttached) { return false; }/*from w w w . j a v a 2 s . c o m*/ if (mDataChanged) { layoutChildren(); } if (android.os.Build.VERSION.SDK_INT < 11) { return false; } boolean handled = false; int action = event.getAction(); if (action != KeyEvent.ACTION_UP) { switch (keyCode) { case KeyEvent.KEYCODE_DPAD_UP: if (event.hasNoModifiers()) { handled = resurrectSelectionIfNeeded(); if (!handled) { while (count-- > 0) { if (arrowScroll(FOCUS_UP)) { handled = true; } else { break; } } } } else if (event.hasModifiers(KeyEvent.META_ALT_ON)) { handled = resurrectSelectionIfNeeded() || fullScroll(FOCUS_UP); } break; case KeyEvent.KEYCODE_DPAD_DOWN: if (event.hasNoModifiers()) { handled = resurrectSelectionIfNeeded(); if (!handled) { while (count-- > 0) { if (arrowScroll(FOCUS_DOWN)) { handled = true; } else { break; } } } } else if (event.hasModifiers(KeyEvent.META_ALT_ON)) { handled = resurrectSelectionIfNeeded() || fullScroll(FOCUS_DOWN); } break; case KeyEvent.KEYCODE_DPAD_LEFT: if (event.hasNoModifiers()) { handled = handleHorizontalFocusWithinListItem(View.FOCUS_LEFT); } break; case KeyEvent.KEYCODE_DPAD_RIGHT: if (event.hasNoModifiers()) { handled = handleHorizontalFocusWithinListItem(View.FOCUS_RIGHT); } break; case KeyEvent.KEYCODE_DPAD_CENTER: case KeyEvent.KEYCODE_ENTER: if (event.hasNoModifiers()) { handled = resurrectSelectionIfNeeded(); if (!handled && event.getRepeatCount() == 0 && getChildCount() > 0) { keyPressed(); handled = true; } } break; case KeyEvent.KEYCODE_SPACE: if (event.hasNoModifiers()) { handled = resurrectSelectionIfNeeded() || pageScroll(FOCUS_DOWN); } else if (event.hasModifiers(KeyEvent.META_SHIFT_ON)) { handled = resurrectSelectionIfNeeded() || pageScroll(FOCUS_UP); } handled = true; break; case KeyEvent.KEYCODE_PAGE_UP: if (event.hasNoModifiers()) { handled = resurrectSelectionIfNeeded() || pageScroll(FOCUS_UP); } else if (event.hasModifiers(KeyEvent.META_ALT_ON)) { handled = resurrectSelectionIfNeeded() || fullScroll(FOCUS_UP); } break; case KeyEvent.KEYCODE_PAGE_DOWN: if (event.hasNoModifiers()) { handled = resurrectSelectionIfNeeded() || pageScroll(FOCUS_DOWN); } else if (event.hasModifiers(KeyEvent.META_ALT_ON)) { handled = resurrectSelectionIfNeeded() || fullScroll(FOCUS_DOWN); } break; case KeyEvent.KEYCODE_MOVE_HOME: if (event.hasNoModifiers()) { handled = resurrectSelectionIfNeeded() || fullScroll(FOCUS_UP); } break; case KeyEvent.KEYCODE_MOVE_END: if (event.hasNoModifiers()) { handled = resurrectSelectionIfNeeded() || fullScroll(FOCUS_DOWN); } break; case KeyEvent.KEYCODE_TAB: break; } } if (handled) { return true; } switch (action) { case KeyEvent.ACTION_DOWN: return super.onKeyDown(keyCode, event); case KeyEvent.ACTION_UP: return super.onKeyUp(keyCode, event); case KeyEvent.ACTION_MULTIPLE: return super.onKeyMultiple(keyCode, count, event); default: // shouldn't happen return false; } }
From source file:com.gome.ecmall.custom.VerticalViewPager.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. * /*from w w w .j av a 2 s.co m*/ * @param event * The key event to execute. * @return Return true if the event was handled, else false. */ public boolean executeKeyEvent(KeyEvent event) { boolean handled = false; if (event.getAction() == KeyEvent.ACTION_DOWN) { switch (event.getKeyCode()) { case KeyEvent.KEYCODE_DPAD_UP: handled = arrowScroll(FOCUS_UP); break; case KeyEvent.KEYCODE_DPAD_DOWN: handled = arrowScroll(FOCUS_DOWN); break; case KeyEvent.KEYCODE_TAB: if (Build.VERSION.SDK_INT >= 11) { // The focus finder had a bug handling FOCUS_FORWARD and // FOCUS_BACKWARD // before Android 3.0. Ignore the tab key on those devices. if (KeyEventCompat.hasNoModifiers(event)) { handled = arrowScroll(FOCUS_FORWARD); } else if (KeyEventCompat.hasModifiers(event, KeyEvent.META_SHIFT_ON)) { handled = arrowScroll(FOCUS_BACKWARD); } } break; } } return handled; }
From source file:com.awrtechnologies.carbudgetsales.hlistview.widget.HListView.java
@TargetApi(11) private boolean commonKey(int keyCode, int count, KeyEvent event) { if (mAdapter == null || !mIsAttached) { return false; }//from w ww . ja v a 2 s . co m if (mDataChanged) { layoutChildren(); } if (android.os.Build.VERSION.SDK_INT < 11) { return false; } boolean handled = false; int action = event.getAction(); if (action != KeyEvent.ACTION_UP) { switch (keyCode) { case KeyEvent.KEYCODE_DPAD_LEFT: if (event.hasNoModifiers()) { handled = resurrectSelectionIfNeeded(); if (!handled) { while (count-- > 0) { if (arrowScroll(FOCUS_UP)) { handled = true; } else { break; } } } } else if (event.hasModifiers(KeyEvent.META_ALT_ON)) { handled = resurrectSelectionIfNeeded() || fullScroll(FOCUS_UP); } break; case KeyEvent.KEYCODE_DPAD_RIGHT: if (event.hasNoModifiers()) { handled = resurrectSelectionIfNeeded(); if (!handled) { while (count-- > 0) { if (arrowScroll(FOCUS_DOWN)) { handled = true; } else { break; } } } } else if (event.hasModifiers(KeyEvent.META_ALT_ON)) { handled = resurrectSelectionIfNeeded() || fullScroll(FOCUS_DOWN); } break; case KeyEvent.KEYCODE_DPAD_UP: if (event.hasNoModifiers()) { handled = handleHorizontalFocusWithinListItem(View.FOCUS_UP); } break; case KeyEvent.KEYCODE_DPAD_DOWN: if (event.hasNoModifiers()) { handled = handleHorizontalFocusWithinListItem(View.FOCUS_DOWN); } break; case KeyEvent.KEYCODE_DPAD_CENTER: case KeyEvent.KEYCODE_ENTER: if (event.hasNoModifiers()) { handled = resurrectSelectionIfNeeded(); if (!handled && event.getRepeatCount() == 0 && getChildCount() > 0) { keyPressed(); handled = true; } } break; case KeyEvent.KEYCODE_SPACE: if (event.hasNoModifiers()) { handled = resurrectSelectionIfNeeded() || pageScroll(FOCUS_DOWN); } else if (event.hasModifiers(KeyEvent.META_SHIFT_ON)) { handled = resurrectSelectionIfNeeded() || pageScroll(FOCUS_UP); } handled = true; break; case KeyEvent.KEYCODE_PAGE_UP: if (event.hasNoModifiers()) { handled = resurrectSelectionIfNeeded() || pageScroll(FOCUS_UP); } else if (event.hasModifiers(KeyEvent.META_ALT_ON)) { handled = resurrectSelectionIfNeeded() || fullScroll(FOCUS_UP); } break; case KeyEvent.KEYCODE_PAGE_DOWN: if (event.hasNoModifiers()) { handled = resurrectSelectionIfNeeded() || pageScroll(FOCUS_DOWN); } else if (event.hasModifiers(KeyEvent.META_ALT_ON)) { handled = resurrectSelectionIfNeeded() || fullScroll(FOCUS_DOWN); } break; case KeyEvent.KEYCODE_MOVE_HOME: if (event.hasNoModifiers()) { handled = resurrectSelectionIfNeeded() || fullScroll(FOCUS_UP); } break; case KeyEvent.KEYCODE_MOVE_END: if (event.hasNoModifiers()) { handled = resurrectSelectionIfNeeded() || fullScroll(FOCUS_DOWN); } break; case KeyEvent.KEYCODE_TAB: break; } } if (handled) { return true; } switch (action) { case KeyEvent.ACTION_DOWN: return super.onKeyDown(keyCode, event); case KeyEvent.ACTION_UP: return super.onKeyUp(keyCode, event); case KeyEvent.ACTION_MULTIPLE: return super.onKeyMultiple(keyCode, count, event); default: // shouldn't happen return false; } }
From source file:android.support.v17.leanback.widget.GridWidgetTest.java
public void testMultipleScrollPosition1() throws Throwable { mInstrumentation = getInstrumentation(); Intent intent = new Intent(mInstrumentation.getContext(), GridActivity.class); intent.putExtra(GridActivity.EXTRA_LAYOUT_RESOURCE_ID, R.layout.vertical_linear); intent.putExtra(GridActivity.EXTRA_CHILD_LAYOUT_ID, R.layout.relative_layout); intent.putExtra(GridActivity.EXTRA_REQUEST_FOCUS_ONLAYOUT, true); int[] items = new int[100]; for (int i = 0; i < items.length; i++) { items[i] = 300;/*from w w w .j a v a 2 s .c o m*/ } intent.putExtra(GridActivity.EXTRA_ITEMS, items); intent.putExtra(GridActivity.EXTRA_STAGGERED, false); intent.putExtra(GridActivity.EXTRA_VIEWTYPEPROVIDER_CLASS, TwoViewTypesProvider.class.getName()); // Set ItemAlignment for each ViewHolder and view type, ViewHolder should // override the view type settings. intent.putExtra(GridActivity.EXTRA_ITEMALIGNMENTPROVIDER_CLASS, PositionItemAlignmentFacetProviderForRelativeLayout1.class.getName()); intent.putExtra(GridActivity.EXTRA_ITEMALIGNMENTPROVIDER_VIEWTYPE_CLASS, ViewTypePositionItemAlignmentFacetProviderForRelativeLayout2.class.getName()); mOrientation = BaseGridView.VERTICAL; mNumRows = 1; initActivity(intent); assertEquals("First view is aligned with padding top", mGridView.getPaddingTop(), mGridView.getChildAt(0).getTop()); sendKeys(KeyEvent.KEYCODE_DPAD_DOWN); waitForScrollIdle(mVerifyLayout); final View v = mGridView.getChildAt(0); View t1 = v.findViewById(R.id.t1); int t1align = (t1.getTop() + t1.getBottom()) / 2; View t2 = v.findViewById(R.id.t2); int t2align = t2.getBottom() - 10; assertEquals("Expected alignment for 2nd textview", mGridView.getPaddingTop() - (t2align - t1align), v.getTop()); }
From source file:org.bangbang.support.v4.widget.VerticalViewPager.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 w w . ja v a2 s. c o m * * @param event The key event to execute. * @return Return true if the event was handled, else false. */ public boolean executeKeyEvent(KeyEvent event) { boolean handled = false; if (event.getAction() == KeyEvent.ACTION_DOWN) { switch (event.getKeyCode()) { case KeyEvent.KEYCODE_DPAD_UP: handled = arrowScroll(FOCUS_UP); break; case KeyEvent.KEYCODE_DPAD_DOWN: handled = arrowScroll(FOCUS_DOWN); break; case KeyEvent.KEYCODE_TAB: if (Build.VERSION.SDK_INT >= 11) { // The focus finder had a bug handling FOCUS_FORWARD and FOCUS_BACKWARD // before Android 3.0. Ignore the tab key on those devices. if (KeyEventCompat.hasNoModifiers(event)) { handled = arrowScroll(FOCUS_FORWARD); } else if (KeyEventCompat.hasModifiers(event, KeyEvent.META_SHIFT_ON)) { handled = arrowScroll(FOCUS_BACKWARD); } } break; } } return handled; }
From source file:com.aliasapps.seq.scroller.TwoWayView.java
private boolean handleKeyEvent(int keyCode, int count, KeyEvent event) { if (mAdapter == null || !mIsAttached) { return false; }/*ww w. j ava2 s . c o m*/ if (mDataChanged) { layoutChildren(); } boolean handled = false; final int action = event.getAction(); if (action != KeyEvent.ACTION_UP) { switch (keyCode) { case KeyEvent.KEYCODE_DPAD_UP: if (mIsVertical) { handled = handleKeyScroll(event, count, View.FOCUS_UP); } else if (KeyEventCompat.hasNoModifiers(event)) { handled = handleFocusWithinItem(View.FOCUS_UP); } break; case KeyEvent.KEYCODE_DPAD_DOWN: { if (mIsVertical) { handled = handleKeyScroll(event, count, View.FOCUS_DOWN); } else if (KeyEventCompat.hasNoModifiers(event)) { handled = handleFocusWithinItem(View.FOCUS_DOWN); } break; } case KeyEvent.KEYCODE_DPAD_LEFT: if (!mIsVertical) { handled = handleKeyScroll(event, count, View.FOCUS_LEFT); } else if (KeyEventCompat.hasNoModifiers(event)) { handled = handleFocusWithinItem(View.FOCUS_LEFT); } break; case KeyEvent.KEYCODE_DPAD_RIGHT: if (!mIsVertical) { handled = handleKeyScroll(event, count, View.FOCUS_RIGHT); } else if (KeyEventCompat.hasNoModifiers(event)) { handled = handleFocusWithinItem(View.FOCUS_RIGHT); } break; case KeyEvent.KEYCODE_DPAD_CENTER: case KeyEvent.KEYCODE_ENTER: if (KeyEventCompat.hasNoModifiers(event)) { handled = resurrectSelectionIfNeeded(); if (!handled && event.getRepeatCount() == 0 && getChildCount() > 0) { keyPressed(); handled = true; } } break; case KeyEvent.KEYCODE_SPACE: if (KeyEventCompat.hasNoModifiers(event)) { handled = resurrectSelectionIfNeeded() || pageScroll(mIsVertical ? View.FOCUS_DOWN : View.FOCUS_RIGHT); } else if (KeyEventCompat.hasModifiers(event, KeyEvent.META_SHIFT_ON)) { handled = resurrectSelectionIfNeeded() || fullScroll(mIsVertical ? View.FOCUS_UP : View.FOCUS_LEFT); } handled = true; break; case KeyEvent.KEYCODE_PAGE_UP: if (KeyEventCompat.hasNoModifiers(event)) { handled = resurrectSelectionIfNeeded() || pageScroll(mIsVertical ? View.FOCUS_UP : View.FOCUS_LEFT); } else if (KeyEventCompat.hasModifiers(event, KeyEvent.META_ALT_ON)) { handled = resurrectSelectionIfNeeded() || fullScroll(mIsVertical ? View.FOCUS_UP : View.FOCUS_LEFT); } break; case KeyEvent.KEYCODE_PAGE_DOWN: if (KeyEventCompat.hasNoModifiers(event)) { handled = resurrectSelectionIfNeeded() || pageScroll(mIsVertical ? View.FOCUS_DOWN : View.FOCUS_RIGHT); } else if (KeyEventCompat.hasModifiers(event, KeyEvent.META_ALT_ON)) { handled = resurrectSelectionIfNeeded() || fullScroll(mIsVertical ? View.FOCUS_DOWN : View.FOCUS_RIGHT); } break; case KeyEvent.KEYCODE_MOVE_HOME: if (KeyEventCompat.hasNoModifiers(event)) { handled = resurrectSelectionIfNeeded() || fullScroll(mIsVertical ? View.FOCUS_UP : View.FOCUS_LEFT); } break; case KeyEvent.KEYCODE_MOVE_END: if (KeyEventCompat.hasNoModifiers(event)) { handled = resurrectSelectionIfNeeded() || fullScroll(mIsVertical ? View.FOCUS_DOWN : View.FOCUS_RIGHT); } break; } } if (handled) { return true; } switch (action) { case KeyEvent.ACTION_DOWN: return super.onKeyDown(keyCode, event); case KeyEvent.ACTION_UP: if (!isEnabled()) { return true; } if (isClickable() && isPressed() && mSelectedPosition >= 0 && mAdapter != null && mSelectedPosition < mAdapter.getCount()) { final View child = getChildAt(mSelectedPosition - mFirstPosition); if (child != null) { performItemClick(child, mSelectedPosition, mSelectedRowId); child.setPressed(false); } setPressed(false); return true; } return false; case KeyEvent.ACTION_MULTIPLE: return super.onKeyMultiple(keyCode, count, event); default: return false; } }
From source file:android.support.v17.leanback.widget.GridWidgetTest.java
public void testMultipleScrollPosition2() throws Throwable { mInstrumentation = getInstrumentation(); Intent intent = new Intent(mInstrumentation.getContext(), GridActivity.class); intent.putExtra(GridActivity.EXTRA_LAYOUT_RESOURCE_ID, R.layout.vertical_linear); intent.putExtra(GridActivity.EXTRA_CHILD_LAYOUT_ID, R.layout.relative_layout); intent.putExtra(GridActivity.EXTRA_REQUEST_FOCUS_ONLAYOUT, true); int[] items = new int[100]; for (int i = 0; i < items.length; i++) { items[i] = 300;/*w w w. jav a 2 s . co m*/ } intent.putExtra(GridActivity.EXTRA_ITEMS, items); intent.putExtra(GridActivity.EXTRA_STAGGERED, false); intent.putExtra(GridActivity.EXTRA_VIEWTYPEPROVIDER_CLASS, TwoViewTypesProvider.class.getName()); intent.putExtra(GridActivity.EXTRA_ITEMALIGNMENTPROVIDER_CLASS, PositionItemAlignmentFacetProviderForRelativeLayout2.class.getName()); mOrientation = BaseGridView.VERTICAL; mNumRows = 1; initActivity(intent); assertEquals("First view is aligned with padding top", mGridView.getPaddingTop(), mGridView.getChildAt(0).getTop()); sendKeys(KeyEvent.KEYCODE_DPAD_DOWN); waitForScrollIdle(mVerifyLayout); final View v = mGridView.getChildAt(0); View t1 = v.findViewById(R.id.t1); int t1align = t1.getTop(); View t2 = v.findViewById(R.id.t2); int t2align = t2.getTop() - 10; assertEquals("Expected alignment for 2nd textview", mGridView.getPaddingTop() - (t2align - t1align), v.getTop()); }
From source file:android.support.v17.leanback.widget.GridWidgetTest.java
public void testMultipleScrollPosition3() throws Throwable { mInstrumentation = getInstrumentation(); Intent intent = new Intent(mInstrumentation.getContext(), GridActivity.class); intent.putExtra(GridActivity.EXTRA_LAYOUT_RESOURCE_ID, R.layout.vertical_linear); intent.putExtra(GridActivity.EXTRA_CHILD_LAYOUT_ID, R.layout.relative_layout); intent.putExtra(GridActivity.EXTRA_REQUEST_FOCUS_ONLAYOUT, true); int[] items = new int[100]; for (int i = 0; i < items.length; i++) { items[i] = 300;//from w w w . j ava 2s .co m } intent.putExtra(GridActivity.EXTRA_ITEMS, items); intent.putExtra(GridActivity.EXTRA_STAGGERED, false); intent.putExtra(GridActivity.EXTRA_VIEWTYPEPROVIDER_CLASS, TwoViewTypesProvider.class.getName()); intent.putExtra(GridActivity.EXTRA_ITEMALIGNMENTPROVIDER_VIEWTYPE_CLASS, ViewTypePositionItemAlignmentFacetProviderForRelativeLayout2.class.getName()); mOrientation = BaseGridView.VERTICAL; mNumRows = 1; initActivity(intent); assertEquals("First view is aligned with padding top", mGridView.getPaddingTop(), mGridView.getChildAt(0).getTop()); sendKeys(KeyEvent.KEYCODE_DPAD_DOWN); waitForScrollIdle(mVerifyLayout); final View v = mGridView.getChildAt(0); View t1 = v.findViewById(R.id.t1); int t1align = t1.getTop(); View t2 = v.findViewById(R.id.t2); int t2align = t2.getBottom() - 10; assertEquals("Expected alignment for 2nd textview", mGridView.getPaddingTop() - (t2align - t1align), v.getTop()); }