protected void setVibrateTo(boolean on) {

    if (Log.DEBUG) Log.d("on = " + on);

    if (on && _vibrateIsMuted) {

      _vibrateIsMuted = false;

      if (_defaultVibrateSettings == AudioManager.VIBRATE_SETTING_OFF) {
        return;
      }

      _audioManager.setVibrateSetting(AudioManager.VIBRATE_TYPE_RINGER, _defaultVibrateSettings);
      _audioManager.setVibrateSetting(
          AudioManager.VIBRATE_TYPE_NOTIFICATION, _defaultVibrateSettings);
    }

    if (!on && !_vibrateIsMuted) {

      _vibrateIsMuted = true;

      _defaultVibrateSettings = _audioManager.getVibrateSetting(AudioManager.VIBRATE_TYPE_RINGER);
      if (_defaultVibrateSettings == AudioManager.VIBRATE_SETTING_OFF) {
        return;
      }

      _vibrator.cancel();
      _audioManager.setVibrateSetting(
          AudioManager.VIBRATE_TYPE_RINGER, AudioManager.VIBRATE_SETTING_OFF);
      _audioManager.setVibrateSetting(
          AudioManager.VIBRATE_TYPE_NOTIFICATION, AudioManager.VIBRATE_SETTING_OFF);
      _vibrator.cancel();
    }
  }
 private void stopAlert(Alarm alarm) {
   mVibrator.cancel();
   mCondition.open();
   mNotificationManager.cancel(alarm.hashCode());
   Log.d(TAG, "Stoped the alert.: " + alarm.dump());
   stopSelf();
 }
예제 #3
0
  /** Stops the ringtone and/or vibrator if any of these are actually ringing/vibrating. */
  void stopRing() {
    synchronized (this) {
      if (DBG) log("stopRing()...");

      try {
        mHardwareService.setAttentionLight(false);
      } catch (RemoteException ex) {
        // the other end of this binder call is in the system process.
      }

      if (mRingHandler != null) {
        mRingHandler.removeCallbacksAndMessages(null);
        Message msg = mRingHandler.obtainMessage(STOP_RING);
        msg.obj = mRingtone;
        mRingHandler.sendMessage(msg);
        PhoneUtils.setAudioMode(mContext, AudioManager.MODE_NORMAL);
        mRingThread = null;
        mRingHandler = null;
        mRingtone = null;
        mFirstRingEventTime = -1;
        mFirstRingStartTime = -1;
      } else {
        if (DBG) log("- stopRing: null mRingHandler!");
      }

      if (mVibratorThread != null) {
        if (DBG) log("- stopRing: cleaning up vibrator thread...");
        mContinueVibrating = false;
        mVibratorThread = null;
      }
      // Also immediately cancel any vibration in progress.
      mVibrator.cancel();
    }
  }
        public void onPanelRevealed() {
          synchronized (mNotificationList) {
            // sound
            mSoundNotification = null;
            long identity = Binder.clearCallingIdentity();
            try {
              mSound.stop();
            } finally {
              Binder.restoreCallingIdentity(identity);
            }

            // vibrate
            mVibrateNotification = null;
            identity = Binder.clearCallingIdentity();
            try {
              mVibrator.cancel();
            } finally {
              Binder.restoreCallingIdentity(identity);
            }

            // light
            mLights.clear();
            mLedNotification = null;
            updateLightsLocked();
          }
        }
예제 #5
0
        public void handleMessage(Message msg) {

          switch (msg.what) {
            case 1:
              if (hit == 0) {
                try {
                  if (alarmMusic.isPlaying()) {
                    alarmMusic.stop();
                    alarmMusic.reset();
                    alarmMusic.release();
                  }
                } catch (Exception e) {
                  alarmMusic = null;
                }
                mVibrator.cancel();
                // 恢复系统之前的音量
                mAudioManager.setStreamVolume(
                    AudioManager.STREAM_MUSIC, current, AudioManager.FLAG_PLAY_SOUND);
                AlarmActivity.this.finish();
                onStartService();
              } else {
                System.out.println("用户已经操作了");
              }
              break;
            case 0:
              mAudioManager.setStreamVolume(
                  AudioManager.STREAM_MUSIC, min + 1, AudioManager.FLAG_PLAY_SOUND);
              min += 1;
              System.out.println("min=" + min);
              break;

            default:
              break;
          }
        };
