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;
private int currentYear = 0;
private int currentMonth = 0;
+ private boolean fragmentIsActive = false;
private static final List<Integer> dayLabelList = new ArrayList<Integer>()
{
return (myView);
}
+
+ @Override
+ public void onResume()
+ {
+ super.onResume();
+
+ fragmentIsActive = true;
+ }
+
+
+ @Override
+ public void onPause()
+ {
+ super.onPause();
+ fragmentIsActive = false;
+ }
+
+ public boolean isFragmentActive()
+ {
+ return (fragmentIsActive);
+ }
+
/**
* クリックされたときの処理
*/
}
/**
- *
+ * 画像ファイル一覧が取得できた後の処理
*
*
*/
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<>();
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);
}
// 最新の撮影データから並べる
{
private final String TAG = toString();
private final OLYCamera camera;
- private List<OLYCamera> list;
+ //private List<OLYCamera> list;
public OlyCameraPlaybackControl(@NonNull OLYCamera camera)
{
{
try
{
+ changeRunModePlayback();
camera.downloadContentList(new OLYCamera.DownloadContentListCallback() {
@Override
public void onCompleted(List<OLYCameraFileInfo> list)
{
try
{
+ changeRunModePlayback();
camera.downloadContentScreennail(path, new OLYCamera.DownloadImageCallback() {
@Override
public void onProgress(OLYCamera.ProgressEvent progressEvent)
{
try
{
+ changeRunModePlayback();
camera.downloadContentThumbnail(path, new OLYCamera.DownloadImageCallback() {
@Override
public void onProgress(OLYCamera.ProgressEvent progressEvent)
{
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);
}
}
}
try
{
+ changeRunModePlayback();
camera.downloadContentList(new OLYCamera.DownloadContentListCallback()
{
@Override
*/
private Date getCameraContentDate(@NonNull ICameraContent cameraContent)
{
-/**/
+ // 各ファイルを個別に撮影時刻をとると、反応が悪すぎるので処理を抑止。
+/*
String fileInfo;
try
{
{
e.printStackTrace();
}
-/**/
+*/
return (cameraContent.getCapturedDate());
}
}
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();
@Override
public void run()
{
- builder.show();
+ try
+ {
+ builder.show();
+ }
+ catch (Exception e)
+ {
+ e.printStackTrace();
+ }
}
});
}
Log.v(TAG, "onPause() Start");
try
{
+/*
+ // Playbackモードでしか使わないので、RunMode は変更しない
if (!runMode.isRecordingMode())
{
// Threadで呼んではダメみたいだ...
runMode.changeRunMode(true);
}
-
+*/
// アクションバーは隠した状態に戻しておく
AppCompatActivity activity = (AppCompatActivity) getActivity();
if (activity != null)
// 画像の選択を落とす
content.setSelected(false);
+
+ // ここでダウンロードが終わるまで、すこし待つ
+ do
+ {
+ try
+ {
+ Thread.sleep(300);
+ }
+ catch (Exception e)
+ {
+ e.printStackTrace();
+ }
+ } while (contentDownloader.isDownloading());
}
}
private String targetFileName = "";
private String filepath = "";
private String mimeType = "image/jpeg";
+ private boolean isDownloading = false;
/**
* コンストラクタ
// 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();
////// ダイアログの表示
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);
}
}
outputStream = new FileOutputStream(filepath);
+
+ Log.v(TAG, "downloadContent : " + path + " (small: " + isSmallSize + ")");
+ playbackControl.downloadContent(path, isSmallSize, this);
}
catch (Exception e)
{
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;
+ }
+ });
}
}
}
try
{
- if (outputStream != null)
+ if ((outputStream != null)&&(length > 0))
{
outputStream.write(bytes, 0, length);
}
{
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();
{
downloadDialog.dismiss();
}
+ downloadDialog = null;
+ isDownloading = false;
presentMessage(activity.getString(R.string.download_control_save_failed), message);
}
});
@Override
public void onErrorOccurred(Exception e)
{
+ isDownloading = false;
final String message = e.getMessage();
try
{
+ e.printStackTrace();
if (outputStream != null)
{
outputStream.flush();
}
catch (Exception ex)
{
- e.printStackTrace();
ex.printStackTrace();
}
activity.runOnUiThread(new Runnable()
{
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);
+ }
+
/**
* 共有の呼び出し
*
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;
changeSceneToCalendar();
}
+/*
// CameraSceneUpdater
public void registerInterface(@NonNull IStatusViewDrawer statusViewDrawer, @NonNull IInterfaceProvider interfaceProvider)
{
this.statusViewDrawer = statusViewDrawer;
this.interfaceProvider = interfaceProvider;
}
+*/
// ICameraStatusReceiver
@Override
{
Log.v(TAG, " CONNECTION MESSAGE : " + message);
try {
+/*
if (statusViewDrawer != null)
{
statusViewDrawer.updateStatusView(message);
statusViewDrawer.updateConnectionStatus(connection.getConnectionStatus());
}
}
+*/
if (anotherStatusReceiver != null)
{
anotherStatusReceiver.onStatusNotify(message);
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();
}
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();
}
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());
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);
}
public void contentsListCreated(int nofContents)
{
Log.v(TAG, "contentsListCreated() : " + nofContents);
+
+ // カレンダー画面のリフレッシュを行いたい (かなり無理やり...)
+ if ((calendarFragment != null)&&(calendarFragment.isFragmentActive()))
+ {
+ calendarFragment.contentsListCreated(nofContents);
+ }
}
}
<string name="get_camera_contents_wait">Check contents… wait</string>
<string name="get_camera_contents_error">Check contents… Error!</string>
- <string name="get_camera_contents_finished">Check contents… 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>