吴小龙同學

党要我帅,我不得不帅!


  • 首页

  • 关于

  • 标签

  • 分类

  • 归档

  • 搜索

Android Design Support Library之TabLayout

发表于 2015-08-03 | 分类于 SupportLibrary

常规使用

效果预览


注:tab2 和tab4 需要自定义。

阅读全文 »

手把手教你建 github 技术博客 by hexo

发表于 2015-07-31 | 分类于 BlogBuild

很多朋友私信问我,我的个人博客是用什么服务器,其实我并没有服务器,用的 GitHub Pages,没错,无需服务器,看完这篇文章,你也可以拥有个人博客。

修订历史

时间 说明
2015.07.31 初始版本
2016.08.20 新增插件安装
2020.11.11 新增博客评论 Gitalk
2020.12.20 薪增同台电脑同时使用多个 GitHub

适合人群

  • 喜欢写 Blog 的人
  • 有一定的编程基础
  • 爱折腾的人
  • 熟练使用版本控制 Git
  • 了解使用 GitHub
  • 熟悉基本的 MarkDown 语法
阅读全文 »

Android获取手机已安装apk文件信息

发表于 2015-07-29 | 分类于 Android
1
2
3
4
5
6
7
8
9
10
11
12
13
14
Intent intent = new Intent(Intent.ACTION_MAIN, null);
intent.addCategory(Intent.CATEGORY_LAUNCHER);
List<AppInfo> applicationList = new ArrayList<>();
List<ResolveInfo> resolveInfoList = getPackageManager().queryIntentActivities(intent, 0);
for (ResolveInfo resolveInfo : resolveInfoList) {
AppInfo appInfo = new AppInfo(MainActivity.this, resolveInfo);
PackageInfo packageInfo = appInfo.getPackageInfo();
//判断(applicationInfo.flags & ApplicationInfo.FLAG_SYSTEM)的值,
// 该值大于0时,表示获取的应用为系统预装的应用,反之则为手动安装的应用
if ((packageInfo.applicationInfo.flags & packageInfo.applicationInfo.FLAG_SYSTEM) <= 0) {
// customs applications
applicationList.add(appInfo);
}
}
阅读全文 »

GitHub之Android-Iconics使用

发表于 2015-07-29 | 分类于 Library

源码地址:https://github.com/mikepenz/Android-Iconics

  • build.gradle添加
1
2
3
dependencies {
compile 'com.mikepenz:iconics:1.3.0@aar'
}
阅读全文 »

Android保存图片并显示系统图库

发表于 2015-07-27 | 分类于 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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
/**
* 0 保存失败;
* 1 保存成功;
* 2 已经存在
*/
class SaveImageToGalleryTask extends AsyncTask<Objects, Objects, Integer> {
@Override
protected Integer doInBackground(Objects... params) {
Bitmap bitmap = null;
try {
bitmap = Picasso.with(GirlImageDetailActivity.this).load("图片URL").get();
} catch (IOException e) {
e.printStackTrace();
}
if (bitmap == null) {
return 0;
}
File appDir = new File(Environment.getExternalStorageDirectory(), "hua");
if (!appDir.exists()) {
appDir.mkdir();
}
final String fileName = "图片名字"+ ".png";
File file = new File(appDir, fileName);
if (file.exists()) {
return 2;
} else {
try {
FileOutputStream fileOutputStream = new FileOutputStream(file);
bitmap.compress(Bitmap.CompressFormat.PNG, 100, fileOutputStream);
fileOutputStream.flush();
fileOutputStream.close();
// 其次把文件插入到系统图库
MediaStore.Images.Media.insertImage(GirlImageDetailActivity.this.getContentResolver(), file.getAbsolutePath(), fileName, null);
// 最后通知图库更新
Intent intent = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE, Uri.parse("file://" + file.getAbsolutePath()));
sendBroadcast(intent);
return 1;
} catch (Exception e) {
e.printStackTrace();
return 0;
}
}
}
@Override
protected void onPostExecute(Integer integer) {
super.onPostExecute(integer);
switch (integer) {
case 0:
Snackbar.make(detailLayout, "保存失败", Snackbar.LENGTH_SHORT).show();
break;
case 1:
File appDir = new File(Environment.getExternalStorageDirectory(), "hua");
Snackbar.make(detailLayout, "成功保存至" + appDir.getAbsolutePath(), Snackbar.LENGTH_SHORT).show();
break;
case 2:
Snackbar.make(detailLayout, "图片已经存在", Snackbar.LENGTH_SHORT).show();
break;
}
}
}

PullLoadMoreRecyclerView

发表于 2015-07-24 | 分类于 RecyclerView

