UiUtils
import android.app.Activity;
import android.app.Dialog;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.os.AsyncTask;
import android.os.IBinder;
import android.os.Looper;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.inputmethod.InputMethodManager;
import android.widget.EditText;
import android.widget.ImageView; import java.io.InputStream; /**
* UI工具类
* @version 1.0
*/
public class UiUtilities {
/**
* 设置view的显示状态
*/
public static void setVisibilitySafe(View view, int visibility) {
if (view != null && view.getVisibility() != visibility) {
view.setVisibility(visibility);
}
} /**
* 设置view的显示状态
*/
public static void setVisibilitySafe(View parent, int id, int visibility) {
if (parent != null) {
setVisibilitySafe(parent.findViewById(id), visibility);
}
} public static void setPressedSafe(View view, boolean pressed) {
if (view != null && view.isPressed() != pressed) {
view.setPressed(pressed);
}
} public static void setEnabledSafe(View parent, int id, boolean enabled) {
if (parent != null) {
View view = parent.findViewById(id);
if (view != null) {
view.setEnabled(enabled);
}
}
} public static void setOnClickListenerSafe(View parent, int id, OnClickListener l) {
if (parent != null) {
View view = parent.findViewById(id);
if (view != null) {
view.setOnClickListener(l);
}
}
} public static void requestFocus(View view) {
if (view != null) {
view.setFocusable(true);
view.setFocusableInTouchMode(true);
view.requestFocus();
}
} public static boolean isEditTextEmpty(EditText edit) {
return edit.getText() == null || edit.getText().toString().trim().length() <= 0;
} public static boolean hideInputMethod(Activity activity) {
return hideInputMethod(activity, activity.getWindow().getDecorView().getWindowToken());
} public static boolean hideInputMethod(Dialog dialog) {
return hideInputMethod(dialog.getContext(), dialog.getWindow().getDecorView().getWindowToken());
} public static boolean hideInputMethod(Context context, IBinder iBinder) {
InputMethodManager im = (InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE);
return im.hideSoftInputFromWindow(iBinder, 0);
} public static void checkBackgroudThread() {
if (Looper.getMainLooper() == Looper.myLooper()) {
throw new IllegalStateException("It must run in backgroud thread.");
}
} public static void cancelAsyncTask(AsyncTask<?, ?, ?> task) {
if (task != null) {
task.cancel(true);
}
} public static void clearBitmapInImageView(ImageView v) {
if (v != null) {
clearBitmapInDrawable(v.getDrawable());
}
} public static void clearBackgroundBitmapInView(View v) {
if (v != null) {
clearBitmapInDrawable(v.getBackground());
}
} public static void clearBitmapInDrawable(Drawable d) {
if (d != null && d instanceof BitmapDrawable) {
Bitmap bitmap = ((BitmapDrawable) d).getBitmap();
if (bitmap != null) {
Logger.v("luochun", bitmap.toString());
bitmap.recycle();
}
}
} public static Bitmap decodeResourceBitmap(Context context, int resId) {
InputStream is = context.getResources().openRawResource(resId);
return BitmapFactory.decodeStream(is);
}
}
UiUtils的更多相关文章
- listview下拉刷新和上拉加载更多的多种实现方案
listview经常结合下来刷新和上拉加载更多使用,本文总结了三种常用到的方案分别作出说明. 方案一:添加头布局和脚布局 android系统为listview提供了addfootview ...
- BaseAdapter的抽取
为了更方便高效的使用BaseAdapter,特意抽取了一下,下面是简单的结构图: 需要4个类: [MyBaseAdapter3]: public abstract class MyBaseAdapte ...
- 使用TabPageIndicator的样式问题
在使用TabPageIndicator往往会出现一些样式问题,导致看不到字,下面是总结的步骤: 1.布局<LinearLayout xmlns:android="http://sche ...
- ExpandableListView实现展开更多和收起更多
[需求]: 如上面图示 当点开某个一级菜单的时候,其他菜单收起: 子级菜单默认最多5个: 多于5个的显示"展开更多" 点击"展开更多",展开该级所有子级菜单,同 ...
- ueditor调用其中的附件上传功能
ueditor实际上是集成了webuploader, 在做内容发布的时候想既有ueditor又有单独的附件上传按钮,这时再加载一个webuploader就显得过于臃肿了,单独利用ueditor的上传功 ...
- selenium元素操作
1.文本框(text field or textarea) element.sendKeys("test");//在输入框中输入内容: element.clear(); //将输入 ...
- Selenium 元素定位
selenium通过driver.findElement(By selector)来定位元素,selector在selenium-java.jar中,里面的方法一共就8种,如下图: 基本定义: By. ...
- 6个强大的AngularJS扩展应用
本文链接:http://www.codeceo.com/article/6-angularjs-extension.html本文作者:码农网 – 小峰 AngularJS现在非常热门,是Google推 ...
- angularjs组件之input mask
今天将奉献一个在在几个angularjs项目中抽离的angular组件 input mask.在我们开发中经常会对用户的输入进行控制,比如日期,货币格式,或者纯数字格式之类的限制,这就是input m ...
随机推荐
- 第三章、前端之JavaScript
目录 第三章.前端之JavaScript 一.javaScript的引入方式 二.JavaScript语言的规范 三.语言基础 变量声明 四.数据类型 五.流程控制 六.函数 函数的argument ...
- CAFFE(一):Ubuntu 下安装CUDA(安装:NVIDIA-384+CUDA9.0+cuDNN7.1)
(安装:NVIDIA-384+CUDA9.0+cuDNN7.1) 显卡(GPU)驱动:NVIDIA-384 CUDA:CUDA9.0 cuDNN:cuDNN7.1 Ubuntu 下安装CUDA需要装N ...
- PHP面试题--基础
1.PHP语言的一大优势是跨平台,什么是跨平台?一.PHP基础: PHP的运行环境最优搭配为Apache+MySQL+PHP,此运行环境可以在不同操作系统(例如windows.Linux等)上配置,不 ...
- PAT Basic 1087 有多少不同的值 (20 分)
当自然数 n 依次取 1.2.3.…….N 时,算式 ⌊ 有多少个不同的值?(注:⌊ 为取整函数,表示不超过 x 的最大自然数,即 x 的整数部分.) 输入格式: 输入给出一个正整数 N(2). 输出 ...
- UESTC 2016 Summer Training #1 J - Objects Panel (A) 按条件遍历树
#include <iostream> #include <cstdio> #include <vector> using namespace std; typed ...
- Java&Selenium&JS&AWT之那些难以点击到的按钮
一.摘要 本篇博文的重点并不是简单的click()方法,而是要讲的是那些click()方法失效的时候的处理方式,其实做自动化久了我们都能发现研发的代码并不是都那么美丽,selenium支持的8种定位方 ...
- async 与 await
async 关键字 1.含义:表示函数是一个异步函数,意味着该函数的执行不会阻塞后面代码的执行 2.定义与调用 async function hello (flag) { if (flag) { re ...
- UOJ117 欧拉回路[欧拉回路]
找欧拉回路的模板题. 知识点详见图连通性学习笔记. 注意一些写法上的问题. line37&line61:因为引用,所以j和head值是同步更新的,类似于网络流的当前弧优化,除了优化枚举外,这样 ...
- hbase实践之HFile结构
本文目录如下所示: 目录 HFile在HBase架构中的位置 什么是HFile HFile逻辑结构 HFile逻辑结构的优点 HFile物理结构 HFile生成流程 HFile中Block块解析 多大 ...
- 前端知识体系:JavaScript基础-原型和原型链-instanceof的底层实现原理
instanceof的底层实现原理(参考文档) instanceof的实现实际上是调用JS的内部函数 [[HasInstance]] 来实现的,其实现原理是:只要右边变量的prototype在左边变量 ...