Skip to content

Commit

Permalink
增加工具类方法
Browse files Browse the repository at this point in the history
  • Loading branch information
xuexiangjys committed Aug 8, 2019
1 parent 6d1c7e1 commit aa8cf24
Show file tree
Hide file tree
Showing 8 changed files with 338 additions and 14 deletions.
2 changes: 2 additions & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
apply plugin: 'com.android.application'
apply plugin: 'com.xuexiang.xaop' //引用xaop插件

android {
compileSdkVersion build_versions.target_sdk
Expand Down Expand Up @@ -77,6 +78,7 @@ dependencies {
// implementation 'com.github.xuexiangjys.XUtil:xutil-core:1.1.3'
// implementation 'com.github.xuexiangjys.XUtil:xutil-sub:1.1.3'

implementation 'com.github.xuexiangjys.XAOP:xaop-runtime:1.0.3' //添加依赖
//butterknife的sdk
implementation deps.butterknife.runtime
annotationProcessor deps.butterknife.compiler
Expand Down
16 changes: 16 additions & 0 deletions app/src/main/java/com/xuexiang/xutildemo/MyApp.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,15 @@
import android.app.Application;
import android.content.Context;

import com.xuexiang.xaop.XAOP;
import com.xuexiang.xaop.util.PermissionUtils;
import com.xuexiang.xpage.AppPageConfig;
import com.xuexiang.xpage.PageConfig;
import com.xuexiang.xpage.PageConfiguration;
import com.xuexiang.xpage.model.PageInfo;
import com.xuexiang.xutil.XUtil;
import com.xuexiang.xutil.common.StringUtils;
import com.xuexiang.xutil.tip.ToastUtils;

import java.util.List;

Expand All @@ -45,6 +49,18 @@ public List<PageInfo> registerPages(Context context) {
return AppPageConfig.getInstance().getPages();
}
}).debug("PageLog").init(this);


XAOP.init(this); //初始化插件
XAOP.debug(true); //日志打印切片开启
//设置动态申请权限切片 申请权限被拒绝的事件响应监听
XAOP.setOnPermissionDeniedListener(new PermissionUtils.OnPermissionDeniedListener() {
@Override
public void onDenied(List<String> permissionsDenied) {
ToastUtils.toast("权限申请被拒绝:" + StringUtils.listToString(permissionsDenied, ","));
}

});
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import android.view.KeyEvent;
import android.view.View;

import com.xuexiang.xaop.annotation.Permission;
import com.xuexiang.xpage.annotation.Page;
import com.xuexiang.xpage.base.XPageSimpleListFragment;
import com.xuexiang.xpage.utils.TitleBar;
Expand All @@ -29,22 +30,29 @@
import com.xuexiang.xutil.app.router.Router;
import com.xuexiang.xutil.common.ClickUtils;
import com.xuexiang.xutil.data.DateUtils;
import com.xuexiang.xutil.system.CameraUtils;
import com.xuexiang.xutil.tip.ToastUtils;
import com.xuexiang.xutildemo.activity.TestRouterActivity;

import java.io.File;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import static android.app.Activity.RESULT_OK;
import static com.xuexiang.xaop.consts.PermissionConsts.CAMERA;
import static com.xuexiang.xaop.consts.PermissionConsts.STORAGE;
import static com.xuexiang.xutil.system.CameraUtils.REQUEST_CAMERA;

