OSDN Git Service

ファイルのダウンロードのロジックまで。(ただまともに取得できない。。。)
authorMRSa <mrsa@myad.jp>
Sun, 5 Aug 2018 15:45:15 +0000 (00:45 +0900)
committerMRSa <mrsa@myad.jp>
Sun, 5 Aug 2018 15:45:15 +0000 (00:45 +0900)
app/src/main/java/net/osdn/gokigen/gr2control/camera/playback/IDownloadContentCallback.java [moved from app/src/main/java/net/osdn/gokigen/gr2control/camera/playback/IDownloadLargeContentCallback.java with 78% similarity]
app/src/main/java/net/osdn/gokigen/gr2control/camera/playback/IDownloadImageCallback.java [deleted file]
app/src/main/java/net/osdn/gokigen/gr2control/camera/playback/IDownloadThumbnailImageCallback.java
app/src/main/java/net/osdn/gokigen/gr2control/camera/playback/IPlaybackControl.java
app/src/main/java/net/osdn/gokigen/gr2control/camera/ricohgr2/wrapper/RicohGr2PlaybackControl.java
app/src/main/java/net/osdn/gokigen/gr2control/camera/utils/SimpleHttpClient.java
app/src/main/java/net/osdn/gokigen/gr2control/playback/ImageGridViewFragment.java
app/src/main/java/net/osdn/gokigen/gr2control/playback/detail/ImagePagerViewFragment.java
app/src/main/java/net/osdn/gokigen/gr2control/playback/detail/MyContentDownloader.java [new file with mode: 0644]
app/src/main/java/net/osdn/gokigen/gr2control/preference/IPreferencePropertyAccessor.java
app/src/main/res/drawable/ic_videocam_black_24dp.xml

diff --git a/app/src/main/java/net/osdn/gokigen/gr2control/camera/playback/IDownloadImageCallback.java b/app/src/main/java/net/osdn/gokigen/gr2control/camera/playback/IDownloadImageCallback.java
deleted file mode 100644 (file)
index ce1ea0c..0000000
+++ /dev/null
@@ -1,12 +0,0 @@
-package net.osdn.gokigen.gr2control.camera.playback;
-
-import android.graphics.Bitmap;
-
-import java.util.Map;
-
-public interface IDownloadImageCallback
-{
-    void onCompleted(byte[]  data, Map<String, Object> metadata);
-    void onErrorOccurred(Exception  e);
-    void onProgress(ProgressEvent e);
-}
index 5d6e5a7..6f9d2ac 100644 (file)
@@ -8,5 +8,4 @@ public interface IDownloadThumbnailImageCallback
 {
     void onCompleted(Bitmap bitmap, Map<String, Object> metadata);
     void onErrorOccurred(Exception  e);
-    void onProgress(ProgressEvent e);
 }
index edea89b..47ccd06 100644 (file)
@@ -3,8 +3,6 @@ package net.osdn.gokigen.gr2control.camera.playback;
 import android.support.annotation.NonNull;
 
 import net.osdn.gokigen.gr2control.camera.ICameraFileInfo;
-import net.osdn.gokigen.gr2control.camera.playback.IDownloadContentListCallback;
-import net.osdn.gokigen.gr2control.camera.playback.IDownloadImageCallback;
 
 /**
  *   画像再生・取得用インタフェース
@@ -18,8 +16,5 @@ public interface IPlaybackControl
 
     void downloadContentScreennail(@NonNull String  path, @NonNull IDownloadThumbnailImageCallback callback);
     void downloadContentThumbnail(@NonNull String path, @NonNull IDownloadThumbnailImageCallback callback);
-    //void downloadContentScreennail(@NonNull String  path, @NonNull IDownloadThumbnailImageCallback callback);
-    //void downloadContentThumbnail(@NonNull String path, @NonNull IDownloadThumbnailImageCallback callback);
-    void downloadImage(@NonNull String  path, float resize, @NonNull IDownloadImageCallback  callback);
-    void downloadLargeContent(@NonNull String  path, @NonNull IDownloadLargeContentCallback  callback);
+    void downloadContent(@NonNull String  path, boolean isSmallSize, @NonNull IDownloadContentCallback callback);
 }
index 4cf5050..6b45f4c 100644 (file)
@@ -8,20 +8,23 @@ import net.osdn.gokigen.gr2control.camera.ICameraFileInfo;
 import net.osdn.gokigen.gr2control.camera.playback.CameraFileInfo;
 import net.osdn.gokigen.gr2control.camera.playback.IContentInfoCallback;
 import net.osdn.gokigen.gr2control.camera.playback.IDownloadContentListCallback;
-import net.osdn.gokigen.gr2control.camera.playback.IDownloadImageCallback;
-import net.osdn.gokigen.gr2control.camera.playback.IDownloadLargeContentCallback;
+import net.osdn.gokigen.gr2control.camera.playback.IDownloadContentCallback;
 import net.osdn.gokigen.gr2control.camera.playback.IDownloadThumbnailImageCallback;
 import net.osdn.gokigen.gr2control.camera.playback.IPlaybackControl;
+import net.osdn.gokigen.gr2control.camera.playback.ProgressEvent;
 import net.osdn.gokigen.gr2control.camera.utils.SimpleHttpClient;
 
 import org.json.JSONArray;
 import org.json.JSONObject;
 
 import java.util.ArrayList;
-import java.util.Date;
 import java.util.HashMap;
 import java.util.List;
 
+/**
+ *
+ *
+ */
 public class RicohGr2PlaybackControl implements IPlaybackControl
 {
     private final String TAG = toString();
@@ -143,8 +146,6 @@ public class RicohGr2PlaybackControl implements IPlaybackControl
         return (value);
     }
 
-
-
     @Override
     public void getContentInfo(@NonNull String path, @NonNull IContentInfoCallback callback)
     {
@@ -205,20 +206,45 @@ public class RicohGr2PlaybackControl implements IPlaybackControl
         catch (Throwable e)
         {
             e.printStackTrace();
+            callback.onErrorOccurred(new NullPointerException());
         }
    }
 
     @Override
-    public void downloadImage(@NonNull String path, float resize, @NonNull IDownloadImageCallback callback)
+    public void downloadContent(@NonNull String  path, boolean isSmallSize, @NonNull final IDownloadContentCallback callback)
     {
-        Log.v(TAG, "downloadImage() " + path + " [" + resize + "]");
-
-    }
+        Log.v(TAG, "downloadContent() : " + path);
+        String suffix = "?size=full";
+        if (isSmallSize)
+        {
+            suffix = "?size=view";
+        }
+        String url = getPhotoUrl + path + suffix;
+        Log.v(TAG, "downloadContent() GET URL : " + url);
+        try
+        {
+            SimpleHttpClient.httpGetBytes(url, DEFAULT_TIMEOUT, new SimpleHttpClient.IReceivedMessageCallback() {
+                @Override
+                public void onCompleted() {
+                    callback.onCompleted();
+                }
 
-    @Override
-    public void downloadLargeContent(@NonNull String path, @NonNull IDownloadLargeContentCallback callback)
-    {
-        Log.v(TAG, "downloadLargeContent() : " + path);
+                @Override
+                public void onErrorOccurred(Exception e) {
+                    callback.onErrorOccurred(e);
+                }
 
+                @Override
+                public void onReceive(int readBytes, int length, byte[] data) {
+                    float percent = (length == 0) ? 0.0f : ((float) readBytes / (float) length);
+                    ProgressEvent event = new ProgressEvent(percent, null);
+                    callback.onProgress(data, event);
+                }
+            });
+        }
+        catch (Throwable e)
+        {
+            e.printStackTrace();
+        }
     }
 }
