Java Code Examples for android.hardware.SensorManager#SENSOR_DELAY_NORMAL

The following examples show how to use android.hardware.SensorManager#SENSOR_DELAY_NORMAL . 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: AdvCamera.java    From adv_camera with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
private void identifyOrientationEvents() {
    OrientationEventListener myOrientationEventListener = new OrientationEventListener(context, SensorManager.SENSOR_DELAY_NORMAL) {
        @Override
        public void onOrientationChanged(int iAngle) {
            final int[] iLookup = {0, 0, 0, 90, 90, 90, 90, 90, 90, 180, 180, 180, 180, 180, 180, 270, 270, 270, 270, 270, 270, 0, 0, 0}; // 15-degree increments
            if (iAngle != ORIENTATION_UNKNOWN) {
                int iNewOrientation = iLookup[iAngle / 15];
                if (iOrientation != iNewOrientation) {
                    iOrientation = iNewOrientation;
                }
                mPhotoAngle = normalize(iAngle);
            }
        }
    };

    if (myOrientationEventListener.canDetectOrientation()) {
        myOrientationEventListener.enable();
    }
}
 
Example 2
Source File: Preferences.java    From ShaderEditor with MIT License 6 votes vote down vote up
private static int parseSensorDelay(String s, int preset) {
	if (s == null) {
		return preset;
	}

	switch (s) {
		case "Fastest":
			return SensorManager.SENSOR_DELAY_FASTEST;
		case "Game":
			return SensorManager.SENSOR_DELAY_GAME;
		case "Normal":
			return SensorManager.SENSOR_DELAY_NORMAL;
		case "UI":
			return SensorManager.SENSOR_DELAY_UI;
	}

	return preset;
}
 
Example 3
Source File: RCTCameraView.java    From react-native-camera-face-detector with MIT License 6 votes vote down vote up
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();
    }
}
 
Example 4
Source File: SensorsDataAPI.java    From sa-sdk-android with Apache License 2.0 6 votes vote down vote up
@Override
public void enableTrackScreenOrientation(boolean enable) {
    try {
        if (enable) {
            if (mOrientationDetector == null) {
                mOrientationDetector = new SensorsDataScreenOrientationDetector(mContext, SensorManager.SENSOR_DELAY_NORMAL);
            }
            mOrientationDetector.enable();
        } else {
            if (mOrientationDetector != null) {
                mOrientationDetector.disable();
                mOrientationDetector = null;
            }
        }
    } catch (Exception e) {
        com.sensorsdata.analytics.android.sdk.SALog.printStackTrace(e);
    }
}
 
Example 5
Source File: MediaPlayerFrame.java    From android-jungle-mediaplayer with Apache License 2.0 6 votes vote down vote up
private void initOrientationSwitcher() {
    mScreenOrientationSwitcher = new ScreenOrientationSwitcher(
            getContext(), SensorManager.SENSOR_DELAY_NORMAL);

    mScreenOrientationSwitcher.setChangeListener(mOrientationChangeListener);
    if (mScreenOrientationSwitcher.canDetectOrientation()) {
        mScreenOrientationSwitcher.enable();
    }

    mLockOrientationPanel.setLockChangedListener(
            new LockOrientationPanel.OnLockChangedListener() {
                @Override
                public void onChanged(boolean isLocked) {
                    if (isLocked) {
                        return;
                    }

                    int requestOrientation = mScreenOrientationSwitcher.getCurrOrientation();
                    switchFullScreenInternal(requestOrientation);
                }
            });
}
 
