android.view.KeyEvent#KEYCODE_FOCUS源码实例Demo

下面列出了android.view.KeyEvent#KEYCODE_FOCUS 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: CodeScaner   文件: CaptureActivity.java

@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
    switch (keyCode) {
        case KeyEvent.KEYCODE_BACK:
            setResult(RESULT_CANCELED);
            finish();
            return true;
        case KeyEvent.KEYCODE_FOCUS:
        case KeyEvent.KEYCODE_CAMERA:
            // Handle these events so they don't launch the Camera app
            return true;
        // Use volume up/down to turn on light
        case KeyEvent.KEYCODE_VOLUME_DOWN:
            cameraManager.setTorch(false);
            return true;
        case KeyEvent.KEYCODE_VOLUME_UP:
            cameraManager.setTorch(true);
            return true;
    }
    return super.onKeyDown(keyCode, event);
}
 

public boolean onKeyDown(int keyCode, KeyEvent event) {
  switch (keyCode) {
    case KeyEvent.KEYCODE_FOCUS:
    case KeyEvent.KEYCODE_CAMERA:
      // Handle these events so they don't launch the Camera app
      return true;
    // Use volume up/down to turn on light
    case KeyEvent.KEYCODE_VOLUME_DOWN:
      setTorchOff();
      return true;
    case KeyEvent.KEYCODE_VOLUME_UP:
      setTorchOn();
      return true;
  }
  return false;
}
 
源代码3 项目: Viewer   文件: CompoundBarcodeView.java

/**
 * Handles focus, camera, volume up and volume down keys.
 *
 * Note that this view is not usually focused, so the Activity should call this directly.
 */
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
    switch (keyCode) {
        case KeyEvent.KEYCODE_FOCUS:
        case KeyEvent.KEYCODE_CAMERA:
            // Handle these events so they don't launch the Camera app
            return true;
        // Use volume up/down to turn on light
        case KeyEvent.KEYCODE_VOLUME_DOWN:
            setTorchOff();
            return true;
        case KeyEvent.KEYCODE_VOLUME_UP:
            setTorchOn();
            return true;
    }
    return super.onKeyDown(keyCode, event);
}
 
源代码4 项目: android-apps   文件: CaptureActivity.java

@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
  if (keyCode == KeyEvent.KEYCODE_BACK) {
    if (source == IntentSource.NATIVE_APP_INTENT) {
      setResult(RESULT_CANCELED);
      finish();
      return true;
    } else if ((source == IntentSource.NONE || source == IntentSource.ZXING_LINK) && lastResult != null) {
      restartPreviewAfterDelay(0L);
      return true;
    }
  } else if (keyCode == KeyEvent.KEYCODE_FOCUS || keyCode == KeyEvent.KEYCODE_CAMERA) {
    // Handle these events so they don't launch the Camera app
    return true;
  }
  return super.onKeyDown(keyCode, event);
}
 
源代码5 项目: bither-android   文件: ScanActivity.java

@Override
public boolean onKeyDown(final int keyCode, final KeyEvent event) {
	switch (keyCode) {
	case KeyEvent.KEYCODE_FOCUS:
	case KeyEvent.KEYCODE_CAMERA:
		// don't launch camera app
		return true;
	case KeyEvent.KEYCODE_VOLUME_DOWN:
	case KeyEvent.KEYCODE_VOLUME_UP:
		cameraHandler.post(new Runnable() {
			@Override
			public void run() {
				cameraManager
						.setTorch(keyCode == KeyEvent.KEYCODE_VOLUME_UP);
			}
		});
		return true;
	}

	return super.onKeyDown(keyCode, event);
}
 
源代码6 项目: retroboy   文件: MainActivity.java

@Override
public boolean onKeyUp(int keyCode, KeyEvent event) {
	switch (keyCode) {
		case KeyEvent.KEYCODE_FOCUS:
			// Reset auto focus when dedicated photo button is completely released
			_focusManager.resetFocus();
			return true;

		case KeyEvent.KEYCODE_CAMERA:
			if (event.getRepeatCount() == 0 && event.getAction() == KeyEvent.ACTION_UP) {
				// Take photo when the dedicated photo button is pressed
				MotionEvent motevent = MotionEvent.obtain(0, 0, MotionEvent.ACTION_UP, 0, 0, 0);
				_captureListener.onTouch(null, motevent);
				motevent.recycle();
			}
			
			return true;
	}

	return super.onKeyUp(keyCode, event);
}
 
