Search in sources :

Example 1 with ImageFixCallback

use of com.zzhoujay.richtext.callback.ImageFixCallback in project RichText by zzhoujay.

the class ListViewActivity method onCreate.

@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_list);
    ListView listView = (ListView) findViewById(R.id.listView);
    listView.setAdapter(new BaseAdapter() {

        @Override
        public int getCount() {
            return testString__.length + 1;
        }

        @Override
        public Object getItem(int position) {
            return testString[position];
        }

        @Override
        public long getItemId(int position) {
            return position;
        }

        @Override
        public View getView(final int position, View convertView, ViewGroup parent) {
            Holder holder;
            if (convertView == null) {
                convertView = LayoutInflater.from(ListViewActivity.this).inflate(R.layout.item_list, parent, false);
                holder = new Holder(convertView);
                convertView.setTag(holder);
            } else {
                holder = (Holder) convertView.getTag();
            }
            Log.i("RichText", "position:" + position + ",textView:" + System.identityHashCode(holder.text));
            String text;
            if (position == 0) {
                text = test;
            } else {
                text = testString__[position - 1];
            }
            RichText.from(text).autoFix(false).fix(new ImageFixCallback() {

                @Override
                public void onFix(ImageHolder holder, boolean imageReady) {
                    if (holder.getImageType() != ImageHolder.ImageType.GIF) {
                        holder.setAutoFix(true);
                    } else {
                        holder.setHeight(200 + position * 10);
                        holder.setWidth(200 + position * 10);
                    }
                    if (position == 0) {
                        holder.setAutoPlay(true);
                    } else {
                        holder.setAutoPlay(false);
                    }
                //                        holder.setAutoPlay(false);
                }
            }).into(holder.text);
            return convertView;
        }

        class Holder {

            public final TextView text;

            public Holder(View view) {
                text = (TextView) view.findViewById(R.id.text_item);
            }
        }
    });
}
Also used : ImageHolder(com.zzhoujay.richtext.ImageHolder) ViewGroup(android.view.ViewGroup) ImageHolder(com.zzhoujay.richtext.ImageHolder) TextView(android.widget.TextView) View(android.view.View) ListView(android.widget.ListView) ImageFixCallback(com.zzhoujay.richtext.callback.ImageFixCallback) ListView(android.widget.ListView) TextView(android.widget.TextView) BaseAdapter(android.widget.BaseAdapter)

Aggregations

View (android.view.View)1 ViewGroup (android.view.ViewGroup)1 BaseAdapter (android.widget.BaseAdapter)1 ListView (android.widget.ListView)1 TextView (android.widget.TextView)1 ImageHolder (com.zzhoujay.richtext.ImageHolder)1 ImageFixCallback (com.zzhoujay.richtext.callback.ImageFixCallback)1