Example usage for android.graphics ColorMatrix ColorMatrix

List of usage examples for android.graphics ColorMatrix ColorMatrix

Introduction

In this page you can find the example usage for android.graphics ColorMatrix ColorMatrix.

Prototype

public ColorMatrix(ColorMatrix src) 

Source Link

Document

Create a new colormatrix initialized with the specified colormatrix.

Usage

From source file:com.nextgis.maplib.display.TMSRenderer.java

/**
 * @param contrast/*from  w  w  w . j a  v  a  2  s.  c  o m*/
 *         0..10 1 is default
 * @param brightness
 *         -255..255 0 is default
 */
public void setContrastBrightness(float contrast, float brightness, boolean bToGreyScale) {

    mContrast = contrast;
    mBrightness = brightness;
    mForceToGrayScale = bToGreyScale;

    ColorMatrix cm;
    if (bToGreyScale) {
        cm = new ColorMatrix(new float[] { contrast * 0.299f, 0.587f, 0.114f, 0, brightness, 0.299f,
                0.587f * contrast, 0.114f, 0, brightness, 0.299f, 0.587f, 0.114f * contrast, 0, brightness, 0,
                0, 0, 1, 0 });
    } else {
        cm = new ColorMatrix(new float[] { contrast, 0, 0, 0, brightness, 0, contrast, 0, 0, brightness, 0, 0,
                contrast, 0, brightness, 0, 0, 0, 1, 0 });
    }
    if (mRasterPaint != null) {
        mRasterPaint.setColorFilter(new ColorMatrixColorFilter(cm));
    }
}

From source file:com.bytestemplar.tonedef.touchpad.TouchPadActivity.java

private void assertInvertState(boolean hook_buttons) {
    boolean mInvertKeyColors = false;
    if (_preferences.getBoolean("invert_text_color", false)) {
        mInvertKeyColors = true;//from   www .  j  av  a  2  s . co  m
        ColorMatrix cm = new ColorMatrix(_invert);
        _invert_paint = new ColorMatrixColorFilter(cm);
    }

    // hook those _buttons
    for (int i = 0; i < _buttons.buttons.size(); i++) {
        ButtonDefinition button = _buttons.buttons.get(i);

        if (hook_buttons) {
            button.getButtonView().setOnTouchListener(this);
            button.getButtonView().setSoundEffectsEnabled(false);
        }

        if (button.getButtonView() instanceof ImageButton) {

            Drawable ib = ((ImageButton) (button.getButtonView())).getDrawable();

            if (ib != null) {
                if (mInvertKeyColors) {
                    ib.setColorFilter(_invert_paint);
                } else {
                    ib.setColorFilter(null);
                }
            }
        }
    }
}

From source file:com.amaze.filemanager.fragments.Main.java

