Android Open Source - CommonLibs Toast Utils






From Project

Back to project page CommonLibs.

License

The source code is released under:

Apache License

If you think the Android project CommonLibs listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.alex.common.utils;
/* w  ww  .  j  av a2  s .c  om*/
import android.content.Context;
import android.widget.Toast;

/**
 * Toast???
 * @author caisenchuan
 */
public class ToastUtils {
    /*--------------------------
     * ?????
     *-------------------------*/

    /*--------------------------
     * ???
     *-------------------------*/

    /*--------------------------
     * ????????
     *-------------------------*/
    private static Toast mSingletonToast = null;
    
    /*--------------------------
     * public??
     *-------------------------*/
    public static void initSingletonToast(Context context) {
        mSingletonToast = Toast.makeText(context, "", Toast.LENGTH_SHORT);
    }
    
    /**
     * ?????Toast
     * @param context
     * @param str ????????
     * @param singleton true?????Toast????????Toast
     */
    public static void showShortToast(Context context, String str, boolean singleton) {
        show(context, str, false, singleton);
    }
    
    /**
     * ?????Toast
     * @param context
     * @param id ??????id
     * @param singleton true?????Toast????????Toast
     */
    public static void showShortToast(Context context, int id, boolean singleton) {
        show(context, context.getString(id), false, singleton);
    }
    
    /**
     * ?????Toast
     * @param context
     * @param str ????????
     * @param singleton true?????Toast????????Toast
     */
    public static void showLongToast(Context context, String str, boolean singleton) {
        show(context, str, true, singleton);
    }
    
    /**
     * ?????Toast
     * @param context
     * @param id ??????id
     * @param singleton true?????Toast????????Toast
     */
    public static void showLongToast(Context context, int id, boolean singleton) {
        show(context, context.getString(id), true, singleton);
    }
    
    /*--------------------------
     * protected??packet??
     *-------------------------*/

    /*--------------------------
     * private??
     *-------------------------*/
    /**
     * ?????????????????????Toast
     * @param context ???
     * @param text ???????
     * @param lengthLong true????Toast?????????Toast
     * @param singleton true?????Toast????????Toast
     */
    private static void show(Context context, String text, boolean lengthLong, boolean singleton) {
        int duration = Toast.LENGTH_SHORT;
        if(lengthLong) {
            duration = Toast.LENGTH_LONG;
        }
        
        if(singleton && mSingletonToast != null) {
            mSingletonToast.setText(text);
            mSingletonToast.setDuration(duration);
            mSingletonToast.show();
        } else {
            Toast.makeText(context, text, duration).show();
        }
    }
}




Java Source Code List

com.alex.common.AppConfig.java
com.alex.common.AppControl.java
com.alex.common.Err.java
com.alex.common.OnHttpRequestReturnListener.java
com.alex.common.activities.BaseActivity.java
com.alex.common.activities.ImageLoadActivity.java
com.alex.common.activities.WebViewActivity.java
com.alex.common.apis.HttpApi.java
com.alex.common.exception.RetErrorException.java
com.alex.common.utils.BackgroundHandler.java
com.alex.common.utils.BaiduMapUtils.java
com.alex.common.utils.DateTimeUtils.java
com.alex.common.utils.DeviceUtils.java
com.alex.common.utils.DialogUtils.java
com.alex.common.utils.FileUtils.java
com.alex.common.utils.ImageUtils.java
com.alex.common.utils.KLog.java
com.alex.common.utils.Misc.java
com.alex.common.utils.NetworkUtils.java
com.alex.common.utils.PrefUtils.java
com.alex.common.utils.ShareUtils.java
com.alex.common.utils.StringUtils.java
com.alex.common.utils.ThreadUtils.java
com.alex.common.utils.ToastUtils.java
com.alex.common.views.ZoomImageView.java