@Override public void onBindViewHolder(@NonNull final LightningViewHolder holder, int position) { holder.exitButton.setTag(position); ViewCompat.jumpDrawablesToCurrentState(holder.exitButton); LightningView web = mTabsManager.getTabAtPosition(position); if (web == null) { return; } holder.txtTitle.setText(web.getTitle()); final Bitmap favicon = web.getFavicon(); if (web.isForegroundTab()) { Drawable foregroundDrawable = null; if (!mDrawerTabs) { foregroundDrawable = new BitmapDrawable(getResources(), mForegroundTabBitmap); if (!mIsIncognito && mColorMode) { foregroundDrawable.setColorFilter(mUiController.getUiColor(), PorterDuff.Mode.SRC_IN); } } if (!mIsIncognito && mColorMode) { mUiController.changeToolbarBackground(favicon, foregroundDrawable); } TextViewCompat.setTextAppearance(holder.txtTitle, R.style.boldText); if (!mDrawerTabs) { DrawableUtils.setBackground(holder.layout, foregroundDrawable); } holder.favicon.setImageBitmap(favicon); } else { TextViewCompat.setTextAppearance(holder.txtTitle, R.style.normalText); if (!mDrawerTabs) { DrawableUtils.setBackground(holder.layout, mBackgroundTabDrawable); } holder.favicon.setImageBitmap(getDesaturatedBitmap(favicon)); } if (mDrawerTabs) { BackgroundDrawable verticalBackground = (BackgroundDrawable) holder.layout.getBackground(); verticalBackground.setCrossFadeEnabled(false); if (web.isForegroundTab()) { verticalBackground.startTransition(200); } else { verticalBackground.reverseTransition(200); } } }
private void bindNumberCommentsView( NumberResponsesViewHolder holder, DiscussionComment response) { String text; Icon icon; int numChildren = response == null ? 0 : response.getChildCount(); if (response.getChildCount() == 0) { if (discussionThread.isClosed()) { text = context.getString(R.string.discussion_add_comment_disabled_title); icon = FontAwesomeIcons.fa_lock; } else { text = context.getString(R.string.number_responses_or_comments_add_comment_label); icon = FontAwesomeIcons.fa_comment; } } else { text = context .getResources() .getQuantityString( R.plurals.number_responses_or_comments_comments_label, numChildren, numChildren); icon = FontAwesomeIcons.fa_comment; } holder.numberResponsesOrCommentsLabel.setText(text); TextViewCompat.setCompoundDrawablesRelativeWithIntrinsicBounds( holder.numberResponsesOrCommentsLabel, new IconDrawable(context, icon) .colorRes(context, R.color.edx_grayscale_neutral_dark) .sizeRes(context, R.dimen.edx_small), null, null, null); }
@Override public View getView(int position, View convertView, ViewGroup parent) { if (convertView == null) { convertView = inflater.inflate(R.layout.item_main_menu, parent, false); convertView.setOnClickListener(sectionClickListener); } Section section = getItem(position); convertView.setSelected(section == currentSection); TextView tv = (TextView) convertView.findViewById(R.id.section_text); SpannableString sectionTitle = new SpannableString(getString(section.getTitleResId())); Drawable sectionIcon = ContextCompat.getDrawable(MainActivity.this, section.getIconResId()); if (section == currentSection) { // Special color for the current section sectionTitle.setSpan( new ForegroundColorSpan(currentSectionForegroundColor), 0, sectionTitle.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); // We need to mutate the drawable before applying the ColorFilter, or else all the similar // drawable instances will be tinted. sectionIcon.mutate().setColorFilter(currentSectionForegroundColor, PorterDuff.Mode.SRC_IN); } tv.setText(sectionTitle); TextViewCompat.setCompoundDrawablesRelativeWithIntrinsicBounds( tv, sectionIcon, null, null, null); return convertView; }
private static void addDetectedValueHeader( @NonNull ListView listView, @StringRes int labelRes, @NonNull String labelKey, @NonNull String labelValue, @NonNull String value, @NonNull Icon icon) { final TextView textView = (TextView) LayoutInflater.from(listView.getContext()) .inflate(R.layout.edx_selectable_list_item, listView, false); { final SpannableString labelValueSpan = new SpannableString(labelValue); labelValueSpan.setSpan( new ForegroundColorSpan( listView.getResources().getColor(R.color.edx_grayscale_neutral_dark)), 0, labelValueSpan.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); textView.setText( ResourceUtil.getFormattedString( listView.getContext().getResources(), labelRes, labelKey, labelValueSpan)); } Context context = textView.getContext(); TextViewCompat.setCompoundDrawablesRelativeWithIntrinsicBounds( textView, new IconDrawable(context, icon) .sizeRes(context, R.dimen.edx_base) .colorRes(context, R.color.edx_grayscale_neutral_light), null, null, null); listView.addHeaderView(textView, new FormOption(labelValue, value), true); }
public static void setTextStyle(TextView textView) { Context context = textView.getContext(); String size = Preferences.getFontSize(context); int sizeId; if (size.equals("small")) sizeId = android.R.style.TextAppearance_Small; else if (size.equals("large")) sizeId = android.R.style.TextAppearance_Large; else sizeId = android.R.style.TextAppearance; TextViewCompat.setTextAppearance(textView, sizeId); // setEmojiconSize((int) getTextSize()); }
private static TextView createField( @NonNull LayoutInflater inflater, @NonNull ViewGroup parent, @NonNull final FormField field, @NonNull final String value, boolean readOnly, @NonNull View.OnClickListener onClickListener) { final TextView textView = (TextView) inflater.inflate(R.layout.edit_user_profile_field, parent, false); final SpannableString formattedValue = new SpannableString(value); formattedValue.setSpan( new ForegroundColorSpan(parent.getResources().getColor(R.color.edx_grayscale_neutral_dark)), 0, formattedValue.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); textView.setText( ResourceUtil.getFormattedString( parent.getResources(), R.string.edit_user_profile_field, new HashMap<String, CharSequence>() { { put("label", field.getLabel()); put("value", formattedValue); } })); Context context = parent.getContext(); TextViewCompat.setCompoundDrawablesRelativeWithIntrinsicBounds( textView, null, null, new IconDrawable(context, FontAwesomeIcons.fa_angle_right) .colorRes(context, R.color.edx_grayscale_neutral_light) .sizeDp(context, 24), null); if (readOnly) { textView.setEnabled(false); textView.setBackgroundColor( textView.getResources().getColor(R.color.edx_grayscale_neutral_x_light)); } else { textView.setOnClickListener(onClickListener); } parent.addView(textView); return textView; }
@Override public View getView(int position, View convertView, ViewGroup parent) { LvMenuItem item = mItems.get(position); switch (item.type) { case LvMenuItem.TYPE_NORMAL: if (convertView == null) { convertView = mInflater.inflate(R.layout.design_drawer_item, parent, false); } TextView itemView = (TextView) convertView; itemView.setText(item.name); Drawable icon = mContext.getResources().getDrawable(item.icon); if (icon != null) { icon.setBounds(0, 0, mIconSize, mIconSize); TextViewCompat.setCompoundDrawablesRelative(itemView, icon, null, null, null); } break; case LvMenuItem.TYPE_NO_ICON: if (convertView == null) { convertView = mInflater.inflate(R.layout.design_drawer_item_subheader, parent, false); } TextView subHeader = (TextView) convertView; subHeader.setText(item.name); break; case LvMenuItem.TYPE_SEPARATOR: if (convertView == null) { convertView = mInflater.inflate(R.layout.design_drawer_item_separator, parent, false); } break; } convertView.setPressed(true); convertView.setSelected(true); return convertView; }
@Override public void onBindViewHolder(RecyclerView.ViewHolder viewHolder, int position) { if (getItemViewType(position) == RowType.PROGRESS) return; final ResponseOrCommentViewHolder holder = (ResponseOrCommentViewHolder) viewHolder; final DiscussionComment discussionComment; final IconDrawable iconDrawable; if (position == 0) { discussionComment = response; DiscussionTextUtils.setEndorsedState( holder.authorLayoutViewHolder.answerTextView, thread, response); final int childCount = discussionComment.getChildCount(); holder.discussionCommentCountReportTextView.setText( context .getResources() .getQuantityString( R.plurals.number_responses_or_comments_comments_label, childCount, childCount)); iconDrawable = new IconDrawable(context, FontAwesomeIcons.fa_comment) .sizeRes(context, R.dimen.edx_small) .colorRes(context, R.color.edx_brand_gray_base); holder.discussionCommentCountReportTextView.setOnClickListener(null); holder.discussionCommentCountReportTextView.setClickable(false); } else { holder.authorLayoutViewHolder.answerTextView.setVisibility(View.GONE); discussionComment = discussionComments.get(position - 1); iconDrawable = new IconDrawable(context, FontAwesomeIcons.fa_flag) .sizeRes(context, R.dimen.edx_small) .colorRes( context, discussionComment.isAbuseFlagged() ? R.color.edx_brand_primary_base : R.color.edx_brand_gray_base); holder.discussionCommentCountReportTextView.setText( discussionComment.isAbuseFlagged() ? context.getString(R.string.discussion_responses_reported_label) : context.getString(R.string.discussion_responses_report_label)); holder.discussionCommentCountReportTextView.setTextColor( context.getResources().getColor(R.color.edx_brand_gray_base)); holder.discussionCommentCountReportTextView.setOnClickListener( new View.OnClickListener() { public void onClick(final View v) { listener.reportComment(discussionComment); } }); } holder.authorLayoutViewHolder.populateViewHolder( config, discussionComment, discussionComment, initialTimeStampMs, new Runnable() { @Override public void run() { listener.onClickAuthor(discussionComment.getAuthor()); } }); TextViewCompat.setCompoundDrawablesRelativeWithIntrinsicBounds( holder.discussionCommentCountReportTextView, iconDrawable, null, null, null); DiscussionTextUtils.renderHtml( holder.discussionCommentBody, discussionComment.getRenderedBody()); }
@Override public void onViewCreated(View view, Bundle savedInstanceState) { super.onViewCreated(view, savedInstanceState); final LayoutInflater inflater = LayoutInflater.from(getActivity()); // Add "All posts" item { final TextView header = (TextView) inflater.inflate(R.layout.row_discussion_topic, discussionTopicsListView, false); header.setText(R.string.discussion_posts_filter_all_posts); final DiscussionTopic discussionTopic = new DiscussionTopic(); discussionTopic.setIdentifier(DiscussionTopic.ALL_TOPICS_ID); discussionTopic.setName(getString(R.string.discussion_posts_filter_all_posts)); discussionTopicsListView.addHeaderView( header, new DiscussionTopicDepth(discussionTopic, 0, true), true); } // Add "Posts I'm following" item { final TextView header = (TextView) inflater.inflate(R.layout.row_discussion_topic, discussionTopicsListView, false); header.setText(R.string.forum_post_i_am_following); TextViewCompat.setCompoundDrawablesRelativeWithIntrinsicBounds( header, new IconDrawable(getActivity(), Iconify.IconValue.fa_star) .colorRes(R.color.edx_grayscale_neutral_dark) .sizeRes(R.dimen.edx_base), null, null, null); final DiscussionTopic discussionTopic = new DiscussionTopic(); discussionTopic.setIdentifier(DiscussionTopic.FOLLOWING_TOPICS_ID); discussionTopic.setName(getString(R.string.forum_post_i_am_following)); discussionTopicsListView.addHeaderView( header, new DiscussionTopicDepth(discussionTopic, 0, true), true); } discussionTopicsListView.setAdapter(discussionTopicsAdapter); discussionTopicsSearchView.setOnQueryTextListener( new SearchView.OnQueryTextListener() { @Override public boolean onQueryTextSubmit(String query) { if (query == null || query.trim().length() == 0) return false; router.showCourseDiscussionPostsForSearchQuery(getActivity(), query, courseData); return true; } @Override public boolean onQueryTextChange(String newText) { return false; } }); discussionTopicsListView.setOnItemClickListener( new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { router.showCourseDiscussionPostsForDiscussionTopic( getActivity(), ((DiscussionTopicDepth) parent.getItemAtPosition(position)).getDiscussionTopic(), courseData); } }); // TODO: Find a better way to hide the keyboard AND take the focus away from the SearchView discussionTopicsSearchView.requestFocus(); discussionTopicsSearchView.clearFocus(); getTopicList(); }
@Override public void onViewCreated(View view, Bundle savedInstanceState) { super.onViewCreated(view, savedInstanceState); viewHolder = new ViewHolder(view); viewHolder.profileImageProgress.setVisibility(View.GONE); viewHolder.username.setText(username); final IconDrawable icon = new IconDrawable(getActivity(), FontAwesomeIcons.fa_camera) .colorRes(getActivity(), R.color.disableable_button_text) .sizeRes(getActivity(), R.dimen.fa_x_small); icon.setTintList( null); // IconDrawable is tinted by default, but we don't want it to be tinted here TextViewCompat.setCompoundDrawablesRelativeWithIntrinsicBounds( viewHolder.changePhoto, icon, null, null, null); viewHolder.changePhoto.setOnClickListener( new View.OnClickListener() { @Override public void onClick(View v) { final PopupMenu popup = new PopupMenu(getActivity(), v); popup.getMenuInflater().inflate(R.menu.change_photo, popup.getMenu()); popup.setOnMenuItemClickListener( new PopupMenu.OnMenuItemClickListener() { public boolean onMenuItemClick(MenuItem item) { switch (item.getItemId()) { case R.id.take_photo: { startActivityForResult( helper.createCaptureIntent(getActivity()), CAPTURE_PHOTO_REQUEST); break; } case R.id.choose_photo: { final Intent galleryIntent = new Intent().setType("image/*").setAction(Intent.ACTION_GET_CONTENT); startActivityForResult(galleryIntent, CHOOSE_PHOTO_REQUEST); break; } case R.id.remove_photo: { executePhotoTask( new DeleteAccountImageTask(getActivity(), username) { @Override protected void onSuccess(Void aVoid) throws Exception { hideLoading(); } private void hideLoading() { if (null != viewHolder) { viewHolder.profileImageProgress.setVisibility(View.GONE); } } }); break; } } return true; } }); popup.show(); } }); setData(account, formDescription); }