目前xUtils主要有四大??椋?/h2>
使用xUtils快速开发框架需要有以下权限:
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
混淆时注意事项:
-
添加Android默认混淆配置${sdk.dir}/tools/proguard/proguard-android.txt
-
不要混淆xUtils中的注解类型,添加混淆配置:-keep class * extends java.lang.annotation.Annotation { *; }
-
对使用DbUtils??槌志没氖堤謇嗖灰煜?,或者注解所有表和列名称@Table(name=”xxx”),@Id(column=”xxx”),@Column(column=”xxx”),@Foreign(column=”xxx”,foreign=”xxx”);
DbUtils使用方法:
DbUtils db = DbUtils.create(this);
User user = new User();
user.setEmail("[email protected]");
user.setName("wyouflf");
db.save(user);
...
Parent entity = db.findById(Parent.class, parent.getId());
List<Parent> list = db.findAll(Parent.class);
Parent Parent = db.findFirst(Selector.from(Parent.class).where("name","=","test"));
Parent Parent = db.findFirst(Selector.from(Parent.class).where("name","=", null));
Parent Parent = db.findFirst(Selector.from(Parent.class).where("name","!=", null));
List<Parent> list = db.findAll(Selector.from(Parent.class)
.where("id" ,"<", 54)
.and(WhereBuilder.b("age", ">", 20).or("age", " < ", 30))
.orderBy("id")
.limit(pageSize)
.offset(pageSize * pageIndex));
Parent test = db.findFirst(Selector.from(Parent.class).where("id", "in", new int[]{1, 2, 3}));
Parent test = db.findFirst(Selector.from(Parent.class).where("id", "between", new String[]{"1", "5"}));
DbModel dbModel = db.findDbModelAll(Selector.from(Parent.class).select("name"));
List<DbModel> dbModels = db.findDbModelAll(Selector.from(Parent.class).groupBy("name").select("name", "count(name)"));
...
List<DbModel> dbModels = db.findDbModelAll(sql);
db.execNonQuery(sql)
...
ViewUtils使用方法
-
完全注解方式就可以进行UI绑定和事件绑定。
-
无需findViewById和setClickListener等。
@ViewInject(R.id.textView)
TextView textView;
@ResInject(id = R.string.label, type = ResType.String)
private String label;
@OnClick(R.id.test_button)
public void testButtonClick(View v) {
...
}
...
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
ViewUtils.inject(this);
...
textView.setText("some text...");
...
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.bitmap_fragment, container, false);
ViewUtils.inject(this, view);
...
}
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
ViewUtils.inject(this, getPreferenceScreen());
...
}
HttpUtils使用方法:
普通get方法
HttpUtils http = new HttpUtils();
http.send(HttpRequest.HttpMethod.GET,
"//www.lidroid.com",
new RequestCallBack<String>(){
@Override
public void onLoading(long total, long current, boolean isUploading) {
testTextView.setText(current + "/" + total);
}
@Override
public void onSuccess(ResponseInfo<String> responseInfo) {
textView.setText(responseInfo.result);
}
@Override
public void onStart() {
}
@Override
public void onFailure(HttpException error, String msg) {
}
});
使用HttpUtils上传文件 或者 提交数据 到服务器(post方法)
RequestParams params = new RequestParams();
params.addHeader("name", "value");
params.addQueryStringParameter("name", "value");
params.addBodyParameter("name", "value");
params.addBodyParameter("file", new File("path"));
...
HttpUtils http = new HttpUtils();
http.send(HttpRequest.HttpMethod.POST,
"uploadUrl....",
params,
new RequestCallBack<String>() {
@Override
public void onStart() {
testTextView.setText("conn...");
}
@Override
public void onLoading(long total, long current, boolean isUploading) {
if (isUploading) {
testTextView.setText("upload: " + current + "/" + total);
} else {
testTextView.setText("reply: " + current + "/" + total);
}
}
@Override
public void onSuccess(ResponseInfo<String> responseInfo) {
testTextView.setText("reply: " + responseInfo.result);
}
@Override
public void onFailure(HttpException error, String msg) {
testTextView.setText(error.getExceptionCode() + ":" + msg);
}
});
使用HttpUtils下载文件:
HttpUtils http = new HttpUtils();
HttpHandler handler = http.download("//apache.dataguru.cn/httpcomponents/httpclient/source/httpcomponents-client-4.2.5-src.zip",
"/sdcard/httpcomponents-client-4.2.5-src.zip",
true,
true,
new RequestCallBack<File>() {
@Override
public void onStart() {
testTextView.setText("conn...");
}
@Override
public void onLoading(long total, long current, boolean isUploading) {
testTextView.setText(current + "/" + total);
}
@Override
public void onSuccess(ResponseInfo<File> responseInfo) {
testTextView.setText("downloaded:" + responseInfo.result.getPath());
}
@Override
public void onFailure(HttpException error, String msg) {
testTextView.setText(msg);
}
});
...
handler.cancel();
...
BitmapUtils 使用方法
BitmapUtils bitmapUtils = new BitmapUtils(this);
bitmapUtils.display(testImageView, "//bbs.lidroid.com/static/image/common/logo.png");
bitmapUtils.display(testImageView, "/sdcard/test.jpg");
bitmapUtils.display(testImageView, "assets/img/wallpaper.jpg");
listView.setOnScrollListener(new PauseOnScrollListener(bitmapUtils, false, true));
listView.setOnScrollListener(new PauseOnScrollListener(bitmapUtils, false, true, customListener));
其他(更多示例代码见sample文件夹中的代码)
输出日志 LogUtils
LogUtils.d("wyouflf");
上一篇: android 自定义view 水波纹进度球 下一篇: android自定义控件之飞入飞出控件