예제 #6
0
 @Override
 protected void onStop() {
   if (null != vibrator) {
     vibrator.cancel();
     vibrator = null;
   }
   super.onStop();
 }
 @Override
 protected void onDestroy() {
   super.onDestroy();
   vibrator.cancel();
   mTangoUx.stop();
   mTango.disconnect();
   mIsTangoServiceConnected = false;
 }
예제 #8
0
 @Override
 protected void onDestroy() {
   super.onDestroy();
   Vibrator v = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE);
   v.cancel();
   if (this.wakeLock.isHeld()) {
     this.wakeLock.release();
   }
 }
예제 #9
0
 /**
  * msg shake
  *
  * @param context
  * @param isShake
  */
 public static void shakeControlMic(Context context, boolean isShake) {
   Vibrator vibrator = (Vibrator) context.getSystemService(Context.VIBRATOR_SERVICE);
   if (vibrator == null) {
     return;
   }
   if (isShake) {
     vibrator.vibrate(SHAKE_MIC_PATTERN, -1);
     return;
   }
   vibrator.cancel();
 }
  private void cancelNotificationLocked(NotificationRecord r, boolean sendDelete) {
    // tell the app
    if (sendDelete) {
      if (r.notification.deleteIntent != null) {
        try {
          r.notification.deleteIntent.send();
        } catch (PendingIntent.CanceledException ex) {
          // do nothing - there's no relevant way to recover, and
          //     no reason to let this propagate
          Slog.w(TAG, "canceled PendingIntent for " + r.pkg, ex);
        }
      }
    }

    // status bar
    if (r.notification.icon != 0) {
      long identity = Binder.clearCallingIdentity();
      try {
        mStatusBar.removeNotification(r.statusBarKey);
      } finally {
        Binder.restoreCallingIdentity(identity);
      }
      r.statusBarKey = null;
    }

    // sound
    if (mSoundNotification == r) {
      mSoundNotification = null;
      long identity = Binder.clearCallingIdentity();
      try {
        mSound.stop();
      } finally {
        Binder.restoreCallingIdentity(identity);
      }
    }

    // vibrate
    if (mVibrateNotification == r) {
      mVibrateNotification = null;
      long identity = Binder.clearCallingIdentity();
      try {
        mVibrator.cancel();
      } finally {
        Binder.restoreCallingIdentity(identity);
      }
    }

    // light
    mLights.remove(r);
    if (mLedNotification == r) {
      mLedNotification = null;
    }
  }
예제 #11
0
 @Override
 protected void onPause() {
   super.onPause();
   // センサーリスナー終了
   if (hasSensor) {
     sensorMgr.unregisterListener(this);
     hasSensor = false;
   }
   // MediaPlayerのリソースを開放
   alarm.release();
   // バイブレーションを止める
   if (pref_vibrator) {
     vib.cancel();
   }
 }