Example 6
Source File: OrientationHelper.java    From Lassi-Android with MIT License 5 votes vote down vote up
public OrientationHelper(@NonNull Context context, @NonNull Callback callback) {
    mCallback = callback;
    mListener = new OrientationEventListener(context.getApplicationContext(), SensorManager.SENSOR_DELAY_NORMAL) {

        @SuppressWarnings("ConstantConditions")
        @Override
        public void onOrientationChanged(int orientation) {
            int or = 0;
            if (orientation == OrientationEventListener.ORIENTATION_UNKNOWN) {
                or = mDeviceOrientation != -1 ? mDeviceOrientation : 0;
            } else if (orientation >= 315 || orientation < 45) {
                or = 0;
            } else if (orientation >= 45 && orientation < 135) {
                or = 90;
            } else if (orientation >= 135 && orientation < 225) {
                or = 180;
            } else if (orientation >= 225 && orientation < 315) {
                or = 270;
            }

            if (or != mDeviceOrientation) {
                mDeviceOrientation = or;
                mCallback.onDeviceOrientationChanged(mDeviceOrientation);
            }
        }
    };
}
 
Example 7
Source File: SensorRotationManager.java    From rtmp-rtsp-stream-client-java with Apache License 2.0 5 votes vote down vote up
public SensorRotationManager(Context context, final RotationChangedListener rotationListener) {
  this.listener = new OrientationEventListener(context, SensorManager.SENSOR_DELAY_NORMAL) {
    @Override
    public void onOrientationChanged(int sensorOrientation) {
      final int rotation = ((sensorOrientation + 45) / 90) % 4;
      final int rotationDegrees = rotation * 90;
      rotationListener.onRotationChanged(rotationDegrees);
    }
  };
}
 
Example 8
Source File: ReactOrientationListenerModule.java    From react-native-orientation-listener with MIT License 5 votes vote down vote up
public ReactOrientationListenerModule(ReactApplicationContext reactContext) {
  super(reactContext);
  this.reactContext = reactContext;
  final ReactApplicationContext thisContext = reactContext;

  mOrientationListener = new OrientationEventListener(reactContext,
    SensorManager.SENSOR_DELAY_NORMAL) {
    @Override
    public void onOrientationChanged(int orientation) {
      WritableNativeMap params = new WritableNativeMap();
      String orientationValue = "";
      if(orientation == 0) {
        orientationValue = "PORTRAIT";
      } else {
        orientationValue = "LANDSCAPE";
      }
      params.putString("orientation", orientationValue);
      params.putString("device", getDeviceName());
      if (thisContext.hasActiveCatalystInstance()) {
        thisContext
          .getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class)
          .emit("orientationDidChange", params);
      }
    }
  };

  if (mOrientationListener.canDetectOrientation() == true) {
    mOrientationListener.enable();
  } else {
    mOrientationListener.disable();
  }
}
 
Example 9
Source File: WhatsappCameraActivity.java    From WhatsAppCamera with MIT License 5 votes vote down vote up
private void identifyOrientationEvents() {

        myOrientationEventListener = new OrientationEventListener(this, SensorManager.SENSOR_DELAY_NORMAL) {
            @Override
            public void onOrientationChanged(int iAngle) {

                final int iLookup[] = {0, 0, 0, 90, 90, 90, 90, 90, 90, 180, 180, 180, 180, 180, 180, 270, 270, 270, 270, 270, 270, 0, 0, 0}; // 15-degree increments
                if (iAngle != ORIENTATION_UNKNOWN) {

                    int iNewOrientation = iLookup[iAngle / 15];
                    if (iOrientation != iNewOrientation) {
                        iOrientation = iNewOrientation;
                        if (iOrientation == 0) {
                            mOrientation = 90;
                        } else if (iOrientation == 270) {
                            mOrientation = 0;
                        } else if (iOrientation == 90) {
                            mOrientation = 180;
                        }

                    }
                    mPhotoAngle = normalize(iAngle);
                }
            }
        };

        if (myOrientationEventListener.canDetectOrientation()) {
            myOrientationEventListener.enable();
        }

    }
 
Example 10
Source File: AccelerationEventListener.java    From Camdroid with Apache License 2.0 4 votes vote down vote up
public AccelerationEventListener(Context context) {
	this(context, SensorManager.SENSOR_DELAY_NORMAL);
}
 
Example 11
Source File: CameraFragment.java    From SquareCamera with MIT License 4 votes vote down vote up
public CameraOrientationListener(Context context) {
    super(context, SensorManager.SENSOR_DELAY_NORMAL);
}
 