index 414fb4f..56df0c6 100644 (file)
@@ -2,8 +2,10 @@ package net.osdn.gokigen.gr2control.camera.utils;
 
 import android.graphics.Bitmap;
 import android.graphics.BitmapFactory;
+import android.support.annotation.NonNull;
 import android.util.Log;
 
+import java.io.BufferedInputStream;
 import java.io.BufferedReader;
 import java.io.ByteArrayOutputStream;
 import java.io.IOException;
@@ -127,12 +129,10 @@ public class SimpleHttpClient
      *
      *
      */
-    public static byte[] httpGetBytes(String url, int timeoutMs)
+    public static void httpGetBytes(String url, int timeoutMs, @NonNull IReceivedMessageCallback callback)
     {
         HttpURLConnection httpConn = null;
         InputStream inputStream = null;
-        byte[] receivedData = new byte[0];
-
         int timeout = timeoutMs;
         if (timeoutMs < 0)
         {
@@ -157,7 +157,9 @@ public class SimpleHttpClient
             if (inputStream == null)
             {
                 Log.w(TAG, "httpGet: Response Code Error: " + responseCode + ": " + url);
-                return (receivedData);
+                callback.onErrorOccurred(new NullPointerException());
+                callback.onCompleted();
+                return;
             }
         }
         catch (Exception e)
@@ -168,46 +170,38 @@ public class SimpleHttpClient
             {
                 httpConn.disconnect();
             }
-            return (receivedData);
+            callback.onErrorOccurred(e);
+            callback.onCompleted();
+            return;
         }
 
         // 応答を確認する
-        BufferedReader reader = null;
-        int count = 0;
         try
         {
+            int contentLength = httpConn.getContentLength();
             byte[] buffer = new byte[BUFFER_SIZE];
-            int c;
-            ByteArrayOutputStream out = new ByteArrayOutputStream();
-            reader = new BufferedReader(new InputStreamReader(inputStream));
-            while ((c = reader.read()) != -1)
+            BufferedInputStream bufferedInputStream = new BufferedInputStream(inputStream);
+            int readBytes = 0;
+            int readSize = bufferedInputStream.read(buffer, 0, BUFFER_SIZE);
+            while (readSize != -1)
             {
-                out.write(c);
-                count++;
+                callback.onReceive(readBytes, contentLength, buffer);
+                readBytes += readSize;
+                readSize = bufferedInputStream.read(buffer, 0, BUFFER_SIZE);
             }
-            receivedData = out.toByteArray();
-            Log.v(TAG, "RECEIVED " + count + " BYTES. ");
+            Log.v(TAG, "RECEIVED " + readBytes + " BYTES. (contentLength : " + contentLength + ")");
+            bufferedInputStream.close();
         }
         catch (Exception e)
         {
             Log.w(TAG, "httpGet: exception: " + e.getMessage());
             e.printStackTrace();
+            callback.onErrorOccurred(e);
         }
         finally
         {
             try
             {
-                if (reader != null)
-                {
-                    reader.close();
-                }
-            }
-            catch (Exception e)
-            {
-                e.printStackTrace();
-            }
-            try
-            {
                 inputStream.close();
             }
             catch (Exception e)
@@ -215,8 +209,9 @@ public class SimpleHttpClient
                 e.printStackTrace();
             }
         }
-        return (receivedData);
+        callback.onCompleted();
     }
+
     /**
      *
      *
@@ -393,4 +388,11 @@ public class SimpleHttpClient
         }
         return (replyString);
     }
+
+    public interface IReceivedMessageCallback
+    {
+        void onCompleted();
+        void onErrorOccurred(Exception  e);
+        void onReceive(int readBytes, int length, byte[] data);
+    }
 }
index b1b273e..2317cb0 100644 (file)
@@ -1,8 +1,6 @@
 package net.osdn.gokigen.gr2control.playback;
 
 import java.io.File;
-import java.io.FileOutputStream;
-import java.io.IOException;
 import java.util.ArrayList;
 import java.util.Collections;
 import java.util.Comparator;
@@ -18,11 +16,8 @@ import android.app.AlertDialog;
 import android.content.Context;
 import android.content.SharedPreferences;
 import android.graphics.Bitmap;
-import android.graphics.BitmapFactory;
-import android.graphics.Matrix;
 import android.preference.PreferenceManager;
 import android.support.annotation.NonNull;
-import android.support.media.ExifInterface;
 import android.os.Bundle;
 import android.support.v4.app.Fragment;
 import android.support.v4.app.FragmentActivity;
@@ -50,7 +45,6 @@ import net.osdn.gokigen.gr2control.camera.ICameraFileInfo;
 import net.osdn.gokigen.gr2control.camera.playback.IDownloadContentListCallback;
 import net.osdn.gokigen.gr2control.camera.playback.IDownloadThumbnailImageCallback;
 import net.osdn.gokigen.gr2control.camera.playback.IPlaybackControl;
-import net.osdn.gokigen.gr2control.camera.playback.ProgressEvent;
 import net.osdn.gokigen.gr2control.playback.detail.ImageContentInfoEx;
 import net.osdn.gokigen.gr2control.playback.detail.ImagePagerViewFragment;
 
@@ -257,11 +251,11 @@ public class ImageGridViewFragment extends Fragment
                 for (ICameraFileInfo item : list)
                 {
                     String path = item.getFilename().toLowerCase(Locale.getDefault());
-                    if ((path.endsWith(JPEG_SUFFIX))||(path.endsWith(MOVIE_SUFFIX)))
+                    if ((path.toLowerCase().endsWith(JPEG_SUFFIX))||(path.toLowerCase().endsWith(MOVIE_SUFFIX)))
                     {
                         contentItems.add(new ImageContentInfoEx(item, false));
                     }
-                    else if (path.endsWith(RAW_SUFFIX))
+                    else if (path.toLowerCase().endsWith(RAW_SUFFIX))
                     {
                         rawItems.put(path, new ImageContentInfoEx(item, true));
                     }
@@ -270,7 +264,7 @@ public class ImageGridViewFragment extends Fragment
                 for (ImageContentInfoEx item : contentItems)
                 {
                     String path = item.getFileInfo().getFilename().toLowerCase(Locale.getDefault());
-                    if (path.endsWith(JPEG_SUFFIX))
+                    if (path.toLowerCase().endsWith(JPEG_SUFFIX))
                     {
                         String target = path.replace(JPEG_SUFFIX, RAW_SUFFIX);
                         ImageContentInfoEx raw = rawItems.get(target);
@@ -482,12 +476,6 @@ public class ImageGridViewFragment extends Fragment
                        playbackControl.downloadContentThumbnail(path, new IDownloadThumbnailImageCallback()
             {
                                @Override
-                               public void onProgress(ProgressEvent e)
-                {
-                       //
-                               }
-                               
-                               @Override
                                public void onCompleted(final Bitmap thumbnail, Map<String, Object> metadata)
                                {
                                        if (thumbnail != null)
@@ -556,7 +544,8 @@ public class ImageGridViewFragment extends Fragment
         }
                activity.runOnUiThread(action);
        }
-       
+
+/*
        private Bitmap createRotatedBitmap(byte[] data, Map<String, Object> metadata)
     {
                Bitmap bitmap = null;
@@ -641,4 +630,5 @@ public class ImageGridViewFragment extends Fragment
                }
                return (degrees);
        }
+*/
 }