예제 #12
0
 @Override
 public void onSensorChanged(SensorEvent event) {
   if (event.sensor.getType() == Sensor.TYPE_PROXIMITY) {
     if (event.values[0] < 1.0) // 近接センサーで「近い」
     {
       // アラーム音を消す
       if (alarm != null) {
         alarm.stop();
       }
       // バイブレーションを止める
       if (pref_vibrator) {
         vib.cancel();
       }
       finish();
     }
   }
 }
  @Override
  public void onClick(View v) {
    if (!alarmActive) return;
    String button = (String) v.getTag();
    v.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY);
    if (button.equalsIgnoreCase("clear")) {
      if (answerBuilder.length() > 0) {
        answerBuilder.setLength(answerBuilder.length() - 1);
        answerView.setText(answerBuilder.toString());
      }
    } else if (button.equalsIgnoreCase(".")) {
      if (!answerBuilder.toString().contains(button)) {
        if (answerBuilder.length() == 0) answerBuilder.append(0);
        answerBuilder.append(button);
        answerView.setText(answerBuilder.toString());
      }
    } else if (button.equalsIgnoreCase("-")) {
      if (answerBuilder.length() == 0) {
        answerBuilder.append(button);
        answerView.setText(answerBuilder.toString());
      }
    } else {
      answerBuilder.append(button);
      answerView.setText(answerBuilder.toString());
      if (isAnswerCorrect()) {
        alarmActive = false;
        if (vibrator != null) vibrator.cancel();
        try {
          mediaPlayer.stop();
        } catch (IllegalStateException ise) {

        }
        try {
          mediaPlayer.release();
        } catch (Exception e) {

        }
        this.finish();
      }
    }
    if (answerView.getText().length() >= answerString.length() && !isAnswerCorrect()) {
      answerView.setTextColor(Color.RED);
    } else {
      answerView.setTextColor(Color.WHITE);
    }
  }
  @Override
  protected void onDestroy() {
    try {
      if (vibrator != null) vibrator.cancel();
    } catch (Exception e) {

    }
    try {
      mediaPlayer.stop();
    } catch (Exception e) {

    }
    try {
      mediaPlayer.release();
    } catch (Exception e) {

    }
    super.onDestroy();
  }
예제 #15
0
  public void setVibrateState(int state) {
    long vibratePattern[] = {0, 0, 0};
    if (m_vibrateperiod == -1 || m_vibrateperiod == 0) {
      if (m_resumeTime == 0) {
        long nonPeriodPattern[] = {(long) 0, (long) m_vibrateDuration};
        vibratePattern = nonPeriodPattern;
      } else {
        long nonPeriodPattern[] = {(long) 0, (long) m_resumeTime};
        vibratePattern = nonPeriodPattern;
      }
    } else {
      long periodPattern[] = {(long) 0, (long) m_vibrateperiod, (long) m_vibrateperiod};
      vibratePattern = periodPattern;
    }

    switch (state) {
      case 0:
      case 1:
        m_vibrator.cancel();
        QtNative.activity().unregisterReceiver(this);
        break;
      case 2:
      case 3:
        registerReciever();
        if (m_vibrateperiod == -1 || m_vibrateperiod == 0) {
          m_vibrator.vibrate(vibratePattern, -1);
        } else {
          if (m_resumeTime == 0) {
            m_alarmManager.set(
                AlarmManager.RTC_WAKEUP,
                (System.currentTimeMillis() + m_vibrateDuration),
                m_pendingIntent);
          } else {
            m_alarmManager.set(
                AlarmManager.RTC_WAKEUP,
                (System.currentTimeMillis() + m_resumeTime),
                m_pendingIntent);
          }
          m_vibrator.vibrate(vibratePattern, 0);
        }
    }
  }
예제 #16
0
  /** Stops alarm audio and disables alarm if it not snoozed and not repeating */
  public void stop() {
    if (Log.LOGV) Log.v("AlarmKlaxon.stop()");
    if (mPlaying) {
      mPlaying = false;

      Intent alarmDone = new Intent(Alarms.ALARM_DONE_ACTION);
      sendBroadcast(alarmDone);

      // Stop audio playing
      if (mMediaPlayer != null) {
        mMediaPlayer.stop();
        mMediaPlayer.release();
        mMediaPlayer = null;
      }

      // Stop vibrator
      mVibrator.cancel();
    }
    disableKiller();
  }
        public void onSetDisabled(int status) {
          synchronized (mNotificationList) {
            mDisabledNotifications = status;
            if ((mDisabledNotifications & StatusBarManager.DISABLE_NOTIFICATION_ALERTS) != 0) {
              // cancel whatever's going on
              long identity = Binder.clearCallingIdentity();
              try {
                mSound.stop();
              } finally {
                Binder.restoreCallingIdentity(identity);
              }

              identity = Binder.clearCallingIdentity();
              try {
                mVibrator.cancel();
              } finally {
                Binder.restoreCallingIdentity(identity);
              }
            }
          }
        }
