OSDN Git Service

自動転送時、受信した画像とそのファイル名を表示するようにした。GR2で停止する問題への対策(検討...)
authorMRSa <mrsa@myad.jp>
Sun, 31 Mar 2019 09:47:37 +0000 (18:47 +0900)
committerMRSa <mrsa@myad.jp>
Sun, 31 Mar 2019 09:47:37 +0000 (18:47 +0900)
app/src/main/java/net/osdn/gokigen/pkremote/MainActivity.java
app/src/main/java/net/osdn/gokigen/pkremote/camera/vendor/ricoh/wrapper/RicohGr2PlaybackControl.java
app/src/main/java/net/osdn/gokigen/pkremote/playback/IContentDownloadNotify.java [new file with mode: 0644]
app/src/main/java/net/osdn/gokigen/pkremote/playback/ImageGridViewFragment.java
app/src/main/java/net/osdn/gokigen/pkremote/playback/MyContentDownloader.java [moved from app/src/main/java/net/osdn/gokigen/pkremote/playback/detail/MyContentDownloader.java with 91% similarity]
app/src/main/java/net/osdn/gokigen/pkremote/playback/detail/ImagePagerViewFragment.java
app/src/main/java/net/osdn/gokigen/pkremote/transfer/AutoTransferFragment.java
app/src/main/java/net/osdn/gokigen/pkremote/transfer/FileAutoTransferMain.java
app/src/main/res/layout/fragment_auto_transfer.xml
app/src/main/res/values-ja/strings.xml
app/src/main/res/values/strings.xml

index 3c6e422..f024950 100644 (file)
@@ -27,6 +27,7 @@ import android.widget.TextView;
 
 import net.osdn.gokigen.pkremote.camera.CameraInterfaceProvider;
 import net.osdn.gokigen.pkremote.camera.interfaces.IInterfaceProvider;
+import net.osdn.gokigen.pkremote.camera.interfaces.control.ICameraConnection;
 import net.osdn.gokigen.pkremote.preference.IPreferencePropertyAccessor;
 import net.osdn.gokigen.pkremote.scene.CameraSceneUpdater;
 
@@ -153,6 +154,27 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe
     }
 
     /**
+     *
+     */
+    @Override
+    protected void onPause()
+    {
+        super.onPause();
+        try
+        {
+            ICameraConnection connection = interfaceProvider.getCameraConnection();
+            if (connection != null)
+            {
+                connection.stopWatchWifiStatus(this);
+            }
+        }
+        catch (Exception e)
+        {
+            e.printStackTrace();
+        }
+    }
+
+    /**
      * クラスの初期化 (instantiate)
      */
     private void initializeClass()
