• R/O
  • HTTP
  • SSH
  • HTTPS

A01d: Commit

OPC(Olympus Air)用望遠鏡アプリ。


Commit MetaInfo

Révision530043deedc47aba00439fd7974c5d453bfaccca (tree)
l'heure2018-06-22 00:41:13
AuteurMRSa <mrsa@myad...>
CommiterMRSa

Message de Log

カメラパラメータで、double と int と boolean を指定できるようにした。

Change Summary

Modification

--- a/app/src/main/java/net/osdn/gokigen/a01d/camera/sony/cameraproperty/SonyCameraApiListFragment.java
+++ b/app/src/main/java/net/osdn/gokigen/a01d/camera/sony/cameraproperty/SonyCameraApiListFragment.java
@@ -307,24 +307,8 @@ public class SonyCameraApiListFragment extends ListFragment implements SendReque
307307 @Override
308308 public void sendRequest(final String service, final String apiName, final String parameter, final String version)
309309 {
310- final String[] parameterItems = parameter.split(",");
311-
312- StringBuilder logBuilder = new StringBuilder();
313- logBuilder.append("sendRequest(");
314- logBuilder.append(service);
315- logBuilder.append(", ");
316- logBuilder.append(apiName);
317- logBuilder.append(", [ ");
318- for (int index = 0; index < parameterItems.length; index++)
319- {
320- logBuilder.append(parameterItems[index]);
321- logBuilder.append(" ");
322- }
323- logBuilder.append("], ");
324- logBuilder.append(version);
325- logBuilder.append(");");
326- Log.v(TAG, logBuilder.toString());
327-
310+ String logValue = "sendRequest(" + service + ", " + apiName + ", [ " + parameter + "], " + version + ");";
311+ Log.v(TAG, logValue);
328312 try
329313 {
330314 Thread thread = new Thread(new Runnable()
@@ -334,31 +318,8 @@ public class SonyCameraApiListFragment extends ListFragment implements SendReque
334318 {
335319 try
336320 {
337- // メッセージを送信する
338- JSONArray params = new JSONArray();
339- if (parameter.length() != 0)
340- {
341- for (int index = 0; index < parameterItems.length; index++)
342- {
343- String oneItem = parameterItems[index];
344- if (oneItem.contains(":"))
345- {
346- // key & value と判断
347- try
348- {
349- String[] keyValue = oneItem.split(":");
350- params.put(new JSONObject().put(keyValue[0], keyValue[1]));
351- }
352- catch (Exception e)
353- {
354- e.printStackTrace();
355- params.put(oneItem);
356- }
357- } else {
358- params.put(oneItem);
359- }
360- }
361- }
321+ // parameterを parseして、メッセージを送信する
322+ JSONArray params = parseParams(parameter);
362323 receivedReply(interfaceProvider.getSonyInterface().getCameraApi().callGenericSonyApiMethod(service, apiName, params, version));
363324 }
364325 catch (Exception e)
@@ -375,6 +336,100 @@ public class SonyCameraApiListFragment extends ListFragment implements SendReque
375336 }
376337 }
377338
339+ private JSONArray parseParams(final String parameter)
340+ {
341+ JSONArray params = new JSONArray();
342+ final String[] parameterItems = parameter.split(",");
343+ if (parameter.length() != 0)
344+ {
345+ for (int index = 0; index < parameterItems.length; index++)
346+ {
347+ String oneItem = parameterItems[index];
348+ if (oneItem.contains(":"))
349+ {
350+ // key & value と判断
351+ try
352+ {
353+ String[] keyValue = oneItem.split(":");
354+ try
355+ {
356+ String key = keyValue[0];
357+ String value = keyValue[1];
358+ if (value.contains("$T"))
359+ {
360+ params.put(new JSONObject().put(key, true));
361+ }
362+ else if (value.contains("$F"))
363+ {
364+ params.put(new JSONObject().put(key, false));
365+ }
366+ else if (value.contains("#"))
367+ {
368+ if (value.contains("."))
369+ {
370+ double doubleValue = Double.parseDouble(value.substring(1));
371+ params.put(new JSONObject().put(key, doubleValue));
372+ }
373+ else
374+ {
375+ int intValue = Integer.parseInt(value.substring(1));
376+ params.put(new JSONObject().put(key, intValue));
377+ }
378+ }
379+ else
380+ {
381+ params.put(new JSONObject().put(keyValue[0], keyValue[1]));
382+ }
383+ }
384+ catch (Exception e)
385+ {
386+ e.printStackTrace();
387+ params.put(oneItem);
388+ }
389+ }
390+ catch (Exception e)
391+ {
392+ e.printStackTrace();
393+ params.put(oneItem);
394+ }
395+ } else {
396+ try
397+ {
398+ if (oneItem.contains("$T"))
399+ {
400+ params.put(true);
401+ }
402+ else if (oneItem.contains("$F"))
403+ {
404+ params.put(false);
405+ }
406+ else if (oneItem.contains("#"))
407+ {
408+ if (oneItem.contains("."))
409+ {
410+ double doubleValue = Double.parseDouble(oneItem.substring(1));
411+ params.put(doubleValue);
412+ } else {
413+ int intValue = Integer.parseInt(oneItem.substring(1));
414+ params.put(intValue);
415+ }
416+ }
417+ else
418+ {
419+ params.put(oneItem);
420+ }
421+ }
422+ catch (Exception e)
423+ {
424+ e.printStackTrace();
425+ params.put(oneItem);
426+ }
427+ }
428+ }
429+ }
430+ return (params);
431+ }
432+
378433 @Override
379434 public void cancelled()
380435 {
Afficher sur ancien navigateur de dépôt.