Example usage for android.content.res ColorStateList ColorStateList

List of usage examples for android.content.res ColorStateList ColorStateList

Introduction

In this page you can find the example usage for android.content.res ColorStateList ColorStateList.

Prototype

public ColorStateList(int[][] states, @ColorInt int[] colors) 

Source Link

Document

Creates a ColorStateList that returns the specified mapping from states to colors.

Usage

From source file:com.androidinspain.deskclock.stopwatch.StopwatchFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle state) {
    mLapsAdapter = new LapsAdapter(getActivity());
    mLapsLayoutManager = new LinearLayoutManager(getActivity());
    mGradientItemDecoration = new GradientItemDecoration(getActivity());

    final View v = inflater.inflate(R.layout.stopwatch_fragment, container, false);
    mTime = (StopwatchCircleView) v.findViewById(R.id.stopwatch_circle);
    mLapsList = (RecyclerView) v.findViewById(R.id.laps_list);
    ((SimpleItemAnimator) mLapsList.getItemAnimator()).setSupportsChangeAnimations(false);
    mLapsList.setLayoutManager(mLapsLayoutManager);
    mLapsList.addItemDecoration(mGradientItemDecoration);

    // In landscape layouts, the laps list can reach the top of the screen and thus can cause
    // a drop shadow to appear. The same is not true for portrait landscapes.
    if (Utils.isLandscape(getActivity())) {
        final ScrollPositionWatcher scrollPositionWatcher = new ScrollPositionWatcher();
        mLapsList.addOnLayoutChangeListener(scrollPositionWatcher);
        mLapsList.addOnScrollListener(scrollPositionWatcher);
    } else {/*from www . j  a  v a 2  s . c o  m*/
        setTabScrolledToTop(true);
    }
    mLapsList.setAdapter(mLapsAdapter);

    // Timer text serves as a virtual start/stop button.
    mMainTimeText = (TextView) v.findViewById(R.id.stopwatch_time_text);
    mHundredthsTimeText = (TextView) v.findViewById(R.id.stopwatch_hundredths_text);
    mStopwatchTextController = new StopwatchTextController(mMainTimeText, mHundredthsTimeText);
    mStopwatchWrapper = v.findViewById(R.id.stopwatch_time_wrapper);

    DataModel.getDataModel().addStopwatchListener(mStopwatchWatcher);

    mStopwatchWrapper.setOnClickListener(new TimeClickListener());
    if (mTime != null) {
        mStopwatchWrapper.setOnTouchListener(new CircleTouchListener());
    }

    final Context c = mMainTimeText.getContext();
    final int colorAccent = ThemeUtils.resolveColor(c, R.attr.colorAccent);
    final int textColorPrimary = ThemeUtils.resolveColor(c, android.R.attr.textColorPrimary);
    final ColorStateList timeTextColor = new ColorStateList(
            new int[][] { { -state_activated, -state_pressed }, {} },
            new int[] { textColorPrimary, colorAccent });
    mMainTimeText.setTextColor(timeTextColor);
    mHundredthsTimeText.setTextColor(timeTextColor);

    return v;
}

From source file:com.tr4android.support.extension.internal.AccountAdapter.java

private static void setupCheckBox(CheckBox checkBox) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        checkBox.setButtonDrawable(R.drawable.btn_checkbox_circle);
        checkBox.setBackgroundResource(R.drawable.btn_checkbox_circle_background);
    } else {/*from  w ww  .  j  ava2 s  .c  o  m*/
        Context context = checkBox.getContext();
        AppCompatDrawableManager dm = AppCompatDrawableManager.get();

        StateListDrawable button = new StateListDrawable();
        button.addState(new int[] { android.R.attr.state_checked },
                dm.getDrawable(context, R.drawable.ic_checkbox_circle_checked));
        button.addState(new int[] {}, dm.getDrawable(context, R.drawable.ic_checkbox_circle_unchecked));
        ColorStateList buttonTint = new ColorStateList(new int[][] { // states
                new int[] { android.R.attr.state_checked }, new int[] {} // state_default
        }, new int[] { // colors
                ThemeUtils.getThemeAttrColor(context, R.attr.colorControlActivated),
                ThemeUtils.getThemeAttrColor(context, R.attr.colorControlNormal) });
        Drawable buttonCompat = DrawableCompat.wrap(button);
        DrawableCompat.setTintList(buttonCompat, buttonTint);
        checkBox.setButtonDrawable(buttonCompat);

        ShapeDrawable background = new ShapeDrawable(new OvalShape());
        int backgroundTint = ThemeUtils.getThemeAttrColor(context, android.R.attr.colorBackground);
        Drawable backgroundCompat = DrawableCompat.wrap(background);
        DrawableCompat.setTint(backgroundCompat, backgroundTint);
        ViewCompatUtils.setBackground(checkBox, backgroundCompat);
    }
}

