List of usage examples for android.media AudioManager RINGER_MODE_NORMAL
int RINGER_MODE_NORMAL
To view the source code for android.media AudioManager RINGER_MODE_NORMAL.
Click Source Link
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 www.j a v a 2 s. co 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:com.handmark.pulltorefresh.library.internal.LoadingLayout.java
public void releaseToRefresh() { if (!mArrowRotated) { mHeaderArrow.startAnimation(mRotateAnimation); rotateArrow();/* www.j a va 2s . c o m*/ mArrowRotated = true; if (!hasPlayedSound) { hasPlayedSound = true; 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.pulldown); mPlayer.start(); } } } } mHeaderText.setText(Html.fromHtml(mReleaseLabel)); }
From source file:com.xortech.sender.SmsReceiver.java
public void onReceive(final Context ctx, Intent intent) { // GET SMS MAP FROM INTENT Bundle extras = intent.getExtras();/* w w w .j ava 2 s . c om*/ context = ctx; // GPS INSTANCE gps = new GPSTracker(context); // LOAD PREFERENCES preferences = PreferenceManager.getDefaultSharedPreferences(context); secretCode = preferences.getString("secretCode", DEFAULT_CODE); tagID = preferences.getString("tagID", DEFAULT_TAGID); senderEnabled = preferences.getBoolean("senderEnabled", true); if (extras != null) { // GET THE RECEIVED SMS ARRAY Object[] smsExtra = (Object[]) extras.get(SMS_EXTRA_NAME); for (int i = 0; i < smsExtra.length; ++i) { // GET THE MESSAGE SmsMessage sms = SmsMessage.createFromPdu((byte[]) smsExtra[i]); // PARSE THE MESSAGE BODY String body = sms.getMessageBody().toString(); String address = sms.getOriginatingAddress(); long time = System.currentTimeMillis(); // GET COORDINATES AND SEND A MESSAGE gps.getLocation(); latitude = String.valueOf(Math.round(FIVE_DIGIT * gps.getLatitude()) / FIVE_DIGIT); longitude = String.valueOf(Math.round(FIVE_DIGIT * gps.getLongitude()) / FIVE_DIGIT); location = "Tag_ID:" + tagID + ":Location:" + latitude + "," + longitude; googleString = GOOGLE_STRING + latitude + "," + longitude + "(" + tagID + ")"; if (body.equals(SECRET_LOCATION_A + secretCode)) { if (senderEnabled) { if (latitude.equals("0.0") | longitude.equals("0.0")) { SmsManager.getDefault().sendTextMessage(address, null, NO_COORDS + tagID, null, null); } else { SmsManager.getDefault().sendTextMessage(address, null, googleString, null, null); } } this.abortBroadcast(); } else if (body.equals(SECRET_LOCATION_B + secretCode)) { if (senderEnabled) { if (latitude.equals("0.0") | longitude.equals("0.0")) { SmsManager.getDefault().sendTextMessage(address, null, NO_COORDS + tagID, null, null); } else { SmsManager.getDefault().sendTextMessage(address, null, location, null, null); } } this.abortBroadcast(); } else if (body.contains("Tag_ID:")) { // ADD TO DATABASE MsgDatabaseHandler dbHandler = new MsgDatabaseHandler(context); // VERIFY IF THE TAG EXISTS IN THE ARRAY String addressExists = VerifyTagExist(address); String[] splitBody = body.split(":"); String tag = splitBody[1]; tag.trim(); String coords = splitBody[3]; String[] splitCoords = coords.split(","); String lat = splitCoords[0]; lat.trim(); String lon = splitCoords[1]; lon.trim(); String _time = String.valueOf(time); String toastMsg = null; // CHECK IF THE ADDRESS EXISTS FOR NAMING PURPOSES if (addressExists == null) { dbHandler.Add_Message(new MessageData(tag, address, lat, lon, _time)); toastMsg = "Response Received: " + tag; } else { dbHandler.Add_Message(new MessageData(addressExists, address, lat, lon, _time)); toastMsg = "Response Received: " + addressExists; } dbHandler.close(); Toast.makeText(context, toastMsg, Toast.LENGTH_LONG).show(); this.abortBroadcast(); } else if (body.contains("Panic!")) { // OVERRIDE THE SILENT FEATURE AudioManager audio = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE); int max = audio.getStreamMaxVolume(AudioManager.STREAM_NOTIFICATION); audio.setRingerMode(AudioManager.RINGER_MODE_NORMAL); audio.setStreamVolume(AudioManager.STREAM_RING, max, AudioManager.FLAG_REMOVE_SOUND_AND_VIBRATE); // DEFINE THE NOTIFICATION MANAGER notificationManager = (NotificationManager) context .getSystemService(Context.NOTIFICATION_SERVICE); // START A TIMER mytimer = new Timer(true); // SOUND LOCATION ALARM soundUri = Uri.parse(BEGIN_PATH + context.getPackageName() + FILE_PATH); // DISPLAY TAG ID FOR EMERGENCY String[] splitBody = body.split("\n"); String fieldTag = splitBody[1]; String[] splitTag = fieldTag.split(":"); emergencyTag = splitTag[1].trim(); // TIMER FOR NOTIFICATIONS mytask = new TimerTask() { public void run() { // RUN NOTIFICATION ON TIMER NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(context) .setSmallIcon(R.drawable.emergency).setContentTitle(PANIC_TXT) .setContentText(emergencyTag + UNDER_DURRESS).setSound(soundUri); //This sets the sound to play // DISPLAY THE NOTIFICATION notificationManager.notify(0, mBuilder.build()); } }; // START TIMER AFTER 5 SECONDS mytimer.schedule(mytask, FIVE_SECONDS); } } } // CLEAR THE CACHE ON RECEIVING A MESSAGE try { MyUpdateReceiver.trimCache(context); } catch (Exception e) { e.printStackTrace(); } }
From source file:cc.psdev.heywifi.MainService.java
private boolean changeRingmode() { for (int i = 0; i < 30; i++) { try {/*from w w w .j a v a 2s . co m*/ for (int j = 0; j < 20; j++) { if (ringmode[j] != -1 && resbssid[i].equals(bssid[j])) { if (pref.getSignal() == 1 && ressignal[i] < SIGNAL_MINIMUM) { continue; } else { if (pref.getRingmodeSaved() < 10) { switch (audm.getRingerMode()) { case 2: pref.putRingmodeSaved(12); break; case 1: pref.putRingmodeSaved(11); break; case 0: pref.putRingmodeSaved(10); break; } } switch (ringmode[j]) { case 2: audm.setRingerMode(AudioManager.RINGER_MODE_NORMAL); return true; case 1: audm.setRingerMode(AudioManager.RINGER_MODE_VIBRATE); return true; case 0: audm.setRingerMode(AudioManager.RINGER_MODE_SILENT); return true; } } } } } catch (NullPointerException ex) { } } return false; }
From source file:ch.carteggio.provider.sync.NotificationService.java
private void updateUnreadNotification(boolean newMessage) { NotificationManager mNotificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE); CarteggioProviderHelper helper = new CarteggioProviderHelper(this); int unreadCount = helper.getUnreadCount(); if (unreadCount == 0) { mNotificationManager.cancel(INCOMING_NOTIFICATION_ID); } else {// w w w . j ava 2 s. c o m String quantityString = getResources().getQuantityString(R.plurals.notification_new_incoming_messages, unreadCount); NotificationCompat.Builder notifyBuilder = new NotificationCompat.Builder(this) .setContentTitle(String.format(quantityString, unreadCount)) .setSmallIcon(android.R.drawable.stat_notify_chat) .setContentText(getString(R.string.notification_text_new_messages)); Intent resultIntent = new Intent(this, MainActivity.class); TaskStackBuilder stackBuilder = TaskStackBuilder.create(this); stackBuilder.addParentStack(MainActivity.class); stackBuilder.addNextIntent(resultIntent); PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT); notifyBuilder.setContentIntent(resultPendingIntent); if (newMessage) { Uri uri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); AudioManager manager = (AudioManager) getSystemService(AUDIO_SERVICE); long pattern[] = { 1000, 500, 2000 }; if (manager.getRingerMode() == AudioManager.RINGER_MODE_NORMAL) { notifyBuilder.setSound(uri); notifyBuilder.setVibrate(pattern); } else if (manager.getRingerMode() == AudioManager.RINGER_MODE_VIBRATE) { notifyBuilder.setVibrate(pattern); } } mNotificationManager.notify(INCOMING_NOTIFICATION_ID, notifyBuilder.build()); } }
From source file:se.droidgiro.scanner.CaptureActivity.java
@Override protected void onResume() { super.onResume(); resetStatusView();/* w ww . j a va 2 s . co m*/ SurfaceView surfaceView = (SurfaceView) findViewById(R.id.preview_view); SurfaceHolder surfaceHolder = surfaceView.getHolder(); if (hasSurface) { // The activity was paused but not stopped, so the surface still // exists. Therefore // surfaceCreated() won't be called, so init the camera here. initCamera(surfaceHolder); } else { // Install the callback and wait for surfaceCreated() to init the // camera. surfaceHolder.addCallback(this); surfaceHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS); } SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this); playBeep = prefs.getBoolean(PreferencesActivity.KEY_PLAY_BEEP, true); if (playBeep) { // See if sound settings overrides this AudioManager audioService = (AudioManager) getSystemService(AUDIO_SERVICE); if (audioService.getRingerMode() != AudioManager.RINGER_MODE_NORMAL) { playBeep = false; } } vibrate = prefs.getBoolean(PreferencesActivity.KEY_VIBRATE, false); initBeepSound(); }
From source file:com.mattprecious.prioritysms.receiver.AlarmReceiver.java
private void doNotify(Context context, BaseProfile profile) { AudioManager audioManager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE); MediaPlayer mediaPlayer = new MediaPlayer(); try {/*from ww w.j a va 2s.com*/ if (audioManager.getRingerMode() == AudioManager.RINGER_MODE_NORMAL || profile.isOverrideSilent()) { mediaPlayer.setWakeMode(context, PowerManager.PARTIAL_WAKE_LOCK); mediaPlayer.setAudioStreamType( profile.isOverrideSilent() ? AudioManager.STREAM_ALARM : AudioManager.STREAM_NOTIFICATION); mediaPlayer.setDataSource(context, profile.getRingtone()); mediaPlayer.prepare(); mediaPlayer.start(); if (profile.isVibrate()) { Vibrator vibrator = (Vibrator) context.getSystemService(Context.VIBRATOR_SERVICE); vibrator.vibrate(VIBRATE_PATTERN, -1); } } } catch (IllegalArgumentException e) { Log.e(TAG, "failed to play audio", e); } catch (IOException e) { Log.e(TAG, "failed to play audio", e); } }
From source file:org.wso2.iot.agent.AlertActivity.java
/** * This method is used to start ringing the phone. *///from w ww.j a va2 s.com @TargetApi(21) private void startRing() { if (audio != null) { ringerMode = audio.getRingerMode(); ringerVolume = audio.getStreamVolume(AudioManager.STREAM_RING); audio.setRingerMode(AudioManager.RINGER_MODE_NORMAL); audio.setStreamVolume(AudioManager.STREAM_RING, audio.getStreamMaxVolume(AudioManager.STREAM_RING), AudioManager.FLAG_PLAY_SOUND); defaultRingtoneUri = RingtoneManager.getActualDefaultRingtoneUri(this, RingtoneManager.TYPE_RINGTONE); if (defaultRingtoneUri != null) { defaultRingtone = RingtoneManager.getRingtone(this, defaultRingtoneUri); if (defaultRingtone != null) { if (deviceInfo.getSdkVersion() >= Build.VERSION_CODES.LOLLIPOP) { AudioAttributes attributes = new AudioAttributes.Builder() .setUsage(AudioAttributes.USAGE_NOTIFICATION) .setContentType(AudioAttributes.CONTENT_TYPE_SONIFICATION).build(); defaultRingtone.setAudioAttributes(attributes); } else { defaultRingtone.setStreamType(AudioManager.STREAM_NOTIFICATION); } defaultRingtone.play(); } } } }
From source file:org.wso2.emm.agent.AlertActivity.java
/** * This method is used to start ringing the phone. *//* ww w. j av a 2 s . c o m*/ @TargetApi(21) private void startRing() { if (audio != null) { audio.setRingerMode(AudioManager.RINGER_MODE_NORMAL); audio.setStreamVolume(AudioManager.STREAM_RING, audio.getStreamMaxVolume(AudioManager.STREAM_RING), AudioManager.FLAG_PLAY_SOUND); defaultRingtoneUri = RingtoneManager.getActualDefaultRingtoneUri(this, RingtoneManager.TYPE_RINGTONE); if (defaultRingtoneUri != null) { defaultRingtone = RingtoneManager.getRingtone(this, defaultRingtoneUri); if (defaultRingtone != null) { if (deviceInfo.getSdkVersion() >= Build.VERSION_CODES.LOLLIPOP) { AudioAttributes attributes = new AudioAttributes.Builder() .setUsage(AudioAttributes.USAGE_NOTIFICATION) .setContentType(AudioAttributes.CONTENT_TYPE_SONIFICATION).build(); defaultRingtone.setAudioAttributes(attributes); } else { defaultRingtone.setStreamType(AudioManager.STREAM_NOTIFICATION); } defaultRingtone.play(); } } } }
From source file:net.geniecode.ttr.ScheduleReceiver.java
@SuppressWarnings("deprecation") @SuppressLint({ "Recycle", "NewApi", "InlinedApi" }) @Override/*ww w .j a v a 2 s.c o m*/ public void onReceive(Context context, Intent intent) { if (!Schedules.SCHEDULE_ACTION.equals(intent.getAction())) { // Unknown intent, bail. return; } Schedule schedule = null; // Grab the schedule from the intent. Since the remote AlarmManagerService // fills in the Intent to add some extra data, it must unparcel the // Schedule object. It throws a ClassNotFoundException when unparcelling. // To avoid this, do the marshalling ourselves. final byte[] data = intent.getByteArrayExtra(Schedules.SCHEDULE_RAW_DATA); if (data != null) { Parcel in = Parcel.obtain(); in.unmarshall(data, 0, data.length); in.setDataPosition(0); schedule = Schedule.CREATOR.createFromParcel(in); } if (schedule == null) { // Make sure we set the next schedule if needed. Schedules.setNextSchedule(context); return; } // Disable this schedule if it does not repeat. if (!schedule.daysOfWeek.isRepeatSet()) { Schedules.enableSchedule(context, schedule.id, false); } else { // Enable the next schedule if there is one. The above call to // enableSchedule will call setNextSchedule so avoid calling it twice. Schedules.setNextSchedule(context); } long now = System.currentTimeMillis(); if (now > schedule.time + STALE_WINDOW) { return; } // Get telephony service mTelephonyManager = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE); // Execute only for devices with versions of Android less than 4.2 if (android.os.Build.VERSION.SDK_INT < 17) { // Get flight mode state boolean isEnabled = Settings.System.getInt(context.getContentResolver(), Settings.System.AIRPLANE_MODE_ON, 0) == 1; // Get Wi-Fi service mWifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE); if ((schedule.aponoff) && (!isEnabled) && (schedule.mode.equals("1")) && (mTelephonyManager.getCallState() == TelephonyManager.CALL_STATE_IDLE)) { // Enable flight mode Settings.System.putInt(context.getContentResolver(), Settings.System.AIRPLANE_MODE_ON, isEnabled ? 0 : 1); // Get Wi-Fi state and disable that one too, just in case // (On some devices it doesn't get disabled when the flight mode is // turned on, so we do it here) boolean isWifiEnabled = mWifiManager.isWifiEnabled(); SharedPreferences settings = context.getSharedPreferences(PREFS_NAME, 0); if (isWifiEnabled) { SharedPreferences.Editor editor = settings.edit(); editor.putBoolean(WIFI_STATE, isWifiEnabled); editor.commit(); mWifiManager.setWifiEnabled(false); } else { SharedPreferences.Editor editor = settings.edit(); editor.putBoolean(WIFI_STATE, isWifiEnabled); editor.commit(); } // Post an intent to reload Intent relintent = new Intent(Intent.ACTION_AIRPLANE_MODE_CHANGED); relintent.putExtra("state", !isEnabled); context.sendBroadcast(relintent); } else if ((!schedule.aponoff) && (isEnabled) && (schedule.mode.equals("1"))) { // Disable flight mode Settings.System.putInt(context.getContentResolver(), Settings.System.AIRPLANE_MODE_ON, isEnabled ? 0 : 1); // Restore previously remembered Wi-Fi state SharedPreferences settings = context.getSharedPreferences(PREFS_NAME, 0); Boolean WiFiState = settings.getBoolean(WIFI_STATE, true); if (WiFiState) { mWifiManager.setWifiEnabled(true); } // Post an intent to reload Intent relintent = new Intent(Intent.ACTION_AIRPLANE_MODE_CHANGED); relintent.putExtra("state", !isEnabled); context.sendBroadcast(relintent); } // Check whether there are ongoing phone calls, and if so // show notification instead of just enabling the flight mode else if ((schedule.aponoff) && (!isEnabled) && (schedule.mode.equals("1")) && (mTelephonyManager.getCallState() != TelephonyManager.CALL_STATE_IDLE)) { setNotification(context); } // Execute for devices with Android 4.2 or higher } else { // Get flight mode state String result = Settings.Global.getString(context.getContentResolver(), Settings.Global.AIRPLANE_MODE_ON); if ((schedule.aponoff) && (result.equals("0")) && (schedule.mode.equals("1")) && (mTelephonyManager.getCallState() == TelephonyManager.CALL_STATE_IDLE)) { // Keep the device awake while enabling flight mode Intent service = new Intent(context, ScheduleIntentService.class); startWakefulService(context, service); } else if ((!schedule.aponoff) && (result.equals("1")) && (schedule.mode.equals("1"))) { // Keep the device awake while enabling flight mode Intent service = new Intent(context, ScheduleIntentService.class); startWakefulService(context, service); } else if ((schedule.aponoff) && (result.equals("0")) && (schedule.mode.equals("1")) && (mTelephonyManager.getCallState() != TelephonyManager.CALL_STATE_IDLE)) { setNotification(context); } } // Get audio service mAudioManager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE); // Get current ringer mode and set silent or normal mode accordingly switch (mAudioManager.getRingerMode()) { case AudioManager.RINGER_MODE_SILENT: if ((!schedule.silentonoff) && (schedule.mode.equals("2"))) { mAudioManager.setRingerMode(AudioManager.RINGER_MODE_NORMAL); } break; case AudioManager.RINGER_MODE_NORMAL: if ((schedule.silentonoff) && (schedule.mode.equals("2"))) { mAudioManager.setRingerMode(AudioManager.RINGER_MODE_SILENT); } break; case AudioManager.RINGER_MODE_VIBRATE: // If the phone is set to vibrate let's make it completely silent if ((schedule.silentonoff) && (schedule.mode.equals("2"))) { mAudioManager.setRingerMode(AudioManager.RINGER_MODE_SILENT); } // or restore the regular sounds on it if that's scheduled else if ((!schedule.silentonoff) && (schedule.mode.equals("2"))) { mAudioManager.setRingerMode(AudioManager.RINGER_MODE_NORMAL); } break; } }