List of usage examples for android.graphics.drawable GradientDrawable setColor
public void setColor(@Nullable ColorStateList colorStateList)
From source file:com.tmall.wireless.tangram.view.LinearScrollView.java
private void setViewColor(View view, int color) { if (view.getBackground() instanceof GradientDrawable) { GradientDrawable drawable = (GradientDrawable) view.getBackground().mutate(); drawable.setColor(color); }// w ww . ja v a 2 s . c o m }
From source file:com.bobomee.android.recyclerviewhelper.fastscroll.FastScroller.java
private void setBubbleAndHandleColor(int accentColor) { //BubbleDrawable accentColor GradientDrawable bubbleDrawable = GradientDrawableHelper.getGradientDrawable(getContext(), R.drawable.fast_scroller_bubble); assert bubbleDrawable != null; bubbleDrawable.setColor(accentColor); setTextBackground(bubble, bubbleDrawable); //HandleDrawable accentColor StateListDrawable stateListDrawable = StateListDrawableHelper.getStateListDrawable(getContext(), R.drawable.fast_scroller_handle); GradientDrawable handleDrawable = (GradientDrawable) StateListDrawableHelper .getStateDrawable(stateListDrawable, 0); assert handleDrawable != null; handleDrawable.setColor(accentColor); handle.setImageDrawable(stateListDrawable); }
From source file:com.karthikb351.vitinfo2.fragment.today.TodayListAdapter.java
@SuppressLint("NewApi") @SuppressWarnings("deprecation") @Override// w w w . j a v a 2s . c om public void onBindViewHolder(TodayViewHolder todayViewHolder, int position) { int attendancePercentage = 0; int goCalculated = 100; int missCalculated = 0; long timeDifference = 0; boolean ended = false; if (courseTimingPairs.get(position).first.getAttendance().isSupported()) { attendancePercentage = courseTimingPairs.get(position).first.getAttendance().getAttendancePercentage(); goCalculated = ((int) Math .ceil((double) (courseTimingPairs.get(position).first.getAttendance().getAttendedClasses() + courseTimingPairs.get(position).first.getClassLength()) * 100 / (courseTimingPairs.get(position).first.getAttendance().getTotalClasses() + courseTimingPairs.get(position).first.getClassLength()))); missCalculated = ((int) Math .ceil((double) courseTimingPairs.get(position).first.getAttendance().getAttendedClasses() * 100 / (courseTimingPairs.get(position).first.getAttendance().getTotalClasses() + courseTimingPairs.get(position).first.getClassLength()))); } if (courseTimingPairs.get(position).second.getDay() == dayOfWeek) { try { timeDifference = DateTimeCalender.getTimeDifference(courseTimingPairs.get(position).second); ended = DateTimeCalender.checkIfSlotEnded(courseTimingPairs.get(position).second); } catch (ParseException ex) { ex.printStackTrace(); timeDifference = -1; ended = false; } } todayViewHolder.courseCode.setText(courseTimingPairs.get(position).first.getCourseCode()); todayViewHolder.courseName.setText(courseTimingPairs.get(position).first.getCourseTitle()); todayViewHolder.venue.setText(courseTimingPairs.get(position).first.getVenue()); todayViewHolder.slot.setText(courseTimingPairs.get(position).first.getSlot()); todayViewHolder.attendance.setText(Integer.toString(attendancePercentage)); todayViewHolder.progressBarAttendance.setProgress(attendancePercentage); todayViewHolder.goAttendance.setText(context.getString(R.string.label_class_go, goCalculated)); todayViewHolder.missAttendance.setText(context.getString(R.string.label_class_miss, missCalculated)); if (today == courseTimingPairs.get(position).second.getDay()) { todayViewHolder.timeLeft.setText(getTimeDifferenceString(timeDifference, ended)); } else { String startTime; String endTime; try { startTime = DateTimeCalender .parseISO8601Time(courseTimingPairs.get(position).second.getStartTime()); endTime = DateTimeCalender.parseISO8601Time(courseTimingPairs.get(position).second.getEndTime()); } catch (ParseException ex) { ex.printStackTrace(); startTime = courseTimingPairs.get(position).second.getStartTime(); endTime = courseTimingPairs.get(position).second.getEndTime(); } todayViewHolder.timeLeft .setText(context.getString(R.string.timetable_course_slot_timing, startTime, endTime)); } int sdk = android.os.Build.VERSION.SDK_INT; int bgColor = getAttendanceColor(attendancePercentage); todayViewHolder.progressBarAttendance.getProgressDrawable().setColorFilter(bgColor, PorterDuff.Mode.SRC_IN); GradientDrawable txt_bgShape; txt_bgShape = (GradientDrawable) todayViewHolder.attendance.getBackground(); txt_bgShape.setColor(bgColor); if (sdk < android.os.Build.VERSION_CODES.JELLY_BEAN) { todayViewHolder.attendance.setBackgroundDrawable(txt_bgShape); } else { todayViewHolder.attendance.setBackground(txt_bgShape); } }
From source file:com.delaroystudios.todolist.CustomCursorAdapter.java
/** * Called by the RecyclerView to display data at a specified position in the Cursor. * * @param holder The ViewHolder to bind Cursor data to * @param position The position of the data in the Cursor *///ww w . j a v a 2 s .co m @Override public void onBindViewHolder(TaskViewHolder holder, int position) { // Indices for the _id, description, and priority columns int idIndex = mCursor.getColumnIndex(TaskContract.TaskEntry._ID); int descriptionIndex = mCursor.getColumnIndex(TaskContract.TaskEntry.COLUMN_DESCRIPTION); int priorityIndex = mCursor.getColumnIndex(TaskContract.TaskEntry.COLUMN_PRIORITY); mCursor.moveToPosition(position); // get to the right location in the cursor // Determine the values of the wanted data final int id = mCursor.getInt(idIndex); String description = mCursor.getString(descriptionIndex); int priority = mCursor.getInt(priorityIndex); //Set values holder.itemView.setTag(id); holder.taskDescriptionView.setText(description); // Programmatically set the text and color for the priority TextView String priorityString = "" + priority; // converts int to String holder.priorityView.setText(priorityString); GradientDrawable priorityCircle = (GradientDrawable) holder.priorityView.getBackground(); // Get the appropriate background color based on the priority int priorityColor = getPriorityColor(priority); priorityCircle.setColor(priorityColor); }
From source file:com.example.android.todolist.TaskAdapter.java
/** * Called by the RecyclerView to display data at a specified position in the Cursor. * * @param holder The ViewHolder to bind Cursor data to * @param position The position of the data in the Cursor *//* w ww . j a v a 2 s . c o m*/ @Override public void onBindViewHolder(TaskViewHolder holder, int position) { // Determine the values of the wanted data TaskEntry taskEntry = mTaskEntries.get(position); String description = taskEntry.getDescription(); int priority = taskEntry.getPriority(); String updatedAt = dateFormat.format(taskEntry.getUpdatedAt()); //Set values holder.taskDescriptionView.setText(description); holder.updatedAtView.setText(updatedAt); // Programmatically set the text and color for the priority TextView String priorityString = "" + priority; // converts int to String holder.priorityView.setText(priorityString); GradientDrawable priorityCircle = (GradientDrawable) holder.priorityView.getBackground(); // Get the appropriate background color based on the priority int priorityColor = getPriorityColor(priority); priorityCircle.setColor(priorityColor); }
From source file:jp.tkgktyk.xposed.forcetouchdetector.app.util.fab.FloatingActionButtonEclairMr1.java
@Override void setBackgroundDrawable(Drawable originalBackground, ColorStateList backgroundTint, PorterDuff.Mode backgroundTintMode, int rippleColor, int borderWidth) { // Now we need to tint the original background with the tint, using // an InsetDrawable if we have a border width mShapeDrawable = DrawableCompat.wrap(originalBackground.mutate()); DrawableCompat.setTintList(mShapeDrawable, backgroundTint); if (backgroundTintMode != null) { DrawableCompat.setTintMode(mShapeDrawable, backgroundTintMode); }/*ww w.ja v a 2 s . com*/ // Now we created a mask Drawable which will be used for touch feedback. // As we don't know the actual outline of mShapeDrawable, we'll just guess that it's a // circle GradientDrawable touchFeedbackShape = new GradientDrawable(); touchFeedbackShape.setShape(GradientDrawable.OVAL); touchFeedbackShape.setColor(Color.WHITE); touchFeedbackShape.setCornerRadius(mShadowViewDelegate.getRadius()); // We'll now wrap that touch feedback mask drawable with a ColorStateList. We do not need // to inset for any border here as LayerDrawable will nest the padding for us mRippleDrawable = DrawableCompat.wrap(touchFeedbackShape); DrawableCompat.setTintList(mRippleDrawable, createColorStateList(rippleColor)); DrawableCompat.setTintMode(mRippleDrawable, PorterDuff.Mode.MULTIPLY); final Drawable[] layers; if (borderWidth > 0) { mBorderDrawable = createBorderDrawable(borderWidth, backgroundTint); layers = new Drawable[] { mBorderDrawable, mShapeDrawable, mRippleDrawable }; } else { mBorderDrawable = null; layers = new Drawable[] { mShapeDrawable, mRippleDrawable }; } mShadowDrawable = new ShadowDrawableWrapper(mView.getResources(), new LayerDrawable(layers), mShadowViewDelegate.getRadius(), mElevation, mElevation + mPressedTranslationZ); mShadowDrawable.setAddPaddingForCorners(false); mShadowViewDelegate.setBackgroundDrawable(mShadowDrawable); updatePadding(); }
From source file:org.dalol.orthodoxmezmurmedia.utilities.widgets.RecyclerViewFastIndexer.java
public void setColorHandle() { GradientDrawable drawable = (GradientDrawable) bubble.getBackground(); drawable.setColor(Color.parseColor("#01cb56")); }
From source file:org.zywx.wbpalmstar.plugin.uexscrawl.PhotoScrawlActivity.java
private View getColorImageView(int color) { final ImageView imageView = new ImageView(this); int width = EUExUtil.dipToPixels(32); LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(width, width); int margin = EUExUtil.dipToPixels(4); lp.leftMargin = margin;/*from w ww .j a v a 2s.co m*/ lp.rightMargin = margin; imageView.setLayoutParams(lp); imageView.setTag(color); GradientDrawable colorDrawable = new GradientDrawable(); colorDrawable.setColor(color); colorDrawable.setCornerRadius(8); if (Build.VERSION.SDK_INT < 16) { imageView.setBackgroundDrawable(colorDrawable); } else { imageView.setBackground(colorDrawable); } imageView.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { mCurrnetColor = (int) imageView.getTag(); mScrawlImageView.setPaintColor(mCurrnetColor); mPreviewView.setColor(mCurrnetColor); } }); return imageView; }
From source file:com.forrestguice.suntimeswidget.settings.ColorChooser.java
private void updateViews() { if (edit != null) { edit.setText(String.format("#%08X", color)); edit.setVisibility((isCollapsed ? View.GONE : View.VISIBLE)); }//from w w w.j a v a 2 s . c o m if (button != null) { Drawable d = button.getDrawable(); if (d != null) { GradientDrawable g = (GradientDrawable) d.mutate(); g.setColor(color); g.invalidateSelf(); } } }
From source file:cn.edu.nuc.seeworld.fg.ColorFragment.java
@Override public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { View v = inflater.inflate(R.layout.fragment_dummy, container, false); Bundle bdl = getArguments();//from w ww .jav a 2s . c o m mContext = this.getActivity(); mMainLayout = (FrameLayout) v.findViewById(R.id.main_layout); LayerDrawable bgDrawable = (LayerDrawable) mMainLayout.getBackground(); GradientDrawable shape = (GradientDrawable) bgDrawable.findDrawableByLayerId(R.id.background_shape); shape.setColor(bdl.getInt(EXTRA_COLOR)); imageView = (ImageView) v.findViewById(R.id.iv_camera); pic_imageView = (ImageView) v.findViewById(R.id.iv_pic); et_site = (EditText) v.findViewById(R.id.et_site); et_text = (EditText) v.findViewById(R.id.et_writeword); btn_publish = (Button) v.findViewById(R.id.btn_publish); imageView.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { AlertDialog.Builder builder = new AlertDialog.Builder(v.getContext()); LayoutInflater layoutInflater = LayoutInflater.from(v.getContext()); View v1 = layoutInflater.inflate(R.layout.camera_dialog, null); builder.setView(v1); camera_log_buttons[0] = (Button) v1.findViewById(R.id.bt_camera_dialog_1); camera_log_buttons[1] = (Button) v1.findViewById(R.id.bt_camera_dialog_2); camera_log_buttons[2] = (Button) v1.findViewById(R.id.bt_camera_dialog_3); for (int i = 0; i < 3; i++) { camera_log_buttons[i].setOnClickListener(new cameraonclicklistener()); } dialog = builder.create(); dialog.show(); } }); btn_publish.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { publish(); } }); return v; }