Example usage for android.media AudioManager STREAM_ALARM

List of usage examples for android.media AudioManager STREAM_ALARM

Introduction

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

Prototype

int STREAM_ALARM

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

Click Source Link

Document

Used to identify the volume of audio streams for alarms

Usage

From source file:org.nerdcircus.android.klaxon.Notifier.java

/** return our notification object.
 *///from ww  w  .  ja va2  s .co  m
Notification getNotification(Context context, String subject) {
    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
    Uri alertsound = Uri.parse(prefs.getString("alert_sound", "DEFAULT"));
    if (alertsound.toString().equals("DEFAULT")) {
        //no setting. use default.
        alertsound = Settings.System.DEFAULT_NOTIFICATION_URI;
    }

    Intent listIntent = new Intent(Intent.ACTION_VIEW);
    listIntent.setType("vnd.android.cursor.dir/pages");
    Intent cancelIntent = new Intent(Pager.SILENCE_ACTION);

    NotificationCompat.Builder nb = new NotificationCompat.Builder(context);
    nb.setSmallIcon(R.drawable.bar_icon);
    nb.setPriority(NotificationCompat.PRIORITY_MAX);
    nb.setLights(R.color.red, 1000, 100);

    int streamtype = Notification.STREAM_DEFAULT;
    if (prefs.getBoolean("use_alarm_stream", false)) {
        streamtype = AudioManager.STREAM_ALARM;
    }
    nb.setSound(alertsound, streamtype);
    nb.setContentTitle(subject);
    nb.setContentIntent(PendingIntent.getActivity(context, 0, listIntent, 0));
    nb.setDeleteIntent(PendingIntent.getBroadcast(context, 0, cancelIntent, 0));
    nb.setAutoCancel(true);

    //vibrate!
    if (prefs.getBoolean("vibrate", true)) {
        nb.setVibrate(new long[] { 0, 800, 500, 800 });
    }

    return nb.build();
}

From source file:com.apps.howard.vicissitude.services.NotificationService.java

private NotificationCompat.Builder getNotificationBuilder(String message, String sender) {
    return new NotificationCompat.Builder(this).setSmallIcon(R.drawable.ic_stat_name)
            .setContentTitle(getString(R.string.notification_title_notification_service) + sender)
            .setStyle((new NotificationCompat.BigTextStyle()).bigText(message)
                    .setBigContentTitle(getString(R.string.notification_title_notification_service) + sender)
                    .setSummaryText("Vicissitude"))
            .setGroup(sender).setSound(getAlarmTone(), AudioManager.STREAM_ALARM).setAutoCancel(true);
}

From source file:com.android.deskclock2.DeskClock.java

