2 * Copyright (C) 2012 Andrew Neal Licensed under the Apache License, Version 2.0
3 * (the "License"); you may not use this file except in compliance with the
4 * License. You may obtain a copy of the License at
5 * http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law
6 * or agreed to in writing, software distributed under the License is
7 * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
8 * KIND, either express or implied. See the License for the specific language
9 * governing permissions and limitations under the License.
12 package com.cyngn.eleven.widgets;
14 import android.content.Context;
15 import android.text.TextUtils;
16 import android.util.AttributeSet;
17 import android.view.View;
18 import android.view.View.OnClickListener;
19 import android.view.View.OnLongClickListener;
20 import android.widget.ImageButton;
22 import com.cyngn.eleven.MusicPlaybackService;
23 import com.cyngn.eleven.R;
24 import com.cyngn.eleven.utils.ApolloUtils;
25 import com.cyngn.eleven.utils.MusicUtils;
26 import com.cyngn.eleven.widgets.theme.HoloSelector;
29 * @author Andrew Neal (andrewdneal@gmail.com)
31 public class ShuffleButton extends ImageButton implements OnClickListener, OnLongClickListener {
34 * Shuffle theme resource
36 private static final String SHUFFLE = "btn_playback_shuffle";
39 * Shuffle all theme resource
41 private static final String SHUFFLE_ALL = "btn_playback_shuffle_all";
44 * @param context The {@link Context} to use
45 * @param attrs The attributes of the XML tag that is inflating the view.
47 @SuppressWarnings("deprecation")
48 public ShuffleButton(final Context context, final AttributeSet attrs) {
49 super(context, attrs);
51 setBackgroundDrawable(new HoloSelector(context));
52 // Control playback (cycle shuffle)
53 setOnClickListener(this);
54 // Show the cheat sheet
55 setOnLongClickListener(this);
62 public void onClick(final View v) {
63 MusicUtils.cycleShuffle();
71 public boolean onLongClick(final View view) {
72 if (TextUtils.isEmpty(view.getContentDescription())) {
75 ApolloUtils.showCheatSheet(view);
81 * Sets the correct drawable for the shuffle state.
83 public void updateShuffleState() {
84 switch (MusicUtils.getShuffleMode()) {
85 case MusicPlaybackService.SHUFFLE_NORMAL:
86 setContentDescription(getResources().getString(R.string.accessibility_shuffle_all));
87 setImageDrawable(getResources().getDrawable(R.drawable.btn_playback_shuffle_all));
89 case MusicPlaybackService.SHUFFLE_AUTO:
90 setContentDescription(getResources().getString(R.string.accessibility_shuffle_all));
91 setImageDrawable(getResources().getDrawable(R.drawable.btn_playback_shuffle_all));
93 case MusicPlaybackService.SHUFFLE_NONE:
94 setContentDescription(getResources().getString(R.string.accessibility_shuffle));
95 setImageDrawable(getResources().getDrawable(R.drawable.btn_playback_shuffle));