예제 #18
0
 @Override
 public void stop() {
   vibrator.cancel();
 }
예제 #19
0
 public void stopVibrate() {
   v.cancel();
 }
예제 #20
0
 @Override
 public void onReceive(Context context, Intent intent) {
   m_vibrator.cancel();
   QtNative.activity().unregisterReceiver(this);
 }
예제 #21
0
  @Override
  public void onClick(View v) {
    // TODO Auto-generated method stub

    if (v == image) {
      AlertDialog.Builder builder = new AlertDialog.Builder(this);
      LayoutInflater inflater = this.getLayoutInflater();
      View view = inflater.inflate(R.layout.image_dialog, null);
      ImageView dialog_image = (ImageView) view.findViewById(R.id.dialog_iamge);

      if (!"".equals(imageUri)) {
        Options op = new Options();
        op.inJustDecodeBounds = false;
        op.inSampleSize = 1;
        Bitmap bitmap = BitmapFactory.decodeFile(imageUri, op);
        if (null != bitmap) {
          // dialog_image.setVisibility(View.VISIBLE);
          dialog_image.setImageBitmap(bitmap);
        } else {

        }
      }

      Dialog dialog = builder.create();
      dialog.show();
      dialog.setContentView(view);
      dialog.setCanceledOnTouchOutside(true);
    }

    if (v == nowText) {
      if (alarmMusic.isPlaying()) {
        alarmMusic.stop();
        alarmMusic.reset();
        alarmMusic.release();
      }
      // 恢复系统之前的音量
      mAudioManager.setStreamVolume(
          AudioManager.STREAM_MUSIC, current, AudioManager.FLAG_PLAY_SOUND);
      mVibrator.cancel();
      hit = 1;
      // startActivity(new Intent(AlarmActivity.this, HomeActivity.class));
      this.finish();
    }
    if (v == shaoHou) {
      if (alarmMusic.isPlaying()) {
        alarmMusic.stop();
        alarmMusic.reset();
        alarmMusic.release();
      }
      // 恢复系统之前的音量
      mAudioManager.setStreamVolume(
          AudioManager.STREAM_MUSIC, current, AudioManager.FLAG_PLAY_SOUND);
      mVibrator.cancel();
      onStartService();
      hit = 1;
      // startActivity(new Intent(AlarmActivity.this, HomeActivity.class));
      this.finish();
    }
    if (v == hulue) {
      if (alarmMusic.isPlaying()) {
        alarmMusic.stop();
        alarmMusic.reset();
        alarmMusic.release();
      }
      // 恢复系统之前的音量
      mAudioManager.setStreamVolume(
          AudioManager.STREAM_MUSIC, current, AudioManager.FLAG_PLAY_SOUND);
      mVibrator.cancel();
      hit = 1;
      // startActivity(new Intent(AlarmActivity.this, HomeActivity.class));
      this.finish();
    }
  }
예제 #22
0
 @Override
 public void cancelVibrate() {
   vibrator.cancel();
 }
예제 #23
0
 protected void endVibrateAlarm() {
   vib.cancel();
 }
예제 #24
0
파일: vibra.java 프로젝트: Jrodriguez1/test
 public static void cancel(Vibrator vib, SoundPool sp) {
   vib.cancel();
   sp.stop(1);
 }
