com.hippo.text.Html Java Examples

The following examples show how to use com.hippo.text.Html. 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: AnalyticsScene.java    From MHViewer with Apache License 2.0 6 votes vote down vote up
@Nullable
@Override
public View onCreateView2(LayoutInflater inflater, @Nullable ViewGroup container,
        @Nullable Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.scene_analytics, container, false);

    mReject = ViewUtils.$$(view, R.id.reject);
    mAccept = ViewUtils.$$(view, R.id.accept);
    TextView text = (TextView) ViewUtils.$$(view, R.id.text);

    text.setText(Html.fromHtml(getString(R.string.analytics_explain)));
    text.setMovementMethod(LinkMovementMethod2.getInstance());

    mReject.setOnClickListener(this);
    mAccept.setOnClickListener(this);

    return view;
}
 
Example #2
Source File: AnalyticsScene.java    From EhViewer with Apache License 2.0 6 votes vote down vote up
@Nullable
@Override
public View onCreateView2(LayoutInflater inflater, @Nullable ViewGroup container,
        @Nullable Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.scene_analytics, container, false);

    mReject = ViewUtils.$$(view, R.id.reject);
    mAccept = ViewUtils.$$(view, R.id.accept);
    TextView text = (TextView) ViewUtils.$$(view, R.id.text);

    text.setText(Html.fromHtml(getString(R.string.analytics_explain)));
    text.setMovementMethod(LinkMovementMethod2.getInstance());

    mReject.setOnClickListener(this);
    mAccept.setOnClickListener(this);

    return view;
}
 
Example #3
Source File: SortForumsActivity.java    From Nimingban with Apache License 2.0 6 votes vote down vote up
@Override
public void onBindViewHolder(ForumHolder holder, int position) {
    if (position > 0) {
        ACForumRaw raw = mLazyList.get(position - 1);
        holder.visibility.setActivated(raw.getVisibility());
        if (mAutoSorting) {
            holder.dragHandler.setVisibility(View.GONE);
            holder.pinning.setVisibility(View.VISIBLE);
            holder.pinning.setActivated(ForumAutoSortingUtils.isACForumPinned(raw));
        } else {
            holder.pinning.setVisibility(View.GONE);
            holder.dragHandler.setVisibility(View.VISIBLE);
        }

        CharSequence name = mForumNames.get(position);
        if (name == null) {
            if (raw.getDisplayname() == null) {
                name = "Forum";
            } else {
                name = Html.fromHtml(raw.getDisplayname());
            }
            mForumNames.put(position, name);
        }
        holder.forum.setText(name);
    }
}
 
Example #4
Source File: ACSearchItem.java    From Nimingban with Apache License 2.0 6 votes vote down vote up
@Override
public void generate(Site site) {
    mSite = site;

    mTime = ACPost.parseTime(now);

    mUser = ACItemUtils.handleUser(Html.fromHtml(userid), getNMBPostId(), getNMBId());

    mContent = ACItemUtils.generateContent(content, sage, title, "");

    if (!TextUtils.isEmpty(img)) {
        String ext2 = ext;
        if (".jpe".equals(ext2)) {
            ext2 = ".jpeg";
        }
        String key = img + ext2;
        mThumbKey = "thumb/" + key;
        mImageKey = "image/" + key;
        ACSite acSite = ACSite.getInstance();
        mThumbUrl = acSite.getPictureUrl(mThumbKey);
        mImageUrl = acSite.getPictureUrl(mImageKey);
    }
}
 
Example #5
Source File: MessagePreference.java    From EhViewer with Apache License 2.0 5 votes vote down vote up
public void init(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
    TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.MessagePreference, defStyleAttr, defStyleRes);
    String message = a.getString(R.styleable.MessagePreference_dialogMessage);
    if (a.getBoolean(R.styleable.MessagePreference_dialogMessageHtml, false)) {
        mDialogMessage = Html.fromHtml(message);
    } else {
        mDialogMessage = message;
    }
    mDialogMessageLinkify = a.getBoolean(R.styleable.MessagePreference_dialogMessageLinkify, false);
    a.recycle();
}
 
