Пример #1
0
 public void onSensorChanged(SensorEvent e) {
   if (!isDetectorStarted) return;
   AbstractDetector rd = this.rd;
   if (rd != null) rd.input(e.values[0], e.values[1], e.values[2]);
   else return;
   if (rd != null && rd.isMatch()) {
     if (rd instanceof RotationDetector) {
       Log.i("unidevel.sensor", "screen on");
       screenOn();
     } else if (rd instanceof LockDetector) {
       Log.i("unidevel.sensor", "screen off");
       screenOff();
     }
   }
 }
Пример #2
0
  @SuppressWarnings("deprecation")
  public void onScreenOff() {
    if (this.isUnlockEnabled()) {
      Log.i("onScreenOff", "unlock enabled");
      rd = new RotationDetector();
      rd.setStamp(System.currentTimeMillis() + TIMEOUT);
      this.startDetector();
      PowerManager pm = (PowerManager) getSystemService(POWER_SERVICE);
      this.lock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, UnlockService.class.getName());
      this.lock.acquire();

      Notification n =
          new Notification(R.drawable.ic_launcher, "Unlocking", System.currentTimeMillis());
      Intent i = new Intent();
      PendingIntent pi = PendingIntent.getActivity(this, 0, i, 0);
      n.setLatestEventInfo(this, "aUnlocker", "waiting for screen on", pi);
      n.flags |= Notification.FLAG_NO_CLEAR;
      this.startForeground(1, n);
    } else {
      Log.i("onScreenOff", "unlock disabled");
      this.stopDetector();
    }
  }