Java Code Examples for android.view.KeyEvent#KEYCODE_DPAD_UP

The following examples show how to use android.view.KeyEvent#KEYCODE_DPAD_UP . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: InternalSelectionView.java    From codeexamples-android with Eclipse Public License 1.0 6 votes vote down vote up
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
    switch(event.getKeyCode()) {
        case KeyEvent.KEYCODE_DPAD_UP:
            if (mSelectedRow > 0) {
                mSelectedRow--;
                invalidate();
                ensureRectVisible();
                return true;
            }
            break;
        case KeyEvent.KEYCODE_DPAD_DOWN:
            if (mSelectedRow < (mNumRows - 1)) {
                mSelectedRow++;
                invalidate();
                ensureRectVisible();
                return true;
            }
            break;
    }
    return false;
}
 
Example 2
Source File: RobocarActivity.java    From robocar with Apache License 2.0 6 votes vote down vote up
private boolean handleKeyCode(int keyCode) {
    if (mCarController != null) {
        switch (keyCode) {
            case KeyEvent.KEYCODE_DPAD_UP: //19
                mCarController.onCarCommand(CarCommands.GO_FORWARD);
                return true;
            case KeyEvent.KEYCODE_DPAD_DOWN: //20
                mCarController.onCarCommand(CarCommands.GO_BACK);
                return true;
            case KeyEvent.KEYCODE_DPAD_LEFT: //21
                mCarController.onCarCommand(CarCommands.TURN_LEFT);
                return true;
            case KeyEvent.KEYCODE_DPAD_RIGHT: //22
                mCarController.onCarCommand(CarCommands.TURN_RIGHT);
                return true;
            case KeyEvent.KEYCODE_DPAD_CENTER: //23
                mCarController.onCarCommand(CarCommands.STOP);
                return true;
        }
    }
    return false;
}
 
Example 3
Source File: VDVideoResolutionButton.java    From NewsMe with Apache License 2.0 6 votes vote down vote up
@Override
public boolean onKeyUp(int keyCode, KeyEvent event) {
	VDLog.e("VDVideoResolutionButton", " onKeyUp keyCode = " + keyCode);
	VDVideoViewController controller = VDVideoViewController
			.getInstance(mContext);
	if (keyCode == KeyEvent.KEYCODE_DPAD_UP) {
		VDLog.e("VDVideoResolutionButton",
				" onKeyUp KEYCODE_DPAD_UP 111111111");
		if (controller == null) {
			return super.onKeyUp(keyCode, event);
		}
		// mVDVideoResolutionList.focusFirstView();
		controller.notifyResolutionListButtonFocusFirst();
		int id = getNextFocusUpId();
		View v = ((ViewGroup) getParent()).findViewById(id);
		if (v != null) {
			VDLog.e("VDVideoResolutionButton", " onKeyUp KEYCODE_DPAD_UP");
			v.requestFocus();
		}
		// return true;
	}
	return super.onKeyUp(keyCode, event);
}
 
Example 4
Source File: AppAdapter.java    From HgLauncher with GNU General Public License v3.0 5 votes vote down vote up
private static boolean isUp(int keycode) {
    switch (keycode) {
        case KeyEvent.KEYCODE_SYSTEM_NAVIGATION_UP:
        case KeyEvent.KEYCODE_DPAD_UP:
            return true;
        default:
            return false;
    }
}
 