/**
* 主界面
*
* @author xuexiang
* @date 2018/4/14 上午1:42
*/
@Page(name = "XUtil")
public class MainFragment extends XPageSimpleListFragment {
private File mCameraFile;
/**
* 初始化例子
*
Expand All @@ -56,6 +64,7 @@ protected List<String> initSimpleData(List<String> lists) {
lists.add("路由测试");
lists.add("通知");
lists.add("社会化分享");
lists.add("拍照");
return lists;
}

Expand All @@ -66,7 +75,7 @@ protected List<String> initSimpleData(List<String> lists) {
*/
@Override
protected void onItemClick(int position) {
switch(position) {
switch (position) {
case 0:
// ActivityUtils.startActivity(TestRouterActivity.class, "param", "我是内容");
Map<String, Object> params = new HashMap<>();
Expand All @@ -78,21 +87,31 @@ protected void onItemClick(int position) {
// ActivityUtils.startActivityForResult(this, "com.xuexiang.TestRouter", 100, params);
// ActivityUtils.startActivityForResult(this, TestRouterActivity.class, 100, params);
Router.newIntent(this).to(TestRouterActivity.class).putExtraParam("param1", "我是参数1").requestCode(100).launch();

Log.e("xuexiang", DateUtils.nDaysAfterToday(2, true));
Log.e("xuexiang", DateUtils.nDaysBeforeToday(2, true));
break;
case 1:
openPage(NotifyFragment.class);
openPage(NotifyFragment.class);
break;
case 2:
openPage(SocialShareFragment.class);
break;
break;
case 3:
openCamera();
break;
default:
break;
}
}

@Permission({CAMERA})
private void openCamera() {
CameraUtils.startOpenCamera(this, new CameraUtils.OnOpenCameraListener() {
@Override
public void onOpenCamera(File cameraFile) {
mCameraFile = cameraFile;
}
});
}


@Override
protected TitleBar initTitleBar() {
Expand Down Expand Up @@ -120,7 +139,11 @@ public boolean onKeyDown(int keyCode, KeyEvent event) {
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (resultCode == RESULT_OK) {
ToastUtils.toast("请求码:" + requestCode + ", 返回码:" + resultCode + ", 返回内容:" + IntentUtils.getStringExtra(data, "back"));
if (requestCode == REQUEST_CAMERA) {
ToastUtils.toast("文件路径:" + mCameraFile.getPath());
} else {
ToastUtils.toast("请求码:" + requestCode + ", 返回码:" + resultCode + ", 返回内容:" + IntentUtils.getStringExtra(data, "back"));
}
}
}

Expand Down
3 changes: 3 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ buildscript {
classpath deps.android_maven_gradle_plugin

classpath deps.gradle_bintray_plugin

classpath 'com.github.xuexiangjys.XAOP:xaop-plugin:1.0.3'

// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
Expand Down
2 changes: 1 addition & 1 deletion xutil-core/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ dependencies {
implementation deps.gson
}

apply from: "https://raw.githubusercontent.com/xuexiangjys/XUtil/master/JitPackUpload.gradle"
apply from: "../JitPackUpload.gradle"

//apply from: "../bintrayUpload.gradle"

Expand Down
87 changes: 82 additions & 5 deletions xutil-core/src/main/java/com/xuexiang/xutil/data/DateUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,83 @@ public static String convertTimeToFileName(String dateTime, String suffix) {

//===============================时间计算==================================//

/**
* 获取日期当天的最早时间
*
* <p>例如:今天日期是 2018-4-24 12:34:58,结果就是 2018-4-24 00:00:00:000</p>
*
* @param date 日期
* @return
*/
public static Date getStartOfDay(Date date) {
Calendar cal = Calendar.getInstance();
cal.setTime(date);
cal.set(Calendar.HOUR_OF_DAY, 0);
cal.set(Calendar.MINUTE, 0);
cal.set(Calendar.SECOND, 0);
cal.set(Calendar.MILLISECOND, 0);
return cal.getTime();
}

/**
* 获取n天后最早的时间
*
* <p>例如:今天日期是 2018-4-24 12:34:58,n=2,结果就是 2018-4-26 00:00:00:000</p>
*
* @param date 日期
* @param dayAfter 几天后
* @return
*/
public static Date getStartOfDay(Date date, int dayAfter) {
Calendar cal = Calendar.getInstance();
cal.setTime(date);
cal.add(Calendar.DAY_OF_MONTH, dayAfter);
cal.set(Calendar.HOUR_OF_DAY, 0);
cal.set(Calendar.MINUTE, 0);
cal.set(Calendar.SECOND, 0);
cal.set(Calendar.MILLISECOND, 0);
return cal.getTime();
}

/**
* 获取日期当天的最后时间
*
* <p>例如:今天日期是 2018-4-24 12:34:58,结果就是 2018-4-24 23:59:59:999</p>
*
* @param date 日期
* @return
*/
public static Date getEndOfDay(Date date) {
Calendar cal = Calendar.getInstance();
cal.setTime(date);
cal.set(Calendar.HOUR_OF_DAY, 23);
cal.set(Calendar.MINUTE, 59);
cal.set(Calendar.SECOND, 59);
cal.set(Calendar.MILLISECOND, 999);
return cal.getTime();
}

/**
* 获取日期当天的最后时间
*
* <p>例如:今天日期是 2018-4-24 12:34:58,n=2,结果就是 2018-4-26 23:59:59:999</p>
*
* @param date 日期
* @param dayAfter 几天后
* @return
*/
public static Date getEndOfDay(Date date, int dayAfter) {
Calendar cal = Calendar.getInstance();
cal.setTime(date);
cal.add(Calendar.DAY_OF_MONTH, dayAfter);
cal.set(Calendar.HOUR_OF_DAY, 23);
cal.set(Calendar.MINUTE, 59);
cal.set(Calendar.SECOND, 59);
cal.set(Calendar.MILLISECOND, 999);
return cal.getTime();
}


/**
* 获取当前日期n天前的日期,返回String
* <p>例如:今天是2018-4-24,day=2, return 2018-4-22</p>
Expand Down Expand Up @@ -715,11 +792,11 @@ private static long getWeeOfToday() {
return cal.getTimeInMillis();
}

private static final int YEAR = 365 * 24 * 60 * 60;// 年
private static final int MONTH = 30 * 24 * 60 * 60;// 月
private static final int DAY = 24 * 60 * 60;// 天
private static final int HOUR = 60 * 60;// 小时
private static final int MINUTE = 60;// 分钟
public static final int YEAR = 365 * 24 * 60 * 60;// 年
public static final int MONTH = 30 * 24 * 60 * 60;// 月
public static final int DAY = 24 * 60 * 60;// 天
public static final int HOUR = 60 * 60;// 小时
public static final int MINUTE = 60;// 分钟

/**
* 根据时间戳获取模糊型的时间描述。
Expand Down
2 changes: 1 addition & 1 deletion xutil-sub/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -44,5 +44,5 @@ dependencies {
compileOnly project(':xutil-core')
}

apply from: "https://raw.githubusercontent.com/xuexiangjys/XUtil/master/JitPackUpload.gradle"
apply from: "../JitPackUpload.gradle"

Loading

0 comments on commit aa8cf24

Please sign in to comment.