From source file:com.vnidens.clickableedittext.ClickableEditTextHelper.java

@Override
public void setStartButtonTint(@ColorInt int color) {
    startButtonTintList = new ColorStateList(new int[][] { STATE_DEFAULT }, new int[] { color });

    updateDrawableTintList(startButtonDrawable, startButtonTintList);
}

From source file:com.amaze.filemanager.ui.views.drawer.Drawer.java

public Drawer(MainActivity mainActivity) {
    this.mainActivity = mainActivity;
    resources = mainActivity.getResources();
    dataUtils = DataUtils.getInstance();

    drawerHeaderLayout = mainActivity.getLayoutInflater().inflate(R.layout.drawerheader, null);
    drawerHeaderParent = drawerHeaderLayout.findViewById(R.id.drawer_header_parent);
    drawerHeaderView = drawerHeaderLayout.findViewById(R.id.drawer_header);
    drawerHeaderView.setOnLongClickListener(v -> {
        Intent intent1;/* w w  w . j  av a  2 s.co  m*/
        if (SDK_INT < Build.VERSION_CODES.KITKAT) {
            intent1 = new Intent();
            intent1.setAction(Intent.ACTION_GET_CONTENT);
        } else {
            intent1 = new Intent(Intent.ACTION_OPEN_DOCUMENT);

        }
        intent1.addCategory(Intent.CATEGORY_OPENABLE);
        intent1.setType("image/*");
        mainActivity.startActivityForResult(intent1, image_selector_request_code);
        return false;
    });

    mImageLoader = AppConfig.getInstance().getImageLoader();

    navView = mainActivity.findViewById(R.id.navigation);

    //set width of drawer in portrait to follow material guidelines
    /*if(!Utils.isDeviceInLandScape(mainActivity)){
    setNavViewDimension(navView);
    }*/

    navView.setNavigationItemSelectedListener(this);

    int accentColor = mainActivity.getAccent(), idleColor;

    if (mainActivity.getAppTheme().equals(AppTheme.LIGHT)) {
        idleColor = mainActivity.getResources().getColor(R.color.item_light_theme);
    } else {
        idleColor = Color.WHITE;
    }

    actionViewStateManager = new ActionViewStateManager(navView, idleColor, accentColor);

    ColorStateList drawerColors = new ColorStateList(
            new int[][] { new int[] { android.R.attr.state_checked },
                    new int[] { android.R.attr.state_enabled }, new int[] { android.R.attr.state_pressed },
                    new int[] { android.R.attr.state_focused }, new int[] { android.R.attr.state_pressed } },
            new int[] { accentColor, idleColor, idleColor, idleColor, idleColor });

    navView.setItemTextColor(drawerColors);
    navView.setItemIconTintList(drawerColors);

    if (mainActivity.getAppTheme().equals(AppTheme.DARK)) {
        navView.setBackgroundColor(Utils.getColor(mainActivity, R.color.holo_dark_background));
    } else if (mainActivity.getAppTheme().equals(AppTheme.BLACK)) {
        navView.setBackgroundColor(Utils.getColor(mainActivity, android.R.color.black));
    } else {
        navView.setBackgroundColor(Color.WHITE);
    }

    mDrawerLayout = mainActivity.findViewById(R.id.drawer_layout);
    //mDrawerLayout.setStatusBarBackgroundColor(Color.parseColor((currentTab==1 ? skinTwo : skin)));
    drawerHeaderView.setBackgroundResource(R.drawable.amaze_header);
    //drawerHeaderParent.setBackgroundColor(Color.parseColor((currentTab==1 ? skinTwo : skin)));
    if (mainActivity.findViewById(R.id.tab_frame) != null) {
        lock(DrawerLayout.LOCK_MODE_LOCKED_OPEN);
        open();
        mDrawerLayout.setScrimColor(Color.TRANSPARENT);
        mDrawerLayout.post(this::open);
    } else if (mainActivity.findViewById(R.id.tab_frame) == null) {
        unlock();
        close();
        mDrawerLayout.post(this::close);
    }
    navView.addHeaderView(drawerHeaderLayout);

    if (!isDrawerLocked) {
        mDrawerToggle = new ActionBarDrawerToggle(mainActivity, /* host Activity */
                mDrawerLayout, /* DrawerLayout object */
                R.drawable.ic_drawer_l, /* nav drawer image to replace 'Up' caret */
                R.string.drawer_open, /* "open drawer" description for accessibility */
                R.string.drawer_close /* "close drawer" description for accessibility */
        ) {
            public void onDrawerClosed(View view) {
                Drawer.this.onDrawerClosed();
            }

            public void onDrawerOpened(View drawerView) {
                //title.setText("Amaze File Manager");
                // creates call to onPrepareOptionsMenu()
            }
        };
        mDrawerLayout.setDrawerListener(mDrawerToggle);
        mainActivity.getSupportActionBar().setHomeAsUpIndicator(R.drawable.ic_drawer_l);
        mainActivity.getSupportActionBar().setDisplayHomeAsUpEnabled(true);
        mainActivity.getSupportActionBar().setHomeButtonEnabled(true);
        mDrawerToggle.syncState();
    }

}