index dce99d2..f1ea1d2 100644 (file)
@@ -1,8 +1,5 @@
 package net.osdn.gokigen.gr2control.playback.detail;
 
-import java.io.File;
-import java.io.FileOutputStream;
-import java.io.IOException;
 import java.text.SimpleDateFormat;
 import java.util.Calendar;
 import java.util.Date;
@@ -12,23 +9,10 @@ import java.util.Map;
 
 import android.app.Activity;
 import android.app.AlertDialog;
-import android.app.ProgressDialog;
-import android.content.ContentResolver;
-import android.content.ContentValues;
-import android.content.Intent;
 import android.graphics.Bitmap;
-import android.graphics.BitmapFactory;
-import android.graphics.Matrix;
-
-import android.net.Uri;
 import android.support.annotation.NonNull;
-import android.support.media.ExifInterface;
 import android.os.Bundle;
-import android.os.Environment;
-import android.provider.MediaStore;
-import android.provider.MediaStore.Images;
 import android.support.v4.app.Fragment;
-import android.support.v4.app.FragmentActivity;
 import android.support.v4.view.PagerAdapter;
 import android.support.v4.view.ViewPager;
 import android.support.v4.view.ViewPager.OnPageChangeListener;
@@ -43,21 +27,17 @@ import android.view.MenuItem;
 import android.view.View;
 import android.view.ViewGroup;
 import android.widget.ImageView;
-import android.widget.Toast;
 
 import net.osdn.gokigen.gr2control.R;
 import net.osdn.gokigen.gr2control.camera.ICameraFileInfo;
-import net.osdn.gokigen.gr2control.camera.playback.IDownloadImageCallback;
-import net.osdn.gokigen.gr2control.camera.playback.IDownloadLargeContentCallback;
 import net.osdn.gokigen.gr2control.camera.playback.IDownloadThumbnailImageCallback;
 import net.osdn.gokigen.gr2control.camera.playback.IPlaybackControl;
-import net.osdn.gokigen.gr2control.camera.playback.ProgressEvent;
 
 public class ImagePagerViewFragment extends Fragment
 {
     private final String TAG = this.toString();
-    private final String JPEG_SUFFIX = ".jpg";
-    private final String RAW_SUFFIX = ".dng";
+    private static final String JPEG_SUFFIX = ".JPG";
+    private static final String RAW_SUFFIX = ".DNG";
     private IPlaybackControl playbackControl;
 
        private List<ImageContentInfoEx> contentList = null;
@@ -67,6 +47,7 @@ public class ImagePagerViewFragment extends Fragment
        private ViewPager viewPager = null;
        private LruCache<String, Bitmap> imageCache =null;
 
+
     public static ImagePagerViewFragment newInstance(@NonNull IPlaybackControl playbackControl, @NonNull List<ImageContentInfoEx> contentList, int contentIndex)
        {
                ImagePagerViewFragment fragment = new ImagePagerViewFragment();
@@ -75,11 +56,13 @@ public class ImagePagerViewFragment extends Fragment
                return (fragment);
        }
 
+
        private void setInterface(@NonNull IPlaybackControl playbackControl)
     {
         this.playbackControl = playbackControl;
     }
 
+
        private void setContentList(@NonNull List<ImageContentInfoEx> contentList, int contentIndex)
        {
                this.contentList = contentList;
@@ -125,7 +108,7 @@ public class ImagePagerViewFragment extends Fragment
                     bar.setTitle(path);
                 }
             }
-                       String lowerCasePath = path.toLowerCase();
+                       String lowerCasePath = path.toUpperCase();
                        if (lowerCasePath.endsWith(JPEG_SUFFIX))
             {
                 if (info.hasRaw())
@@ -192,7 +175,7 @@ public class ImagePagerViewFragment extends Fragment
                 {
                     showFileInformation((contentList.get(contentIndex)).getFileInfo());
                 }
-                       });
+               });
                try
             {
                 thread.start();
@@ -203,27 +186,26 @@ public class ImagePagerViewFragment extends Fragment
             }
         }
 
-        /*
                if (doDownload)
                {
                        try
                        {
                 ICameraFileInfo file = (contentList.get(contentIndex)).getFileInfo();
                                String path = file.getDirectoryPath() + "/" + file.getFilename();
-                               String lowerCasePath = path.toLowerCase();
-                               String suffix = (specialSuffix == null) ? lowerCasePath.substring(lowerCasePath.lastIndexOf(".")) : specialSuffix;
+                               String upperCasePath = path.toUpperCase();
+                               String suffix = (specialSuffix == null) ? upperCasePath.substring(upperCasePath.lastIndexOf(".")) : specialSuffix;
                                Calendar calendar = Calendar.getInstance();
                                String filename = new SimpleDateFormat("yyyyMMdd_HHmmss", Locale.getDefault()).format(calendar.getTime()) + suffix;
 
                                //  ダイアログを表示して保存する
-                               saveImageWithDialog(filename, downloadSize, getInformation);
+                               saveImageWithDialog(filename, isSmallSize);
                        }
                        catch (Exception e)
                        {
                                e.printStackTrace();
                        }
                }
-*/
+
                return (super.onOptionsItemSelected(item));
        }
 
@@ -380,6 +362,10 @@ public class ImagePagerViewFragment extends Fragment
                }
        }
 