实现RecyclerView下拉刷新和上拉加载更多以及RecyclerView线性、网格、瀑布流效果演示。如果你只需要简单地实现下拉刷新和上拉加载效果,不需要定制,那PullLoadMoreRecyclerView最适合不过。

效果预览

使用方法

build.gradle文件

1
2
3
dependencies {
compile 'com.wuxiaolong.pullloadmorerecyclerview:library:1.1.2'
}

xml引用

1
2
3
4
<com.wuxiaolong.pullloadmorerecyclerview.PullLoadMoreRecyclerView
android:id="@+id/pullLoadMoreRecyclerView"
android:layout_width="match_parent"
android:layout_height="match_parent" />

设置线性布局

1
2
mPullLoadMoreRecyclerView = (PullLoadMoreRecyclerView) view.findViewById(R.id.pullLoadMoreRecyclerView);
mPullLoadMoreRecyclerView.setLinearLayout();

设置网格布局

1
mPullLoadMoreRecyclerView.setGridLayout(2);//参数为列数

设置交错网格布局,即瀑布流效果

1
mPullLoadMoreRecyclerView.setStaggeredGridLayout(2);//参数为列数

绑定适配器

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
mRecyclerViewAdapter = new RecyclerViewAdapter();
mPullLoadMoreRecyclerView.setAdapter(mRecyclerViewAdapter);
public class RecyclerViewAdapter extends RecyclerView.Adapter<RecyclerViewAdapter.ViewHolder> {
public RecyclerViewAdapter() {
}
@Override
public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.recycler_view_item, parent, false);
return new ViewHolder(view);
}
@Override
public void onBindViewHolder(ViewHolder holder, int position) {
}
@Override
public int getItemCount() {
return 0;
}
public class ViewHolder extends RecyclerView.ViewHolder {
public ViewHolder(View itemView) {
super(itemView);
}
}
}

调用下拉刷新和加载更多

1
2
3
4
5
6
7
8
9
10
11
mPullLoadMoreRecyclerView.setOnPullLoadMoreListener(new PullLoadMoreRecyclerView.PullLoadMoreListener() {
@Override
public void onRefresh() {
}
@Override
public void onLoadMore() {
}
});

刷新结束

1
mPullLoadMoreRecyclerView.setPullLoadMoreCompleted();

其他方法

显示下拉刷新

1
mPullLoadMoreRecyclerView.setRefreshing(true);

不需要下拉刷新

1
mPullLoadMoreRecyclerView.setPullRefreshEnable(false);

不需要上拉刷新

1
mPullLoadMoreRecyclerView.setPushRefreshEnable(false);

设置上拉刷新文字

1
mPullLoadMoreRecyclerView.setFooterViewText("loading");

设置上拉刷新文字颜色

1
mPullLoadMoreRecyclerView.setFooterViewTextColor(R.color.white);

设置加载更多背景色

1
mPullLoadMoreRecyclerView.setFooterViewBackgroundColor(R.color.colorBackground);

设置下拉刷新颜色

1
mPullLoadMoreRecyclerView.setColorSchemeResources(android.R.color.holo_red_dark,android.R.color.holo_blue_dark);

快速Top

1
mPullLoadMoreRecyclerView.scrollToTop();

License

Apache-2.0

更新日志

  • 2016/12/20 修改
  • 2015/07/24 撰写

Saving Data-Saving Files

发表于 2015-07-13 | 分类于 Android

微言App中有个阅读量的功能,是直接将用户的阅读量保存在SD卡上,我封装成了工具类。

需要权限

1
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

ReadUtil.java

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
38
39
40
41
42
43
44
45
46
public class ReadUtil {
public static final File SDCardDir = Environment.getExternalStorageDirectory(); //获取SDCard目录
public static final String SD_ROOT_NAME = "WeiYan/";
public static final String SD_FILE_NAME = "reading";
public static void saveToFile(int readTotal) {
try {
// 判断SD卡是否存在,并且是否具有读写权限
if (Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) {
File saveFile = new File(SDCardDir + File.separator + SD_ROOT_NAME, SD_FILE_NAME);
if (!saveFile.getParentFile().exists()) {
saveFile.getParentFile().mkdirs();
}
int nowReadingTotal = getReadedTotal() + readTotal;
String readedTotal = nowReadingTotal + "";
FileOutputStream outStream = new FileOutputStream(saveFile);
outStream.write(readedTotal.getBytes());
outStream.close();
} else {
}
} catch (Exception e) {
e.printStackTrace();
}
}
public static int getReadedTotal() {
int readedTotal = 0;
File file = new File(SDCardDir + File.separator + SD_ROOT_NAME, SD_FILE_NAME);
if (file.exists() && file.isFile()) {
StringBuffer stringBuffer = new StringBuffer();
try {
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(new FileInputStream(file), "UTF-8"));
int c;
while ((c = bufferedReader.read()) != -1) {
stringBuffer.append((char) c);
}
bufferedReader.close();
} catch (Exception e) {
e.printStackTrace();
}
String result = stringBuffer.toString();
readedTotal = Integer.parseInt(result);
}
return readedTotal;
}
}