源代码7 项目: Camera2   文件: PhotoModule.java

@Override
public boolean onKeyDown(int keyCode, KeyEvent event)
{
    switch (keyCode)
    {
        case KeyEvent.KEYCODE_VOLUME_UP:
        case KeyEvent.KEYCODE_VOLUME_DOWN:
        case KeyEvent.KEYCODE_FOCUS:
            if (/* TODO: mActivity.isInCameraApp() && */mFirstTimeInitialized && !mActivity.getCameraAppUI()
                    .isInIntentReview())
            {
                if (event.getRepeatCount() == 0)
                {
                    onShutterButtonFocus(true);
                }
                return true;
            }
            return false;
        case KeyEvent.KEYCODE_CAMERA:
            if (mFirstTimeInitialized && event.getRepeatCount() == 0)
            {
                onShutterButtonClick();
            }
            return true;
        case KeyEvent.KEYCODE_DPAD_CENTER:
            // If we get a dpad center event without any focused view, move
            // the focus to the shutter button and press it.
            if (mFirstTimeInitialized && event.getRepeatCount() == 0)
            {
                // Start auto-focus immediately to reduce shutter lag. After
                // the shutter button gets the focus, onShutterButtonFocus()
                // will be called again but it is fine.
                onShutterButtonFocus(true);
            }
            return true;
    }
    return false;
}
 
源代码8 项目: Camera2   文件: PhotoModule.java

@Override
public boolean onKeyUp(int keyCode, KeyEvent event)
{
    switch (keyCode)
    {
        case KeyEvent.KEYCODE_VOLUME_UP:
        case KeyEvent.KEYCODE_VOLUME_DOWN:
            if (/* mActivity.isInCameraApp() && */mFirstTimeInitialized && !mActivity.getCameraAppUI()
                    .isInIntentReview())
            {
                if (mUI.isCountingDown())
                {
                    cancelCountDown();
                } else
                {
                    mVolumeButtonClickedFlag = true;
                    onShutterButtonClick();
                }
                return true;
            }
            return false;
        case KeyEvent.KEYCODE_FOCUS:
            if (mFirstTimeInitialized)
            {
                onShutterButtonFocus(false);
            }
            return true;
    }
    return false;
}
 
源代码9 项目: Camera2   文件: ImageCapture.java

public void captureImages(String reportTag, Instrumentation inst)
{
    int total_num_of_images = CameraStressTestRunner.mImageIterations;
    Log.v(TAG, "no of images = " + total_num_of_images);

    //TODO(yslau): Need to integrate the outoput with the central dashboard,
    //write to a txt file as a temp solution
    boolean memoryResult = false;
    KeyEvent focusEvent = new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_FOCUS);

    try
    {
        testUtil.writeReportHeader(reportTag, total_num_of_images);
        for (int i = 0; i < total_num_of_images; i++)
        {
            Thread.sleep(WAIT_FOR_IMAGE_CAPTURE_TO_BE_TAKEN);
            inst.sendKeySync(focusEvent);
            inst.sendCharacterSync(KeyEvent.KEYCODE_CAMERA);
            Thread.sleep(WAIT_FOR_IMAGE_CAPTURE_TO_BE_TAKEN);
            testUtil.writeResult(i);
        }
    } catch (Exception e)
    {
        Log.v(TAG, "Got exception: " + e.toString());
        assertTrue("testImageCapture", false);
    }
}
 
源代码10 项目: green_android   文件: ScanActivity.java

@Override
public boolean onKeyDown(final int keyCode, final KeyEvent event) {
    switch (keyCode) {
    case KeyEvent.KEYCODE_FOCUS:
    case KeyEvent.KEYCODE_CAMERA:
        // don't launch camera app
        return true;
    case KeyEvent.KEYCODE_VOLUME_DOWN:
    case KeyEvent.KEYCODE_VOLUME_UP:
        cameraHandler.post(() -> cameraManager.setTorch(keyCode == KeyEvent.KEYCODE_VOLUME_UP));
        return true;
    }

    return super.onKeyDown(keyCode, event);
}
 
