OSDN Git Service

OPCで一括ダウンロードできるようにする。Smallサイズ取得も可能にする。
authorMRSa <mrsa@myad.jp>
Thu, 21 Mar 2019 13:07:14 +0000 (22:07 +0900)
committerMRSa <mrsa@myad.jp>
Thu, 21 Mar 2019 13:07:14 +0000 (22:07 +0900)
app/src/main/java/net/osdn/gokigen/pkremote/calendar/CalendarFragment.java
app/src/main/java/net/osdn/gokigen/pkremote/camera/playback/CameraContentsRecognizer.java
app/src/main/java/net/osdn/gokigen/pkremote/camera/vendor/olympus/wrapper/playback/OlyCameraPlaybackControl.java
app/src/main/java/net/osdn/gokigen/pkremote/camera/vendor/ricoh/wrapper/RicohGr2PlaybackControl.java
app/src/main/java/net/osdn/gokigen/pkremote/camera/vendor/ricoh/wrapper/connection/RicohGr2Connection.java
app/src/main/java/net/osdn/gokigen/pkremote/playback/ImageGridViewFragment.java
app/src/main/java/net/osdn/gokigen/pkremote/playback/detail/MyContentDownloader.java
app/src/main/java/net/osdn/gokigen/pkremote/scene/CameraSceneUpdater.java
app/src/main/res/values/strings.xml

index 0b4faf8..8a36888 100644 (file)
@@ -15,6 +15,8 @@ import android.widget.Button;
 import android.widget.ImageButton;
 import android.widget.TextView;
 
+import com.google.android.material.snackbar.Snackbar;
+
 import net.osdn.gokigen.pkremote.R;
 import net.osdn.gokigen.pkremote.camera.interfaces.IInterfaceProvider;
 import net.osdn.gokigen.pkremote.camera.interfaces.playback.ICameraContent;
@@ -58,6 +60,7 @@ public class CalendarFragment extends Fragment  implements View.OnClickListener,
 
     private int currentYear = 0;
     private int currentMonth = 0;
+    private boolean fragmentIsActive = false;
 
     private static final List<Integer> dayLabelList = new ArrayList<Integer>()
     {
@@ -265,6 +268,28 @@ public class CalendarFragment extends Fragment  implements View.OnClickListener,
         return (myView);
     }
 
+
+    @Override
+    public void onResume()
+    {
+        super.onResume();
+
+        fragmentIsActive = true;
+    }
+
+
+    @Override
+    public void onPause()
+    {
+        super.onPause();
+        fragmentIsActive = false;
+    }
+
+    public boolean isFragmentActive()
+    {
+        return (fragmentIsActive);
+    }
+
     /**
      *   クリックされたときの処理
      */
@@ -580,7 +605,7 @@ public class CalendarFragment extends Fragment  implements View.OnClickListener,
     }
 
     /**
-     *
+     *    画像ファイル一覧が取得できた後の処理
      *
      *
      */