index 6d363cf..36eb0e3 100644 (file)
@@ -433,7 +433,7 @@ public class RicohGr2PlaybackControl implements IPlaybackControl
                     for (int fileIndex = 0; fileIndex < nofFiles; fileIndex++)
                     {
                         String fileName = filesArray.getString(fileIndex);
-                        Log.v(TAG, "FILE : " + fileName);
+                        //Log.v(TAG, "FILE : " + fileName);
                         ICameraContent cameraContent = new CameraContentInfo(cameraId, "sd1", dirName, fileName, new Date());
                         cameraContent.setCapturedDate(getCameraContentDate(cameraContent));
                         fileList.add(cameraContent);
diff --git a/app/src/main/java/net/osdn/gokigen/pkremote/playback/IContentDownloadNotify.java b/app/src/main/java/net/osdn/gokigen/pkremote/playback/IContentDownloadNotify.java
new file mode 100644 (file)
index 0000000..2f86c86
--- /dev/null
@@ -0,0 +1,8 @@
+package net.osdn.gokigen.pkremote.playback;
+
+import android.net.Uri;
+
+public interface IContentDownloadNotify
+{
+    void downloadedImage(String contentInfo, Uri content);
+}
index 65d3845..7b74249 100644 (file)
@@ -29,7 +29,6 @@ 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;
@@ -92,7 +91,7 @@ public class ImageGridViewFragment extends Fragment implements AdapterView.OnIte
         Activity activity = getActivity();
         if (activity != null)
         {
-            this.contentDownloader = new MyContentDownloader(getActivity(), playbackControl);
+            this.contentDownloader = new MyContentDownloader(getActivity(), playbackControl, null);
         }
         else
         {
@@ -541,7 +540,7 @@ public class ImageGridViewFragment extends Fragment implements AdapterView.OnIte
                     // activityが取れない時には終わる。
                     return;
                 }
-                this.contentDownloader = new MyContentDownloader(getActivity(), playbackControl);
+                this.contentDownloader = new MyContentDownloader(getActivity(), playbackControl, null);
             }
             Thread thread = new Thread(new Runnable()
             {
@@ -1,4 +1,4 @@
-package net.osdn.gokigen.pkremote.playback.detail;
+package net.osdn.gokigen.pkremote.playback;
 import android.app.Activity;
 import android.app.AlertDialog;
 import android.app.ProgressDialog;
@@ -28,6 +28,7 @@ import java.util.Calendar;
 import java.util.Locale;
 
 import androidx.annotation.NonNull;
+import androidx.annotation.Nullable;
 import androidx.preference.PreferenceManager;
 
 /**
@@ -39,6 +40,7 @@ public class MyContentDownloader implements IDownloadContentCallback
     private final String TAG = toString();
     private final Activity activity;
     private final IPlaybackControl playbackControl;
+    private final IContentDownloadNotify receiver;
     private static final String RAW_SUFFIX_1 = ".DNG";
     private static final String RAW_SUFFIX_2 = ".ORF";
     private static final String RAW_SUFFIX_3 = ".PEF";
@@ -55,10 +57,11 @@ public class MyContentDownloader implements IDownloadContentCallback
      *   コンストラクタ
      *
      */
-    public MyContentDownloader(@NonNull Activity activity, @NonNull final IPlaybackControl playbackControl)
+    public MyContentDownloader(@NonNull Activity activity, @NonNull final IPlaybackControl playbackControl, @Nullable IContentDownloadNotify receiver)
     {
         this.activity = activity;
         this.playbackControl = playbackControl;
+        this.receiver = receiver;
     }
 
     /**
@@ -234,18 +237,29 @@ public class MyContentDownloader implements IDownloadContentCallback
                 final Uri content = resolver.insert(mediaValue, 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);
+                                SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(activity);
+                                if (preferences.getBoolean(IPreferencePropertyAccessor.SHARE_AFTER_SAVE, false))
+                                {
+                                    shareContent(content, mimeType);
+                                }
+                                try
+                                {
+                                    if (receiver != null)
+                                    {
+                                        receiver.downloadedImage(targetFileName, content);
+                                    }
+                                }
+                                catch (Exception e)
+                                {
+                                    e.printStackTrace();
+                                }
                             }
                         });
-                    }
                 }
                 catch (Exception e)
                 {
index f3a6308..256c5fe 100644 (file)
@@ -20,6 +20,7 @@ import net.osdn.gokigen.pkremote.camera.interfaces.playback.ICameraFileInfo;
 import net.osdn.gokigen.pkremote.camera.interfaces.playback.IContentInfoCallback;
 import net.osdn.gokigen.pkremote.camera.interfaces.playback.IDownloadThumbnailImageCallback;
 import net.osdn.gokigen.pkremote.camera.interfaces.playback.IPlaybackControl;
+import net.osdn.gokigen.pkremote.playback.MyContentDownloader;
 
 import java.text.SimpleDateFormat;
 import java.util.Date;
@@ -516,7 +517,7 @@ public class ImagePagerViewFragment extends Fragment
                 Thread thread = new Thread(new Runnable() {
                     @Override
                     public void run() {
-                        MyContentDownloader contentDownloader = new MyContentDownloader(activity, playbackControl);
+                        MyContentDownloader contentDownloader = new MyContentDownloader(activity, playbackControl, null);
                         CameraContentEx infoEx = contentList.get(contentIndex);
                         if (infoEx != null)
                         {
index 17980a4..f37c033 100644 (file)
@@ -2,6 +2,7 @@ package net.osdn.gokigen.pkremote.transfer;
 
 import android.content.Context;
 import android.graphics.Bitmap;
+import android.net.Uri;
 import android.os.Bundle;
 import android.os.Vibrator;
 import android.util.Log;
@@ -17,6 +18,7 @@ import android.widget.TextView;
 
 import net.osdn.gokigen.pkremote.R;
 import net.osdn.gokigen.pkremote.camera.interfaces.IInterfaceProvider;
+import net.osdn.gokigen.pkremote.playback.IContentDownloadNotify;
 
 import androidx.annotation.NonNull;
 import androidx.appcompat.app.AppCompatActivity;
@@ -28,7 +30,7 @@ import static android.content.Context.VIBRATOR_SERVICE;
  *   自動転送クラス
  *
  */
-public class AutoTransferFragment extends Fragment implements View.OnClickListener, ITransferMessage
+public class AutoTransferFragment extends Fragment implements View.OnClickListener, ITransferMessage, IContentDownloadNotify
 {
     private final String TAG = this.toString();
 
@@ -39,6 +41,7 @@ public class AutoTransferFragment extends Fragment implements View.OnClickListen
     private FileAutoTransferMain transferMain = null;
     private View myView = null;
     private boolean transferThreadIsRunning = false;
+    private boolean startTransferReceived = false;
 
     public static AutoTransferFragment newInstance(@NonNull AppCompatActivity context, @NonNull IInterfaceProvider provider)
     {
@@ -61,7 +64,7 @@ public class AutoTransferFragment extends Fragment implements View.OnClickListen
     {
         Log.v(TAG, "prepare()");
         this.activity = activity;
-        transferMain = new FileAutoTransferMain(activity, interfaceProvider, this);
+        transferMain = new FileAutoTransferMain(activity, interfaceProvider, this, this);
     }
 
     /**
@@ -169,6 +172,14 @@ public class AutoTransferFragment extends Fragment implements View.OnClickListen
         }
         try
         {
+            // とにかく転送スレッドを止める指示を出す
+            transferThreadIsRunning = false;
+            while (startTransferReceived)
+            {
+                // すでにコマンドは発行状態...終わるまで待つ
+                Thread.sleep(SLEEP_MS);
+            }
+
             // STARTボタンを無効化してぶるぶるする...
             controlButton(false);
             Vibrator vibrator = (activity != null) ? (Vibrator) activity.getSystemService(VIBRATOR_SERVICE) : null;
@@ -176,6 +187,11 @@ public class AutoTransferFragment extends Fragment implements View.OnClickListen
             {
                 vibrator.vibrate(50);
             }
+            startTransferReceived = true;
+
+            // 画像を初期データにする
+            ImageView imageView = activity.findViewById(R.id.image_view_area);
+            imageView.setImageResource(R.drawable.ic_satellite_grey_24dp);
 
             // 画面上にある自動転送の設定を取得
             CheckBox raw = activity.findViewById(R.id.check_auto_download_raw);
@@ -200,8 +216,8 @@ public class AutoTransferFragment extends Fragment implements View.OnClickListen
                         {
                             if (transferMain != null)
                             {
-                                // 現在時刻を取得する
-                                long checkStartTime = System.currentTimeMillis();
+                                //// 現在時刻を取得する
+                                //long checkStartTime = System.currentTimeMillis();
 
                                 // チェックして追加ファイルがあったらダウンロード
                                 transferMain.checkFiles();
@@ -211,12 +227,15 @@ public class AutoTransferFragment extends Fragment implements View.OnClickListen
                                 {
                                     Thread.sleep(SLEEP_MS);
                                 }
-                                long checkTime = Math.abs(System.currentTimeMillis() - checkStartTime);
-                                if (checkTime < SLEEP_WAIT_MS)
-                                {
-                                    // 画像数確認の時間が規定時間よりも短い場合は、しばらく待つ
-                                    Thread.sleep(SLEEP_WAIT_MS - checkTime);
-                                }
+                                //long checkTime = Math.abs(System.currentTimeMillis() - checkStartTime);
+                                //if (checkTime < SLEEP_WAIT_MS)
+                                //{
+                                //    // 画像数確認の時間が規定時間よりも短い場合は、しばらく待つ
+                                //    Thread.sleep(SLEEP_WAIT_MS - checkTime);
+                                //}
+
+                                // 一定時間しばらく待つ (急ぎすぎると、GR2の電源が落ちる...
+                                Thread.sleep(SLEEP_WAIT_MS);
                             }
                             //count++;
                             //Log.v(TAG, "TRANSFER LOOP : " + count);
@@ -231,6 +250,7 @@ public class AutoTransferFragment extends Fragment implements View.OnClickListen
                         // 後処理...
                         transferMain.finish();
                     }
+                    startTransferReceived = false;
                 }
             });
 
@@ -430,4 +450,35 @@ public class AutoTransferFragment extends Fragment implements View.OnClickListen
             });
         }
     }
+
+    // IContentDownloadNotify
+    @Override
+    public void downloadedImage(final String contentInfo, final Uri content)
+    {
+        if (activity != null)
+        {
+            activity.runOnUiThread(new Runnable() {
+                @Override
+                public void run() {
+                    ImageView imageView = activity.findViewById(R.id.image_view_area);
+                    TextView textView = activity.findViewById(R.id.image_view_information);
+                    try
+                    {
+                        if ((imageView != null)&&(content != null))
+                        {
+                            imageView.setImageURI(content);
+                        }
+                        if ((textView != null)&&(contentInfo != null))
+                        {
+                            textView.setText(contentInfo);
+                        }
+                    }
+                    catch (Throwable t)
+                    {
+                        t.printStackTrace();
+                    }
+                }
+            });
+        }
+    }
 }
index da04099..7457382 100644 (file)
@@ -6,7 +6,8 @@ import net.osdn.gokigen.pkremote.R;
 import net.osdn.gokigen.pkremote.camera.interfaces.IInterfaceProvider;
 import net.osdn.gokigen.pkremote.camera.interfaces.playback.ICameraContent;
 import net.osdn.gokigen.pkremote.camera.interfaces.playback.ICameraContentListCallback;
-import net.osdn.gokigen.pkremote.playback.detail.MyContentDownloader;
+import net.osdn.gokigen.pkremote.playback.IContentDownloadNotify;
+import net.osdn.gokigen.pkremote.playback.MyContentDownloader;
 
 import java.util.ArrayList;
 import java.util.HashMap;
@@ -36,12 +37,12 @@ class FileAutoTransferMain implements ICameraContentListCallback
     private boolean isChecking = false;
 
 
-    FileAutoTransferMain(@NonNull AppCompatActivity context, @NonNull IInterfaceProvider provider, @NonNull ITransferMessage messageInterface)
+    FileAutoTransferMain(@NonNull AppCompatActivity context, @NonNull IInterfaceProvider provider, @NonNull ITransferMessage messageInterface, @NonNull IContentDownloadNotify receiver)
     {
         this.activity = context;
         this.interfaceProvider = provider;
         this.messageInterface = messageInterface;
-        this.downloader = new MyContentDownloader(context, provider.getPlaybackControl());
+        this.downloader = new MyContentDownloader(context, provider.getPlaybackControl(), receiver);
         this.contentHashMap = new HashMap<>();
     }
 
@@ -92,6 +93,7 @@ class FileAutoTransferMain implements ICameraContentListCallback
         try
         {
             Log.v(TAG, "CHECK FILE");
+            messageInterface.showInformation(activity.getString(R.string.get_image_list));
             isChecking = true;
             interfaceProvider.getPlaybackControl().getCameraContentList(this);
         }
@@ -206,6 +208,7 @@ class FileAutoTransferMain implements ICameraContentListCallback
         Log.v(TAG, "RECEIVE CONTENT LIST");
         try
         {
+            messageInterface.showInformation(activity.getString(R.string.get_image_list_done));
             if (firstContent)
             {
                 baseContentList = contentList;
@@ -259,14 +262,15 @@ class FileAutoTransferMain implements ICameraContentListCallback
             e.printStackTrace();
         }
         isChecking = false;
+        Log.v(TAG, "CHECK FILE DONE.");
     }
 
     // ICameraContentListCallback
     @Override
     public void onErrorOccurred(Exception e)
     {
-        Log.v(TAG, "RECEIVE FAILURE...");
         e.printStackTrace();
         isChecking = false;
+        Log.v(TAG, "CHECK FILE DONE(WITH ERROR).");
     }
 }
index 0ec2049..dbb79ee 100644 (file)
         android:layout_width="match_parent"
         android:layout_height="wrap_content"
         android:orientation="vertical">
-
-        <ImageView
-            android:id="@+id/image_view_area"
-            android:layout_width="match_parent"
-            android:layout_height="160dp"
-            android:src="@null"
-            android:scaleType="fitCenter"
-            tools:ignore="ContentDescription" />
+        <View
+            android:layout_width="fill_parent"
+            android:layout_height="1dp"
+            android:background="@android:color/darker_gray"/>
 
         <TextView
             android:id="@+id/image_view_information"
             android:focusable="true"
             android:text="@string/blank"
             android:textColor="@color/background_dark"
-            android:textSize="9pt" />
+            android:textSize="8pt" />
+
+        <ImageView
+            android:id="@+id/image_view_area"
+            android:layout_width="match_parent"
+            android:layout_height="160dp"
+            android:layout_marginTop="2dp"
+            android:src="@null"
+            android:scaleType="fitCenter"
+            tools:ignore="ContentDescription" />
 
         <View
             android:layout_width="fill_parent"
             android:layout_height="1dp"
+            android:layout_marginTop="2dp"
             android:background="@android:color/darker_gray"/>
 
         <LinearLayout
index edcf68b..aaf0462 100644 (file)
     <string name="image_checking">撮影画像確認中&#8230;</string>
     <string name="add_image_pics">追加画像 : </string>
     <string name="image_download_done">転送終了</string>
+    <string name="get_image_list">画像一覧取得中&#8230;</string>
+    <string name="get_image_list_done">画像一覧取得中&#8230;完了</string>
 
 </resources>
index 88cb4ed..4e87998 100644 (file)
     <string name="image_checking">Image checking&#8230;</string>
     <string name="add_image_pics">Detect Image : </string>
     <string name="image_download_done">Transfer Finished.</string>
-
+    <string name="get_image_list">Get Image List&#8230;</string>
+    <string name="get_image_list_done">Get Image List&#8230;DONE.</string>
 </resources>