Example #6
Source File: IdentityCookiePreference.java    From EhViewer with Apache License 2.0 5 votes vote down vote up
private void init() {
    EhCookieStore store = EhApplication.getEhCookieStore(getContext());
    List<Cookie> eCookies = store.getCookies(HttpUrl.get(EhUrl.HOST_E));
    List<Cookie> exCookies = store.getCookies(HttpUrl.get(EhUrl.HOST_EX));
    List<Cookie> cookies = new LinkedList<>(eCookies);
    cookies.addAll(exCookies);

    String ipbMemberId = null;
    String ipbPassHash = null;
    String igneous = null;

    for (int i = 0, n = cookies.size(); i < n; i++) {
        Cookie cookie = cookies.get(i);
        switch (cookie.name()) {
            case EhCookieStore.KEY_IPD_MEMBER_ID:
                ipbMemberId = cookie.value();
                break;
            case EhCookieStore.KEY_IPD_PASS_HASH:
                ipbPassHash = cookie.value();
                break;
            case EhCookieStore.KEY_IGNEOUS:
                igneous = cookie.value();
                break;
        }
    }

    if (ipbMemberId != null || ipbPassHash != null || igneous != null) {
        message = EhCookieStore.KEY_IPD_MEMBER_ID + ": " + ipbMemberId + "<br>"
                + EhCookieStore.KEY_IPD_PASS_HASH + ": " + ipbPassHash + "<br>"
                + EhCookieStore.KEY_IGNEOUS + ": " + igneous;
        setDialogMessage(Html.fromHtml(getContext().getString(R.string.settings_eh_identity_cookies_signed, message)));
        message = message.replace("<br>", "\n");
    } else {
        setDialogMessage(getContext().getString(R.string.settings_eh_identity_cookies_tourist));
    }
}
 
Example #7
Source File: CommonOperations.java    From EhViewer with Apache License 2.0 5 votes vote down vote up
private void handleResult(JSONObject jo) {
    if (null == jo || mActivity.isFinishing()) {
        return;
    }

    String versionName;
    int versionCode;
    String size;
    CharSequence info;
    String url;

    try {
        PackageManager pm = mActivity.getPackageManager();
        PackageInfo pi = pm.getPackageInfo(mActivity.getPackageName(), PackageManager.GET_ACTIVITIES);
        int currentVersionCode = pi.versionCode;
        versionCode = jo.getInt("version_code");
        if (currentVersionCode >= versionCode) {
            // Update to date
            if (mFeedback) {
                showUpToDateDialog();
            }
            return;
        }

        versionName = jo.getString("version_name");
        size = FileUtils.humanReadableByteCount(jo.getLong("size"), false);
        info = Html.fromHtml(jo.getString("info"));
        url = jo.getString("url");
    } catch (Throwable e) {
        ExceptionUtils.throwIfFatal(e);
        return;
    }

    if (mFeedback || versionCode != Settings.getSkipUpdateVersion()) {
        showUpdateDialog(versionName, versionCode, size, info, url);
    }
}
 
Example #8
Source File: ACItemUtils.java    From Nimingban with Apache License 2.0 5 votes vote down vote up
public static CharSequence generateContent(String content) {
    content = replaceBracketsH(content);
    CharSequence charSequence;
    charSequence = Html.fromHtml(content, null, AC_HTML_TAG_HANDLER);
    charSequence = handleReference(charSequence);
    charSequence = handleTextUrl(charSequence);
    charSequence = handleAcUrl(charSequence);

    return charSequence;
}
 
