Android:MD5工具类及单例Toast(小白进)

//md5加密算法,将要加密的字符串传进去,返回加密后的字符串

public static String encode(String password) {  
        try {
            MessageDigest digest = MessageDigest.getInstance("md5");
            byte[] result = digest.digest(password.getBytes());
            StringBuffer sb = new StringBuffer();
            for (byte b : result) {
                int num = b & 0xff-3;   // -3 加盐,自定义算法
                String stri = Integer.toHexString(num);
                if (stri.length() == 1) {
                    sb.append(0);
                }
                sb.append(stri);
            }
            return sb.toString();
        } catch (NoSuchAlgorithmException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
            return "";
        }       
    }

下面这是简单的单例Toast

public class ToastUtil {
    private static Toast toast;
    /**
     * 强大的吐司,能够连续弹的吐司
     * @param text
     */
    public static void showToast(String text){
        if(toast==null){
            toast = Toast.makeText(GooglePlayApplication.context, text,0);
        }else {
            toast.setText(text);//如果不为空,则直接改变当前toast的文本
        }
        toast.show();
    }
}
posted @ 2016-07-28 11:36  我的网名  阅读(41)  评论(0)    收藏  举报