Example usage for android.media AudioManager getRingerMode

List of usage examples for android.media AudioManager getRingerMode

Introduction

In this page you can find the example usage for android.media AudioManager getRingerMode.

Prototype

public int getRingerMode() 

Source Link

Document

Returns the current ringtone mode.

Usage

From source file:net.globide.coloring_book.MainActivity.java

/**
 * private RelativeLayout mRlMainRight; private RelativeLayout mRlMainLeft;
 * Implements onCreate()./* ww w.jav a  2  s.  c  om*/
 */
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    // Set the activity to full screen mode.
    requestWindowFeature(Window.FEATURE_NO_TITLE);
    getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
            WindowManager.LayoutParams.FLAG_FULLSCREEN);

    // Add default content.
    setContentView(R.layout.activity_main);

    // Determine whether or not the current device is a tablet.
    MainActivity.sIsTablet = getResources().getBoolean(R.bool.isTablet);
    MainActivity.sIsSmall = getResources().getBoolean(R.bool.isSmall);
    MainActivity.sIsNormal = getResources().getBoolean(R.bool.isNormal);
    MainActivity.sIsLarge = getResources().getBoolean(R.bool.isLarge);
    MainActivity.sIsExtraLarge = getResources().getBoolean(R.bool.isExtraLarge);

    // Get stored preferences, if any.
    mSharedPreferences = getSharedPreferences(sFilename, 0);
    // Setup the editor in this function, so it can be used anywhere else if
    // needed.
    mEditor = mSharedPreferences.edit();

    // If this activity continues playing the music, start the media player
    // if the phone is not muted
    AudioManager audio = (AudioManager) getSystemService(Context.AUDIO_SERVICE);

    // This should only run once at the start of the application.
    switch (audio.getRingerMode()) {
    case AudioManager.RINGER_MODE_SILENT:
        if (!MusicManager.sIsManualSound) {
            // Set the preferences to turn music off.
            mEditor.putBoolean("tbSettingsMusicIsChecked", false);
            mEditor.commit();
        }
        break;
    }

    // This should only run once at the start of the application.
    if (!MusicManager.sIsManualSound) {
        // Set the preferences as early as possible in MusicManager.
        MusicManager.setPreferences(mSharedPreferences);

        // Update actual status
        MusicManager.updateVolume();
        MusicManager.updateStatusFromPrefs(this);

        // This method can no longer be invoked to turn off the
        // sound once the user has manually turned sound on.
        MusicManager.sIsManualSound = true;
    }

    // Store the preference values in local variables.
    boolean tbSettingsMusicIsChecked = mSharedPreferences.getBoolean("tbSettingsMusicIsChecked", false);

    // Set whether music is on or not in the Music Manager
    if (tbSettingsMusicIsChecked) {
        MusicManager.start(this, MusicManager.MUSIC_A);
    }

    // Attach views to their corresponding resource ids.
    mIbPagerLeft = (ImageButton) findViewById(R.id.ibPagerLeft);
    mIbPagerRight = (ImageButton) findViewById(R.id.ibPagerRight);
    mIbMainHelp = (ImageButton) findViewById(R.id.ibMainHelp);
    mIbMainSettings = (ImageButton) findViewById(R.id.ibMainSettings);
    mRlMainLeftTop = (RelativeLayout) findViewById(R.id.rlMainLeftTop);
    mRlMainRightTop = (RelativeLayout) findViewById(R.id.rlMainRightTop);

    /*
     * This screen needs to be dynamically positioned to fit each screen
     * size fluidly.
     */

    // Get the screen metrics.
    DisplayMetrics dm = new DisplayMetrics();
    getWindowManager().getDefaultDisplay().getMetrics(dm);
    int screenHeight = dm.heightPixels;

    // Determine the floor section size
    Drawable image = this.getResources().getDrawable(R.drawable.floor);
    // Store the height locally
    int floorHeight = image.getIntrinsicHeight();

    // Determine the title section size

    // Get the top spacing (THIS IS ALSO DEFINED EXACTLY AS IT IS HERE IN
    // EACH XML FILE.
    int topSpacing = 0;

    if (MainActivity.sIsTablet) {
        if (MainActivity.sIsSmall) {
            topSpacing = 18;
        } else if (MainActivity.sIsNormal) {
            topSpacing = 24;
        } else if (MainActivity.sIsLarge) {
            topSpacing = 27;
        } else if (MainActivity.sIsExtraLarge) {
            topSpacing = 30;
        }
    } else {
        topSpacing = 12;
    }

    Drawable imageTitle = this.getResources().getDrawable(R.drawable.main_title);
    // Store the height locally
    int titleHeight = imageTitle.getIntrinsicHeight() + topSpacing;

    // Resize the layout views to be centered in their proper positions
    // based on the sizes calculated.
    ViewGroup.LayoutParams paramsLeftTop = mRlMainLeftTop.getLayoutParams();
    ViewGroup.LayoutParams paramsRightTop = mRlMainRightTop.getLayoutParams();
    int resultHeight = (screenHeight - floorHeight) - titleHeight;
    paramsLeftTop.height = resultHeight;
    paramsRightTop.height = resultHeight;
    mRlMainLeftTop.setLayoutParams(paramsLeftTop);
    mRlMainRightTop.setLayoutParams(paramsRightTop);

    // TODO: See if there are better methods of retrieving the floor height
    // value from the xml layout.

    // Set listeners to objects that can receive user input.
    mIbPagerRight.setOnClickListener(this);
    mIbPagerLeft.setOnClickListener(this);
    mIbMainHelp.setOnClickListener(this);
    mIbMainSettings.setOnClickListener(this);

    // Database check!

    // Create our database access object.
    mDbNodeHelper = new NodeDatabase(this);

    // Call the create method right just in case the user has never run the
    // app before. If a database does not exist, the prepopulated one will
    // be copied from the assets folder. Else, a connection is established.
    mDbNodeHelper.createDatabase();

    // Query the database for all purchased categories.

    // Set a conditional buffer. Internally, the orderby is set to _id ASC
    // (NodeDatabase.java).
    mDbNodeHelper.setConditions("isAvailable", "1");
    // Execute the query.
    mCategoryData = mDbNodeHelper.getCategoryListData();
    // Store the number of categories available.
    mCategoryLength = mCategoryData.length + 1;
    // Flush the buffer.
    mDbNodeHelper.flushQuery();

    // This activity no longer needs the connection, so close it.
    mDbNodeHelper.close();

    // Initialize the pager
    this.initializePaging();
}