Example 5
Source File: BlurActivity.java    From base-module with Apache License 2.0 5 votes vote down vote up
@Override
    public boolean onKeyUp(int keyCode, KeyEvent event) {
        if (keyCode == KeyEvent.KEYCODE_DPAD_RIGHT) {
            DBlur.source(this, R.drawable.timg).modeRs().radius(radius).sampling(sampling).build().doBlur();
//            testBlur();
        } else if (keyCode == KeyEvent.KEYCODE_DPAD_LEFT) {

            DBlur.source(this, R.drawable.image).mode(i++).radius(radius).sampling(sampling).build()
                    .doBlur(new OnBlurListener() {
                        @Override
                        public void onBlurSuccess(Bitmap bitmap) {
                            Log.e("!!!!!", "onBlurSuccess");
                            imageView1.setImageBitmap(bitmap);
                        }

                        @Override
                        public void onBlurFailed() {
                            Log.e("!!!!!", "onBlurFailed");
                        }
                    });

        } else if (keyCode == KeyEvent.KEYCODE_DPAD_UP) {
            DBlur.source(this).intoTarget(imageView1).animAlpha().mode(i).radius(radius++).sampling(sampling).build().doBlur();
        } else if (keyCode == KeyEvent.KEYCODE_DPAD_DOWN) {
            DBlur.source(imageView).intoTarget(imageView1).animAlpha().mode(i).radius(radius).sampling(sampling++).build().doBlur();
        }
        if (i > 3) {
            i = 0;
        }

        return super.onKeyUp(keyCode, event);
    }
 
Example 6
Source File: TextPicker.java    From GifAssistant with Apache License 2.0 5 votes vote down vote up
@Override
public boolean dispatchKeyEvent(KeyEvent event) {
    final int keyCode = event.getKeyCode();
    switch (keyCode) {
        case KeyEvent.KEYCODE_DPAD_CENTER:
        case KeyEvent.KEYCODE_ENTER:
            removeAllCallbacks();
            break;
        case KeyEvent.KEYCODE_DPAD_DOWN:
        case KeyEvent.KEYCODE_DPAD_UP:
            if (!mHasSelectorWheel) {
                break;
            }
            switch (event.getAction()) {
                case KeyEvent.ACTION_DOWN:
                    if (mWrapSelectorWheel || (keyCode == KeyEvent.KEYCODE_DPAD_DOWN)
                            ? getValue() < getMaxValue() : getValue() > getMinValue()) {
                        requestFocus();
                        mLastHandledDownDpadKeyCode = keyCode;
                        removeAllCallbacks();
                        if (mFlingScroller.isFinished()) {
                            changeValueByOne(keyCode == KeyEvent.KEYCODE_DPAD_DOWN);
                        }
                        return true;
                    }
                    break;
                case KeyEvent.ACTION_UP:
                    if (mLastHandledDownDpadKeyCode == keyCode) {
                        mLastHandledDownDpadKeyCode = -1;
                        return true;
                    }
                    break;
            }
    }
    return super.dispatchKeyEvent(event);
}
 
Example 7
Source File: SkbContainer.java    From AndroidTVWidget with Apache License 2.0 5 votes vote down vote up
/**
 * 处理DOWN事件.
 */
@Override
public boolean onSoftKeyDown(int keyCode, KeyEvent event) {
	if (!isFocused()) {
		return false;
	}
	SoftKey tempSoftKey = new SoftKey();
	OPENLOG.D("onSoftKeyDown keyCode:" + keyCode);
	switch (keyCode) {
	case KeyEvent.KEYCODE_ENTER:
	case KeyEvent.KEYCODE_DPAD_CENTER:
		SoftKeyboard softKeyboard = mSoftKeyboardView.getSoftKeyboard();
		SoftKey softKey = softKeyboard.getSelectSoftKey();
		mSoftKeyboardView.setSoftKeyPress(true);
		OPENLOG.D("onSoftKeyDown softKey:" + softKey);
		if (!setKeyCodeEnter(softKey)) {
			return false;
		}
		break;
	case KeyEvent.KEYCODE_BACK:
		tempSoftKey.setKeyCode(KeyEvent.KEYCODE_BACK);
		onBack(tempSoftKey);
		break;
	case KeyEvent.KEYCODE_DEL:
		tempSoftKey.setKeyCode(KeyEvent.KEYCODE_DEL);
		onDelete(tempSoftKey);
		break;
	case KeyEvent.KEYCODE_DPAD_LEFT: // 左
	case KeyEvent.KEYCODE_DPAD_RIGHT: // 右
	case KeyEvent.KEYCODE_DPAD_UP: // 上
	case KeyEvent.KEYCODE_DPAD_DOWN: // 下
		mSoftKeyboardView.setSoftKeyPress(false);
		return actionForKeyEvent(keyCode); // 按键移动.
	default:
		OPENLOG.D("onSoftKeyDown false keyCode:" + keyCode);
		return false;
	}
	OPENLOG.D("onSoftKeyDown true keyCode:" + keyCode);
	return true;
}
 
