in.uncod.android.bypass.Bypass Java Examples

The following examples show how to use in.uncod.android.bypass.Bypass. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: PreviewDialogFragment.java    From android-discourse with Apache License 2.0 6 votes vote down vote up
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
    String message = getArguments().getString(Utils.EXTRA_MSG);

    Bypass bypass = new Bypass();

    CharSequence string = bypass.markdownToSpannable(message);

    return new AlertDialog.Builder(getActivity()).setTitle(R.string.action_preview).setMessage(string).setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int whichButton) {
                    dialog.dismiss();
                }
            }).create();

}
 
Example #2
Source File: Tools.java    From intra42 with Apache License 2.0 5 votes vote down vote up
public static void setMarkdown(Context context, TextView textView, String content) {
    if (AppSettings.Advanced.getAllowMarkdownRenderer(context)) {
        Bypass bypass = new Bypass(context);

        content = content.replace(":\r\n-", ":\r\n\r\n-");

        CharSequence string = bypass.markdownToSpannable(content, new BypassPicassoImageGetter(textView));

        textView.setText(string);
        textView.setMovementMethod(LinkMovementMethod.getInstance());
    } else
        textView.setText(content);
}
 
Example #3
Source File: BaseRecyclerAdapter.java    From intra42 with Apache License 2.0 5 votes vote down vote up
void onBindView(Events item) {

            Context context = itemView.getContext();

            textViewName.setText(item.name);
            TagSpanGenerator span = new TagSpanGenerator(context);
            if (item.kind != null)
                span.addTag(item.kind.getString(context), item.kind.getColorInt(context));
            span.addText(item.name);
            textViewName.setText(span.getString());

            String content = item.description;
            content = content.replace("\r\n\r\n", " ");
            content = content.replace("\n\n", " ");
            content = content.replace("\r\n", " ");
            content = content.replace('\n', ' ');
            textViewDescription.setText(content);

            Bypass b = new Bypass(context);
            String content_tmp = b.markdownToSpannable(item.description).toString().replace('\n', ' ');
            textViewDescription.setText(content_tmp);

            String time;
            time = DateUtils.formatDateRange(context, item.beginAt.getTime(), item.endAt.getTime(), DateUtils.FORMAT_SHOW_TIME);
            if (time.length() > 30)
                time = time.replace(" – ", "\n");
            textViewTime.setText(time);
            textViewPlace.setText(item.location);

            if (item.nbrSubscribers >= item.maxPeople && item.maxPeople > 0) {
                textViewFull.setVisibility(View.VISIBLE);
            } else
                textViewFull.setVisibility(View.GONE);
        }
 
Example #4
Source File: HtmlUtils.java    From android-proguards with Apache License 2.0 5 votes vote down vote up
/**
 * Parse Markdown and plain-text links and set on the {@link TextView} with proper clickable
 * spans.
 */
public static void parseMarkdownAndSetText(
        TextView textView,
        String input,
        Bypass markdown,
        Bypass.LoadImageCallback loadImageCallback) {
    if (TextUtils.isEmpty(input)) return;
    setTextWithNiceLinks(textView,
            parseMarkdownAndPlainLinks(textView, input, markdown, loadImageCallback));
}
 
Example #5
Source File: MarkupUtil.java    From commcare-android with Apache License 2.0 5 votes vote down vote up
private static CharSequence generateMarkdown(Context c, String message) {
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN) {
        return trimTrailingWhitespace(
                new Bypass(c).markdownToSpannable(convertCharacterEncodings(message)));
    }
    return trimTrailingWhitespace(
            Markwon.markdown(c, convertCharacterEncodings(message)));
}
 
Example #6
Source File: AboutActivity.java    From materialup with Apache License 2.0 4 votes vote down vote up
public AboutPagerAdapter(Context context) {
    layoutInflater = LayoutInflater.from(context);
    markdown = new Bypass(context, new Bypass.Options());
}
 
