Codepet's Blog

Learn and live


  • 首页

  • 归档

  • 分类

  • 标签

  • 关于

ContentProvider的使用

发表于 2016-07-29   |   分类于 Android

获取手机中音乐列表

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
/**
* 用于从数据库中查询歌曲的信息,保存在List当中
*/
public static List<Mp3Infos> getMp3Infos(Context context) {
Cursor cursor = context.getContentResolver().query(
MediaStore.Audio.Media.EXTERNAL_CONTENT_URI, null, null, null,
MediaStore.Audio.Media.DEFAULT_SORT_ORDER);
List<Mp3Infos> mp3Infos = new ArrayList<Mp3Infos>();
for (int i = 0; i < cursor.getCount(); i++) {
Mp3Infos mp3Info = new Mp3Infos();
cursor.moveToNext();
long id = cursor.getLong(cursor
.getColumnIndex(MediaStore.Audio.Media._ID)); // 音乐id
String title = cursor.getString((cursor
.getColumnIndex(MediaStore.Audio.Media.TITLE)));// 音乐标题
String artist = cursor.getString(cursor
.getColumnIndex(MediaStore.Audio.Media.ARTIST));// 艺术家
long duration = cursor.getLong(cursor
.getColumnIndex(MediaStore.Audio.Media.DURATION));// 时长
long size = cursor.getLong(cursor
.getColumnIndex(MediaStore.Audio.Media.SIZE)); // 文件大小
String url = cursor.getString(cursor
.getColumnIndex(MediaStore.Audio.Media.DATA)); // 文件路径
int isMusic = cursor.getInt(cursor
.getColumnIndex(MediaStore.Audio.Media.IS_MUSIC));// 是否为音乐
if (isMusic != 0) { // 只把音乐添加到集合当中
mp3Info.setId(id);
mp3Info.setTitle(title);
mp3Info.setArtist(artist);
mp3Info.setDuration(duration);
mp3Info.setSize(size);
mp3Info.setPath(url);
mp3Infos.add(mp3Info);
}
}
return mp3Infos;
}
阅读全文 »

正则表达式的使用

发表于 2016-07-29   |   分类于 Java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
/**
* 验证手机格式
*/
public static boolean isMobileNO(String mobiles) {
/**
* 移动:134、135、136、137、138、139、150、151、157(TD)、158、159、187、188
* 联通:130、131、132、152、155、156、185、186
* 电信:133、153、180、189、(1349卫通)
* 总结起来就是第一位必定为1,第二位必定为3或5或8,其他位置的可以为0-9
*/
// "[1]"代表第1位为数字1
// "[358]"代表第二位可以为3、5、8中的一个
// "\\d{9}"代表后面是可以是0~9的数字,有9位。
String telRegex = "[1][358]\\d{9}";
if (TextUtils.isEmpty(mobiles))
return false;
else return mobiles.matches(telRegex);
}
阅读全文 »

Android开发中常用的工具类

发表于 2016-07-28   |   分类于 Android

提示工具类(Snackebar&Toast)

1
2
3
4
5
6
7
8
9
10
11
12
13
public class SnackbarUtil {
private static Snackbar snackbar;
public static void show(View view, String message) {
if (snackbar == null) {
snackbar = Snackbar.make(view, message, Snackbar.LENGTH_SHORT);
} else {
snackbar.setText(message);
}
snackbar.show();
}
}
阅读全文 »

开源项目|易天气

发表于 2016-07-28   |   分类于 Android

一款查询中国天气的软件
数据来源:http://apis.baidu.com/apistore/weatherservice

实战中学习Retrofit、RxJava、RxAndroid的实际应用,若未接触过可先移步Retrofit、RxJava&RxAndroid进行学习。

先看效果图:

主界面

阅读全文 »
123
codepet

codepet

追求卓越,成功会出其不意地上门

24 日志
4 分类
10 标签
High一下
© 2016 codepet
由 Hexo 强力驱动
主题 - NexT.Pisces