Example 8
Source File: NumberPicker.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
@Override
public boolean dispatchKeyEvent(KeyEvent event) {
    final int keyCode = event.getKeyCode();
    switch (keyCode) {
        case KeyEvent.KEYCODE_DPAD_CENTER:
        case KeyEvent.KEYCODE_ENTER:
            removeAllCallbacks();
            break;
        case KeyEvent.KEYCODE_DPAD_DOWN:
        case KeyEvent.KEYCODE_DPAD_UP:
            switch (event.getAction()) {
                case KeyEvent.ACTION_DOWN:
                    if (mWrapSelectorWheel || (keyCode == KeyEvent.KEYCODE_DPAD_DOWN)
                            ? getValue() < getMaxValue() : getValue() > getMinValue()) {
                        requestFocus();
                        mLastHandledDownDpadKeyCode = keyCode;
                        removeAllCallbacks();
                        if (mFlingScroller.isFinished()) {
                            changeValueByOne(keyCode == KeyEvent.KEYCODE_DPAD_DOWN);
                        }
                        return true;
                    }
                    break;
                case KeyEvent.ACTION_UP:
                    if (mLastHandledDownDpadKeyCode == keyCode) {
                        mLastHandledDownDpadKeyCode = -1;
                        return true;
                    }
                    break;
            }
    }
    return super.dispatchKeyEvent(event);
}
 
Example 9
Source File: SliderKeyTestCommon.java    From material-components-android with Apache License 2.0 5 votes vote down vote up
@Test
public void testFocusDefaultThumb_clickUpDPad_unhandled() {
  slider.requestFocus();

  KeyEventBuilder up = new KeyEventBuilder(KeyEvent.KEYCODE_DPAD_UP);
  boolean handledDown = slider.dispatchKeyEvent(up.buildDown());
  boolean handledUp = slider.dispatchKeyEvent(up.buildUp());

  assertThat(handledDown).isFalse();
  assertThat(handledUp).isFalse();
}
 
Example 10
Source File: NumberPicker.java    From ticdesign with Apache License 2.0 5 votes vote down vote up
@Override
public boolean dispatchKeyEvent(KeyEvent event) {
    final int keyCode = event.getKeyCode();
    switch (keyCode) {
        case KeyEvent.KEYCODE_DPAD_CENTER:
        case KeyEvent.KEYCODE_ENTER:
            removeAllCallbacks();
            break;
        case KeyEvent.KEYCODE_DPAD_DOWN:
        case KeyEvent.KEYCODE_DPAD_UP:
            if (!mHasSelectorWheel) {
                break;
            }
            switch (event.getAction()) {
                case KeyEvent.ACTION_DOWN:
                    if (mWrapSelectorWheel || ((keyCode == KeyEvent.KEYCODE_DPAD_DOWN)
                            ? getValue() < getMaxValue() : getValue() > getMinValue())) {
                        requestFocus();
                        mLastHandledDownDpadKeyCode = keyCode;
                        removeAllCallbacks();
                        if (mFlingScroller.isFinished()) {
                            changeValueByOne(keyCode == KeyEvent.KEYCODE_DPAD_DOWN);
                        }
                        return true;
                    }
                    break;
                case KeyEvent.ACTION_UP:
                    if (mLastHandledDownDpadKeyCode == keyCode) {
                        mLastHandledDownDpadKeyCode = -1;
                        return true;
                    }
                    break;
            }
    }
    return super.dispatchKeyEvent(event);
}
 