From source file:net.globide.coloring_book_08.MainActivity.java

/**
 * private RelativeLayout mRlMainRight; private RelativeLayout mRlMainLeft;
 * Implements onCreate()./*  w  w  w  .  j ava2  s .c om*/
 */
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    // Set the activity to full screen mode.
    requestWindowFeature(Window.FEATURE_NO_TITLE);
    getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
            WindowManager.LayoutParams.FLAG_FULLSCREEN);

    // Add default content.
    setContentView(R.layout.activity_main);

    // Determine whether or not the current device is a tablet.
    MainActivity.sIsTablet = getResources().getBoolean(R.bool.isTablet);
    MainActivity.sIsSmall = getResources().getBoolean(R.bool.isSmall);
    MainActivity.sIsNormal = getResources().getBoolean(R.bool.isNormal);
    MainActivity.sIsLarge = getResources().getBoolean(R.bool.isLarge);
    MainActivity.sIsExtraLarge = getResources().getBoolean(R.bool.isExtraLarge);

    // Get stored preferences, if any.
    mSharedPreferences = getSharedPreferences(sFilename, 0);
    // Setup the editor in this function, so it can be used anywhere else if
    // needed.
    mEditor = mSharedPreferences.edit();

    // If this activity continues playing the music, start the media player
    // if the phone is not muted
    AudioManager audio = (AudioManager) getSystemService(Context.AUDIO_SERVICE);

    // This should only run once at the start of the application.
    switch (audio.getRingerMode()) {
    case AudioManager.RINGER_MODE_SILENT:
        if (!MusicManager.sIsManualSound) {
            // Set the preferences to turn music off.
            mEditor.putBoolean("tbSettingsMusicIsChecked", false);
            mEditor.commit();
        }
        break;
    }

    // This should only run once at the start of the application.
    if (!MusicManager.sIsManualSound) {
        // Set the preferences as early as possible in MusicManager.
        MusicManager.setPreferences(mSharedPreferences);

        // Update actual status
        MusicManager.updateVolume();
        MusicManager.updateStatusFromPrefs(this);

        // This method can no longer be invoked to turn off the
        // sound once the user has manually turned sound on.
        MusicManager.sIsManualSound = true;
    }

    // Store the preference values in local variables.
    boolean tbSettingsMusicIsChecked = mSharedPreferences.getBoolean("tbSettingsMusicIsChecked", false);

    // Set whether music is on or not in the Music Manager
    if (tbSettingsMusicIsChecked) {
        MusicManager.start(this, MusicManager.MUSIC_A);
    }

    // Attach views to their corresponding resource ids.
    mIbPagerLeft = (ImageButton) findViewById(R.id.ibPagerLeft);
    mIbPagerRight = (ImageButton) findViewById(R.id.ibPagerRight);
    mIbMainHelp = (ImageButton) findViewById(R.id.ibMainHelp);
    mIbMainSettings = (ImageButton) findViewById(R.id.ibMainSettings);
    mRlMainLeftTop = (RelativeLayout) findViewById(R.id.rlMainLeftTop);
    mRlMainRightTop = (RelativeLayout) findViewById(R.id.rlMainRightTop);

    /*
     * This screen needs to be dynamically positioned to fit each screen
     * size fluidly.
     */

    // Get the screen metrics.
    DisplayMetrics dm = new DisplayMetrics();
    getWindowManager().getDefaultDisplay().getMetrics(dm);
    int screenHeight = dm.heightPixels;

    // Determine the floor section size
    Drawable image = this.getResources().getDrawable(R.drawable.floor);
    // Store the height locally
    int floorHeight = image.getIntrinsicHeight();

    // Determine the title section size

    // Get the top spacing (THIS IS ALSO DEFINED EXACTLY AS IT IS HERE IN
    // EACH XML FILE.
    int topSpacing = 0;

    if (MainActivity.sIsTablet) {
        if (MainActivity.sIsSmall) {
            topSpacing = 18;
        } else if (MainActivity.sIsNormal) {
            topSpacing = 24;
        } else if (MainActivity.sIsLarge) {
            topSpacing = 27;
        } else if (MainActivity.sIsExtraLarge) {
            topSpacing = 30;
        }
    } else {
        topSpacing = 12;
    }

    Drawable imageTitle = this.getResources().getDrawable(R.drawable.main_title);
    // Store the height locally
    int titleHeight = imageTitle.getIntrinsicHeight() + topSpacing;

    // Resize the layout views to be centered in their proper positions
    // based on the sizes calculated.
    ViewGroup.LayoutParams paramsLeftTop = mRlMainLeftTop.getLayoutParams();
    ViewGroup.LayoutParams paramsRightTop = mRlMainRightTop.getLayoutParams();
    int resultHeight = (screenHeight - floorHeight) - titleHeight;
    paramsLeftTop.height = resultHeight;
    paramsRightTop.height = resultHeight;
    mRlMainLeftTop.setLayoutParams(paramsLeftTop);
    mRlMainRightTop.setLayoutParams(paramsRightTop);

    // TODO: See if there are better methods of retrieving the floor height
    // value from the xml layout.

    // Set listeners to objects that can receive user input.
    mIbPagerRight.setOnClickListener(this);
    mIbPagerLeft.setOnClickListener(this);
    mIbMainHelp.setOnClickListener(this);
    mIbMainSettings.setOnClickListener(this);

    // Database check!

    // Create our database access object.
    mDbNodeHelper = new NodeDatabase(this);

    // Call the create method right just in case the user has never run the
    // app before. If a database does not exist, the prepopulated one will
    // be copied from the assets folder. Else, a connection is established.
    mDbNodeHelper.createDatabase();

    // Query the database for all purchased categories.

    // Set a conditional buffer. Internally, the orderby is set to _id ASC
    // (NodeDatabase.java).
    mDbNodeHelper.setConditions("isAvailable", "1");
    // Execute the query.
    mCategoryData = mDbNodeHelper.getCategoryListData();
    // Store the number of categories available.
    mCategoryLength = mCategoryData.length;
    // Flush the buffer.
    mDbNodeHelper.flushQuery();

    // This activity no longer needs the connection, so close it.
    mDbNodeHelper.close();

    // Initialize the pager
    this.initializePaging();
}