Example #7
Source File: DesignerNewsStory.java    From android-proguards with Apache License 2.0 4 votes vote down vote up
private void bindComment(final CommentHolder holder, List<Object> partialChanges) {
    // Check if this is a partial update for expanding/collapsing a comment. If it is we
    // can do a partial bind as the bound data has not changed.
    if (partialChanges == null || partialChanges.isEmpty() ||
            !(partialChanges.contains(CommentAnimator.COLLAPSE_COMMENT)
                || partialChanges.contains(CommentAnimator.EXPAND_COMMENT))) {

        final Comment comment = getComment(holder.getAdapterPosition());
        HtmlUtils.parseMarkdownAndSetText(holder.comment, comment.body, markdown,
                new Bypass.LoadImageCallback() {
            @Override
            public void loadImage(String src, ImageLoadingSpan loadingSpan) {
                Glide.with(DesignerNewsStory.this)
                        .load(src)
                        .asBitmap()
                        .diskCacheStrategy(DiskCacheStrategy.ALL)
                        .into(new ImageSpanTarget(holder.comment, loadingSpan));
            }
        });
        if (comment.user_display_name != null) {
            holder.author.setText(comment.user_display_name.toLowerCase());
        }
        holder.author.setOriginalPoster(isOP(comment.user_id));
        if (comment.created_at != null) {
            holder.timeAgo.setText(
                    DateUtils.getRelativeTimeSpanString(comment.created_at.getTime(),
                            System.currentTimeMillis(),
                            DateUtils.SECOND_IN_MILLIS)
                            .toString().toLowerCase());
        }
        // FIXME updating drawable doesn't seem to be working, just create a new one
        //((ThreadedCommentDrawable) holder.threadDepth.getDrawable())
        //     .setDepth(comment.depth);

        holder.threadDepth.setImageDrawable(
                new ThreadedCommentDrawable(threadWidth, threadGap, comment.depth));
    }

    // set/clear expanded comment state
    holder.itemView.setActivated(holder.getAdapterPosition() == expandedCommentPosition);
    if (holder.getAdapterPosition() == expandedCommentPosition) {
        final int threadDepthWidth = holder.threadDepth.getDrawable().getIntrinsicWidth();
        final float leftShift = -(threadDepthWidth + ((ViewGroup.MarginLayoutParams)
                holder.threadDepth.getLayoutParams()).getMarginEnd());
        holder.author.setTranslationX(leftShift);
        holder.comment.setTranslationX(leftShift);
        holder.threadDepth.setTranslationX(-(threadDepthWidth
                + ((ViewGroup.MarginLayoutParams)
                holder.threadDepth.getLayoutParams()).getMarginStart()));
    } else {
        holder.threadDepth.setTranslationX(0f);
        holder.author.setTranslationX(0f);
        holder.comment.setTranslationX(0f);
    }
}
 
Example #8
Source File: AboutActivity.java    From android-proguards with Apache License 2.0 4 votes vote down vote up
AboutPagerAdapter(@NonNull Activity host) {
    this.host = host;
    resources = host.getResources();
    layoutInflater = LayoutInflater.from(host);
    markdown = new Bypass(host, new Bypass.Options());
}
 
Example #9
Source File: HtmlUtils.java    From android-proguards with Apache License 2.0 3 votes vote down vote up
/**
 * Parse Markdown and plain-text links.
 * <p/>
 * {@link Bypass} does not handle plain text links (i.e. not md syntax) and requires a
 * {@code String} input (i.e. squashes any spans). {@link Linkify} handles plain links but also
 * removes any existing spans. So we can't just run our input through both.
 * <p/>
 * Instead we use the markdown lib, then take a copy of the output and Linkify
 * <strong>that</strong>. We then find any {@link URLSpan}s and add them to the markdown output.
 * Best of both worlds.
 */
public static CharSequence parseMarkdownAndPlainLinks(
        TextView textView,
        String input,
        Bypass markdown,
        Bypass.LoadImageCallback loadImageCallback) {
    CharSequence markedUp = markdown.markdownToSpannable(input, textView, loadImageCallback);
    return linkifyPlainLinks(
            markedUp, textView.getLinkTextColors(), textView.getHighlightColor());
}