Example 11
Source File: PlaybackActivity.java    From android-vlc-remote with GNU General Public License v3.0 4 votes vote down vote up
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
    int c = event.getUnicodeChar();
    if (keyCode == KeyEvent.KEYCODE_VOLUME_UP) {
        if (mVolumeLevel != VOLUME_LEVEL_UNKNOWN) {
            setVolume(mVolumeLevel + 20);
        } else {
            mMediaServer.status().command.volumeUp();
        }
        return true;
    } else if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN) {
        if (mVolumeLevel != VOLUME_LEVEL_UNKNOWN) {
            setVolume(mVolumeLevel - 20);
        } else {
            mMediaServer.status().command.volumeDown();
        }
        return true;
    } else if (keyCode == KeyEvent.KEYCODE_DPAD_LEFT) {
        if (event.isAltPressed()) {
            mMediaServer.status().command.seek(Uri.encode("-".concat(Preferences.get(this).getSeekTime())));
            return true;
        } else if (event.isShiftPressed()) {
            mMediaServer.status().command.seek(Uri.encode("-3"));
            return true;
        } else {
            mMediaServer.status().command.key("nav-left");
            return true;
        }
    } else if (keyCode == KeyEvent.KEYCODE_DPAD_RIGHT) {
        if (event.isAltPressed()) {
            mMediaServer.status().command.seek(Uri.encode("+".concat(Preferences.get(this).getSeekTime())));
            return true;
        } else if (event.isShiftPressed()) {
            mMediaServer.status().command.seek(Uri.encode("+3"));
            return true;
        } else {
            mMediaServer.status().command.key("nav-right");
            return true;
        }
    } else if (keyCode == KeyEvent.KEYCODE_DPAD_UP) {
        mMediaServer.status().command.key("nav-up");
        return true;
    } else if (keyCode == KeyEvent.KEYCODE_DPAD_DOWN) {
        mMediaServer.status().command.key("nav-down");
        return true;
    } else if (keyCode == KeyEvent.KEYCODE_DPAD_CENTER) {
        mMediaServer.status().command.key("nav-activate");
        return true;
    } else if (c == ' ') {
        mMediaServer.status().command.playback.pause();
        return true;
    } else if (c == 's') {
        mMediaServer.status().command.playback.stop();
        return true;
    } else if (c == 'p') {
        mMediaServer.status().command.playback.previous();
        return true;
    } else if (c == 'n') {
        mMediaServer.status().command.playback.next();
        return true;
    } else if (c == '+') {
        // TODO: Play faster
        return super.onKeyDown(keyCode, event);
    } else if (c == '-') {
        // TODO: Play slower
        return super.onKeyDown(keyCode, event);
    } else if (c == 'f') {
        mMediaServer.status().command.fullscreen();
        return true;
    } else if (c == 'm') {
        mute();
        return true;
    } else {
        return super.onKeyDown(keyCode, event);
    }
}
 
Example 12
Source File: SimpleMonthView.java    From DateTimePicker with Apache License 2.0 4 votes vote down vote up
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
    // We need to handle focus change within the SimpleMonthView because we are simulating
    // multiple Views. The arrow keys will move between days until there is no space (no
    // day to the left, top, right, or bottom). Focus forward and back jumps out of the
    // SimpleMonthView, skipping over other SimpleMonthViews in the parent ViewPager
    // to the next focusable View in the hierarchy.
    boolean focusChanged = false;
    switch (event.getKeyCode()) {
        case KeyEvent.KEYCODE_DPAD_LEFT:
            if (event.hasNoModifiers()) {
                focusChanged = moveOneDay(isLayoutRtl());
            }
            break;
        case KeyEvent.KEYCODE_DPAD_RIGHT:
            if (event.hasNoModifiers()) {
                focusChanged = moveOneDay(!isLayoutRtl());
            }
            break;
        case KeyEvent.KEYCODE_DPAD_UP:
            if (event.hasNoModifiers()) {
                ensureFocusedDay();
                if (mHighlightedDay > 7) {
                    mHighlightedDay -= 7;
                    focusChanged = true;
                }
            }
            break;
        case KeyEvent.KEYCODE_DPAD_DOWN:
            if (event.hasNoModifiers()) {
                ensureFocusedDay();
                if (mHighlightedDay <= mDaysInMonth - 7) {
                    mHighlightedDay += 7;
                    focusChanged = true;
                }
            }
            break;
        case KeyEvent.KEYCODE_DPAD_CENTER:
        case KeyEvent.KEYCODE_ENTER:
            if (mHighlightedDay != -1) {
                onDayClicked(mHighlightedDay);
                return true;
            }
            break;
        case KeyEvent.KEYCODE_TAB: {
            int focusChangeDirection = 0;
            if (event.hasNoModifiers()) {
                focusChangeDirection = View.FOCUS_FORWARD;
            } else if (event.hasModifiers(KeyEvent.META_SHIFT_ON)) {
                focusChangeDirection = View.FOCUS_BACKWARD;
            }
            if (focusChangeDirection != 0) {
                final ViewParent parent = getParent();
                // move out of the ViewPager next/previous
                View nextFocus = this;
                do {
                    nextFocus = nextFocus.focusSearch(focusChangeDirection);
                } while (nextFocus != null && nextFocus != this &&
                        nextFocus.getParent() == parent);
                if (nextFocus != null) {
                    nextFocus.requestFocus();
                    return true;
                }
            }
            break;
        }
    }
    if (focusChanged) {
        invalidate();
        return true;
    } else {
        return super.onKeyDown(keyCode, event);
    }
}
 
