OSDN Git Service

838c2e7101d6bdd3d65cc408b6c6bcdce7f43041
[android-x86/packages-apps-Eleven.git] / src / com / cyanogenmod / eleven / widgets / ShuffleButton.java
1 /*
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.
12  */
13
14 package com.cyanogenmod.eleven.widgets;
15
16 import android.content.Context;
17 import android.util.AttributeSet;
18 import android.view.View;
19
20 import com.cyanogenmod.eleven.MusicPlaybackService;
21 import com.cyanogenmod.eleven.R;
22 import com.cyanogenmod.eleven.utils.MusicUtils;
23
24 /**
25  * @author Andrew Neal (andrewdneal@gmail.com)
26  */
27 public class ShuffleButton extends AudioButton {
28     public ShuffleButton(final Context context, final AttributeSet attrs) {
29         super(context, attrs);
30     }
31
32     @Override
33     public void onClick(final View v) {
34         MusicUtils.cycleShuffle();
35         updateShuffleState();
36     }
37
38     /** Sets the correct drawable for the shuffle state. */
39     public void updateShuffleState() {
40         switch (MusicUtils.getShuffleMode()) {
41             case MusicPlaybackService.SHUFFLE_NORMAL:
42                 setContentDescription(getResources().getString(R.string.accessibility_shuffle_all));
43                 setAlpha(ACTIVE_ALPHA);
44                 break;
45             case MusicPlaybackService.SHUFFLE_AUTO:
46                 setContentDescription(getResources().getString(R.string.accessibility_shuffle_all));
47                 setAlpha(ACTIVE_ALPHA);
48                 break;
49             case MusicPlaybackService.SHUFFLE_NONE:
50                 setContentDescription(getResources().getString(R.string.accessibility_shuffle));
51                 setAlpha(INACTIVE_ALPHA);
52                 break;
53             default:
54                 break;
55         }
56     }
57 }