源代码11 项目: barterli_android   文件: ScanIsbnActivity.java

@Override
public boolean onKeyDown(final int keyCode, final KeyEvent event) {
    if ((keyCode == KeyEvent.KEYCODE_FOCUS)
                    || (keyCode == KeyEvent.KEYCODE_CAMERA)) {
        // Handle these events so they don't launch the Camera app
        return true;
    }
    return super.onKeyDown(keyCode, event);
}
 
源代码12 项目: bither-android   文件: UEntropyActivity.java

@Override
public boolean onKeyDown(final int keyCode, final KeyEvent event) {
    switch (keyCode) {
        case KeyEvent.KEYCODE_FOCUS:
        case KeyEvent.KEYCODE_CAMERA:
            // don't launch camera app
            return true;
        case KeyEvent.KEYCODE_VOLUME_DOWN:
        case KeyEvent.KEYCODE_VOLUME_UP:
            return true;
    }
    return super.onKeyDown(keyCode, event);
}
 

@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
  switch (keyCode) {
    case KeyEvent.KEYCODE_BACK:
      if (source == IntentSource.NATIVE_APP_INTENT) {
        setResult(RESULT_CANCELED);
        finish();
        return true;
      }
      if ((source == IntentSource.NONE || source == IntentSource.ZXING_LINK) && lastResult != null) {
        restartPreviewAfterDelay(0L);
        return true;
      }
      break;
    case KeyEvent.KEYCODE_FOCUS:
    case KeyEvent.KEYCODE_CAMERA:
      // Handle these events so they don't launch the Camera app
      return true;
    // Use volume up/down to turn on light
    case KeyEvent.KEYCODE_VOLUME_DOWN:
      cameraManager.setTorch(false);
      return true;
    case KeyEvent.KEYCODE_VOLUME_UP:
      cameraManager.setTorch(true);
      return true;
  }
  return super.onKeyDown(keyCode, event);
}
 

@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
  switch (keyCode) {
    case KeyEvent.KEYCODE_BACK:
      if (source == IntentSource.NATIVE_APP_INTENT) {
        setResult(RESULT_CANCELED);
        finish();
        return true;
      }
      if ((source == IntentSource.NONE || source == IntentSource.ZXING_LINK) && lastResult != null) {
        restartPreviewAfterDelay(0L);
        return true;
      }
      break;
    case KeyEvent.KEYCODE_FOCUS:
    case KeyEvent.KEYCODE_CAMERA:
      // Handle these events so they don't launch the Camera app
      return true;
    // Use volume up/down to turn on light
    case KeyEvent.KEYCODE_VOLUME_DOWN:
      cameraManager.setTorch(false);
      return true;
    case KeyEvent.KEYCODE_VOLUME_UP:
      cameraManager.setTorch(true);
      return true;
  }
  return super.onKeyDown(keyCode, event);
}
 
源代码15 项目: LLApp   文件: QrViewActivity.java

@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
    if (keyCode == KeyEvent.KEYCODE_BACK) {
        setResult(RESULT_CANCELED);
        finish();
        return true;
    } else if (keyCode == KeyEvent.KEYCODE_FOCUS || keyCode == KeyEvent.KEYCODE_CAMERA) {
        return true;
    }
    return super.onKeyDown(keyCode, event);
}
 
源代码16 项目: reacteu-app   文件: CaptureActivity.java

@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
  switch (keyCode) {
    case KeyEvent.KEYCODE_BACK:
      if (source == IntentSource.NATIVE_APP_INTENT) {
        setResult(RESULT_CANCELED);
        finish();
        return true;
      }
      if ((source == IntentSource.NONE || source == IntentSource.ZXING_LINK) && lastResult != null) {
        restartPreviewAfterDelay(0L);
        return true;
      }
      break;
    case KeyEvent.KEYCODE_FOCUS:
    case KeyEvent.KEYCODE_CAMERA:
      // Handle these events so they don't launch the Camera app
      return true;
    // Use volume up/down to turn on light
    case KeyEvent.KEYCODE_VOLUME_DOWN:
      cameraManager.setTorch(false);
      return true;
    case KeyEvent.KEYCODE_VOLUME_UP:
      cameraManager.setTorch(true);
      return true;
  }
  return super.onKeyDown(keyCode, event);
}
 

