Example usage for android.content.res ColorStateList valueOf

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

Introduction

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

Prototype

@NonNull
public static ColorStateList valueOf(@ColorInt int color) 

Source Link

Usage

From source file:com.acious.android.paginationseekbar.PaginationSeekBar.java

public void setThumbColor(int startColor, int endColor) {
    mThumb.setColorStateList(ColorStateList.valueOf(startColor));
    mIndicator.setColors(startColor, endColor);
}

From source file:xyz.berial.textinputlayout.TextInputLayout.java

/**
 * Sets the hint text color, size, style from the specified TextAppearance resource.
 *
 * @attr ref android.support.design.R.styleable#TextInputLayout_hintTextAppearance
 *//*from w  ww.  j av a 2  s  . c om*/
public void setHintTextAppearance(@StyleRes int resId) {
    mCollapsingTextHelper.setCollapsedTextAppearance(resId);
    mFocusedTextColor = ColorStateList.valueOf(mCollapsingTextHelper.getCollapsedTextColor());

    if (mEditText != null) {
        updateLabelVisibility(false);

        // Text size might have changed so update the top margin
        LayoutParams lp = updateEditTextMargin(mEditText.getLayoutParams());
        mEditText.setLayoutParams(lp);
        mEditText.requestLayout();
    }
}

From source file:org.xbmc.kore.ui.sections.video.TVShowProgressFragment.java

/**
 * Display the seasons list/*from   w w w  . jav a  2  s .c  om*/
 *
 * @param cursor Cursor with the data
 */
private void displaySeasonList(Cursor cursor) {
    TextView seasonsListTitle = (TextView) getActivity().findViewById(R.id.seasons_title);
    GridLayout seasonsList = (GridLayout) getActivity().findViewById(R.id.seasons_list);

    if (cursor.moveToFirst()) {
        seasonsListTitle.setVisibility(View.VISIBLE);
        seasonsList.setVisibility(View.VISIBLE);

        HostManager hostManager = HostManager.getInstance(getActivity());

        View.OnClickListener seasonListClickListener = new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                listenerActivity.onSeasonSelected(itemId, (int) v.getTag());
            }
        };

        // Get the art dimensions
        Resources resources = getActivity().getResources();
        int artWidth = (int) (resources.getDimension(R.dimen.seasonlist_art_width)
                / UIUtils.IMAGE_RESIZE_FACTOR);
        int artHeight = (int) (resources.getDimension(R.dimen.seasonlist_art_heigth)
                / UIUtils.IMAGE_RESIZE_FACTOR);

        // Get theme colors
        Resources.Theme theme = getActivity().getTheme();
        TypedArray styledAttributes = theme
                .obtainStyledAttributes(new int[] { R.attr.colorinProgress, R.attr.colorFinished });

        int inProgressColor = styledAttributes.getColor(styledAttributes.getIndex(0),
                resources.getColor(R.color.orange_500));
        int finishedColor = styledAttributes.getColor(styledAttributes.getIndex(1),
                resources.getColor(R.color.green_400));
        styledAttributes.recycle();

        seasonsList.removeAllViews();
        do {
            int seasonNumber = cursor.getInt(SeasonsListQuery.SEASON);
            String thumbnail = cursor.getString(SeasonsListQuery.THUMBNAIL);
            int numEpisodes = cursor.getInt(SeasonsListQuery.EPISODE);
            int watchedEpisodes = cursor.getInt(SeasonsListQuery.WATCHEDEPISODES);

            View seasonView = LayoutInflater.from(getActivity()).inflate(R.layout.grid_item_season, seasonsList,
                    false);

            ImageView seasonPictureView = (ImageView) seasonView.findViewById(R.id.art);
            TextView seasonNumberView = (TextView) seasonView.findViewById(R.id.season);
            TextView seasonEpisodesView = (TextView) seasonView.findViewById(R.id.episodes);
            ProgressBar seasonProgressBar = (ProgressBar) seasonView.findViewById(R.id.season_progress_bar);

            seasonNumberView
                    .setText(String.format(getActivity().getString(R.string.season_number), seasonNumber));
            seasonEpisodesView.setText(String.format(getActivity().getString(R.string.num_episodes),
                    numEpisodes, numEpisodes - watchedEpisodes));
            seasonProgressBar.setMax(numEpisodes);
            seasonProgressBar.setProgress(watchedEpisodes);

            if (Utils.isLollipopOrLater()) {
                int watchedColor = (numEpisodes - watchedEpisodes == 0) ? finishedColor : inProgressColor;
                seasonProgressBar.setProgressTintList(ColorStateList.valueOf(watchedColor));
            }

            UIUtils.loadImageWithCharacterAvatar(getActivity(), hostManager, thumbnail,
                    String.valueOf(seasonNumber), seasonPictureView, artWidth, artHeight);

            seasonView.setTag(seasonNumber);
            seasonView.setOnClickListener(seasonListClickListener);
            seasonsList.addView(seasonView);
        } while (cursor.moveToNext());
    } else {
        // No seasons, hide views
        seasonsListTitle.setVisibility(View.GONE);
        seasonsList.setVisibility(View.GONE);
    }
}