From source file:de.spiritcroc.modular_remote.MainActivity.java

@Override
protected void onResume() {
    super.onResume();
    appWidgetHost.startListening();//  w w w  . java  2 s  . c  o  m

    tcpConnectionManager.refreshConnections();

    viewPager.addOnPageChangeListener(this);
    onPageSelected(viewPager.getCurrentItem());

    int tmp = Util.getPreferenceInt(sharedPreferences, Preferences.OFFSCREEN_PAGE_LIMIT, 2);
    if (tmp < 0) {
        neverDestroyPages = true;
        viewPager.setOffscreenPageLimit(pages.size());
    } else {
        neverDestroyPages = false;
        viewPager.setOffscreenPageLimit(tmp);
    }

    fullscreen = sharedPreferences.getBoolean(Preferences.FULLSCREEN, false);
    hideNavigationBar = sharedPreferences.getBoolean(Preferences.HIDE_NAVIGATION_BAR, false);
    hideActionBar = sharedPreferences.getBoolean(Preferences.HIDE_ACTION_BAR, false);

    int pagerTabStripVisibility = sharedPreferences.getBoolean(Preferences.HIDE_PAGER_TAB_STRIP, false)
            ? View.GONE
            : View.VISIBLE;
    if (pagerTabStrip.getVisibility() != pagerTabStripVisibility) {
        pagerTabStrip.setVisibility(pagerTabStripVisibility);
    }

    String ringerMode = sharedPreferences.getString(Preferences.CHANGE_RINGER_MODE,
            getString(R.string.pref_ringer_mode_keep_value));
    AudioManager audioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
    previousRingerMode = audioManager.getRingerMode();
    if (getString(R.string.pref_ringer_mode_mute_value).equals(ringerMode)) {
        audioManager.setRingerMode(AudioManager.RINGER_MODE_SILENT);
        changedRingerMode = true;
    } else if (getString(R.string.pref_ringer_mode_vibrate_value).equals(ringerMode)) {
        audioManager.setRingerMode(AudioManager.RINGER_MODE_VIBRATE);
        changedRingerMode = true;
    } else if (getString(R.string.pref_ringer_mode_vibrate_if_not_muted_value).equals(ringerMode)
            && previousRingerMode != AudioManager.RINGER_MODE_SILENT) {
        audioManager.setRingerMode(AudioManager.RINGER_MODE_VIBRATE);
        changedRingerMode = true;
    }

    if (forceOrientation == FORCE_ORIENTATION_PORTRAIT) {
        setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
    } else if (forceOrientation == FORCE_ORIENTATION_LANDSCAPE) {
        setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
    } else {
        String orientation = sharedPreferences.getString(Preferences.ORIENTATION,
                Preferences.ORIENTATION_SHARE_LAYOUT);
        if (Preferences.ORIENTATION_PORTRAIT_ONLY.equals(orientation)) {
            setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
        } else if (Preferences.ORIENTATION_LANDSCAPE_ONLY.equals(orientation)) {
            setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
        } else {
            setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_USER);
        }
    }

    resizeContent();

    setLockedModeVisibilities();
}

