GithubHelp home page GithubHelp logo

Comments (11)

chinalwb avatar chinalwb commented on May 24, 2024

哇 这个真是不巧。。我还没有做好计划。所以估计不会太快 如果你有问题可以提出来 我们讨论讨论 你做提取 然后PR呗?

from android-rich-text-editor.

lrain-lv avatar lrain-lv commented on May 24, 2024

我已经把你的代码复制到我的项目里面了,toolbar我只需要部分的功能 所以能简单就简单 不需要的功能我都给删了 现在试着改改 有问题 问你哈

from android-rich-text-editor.

lrain-lv avatar lrain-lv commented on May 24, 2024

大神 我的recyclerview item有aretextview 但是当图片多的时候 滑动就会卡顿 请问对于图片的加载有没有优化的方法啊

from android-rich-text-editor.

chinalwb avatar chinalwb commented on May 24, 2024

贴Adapter代码来看看

from android-rich-text-editor.

lrain-lv avatar lrain-lv commented on May 24, 2024

image
image

from android-rich-text-editor.

chinalwb avatar chinalwb commented on May 24, 2024

查看下最新的AreTextView.java 或者 下面的代码。
使用 fromHtmlWithCache 代替 fromHtml, 不过在你的Activity退出或其他合适的时机,需要调用 clearCache

package com.chinalwb.are.render;

import android.content.Context;
import android.support.annotation.Nullable;
import android.support.v7.widget.AppCompatTextView;
import android.text.Spanned;
import android.util.AttributeSet;
import android.util.TypedValue;

import com.chinalwb.are.Constants;
import com.chinalwb.are.Util;
import com.chinalwb.are.android.inner.Html;
import com.chinalwb.are.events.AREMovementMethod;
import com.chinalwb.are.strategies.AreClickStrategy;
import com.chinalwb.are.strategies.defaults.DefaultClickStrategy;

import java.util.HashMap;

/**
 * @author dlink
 * @email [email protected]
 * @date 2018/5/20
 * @discription null
 * @usage null
 */
public class AreTextView extends AppCompatTextView {

    private static HashMap<String, Spanned> spannedHashMap = new HashMap<>();

    private AreClickStrategy mClickStrategy;

    Context mContext;

    public AreTextView(Context context) {
        this(context, null);
    }

    public AreTextView(Context context, @Nullable AttributeSet attrs) {
        this(context, attrs, 0);
    }

    public AreTextView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        mContext = context;
        this.setTextSize(TypedValue.COMPLEX_UNIT_SP, Constants.DEFAULT_FONT_SIZE);
        initGlobalValues();
        initMovementMethod();
    }

    private void initGlobalValues() {
        int[] wh = Util.getScreenWidthAndHeight(mContext);
        Constants.SCREEN_WIDTH = wh[0];
        Constants.SCREEN_HEIGHT = wh[1];
    }

    private void initMovementMethod() {
        if (this.mClickStrategy == null) {
            this.mClickStrategy = new DefaultClickStrategy();
        }
        this.setMovementMethod(new AREMovementMethod(this.mClickStrategy));
    }

    public void fromHtml(String html) {
        Spanned spanned = getSpanned(html);
        setText(spanned);
    }

    private Spanned getSpanned(String html) {
        Html.sContext = mContext;
        Html.ImageGetter imageGetter = new AreImageGetter(mContext, this);
        Html.TagHandler tagHandler = new AreTagHandler();
        return Html.fromHtml(html, Html.FROM_HTML_SEPARATOR_LINE_BREAK_PARAGRAPH, imageGetter, tagHandler);
    }

    /**
     * Use cache will take more RAM, you need to call clear cache when you think it is safe to do that.
     * You may need cache when working with {@link android.widget.ListView} or RecyclerView
     *
     * @param html
     */
    public void fromHtmlWithCache(String html) {
        Spanned spanned = null;
        if (spannedHashMap.containsKey(html)) {
            spanned = spannedHashMap.get(html);
        }
        if (spanned == null) {
            spanned = getSpanned(html);
            spannedHashMap.put(html, spanned);
        }
        if (spanned != null) {
            setText(spanned);
        }
    }

    public static void clearCache() {
        spannedHashMap.clear();
    }

    public void setClickStrategy(AreClickStrategy clickStrategy) {
        this.mClickStrategy = clickStrategy;
    }
}

from android-rich-text-editor.

lrain-lv avatar lrain-lv commented on May 24, 2024

现在不卡了,不过感觉这个只是一时的解决 不算是根本解决 因为是存到内存中 所以不能太多对象 。

from android-rich-text-editor.

chinalwb avatar chinalwb commented on May 24, 2024

你说的对。根本解决我也没有好的想法,我能想到的顶多是换成弱引用的缓存,毕竟图像要显示的话 他一定得占内存,用在list中更是如此,只要出了内存再往内存里加载,这个过程肯定就会慢。
上面的代码主要是缓存了 Spanned, 省去的是解析过程。
图片压缩性能方面没有太多研究,欢迎前来增强。

from android-rich-text-editor.

lrain-lv avatar lrain-lv commented on May 24, 2024

大神 我测试了下 我把 imageGetter里面的 Util.scaleBitmapToFitWidth(bitmap, Constants.SCREEN_WIDTH) 这段缩放的代码注释 然后滑动就没有卡顿了

from android-rich-text-editor.

chinalwb avatar chinalwb commented on May 24, 2024

👍 忽然很想看看把AreTextView放到RecyclerView里面是啥样。

from android-rich-text-editor.

chinalwb avatar chinalwb commented on May 24, 2024

最新版本已经解耦。欢迎查看,谢谢。

from android-rich-text-editor.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.