Example usage for android.media AudioManager RINGER_MODE_SILENT

List of usage examples for android.media AudioManager RINGER_MODE_SILENT

Introduction

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

Prototype

int RINGER_MODE_SILENT

To view the source code for android.media AudioManager RINGER_MODE_SILENT.

Click Source Link

Document

Ringer mode that will be silent and will not vibrate.

Usage

From source file:com.whereismyfriend.GcmIntentService.java

private void sendNotification(String msg, String badge, String type) {
    mNotificationManager = (NotificationManager) this.getSystemService(Context.NOTIFICATION_SERVICE);

    int notification_id;
    PendingIntent contentIntent;//from  ww w  . j a  va 2 s .c o  m
    if (type.compareTo("s") == 0) {
        contentIntent = PendingIntent.getActivity(this, 0, new Intent(this, Solicitudes.class), 0);
        notification_id = 0;
    } else {
        contentIntent = PendingIntent.getActivity(this, 0, new Intent(this, Mapa.class), 0);
        notification_id = 1;
    }

    if (Integer.parseInt(badge) > 1) {
        if (type.compareTo("s") == 0)
            msg = getResources().getString(R.string.push_no_leidas_1) + " " + badge + " "
                    + getResources().getString(R.string.push_no_leidas_2);
        else
            msg = getResources().getString(R.string.push_no_leidas_1_acc) + " " + badge + " "
                    + getResources().getString(R.string.push_no_leidas_2_acc);
    }

    NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this)
            .setSmallIcon(R.drawable.ic_stat_gcm).setContentTitle(getResources().getString(R.string.app_name))
            .setStyle(new NotificationCompat.BigTextStyle().bigText(msg)).setContentText(msg)
            .setAutoCancel(true);

    AudioManager am = (AudioManager) getSystemService(Context.AUDIO_SERVICE);

    switch (am.getRingerMode()) {
    case AudioManager.RINGER_MODE_SILENT:
        mBuilder.setLights(Color.CYAN, 3000, 3000);
        break;
    case AudioManager.RINGER_MODE_VIBRATE:
        mBuilder.setVibrate(new long[] { 1000, 1000, 1000, 1000, 1000 });
        mBuilder.setLights(Color.CYAN, 3000, 3000);
        break;
    case AudioManager.RINGER_MODE_NORMAL:
        mBuilder.setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION));
        mBuilder.setLights(Color.CYAN, 3000, 3000);
        break;
    }

    mBuilder.setContentIntent(contentIntent);
    mNotificationManager.notify(notification_id, mBuilder.build());
}

From source file:com.ayaseya.padnotification.GcmIntentService.java