Example 12
Source File: AmbientLightEventListener.java    From Camdroid with Apache License 2.0 4 votes vote down vote up
public AmbientLightEventListener(Context context) {
	this(context, SensorManager.SENSOR_DELAY_NORMAL);
}
 
Example 13
Source File: SensorSourceSetup.java    From quarks with Apache License 2.0 4 votes vote down vote up
public SensorSourceSetup(SensorManager mSensorManager, Sensor ... sensors) {
    this(mSensorManager , SensorManager.SENSOR_DELAY_NORMAL, sensors);  
}
 
Example 14
Source File: CordovaActivity.java    From crosswalk-cordova-android with Apache License 2.0 4 votes vote down vote up
/**
 * Shows the splash screen over the full Activity
 */
@SuppressWarnings("deprecation")
protected void showSplashScreen(final int time) {
    final CordovaActivity that = this;

    Runnable runnable = new Runnable() {
        public void run() {
            // Create the layout for the dialog
            splashLayout = getSplashLayout();
            // Create and show the dialog
            splashDialog = new Dialog(that, android.R.style.Theme_Translucent_NoTitleBar);
            // check to see if the splash screen should be full screen
            if(getBooleanProperty("FullScreen", false))
            {
                toggleFullscreen(splashDialog.getWindow());

                if (isImmersiveMode()) {
                    splashDialog.getWindow().getDecorView().setOnSystemUiVisibilityChangeListener(new View.OnSystemUiVisibilityChangeListener() {
                        @Override
                        public void onSystemUiVisibilityChange(int visibility) {
                            if ((visibility & View.SYSTEM_UI_FLAG_FULLSCREEN) == 0) {
                                setSystemUiVisibilityMode(splashDialog.getWindow());
                            }
                        }
                    });
                }
            }

            splashDialog.setContentView(splashLayout);
            splashDialog.setCancelable(false);
            splashDialog.show();

            mCurrentOrientation = getScreenOrientation();
            splashOrientationListener = new OrientationEventListener(that,
                    SensorManager.SENSOR_DELAY_NORMAL) {
                public void onOrientationChanged(int ori) {
                    if (splashDialog == null || !splashDialog.isShowing()) {
                        return;
                    }
                    // Reset contentView of splashDialog when orientation changed.
                    int orientation = getScreenOrientation();
                    if (orientation != mCurrentOrientation) {
                        splashLayout = getSplashLayout();
                        splashDialog.setContentView(splashLayout);
                        mCurrentOrientation = orientation;
                    }
                }
            };
            splashOrientationListener.enable();

            // Set Runnable to remove splash screen just in case
            final Handler handler = new Handler();
            handler.postDelayed(new Runnable() {
                public void run() {
                    removeSplashScreen();
                }
            }, time);
        }
    };
    this.runOnUiThread(runnable);
}
 
Example 15
Source File: XSensorManager.java    From XPrivacy with GNU General Public License v3.0 4 votes vote down vote up
@Override
protected void before(XParam param) throws Throwable {
	switch (mMethod) {
	case getDefaultSensor:
		if (isRestricted(param))
			param.setResult(null);
		else if (param.args.length > 0 && param.args[0] instanceof Integer)
			if (isRestricted(param, (Integer) param.args[0]))
				param.setResult(null);
		break;

	case getSensorList:
		if (isRestricted(param))
			param.setResult(new ArrayList<Sensor>());
		else if (param.args.length > 0 && param.args[0] instanceof Integer)
			if (isRestricted(param, (Integer) param.args[0]))
				param.setResult(new ArrayList<Sensor>());
		break;

	case registerListener:
		if (param.args.length > 2 && param.args[1] instanceof Sensor && param.args[2] instanceof Integer) {
			int type = ((Sensor) param.args[1]).getType();
			if (type == Sensor.TYPE_GYROSCOPE || type == Sensor.TYPE_GYROSCOPE_UNCALIBRATED) {
				int rateUs = (Integer) param.args[2];

				// http://developer.android.com/guide/topics/sensors/sensors_overview.html
				if (rateUs == SensorManager.SENSOR_DELAY_NORMAL)
					return; // 200,000 us
				else if (rateUs == SensorManager.SENSOR_DELAY_UI)
					return; // 60,000 us
				else if (rateUs == SensorManager.SENSOR_DELAY_GAME)
					return; // 20,000 us
				else if (rateUs == SensorManager.SENSOR_DELAY_FASTEST)
					; // 0 us

				if (rateUs < cMaxRateUs) // 10,000 us
					if (isRestricted(param))
						param.args[2] = cMaxRateUs;
			}
		}
		break;
	}
}
 