@@ -588,6 +613,21 @@ public class CalendarFragment extends Fragment  implements View.OnClickListener,
     public void contentsListCreated(int nofContents)
     {
         Log.v(TAG, "contentsListCreated() : " + nofContents);
+        if (nofContents == 0)
+        {
+            // コンテンツが1件も取得できなかった
+            final Activity activity = getActivity();
+            if (activity != null)
+            {
+                // コンテンツないよ、を表示する
+                activity.runOnUiThread(new Runnable() {
+                    @Override
+                    public void run() {
+                        Snackbar.make(activity.findViewById(R.id.fragment1), R.string.get_camera_contents_is_nothing, Snackbar.LENGTH_SHORT).show();
+                    }
+                });
+            }
+        }
         try
         {
             SparseArray<ICameraContent> imageMaps = new SparseArray<>();
index e42aeec..62853ab 100644 (file)
@@ -119,7 +119,8 @@ public class CameraContentsRecognizer implements ICameraContentsRecognizer, ICam
                 contentsListCallback.contentsListCreated(contentList.size());
                 if (informationReceiver != null)
                 {
-                    informationReceiver.updateMessage(activity.getString(R.string.get_camera_contents_finished), false, false, 0);
+                    String message = activity.getString(R.string.get_camera_contents_finished) + " : " + contentList.size();
+                    informationReceiver.updateMessage(message, false, false, 0);
                 }
 
                 // 最新の撮影データから並べる
index 779dded..9d7b679 100644 (file)
@@ -27,7 +27,7 @@ public class OlyCameraPlaybackControl implements IPlaybackControl
 {
     private final String TAG = toString();
     private final OLYCamera camera;
-    private List<OLYCamera> list;
+    //private List<OLYCamera> list;
 
     public OlyCameraPlaybackControl(@NonNull OLYCamera camera)
     {
@@ -45,6 +45,7 @@ public class OlyCameraPlaybackControl implements IPlaybackControl
     {
         try
         {
+            changeRunModePlayback();
             camera.downloadContentList(new OLYCamera.DownloadContentListCallback() {
                 @Override
                 public void onCompleted(List<OLYCameraFileInfo> list)
@@ -106,6 +107,7 @@ public class OlyCameraPlaybackControl implements IPlaybackControl
     {
         try
         {
+            changeRunModePlayback();
             camera.downloadContentScreennail(path, new OLYCamera.DownloadImageCallback() {
                 @Override
                 public void onProgress(OLYCamera.ProgressEvent progressEvent)
@@ -146,6 +148,7 @@ public class OlyCameraPlaybackControl implements IPlaybackControl
     {
         try
         {
+            changeRunModePlayback();
             camera.downloadContentThumbnail(path, new OLYCamera.DownloadImageCallback() {
                 @Override
                 public void onProgress(OLYCamera.ProgressEvent progressEvent)
@@ -186,51 +189,137 @@ public class OlyCameraPlaybackControl implements IPlaybackControl
     {
         try
         {
-            camera.downloadLargeContent(path, new OLYCamera.DownloadLargeContentCallback() {
-                @Override
-                public void onProgress(byte[] bytes, OLYCamera.ProgressEvent progressEvent)
+            changeRunModePlayback();
+            if (path.toLowerCase().endsWith(".jpg"))
+            {
+                // JPEGはスモールサイズで取得する
+                downloadJpegContent(path, isSmallSize, callback);
+            }
+            else
+            {
+                downloadLargeContent(path, callback);
+            }
+        }
+        catch (Exception e)
+        {
+            e.printStackTrace();
+            callback.onErrorOccurred(e);
+        }
+    }
+
+    private void downloadJpegContent(@NonNull String path, boolean isSmallSize, @NonNull final IDownloadContentCallback callback)
+    {
+        float imageSize = (isSmallSize) ? OLYCamera.IMAGE_RESIZE_1600 : OLYCamera.IMAGE_RESIZE_NONE;
+
+        camera.downloadImage(path, imageSize, new OLYCamera.DownloadImageCallback()
+        {
+            @Override
+            public void onProgress(OLYCamera.ProgressEvent progressEvent)
+            {
+                try
                 {
-                    try
-                    {
-                        callback.onProgress(bytes, bytes.length, new ProgressEvent(progressEvent.getProgress(), null));
-                    }
-                    catch (Exception e)
-                    {
-                        e.printStackTrace();
-                    }
+                    callback.onProgress(null, 0, new ProgressEvent(progressEvent.getProgress(), null));
+                    //Log.v(TAG, "progressEvent.getProgress() : " + progressEvent.getProgress());
+                }
+                catch (Exception e)
+                {
+                    e.printStackTrace();
                 }
+            }
 
-                @Override
-                public void onCompleted()
+            @Override
+            public void onCompleted(byte[] bytes, Map<String, Object> map)
+            {
+                try
                 {
-                    try
-                    {
-                        callback.onCompleted();
-                    }
-                    catch (Exception e)
-                    {
-                        e.printStackTrace();
-                    }
+                    callback.onProgress(bytes, bytes.length, new ProgressEvent(1.0f, null));
+                    callback.onCompleted();
+                }
+                catch (Exception e)
+                {
+                    e.printStackTrace();
                 }
+            }
 
-                @Override
-                public void onErrorOccurred(Exception e)
+            @Override
+            public void onErrorOccurred(Exception e)
+            {
+                try
                 {
-                    try
-                    {
-                        callback.onErrorOccurred(e);
-                    }
-                    catch (Exception ee)
-                    {
-                        ee.printStackTrace();
-                    }
+                    callback.onErrorOccurred(e);
                 }
-            });
+                catch (Exception ee)
+                {
+                    ee.printStackTrace();
+                }
+            }
+        });
+    }
+
+    private void downloadLargeContent(@NonNull String path, @NonNull final IDownloadContentCallback callback)
+    {
+        camera.downloadLargeContent(path, new OLYCamera.DownloadLargeContentCallback()
+        {
+            @Override
+            public void onProgress(byte[] bytes, OLYCamera.ProgressEvent progressEvent)
+            {
+                try
+                {
+                    callback.onProgress(bytes, bytes.length, new ProgressEvent(progressEvent.getProgress(), null));
+                }
+                catch (Exception e)
+                {
+                    e.printStackTrace();
+                }
+            }
+
+            @Override
+            public void onCompleted()
+            {
+                try
+                {
+                    callback.onCompleted();
+                }
+                catch (Exception e)
+                {
+                    e.printStackTrace();
+                }
+            }
+
+            @Override
+            public void onErrorOccurred(Exception e)
+            {
+                try
+                {
+                    callback.onErrorOccurred(e);
+                }
+                catch (Exception ee)
+                {
+                    ee.printStackTrace();
+                }
+            }
+        });
+    }
+
+
+
+    /**
+     *    ことあるごとに、とにかくRunMode を Playbackにする
+     *    (たまに外れることがあるので...)
+     *
+     */
+    private void changeRunModePlayback()
+    {
+        try
+        {
+            if (camera.getRunMode() != OLYCamera.RunMode.Playback)
+            {
+                camera.changeRunMode(OLYCamera.RunMode.Playback);
+            }
         }
         catch (Exception e)
         {
             e.printStackTrace();
-            callback.onErrorOccurred(e);
         }
     }
 
@@ -244,6 +333,7 @@ public class OlyCameraPlaybackControl implements IPlaybackControl
         }
         try
         {
+            changeRunModePlayback();
             camera.downloadContentList(new OLYCamera.DownloadContentListCallback()
             {
                 @Override
index 2223973..6d363cf 100644 (file)
@@ -288,7 +288,8 @@ public class RicohGr2PlaybackControl implements IPlaybackControl
      */
     private Date getCameraContentDate(@NonNull ICameraContent cameraContent)
     {
-/**/
+        // 各ファイルを個別に撮影時刻をとると、反応が悪すぎるので処理を抑止。
+/*
         String fileInfo;
         try
         {
@@ -307,7 +308,7 @@ public class RicohGr2PlaybackControl implements IPlaybackControl
         {
             e.printStackTrace();
         }
-/**/
+*/
         return (cameraContent.getCapturedDate());
     }
 
@@ -415,31 +416,37 @@ public class RicohGr2PlaybackControl implements IPlaybackControl
         }
         try
         {
+            Log.v(TAG, "PHOTO LIST RECV: [" + contentList.length() + "]");
             String cameraId = statusChecker.getCameraId();
             JSONArray dirsArray = new JSONObject(contentList).getJSONArray("dirs");
             if (dirsArray != null)
             {
                 int size = dirsArray.length();
+                Log.v(TAG, "DIRECTORIES : " + size);
                 for (int index = 0; index < size; index++)
                 {
                     JSONObject object = dirsArray.getJSONObject(index);
                     String dirName = object.getString("name");
                     JSONArray filesArray = object.getJSONArray("files");
                     int nofFiles = filesArray.length();
+                    Log.v(TAG, "FILES : [" + dirName + "] " + nofFiles);
                     for (int fileIndex = 0; fileIndex < nofFiles; fileIndex++)
                     {
                         String fileName = filesArray.getString(fileIndex);
-                        ICameraContent cameraContent = new CameraContentInfo(cameraId, "sd1", dirName, fileName, new Date(2001, 1, 1));
+                        Log.v(TAG, "FILE : " + fileName);
+                        ICameraContent cameraContent = new CameraContentInfo(cameraId, "sd1", dirName, fileName, new Date());
                         cameraContent.setCapturedDate(getCameraContentDate(cameraContent));
                         fileList.add(cameraContent);
                     }
                 }
             }
+            else
+            {
+                Log.v(TAG, "NOT FOUND dirs array.");
+            }
         }
         catch (Exception e)
         {
-            //callback.onErrorOccurred(e);
-            //return;
             e.printStackTrace();
             try {
                 fileList.clear();
index 37a0be8..4be0024 100644 (file)
@@ -212,7 +212,14 @@ public class RicohGr2Connection implements ICameraConnection
             @Override
             public void run()
             {
-                builder.show();
+                try
+                {
+                    builder.show();
+                }
+                catch (Exception e)
+                {
+                    e.printStackTrace();
+                }
             }
         });
     }
index b714ca9..293ef4e 100644 (file)
@@ -278,12 +278,14 @@ public class ImageGridViewFragment extends Fragment implements AdapterView.OnIte
         Log.v(TAG, "onPause() Start");
         try
         {
+/*
+            // Playbackモードでしか使わないので、RunMode は変更しない
             if (!runMode.isRecordingMode())
             {
                 // Threadで呼んではダメみたいだ...
                 runMode.changeRunMode(true);
             }
-
+*/
             //  アクションバーは隠した状態に戻しておく
             AppCompatActivity activity = (AppCompatActivity) getActivity();
             if (activity != null)
@@ -563,6 +565,19 @@ public class ImageGridViewFragment extends Fragment implements AdapterView.OnIte
 
                                 // 画像の選択を落とす
                                 content.setSelected(false);
+
+                                // ここでダウンロードが終わるまで、すこし待つ
+                                do
+                                {
+                                    try
+                                    {
+                                        Thread.sleep(300);
+                                    }
+                                    catch (Exception e)
+                                    {
+                                        e.printStackTrace();
+                                    }
+                                } while (contentDownloader.isDownloading());
                             }
                         }
 
index 011cfe1..1f39f81 100644 (file)
@@ -49,6 +49,7 @@ public class MyContentDownloader implements IDownloadContentCallback
     private String targetFileName = "";
     private String filepath = "";
     private String mimeType = "image/jpeg";
+    private boolean isDownloading = false;
 
     /**
      *   コンストラクタ
@@ -76,6 +77,7 @@ public class MyContentDownloader implements IDownloadContentCallback
         // Download the image.
         try
         {
+            isDownloading = true;
             Calendar calendar = Calendar.getInstance();
             String extendName = new SimpleDateFormat("yyyyMMdd-HHmmss", Locale.getDefault()).format(calendar.getTime());
             targetFileName = fileInfo.getContentName().toUpperCase();
@@ -111,8 +113,12 @@ public class MyContentDownloader implements IDownloadContentCallback
             ////// ダイアログの表示
             activity.runOnUiThread(new Runnable() {
                 @Override
-                public void run() {
-                    downloadDialog = new ProgressDialog(activity);
+                public void run()
+                {
+                    if (downloadDialog == null)
+                    {
+                        downloadDialog = new ProgressDialog(activity);
+                    }
                     downloadDialog.setTitle(activity.getString(R.string.dialog_download_file_title) + appendTitle);
                     downloadDialog.setMessage(activity.getString(R.string.dialog_download_message) + " " + targetFileName);
                     downloadDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
@@ -136,6 +142,9 @@ public class MyContentDownloader implements IDownloadContentCallback
                     }
                 }
                 outputStream = new FileOutputStream(filepath);
+
+                Log.v(TAG, "downloadContent : " + path + " (small: " + isSmallSize + ")");
+                playbackControl.downloadContent(path, isSmallSize, this);
             }
             catch (Exception e)
             {
@@ -146,16 +155,33 @@ public class MyContentDownloader implements IDownloadContentCallback
                         if (downloadDialog != null) {
                             downloadDialog.dismiss();
                         }
+                        downloadDialog = null;
+                        isDownloading = false;
                         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();
+            activity.runOnUiThread(new Runnable() {
+                @Override
+                public void run() {
+                    try
+                    {
+                        if (downloadDialog != null) {
+                            downloadDialog.dismiss();
+                        }
+                    }
+                    catch (Exception e)
+                    {
+                        e.printStackTrace();
+                    }
+                    downloadDialog = null;
+                    isDownloading = false;
+                }
+            });
         }
     }
 
@@ -171,7 +197,7 @@ public class MyContentDownloader implements IDownloadContentCallback
         }
         try
         {
-            if (outputStream != null)
+            if ((outputStream != null)&&(length > 0))
             {
                 outputStream.write(bytes, 0, length);
             }
@@ -235,6 +261,8 @@ public class MyContentDownloader implements IDownloadContentCallback
                     {
                         downloadDialog.dismiss();
                     }
+                    downloadDialog = null;
+                    isDownloading = false;
                     View view = activity.findViewById(R.id.fragment1);
                     Snackbar.make(view, activity.getString(R.string.download_control_save_success) + " " + targetFileName, Snackbar.LENGTH_SHORT).show();
                     //Toast.makeText(activity, activity.getString(R.string.download_control_save_success) + " " + targetFileName, Toast.LENGTH_SHORT).show();
@@ -252,6 +280,8 @@ public class MyContentDownloader implements IDownloadContentCallback
                     {
                         downloadDialog.dismiss();
                     }
+                    downloadDialog = null;
+                    isDownloading = false;
                     presentMessage(activity.getString(R.string.download_control_save_failed), message);
                 }
             });
@@ -262,9 +292,11 @@ public class MyContentDownloader implements IDownloadContentCallback
     @Override
     public void onErrorOccurred(Exception e)
     {
+        isDownloading = false;
         final String message = e.getMessage();
         try
         {
+            e.printStackTrace();
             if (outputStream != null)
             {
                 outputStream.flush();
@@ -274,7 +306,6 @@ public class MyContentDownloader implements IDownloadContentCallback
         }
         catch (Exception ex)
         {
-            e.printStackTrace();
             ex.printStackTrace();
         }
         activity.runOnUiThread(new Runnable()
@@ -286,13 +317,19 @@ public class MyContentDownloader implements IDownloadContentCallback
                 {
                     downloadDialog.dismiss();
                 }
+                downloadDialog = null;
+                isDownloading = false;
                 presentMessage(activity.getString(R.string.download_control_download_failed), message);
-                System.gc();
             }
         });
         System.gc();
     }
 
+    public boolean isDownloading()
+    {
+        return (isDownloading);
+    }
+
     /**
      *   共有の呼び出し
      *
index 8325763..d734f99 100644 (file)
@@ -34,9 +34,8 @@ public class CameraSceneUpdater implements ICameraStatusReceiver, IChangeScene,
     private final AppCompatActivity activity;
     private final BottomNavigationView bottomNavigationView;
     private IInterfaceProvider interfaceProvider;
-    private IStatusViewDrawer statusViewDrawer;
+    //private IStatusViewDrawer statusViewDrawer;
     private ICameraStatusReceiver anotherStatusReceiver = null;
-
     private PreferenceFragmentCompat preferenceFragment = null;
     private LogCatFragment logCatFragment = null;
     private CalendarFragment calendarFragment = null;
@@ -76,6 +75,7 @@ public class CameraSceneUpdater implements ICameraStatusReceiver, IChangeScene,
         changeSceneToCalendar();
     }
 
+/*
     //  CameraSceneUpdater
     public void registerInterface(@NonNull IStatusViewDrawer statusViewDrawer, @NonNull IInterfaceProvider interfaceProvider)
     {
@@ -83,6 +83,7 @@ public class CameraSceneUpdater implements ICameraStatusReceiver, IChangeScene,
         this.statusViewDrawer = statusViewDrawer;
         this.interfaceProvider = interfaceProvider;
     }
+*/
 
     // ICameraStatusReceiver
     @Override
@@ -90,6 +91,7 @@ public class CameraSceneUpdater implements ICameraStatusReceiver, IChangeScene,
     {
         Log.v(TAG, " CONNECTION MESSAGE : " + message);
         try {
+/*
             if (statusViewDrawer != null)
             {
                 statusViewDrawer.updateStatusView(message);
@@ -98,6 +100,7 @@ public class CameraSceneUpdater implements ICameraStatusReceiver, IChangeScene,
                     statusViewDrawer.updateConnectionStatus(connection.getConnectionStatus());
                 }
             }
+*/
             if (anotherStatusReceiver != null)
             {
                 anotherStatusReceiver.onStatusNotify(message);
@@ -117,12 +120,15 @@ public class CameraSceneUpdater implements ICameraStatusReceiver, IChangeScene,
             if (connection != null) {
                 connection.forceUpdateConnectionStatus(ICameraConnection.CameraConnectionStatus.CONNECTED);
             }
-            if (statusViewDrawer != null) {
+/*
+            if (statusViewDrawer != null)
+            {
                 statusViewDrawer.updateConnectionStatus(ICameraConnection.CameraConnectionStatus.CONNECTED);
 
                 // ライブビューの開始... 今回は手動化。
                 //statusViewDrawer.startLiveView();
             }
+*/
             if (anotherStatusReceiver != null) {
                 anotherStatusReceiver.onCameraConnected();
             }
@@ -143,10 +149,12 @@ public class CameraSceneUpdater implements ICameraStatusReceiver, IChangeScene,
         String message = activity.getString(R.string.camera_disconnected);
         updateConnectionStatus(message, ICameraConnection.CameraConnectionStatus.DISCONNECTED);
         try {
+/*
             if (statusViewDrawer != null) {
                 statusViewDrawer.updateStatusView(activity.getString(R.string.camera_disconnected));
                 statusViewDrawer.updateConnectionStatus(ICameraConnection.CameraConnectionStatus.DISCONNECTED);
             }
+*/
             if (anotherStatusReceiver != null) {
                 anotherStatusReceiver.onCameraDisconnected();
             }
@@ -160,7 +168,7 @@ public class CameraSceneUpdater implements ICameraStatusReceiver, IChangeScene,
     public void onCameraOccursException(String message, Exception e) {
         Log.v(TAG, "onCameraOccursException() " + message);
         try {
-            ICameraConnection.CameraConnectionStatus connectionStatus = ICameraConnection.CameraConnectionStatus.UNKNOWN;
+            ICameraConnection.CameraConnectionStatus connectionStatus;  // = ICameraConnection.CameraConnectionStatus.UNKNOWN;
 
             e.printStackTrace();
             ICameraConnection connection = getCameraConnection(interfaceProvider.getCammeraConnectionMethod());
@@ -169,12 +177,14 @@ public class CameraSceneUpdater implements ICameraStatusReceiver, IChangeScene,
                 connection.alertConnectingFailed(message + " " + e.getLocalizedMessage());
                 updateConnectionStatus(message, connectionStatus);
             }
+/*
             if (statusViewDrawer != null) {
                 statusViewDrawer.updateStatusView(message);
                 if (connection != null) {
                     statusViewDrawer.updateConnectionStatus(connectionStatus);
                 }
             }
+*/
             if (anotherStatusReceiver != null) {
                 anotherStatusReceiver.onCameraOccursException(message, e);
             }
@@ -465,5 +475,11 @@ public class CameraSceneUpdater implements ICameraStatusReceiver, IChangeScene,
     public void contentsListCreated(int nofContents)
     {
         Log.v(TAG, "contentsListCreated() : " + nofContents);
+
+        // カレンダー画面のリフレッシュを行いたい (かなり無理やり...)
+        if ((calendarFragment != null)&&(calendarFragment.isFragmentActive()))
+        {
+            calendarFragment.contentsListCreated(nofContents);
+        }
     }
 }
index b6efeee..83ac0b2 100644 (file)
 
     <string name="get_camera_contents_wait">Check contents&#8230; wait</string>
     <string name="get_camera_contents_error">Check contents&#8230; Error!</string>
-    <string name="get_camera_contents_finished">Check contents&#8230; finished</string>
+    <string name="get_camera_contents_finished">Contents </string>
     <string name="get_camera_contents_error_retry">Try Again?</string>
+    <string name="get_camera_contents_is_nothing">Camera content is nothing!</string>
 
     <string name="action_synchroize_datetime">Time Sync.</string>
     <string name="action_info">Information</string>