diff --git a/model_zoo/official/lite/MindSpore_inhand/app/src/main/java/com/mindspore/himindspore/crash/CrashManager.java b/model_zoo/official/lite/MindSpore_inhand/app/src/main/java/com/mindspore/himindspore/crash/CrashManager.java index 7844bd084c09f2af95c8f1dd613af2e28231fe50..56203f890440a9e83b1a9f2c60864a4d7ca1774f 100644 --- a/model_zoo/official/lite/MindSpore_inhand/app/src/main/java/com/mindspore/himindspore/crash/CrashManager.java +++ b/model_zoo/official/lite/MindSpore_inhand/app/src/main/java/com/mindspore/himindspore/crash/CrashManager.java @@ -36,7 +36,7 @@ import java.util.Date; public class CrashManager implements Thread.UncaughtExceptionHandler { public static final String TAG = "CrashManager"; - public static final String PATH = StorageUtils.CRASH_PATH; + public static String PATH; public static final String FILE_NAME = "crash_"; public static final String FILE_NAME_SUFFIX = ".txt"; private Thread.UncaughtExceptionHandler mDefaultHandler; @@ -53,6 +53,7 @@ public class CrashManager implements Thread.UncaughtExceptionHandler { public void init(Context context) { mContext = context; + PATH = StorageUtils.getCrashPath(context); mDefaultHandler = Thread.getDefaultUncaughtExceptionHandler(); Thread.setDefaultUncaughtExceptionHandler(this); } @@ -85,7 +86,8 @@ public class CrashManager implements Thread.UncaughtExceptionHandler { } long currentData = System.currentTimeMillis(); String time = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date(currentData)); - File file = new File(PATH + FILE_NAME + time.replace(" ", "_") + FILE_NAME_SUFFIX); + File file = new File(PATH + File.separator + FILE_NAME + + time.replace(" ", "_") + FILE_NAME_SUFFIX); Log.e(TAG, "crash file path:" + file.getAbsolutePath()); try { PrintWriter printWriter = new PrintWriter(new BufferedWriter(new FileWriter(file))); diff --git a/model_zoo/official/lite/MindSpore_inhand/app/src/main/java/com/mindspore/himindspore/server/DownloadServer.java b/model_zoo/official/lite/MindSpore_inhand/app/src/main/java/com/mindspore/himindspore/server/DownloadServer.java index 8dda667fd70f89419a9f086f4b2ee9877b09c72c..8fef14ef8ba26d84069beaabe062cfea82164a2c 100644 --- a/model_zoo/official/lite/MindSpore_inhand/app/src/main/java/com/mindspore/himindspore/server/DownloadServer.java +++ b/model_zoo/official/lite/MindSpore_inhand/app/src/main/java/com/mindspore/himindspore/server/DownloadServer.java @@ -2,11 +2,14 @@ package com.mindspore.himindspore.server; import android.content.Context; import android.content.Intent; +import android.util.Log; import androidx.annotation.NonNull; import androidx.core.app.JobIntentService; import com.mindspore.common.config.StorageUtils; +import com.mindspore.common.db.CacheVideo; +import com.mindspore.common.db.DataBaseManager; import com.mindspore.common.net.download.DownloadInfo; import com.mindspore.common.net.download.DownloadManager; import com.mindspore.common.net.download.listener.DownFileCallback; @@ -17,9 +20,11 @@ import com.mindspore.himindspore.comment.Constant; import org.greenrobot.eventbus.EventBus; +import java.io.File; + public class DownloadServer extends JobIntentService { private static final String TAG = DownloadServer.class.getSimpleName(); - + private static Context mContext; /** * 这个Service 唯一的id */ @@ -29,6 +34,7 @@ public class DownloadServer extends JobIntentService { * Convenience method for enqueuing work in to this service. */ public static void enqueueWork(Context context, Intent work) { + mContext = context; enqueueWork(context, DownloadServer.class, JOB_ID, work); } @@ -39,29 +45,41 @@ public class DownloadServer extends JobIntentService { new CourseDetailsBean.PostEntityListBean(); currentVideo.setVideoUrl(intent.getStringExtra("videoUrl")); currentVideo.setTitle(intent.getStringExtra("title")); - DownloadManager.getInstance().downloadPath(StorageUtils.VIDEO_DOWNLOAD_PATH, - currentVideo.getTitle()).download(currentVideo.getVideoUrl(), - new DownFileCallback() { + DownloadManager instance = DownloadManager.getInstance(); + String downloadPath = StorageUtils.getDownloadPath(mContext) + File.separator; + instance.downloadPath(downloadPath, currentVideo.getTitle()) + .download(currentVideo.getVideoUrl(), new DownFileCallback() { - @Override - public void onSuccess(DownloadInfo info) { - MyToast.MakeText(getResources().getString(R.string.cache_data_download_complete), 1000); - EventBus.getDefault().post(new DownloadVideoResultEvent(currentVideo.getTitle(), - Constant.CACHE_STATE_DOWNLOAD_SUCCESS)); - } + @Override + public void onSuccess(DownloadInfo info) { + MyToast.MakeText(getResources() + .getString(R.string.cache_data_download_complete), 1000); + DownloadVideoResultEvent event = + new DownloadVideoResultEvent(currentVideo.getTitle(), + Constant.CACHE_STATE_DOWNLOAD_SUCCESS); + CacheVideo cacheVideo = new CacheVideo( + intent.getIntExtra("id", -1) + , intent.getStringExtra("thumbnailUrl") + , downloadPath + currentVideo.getTitle() + , intent.getStringExtra("title") + , intent.getStringExtra("duration") + ); + DataBaseManager.addCacheVideo(mContext, cacheVideo); + EventBus.getDefault().post(event); + } - @Override - public void onFail(String msg) { - MyToast.MakeText(getResources().getString(R.string.cache_data_download_fail), 1000); - EventBus.getDefault().post(new DownloadVideoResultEvent(currentVideo.getTitle(), - Constant.CACHE_STATE_DOWNLOAD_FAIL)); - } + @Override + public void onFail(String msg) { + MyToast.MakeText(getResources().getString(R.string.cache_data_download_fail), 1000); + EventBus.getDefault().post(new DownloadVideoResultEvent(currentVideo.getTitle(), + Constant.CACHE_STATE_DOWNLOAD_FAIL)); + } - @Override - public void onProgress(long totalSize, long downSize) { + @Override + public void onProgress(long totalSize, long downSize) { - } - }); + } + }); } } \ No newline at end of file diff --git a/model_zoo/official/lite/MindSpore_inhand/app/src/main/java/com/mindspore/himindspore/ui/lessons/LessonIntroductionFragment.java b/model_zoo/official/lite/MindSpore_inhand/app/src/main/java/com/mindspore/himindspore/ui/lessons/LessonIntroductionFragment.java index 668e1cb753be62f54d8704c1d2949ab4fecadad7..3a049bd219e5bce4155a1a3e138b814548bbf71a 100644 --- a/model_zoo/official/lite/MindSpore_inhand/app/src/main/java/com/mindspore/himindspore/ui/lessons/LessonIntroductionFragment.java +++ b/model_zoo/official/lite/MindSpore_inhand/app/src/main/java/com/mindspore/himindspore/ui/lessons/LessonIntroductionFragment.java @@ -106,8 +106,8 @@ public class LessonIntroductionFragment extends BaseFragment refreshVideo()); } - @Subscribe(threadMode = ThreadMode.MAIN) - public void onEventMainThread(DownloadVideoResultEvent event) { - int result = event.getResult(); - String title = event.getTitle(); - runOnUiThread(() -> { - if (title.equals(getVideoFileName(currentVideo))) { - if (result == Constant.CACHE_STATE_DOWNLOAD_SUCCESS) { - - } else if (result == Constant.CACHE_STATE_DOWNLOAD_FAIL) { - File f = new File(StorageUtils.VIDEO_DOWNLOAD_PATH - + getVideoFileName(currentVideo)); - if (f.exists()) { - f.delete(); - } - } - updateCacheView(); - } - }); - } - public void init() { // 在 OnCreate 中调用 id = getIntent().getIntExtra(ITEM_ID, 0); videoPlayer = findViewById(R.id.player); @@ -157,15 +127,7 @@ private final static int[] tabs = {R.string.lessons_introduction, }); LinearLayout mBulletChat = findViewById(R.id.bullet_chat_layout); - LinearLayout mStoreLayout = findViewById(R.id.store_layout); - LinearLayout mForwardLayout = findViewById(R.id.forward_layout); - LinearLayout mCacheLayout = findViewById(R.id.cache_layout); - mCacheText = findViewById(R.id.cache_title); - mBulletChat.setOnClickListener(LessonsActivity.this); - mStoreLayout.setOnClickListener(LessonsActivity.this); - mForwardLayout.setOnClickListener(LessonsActivity.this); - mCacheLayout.setOnClickListener(LessonsActivity.this); presenter = new CourseDetailsPresenter(this); requestNetworkData(); @@ -316,30 +278,6 @@ private final static int[] tabs = {R.string.lessons_introduction, videoBean = new VideoBean(imageView, currentVideo.getVideoUrl(), currentVideo.getTitle()); initPlayer(); playVideo(); - updateCacheView(); - } - - private void updateCacheView() { - if (checkVideoCacheExist()) { // 已经缓存过了 - mCacheText.setText(getResources().getText(R.string.lesson_cache_downloaded)); - cacheState = Constant.CACHE_STATE_DOWNLOADED; - } else { // 未缓存 - mCacheText.setText(getResources().getText(R.string.lesson_cache)); - cacheState = Constant.CACHE_STATE_NO_DOWNLOAD; - } - } - - private boolean checkVideoCacheExist() { - File f = new File(StorageUtils.VIDEO_DOWNLOAD_PATH + getVideoFileName(currentVideo)); - return f.exists(); - } - - private String getVideoFileName(CourseDetailsBean.PostEntityListBean video) { - if (video != null) { - return video.getTitle() + "." + Tools.getExtensionName(video.getVideoUrl()); - } else { - return ""; - } } private void initTabLayout() { @@ -452,56 +390,15 @@ private final static int[] tabs = {R.string.lessons_introduction, } } - @Override + @Override public void onClick(View view) { switch (view.getId()) { case R.id.bullet_chat_layout: - case R.id.store_layout: - MyToast.FunctionNoOpen(); - break; - case R.id.forward_layout: - if (data == null) { - MyToast.MakeText(getResources().getString(R.string.on_share_data), 1000); - } else { - Tools.onClickShare(this, - new ShareBean.Builder() - .title(data.getTitle()) - .url(data.getContent()) - .build()); - } - break; - case R.id.cache_layout: - downloadVideo(); - break; default: throw new IllegalStateException("Unexpected value: " + view.getId()); } } - private void downloadVideo() { - if (cacheState == Constant.CACHE_STATE_DOWNLOADING) { - MyToast.MakeText(getResources().getString(R.string.cache_data_downloading), 1000); - } else if (cacheState == Constant.CACHE_STATE_DOWNLOADED) { - MyToast.MakeText(getResources().getString(R.string.lesson_cache_downloaded), 1000); - } else if (cacheState == Constant.CACHE_STATE_NO_DOWNLOAD) { - if (currentVideo != null) { - // 实现下载此url的视频, - String url = currentVideo.getVideoUrl(); - Intent intent = new Intent(); - intent.putExtra("title", getVideoFileName(currentVideo)); - intent.putExtra("videoUrl", currentVideo.getVideoUrl()); - DownloadServer.enqueueWork(this, intent); - - cacheState = Constant.CACHE_STATE_DOWNLOADING; - mCacheText.setText(getResources().getText(R.string.lesson_cache_downloading)); - } else { - MyToast.MakeText(getResources().getString(R.string.no_cache_data), 1000); - } - } else { - // cacheState error, do nothing. - } - } - @Override public void refreshResponseData(CourseDetailsBean responseBean) { data = responseBean; diff --git a/model_zoo/official/lite/MindSpore_inhand/app/src/main/java/com/mindspore/himindspore/ui/lessons/adapter/LessonsIntroduceAdapter.java b/model_zoo/official/lite/MindSpore_inhand/app/src/main/java/com/mindspore/himindspore/ui/lessons/adapter/LessonsIntroduceAdapter.java index 8a9935b438e54df429e17e121f2c5d7929567958..592d75f39d0ce08fd00c932e5941bb8f751e5688 100644 --- a/model_zoo/official/lite/MindSpore_inhand/app/src/main/java/com/mindspore/himindspore/ui/lessons/adapter/LessonsIntroduceAdapter.java +++ b/model_zoo/official/lite/MindSpore_inhand/app/src/main/java/com/mindspore/himindspore/ui/lessons/adapter/LessonsIntroduceAdapter.java @@ -18,6 +18,9 @@ import com.bumptech.glide.load.resource.bitmap.RoundedCorners; import com.bumptech.glide.request.RequestOptions; import com.mindspore.common.config.MSLinkUtils; import com.mindspore.common.config.StorageUtils; +import com.mindspore.common.db.CacheVideo; +import com.mindspore.common.db.CacheVideoDao; +import com.mindspore.common.db.DataBaseManager; import com.mindspore.common.netbean.response.CourseDetailsBean; import com.mindspore.customview.ui.MyToast; import com.mindspore.customview.ui.TopImageBottomTextView; @@ -35,7 +38,7 @@ public class LessonsIntroduceAdapter extends DelegateAdapter.Adapter mList = new ArrayList(); + private ArrayList mList = new ArrayList(); protected void init() { appTitle = findViewById(R.id.refreshLayoutTitle); @@ -50,41 +51,26 @@ public class CacheActivity extends BaseActivity { multipleStatusView = findViewById(R.id.multipleStatusView); mRecyclerView = findViewById(R.id.recyclerView); mFrameLayout = findViewById(R.id.fragmentRefreshLayout); - initListData(); + initListByDataBase(); CacheAdapter adapter = new CacheAdapter(CacheActivity.this, mList); - LinearLayoutManager manager = new LinearLayoutManager(CacheActivity.this, LinearLayoutManager.VERTICAL, false); + LinearLayoutManager manager = new LinearLayoutManager(CacheActivity.this, + LinearLayoutManager.VERTICAL, false); mRecyclerView.setLayoutManager(manager); mRecyclerView.setAdapter(adapter); } - private void initListData() { - File path = new File(StorageUtils.VIDEO_DOWNLOAD_PATH); - File[] files = path.listFiles();// 读取文件夹下文件 - if (files == null || files.length == 0) { + private void initListByDataBase() { + List list = DataBaseManager.getAllCacheVideo(this); + if (list == null || list.isEmpty()) { MyToast.MakeText(getResources().getString(R.string.cache_data_list_null), 2000); return; } - for (File file : files) { - String name = file.getName(); - int i = name.lastIndexOf('.'); - if (i != -1) { - name = name.substring(i); - if (name.equalsIgnoreCase(".mp4") || name.equalsIgnoreCase(".3gp") - || name.equalsIgnoreCase(".wmv") - || name.equalsIgnoreCase(".ts") || name.equalsIgnoreCase(".rmvb") - || name.equalsIgnoreCase(".mov") || name.equalsIgnoreCase(".m4v") - || name.equalsIgnoreCase(".avi") || name.equalsIgnoreCase(".m3u8") - || name.equalsIgnoreCase(".3gpp") || name.equalsIgnoreCase(".3gpp2") - || name.equalsIgnoreCase(".mkv") || name.equalsIgnoreCase(".flv") - || name.equalsIgnoreCase(".divx") || name.equalsIgnoreCase(".f4v") - || name.equalsIgnoreCase(".rm") || name.equalsIgnoreCase(".asf") - || name.equalsIgnoreCase(".ram") || name.equalsIgnoreCase(".mpg") - || name.equalsIgnoreCase(".v8") || name.equalsIgnoreCase(".swf") - || name.equalsIgnoreCase(".m2v") || name.equalsIgnoreCase(".asx") - || name.equalsIgnoreCase(".ra") || name.equalsIgnoreCase(".ndivx") - || name.equalsIgnoreCase(".xvid")) { - mList.add(file); - } + for (CacheVideo cacheVideo : list) { + File videoFile = new File(cacheVideo.getVideoUri()); + if (videoFile.exists()) { + mList.add(cacheVideo); + } else { + DataBaseManager.delCacheVideo(this, cacheVideo.getVideoId()); } } } diff --git a/model_zoo/official/lite/MindSpore_inhand/app/src/main/java/com/mindspore/himindspore/ui/me/adapter/CacheAdapter.java b/model_zoo/official/lite/MindSpore_inhand/app/src/main/java/com/mindspore/himindspore/ui/me/adapter/CacheAdapter.java index 58f9af06f40632a271c332fbd88d8a9956676dda..63828c53d2f86f90ccef21c1c30df63a6fc170aa 100644 --- a/model_zoo/official/lite/MindSpore_inhand/app/src/main/java/com/mindspore/himindspore/ui/me/adapter/CacheAdapter.java +++ b/model_zoo/official/lite/MindSpore_inhand/app/src/main/java/com/mindspore/himindspore/ui/me/adapter/CacheAdapter.java @@ -32,6 +32,7 @@ import androidx.recyclerview.widget.RecyclerView; import com.bumptech.glide.Glide; import com.bumptech.glide.load.resource.bitmap.RoundedCorners; import com.bumptech.glide.request.RequestOptions; +import com.mindspore.common.db.CacheVideo; import com.mindspore.himindspore.R; import com.mindspore.himindspore.ui.me.PlayVideoActivity; @@ -43,9 +44,9 @@ public class CacheAdapter extends RecyclerView.Adapter private static final String TAG = CacheAdapter.class.getSimpleName(); private Context mContext; - private ArrayList mList; + private ArrayList mList; - public CacheAdapter(Context mContext, ArrayList mList) { + public CacheAdapter(Context mContext, ArrayList mList) { this.mContext = mContext; this.mList = mList; } @@ -58,12 +59,12 @@ public class CacheAdapter extends RecyclerView.Adapter @Override public void onBindViewHolder(@NonNull CacheAdapter.ViewHolder holder, int position) { - String path = mList.get(position).getAbsolutePath(); + String path = mList.get(position).getVideoUri(); Log.d(TAG, "onBindViewHolder path:" + path); // Bitmap bitmap = ThumbnailUtils.createVideoThumbnail(path, MediaStore.Images.Thumbnails.MICRO_KIND); // holder.thumbnailIv.setImageBitmap(bitmap); Glide.with(mContext) - .load((Uri) null) + .load( mList.get(position).getThumbnail()) .apply(RequestOptions.bitmapTransform(new RoundedCorners( (int) mContext.getResources().getDimension(R.dimen.listItemImageConner)))) .error(R.drawable.icon_default) @@ -71,12 +72,12 @@ public class CacheAdapter extends RecyclerView.Adapter .into(holder.thumbnailIv); // holder.durationTv.setText(duration); - String name = mList.get(position).getName(); + String name = mList.get(position).getVideoName(); String title = name.substring(0, name.lastIndexOf('.')); holder.nameTv.setText(title); DecimalFormat decimalFormat = new DecimalFormat("0.00"); - float fileSize = mList.get(position).length() / (1024*1024f); // 转为M为单位 + float fileSize = new File(mList.get(position).getVideoUri()).length() / (1024*1024f); // 转为M为单位 holder.sizeTv.setText(decimalFormat.format(fileSize) + "M"); holder.itemView.setOnClickListener(v -> { Intent intent = new Intent(mContext, PlayVideoActivity.class); @@ -84,6 +85,7 @@ public class CacheAdapter extends RecyclerView.Adapter mContext.startActivity(intent); } ); + holder.durationTv.setText(mList.get(position).getVideoDuration()); } @Override diff --git a/model_zoo/official/lite/MindSpore_inhand/app/src/main/res/layout/adapter_layout_cache.xml b/model_zoo/official/lite/MindSpore_inhand/app/src/main/res/layout/adapter_layout_cache.xml index 74cb816fa921f957515d59c6d2337511c70fcdb5..a477de77ac1e7068f7e36b99c09e742f46aaa0d8 100644 --- a/model_zoo/official/lite/MindSpore_inhand/app/src/main/res/layout/adapter_layout_cache.xml +++ b/model_zoo/official/lite/MindSpore_inhand/app/src/main/res/layout/adapter_layout_cache.xml @@ -58,7 +58,7 @@ tools:text="01:04/49:03" style="@style/TextGraySubTitle" android:textColor="@color/white" - android:visibility="gone" + android:visibility="visible" app:layout_constraintBottom_toBottomOf="@id/cache_image" app:layout_constraintEnd_toEndOf="@id/cache_image" /> diff --git a/model_zoo/official/lite/MindSpore_inhand/common/build.gradle b/model_zoo/official/lite/MindSpore_inhand/common/build.gradle index fc94c9bc9b0e74d3d32dfaf52840c3a9fcd208fd..487389bb8dfa42340953bf2d041ecc3a7f78f47e 100644 --- a/model_zoo/official/lite/MindSpore_inhand/common/build.gradle +++ b/model_zoo/official/lite/MindSpore_inhand/common/build.gradle @@ -51,4 +51,9 @@ dependencies { implementation "com.squareup.okhttp3:logging-interceptor:${config.dependencies.okhttp3}" implementation "org.greenrobot:eventbus:${config.dependencies.eventbus}" + + implementation "android.arch.persistence.room:runtime:${config.dependencies.room}" + annotationProcessor "android.arch.persistence.room:compiler:${config.dependencies.room}" + implementation "android.arch.persistence.room:guava:${config.dependencies.room}" + } \ No newline at end of file diff --git a/model_zoo/official/lite/MindSpore_inhand/common/src/main/java/com/mindspore/common/config/StorageUtils.java b/model_zoo/official/lite/MindSpore_inhand/common/src/main/java/com/mindspore/common/config/StorageUtils.java index d26b95654d865c3a8395ff34539dbf7a103522d1..e623da71c27d4b90572b8f6c38b0df59ea15a341 100644 --- a/model_zoo/official/lite/MindSpore_inhand/common/src/main/java/com/mindspore/common/config/StorageUtils.java +++ b/model_zoo/official/lite/MindSpore_inhand/common/src/main/java/com/mindspore/common/config/StorageUtils.java @@ -1,5 +1,6 @@ package com.mindspore.common.config; +import android.content.Context; import android.os.Environment; import java.io.File; @@ -8,19 +9,40 @@ public class StorageUtils { private static final String APP_NAME = "MindSpore"; - public static final String STORAGE_PHOTO = Environment.getExternalStorageDirectory() - + File.separator + "photo.jpeg"; - - public static final String VIDEO_PATH = Environment.getExternalStorageDirectory().getPath() - + "/" + Environment.DIRECTORY_DOWNLOADS + "/"; - - public static final String CRASH_PATH = Environment.getExternalStorageDirectory().getPath() - + "/MindSpore/CrashLog/"; - - public static final String VIDEO_DOWNLOAD_PATH_NAME = VIDEO_PATH + APP_NAME; - - public static final String VIDEO_DOWNLOAD_PATH = VIDEO_DOWNLOAD_PATH_NAME + "/"; - - public static final File ABSOLUTE_FILE = Environment.getExternalStorageDirectory() - .getAbsoluteFile(); + /** + * 手机存储根目录 + * Android11 以上,不可以直接操作该目录 + * */ + private static final String ROOT = Environment.getExternalStorageDirectory().getPath(); + + public static final String PICTURES_SHARE = ROOT + "/Pictures/MindSpore"; + + public static String getFilePath(Context context) { + String filePath; + if (Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState()) + || !Environment.isExternalStorageRemovable()) { + //外部存储可用 + filePath = context.getExternalFilesDir(null).getPath(); + } else { + //外部存储不可用 + filePath = context.getFilesDir().getPath(); + } + return filePath; + } + + public static String getTempPath(Context context) { + return getFilePath(context) + File.separator + "temp"; + } + + public static String getDancePath(Context context) { + return getFilePath(context) + File.separator + "dance"; + } + + public static String getDownloadPath(Context context) { + return getFilePath(context) + File.separator + Environment.DIRECTORY_DOWNLOADS; + } + + public static String getCrashPath(Context context) { + return getFilePath(context) + File.separator + "CrashLog"; + } } diff --git a/model_zoo/official/lite/MindSpore_inhand/common/src/main/java/com/mindspore/common/db/CacheDataBase.java b/model_zoo/official/lite/MindSpore_inhand/common/src/main/java/com/mindspore/common/db/CacheDataBase.java new file mode 100644 index 0000000000000000000000000000000000000000..dbff62cd3a4c77851949ce1a75dde10172d18d94 --- /dev/null +++ b/model_zoo/official/lite/MindSpore_inhand/common/src/main/java/com/mindspore/common/db/CacheDataBase.java @@ -0,0 +1,11 @@ +package com.mindspore.common.db; + +import androidx.room.Database; +import androidx.room.RoomDatabase; + +@Database(entities = {CacheVideo.class}, version = 2, exportSchema = false) +abstract public class CacheDataBase extends RoomDatabase { + + public abstract CacheVideoDao cacheVideoDao(); + +} \ No newline at end of file diff --git a/model_zoo/official/lite/MindSpore_inhand/common/src/main/java/com/mindspore/common/db/CacheVideo.java b/model_zoo/official/lite/MindSpore_inhand/common/src/main/java/com/mindspore/common/db/CacheVideo.java new file mode 100644 index 0000000000000000000000000000000000000000..ca30c4798318f1a7e0d35bf57940323c363d08c9 --- /dev/null +++ b/model_zoo/official/lite/MindSpore_inhand/common/src/main/java/com/mindspore/common/db/CacheVideo.java @@ -0,0 +1,101 @@ +package com.mindspore.common.db; + +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; +import androidx.room.ColumnInfo; +import androidx.room.Entity; +import androidx.room.PrimaryKey; + +@Entity(tableName = "cache_video") +public class CacheVideo { + + @PrimaryKey + @NonNull + @ColumnInfo(name = "video_id") + private int videoId; + + @Nullable + @ColumnInfo(name = "thumbnail") + private String thumbnail; + + @Nullable + @ColumnInfo(name = "video_uri_in_disk") + private String videoUri; + + @Nullable + @ColumnInfo(name = "video_name") + private String videoName; + + @Nullable + @ColumnInfo(name = "video_duration") + private String videoDuration; + + public CacheVideo() { + } + + /* @Ignore*/ + public CacheVideo(@NonNull int mVideoId, @Nullable String mThumbnail, + @Nullable String mVideoUri, String mVideoName, String mVideoDuration) { + this.videoId = mVideoId; + this.thumbnail = mThumbnail; + this.videoUri = mVideoUri; + this.videoName = mVideoName; + this.videoDuration = mVideoDuration; + } + + @NonNull + public int getVideoId() { + return videoId; + } + + public void setVideoId(@NonNull int videoId) { + this.videoId = videoId; + } + + @Nullable + public String getThumbnail() { + return thumbnail; + } + + public void setThumbnail(@Nullable String thumbnail) { + this.thumbnail = thumbnail; + } + + @Nullable + public String getVideoUri() { + return videoUri; + } + + public void setVideoUri(@Nullable String videoUri) { + this.videoUri = videoUri; + } + + @Nullable + public String getVideoName() { + return videoName; + } + + public void setVideoName(@Nullable String videoName) { + this.videoName = videoName; + } + + @Nullable + public String getVideoDuration() { + return videoDuration; + } + + public void setVideoDuration(@Nullable String videoDuration) { + this.videoDuration = videoDuration; + } + + @Override + public String toString() { + return "CacheVideo{" + + "videoId='" + videoId + '\'' + + ", thumbnail='" + thumbnail + '\'' + + ", videoUri='" + videoUri + '\'' + + ", videoName='" + videoName + '\'' + + ", videoDuration='" + videoDuration + '\'' + + '}'; + } +} \ No newline at end of file diff --git a/model_zoo/official/lite/MindSpore_inhand/common/src/main/java/com/mindspore/common/db/CacheVideoDao.java b/model_zoo/official/lite/MindSpore_inhand/common/src/main/java/com/mindspore/common/db/CacheVideoDao.java new file mode 100644 index 0000000000000000000000000000000000000000..837f099db5d400d07f65cbf7acaa3ebb98685067 --- /dev/null +++ b/model_zoo/official/lite/MindSpore_inhand/common/src/main/java/com/mindspore/common/db/CacheVideoDao.java @@ -0,0 +1,30 @@ +package com.mindspore.common.db; + +import androidx.room.Dao; +import androidx.room.Insert; +import androidx.room.OnConflictStrategy; +import androidx.room.Query; +import androidx.room.Update; + +import java.util.List; + +@Dao +public interface CacheVideoDao { + + @Query("SELECT * FROM cache_video") + List getAllCacheVideo(); + + @Query("SELECT * FROM cache_video WHERE video_id = :videoId") + CacheVideo getCacheVideoById(int videoId); + + @Insert(onConflict = OnConflictStrategy.REPLACE) + void insertCacheVideo(CacheVideo cacheVideo); + + @Update + int updateCacheVideo(CacheVideo CacheVideo); + + + @Query("DELETE FROM cache_video WHERE video_id = :videoId") + int deleteCacheVideoById(int videoId); + +} \ No newline at end of file diff --git a/model_zoo/official/lite/MindSpore_inhand/common/src/main/java/com/mindspore/common/db/DataBaseManager.java b/model_zoo/official/lite/MindSpore_inhand/common/src/main/java/com/mindspore/common/db/DataBaseManager.java new file mode 100644 index 0000000000000000000000000000000000000000..457b088a6bb9834e08b25f9a5a9d298c6abbf087 --- /dev/null +++ b/model_zoo/official/lite/MindSpore_inhand/common/src/main/java/com/mindspore/common/db/DataBaseManager.java @@ -0,0 +1,54 @@ +package com.mindspore.common.db; + +import android.content.Context; + +import androidx.room.Room; +import androidx.room.migration.Migration; +import androidx.sqlite.db.SupportSQLiteDatabase; + +import java.util.List; + +public class DataBaseManager { + + private static CacheDataBase database; + + public synchronized static CacheDataBase getInstance(Context context) { + if (database == null) { + database = Room.databaseBuilder(context, + CacheDataBase.class, "mindspore.db") + .allowMainThreadQueries() + .addMigrations(MIGRATION_1_2) + .build(); + } + return database; + } + + public static synchronized void addCacheVideo(Context context, CacheVideo cacheVideo) { + getInstance(context).cacheVideoDao().insertCacheVideo(cacheVideo); + } + + public static synchronized List getAllCacheVideo(Context context) { + return getInstance(context).cacheVideoDao().getAllCacheVideo(); + } + + public static synchronized CacheVideo getCacheVideoById(Context context, int id) { + return getInstance(context).cacheVideoDao().getCacheVideoById(id); + } + + public static synchronized int delCacheVideo(Context context, int cacheVideoId) { + return getInstance(context).cacheVideoDao().deleteCacheVideoById(cacheVideoId); + } + + static final Migration MIGRATION_1_2 = new Migration(1, 2) { + @Override + public void migrate(SupportSQLiteDatabase database) { + database.execSQL("CREATE TABLE `cache_video` (`video_id` INTEGER, " + + "`thumbnail` TEXT, " + + "`video_uri_in_disk` TEXT, " + + "`video_name` TEXT, " + + "`video_duration` TEXT, " + + "PRIMARY KEY(`video_id`))"); + } + }; + +} \ No newline at end of file diff --git a/model_zoo/official/lite/MindSpore_inhand/common/src/main/java/com/mindspore/common/utils/BitmapUtils.java b/model_zoo/official/lite/MindSpore_inhand/common/src/main/java/com/mindspore/common/utils/BitmapUtils.java index e8f9604c391e13946239ac21de12162c01315c21..1e5e67c763c7d25fcf0fbe320fe8ef1e25b1f1bc 100644 --- a/model_zoo/official/lite/MindSpore_inhand/common/src/main/java/com/mindspore/common/utils/BitmapUtils.java +++ b/model_zoo/official/lite/MindSpore_inhand/common/src/main/java/com/mindspore/common/utils/BitmapUtils.java @@ -300,8 +300,7 @@ public class BitmapUtils { public static void saveToAlbum(final Context context, Bitmap bitmap) { File file = null; String fileName = System.currentTimeMillis() + ".jpg"; - File root = new File(StorageUtils.ABSOLUTE_FILE, context.getPackageName()); - File dir = new File(root, "image"); + File dir = new File(StorageUtils.PICTURES_SHARE); if (dir.mkdirs() || dir.isDirectory()) { file = new File(dir, fileName); } diff --git a/model_zoo/official/lite/MindSpore_inhand/common/src/main/java/com/mindspore/common/utils/ImageUtils.java b/model_zoo/official/lite/MindSpore_inhand/common/src/main/java/com/mindspore/common/utils/ImageUtils.java index 6c45165d97e5467b60593c63b6f9920b05140d24..973c74f30bdcaaaf579df18bc475fd669273df44 100644 --- a/model_zoo/official/lite/MindSpore_inhand/common/src/main/java/com/mindspore/common/utils/ImageUtils.java +++ b/model_zoo/official/lite/MindSpore_inhand/common/src/main/java/com/mindspore/common/utils/ImageUtils.java @@ -97,8 +97,7 @@ public class ImageUtils { Bitmap cache = loadBitmapFromView(view, isNeedCrop); File file = null; String fileName = TextUtils.isEmpty(child) ? System.currentTimeMillis() + ".jpg" : child + ".jpg"; - File root = new File(StorageUtils.ABSOLUTE_FILE, context.getPackageName()); - File dir = new File(root, "image"); + File dir = new File(StorageUtils.PICTURES_SHARE); if (dir.mkdirs() || dir.isDirectory()) { file = new File(dir, fileName); } @@ -226,8 +225,7 @@ public class ImageUtils { public static void saveToAlbum(final Context context, Bitmap bitmap) { File file = null; String fileName = System.currentTimeMillis() + ".jpg"; - File root = new File(StorageUtils.ABSOLUTE_FILE, context.getPackageName()); - File dir = new File(root, "image"); + File dir = new File(StorageUtils.PICTURES_SHARE); if (dir.mkdirs() || dir.isDirectory()) { file = new File(dir, fileName); } diff --git a/model_zoo/official/lite/MindSpore_inhand/config.gradle b/model_zoo/official/lite/MindSpore_inhand/config.gradle index f16f1871132fd089a2df34bc801f7f3a6695a23b..80d772a7ea27088d742efb5f7a761230610904a6 100644 --- a/model_zoo/official/lite/MindSpore_inhand/config.gradle +++ b/model_zoo/official/lite/MindSpore_inhand/config.gradle @@ -56,6 +56,8 @@ ext { vlayout : "1.0.3@aar", richtext : "2.5.1", flow_layout : "0.1.4", - circleimageview : "3.1.0" + circleimageview : "3.1.0", + room : "1.1.1", + face : "2.0.5.300" ] } \ No newline at end of file diff --git a/model_zoo/official/lite/MindSpore_inhand/dance/src/main/java/com/mindspore/dance/util/Tools.java b/model_zoo/official/lite/MindSpore_inhand/dance/src/main/java/com/mindspore/dance/util/Tools.java index 45fc554cb1327f302910ea677bd2fe85528a36a9..36c68077a7fff979aa01f39f77d3b90adad76ebe 100644 --- a/model_zoo/official/lite/MindSpore_inhand/dance/src/main/java/com/mindspore/dance/util/Tools.java +++ b/model_zoo/official/lite/MindSpore_inhand/dance/src/main/java/com/mindspore/dance/util/Tools.java @@ -18,6 +18,7 @@ package com.mindspore.dance.util; import android.Manifest; import android.app.Activity; +import android.content.Context; import android.content.pm.PackageManager; import android.graphics.Rect; import android.util.Log; @@ -163,8 +164,8 @@ public class Tools { parentView.addView(childView); } - public static boolean checkDiskHasVideo() { - File f = new File(StorageUtils.VIDEO_PATH + Constants.VIDEO_NAME); + public static boolean checkDiskHasVideo(Context context) { + File f = new File(StorageUtils.getDancePath(context), Constants.VIDEO_NAME); Variables.hasVideo = f.exists() && f.length() == Constants.VIDEO_LENGTH; return Variables.hasVideo; } diff --git a/model_zoo/official/lite/MindSpore_inhand/dance/src/main/java/com/mindspore/dance/view/fragment/PrepareFragment.java b/model_zoo/official/lite/MindSpore_inhand/dance/src/main/java/com/mindspore/dance/view/fragment/PrepareFragment.java index f36534a7ae568ab055faf5fdc2e803d65099b3ed..3c402723fb622d3faf700e48fcc3659dc9085219 100644 --- a/model_zoo/official/lite/MindSpore_inhand/dance/src/main/java/com/mindspore/dance/view/fragment/PrepareFragment.java +++ b/model_zoo/official/lite/MindSpore_inhand/dance/src/main/java/com/mindspore/dance/view/fragment/PrepareFragment.java @@ -19,7 +19,6 @@ package com.mindspore.dance.view.fragment; import android.Manifest; import android.content.pm.PackageManager; import android.os.Bundle; -import android.util.Log; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; @@ -45,6 +44,8 @@ import com.mindspore.dance.global.Variables; import com.mindspore.dance.present.video.MyVideoView; import com.mindspore.dance.util.Tools; +import java.io.File; + public class PrepareFragment extends BaseFragment { private final String TAG = PrepareFragment.class.getSimpleName(); @@ -59,11 +60,12 @@ public class PrepareFragment extends BaseFragment { Tools.verifyStoragePermissions(getActivity()); Tools.verifyCameraPermissions(getActivity()); - Tools.checkDiskHasVideo(); + Tools.checkDiskHasVideo(getContext()); } @Override - public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { + public View onCreateView(LayoutInflater inflater, ViewGroup container, + Bundle savedInstanceState) { return inflater.inflate(R.layout.fragment_prepare, container, false); } @@ -75,32 +77,40 @@ public class PrepareFragment extends BaseFragment { } public void downFile() { - DownloadManager.getInstance().downloadPath(StorageUtils.VIDEO_PATH, Constants.VIDEO_NAME).download(Constants.VIDEO_URL, new DownFileCallback() { - @Override - public void onSuccess(DownloadInfo info) { - Tools.checkDiskHasVideo(); - if (Variables.hasVideo) { - downloadText.setVisibility(View.GONE); - if (videoView != null && !videoView.isPlaying()) { - start(); + File danceFolder = new File(StorageUtils.getDancePath(getContext())); + if (!danceFolder.exists()) { + danceFolder.mkdirs(); + } + DownloadManager.getInstance() + .downloadPath(StorageUtils.getDancePath(getContext()) + + File.separator, Constants.VIDEO_NAME) + .download(Constants.VIDEO_URL, new DownFileCallback() { + @Override + public void onSuccess(DownloadInfo info) { + Tools.checkDiskHasVideo(getContext()); + if (Variables.hasVideo) { + downloadText.setVisibility(View.GONE); + if (videoView != null && !videoView.isPlaying()) { + start(); + } + } } - } - } - @Override - public void onFail(String msg) { + @Override + public void onFail(String msg) { - } + } - @Override - public void onProgress(long totalSize, long downSize) { - getActivity().runOnUiThread(() -> { - if (isAdded()) { - downloadText.setText(String.format(getString(R.string.downloading), (int) (downSize * 100 / totalSize), "%")); + @Override + public void onProgress(long totalSize, long downSize) { + getActivity().runOnUiThread(() -> { + if (isAdded()) { + downloadText.setText(String.format(getString(R.string.downloading), + (int) (downSize * 100 / totalSize), "%")); + } + }); } }); - } - }); } @@ -166,12 +176,14 @@ public class PrepareFragment extends BaseFragment { ImageButton buttonView = new ImageButton(getContext()); buttonView.setBackgroundResource(R.drawable.begin_run_bt); buttonView.setOnClickListener(v -> { - int permission = ActivityCompat.checkSelfPermission(getActivity(), Manifest.permission.CAMERA); + int permission = ActivityCompat.checkSelfPermission(getActivity(), + Manifest.permission.CAMERA); if (permission != PackageManager.PERMISSION_GRANTED) { Toast.makeText(getActivity(), R.string.toast_no_camera_permission, Toast.LENGTH_SHORT).show(); return; } - permission = ActivityCompat.checkSelfPermission(getActivity(), Manifest.permission.WRITE_EXTERNAL_STORAGE); + permission = ActivityCompat.checkSelfPermission(getActivity(), + Manifest.permission.WRITE_EXTERNAL_STORAGE); if (permission != PackageManager.PERMISSION_GRANTED) { Toast.makeText(getActivity(), R.string.toast_no_storage_permission, Toast.LENGTH_SHORT).show(); @@ -193,13 +205,12 @@ public class PrepareFragment extends BaseFragment { private void start() { mediaController = new MediaController(getContext()); - String uri = StorageUtils.VIDEO_PATH + Constants.VIDEO_NAME; - Log.d(TAG, "start uri:" + uri); + String uri = StorageUtils.getDancePath(getContext()) + File.separator + + Constants.VIDEO_NAME; videoView.setVideoPath(uri); videoView.setMediaController(mediaController); mediaController.setMediaPlayer(videoView); videoView.requestFocus(); videoView.start(); } - } \ No newline at end of file diff --git a/model_zoo/official/lite/MindSpore_inhand/dance/src/main/java/com/mindspore/dance/view/fragment/RunFragment.java b/model_zoo/official/lite/MindSpore_inhand/dance/src/main/java/com/mindspore/dance/view/fragment/RunFragment.java index 83a98d76eaa09f9cbb7e1d4e8fb15c5ca43ee8f6..70d4bdeb05e960befcba6d23762dff311b02304a 100644 --- a/model_zoo/official/lite/MindSpore_inhand/dance/src/main/java/com/mindspore/dance/view/fragment/RunFragment.java +++ b/model_zoo/official/lite/MindSpore_inhand/dance/src/main/java/com/mindspore/dance/view/fragment/RunFragment.java @@ -51,6 +51,7 @@ import com.mindspore.dance.present.video.MyVideoView; import com.mindspore.dance.task.SampleTask; import com.mindspore.dance.util.Tools; +import java.io.File; import java.lang.ref.WeakReference; import java.util.Timer; import java.util.TimerTask; @@ -111,7 +112,7 @@ public class RunFragment extends Fragment { Thread thread = new Thread(new Runnable() { @Override public void run() { - Log.d(TAG, "run this thread:"+android.os.Process.myTid()); + Log.d(TAG, "run this thread:" + android.os.Process.myTid()); Message message = new Message(); message.what = timeWhat; timeWhat++; @@ -171,8 +172,8 @@ public class RunFragment extends Fragment { } private void start() { - String uri = StorageUtils.VIDEO_PATH + Constants.VIDEO_NAME; - Log.d(TAG, "start uri:" + uri); + String uri = StorageUtils.getDancePath(getContext()) + File.separator + + Constants.VIDEO_NAME; videoView.setVideoPath(uri); videoView.setMediaController(mediaController); mediaController.setMediaPlayer(videoView); diff --git a/model_zoo/official/lite/MindSpore_inhand/modelcamera/build.gradle b/model_zoo/official/lite/MindSpore_inhand/modelcamera/build.gradle index ec553bdbf718ade4cd7bd17a53897b4c8ef916e6..7c312148c10b9e303921a92eecb6a77cca826f4a 100644 --- a/model_zoo/official/lite/MindSpore_inhand/modelcamera/build.gradle +++ b/model_zoo/official/lite/MindSpore_inhand/modelcamera/build.gradle @@ -103,4 +103,15 @@ dependencies { implementation "androidx.camera:camera-view:${config.dependencies.camera_view}" implementation "androidx.camera:camera-extensions:${config.dependencies.camera_extensions}" + // 引入基础SDK + implementation "com.huawei.hms:ml-computer-vision-face:${config.dependencies.face}" + // 引入人脸轮廓+关键点检测模型包 + implementation "com.huawei.hms:ml-computer-vision-face-shape-point-model:${config.dependencies.face}" + // 引入表情检测模型包 + implementation "com.huawei.hms:ml-computer-vision-face-emotion-model:${config.dependencies.face}" + // 引入特征检测模型包 + implementation "com.huawei.hms:ml-computer-vision-face-feature-model:${config.dependencies.face}" + // 引入3d检测模型包 + implementation "com.huawei.hms:ml-computer-vision-face-3d-model:${config.dependencies.face}" + } \ No newline at end of file diff --git a/model_zoo/official/lite/MindSpore_inhand/modelcamera/src/main/java/com/mindspore/modelcamera/ui/fragment/CommonCameraFragment.java b/model_zoo/official/lite/MindSpore_inhand/modelcamera/src/main/java/com/mindspore/modelcamera/ui/fragment/CommonCameraFragment.java index 83e50a565921def91e5ffd7d8efbe570e07ff7f1..7018044cf5e7e2b5f515e59d58d6009f64d8cf21 100644 --- a/model_zoo/official/lite/MindSpore_inhand/modelcamera/src/main/java/com/mindspore/modelcamera/ui/fragment/CommonCameraFragment.java +++ b/model_zoo/official/lite/MindSpore_inhand/modelcamera/src/main/java/com/mindspore/modelcamera/ui/fragment/CommonCameraFragment.java @@ -105,8 +105,6 @@ public class CommonCameraFragment extends BaseCameraFragment { cameraExecutor = Executors.newSingleThreadExecutor(); } - - private void startCamera() { ListenableFuture cameraProviderFuture = ProcessCameraProvider.getInstance(getActivity()); cameraProviderFuture.addListener(() -> { @@ -119,59 +117,58 @@ public class CommonCameraFragment extends BaseCameraFragment { imageAnalysis.setAnalyzer(cameraExecutor, image -> { - ImageProxy.PlaneProxy[] planes = image.getPlanes(); - new Thread(() -> { - - for (int i = 0; i < planes.length; i++) { - Log.i(TAG, "pixelStride " + planes[i].getPixelStride()); - Log.i(TAG, "rowStride " + planes[i].getRowStride()); - Log.i(TAG, "width " + image.getWidth()); - Log.i(TAG, "height " + image.getHeight()); - Log.i(TAG, "Finished reading data from plane " + i); - } - - //cameraX 获取yuv - ByteBuffer yBuffer = planes[0].getBuffer(); - ByteBuffer uBuffer = planes[1].getBuffer(); - ByteBuffer vBuffer = planes[2].getBuffer(); - - int ySize = yBuffer.remaining(); - int uSize = uBuffer.remaining(); - int vSize = vBuffer.remaining(); - - byte[] nv21 = new byte[ySize + uSize + vSize]; - - yBuffer.get(nv21, 0, ySize); - vBuffer.get(nv21, ySize, vSize); - uBuffer.get(nv21, ySize + vSize, uSize); - - //开始时间 - long START = System.currentTimeMillis(); - //获取yuvImage - YuvImage yuvImage = new YuvImage(nv21, ImageFormat.NV21, image.getWidth(), image.getHeight(), null); - //输出流 - ByteArrayOutputStream out = new ByteArrayOutputStream(); - //压缩写入out - yuvImage.compressToJpeg(new Rect(0, 0, yuvImage.getWidth(), yuvImage.getHeight()), 50, out); - //转数组 - byte[] imageBytes = out.toByteArray(); - //生成bitmap - Bitmap bitmap = BitmapFactory.decodeByteArray(imageBytes, 0, imageBytes.length); - //旋转bitmap + ImageProxy.PlaneProxy[] planes = image.getPlanes(); + new Thread(() -> { + + for (int i = 0; i < planes.length; i++) { + Log.i(TAG, "pixelStride " + planes[i].getPixelStride()); + Log.i(TAG, "rowStride " + planes[i].getRowStride()); + Log.i(TAG, "width " + image.getWidth()); + Log.i(TAG, "height " + image.getHeight()); + Log.i(TAG, "Finished reading data from plane " + i); + } + + //cameraX 获取yuv + ByteBuffer yBuffer = planes[0].getBuffer(); + ByteBuffer uBuffer = planes[1].getBuffer(); + ByteBuffer vBuffer = planes[2].getBuffer(); + + int ySize = yBuffer.remaining(); + int uSize = uBuffer.remaining(); + int vSize = vBuffer.remaining(); + + byte[] nv21 = new byte[ySize + uSize + vSize]; + + yBuffer.get(nv21, 0, ySize); + vBuffer.get(nv21, ySize, vSize); + uBuffer.get(nv21, ySize + vSize, uSize); + + //开始时间 + long START = System.currentTimeMillis(); + //获取yuvImage + YuvImage yuvImage = new YuvImage(nv21, ImageFormat.NV21, image.getWidth(), image.getHeight(), null); + //输出流 + ByteArrayOutputStream out = new ByteArrayOutputStream(); + //压缩写入out + yuvImage.compressToJpeg(new Rect(0, 0, yuvImage.getWidth(), yuvImage.getHeight()), 50, out); + //转数组 + byte[] imageBytes = out.toByteArray(); + //生成bitmap + Bitmap bitmap = BitmapFactory.decodeByteArray(imageBytes, 0, imageBytes.length); + //旋转bitmap // Bitmap rotateBitmap = rotateBitmap(bitmap, 90); - //结束时间 - long END = System.currentTimeMillis(); - getActivity().runOnUiThread(() -> { + //结束时间 + long END = System.currentTimeMillis(); + getActivity().runOnUiThread(() -> { // imageView.setImageBitmap(rotateBitmap); - Log.e(TAG, "耗时: " + (END - START)); - //关闭 - image.close(); - }); - }).start(); - }); - - //... + Log.e(TAG, "耗时: " + (END - START)); + //关闭 + image.close(); + }); + }).start(); + }); + //... CameraSelector cameraSelector = @@ -206,7 +203,7 @@ public class CommonCameraFragment extends BaseCameraFragment { imageRecyclerView.setVisibility(View.GONE); } - if (model ==CameraConstants.STICK ){ + if (model == CameraConstants.STICK) { borderImageView.setVisibility(View.VISIBLE); imageRecyclerView.setVisibility(View.VISIBLE); imageRecyclerView.setLayoutManager(new LinearLayoutManager(getActivity(), RecyclerView.HORIZONTAL, false)); @@ -220,7 +217,7 @@ public class CommonCameraFragment extends BaseCameraFragment { }); imageRecyclerView.setAdapter(imageCameraAdapter); - }else{ + } else { borderImageView.setVisibility(View.GONE); } } @@ -233,11 +230,9 @@ public class CommonCameraFragment extends BaseCameraFragment { return; } - File root; - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) { - root = getActivity().getExternalFilesDirs(null)[0]; - } else { - root = new File(StorageUtils.ABSOLUTE_FILE, Utils.getApp().getPackageName()); + File root = new File(StorageUtils.getTempPath(getContext())); + if (!root.exists()) { + root.mkdirs(); } File mFile = new File(root, "temp.jpg");