public boolean shouldOverrideKeyEvent(KeyEvent event) {
    int keyCode = event.getKeyCode();
    // We need to send almost every key to WebKit. However:
    // 1. We don't want to block the device on the renderer for
    // some keys like menu, home, call.
    // 2. There are no WebKit equivalents for some of these keys
    // (see app/keyboard_codes_win.h)
    // Note that these are not the same set as KeyEvent.isSystemKey:
    // for instance, AKEYCODE_MEDIA_* will be dispatched to webkit.
    if (keyCode == KeyEvent.KEYCODE_MENU ||
        keyCode == KeyEvent.KEYCODE_HOME ||
        keyCode == KeyEvent.KEYCODE_BACK ||
        keyCode == KeyEvent.KEYCODE_CALL ||
        keyCode == KeyEvent.KEYCODE_ENDCALL ||
        keyCode == KeyEvent.KEYCODE_POWER ||
        keyCode == KeyEvent.KEYCODE_HEADSETHOOK ||
        keyCode == KeyEvent.KEYCODE_CAMERA ||
        keyCode == KeyEvent.KEYCODE_FOCUS ||
        keyCode == KeyEvent.KEYCODE_VOLUME_DOWN ||
        keyCode == KeyEvent.KEYCODE_VOLUME_MUTE ||
        keyCode == KeyEvent.KEYCODE_VOLUME_UP) {
        return true;
    }

    // We also have to intercept some shortcuts before we send them to the ContentView.
    if (event.isCtrlPressed() && (
            keyCode == KeyEvent.KEYCODE_TAB ||
            keyCode == KeyEvent.KEYCODE_W ||
            keyCode == KeyEvent.KEYCODE_F4)) {
        return true;
    }

    return false;
}
 
源代码18 项目: barterli_android   文件: DecoderActivity.java

@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
    if (keyCode == KeyEvent.KEYCODE_FOCUS || keyCode == KeyEvent.KEYCODE_CAMERA) {
        // Handle these events so they don't launch the Camera app
        return true;
    }
    return super.onKeyDown(keyCode, event);
}
 

@Override
public boolean dispatchKeyEvent(KeyEvent event) {
    // Avoid closing alarm by the following keys
    switch (event.getKeyCode()) {
        case KeyEvent.KEYCODE_VOLUME_UP:
        case KeyEvent.KEYCODE_VOLUME_DOWN:
        case KeyEvent.KEYCODE_CAMERA:
        case KeyEvent.KEYCODE_FOCUS:
            return true;
        default:
            break;
    }
    return super.dispatchKeyEvent(event);
}
 
源代码20 项目: 365browser   文件: ContentViewCore.java

/**
 * Check whether a key should be propagated to the embedder or not.
 * We need to send almost every key to Blink. However:
 * 1. We don't want to block the device on the renderer for
 * some keys like menu, home, call.
 * 2. There are no WebKit equivalents for some of these keys
 * (see app/keyboard_codes_win.h)
 * Note that these are not the same set as KeyEvent.isSystemKey:
 * for instance, AKEYCODE_MEDIA_* will be dispatched to webkit*.
 */
private static boolean shouldPropagateKeyEvent(KeyEvent event) {
    int keyCode = event.getKeyCode();
    if (keyCode == KeyEvent.KEYCODE_MENU || keyCode == KeyEvent.KEYCODE_HOME
            || keyCode == KeyEvent.KEYCODE_BACK || keyCode == KeyEvent.KEYCODE_CALL
            || keyCode == KeyEvent.KEYCODE_ENDCALL || keyCode == KeyEvent.KEYCODE_POWER
            || keyCode == KeyEvent.KEYCODE_HEADSETHOOK || keyCode == KeyEvent.KEYCODE_CAMERA
            || keyCode == KeyEvent.KEYCODE_FOCUS || keyCode == KeyEvent.KEYCODE_VOLUME_DOWN
            || keyCode == KeyEvent.KEYCODE_VOLUME_MUTE
            || keyCode == KeyEvent.KEYCODE_VOLUME_UP) {
        return false;
    }
    return true;
}
 
 方法所在类
 同类方法