From source file:com.z3r0byte.magistify.Services.BackgroundService.java

private void autoSilent() {
    Appointment[] appointments = calendarDB.getSilentAppointments(getMargin());
    if (doSilent(appointments)) {
        setSilenced(true);//from  w  ww.  j  av a  2  s  . com
        AudioManager audiomanager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);
        if (audiomanager == null)
            return;
        if (!isSilencedByApp())
            configUtil.setInteger("previous_silent_state", audiomanager.getRingerMode());
        if (audiomanager.getRingerMode() != AudioManager.RINGER_MODE_SILENT) {
            audiomanager.setRingerMode(AudioManager.RINGER_MODE_SILENT);
        }
    } else {
        if (isSilencedByApp()) {
            AudioManager audiomanager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);
            if (audiomanager == null)
                return;
            if (configUtil.getBoolean("reverse_silent_state")) {
                audiomanager.setRingerMode(configUtil.getInteger("previous_silent_state"));
            } else {
                audiomanager.setRingerMode(AudioManager.RINGER_MODE_NORMAL);
            }
            setSilenced(false);
        }
    }
}

From source file:fr.inria.ucn.collectors.SysStateCollector.java

@SuppressWarnings("deprecation")
private JSONObject getAudioState(Context c) throws JSONException {
    AudioManager am = (AudioManager) c.getSystemService(Context.AUDIO_SERVICE);

    JSONObject data = new JSONObject();

    data.put("is_bluetooth_a2dp_on", am.isBluetoothA2dpOn());
    data.put("is_microphone_mute", am.isMicrophoneMute());
    data.put("is_music_active", am.isMusicActive());
    data.put("is_speaker_phone_on", am.isSpeakerphoneOn());
    data.put("is_wired_headset_on", am.isWiredHeadsetOn());

    switch (am.getMode()) {
    case AudioManager.MODE_IN_CALL:
        data.put("mode", "in_call");
        break;/*from   w  ww  .  ja  v a  2 s. c  o  m*/
    case AudioManager.MODE_IN_COMMUNICATION:
        data.put("mode", "in_comm");
        break;
    case AudioManager.MODE_NORMAL:
        data.put("mode", "normal");
        break;
    case AudioManager.MODE_RINGTONE:
        data.put("mode", "ringtone");
        break;
    case AudioManager.MODE_INVALID:
    default:
        data.put("mode", "invalid");
        break;
    }

    switch (am.getRingerMode()) {
    case AudioManager.RINGER_MODE_VIBRATE:
        data.put("ringer_mode", "vibrate");
        break;
    case AudioManager.RINGER_MODE_SILENT:
        data.put("ringer_mode", "silent");
        break;
    case AudioManager.RINGER_MODE_NORMAL:
        data.put("ringer_mode", "normal");
        break;
    default:
        data.put("ringer_mode", "invalid");
        break;
    }
    return data;
}

