com.blankj.utilcode.util.TimeUtils Java Examples

The following examples show how to use com.blankj.utilcode.util.TimeUtils. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: LockAudioActivity.java    From YCAudioPlayer with Apache License 2.0 6 votes vote down vote up
@SuppressLint({"SetTextI18n", "SimpleDateFormat"})
private void onChangeImpl(AudioBean music) {
    if (music == null) {
        return;
    }
    String nowString = TimeUtils.getNowString(new SimpleDateFormat("hh:mm", Locale.CHINESE));
    tvTime.setText(nowString);
    Bitmap cover = CoverLoader.getInstance().loadThumbnail(music);
    ivImage.setImageBitmap(cover);
    tvTitle.setText(music.getTitle()+ " / " + music.getArtist());
    mLastProgress = 0;
    //更新进度条
    sbProgress.setMax((int) music.getDuration());
    sbProgress.setProgress((int) playService.getCurrentPosition());
    tvCurrentTime.setText("00:00");
    tvTotalTime.setText(VideoPlayerUtils.formatTime(music.getDuration()));
}
 
Example #2
Source File: EditNotePresenter.java    From SuperNote with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void initData() {
    Intent intent = mView.getActivityIntent();
    mIsAdd = intent.getBooleanExtra("is_add", false);
    if (mIsAdd) {
        mNoteId = UUID.randomUUID().toString();
        mModifiedTime = TimeUtils.getNowMills();
        mNoteContent = new String("");
    } else {
        mPosition = intent.getIntExtra("position", 0);
        mNoteId = intent.getStringExtra("note_id");
        mModifiedTime = intent.getLongExtra("modified_time", 0);
        mNoteContent = intent.getStringExtra("note_content");
    }
    mView.setTitle(TimeUtils.millis2String(mModifiedTime));
}
 
Example #3
Source File: LocalVideoAdapter.java    From YCAudioPlayer with Apache License 2.0 5 votes vote down vote up
@SuppressLint({"SetTextI18n", "SimpleDateFormat"})
@Override
public void setData(VideoBean data) {
    super.setData(data);
    Bitmap videoThumbnail = data.getVideoThumbnail();
    if(videoThumbnail!=null){
        Drawable drawable = ImageUtils.bitmap2Drawable(videoThumbnail);
        ivCover.setBackground(drawable);
    }
    tvTitle.setText(data.getTitle());
    String string = TimeUtils.millis2String(data.getDuration(), new SimpleDateFormat("mm:ss"));
    tvArtist.setText("时长:"+string+"   分辨率:"+data.getResolution()+"   大小"+data.getFileSize());
    vDivider.setVisibility(View.VISIBLE);
}
 
Example #4
Source File: AppHealthInfoUtil.java    From DoraemonKit with Apache License 2.0 5 votes vote down vote up
/**
 * 设置基本信息
 *
 * @param caseName   用例名称
 * @param testPerson 测试人员名字
 */
void setBaseInfo(String caseName, String testPerson) {
    AppHealthInfo.BaseInfoBean baseInfoBean = new AppHealthInfo.BaseInfoBean();
    baseInfoBean.setTestPerson(testPerson);
    baseInfoBean.setCaseName(caseName);
    baseInfoBean.setAppName(AppUtils.getAppName());
    baseInfoBean.setAppVersion(AppUtils.getAppVersionName());
    baseInfoBean.setDokitVersion(BuildConfig.DOKIT_VERSION);
    baseInfoBean.setPlatform("Android");
    baseInfoBean.setPhoneMode(DeviceUtils.getModel());
    baseInfoBean.setTime(TimeUtils.getNowString());
    baseInfoBean.setSystemVersion(DeviceUtils.getSDKVersionName());
    baseInfoBean.setpId("" + DokitConstant.PRODUCT_ID);
    mAppHealthInfo.setBaseInfo(baseInfoBean);
}
 