@Override
protected void onCreate(Bundle icicle) {
    super.onCreate(icicle);
    setVolumeControlStream(AudioManager.STREAM_ALARM);

    if (icicle != null) {
        mSelectedTab = icicle.getInt(KEY_SELECTED_TAB, CLOCK_TAB_INDEX);
    } else {//from w w  w .  ja  va2s  .c o  m
        mSelectedTab = CLOCK_TAB_INDEX;

        // Set the background color to initially match the theme value so that we can
        // smoothly transition to the dynamic color.
        setBackgroundColor(getResources().getColor(R.color.default_background), false /* animate */);
    }

    // Honor the tab requested by the intent, if any.
    final Intent intent = getIntent();
    if (intent != null) {
        int tab = intent.getIntExtra(SELECT_TAB_INTENT_EXTRA, -1);
        if (tab != -1) {
            mSelectedTab = tab;
        }
    }

    setContentView(R.layout.desk_clock);
    final Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);
    mTabLayout = (TabLayout) findViewById(R.id.sliding_tabs);
    mFab = (ImageView) findViewById(R.id.fab);
    mLeftButton = (ImageButton) findViewById(R.id.left_button);
    mRightButton = (ImageButton) findViewById(R.id.right_button);
    if (mTabsAdapter == null) {
        mViewPager = (RtlViewPager) findViewById(R.id.desk_clock_pager);
        // Keep all four tabs to minimize jank.
        mViewPager.setOffscreenPageLimit(3);
        // Set Accessibility Delegate to null so ViewPager doesn't intercept movements and
        // prevent the fab from being selected.
        mViewPager.setAccessibilityDelegate(null);
        mTabsAdapter = new TabsAdapter(this, mViewPager);
        createTabs();
        mTabLayout.setOnTabSelectedListener(new ViewPagerOnTabSelectedListener(mViewPager));
    }

    mFab.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View view) {
            getSelectedFragment().onFabClick(view);
        }
    });
    mLeftButton.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View view) {
            getSelectedFragment().onLeftButtonClick(view);
        }
    });
    mRightButton.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View view) {
            getSelectedFragment().onRightButtonClick(view);
        }
    });

    // Configure the menu item controllers.
    mActionBarMenuManager.addMenuItemController(new SettingMenuItemController(this))
            .addMenuItemController(new NightModeMenuItemController(this))
            .addMenuItemController(MenuItemControllerFactory.getInstance().buildMenuItemControllers(this));

    // Inflate the menu during creation to avoid a double layout pass. Otherwise, the menu
    // inflation occurs *after* the initial draw and a second layout pass adds in the menu.
    onCreateOptionsMenu(toolbar.getMenu());

    // We need to update the system next alarm time on app startup because the
    // user might have clear our data.
    AlarmStateManager.updateNextAlarm(this);
}

From source file:com.onyx.deskclock.deskclock.DeskClock.java

@Override
protected void onCreate(Bundle icicle) {
    super.onCreate(icicle);
    setVolumeControlStream(AudioManager.STREAM_ALARM);

    if (icicle != null) {
        mSelectedTab = icicle.getInt(KEY_SELECTED_TAB, CLOCK_TAB_INDEX);
        //            mSelectedTab = icicle.getInt(KEY_SELECTED_TAB, ALARM_TAB_INDEX);
    } else {//from  ww  w  . j  a va 2 s. co m
        mSelectedTab = CLOCK_TAB_INDEX;
        //            mSelectedTab = ALARM_TAB_INDEX;

        // Set the background color to initially match the theme value so that we can
        // smoothly transition to the dynamic color.
        setBackgroundColor(getResources().getColor(R.color.default_background), false /* animate */);
    }

    // Honor the tab requested by the intent, if any.
    final Intent intent = getIntent();
    if (intent != null) {
        int tab = intent.getIntExtra(SELECT_TAB_INTENT_EXTRA, -1);
        if (tab != -1) {
            mSelectedTab = tab;
        }
    }

    setContentView(R.layout.desk_clock);
    final Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);
    mTabLayout = (TabLayout) findViewById(R.id.sliding_tabs);
    mFab = (ImageView) findViewById(R.id.fab);

    // ?? tab
    toolbar.setVisibility(View.GONE);

    mLeftButton = (ImageButton) findViewById(R.id.left_button);
    mRightButton = (ImageButton) findViewById(R.id.right_button);
    if (mTabsAdapter == null) {
        mViewPager = (RtlViewPager) findViewById(R.id.desk_clock_pager);
        // Keep all four tabs to minimize jank.
        mViewPager.setOffscreenPageLimit(3);
        // Set Accessibility Delegate to null so ViewPager doesn't intercept movements and
        // prevent the fab from being selected.
        mViewPager.setAccessibilityDelegate(null);
        mTabsAdapter = new TabsAdapter(this, mViewPager);
        createTabs();
        mTabLayout.setOnTabSelectedListener(new ViewPagerOnTabSelectedListener(mViewPager));
    }

    mFab.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View view) {
            getSelectedFragment().onFabClick(view);
        }
    });
    mLeftButton.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View view) {
            getSelectedFragment().onLeftButtonClick(view);
        }
    });
    mRightButton.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View view) {
            getSelectedFragment().onRightButtonClick(view);
        }
    });

    // Configure the menu item controllers.
    mActionBarMenuManager.addMenuItemController(new SettingMenuItemController(this))
            .addMenuItemController(new NightModeMenuItemController(this))
            .addMenuItemController(MenuItemControllerFactory.getInstance().buildMenuItemControllers(this));

    // Inflate the menu during creation to avoid a double layout pass. Otherwise, the menu
    // inflation occurs *after* the initial draw and a second layout pass adds in the menu.
    onCreateOptionsMenu(toolbar.getMenu());

    // We need to update the system next alarm time on app startup because the
    // user might have clear our data.
    AlarmStateManager.updateNextAlarm(this);
}

