1
2
3
4
5
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@mipmap/nav_zyjd_selected" android:state_checked="true"/>
<item android:drawable="@mipmap/nav_zyjd" android:state_checked="false"/>
</selector>
1
2
3
4
5
int width = MyUtils.dip2px(TrialingActivity.this, 11);
int heigth = MyUtils.dip2px(TrialingActivity.this, 12);
Drawable dispute = getResources().getDrawable(R.drawable.selector_trialing_dispute);
dispute.setBounds(0, 0,width ,heigth);
rb_dispute.setCompoundDrawables(null, dispute, null, null);

####加载圆形图片:

1
2
3
4
5
6
RequestOptions mRequestOptions = RequestOptions.circleCropTransform()
.diskCacheStrategy(DiskCacheStrategy.NONE)//不做磁盘缓存
.skipMemoryCache(true);//不做内存缓存
.error(R.mipmap.icon_store_default_head)//错误图片
.placeholder(R.mipmap.icon_store_default_head)//预加载图片
Glide.with(mContext).load(userInfo.getImage()).apply(mRequestOptions).into(mUserIcon);

####加载圆角图片:

1
2
3
4
5
6
//设置图片圆角角度
RoundedCorners roundedCorners= new RoundedCorners(6);//px
//通过RequestOptions扩展功能,override:采样率,因为ImageView就这么大,可以压缩图片,降低内存消耗
RequestOptions options=RequestOptions.bitmapTransform(roundedCorners).override(300, 300);
Glide.with(context).load(files.getFilePath()).apply(options).into(mUserPhoto);

1
2
3
4
5
6
7
8
9
10
11
//调用方法
String dirPath = ContextCompat.getExternalFilesDirs(MainActivity.this,
Environment.DIRECTORY_DCIM)[0].getAbsolutePath() + File.separator + "PrintFile";
try {
copyAssetToFile("庭审系统安卓端操作手册.pdf",dirPath,"/庭审系统安卓端操作手册.pdf");
} catch (IOException e) {
Log.e("tyl","IOException="+e.getMessage());
e.printStackTrace();
}
//读取到本地file文件
File file = new File(dirPath+"/庭审系统安卓端操作手册.pdf");
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
/**
* 复制assets下的文件到本地文件
* assetName assets内的文件名称
* savepath 本地文件夹路径
* savename 保存的文件名称需带后缀文件类型 如.pdf
* @throws IOException
*/
public void copyAssetToFile(String assetName, String savepath, String savename) throws IOException {
InputStream myInput;
File dir = new File(savepath);
if (!dir.exists()) {
dir.mkdirs();
}
File dbf = new File(savepath + savename);
if (dbf.exists()) {
dbf.delete();
}
String outFileName = savepath + savename;
OutputStream myOutput = new FileOutputStream(outFileName);
myInput = this.getAssets().open(assetName);
byte[] buffer = new byte[1024];
int length;
while ((length = myInput.read(buffer)) > 0) {
myOutput.write(buffer, 0, length);
}
myOutput.flush();
myInput.close();
myOutput.close();
}

####1.权限申请
为了实现在项目中调用系统日历和插入日程事件,我们首先在AndroidManifest.xml文件中添加如下相关权限

1
2
<uses-permission android:name="android.permission.READ_CALENDAR" />
<uses-permission android:name="android.permission.WRITE_CALENDAR" />

####2.日历相关uri
系统calendar content provider相关的uri,以下为Android2.2版本以后的uri

1
2
3
private static String CALENDER_URL = "content://com.android.calendar/calendars";
private static String CALENDER_EVENT_URL = "content://com.android.calendar/events";
private static String CALENDER_REMINDER_URL = "content://com.android.calendar/reminders";

####3.具体实现

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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
package com.guoshikeji.calendar.utils;

import android.content.ContentUris;
import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.graphics.Color;
import android.net.Uri;
import android.provider.CalendarContract;
import android.text.TextUtils;