@Override
public void onActivityCreated(final Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);

    setHasOptionsMenu(false);/* w  w w. ja  va 2s . c  o  m*/
    //MAIN_ACTIVITY = (MainActivity) getActivity();
    initNoFileLayout();
    utils = new Futils();
    String x = PreferenceUtils.getSelectionColor(skin);
    skinselection = Color.parseColor(x);
    color = PreferenceUtils.calculatevalues(x);
    ColorMatrix colorMatrix = new ColorMatrix(PreferenceUtils.calculatefilter(color));
    colorMatrixColorFilter = new ColorMatrixColorFilter(colorMatrix);
    ROOT_MODE = Sp.getBoolean("rootmode", false);
    SHOW_HIDDEN = Sp.getBoolean("showHidden", false);
    COLORISE_ICONS = Sp.getBoolean("coloriseIcons", true);
    folder = res.getDrawable(R.drawable.ic_grid_folder_new);
    getSortModes();
    DARK_IMAGE = res.getDrawable(R.drawable.ic_doc_image_dark);
    DARK_VIDEO = res.getDrawable(R.drawable.ic_doc_video_dark);
    this.setRetainInstance(false);
    f = new HFile(HFile.UNKNOWN, CURRENT_PATH);
    f.generateMode(getActivity());
    MAIN_ACTIVITY.initiatebbar();
    IS_LIST = savedInstanceState != null ? savedInstanceState.getBoolean("IS_LIST", IS_LIST) : IS_LIST;
    ic = new IconHolder(getActivity(), SHOW_THUMBS, !IS_LIST);
    if (theme1 == 1) {

        listView.setBackgroundDrawable(
                new ColorDrawable(getResources().getColor(R.color.holo_dark_background)));
    } else {

        if (IS_LIST)
            listView.setBackgroundDrawable(
                    new ColorDrawable(getResources().getColor(android.R.color.background_light)));

    }
    listView.setHasFixedSize(true);
    columns = Integer.parseInt(Sp.getString("columns", "-1"));
    if (IS_LIST) {
        mLayoutManager = new LinearLayoutManager(getActivity());
        listView.setLayoutManager(mLayoutManager);
    } else {
        if (columns == -1 || columns == 0)
            mLayoutManagerGrid = new GridLayoutManager(getActivity(), 3);
        else
            mLayoutManagerGrid = new GridLayoutManager(getActivity(), columns);
        listView.setLayoutManager(mLayoutManagerGrid);
    }
    // use a linear layout manager
    footerView = getActivity().getLayoutInflater().inflate(R.layout.divider, null);
    dividerItemDecoration = new DividerItemDecoration(getActivity(), DividerItemDecoration.VERTICAL_LIST, false,
            SHOW_DIVIDERS);
    listView.addItemDecoration(dividerItemDecoration);
    mSwipeRefreshLayout.setColorSchemeColors(Color.parseColor(fabSkin));
    DefaultItemAnimator animator = new DefaultItemAnimator();
    listView.setItemAnimator(animator);
    mToolbarContainer.getViewTreeObserver()
            .addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
                @Override
                public void onGlobalLayout() {
                    if ((columns == 0 || columns == -1)) {
                        int screen_width = listView.getWidth();
                        int dptopx = dpToPx(115);
                        columns = screen_width / dptopx;
                        if (columns == 0 || columns == -1)
                            columns = 3;
                        if (!IS_LIST)
                            mLayoutManagerGrid.setSpanCount(columns);
                    }
                    if (savedInstanceState != null && !IS_LIST)
                        retrieveFromSavedInstance(savedInstanceState);
                    if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.JELLY_BEAN) {
                        mToolbarContainer.getViewTreeObserver().removeOnGlobalLayoutListener(this);
                    } else {
                        mToolbarContainer.getViewTreeObserver().removeGlobalOnLayoutListener(this);
                    }
                }

            });
    if (savedInstanceState == null) {
        loadlist(CURRENT_PATH, false, openMode);

    } else {
        if (IS_LIST)
            retrieveFromSavedInstance(savedInstanceState);
    }
}

From source file:com.filemanager.free.fragments.Main.java

