2 * Copyright (C) 2012 Andrew Neal
3 * Copyright (C) 2014 The CyanogenMod Project
4 * Licensed under the Apache License, Version 2.0
5 * (the "License"); you may not use this file except in compliance with the
6 * License. You may obtain a copy of the License at
7 * http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law
8 * or agreed to in writing, software distributed under the License is
9 * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
10 * KIND, either express or implied. See the License for the specific language
11 * governing permissions and limitations under the License.
14 package org.lineageos.eleven.widgets;
16 import android.animation.Animator;
17 import android.content.Context;
18 import android.text.TextUtils;
19 import android.util.AttributeSet;
20 import android.view.View;
21 import android.view.ViewAnimationUtils;
22 import android.view.View.OnClickListener;
23 import android.view.View.OnLongClickListener;
24 import android.view.animation.Animation;
25 import android.view.animation.AnimationUtils;
26 import android.widget.ImageButton;
28 import org.lineageos.eleven.R;
29 import org.lineageos.eleven.utils.ApolloUtils;
30 import org.lineageos.eleven.utils.MusicUtils;
33 * A custom {@link ImageButton} that represents the "play and pause" button.
35 * @author Andrew Neal (andrewdneal@gmail.com)
37 public class PlayPauseButton extends ImageButton implements OnClickListener, OnLongClickListener {
40 * Play button theme resource
42 private static final String PLAY = "btn_playback_play";
45 * Pause button theme resource
47 private static final String PAUSE = "btn_playback_pause";
50 * @param context The {@link Context} to use
51 * @param attrs The attributes of the XML tag that is inflating the view.
53 @SuppressWarnings("deprecation")
54 public PlayPauseButton(final Context context, final AttributeSet attrs) {
55 super(context, attrs);
56 setBackground(getResources().getDrawable(R.drawable.selectable_background));
57 // Control playback (play/pause)
58 setOnClickListener(this);
59 // Show the cheat sheet
60 setOnLongClickListener(this);
67 public void onClick(final View v) {
68 MusicUtils.playOrPause();
69 int centerX = (v.getLeft() + v.getRight()) / 2;
70 int centerY = (v.getTop() + v.getBottom()) / 2;
72 int endRadius = (int) Math.hypot(v.getWidth(), v.getHeight());
74 Animator anim = ViewAnimationUtils.createCircularReveal(
75 v, centerX, centerY, startRadius, endRadius);
77 anim.setDuration(800);
87 public boolean onLongClick(final View view) {
88 if (TextUtils.isEmpty(view.getContentDescription())) {
91 ApolloUtils.showCheatSheet(view);
97 * Sets the correct drawable for playback.
99 public void updateState() {
100 if (MusicUtils.isPlaying()) {
101 setContentDescription(getResources().getString(R.string.accessibility_pause));
102 setImageDrawable(getResources().getDrawable(R.drawable.btn_playback_pause));
104 setContentDescription(getResources().getString(R.string.accessibility_play));
105 setImageDrawable(getResources().getDrawable(R.drawable.btn_playback_play));