Example #9
Source File: ACReply.java    From Nimingban with Apache License 2.0 5 votes vote down vote up
@Override
public void generate(Site site) {
    mSite = site;

    mTime = ACPost.parseTime(now);

    if ("1".equals(admin)) {
        Spannable spannable = new SpannableString(userid);
        spannable.setSpan(new ForegroundColorSpan(Color.RED), 0, userid.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
        mUser = spannable;
    } else {
        mUser = ACItemUtils.handleUser(Html.fromHtml(userid), getNMBPostId(), getNMBId());
    }

    mContent = ACItemUtils.generateContent(content, sage, title, name);

    if (!TextUtils.isEmpty(img)) {
        String ext2 = ext;
        if (".jpe".equals(ext2)) {
            ext2 = ".jpeg";
        }
        String key = img + ext2;
        mThumbKey = "thumb/" + key;
        mImageKey = "image/" + key;
        ACSite acSite = ACSite.getInstance();
        mThumbUrl = acSite.getPictureUrl(mThumbKey);
        mImageUrl = acSite.getPictureUrl(mImageKey);
    }
}
 
Example #10
Source File: ACFeed.java    From Nimingban with Apache License 2.0 5 votes vote down vote up
@Override
public void generate(Site site) {
    mSite = site;

    mTime = ACPost.parseTime(now);

    if ("1".equals(admin)) {
        Spannable spannable = new SpannableString(userid);
        spannable.setSpan(new ForegroundColorSpan(Color.RED), 0, userid.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
        mUser = spannable;
    } else {
        mUser = ACItemUtils.handleUser(Html.fromHtml(userid), getNMBPostId(), getNMBId());
    }

    mContent = ACItemUtils.generateContent(content, "", title, name);

    if (!TextUtils.isEmpty(img)) {
        String ext2 = ext;
        if (".jpe".equals(ext2)) {
            ext2 = ".jpeg";
        }
        String key = img + ext2;
        mThumbKey = "thumb/" + key;
        mImageKey = "image/" + key;
        ACSite acSite = ACSite.getInstance();
        mThumbUrl = acSite.getPictureUrl(mThumbKey);
        mImageUrl = acSite.getPictureUrl(mImageKey);
    }
}
 
Example #11
Source File: UpdateHelper.java    From Nimingban with Apache License 2.0 5 votes vote down vote up
public static void showUpdateDialog(final Activity activity, final UpdateStatus status) {
    if (activity.isFinishing()) {
        return;
    }

    if (status == null) {
        return;
    }

    int versionCode = Settings.getVersionCode();
    if (versionCode >= status.versionCode) {
        return;
    }

    if (status.info == null || status.versionName == null || status.size == 0) {
        return;
    }

    Resources resources = activity.getResources();
    CharSequence message = TextUtils2.combine(
            resources.getString(R.string.version) + ": " + status.versionName + '\n' +
                    resources.getString(R.string.size) + ": " + FileUtils.humanReadableByteCount(status.size, false) + "\n\n",
            Html.fromHtml(status.info));
    new AlertDialog.Builder(activity)
            .setTitle(R.string.download_update)
            .setMessage(message)
            .setPositiveButton(R.string.download, new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    showSelectDialog(activity, status);
                }
            })
            .show();
}
 
Example #12
Source File: DisplayForum.java    From Nimingban with Apache License 2.0 5 votes vote down vote up
@Override
public CharSequence getNMBDisplayname() {
    if (name == null) {
        if (displayname == null) {
            name = "Forum";
        } else {
            name = Html.fromHtml(displayname);
        }
    }
    return name;
}
 
Example #13
Source File: MessagePreference.java    From MHViewer with Apache License 2.0 5 votes vote down vote up
public void init(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
    TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.MessagePreference, defStyleAttr, defStyleRes);
    String message = a.getString(R.styleable.MessagePreference_dialogMessage);
    if (a.getBoolean(R.styleable.MessagePreference_dialogMessageHtml, false)) {
        mDialogMessage = Html.fromHtml(message);
    } else {
        mDialogMessage = message;
    }
    mDialogMessageLinkify = a.getBoolean(R.styleable.MessagePreference_dialogMessageLinkify, false);
    a.recycle();
}
 