From source file:ticwear.design.widget.FloatingActionButton.java

/**
 * Set the ripple color for this {@link FloatingActionButton}.
 * <p>/*w ww. j av a 2s  .c om*/
 * When running on devices with KitKat or below, we draw a fill rather than a ripple.
 *
 * @param color ARGB color to use for the ripple.
 */
public void setRippleColor(@ColorInt int color) {
    if (getRippleDrawable() != null) {
        getRippleDrawable().setColor(ColorStateList.valueOf(color));
    }
}

From source file:de.vanita5.twittnuker.util.ThemeUtils.java

private static void applyColorTintForView(View view, int tintColor) {
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP)
        return;// ww  w.  j  av  a  2 s .  c  om
    if (view instanceof IThemedView) {
        final ColorStateList tintList = ColorStateList.valueOf(tintColor);
        ((IThemedView) view).setThemeTintColor(tintList);
    } else if (view instanceof ProgressBar) {
        final ColorStateList tintList = ColorStateList.valueOf(tintColor);
        final ProgressBar progressBar = (ProgressBar) view;
        ViewAccessor.setProgressTintList(progressBar, tintList);
        ViewAccessor.setProgressBackgroundTintList(progressBar, tintList);
        ViewAccessor.setIndeterminateTintList(progressBar, tintList);
    } else if (view instanceof CompoundButton) {
        final ColorStateList tintList = ColorStateList.valueOf(tintColor);
        final CompoundButton compoundButton = (CompoundButton) view;
        ViewAccessor.setButtonTintList(compoundButton, tintList);
    }
}

From source file:com.example.mego.adas.main.UserFragment.java

/**
 * implement the click of the floating action button click
 *///from   w  ww.ja v a2  s  .  com
@Override
public void onClick(View v) {
    if (NetworkUtil.isAvailableInternetConnection(getContext())) {

        switch (v.getId()) {
        case R.id.lights_on_button_user:
            if (lightsState == 0) {

                //change the button color to the accent color when it's on
                lightsButton
                        .setBackgroundTintList(ColorStateList.valueOf(getResources().getColor(R.color.off)));

                //send the state of the lights to the firebase
                lightsState = 1;
                lightsStateDatabaseReference.setValue(lightsState);

            } else if (lightsState == 1) {
                //change the button color to the accent color when it's on
                lightsButton.setBackgroundTintList(
                        ColorStateList.valueOf(getResources().getColor(R.color.colorPrimary)));

                //send the state of the lights to the firebase
                lightsState = 0;
                lightsStateDatabaseReference.setValue(lightsState);
            }
            break;
        case R.id.lock_user_button:
            if (lockState == 0) {
                //change the button color to the accent color when it's on
                lockButton.setBackgroundTintList(ColorStateList.valueOf(getResources().getColor(R.color.off)));

                lockButton.setImageResource(R.drawable.lock_outline);

                //send the state of the lock to the firebase
                lockState = 1;
                lockStateDatabaseReference.setValue(lockState);

            } else if (lockState == 1) {
                //change the button color to the accent color when it's on
                lockButton.setBackgroundTintList(
                        ColorStateList.valueOf(getResources().getColor(R.color.colorPrimary)));

                lockButton.setImageResource(R.drawable.lock_open_outline);

                //send the state of the lock to the firebase
                lockState = 0;
                lockStateDatabaseReference.setValue(lockState);
            }
            break;

        case R.id.start_user_button:
            if (startState == 0) {
                //change the button color to the accent color when it's on
                startButton.setBackgroundTintList(ColorStateList.valueOf(getResources().getColor(R.color.off)));

                //send the state of the start to the firebase
                startState = 1;
                startStateStateDatabaseReference.setValue(startState);
            } else if (startState == 1) {
                //change the button color to the accent color when it's on
                startButton.setBackgroundTintList(
                        ColorStateList.valueOf(getResources().getColor(R.color.colorPrimary)));

                //send the state of the start to the firebase
                startState = 0;
                startStateStateDatabaseReference.setValue(startState);
            }
            break;
        case R.id.user_location_button:
            if (locationButtonClicked == 0) {
                if (userConnected == 1) {
                    if (userFragments.isAdded()) {

                        //change the button color to the accent color when it's on
                        userLocationButton.setBackgroundTintList(
                                ColorStateList.valueOf(getResources().getColor(R.color.off)));

                        locationButtonClicked = 1;
                        accidentPlace = new LatLng(userLatitude, userLatitude);

                        cameraPosition = CameraPosition.builder()
                                .target(new LatLng(userLatitude, userLongitude)).zoom(zoom).bearing(bearing)
                                .tilt(tilt).build();

                        //check for the map state if it's ready start
                        if (mapReady) {

                            carPlace = new MarkerOptions().position(new LatLng(userLatitude, userLongitude))
                                    .title("My Place")
                                    .icon(BitmapDescriptorFactory.fromResource(R.drawable.ic_user_marker));

                            userMarker = mMap.addMarker(carPlace);
                            flyTo(cameraPosition);
                        }
                    }
                }
            } else if (locationButtonClicked == 1) {
                if (userFragments.isAdded()) {
                    //change the button color to the accent color when it's on
                    userLocationButton.setBackgroundTintList(
                            ColorStateList.valueOf(getResources().getColor(R.color.colorPrimary)));
                    locationButtonClicked = 0;
                    userMarker.remove();
                }
            }
            break;
        }
    }
}

