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.utils.ThemeUtils;
27 import com.cyngn.eleven.widgets.theme.HoloSelector;
30 * A custom {@link ImageButton} that represents the "repeat" button.
32 * @author Andrew Neal (andrewdneal@gmail.com)
34 public class RepeatButton extends ImageButton implements OnClickListener, OnLongClickListener {
37 * Repeat one theme resource
39 private static final String REPEAT_ALL = "btn_playback_repeat_all";
42 * Repeat one theme resource
44 private static final String REPEAT_CURRENT = "btn_playback_repeat_one";
47 * Repeat one theme resource
49 private static final String REPEAT_NONE = "btn_playback_repeat";
52 * The resources to use.
54 private final ThemeUtils mResources;
57 * @param context The {@link Context} to use
58 * @param attrs The attributes of the XML tag that is inflating the view.
60 @SuppressWarnings("deprecation")
61 public RepeatButton(final Context context, final AttributeSet attrs) {
62 super(context, attrs);
63 // Initialze the theme resources
64 mResources = new ThemeUtils(context);
66 setBackgroundDrawable(new HoloSelector(context));
67 // Control playback (cycle repeat modes)
68 setOnClickListener(this);
69 // Show the cheat sheet
70 setOnLongClickListener(this);
77 public void onClick(final View v) {
78 MusicUtils.cycleRepeat();
86 public boolean onLongClick(final View view) {
87 if (TextUtils.isEmpty(view.getContentDescription())) {
90 ApolloUtils.showCheatSheet(view);
96 * Sets the correct drawable for the repeat state.
98 public void updateRepeatState() {
99 switch (MusicUtils.getRepeatMode()) {
100 case MusicPlaybackService.REPEAT_ALL:
101 setContentDescription(getResources().getString(R.string.accessibility_repeat_all));
102 setImageDrawable(mResources.getDrawable(REPEAT_ALL));
104 case MusicPlaybackService.REPEAT_CURRENT:
105 setContentDescription(getResources().getString(R.string.accessibility_repeat_one));
106 setImageDrawable(mResources.getDrawable(REPEAT_CURRENT));
108 case MusicPlaybackService.REPEAT_NONE:
109 setContentDescription(getResources().getString(R.string.accessibility_repeat));
110 setImageDrawable(mResources.getDrawable(REPEAT_NONE));