From source file:com.shine.demo.viewpager.smartTabLayout.SmartTabLayout.java

public SmartTabLayout(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);

    // Disable the Scroll Bar
    setHorizontalScrollBarEnabled(false);

    final DisplayMetrics dm = getResources().getDisplayMetrics();
    final float density = dm.density;

    int tabBackgroundResId = NO_ID;
    boolean textAllCaps = TAB_VIEW_TEXT_ALL_CAPS;
    ColorStateList textColors;//  ww  w.  j ava  2 s . co m
    float textSize = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP, TAB_VIEW_TEXT_SIZE_SP, dm);
    int textHorizontalPadding = (int) (TAB_VIEW_PADDING_DIPS * density);
    int textMinWidth = (int) (TAB_VIEW_TEXT_MIN_WIDTH * density);
    boolean distributeEvenly = DEFAULT_DISTRIBUTE_EVENLY;
    int customTabLayoutId = NO_ID;
    int customTabTextViewId = NO_ID;
    boolean clickable = TAB_CLICKABLE;
    int titleOffset = (int) (TITLE_OFFSET_DIPS * density);

    TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.stl_SmartTabLayout, defStyle, 0);
    tabBackgroundResId = a.getResourceId(R.styleable.stl_SmartTabLayout_stl_defaultTabBackground,
            tabBackgroundResId);
    textAllCaps = a.getBoolean(R.styleable.stl_SmartTabLayout_stl_defaultTabTextAllCaps, textAllCaps);
    textColors = a.getColorStateList(R.styleable.stl_SmartTabLayout_stl_defaultTabTextColor);
    textSize = a.getDimension(R.styleable.stl_SmartTabLayout_stl_defaultTabTextSize, textSize);
    textHorizontalPadding = a.getDimensionPixelSize(
            R.styleable.stl_SmartTabLayout_stl_defaultTabTextHorizontalPadding, textHorizontalPadding);
    textMinWidth = a.getDimensionPixelSize(R.styleable.stl_SmartTabLayout_stl_defaultTabTextMinWidth,
            textMinWidth);
    customTabLayoutId = a.getResourceId(R.styleable.stl_SmartTabLayout_stl_customTabTextLayoutId,
            customTabLayoutId);
    customTabTextViewId = a.getResourceId(R.styleable.stl_SmartTabLayout_stl_customTabTextViewId,
            customTabTextViewId);
    distributeEvenly = a.getBoolean(R.styleable.stl_SmartTabLayout_stl_distributeEvenly, distributeEvenly);
    clickable = a.getBoolean(R.styleable.stl_SmartTabLayout_stl_clickable, clickable);
    titleOffset = a.getLayoutDimension(R.styleable.stl_SmartTabLayout_stl_titleOffset, titleOffset);
    a.recycle();

    this.titleOffset = titleOffset;
    this.tabViewBackgroundResId = tabBackgroundResId;
    this.tabViewTextAllCaps = textAllCaps;
    this.tabViewTextColors = (textColors != null) ? textColors : ColorStateList.valueOf(TAB_VIEW_TEXT_COLOR);
    this.tabViewTextSize = textSize;
    this.tabViewTextHorizontalPadding = textHorizontalPadding;
    this.tabViewTextMinWidth = textMinWidth;
    this.internalTabClickListener = clickable ? new InternalTabClickListener() : null;
    this.distributeEvenly = distributeEvenly;

    if (customTabLayoutId != NO_ID) {
        setCustomTabView(customTabLayoutId, customTabTextViewId);
    }

    this.tabStrip = new SmartTabStrip(context, attrs);

    if (distributeEvenly && tabStrip.isIndicatorAlwaysInCenter()) {
        throw new UnsupportedOperationException(
                "'distributeEvenly' and 'indicatorAlwaysInCenter' both use does not support");
    }

    this.tabViewTextColors = new ColorStateList(
            new int[][] { new int[] { android.R.attr.state_pressed },
                    new int[] { android.R.attr.state_selected }, new int[] {} },
            new int[] { Color.rgb(255, 111, 51), Color.rgb(255, 111, 51), Color.parseColor("#222222") });

    // Make sure that the Tab Strips fills this View
    setFillViewport(!tabStrip.isIndicatorAlwaysInCenter());

    addView(tabStrip, LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);

}