From source file:com.example.mego.adas.main.CarFragment.java

/**
 * implement the click of the floating action button click
 *//*from   ww w  .j  ava 2  s.  c  om*/
@Override
public void onClick(View v) {
    switch (v.getId()) {
    case R.id.lights_on_button:
        if (lightsState == 0) {

            //change the button color to the accent color when it's on
            lightsButton.setBackgroundTintList(ColorStateList.valueOf(getResources().getColor(R.color.off)));
            if (connected) {
                sendBluetoothCommand("o");
            }
            //send the state of the lights to the firebase
            lightsState = 1;
            if (NetworkUtil.isAvailableInternetConnection(getContext())) {
                lightsStateDatabaseReference.setValue(lightsState);
            }

        } else if (lightsState == 1) {
            //change the button color to the accent color when it's on
            lightsButton.setBackgroundTintList(
                    ColorStateList.valueOf(getResources().getColor(R.color.colorPrimary)));
            if (connected) {
                sendBluetoothCommand("f");
            }
            //send the state of the lights to the firebase
            lightsState = 0;
            if (NetworkUtil.isAvailableInternetConnection(getContext())) {
                lightsStateDatabaseReference.setValue(lightsState);
            }
        }
        break;
    case R.id.lock_car_button:
        if (lockState == 0) {
            //change the button color to the accent color when it's on
            lockButton.setBackgroundTintList(ColorStateList.valueOf(getResources().getColor(R.color.off)));
            if (connected) {
                sendBluetoothCommand("r");
            }

            lockButton.setImageResource(R.drawable.lock_outline);

            //send the state of the lock to the firebase
            lockState = 1;
            if (NetworkUtil.isAvailableInternetConnection(getContext())) {
                lockStateDatabaseReference.setValue(lockState);
            }

        } else if (lockState == 1) {
            //change the button color to the accent color when it's on
            lockButton.setBackgroundTintList(
                    ColorStateList.valueOf(getResources().getColor(R.color.colorPrimary)));

            if (connected) {
                sendBluetoothCommand("v");
            }

            lockButton.setImageResource(R.drawable.lock_open_outline);

            //send the state of the lock to the firebase
            lockState = 0;
            if (NetworkUtil.isAvailableInternetConnection(getContext())) {
                lockStateDatabaseReference.setValue(lockState);
            }
        }
        break;

    case R.id.start_car_button:
        if (startState == 0) {
            //change the button color to the accent color when it's on
            startButton.setBackgroundTintList(ColorStateList.valueOf(getResources().getColor(R.color.off)));

            if (connected) {
                sendBluetoothCommand("p");
            }

            //send the state of the start to the firebase
            startState = 1;
            if (NetworkUtil.isAvailableInternetConnection(getContext())) {
                startStateStateDatabaseReference.setValue(startState);
            }
        } else if (startState == 1) {
            //change the button color to the accent color when it's on
            startButton.setBackgroundTintList(
                    ColorStateList.valueOf(getResources().getColor(R.color.colorPrimary)));

            if (connected) {
                sendBluetoothCommand("t");
            }

            //send the state of the start to the firebase
            startState = 0;
            if (NetworkUtil.isAvailableInternetConnection(getContext())) {
                startStateStateDatabaseReference.setValue(startState);
            }
        }
        break;
    case R.id.disconnect_button:
        if (connectionState == 0) {
            //change the button color to the accent color when it's on
            disconnectButton.setBackgroundTintList(
                    ColorStateList.valueOf(getResources().getColor(R.color.colorPrimary)));
        } else if (connectionState == 1) {
            //change the button color to the accent color when it's on
            disconnectButton
                    .setBackgroundTintList(ColorStateList.valueOf(getResources().getColor(R.color.off)));

            //send the state of the connection to the firebase
            showLoseConnectionDialog(getString(R.string.are_you_sure_to_lose_connection));
        }
        break;
    }

}

