OSDN Git Service

画像の一括取得をできるようにしてみた。
authorMRSa <mrsa@myad.jp>
Mon, 18 Mar 2019 15:35:56 +0000 (00:35 +0900)
committerMRSa <mrsa@myad.jp>
Mon, 18 Mar 2019 15:35:56 +0000 (00:35 +0900)
app/src/main/java/net/osdn/gokigen/pkremote/playback/ImageGridViewFragment.java
app/src/main/java/net/osdn/gokigen/pkremote/playback/detail/ImagePagerViewFragment.java
app/src/main/java/net/osdn/gokigen/pkremote/playback/detail/MyContentDownloader.java
app/src/main/res/drawable/ic_refresh_grey_24dp.xml [new file with mode: 0644]
app/src/main/res/menu/image_grid_view.xml
app/src/main/res/values/strings.xml
app/src/main/res/xml/preferences_ricoh_gr2.xml

index ecba1e2..dcd2c98 100644 (file)
@@ -28,6 +28,7 @@ import net.osdn.gokigen.pkremote.camera.interfaces.playback.ICameraContentsRecog
 import net.osdn.gokigen.pkremote.camera.interfaces.playback.IPlaybackControl;
 import net.osdn.gokigen.pkremote.playback.detail.CameraContentEx;
 import net.osdn.gokigen.pkremote.playback.detail.ImagePagerViewFragment;
+import net.osdn.gokigen.pkremote.playback.detail.MyContentDownloader;
 import net.osdn.gokigen.pkremote.playback.grid.ImageGridViewAdapter;
 
 import java.util.ArrayList;
@@ -60,6 +61,7 @@ public class ImageGridViewFragment extends Fragment implements AdapterView.OnIte
        private static final String OLYMPUS_RAW_SUFFIX = ".orf";
        private static final String PENTAX_RAW_PEF_SUFFIX = ".pef";
 
+    private MyContentDownloader contentDownloader;
     private GridView gridView;
        private IInterfaceProvider interfaceProvider;
        private IPlaybackControl playbackControl;
@@ -84,6 +86,15 @@ public class ImageGridViewFragment extends Fragment implements AdapterView.OnIte
                this.interfaceProvider = interfaceProvider;
                this.playbackControl = interfaceProvider.getPlaybackControl();
                this.runMode = interfaceProvider.getCameraRunMode();
+        Activity activity = getActivity();
+        if (activity != null)
+        {
+            this.contentDownloader = new MyContentDownloader(getActivity(), playbackControl);
+        }
+        else
+        {
+            this.contentDownloader = null;
+        }
        }
 
        @Override
@@ -141,6 +152,23 @@ public class ImageGridViewFragment extends Fragment implements AdapterView.OnIte
                        refresh();
                        return (true);
                }
+        if (id == R.id.action_batch_download_original_size_raw)
+        {
+            // オリジナルサイズのダウンロード
+            startDownloadBatch(false);
+            return (true);
+        }
+        if (id == R.id.action_batch_download_640x480_raw)
+        {
+            // 小さいサイズのダウンロード
+            startDownloadBatch(true);
+            return (true);
+        }
+        if (id == R.id.action_select_all)
+        {
+            selectUnselectAll();
+            return (true);
+        }
                return (super.onOptionsItemSelected(item));
        }
        
@@ -227,7 +255,24 @@ public class ImageGridViewFragment extends Fragment implements AdapterView.OnIte
             // Threadで呼んではダメみたいだ...
             runMode.changeRunMode(true);
         }
-
+        try
+        {
+            //  アクションバーは隠した状態に戻しておく
+            AppCompatActivity activity = (AppCompatActivity) getActivity();
+            if (activity != null)
+            {
+                ActionBar bar = activity.getSupportActionBar();
+                if (bar != null)
+                {
+                    bar.hide();
+                }
+            }
+        }
+        catch (Exception e)
+        {
+            e.printStackTrace();
+        }
+        System.gc();
                if (!executor.isShutdown())
                {
                        executor.shutdownNow();
@@ -400,6 +445,137 @@ public class ImageGridViewFragment extends Fragment implements AdapterView.OnIte
         Log.v(TAG, "refreshImpl() end");
     }
 