Example #5
Source File: DataPickBean.java    From DoraemonKit with Apache License 2.0 5 votes vote down vote up
DataPickBean() {
    //初始化基础数据
    this.pId = DokitConstant.PRODUCT_ID;
    this.appName = AppUtils.getAppName();
    this.appId = AppUtils.getAppPackageName();
    this.dokitVersion = BuildConfig.DOKIT_VERSION;
    this.platform = "Android";
    this.phoneMode = DeviceUtils.getModel();
    this.time = "" + TimeUtils.getNowMills();
    this.systemVersion = DeviceUtils.getSDKVersionName();
    this.language = Locale.getDefault().getDisplayLanguage();
}
 
Example #6
Source File: EditNotePresenter.java    From SuperNote with GNU General Public License v3.0 5 votes vote down vote up
private void setFile(Activity activity) throws IOException {
    mImageName = TimeUtils.getNowString() + ".jpg";
    mImageFolder = activity.getExternalFilesDir(mNoteId);
    mImageFile = new File(mImageFolder, mImageName);

    checkImageFolder();
}
 
Example #7
Source File: SharePresenter.java    From SuperNote with GNU General Public License v3.0 5 votes vote down vote up
@Override
public Uri saveImageAndGetUri() {
    String filePath = mView.getActivity().getExternalFilesDir("share").getPath() + "/" + TimeUtils.getNowMills() + ".jpg";
    File file = new File(filePath);
    ImageUtils.save(mBitmap, file, Bitmap.CompressFormat.JPEG);
    return Uri.fromFile(file);
}
 
Example #8
Source File: RvNoteListAdapter.java    From SuperNote with GNU General Public License v3.0 5 votes vote down vote up
/**
 * 设置便签的时间显示格式:
 * 便签修改时间与当前时间对比,
 * 同一天的显示为:HH:mm;
 * 同一年的显示为:MM-DD HH:mm
 * 其他显示为:yyyy-MM-DD HH:mm
 *
 * @param time 时间戳
 * @describe
 */
private void setNoteTime(BaseViewHolder helper, long time) {

    // 系统当前时间,用于与便签的修改时间进行对比
    long nowTime = TimeUtils.getNowMills();

    if (DateUtils.isInSameDay(nowTime, time))  // 同一天
        setNoteTimeInfo(helper, time, new SimpleDateFormat("HH:mm"));
    else if (DateUtils.isInSameYear(nowTime, time))  // 同一年
        setNoteTimeInfo(helper, time, new SimpleDateFormat("MM-dd HH:mm"));
    else // 其他
        setNoteTimeInfo(helper, time, new SimpleDateFormat("yyyy-MM-dd HH:mm"));

}
 
Example #9
Source File: RvNoteListAdapter.java    From SuperNote with GNU General Public License v3.0 5 votes vote down vote up
/**
 * 设置线性布局时的分组的格式
 *
 * @describe
 */
private void setLinearGroupStyle(BaseViewHolder helper, long time) {
    long nowTime = TimeUtils.getNowMills();

    if (DateUtils.isInSameYear(nowTime, time)) { // 如果同一年 显示为:x月
        helper.setText(R.id.tv_note_list_linear_month, TimeUtils.millis2String(time, new SimpleDateFormat("MM月")));
    } else { //否则 显示为:xxxx年x月
        helper.setText(R.id.tv_note_list_linear_month, TimeUtils.millis2String(time, new SimpleDateFormat("yyyy年MM月")));
    }
}
 
Example #10
Source File: LogInfoDokitView.java    From DoraemonKit with Apache License 2.0 4 votes vote down vote up
/**
 * 将日志信息保存到文件
 *
 * @param operateType 100 保存到本地  101 保存到本地并分享
 */
