package com.roly.nfc.crypto.view;

import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.graphics.drawable.Drawable;
import android.graphics.drawable.StateListDrawable;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.TextView;

import com.roly.nfc.crypto.R;

public class MenuEntry extends FrameLayout{

    public MenuEntry(Context context, AttributeSet attrs) {
        super(context, attrs);

        TypedArray a = context.obtainStyledAttributes(attrs,
                R.styleable.menu_entry, 0, 0);
        String text = a.getString(R.styleable.menu_entry_label);
        Drawable drawable = a.getDrawable(R.styleable.menu_entry_imageSrc);
        int background = a.getColor(R.styleable.menu_entry_backgroundColor, android.R.color.background_light);
        a.recycle();

        LayoutInflater inflater = (LayoutInflater) context
                .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        View view = inflater.inflate(R.layout.menu_entry, this, true);

        StateListDrawable stateListDrawable = new StateListDrawable();
        ColorDrawable colorPressed = new ColorDrawable(Color.parseColor("#2c3e50"));
        stateListDrawable.addState(new int[]{android.R.attr.state_focused}, colorPressed);
        stateListDrawable.addState(new int[]{android.R.attr.state_pressed}, colorPressed);
        stateListDrawable.addState(new int[]{android.R.attr.state_enabled}, new ColorDrawable(background));

        int sdk = android.os.Build.VERSION.SDK_INT;
        if(sdk < android.os.Build.VERSION_CODES.JELLY_BEAN) {
            setBackgroundDrawable(stateListDrawable);
        } else {
            setBackground(stateListDrawable);
        }

        ImageView image = (ImageView) view.findViewById(R.id.menu_entry_image);
        image.setImageDrawable(drawable);

        TextView label = (TextView) view.findViewById(R.id.menu_entry_label);
        label.setText(text);
    }

    @Override
    public boolean onInterceptTouchEvent(MotionEvent ev) {
        return true;
    }
}

@@ -103,39 +103,8 @@
 ay;%0A
-import android.graphics.Color;%0A
 impo
@@ -501,16 +501,60 @@
 rypto.R;
+%0Aimport com.roly.nfc.crypto.util.ColorUtils;
 %0A%0Apublic
@@ -1277,153 +1277,69 @@
     
-StateListDrawable stateListDrawable = new StateListDrawable();%0A        ColorDrawable colorPress
+int colorSelect
 ed =
- new
  Color
-Drawable(Color.parseColor(%22#2c3e50%22)
+Utils.darken(background, (float) 0.5
 );%0A 
@@ -1337,33 +1337,33 @@
 ) 0.5);%0A        
-s
+S
 tateListDrawable
@@ -1366,71 +1366,51 @@
 able
-.addState(new int%5B%5D%7Bandroid.R.attr.state_focused%7D, colorPressed
+ stateListDrawable = new StateListDrawable(
 );%0A 
@@ -1488,21 +1488,41 @@
 d%7D, 
-colorPress
+new ColorDrawable(colorSelect
 ed)
+)
 ;%0A  
@@ -1640,240 +1640,49 @@
     
-int sdk = android.os.Build.VERSION.SDK_INT;%0A        if(sdk %3C android.os.Build.VERSION_CODES.JELLY_BEAN) %7B%0A            setBackgroundDrawable(stateListDrawable);%0A        %7D else %7B%0A            setBackground(stateListDrawable);%0A        %7D
+setBackgroundDrawable(stateListDrawable);
 %0A%0A  

Use darken method in MenuEntry to get background color when selected