Skip to content

Commit e95f6fb

Browse files
committed
スクリーンショットと読み込んだ写真が共有されない不具合を修正。
1 parent 72dcc7b commit e95f6fb

2 files changed

Lines changed: 17 additions & 55 deletions

File tree

dConnectDevicePlugin/dConnectDeviceTheta/app/src/main/java/org/deviceconnect/android/deviceplugin/theta/data/ThetaObjectStorage.java

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828
import java.io.File;
2929
import java.io.IOException;
3030
import java.io.InputStream;
31-
import java.io.OutputStream;
3231
import java.text.SimpleDateFormat;
3332
import java.util.ArrayList;
3433
import java.util.Date;
@@ -337,7 +336,7 @@ private ContentValues makeContentValue(final ThetaObject object) throws IOExcept
337336
dataImage);
338337
values.put(THETA_MAIN_URL, imagePath);
339338

340-
mMediaSharing.sharePhoto(mContext, new File(mFileManager.getBasePath(), imagePath));
339+
mMediaSharing.sharePhoto(mContext, new File(imagePath));
341340
}
342341
}
343342
return values;
@@ -346,25 +345,22 @@ private ContentValues makeContentValue(final ThetaObject object) throws IOExcept
346345

347346
// save theta's image
348347
@SuppressWarnings("deprecation")
349-
private String saveThetaImage(final String cacheDir,
348+
private String saveThetaImage(final String cacheDirName,
350349
final String originalFileName,
351350
final byte[] thetaImage) throws IOException {
352-
String root = mFileManager.getBasePath().getAbsolutePath()
353-
+ "/" + cacheDir + "/";
354-
File dir = new File(root);
355-
if (!dir.exists()) {
356-
if (!dir.mkdirs()) {
357-
throw new IOException("Failed to create directory: path = " + dir.getAbsolutePath());
351+
File cacheDir = new File(mFileManager.getBasePath(), cacheDirName);
352+
if (!cacheDir.exists()) {
353+
if (!cacheDir.mkdirs()) {
354+
throw new IOException("Failed to create directory: path = " + cacheDir.getAbsolutePath());
358355
}
359356
}
360357

361358
Date date = new Date();
362359
SimpleDateFormat fileDate = new SimpleDateFormat("yyyyMMdd_HHmmss");
363360
final String fileName = originalFileName + "." + fileDate.format(date);
364-
final String filePath = cacheDir + "/" + fileName;
365361

366-
mFileManager.saveFile(filePath, thetaImage);
367-
return filePath;
362+
mFileManager.saveFile(cacheDirName + "/" + fileName, thetaImage);
363+
return new File(cacheDir, fileName).getAbsolutePath();
368364
}
369365

370366
// load theta's image data.

dConnectDevicePlugin/dConnectDeviceTheta/app/src/main/java/org/deviceconnect/android/deviceplugin/theta/fragment/ThetaVRModeFragment.java

Lines changed: 9 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,9 @@
77
package org.deviceconnect.android.deviceplugin.theta.fragment;
88

99
import android.app.Activity;
10-
import android.content.ContentResolver;
11-
import android.content.ContentValues;
1210
import android.content.Intent;
1311
import android.content.res.Configuration;
14-
import android.net.Uri;
1512
import android.os.Bundle;
16-
import android.provider.MediaStore;
1713
import android.view.LayoutInflater;
1814
import android.view.MotionEvent;
1915
import android.view.ScaleGestureDetector;
@@ -28,7 +24,6 @@
2824
import androidx.collection.LruCache;
2925
import androidx.fragment.app.Fragment;
3026

31-
import org.deviceconnect.android.deviceplugin.theta.BuildConfig;
3227
import org.deviceconnect.android.deviceplugin.theta.R;
3328
import org.deviceconnect.android.deviceplugin.theta.ThetaDeviceApplication;
3429
import org.deviceconnect.android.deviceplugin.theta.activity.ThetaDeviceSettingsActivity;
@@ -46,7 +41,6 @@
4641

4742
import java.io.File;
4843
import java.io.IOException;
49-
import java.io.OutputStream;
5044
import java.text.SimpleDateFormat;
5145
import java.util.Date;
5246
import java.util.List;
@@ -338,8 +332,9 @@ private void init3DButtons(final View rootView) {
338332
/**
339333
* Save ScreenShot.
340334
*/
335+
@SuppressWarnings("deprecation")
341336
private void saveScreenShot() {
342-
FileManager fileManager = new FileManager(getActivity());
337+
final FileManager fileManager = new FileManager(getActivity());
343338
fileManager.checkWritePermission(new FileManager.CheckPermissionCallback() {
344339
@Override
345340
public void onSuccess() {
@@ -357,24 +352,21 @@ public void onSuccess() {
357352
});
358353
return;
359354
}
360-
String root = getContext().getExternalFilesDir(null).getPath() + "/screenshots/";
361-
File dir = new File(root);
362-
if (!dir.exists()) {
363-
dir.mkdir();
355+
356+
String cacheDirName = "screenshots";
357+
File cacheDir = new File(fileManager.getBasePath(), cacheDirName);
358+
if (!cacheDir.exists()) {
359+
cacheDir.mkdirs();
364360
}
365361

366362
Date date = new Date();
367363
SimpleDateFormat fileDate = new SimpleDateFormat("yyyyMMdd_HHmmss");
368364
final String fileName = "theta_vr_screenshot_" + fileDate.format(date) + ".jpg";
369-
final String filePath = root + fileName;
370365

371366
try {
372-
saveFile(filePath, mSphereView.takeSnapshot());
373-
if (BuildConfig.DEBUG) {
374-
mLogger.info("absolute path:" + filePath);
375-
}
367+
fileManager.saveFile(cacheDirName + "/" + fileName, mSphereView.takeSnapshot());
376368

377-
mMediaSharing.sharePhoto(getContext(), new File(filePath));
369+
mMediaSharing.sharePhoto(getContext(), new File(cacheDir, fileName));
378370

379371
if (activity != null) {
380372
activity.runOnUiThread(() -> {
@@ -418,32 +410,6 @@ public void onFail() {
418410

419411
}
420412

421-
/**
422-
* Save File.
423-
* @param filename absolute path
424-
* @param data binary
425-
* @throws IOException Failed Save
426-
*/
427-
private void saveFile(final String filename, final byte[] data) throws IOException {
428-
Uri u = Uri.parse("file://" + filename);
429-
ContentResolver contentResolver = getActivity().getContentResolver();
430-
OutputStream out = null;
431-
try {
432-
out = contentResolver.openOutputStream(u, "w");
433-
out.write(data);
434-
out.flush();
435-
} catch (Exception e) {
436-
throw new IOException("Failed to save a file." + filename);
437-
} finally {
438-
if (out != null) {
439-
try {
440-
out.close();
441-
} catch (IOException e) {
442-
e.printStackTrace();
443-
}
444-
}
445-
}
446-
}
447413
/**
448414
* ScreenShot failed.
449415
*/

0 commit comments

Comments
 (0)