示例#1
1
  @Override
  protected void onResume() {
    super.onResume();

    // Manage bubble popping sound
    // Use AudioManager.STREAM_MUSIC as stream type

    mAudioManager = (AudioManager) getSystemService(AUDIO_SERVICE);

    mStreamVolume =
        (float) mAudioManager.getStreamVolume(AudioManager.STREAM_MUSIC)
            / mAudioManager.getStreamMaxVolume(AudioManager.STREAM_MUSIC);

    mSoundPool = new SoundPool(10, AudioManager.STREAM_MUSIC, 0);

    mSoundPool.setOnLoadCompleteListener(
        new OnLoadCompleteListener() {

          @Override
          public void onLoadComplete(SoundPool soundPool, int sampleId, int status) {
            if (status == 0) {
              setupGestureDetector();
            } else {
              Log.i(TAG, "Unable to load sound");
              finish();
            }
          }
        });

    mSoundID = mSoundPool.load(this, R.raw.bubble_pop, 1);
  }
  private String getPhoneVibrateSettingValue() {
    boolean vibeInSilent =
        (Settings.System.getInt(getContentResolver(), Settings.System.VIBRATE_IN_SILENT, 1) == 1);

    // Control phone vibe independent of silent mode
    int callsVibrateSetting = mAudioManager.getVibrateSetting(AudioManager.VIBRATE_TYPE_RINGER);

    if (vibeInSilent) {
      if (callsVibrateSetting == AudioManager.VIBRATE_SETTING_OFF) {
        // this state does not make sense; fix it up for the user
        mAudioManager.setVibrateSetting(
            AudioManager.VIBRATE_TYPE_RINGER, AudioManager.VIBRATE_SETTING_ONLY_SILENT);
      }
      if (callsVibrateSetting == AudioManager.VIBRATE_SETTING_ON) {
        return VALUE_VIBRATE_ALWAYS;
      } else {
        return VALUE_VIBRATE_ONLY_SILENT;
      }
    } else {
      if (callsVibrateSetting == AudioManager.VIBRATE_SETTING_ONLY_SILENT) {
        // this state does not make sense; fix it up
        mAudioManager.setVibrateSetting(
            AudioManager.VIBRATE_TYPE_RINGER, AudioManager.VIBRATE_SETTING_OFF);
      }
      if (callsVibrateSetting == AudioManager.VIBRATE_SETTING_ON) {
        return VALUE_VIBRATE_UNLESS_SILENT;
      } else {
        return VALUE_VIBRATE_NEVER;
      }
    }
  }
 /** Sets the speaker phone mode. */
 private void setSpeakerphoneOn(boolean on) {
   boolean wasOn = audioManager.isSpeakerphoneOn();
   if (wasOn == on) {
     return;
   }
   audioManager.setSpeakerphoneOn(on);
 }
示例#4
0
  @Override
  public void onChange(boolean selfChange) {
    Log.d("C3PO", "Received settings change!");

    super.onChange(selfChange);
    Log.d("C3PO", "Settings change detected");

    int vol = audioManager.getStreamVolume(AudioManager.STREAM_RING);
    int max_vol = audioManager.getStreamMaxVolume(AudioManager.STREAM_RING);
    if (vol == oldVolume) {
      return;
    }
    oldVolume = vol;
    SimplMessageAndroid msg_out = new SimplMessageAndroid();
    try {
      msg_out.addParam(Param.MSGID, -1);
      msg_out.addParam(Param.CURRENT_VOLUME, vol);
      msg_out.addParam(Param.MAX_VOLUME, max_vol);
    } catch (JSONException e) {
      e.printStackTrace();
    }
    try {
      Socket s =
          new Socket(
              context.getString(R.string.comm_relay_ip),
              Integer.parseInt(context.getString(R.string.comm_relay_outbound)));
      SecureChannel channel = new SecureChannelAndroid(new RSAUtilImpl(context));
      channel.serialize(msg_out, s);
      Log.d("C3PO", "Sent notification of change");
    } catch (Exception e) {
      e.printStackTrace();
    }
  }
 void restoreVolume() {
   switch (getMode()) {
     case AudioManager.MODE_IN_CALL:
       int oldring =
           PreferenceManager.getDefaultSharedPreferences(Receiver.mContext).getInt("oldring", 0);
       if (oldring > 0)
         setStreamVolume(
             AudioManager.STREAM_RING,
             (int)
                 (am.getStreamMaxVolume(AudioManager.STREAM_RING)
                     * org.sipdroid.sipua.ui.Settings.getEarGain()
                     * 3
                     / 4),
             0);
       track.setStereoVolume(
           AudioTrack.getMaxVolume() * (ogain = org.sipdroid.sipua.ui.Settings.getEarGain() * 2),
           AudioTrack.getMaxVolume() * org.sipdroid.sipua.ui.Settings.getEarGain() * 2);
       if (gain == 0 || ogain <= 1) gain = ogain;
       break;
     case AudioManager.MODE_NORMAL:
       track.setStereoVolume(AudioTrack.getMaxVolume(), AudioTrack.getMaxVolume());
       break;
   }
   setStreamVolume(
       stream(),
       PreferenceManager.getDefaultSharedPreferences(Receiver.mContext)
           .getInt(
               "volume" + speakermode,
               am.getStreamMaxVolume(stream())
                   * (speakermode == AudioManager.MODE_NORMAL ? 4 : 3)
                   / 4),
       0);
 }