From source file:com.androidinspain.deskclock.alarms.AlarmActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setVolumeControlStream(AudioManager.STREAM_ALARM);
    final long instanceId = AlarmInstance.getId(getIntent().getData());
    mAlarmInstance = AlarmInstance.getInstance(getContentResolver(), instanceId);
    if (mAlarmInstance == null) {
        // The alarm was deleted before the activity got created, so just finish()
        LOGGER.e("Error displaying alarm for intent: %s", getIntent());
        finish();/*from   w ww .j  a  v  a  2  s .  c  om*/
        return;
    } else if (mAlarmInstance.mAlarmState != AlarmInstance.FIRED_STATE) {
        LOGGER.i("Skip displaying alarm for instance: %s", mAlarmInstance);
        finish();
        return;
    }

    LOGGER.i("Displaying alarm for instance: %s", mAlarmInstance);

    // Get the volume/camera button behavior setting
    mVolumeBehavior = DataModel.getDataModel().getAlarmVolumeButtonBehavior();

    getWindow().addFlags(WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED
            | WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD | WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON
            | WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON
            | WindowManager.LayoutParams.FLAG_ALLOW_LOCK_WHILE_SCREEN_ON);

    // Hide navigation bar to minimize accidental tap on Home key
    hideNavigationBar();

    // Close dialogs and window shade, so this is fully visible
    sendBroadcast(new Intent(Intent.ACTION_CLOSE_SYSTEM_DIALOGS));

    // Honor rotation on tablets; fix the orientation on phones.
    if (!getResources().getBoolean(com.androidinspain.deskclock.R.bool.rotateAlarmAlert)) {
        setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_NOSENSOR);
    }

    mAccessibilityManager = (AccessibilityManager) getSystemService(ACCESSIBILITY_SERVICE);

    setContentView(com.androidinspain.deskclock.R.layout.alarm_activity);

    mAlertView = (ViewGroup) findViewById(com.androidinspain.deskclock.R.id.alert);
    mAlertTitleView = (TextView) mAlertView.findViewById(com.androidinspain.deskclock.R.id.alert_title);
    mAlertInfoView = (TextView) mAlertView.findViewById(com.androidinspain.deskclock.R.id.alert_info);

    mContentView = (ViewGroup) findViewById(com.androidinspain.deskclock.R.id.content);
    mAlarmButton = (ImageView) mContentView.findViewById(com.androidinspain.deskclock.R.id.alarm);
    mSnoozeButton = (ImageView) mContentView.findViewById(com.androidinspain.deskclock.R.id.snooze);
    mDismissButton = (ImageView) mContentView.findViewById(com.androidinspain.deskclock.R.id.dismiss);
    mHintView = (TextView) mContentView.findViewById(com.androidinspain.deskclock.R.id.hint);

    final TextView titleView = (TextView) mContentView.findViewById(com.androidinspain.deskclock.R.id.title);
    final TextClock digitalClock = (TextClock) mContentView
            .findViewById(com.androidinspain.deskclock.R.id.digital_clock);
    final CircleView pulseView = (CircleView) mContentView
            .findViewById(com.androidinspain.deskclock.R.id.pulse);

    titleView.setText(mAlarmInstance.getLabelOrDefault(this));
    Utils.setTimeFormat(digitalClock, false);

    mCurrentHourColor = ThemeUtils.resolveColor(this, android.R.attr.windowBackground);
    getWindow().setBackgroundDrawable(new ColorDrawable(mCurrentHourColor));

    mAlarmButton.setOnTouchListener(this);
    mSnoozeButton.setOnClickListener(this);
    mDismissButton.setOnClickListener(this);

    mAlarmAnimator = AnimatorUtils.getScaleAnimator(mAlarmButton, 1.0f, 0.0f);
    mSnoozeAnimator = getButtonAnimator(mSnoozeButton, Color.WHITE);
    mDismissAnimator = getButtonAnimator(mDismissButton, mCurrentHourColor);
    mPulseAnimator = ObjectAnimator.ofPropertyValuesHolder(pulseView,
            PropertyValuesHolder.ofFloat(CircleView.RADIUS, 0.0f, pulseView.getRadius()),
            PropertyValuesHolder.ofObject(CircleView.FILL_COLOR, AnimatorUtils.ARGB_EVALUATOR,
                    ColorUtils.setAlphaComponent(pulseView.getFillColor(), 0)));
    mPulseAnimator.setDuration(PULSE_DURATION_MILLIS);
    mPulseAnimator.setInterpolator(PULSE_INTERPOLATOR);
    mPulseAnimator.setRepeatCount(ValueAnimator.INFINITE);
    mPulseAnimator.start();
}