@Override
public void onCreate() {
    super.onCreate();

    ringerMode = false;/*  www.j  a  v  a  2 s.com*/
    silentMode = false;
    vibrateMode = false;

    isPlugged = false;

    sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this);

    checkbox_sound = sharedPreferences.getBoolean("checkbox_sound_key", true);
    checkbox_vibration = sharedPreferences.getBoolean("checkbox_vibration_key", false);

    Set<String> multiValues = sharedPreferences.getStringSet("list_preference", null);
    ArrayList<String> timeZone = new ArrayList<String>();

    if (multiValues != null) {

        timeZone.addAll(multiValues);
        Collections.sort(timeZone);
        for (int i = 0; i < timeZone.size(); i++) {
            //            Log.v(TAG, "TimeZone=" + timeZone.get(i));
        }

        Calendar calendar = Calendar.getInstance();
        int hour = calendar.get(Calendar.HOUR_OF_DAY);
        if (timeZone.indexOf(String.valueOf(hour)) == -1) {
            notificationPermission = false;
            Log.v(TAG, "?????????");
        } else {
            notificationPermission = true;
            Log.v(TAG, "??????");
        }
    }

    vibrator = (Vibrator) getSystemService(VIBRATOR_SERVICE);

    ringerModeStateChangeReceiver = new BroadcastReceiver() {

        @Override
        public void onReceive(Context context, Intent intent) {
            // ?
            if (intent.getAction().equals(AudioManager.RINGER_MODE_CHANGED_ACTION)) {
                if (intent.getIntExtra(AudioManager.EXTRA_RINGER_MODE, -1) == AudioManager.RINGER_MODE_NORMAL) {
                    // 
                    ringerMode = true;
                } else {
                    ringerMode = false;

                }

                if (intent.getIntExtra(AudioManager.EXTRA_RINGER_MODE,
                        -1) == AudioManager.RINGER_MODE_VIBRATE) {
                    // 
                    vibrateMode = true;

                } else {

                    vibrateMode = false;

                }

                if (intent.getIntExtra(AudioManager.EXTRA_RINGER_MODE, -1) == AudioManager.RINGER_MODE_SILENT) {
                    // 
                    silentMode = true;

                } else {

                    silentMode = false;

                }
            }
        }
    };

    plugStateChangeReceiver = new BroadcastReceiver() {

        @Override
        public void onReceive(Context context, Intent intent) {
            // ?
            if (intent.getIntExtra("state", 0) > 0) {
                isPlugged = true;
                //               Log.v(TAG, "IN");
            } else {
                isPlugged = false;
                //               Log.v(TAG, "OUT");
            }
        }
    };

    // Broadcast Receiver???
    registerReceiver(plugStateChangeReceiver, plugIntentFilter);
    registerReceiver(ringerModeStateChangeReceiver, ringerModeIntentFilter);
}

From source file:com.ayaseya.nolnotification.GcmIntentService.java

@Override
public void onCreate() {
    super.onCreate();

    ringerMode = false;//from   w w w.  j  a  va2  s .co  m
    silentMode = false;
    vibrateMode = false;

    isPlugged = false;

    sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this);

    checkbox_sound = sharedPreferences.getBoolean("checkbox_sound_key", true);
    checkbox_vibration = sharedPreferences.getBoolean("checkbox_vibration_key", false);

    Set<String> multiValues = sharedPreferences.getStringSet("list_preference", null);
    ArrayList<String> timeZone = new ArrayList<String>();

    if (multiValues != null) {

        timeZone.addAll(multiValues);
        Collections.sort(timeZone);
        for (int i = 0; i < timeZone.size(); i++) {
            //            Log.v(TAG, "TimeZone=" + timeZone.get(i));
        }

        Calendar calendar = Calendar.getInstance();
        int hour = calendar.get(Calendar.HOUR_OF_DAY);

        if (timeZone.indexOf(String.valueOf(hour)) == -1) {
            notificationPermission = false;
            //            Log.v(TAG, "?????????");
        } else {
            notificationPermission = true;
            //            Log.v(TAG, "??????");
        }
    }

    vibrator = (Vibrator) getSystemService(VIBRATOR_SERVICE);

    ringerModeStateChangeReceiver = new BroadcastReceiver() {

        @Override
        public void onReceive(Context context, Intent intent) {
            // ?
            if (intent.getAction().equals(AudioManager.RINGER_MODE_CHANGED_ACTION)) {
                if (intent.getIntExtra(AudioManager.EXTRA_RINGER_MODE, -1) == AudioManager.RINGER_MODE_NORMAL) {
                    // 
                    ringerMode = true;
                } else {
                    ringerMode = false;

                }

                if (intent.getIntExtra(AudioManager.EXTRA_RINGER_MODE,
                        -1) == AudioManager.RINGER_MODE_VIBRATE) {
                    // 
                    vibrateMode = true;

                } else {

                    vibrateMode = false;

                }

                if (intent.getIntExtra(AudioManager.EXTRA_RINGER_MODE, -1) == AudioManager.RINGER_MODE_SILENT) {
                    // 
                    silentMode = true;

                } else {

                    silentMode = false;

                }
            }
        }
    };

    plugStateChangeReceiver = new BroadcastReceiver() {

        @Override
        public void onReceive(Context context, Intent intent) {
            // ?
            if (intent.getIntExtra("state", 0) > 0) {
                isPlugged = true;
                //               Log.v(TAG, "IN");
            } else {
                isPlugged = false;
                //               Log.v(TAG, "OUT");
            }
        }
    };

    // Broadcast Receiver???
    registerReceiver(plugStateChangeReceiver, plugIntentFilter);
    registerReceiver(ringerModeStateChangeReceiver, ringerModeIntentFilter);
}

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

