use of android.text.style.ForegroundColorSpan in project GT by Tencent.
the class SearchLogAdapter method getView.
@Override
public View getView(int position, View convertView, ViewGroup parent) {
LinearLayout ll;
if (convertView == null) {
ll = (LinearLayout) LayoutInflater.from(context).inflate(R.layout.gt_log_search_list_item, parent, false);
} else {
ll = (LinearLayout) convertView;
}
TextView tvSeq = (TextView) ll.findViewById(R.id.log_search_list_item_seq);
tvSeq.setText(position + ".");
TextView tv = (TextView) ll.findViewById(R.id.log_search_list_item);
String target = dataSet[position].msg;
int tagStart = target.indexOf("/") + 1;
int tagEnd = target.indexOf("(", tagStart + 1);
int tidStart = tagEnd + 1;
int tidEnd = target.indexOf(")", tidStart + 1);
if (tagStart < tagEnd && tidStart < tidEnd) {
SpannableString ss = new SpannableString(target);
ss.setSpan(new ForegroundColorSpan(Color.argb(0xff, 0x9f, 0x9f, 0x9e)), 0, 19, // 日期浅灰色
Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
ss.setSpan(new ForegroundColorSpan(Color.argb(0xff, 0xcb, 0x74, 0x18)), 20, 21, // 级别橘红色
Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
ss.setSpan(new ForegroundColorSpan(Color.argb(0xff, 0xcb, 0x74, 0x18)), tagStart, tagEnd, // TAG橘红色
Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
ss.setSpan(new ForegroundColorSpan(Color.argb(0xff, 0xcb, 0x74, 0x18)), tidStart, tidEnd, // 线程号橘红色
Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
// TODO 搜索字符串高亮部分处理
if (GTLogInternal.getLastMatchedEntryList().size() > 0) {
List<MatchedEntry> matchedList = GTLogInternal.getLastMatchedEntryList();
for (int matchedSeq = 0; matchedSeq < matchedList.size(); matchedSeq++) {
MatchedEntry mached = matchedList.get(matchedSeq);
if (// 比当前显示位置远的部分不需要即时处理
mached.posionInDataSet > position) {
break;
}
if (mached.posionInDataSet == position) {
ss.setSpan(new ForegroundColorSpan(Color.argb(0xff, 0x00, 0x00, 0x00)), mached.start, mached.end, // 前景色黑色
Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
if (matchedSeq == GTLogInternal.getLastMatchedSeq()) {
ss.setSpan(new BackgroundColorSpan(Color.argb(0xff, 0xdd, 0xff, 0x43)), mached.start, mached.end, // 背景色黄色
Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
} else {
ss.setSpan(new BackgroundColorSpan(Color.argb(0xff, 0x38, 0xad, 0x29)), mached.start, mached.end, // 背景色绿色
Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
}
}
}
}
tv.setText(ss);
return ll;
}
// 如果无法解析,直接返回文本内容
tv.setText(target);
return ll;
}
use of android.text.style.ForegroundColorSpan in project Reader by TheKeeperOfPie.
the class FragmentThreadList method onCreateView.
@SuppressWarnings("ResourceType")
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
initialize();
view = bind(inflater.inflate(R.layout.fragment_thread_list, container, false));
setUpToolbar();
buttonExpandActions.setOnClickListener(v -> toggleLayoutActions());
behaviorButtonExpandActions = new ScrollAwareFloatingActionButtonBehavior(getActivity(), null, new ScrollAwareFloatingActionButtonBehavior.OnVisibilityChangeListener() {
@Override
public void onStartHideFromScroll() {
hideLayoutActions(0);
}
@Override
public void onEndHideFromScroll() {
buttonExpandActions.setImageResource(R.drawable.ic_unfold_more_white_24dp);
buttonExpandActions.setColorFilter(themer.getColorFilterAccent());
}
});
((CoordinatorLayout.LayoutParams) buttonExpandActions.getLayoutParams()).setBehavior(behaviorButtonExpandActions);
buttonJumpTop.setOnClickListener(v -> scrollToPositionWithOffset(0, 0));
buttonJumpTop.setOnLongClickListener(v -> {
Toast.makeText(getActivity(), getString(R.string.content_description_button_jump_top), Toast.LENGTH_SHORT).show();
return false;
});
buttonClearViewed.setOnClickListener(v -> controllerLinks.clearViewed(historian));
buttonClearViewed.setOnLongClickListener(v -> {
Toast.makeText(getActivity(), getString(R.string.content_description_button_clear_viewed), Toast.LENGTH_SHORT).show();
return false;
});
// Margin is included within shadow margin on pre-Lollipop, so remove all regular margin
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
((CoordinatorLayout.LayoutParams) buttonExpandActions.getLayoutParams()).setMargins(0, 0, 0, 0);
int margin = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 8, getResources().getDisplayMetrics());
LinearLayout.LayoutParams layoutParamsJumpTop = (LinearLayout.LayoutParams) buttonJumpTop.getLayoutParams();
layoutParamsJumpTop.setMargins(0, 0, 0, 0);
buttonJumpTop.setLayoutParams(layoutParamsJumpTop);
LinearLayout.LayoutParams layoutParamsClearViewed = (LinearLayout.LayoutParams) buttonClearViewed.getLayoutParams();
layoutParamsClearViewed.setMargins(0, 0, 0, 0);
buttonClearViewed.setLayoutParams(layoutParamsClearViewed);
RelativeLayout.LayoutParams layoutParamsActions = (RelativeLayout.LayoutParams) layoutActions.getLayoutParams();
layoutParamsActions.setMarginStart(margin);
layoutParamsActions.setMarginEnd(margin);
layoutActions.setLayoutParams(layoutParamsActions);
}
buttonExpandActions.setColorFilter(themer.getColorFilterAccent());
buttonJumpTop.setColorFilter(themer.getColorFilterAccent());
buttonClearViewed.setColorFilter(themer.getColorFilterAccent());
swipeRefreshThreadList.setOnRefreshListener(() -> {
controllerLinks.reload();
});
AdapterListener adapterListener = new AdapterListener() {
@Override
public void requestMore() {
controllerLinks.loadMore();
}
@Override
public void scrollAndCenter(int position, int height) {
UtilsAnimation.scrollToPositionWithCentering(position, recyclerThreadList, height, 0, 0, false);
}
@Override
public void hideToolbar() {
AppBarLayout.Behavior behaviorAppBar = (AppBarLayout.Behavior) ((CoordinatorLayout.LayoutParams) layoutAppBar.getLayoutParams()).getBehavior();
behaviorAppBar.onNestedFling(layoutCoordinator, layoutAppBar, null, 0, 1000, true);
}
@Override
public void clearDecoration() {
behaviorButtonExpandActions.animateOut(buttonExpandActions);
AppBarLayout.Behavior behaviorAppBar = (AppBarLayout.Behavior) ((CoordinatorLayout.LayoutParams) layoutAppBar.getLayoutParams()).getBehavior();
behaviorAppBar.onNestedFling(layoutCoordinator, layoutAppBar, null, 0, 1000, true);
}
@Override
public void requestDisallowInterceptTouchEventVertical(boolean disallow) {
recyclerThreadList.requestDisallowInterceptTouchEvent(disallow);
swipeRefreshThreadList.requestDisallowInterceptTouchEvent(disallow);
itemTouchHelper.select(null, CustomItemTouchHelper.ACTION_STATE_IDLE);
}
@Override
public void requestDisallowInterceptTouchEventHorizontal(boolean disallow) {
itemTouchHelper.setDisallow(disallow);
}
};
AdapterLink.ViewHolderLink.Listener listener = new LinksListenerBase(mListener.getEventListenerBase()) {
@Override
public void onVote(Link link, AdapterLink.ViewHolderLink viewHolderLink, Likes vote) {
mListener.getEventListenerBase().onVote(link, vote).subscribe(new ObserverEmpty<Link>() {
@Override
public void onError(Throwable e) {
controllerLinks.getEventHolder().getErrors().call(LinksError.VOTE);
}
@Override
public void onNext(Link link) {
controllerLinks.update(link);
}
});
}
@Override
public void onDelete(Link link) {
new AlertDialog.Builder(getContext()).setTitle(R.string.delete_post).setMessage(link.getTitle()).setPositiveButton(R.string.yes, (dialog, which) -> {
mListener.getEventListenerBase().onDelete(link).subscribe(new ObserverEmpty<Link>() {
@Override
public void onError(Throwable e) {
controllerLinks.getEventHolder().getErrors().call(LinksError.DELETE);
}
@Override
public void onNext(Link link) {
controllerLinks.remove(link);
}
});
}).setNegativeButton(R.string.no, null).show();
}
@Override
public void onReport(Link link) {
// TODO: Add link title
new AlertDialog.Builder(getContext()).setTitle(R.string.report_title).setSingleChoiceItems(Report.getDisplayReasons(getResources()), -1, (dialog, which) -> {
reportSelected = Report.values()[which];
}).setPositiveButton(R.string.ok, (dialog, which) -> {
if (reportSelected == Report.OTHER) {
View viewDialog = LayoutInflater.from(getContext()).inflate(R.layout.dialog_text_input, null, false);
final EditText editText = (EditText) viewDialog.findViewById(R.id.edit_text);
editText.setFilters(new InputFilter[] { new InputFilter.LengthFilter(100) });
new AlertDialog.Builder(getContext()).setView(viewDialog).setTitle(R.string.item_report).setPositiveButton(R.string.ok, (dialog1, which1) -> {
mListener.getEventListenerBase().onReport(link, editText.getText().toString()).subscribe(new ObserverError<String>() {
@Override
public void onError(Throwable e) {
controllerLinks.getEventHolder().getErrors().call(LinksError.REPORT);
}
});
}).setNegativeButton(R.string.cancel, (dialog1, which1) -> {
dialog1.dismiss();
}).show();
} else if (reportSelected != null) {
mListener.getEventListenerBase().onReport(link, reportSelected.getReason()).subscribe(new ObserverError<String>() {
@Override
public void onError(Throwable e) {
controllerLinks.getEventHolder().getErrors().call(LinksError.REPORT);
}
});
}
}).setNegativeButton(R.string.cancel, null).show();
}
@Override
public void onSave(Link link) {
if (link.isSaved()) {
mListener.getEventListenerBase().onUnsave(link).subscribe(new ObserverEmpty<Link>() {
@Override
public void onError(Throwable e) {
controllerLinks.getEventHolder().getErrors().call(LinksError.UNSAVE);
}
@Override
public void onNext(Link link) {
controllerLinks.update(link);
}
});
} else {
mListener.getEventListenerBase().onSave(link).subscribe(new ObserverEmpty<Link>() {
@Override
public void onError(Throwable e) {
controllerLinks.getEventHolder().getErrors().call(LinksError.SAVE);
}
@Override
public void onNext(Link link) {
controllerLinks.update(link);
}
});
}
}
@Override
public void onMarkNsfw(Link link) {
if (link.isOver18()) {
mListener.getEventListenerBase().onUnmarkNsfw(link).subscribe(new ObserverEmpty<Link>() {
@Override
public void onError(Throwable e) {
controllerLinks.getEventHolder().getErrors().call(LinksError.UNMARK_NSFW);
}
@Override
public void onNext(Link link) {
controllerLinks.update(link);
}
});
} else {
mListener.getEventListenerBase().onMarkNsfw(link).subscribe(new ObserverEmpty<Link>() {
@Override
public void onError(Throwable e) {
controllerLinks.getEventHolder().getErrors().call(LinksError.MARK_NSFW);
}
@Override
public void onNext(Link link) {
controllerLinks.update(link);
}
});
}
}
};
adapterLinkList = new AdapterLinkList(getActivity(), adapterListener, eventListenerHeader, listener);
adapterLinkGrid = new AdapterLinkGrid(getActivity(), adapterListener, eventListenerHeader, listener);
adapterLink = AppSettings.MODE_GRID.equals(preferences.getString(AppSettings.INTERFACE_MODE, AppSettings.MODE_GRID)) ? adapterLinkGrid : adapterLinkList;
itemDecorationDivider = new ItemDecorationDivider(getActivity(), ItemDecorationDivider.VERTICAL_LIST);
// recyclerThreadList.setItemAnimator(null);
resetAdapter(adapterLink);
recyclerThreadList.addOnScrollListener(new RecyclerView.OnScrollListener() {
@Override
public void onScrollStateChanged(RecyclerView recyclerView, int newState) {
super.onScrollStateChanged(recyclerView, newState);
switch(newState) {
case RecyclerView.SCROLL_STATE_IDLE:
case RecyclerView.SCROLL_STATE_DRAGGING:
picasso.resumeTag(AdapterLink.TAG_PICASSO);
break;
case RecyclerView.SCROLL_STATE_SETTLING:
picasso.pauseTag(AdapterLink.TAG_PICASSO);
break;
}
}
});
itemTouchHelper = new CustomItemTouchHelper(new CustomItemTouchHelper.SimpleCallback(getActivity(), R.drawable.ic_visibility_off_white_24dp, ItemTouchHelper.START | ItemTouchHelper.END, ItemTouchHelper.START | ItemTouchHelper.END) {
@Override
public float getSwipeThreshold(RecyclerView.ViewHolder viewHolder) {
if (layoutManager instanceof StaggeredGridLayoutManager) {
return 1f / ((StaggeredGridLayoutManager) layoutManager).getSpanCount();
}
return 0.5f;
}
@Override
public int getSwipeDirs(RecyclerView recyclerView, RecyclerView.ViewHolder viewHolder) {
if (viewHolder.getAdapterPosition() == 0) {
return 0;
}
ViewGroup.LayoutParams layoutParams = viewHolder.itemView.getLayoutParams();
if (layoutParams instanceof StaggeredGridLayoutManager.LayoutParams && !((StaggeredGridLayoutManager.LayoutParams) layoutParams).isFullSpan()) {
int spanCount = layoutManager instanceof StaggeredGridLayoutManager ? ((StaggeredGridLayoutManager) layoutManager).getSpanCount() : 2;
int spanIndex = ((StaggeredGridLayoutManager.LayoutParams) layoutParams).getSpanIndex() % spanCount;
if (spanIndex == 0) {
return ItemTouchHelper.END;
} else if (spanIndex == spanCount - 1) {
return ItemTouchHelper.START;
}
}
return super.getSwipeDirs(recyclerView, viewHolder);
}
@Override
public boolean isLongPressDragEnabled() {
return false;
}
@Override
public boolean onMove(RecyclerView recyclerView, RecyclerView.ViewHolder viewHolder, RecyclerView.ViewHolder target) {
return false;
}
@Override
public void onSwiped(final RecyclerView.ViewHolder viewHolder, int direction) {
// Offset by 1 due to subreddit header
Link link = controllerLinks.hideLink(viewHolder.getAdapterPosition());
mListener.getEventListenerBase().hide(link);
if (snackbar != null) {
snackbar.dismiss();
}
SpannableString text = new SpannableString(link.isHidden() ? getString(R.string.link_hidden) : getString(R.string.link_shown));
text.setSpan(new ForegroundColorSpan(themer.getColorFilterPrimary().getColor()), 0, text.length(), Spanned.SPAN_INCLUSIVE_EXCLUSIVE);
//noinspection ResourceType
snackbar = Snackbar.make(recyclerThreadList, text, UtilsAnimation.SNACKBAR_DURATION).setActionTextColor(themer.getColorFilterPrimary().getColor()).setAction(R.string.undo, v -> {
mListener.getEventListenerBase().hide(link);
controllerLinks.reshowLastHiddenLink();
});
snackbar.getView().setBackgroundColor(themer.getColorPrimary());
snackbar.show();
}
});
itemTouchHelper.attachToRecyclerView(recyclerThreadList);
recyclerThreadList.addOnItemTouchListener(new RecyclerView.OnItemTouchListener() {
@Override
public boolean onInterceptTouchEvent(RecyclerView rv, MotionEvent e) {
// rv.getChildViewHolder(rv.findChildViewUnder(e.getX(), e.getY()));
return false;
}
@Override
public void onTouchEvent(RecyclerView rv, MotionEvent e) {
}
@Override
public void onRequestDisallowInterceptTouchEvent(boolean disallowIntercept) {
}
});
if (layoutManager instanceof LinearLayoutManager) {
recyclerThreadList.setPadding(0, 0, 0, 0);
} else {
int padding = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 2, getResources().getDisplayMetrics());
recyclerThreadList.setPadding(padding, 0, padding, 0);
}
textSidebar.setMovementMethod(LinkMovementMethod.getInstance());
buttonSubscribe.setOnClickListener(v -> controllerLinks.subscribe());
return view;
}
use of android.text.style.ForegroundColorSpan in project Reader by TheKeeperOfPie.
the class FragmentHistory method onCreateView.
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
view = inflater.inflate(R.layout.fragment_history, container, false);
layoutCoordinator = (CoordinatorLayout) view.findViewById(R.id.layout_coordinator);
layoutAppBar = (AppBarLayout) view.findViewById(R.id.layout_app_bar);
int styleColorBackground = AppSettings.THEME_DARK.equals(mListener.getThemeBackground()) ? R.style.MenuDark : R.style.MenuLight;
ContextThemeWrapper contextThemeWrapper = new ContextThemeWrapper(new ThemeWrapper(getActivity(), UtilsColor.getThemeForColor(getResources(), themer.getColorPrimary(), mListener)), styleColorBackground);
toolbar = (Toolbar) getActivity().getLayoutInflater().cloneInContext(contextThemeWrapper).inflate(R.layout.toolbar, layoutAppBar, false);
layoutAppBar.addView(toolbar);
((AppBarLayout.LayoutParams) toolbar.getLayoutParams()).setScrollFlags(AppBarLayout.LayoutParams.SCROLL_FLAG_SCROLL | AppBarLayout.LayoutParams.SCROLL_FLAG_ENTER_ALWAYS);
if (getFragmentManager().getBackStackEntryCount() <= 1) {
toolbar.setNavigationIcon(R.drawable.ic_menu_white_24dp);
toolbar.setNavigationOnClickListener(v -> mListener.openDrawer());
} else {
toolbar.setNavigationIcon(R.drawable.ic_arrow_back_white_24dp);
toolbar.setNavigationOnClickListener(v -> mListener.onNavigationBackClick());
}
toolbar.getNavigationIcon().mutate().setColorFilter(themer.getColorFilterPrimary());
toolbar.setTitleTextColor(themer.getColorFilterPrimary().getColor());
toolbar.setTitle(R.string.history);
setUpOptionsMenu();
swipeRefreshHistory = (SwipeRefreshLayout) view.findViewById(R.id.swipe_refresh_history);
swipeRefreshHistory.setOnRefreshListener(() -> controllerHistory.reload());
AdapterLink.ViewHolderHeader.EventListener eventListenerHeader = new AdapterLink.ViewHolderHeader.EventListener() {
@Override
public void onClickSubmit(Reddit.PostType postType) {
}
@Override
public void showSidebar() {
}
};
AdapterListener adapterListener = new AdapterListener() {
@Override
public void requestMore() {
controllerHistory.loadMoreLinks().observeOn(AndroidSchedulers.mainThread()).subscribe(new ObserverError<Listing>() {
@Override
public void onError(Throwable e) {
Toast.makeText(getContext(), getContext().getString(R.string.error_loading_links), Toast.LENGTH_SHORT).show();
}
});
}
@Override
public void scrollAndCenter(int position, int height) {
UtilsAnimation.scrollToPositionWithCentering(position, recyclerHistory, false);
}
@Override
public void hideToolbar() {
AppBarLayout.Behavior behaviorAppBar = (AppBarLayout.Behavior) ((CoordinatorLayout.LayoutParams) layoutAppBar.getLayoutParams()).getBehavior();
behaviorAppBar.onNestedFling(layoutCoordinator, layoutAppBar, null, 0, 1000, true);
}
@Override
public void clearDecoration() {
AppBarLayout.Behavior behaviorAppBar = (AppBarLayout.Behavior) ((CoordinatorLayout.LayoutParams) layoutAppBar.getLayoutParams()).getBehavior();
behaviorAppBar.onNestedFling(layoutCoordinator, layoutAppBar, null, 0, 1000, true);
}
@Override
public void requestDisallowInterceptTouchEventVertical(boolean disallow) {
swipeRefreshHistory.requestDisallowInterceptTouchEvent(disallow);
recyclerHistory.requestDisallowInterceptTouchEvent(disallow);
itemTouchHelper.select(null, CustomItemTouchHelper.ACTION_STATE_IDLE);
}
@Override
public void requestDisallowInterceptTouchEventHorizontal(boolean disallow) {
itemTouchHelper.setDisallow(disallow);
}
};
AdapterLink.ViewHolderLink.Listener listenerLink = new AdapterLink.ViewHolderLink.Listener() {
@Override
public void onSubmitComment(Link link, String text) {
}
@Override
public void onDownloadImage(Link link) {
}
@Override
public void onDownloadImage(Link link, String title, String fileName, String url) {
}
@Override
public void onLoadUrl(Link link, boolean forceExternal) {
}
@Override
public void onShowFullEditor(Link link) {
}
@Override
public void onVote(Link link, AdapterLink.ViewHolderLink viewHolderLink, Likes vote) {
}
@Override
public void onCopyText(Link link) {
}
@Override
public void onEdit(Link link) {
}
@Override
public void onDelete(Link link) {
}
@Override
public void onReport(Link link) {
}
@Override
public void onSave(Link link) {
}
@Override
public void onShowComments(Link link, AdapterLink.ViewHolderLink viewHolderLink, Source source) {
}
@Override
public void onShowError(String error) {
}
@Override
public void onMarkNsfw(Link link) {
}
};
if (adapterLinkList == null) {
adapterLinkList = new AdapterHistoryLinkList(getActivity(), adapterListener, eventListenerHeader, listenerLink);
}
if (adapterLinkGrid == null) {
adapterLinkGrid = new AdapterHistoryLinkGrid(getActivity(), adapterListener, eventListenerHeader, listenerLink);
}
if (AppSettings.MODE_LIST.equals(preferences.getString(AppSettings.INTERFACE_MODE, AppSettings.MODE_GRID))) {
adapterLink = adapterLinkList;
} else {
adapterLink = adapterLinkGrid;
}
layoutManager = adapterLink.getLayoutManager();
itemDecorationDivider = new ItemDecorationDivider(getActivity(), ItemDecorationDivider.VERTICAL_LIST);
recyclerHistory = (RecyclerView) view.findViewById(R.id.recycler_history);
recyclerHistory.setHasFixedSize(true);
recyclerHistory.setItemAnimator(null);
resetAdapter(adapterLink);
itemTouchHelper = new CustomItemTouchHelper(new CustomItemTouchHelper.SimpleCallback(getActivity(), R.drawable.ic_visibility_off_white_24dp, ItemTouchHelper.START | ItemTouchHelper.END, ItemTouchHelper.START | ItemTouchHelper.END) {
@Override
public float getSwipeThreshold(RecyclerView.ViewHolder viewHolder) {
if (layoutManager instanceof StaggeredGridLayoutManager) {
return 1f / ((StaggeredGridLayoutManager) layoutManager).getSpanCount();
}
return 0.4f;
}
@Override
public int getSwipeDirs(RecyclerView recyclerView, RecyclerView.ViewHolder viewHolder) {
if (viewHolder.getAdapterPosition() == 0) {
return 0;
}
ViewGroup.LayoutParams layoutParams = viewHolder.itemView.getLayoutParams();
if (layoutParams instanceof StaggeredGridLayoutManager.LayoutParams && !((StaggeredGridLayoutManager.LayoutParams) layoutParams).isFullSpan()) {
int spanCount = layoutManager instanceof StaggeredGridLayoutManager ? ((StaggeredGridLayoutManager) layoutManager).getSpanCount() : 2;
int spanIndex = ((StaggeredGridLayoutManager.LayoutParams) layoutParams).getSpanIndex() % spanCount;
if (spanIndex == 0) {
return ItemTouchHelper.END;
} else if (spanIndex == spanCount - 1) {
return ItemTouchHelper.START;
}
}
return super.getSwipeDirs(recyclerView, viewHolder);
}
@Override
public boolean isLongPressDragEnabled() {
return false;
}
@Override
public boolean onMove(RecyclerView recyclerView, RecyclerView.ViewHolder viewHolder, RecyclerView.ViewHolder target) {
return false;
}
@Override
public void onSwiped(final RecyclerView.ViewHolder viewHolder, int direction) {
final int position = viewHolder.getAdapterPosition();
final Link link = controllerHistory.remove(position);
if (snackbar != null) {
snackbar.dismiss();
}
SpannableString text = new SpannableString(getString(R.string.history_entry_deleted));
text.setSpan(new ForegroundColorSpan(themer.getColorFilterPrimary().getColor()), 0, text.length(), Spanned.SPAN_INCLUSIVE_EXCLUSIVE);
//noinspection ResourceType
snackbar = Snackbar.make(recyclerHistory, text, UtilsAnimation.SNACKBAR_DURATION).setActionTextColor(themer.getColorFilterPrimary().getColor()).setAction(R.string.undo, new View.OnClickListener() {
@Override
public void onClick(View v) {
controllerHistory.add(position, link);
recyclerHistory.invalidate();
}
});
snackbar.getView().setBackgroundColor(themer.getColorPrimary());
snackbar.show();
}
});
itemTouchHelper.attachToRecyclerView(recyclerHistory);
if (layoutManager instanceof LinearLayoutManager) {
recyclerHistory.setPadding(0, 0, 0, 0);
} else {
int padding = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 2, getResources().getDisplayMetrics());
recyclerHistory.setPadding(padding, 0, padding, 0);
}
return view;
}
use of android.text.style.ForegroundColorSpan in project android-ocr by rmtheis.
the class CaptureActivity method handleOcrContinuousDecode.
/**
* Version of handleOcrContinuousDecode for failed OCR requests. Displays a failure message.
*
* @param obj Metadata for the failed OCR request.
*/
void handleOcrContinuousDecode(OcrResultFailure obj) {
lastResult = null;
viewfinderView.removeResultText();
// Reset the text in the recognized text box.
statusViewTop.setText("");
if (CONTINUOUS_DISPLAY_METADATA) {
// Color text delimited by '-' as red.
statusViewBottom.setTextSize(14);
CharSequence cs = setSpanBetweenTokens("OCR: " + sourceLanguageReadable + " - OCR failed - Time required: " + obj.getTimeRequired() + " ms", "-", new ForegroundColorSpan(0xFFFF0000));
statusViewBottom.setText(cs);
}
}
use of android.text.style.ForegroundColorSpan in project platform_frameworks_base by android.
the class HtmlToSpannedConverter method withinParagraph.
private static void withinParagraph(StringBuilder out, Spanned text, int start, int end) {
int next;
for (int i = start; i < end; i = next) {
next = text.nextSpanTransition(i, end, CharacterStyle.class);
CharacterStyle[] style = text.getSpans(i, next, CharacterStyle.class);
for (int j = 0; j < style.length; j++) {
if (style[j] instanceof StyleSpan) {
int s = ((StyleSpan) style[j]).getStyle();
if ((s & Typeface.BOLD) != 0) {
out.append("<b>");
}
if ((s & Typeface.ITALIC) != 0) {
out.append("<i>");
}
}
if (style[j] instanceof TypefaceSpan) {
String s = ((TypefaceSpan) style[j]).getFamily();
if ("monospace".equals(s)) {
out.append("<tt>");
}
}
if (style[j] instanceof SuperscriptSpan) {
out.append("<sup>");
}
if (style[j] instanceof SubscriptSpan) {
out.append("<sub>");
}
if (style[j] instanceof UnderlineSpan) {
out.append("<u>");
}
if (style[j] instanceof StrikethroughSpan) {
out.append("<span style=\"text-decoration:line-through;\">");
}
if (style[j] instanceof URLSpan) {
out.append("<a href=\"");
out.append(((URLSpan) style[j]).getURL());
out.append("\">");
}
if (style[j] instanceof ImageSpan) {
out.append("<img src=\"");
out.append(((ImageSpan) style[j]).getSource());
out.append("\">");
// Don't output the dummy character underlying the image.
i = next;
}
if (style[j] instanceof AbsoluteSizeSpan) {
AbsoluteSizeSpan s = ((AbsoluteSizeSpan) style[j]);
float sizeDip = s.getSize();
if (!s.getDip()) {
Application application = ActivityThread.currentApplication();
sizeDip /= application.getResources().getDisplayMetrics().density;
}
// px in CSS is the equivalance of dip in Android
out.append(String.format("<span style=\"font-size:%.0fpx\";>", sizeDip));
}
if (style[j] instanceof RelativeSizeSpan) {
float sizeEm = ((RelativeSizeSpan) style[j]).getSizeChange();
out.append(String.format("<span style=\"font-size:%.2fem;\">", sizeEm));
}
if (style[j] instanceof ForegroundColorSpan) {
int color = ((ForegroundColorSpan) style[j]).getForegroundColor();
out.append(String.format("<span style=\"color:#%06X;\">", 0xFFFFFF & color));
}
if (style[j] instanceof BackgroundColorSpan) {
int color = ((BackgroundColorSpan) style[j]).getBackgroundColor();
out.append(String.format("<span style=\"background-color:#%06X;\">", 0xFFFFFF & color));
}
}
withinStyle(out, text, i, next);
for (int j = style.length - 1; j >= 0; j--) {
if (style[j] instanceof BackgroundColorSpan) {
out.append("</span>");
}
if (style[j] instanceof ForegroundColorSpan) {
out.append("</span>");
}
if (style[j] instanceof RelativeSizeSpan) {
out.append("</span>");
}
if (style[j] instanceof AbsoluteSizeSpan) {
out.append("</span>");
}
if (style[j] instanceof URLSpan) {
out.append("</a>");
}
if (style[j] instanceof StrikethroughSpan) {
out.append("</span>");
}
if (style[j] instanceof UnderlineSpan) {
out.append("</u>");
}
if (style[j] instanceof SubscriptSpan) {
out.append("</sub>");
}
if (style[j] instanceof SuperscriptSpan) {
out.append("</sup>");
}
if (style[j] instanceof TypefaceSpan) {
String s = ((TypefaceSpan) style[j]).getFamily();
if (s.equals("monospace")) {
out.append("</tt>");
}
}
if (style[j] instanceof StyleSpan) {
int s = ((StyleSpan) style[j]).getStyle();
if ((s & Typeface.BOLD) != 0) {
out.append("</b>");
}
if ((s & Typeface.ITALIC) != 0) {
out.append("</i>");
}
}
}
}
}
Aggregations