示例#6
0
  @TargetApi(8)
  private void changeAudioFocus(boolean gain) {
    if (!Util.isFroyoOrLater()) // NOP if not supported
    return;

    audioFocusListener =
        new OnAudioFocusChangeListener() {
          @Override
          public void onAudioFocusChange(int focusChange) {
            if (focusChange == AudioManager.AUDIOFOCUS_LOSS_TRANSIENT_CAN_DUCK
                || focusChange == AudioManager.AUDIOFOCUS_LOSS_TRANSIENT) {
              /*
               * Lower the volume to 36% to "duck" when an alert or something
               * needs to be played.
               */
              LibVLC.getExistingInstance().setVolume(36);
            } else {
              LibVLC.getExistingInstance().setVolume(100);
            }
          }
        };

    AudioManager am = (AudioManager) getSystemService(AUDIO_SERVICE);
    if (gain)
      am.requestAudioFocus(
          audioFocusListener, AudioManager.STREAM_MUSIC, AudioManager.AUDIOFOCUS_GAIN);
    else am.abandonAudioFocus(audioFocusListener);
  }
示例#7
0
  @Override
  public int onStartCommand(Intent intent, int flags, int startId) {
    instance = this;
    Log.i("Jane", "Received start id " + startId + ": " + intent);
    Log.d("Jane", "Service received start command.");

    tts =
        new TextToSpeech(
            this,
            new TextToSpeech.OnInitListener() {

              @Override
              public void onInit(int status) {}
            });
    tts.setOnUtteranceCompletedListener(this);

    // set up Bluetooth here
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB) {
      bt = new Gingerbread();
    } else {
      bt = new Honeycomb();
    }

    bt.setContext(getApplicationContext());

    try {
      bt.getProxy();
    } catch (Exception e) {
      e.printStackTrace();
    }

    AudioManager am = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
    ComponentName mediaButtonResponder =
        new ComponentName(getPackageName(), MediaButtonIntentReceiver.class.getName());
    am.registerMediaButtonEventReceiver(mediaButtonResponder);

    PowerManager powerManager = (PowerManager) getSystemService(Context.POWER_SERVICE);
    WakeLock lock = powerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "JaneLock");
    lock.acquire(10 * 60 * 1000);

    localBroadcastManager = LocalBroadcastManager.getInstance(this);
    localChatReceiver = new ChatReceiver(this);

    String username = intent.getExtras().getString("username");
    String password = intent.getExtras().getString("password");
    uiMessenger = intent.getExtras().getParcelable("messenger");

    nameCache = new HashMap<String, String>();
    chatCache = new HashMap<String, Chat>();

    smack = org.jivesoftware.smack.SmackAndroid.init(this);

    this.registerReceiver(stateIntents, new IntentFilter(JaneIntent));
    this.registerReceiver(stateIntents, new IntentFilter(Bluetooth.BLUETOOTH_STATE));

    LoginThread login = new LoginThread(username, password, this);
    login.start();

    return START_STICKY;
  }
  @Override
  protected void onPause() {
    super.onPause();
    //	removeWindow();
    kl.reenableKeyguard();
    unregisterReceiver(mWifiReceiver);
    unregisterReceiver(mPowerBroadcastReceiver);
    sensorManager.unregisterListener(lsn);
    mWifiHandler.removeMessages(WIFI_MSG_SCAN);
    Log.d(TAG, " __________________---------- oldBrightness = " + oldBrightness);

    switch (mRecorder.state()) {
      case Recorder.IDLE_STATE:
        mRecorder.delete();
        break;
      case Recorder.PLAYING_STATE:
        mRecorder.stop();
        mRecorder.delete();
        break;
      case Recorder.RECORDING_STATE:
        mRecorder.stop();
        mRecorder.clear();
        break;
    }
    mAudioManager.setStreamVolume(AudioManager.STREAM_MUSIC, mOldVolume, 0);
    if (mSpeakerOn) {
      mAudioManager.setSpeakerphoneOn(false);
    }
    //		unregisterReceiver(mPowerBroadcastReceiver);
  }
  @Override
  protected void onResume() {
    super.onResume();

    // Manage bubble popping sound
    // Use AudioManager.STREAM_MUSIC as stream type

    mAudioManager = (AudioManager) getSystemService(AUDIO_SERVICE);

    mStreamVolume =
        (float) mAudioManager.getStreamVolume(AudioManager.STREAM_MUSIC)
            / mAudioManager.getStreamMaxVolume(AudioManager.STREAM_MUSIC);
    // done
    mSoundPool = new SoundPool(10, AudioManager.STREAM_MUSIC, 0);

    // done
    mSoundPool.setOnLoadCompleteListener(
        new SoundPool.OnLoadCompleteListener() {
          @Override
          public void onLoadComplete(SoundPool soundPool, int i, int i2) {
            setupGestureDetector();
          }
        });

    // done
    mSoundID = mSoundPool.load(this, R.raw.bubble_pop, 1);
  }
 public static boolean shouldVibrate(
     String vibroModeKey, SharedPreferences settings, AudioManager audioManager) {
   try {
     int mode = Integer.parseInt(settings.getString(vibroModeKey, "0"));
     switch (mode) {
       case MODE_SYSTEM:
         return audioManager.shouldVibrate(AudioManager.VIBRATE_TYPE_NOTIFICATION);
       case MODE_ALWAYS:
         return true;
       case MODE_NEVER:
         return false;
       case MODE_NORMAL_ONLY:
         return audioManager.getRingerMode() == AudioManager.RINGER_MODE_NORMAL;
       case MODE_SILENT_ONLY:
         switch (audioManager.getRingerMode()) {
           case AudioManager.RINGER_MODE_SILENT:
           case AudioManager.RINGER_MODE_VIBRATE:
             return true;
         }
         return false;
     }
   } catch (Exception ex) {
     Log.w(Settings.class.getSimpleName(), "", ex);
   }
   return false;
 }
 public static int shouldSound(
     String soundModeKey, SharedPreferences settings, AudioManager audioManager) {
   try {
     int mode = Integer.parseInt(settings.getString(soundModeKey, "0"));
     switch (mode) {
       case MODE_SYSTEM:
         return SHOULD_SOUND_SYSTEM;
       case MODE_NORMAL_ONLY:
         return audioManager.getRingerMode() == AudioManager.RINGER_MODE_NORMAL
             ? SHOULD_SOUND_TRUE
             : SHOULD_SOUND_FALSE;
       case MODE_ALWAYS:
         return SHOULD_SOUND_TRUE;
       case MODE_NEVER:
         return SHOULD_SOUND_FALSE;
       case MODE_SILENT_ONLY:
         return audioManager.getRingerMode() == AudioManager.RINGER_MODE_SILENT
             ? SHOULD_SOUND_TRUE
             : SHOULD_SOUND_FALSE;
     }
   } catch (Exception ex) {
     Log.w(Settings.class.getSimpleName(), "", ex);
   }
   return SHOULD_SOUND_SYSTEM;
 }
