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

Commit d7706b7b authored by Jorge Ruesga's avatar Jorge Ruesga
Browse files

core: add support for translucent volume panel



Add support for display the volume panel in translucent mode

Patchset 4: Make it depends to high-end graphics flag

Change-Id: I4f21a6cc88282789072a0e71ae696b754a5e083e
Signed-off-by: default avatarJorge Ruesga <jorge@ruesga.com>
parent 91ec372f
Loading
Loading
Loading
Loading
+65 −1
Original line number Original line Diff line number Diff line
@@ -18,6 +18,11 @@ package android.view;


import com.android.internal.R;
import com.android.internal.R;


import android.animation.Animator;
import android.animation.Animator.AnimatorListener;
import android.animation.AnimatorSet;
import android.animation.ObjectAnimator;
import android.app.ActivityManager;
import android.app.AlertDialog;
import android.app.AlertDialog;
import android.app.Dialog;
import android.app.Dialog;
import android.content.DialogInterface.OnDismissListener;
import android.content.DialogInterface.OnDismissListener;
@@ -42,6 +47,7 @@ import android.os.Vibrator;
import android.provider.Settings;
import android.provider.Settings;
import android.util.Log;
import android.util.Log;
import android.view.WindowManager.LayoutParams;
import android.view.WindowManager.LayoutParams;
import android.view.animation.AccelerateInterpolator;
import android.widget.ImageView;
import android.widget.ImageView;
import android.widget.SeekBar;
import android.widget.SeekBar;
import android.widget.SeekBar.OnSeekBarChangeListener;
import android.widget.SeekBar.OnSeekBarChangeListener;
@@ -111,6 +117,9 @@ public class VolumePanel extends Handler implements OnSeekBarChangeListener, Vie
    public static final int VOLUME_OVERLAY_EXPANDED = 2;
    public static final int VOLUME_OVERLAY_EXPANDED = 2;
    public static final int VOLUME_OVERLAY_NONE = 3;
    public static final int VOLUME_OVERLAY_NONE = 3;


    private static final int TRANSLUCENT_START_LEVEL = 160;
    private static final int TRANSLUCENT_TO_OPAQUE_DURATION = 400;

    protected Context mContext;
    protected Context mContext;
    private AudioManager mAudioManager;
    private AudioManager mAudioManager;
    protected AudioService mAudioService;
    protected AudioService mAudioService;
@@ -120,6 +129,10 @@ public class VolumePanel extends Handler implements OnSeekBarChangeListener, Vie
    private boolean mVolumeLinkNotification;
    private boolean mVolumeLinkNotification;
    private int mCurrentOverlayStyle = -1;
    private int mCurrentOverlayStyle = -1;


    private final boolean mTranslucentDialog;
    private boolean mShouldRunDropTranslucentAnimation = false;
    private boolean mRunningDropTranslucentAnimation = false;

    // True if we want to play tones on the system stream when the master stream is specified.
    // True if we want to play tones on the system stream when the master stream is specified.
    private final boolean mPlayMasterStreamTones;
    private final boolean mPlayMasterStreamTones;


