List of usage examples for android.support.v4.content.res ResourcesCompat getDrawable
public static Drawable getDrawable(Resources resources, int i, Theme theme) throws NotFoundException
From source file:com.github.guwenk.smuradio.SignInDialog.java
@Override public void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); // Result returned from launching the Intent from GoogleSignInApi.getSignInIntent(...); if (requestCode == RC_SIGN_IN) { GoogleSignInResult result = Auth.GoogleSignInApi.getSignInResultFromIntent(data); if (result.isSuccess()) { Log.d(AuthTag, "Result is success"); // Google Sign In was successful, authenticate with Firebase account = result.getSignInAccount(); firebaseAuthWithGoogle(account); } else {/* w ww . j a va 2s .c o m*/ Log.d(AuthTag, "Result is not success"); } } if (requestCode == PICK_MUSIC_REQUEST && resultCode == RESULT_OK && data != null && data.getData() != null) { filepath = data.getData(); songTitle = getFileName(filepath); Log.d(AuthTag, "SONG: " + songTitle); selectFileButton.setText(songTitle); selectFileButton.setCompoundDrawablesWithIntrinsicBounds( ResourcesCompat.getDrawable(getResources(), R.drawable.ic_check_circle_24dp, null), null, null, null); check3 = true; buttonStatus(); } }
From source file:com.hellofyc.base.app.adapter.BaseRecyclerViewAdapter.java
@Override public Drawable getDrawable(@DrawableRes int id, Resources.Theme theme) { return ResourcesCompat.getDrawable(getResources(), id, theme); }
From source file:app.abhijit.iter.MainActivity.java
private void setupGettingStartedHint() { TextView gettingStartedHint = (TextView) findViewById(R.id.hint_getting_started); int lineHeight = gettingStartedHint.getLineHeight(); Drawable hamburgerIcon = ResourcesCompat.getDrawable(getResources(), R.drawable.ic_hamburger, null); hamburgerIcon.setBounds(0, 0, lineHeight, lineHeight); SpannableStringBuilder hintText = new SpannableStringBuilder(); hintText.append(getResources().getString(R.string.hint_getting_started_1)).append(" "); hintText.setSpan(new ImageSpan(hamburgerIcon), hintText.length() - 1, hintText.length(), 0); hintText.append(getResources().getString(R.string.hint_getting_started_2)); gettingStartedHint.setText(hintText); }
From source file:com.mischivous.wormysharpyloggy.wsl.model.Tile.java
/** * Returns a miniature version of the Drawable representing the Tile. * * @param context The context to retrieve the Tile from * @return A Drawable representing the Tile */// w w w.j a v a 2s.c o m @NonNull public Drawable GetSmallDrawable(@NonNull Context context) { if (context == null) { throw new NullPointerException("Context cannot be null."); } int id = context.getResources().getIdentifier( String.format("tile_small_%d%d%d%d", GetNum(), GetShapeVal(), GetColorVal(), GetFillVal()), "mipmap", context.getPackageName()); return ResourcesCompat.getDrawable(context.getResources(), id, null); }
From source file:com.mifos.mifosxdroid.online.clientcharge.ClientChargeFragment.java
@Override public void onPrepareOptionsMenu(Menu menu) { menu.clear();//from w w w. j a v a 2s. c o m MenuItem menuItemAddNewDocument = menu.add(Menu.NONE, MENU_ITEM_ADD_NEW_CHARGES, Menu.NONE, getString(R.string.add_new)); menuItemAddNewDocument .setIcon(ResourcesCompat.getDrawable(getResources(), R.drawable.ic_add_white_24dp, null)); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) menuItemAddNewDocument.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM); super.onPrepareOptionsMenu(menu); }
From source file:com.vnidens.clickableedittext.ClickableEditTextHelper.java
@Override public void setEndButtonDrawable(@DrawableRes int drawable) { EditText et = viewWeakRef.get();//from w w w . j a va 2 s. c o m if (et != null) { setEndButtonDrawable( ResourcesCompat.getDrawable(et.getResources(), drawable, et.getContext().getTheme())); } }
From source file:com.giovanniterlingen.windesheim.view.Adapters.ScheduleAdapter.java
@Override public void onBindViewHolder(final ViewHolder holder, int position) { final TextView lessonName = holder.lessonName; final TextView lessonTime = holder.lessonTime; final TextView lessonRoom = holder.lessonRoom; final TextView lessonComponent = holder.lessonComponent; final RelativeLayout menuButton = holder.menuButton; final ImageView menuButtonImage = holder.menuButtonImage; final View scheduleIdentifier = holder.scheduleIdentifier; Lesson lesson = this.lessons[position]; long databaseDateStart = Long .parseLong(lesson.getDate().replaceAll("-", "") + lesson.getStartTime().replaceAll(":", "")); long databaseDateEnd = Long .parseLong(lesson.getDate().replaceAll("-", "") + lesson.getEndTime().replaceAll(":", "")); SimpleDateFormat yearMonthDayDateFormat = CalendarController.getInstance().getYearMonthDayDateTimeFormat(); long currentDate = Long.parseLong(yearMonthDayDateFormat.format(new Date())); lessonName.setText(lesson.getSubject()); lessonRoom.setText(lesson.getRoom()); lessonComponent.setText(lesson.getScheduleType() == 2 ? lesson.getClassName() : lesson.getTeacher()); lessonComponent.setSelected(true);// w ww . j a va 2 s . c om if (databaseDateStart <= currentDate && databaseDateEnd >= currentDate) { lessonTime.setTextColor(ContextCompat.getColor(activity, R.color.colorAccent)); lessonTime.setText( ApplicationLoader.applicationContext.getResources().getString(R.string.lesson_started)); holder.cardView.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Lesson lesson = ScheduleAdapter.this.lessons[holder.getAdapterPosition()]; if (!lessonTime.getText().toString().equals(ApplicationLoader.applicationContext.getResources() .getString(R.string.lesson_started))) { TranslateAnimation animation = new TranslateAnimation(Animation.RELATIVE_TO_SELF, 0.0f, Animation.RELATIVE_TO_SELF, 0.0f, Animation.RELATIVE_TO_SELF, -1.0f, Animation.RELATIVE_TO_SELF, 0.0f); animation.setDuration(100); lessonTime.setAnimation(animation); lessonTime.setTextColor(ContextCompat.getColor(activity, R.color.colorAccent)); lessonTime.setText(ApplicationLoader.applicationContext.getResources() .getString(R.string.lesson_started)); } else { TranslateAnimation animation = new TranslateAnimation(Animation.RELATIVE_TO_SELF, 0.0f, Animation.RELATIVE_TO_SELF, 0.0f, Animation.RELATIVE_TO_SELF, 1.0f, Animation.RELATIVE_TO_SELF, 0.0f); animation.setDuration(100); lessonTime.setAnimation(animation); String lessonTimes = lesson.getStartTime() + " - " + lesson.getEndTime(); lessonTime.setTextColor(ContextCompat.getColor(activity, R.color.colorSecondaryText)); lessonTime.setText(lessonTimes); } } }); } else if (databaseDateEnd < currentDate) { lessonTime.setTextColor(ContextCompat.getColor(activity, R.color.colorAccent)); lessonTime.setText(ApplicationLoader.applicationContext.getResources().getString(R.string.finished)); holder.cardView.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Lesson lesson = ScheduleAdapter.this.lessons[holder.getAdapterPosition()]; if (!lessonTime.getText().toString().equals( ApplicationLoader.applicationContext.getResources().getString(R.string.finished))) { TranslateAnimation animation = new TranslateAnimation(Animation.RELATIVE_TO_SELF, 0.0f, Animation.RELATIVE_TO_SELF, 0.0f, Animation.RELATIVE_TO_SELF, -1.0f, Animation.RELATIVE_TO_SELF, 0.0f); animation.setDuration(100); lessonTime.setAnimation(animation); lessonTime.setTextColor(ContextCompat.getColor(activity, R.color.colorAccent)); lessonTime.setText( ApplicationLoader.applicationContext.getResources().getString(R.string.finished)); } else { TranslateAnimation animation = new TranslateAnimation(Animation.RELATIVE_TO_SELF, 0.0f, Animation.RELATIVE_TO_SELF, 0.0f, Animation.RELATIVE_TO_SELF, 1.0f, Animation.RELATIVE_TO_SELF, 0.0f); animation.setDuration(100); lessonTime.setAnimation(animation); String lessonTimes = lesson.getStartTime() + " - " + lesson.getEndTime(); lessonTime.setTextColor(ContextCompat.getColor(activity, R.color.colorSecondaryText)); lessonTime.setText(lessonTimes); } } }); } else { String lessonTimes = lesson.getStartTime() + " - " + lesson.getEndTime(); lessonTime.setTextColor(ContextCompat.getColor(activity, R.color.colorSecondaryText)); lessonTime.setText(lessonTimes); holder.cardView.setOnClickListener(null); } menuButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { menuButtonImage.setImageDrawable( ResourcesCompat.getDrawable(activity.getResources(), R.drawable.overflow_open, null)); PopupMenu popupMenu = new PopupMenu(activity, menuButton); popupMenu.inflate(R.menu.menu_schedule); popupMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() { public boolean onMenuItemClick(MenuItem item) { Lesson lesson = ScheduleAdapter.this.lessons[holder.getAdapterPosition()]; if (item.getItemId() == R.id.hide_lesson) { showPromptDialog(lesson.getSubject()); return true; } if (item.getItemId() == R.id.save_lesson) { showCalendarDialog(lesson.getRowId()); } return true; } }); popupMenu.setOnDismissListener(new PopupMenu.OnDismissListener() { @Override public void onDismiss(PopupMenu menu) { menuButtonImage.setImageDrawable(ResourcesCompat.getDrawable(activity.getResources(), R.drawable.overflow_normal, null)); } }); popupMenu.show(); } }); scheduleIdentifier.setBackgroundColor(ColorController.getInstance().getColorById(lesson.getScheduleId())); }
From source file:com.ruesga.rview.drawer.DrawerNavigationMenuItemView.java
@Override public void setIcon(Drawable icon) { if (icon != null) { if (mShouldTintedIcon && mHasIconTintList) { Drawable.ConstantState state = icon.getConstantState(); icon = DrawableCompat.wrap(state == null ? icon : state.newDrawable()).mutate(); DrawableCompat.setTintList(icon, mIconTintList); }/* ww w . java 2 s . co m*/ icon.setBounds(0, 0, mIconSize, mIconSize); } else if (mNeedsEmptyIcon) { if (mEmptyDrawable == null) { mEmptyDrawable = ResourcesCompat.getDrawable(getResources(), R.drawable.navigation_empty_icon, getContext().getTheme()); if (mEmptyDrawable != null) { mEmptyDrawable.setBounds(0, 0, mIconSize, mIconSize); } } icon = mEmptyDrawable; } mIcon.setImageDrawable(icon); }
From source file:com.journeyapps.barcodescanner.WXViewfinderView.java
@SuppressLint("DrawAllocation") @Override// ww w .ja v a 2 s. c o m public void onDraw(Canvas canvas) { refreshSizes(); if (framingRect == null || previewFramingRect == null) { return; } Rect frame = framingRect; Rect previewFrame = previewFramingRect; int width = canvas.getWidth(); int height = canvas.getHeight(); maskPaint.setColor(maskColor); canvas.drawRect(0, 0, width, frame.top, maskPaint); canvas.drawRect(0, frame.top, frame.left, frame.bottom + 1, maskPaint); canvas.drawRect(frame.right + 1, frame.top, width, frame.bottom + 1, maskPaint); canvas.drawRect(0, frame.bottom + 1, width, height, maskPaint); //drawable the border canvas.drawRect(frame.left + 1, frame.top + 1, frame.right, frame.bottom, borderPaint); int halfWidth = (int) (cornerWidth / 2); //draw four corner Path corner1 = new Path(); corner1.moveTo(frame.left, frame.top + cornerLength); corner1.lineTo(frame.left, frame.top); corner1.lineTo(frame.left + cornerLength, frame.top); Matrix translate1 = new Matrix(); translate1.setTranslate(halfWidth, halfWidth); corner1.transform(translate1); canvas.drawPath(corner1, cornerPaint); Path corner2 = new Path(); corner2.moveTo(frame.right + 1 - cornerLength, frame.top); corner2.lineTo(frame.right + 1, frame.top); corner2.lineTo(frame.right + 1, frame.top + cornerLength); Matrix translate2 = new Matrix(); translate2.setTranslate(-halfWidth, halfWidth); corner2.transform(translate2); canvas.drawPath(corner2, cornerPaint); Path corner3 = new Path(); corner3.moveTo(frame.left, frame.bottom + 1 - cornerLength); corner3.lineTo(frame.left, frame.bottom + 1); corner3.lineTo(frame.left + cornerLength, frame.bottom + 1); Matrix translate3 = new Matrix(); translate3.setTranslate(halfWidth, -halfWidth); corner3.transform(translate3); canvas.drawPath(corner3, cornerPaint); Path corner4 = new Path(); corner4.moveTo(frame.right + 1 - cornerLength, frame.bottom + 1); corner4.lineTo(frame.right + 1, frame.bottom + 1); corner4.lineTo(frame.right + 1, frame.bottom + 1 - cornerLength); Matrix translate4 = new Matrix(); translate4.setTranslate(-halfWidth, -halfWidth); corner4.transform(translate4); canvas.drawPath(corner4, cornerPaint); offset += speed; if (offset >= frame.bottom - frame.top) { offset = 0; } Rect rect = new Rect(); rect.left = frame.left + 1 + laserPadding; rect.top = frame.top + 1 + offset; rect.right = frame.right - laserPadding; rect.bottom = frame.top + 1 + offset + 3; Bitmap laserBitmap = ((BitmapDrawable) ResourcesCompat.getDrawable(getResources(), R.drawable.scan_laser, null)).getBitmap(); canvas.drawBitmap(laserBitmap, null, rect, linePaint); textPaint.setTextAlign(Paint.Align.CENTER); canvas.drawText(statusText, (frame.right + frame.left) / 2, frame.bottom + statusTextPadding + statusTextSize, textPaint); postInvalidateDelayed(animationDelay, frame.left, frame.top, frame.right, frame.bottom); }
From source file:com.nttec.everychan.ui.tabs.TabsAdapter.java
@Override public View getView(final int position, View convertView, ViewGroup parent) { View view = convertView == null ? inflater.inflate(R.layout.sidebar_tabitem, parent, false) : convertView; View dragHandler = view.findViewById(R.id.tab_drag_handle); ImageView favIcon = (ImageView) view.findViewById(R.id.tab_favicon); TextView title = (TextView) view.findViewById(R.id.tab_text_view); ImageView closeBtn = (ImageView) view.findViewById(R.id.tab_close_button); dragHandler.getLayoutParams().width = position == draggingItem ? ViewGroup.LayoutParams.WRAP_CONTENT : 0; dragHandler.setLayoutParams(dragHandler.getLayoutParams()); if (position == selectedItem) { TypedValue typedValue = ThemeUtils.resolveAttribute(context.getTheme(), R.attr.sidebarSelectedItem, true);//from w w w . ja v a2 s . c o m if (typedValue.type >= TypedValue.TYPE_FIRST_COLOR_INT && typedValue.type <= TypedValue.TYPE_LAST_COLOR_INT) { view.setBackgroundColor(typedValue.data); } else { view.setBackgroundResource(typedValue.resourceId); } } else { view.setBackgroundColor(Color.TRANSPARENT); } TabModel model = this.getItem(position); switch (model.type) { case TabModel.TYPE_NORMAL: case TabModel.TYPE_LOCAL: closeBtn.setVisibility(View.VISIBLE); String titleText = model.title; if (model.unreadPostsCount > 0 || model.autoupdateError) { StringBuilder titleStringBuilder = new StringBuilder(); if (model.unreadSubscriptions) titleStringBuilder.append("[*] "); if (model.autoupdateError) titleStringBuilder.append("[X] "); if (model.unreadPostsCount > 0) titleStringBuilder.append('[').append(model.unreadPostsCount).append("] "); titleText = titleStringBuilder.append(titleText).toString(); } title.setText(titleText); ChanModule chan = MainApplication.getInstance().getChanModule(model.pageModel.chanName); Drawable icon = chan != null ? chan.getChanFavicon() : ResourcesCompat.getDrawable(context.getResources(), android.R.drawable.ic_delete, null); if (icon != null) { if (model.type == TabModel.TYPE_LOCAL) { Drawable[] layers = new Drawable[] { icon, ResourcesCompat.getDrawable(context.getResources(), R.drawable.favicon_overlay_local, null) }; icon = new LayerDrawable(layers); } /* XXX ? ( overlay favicon ), ? ?? , , ( ). ? ? ? , , ? -? - , ?. ?? ?, ? ? . else if (model.type == TabModel.TYPE_NORMAL && model.pageModel != null && model.pageModel.type == UrlPageModel.TYPE_THREADPAGE && model.autoupdateBackground && MainApplication.getInstance().settings.isAutoupdateEnabled() && MainApplication.getInstance().settings.isAutoupdateBackground()) { Drawable[] layers = new Drawable[] { icon, ResourcesCompat.getDrawable(context.getResources(), R.drawable.favicon_overlay_autoupdate, null) }; icon = new LayerDrawable(layers); } */ favIcon.setImageDrawable(icon); favIcon.setVisibility(View.VISIBLE); } else { favIcon.setVisibility(View.GONE); } break; default: closeBtn.setVisibility(View.GONE); title.setText(R.string.error_deserialization); favIcon.setVisibility(View.GONE); } closeBtn.setTag(position); closeBtn.setOnClickListener(onCloseClick); return view; }