@SuppressLint("InflateParams")
@Override//from  www .  ja va 2 s  . c  o  m
public void onActivityCreated(final Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);

    setHasOptionsMenu(false);
    //MAIN_ACTIVITY = (MainActivity) getActivity();
    initNoFileLayout();
    utils = new Futils();
    String x = PreferenceUtils.getSelectionColor(skin);
    skinselection = Color.parseColor(x);
    color = PreferenceUtils.calculatevalues(x);
    ColorMatrix colorMatrix = new ColorMatrix(PreferenceUtils.calculatefilter(color));
    colorMatrixColorFilter = new ColorMatrixColorFilter(colorMatrix);
    ROOT_MODE = Sp.getBoolean("rootmode", false);
    SHOW_HIDDEN = Sp.getBoolean("showHidden", false);
    COLORISE_ICONS = Sp.getBoolean("coloriseIcons", true);
    folder = ContextCompat.getDrawable(getContext(), R.drawable.ic_grid_folder_new);
    getSortModes();
    DARK_IMAGE = ContextCompat.getDrawable(getContext(), R.drawable.ic_doc_image_dark);
    DARK_VIDEO = ContextCompat.getDrawable(getContext(), R.drawable.ic_doc_video_dark);
    this.setRetainInstance(false);
    f = new HFile(HFile.UNKNOWN, CURRENT_PATH);
    f.generateMode(getActivity());
    MAIN_ACTIVITY.initiatebbar();
    IS_LIST = savedInstanceState != null ? savedInstanceState.getBoolean("IS_LIST", IS_LIST) : IS_LIST;
    ic = new IconHolder(getActivity(), SHOW_THUMBS, !IS_LIST);
    if (theme1 == 1) {
        listView.setBackgroundColor(ContextCompat.getColor(getContext(), R.color.holo_dark_background));
    } else {
        if (IS_LIST)
            listView.setBackgroundColor(ContextCompat.getColor(getContext(), android.R.color.background_light));
    }
    listView.setHasFixedSize(true);
    columns = Integer.parseInt(Sp.getString("columns", "-1"));
    if (IS_LIST) {
        mLayoutManager = new LinearLayoutManager(getActivity());
        listView.setLayoutManager(mLayoutManager);
    } else {
        if (columns == -1 || columns == 0)
            mLayoutManagerGrid = new GridLayoutManager(getActivity(), 3);
        else
            mLayoutManagerGrid = new GridLayoutManager(getActivity(), columns);
        listView.setLayoutManager(mLayoutManagerGrid);
    }

    // use a linear layout manager
    footerView = getActivity().getLayoutInflater().inflate(R.layout.divider, null);
    dividerItemDecoration = new DividerItemDecoration(getActivity(), DividerItemDecoration.VERTICAL_LIST, false,
            SHOW_DIVIDERS);
    listView.addItemDecoration(dividerItemDecoration);
    mSwipeRefreshLayout.setColorSchemeColors(Color.parseColor(fabSkin));
    DefaultItemAnimator animator = new DefaultItemAnimator();
    listView.setItemAnimator(animator);
    mToolbarContainer.getViewTreeObserver()
            .addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
                @Override
                public void onGlobalLayout() {
                    if ((columns == 0 || columns == -1)) {
                        int screen_width = listView.getWidth();
                        int dptopx = dpToPx(115);
                        columns = screen_width / dptopx;
                        if (columns == 0 || columns == -1)
                            columns = 3;
                        if (!IS_LIST)
                            mLayoutManagerGrid.setSpanCount(columns);
                    }
                    if (savedInstanceState != null && !IS_LIST)
                        retrieveFromSavedInstance(savedInstanceState);
                    if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.JELLY_BEAN) {
                        mToolbarContainer.getViewTreeObserver().removeOnGlobalLayoutListener(this);
                    } else {
                        mToolbarContainer.getViewTreeObserver().removeGlobalOnLayoutListener(this);
                    }
                }

            });
    if (savedInstanceState == null) {
        loadlist(CURRENT_PATH, false, openMode);

    } else {
        if (IS_LIST)
            retrieveFromSavedInstance(savedInstanceState);
    }
}

From source file:com.igniva.filemanager.fragments.Main.java

