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

Commit d4f2ba9d authored by John Spurlock's avatar John Spurlock Committed by Android (Google) Code Review
Browse files

Merge "Remove unused VolumeController."

parents 3105a9c3 027e6f58
Loading
Loading
Loading
Loading
+0 −72
Original line number Diff line number Diff line
/*
 * Copyright (C) 2010 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.android.systemui.statusbar.policy;

import android.content.Context;
import android.media.AudioManager;
import android.os.Vibrator;

import com.android.systemui.settings.ToggleSlider;

public class VolumeController implements ToggleSlider.Listener {
    private static final String TAG = "StatusBar.VolumeController";
    private static final int STREAM = AudioManager.STREAM_NOTIFICATION;

    private Context mContext;
    private ToggleSlider mControl;
    private AudioManager mAudioManager;

    private boolean mMute;
    private int mVolume;
    // Is there a vibrator
    private final boolean mHasVibrator;

    public VolumeController(Context context, ToggleSlider control) {
        mContext = context;
        mControl = control;

        Vibrator vibrator = (Vibrator) context.getSystemService(Context.VIBRATOR_SERVICE);
        mHasVibrator = vibrator == null ? false : vibrator.hasVibrator();

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

        mMute = mAudioManager.getRingerMode() != AudioManager.RINGER_MODE_NORMAL;
        mVolume = mAudioManager.getStreamVolume(STREAM);

        control.setOnChangedListener(this);
    }

    @Override
    public void onInit(ToggleSlider control) {
        control.setMax(mAudioManager.getStreamMaxVolume(STREAM));
        control.setValue(mVolume);
        control.setChecked(mMute);
    }

    public void onChanged(ToggleSlider view, boolean tracking, boolean mute, int level) {
        if (!tracking) {
            if (mute) {
                mAudioManager.setRingerMode(
                        mHasVibrator ? AudioManager.RINGER_MODE_VIBRATE
                                     : AudioManager.RINGER_MODE_SILENT);
            } else {
                mAudioManager.setRingerMode(AudioManager.RINGER_MODE_NORMAL);
                mAudioManager.setStreamVolume(STREAM, level, AudioManager.FLAG_PLAY_SOUND);
            }
        }
    }
}