77package org .deviceconnect .android .deviceplugin .theta .fragment ;
88
99import android .app .Activity ;
10- import android .content .ContentResolver ;
11- import android .content .ContentValues ;
1210import android .content .Intent ;
1311import android .content .res .Configuration ;
14- import android .net .Uri ;
1512import android .os .Bundle ;
16- import android .provider .MediaStore ;
1713import android .view .LayoutInflater ;
1814import android .view .MotionEvent ;
1915import android .view .ScaleGestureDetector ;
2824import androidx .collection .LruCache ;
2925import androidx .fragment .app .Fragment ;
3026
31- import org .deviceconnect .android .deviceplugin .theta .BuildConfig ;
3227import org .deviceconnect .android .deviceplugin .theta .R ;
3328import org .deviceconnect .android .deviceplugin .theta .ThetaDeviceApplication ;
3429import org .deviceconnect .android .deviceplugin .theta .activity .ThetaDeviceSettingsActivity ;
4641
4742import java .io .File ;
4843import java .io .IOException ;
49- import java .io .OutputStream ;
5044import java .text .SimpleDateFormat ;
5145import java .util .Date ;
5246import 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