+    /**
+     *
+     *
+     */
        private void downloadImage(final int position, final ImageView view)
        {
                Thread thread = new Thread(new Runnable() {
@@ -398,6 +384,10 @@ public class ImagePagerViewFragment extends Fragment
                }
        }
 
+    /**
+     *
+     *
+     */
        private void downloadImageImpl(int position, final ImageView view)
     {
         try
@@ -426,14 +416,6 @@ public class ImagePagerViewFragment extends Fragment
             // Download the image.
             playbackControl.downloadContentScreennail(path, new IDownloadThumbnailImageCallback() {
                 @Override
-                public void onProgress(ProgressEvent e) {
-                    // MARK: Do not use to cancel a downloading by progress handler.
-                    //       A communication error may occur by the downloading of the next image when
-                    //       you cancel the downloading of the image by a progress handler in
-                    //       the current version.
-                }
-
-                @Override
                                //public void onCompleted(final byte[] data, final Map<String, Object> metadata) {
                 public void onCompleted(final Bitmap bitmap, final Map<String, Object> metadata) {
                     // Cache the downloaded image.
@@ -487,21 +469,25 @@ public class ImagePagerViewFragment extends Fragment
         *   デバイスに画像ファイルをダウンロード(保存)する
         *
         * @param filename       ファイル名(カメラ内の)
-        * @param downloadSize   ダウンロードサイズ
-     * @param isGetInformationMode 情報取得モードか?
+        * @param isSmallSize    小さいサイズの量にするか
      */
-       public void saveImageWithDialog(final String filename, float downloadSize, boolean isGetInformationMode)
+       public void saveImageWithDialog(final String filename, final boolean isSmallSize)
        {
-           try
+        Log.v(TAG, "saveImageWithDialog() : " + filename + " (small : " + isSmallSize + ")");
+        try
         {
-            if (filename.endsWith(JPEG_SUFFIX)) {
-                // 静止画の取得
-                MyImageDownloader imageDownloader = new MyImageDownloader(filename, downloadSize, isGetInformationMode);
-                imageDownloader.startDownload();
-            } else {
-                // 動画・RAWファイルの取得
-                MyMovieDownloader movieDownloader = new MyMovieDownloader(filename);
-                movieDownloader.startDownload();
+            final Activity activity = getActivity();
+            if (activity != null)
+            {
+                Thread thread = new Thread(new Runnable() {
+                    @Override
+                    public void run() {
+                        MyContentDownloader contentDownloader = new MyContentDownloader(activity, playbackControl);
+                        ICameraFileInfo fileInfo = (contentList.get(contentIndex)).getFileInfo();
+                        contentDownloader.startDownload(fileInfo,  (filename.endsWith(RAW_SUFFIX)) ? RAW_SUFFIX : null, isSmallSize);
+                    }
+                });
+                thread.start();
             }
         }
         catch (Exception e)
@@ -510,16 +496,20 @@ public class ImagePagerViewFragment extends Fragment
         }
        }
 
-
        // -------------------------------------------------------------------------
        // Helpers
        // -------------------------------------------------------------------------
        
-       private void presentMessage(String title, String message)
+       private void presentMessage(final String title, final String message)
     {
-               AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
-               builder.setTitle(title).setMessage(message);
-               builder.show();
+        runOnUiThread(new Runnable() {
+                @Override
+                public void run() {
+                    AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
+                    builder.setTitle(title).setMessage(message);
+                    builder.show();
+                }
+        });
        }
        
        private void runOnUiThread(Runnable action)
@@ -530,7 +520,8 @@ public class ImagePagerViewFragment extends Fragment
                }
                getActivity().runOnUiThread(action);
        }
-       
+
+/*
        private Bitmap createRotatedBitmap(byte[] data, Map<String, Object> metadata)
        {
                Bitmap bitmap;
@@ -620,691 +611,5 @@ public class ImagePagerViewFragment extends Fragment
                }
                return degrees;
        }
-
-    /**
-     *   静止画のダウンロード(とEXIF情報の取得)
-     *
-     */
-       private class MyImageDownloader implements IDownloadImageCallback
-       {
-        private boolean isGetInformation;
-               private ProgressDialog downloadDialog = null;
-               private String filename;
-               private float downloadImageSize;
-
-               /**
-                *   コンストラクタ
-                *
-                * @param filename  ファイル名
-                * @param downloadSize  ダウンロードのサイズ
-         * @param isGetInformation  情報を取得するだけかどうか(trueなら情報を取得するだけ)
-         */
-               MyImageDownloader(final String filename, float downloadSize, boolean isGetInformation)
-               {
-                       this.filename = filename;
-                       this.downloadImageSize = downloadSize;
-            this.isGetInformation = isGetInformation;
-               }
-
-               /**
-                *   静止画のダウンロード開始指示
-                *
-                */
-               void startDownload()
-               {
-                       Log.v(TAG, "startDownload() " + filename);
-                       downloadDialog = new ProgressDialog(getContext());
-            if (isGetInformation)
-            {
-                downloadDialog.setTitle(getString(R.string.dialog_get_information_title));
-            }
-            else
-            {
-                downloadDialog.setTitle(getString(R.string.dialog_download_title));
-            }
-                       downloadDialog.setMessage(getString(R.string.dialog_download_message) + " " + filename);
-                       downloadDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
-                       downloadDialog.setCancelable(false);
-                       downloadDialog.show();
-
-                       // Download the image.
-            try
-            {
-                ICameraFileInfo file = (contentList.get(contentIndex)).getFileInfo();
-                String path = file.getDirectoryPath() + "/" + file.getFilename();
-                playbackControl.downloadImage(path, downloadImageSize, this);
-            }
-            catch (Exception e)
-            {
-                e.printStackTrace();
-            }
-               }
-
-               /**
-                *   進行中の表示 (進捗バーの更新)
-                *
-                * @param progressEvent 進捗情報
-         */
-               @Override
-               public void onProgress(ProgressEvent progressEvent)
-               {
-                       //
-                       if (downloadDialog != null)
-                       {
-                               int percent = (int)(progressEvent.getProgress() * 100.0f);
-                               downloadDialog.setProgress(percent);
-                               //downloadDialog.setCancelable(progressEvent.isCancellable()); // キャンセルできるようにしないほうが良さそうなので
-                       }
-               }
-
-               /**
-                *   ファイル受信終了時の処理
-                *
-                * @param bytes  受信バイト数
-         * @param map    ファイルの情報
-         */
-               @Override
-               public void onCompleted(byte[] bytes, Map<String, Object> map)
-               {
-/*
-            if (isGetInformation) {
-                // Exif情報をダイアログ表示して終わる
-                showExifInformation(bytes);
-                System.gc();
-                return;
-            }
 */
-            final String directoryPath = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DCIM).getPath() + "/" + getString(R.string.app_name2) + "/";
-            final String filepath = new File(directoryPath.toLowerCase(), filename).getPath();
-
-            // ファイルを保存する
-            try {
-                final File directory = new File(directoryPath);
-                if (!directory.exists()) {
-                    if (!directory.mkdirs()) {
-                        Log.v(TAG, "MKDIR FAIL. : " + directoryPath);
-                    }
-                }
-                FileOutputStream outputStream = new FileOutputStream(filepath);
-                outputStream.write(bytes);
-                outputStream.close();
-            } catch (Exception e) {
-                final String message = e.getMessage();
-                runOnUiThread(new Runnable() {
-                    @Override
-                    public void run() {
-                        if (downloadDialog != null) {
-                            downloadDialog.dismiss();
-                        }
-                        presentMessage(getString(R.string.download_control_save_failed), message);
-                    }
-                });
-                // ダウンロード失敗時には、ギャラリーにデータ登録を行わない。
-                return;
-            }
-
-            boolean hasGps = false;
-            float[] latLong = new float[2];
-            try
-            {
-                //
-                ExifInterface exif = new ExifInterface(filepath);
-                hasGps = exif.getLatLong(latLong);
-            }
-            catch (Exception e)
-            {
-                e.printStackTrace();
-            }
-
-                       // ギャラリーに受信したファイルを登録する
-                       try
-                       {
-                               long now = System.currentTimeMillis();
-                               ContentValues values = new ContentValues();
-                               values.put(Images.Media.MIME_TYPE, "image/jpeg");
-                               values.put(Images.Media.DATA, filepath);
-                               values.put(Images.Media.DATE_ADDED, now);
-                               values.put(Images.Media.DATE_TAKEN, now);
-                values.put(Images.Media.DATE_MODIFIED, now);
-                values.put(Images.Media.ORIENTATION, getRotationDegrees(bytes, map));
-                if (hasGps)
-                {
-                    values.put(MediaStore.Images.Media.LATITUDE, latLong[0]);
-                    values.put(MediaStore.Images.Media.LONGITUDE, latLong[1]);
-                }
-                Activity activity = getActivity();
-                if (activity != null)
-                {
-                    ContentResolver resolver = getActivity().getContentResolver();
-                    final Uri insertedImage = resolver.insert(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, values);
-                }
-
-                               runOnUiThread(new Runnable() {
-                                       @Override
-                                       public void run()
-                                       {
-                                               if (downloadDialog != null)
-                                               {
-                                                       downloadDialog.dismiss();
-                                               }
-                                               Toast.makeText(getActivity(), getString(R.string.download_control_save_success) + " " + filename, Toast.LENGTH_SHORT).show();
-/*
-                        try
-                        {
-                            SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(getContext());
-                            if (preferences.getBoolean(ICameraPropertyAccessor.SHARE_AFTER_SAVE, false))
-                            {
-                                shareContent(insertedImage);
-                            }
-                        }
-                        catch (Exception e)
-                        {
-                            e.printStackTrace();
-                        }
-*/
-                    }
-                               });
-                       } catch (Exception e) {
-                               final String message = e.getMessage();
-                               runOnUiThread(new Runnable() {
-                                       @Override
-                                       public void run() {
-                                               if (downloadDialog != null)
-                                               {
-                                                       downloadDialog.dismiss();
-                                               }
-                                               presentMessage(getString(R.string.download_control_save_failed), message);
-                                       }
-                               });
-                       }
-                       System.gc();
-               }
-
-        /**
-         *   エラー発生時の処理
-         *
-         * @param e エラーの情報
-         */
-               @Override
-               public void onErrorOccurred(Exception e)
-               {
-                       final String message = e.getMessage();
-                       runOnUiThread(new Runnable()
-                       {
-                               @Override
-                               public void run()
-                               {
-                                       if (downloadDialog != null)
-                                       {
-                                               downloadDialog.dismiss();
-                                       }
-                    if (isGetInformation)
-                    {
-                        presentMessage(getString(R.string.download_control_get_information_failed), message);
-                    }
-                    else
-                    {
-                        presentMessage(getString(R.string.download_control_download_failed), message);
-                    }
-                               }
-                       });
-               }
-
-        /**
-         *   共有の呼び出し
-         *
-         * @param pictureUri  画像ファイル名
-         */
-        private void shareContent(final Uri pictureUri)
-        {
-            Intent intent = new Intent();
-            intent.setAction(Intent.ACTION_SEND);
-            try
-            {
-                intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
-                intent.setType("image/jpeg");
-                intent.putExtra(Intent.EXTRA_STREAM, pictureUri);
-                getActivity().startActivityForResult(intent, 0);
-            }
-            catch (Exception e)
-            {
-                e.printStackTrace();
-                Log.v(TAG, " URI : " + pictureUri);
-            }
-        }
-
-
-
-        /**
-         *   EXIF情報の表示 (ExifInterface を作って、表示クラスに渡す)
-         *
-         * @param bytes データ並び
-         */
-        private void showExifInformation(byte[] bytes)
-        {
-            ExifInterface exif = null;
-            try
-            {
-                Calendar calendar = Calendar.getInstance();
-                String filename = new SimpleDateFormat("yyyyMMdd_HHmmss", Locale.getDefault()).format(calendar.getTime());
-                File tempFile = File.createTempFile(filename, null);
-                {
-                    FileOutputStream outStream = new FileOutputStream(tempFile.getAbsolutePath());
-                    outStream.write(bytes);
-                    outStream.close();
-                }
-                exif = new ExifInterface(tempFile.getAbsolutePath());
-                if (!tempFile.delete())
-                {
-                    Log.v(TAG, "temp file delete failure.");
-                }
-            }
-            catch (IOException e)
-            {
-                e.printStackTrace();
-            }
-            runOnUiThread(new ExifInfoToShow(exif));
-        }
-
-        /**
-         *   EXIF情報を表示する処理
-         *   (クラス生成時に、表示情報を作り出す)
-         */
-        private class ExifInfoToShow implements Runnable
-        {
-            private String message = "";
-
-            /**
-             *   コンストラクタ
-             * @param information メッセージ
-             */
-            ExifInfoToShow(ExifInterface information)
-            {
-                this.message = formMessage(information);
-            }
-
-            /**
-             *   Exif情報を表示に適した形式に変更し、情報を表示する
-             * @param exifInterface Exif情報
-             * @return 表示に適したExif情報
-             */
-            private String formMessage(ExifInterface exifInterface)
-            {
-                String msg = "";
-                if (exifInterface != null) {
-                                       // 撮影時刻
-                                       msg = msg + getString(R.string.exif_datetime_title);
-                                       msg = msg + " " + getExifAttribute(exifInterface, ExifInterface.TAG_DATETIME) + "\r\n"; //(string)
-                                       //msg = msg + "\r\n";
-
-                                       // 焦点距離
-                                       double focalLength = exifInterface.getAttributeDouble(ExifInterface.TAG_FOCAL_LENGTH, 0.0f);
-                                       msg = msg + getString(R.string.exif_focal_length_title);
-                                       msg = msg + " " + String.valueOf(focalLength) + "mm ";
-                                       msg = msg + "(" + getString(R.string.exif_focal_35mm_equiv_title) + " " + String.valueOf(focalLength * 2.0d) + "mm)" + "\r\n";
-                                       msg = msg + "\r\n";
-
-                                       // カスタムイメージプロセッシング利用の有無
-                                       //if (exifInterface.getAttributeInt(ExifInterface.TAG_CUSTOM_RENDERED, 0) != 0)
-                                       //{
-                                       //      msg = msg + getString(R.string.exif_custom_process_title) + "\r\n";
-                                       //}
-
-                                       // 撮影モード
-                                       String[] stringArray = getResources().getStringArray(R.array.exif_exposure_program_value);
-                                       int exposureProgram = exifInterface.getAttributeInt(ExifInterface.TAG_EXPOSURE_PROGRAM, 0);
-                                       msg = msg + getString(R.string.exif_camera_mode_title);
-                                       msg = msg + " " + ((stringArray.length > exposureProgram) ? stringArray[exposureProgram] : ("? (" + exposureProgram + ")")) + "\r\n";
-                                       //msg = msg + "\r\n";
-
-                                       // 測光モードの表示
-                                       String[] meteringStringArray = getResources().getStringArray(R.array.exif_metering_mode_value);
-                                       int metering = exifInterface.getAttributeInt(ExifInterface.TAG_METERING_MODE, 0);
-                                       msg = msg + getString(R.string.exif_metering_mode_title);
-                                       msg = msg + " " + ((meteringStringArray.length > metering) ? meteringStringArray[metering] : ("? (" + metering + ")")) + "\r\n";
-                                       //msg = msg + "\r\n";
-
-                    // 露光時間
-                    msg = msg + getString(R.string.exif_exposure_time_title);
-                                       String expTime =  getExifAttribute(exifInterface, ExifInterface.TAG_EXPOSURE_TIME);
-                                       float val, inv = 0.0f;
-                                       try
-                                       {
-                                               val = Float.parseFloat(expTime);
-                                               if (val < 1.0f)
-                                               {
-                                                       inv = 1.0f / val;
-                                               }
-                                               if (inv < 2.0f)  // if (inv < 10.0f)
-                                               {
-                                                       inv = 0.0f;
-                                               }
-                                       }
-                                       catch (Exception e)
-                                       {
-                                               //
-                                               e.printStackTrace();
-                                       }
-
-                    //msg = msg + " " + expTime + "s "; //(string)
-                                       if (inv > 0.0f)
-                                       {
-                        // シャッター速度を分数で表示する
-                        int intValue = (int) inv;
-                        int modValue = intValue % 10;
-                        if ((modValue == 9)||(modValue == 4))
-                        {
-                            // ちょっと格好が悪いけど...切り上げ
-                            intValue++;
-                        }
-                        msg = msg + " 1/" + intValue + " s ";
-                                       }
-                    else
-                    {
-                        // シャッター速度を数値(秒数)で表示する
-                        msg = msg + " " + expTime + "s "; //(string)
-                    }
-                                       msg = msg + "\r\n";
-
-                    // 絞り値
-                    msg = msg + getString(R.string.exif_aperture_title);
-                    msg = msg + " " + getExifAttribute(exifInterface, ExifInterface.TAG_F_NUMBER) + "\r\n";  // (string)
-
-                    // ISO感度
-                    msg = msg + getString(R.string.exif_iso_title);
-                    msg = msg + " " + getExifAttribute(exifInterface, ExifInterface.TAG_ISO_SPEED_RATINGS) + "\r\n";  // (string)
-
-                    msg = msg + "\r\n";
-
-                    // カメラの製造元
-                    msg = msg + getString(R.string.exif_maker_title);
-                    msg = msg + " " + getExifAttribute(exifInterface, ExifInterface.TAG_MAKE) + "\r\n";
-
-                    // カメラのモデル名
-                    msg = msg + getString(R.string.exif_camera_title);
-                    msg = msg + " " + getExifAttribute(exifInterface, ExifInterface.TAG_MODEL)+ "\r\n";  // (string)
-
-                                       String lat = getExifAttribute(exifInterface, ExifInterface.TAG_GPS_LATITUDE);
-                                       if ((lat != null)&&(lat.length() > 0))
-                                       {
-                        // 「位置情報あり」と表示
-                                               msg = msg + "\r\n  " + getString(R.string.exif_with_gps) + "\r\n";
-                                       }
-                    //msg = msg + getExifAttribute(exifInterface, ExifInterface.TAG_FLASH);      // フラッシュ (int)
-                    //msg = msg + getExifAttribute(exifInterface, ExifInterface.TAG_ORIENTATION);  // 画像の向き (int)
-                    //msg = msg + getExifAttribute(exifInterface, ExifInterface.TAG_WHITE_BALANCE);  // ホワイトバランス (int)
-
-                    // その他の情報...EXIFタグで取得できたものをログにダンプする
-                    msg = msg + ExifInformationDumper.dumpExifInformation(exifInterface, false);
-                }
-                else
-                {
-                    msg = getString(R.string.download_control_get_information_failed);
-                }
-                return (msg);
-            }
-
-            private String getExifAttribute(ExifInterface attr, String tag)
-            {
-                String value = attr.getAttribute(tag);
-                if (value == null)
-                {
-                    value = "";
-                }
-                return (value);
-            }
-
-
-            @Override
-            public void run()
-            {
-                if (downloadDialog != null)
-                {
-                    downloadDialog.dismiss();
-                }
-                presentMessage(getString(R.string.download_control_get_information_title), message);
-                System.gc();
-            }
-        }
-    }
-
-       /**
-        *   動画(とRAWファイル)のダウンロード
-        *
-        */
-       private class MyMovieDownloader implements IDownloadLargeContentCallback
-       {
-               private ProgressDialog downloadDialog = null;
-               private String filename = null;
-               private String filepath = null;
-               private FileOutputStream outputStream = null;
-
-               /**
-                *   コンストラクタ
-                *
-                * @param filename ファイル名
-                */
-               MyMovieDownloader(final String filename)
-               {
-                       this.filename = filename;
-               }
-
-               /**
-                *   ダウンロードの開始
-                *
-                */
-               void startDownload()
-               {
-                       Log.v(TAG, "startDownload() " + filename);
-                       downloadDialog = new ProgressDialog(getContext());
-                       downloadDialog.setTitle(getString(R.string.dialog_download_file_title));
-                       downloadDialog.setMessage(getString(R.string.dialog_download_message) + " " + filename);
-                       downloadDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
-                       downloadDialog.setCancelable(false);
-                       downloadDialog.show();
-
-                       // Download the image.
-            try
-            {
-                ImageContentInfoEx content = contentList.get(contentIndex);
-                ICameraFileInfo file = content.getFileInfo();
-                String targetFileName = file.getFilename();
-                if (content.hasRaw())
-                {
-                    targetFileName = targetFileName.replace(".JPG", ".ORF");
-                }
-                String path = file.getDirectoryPath() + "/" + targetFileName;
-                Log.v(TAG, "downloadLargeContent : " + path);
-                playbackControl.downloadLargeContent(path, this);
-
-                final String directoryPath = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DCIM).getPath() + "/" + getString(R.string.app_name2) + "/";
-                filepath = new File(directoryPath.toLowerCase(), filename).getPath();
-                try {
-                    final File directory = new File(directoryPath);
-                    if (!directory.exists())
-                    {
-                        if (!directory.mkdirs())
-                        {
-                            Log.v(TAG, "MKDIR FAIL. : " + directoryPath);
-                        }
-                    }
-                    outputStream = new FileOutputStream(filepath);
-                }
-                catch (Exception e)
-                {
-                    final String message = e.getMessage();
-                    runOnUiThread(new Runnable() {
-                        @Override
-                        public void run() {
-                            if (downloadDialog != null) {
-                                downloadDialog.dismiss();
-                            }
-                            presentMessage(getString(R.string.download_control_save_failed), message);
-                        }
-                    });
-                }
-            }
-            catch (Exception ex)
-            {
-                ex.printStackTrace();
-            }
-               }
-
-               @Override
-               public void onProgress(byte[] bytes, ProgressEvent progressEvent)
-               {
-                       if (downloadDialog != null)
-                       {
-                               int percent = (int)(progressEvent.getProgress() * 100.0f);
-                               downloadDialog.setProgress(percent);
-                               //downloadDialog.setCancelable(progressEvent.isCancellable()); // キャンセルできるようにしないほうが良さそうなので
-                       }
-                       try
-                       {
-                               if (outputStream != null)
-                               {
-                                       outputStream.write(bytes);
-                               }
-                       }
-            catch (Exception e)
-                       {
-                e.printStackTrace();
-                       }
-               }
-
-               @Override
-               public void onCompleted()
-               {
-                       try
-                       {
-                               if (outputStream != null)
-                               {
-                                       outputStream.flush();
-                                       outputStream.close();
-                    outputStream = null;
-                               }
-                if (!filename.endsWith(RAW_SUFFIX))
-                {
-                    // ギャラリーに受信したファイルを登録する
-                    long now = System.currentTimeMillis();
-                    ContentValues values = new ContentValues();
-                    ContentResolver resolver = getActivity().getContentResolver();
-                    values.put(Images.Media.MIME_TYPE, "video/mp4");
-                    values.put(Images.Media.DATA, filepath);
-                    values.put(Images.Media.DATE_ADDED, now);
-                    values.put(Images.Media.DATE_TAKEN, now);
-                    values.put(Images.Media.DATE_MODIFIED, now);
-                                       final Uri content = resolver.insert(MediaStore.Video.Media.EXTERNAL_CONTENT_URI, values);
-/*
-                    try
-                    {
-                        SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(getContext());
-                        if (preferences.getBoolean(ICameraPropertyAccessor.SHARE_AFTER_SAVE, false))
-                        {
-                            runOnUiThread(new Runnable()
-                            {
-                                @Override
-                                public void run()
-                                {
-                                    shareContent(content);
-                                }
-                            });
-                        }
-                    }
-                    catch (Exception e)
-                    {
-                        e.printStackTrace();
-                    }
-*/
-                }
-                               runOnUiThread(new Runnable() {
-                                       @Override
-                                       public void run()
-                                       {
-                                               if (downloadDialog != null)
-                                               {
-                                                       downloadDialog.dismiss();
-                                               }
-                                               Toast.makeText(getActivity(), getString(R.string.download_control_save_success) + " " + filename, Toast.LENGTH_SHORT).show();
-                        System.gc();
-                                       }
-                               });
-                       }
-                       catch (Exception e)
-                       {
-                               final String message = e.getMessage();
-                               runOnUiThread(new Runnable() {
-                                       @Override
-                                       public void run() {
-                                               if (downloadDialog != null)
-                                               {
-                                                       downloadDialog.dismiss();
-                                               }
-                                               presentMessage(getString(R.string.download_control_save_failed), message);
-                                       }
-                               });
-                       }
-            System.gc();
-               }
-
-               @Override
-               public void onErrorOccurred(Exception e)
-               {
-                       final String message = e.getMessage();
-            try
-            {
-                if (outputStream != null)
-                {
-                    outputStream.flush();
-                    outputStream.close();
-                    outputStream = null;
-                }
-            }
-            catch (Exception ex)
-            {
-                e.printStackTrace();
-                ex.printStackTrace();
-            }
-                       runOnUiThread(new Runnable()
-                       {
-                               @Override
-                               public void run()
-                               {
-                                       if (downloadDialog != null)
-                                       {
-                                               downloadDialog.dismiss();
-                                       }
-                                       presentMessage(getString(R.string.download_control_download_failed), message);
-                    System.gc();
-                               }
-                       });
-                       System.gc();
-               }
-
-        /**
-         *   共有の呼び出し
-         *
-         * @param movieFileUri  動画ファイルUri
-         */
-        private void shareContent(final Uri movieFileUri)
-        {
-            Intent intent = new Intent();
-            intent.setAction(Intent.ACTION_SEND);
-            try
-            {
-                intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
-                intent.setType("video/mp4");
-                intent.putExtra(Intent.EXTRA_STREAM, movieFileUri);
-                FragmentActivity activity = getActivity();
-                if (activity != null)
-                {
-                                       activity.startActivityForResult(intent, 0);
-                               }
-            }
-            catch (Exception e)
-            {
-                e.printStackTrace();
-            }
-        }
-       }
 }
