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 ...
随机推荐
- $(selector).each() 和$each() 的区别
今天在做项目的时候, 后台数据需要循环遍历出来, 想到each, 结果,竟然不记得语法了 现在来回顾一下,而搜索了一下,竟然发现有两种each 一种就是$(selector).each() ...
- 反编译DLL并修改DLL中的内容
使用场景:针对当前用户因不愿意进行软件版本升级,但又希望可以解决当前问题,此时可以考虑通过反编辑DLL进行修改内容,然后重新生成新的DLL 操作步骤: 1.首先使用ILSpy.exe反编译DLL,查看 ...
- How to export Overload functions from DLL?
Library that exports functions library liba; procedure F(X: Integer); stdcall; overload; begin end; ...
- PAT Basic 1064 朋友数 (20 分)
如果两个整数各位数字的和是一样的,则被称为是“朋友数”,而那个公共的和就是它们的“朋友证号”.例如 123 和 51 就是朋友数,因为 1+2+3 = 5+1 = 6,而 6 就是它们的朋友证号.给定 ...
- ReaderWriterLockSlim使用示例
/// <summary> /// ReaderWriterLockSlim使用示例 /// </summary> internal sealed class Transact ...
- VSCode 快捷键定义
默认的 Toggle explore side bar 快捷键为 Ctrl + B, 但是这和 Vim 的快捷键冲突,解决方法: File > Preferences > Keyb ...
- 箭头函数与定时器的this指向问题
函数体内的this对象,就是定义时所在的对象,而不是使用时所在的对象. 箭头函数本身没有this,this继承上级的this. 定时器中箭头函数的this指向包含定时器的函数,所以定时器中的箭头函数要 ...
- 记录一下UILabel加载富文本 iOS
一般情况下我们都习惯用webview加载富文本.但是webview比较消耗内存.然后发现其实本身可以用uilabel加载,性能还不错就记录下~~ 核心方法下面两个 -(NSMutableAttribu ...
- C# WebClient 的文件上传下载
上传文件 string path = openFileDialog1.FileName; WebClient wc = new WebClient(); wc.Credentials = Creden ...
- Codeforces Round #591 (Div. 2, based on Technocup 2020 Elimination Round 1) B. Strings Equalization
链接: https://codeforces.com/contest/1241/problem/B 题意: You are given two strings of equal length s an ...