示例#12
0
文件: Menu.java 项目: psud/Melde-App
 private void MuteDevice() {
   // TODO Auto-generated method stub
   if (true) {
     AudioManager audioManager = (AudioManager) this.getSystemService(Context.AUDIO_SERVICE);
     audioManager.setRingerMode(AudioManager.RINGER_MODE_SILENT);
   }
 }
  private void resumeSync() {
    if (playerStatus == PlayerStatus.PAUSED || playerStatus == PlayerStatus.PREPARED) {
      int focusGained =
          audioManager.requestAudioFocus(
              audioFocusChangeListener, AudioManager.STREAM_MUSIC, AudioManager.AUDIOFOCUS_GAIN);
      if (focusGained == AudioManager.AUDIOFOCUS_REQUEST_GRANTED) {
        acquireWifiLockIfNecessary();
        setSpeed(Float.parseFloat(UserPreferences.getPlaybackSpeed()));
        mediaPlayer.start();
        if (playerStatus == PlayerStatus.PREPARED && media.getPosition() > 0) {
          mediaPlayer.seekTo(media.getPosition());
        }

        setPlayerStatus(PlayerStatus.PLAYING, media);
        pausedBecauseOfTransientAudiofocusLoss = false;
        if (android.os.Build.VERSION.SDK_INT >= 14) {
          RemoteControlClient remoteControlClient = callback.getRemoteControlClient();
          if (remoteControlClient != null) {
            audioManager.registerRemoteControlClient(remoteControlClient);
          }
        }
        audioManager.registerMediaButtonEventReceiver(
            new ComponentName(context.getPackageName(), MediaButtonReceiver.class.getName()));
        media.onPlaybackStart();

      } else {
        if (BuildConfig.DEBUG) Log.e(TAG, "Failed to request audio focus");
      }
    } else {
      if (BuildConfig.DEBUG)
        Log.d(
            TAG,
            "Call to resume() was ignored because current state of PSMP object is " + playerStatus);
    }
  }