@Override
public void onActivityCreated(final Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);

    setHasOptionsMenu(false);//from   w ww. j a v  a2 s  .c om
    //MAIN_ACTIVITY = (MainActivity) getActivity();
    initNoFileLayout();
    utils = new Futils();
    String x = PreferenceUtils
            .getSelectionColor(MainActivity.currentTab == 1 ? BaseActivity.skinTwo : BaseActivity.skin);
    skinselection = Color.parseColor(x);
    color = PreferenceUtils.calculatevalues(x);
    ColorMatrix colorMatrix = new ColorMatrix(PreferenceUtils.calculatefilter(color));
    colorMatrixColorFilter = new ColorMatrixColorFilter(colorMatrix);
    SHOW_HIDDEN = Sp.getBoolean("showHidden", false);
    COLORISE_ICONS = Sp.getBoolean("coloriseIcons", true);
    folder = res.getDrawable(R.drawable.ic_grid_folder_new);
    getSortModes();
    DARK_IMAGE = res.getDrawable(R.drawable.ic_doc_image_dark);
    DARK_VIDEO = res.getDrawable(R.drawable.ic_doc_video_dark);
    this.setRetainInstance(false);
    f = new HFile(HFile.UNKNOWN, CURRENT_PATH);
    f.generateMode(getActivity());
    MAIN_ACTIVITY.initiatebbar();
    ic = new IconHolder(getActivity(), SHOW_THUMBS, !IS_LIST);
    /*if (theme1 == 1) {
            
    listView.setBackgroundDrawable(new ColorDrawable(getResources().getColor(R.color.holo_dark_background)));
    } else {
            
    if (IS_LIST)
        listView.setBackgroundDrawable(new ColorDrawable(getResources().getColor(android.R.color.background_light)));
            
    }*/
    if (theme1 == 0 && !IS_LIST)
        listView.setBackgroundColor(getResources().getColor(R.color.grid_background_light));
    else
        listView.setBackgroundDrawable(null);

    listView.setHasFixedSize(true);
    columns = Integer.parseInt(Sp.getString("columns", "-1"));
    if (IS_LIST) {
        mLayoutManager = new LinearLayoutManager(getActivity());
        listView.setLayoutManager(mLayoutManager);
    } else {
        if (columns == -1 || columns == 0)
            mLayoutManagerGrid = new GridLayoutManager(getActivity(), 3);
        else
            mLayoutManagerGrid = new GridLayoutManager(getActivity(), columns);
        listView.setLayoutManager(mLayoutManagerGrid);
    }
    // use a linear layout manager
    footerView = getActivity().getLayoutInflater().inflate(R.layout.divider, null);
    dividerItemDecoration = new DividerItemDecoration(getActivity(), DividerItemDecoration.VERTICAL_LIST, false,
            SHOW_DIVIDERS);
    listView.addItemDecoration(dividerItemDecoration);
    mSwipeRefreshLayout.setColorSchemeColors(getResources().getColor(R.color.accent_yellow));
    DefaultItemAnimator animator = new DefaultItemAnimator();
    listView.setItemAnimator(animator);
    mToolbarContainer.getViewTreeObserver()
            .addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
                @Override
                public void onGlobalLayout() {
                    if ((columns == 0 || columns == -1)) {
                        int screen_width = listView.getWidth();
                        int dptopx = dpToPx(115);
                        columns = screen_width / dptopx;
                        if (columns == 0 || columns == -1)
                            columns = 3;
                        if (!IS_LIST)
                            mLayoutManagerGrid.setSpanCount(columns);
                    }
                    if (savedInstanceState != null && !IS_LIST)
                        retrieveFromSavedInstance(savedInstanceState);
                    if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.JELLY_BEAN) {
                        mToolbarContainer.getViewTreeObserver().removeOnGlobalLayoutListener(this);
                    } else {
                        mToolbarContainer.getViewTreeObserver().removeGlobalOnLayoutListener(this);
                    }
                }

            });
    if (savedInstanceState == null) {
        loadlist(CURRENT_PATH, false, openMode);

    } else {
        if (IS_LIST)
            retrieveFromSavedInstance(savedInstanceState);
    }
}

From source file:org.appcelerator.titanium.util.TiUIHelper.java

public static ColorFilter createColorFilterForOpacity(final float opacity) {
    // 5x4 identity color matrix + fade the alpha to achieve opacity
    float[] matrix = { 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, opacity, 0 };

    return new ColorMatrixColorFilter(new ColorMatrix(matrix));
}