package android.widget;import android.app.ITransientNotification;import android.content.Context;import android.view.Gravity;import android.view.LayoutInflater;import android.view.View;import java.lang.reflect.Field;public class ToastUtils {    private static Toast mToast = null ;    public static final int MEDIA_TYPE_MUSIC = 0x00000001;    public static final int MEDIA_STATUS_LOADING = 0x10000000;    public static void showMediaStatusToast(Context context, int mediaType, String msg) {        TextView toastMsg = null;        ImageView toastImage = null;        if (mToast == null) {            LayoutInflater inflate = (LayoutInflater)                    context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);            View toastView = inflate.inflate(com.android.internal.R.layout.media_ready_toast, null);            toastMsg = ((TextView) toastView.findViewById(com.android.internal.R.id.tv_toast_clear));            toastImage = (ImageView) toastView.findViewById(com.android.internal.R.id.iv_toast_clear);            mToast = new Toast(context.getApplicationContext());            mToast.setDuration(Toast.LENGTH_SHORT);            mToast.setGravity(Gravity.CENTER, 0, 0);            mToast.setView(toastView);        } else {            toastMsg = (TextView) mToast.getView().findViewById(com.android.internal.R.id.tv_toast_clear);            toastImage = (ImageView) mToast.getView().findViewById(com.android.internal.R.id.iv_toast_clear);        }        switch(mediaType) {            case MEDIA_TYPE_MUSIC://music                toastImage.setImageResource(com.android.internal.R.drawable.img_no_usb);                break;            case MEDIA_STATUS_LOADING://loading                toastImage.setImageResource(com.android.internal.R.drawable.media_progress);                toastMsg.setText(msg);                showProgress();                break;        }        if (mediaType != MEDIA_STATUS_LOADING) {            toastMsg.setText(msg);            mToast.show();        }    }    private static void showProgress() {        if (mToast != null) {            try {                Field toastNextView = mToast.getClass().getDeclaredField("mNextView");                toastNextView.setAccessible(true);                Object toastView = toastNextView.get(mToast);                toastNextView.setAccessible(false);                Field mTN = mToast.getClass().getDeclaredField("mTN");                mTN.setAccessible(true);                Object tn = mTN.get(mToast);                mTN.setAccessible(false);                Field tnView = tn.getClass().getDeclaredField("mNextView");                tnView.setAccessible(true);                tnView.set(tn, toastView);                tnView.setAccessible(false);                ITransientNotification notification = (ITransientNotification) mTN.get(mToast);                notification.show();            } catch (Exception e) {                e.printStackTrace();            }        }    }    public static void hideProgress() {        if (mToast != null) {            try {                Field mTN = mToast.getClass().getDeclaredField("mTN");                ITransientNotification notification = (ITransientNotification) mTN.get(mToast);                notification.hide();            } catch (Exception e) {                e.printStackTrace();            }        }    }}

更多相关文章

  1. 代码中设置drawableleft
  2. android 3.0 隐藏 系统标题栏
  3. Android开发中activity切换动画的实现
  4. Android(安卓)学习 笔记_05. 文件下载
  5. Android中直播视频技术探究之—摄像头Camera视频源数据采集解析
  6. 技术博客汇总
  7. android 2.3 wifi (一)
  8. AndRoid Notification的清空和修改
  9. Android中的Chronometer

随机推荐

  1. jquery处理多维数组
  2. 在jquery下翻看图片,如何判断最后一张呢?
  3. 如何将JQuery变量值分配给Laravel Blade
  4. console.dir()等效在xCode中使用jQuery Mob
  5. 调用没有当前上下文的OpenGL ES API(每个
  6. 尝试用动态内容填充分享Twitter链接
  7. jQuery的$.getJSON方法在IE浏览器下失效
  8. 小白的jquery学习之路02选择器.2
  9. jquery ajax 跨域请求
  10. Node.js如何将Ajax成功消息传递给app.js