diff --git a/app/src/main/java/net/osdn/gokigen/gr2control/playback/detail/MyContentDownloader.java b/app/src/main/java/net/osdn/gokigen/gr2control/playback/detail/MyContentDownloader.java
new file mode 100644 (file)
index 0000000..00cd080
--- /dev/null
@@ -0,0 +1,300 @@
+package net.osdn.gokigen.gr2control.playback.detail;
+
+import android.app.Activity;
+import android.app.AlertDialog;
+import android.app.ProgressDialog;
+import android.content.ContentResolver;
+import android.content.ContentValues;
+import android.content.Intent;
+import android.content.SharedPreferences;
+import android.net.Uri;
+import android.os.Environment;
+import android.provider.MediaStore;
+import android.support.annotation.NonNull;
+import android.support.v7.preference.PreferenceManager;
+import android.util.Log;
+import android.widget.Toast;
+
+import net.osdn.gokigen.gr2control.R;
+import net.osdn.gokigen.gr2control.camera.ICameraFileInfo;
+import net.osdn.gokigen.gr2control.camera.playback.IDownloadContentCallback;
+import net.osdn.gokigen.gr2control.camera.playback.IPlaybackControl;
+import net.osdn.gokigen.gr2control.camera.playback.ProgressEvent;
+import net.osdn.gokigen.gr2control.preference.IPreferencePropertyAccessor;
+
+import java.io.File;
+import java.io.FileOutputStream;
+
+/**
+ *   コンテントのダウンロード
+ *
+ */
+class MyContentDownloader implements IDownloadContentCallback
+{
+    private final String TAG = toString();
+    private final Activity activity;
+    private final IPlaybackControl playbackControl;
+    private static final String RAW_SUFFIX = ".DNG";
+    private static final String MOVIE_SUFFIX = ".MOV";
+    private static final String JPEG_SUFFIX = ".JPG";
+    private ProgressDialog downloadDialog = null;
+    private FileOutputStream outputStream = null;
+    private String targetFileName = "";
+    private String filepath = "";
+    private String mimeType = "image/jpeg";
+
+    /**
+     *   コンストラクタ
+     *
+     */
+    MyContentDownloader(@NonNull Activity activity, @NonNull final IPlaybackControl playbackControl)
+    {
+        this.activity = activity;
+        this.playbackControl = playbackControl;
+    }
+
+    /**
+     *   ダウンロードの開始
+     *
+     */
+    void startDownload(final ICameraFileInfo fileInfo, String replaceJpegSuffix, boolean isSmallSize)
+    {
+        if (fileInfo == null)
+        {
+            Log.v(TAG, "startDownload() ICameraFileInfo is NULL...");
+            return;
+        }
+        Log.v(TAG, "startDownload() " + fileInfo.getFilename());
+
+        // Download the image.
+        try
+        {
+            ////// ダイアログの表示
+            activity.runOnUiThread(new Runnable() {
+                @Override
+                public void run() {
+                    downloadDialog = new ProgressDialog(activity);
+                    downloadDialog.setTitle(activity.getString(R.string.dialog_download_file_title));
+                    downloadDialog.setMessage(activity.getString(R.string.dialog_download_message) + " " + fileInfo.getFilename());
+                    downloadDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
+                    downloadDialog.setCancelable(false);
+                    downloadDialog.show();
+                }
+            });
+
+            targetFileName = fileInfo.getFilename().toUpperCase();
+            if (replaceJpegSuffix != null)
+            {
+                targetFileName = targetFileName.replace(JPEG_SUFFIX, replaceJpegSuffix);
+            }
+            if (targetFileName.contains(RAW_SUFFIX))
+            {
+                mimeType = "image/x-adobe-dng";
+            }
+            else if (targetFileName.contains(MOVIE_SUFFIX))
+            {
+                mimeType =  "video/mp4";
+            }
+
+            String path = fileInfo.getDirectoryPath() + "/" + targetFileName;
+
+
+            final String directoryPath = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DCIM).getPath() + "/" + activity.getString(R.string.app_name2) + "/";
+            filepath = new File(directoryPath.toLowerCase(), targetFileName.toLowerCase()).getPath();
+            try
+            {
+                final File directory = new File(directoryPath);
+                if (!directory.exists())
+                {
+                    if (!directory.mkdirs())
+                    {
+                        Log.v(TAG, "MKDIR FAIL. : " + directoryPath);
+                    }
+                }
+                outputStream = new FileOutputStream(filepath);
+            }
+            catch (Exception e)
+            {
+                final String message = e.getMessage();
+                activity.runOnUiThread(new Runnable() {
+                    @Override
+                    public void run() {
+                        if (downloadDialog != null) {
+                            downloadDialog.dismiss();
+                        }
+                        presentMessage(activity.getString(R.string.download_control_save_failed), message);
+                    }
+                });
+            }
+            Log.v(TAG, "downloadContent : " + path + " (small: " + isSmallSize + ")");
+            playbackControl.downloadContent(path, isSmallSize, this);
+        }
+        catch (Exception ex)
+        {
+            ex.printStackTrace();
+        }
+    }
+
+    @Override
+    public void onProgress(byte[] bytes, ProgressEvent progressEvent)
+    {
+        if (downloadDialog != null)
+        {
+            int percent = (int)(progressEvent.getProgress() * 100.0f);
+            downloadDialog.setProgress(percent);
+            //downloadDialog.setCancelable(progressEvent.isCancellable()); // キャンセルできるようにしないほうが良さそうなので
+        }
+        try
+        {
+            if (outputStream != null)
+            {
+                outputStream.write(bytes);
+            }
+        }
+        catch (Exception e)
+        {
+            e.printStackTrace();
+        }
+    }
+
+    @Override
+    public void onCompleted()
+    {
+        try
+        {
+            if (outputStream != null)
+            {
+                outputStream.flush();
+                outputStream.close();
+                outputStream = null;
+            }
+            if (!targetFileName.endsWith(RAW_SUFFIX))
+            {
+                // ギャラリーに受信したファイルを登録する
+                long now = System.currentTimeMillis();
+                ContentValues values = new ContentValues();
+                ContentResolver resolver = activity.getContentResolver();
+                values.put(MediaStore.Images.Media.MIME_TYPE, mimeType);
+                values.put(MediaStore.Images.Media.DATA, filepath);
+                values.put(MediaStore.Images.Media.DATE_ADDED, now);
+                values.put(MediaStore.Images.Media.DATE_TAKEN, now);
+                values.put(MediaStore.Images.Media.DATE_MODIFIED, now);
+                final Uri content = resolver.insert(MediaStore.Video.Media.EXTERNAL_CONTENT_URI, values);
+                    try
+                    {
+                        SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(activity);
+                        if (preferences.getBoolean(IPreferencePropertyAccessor.SHARE_AFTER_SAVE, false))
+                        {
+                            activity.runOnUiThread(new Runnable()
+                            {
+                                @Override
+                                public void run()
+                                {
+                                    shareContent(content, mimeType);
+                                }
+                            });
+                        }
+                    }
+                    catch (Exception e)
+                    {
+                        e.printStackTrace();
+                    }
+            }
+            activity.runOnUiThread(new Runnable() {
+                @Override
+                public void run()
+                {
+                    if (downloadDialog != null)
+                    {
+                        downloadDialog.dismiss();
+                    }
+                    Toast.makeText(activity, activity.getString(R.string.download_control_save_success) + " " + targetFileName, Toast.LENGTH_SHORT).show();
+                    System.gc();
+                }
+            });
+        }
+        catch (Exception e)
+        {
+            final String message = e.getMessage();
+            activity.runOnUiThread(new Runnable() {
+                @Override
+                public void run() {
+                    if (downloadDialog != null)
+                    {
+                        downloadDialog.dismiss();
+                    }
+                    presentMessage(activity.getString(R.string.download_control_save_failed), message);
+                }
+            });
+        }
+        System.gc();
+    }
+
+    @Override
+    public void onErrorOccurred(Exception e)
+    {
+        final String message = e.getMessage();
+        try
+        {
+            if (outputStream != null)
+            {
+                outputStream.flush();
+                outputStream.close();
+                outputStream = null;
+            }
+        }
+        catch (Exception ex)
+        {
+            e.printStackTrace();
+            ex.printStackTrace();
+        }
+        activity.runOnUiThread(new Runnable()
+        {
+            @Override
+            public void run()
+            {
+                if (downloadDialog != null)
+                {
+                    downloadDialog.dismiss();
+                }
+                presentMessage(activity.getString(R.string.download_control_download_failed), message);
+                System.gc();
+            }
+        });
+        System.gc();
+    }
+
+    /**
+     *   共有の呼び出し
+     *
+     * @param fileUri  ファイルUri
+     */
+    private void shareContent(final Uri fileUri, final String contentType)
+    {
+        Intent intent = new Intent();
+        intent.setAction(Intent.ACTION_SEND);
+        try
+        {
+            intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
+            intent.setType(contentType);   // "video/mp4"  or "image/jpeg"  or "image/x-adobe-dng"
+            intent.putExtra(Intent.EXTRA_STREAM, fileUri);
+            activity.startActivityForResult(intent, 0);
+        }
+        catch (Exception e)
+        {
+            e.printStackTrace();
+        }
+    }
+
+    private void presentMessage(final String title, final String message)
+    {
+        activity.runOnUiThread(new Runnable() {
+            @Override
+            public void run() {
+                AlertDialog.Builder builder = new AlertDialog.Builder(activity);
+                builder.setTitle(title).setMessage(message);
+                builder.show();
+            }
+        });
+    }
+}
index 7fdaeab..ce183ab 100644 (file)
@@ -29,6 +29,8 @@ public interface IPreferencePropertyAccessor
 
     String SHOW_GRID_STATUS = "show_grid";
 
+    String SHARE_AFTER_SAVE = "share_after_save";
+
     String DIGITAL_ZOOM_LEVEL = "digital_zoom_level";
     String DIGITAL_ZOOM_LEVEL_DEFAULT_VALUE = "1.0";
 
index e23eac8..a62fddb 100644 (file)
@@ -4,6 +4,6 @@
         android:viewportWidth="24.0"
         android:viewportHeight="24.0">
     <path
-        android:fillColor="#FF000000"
+        android:fillColor="#FF444444"
         android:pathData="M17,10.5V7c0,-0.55 -0.45,-1 -1,-1H4c-0.55,0 -1,0.45 -1,1v10c0,0.55 0.45,1 1,1h12c0.55,0 1,-0.45 1,-1v-3.5l4,4v-11l-4,4z"/>
 </vector>