本文整理汇总了Java中android.view.OrientationEventListener类的典型用法代码示例。如果您正苦于以下问题:Java OrientationEventListener类的具体用法?Java OrientationEventListener怎么用?Java OrientationEventListener使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
OrientationEventListener类属于android.view包,在下文中一共展示了OrientationEventListener类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: DisplayOrientationDetector
import android.view.OrientationEventListener; //导入依赖的package包/类
public DisplayOrientationDetector(Context context) {
mOrientationEventListener = new OrientationEventListener(context) {
/** This is either Surface.Rotation_0, _90, _180, _270, or -1 (invalid). */
private int mLastKnownRotation = -1;
@Override
public void onOrientationChanged(int orientation) {
if (orientation == OrientationEventListener.ORIENTATION_UNKNOWN ||
mDisplay == null) {
return;
}
final int rotation = mDisplay.getRotation();
if (mLastKnownRotation != rotation) {
mLastKnownRotation = rotation;
dispatchOnDisplayOrientationChanged(DISPLAY_ORIENTATIONS.get(rotation));
}
}
};
}
示例2: RCTCameraView
import android.view.OrientationEventListener; //导入依赖的package包/类
public RCTCameraView(Context context) {
super(context);
this._context = context;
RCTCamera.createInstance(getDeviceOrientation(context));
_orientationListener = new OrientationEventListener(context, SensorManager.SENSOR_DELAY_NORMAL) {
@Override
public void onOrientationChanged(int orientation) {
if (setActualDeviceOrientation(_context)) {
layoutViewFinder();
}
}
};
if (_orientationListener.canDetectOrientation()) {
_orientationListener.enable();
} else {
_orientationListener.disable();
}
}
示例3: onViewCreated
import android.view.OrientationEventListener; //导入依赖的package包/类
@Override
public void onViewCreated(final View view, Bundle savedInstanceState) {
view.findViewById(R.id.picture).setOnClickListener(this);
mTextureView = (AutoFitTextureView) view.findViewById(R.id.texture);
// Setup a new OrientationEventListener. This is used to handle rotation events like a
// 180 degree rotation that do not normally trigger a call to onCreate to do view re-layout
// or otherwise cause the preview TextureView's size to change.
mOrientationListener = new OrientationEventListener(getActivity(),
SensorManager.SENSOR_DELAY_NORMAL) {
@Override
public void onOrientationChanged(int orientation) {
if (mTextureView != null && mTextureView.isAvailable()) {
configureTransform(mTextureView.getWidth(), mTextureView.getHeight());
}
}
};
}
示例4: startOrientationChangeListener
import android.view.OrientationEventListener; //导入依赖的package包/类
/**
* 启动屏幕朝向改变监听函数 用于在屏幕横竖屏切换时改变保存的图片的方向
*/
private void startOrientationChangeListener() {
OrientationEventListener mOrEventListener = new OrientationEventListener(getContext()) {
@Override
public void onOrientationChanged(int rotation) {
if (((rotation >= 0) && (rotation <= 45)) || (rotation > 315)){
rotation=0;
}else if ((rotation > 45) && (rotation <= 135)) {
rotation=90;
}
else if ((rotation > 135) && (rotation <= 225)) {
rotation=180;
}
else if((rotation > 225) && (rotation <= 315)) {
rotation=270;
}else {
rotation=0;
}
if(rotation==mOrientation)
return;
mOrientation=rotation;
updateCameraOrientation();
}
};
mOrEventListener.enable();
}
示例5: OrientationPlugin
import android.view.OrientationEventListener; //导入依赖的package包/类
public OrientationPlugin(Context ctxt) {
this.ctxt=ctxt.getApplicationContext();
orientationEventListener=new OrientationEventListener(ctxt) {
@Override
public void onOrientationChanged(int orientation) {
lastOrientation=orientation;
}
};
if (orientationEventListener.canDetectOrientation()) {
orientationEventListener.enable();
}
else {
orientationEventListener.disable();
orientationEventListener=null;
}
}
示例6: addToCaptureRequest
import android.view.OrientationEventListener; //导入依赖的package包/类
/**
* {@inheritDoc}
*/
@Override
public void addToCaptureRequest(CameraCharacteristics cc,
boolean facingFront,
CaptureRequest.Builder captureBuilder) {
// based on https://developer.android.com/reference/android/hardware/camera2/CaptureRequest.html#JPEG_ORIENTATION
int pictureOrientation=0;
if (lastOrientation!=android.view.OrientationEventListener.ORIENTATION_UNKNOWN) {
int sensorOrientation=cc.get(CameraCharacteristics.SENSOR_ORIENTATION);
int deviceOrientation=(lastOrientation + 45) / 90 * 90;
if (facingFront) {
deviceOrientation = -deviceOrientation;
}
pictureOrientation=(sensorOrientation + deviceOrientation + 360) % 360;
}
captureBuilder.set(CaptureRequest.JPEG_ORIENTATION, pictureOrientation);
}
示例7: setRotationParameter
import android.view.OrientationEventListener; //导入依赖的package包/类
public static void setRotationParameter(Parameters parameters,
int cameraId, int orientation) {
// See android.hardware.Camera.Parameters.setRotation for
// documentation.
int rotation = 0;
if (orientation != OrientationEventListener.ORIENTATION_UNKNOWN) {
CameraInfo info =
CameraHolder.instance().getCameraInfo()[cameraId];
// CameraInfo info = new CameraInfo();
// Camera.getCameraInfo(cameraId, info);
if (info.facing == CameraInfo.CAMERA_FACING_FRONT) {
rotation = (info.orientation - orientation + 360) % 360;
} else { // back-facing camera
rotation = (info.orientation + orientation) % 360;
}
}
parameters.setRotation(rotation);
}
示例8: setOrientationHint
import android.view.OrientationEventListener; //导入依赖的package包/类
@Override
public void setOrientationHint() {
// Util.setRotationParameter(camera_parameters, m_cameraIndex,
// WiCameraActivity.mOrientation);
// // System.out.println("拍照时的mOrientation="
// // + WiCameraActivity.mOrientation + "m_cameraIndex="
// // + m_cameraIndex);
// cameras.setParameters(camera_parameters);
if (cameras != null) {
int rotation = 0;
if (WiCameraActivity.mOrientation != OrientationEventListener.ORIENTATION_UNKNOWN) {
CameraInfo info = CameraHolder.instance().getCameraInfo()[m_cameraIndex];
if (info.facing == CameraInfo.CAMERA_FACING_FRONT) {
rotation = (info.orientation
- WiCameraActivity.mOrientation + 360) % 360;
} else { // back-facing camera
rotation = (info.orientation + WiCameraActivity.mOrientation) % 360;
}
}
m_recorder.setOrientationHint(rotation);
}
}
示例9: onOrientationChanged
import android.view.OrientationEventListener; //导入依赖的package包/类
@Override
public void onOrientationChanged(int orientation) {
// We keep the last known orientation. So if the user first orient
// the camera then point the camera to floor or sky, we still have
// the correct orientation.
if (orientation == OrientationEventListener.ORIENTATION_UNKNOWN) {
return;
}
int newOrientation = CameraUtil.roundOrientation(orientation, mOrientation);
if (mOrientation != newOrientation) {
mOrientation = newOrientation;
}
mUI.onOrientationChanged(orientation);
}
示例10: onOrientationChanged
import android.view.OrientationEventListener; //导入依赖的package包/类
/**
* Handles orientation change by starting/stopping the video hint based on the
* new orientation.
*/
public void onOrientationChanged(int orientation) {
if (mLastOrientation == orientation) {
return;
}
mLastOrientation = orientation;
if (mLastOrientation == OrientationEventListener.ORIENTATION_UNKNOWN) {
return;
}
mIsInLandscape = isInLandscape();
if (getVisibility() == VISIBLE) {
if (mIsInLandscape) {
// Landscape.
mRotationAnimation.cancel();
// Start fading out.
if (mAlphaAnimator.isRunning()) {
return;
}
mAlphaAnimator.start();
} else {
// Portrait.
continueRotationAnimation();
}
}
}
示例11: FocusModePlugin
import android.view.OrientationEventListener; //导入依赖的package包/类
public FocusModePlugin(Context ctxt,
FocusMode focusMode,
boolean isVideo) {
this.ctxt=ctxt.getApplicationContext();
this.focusMode=focusMode;
this.isVideo=isVideo;
orientationEventListener=new OrientationEventListener(ctxt) {
@Override
public void onOrientationChanged(int orientation) {
lastOrientation=orientation;
}
};
if (orientationEventListener.canDetectOrientation()) {
orientationEventListener.enable();
}
else {
orientationEventListener.disable();
orientationEventListener=null;
}
}
示例12: OrientationPlugin
import android.view.OrientationEventListener; //导入依赖的package包/类
public OrientationPlugin(Context ctxt) {
this.ctxt=ctxt.getApplicationContext();
orientationEventListener=new OrientationEventListener(ctxt) {
@Override
public void onOrientationChanged(int orientation) {
if (lastOrientation!=orientation) {
AbstractCameraActivity.BUS
.post(new CameraEngine.OrientationChangedEvent());
}
lastOrientation=orientation;
}
};
if (orientationEventListener.canDetectOrientation()) {
orientationEventListener.enable();
}
else {
orientationEventListener.disable();
orientationEventListener=null;
}
}
示例13: addToCaptureRequest
import android.view.OrientationEventListener; //导入依赖的package包/类
/**
* {@inheritDoc}
*/
@Override
public void addToCaptureRequest(CameraSession session,
CameraCharacteristics cc,
boolean facingFront,
CaptureRequest.Builder captureBuilder) {
// based on https://developer.android.com/reference/android/hardware/camera2/CaptureRequest.html#JPEG_ORIENTATION
int pictureOrientation=0;
if (lastOrientation!=android.view.OrientationEventListener.ORIENTATION_UNKNOWN) {
int sensorOrientation=cc.get(CameraCharacteristics.SENSOR_ORIENTATION);
int deviceOrientation=(lastOrientation + 45) / 90 * 90;
if (facingFront) {
deviceOrientation = -deviceOrientation;
}
pictureOrientation=(sensorOrientation + deviceOrientation + 360) % 360;
}
captureBuilder.set(CaptureRequest.JPEG_ORIENTATION, pictureOrientation);
}
示例14: enableCameraView
import android.view.OrientationEventListener; //导入依赖的package包/类
@Override
public void enableCameraView() {
// Start listening for orientation events
mCameraOrientationEventListener = new OrientationEventListener(this) {
@Override
public void onOrientationChanged(int orientation) {
if (mAppStateListeners != null) {
for (GeckoAppShell.AppStateListener listener: mAppStateListeners) {
listener.onOrientationChanged();
}
}
}
};
mCameraOrientationEventListener.enable();
// Try to make it fully transparent.
if (mCameraView instanceof SurfaceView) {
if (Versions.feature11Plus) {
mCameraView.setAlpha(0.0f);
}
ViewGroup mCameraLayout = (ViewGroup) findViewById(R.id.camera_layout);
// Some phones (eg. nexus S) need at least a 8x16 preview size
mCameraLayout.addView(mCameraView,
new AbsoluteLayout.LayoutParams(8, 16, 0, 0));
}
}
示例15: onOrientationChanged
import android.view.OrientationEventListener; //导入依赖的package包/类
@Override
public void onOrientationChanged(int orientation) {
// We keep the last known orientation. So if the user first orient
// the camera then point the camera to floor or sky, we still have
// the correct orientation.
if (orientation == OrientationEventListener.ORIENTATION_UNKNOWN) return;
int newOrientation = CameraUtil.roundOrientation(orientation, mOrientation);
if (mOrientation != newOrientation) {
mOrientation = newOrientation;
}
// Show the toast after getting the first orientation changed.
if (mHandler.hasMessages(SHOW_TAP_TO_SNAPSHOT_TOAST)) {
mHandler.removeMessages(SHOW_TAP_TO_SNAPSHOT_TOAST);
showTapToSnapshotToast();
}
}