Android Open Source - DatePicker Sound






From Project

Back to project page DatePicker.

License

The source code is released under:

Apache License

If you think the Android project DatePicker listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package org.chenglei.widget.datepicker;
/*  ww w.  ja v a 2  s  .  c  om*/
import android.content.Context;
import android.media.AudioManager;
import android.media.SoundPool;

public class Sound {
  
  private SoundPool mSoundPool;
  private AudioManager mAudioManager;
  private float mCurrVolume;
  private Context mContext;
  private int mSoundId;
  
  public Sound(Context context) {
    mContext = context;
    mSoundPool = new SoundPool(1, AudioManager.STREAM_SYSTEM, 0);
    mAudioManager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);
  }
  
  public void playSoundEffect() {
    mCurrVolume = mAudioManager.getStreamVolume(AudioManager.STREAM_SYSTEM);
    if (mSoundId != 0) {
      mSoundPool.play(mSoundId, mCurrVolume, mCurrVolume, 0, 0, 1);
    } else {
      mAudioManager.playSoundEffect(AudioManager.FX_KEY_CLICK, mCurrVolume);
    }
  }
  
  public void setCustomSound(int resId) {
    mSoundId = mSoundPool.load(mContext, resId, 1);
  }

}




Java Source Code List

org.chenglei.widget.datepicker.DatePicker.java
org.chenglei.widget.datepicker.NumberPicker.java
org.chenglei.widget.datepicker.Sound.java
org.chenglei.widget.datepicker.Sample.MainActivity.java