/**
 * private RelativeLayout mRlMainRight; private RelativeLayout mRlMainLeft;
 * Implements onCreate()./*from  ww  w  .  ja v  a 2s  .  c  o m*/
 */
@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 a  v a2 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:org.wso2.emm.agent.AlertActivity.java

/**
 * This method stops the device ring./*from   w ww .java  2s  .  c o  m*/
 */
private void stopRing() {
    if (defaultRingtone != null && defaultRingtone.isPlaying()) {
        defaultRingtone.stop();
    }
    audio.setStreamVolume(AudioManager.STREAM_RING, DEFAULT_VOLUME, DEFAULT_FLAG);
    audio.setRingerMode(AudioManager.RINGER_MODE_SILENT);
}

From source file:com.handmark.pulltorefresh.library.internal.LoadingLayout.java

public void refreshing() {
    if (hasPlayedSound) {
        hasPlayedSound = false;// ww w.  j a  v  a2  s  .c  o m
        boolean isMuted = false;

        switch (audioManager.getRingerMode()) {
        case AudioManager.RINGER_MODE_NORMAL:
            isMuted = false;
            break;
        case AudioManager.RINGER_MODE_SILENT:
            isMuted = true;
            break;
        case AudioManager.RINGER_MODE_VIBRATE:
            isMuted = true;
            break;
        }
        if (mPreferences.getBoolean(PREFERENCE_KEY_SOUND_NAVIGATION, true)) {
            if (isMuted != true) {
                if (mPlayer != null) {
                    if (mPlayer.isPlaying()) {
                        mPlayer.stop();
                    }
                    mPlayer.release();
                }
                mPlayer = MediaPlayer.create(mContext, R.raw.release);
                mPlayer.start();
            }
        }
    }
    mHeaderText.setText(Html.fromHtml(mRefreshingLabel));
    mHeaderArrow.setVisibility(View.INVISIBLE);
    mHeaderProgress.setVisibility(View.VISIBLE);
    mSubHeaderText.setVisibility(View.GONE);
}

From source file:com.kyakujin.android.autoeco.ui.EcoFragment.java