+
+    /**
+     *   全選択・全選択解除
+     *
+     */
+    private void selectUnselectAll()
+    {
+        if ((imageContentList == null)||(imageContentList.size() == 0))
+        {
+            // 選択されていない時は終わる。
+            return;
+        }
+
+        int nofSelected = 0;
+        for (CameraContentEx content : imageContentList)
+        {
+            if (content.isSelected())
+            {
+                nofSelected++;
+            }
+        }
+
+        // 全部選択されているときは全選択解除・そうでない時は全選択
+        boolean setSelected = (nofSelected != imageContentList.size());
+        for (CameraContentEx content : imageContentList)
+        {
+            content.setSelected(setSelected);
+        }
+
+        // グリッドビューの再描画
+        redrawGridView();
+    }
+
+
+    /**
+     *    一括ダウンロードの開始
+     *
+     * @param isSmall  小さいサイズ(JPEG)
+     */
+    private void startDownloadBatch(final boolean isSmall)
+    {
+        try
+        {
+            if ((imageContentList == null)||(imageContentList.size() == 0))
+            {
+                // 画像が選択されていない場合にはなにもしない。
+                return;
+            }
+
+            // 念のため、contentDownloader がなければ作る
+            if (contentDownloader == null)
+            {
+                Activity activity = getActivity();
+                if (activity == null)
+                {
+                    // activityが取れない時には終わる。
+                    return;
+                }
+                this.contentDownloader = new MyContentDownloader(getActivity(), playbackControl);
+            }
+            Thread thread = new Thread(new Runnable()
+            {
+                @Override
+                public void run()
+                {
+                    try
+                    {
+                        // ダウンロード枚数を取得
+                        int totalSize = 0;
+                        for (CameraContentEx content : imageContentList)
+                        {
+                            if (content.isSelected())
+                            {
+                                totalSize++;
+                            }
+                        }
+                        if (totalSize == 0)
+                        {
+                            // 画像が選択されていなかった...終了する
+                            return;
+                        }
+                        int count = 1;
+                        for (CameraContentEx content : imageContentList)
+                        {
+                            if (content.isSelected())
+                            {
+                                contentDownloader.startDownload(content.getFileInfo(), " (" + count + "/" + totalSize + ") ", null, isSmall);
+                                count++;
+
+                                // 画像の選択を落とす
+                                content.setSelected(false);
+                            }
+                        }
+
+                        // グリッドビューの再描画
+                        redrawGridView();
+                    }
+                    catch (Exception e)
+                    {
+                        e.printStackTrace();
+                    }
+                }
+            });
+            thread.start();
+        }
+        catch (Exception e)
+        {
+            e.printStackTrace();
+        }
+    }
+
+    private void redrawGridView()
+    {
+        // グリッドビューの再描画
+        Activity activity = getActivity();
+        if (activity != null)
+        {
+            getActivity().runOnUiThread(new Runnable()
+            {
+                @Override
+                public void run()
+                {
+                    if (gridView != null)
+                    {
+                        gridView.invalidateViews();
+                    }
+                }
+            });
+        }
+    }
+
        private void runOnUiThread(Runnable action)
     {
                Activity activity = getActivity();
@@ -425,7 +601,7 @@ public class ImageGridViewFragment extends Fragment implements AdapterView.OnIte
         }
     }
 
-
+    //  AdapterView.OnItemLongClickListener
     @Override
     public boolean onItemLongClick(final AdapterView<?> parent, View view, int position, long id)
     {
@@ -463,7 +639,6 @@ public class ImageGridViewFragment extends Fragment implements AdapterView.OnIte
         return (false);
     }
 
-
     // AdapterView.OnItemSelectedListener
     @Override
     public void onItemSelected(AdapterView<?> parent, View view, int position, long id)