From source file:connect.app.com.connect.calendar.SimpleMonthView.java

/**
 * Applies the specified text appearance resource to a paint, returning the
 * text color if one is set in the text appearance.
 *
 * @param p the paint to modify//from  w  ww.j  a va2 s .co m
 * @param resId the resource ID of the text appearance
 * @return the text color, if available
 */
private ColorStateList applyTextAppearance(Paint p, int resId) {
    final TypedArray ta = getContext().obtainStyledAttributes(null, R.styleable.TextAppearance, 0, resId);

    //        final String fontFamily = ta.getString(R.styleable.TextAppearance_fontFamily);
    //        if (fontFamily != null) {
    //            p.setTypeface(Typeface.create(fontFamily, 0));
    //        }

    //        p.setTextSize(ta.getDimensionPixelSize(
    //                R.styleable.TextAppearance_textSize, (int) p.getTextSize()));

    //        final ColorStateList textColor = ta.getColorStateList(R.styleable.TextAppearance_textColor);
    //        if (textColor != null) {
    //            final int enabledColor = textColor.getColorForState(ENABLED_STATE_SET, 0);
    //            p.setColor(enabledColor);
    //        }

    ta.recycle();

    return new ColorStateList(new int[][] {}, new int[] {});
}

From source file:com.owncloud.android.utils.ThemeUtils.java

public static void tintCheckbox(AppCompatCheckBox checkBox, int color) {
    CompoundButtonCompat//from  w w  w  . j a  v  a  2s . c  om
            .setButtonTintList(checkBox,
                    new ColorStateList(
                            new int[][] { new int[] { -android.R.attr.state_checked },
                                    new int[] { android.R.attr.state_checked }, },
                            new int[] { Color.GRAY, color }));
}

From source file:com.amaze.filemanager.utils.Futils.java

private ColorStateList createEditTextColorStateList(int color) {
    int[][] states = new int[3][];
    int[] colors = new int[3];
    int i = 0;/*w  ww .j av a2  s .  c o  m*/
    states[i] = new int[] { -android.R.attr.state_enabled };
    colors[i] = Color.parseColor("#f6f6f6");
    i++;
    states[i] = new int[] { -android.R.attr.state_pressed, -android.R.attr.state_focused };
    colors[i] = Color.parseColor("#666666");
    i++;
    states[i] = new int[] {};
    colors[i] = color;
    return new ColorStateList(states, colors);
}

From source file:com.amaze.filemanager.utils.Futils.java

public void setTint(CheckBox box, int color) {
    if (Build.VERSION.SDK_INT >= 21)
        return;/*  w w  w  .ja v a  2s  . c  o  m*/
    ColorStateList sl = new ColorStateList(
            new int[][] { new int[] { -android.R.attr.state_checked },
                    new int[] { android.R.attr.state_checked } },
            new int[] { Color.parseColor("#666666"), color });
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        box.setButtonTintList(sl);
    } else {
        Drawable drawable = DrawableCompat
                .wrap(ContextCompat.getDrawable(box.getContext(), R.drawable.abc_btn_check_material));
        DrawableCompat.setTintList(drawable, sl);
        box.setButtonDrawable(drawable);
    }
}

From source file:com.hezaijin.advance.widgets.view.progress.DiscreteSeekBar.java