From source file:com.fastaccess.ui.modules.repos.RepoPagerActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    if (savedInstanceState == null) {
        if (getIntent() == null || getIntent().getExtras() == null) {
            finish();/*from ww  w. ja v  a 2 s .  co  m*/
            return;
        }
        final Bundle extras = getIntent().getExtras();
        repoId = extras.getString(BundleConstant.ID);
        login = extras.getString(BundleConstant.EXTRA_TWO);
        navType = extras.getInt(BundleConstant.EXTRA_TYPE);
    }
    if (savedInstanceState == null) {
        getPresenter().onUpdatePinnedEntry(repoId, login);
    }
    getPresenter().onActivityCreate(repoId, login, navType);
    setTitle("");
    accentColor = ViewHelper.getAccentColor(this);
    iconColor = ViewHelper.getIconColor(this);
    if (savedInstanceState == null) {
        getSupportFragmentManager().beginTransaction().add(R.id.container, new DummyFragment(), "DummyFragment")
                .commit();
    }
    Typeface myTypeface = TypeFaceHelper.getTypeface();
    bottomNavigation.setDefaultTypeface(myTypeface);
    fab.setImageTintList(ColorStateList.valueOf(Color.WHITE));
    showHideFab();
}

From source file:com.doomy.library.DiscreteSeekBar.java

/**
 * Sets the color of the seek thumb, as well as the color of the popup indicator.
 *
 * @param startColor The color the seek thumb will be changed to
 * @param endColor   The color the popup indicator will be changed to
 *//*  ww  w.j a v  a 2s .com*/
public void setThumbColor(int startColor, int endColor) {
    mThumb.setColorStateList(ColorStateList.valueOf(startColor));
    mIndicator.setColors(startColor, endColor);
}

From source file:com.elekso.potfix.MainActivity.java

@SuppressWarnings("StatementWithEmptyBody")
@Override//from ww w.  ja  va  2  s .c o m
public boolean onNavigationItemSelected(MenuItem item) {
    // Handle navigation view item clicks here.
    int id = item.getItemId();
    Fragment newFragment = null;

    if (id == R.id.nav_profile) {
        currentFragment = 1;
        newFragment = new ProfileFragment();
        fab.setRippleColor(Color.parseColor("#99ff66"));
        fab.setBackgroundTintList(ColorStateList.valueOf(Color.parseColor("#00CC33")));
        fab.setImageResource(R.drawable.ic_autorenew_white_36dp);

    } else if (id == R.id.nav_map) {
        currentFragment = 2;
        newFragment = new MapsFragment();
        fab.setRippleColor(Color.parseColor("#78D6F3"));
        fab.setBackgroundTintList(ColorStateList.valueOf(Color.parseColor("#039FDC")));
        fab.setImageResource(R.drawable.ic_gps_fixed_white_24dp);

        //        } else if (id == R.id.nav_news) {
        //            newFragment = new NewsFragment();
        //            fab.setImageResource(android.R.drawable.ic_dialog_info);
        //        } else if (id == R.id.nav_setting) {
        //            newFragment = new SettingFragment();
        //            fab.setImageResource(R.drawable.ic_settings_white_24dp);
    } else if (id == R.id.nav_share) {
        currentFragment = 3;
        newFragment = new ShareFragment();
        fab.setRippleColor(Color.parseColor("#FF7F50"));
        fab.setBackgroundTintList(ColorStateList.valueOf(Color.parseColor("#FF2400")));
        fab.setImageResource(android.R.drawable.ic_dialog_email);
    } else if (id == R.id.nav_license) {
        currentFragment = 4;
        newFragment = new LicenseFragment();
        fab.setRippleColor(Color.parseColor("#FFFFFF"));
        fab.setBackgroundTintList(ColorStateList.valueOf(Color.parseColor("#808080")));
        fab.setImageResource(R.drawable.ic_done_white_24dp);
    }

    DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
    drawer.closeDrawer(GravityCompat.START);
    FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
    transaction.replace(R.id.frame_containerone, newFragment);
    transaction.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN);
    //  transaction.addToBackStack(null);
    transaction.commit();
    return true;
}