Android Open Source - SoundScheduler Sound Manager






From Project

Back to project page SoundScheduler.

License

The source code is released under:

GNU General Public License

If you think the Android project SoundScheduler 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

/*
 * Sound Scheduler//from   w w  w. j a  v a  2  s  .  c o m
 * Copyright (C) 2013 Victor Kifer
 */

package com.victorkifer.SoundScheduler.managers;

import android.content.Context;
import android.content.Intent;
import android.media.AudioManager;
import android.os.Build;
import android.provider.Settings;

public class SoundManager {
    private Context context;
    private AudioManager audioManager;

    public SoundManager(Context context) {
         this.context = context.getApplicationContext();
         audioManager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);
    }

    public void setVibrateMode() {
        audioManager.setRingerMode(AudioManager.RINGER_MODE_VIBRATE);
    }

    public void setSilentMode() {
        audioManager.setRingerMode(AudioManager.RINGER_MODE_SILENT);
    }

    public void setNormalMode() {
        audioManager.setRingerMode(AudioManager.RINGER_MODE_NORMAL);
    }

    public boolean isVibrateModeEnabled() {
        return (audioManager.getRingerMode() == AudioManager.RINGER_MODE_VIBRATE);
    }

    public boolean isSilentModeEnabled() {
        return (audioManager.getRingerMode() == AudioManager.RINGER_MODE_SILENT);
    }

    public boolean isNormalModeEnabled() {
        return (audioManager.getRingerMode() == AudioManager.RINGER_MODE_NORMAL);
    }

    public void setAirplaneModeOn() {
        setAirplaceMode(1);
    }

    public void setAirplaneModeOff() {
        setAirplaceMode(0);
    }

    @SuppressWarnings("deprecation")
    public boolean isAirplaneModeOn() {
        if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN_MR1) {
            return Settings.System.getInt(context.getContentResolver(),
                    Settings.System.AIRPLANE_MODE_ON, 0) != 0;
        } else {
            return Settings.Global.getInt(context.getContentResolver(),
                    Settings.Global.AIRPLANE_MODE_ON, 0) != 0;
        }
    }

    @SuppressWarnings("deprecation")
    private void setAirplaceMode(int value) {
        if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN_MR1) {
            Settings.System.putInt(
                    context.getContentResolver(),
                    Settings.System.AIRPLANE_MODE_ON, value);
        } else {
            Settings.Global.putInt(
                    context.getContentResolver(),
                    Settings.Global.AIRPLANE_MODE_ON, value);
        }

        Intent intent = new Intent(Intent.ACTION_AIRPLANE_MODE_CHANGED);
        boolean enabled = value > 0;
        intent.putExtra("state", enabled);
        context.sendBroadcast(intent);
    }
}




Java Source Code List

com.victorkifer.SoundScheduler.AboutActivity.java
com.victorkifer.SoundScheduler.EditRuleActivity.java
com.victorkifer.SoundScheduler.MainActivity.java
com.victorkifer.SoundScheduler.adapters.RuleListAdapter.java
com.victorkifer.SoundScheduler.database.RulesDataSource.java
com.victorkifer.SoundScheduler.database.RulesDatabaseHelper.java
com.victorkifer.SoundScheduler.entities.Rule.java
com.victorkifer.SoundScheduler.listeners.RuleDeleteListener.java
com.victorkifer.SoundScheduler.listeners.RuleItemStateListener.java
com.victorkifer.SoundScheduler.managers.SoundManager.java
com.victorkifer.SoundScheduler.receivers.BootCompleteReceiver.java
com.victorkifer.SoundScheduler.receivers.TimeChangeReceiver.java