From 35e59ec0291591bd6d452ad88565316dbf9512fe Mon Sep 17 00:00:00 2001 From: mengjk <851778509@qq.com> Date: Mon, 9 Jan 2017 14:14:40 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=EF=BC=8C=E5=B4=A9=E6=BA=83?= =?UTF-8?q?=E9=97=AE=E9=A2=98=EF=BC=8C=E5=8E=BB=E6=8E=89=E5=AD=98=E5=82=A8?= =?UTF-8?q?=E6=97=A5=E5=BF=97=E6=96=87=E4=BB=B6=EF=BC=8C=E5=B9=B6=E6=94=B9?= =?UTF-8?q?=E5=86=99=E5=AD=98=E5=82=A8=E6=96=87=E4=BB=B6=E7=9A=84=E6=96=B9?= =?UTF-8?q?=E5=BC=8F=EF=BC=8C=E4=BD=BF=E7=94=A8=E6=9C=80=E6=96=B0=E7=9A=84?= =?UTF-8?q?api=E8=8E=B7=E5=8F=96=E6=96=87=E4=BB=B6=E7=9B=AE=E5=BD=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/build.gradle | 2 +- .../activity/GroupMediaListActivity.java | 3 +- .../monitor/activity/MainUserActivity.java | 38 +++++------ .../monitor/activity/MediaListActivity.java | 12 ++-- .../activity/PhotoCaptureActivity.java | 2 +- .../monitor/activity/ProfileActivity.java | 6 +- .../monitor/common/BaseApplication.java | 13 ++++ .../com/egovcomm/monitor/db/DBHelper.java | 2 +- .../fragment/MediaCompletedFragment.java | 6 +- .../fragment/MediaUploadingFragment.java | 2 +- .../egovcomm/monitor/utils/CameraHelper.java | 10 +-- .../com/egovcomm/monitor/utils/FileUtils.java | 63 ++++++++++++++----- .../com/egovcomm/monitor/utils/LogUtils.java | 27 ++++---- .../monitor/utils/MediaDownLoadAsyncTask.java | 4 +- datetimepicker-library/build.gradle | 4 +- 15 files changed, 120 insertions(+), 74 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index 4229144..fc5825d 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -24,7 +24,7 @@ android { minSdkVersion 14 targetSdkVersion 24 versionCode 1 - versionName "0.0.9" + versionName "0.1.1" testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" } buildTypes { diff --git a/app/src/main/java/com/egovcomm/monitor/activity/GroupMediaListActivity.java b/app/src/main/java/com/egovcomm/monitor/activity/GroupMediaListActivity.java index 57d982d..74da68d 100644 --- a/app/src/main/java/com/egovcomm/monitor/activity/GroupMediaListActivity.java +++ b/app/src/main/java/com/egovcomm/monitor/activity/GroupMediaListActivity.java @@ -18,6 +18,7 @@ import com.egovcomm.monitor.R; import com.egovcomm.monitor.adapter.EBBaseAdapter; import com.egovcomm.monitor.adapter.GroupListAdapter; +import com.egovcomm.monitor.common.BaseApplication; import com.egovcomm.monitor.db.DBHelper; import com.egovcomm.monitor.model.ItemEntity; import com.egovcomm.monitor.model.MonitorMedia; @@ -92,7 +93,7 @@ public void dataBack(int id, Object obj) { && group.getData().getData() != null) { List listGroup = group.getData().getData(); for(RspMediaGroup g:listGroup){ - g.setThumbnailPath(FileUtils.getAppStorageThumbnailDirectoryPath()+File.separator+g.getId()+".jpg");//用服务器回来的ID做缩略图 + g.setThumbnailPath(FileUtils.getAppStorageThumbnailDirectoryPath(GroupMediaListActivity.this)+File.separator+g.getId()+".jpg");//用服务器回来的ID做缩略图 } list.addAll(listGroup); diff --git a/app/src/main/java/com/egovcomm/monitor/activity/MainUserActivity.java b/app/src/main/java/com/egovcomm/monitor/activity/MainUserActivity.java index 62ecbb7..d19d2ce 100644 --- a/app/src/main/java/com/egovcomm/monitor/activity/MainUserActivity.java +++ b/app/src/main/java/com/egovcomm/monitor/activity/MainUserActivity.java @@ -62,7 +62,7 @@ protected void onCreate(Bundle savedInstanceState) { } toastTime =System.currentTimeMillis(); requestTime =System.currentTimeMillis(); - LogUtils.writeLogtoFile("mjk:","MainUserActivity--onCreate"); +// LogUtils.writeLogtoFile(MainUserActivity.this,"mjk:","MainUserActivity--onCreate"); startLocation();//开始定位 } @@ -83,7 +83,7 @@ public void onData(View view) { public void onProfile(View view) { // ToastUtils.toast(getApplicationContext(), "个人中心"); - LogUtils.writeLogtoFile("mjk:","MainUserActivity-打开profile页面"); +// LogUtils.writeLogtoFile(MainUserActivity.this,"mjk:","MainUserActivity-打开profile页面"); openActivity(ProfileActivity.class,null,false,true,ProfileActivity.REQUEST_CODE_PROFILE); } @@ -92,20 +92,20 @@ public void onProfile(View view) { @Override protected void onDestroy() { super.onDestroy(); - LogUtils.writeLogtoFile("mjk:","执行MainUser 中的destroy中的exitApp方法"); +// LogUtils.writeLogtoFile(MainUserActivity.this,"mjk:","执行MainUser 中的destroy中的exitApp方法"); exitApp(); - LogUtils.writeLogtoFile("mjk:","MainUserActivity--onDestroy结束"); +// LogUtils.writeLogtoFile(MainUserActivity.this,"mjk:","MainUserActivity--onDestroy结束"); } @Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); - LogUtils.writeLogtoFile("mjk:","MainUserActivity--onActivityResult关闭profile返回"); +// LogUtils.writeLogtoFile(MainUserActivity.this,"mjk:","MainUserActivity--onActivityResult关闭profile返回"); if(requestCode==ProfileActivity.REQUEST_CODE_PROFILE&&resultCode==RESULT_OK){//需要注销登录 openActivity(SigninActivity.class,null,true); //以下为测试代码 // ToastUtils.toast(MainUserActivity.this,"延迟后打开登录页面"); -// LogUtils.writeLogtoFile("mjk:","发送延迟Handler"); +// LogUtils.writeLogtoFile(MainUserActivity.this,"mjk:","发送延迟Handler"); // handler.sendEmptyMessageDelayed(0,2000); } } @@ -114,32 +114,32 @@ protected void onActivityResult(int requestCode, int resultCode, Intent data) { @Override public void handleMessage(Message msg) { super.handleMessage(msg); - LogUtils.writeLogtoFile("mjk:","收到延迟Handler并打开登录销毁MainUser页面"); +// LogUtils.writeLogtoFile(MainUserActivity.this,"mjk:","收到延迟Handler并打开登录销毁MainUser页面"); openActivity(SigninActivity.class,null,true); } }; @Override public boolean onKeyDown(int keyCode, KeyEvent event) { - if(keyCode == KeyEvent.KEYCODE_BACK && event.getAction() == KeyEvent.ACTION_DOWN){ - if((System.currentTimeMillis()-exitTime) > AppConstant.SPACE_TIME){ - Toast.makeText(getApplicationContext(), "再按一次退出程序", Toast.LENGTH_SHORT).show(); - exitTime = System.currentTimeMillis(); + if(keyCode == KeyEvent.KEYCODE_BACK && event.getAction() == KeyEvent.ACTION_DOWN){ + if((System.currentTimeMillis()-exitTime) > AppConstant.SPACE_TIME){ + Toast.makeText(getApplicationContext(), "再按一次退出程序", Toast.LENGTH_SHORT).show(); + exitTime = System.currentTimeMillis(); } else { - LogUtils.writeLogtoFile("mjk:","按两次返回键"); +// LogUtils.writeLogtoFile(MainUserActivity.this,"mjk:","按两次返回键"); finish(); } - return true; + return true; } return super.onKeyDown(keyCode, event); } /**注销退出应用*/ private void exitApp(){ - LogUtils.writeLogtoFile("mjk:","进入exitApp方法"); +// LogUtils.writeLogtoFile(MainUserActivity.this,"mjk:","进入exitApp方法"); BaseApplication.status = BaseApplication.STATUS_OFFLINE; - LogUtils.writeLogtoFile("mjk:","发送最后一次位置"); +// LogUtils.writeLogtoFile(MainUserActivity.this,"mjk:","发送最后一次位置"); uploadLocation();// 结束的时候发送最后一次位置 - LogUtils.writeLogtoFile("jk:","开始执行destroyLocation"); +// LogUtils.writeLogtoFile(MainUserActivity.this,"mjk:","开始执行destroyLocation"); try { new Thread(){ @@ -152,7 +152,7 @@ public void run() { }catch (Exception e){ e.printStackTrace(); } - LogUtils.writeLogtoFile("jk:","执行destroyLocation完成"); +// LogUtils.writeLogtoFile(MainUserActivity.this,"mjk:","执行destroyLocation完成"); } /** @@ -165,7 +165,7 @@ public void run() { private AMapLocationClientOption getDefaultOption() { AMapLocationClientOption mOption = new AMapLocationClientOption(); mOption.setLocationMode(AMapLocationClientOption.AMapLocationMode.Hight_Accuracy);// 可选,设置定位模式,可选的模式有高精度、仅设备、仅网络。默认为高精度模式 - mOption.setGpsFirst(false);// 可选,设置是否gps优先,只在高精度模式下有效。默认关闭 + mOption.setGpsFirst(true);// 可选,设置是否gps优先,只在高精度模式下有效。默认关闭 mOption.setHttpTimeOut(30000);// 可选,设置网络请求超时时间。默认为30秒。在仅设备模式下无效 mOption.setInterval(3000);// 可选,设置定位间隔。默认为3秒 mOption.setNeedAddress(true);// 可选,设置是否返回逆地理地址信息。默认是true @@ -213,7 +213,7 @@ public void onLocationChanged(AMapLocation loc) { * */ private void startLocation() { - LogUtils.writeLogtoFile("mjk:","开始定位"); +// LogUtils.writeLogtoFile(MainUserActivity.this,"mjk:","开始定位"); // 初始化client locationClient = new AMapLocationClient(this.getApplicationContext()); // 设置定位参数 diff --git a/app/src/main/java/com/egovcomm/monitor/activity/MediaListActivity.java b/app/src/main/java/com/egovcomm/monitor/activity/MediaListActivity.java index 7a139af..c037727 100644 --- a/app/src/main/java/com/egovcomm/monitor/activity/MediaListActivity.java +++ b/app/src/main/java/com/egovcomm/monitor/activity/MediaListActivity.java @@ -113,34 +113,34 @@ private void freshData(){ private boolean isNeedDownLoad(MonitorMedia media) { boolean isNeed = false; // 只有是服务器的并且还没有下载的才去请求 - if (media.getDownloadState()!=MonitorMedia.DOWNLOAD_STATE_DOWNLOADING&&!FileUtils.isFileExit(FileUtils.getAppStorageOriginalDirectoryPath() + if (media.getDownloadState()!=MonitorMedia.DOWNLOAD_STATE_DOWNLOADING&&!FileUtils.isFileExit(FileUtils.getAppStorageOriginalDirectoryPath(MediaListActivity.this) + File.separator + media.getFileName())) {// 通过本地服务器路径加上文件名来判断文件是否存在 isNeed = true; } else { isNeed = false; - media.setPath(FileUtils.getAppStorageOriginalDirectoryPath() + media.setPath(FileUtils.getAppStorageOriginalDirectoryPath(MediaListActivity.this) + File.separator + media.getFileName()); media.setDownloadState(MonitorMedia.DOWNLOAD_STATE_DOWNLOADED); if (!FileUtils.isFileExit(FileUtils - .getAppStorageThumbnailDirectoryPath() + .getAppStorageThumbnailDirectoryPath(MediaListActivity.this) + File.separator + media.getFileName())) { // 缩略图不存在,则存储一个缩略图 String thump = FileUtils.saveMediaThumbnail( getApplicationContext(), - FileUtils.getAppStorageOriginalDirectoryPath() + FileUtils.getAppStorageOriginalDirectoryPath(MediaListActivity.this) + File.separator + media.getFileName(), media.getMediaType(), false); media.setThumbnailPath(thump); } else { media.setThumbnailPath(FileUtils - .getAppStorageThumbnailDirectoryPath() + .getAppStorageThumbnailDirectoryPath(MediaListActivity.this) + File.separator + media.getFileName()); } /**在这里添加如果组没有缩略图则创建一个*/ - if(uploadGroup!=null&&!FileUtils.isFileExit(FileUtils.getAppStorageThumbnailDirectoryPath()+File.separator+uploadGroup.getId()+".jpg")) { + if(uploadGroup!=null&&!FileUtils.isFileExit(FileUtils.getAppStorageThumbnailDirectoryPath(MediaListActivity.this)+File.separator+uploadGroup.getId()+".jpg")) { //不存在 FileUtils.saveMediaGroupThumbnail(this,media.getThumbnailPath(),uploadGroup.getId()); } diff --git a/app/src/main/java/com/egovcomm/monitor/activity/PhotoCaptureActivity.java b/app/src/main/java/com/egovcomm/monitor/activity/PhotoCaptureActivity.java index 4b378ec..888e4e2 100644 --- a/app/src/main/java/com/egovcomm/monitor/activity/PhotoCaptureActivity.java +++ b/app/src/main/java/com/egovcomm/monitor/activity/PhotoCaptureActivity.java @@ -102,7 +102,7 @@ public void onShutter() { @Override public void onPictureTaken(byte[] data, Camera camera) { - File file=CameraHelper.saveData(data, CameraHelper.MEDIA_TYPE_IMAGE, CameraHelper.SCREEN_PORTRAIT); + File file=CameraHelper.saveData(PhotoCaptureActivity.this,data, CameraHelper.MEDIA_TYPE_IMAGE, CameraHelper.SCREEN_PORTRAIT); String thumpFilePath=FileUtils.saveMediaThumbnail(getApplicationContext(), file.getAbsolutePath(), MonitorMediaGroup.TYPE_PHOTO+"",true); mCamera.stopPreview(); mCamera.startPreview(); diff --git a/app/src/main/java/com/egovcomm/monitor/activity/ProfileActivity.java b/app/src/main/java/com/egovcomm/monitor/activity/ProfileActivity.java index 946256c..2bd9374 100644 --- a/app/src/main/java/com/egovcomm/monitor/activity/ProfileActivity.java +++ b/app/src/main/java/com/egovcomm/monitor/activity/ProfileActivity.java @@ -57,7 +57,7 @@ protected void onCreate(Bundle savedInstanceState) { mBack.setOnClickListener(this); mRightTv.setOnClickListener(this); mRightIv.setOnClickListener(this); - LogUtils.writeLogtoFile("mjk:","Profile onCreate"); +// LogUtils.writeLogtoFile(ProfileActivity.this,"mjk:","Profile onCreate"); initData(); } @@ -88,7 +88,7 @@ public void onCheckUpdate(View view){ public void onExit(View view){ SPUtils.cleanLocalData(this); - LogUtils.writeLogtoFile("mjk:","Profile 点击了注销登录按钮"); +// LogUtils.writeLogtoFile(ProfileActivity.this,"mjk:","Profile 点击了注销登录按钮"); setResult(RESULT_OK); finish(); } @@ -96,7 +96,7 @@ public void onExit(View view){ @Override protected void onDestroy() { super.onDestroy(); - LogUtils.writeLogtoFile("mjk:","Profile onDestroy"); +// LogUtils.writeLogtoFile(ProfileActivity.this,"mjk:","Profile onDestroy"); } @Override diff --git a/app/src/main/java/com/egovcomm/monitor/common/BaseApplication.java b/app/src/main/java/com/egovcomm/monitor/common/BaseApplication.java index 50cc547..fcbe14e 100644 --- a/app/src/main/java/com/egovcomm/monitor/common/BaseApplication.java +++ b/app/src/main/java/com/egovcomm/monitor/common/BaseApplication.java @@ -2,10 +2,13 @@ import com.egovcomm.monitor.ftp.FTPConnection; import com.egovcomm.monitor.model.AppRequest; +import com.egovcomm.monitor.utils.FileUtils; import com.egovcomm.monitor.utils.LogUtils; import com.egovcomm.monitor.utils.SPUtils; +import com.egovcomm.monitor.utils.ToastUtils; import android.app.Application; +import android.text.TextUtils; /** * Application基类 @@ -28,6 +31,7 @@ public void onCreate() { initData(); } + private void initData(){ isUpdating=false; LogUtils.i("BaseApplication", "初始化数据!!!!!"); @@ -43,6 +47,15 @@ private void initData(){ FTPConnection.port=ftpPort; FTPConnection.userName=ftpUserName; FTPConnection.password=ftpPassword; + + //创建默认文件夹 + String originalPath=FileUtils.getAppStorageOriginalDirectoryPath(this); + String thumbnailPath=FileUtils.getAppStorageThumbnailDirectoryPath(this); + LogUtils.i("application","初始化application-源目录:"+originalPath); + LogUtils.i("application","初始化application-缩略图目录:"+thumbnailPath); + if(TextUtils.isEmpty(originalPath)||TextUtils.isEmpty(thumbnailPath)){ + ToastUtils.toast(this,"存储不可用,请检查设备状态!"); + } } } diff --git a/app/src/main/java/com/egovcomm/monitor/db/DBHelper.java b/app/src/main/java/com/egovcomm/monitor/db/DBHelper.java index cf4f23c..38795fc 100644 --- a/app/src/main/java/com/egovcomm/monitor/db/DBHelper.java +++ b/app/src/main/java/com/egovcomm/monitor/db/DBHelper.java @@ -28,7 +28,7 @@ public class DBHelper extends SQLiteOpenHelper { private final static String TAG = DBHelper.class.getSimpleName(); private static DBHelper _instance; private static final String DB_NAME = "monitor.db"; - private static final int DB_VERSION = 2; + private static final int DB_VERSION = 3; private static Context mContext; private static Gson gson = new Gson(); diff --git a/app/src/main/java/com/egovcomm/monitor/fragment/MediaCompletedFragment.java b/app/src/main/java/com/egovcomm/monitor/fragment/MediaCompletedFragment.java index 3cb3483..91877b3 100644 --- a/app/src/main/java/com/egovcomm/monitor/fragment/MediaCompletedFragment.java +++ b/app/src/main/java/com/egovcomm/monitor/fragment/MediaCompletedFragment.java @@ -79,7 +79,7 @@ public void dataBack(int id, Object obj) { MonitorMediaGroupUpload group = it.next(); group.setShowCheck(0); group.setCheck(0); - group.setThumbnailPath(FileUtils.getAppStorageThumbnailDirectoryPath()+File.separator+group.getId()+".jpg");//用组ID做缩略图 + group.setThumbnailPath(FileUtils.getAppStorageThumbnailDirectoryPath(getActivity())+File.separator+group.getId()+".jpg");//用组ID做缩略图 if (!TextUtils.isEmpty(mediaType)&&!TextUtils.equals(mediaType, group.getMediaGroup() .getMediaType())) { it.remove(); @@ -96,7 +96,7 @@ public void dataBack(int id, Object obj) { for(RspMediaGroup g:listGroup){ MonitorMediaGroupUpload mg=new MonitorMediaGroupUpload(); mg.setId(g.getId()); - mg.setThumbnailPath(FileUtils.getAppStorageThumbnailDirectoryPath()+File.separator+g.getId()+".jpg");//用服务器回来的ID做缩略图 + mg.setThumbnailPath(FileUtils.getAppStorageThumbnailDirectoryPath(getActivity())+File.separator+g.getId()+".jpg");//用服务器回来的ID做缩略图 mg.setMediaGroup(g); mg.setUploadState(MonitorMediaGroupUpload.UPLOAD_STATE_SERVER_DATA); mg.setShowCheck(0); @@ -110,7 +110,7 @@ public void dataBack(int id, Object obj) { mediaList.add(media); if(getActivity()!=null&&!FileUtils.isFileExit(mg.getThumbnailPath())){//组缩略图不存在,寻找子有没有 media.setThumbnailPath(FileUtils - .getAppStorageThumbnailDirectoryPath() + .getAppStorageThumbnailDirectoryPath(getActivity()) + File.separator + media.getFileName()); if (FileUtils.isFileExit(media.getThumbnailPath())) {//子缩略图存在 FileUtils.saveMediaGroupThumbnail(getActivity(),media.getThumbnailPath(),g.getId()); diff --git a/app/src/main/java/com/egovcomm/monitor/fragment/MediaUploadingFragment.java b/app/src/main/java/com/egovcomm/monitor/fragment/MediaUploadingFragment.java index b004de0..89ac9af 100644 --- a/app/src/main/java/com/egovcomm/monitor/fragment/MediaUploadingFragment.java +++ b/app/src/main/java/com/egovcomm/monitor/fragment/MediaUploadingFragment.java @@ -70,7 +70,7 @@ public void listViewRefresh() { Iterator it = list.iterator(); while (it.hasNext()) { MonitorMediaGroupUpload group = it.next(); - group.setThumbnailPath(FileUtils.getAppStorageThumbnailDirectoryPath()+File.separator+group.getId()+".jpg");//用组ID做缩略图 + group.setThumbnailPath(FileUtils.getAppStorageThumbnailDirectoryPath(getActivity())+File.separator+group.getId()+".jpg");//用组ID做缩略图 if (!TextUtils.isEmpty(mediaType)&&!TextUtils.equals(mediaType, group.getMediaGroup().getMediaType())) { it.remove(); diff --git a/app/src/main/java/com/egovcomm/monitor/utils/CameraHelper.java b/app/src/main/java/com/egovcomm/monitor/utils/CameraHelper.java index d011933..831e2d9 100644 --- a/app/src/main/java/com/egovcomm/monitor/utils/CameraHelper.java +++ b/app/src/main/java/com/egovcomm/monitor/utils/CameraHelper.java @@ -455,7 +455,7 @@ protected MediaRecorder doInBackground(Void... params) { // Step 4: Set output file - path=getOutputMediaFile( + path=getOutputMediaFile(context, CameraHelper.MEDIA_TYPE_VIDEO).toString(); mMediaRecorder.setOutputFile(path); // END_INCLUDE (configure_media_recorder) @@ -560,8 +560,8 @@ private static Camera getDefaultCamera(int position) { * Media type. Can be video or image. * @return A file object pointing to the newly created file. */ - public static File getOutputMediaFile(int type) { - File mediaStorageDir=new File(FileUtils.getAppStorageOriginalDirectoryPath()); + public static File getOutputMediaFile(Context context,int type) { + File mediaStorageDir=new File(FileUtils.getAppStorageOriginalDirectoryPath(context)); // Create a media file name //String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date()); String timeStamp =UUID.randomUUID().toString(); @@ -577,10 +577,10 @@ public static File getOutputMediaFile(int type) { return mediaFile; } - public static File saveData(byte[] data,int mediaType,int screenOrientation){ + public static File saveData(Context context,byte[] data,int mediaType,int screenOrientation){ String path=""; File saveFile=null; - saveFile=getOutputMediaFile(mediaType); + saveFile=getOutputMediaFile(context,mediaType); path=saveFile.getAbsolutePath(); if(mediaType==MEDIA_TYPE_IMAGE){ Bitmap b = null; diff --git a/app/src/main/java/com/egovcomm/monitor/utils/FileUtils.java b/app/src/main/java/com/egovcomm/monitor/utils/FileUtils.java index 2009d2d..2d23134 100644 --- a/app/src/main/java/com/egovcomm/monitor/utils/FileUtils.java +++ b/app/src/main/java/com/egovcomm/monitor/utils/FileUtils.java @@ -184,12 +184,12 @@ public static String saveMediaThumbnail(Context context,String path,String media File f=new File(path); if(isLocalFile){ - File fdir=new File(getAppStorageThumbnailDirectoryPath()); + File fdir=new File(getAppStorageThumbnailDirectoryPath(context)); if(fdir!=null){ thumpPath=fdir.getAbsolutePath()+File.separator+getFileNameNoEx(f.getName())+".jpg"; } }else{ - File fdir=new File(getAppStorageThumbnailDirectoryPath()); + File fdir=new File(getAppStorageThumbnailDirectoryPath(context)); if(fdir!=null){ thumpPath=fdir.getAbsolutePath()+File.separator+getFileNameNoEx(f.getName())+".jpg"; } @@ -223,7 +223,7 @@ public static String saveMediaGroupThumbnail(Context context,String mediaThmbnai //写入 try { File mediaFile=new File(mediaThmbnailPath); - File fdir=new File(getAppStorageThumbnailDirectoryPath()); + File fdir=new File(getAppStorageThumbnailDirectoryPath(context)); File groupFile=new File(fdir.getAbsolutePath()+File.separator+groupId+".jpg"); if(!groupFile.exists()){ groupFile.createNewFile(); @@ -357,25 +357,53 @@ public static boolean isFileExit(String path){ return isExit; } + + /* Checks if external storage is available for read and write */ + public static boolean isExternalStorageWritable() { + String state = Environment.getExternalStorageState(); + if (Environment.MEDIA_MOUNTED.equals(state)) { + return true; + } + return false; + } /**统一获取要保存的文件路径 * * @param childPath 统一存储路径下的子路径,像 /local/test 则会在统一路径下新建一个/local/test的文件夹,并返回此目录的路径,如果为空则返回统一路径 * */ - public static File getAppStorageDirectory(String childPath) { + public static File getAppStorageDirectory(Context context,String childPath) { File f=null; String storePath=""; - if (!Environment.getExternalStorageState().equalsIgnoreCase(Environment.MEDIA_MOUNTED)) { - storePath=Environment.getDataDirectory().getAbsolutePath(); - }else{ - storePath=Environment.getExternalStorageDirectory().getAbsolutePath(); - } + long _10MB=10*1024*1024L;//10MB + try { + if (!isExternalStorageWritable()) {//外部存储不可用,则获取内部的存储 + if(context!=null){ + long size=context.getFilesDir().getFreeSpace();//单位是Byte + LogUtils.i("FileUtils","剩余存储大小:"+size);//单位是Byte + if(size<_10MB){//小于10MB则提示存储空间不足 + ToastUtils.toast(context,"存储空间不足!请适当清理文件"); + } + storePath=context.getFilesDir().getAbsolutePath(); + } + }else{//外部存储可用 + if(context!=null){//获取一个应用卸载时会自动删除的目录 + long size=context.getFilesDir().getFreeSpace(); + LogUtils.i("FileUtils","剩余存储大小:"+size);//单位是Byte + if(size<_10MB){//小于10MB则提示存储空间不足 + ToastUtils.toast(context,"存储空间不足!请适当清理文件"); + } + storePath=context.getExternalFilesDir(null).getAbsolutePath(); + }else{ + storePath=Environment.getExternalStorageDirectory().getAbsolutePath(); + } + } + LogUtils.i("FileUtils","本应用存储文件的目录是:"+storePath); if(!TextUtils.isEmpty(childPath)){ - if(childPath.startsWith("/")){ - f = new File(storePath+File.separator+AppConstant.FILE_DIR+childPath); + if(childPath.startsWith(File.separator)){ + f = new File(storePath+childPath); }else{ - f = new File(storePath+File.separator+AppConstant.FILE_DIR+File.separator+childPath); + f = new File(storePath+File.separator+childPath); } } @@ -386,11 +414,14 @@ public static File getAppStorageDirectory(String childPath) { return null; } } + }catch (Exception e){ + e.printStackTrace(); + } return f; } /**获取存储文件的路径*/ - public static String getAppStorageOriginalDirectoryPath() { - File f=getAppStorageDirectory(AppConstant.FILE_DIR_ORIGINAL); + public static String getAppStorageOriginalDirectoryPath(Context context) { + File f=getAppStorageDirectory(context,AppConstant.FILE_DIR_ORIGINAL); if(f!=null){ return f.getAbsolutePath(); }else{ @@ -399,8 +430,8 @@ public static String getAppStorageOriginalDirectoryPath() { } /**获取存储文件缩略图的路径*/ - public static String getAppStorageThumbnailDirectoryPath() { - File f=getAppStorageDirectory(AppConstant.FILE_DIR_THUMBNAIL); + public static String getAppStorageThumbnailDirectoryPath(Context context) { + File f=getAppStorageDirectory(context,AppConstant.FILE_DIR_THUMBNAIL); if(f!=null){ return f.getAbsolutePath(); }else{ diff --git a/app/src/main/java/com/egovcomm/monitor/utils/LogUtils.java b/app/src/main/java/com/egovcomm/monitor/utils/LogUtils.java index 133a073..d9131ce 100644 --- a/app/src/main/java/com/egovcomm/monitor/utils/LogUtils.java +++ b/app/src/main/java/com/egovcomm/monitor/utils/LogUtils.java @@ -11,6 +11,7 @@ import java.util.Calendar; import java.util.Date; +import android.content.Context; import android.os.Environment; import android.text.TextUtils; import android.util.Log; @@ -96,21 +97,21 @@ public static void setOpenLog(boolean isOpenLog) { * * @return * **/ - public static void writeLogtoFile(String tag, String text) {// 新建或打开日志文件 + public static void writeLogtoFile(Context context,String tag, String text) {// 新建或打开日志文件 if(isOpenLog){ - Date nowtime = new Date(); - String needWriteFiel = logfile.format(nowtime); - String needWriteMessage = myLogSdf.format(nowtime) + " " + tag + "\n" + text; - File dir=FileUtils.getAppStorageDirectory(File.separator+AppConstant.FILE_DIR_LOG+File.separator); - File file = new File(dir.getAbsolutePath(), needWriteFiel+ MYLOGFILEName); - if(!file.exists()){ - try { - file.createNewFile(); - } catch (IOException e) { - LogUtils.e("LogUtils", "新建文件出错"); - } - } try { + Date nowtime = new Date(); + String needWriteFiel = logfile.format(nowtime); + String needWriteMessage = myLogSdf.format(nowtime) + " " + tag + "\n" + text; + File dir=FileUtils.getAppStorageDirectory(context,File.separator+AppConstant.FILE_DIR_LOG+File.separator); + File file = new File(dir.getAbsolutePath(), needWriteFiel+ MYLOGFILEName); + if(!file.exists()){ + try { + file.createNewFile(); + } catch (IOException e) { + LogUtils.e("LogUtils", "新建文件出错"); + } + } FileWriter filerWriter = new FileWriter(file, true);//后面这个参数代表是不是要接上文件中原来的数据,不进行覆盖 BufferedWriter bufWriter = new BufferedWriter(filerWriter); bufWriter.write(needWriteMessage); diff --git a/app/src/main/java/com/egovcomm/monitor/utils/MediaDownLoadAsyncTask.java b/app/src/main/java/com/egovcomm/monitor/utils/MediaDownLoadAsyncTask.java index ce8435e..bf7f615 100644 --- a/app/src/main/java/com/egovcomm/monitor/utils/MediaDownLoadAsyncTask.java +++ b/app/src/main/java/com/egovcomm/monitor/utils/MediaDownLoadAsyncTask.java @@ -57,7 +57,7 @@ protected MonitorMedia doInBackground(String... arg0) { int downloadCount = length / buf.length; int spacing = downloadCount / 100; int m = 0; - mediaFile=new File(FileUtils.getAppStorageOriginalDirectoryPath()+File.separator+media.getFileName()); + mediaFile=new File(FileUtils.getAppStorageOriginalDirectoryPath(context)+File.separator+media.getFileName()); mediaFile.createNewFile(); FileOutputStream fos = new FileOutputStream(mediaFile); int len = 0; @@ -76,7 +76,7 @@ protected MonitorMedia doInBackground(String... arg0) { media.setPath(mediaFile.getPath()); media.setThumbnailPath(FileUtils.saveMediaThumbnail(context, mediaFile.getPath(), media.getMediaType(), false)); - if(!FileUtils.isFileExit(FileUtils.getAppStorageThumbnailDirectoryPath()+File.separator+media.getGroupUploadId()+".jpg")){ + if(!FileUtils.isFileExit(FileUtils.getAppStorageThumbnailDirectoryPath(context)+File.separator+media.getGroupUploadId()+".jpg")){ FileUtils.saveMediaGroupThumbnail(context, media.getThumbnailPath(), media.getGroupUploadId()); } } diff --git a/datetimepicker-library/build.gradle b/datetimepicker-library/build.gradle index 061bf1c..a40ece5 100644 --- a/datetimepicker-library/build.gradle +++ b/datetimepicker-library/build.gradle @@ -14,10 +14,10 @@ android { buildToolsVersion "19.1.0" defaultConfig { - minSdkVersion 7 + minSdkVersion 14 targetSdkVersion 19 versionCode 1 - versionName "0.0.9" + versionName "0.1.1" } sourceSets {