android.hardware.SensorManager#SENSOR_DELAY_NORMAL源码实例Demo

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

源代码1 项目: adv_camera   文件: AdvCamera.java
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();
    }
}
 
源代码2 项目: ShaderEditor   文件: Preferences.java
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;
}
 
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();
    }
}
 
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);
                }
            });
}
 
源代码5 项目: sa-sdk-android   文件: SensorsDataAPI.java
@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);
    }
}
 
源代码6 项目: Lassi-Android   文件: OrientationHelper.java
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);
            }
        }
    };
}
 
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);
    }
  };
}
 
源代码8 项目: WhatsAppCamera   文件: WhatsappCameraActivity.java
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();
        }

    }
 
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();
  }
}
 
源代码10 项目: 361Camera   文件: Camera2Fragment.java
@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());
            }
        }
    };
}
 
源代码11 项目: XPrivacy   文件: XSensorManager.java
@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;
	}
}
 
/**
 * 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);
}
 
源代码13 项目: quarks   文件: SensorSourceSetup.java
public SensorSourceSetup(SensorManager mSensorManager, Sensor ... sensors) {
    this(mSensorManager , SensorManager.SENSOR_DELAY_NORMAL, sensors);  
}
 
源代码14 项目: Camdroid   文件: AmbientLightEventListener.java
public AmbientLightEventListener(Context context) {
	this(context, SensorManager.SENSOR_DELAY_NORMAL);
}
 
源代码15 项目: SquareCamera   文件: CameraFragment.java
public CameraOrientationListener(Context context) {
    super(context, SensorManager.SENSOR_DELAY_NORMAL);
}
 
源代码16 项目: Camdroid   文件: AccelerationEventListener.java
public AccelerationEventListener(Context context) {
	this(context, SensorManager.SENSOR_DELAY_NORMAL);
}
 
/**
 * Creates a new OrientationEventListener.
 * 
 * @param context for the OrientationEventListener.
 */
public OrientationEventListener(Context context) {
    this(context, SensorManager.SENSOR_DELAY_NORMAL);
}
 
源代码18 项目: Dota2Helper   文件: DeviceOrientationHelper.java
public DeviceOrientationHelper(Activity ctxt, OrientationChangeCallback callback){
	
	super(ctxt, SensorManager.SENSOR_DELAY_NORMAL);
	this.callback = callback;
	
}
 
源代码19 项目: SimplifyReader   文件: DeviceOrientationHelper.java
public DeviceOrientationHelper(Activity ctxt, OrientationChangeCallback callback){
	
	super(ctxt, SensorManager.SENSOR_DELAY_NORMAL);
	this.callback = callback;
	
}
 
源代码20 项目: retroboy   文件: WindowOrientationListener.java
/**
 * Creates a new WindowOrientationListener.
 * 
 * @param context for the WindowOrientationListener.
 */
public WindowOrientationListener(Context context) {
    this(context, SensorManager.SENSOR_DELAY_NORMAL);
}