Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 47255e4c authored by Vladimir Vainer's avatar Vladimir Vainer Committed by Abhisek Devkota
Browse files

Alarm: Show a warning toast when alarm volume is set to silent

Change-Id: I97edae55351101046def5058a2459ab88edf2d0d
parent ef56f3e9
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
@@ -79,4 +79,7 @@
    <!-- Alarm types -->
    <string name="alarm_type_ringtone">Ringtone</string>
    <string name="alarm_type_random">Randomly</string>

    <!-- Warn Silent Alarm title -->
    <string name="warn_silent_alarm_title">Alarm volume is silent</string>
</resources>
+24 −1
Original line number Diff line number Diff line
@@ -39,6 +39,7 @@ import android.database.Cursor;
import android.database.DataSetObserver;
import android.graphics.Rect;
import android.graphics.Typeface;
import android.media.AudioManager;
import android.media.Ringtone;
import android.media.RingtoneManager;
import android.net.Uri;
@@ -122,6 +123,7 @@ public class AlarmClockFragment extends DeskClockFragment implements

    private ProfileManager mProfileManager;
    private ProfilesObserver mProfileObserver;
    private AudioManager mAudioManager;

    private final Uri PROFILES_SETTINGS_URI =
        Settings.System.getUriFor(Settings.System.SYSTEM_PROFILES_ENABLED);
@@ -467,6 +469,8 @@ public class AlarmClockFragment extends DeskClockFragment implements
        mAlarmsList.setVerticalScrollBarEnabled(true);
        mAlarmsList.setOnCreateContextMenuListener(this);

        mAudioManager = (AudioManager)getActivity().getSystemService(Context.AUDIO_SERVICE);

        if (mUndoShowing) {
            showUndoBar();
        }
@@ -507,6 +511,12 @@ public class AlarmClockFragment extends DeskClockFragment implements

            // Remove the SCROLL_TO_ALARM extra now that we've processed it.
            intent.removeExtra(SCROLL_TO_ALARM_INTENT_EXTRA);
        } else {
            // If alarm stream volume is 0, show a warning
            if (mAudioManager.getStreamVolume(AudioManager.STREAM_ALARM) == 0) {
                showSilentWarningBar();
            }

        }

        // Make sure to use the child FragmentManager. We have to use that one for the
@@ -548,7 +558,20 @@ public class AlarmClockFragment extends DeskClockFragment implements
                mDeletedAlarm = null;
                mUndoShowing = false;
            }
        }, 0, getResources().getString(R.string.alarm_deleted), true, R.string.alarm_undo, true);
        }, 0, getResources().getString(R.string.alarm_deleted), true, 0, R.string.alarm_undo, true);
    }

    private void showSilentWarningBar() {
        mUndoFrame.setVisibility(View.VISIBLE);
        mUndoBar.show(new ActionableToastBar.ActionClickedListener() {
            @Override
            public void onActionClicked() {
                mAudioManager.adjustStreamVolume(AudioManager.STREAM_ALARM,
                        AudioManager.ADJUST_SAME, AudioManager.FLAG_SHOW_UI);
                mUndoShowing = false;
            }
        }, 0, getResources().getString(R.string.warn_silent_alarm_title), true,
                R.drawable.ic_alarm, 0, true);
    }

    @Override
+19 −6
Original line number Diff line number Diff line
@@ -47,7 +47,7 @@ public class ActionableToastBar extends LinearLayout {
    /** The clickable view */
    private View mActionButton;
    /** Icon for the action button. */
    private View mActionIcon;
    private ImageView mActionIcon;
    /** The view that contains the description. */
    private TextView mActionDescriptionView;
    /** The view that contains the text for the action button. */
@@ -76,7 +76,7 @@ public class ActionableToastBar extends LinearLayout {
        mActionDescriptionIcon = (ImageView) findViewById(R.id.description_icon);
        mActionDescriptionView = (TextView) findViewById(R.id.description_text);
        mActionButton = findViewById(R.id.action_button);
        mActionIcon = findViewById(R.id.action_icon);
        mActionIcon = (ImageView)findViewById(R.id.action_icon);
        mActionText = (TextView) findViewById(R.id.action_text);
    }

@@ -104,8 +104,8 @@ public class ActionableToastBar extends LinearLayout {
     * Otherwise, skip showing this toast.
     */
    public void show(final ActionClickedListener listener, int descriptionIconResourceId,
            CharSequence descriptionText, boolean showActionIcon, int actionTextResource,
            boolean replaceVisibleToast) {
            CharSequence descriptionText, boolean showActionIcon, int actionIconResourceId,
            int actionTextResource, boolean replaceVisibleToast) {

        if (!mHidden && !replaceVisibleToast) {
            return;
@@ -129,9 +129,22 @@ public class ActionableToastBar extends LinearLayout {
            mActionDescriptionIcon.setImageResource(descriptionIconResourceId);
        }

        // Set action icon
        if (showActionIcon) {
            mActionIcon.setVisibility(VISIBLE);
            mActionIcon.setImageResource(actionIconResourceId == 0 ?
                    R.drawable.ic_menu_revert_holo_dark : actionIconResourceId);
        } else {
            mActionIcon.setVisibility(GONE);
        }

        mActionDescriptionView.setText(descriptionText);
        mActionIcon.setVisibility(showActionIcon ? VISIBLE : GONE);
        if (actionTextResource == 0) {
            mActionText.setVisibility(GONE);
        } else {
            mActionText.setVisibility(VISIBLE);
            mActionText.setText(actionTextResource);
        }

        mHidden = false;
        getShowAnimation().start();