private void export2File(final int operateType) {
    ToastUtils.showShort("日志保存中,请稍后...");
    final String logPath = PathUtils.getInternalAppFilesPath() + File.separator + AppUtils.getAppName() + "_" + TimeUtils.getNowString(new SimpleDateFormat("yyyy-MM-dd-HH:mm:ss")) + ".log";
    final File logFile = new File(logPath);

    ThreadUtils.executeByCpu(new ThreadUtils.Task<Boolean>() {
        @Override
        public Boolean doInBackground() throws Throwable {
            try {
                List<LogLine> logLines = new ArrayList<>(mLogItemAdapter.getTrueValues());
                for (LogLine logLine : logLines) {
                    String strLog = logLine.getProcessId() + "   " + "   " + logLine.getTimestamp() + "   " + logLine.getTag() + "   " + logLine.getLogLevelText() + "   " + logLine.getLogOutput() + "\n";
                    FileIOUtils.writeFileFromString(logFile, strLog, true);
                }
                return true;
            } catch (Exception e) {
                e.printStackTrace();
                return false;
            }
        }

        @Override
        public void onSuccess(Boolean result) {
            if (result) {
                ToastUtils.showShort("文件保存在:" + logPath);
                //分享
                if (operateType == 101) {
                    FileUtil.systemShare(DoraemonKit.APPLICATION, logFile);
                }
            }
        }

        @Override
        public void onCancel() {
            if (logFile.exists()) {
                FileUtils.delete(logFile);
            }
            ToastUtils.showShort("日志保存失败");
        }

        @Override
        public void onFail(Throwable t) {
            if (logFile.exists()) {
                FileUtils.delete(logFile);
            }
            ToastUtils.showShort("日志保存失败");
        }
    });

}
 
Example #11
Source File: DataPickBean.java    From DoraemonKit with Apache License 2.0 4 votes vote down vote up
EventBean(String eventName) {
    this.eventName = eventName;
    this.time = "" + TimeUtils.getNowMills();
}
 
Example #12
Source File: CommonUtils.java    From DanDanPlayForAndroid with MIT License 4 votes vote down vote up
/**
 * 处理补丁回调
 */
public static PatchLoadStatusListener getPatchLoadListener() {
    return (mode, code, serviceMsg, version) -> {
        String msg = "";
        List<PatchFixEvent> eventList = JsonUtils.getObjectList(SPUtils.getInstance().getString("patch_his"), PatchFixEvent.class);
        if (eventList == null) eventList = new ArrayList<>();
        AppConfig.getInstance().setPatchVersion(version);
        PatchFixEvent event = new PatchFixEvent();
        event.setVersion(version);
        event.setTime(TimeUtils.date2String(new java.util.Date()));
        switch (code) {
            //加载阶段, 成功
            case PatchStatus.CODE_LOAD_SUCCESS:
                msg = "加载补丁成功";
                break;
            //加载阶段, 失败设备不支持
            case PatchStatus.CODE_ERR_INBLACKLIST:
                msg = "加载失败,设备不支持";
                break;
            //查询阶段, 没有发布新补丁
            case PatchStatus.CODE_REQ_NOUPDATE:
                msg = "已是最新补丁";
                event.setCode(-2);
                break;
            //查询阶段, 补丁不是最新的
            case PatchStatus.CODE_REQ_NOTNEWEST:
                msg = "开始下载补丁";
                break;
            //查询阶段, 补丁下载成功
            case PatchStatus.CODE_DOWNLOAD_SUCCESS:
                msg = "补丁下载成功";
                break;
            //查询阶段, 补丁文件损坏下载失败
            case PatchStatus.CODE_DOWNLOAD_BROKEN:
                msg = "补丁文件损坏下载失败";
                break;
            //查询阶段, 补丁解密失败
            case PatchStatus.CODE_UNZIP_FAIL:
                msg = "补丁解密失败";
                break;
            //预加载阶段, 需要重启
            case PatchStatus.CODE_LOAD_RELAUNCH:
                msg = "加载成功,重启应用后生效";
                break;
            //查询阶段, appid异常
            case PatchStatus.CODE_REQ_APPIDERR:
                msg = "加载失败,appid异常";
                break;
            //查询阶段, 签名异常
            case PatchStatus.CODE_REQ_SIGNERR:
                msg = "加载失败,签名异常";
                break;
            //查询阶段, 系统无效
            case PatchStatus.CODE_REQ_UNAVAIABLE:
                msg = "加载失败,系统无效";
                break;
            //查询阶段, 系统异常
            case PatchStatus.CODE_REQ_SYSTEMERR:
                msg = "加载失败,系统异常";
                break;
            //查询阶段, 一键清除补丁
            case PatchStatus.CODE_REQ_CLEARPATCH:
                msg = "一键清除成功";
                break;
            //加载阶段, 补丁格式非法
            case PatchStatus.CODE_PATCH_INVAILD:
                msg = "加载失败,补丁格式非法";
                break;
            default:
                event.setCode(code);
                break;
        }
        LogUtils.e(msg);
        event.setMsg(msg);
        eventList.add(event);
        EventBus.getDefault().post(event);
        SPUtils.getInstance().put("patch_his", JsonUtils.toJson(eventList));
    };
}
 
