Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;

import android.content.Context;

import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.text.Spannable;
import android.text.SpannableString;
import android.text.style.ImageSpan;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class Main {
    public static SpannableString StringToBitMap(Context context, String msg) {
        SpannableString ss = new SpannableString(msg);
        Pattern p = Pattern.compile("/mnt/sdcard/.+?\\.\\w{3}");
        Matcher m = p.matcher(msg);
        while (m.find()) {
            Bitmap bitmap = BitmapFactory.decodeFile(m.group());
            ImageSpan imageSpan = new ImageSpan(context, bitmap);
            ss.setSpan(imageSpan, m.start(), m.end(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
        }
        return ss;
    }
}