首页 > 代码库 > <ww>

<ww>

1.

package com.multak.cookaraclient;


import android.content.Context;
import android.content.res.TypedArray;
import android.support.annotation.Nullable;
import android.util.AttributeSet;
import android.widget.ImageView;

import com.multak.cookara.ColorUtils;
import com.multak.cookara.StatusBarUtils;

import java.util.ArrayList;

public class RippleImageView extends ImageView {
    public static ArrayList<RippleImageView> ImageList = new ArrayList<RippleImageView>();

    private boolean globalColor = false;

    public RippleImageView(Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
        StatusBarUtils.RippleView(this, context);

        TypedArray ta = context.obtainStyledAttributes(attrs, R.styleable.mk);
        globalColor = ta.getBoolean(R.styleable.mk_globalcolor, false);
        if(globalColor == true)
        {
            setColorFilter(ColorUtils.GlobalColor);
        }

        if(ImageList.contains(this) == false)
        {
            ImageList.add(this);
        }
    }

    public void ChangeColor(int Color)
    {
        if(globalColor == true)
        {
            setColorFilter(Color);
        }
    }
}

2.

package com.multak.cookara;

import android.content.res.ColorStateList;

public class ColorUtils {
    public static int GlobalColor = 0xffd43b33;
    public static int GlobalColorSelected = 0xffffffff;
    public static String GlobalColorString = "#FFD43B33";

    public static int GlobalTextColorTitle = 0xff606060;
    public static int GlobalTextColorSubtitle = 0xff7f7d7d;

    public static ColorStateList colorStateList= null;

    public static ColorStateList getColorStateList(int mode)
    {
        if(colorStateList == null)
        {
            int[][] states = new int[2][];
            states[0] = new int[]{android.R.attr.state_pressed};
            states[1] = new int[]{android.R.attr.state_enabled};

            int[] colors = new int[]{GlobalColor, GlobalColor};

            colorStateList = new ColorStateList(states, colors);
        }
        return colorStateList;
    }

    public static void SetThemeColor(int BackColor, boolean backColorLight)
    {
        GlobalColor = BackColor;
        if(backColorLight == true)
        {
            GlobalTextColorTitle = 0xff606060;
            GlobalTextColorSubtitle = 0xff7f7d7d;
        }
        else
        {
            GlobalTextColorTitle = 0xffffffff;
            GlobalTextColorSubtitle = 0xffd0cece;
        }
    }

}

3.

package com.multak.cookara;

import android.app.Activity;
import android.app.Dialog;
import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.Color;
import android.os.Build;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;

public class StatusBarUtils {
    public static void setWindowStatusBarColor(Activity activity, String color) {
        try {
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
                Window window = activity.getWindow();
                window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
                window.setStatusBarColor(Color.parseColor(color));

                //底部导航栏
                //window.setNavigationBarColor(activity.getResources().getColor(colorResId));
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public static void setWindowStatusBarColor(Dialog dialog, String color) {
        try {
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
                Window window = dialog.getWindow();
                window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
                window.setStatusBarColor(Color.parseColor(color));

                //底部导航栏
                //window.setNavigationBarColor(activity.getResources().getColor(colorResId));
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public static void RippleView(View view, Context context)
    {
        if(android.os.Build.VERSION.SDK_INT >= 21)
        {
            int[] attrsArray = { android.R.attr.selectableItemBackgroundBorderless };
            //TypedArray typedArray = activity.obtainStyledAttributes(attrsArray);
            TypedArray typedArray = context.obtainStyledAttributes(attrsArray);
            int selector = typedArray.getResourceId(0, attrsArray[0]);
            view.setBackgroundResource(selector);
            // don‘t forget the resource recycling
            typedArray.recycle();
        }
        else
        {
            int[] attrsArray = { android.R.attr.selectableItemBackground };
            TypedArray typedArray = context.obtainStyledAttributes(attrsArray);
            //TypedArray typedArray = getActivity().obtainStyledAttributes(attrsArray);
            int selector = typedArray.getResourceId(0, attrsArray[0]);
            view.setBackgroundResource(selector);
            typedArray.recycle();
        }

    }
}

 

<ww>