Android常用工具类之界面上的一些工具
来源:互联网 发布:导入mac的视频找不到了 编辑:程序博客网 时间:2024/04/30 07:05
对Toast的封装,获取线程ID,获取当前线程,设置背景
package com.ankoninc.utils;import android.app.Dialog;import android.content.Context;import android.content.DialogInterface;import android.graphics.drawable.Drawable;import android.os.Handler;import android.os.Looper;import android.view.View;import android.view.WindowManager;import android.widget.Toast;/** * Created by zengna on 2015/12/29. */public class UIUtil { private static final String TAG = "UIUtil"; private static Handler sHandler = new Handler(Looper.getMainLooper()); /** * Retrieve the sHandler. * * @return the sHandler */ public static Handler getHandler() { return sHandler; } public static Thread getUIThread() { return Looper.getMainLooper().getThread(); } public static boolean isOnUIThread() { return Thread.currentThread() == getUIThread(); } /** * Execute an runnable object on UI thread. * * @param action the object to execute. */ public static void runOnUIThread(Runnable action) { if (!isOnUIThread()) { getHandler().post(action); } else { action.run(); } } public static boolean showDialogSafe(Dialog dialog) { try { dialog.show(); return true; } catch (Exception e) { // log detail informations Log.w(null, e); return false; } } public static boolean dismissDialogSafe(DialogInterface dialog) { if (dialog == null) { return false; } try { dialog.dismiss(); return true; } catch (WindowManager.BadTokenException e) { Log.w(null, e.getMessage()); return false; } catch (IllegalStateException e) { Log.w(null, e.getMessage()); return false; } catch (Exception e) { Log.w(null, e.getMessage()); return false; } } public static void showToastSafe(Context context, int msgId) { try { Toast.makeText(context, context.getString(msgId), Toast.LENGTH_SHORT).show(); } catch (Exception e) { Log.e(e.getMessage()); } } public static void showToastSafe(Context context, String msg) { try { Toast.makeText(context, msg, Toast.LENGTH_SHORT).show(); } catch (Exception e) { Log.e(e.getMessage()); } } public static boolean showToastSafe(Toast toast) { try { toast.show(); return true; } catch (Exception e) { // log detail informations Log.e(e.getMessage()); return false; } } public static void setBackground(View view, Drawable drawable) { if (null == view) { return; } view.setBackground(drawable); }}
阅读全文
0 0
- Android常用工具类之界面上的一些工具
- Android常用工具类之与网络相关的工具类
- Android常用工具类之Http网络请求的工具类
- Android常用工具类之String的工具类
- Android常用工具类之 Toast工具类
- Android常用工具类之 Log工具类
- Android 一些常用工具类的整理
- android之常用工具类
- android之常用工具类
- Android常用工具类之IO文件流工具类
- GitHub上整理的一些常用工具。。。。
- GitHub上整理的一些常用工具
- Spring的一些常用工具类
- Liferay的一些常用工具类
- android开发之常用工具类
- 常用工具类之公共工具类
- Android常用工具类之获取屏幕相关的辅助类
- Android常用工具类之SD卡相关的辅助类
- nginx 配置 同一个域名 同时支持iis和tomcat
- leetcode 190. Reverse Bits
- 超级台阶-OJ
- 《神经网络设计》读书笔记——性能优化(一)
- css实现:鼠标放在图片查看大图
- Android常用工具类之界面上的一些工具
- NYOJ 18-The Triangle(典型DP)
- bzoj 2286: [Sdoi2011]消耗战
- java语言概述
- Web MVC
- Numpy基础学习笔记
- 一位资深开发的个人经历(走心好文)
- Maven导入项目出现类似"Cannot read lifecycle ..invalid END header "问题的解决办法
- Linux当磁盘空间不足:利用windows空盘重新挂载