List of usage examples for android.content.res ColorStateList valueOf
@NonNull public static ColorStateList valueOf(@ColorInt int color)
From source file:com.sbgapps.scoreit.ScoreItActivity.java
private void setActionButtonColor() { if (null == mLap) { mActionButton.setImageDrawable(ContextCompat.getDrawable(this, R.drawable.ic_plus_24dp)); mActionButton.setBackgroundTintList( ColorStateList.valueOf(ContextCompat.getColor(this, R.color.color_accent))); } else {//from ww w . j av a 2 s . c om mActionButton.setImageDrawable(ContextCompat.getDrawable(this, R.drawable.ic_done_24dp)); mActionButton.setBackgroundTintList( ColorStateList.valueOf(ContextCompat.getColor(this, R.color.color_primary))); } }
From source file:org.rebo.app.TileMap.java
public void toggleCompass(Compass.Mode mode) { if (mode == null) { switch (mCompass.getMode()) { case OFF: mode = Compass.Mode.C2D;//from w w w . java2 s . c o m break; default: mode = Compass.Mode.OFF; break; } } ((Vibrator) getSystemService(Context.VIBRATOR_SERVICE)).vibrate(50); mCompass.setMode(mode); switch (mode) { case NAV: mCompassFab.setBackgroundTintList(ColorStateList .valueOf(ColorUtils.adjustAlpha(getResources().getColor(R.color.colorAccent), 0.4f))); break; case C2D: mCompassFab.setBackgroundTintList(ColorStateList .valueOf(ColorUtils.adjustAlpha(getResources().getColor(R.color.colorAccent), 0.4f))); //App.activity.showToastOnUiThread("Compass 2D"); break; case C3D: mCompassFab.setBackgroundTintList(ColorStateList .valueOf(ColorUtils.adjustAlpha(getResources().getColor(R.color.colorSecondAccent), 0.4f))); //App.activity.showToastOnUiThread("Compass 3D"); break; case OFF: mCompassFab.setBackgroundTintList( ColorStateList.valueOf(ColorUtils.adjustAlpha(getResources().getColor(R.color.white), 0.4f))); mCompass.setRotation(0); mCompass.setTilt(0); //App.activity.showToastOnUiThread("Manual"); break; default: break; } App.map.updateMap(true); }
From source file:com.astir_trotter.atcustom.ui.iconics.core.IconicsDrawable.java
@Override public void setTint(int tintColor) { setTintList(ColorStateList.valueOf(tintColor)); }
From source file:org.huxizhijian.hhcomicviewer.ui.entry.ComicDetailsActivity.java
private void updateViews() { //?/* ww w. j a v a 2 s .c o m*/ mBinding.comicAuthorComicDetails.setVisibility(View.VISIBLE); mBinding.comicAuthorComicDetails.setText(mComic.getAuthor()); mBinding.comicVolStatusComicDetails.setText(mComic.getComicStatus()); mBinding.comicFavoriteNumberComicDetails.setText(mComic.getComicFavorite()); mBinding.comicUpdateTimeComicDetails.setText(mComic.getComicUpdateTime()); // mBinding.comicDescriptionComicDetails.setText(mComic.getDescription()); //? mBinding.comicDescriptionComicDetailsBack.setVisibility(View.VISIBLE); mBinding.comicDescriptionComicDetailsBack.setText(mComic.getDescription()); final ViewTreeObserver vto1 = mBinding.comicDescriptionComicDetails.getViewTreeObserver(); vto1.addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() { @Override public void onGlobalLayout() { mDetailsHeight = mBinding.comicDescriptionComicDetails.getHeight(); //?? mBinding.comicDescriptionComicDetails.getViewTreeObserver().removeGlobalOnLayoutListener(this); } }); //?tv_back ViewTreeObserver vto = mBinding.comicDescriptionComicDetailsBack.getViewTreeObserver(); vto.addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() { @Override public void onGlobalLayout() { mBackHeight = mBinding.comicDescriptionComicDetailsBack.getHeight(); mBinding.comicDescriptionComicDetailsBack.getViewTreeObserver().removeGlobalOnLayoutListener(this); // if (mBackHeight > mDetailsHeight) { // mBinding.ivArrow.setVisibility(View.VISIBLE); //? mBinding.comicDescriptionComicDetails.setTag(true); isDescriptionCanOpen = true; } else { mBinding.ivArrow.setVisibility(View.GONE); isDescriptionCanOpen = false; } mBinding.comicDescriptionComicDetailsBack.setVisibility(View.GONE); } }); //? mBinding.ratingBarComicDetails.setRating((mComic.getRatingNumber() / 10.0f) * 5.0f); mBinding.ratingBarDescriptionComicDetails.setText(mComic.getRatingNumber() + "(10), " + "" + mComic.getRatingPeopleNum() + ""); // if (mComic.isMark() || mComic.isDownload()) { mVolAdapter = new VolRecyclerViewAdapter(ComicDetailsActivity.this, mComic.getChapterName(), mComic.getReadChapter(), mFinishedComicChapters); } else { mVolAdapter = new VolRecyclerViewAdapter(ComicDetailsActivity.this, mComic.getChapterName(), mFinishedComicChapters); } //?RecyclerView mBinding.recyclerViewComicDetails .setLayoutManager(new FullyGridLayoutManager(ComicDetailsActivity.this, 4)); mBinding.recyclerViewComicDetails.setItemAnimator(new DefaultItemAnimator()); mBinding.recyclerViewComicDetails.setHasFixedSize(true); mBinding.recyclerViewComicDetails.setNestedScrollingEnabled(false); mVolAdapter.setOnItemClickListener(new VolRecyclerViewAdapter.OnItemClickListener() { @Override public void onItemClick(View view, int position) { Intent intent = new Intent(ComicDetailsActivity.this, GalleryActivity.class); intent.putExtra("comic", mComic); intent.putExtra("position", position); startActivityForResult(intent, 0); } @Override public void onItemLongClick(View view, int position) { } }); mBinding.recyclerViewComicDetails.setAdapter(mVolAdapter); mBinding.recyclerViewComicDetails.setFocusable(false); mBinding.nestScrollViewComicDetails.setFocusable(true); mBinding.nestScrollViewComicDetails.smoothScrollBy(0, 0); //?? if (mComic.isMark()) { mBinding.btnFavoriteComicDetails.setImageResource(R.mipmap.my_favorite); mBinding.buttonTextFavoriteComicDetails.setText("?"); } //? mBinding.FABComicDetails.setOnClickListener(this); mBinding.readButton.setOnClickListener(this); // mBinding.btnFavorite.setOnClickListener(this); mBinding.btnShare.setOnClickListener(this); mBinding.btnFind.setOnClickListener(this); mBinding.btnDownload.setOnClickListener(this); // mBinding.comicAuthorComicDetails.setOnClickListener(this); mBinding.comicDescriptionComicDetailsLl.setOnClickListener(this); //?? mBinding.FABComicDetails .setBackgroundTintList(ColorStateList.valueOf(getResources().getColor(R.color.colorAccent))); mBinding.linearLayoutComicDetails.setVisibility(View.VISIBLE); Animation alpha = AnimationUtils.loadAnimation(this, R.anim.alpha_in); //? alpha.setInterpolator(new AccelerateInterpolator()); mBinding.linearLayoutComicDetails.startAnimation(alpha); }
From source file:eu.long1.spacetablayout.SpaceTabLayout.java
public void setButtonColor(@ColorInt int backgroundColor) { actionButton.setBackgroundTintList(ColorStateList.valueOf(backgroundColor)); }
From source file:com.mukesh.OtpView.java
/** * Sets the line color for all the states (normal, selected, * focused) to be this color./*www .j av a 2 s .c om*/ * * @param color A color value in the form 0xAARRGGBB. * Do not pass a resource ID. To get a color value from a resource ID, call * {@link android.support.v4.content.ContextCompat#getColor(Context, int) getColor}. * @attr ref R.styleable#OtpView_lineColor * @see #setLineColor(ColorStateList) * @see #getLineColors() */ public void setLineColor(@ColorInt int color) { lineColor = ColorStateList.valueOf(color); updateColors(); }
From source file:com.example.mego.adas.main.UserFragment.java
/** * method to get the data from the firebase and take action based on it *///from ww w. ja v a 2 s. c om private void actionResolver() { startStateEventListener = new ValueEventListener() { @Override public void onDataChange(DataSnapshot dataSnapshot) { if (dataSnapshot.exists()) { startState = (long) dataSnapshot.getValue(); if (startState == 1) { if (userFragments.isAdded()) { //change the button color to the accent color when it's on startButton.setBackgroundTintList( ColorStateList.valueOf(getResources().getColor(R.color.off))); } } else if (startState == 0) { //change the button color to the accent color when it's on if (userFragments.isAdded()) { startButton.setBackgroundTintList( ColorStateList.valueOf(getResources().getColor(R.color.colorPrimary))); } } } } @Override public void onCancelled(DatabaseError databaseError) { } }; lockStateEventListener = new ValueEventListener() { @Override public void onDataChange(DataSnapshot dataSnapshot) { if (dataSnapshot.exists()) { lockState = (long) dataSnapshot.getValue(); if (lockState == 1) { if (userFragments.isAdded()) { //change the button color to the accent color when it's on lockButton.setBackgroundTintList( ColorStateList.valueOf(getResources().getColor(R.color.off))); } } else if (lockState == 0) { //change the button color to the accent color when it's on if (userFragments.isAdded()) { lockButton.setBackgroundTintList( ColorStateList.valueOf(getResources().getColor(R.color.colorPrimary))); } } } } @Override public void onCancelled(DatabaseError databaseError) { } }; lightsStateEventListener = new ValueEventListener() { @Override public void onDataChange(DataSnapshot dataSnapshot) { if (dataSnapshot.exists()) { lightsState = (long) dataSnapshot.getValue(); if (lightsState == 1) { if (userFragments.isAdded()) { //change the button color to the accent color when it's on lightsButton.setBackgroundTintList( ColorStateList.valueOf(getResources().getColor(R.color.off))); } } else if (lightsState == 0) { if (userFragments.isAdded()) { //change the button color to the accent color when it's on lightsButton.setBackgroundTintList( ColorStateList.valueOf(getResources().getColor(R.color.colorPrimary))); } } } } @Override public void onCancelled(DatabaseError databaseError) { } }; sensorsValueEventListener = new ValueEventListener() { @Override public void onDataChange(DataSnapshot dataSnapshot) { if (dataSnapshot.exists()) { SensorsValues sensorsValues = dataSnapshot.getValue(SensorsValues.class); //get the data from the firebase tempSensorValue = sensorsValues.getTemperatureSensorValue(); tempPublishProcessor.onNext(tempSensorValue); //Temperature in Fahrenheit tempSensorInFahrenheit = (int) AdasUtils.celsiusToFahrenheit(tempSensorValue); ldrSensorValue = sensorsValues.getLdrSensorValue(); ldrPublishProcessor.onNext(ldrSensorValue); potSensorValue = sensorsValues.getPotSensorValue(); potPublishProcessor.onNext(potSensorValue); refreshUI(); } else { showToast(getString(R.string.no_car_for_this_user)); //progressDialog.dismiss(); } } @Override public void onCancelled(DatabaseError databaseError) { } }; mappingServicesEventListener = new ValueEventListener() { @Override public void onDataChange(DataSnapshot dataSnapshot) { if (dataSnapshot.exists()) { MappingServices mappingServices = dataSnapshot.getValue(MappingServices.class); latitude = mappingServices.getLatitude(); longitude = mappingServices.getLongitude(); if (onConnectedFlag <= 1) { onConnectedFlag = mappingServices.getOnConnectedFlag(); } onLocationChangedFlag = mappingServices.getOnLocationChangedFlag(); accidentPlace = new LatLng(latitude, longitude); cameraPosition = CameraPosition.builder().target(new LatLng(latitude, longitude)).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(latitude, longitude)).title("Car Place") .icon(BitmapDescriptorFactory.fromResource(R.drawable.ic_marker)); if (onConnectedFlag == 1) { marker = mMap.addMarker(carPlace); flyTo(cameraPosition); } if (onLocationChangedFlag == 1) { DirectionsApiUtilities.AnimateMarker(marker, accidentPlace, false, mMap); cameraPosition = new CameraPosition.Builder().target(accidentPlace).zoom(zoom) .bearing(bearing).tilt(tilt).build(); mMap.animateCamera(CameraUpdateFactory.newCameraPosition(cameraPosition)); } if (onConnectedFlag < 5) { onConnectedFlag++; } } } } @Override public void onCancelled(DatabaseError databaseError) { } }; accidentStateEventListener = new ValueEventListener() { @Override public void onDataChange(DataSnapshot dataSnapshot) { if (dataSnapshot.exists()) { Circle circle = null; accidentState = (long) dataSnapshot.getValue(); if (accidentState == 1) { accidentNotificationFlag++; if (accidentNotificationFlag == 1) { showAccidentHappenDialog(); circle = mMap.addCircle(new CircleOptions().center(accidentPlace).radius(50) .strokeColor(getResources().getColor((R.color.red))) .fillColor(Color.argb(64, 255, 0, 0))); //NotificationUtils.showAccidentNotification(getContext()); } } else if (accidentState == 0) { accidentNotificationFlag = 0; if (circle != null) { circle.remove(); } } } } @Override public void onCancelled(DatabaseError databaseError) { } }; connectionStateEventListener = new ValueEventListener() { @Override public void onDataChange(DataSnapshot dataSnapshot) { if (dataSnapshot.exists()) { connectionState = (long) dataSnapshot.getValue(); if (connectionState == 0) { if (userFragments.isAdded()) { makeText(getContext(), R.string.car_not_connected, Toast.LENGTH_LONG).show(); } } else if (connectionState == 1) { if (userFragments.isAdded()) { makeText(getContext(), R.string.car_is_connected, Toast.LENGTH_LONG).show(); } } } } @Override public void onCancelled(DatabaseError databaseError) { } }; //add a listener to the reference mappingServicesDatabaseReference.addValueEventListener(mappingServicesEventListener); accidentStateDatabaseReference.addValueEventListener(accidentStateEventListener); sensorsValuesDatabaseReference.addValueEventListener(sensorsValueEventListener); startStateStateDatabaseReference.addValueEventListener(startStateEventListener); lockStateDatabaseReference.addValueEventListener(lockStateEventListener); lightsStateDatabaseReference.addValueEventListener(lightsStateEventListener); connectionStateDatabaseReference.addValueEventListener(connectionStateEventListener); }
From source file:com.hss01248.toast.supertoast.SuperActivityToast.java
/** * Modify various attributes of the SuperActivityToast before being shown. */// w w w . j a v a 2 s. co m @Override protected void onPrepareShow() { super.onPrepareShow(); // This will take care of many modifications final FrameLayout.LayoutParams layoutParams = new FrameLayout.LayoutParams(this.mStyle.width, this.mStyle.height); // Make some type specific tweaks switch (this.mStyle.type) { case Style.TYPE_STANDARD: break; case Style.TYPE_BUTTON: // If NOT Lollipop frame, give padding on each side if (this.mStyle.frame != Style.FRAME_LOLLIPOP) { this.mStyle.width = FrameLayout.LayoutParams.MATCH_PARENT; this.mStyle.xOffset = BackgroundUtils.convertToDIP(24); this.mStyle.yOffset = BackgroundUtils.convertToDIP(24); } // On a big screen device, show the SuperActivityToast on the bottom left if ((this.mContext.getResources().getConfiguration().screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK) >= Configuration.SCREENLAYOUT_SIZE_LARGE) { this.mStyle.width = BackgroundUtils.convertToDIP(568); this.mStyle.gravity = Gravity.BOTTOM | Gravity.START; } // Set up the Button attributes final Button button = (Button) this.mView.findViewById(R.id.button); button.setBackgroundResource(BackgroundUtils.getButtonBackgroundResource(this.mStyle.frame)); button.setText(this.mStyle.buttonText != null ? this.mStyle.buttonText.toUpperCase() : ""); button.setTypeface(button.getTypeface(), this.mStyle.buttonTypefaceStyle); button.setTextColor(this.mStyle.buttonTextColor); button.setTextSize(this.mStyle.buttonTextSize); if (this.mStyle.frame != Style.FRAME_LOLLIPOP) { this.mView.findViewById(R.id.divider).setBackgroundColor(this.mStyle.buttonDividerColor); // Set an icon resource if desired if (this.mStyle.buttonIconResource > 0) { button.setCompoundDrawablesWithIntrinsicBounds( ResourcesCompat.getDrawable(mContext.getResources(), this.mStyle.buttonIconResource, mContext.getTheme()), null, null, null); } } if (this.mOnButtonClickListener != null) { button.setOnClickListener(new View.OnClickListener() { short clicked = 0; @Override public void onClick(View view) { // Prevent button spamming if (clicked > 0) return; clicked++; mOnButtonClickListener.onClick(view, getButtonToken()); SuperActivityToast.this.dismiss(); } }); } break; case Style.TYPE_PROGRESS_CIRCLE: if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { this.mProgressBar.setIndeterminateTintMode(PorterDuff.Mode.SRC_IN); this.mProgressBar.setIndeterminateTintList(ColorStateList.valueOf(this.mStyle.progressBarColor)); } break; case Style.TYPE_PROGRESS_BAR: if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { this.mProgressBar.setIndeterminateTintMode(PorterDuff.Mode.SRC_IN); this.mProgressBar.setIndeterminateTintList(ColorStateList.valueOf(this.mStyle.progressBarColor)); this.mProgressBar.setProgressTintMode(PorterDuff.Mode.SRC_IN); this.mProgressBar.setProgressTintList(ColorStateList.valueOf(this.mStyle.progressBarColor)); } this.mProgressBar.setProgress(this.mStyle.progress); this.mProgressBar.setMax(this.mStyle.progressMax); this.mProgressBar.setIndeterminate(this.mStyle.progressIndeterminate); break; } layoutParams.width = this.mStyle.width; layoutParams.height = this.mStyle.height; layoutParams.gravity = this.mStyle.gravity; layoutParams.bottomMargin = this.mStyle.yOffset; layoutParams.topMargin = this.mStyle.yOffset; layoutParams.leftMargin = this.mStyle.xOffset; layoutParams.rightMargin = this.mStyle.xOffset; this.mView.setLayoutParams(layoutParams); // Set up touch to dismiss if (this.mStyle.touchToDismiss) { mView.setOnTouchListener(new View.OnTouchListener() { int timesTouched; @Override public boolean onTouch(View v, MotionEvent motionEvent) { // Prevent repetitive touch events if (timesTouched == 0 && motionEvent.getAction() == MotionEvent.ACTION_DOWN) dismiss(); timesTouched++; return false; // Do not consume the event in case a Button listener is set } }); } else { // Make sure no listener is set mView.setOnTouchListener(null); } }
From source file:com.rks.musicx.ui.fragments.PlayingViews.Playing1Fragment.java
private void colorMode(int color) { if (Extras.getInstance().getDarkTheme() || Extras.getInstance().getBlackTheme()) { mSeekBar.setCircleProgressColor(color); mSeekBar.setPointerColor(color); mSeekBar.setPointerHaloColor(color); playpausebutton.setBackgroundTintList(ColorStateList.valueOf(color)); Playing3view.setBackgroundColor(color); mAlbumCoverView.setBorderColor(color); } else {/*from w w w . j av a 2s.c o m*/ mSeekBar.setCircleProgressColor(color); mSeekBar.setPointerColor(color); mSeekBar.setPointerHaloColor(color); playpausebutton.setBackgroundTintList(ColorStateList.valueOf(color)); Playing3view.setBackgroundColor(color); mAlbumCoverView.setBorderColor(color); } }
From source file:com.hss01248.lib.supertoast.SuperActivityToast.java
/** * Modify various attributes of the SuperActivityToast before being shown. *//* w ww . j a va 2 s . com*/ @Override protected void onPrepareShow() { super.onPrepareShow(); // This will take care of many modifications final FrameLayout.LayoutParams layoutParams = new FrameLayout.LayoutParams(this.mStyle.width, this.mStyle.height); // Make some type specific tweaks switch (this.mStyle.type) { case Style.TYPE_STANDARD: break; case Style.TYPE_BUTTON: // If NOT Lollipop frame, give padding on each side if (this.mStyle.frame != Style.FRAME_LOLLIPOP) { this.mStyle.width = FrameLayout.LayoutParams.MATCH_PARENT; this.mStyle.xOffset = BackgroundUtils.convertToDIP(24); this.mStyle.yOffset = BackgroundUtils.convertToDIP(24); } // On a big screen device, show the SuperActivityToast on the bottom left if ((this.mContext.getResources().getConfiguration().screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK) >= Configuration.SCREENLAYOUT_SIZE_LARGE) { this.mStyle.width = BackgroundUtils.convertToDIP(568); this.mStyle.gravity = Gravity.BOTTOM | Gravity.START; } // Set up the Button attributes final Button button = (Button) this.mView.findViewById(R.id.button); button.setBackgroundResource(BackgroundUtils.getButtonBackgroundResource(this.mStyle.frame)); button.setText(this.mStyle.buttonText != null ? this.mStyle.buttonText.toUpperCase() : ""); button.setTypeface(button.getTypeface(), this.mStyle.buttonTypefaceStyle); button.setTextColor(this.mStyle.buttonTextColor); button.setTextSize(this.mStyle.buttonTextSize); if (this.mStyle.frame != Style.FRAME_LOLLIPOP) { this.mView.findViewById(R.id.divider).setBackgroundColor(this.mStyle.buttonDividerColor); // Set an icon resource if desired if (this.mStyle.buttonIconResource > 0) { button.setCompoundDrawablesWithIntrinsicBounds( ResourcesCompat.getDrawable(mContext.getResources(), this.mStyle.buttonIconResource, mContext.getTheme()), null, null, null); } } if (this.mOnButtonClickListener != null) { button.setOnClickListener(new View.OnClickListener() { short clicked = 0; @Override public void onClick(View view) { // Prevent button spamming if (clicked > 0) return; clicked++; mOnButtonClickListener.onClick(view, getButtonToken()); SuperActivityToast.this.dismiss(); } }); } break; case Style.TYPE_PROGRESS_CIRCLE: if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { this.mProgressBar.setIndeterminateTintMode(PorterDuff.Mode.SRC_IN); this.mProgressBar.setIndeterminateTintList(ColorStateList.valueOf(this.mStyle.progressBarColor)); } break; case Style.TYPE_PROGRESS_BAR: if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { this.mProgressBar.setIndeterminateTintMode(PorterDuff.Mode.SRC_IN); this.mProgressBar.setIndeterminateTintList(ColorStateList.valueOf(this.mStyle.progressBarColor)); this.mProgressBar.setProgressTintMode(PorterDuff.Mode.SRC_IN); this.mProgressBar.setProgressTintList(ColorStateList.valueOf(this.mStyle.progressBarColor)); } this.mProgressBar.setProgress(this.mStyle.progress); this.mProgressBar.setMax(this.mStyle.progressMax); this.mProgressBar.setIndeterminate(this.mStyle.progressIndeterminate); break; } layoutParams.width = this.mStyle.width; layoutParams.height = this.mStyle.height; layoutParams.gravity = this.mStyle.gravity; layoutParams.bottomMargin = this.mStyle.yOffset; layoutParams.topMargin = this.mStyle.yOffset; layoutParams.leftMargin = this.mStyle.xOffset; layoutParams.rightMargin = this.mStyle.xOffset; this.mView.setLayoutParams(layoutParams); // Set up touch to dismiss if (this.mStyle.touchToDismiss) { mView.setOnTouchListener(new View.OnTouchListener() { int timesTouched; @Override public boolean onTouch(View v, MotionEvent motionEvent) { // Prevent repetitive touch events if (timesTouched == 0 && motionEvent.getAction() == MotionEvent.ACTION_DOWN) dismiss(); timesTouched++; return false; // Do not consume the event in case a Button listener is set } }); } else { // Make sure no listener is set mView.setOnTouchListener(null); } }