예제 #25
0
  private void play(Alarm alarm) {
    // stop() checks to see if we are already playing.
    stop();

    if (Log.LOGV) {
      Log.v("AlarmKlaxon.play() " + alarm.id + " alert " + alarm.alert);
    }

    if (!alarm.silent) {
      Uri alert = alarm.alert;
      // Fall back on the default alarm if the database does not have an
      // alarm stored.
      if (alert == null) {
        alert = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_ALARM);
        if (Log.LOGV) {
          Log.v("Using default alarm: " + alert.toString());
        }
      }

      // TODO: Reuse mMediaPlayer instead of creating a new one and/or use
      // RingtoneManager.
      mMediaPlayer = new MediaPlayer();
      mMediaPlayer.setOnErrorListener(
          new OnErrorListener() {
            public boolean onError(MediaPlayer mp, int what, int extra) {
              Log.e("Error occurred while playing audio.");
              mp.stop();
              mp.release();
              mMediaPlayer = null;
              return true;
            }
          });

      try {
        // Check if we are in a call. If we are, use the in-call alarm
        // resource at a low volume to not disrupt the call.
        if (mTelephonyManager.getCallState() != TelephonyManager.CALL_STATE_IDLE) {
          Log.v("Using the in-call alarm");
          mMediaPlayer.setVolume(IN_CALL_VOLUME, IN_CALL_VOLUME);
          setDataSourceFromResource(getResources(), mMediaPlayer, R.raw.in_call_alarm);
        } else {
          mMediaPlayer.setDataSource(this, alert);
        }
        startAlarm(mMediaPlayer);
      } catch (Exception ex) {
        Log.v("Using the fallback ringtone");
        // The alert may be on the sd card which could be busy right
        // now. Use the fallback ringtone.
        try {
          // Must reset the media player to clear the error state.
          mMediaPlayer.reset();
          setDataSourceFromResource(getResources(), mMediaPlayer, R.raw.fallbackring);
          startAlarm(mMediaPlayer);
        } catch (Exception ex2) {
          // At this point we just don't play anything.
          Log.e("Failed to play fallback ringtone", ex2);
        }
      }
    }

    /* Start the vibrator after everything is ok with the media player */
    if (alarm.vibrate) {
      mVibrator.vibrate(sVibratePattern, 0);
    } else {
      mVibrator.cancel();
    }

    enableKiller(alarm);
    mPlaying = true;
    mStartTime = System.currentTimeMillis();
  }
예제 #26
0
 public static void stopVibrate() {
   vibrator.cancel();
 }
예제 #27
0
 public static void cancel(Context context) {
   Vibrator vibrator = (Vibrator) context.getSystemService(Context.VIBRATOR_SERVICE);
   vibrator.cancel();
 }
예제 #28
0
 @Override
 public void onDestroy() {
   mediaPlayer.release();
   vibrator.cancel();
   super.onDestroy();
 }
예제 #29
0
 @JavascriptInterface
 @SuppressWarnings("unused")
 public void cancel() {
   mVibrator.cancel();
 }
예제 #30
0
        @Override
        public void handleMessage(Message msg) {

          switch (msg.what) {
            case MSG_LOCK_SUCESS1:
              try {
                if (alarmMusic.isPlaying()) {
                  alarmMusic.stop();
                  alarmMusic.reset();
                  alarmMusic.release();
                }
              } catch (Exception e) {
                // TODO: handle exception
              }
              // 恢复系统之前的音量
              mAudioManager.setStreamVolume(
                  AudioManager.STREAM_MUSIC, current, AudioManager.FLAG_PLAY_SOUND);
              mVibrator.cancel();
              hit = 1;
              AlarmActivity.this.finish();
              break;
            case MSG_LOCK_SUCESS2:
              try {
                if (alarmMusic.isPlaying()) {
                  alarmMusic.stop();
                  alarmMusic.reset();
                  alarmMusic.release();
                }
              } catch (Exception e) {
                // TODO: handle exception
              }
              // 恢复系统之前的音量
              mAudioManager.setStreamVolume(
                  AudioManager.STREAM_MUSIC, current, AudioManager.FLAG_PLAY_SOUND);
              mVibrator.cancel();
              onStartService();
              hit = 1;
              AlarmActivity.this.finish();

              break;
            case MSG_LOCK_SUCESS3:
              try {
                if (alarmMusic.isPlaying()) {
                  alarmMusic.stop();
                  alarmMusic.reset();
                  alarmMusic.release();
                }
              } catch (Exception e) {
                // TODO: handle exception
              }

              // 恢复系统之前的音量
              mAudioManager.setStreamVolume(
                  AudioManager.STREAM_MUSIC, current, AudioManager.FLAG_PLAY_SOUND);
              mVibrator.cancel();
              hit = 1;
              AlarmActivity.this.finish();
              break;

            default:
              break;
          }
        }