Example #13
Source File: SharePresenter.java    From SuperNote with GNU General Public License v3.0 4 votes vote down vote up
private void saveImageToLocation(Bitmap bitmap) {
    File file = new File(Constans.imageSaveFolder + "/" + TimeUtils.getNowMills() + ".jpg");
    ImageUtils.save(bitmap, file, Bitmap.CompressFormat.JPEG);
    ToastUtils.showLong("已保存至" + "/SuperNote/Image/" + "中");
}
 
Example #14
Source File: NoteModel.java    From SuperNote with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void initNote(int folderId) {

    long years = (long)12 * 30 * 24 * 60 * 60 * 1000;
    long month =(long) 24 * 60 * 60 * 1000 * 30;
    long days = (long)24 * 60 * 60 * 1000;
    long m=(long)60*1000;

    long time = TimeUtils.getNowMills();


    Note note2 = new Note();
    note2.setCreatedTime(time-m-m-m-m);
    note2.setModifiedTime(time-m-m-m-m);
    note2.setNoteFolderId(folderId);
    note2.setNoteContent(Utils.getContext().getResources().getString(R.string.database_content_three));
    note2.setIsPrivacy(0);
    note2.setInRecycleBin(0);
    note2.setNoteId(UUID.randomUUID().toString());
    note2.save();

    Note note3 = new Note();
    note3.setCreatedTime(time-m-m-m);
    note3.setModifiedTime(time-m-m-m);
    note3.setNoteFolderId(folderId);
    note3.setNoteContent(Utils.getContext().getResources().getString(R.string.database_content_four));
    note3.setIsPrivacy(0);
    note3.setInRecycleBin(0);
    note3.setNoteId(UUID.randomUUID().toString());
    note3.save();

    Note note4 = new Note();
    note4.setCreatedTime(time-m-m);
    note4.setModifiedTime(time -m-m);
    note4.setNoteFolderId(folderId);
    note4.setNoteContent(Utils.getContext().getResources().getString(R.string.database_content_five));
    note4.setIsPrivacy(0);
    note4.setInRecycleBin(0);
    note4.setNoteId(UUID.randomUUID().toString());
    note4.save();

    Note note5 = new Note();
    note5.setCreatedTime(time -m);
    note5.setModifiedTime(time -m);
    note5.setNoteContent(Utils.getContext().getResources().getString(R.string.database_content_one));
    note5.setNoteFolderId(folderId);
    note5.setIsPrivacy(0);
    note5.setInRecycleBin(0);
    note5.setNoteId(UUID.randomUUID().toString());
    note5.save();

    Note note1 = new Note();
    note1.setCreatedTime(time );
    note1.setModifiedTime(time );
    note1.setNoteFolderId(folderId);
    note1.setNoteContent(Utils.getContext().getResources().getString(R.string.database_content_two));
    note1.setIsPrivacy(0);
    note1.setInRecycleBin(0);
    note1.setNoteId(UUID.randomUUID().toString());
    note1.save();


}
 
Example #15
Source File: RvNoteListAdapter.java    From SuperNote with GNU General Public License v3.0 3 votes vote down vote up
/**
 * 设置便签显示的时间
 *
 * @param helper
 * @param time   时间戳
 * @param format 时间格式
 * @describe
 */
private void setNoteTimeInfo(BaseViewHolder helper, long time, SimpleDateFormat format) {
    if (isLinearLayoutManager()) {
        helper.setText(R.id.tv_note_list_linear_time, TimeUtils.millis2String(time, format));
    } else {
        helper.setText(R.id.tv_note_list_grid_time, TimeUtils.millis2String(time, format));
    }
}