private void fillEco(Cursor c) {
    EcoDAO dao = new EcoDAO(mActivity);
    mModel = dao.readToEcoModelByCursor(c);

    // Description????

    // Wifi Desc//from   w ww.ja va2s .c o m
    if (mModel.getWifiEnabled()) {
        mWifiDesc.setText(getResources().getString(R.string.radio_on));
    } else {
        mWifiDesc.setText(getResources().getString(R.string.radio_off));
    }

    // Bluetooth Desc
    if (mModel.getBluetoothEnabled()) {
        mBluetoothDesc.setText(getResources().getString(R.string.radio_on));
    } else {
        mBluetoothDesc.setText(getResources().getString(R.string.radio_off));
    }

    // Rotate Desc        
    if (mModel.getRotateEnabled()) {
        mRotateDesc.setText(getResources().getString(R.string.radio_on));
    } else {
        mRotateDesc.setText(getResources().getString(R.string.radio_off));
    }

    // Sync Desc        
    if (mModel.getSyncEnabled()) {
        mSyncDesc.setText(getResources().getString(R.string.radio_on));
    } else {
        mSyncDesc.setText(getResources().getString(R.string.radio_off));
    }

    String desc = "";
    // SilentMode Desc
    switch (mModel.getSilentMode()) {
    case AudioManager.RINGER_MODE_NORMAL:
        desc = getResources().getString(R.string.radio_normal);
        break;
    case AudioManager.RINGER_MODE_SILENT:
        desc = getResources().getString(R.string.radio_silent);
        break;
    case AudioManager.RINGER_MODE_VIBRATE:
        desc = getResources().getString(R.string.radio_vibrate);
        break;
    default:
    }
    mSilentDesc.setText(desc);

    // ? Desc           
    if (mModel.getBrightnessAuto()) {
        desc = mActivity.getResources().getString(R.string.label_auto_brightness);
    } else {
        desc = String.valueOf(mModel.getBrightnessValue());
    }
    mBrightnessDesc.setText(desc);

    // Sleep Desc
    mSleepTime = Conf.mapSleepTime.get(mModel.getSleepTimeOrdinal());
    switch (mSleepTime) {
    case TIME1:
        mSleepTime = SleepTime.TIME1;
        mSleepDesc.setText(getResources().getString(R.string.radio_time1));
        break;
    case TIME2:
        mSleepTime = SleepTime.TIME2;
        mSleepDesc.setText(getResources().getString(R.string.radio_time2));
        break;
    case TIME3:
        mSleepTime = SleepTime.TIME3;
        mSleepDesc.setText(getResources().getString(R.string.radio_time3));
        break;
    case TIME4:
        mSleepTime = SleepTime.TIME4;
        mSleepDesc.setText(getResources().getString(R.string.radio_time4));
        break;
    case TIME5:
        mSleepTime = SleepTime.TIME5;
        mSleepDesc.setText(getResources().getString(R.string.radio_time5));
        break;
    case TIME6:
        mSleepTime = SleepTime.TIME6;
        mSleepDesc.setText(getResources().getString(R.string.radio_time6));
        break;
    default:
    }
}

From source file:net.networksaremadeofstring.rhybudd.Notifications.java