Example 16
Source File: Camera2Fragment.java    From 361Camera with Apache License 2.0 4 votes vote down vote up
@Override
public void onViewCreated(final View view, Bundle savedInstanceState) {
    view.findViewById(R.id.capture).setOnClickListener(this);
    view.findViewById(R.id.switch_camera).setOnClickListener(this);
    mTextureView = (AutoFitTextureView) view.findViewById(R.id.texture_view_camera2);
    mImageShow = (ImageView) view.findViewById(R.id.iv_show_camera2);
    mTimer = (ImageView) view.findViewById(R.id.timer);
    mTimeText = (TextView) view.findViewById(R.id.timer_text);
    mFlashBtn = (ImageView) view.findViewById(R.id.flash);
    mIvFocus = (ImageView) view.findViewById(R.id.iv_focus);
    mIvHdr = (ImageView) view.findViewById(R.id.hdr);
    mTimer.setOnClickListener(this);
    mFlashBtn.setOnClickListener(this);
    mIvHdr.setOnClickListener(this);

    mTextureView.setOnTouchListener(new View.OnTouchListener() {
        @Override
        public boolean onTouch(View v, MotionEvent event) {
            int actionMasked = MotionEventCompat.getActionMasked(event);
            int fingerX, fingerY;
            int length = (int) (getResources().getDisplayMetrics().density * 80);
            switch (actionMasked) {
                case MotionEvent.ACTION_DOWN:
                    fingerX = (int) event.getX();
                    fingerY = (int) event.getY();
                    LogUtil.d("onTouch: x->" + fingerX + ",y->" + fingerY);

                    mIvFocus.setX(fingerX - length / 2);
                    mIvFocus.setY(fingerY - length / 2);

                    mIvFocus.setVisibility(View.VISIBLE);
                    triggerFocusArea(fingerX, fingerY);

                    break;
            }

            return false;
        }
    });

    // 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());
            }
        }
    };
}
 
Example 17
Source File: DeviceOrientationHelper.java    From Dota2Helper with Apache License 2.0 3 votes vote down vote up
public DeviceOrientationHelper(Activity ctxt, OrientationChangeCallback callback){
	
	super(ctxt, SensorManager.SENSOR_DELAY_NORMAL);
	this.callback = callback;
	
}
 
Example 18
Source File: DeviceOrientationHelper.java    From SimplifyReader with Apache License 2.0 2 votes vote down vote up
public DeviceOrientationHelper(Activity ctxt, OrientationChangeCallback callback){
	
	super(ctxt, SensorManager.SENSOR_DELAY_NORMAL);
	this.callback = callback;
	
}
 
Example 19
Source File: WindowOrientationListener.java    From retroboy with MIT License 2 votes vote down vote up
/**
 * Creates a new WindowOrientationListener.
 * 
 * @param context for the WindowOrientationListener.
 */
public WindowOrientationListener(Context context) {
    this(context, SensorManager.SENSOR_DELAY_NORMAL);
}
 
Example 20
Source File: OrientationEventListener.java    From android_9.0.0_r45 with Apache License 2.0 2 votes vote down vote up
/**
 * Creates a new OrientationEventListener.
 * 
 * @param context for the OrientationEventListener.
 */
public OrientationEventListener(Context context) {
    this(context, SensorManager.SENSOR_DELAY_NORMAL);
}