@@ -280,6 +293,7 @@ public class VolumePanel extends Handler implements OnSeekBarChangeListener, Vie
        mContext = context;
        mContext = context;
        mAudioManager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);
        mAudioManager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);
        mAudioService = volumeService;
        mAudioService = volumeService;
        mTranslucentDialog = ActivityManager.isHighEndGfx();


        // For now, only show master volume if master volume is supported
        // For now, only show master volume if master volume is supported
        boolean useMasterVolume = context.getResources().getBoolean(
        boolean useMasterVolume = context.getResources().getBoolean(
@@ -368,6 +382,8 @@ public class VolumePanel extends Handler implements OnSeekBarChangeListener, Vie


        mMoreButton.setOnClickListener(this);
        mMoreButton.setOnClickListener(this);
        listenToRingerMode();
        listenToRingerMode();

        applyTranslucentWindow();
    }
    }


    public void setLayoutDirection(int layoutDirection) {
    public void setLayoutDirection(int layoutDirection) {
@@ -1076,6 +1092,7 @@ public class VolumePanel extends Handler implements OnSeekBarChangeListener, Vie


            case MSG_TIMEOUT: {
            case MSG_TIMEOUT: {
                if (mDialog.isShowing()) {
                if (mDialog.isShowing()) {
                    applyTranslucentWindow();
                    mDialog.dismiss();
                    mDialog.dismiss();
                    mActiveStreamType = -1;
                    mActiveStreamType = -1;
                }
                }
@@ -1134,6 +1151,9 @@ public class VolumePanel extends Handler implements OnSeekBarChangeListener, Vie
    }
    }


    public void onStartTrackingTouch(SeekBar seekBar) {
    public void onStartTrackingTouch(SeekBar seekBar) {
        if (mTranslucentDialog && mShouldRunDropTranslucentAnimation) {
            startRemoveTranslucentAnimation();
        }
    }
    }


    public void onStopTrackingTouch(SeekBar seekBar) {
    public void onStopTrackingTouch(SeekBar seekBar) {
@@ -1151,7 +1171,9 @@ public class VolumePanel extends Handler implements OnSeekBarChangeListener, Vie
    }
    }


    public void onClick(View v) {
    public void onClick(View v) {
        if (v == mMoreButton) {
        if (mTranslucentDialog && mShouldRunDropTranslucentAnimation) {
            startRemoveTranslucentAnimation();
        } else if (v == mMoreButton) {
            expand();
            expand();
        } else if (v instanceof ImageView) {
        } else if (v instanceof ImageView) {
            Intent volumeSettings = new Intent(android.provider.Settings.ACTION_SOUND_SETTINGS);
            Intent volumeSettings = new Intent(android.provider.Settings.ACTION_SOUND_SETTINGS);
@@ -1162,4 +1184,46 @@ public class VolumePanel extends Handler implements OnSeekBarChangeListener, Vie
        }
        }
        resetTimeout();
        resetTimeout();
    }
    }

    private void applyTranslucentWindow() {
        if (!mTranslucentDialog || mRunningDropTranslucentAnimation) return;

        mPanel.getBackground().setAlpha(TRANSLUCENT_START_LEVEL);
        mMoreButton.setAlpha(0.0f);
        mDivider.setAlpha(0.0f);
        mShouldRunDropTranslucentAnimation = true;
    }

    private void startRemoveTranslucentAnimation() {
        if (mRunningDropTranslucentAnimation) return;
        mRunningDropTranslucentAnimation = true;

        AnimatorSet set = new AnimatorSet();
        Animator panelAlpha = ObjectAnimator.ofInt(
                mPanel.getBackground(), "alpha", mPanel.getBackground().getAlpha(), 255);
        Animator moreAlpha = ObjectAnimator.ofFloat(
                mMoreButton, "alpha", mMoreButton.getAlpha(), 255);
        Animator dividerAlpha = ObjectAnimator.ofFloat(
                mDivider, "alpha", mDivider.getAlpha(), 255);
        set.setInterpolator(new AccelerateInterpolator());
        set.addListener(new AnimatorListener() {
            @Override
            public void onAnimationStart(Animator animation) {}

            @Override
            public void onAnimationRepeat(Animator animation) {}

            @Override
            public void onAnimationEnd(Animator animation) {
                mRunningDropTranslucentAnimation = false;
                mShouldRunDropTranslucentAnimation = false;
            }

            @Override
            public void onAnimationCancel(Animator animation) {}
        });
        set.setDuration(TRANSLUCENT_TO_OPAQUE_DURATION);
        set.playTogether(panelAlpha, moreAlpha, dividerAlpha);
        set.start();
    }
}
}