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 ...
随机推荐
- 翻译应用将在Win8.1系统中取消下载安装
自Windows8.Windows Phone 7.1和Windows Phone 8受到影响之后,微软又正式宣布停止对翻译应用提供支持服务.Microsoft Translator这款应用将从Win ...
- 高性能Java科学与技术运算库Colt
在学习<Machine Learning in Action>和<NLTK Natural Language Processing with Python>的过程中,我真切地感 ...
- Oracle笔记(十一) 建表、更新、查询综合练习
有某个学生运动会比赛信息的数据库,保存了如下的表: 运动员sporter(运动员编号sporterid,运动员姓名name,运动员性别sex,所属系号department) 项目item(项目编号it ...
- 电脑设置自动关机和取消自动关机代码bat命令
一.设置定时关机bat 1.首先在桌面新建一个记事本txt 2.打开记事本,输入“shutdown -s -t 1260 ”1260是指1260秒,即21分钟内关机.可以修改成别的时间. 3.保存后, ...
- okhttp缓存策略源码分析:put&get方法
对于OkHttp的缓存策略其实就是在下一次请求的时候能节省更加的时间,从而可以更快的展示出数据,那在Okhttp如何使用缓存呢?其实很简单,如下: 配置一个Cache既可,其中接收两个参数:一个是缓存 ...
- kotlin变量基础
kotlin变量与输出 这里看一下在Kotlin中的变量是如何定义的? 编译运行: 对比下我们常用的JAVA语言,定义上的区别: 1.Kotlin变量是统一以var开头,而不区分具体类型,而Java在 ...
- python打开excel跳转对应分页
需求: 在python脚本层,直接打开excel,跳转特定分页,方便策划编辑 尝试了几种不同的方法,最终选择了方法4.4种方法都可以实现打开外部文件,3.4可以实现跳转特定分页.3和4的区别是,3通过 ...
- TC做题笔记
SRM593 Div1Medium--May The Best Pet Win(bitset优化) Description 给出n个元素取值的max.min,把这n个元素分割成两个集合,求如何分割使两 ...
- Educational Codeforces Round 50 (Rated for Div. 2) F - Relatively Prime Powers(数学+容斥)
题目链接:http://codeforces.com/contest/1036/problem/F 题意: 题解:求在[2,n]中,x != a ^ b(b >= 2 即为gcd)的个数,那么实 ...
- Hibernate 4 升级到 5 后显示未知实体错误
提示的错误信息如下: org.hibernate.MappingException: Unknown entity: com.ossez.reoc.common.crm.DoNotCall at or ...