Example 13
Source File: Dpad.java    From Alite with GNU General Public License v3.0 4 votes vote down vote up
public int getDirectionPressed(InputEvent event) {
	if (!isDpadDevice(event)) {
		return -1;
	}
	directionPressed = NONE;
	
	// If the input event is a MotionEvent, check its hat axis values.
	if (event instanceof MotionEvent) {

		// Use the hat axis value to find the D-pad direction
		MotionEvent motionEvent = (MotionEvent) event;
		float xaxis = motionEvent.getAxisValue(MotionEvent.AXIS_HAT_X);
		float yaxis = motionEvent.getAxisValue(MotionEvent.AXIS_HAT_Y);
		boolean nox = false;
		boolean noy = false;
		
		// Check if the AXIS_HAT_X value is -1 or 1, and set the D-pad
		// LEFT and RIGHT direction accordingly.
		if (Float.compare(xaxis, -1.0f) == 0) {
			directionPressed = Dpad.LEFT;
		} else if (Float.compare(xaxis, 1.0f) == 0) {
			directionPressed = Dpad.RIGHT;
		} else if (Float.compare(xaxis, 0.0f) == 0) {
			nox = true;  
		}
		// Check if the AXIS_HAT_Y value is -1 or 1, and set the D-pad
		// UP and DOWN direction accordingly.
		else if (Float.compare(yaxis, -1.0f) == 0) {
			directionPressed = Dpad.UP;
		} else if (Float.compare(yaxis, 1.0f) == 0) {
			directionPressed = Dpad.DOWN;
		} else if (Float.compare(yaxis, 0.0f) == 0) {
			noy = true;
		}			
		
		if (nox && noy) {
			directionPressed = Dpad.NONE;
		}
	}

	// If the input event is a KeyEvent, check its key code.
	else if (event instanceof KeyEvent) {
		// Use the key code to find the D-pad direction.
		KeyEvent keyEvent = (KeyEvent) event;
		if (keyEvent.getKeyCode() == KeyEvent.KEYCODE_DPAD_LEFT) {
			directionPressed = Dpad.LEFT;
		} else if (keyEvent.getKeyCode() == KeyEvent.KEYCODE_DPAD_RIGHT) {
			directionPressed = Dpad.RIGHT;
		} else if (keyEvent.getKeyCode() == KeyEvent.KEYCODE_DPAD_UP) {
			directionPressed = Dpad.UP;
		} else if (keyEvent.getKeyCode() == KeyEvent.KEYCODE_DPAD_DOWN) {
			directionPressed = Dpad.DOWN;
		} else if (keyEvent.getKeyCode() == KeyEvent.KEYCODE_DPAD_CENTER) {
			directionPressed = Dpad.CENTER;
		}
	}
	return directionPressed;
}
 
