OSDN Git Service

Eleven: strip out app-level theming
[android-x86/packages-apps-Eleven.git] / src / com / cyngn / eleven / widgets / ShuffleButton.java
1 /*
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.
10  */
11
12 package com.cyngn.eleven.widgets;
13
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;
21
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;
27
28 /**
29  * @author Andrew Neal (andrewdneal@gmail.com)
30  */
31 public class ShuffleButton extends ImageButton implements OnClickListener, OnLongClickListener {
32
33     /**
34      * Shuffle theme resource
35      */
36     private static final String SHUFFLE = "btn_playback_shuffle";
37
38     /**
39      * Shuffle all theme resource
40      */
41     private static final String SHUFFLE_ALL = "btn_playback_shuffle_all";
42
43     /**
44      * @param context The {@link Context} to use
45      * @param attrs The attributes of the XML tag that is inflating the view.
46      */
47     @SuppressWarnings("deprecation")
48     public ShuffleButton(final Context context, final AttributeSet attrs) {
49         super(context, attrs);
50         // Theme the selector
51         setBackgroundDrawable(new HoloSelector(context));
52         // Control playback (cycle shuffle)
53         setOnClickListener(this);
54         // Show the cheat sheet
55         setOnLongClickListener(this);
56     }
57
58     /**
59      * {@inheritDoc}
60      */
61     @Override
62     public void onClick(final View v) {
63         MusicUtils.cycleShuffle();
64         updateShuffleState();
65     }
66
67     /**
68      * {@inheritDoc}
69      */
70     @Override
71     public boolean onLongClick(final View view) {
72         if (TextUtils.isEmpty(view.getContentDescription())) {
73             return false;
74         } else {
75             ApolloUtils.showCheatSheet(view);
76             return true;
77         }
78     }
79
80     /**
81      * Sets the correct drawable for the shuffle state.
82      */
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));
88                 break;
89             case MusicPlaybackService.SHUFFLE_AUTO:
90                 setContentDescription(getResources().getString(R.string.accessibility_shuffle_all));
91                 setImageDrawable(getResources().getDrawable(R.drawable.btn_playback_shuffle_all));
92                 break;
93             case MusicPlaybackService.SHUFFLE_NONE:
94                 setContentDescription(getResources().getString(R.string.accessibility_shuffle));
95                 setImageDrawable(getResources().getDrawable(R.drawable.btn_playback_shuffle));
96                 break;
97             default:
98                 break;
99         }
100     }
101
102 }