示例#14
0
  private void handleMessage(final Context context, Intent intent) {
    // push를 사용 안할 경우 메시지가 오더라도 무시 함.
    SharedPreferences preferences = context.getSharedPreferences("pushPref", Activity.MODE_PRIVATE);
    boolean isPushEnable = preferences.getBoolean("isPushEnable", true);
    if (!isPushEnable) {
      Logger.d("handleMessage", "isPushEnable : " + isPushEnable);
      return;
    }

    // 화면을 켬
    pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
    wl =
        pm.newWakeLock(
            PowerManager.SCREEN_BRIGHT_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP, "bbbb");
    wl.acquire();

    Log.i("handleMessage", "------------ COME MESSAGE: " + pushKey);
    // TODO Auto-generated method stub
    String count = intent.getExtras().getString("badge");
    String message = intent.getExtras().getString("message");
    // String collaspe_key = intent.getExtras().getString("collaspe_key");

    Log.i("handleMessage", "------------ COME MESSAGE: " + message + ", " + count);

    Notification notification =
        new Notification(
            RUtil.getDrawableR(context, "app_icon"), message, System.currentTimeMillis());

    // notiId
    int notiID = (int) System.currentTimeMillis();
    // TODO 현재는 시작 화면으로 가게 했지만 추후 수정해야함.
    String title = PushManager.getInstance().getNotiMessage(PushManager.MESSAGE_TITLE);
    Intent in = new Intent(Intent.ACTION_MAIN);
    in.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    in.addCategory(Intent.CATEGORY_LAUNCHER);
    in.setComponent(new ComponentName(context, DummyActivity.class));
    in.putExtra("push", message);
    in.putExtra("push_noti_id", notiID);
    PendingIntent pi =
        PendingIntent.getActivity(
            context, notiID, in, Intent.FLAG_ACTIVITY_NEW_TASK | PendingIntent.FLAG_ONE_SHOT);
    notification.setLatestEventInfo(context, title, message, pi);
    notification.flags |= Notification.FLAG_AUTO_CANCEL; // 선택시 자동삭제

    NotificationManager nm =
        (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);

    AudioManager audioManager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);
    // 전체 제거 고려
    if (audioManager.getRingerMode() == AudioManager.RINGER_MODE_NORMAL) {
      notification.defaults |= android.app.Notification.DEFAULT_SOUND;
    } else {
      // 진동 효과 구성
      long[] vibrate = {1000, 1000, 1000, 1000, 1000};
      notification.vibrate = vibrate;
    }
    // nm.notify(PushManager.PUSH_MESSAGE, notification);
    nm.notify(notiID, notification);
    run.run();
  }
  private void setPhoneVibrateSettingValue(String value) {
    boolean vibeInSilent;
    int callsVibrateSetting;

    if (value.equals(VALUE_VIBRATE_UNLESS_SILENT)) {
      callsVibrateSetting = AudioManager.VIBRATE_SETTING_ON;
      vibeInSilent = false;
    } else if (value.equals(VALUE_VIBRATE_NEVER)) {
      callsVibrateSetting = AudioManager.VIBRATE_SETTING_OFF;
      vibeInSilent = false;
    } else if (value.equals(VALUE_VIBRATE_ONLY_SILENT)) {
      callsVibrateSetting = AudioManager.VIBRATE_SETTING_ONLY_SILENT;
      vibeInSilent = true;
    } else { // VALUE_VIBRATE_ALWAYS
      callsVibrateSetting = AudioManager.VIBRATE_SETTING_ON;
      vibeInSilent = true;
    }

    Settings.System.putInt(
        getContentResolver(), Settings.System.VIBRATE_IN_SILENT, vibeInSilent ? 1 : 0);

    // might need to switch the ringer mode from one kind of "silent" to
    // another
    if (mSilent.isChecked()) {
      mAudioManager.setRingerMode(
          vibeInSilent ? AudioManager.RINGER_MODE_VIBRATE : AudioManager.RINGER_MODE_SILENT);
    }

    mAudioManager.setVibrateSetting(AudioManager.VIBRATE_TYPE_RINGER, callsVibrateSetting);
  }
  @Override
  protected void onResume() {
    super.onResume();
    SurfaceView surfaceView = (SurfaceView) findViewById(R.id.preview_view);
    SurfaceHolder surfaceHolder = surfaceView.getHolder();
    if (hasSurface) {
      initCamera(surfaceHolder);
    } else {
      surfaceHolder.addCallback(this);
      surfaceHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
    }
    decodeFormats = null;
    characterSet = null;

    playBeep = true;
    AudioManager audioService = (AudioManager) getSystemService(AUDIO_SERVICE);
    if (audioService.getRingerMode() != AudioManager.RINGER_MODE_NORMAL) {
      playBeep = false;
    }
    initBeepSound();
    vibrate = true;

    // quit the scan view
    cancelScanButton.setOnClickListener(
        new OnClickListener() {

          @Override
          public void onClick(View v) {
            CaptureActivity.this.finish();
          }
        });
  }