Example 14
Source File: MetroLayout.java    From android_tv_metro with Apache License 2.0 4 votes vote down vote up
@Override
public boolean dispatchKeyEvent(KeyEvent event) {
    // Handle automatic focus changes.
    if (event.getAction() == KeyEvent.ACTION_DOWN) {
        int direction = 0;
        switch (event.getKeyCode()) {
            case KeyEvent.KEYCODE_DPAD_LEFT:
                if (event.hasNoModifiers()) {
                    direction = View.FOCUS_LEFT;
                }
                break;
            case KeyEvent.KEYCODE_DPAD_RIGHT:
                if (event.hasNoModifiers()) {
                    direction = View.FOCUS_RIGHT;
                }
                break;
            case KeyEvent.KEYCODE_DPAD_UP:
                if (event.hasNoModifiers()) {
                    direction = View.FOCUS_UP;
                }
                break;
            case KeyEvent.KEYCODE_DPAD_DOWN:
                if (event.hasNoModifiers()) {
                    direction = View.FOCUS_DOWN;
                }
                break;
            case KeyEvent.KEYCODE_TAB:
                if (event.hasNoModifiers()) {
                    direction = View.FOCUS_FORWARD;
                } else if (event.hasModifiers(KeyEvent.META_SHIFT_ON)) {
                    direction = View.FOCUS_BACKWARD;
                }
                break;
        }
        if (direction == View.FOCUS_DOWN || direction == View.FOCUS_UP) {
            View focused = findFocus();
            if (focused != null) {
                View v = focused.focusSearch(direction);
                if (v == null) {
                    Utils.playKeySound(this, Utils.SOUND_ERROR_KEY);
                    mMetroCursorView.showIndicator();
                }
            }
        }
    }
    boolean ret = super.dispatchKeyEvent(event);
    return ret;
}
 