From source file:org.cryptsecure.Utility.java

/**
 * Check if is phone completely muted (even no vibration).
 * //from w  ww. j  av a  2s.  c  o m
 * @param context
 *            the context
 * @return true, if is phone muted
 */
public static boolean isPhoneMuted(Context context) {
    AudioManager audio = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);
    switch (audio.getRingerMode()) {
    case AudioManager.RINGER_MODE_NORMAL:
        return false;
    case AudioManager.RINGER_MODE_SILENT:
        return true;
    case AudioManager.RINGER_MODE_VIBRATE:
        return false;
    }
    return false;
}

From source file:org.cryptsecure.Utility.java

/**
 * Check if is phone muted but vibration may still be on.
 * //from   ww w .  j a  v a 2 s.co m
 * @param context
 *            the context
 * @return true, if is phone muted with vibration
 */
public static boolean isPhoneMutedOrVibration(Context context) {
    AudioManager audio = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);
    switch (audio.getRingerMode()) {
    case AudioManager.RINGER_MODE_NORMAL:
        return false;
    case AudioManager.RINGER_MODE_SILENT:
        return false;
    case AudioManager.RINGER_MODE_VIBRATE:
        return true;
    }
    return false;
}

From source file:com.android.launcher3.Utilities.java

public static void modeSilent(Activity activity) {
    checkPermissionForRingtone(activity);
    AudioManager mobilemode = (AudioManager) activity.getSystemService(Context.AUDIO_SERVICE);
    if (isModeSilent) {
        mobilemode.setRingerMode(mobileModeSilentPrevious);
        isModeSilent = false;/*from www  . jav  a  2 s.c  o m*/
    } else {
        isModeSilent = true;
        mobileModeSilentPrevious = mobilemode.getRingerMode();
        mobilemode.setRingerMode(AudioManager.RINGER_MODE_SILENT);
    }
}

From source file:com.android.launcher3.Utilities.java

public static void modeNormal(Activity activity) {
    checkPermissionForRingtone(activity);
    AudioManager mobilemode = (AudioManager) activity.getSystemService(Context.AUDIO_SERVICE);
    if (isModeNormal) {
        mobilemode.setRingerMode(mobileModeNormalPrevious);
        isModeNormal = false;//ww  w.j  a v  a 2s . co  m
    } else {
        isModeNormal = true;
        mobileModeNormalPrevious = mobilemode.getRingerMode();
        mobilemode.setRingerMode(AudioManager.RINGER_MODE_NORMAL);
    }
}

From source file:com.android.launcher3.Utilities.java

public static void modeVibrate(Activity activity) {
    checkPermissionForRingtone(activity);
    AudioManager mobilemode = (AudioManager) activity.getSystemService(Context.AUDIO_SERVICE);
    if (isModeVibrate) {
        mobilemode.setRingerMode(mobileModeVibratePrevious);
        isModeVibrate = false;//from  w  w w  .jav a2s  .c  o m
    } else {
        isModeVibrate = true;
        mobileModeVibratePrevious = mobilemode.getRingerMode();
        mobilemode.setRingerMode(AudioManager.RINGER_MODE_VIBRATE);
    }
}