Example #14
Source File: IdentityCookiePreference.java    From MHViewer with Apache License 2.0 5 votes vote down vote up
private void init() {
    EhCookieStore store = EhApplication.getEhCookieStore(getContext());
    List<Cookie> eCookies = store.getCookies(HttpUrl.get(EhUrl.HOST_E));
    List<Cookie> exCookies = store.getCookies(HttpUrl.get(EhUrl.HOST_EX));
    List<Cookie> cookies = new LinkedList<>(eCookies);
    cookies.addAll(exCookies);

    String ipbMemberId = null;
    String ipbPassHash = null;
    String igneous = null;

    for (int i = 0, n = cookies.size(); i < n; i++) {
        Cookie cookie = cookies.get(i);
        switch (cookie.name()) {
            case EhCookieStore.KEY_IPD_MEMBER_ID:
                ipbMemberId = cookie.value();
                break;
            case EhCookieStore.KEY_IPD_PASS_HASH:
                ipbPassHash = cookie.value();
                break;
            case EhCookieStore.KEY_IGNEOUS:
                igneous = cookie.value();
                break;
        }
    }

    if (ipbMemberId != null || ipbPassHash != null || igneous != null) {
        message = EhCookieStore.KEY_IPD_MEMBER_ID + ": " + ipbMemberId + "<br>"
                + EhCookieStore.KEY_IPD_PASS_HASH + ": " + ipbPassHash + "<br>"
                + EhCookieStore.KEY_IGNEOUS + ": " + igneous;
        setDialogMessage(Html.fromHtml(getContext().getString(R.string.settings_eh_identity_cookies_signed, message)));
        message = message.replace("<br>", "\n");
    } else {
        setDialogMessage(getContext().getString(R.string.settings_eh_identity_cookies_tourist));
    }
}
 
Example #15
Source File: CommonOperations.java    From MHViewer with Apache License 2.0 5 votes vote down vote up
private void handleResult(JSONObject jo) {
    if (null == jo || mActivity.isFinishing()) {
        return;
    }

    String versionName;
    int versionCode;
    String size;
    CharSequence info;
    String url;

    try {
        PackageManager pm = mActivity.getPackageManager();
        PackageInfo pi = pm.getPackageInfo(mActivity.getPackageName(), PackageManager.GET_ACTIVITIES);
        int currentVersionCode = pi.versionCode;
        versionCode = jo.getInt("version_code");
        if (currentVersionCode >= versionCode) {
            // Update to date
            if (mFeedback) {
                showUpToDateDialog();
            }
            return;
        }

        versionName = jo.getString("version_name");
        size = FileUtils.humanReadableByteCount(jo.getLong("size"), false);
        info = Html.fromHtml(jo.getString("info"));
        url = jo.getString("url");
    } catch (Throwable e) {
        ExceptionUtils.throwIfFatal(e);
        return;
    }

    if (mFeedback || versionCode != Settings.getSkipUpdateVersion()) {
        showUpdateDialog(versionName, versionCode, size, info, url);
    }
}
 