Example 15
Source File: ScrollView.java    From android_9.0.0_r45 with Apache License 2.0 4 votes vote down vote up
/**
 * 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.
 *
 * @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 (!canScroll()) {
        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_UP:
                if (!event.isAltPressed()) {
                    handled = arrowScroll(View.FOCUS_UP);
                } else {
                    handled = fullScroll(View.FOCUS_UP);
                }
                break;
            case KeyEvent.KEYCODE_DPAD_DOWN:
                if (!event.isAltPressed()) {
                    handled = arrowScroll(View.FOCUS_DOWN);
                } else {
                    handled = fullScroll(View.FOCUS_DOWN);
                }
                break;
            case KeyEvent.KEYCODE_SPACE:
                pageScroll(event.isShiftPressed() ? View.FOCUS_UP : View.FOCUS_DOWN);
                break;
        }
    }

    return handled;
}
 
Example 16
Source File: SimpleMonthView.java    From android_9.0.0_r45 with Apache License 2.0 4 votes vote down vote up
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
    // We need to handle focus change within the SimpleMonthView because we are simulating
    // multiple Views. The arrow keys will move between days until there is no space (no
    // day to the left, top, right, or bottom). Focus forward and back jumps out of the
    // SimpleMonthView, skipping over other SimpleMonthViews in the parent ViewPager
    // to the next focusable View in the hierarchy.
    boolean focusChanged = false;
    switch (event.getKeyCode()) {
        case KeyEvent.KEYCODE_DPAD_LEFT:
            if (event.hasNoModifiers()) {
                focusChanged = moveOneDay(isLayoutRtl());
            }
            break;
        case KeyEvent.KEYCODE_DPAD_RIGHT:
            if (event.hasNoModifiers()) {
                focusChanged = moveOneDay(!isLayoutRtl());
            }
            break;
        case KeyEvent.KEYCODE_DPAD_UP:
            if (event.hasNoModifiers()) {
                ensureFocusedDay();
                if (mHighlightedDay > 7) {
                    mHighlightedDay -= 7;
                    focusChanged = true;
                }
            }
            break;
        case KeyEvent.KEYCODE_DPAD_DOWN:
            if (event.hasNoModifiers()) {
                ensureFocusedDay();
                if (mHighlightedDay <= mDaysInMonth - 7) {
                    mHighlightedDay += 7;
                    focusChanged = true;
                }
            }
            break;
        case KeyEvent.KEYCODE_DPAD_CENTER:
        case KeyEvent.KEYCODE_ENTER:
            if (mHighlightedDay != -1) {
                onDayClicked(mHighlightedDay);
                return true;
            }
            break;
        case KeyEvent.KEYCODE_TAB: {
            int focusChangeDirection = 0;
            if (event.hasNoModifiers()) {
                focusChangeDirection = View.FOCUS_FORWARD;
            } else if (event.hasModifiers(KeyEvent.META_SHIFT_ON)) {
                focusChangeDirection = View.FOCUS_BACKWARD;
            }
            if (focusChangeDirection != 0) {
                final ViewParent parent = getParent();
                // move out of the ViewPager next/previous
                View nextFocus = this;
                do {
                    nextFocus = nextFocus.focusSearch(focusChangeDirection);
                } while (nextFocus != null && nextFocus != this &&
                        nextFocus.getParent() == parent);
                if (nextFocus != null) {
                    nextFocus.requestFocus();
                    return true;
                }
            }
            break;
        }
    }
    if (focusChanged) {
        invalidate();
        return true;
    } else {
        return super.onKeyDown(keyCode, event);
    }
}
 
Example 17
Source File: VideoPlayerActivity.java    From OTTLivePlayer_vlc with MIT License 4 votes vote down vote up
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
    switch (keyCode) {
        case KeyEvent.KEYCODE_DPAD_CENTER:
        case KeyEvent.KEYCODE_ENTER:
            if (event.getRepeatCount() != 0) {
                break;
            }

            togglePlaylist();
            break;

        case KeyEvent.KEYCODE_DPAD_UP:
            if (currentListItemID == 0) {
                lvProgram.setSelection(liveBean.getData().size() - 1);
            }

            if (llProgramList.getVisibility() == View.VISIBLE) {
                return false;
            }
            previous();
            showProgramInfo();
            break;

        case KeyEvent.KEYCODE_DPAD_DOWN:
            if (currentListItemID == liveBean.getData().size() - 1) {
                lvProgram.setSelection(0);
            }

            if (llProgramList.getVisibility() == View.VISIBLE) {
                return false;
            }
            next();
            showProgramInfo();
            break;

        case KeyEvent.KEYCODE_MENU:
            showProgramInfo();
            handler.sendEmptyMessageDelayed(CODE_GONE_PROGRAMINFO, 4000);
            break;
    }
    return super.onKeyDown(keyCode, event);
}
 
Example 18
Source File: SoundTool.java    From zidoorecorder with Apache License 2.0 4 votes vote down vote up
/**
 * 
 * 播放声音
 * 
 * @author jiangbo
 * @param keyCode
 *            2013-12-5
 */
public static void soundKey(int keyCode) {
	if (!ISSOUND) {
		return;
	}
	try {
		// AudioManager mAudioManager = (AudioManager) context_s
		// .getSystemService(Context.AUDIO_SERVICE);
		// // 当前音量
		// int currentVolume = mAudioManager
		// .getStreamVolume(AudioManager.STREAM_MUSIC);
		switch (keyCode) {
		case KeyEvent.KEYCODE_DPAD_LEFT:
			soundPool.play(soundMap.get(2), 1, 1, 1, 0, 1);
			break;
		case KeyEvent.KEYCODE_DPAD_RIGHT:
			soundPool.play(soundMap.get(2), 1, 1, 1, 0, 1);
			break;
		case KeyEvent.KEYCODE_DPAD_UP:
			soundPool.play(soundMap.get(2), 1, 1, 1, 0, 1);
			break;
		case KeyEvent.KEYCODE_DPAD_DOWN:
			soundPool.play(soundMap.get(2), 1, 1, 1, 0, 1);
			break;
		case KeyEvent.KEYCODE_BACK:
			soundPool.play(soundMap.get(6), 1, 1, 1, 0, 1);
			break;
		case KeyEvent.KEYCODE_DPAD_CENTER:
		case KeyEvent.KEYCODE_ENTER:
			soundPool.play(soundMap.get(7), 1, 1, 1, 0, 1);
			break;
		case KeyEvent.KEYCODE_MENU:
			soundPool.play(soundMap.get(5), 1, 1, 1, 0, 1);
			break;

		default:
			break;
		}
	} catch (Exception e) {
		// TODO: handle exception
	}
}
 