示例#17
0
  @Override
  public boolean onPrepareOptionsMenu(Menu menu) {
    // Only show favourites and access tokens (DB-related) if the connected server has a DB
    // representation (non-public).
    MenuItem fullscreenItem = menu.findItem(R.id.menu_fullscreen);
    MenuItem favouritesViewItem = menu.findItem(R.id.menu_view_favorites_button);
    MenuItem accessTokensItem = menu.findItem(R.id.menu_access_tokens_button);

    userRegisterItem = menu.findItem(R.id.menu_user_register);
    userCommentItem = menu.findItem(R.id.menu_user_comment);
    userInformationItem = menu.findItem(R.id.menu_user_information);

    if (mService != null && mService.getConnectedServer() != null) {

      favouritesViewItem.setVisible(!mService.isConnectedServerPublic());
      accessTokensItem.setVisible(!mService.isConnectedServerPublic());
    }

    fullscreenItem.setVisible(mViewPager == null); // Only show fullscreen option if in tablet mode

    // Show whether or not SCO is enabled
    AudioManager audioManager = (AudioManager) getSystemService(AUDIO_SERVICE);
    bluetoothItem = menu.findItem(R.id.menu_bluetooth);
    bluetoothItem.setChecked(audioManager.isBluetoothScoOn());

    return super.onPrepareOptionsMenu(menu);
  }
示例#18
0
  public void init() {
    Log.d(TAG, "init");
    if (initialized) {
      return;
    }

    // Store current audio state so we can restore it when close() is called.
    savedAudioMode = audioManager.getMode();
    savedIsSpeakerPhoneOn = audioManager.isSpeakerphoneOn();
    savedIsMicrophoneMute = audioManager.isMicrophoneMute();

    // Request audio focus before making any device switch.
    audioManager.requestAudioFocus(
        null, AudioManager.STREAM_VOICE_CALL, AudioManager.AUDIOFOCUS_GAIN_TRANSIENT);

    // Start by setting RINGTONE as default audio mode. The native WebRTC
    // audio layer will switch to COMMUNICATION mode when the first streaming
    // session starts and return to RINGTONE mode when all streaming stops.
    audioManager.setMode(AudioManager.MODE_RINGTONE);

    // Always disable microphone mute during a WebRTC call.
    setMicrophoneMute(false);

    // Do initial selection of audio device. This setting can later be changed
    // either by adding/removing a wired headset or by covering/uncovering the
    // proximity sensor.
    updateAudioDeviceState(hasWiredHeadset());

    // Register receiver for broadcast intents related to adding/removing a
    // wired headset (Intent.ACTION_HEADSET_PLUG).
    registerForWiredHeadsetIntentBroadcast();

    initialized = true;
  }
示例#19
0
  /** 设置闹铃 */
  private void setAlarm() {

    alarmMusic = MediaPlayer.create(this, R.raw.a);
    mAudioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
    max = mAudioManager.getStreamMaxVolume(AudioManager.STREAM_SYSTEM);
    current = mAudioManager.getStreamVolume(AudioManager.STREAM_SYSTEM);

    Iterator<Map.Entry<String, Integer>> iterator = map.entrySet().iterator();
    while (iterator.hasNext()) {
      Map.Entry<String, Integer> entry = iterator.next();
      String key = entry.getKey();
      try {
        if (clockModel.getRing().equals(key)) {
          alarmMusic = MediaPlayer.create(this, map.get(key));
        }
      } catch (Exception e) {
        alarmMusic = MediaPlayer.create(this, R.raw.a);
      }
    }
    // 设置为循环播放
    alarmMusic.setLooping(true);
    // 获取震动
    mVibrator = (Vibrator) this.getSystemService(Context.VIBRATOR_SERVICE);
    // 震动时长与音乐播放时长一样,放在MediaPlayer.create()之后,不然报错null object reference
    // mVibrator.vibrate(alarmMusic.getDuration());
    mVibrator.vibrate(new long[] {1000, 2000, 1000, 2000, 1000}, 0);
    // 调节到最大音量
    mAudioManager.setStreamVolume(AudioManager.STREAM_MUSIC, max, AudioManager.FLAG_PLAY_SOUND);

    // 闹铃响
    alarmMusic.start();
  }
  private void initData(Context context) {
    this.mContext = context;
    mActivity = (Activity) context;
    DisplayMetrics dm = new DisplayMetrics();
    mActivity.getWindowManager().getDefaultDisplay().getMetrics(dm);
    mDensity = dm.density;
    mWidth = dm.widthPixels;
    mInflater = LayoutInflater.from(mContext);
    AudioManager audioManager = (AudioManager) mContext.getSystemService(Context.AUDIO_SERVICE);
    audioManager.setMode(AudioManager.MODE_NORMAL);
    if (audioManager.isSpeakerphoneOn()) {
      audioManager.setSpeakerphoneOn(true);
    } else {
      audioManager.setSpeakerphoneOn(false);
    }
    mp.setAudioStreamType(AudioManager.STREAM_RING);
    mp.setOnErrorListener(
        new OnErrorListener() {

          @Override
          public boolean onError(MediaPlayer mp, int what, int extra) {
            return false;
          }
        });
  }