import java.util.Calendar;
import java.util.TimeZone;

/**
* Created by tyl
* 2018/11/20/020
* Describe:往本地日历插入事件
*/

public class CalendarReminderUtils {

private static String CALENDER_URL = "content://com.android.calendar/calendars";
private static String CALENDER_EVENT_URL = "content://com.android.calendar/events";
private static String CALENDER_REMINDER_URL = "content://com.android.calendar/reminders";

private static String CALENDARS_NAME = "boohee";
private static String CALENDARS_ACCOUNT_NAME = "BOOHEE@boohee.com";
private static String CALENDARS_ACCOUNT_TYPE = "com.android.boohee";
private static String CALENDARS_DISPLAY_NAME = "BOOHEE账户";

/**
* 检查是否已经添加了日历账户,如果没有添加先添加一个日历账户再查询
* 获取账户成功返回账户id,否则返回-1
*/
private static int checkAndAddCalendarAccount(Context context) {
int oldId = checkCalendarAccount(context);
if( oldId >= 0 ){
return oldId;
}else{
long addId = addCalendarAccount(context);
if (addId >= 0) {
return checkCalendarAccount(context);
} else {
return -1;
}
}
}
/**
* 检查是否存在现有账户,存在则返回账户id,否则返回-1
*/
private static int checkCalendarAccount(Context context) {
Cursor userCursor = context.getContentResolver().query(Uri.parse(CALENDER_URL), null, null, null, null);
try {
if (userCursor == null) { //查询返回空值
return -1;
}
int count = userCursor.getCount();
if (count > 0) { //存在现有账户,取第一个账户的id返回
userCursor.moveToFirst();
return userCursor.getInt(userCursor.getColumnIndex(CalendarContract.Calendars._ID));
} else {
return -1;
}
} finally {
if (userCursor != null) {
userCursor.close();
}
}
}

/**
* 添加日历账户,账户创建成功则返回账户id,否则返回-1
*/
private static long addCalendarAccount(Context context) {
TimeZone timeZone = TimeZone.getDefault();
ContentValues value = new ContentValues();
value.put(CalendarContract.Calendars.NAME, CALENDARS_NAME);
value.put(CalendarContract.Calendars.ACCOUNT_NAME, CALENDARS_ACCOUNT_NAME);
value.put(CalendarContract.Calendars.ACCOUNT_TYPE, CALENDARS_ACCOUNT_TYPE);
value.put(CalendarContract.Calendars.CALENDAR_DISPLAY_NAME, CALENDARS_DISPLAY_NAME);
value.put(CalendarContract.Calendars.VISIBLE, 1);
value.put(CalendarContract.Calendars.CALENDAR_COLOR, Color.BLUE);
value.put(CalendarContract.Calendars.CALENDAR_ACCESS_LEVEL, CalendarContract.Calendars.CAL_ACCESS_OWNER);
value.put(CalendarContract.Calendars.SYNC_EVENTS, 1);
value.put(CalendarContract.Calendars.CALENDAR_TIME_ZONE, timeZone.getID());
value.put(CalendarContract.Calendars.OWNER_ACCOUNT, CALENDARS_ACCOUNT_NAME);
value.put(CalendarContract.Calendars.CAN_ORGANIZER_RESPOND, 0);

Uri calendarUri = Uri.parse(CALENDER_URL);
calendarUri = calendarUri.buildUpon()
.appendQueryParameter(CalendarContract.CALLER_IS_SYNCADAPTER, "true")
.appendQueryParameter(CalendarContract.Calendars.ACCOUNT_NAME, CALENDARS_ACCOUNT_NAME)
.appendQueryParameter(CalendarContract.Calendars.ACCOUNT_TYPE, CALENDARS_ACCOUNT_TYPE)
.build();

Uri result = context.getContentResolver().insert(calendarUri, value);
long id = result == null ? -1 : ContentUris.parseId(result);
return id;
}
/**
* 添加日历事件
*/
public static void addCalendarEvent(Context context, String title, String description, long reminderTime, int previousDate) {
if (context == null) {
return;
}
int calId = checkAndAddCalendarAccount(context); //获取日历账户的id
if (calId < 0) { //获取账户id失败直接返回,添加日历事件失败
return;
}

//添加日历事件
Calendar mCalendar = Calendar.getInstance();
mCalendar.setTimeInMillis(reminderTime);//设置开始时间
long start = mCalendar.getTime().getTime();
mCalendar.setTimeInMillis(start + 10 * 60 * 1000);//设置终止时间,开始时间加10分钟
long end = mCalendar.getTime().getTime();
ContentValues event = new ContentValues();
event.put("title", title);
event.put("description", description);
event.put("calendar_id", calId); //插入账户的id
event.put(CalendarContract.Events.DTSTART, start);
event.put(CalendarContract.Events.DTEND, end);
event.put(CalendarContract.Events.HAS_ALARM, 1);//设置有闹钟提醒
event.put(CalendarContract.Events.EVENT_TIMEZONE, "Asia/Shanghai");//这个是时区,必须有
Uri newEvent = context.getContentResolver().insert(Uri.parse(CALENDER_EVENT_URL), event); //添加事件
if (newEvent == null) { //添加日历事件失败直接返回
return;
}
//事件提醒的设定
ContentValues values = new ContentValues();
values.put(CalendarContract.Reminders.EVENT_ID, ContentUris.parseId(newEvent));
values.put(CalendarContract.Reminders.MINUTES, previousDate * 24 * 60);// 提前previousDate天有提醒
values.put(CalendarContract.Reminders.METHOD, CalendarContract.Reminders.METHOD_ALERT);
Uri uri = context.getContentResolver().insert(Uri.parse(CALENDER_REMINDER_URL), values);
if(uri == null) { //添加事件提醒失败直接返回
return;
}
}

/**
* 删除日历事件
*/
public static void deleteCalendarEvent(Context context,String title) {
if (context == null) {
return;
}
Cursor eventCursor = context.getContentResolver().query(Uri.parse(CALENDER_EVENT_URL), null, null, null, null);
try {
if (eventCursor == null) { //查询返回空值
return;
}
if (eventCursor.getCount() > 0) {
//遍历所有事件,找到title跟需要查询的title一样的项
for (eventCursor.moveToFirst(); !eventCursor.isAfterLast(); eventCursor.moveToNext()) {
String eventTitle = eventCursor.getString(eventCursor.getColumnIndex("title"));
if (!TextUtils.isEmpty(title) && title.equals(eventTitle)) {
int id = eventCursor.getInt(eventCursor.getColumnIndex(CalendarContract.Calendars._ID));//取得id
Uri deleteUri = ContentUris.withAppendedId(Uri.parse(CALENDER_EVENT_URL), id);
int rows = context.getContentResolver().delete(deleteUri, null, null);
if (rows == -1) { //事件删除失败
return;
}
}
}
}
} finally {
if (eventCursor != null) {
eventCursor.close();
}
}
}
}
透明度 数值
100% FF
95% F2
90% E6
85% D9
80% CC
75% BF
70% B3
65% A6
60% 99
55% 8C
50% 80
45% 73
40% 66
35% 59
30% 4D
25% 40
20% 33
15% 26
10% 1A
5% 0D
0% 00