public DiscreteSeekBar(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);
    setFocusable(true);/*from ww  w. j  a va2s.  c  o m*/
    setWillNotDraw(false);

    mTouchSlop = ViewConfiguration.get(context).getScaledTouchSlop();
    float density = context.getResources().getDisplayMetrics().density;
    mTrackHeight = (int) (1 * density);
    mScrubberHeight = (int) (4 * density);
    int thumbSize = (int) (density * ThumbDrawable.DEFAULT_SIZE_DP);

    //Extra pixels for a touch area of 48dp
    int touchBounds = (int) (density * 32);
    mAddedTouchBounds = (touchBounds - thumbSize) / 2;

    TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.DiscreteSeekBar,
            R.attr.discreteSeekBarStyle, defStyle);

    int max = 100;
    int min = 0;
    int value = 0;
    mMirrorForRtl = a.getBoolean(R.styleable.DiscreteSeekBar_dsb_mirrorForRtl, mMirrorForRtl);
    mAllowTrackClick = a.getBoolean(R.styleable.DiscreteSeekBar_dsb_allowTrackClickToDrag, mAllowTrackClick);

    int indexMax = R.styleable.DiscreteSeekBar_dsb_max;
    int indexMin = R.styleable.DiscreteSeekBar_dsb_min;
    int indexValue = R.styleable.DiscreteSeekBar_dsb_value;
    final TypedValue out = new TypedValue();
    //Not sure why, but we wanted to be able to use dimensions here...
    if (a.getValue(indexMax, out)) {
        if (out.type == TypedValue.TYPE_DIMENSION) {
            max = a.getDimensionPixelSize(indexMax, max);
        } else {
            max = a.getInteger(indexMax, max);
        }
    }
    if (a.getValue(indexMin, out)) {
        if (out.type == TypedValue.TYPE_DIMENSION) {
            min = a.getDimensionPixelSize(indexMin, min);
        } else {
            min = a.getInteger(indexMin, min);
        }
    }
    if (a.getValue(indexValue, out)) {
        if (out.type == TypedValue.TYPE_DIMENSION) {
            value = a.getDimensionPixelSize(indexValue, value);
        } else {
            value = a.getInteger(indexValue, value);
        }
    }

    mMin = min;
    mMax = Math.max(min + 1, max);
    mValue = Math.max(min, Math.min(max, value));
    updateKeyboardRange();

    mIndicatorFormatter = a.getString(R.styleable.DiscreteSeekBar_dsb_indicatorFormatter);

    ColorStateList trackColor = a.getColorStateList(R.styleable.DiscreteSeekBar_dsb_trackColor);
    ColorStateList progressColor = a.getColorStateList(R.styleable.DiscreteSeekBar_dsb_progressColor);
    ColorStateList rippleColor = a.getColorStateList(R.styleable.DiscreteSeekBar_dsb_rippleColor);
    boolean editMode = isInEditMode();
    if (editMode && rippleColor == null) {
        rippleColor = new ColorStateList(new int[][] { new int[] {} }, new int[] { Color.DKGRAY });
    }
    if (editMode && trackColor == null) {
        trackColor = new ColorStateList(new int[][] { new int[] {} }, new int[] { Color.GRAY });
    }
    if (editMode && progressColor == null) {
        progressColor = new ColorStateList(new int[][] { new int[] {} }, new int[] { 0xff009688 });
    }
    mRipple = SeekBarCompat.getRipple(rippleColor);
    if (isLollipopOrGreater) {
        SeekBarCompat.setBackground(this, mRipple);
    } else {
        mRipple.setCallback(this);
    }

    TrackRectDrawable shapeDrawable = new TrackRectDrawable(trackColor);
    mTrack = shapeDrawable;
    mTrack.setCallback(this);

    shapeDrawable = new TrackRectDrawable(progressColor);
    mScrubber = shapeDrawable;
    mScrubber.setCallback(this);

    ThumbDrawable thumbDrawable = new ThumbDrawable(progressColor, thumbSize);
    mThumb = thumbDrawable;
    mThumb.setCallback(this);
    mThumb.setBounds(0, 0, mThumb.getIntrinsicWidth(), mThumb.getIntrinsicHeight());

    if (!editMode) {
        mIndicator = new PopupIndicator(context, attrs, defStyle, convertValueToMessage(mMax));
        mIndicator.setValue(convertValueToMessage(mValue));
        mIndicator.setListener(mFloaterListener);
    }
    a.recycle();

    setNumericTransformer(new DefaultNumericTransformer());

}