public static void SendGCMNotification(ZenossEvent Event, Context context) {
    SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(context);

    Time now = new Time();
    now.setToNow();//from w  w w  .  j  a  v a 2s  .c om

    //We don't need to overwhelm the user with their notification sound / vibrator
    if ((now.toMillis(true) - PreferenceManager.getDefaultSharedPreferences(context).getLong("lastCheck",
            now.toMillis(true))) < 3000) {
        //Log.e("SendGCMNotification", "Not publishing a notification due to stampede control");
        return;
    }

    Intent notificationIntent = new Intent(context, ViewZenossEventsListActivity.class);
    notificationIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    notificationIntent.putExtra("forceRefresh", true);
    PendingIntent contentIntent = PendingIntent.getActivity(context, 0, notificationIntent, 0);

    Uri soundURI = null;
    try {
        if (settings.getBoolean("notificationSound", true)) {
            if (settings.getString("notificationSoundChoice", "").equals("")) {
                soundURI = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
            } else {
                try {
                    soundURI = Uri.parse(settings.getString("notificationSoundChoice", ""));
                } catch (Exception e) {
                    soundURI = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
                }
            }
        } else {
            soundURI = null;
        }
    } catch (Exception e) {

    }

    String notifTitle = "New Events Received";
    int notifPriority = Notification.PRIORITY_DEFAULT;
    //int AlertType = NOTIFICATION_GCM_GENERIC;

    try {
        if (Event.getSeverity().equals("5")) {
            notifTitle = context.getString(R.string.CriticalNotificationTitle);
            notifPriority = Notification.PRIORITY_MAX;
            //AlertType = NOTIFICATION_GCM_CRITICAL;
        } else if (Event.getSeverity().equals("4")) {
            notifTitle = context.getString(R.string.ErrorNotificationTitle);
            notifPriority = Notification.PRIORITY_HIGH;
            //AlertType = NOTIFICATION_GCM_ERROR;
        } else if (Event.getSeverity().equals("3")) {
            notifTitle = context.getString(R.string.WarnNotificationTitle);
            notifPriority = Notification.PRIORITY_DEFAULT;
            //AlertType = NOTIFICATION_GCM_WARNING;
        } else if (Event.getSeverity().equals("2")) {
            notifTitle = context.getString(R.string.InfoNotificationTitle);
            notifPriority = Notification.PRIORITY_LOW;
            //AlertType = NOTIFICATION_GCM_INFO;
        } else if (Event.getSeverity().equals("1")) {
            notifTitle = context.getString(R.string.DebugNotificationTitle);
            notifPriority = Notification.PRIORITY_MIN;
            //AlertType = NOTIFICATION_GCM_DEBUG;
        }
    } catch (Exception e) {

    }

    long[] vibrate = { 0, 100, 200, 300 };

    try {
        AudioManager audio = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);

        //Log.e("audio.getRingerMode()",Integer.toString(audio.getRingerMode()));
        switch (audio.getRingerMode()) {
        case AudioManager.RINGER_MODE_SILENT:
            //Do nothing to fix GitHub issue #13
            //Log.e("AudioManager","Doing nothing because we are silent");
            vibrate = new long[] { 0, 0 };
            break;
        }
    } catch (Exception e) {
        e.printStackTrace();
    }

    Intent broadcastMassAck = new Intent();
    broadcastMassAck.setAction(MassAcknowledgeReceiver.BROADCAST_ACTION);
    PendingIntent pBroadcastMassAck = PendingIntent.getBroadcast(context, 0, broadcastMassAck, 0);

    if (Build.VERSION.SDK_INT >= 16) {
        Notification noti = new Notification.BigTextStyle(new Notification.Builder(context)
                .setContentTitle(notifTitle).setPriority(notifPriority).setAutoCancel(true).setSound(soundURI)
                .setVibrate(vibrate).setContentText(Event.getDevice()).setContentIntent(contentIntent)
                .addAction(R.drawable.ic_action_resolve_all, "Acknowledge all Events", pBroadcastMassAck)
                .setSmallIcon(R.drawable.ic_stat_alert)).bigText(
                        Event.getSummary() + "\r\n" + Event.getComponentText() + "\r\n" + Event.geteventClass())
                        .build();

        if (settings.getBoolean("notificationSoundInsistent", false))
            noti.flags |= Notification.FLAG_INSISTENT;

        noti.tickerText = notifTitle;

        NotificationManager mNM = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
        mNM.notify(NOTIFICATION_GCM_GENERIC, noti);
    } else {
        NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(context)
                .setSmallIcon(R.drawable.ic_stat_alert).setContentTitle(notifTitle)
                .setContentText(Event.getDevice() + ": " + Event.getSummary()).setContentIntent(contentIntent)
                .setSound(soundURI).setVibrate(vibrate)
                .addAction(R.drawable.ic_action_resolve_all, "Acknowledge all Events", pBroadcastMassAck)
                .setAutoCancel(true).setPriority(notifPriority);

        NotificationManager mNM = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
        mNM.notify(NOTIFICATION_GCM_GENERIC, mBuilder.build());
    }
}

From source file:it.interfree.leonardoce.bootreceiver.AlarmKlaxon.java

private void startAlarm(MediaPlayer player)
        throws java.io.IOException, IllegalArgumentException, IllegalStateException {
    final AudioManager audioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE);

    // Non deve suonare se il cellulare e' silenzioso
    Log.v(LTAG, "Stato del telefono: " + audioManager.getRingerMode());

    // do not play alarms if stream volume is 0
    // (typically because ringer mode is silent).
    if (audioManager.getStreamVolume(AudioManager.STREAM_ALARM) != 0
            && audioManager.getRingerMode() != AudioManager.RINGER_MODE_SILENT
            && audioManager.getRingerMode() != AudioManager.RINGER_MODE_VIBRATE) {
        player.setAudioStreamType(AudioManager.STREAM_ALARM);
        player.setLooping(true);/*  w  ww  .  j  a  va2  s .co m*/
        player.prepare();
        player.start();
    }
}