示例#21
0
  /**
   * Set up the remote control and tell the system we want to be the default receiver for the MEDIA
   * buttons
   *
   * @see http://android-developers.blogspot.fr/2010/06/allowing-applications-to-play-nicer.html
   */
  @TargetApi(14)
  public void setUpRemoteControlClient() {
    Context context = VLCApplication.getAppContext();
    AudioManager audioManager = (AudioManager) context.getSystemService(AUDIO_SERVICE);

    if (Util.isICSOrLater()) {
      audioManager.registerMediaButtonEventReceiver(mRemoteControlClientReceiverComponent);

      if (mRemoteControlClient == null) {
        Intent mediaButtonIntent = new Intent(Intent.ACTION_MEDIA_BUTTON);
        mediaButtonIntent.setComponent(mRemoteControlClientReceiverComponent);
        PendingIntent mediaPendingIntent =
            PendingIntent.getBroadcast(context, 0, mediaButtonIntent, 0);

        // create and register the remote control client
        mRemoteControlClient = new RemoteControlClient(mediaPendingIntent);
        audioManager.registerRemoteControlClient(mRemoteControlClient);
      }

      mRemoteControlClient.setTransportControlFlags(
          RemoteControlClient.FLAG_KEY_MEDIA_PLAY
              | RemoteControlClient.FLAG_KEY_MEDIA_PAUSE
              | RemoteControlClient.FLAG_KEY_MEDIA_PREVIOUS
              | RemoteControlClient.FLAG_KEY_MEDIA_NEXT
              | RemoteControlClient.FLAG_KEY_MEDIA_STOP);
    } else if (Util.isFroyoOrLater()) {
      audioManager.registerMediaButtonEventReceiver(mRemoteControlClientReceiverComponent);
    }
  }
示例#22
0
 public static void playSound(int index, float speed) {
   if (playSound) {
     float streamVolume = mAudioManager.getStreamVolume(AudioManager.STREAM_MUSIC);
     streamVolume = streamVolume / mAudioManager.getStreamMaxVolume(AudioManager.STREAM_MUSIC);
     mSoundPool.play(mSoundPoolMap.get(index), streamVolume, streamVolume, 1, 0, speed);
   }
 }
  public void playSound(int index) {
    if (!mContext.getSettings().isSoundEnabled()) return; // user does not want sound

    float streamVolume = mAudioManager.getStreamVolume(AudioManager.STREAM_MUSIC);
    streamVolume = streamVolume / mAudioManager.getStreamMaxVolume(AudioManager.STREAM_MUSIC);
    mSoundPool.play(mSoundPoolMap.get(index), streamVolume, streamVolume, 1, 0, 1f);
  }
