List of usage examples for android.content Context AUDIO_SERVICE
String AUDIO_SERVICE
To view the source code for android.content Context AUDIO_SERVICE.
Click Source Link
From source file:com.example.android.miwok.activity.NumbersActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.word_list);/*from w w w.ja v a2 s . c om*/ //Create and setup the {@link AudioManager} to request audio focus mAudioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE); // Create a list of words //made the arraylist final so that it could be accessed inside the onItemClick method. final ArrayList<Word> words = new ArrayList<Word>(); words.add(new Word("one", "lutti", R.drawable.number_one, R.raw.number_one)); words.add(new Word("two", "otiiko", R.drawable.number_two, R.raw.number_two)); words.add(new Word("three", "tolookosu", R.drawable.number_three, R.raw.number_three)); words.add(new Word("four", "oyyisa", R.drawable.number_four, R.raw.number_four)); words.add(new Word("five", "massokka", R.drawable.number_five, R.raw.number_five)); words.add(new Word("six", "temmokka", R.drawable.number_six, R.raw.number_six)); words.add(new Word("seven", "kenekaku", R.drawable.number_seven, R.raw.number_seven)); words.add(new Word("eight", "kawinta", R.drawable.number_eight, R.raw.number_eight)); words.add(new Word("nine", "woe", R.drawable.number_nine, R.raw.number_nine)); words.add(new Word("ten", "naaacha", R.drawable.number_ten, R.raw.number_ten)); // Create an {@link WordAdapter}, whose data source is a list of {@link Word}s. The // adapter knows how to create list items for each item in the list. WordAdapter adapter = new WordAdapter(this, words); // Find the {@link ListView} object in the view hierarchy of the {@link Activity}. // There should be a {@link ListView} with the view ID called list, which is declared in the // word_list.xml layout file. ListView listView = (ListView) findViewById(R.id.list); //listView.setBackgroundColor(R.color.category_numbers); listView.setBackgroundColor(Color.parseColor("#FD8E09")); // Make the {@link ListView} use the {@link WordAdapter} we created above, so that the // {@link ListView} will display list items for each {@link Word} in the list. listView.setAdapter(adapter); //plays the audio for number one when any item in the list is clicked click listView.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { //release current resources being used for media player if it currently exists //because we are about to play a different sound file. releaseMediaPlayer(); //get the word located in the list that is at same position as the item clicked in the list Word currentWord = words.get(position); // Request audio focus for playback int result = mAudioManager.requestAudioFocus(mAudioFocusChangeListener, // Use the music stream. AudioManager.STREAM_MUSIC, // Request temporary focus. AudioManager.AUDIOFOCUS_GAIN_TRANSIENT); if (result == AudioManager.AUDIOFOCUS_REQUEST_GRANTED) { //create the medial player with the audio file that is stored in the list for that word. mMediaPlayer = MediaPlayer.create(getApplicationContext(), currentWord.getmMiwokAudio()); //play the file mMediaPlayer.start(); //listener to stop and release the media player and resources being used // once the sounds has finished playing mMediaPlayer.setOnCompletionListener(mCompletionListener); } } }); }
From source file:com.pixate.freestyle.fragment.ButtonsFragment.java
/** Set the volumn controling to seek bar */ private void setSeekBar(SeekBar seek) { AudioManager audioManager = (AudioManager) getActivity().getSystemService(Context.AUDIO_SERVICE); seek.setMax(audioManager.getStreamMaxVolume(AudioManager.STREAM_RING)); seek.setProgress(m_nAlarmVolum);/*from w w w. j a v a2 s . c o m*/ seek.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() { @Override public void onStopTrackingTouch(SeekBar arg0) { } @Override public void onStartTrackingTouch(SeekBar arg0) { } @Override public void onProgressChanged(SeekBar seekBar, int progress, boolean arg2) { m_nAlarmVolum = progress; AudioManager audioManager = (AudioManager) getActivity().getSystemService(Context.AUDIO_SERVICE); audioManager.setStreamVolume(AudioManager.STREAM_RING, m_nAlarmVolum, AudioManager.FLAG_ALLOW_RINGER_MODES | AudioManager.FLAG_PLAY_SOUND); } }); }
From source file:com.appsaur.tarucassist.AutomuteAlarmReceiver.java
@Override public void onReceive(Context context, Intent intent) { int mReceivedID = Integer.parseInt(intent.getStringExtra(BaseActivity.EXTRA_REMINDER_ID)); // Get notification title from Reminder Database ScheduleAutomuteDataSource scheduleAutomuteDataSource = new ScheduleAutomuteDataSource(context); scheduleAutomuteDataSource.open();/*from ww w. j av a 2s. c o m*/ ScheduleAutomute scheduleAutomute = scheduleAutomuteDataSource.getScheduleAutomute(mReceivedID); mCalendar = Calendar.getInstance(); myAudioManager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE); if (scheduleAutomute.getAutomuteMode().equals("Vibrate")) { myAudioManager.setRingerMode(AudioManager.RINGER_MODE_VIBRATE); } else if (scheduleAutomute.getAutomuteMode().equals("Silent")) { myAudioManager.setRingerMode(AudioManager.RINGER_MODE_SILENT); } else if (scheduleAutomute.getAutomuteMode().equals("Normal")) myAudioManager.setRingerMode(AudioManager.RINGER_MODE_NORMAL); }
From source file:org.y20k.transistor.PlayerService.java
@Override public void onCreate() { super.onCreate(); // set up variables mAudioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE); mMediaPlayer = null;//from w w w. ja v a 2 s . co m // Listen for headphone unplug IntentFilter headphoneUnplugIntentFilter = new IntentFilter(AudioManager.ACTION_AUDIO_BECOMING_NOISY); mHeadphoneUnplugReceiver = new HeadphoneUnplugReceiver(); registerReceiver(mHeadphoneUnplugReceiver, headphoneUnplugIntentFilter); // TODO Listen for headphone button // Use MediaSession }
From source file:com.prey.actions.picture.PictureUtil.java
private static byte[] getPicture(Context ctx, String focus) { AudioManager mgr = null;/*from w ww .j av a 2s. co m*/ SimpleCameraActivity.dataImagen = null; int streamType = AudioManager.STREAM_SYSTEM; SimpleCameraActivity.activity = null; Intent intent = new Intent(ctx, SimpleCameraActivity.class); intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); intent.putExtra("focus", focus); ctx.startActivity(intent); int i = 0; mgr = (AudioManager) ctx.getSystemService(Context.AUDIO_SERVICE); mgr.setStreamSolo(streamType, true); mgr.setRingerMode(AudioManager.RINGER_MODE_SILENT); mgr.setStreamMute(streamType, true); while (SimpleCameraActivity.activity == null && i < 10) { try { Thread.sleep(1000); } catch (InterruptedException e) { } i++; } if (SimpleCameraActivity.activity != null) { SimpleCameraActivity.activity.takePicture(ctx, focus); } try { Thread.sleep(4000); } catch (InterruptedException e) { } mgr.setStreamSolo(streamType, false); mgr.setRingerMode(AudioManager.RINGER_MODE_NORMAL); mgr.setStreamMute(streamType, false); try { i = 0; while (SimpleCameraActivity.activity != null && SimpleCameraActivity.dataImagen == null && i < 5) { Thread.sleep(2000); i++; } } catch (InterruptedException e) { PreyLogger.i("Error:" + e.getMessage()); } byte[] out = null; if (SimpleCameraActivity.activity != null) { out = SimpleCameraActivity.dataImagen; SimpleCameraActivity.activity.finish(); SimpleCameraActivity.activity = null; SimpleCameraActivity.dataImagen = null; } return out; }
From source file:com.sublimis.urgentcallfilter.Magic.java
public Magic(Context context, String number, boolean isRingStart) { if (context != null) { mContext = context;// w w w . jav a 2s . co m mAudioManager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE); mIsRinging = isRingStart; mNumber = number; if (mAudioManager != null) { mRingerModeOriginal = mAudioManager.getRingerMode(); mVolumeOriginal = mAudioManager.getStreamVolume(AudioManager.STREAM_RING); mVolumeMax = mAudioManager.getStreamMaxVolume(AudioManager.STREAM_RING); } MyPreference.setContext(context); } }
From source file:net.hyx.app.volumenotification.factory.NotificationFactory.java
private NotificationFactory(Context context) { this.context = context; manager = (NotificationManager) this.context.getSystemService(Context.NOTIFICATION_SERVICE); audio = (AudioManager) this.context.getSystemService(Context.AUDIO_SERVICE); settings = new SettingsModel(this.context); model = new VolumeControlModel(this.context); items = model.getList();//w ww.j a va 2s . co m _package = this.context.getPackageName(); }
From source file:com.shinymayhem.radiopresets.FragmentPlayer.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { if (LOCAL_LOGV) log("onCreateView()", "v"); //inflate view from layout View view = inflater.inflate(R.layout.player_fragment, container, false); AudioManager audio = (AudioManager) this.getActivity().getSystemService(Context.AUDIO_SERVICE); SeekBar volumeSlider = (SeekBar) view.findViewById(R.id.volume_slider); //slider max = volume stream max volumeSlider.setMax(audio.getStreamMaxVolume(AudioManager.STREAM_MUSIC)); //detect slider updates volumeSlider.setOnSeekBarChangeListener(new OnSeekBarChangeListener() { //update volume as slider is moved @Override//ww w .jav a 2 s .c om public void onProgressChanged(SeekBar slider, int progress, boolean fromUser) { if (LOCAL_LOGV) log("onProgressChanged(): " + String.valueOf(progress), "v"); if (fromUser) //responding to touch slide event { mListener.setVolume(progress); } else //progress probably changed as a result of volume changing { } } @Override public void onStartTrackingTouch(SeekBar slider) { } @Override public void onStopTrackingTouch(SeekBar slider) { } }); return view; }
From source file:jhe.lin.boo.profile.PagerActivity.java
public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main);//w w w .j ava 2 s. co m WH.getDisplayMetrics(this); audioManager = (AudioManager) this.getSystemService(Context.AUDIO_SERVICE); pager_bar = (LinearLayout) findViewById(R.id.pager_bar); LayoutParams ll = (LayoutParams) pager_bar.getLayoutParams(); ll.topMargin = WH.getHeightPercent(70); pager_bar.setLayoutParams(ll); title = (TextView) findViewById(R.id.title); ll = (LayoutParams) title.getLayoutParams(); ll.topMargin = WH.getHeightPercent(10); title.setLayoutParams(ll); pager = (ViewPager) findViewById(R.id.pager); title.setTypeface(Typeface.createFromAsset(getAssets(), "fonts/w1.otf")); initPages_bar(); pager.setPageTransformer(true, new ZoomOutPageTransformer()); PagerAdapter adapter = new MyPagerAdapter(); pager.setAdapter(adapter); pager.setCurrentItem(firstPage); pager.setOnPageChangeListener(new OnPageChangeListener() { @Override public void onPageScrollStateChanged(int arg0) { // TODO Auto-generated method stub for (int i = 0; i < item.length; i++) { CircleView cv = (CircleView) pager_bar.getChildAt(i); cv.setColor(Color.parseColor(DEFAULT)); } CircleView cv = (CircleView) pager_bar.getChildAt(pager.getCurrentItem()); cv.setColor(Color.parseColor(SELECTED)); } @Override public void onPageScrolled(int arg0, float arg1, int arg2) { // TODO Auto-generated method stub } @Override public void onPageSelected(int arg0) { // TODO Auto-generated method stub } }); //Necessary or the pager will only have one extra page to show // make this at least however many pages you can see pager.setOffscreenPageLimit(adapter.getCount()); //A little space between pages pager.setPageMargin(15); //If hardware acceleration is enabled, you should also remove // clipping on the pager for its children. pager.setClipChildren(false); }
From source file:cc.psdev.heywifi.MainService.java
@Override public int onStartCommand(Intent intent, int flags, int startId) { Log.i("onStartCommand", "called"); wm = (WifiManager) getSystemService(Context.WIFI_SERVICE); cm = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE); ni = cm.getNetworkInfo(ConnectivityManager.TYPE_WIFI); dm = new DBManager(getApplicationContext(), "data", null, DATABASE_VERSION); audm = (AudioManager) getSystemService(Context.AUDIO_SERVICE); actm = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE); nm = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); pref = new SharedPrefSettings(this); Thread thread = new Thread(this); thread.start();// w w w .j av a 2 s . com return START_STICKY; }