判断软键盘是否弹出:

1
2
3
4
5
6
7
8
private boolean isSoftShowing() {
//获取当前屏幕内容的高度
int screenHeight = getWindow().getDecorView().getHeight();
//获取View可见区域的bottom
Rect rect = new Rect();
getWindow().getDecorView().getWindowVisibleDisplayFrame(rect);
return screenHeight - rect.bottom != 0;
}

隐藏软键盘(只适用于Activity,不适用于Fragment)

1
2
3
4
5
6
7
public static void hideSoftKeyboard(Activity activity) {
View view = activity.getCurrentFocus();
if (view != null) {
InputMethodManager inputMethodManager = (InputMethodManager) activity.getSystemService(Activity.INPUT_METHOD_SERVICE);
inputMethodManager.hideSoftInputFromWindow(view.getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS);
}
}

隐藏软键盘(可用于Activity,Fragment)

1
2
3
4
5
6
7
public static void hideSoftKeyboard(Context context, List<View> viewList) {
if (viewList == null) return;
InputMethodManager inputMethodManager = (InputMethodManager) context.getSystemService(Activity.INPUT_METHOD_SERVICE);
for (View v : viewList) {
inputMethodManager.hideSoftInputFromWindow(v.getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS);
}
}

配置:

1
2
3
4
5
6
7
//工程的build.gradle中添加:
allprojects {
repositories {
...
maven { url 'https://www.jitpack.io' }
}
}
1
implementation 'com.github.fs437563:JetShineBoxSwitchPower:1.2'