示例#24
0
  public boolean endCall() {
    if (_prevRingerMode == null) {
      _prevRingerMode = _audioManager.getRingerMode();
    }

    _audioManager.setRingerMode(AudioManager.RINGER_MODE_SILENT);

    try {
      String serviceManagerName = "android.os.ServiceManager";
      String serviceManagerNativeName = "android.os.ServiceManagerNative";
      String telephonyName = "com.android.internal.telephony.ITelephony";

      Class<?> telephonyClass = Class.forName(telephonyName);
      Class<?> telephonyStubClass = telephonyClass.getClasses()[0];
      Class<?> serviceManagerClass = Class.forName(serviceManagerName);
      Class<?> serviceManagerNativeClass = Class.forName(serviceManagerNativeName);

      Binder tmpBinder = new Binder();
      tmpBinder.attachInterface(null, "fake");
      Method tempInterfaceMethod =
          serviceManagerNativeClass.getMethod("asInterface", IBinder.class);
      Object serviceManagerObject = tempInterfaceMethod.invoke(null, tmpBinder);
      Method getService = serviceManagerClass.getMethod("getService", String.class);
      IBinder retbinder = (IBinder) getService.invoke(serviceManagerObject, "phone");

      Method serviceMethod = telephonyStubClass.getMethod("asInterface", IBinder.class);
      Object telephonyObject = serviceMethod.invoke(null, retbinder);
      Method telephonyEndCall = telephonyClass.getMethod("endCall");
      telephonyEndCall.invoke(telephonyObject);
      return true;
    } catch (Exception e) {
      Log.e(TAG, "Could not connect to telephony subsystem", e);
      return false;
    }
  }
 void saveSettings() {
   if (!PreferenceManager.getDefaultSharedPreferences(Receiver.mContext)
       .getBoolean(
           org.sipdroid.sipua.ui.Settings.PREF_OLDVALID,
           org.sipdroid.sipua.ui.Settings.DEFAULT_OLDVALID)) {
     int oldvibrate = am.getVibrateSetting(AudioManager.VIBRATE_TYPE_RINGER);
     int oldvibrate2 = am.getVibrateSetting(AudioManager.VIBRATE_TYPE_NOTIFICATION);
     if (!PreferenceManager.getDefaultSharedPreferences(Receiver.mContext)
         .contains(org.sipdroid.sipua.ui.Settings.PREF_OLDVIBRATE2))
       oldvibrate2 = AudioManager.VIBRATE_SETTING_ON;
     int oldpolicy =
         android.provider.Settings.System.getInt(
             cr,
             android.provider.Settings.System.WIFI_SLEEP_POLICY,
             Settings.System.WIFI_SLEEP_POLICY_DEFAULT);
     Editor edit = PreferenceManager.getDefaultSharedPreferences(Receiver.mContext).edit();
     edit.putInt(org.sipdroid.sipua.ui.Settings.PREF_OLDVIBRATE, oldvibrate);
     edit.putInt(org.sipdroid.sipua.ui.Settings.PREF_OLDVIBRATE2, oldvibrate2);
     edit.putInt(org.sipdroid.sipua.ui.Settings.PREF_OLDPOLICY, oldpolicy);
     edit.putInt(
         org.sipdroid.sipua.ui.Settings.PREF_OLDRING,
         am.getStreamVolume(AudioManager.STREAM_RING));
     edit.putBoolean(org.sipdroid.sipua.ui.Settings.PREF_OLDVALID, true);
     edit.commit();
   }
 }
 @Override
 public boolean onOptionsItemSelected(MenuItem item) {
   // Handle item selection
   switch (item.getItemId()) {
     case R.id.exit:
       moveTaskToBack(true);
       return true;
     case R.id.sound:
       AudioManager volumeControl = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
       if (soundOn) {
         volumeControl.setStreamMute(AudioManager.STREAM_MUSIC, true);
         soundOn = false;
         item.setTitle("Sound On");
       } else {
         volumeControl.setStreamMute(AudioManager.STREAM_MUSIC, false);
         soundOn = true;
         item.setTitle("Sound Off");
       }
       return true;
     case R.id.ratings:
       startActivity(
           new Intent(
               Intent.ACTION_VIEW, Uri.parse("market://details?id=com.apps.tictactoe#rate")));
       return true;
     case R.id.back:
       startActivity(new Intent(this, HomeScreenActivity.class));
       return true;
     case R.id.about:
       startActivity(new Intent(this, About.class));
       return true;
     default:
       return super.onOptionsItemSelected(item);
   }
 }
  public void init() {
    Log.d(TAG, "init");
    if (initialized) {
      return;
    }

    // Store current audio state so we can restore it when close() is called.
    savedAudioMode = audioManager.getMode();
    savedIsSpeakerPhoneOn = audioManager.isSpeakerphoneOn();
    savedIsMicrophoneMute = audioManager.isMicrophoneMute();

    // Request audio focus before making any device switch.
    audioManager.requestAudioFocus(
        null, AudioManager.STREAM_VOICE_CALL, AudioManager.AUDIOFOCUS_GAIN_TRANSIENT);

    // Start by setting MODE_IN_COMMUNICATION as default audio mode. It is
    // required to be in this mode when playout and/or recording starts for
    // best possible VoIP performance.
    // TODO(henrika): we migh want to start with RINGTONE mode here instead.
    audioManager.setMode(AudioManager.MODE_IN_COMMUNICATION);

    // Always disable microphone mute during a WebRTC call.
    setMicrophoneMute(false);

    // Do initial selection of audio device. This setting can later be changed
    // either by adding/removing a wired headset or by covering/uncovering the
    // proximity sensor.
    updateAudioDeviceState(hasWiredHeadset());

    // Register receiver for broadcast intents related to adding/removing a
    // wired headset (Intent.ACTION_HEADSET_PLUG).
    registerForWiredHeadsetIntentBroadcast();

    initialized = true;
  }