如何调用

读取数据

1
ReadUtil.getReadedTotal()

保存阅读量

1
ReadUtil.saveToFile(readTotal);

EditText输入手机号自动带空格

发表于 2015-07-09 | 分类于 AndroidUtil

转载:http://www.jcodecraeer.com/plus/view.php?aid=3163

在android开发过程中,经常会要求用户输入手机号,为了便于观看,我们都会已135 xxxx xxxx这种格式展示。

阅读全文 »

刷新RecyclerView/ListView某个item状态

发表于 2015-07-08 | 分类于 Android

本文是实际开发遇到的问题,结合情景,给出解决方案,很有启示作用。

1、比如列表有收藏按钮,当前页面收藏

1
2
3
4
5
private List<Map<String, String>> mList = new ArrayList<>();
...
//走收藏接口,在成功后,只更改刚刚点击的item的收藏按钮状态
mList.get(position).put("favorites", "1");
notifyDataSetChanged();
阅读全文 »

时间工具类TimeUtil

发表于 2015-07-08 | 分类于 AndroidUtil
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
public class TimeUtil {
/**
* 获取当前时间
*
* @param format "yyyy-MM-dd HH:mm:ss"
*/
public static String getCurrentTime(String format) {
Date date = new Date();
SimpleDateFormat simpleDateFormat = new SimpleDateFormat(format, Locale.getDefault());
return simpleDateFormat.format(date);
}
/**
* 获取当前时间为本月的第几周
*/
public static int getWeekOfMonth() {
Calendar calendar = Calendar.getInstance();
int week = calendar.get(Calendar.WEEK_OF_MONTH);
return week - 1;
}
/**
* 获取当前时间为本周的第几天
*/
public static int getDayOfWeek() {
Calendar calendar = Calendar.getInstance();
int day = calendar.get(Calendar.DAY_OF_WEEK);
if (day == 1) {
day = 7;
} else {
day = day - 1;
}
return day;
}
/**
* 获取当前时间的年份
*/
public static int getYear() {
Calendar calendar = GregorianCalendar.getInstance();
return calendar.get(Calendar.YEAR);
}
/**
* 获取当前时间的月份
*/
public static int getMonth() {
Calendar calendar = GregorianCalendar.getInstance();
return calendar.get(Calendar.MONTH);
}
/**
* 获取当前时间是哪天
*/
public static int getDay() {
Calendar calendar = GregorianCalendar.getInstance();
return calendar.get(Calendar.DATE);
}
/**
* @param date1
* @param date2
* @return 1:date1大于date2;
* -1:date1小于date2
*/
public static int compareDate(String date1, String date2, String format) {
DateFormat df = new SimpleDateFormat(format, Locale.getDefault());
try {
Date dt1 = df.parse(date1);
Date dt2 = df.parse(date2);
if (dt1.getTime() > dt2.getTime()) {
return 1;
} else if (dt1.getTime() < dt2.getTime()) {
return -1;
} else {
return 0;
}
} catch (Exception exception) {
exception.printStackTrace();
}
return 0;
}
/**
* 时间加减
*
* @param day 如"2015-09-22"
* @param dayAddNum 加减值
* @return
*/
public static String timeAddSubtract(String day, int dayAddNum) {
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd", Locale.getDefault());
try {
Date newDate = new Date(simpleDateFormat.parse(day).getTime() + dayAddNum * 24 * 60 * 60 * 1000);
return simpleDateFormat.format(newDate);
} catch (ParseException e) {
e.printStackTrace();
}
return null;
}
/**
* 毫秒格式化
*
* @param millisecond 如"1449455517602"
* @param format 如"yyyy-MM-dd HH:mm:ss"
* @return
*/
public static String millisecond2String(long millisecond, String format) {
SimpleDateFormat simpleDateFormat = new SimpleDateFormat(format, Locale.getDefault());
return simpleDateFormat.format(millisecond);
}
}
1…111213…16
吴小龙同學

吴小龙同學

公众号:吴小龙同学

154 日志
43 分类
116 标签
RSS
WeChat GitHub 知乎 Weibo
© 2013 – 2024 吴小龙同學
由 Hexo 强力驱动 v3.4.2
|
主题 – NexT.Gemini v6.7.0