From source file:org.schabi.terminightor.NightKillerService.java

private MediaPlayer setupNewMediaPlayer(Alarm alarm) {
    MediaPlayer mediaPlayer = null;/*from w w w. java 2 s .  c  om*/
    try {
        mediaPlayer = new MediaPlayer();
        mediaPlayer.setDataSource(this, Uri.parse(alarm.getAlarmTone()));
        boolean overrideVolume = PreferenceManager.getDefaultSharedPreferences(this)
                .getBoolean(getString(R.string.overrideAlarmVolume), false);
        if (overrideVolume) {
            mediaPlayer.setVolume(1.0f, 1.0f);
        }
        mediaPlayer.setAudioStreamType(AudioManager.STREAM_ALARM);
        mediaPlayer.setLooping(true);
        mediaPlayer.prepare();
    } catch (Exception e) {
        e.printStackTrace();
    }
    return mediaPlayer;
}

From source file:org.hansel.myAlert.AlarmFragment.java

private void playSound(Context context, Uri alert) {
    mMediaPlayer = new MediaPlayer();
    try {// ww  w. j a  va 2 s. co m
        mMediaPlayer.setDataSource(context, alert);
        final AudioManager audioManager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);
        if (audioManager.getStreamVolume(AudioManager.STREAM_ALARM) != 0) {
            mMediaPlayer.setAudioStreamType(AudioManager.STREAM_ALARM);
            mMediaPlayer.prepare();
            mMediaPlayer.start();
        }
    } catch (IOException e) {
        System.out.println("Error tocando alarma");
    }
}

From source file:com.android.deskclock.RingtonePickerDialogFragment.java

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

    // Allow the volume rocker to control the alarm stream volume while the picker is showing.
    mDialog.setVolumeControlStream(AudioManager.STREAM_ALARM);
}

From source file:com.apps.howard.vicissitude.services.NotificationService.java

private void maybeOverrideVolumeBeforeNotify() {

    boolean settingsOverrideVolumeEnabled = prefs.getBoolean(this.getString(R.string.pref_override_volume_key),
            false);//from  ww w. j  a  va2 s.  c  o m
    int settingsOverrideVolume = prefs.getInt(this.getString(R.string.pref_alert_volume_key), 1);

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

    if (settingsOverrideVolumeEnabled) {
        audioManager.setStreamVolume(AudioManager.STREAM_ALARM, settingsOverrideVolume, 0);
    }
}

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);//from  w ww .j  ava2s.  co  m
        player.prepare();
        player.start();
    }
}