index 5aa11a7..31bd7c9 100644 (file)
@@ -521,7 +521,7 @@ public class ImagePagerViewFragment extends Fragment
                         if (infoEx != null)
                         {
                             ICameraContent fileInfo = infoEx.getFileInfo();
-                            contentDownloader.startDownload(fileInfo, (isRaw) ? infoEx.getRawSuffix() : null, isSmallSize);
+                            contentDownloader.startDownload(fileInfo, "", (isRaw) ? infoEx.getRawSuffix() : null, isSmallSize);
                         }
                     }
                 });
index 2036545..011cfe1 100644 (file)
@@ -1,7 +1,6 @@
 package net.osdn.gokigen.pkremote.playback.detail;
-
-
 import android.app.Activity;
+import android.app.AlertDialog;
 import android.app.ProgressDialog;
 import android.content.ContentResolver;
 import android.content.ContentValues;
@@ -11,7 +10,9 @@ import android.net.Uri;
 import android.os.Environment;
 import android.provider.MediaStore;
 import android.util.Log;
-import android.widget.Toast;
+import android.view.View;
+
+import com.google.android.material.snackbar.Snackbar;
 
 import net.osdn.gokigen.pkremote.R;
 import net.osdn.gokigen.pkremote.camera.interfaces.playback.ICameraContent;
@@ -27,14 +28,13 @@ import java.util.Calendar;
 import java.util.Locale;
 
 import androidx.annotation.NonNull;
-import androidx.appcompat.app.AlertDialog;
 import androidx.preference.PreferenceManager;
 
 /**
  *   コンテントのダウンロード
  *
  */