Example 19
Source File: TwoDScrollView.java    From microMathematics with GNU General Public License v3.0 4 votes vote down vote up
/**
 * 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.
 *
 * @param event The key event to execute.
 * @return Return true if the event was handled, else false.
 */
public boolean executeKeyEvent(KeyEvent event)
{
    mTempRect.setEmpty();
    boolean handled = false;
    if (event.getAction() == KeyEvent.ACTION_DOWN)
    {
        switch (event.getKeyCode())
        {
        case KeyEvent.KEYCODE_DPAD_UP:
            if (!event.isAltPressed())
            {
                handled = arrowScroll(View.FOCUS_UP, false);
            }
            else
            {
                handled = fullScroll(View.FOCUS_UP, false);
            }
            break;
        case KeyEvent.KEYCODE_DPAD_DOWN:
            if (!event.isAltPressed())
            {
                handled = arrowScroll(View.FOCUS_DOWN, false);
            }
            else
            {
                handled = fullScroll(View.FOCUS_DOWN, false);
            }
            break;
        case KeyEvent.KEYCODE_DPAD_LEFT:
            if (!event.isAltPressed())
            {
                handled = arrowScroll(View.FOCUS_LEFT, true);
            }
            else
            {
                handled = fullScroll(View.FOCUS_LEFT, true);
            }
            break;
        case KeyEvent.KEYCODE_DPAD_RIGHT:
            if (!event.isAltPressed())
            {
                handled = arrowScroll(View.FOCUS_RIGHT, true);
            }
            else
            {
                handled = fullScroll(View.FOCUS_RIGHT, true);
            }
            break;
        }
    }
    return handled;
}
 
Example 20
Source File: PipService.java    From zidoorecorder with Apache License 2.0 4 votes vote down vote up
@Override
public boolean onKey(View v, int keyCode, KeyEvent event)
{
	if (mOperating) return true;
	if (event.getAction() == KeyEvent.ACTION_DOWN)
	{
		int id = v.getId();
		if (id == R.id.fm_pip)
		{
			if (mIsFullScreen)
			{
				TvPipPopManager.getInstance().setPipSubwindow(getScaledWindowType(mWindowType.x, mWindowType.y, mWindowType.width, mWindowType.height));
				adjustPipFrame(mWindowType.x, mWindowType.y, mWindowType.width, mWindowType.height);
				mFmPip.setFocusable(false);
				mRlController.setVisibility(View.VISIBLE);
				mRlController.requestFocus();
				mIsFullScreen = false;
			} else
			{
				if (mSetPositionOrSize)
				{
					changePosition(keyCode);
				} else
				{
					changeSize(keyCode);
				}
			}
			return true;
		} else
		{
			switch (keyCode)
			{
			case KeyEvent.KEYCODE_DPAD_UP:
				return id == R.id.tv_scale_0 || id == R.id.rl_audio;
			case KeyEvent.KEYCODE_DPAD_DOWN:
				return id == R.id.tv_scale_3 || id == R.id.rl_audio;
			case KeyEvent.KEYCODE_DPAD_RIGHT:
				switch (id)
				{
				case R.id.tv_scale_0:
				case R.id.tv_scale_1:
				case R.id.tv_scale_2:
				case R.id.tv_scale_3:
					return mTvScale.requestFocus();

				default:
					break;
				}
				break;
			case KeyEvent.KEYCODE_BACK:
				hideController();
				break;

			default:
				break;
			}
		}
	}
	return false;
}