1.添加权限

1
2
3
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>

2.同步系统时间

1
2
//系统时间同步并非立即生效有1/2秒延迟,不要和开关机设置同时间执行
BoxSwitchPowerUtil.getInstance().synSystemTime(2021,07,05,12,01,50;

3.设置开机

1
2
3
   BoxSwitchPowerUtil.getInstance().openPower(MainActivity.this);
//or
BoxSwitchPowerUtil.getInstance().setStartTime(MainActivity.this,"2021-07-05 12:03:00");

4.设置关机

1
2
3
BoxSwitchPowerUtil.getInstance().closePower(MainActivity.this);
//or
BoxSwitchPowerUtil.getInstance().setCloseTime(MainActivity.this,"2021-07-05 12:02:00");

在android开发中,Eclipse或者AndroidStudio调试时打印的信息很多,或者某些log字数超过Eclipse一行的字数限制,这个时候Eclipse就傻傻地把超出一行的log省略掉了,给我们开发中带来不方便。或者在进行黑盒测试时,为了更加方便的找到错误信息,我们可以把log信息使用命令行查看或者直接输出到本地。
下面是命令的格式:

1
2
3
4
5
6
7
8
  V    Verbose (default for <tag>)
D Debug (default for '*')
I Info
W Warn
E Error
F Fatal
S Silent (suppress all output)
adb shell logcat TAG:I *:S > D:\\log.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
/**
* 返回app运行状态
* @param packageName 要判断应用的包名
* @return int 1:前台 2:后台 0:不存在
*/
private int isAppAlive(Context context, String packageName) {
ActivityManager activityManager = (ActivityManager) context
.getSystemService(Context.ACTIVITY_SERVICE);
List<ActivityManager.RunningTaskInfo> listInfos = activityManager
.getRunningTasks(20);
// 判断程序是否在栈顶
if (listInfos.get(0).topActivity.getPackageName().equals(packageName)) {
return 1;
} else {
// 判断程序是否在栈里
for (ActivityManager.RunningTaskInfo info : listInfos) {
if (info.topActivity.getPackageName().equals(packageName)) {
return 2;
}
}
return 0;// 栈里找不到,返回3
}
}

网站图
#####地址:http://www.aigei.com/bgremover/
工具说明: 当我们在提取一些素材图片的时候,可能由于图片格式等原因,使得原本背景透明的图片变成了纯色背景的图片。这时候我们可以使用BgRemover图片去底工具将“纯色背景的图片”再次还原成“透明背景的图片”。

操作方法: 点击“浏览文件”按钮,选择需要去底的图片,BgRemover会自动帮你完成图片去底工作,去底完成后点击下载按钮保存已去底的图片即可。

浏览器要求: 请使用IE9+,或者谷歌,火狐,360,搜狗等浏览器。