-class MyContentDownloader implements IDownloadContentCallback
+public class MyContentDownloader implements IDownloadContentCallback
 {
     private final String TAG = toString();
     private final Activity activity;
@@ -54,7 +54,7 @@ class MyContentDownloader implements IDownloadContentCallback
      *   コンストラクタ
      *
      */
-    MyContentDownloader(@NonNull Activity activity, @NonNull final IPlaybackControl playbackControl)
+    public MyContentDownloader(@NonNull Activity activity, @NonNull final IPlaybackControl playbackControl)
     {
         this.activity = activity;
         this.playbackControl = playbackControl;
@@ -64,7 +64,7 @@ class MyContentDownloader implements IDownloadContentCallback
      *   ダウンロードの開始
      *
      */
-    void startDownload(final ICameraContent fileInfo, String replaceJpegSuffix, boolean isSmallSize)
+    public void startDownload(final ICameraContent fileInfo, final String appendTitle, String replaceJpegSuffix, boolean isSmallSize)
     {
         if (fileInfo == null)
         {
@@ -86,18 +86,26 @@ class MyContentDownloader implements IDownloadContentCallback
             if (targetFileName.toUpperCase().contains(RAW_SUFFIX_1))
             {
                 mimeType = "image/x-adobe-dng";
+                isSmallSize = false;
             }
             else if (targetFileName.toUpperCase().contains(RAW_SUFFIX_2))
             {
                 mimeType = "image/x-olympus-orf";
+                isSmallSize = false;
             }
             else if (targetFileName.toUpperCase().contains(RAW_SUFFIX_3))
             {
                 mimeType = "image/x-pentax-pef";
+                isSmallSize = false;
             }
             else if (targetFileName.toUpperCase().contains(MOVIE_SUFFIX))
             {
                 mimeType =  "video/mp4";
+                isSmallSize = false;
+            }
+            else
+            {
+                mimeType = "image/jpeg";
             }
 
             ////// ダイアログの表示
@@ -105,7 +113,7 @@ class MyContentDownloader implements IDownloadContentCallback
                 @Override
                 public void run() {
                     downloadDialog = new ProgressDialog(activity);
-                    downloadDialog.setTitle(activity.getString(R.string.dialog_download_file_title));
+                    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);
                     downloadDialog.setCancelable(false);
@@ -227,7 +235,9 @@ class MyContentDownloader implements IDownloadContentCallback
                     {
                         downloadDialog.dismiss();
                     }
-                    Toast.makeText(activity, activity.getString(R.string.download_control_save_success) + " " + targetFileName, Toast.LENGTH_SHORT).show();
+                    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();
                     System.gc();
                 }
             });
diff --git a/app/src/main/res/drawable/ic_refresh_grey_24dp.xml b/app/src/main/res/drawable/ic_refresh_grey_24dp.xml
new file mode 100644 (file)
index 0000000..fee77b8
--- /dev/null
@@ -0,0 +1,10 @@
+<vector xmlns:android="http://schemas.android.com/apk/res/android"
+        android:tint="#C0C0C0"
+        android:width="24dp"
+        android:height="24dp"
+        android:viewportWidth="24.0"
+        android:viewportHeight="24.0">
+    <path
+        android:fillColor="#FF000000"
+        android:pathData="M17.65,6.35C16.2,4.9 14.21,4 12,4c-4.42,0 -7.99,3.58 -7.99,8s3.57,8 7.99,8c3.73,0 6.84,-2.55 7.73,-6h-2.08c-0.82,2.33 -3.04,4 -5.65,4 -3.31,0 -6,-2.69 -6,-6s2.69,-6 6,-6c1.66,0 3.14,0.69 4.22,1.78L13,11h7V4l-2.35,2.35z"/>
+</vector>
index 966083a..6d7e72e 100644 (file)
@@ -3,12 +3,45 @@
        xmlns:compat="http://schemas.android.com/apk/res-auto" >
 
     <item
+        android:id="@+id/action_select_all"
+        compat:showAsAction="ifRoom"
+        android:icon="@drawable/ic_select_all_grey_24dp"
+        android:title="@string/action_select_all"
+        android:visible="true" />
+
+    <item
         android:id="@+id/action_refresh"
         compat:showAsAction="ifRoom"
-        android:icon="@drawable/ic_refresh_black_24dp"
+        android:icon="@drawable/ic_refresh_grey_24dp"
         android:title="@string/action_refresh"
         android:visible="false" />
 
+    <item android:id="@+id/action_batch_download_with_raw"
+        compat:showAsAction="ifRoom"
+        android:icon="@drawable/ic_file_download_white_24dp"
+        android:title="@string/action_download"
+        android:visible="true" >
+        <menu>
+            <item
+                android:id="@+id/action_batch_download_original_size_raw"
+                compat:showAsAction="never"
+                android:title="@string/action_download_original_size"/>
+
+            <item
+                android:id="@+id/action_batch_download_640x480_raw"
+                compat:showAsAction="never"
+                android:title="@string/action_batch_download_640x480"/>
+
+            <!---->
+            <item
+                android:id="@+id/action_batch_download_raw"
+                compat:showAsAction="never"
+                android:visible="false"
+                android:title="@string/action_batch_download_raw"/>
+            <!---->
+        </menu>
+    </item>
+
     <item
         android:id="@+id/action_datetime_synchronize"
         compat:showAsAction="ifRoom"
index 3bbdbfb..4504dcd 100644 (file)
     <string name="message_download_finished_pics_with_failure">Finished. # of Pics. : </string>
     <string name="message_download_failure_count"> Failures : </string>
     <string name="message_download_finished_but_failed">Download was failed&#8230; </string>
+
+    <string name="action_batch_download_640x480">Small Size(JPEG)</string>
+    <string name="action_batch_download_raw">Original Size(with RAW)</string>
+    <string name="action_select_all">Select All/Unselect All</string>
 </resources>
index 1ebd267..4c1b42a 100644 (file)
             android:title="@string/pref_use_gr2_special_command"
             android:summary="@string/summary_use_gr2_special_command"
             />
-
+<!--
         <CheckBoxPreference
             android:key="pentax_capture_after_auto_focus"
             android:title="@string/pref_pentax_capture_after_auto_focus"
             android:summary="@string/summary_pentax_capture_after_auto_focus"
             />
+-->
     </PreferenceCategory>
 
     <PreferenceCategory