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.andrew.apollo.widgets.theme;
14 import android.annotation.SuppressLint;
15 import android.content.Context;
16 import android.graphics.Color;
17 import android.graphics.drawable.ColorDrawable;
18 import android.graphics.drawable.StateListDrawable;
20 import com.andrew.apollo.utils.ApolloUtils;
21 import com.andrew.apollo.utils.ThemeUtils;
23 import java.lang.ref.WeakReference;
26 * A themeable {@link StateListDrawable}.
28 * @author Andrew Neal (andrewdneal@gmail.com)
30 public class HoloSelector extends StateListDrawable {
33 * Used to theme the touched and focused colors
35 private static final String RESOURCE_NAME = "holo_selector";
40 private static final int FOCUSED = android.R.attr.state_focused;
45 private static final int PRESSED = android.R.attr.state_pressed;
48 * Constructor for <code>HoloSelector</code>
50 * @param context The {@link Context} to use.
52 @SuppressLint("NewApi")
53 public HoloSelector(final Context context) {
54 final ThemeUtils resources = new ThemeUtils(context);
55 final int themeColor = resources.getColor(RESOURCE_NAME);
59 }, makeColorDrawable(themeColor));
63 }, makeColorDrawable(themeColor));
65 addState(new int[] {}, makeColorDrawable(Color.TRANSPARENT));
66 setExitFadeDuration(400);
70 * @param color The color to use.
71 * @return A new {@link ColorDrawable}.
73 private static final ColorDrawable makeColorDrawable(final int color) {
74 return new WeakReference<ColorDrawable>(new ColorDrawable(color)).get();