Example #16
Source File: ACPost.java    From Nimingban with Apache License 2.0 4 votes vote down vote up
@Override
public void generate(Site site) {
    mSite = site;

    mTime = parseTime(now);

    if ("1".equals(admin)) {
        Spannable spannable = new SpannableString(userid);
        spannable.setSpan(new ForegroundColorSpan(Color.RED), 0, userid.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
        mUser = spannable;
    } else {
        mUser = ACItemUtils.handleUser(Html.fromHtml(userid), getNMBPostId(), getNMBId());
    }

    mReplyCount = NumberUtils.parseIntSafely(replyCount, -1);

    mContent = ACItemUtils.generateContent(content, sage, title, name);

    if (!TextUtils.isEmpty(img)) {
        String ext2 = ext;
        if (".jpe".equals(ext2)) {
            ext2 = ".jpeg";
        }
        String key = img + ext2;
        mThumbKey = "thumb/" + key;
        mImageKey = "image/" + key;
        ACSite acSite = ACSite.getInstance();
        mThumbUrl = acSite.getPictureUrl(mThumbKey);
        mImageUrl = acSite.getPictureUrl(mImageKey);
    }

    List<ACReply> replyList = replys;
    if (replyList != null && replyList.size() > 0) {
        int n = replyList.size();
        Reply[] replies = new Reply[n];
        mReplies = replies;
        for (int i = 0; i < n; i++) {
            replies[i] = replyList.get(i);
        }
    } else {
        mReplies = EMPTY_REPLY_ARRAY;
    }
}
 
Example #17
Source File: ListActivity.java    From Nimingban with Apache License 2.0 4 votes vote down vote up
@Override
public void onBindViewHolder(ListHolder holder, int position) {
    Post post = mPostHelper.getDataAt(position);
    holder.leftText.setText(post.getNMBDisplayUsername());
    ACForumRaw forum = DB.getACForumForForumid(post.getNMBFid());
    if (forum != null) {
        String displayName = forum.getDisplayname();
        CharSequence name = mForumNames.get(displayName);
        if (name == null) {
            if (displayName == null) {
                name = "Forum";
            } else {
                name = Html.fromHtml(displayName);
            }
            mForumNames.put(displayName, name);
        }
        holder.centerText.setText(name);
    } else {
        holder.centerText.setText("No." + post.getNMBId());
    }
    holder.rightText.setText(ReadableTime.getDisplayTime(post.getNMBTime()));
    ACItemUtils.setContentText(holder.content, post.getNMBDisplayContent());
    holder.bottomText.setText(post.getNMBReplyDisplayCount());

    View bottom = holder.bottom;
    RelativeLayout.LayoutParams lp = (RelativeLayout.LayoutParams) bottom.getLayoutParams();
    String thumbKey = post.getNMBThumbKey();
    String thumbUrl = post.getNMBThumbUrl();

    boolean tryShowImage;
    boolean loadFromNetwork;
    int ils = Settings.getImageLoadingStrategy();
    if (ils == Settings.IMAGE_LOADING_STRATEGY_ALL ||
            (ils == Settings.IMAGE_LOADING_STRATEGY_WIFI && NMBApplication.isConnectedWifi(ListActivity.this))) {
        tryShowImage = true;
        loadFromNetwork = true;
    } else {
        tryShowImage = Settings.getImageLoadingStrategy2();
        loadFromNetwork = false;
    }

    boolean showImage;
    if (!TextUtils.isEmpty(thumbKey) && !TextUtils.isEmpty(thumbUrl) && tryShowImage) {
        showImage = true;

        holder.thumb.setVisibility(View.VISIBLE);
        holder.thumb.unload();
        holder.thumb.load(thumbKey, thumbUrl, loadFromNetwork);
    } else {
        showImage = false;

        holder.thumb.setVisibility(View.GONE);
        holder.thumb.unload();
    }

    boolean showReplies;
    Reply[] replies = post.getNMBReplies();
    if (Settings.getDynamicComments()) {
        showReplies = holder.setReplies(replies);
    } else {
        showReplies = holder.setReplies(null);
    }

    if (showImage && !showReplies) {
        lp.addRule(RelativeLayout.ALIGN_BOTTOM, R.id.thumb);
        lp.addRule(RelativeLayout.BELOW, 0);
        bottom.setLayoutParams(lp);
    } else if (showImage) {
        lp.addRule(RelativeLayout.ALIGN_BOTTOM, 0);
        lp.addRule(RelativeLayout.BELOW, R.id.thumb);
        bottom.setLayoutParams(lp);
    } else {
        lp.addRule(RelativeLayout.ALIGN_BOTTOM, 0);
        lp.addRule(RelativeLayout.BELOW, R.id.content);
        bottom.setLayoutParams(lp);
    }

    holder.content.setTextSize(Settings.getFontSize());
    holder.content.setLineSpacing(LayoutUtils.dp2pix(ListActivity.this, Settings.getLineSpacing()), 1.0f);
    if (Settings.getFixEmojiDisplay()) {
        holder.content.useCustomTypeface();
    } else {
        holder.content.useOriginalTypeface();
    }
}