示例#28
0
  private void LoadContent() {
    audioManager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);
    ((Activity) context).setVolumeControlStream(AudioManager.STREAM_MUSIC);
    soundPool = new SoundPool(20, AudioManager.STREAM_RING, 100);

    curVolume = audioManager.getStreamVolume(AudioManager.STREAM_MUSIC);
    maxVolume = audioManager.getStreamMaxVolume(AudioManager.STREAM_MUSIC);
    leftVolume = (curVolume / maxVolume);
    rightVolume = (curVolume / maxVolume);

    soundPoolMap[0] = soundPool.load(context, R.raw.coin_collect, 1);
    aff = soundPool.load(context, R.raw.coin_collect, 1);
    soundPoolMap[1] = soundPool.load(context, R.raw.cheer1, 1);
    soundPoolMap[2] = soundPool.load(context, R.raw.sound_bird, 1);
    soundPoolMap[3] = soundPool.load(context, R.raw.sound_shark, 1);
    soundPoolMap[4] = soundPool.load(context, R.raw.sound_splash, 1);
    soundPoolMap[5] = soundPool.load(context, R.raw.sound_swoosh, 1);
    soundPoolMap[6] = soundPool.load(context, R.raw.noluck, 1);
    soundPoolMap[7] = soundPool.load(context, R.raw.luck, 1);
    soundPoolMap[8] = soundPool.load(context, R.raw.start_boat, 1);

    priority = 1;
    no_loop = 0;
    normal_playback_rate = 1f;

    themePlay = MediaPlayer.create(this.context, R.raw.theme);
    themePlay.setLooping(true);
    themePlay.start();

    wavePlay = MediaPlayer.create(this.context, R.raw.wave_sound);
    wavePlay.setLooping(true);
    wavePlay.setVolume(leftVolume / 5, rightVolume / 5);
    wavePlay.start();
  }
 /** Sets the microphone mute state. */
 private void setMicrophoneMute(boolean on) {
   boolean wasMuted = audioManager.isMicrophoneMute();
   if (wasMuted == on) {
     return;
   }
   audioManager.setMicrophoneMute(on);
 }
示例#30
0
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setContentView(R.layout.activity_camera);

    setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);

    mContext = CameraActivity.this;

    mUsersSQL = "select a.[CORPNO], a.[OPERNO], a.[OPERPASS] from b_opera a;";
    mSearchUsersSQL = "select count(*) from b_opera a where a.[CORPNO] = ? and a.[OPERNO] = ?;";
    mInsertOperaSQL = "INSERT INTO B_OPERA (CORPNO, OPERNO, OPERPASS) VALUES(?, ?, ?, ?, ?);";
    mInsertDownInfoSQL =
        "INSERT INTO B_LOGININFO (CORPNO, PROJDESC, DOWNURL, UPLOADURL, DBFILENAME, DOWNTIME) VALUES(?, ?, ?, ?, ?, ?);";
    mDownLoadInfoSQL =
        "select a.[CORPNO], a.[PROJDESC], a.[DOWNURL], a.[UPLOADURL], a.[DBFILENAME] from b_logininfo a;";
    autoFocusHandler = new Handler();
    mCamera = getCameraInstance();

    /* Instance barcode scanner */
    scanner = new ImageScanner();
    scanner.setConfig(0, Config.X_DENSITY, 3);
    scanner.setConfig(0, Config.Y_DENSITY, 3);

    Log.i(TAG, "CameraActivity onCreate()");
    mPreview = new CameraPreview(this, mCamera, previewCb, autoFocusCB);
    FrameLayout preview = (FrameLayout) findViewById(R.id.cameraPreview);
    preview.addView(mPreview);

    mCamera.setPreviewCallback(previewCb);
    mCamera.startPreview();
    previewing = true;
    mCamera.autoFocus(autoFocusCB);

    // 初始化声音和震动
    AudioManager audioService = (AudioManager) getSystemService(AUDIO_SERVICE);
    // 如果手机是震动模式就震动
    if (audioService.getRingerMode() != AudioManager.RINGER_MODE_NORMAL) {
      playBeep = false;
    }
    // 初始化声音
    initBeepSound();
    initLoginDataBase();
    // MyApp.showToast(CameraActivity.this, "hello");

    Button mButtonBack = (Button) findViewById(R.id.button_back);

    /*返回按钮*/
    mButtonBack.setOnClickListener(
        new View.OnClickListener() {

          @Override
          public void onClick(View v) {
            Intent intent = new Intent();
            intent.putExtra("downloadfile", "");
            setResult(RESULT_OK, intent);
            finish();
          }
        });
  }