OSDN Git Service

Theta用の仕込みも入れておく。
authorMRSa <mrsa@myad.jp>
Mon, 13 Jan 2020 13:23:41 +0000 (22:23 +0900)
committerMRSa <mrsa@myad.jp>
Mon, 13 Jan 2020 13:23:41 +0000 (22:23 +0900)
app/src/main/java/net/osdn/gokigen/a01d/camera/theta/IThetaInterfaceProvider.java [new file with mode: 0644]
app/src/main/java/net/osdn/gokigen/a01d/preference/theta/ThetaPreferenceFragment.java [new file with mode: 0644]
app/src/main/res/values-ja/strings.xml
app/src/main/res/values/strings.xml
app/src/main/res/xml/preferences_theta.xml [new file with mode: 0644]

diff --git a/app/src/main/java/net/osdn/gokigen/a01d/camera/theta/IThetaInterfaceProvider.java b/app/src/main/java/net/osdn/gokigen/a01d/camera/theta/IThetaInterfaceProvider.java
new file mode 100644 (file)
index 0000000..fb647f6
--- /dev/null
@@ -0,0 +1,42 @@
+package net.osdn.gokigen.a01d.camera.theta;
+
+import net.osdn.gokigen.a01d.camera.ICameraConnection;
+import net.osdn.gokigen.a01d.camera.ICameraInformation;
+import net.osdn.gokigen.a01d.camera.ICameraStatus;
+import net.osdn.gokigen.a01d.camera.ICameraStatusWatcher;
+import net.osdn.gokigen.a01d.camera.ICaptureControl;
+import net.osdn.gokigen.a01d.camera.IDisplayInjector;
+import net.osdn.gokigen.a01d.camera.IFocusingControl;
+import net.osdn.gokigen.a01d.camera.ILiveViewControl;
+import net.osdn.gokigen.a01d.camera.IZoomLensControl;
+import net.osdn.gokigen.a01d.liveview.ICameraStatusUpdateNotify;
+import net.osdn.gokigen.a01d.liveview.liveviewlistener.ILiveViewListener;
+
+public interface IThetaInterfaceProvider
+{
+    ICameraConnection getCanonCameraConnection();
+    ILiveViewControl getLiveViewControl();
+    ILiveViewListener getLiveViewListener();
+    IFocusingControl getFocusingControl();
+    ICameraInformation getCameraInformation();
+    IZoomLensControl getZoomLensControl();
+    ICaptureControl getCaptureControl();
+    IDisplayInjector getDisplayInjector();
+
+    /*
+    IFujiXRunModeHolder getRunModeHolder();
+    IFujiXCommandCallback getStatusHolder();
+    IFujiXCommandPublisher getCommandPublisher();
+    IFujiXCommunication getLiveviewCommunication();
+    IFujiXCommunication getAsyncEventCommunication();
+    IFujiXCommunication getCommandCommunication();
+     */
+
+
+    ICameraStatusWatcher getStatusWatcher();
+    ICameraStatusUpdateNotify getStatusListener();
+
+    ICameraStatusWatcher getCameraStatusWatcher();
+    ICameraStatus getCameraStatusListHolder();
+
+}
diff --git a/app/src/main/java/net/osdn/gokigen/a01d/preference/theta/ThetaPreferenceFragment.java b/app/src/main/java/net/osdn/gokigen/a01d/preference/theta/ThetaPreferenceFragment.java
new file mode 100644 (file)
index 0000000..f3f855c
--- /dev/null
@@ -0,0 +1,350 @@
+package net.osdn.gokigen.a01d.preference.theta;
+
+import android.content.Context;
+import android.content.Intent;
+import android.content.SharedPreferences;
+import android.os.Bundle;
+import android.provider.Settings;
+import android.util.Log;
+
+import androidx.annotation.NonNull;
+import androidx.appcompat.app.AppCompatActivity;
+import androidx.fragment.app.FragmentActivity;
+import androidx.preference.CheckBoxPreference;
+import androidx.preference.ListPreference;
+import androidx.preference.Preference;
+import androidx.preference.PreferenceFragmentCompat;
+import androidx.preference.PreferenceManager;
+
+import net.osdn.gokigen.a01d.IChangeScene;
+import net.osdn.gokigen.a01d.R;
+import net.osdn.gokigen.a01d.camera.ptpip.operation.PtpIpCameraPowerOff;
+import net.osdn.gokigen.a01d.logcat.LogCatViewer;
+import net.osdn.gokigen.a01d.preference.IPreferencePropertyAccessor;
+
+import java.util.Map;
+
+import static net.osdn.gokigen.a01d.preference.IPreferencePropertyAccessor.WIFI_SETTINGS;
+
+/**
+ *
+ *
+ */
+public class ThetaPreferenceFragment extends PreferenceFragmentCompat implements SharedPreferences.OnSharedPreferenceChangeListener, Preference.OnPreferenceClickListener
+{
+    private final String TAG = toString();
+    private AppCompatActivity context = null;
+    private SharedPreferences preferences = null;
+    private PtpIpCameraPowerOff powerOffController = null;
+    private LogCatViewer logCatViewer = null;
+
+    /**
+     *
+     *
+     */
+    public static ThetaPreferenceFragment newInstance(@NonNull AppCompatActivity context, @NonNull IChangeScene changeScene)
+    {
+        ThetaPreferenceFragment instance = new ThetaPreferenceFragment();
+        instance.prepare(context, changeScene);
+
+        // パラメータはBundleにまとめておく
+        Bundle arguments = new Bundle();
+        //arguments.putString("title", title);
+        //arguments.putString("message", message);
+        instance.setArguments(arguments);
+
+        return (instance);
+    }
+
+    /**
+     *
+     *
+     */
+    private void prepare(@NonNull AppCompatActivity context, @NonNull IChangeScene changeScene)
+    {
+        try
+        {
+            powerOffController = new PtpIpCameraPowerOff(context, changeScene);
+            powerOffController.prepare();
+
+            logCatViewer = new LogCatViewer(changeScene);
+            logCatViewer.prepare();
+
+            //cameraApiListViewer = new PanasonicCameraApiListViewer(changeScene);
+            //cameraApiListViewer.prepare();
+
+            this.context = context;
+        }
+        catch (Exception e)
+        {
+            e.printStackTrace();
+        }
+    }
+
+    /**
+     *
+     *
+     */
+    @Override
+    public void onAttach(@NonNull Context activity)
+    {
+        super.onAttach(activity);
+        Log.v(TAG, "onAttach()");
+
+        try
+        {
+            // Preference をつかまえる
+            preferences = PreferenceManager.getDefaultSharedPreferences(activity);
+
+            // Preference を初期設定する
+            initializePreferences();
+
+            preferences.registerOnSharedPreferenceChangeListener(this);
+        }
+        catch (Exception e)
+        {
+            e.printStackTrace();
+        }
+    }
+
+    /**
+     * Preferenceの初期化...
+     *
+     */
+    private void initializePreferences()
+    {
+        try
+        {
+            Map<String, ?> items = preferences.getAll();
+            SharedPreferences.Editor editor = preferences.edit();
+
+            if (!items.containsKey(IPreferencePropertyAccessor.AUTO_CONNECT_TO_CAMERA)) {
+                editor.putBoolean(IPreferencePropertyAccessor.AUTO_CONNECT_TO_CAMERA, true);
+            }
+            if (!items.containsKey(IPreferencePropertyAccessor.CAPTURE_BOTH_CAMERA_AND_LIVE_VIEW)) {
+                editor.putBoolean(IPreferencePropertyAccessor.CAPTURE_BOTH_CAMERA_AND_LIVE_VIEW, true);
+            }
+            if (!items.containsKey(IPreferencePropertyAccessor.CONNECTION_METHOD)) {
+                editor.putString(IPreferencePropertyAccessor.CONNECTION_METHOD, IPreferencePropertyAccessor.CONNECTION_METHOD_DEFAULT_VALUE);
+            }
+            editor.apply();
+        }
+        catch (Exception e)
+        {
+            e.printStackTrace();
+        }
+    }
+
+    /**
+     *
+     *
+     */
+    @Override
+    public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key)
+    {
+        Log.v(TAG, "onSharedPreferenceChanged() : " + key);
+        boolean value;
+        if (key != null)
+        {
+            switch (key)
+            {
+                case IPreferencePropertyAccessor.AUTO_CONNECT_TO_CAMERA:
+                    value = preferences.getBoolean(key, true);
+                    Log.v(TAG, " " + key + " , " + value);
+                    break;
+
+                case IPreferencePropertyAccessor.CAPTURE_BOTH_CAMERA_AND_LIVE_VIEW:
+                    value = preferences.getBoolean(key, true);
+                    Log.v(TAG, " " + key + " , " + value);
+                    break;
+
+                default:
+                    String strValue = preferences.getString(key, "");
+                    setListPreference(key, key, strValue);
+                    break;
+            }
+        }
+    }
+
+    /**
+     *
+     *
+     */
+    @Override
+    public void onCreatePreferences(Bundle savedInstanceState, String rootKey)
+    {
+        Log.v(TAG, "onCreatePreferences()");
+        try
+        {
+            //super.onCreate(savedInstanceState);
+            addPreferencesFromResource(R.xml.preferences_olympuspen);
+
+            ListPreference connectionMethod = findPreference(IPreferencePropertyAccessor.CONNECTION_METHOD);
+            connectionMethod.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
+                @Override
+                public boolean onPreferenceChange(Preference preference, Object newValue) {
+                    preference.setSummary(newValue + " ");
+                    return (true);
+                }
+            });
+            connectionMethod.setSummary(connectionMethod.getValue() + " ");
+
+            findPreference("exit_application").setOnPreferenceClickListener(powerOffController);
+            findPreference("debug_info").setOnPreferenceClickListener(logCatViewer);
+            //findPreference("panasonic_api_list").setOnPreferenceClickListener(cameraApiListViewer);
+            findPreference(WIFI_SETTINGS).setOnPreferenceClickListener(this);
+        }
+        catch (Exception e)
+        {
+            e.printStackTrace();
+        }
+    }
+
+    /**
+     *
+     *
+     */
+    @Override
+    public void onResume()
+    {
+        super.onResume();
+        Log.v(TAG, "onResume() Start");
+
+        try
+        {
+            synchronizedProperty();
+        }
+        catch (Exception e)
+        {
+            e.printStackTrace();
+        }
+
+        Log.v(TAG, "onResume() End");
+
+    }
+
+    /**
+     *
+     *
+     */
+    @Override
+    public void onPause()
+    {
+        super.onPause();
+        Log.v(TAG, "onPause() Start");
+
+        try
+        {
+            // Preference変更のリスナを解除
+            preferences.unregisterOnSharedPreferenceChangeListener(this);
+        }
+        catch (Exception e)
+        {
+            e.printStackTrace();
+        }
+
+        Log.v(TAG, "onPause() End");
+    }
+
+    /**
+     * ListPreference の表示データを設定
+     *
+     * @param pref_key     Preference(表示)のキー
+     * @param key          Preference(データ)のキー
+     * @param defaultValue Preferenceのデフォルト値
+     */
+    private void setListPreference(String pref_key, String key, String defaultValue)
+    {
+        try
+        {
+            ListPreference pref;
+            pref = (ListPreference) findPreference(pref_key);
+            String value = preferences.getString(key, defaultValue);
+            if (pref != null)
+            {
+                pref.setValue(value);
+                pref.setSummary(value);
+            }
+        }
+        catch (Exception e)
+        {
+            e.printStackTrace();
+        }
+    }
+
+    /**
+     * BooleanPreference の表示データを設定
+     *
+     * @param pref_key     Preference(表示)のキー
+     * @param key          Preference(データ)のキー
+     * @param defaultValue Preferenceのデフォルト値
+     */
+    private void setBooleanPreference(String pref_key, String key, boolean defaultValue)
+    {
+        try
+        {
+            CheckBoxPreference pref = findPreference(pref_key);
+            if (pref != null) {
+                boolean value = preferences.getBoolean(key, defaultValue);
+                pref.setChecked(value);
+            }
+        }
+        catch (Exception e)
+        {
+            e.printStackTrace();
+        }
+    }
+
+    /**
+     *
+     *
+     */
+    private void synchronizedProperty()
+    {
+        final FragmentActivity activity = getActivity();
+        final boolean defaultValue = true;
+        if (activity != null)
+        {
+            activity.runOnUiThread(new Runnable() {
+                @Override
+                public void run() {
+                    try
+                    {
+                        // Preferenceの画面に反映させる
+                        setBooleanPreference(IPreferencePropertyAccessor.AUTO_CONNECT_TO_CAMERA, IPreferencePropertyAccessor.AUTO_CONNECT_TO_CAMERA, defaultValue);
+                        setBooleanPreference(IPreferencePropertyAccessor.CAPTURE_BOTH_CAMERA_AND_LIVE_VIEW, IPreferencePropertyAccessor.CAPTURE_BOTH_CAMERA_AND_LIVE_VIEW, defaultValue);
+                    }
+                    catch (Exception e)
+                    {
+                        e.printStackTrace();
+                    }
+                }
+            });
+        }
+    }
+
+    @Override
+    public boolean onPreferenceClick(Preference preference)
+    {
+        try
+        {
+            String preferenceKey = preference.getKey();
+            if (preferenceKey.contains(WIFI_SETTINGS))
+            {
+                // Wifi 設定画面を表示する
+                Log.v(TAG, " onPreferenceClick : " + preferenceKey);
+                if (context != null)
+                {
+                    context.startActivity(new Intent(Settings.ACTION_WIFI_SETTINGS));
+                }
+            }
+            return (true);
+        }
+        catch (Exception e)
+        {
+            e.printStackTrace();
+        }
+        return (false);
+    }
+
+}
index ba05bb6..3f47db4 100644 (file)
@@ -30,6 +30,7 @@
     <string name="pref_exit_power_off_olympuspen">アプリ終了(とカメラOFF)</string>
     <string name="pref_exit_power_off_canon">アプリ終了</string>
     <string name="pref_exit_power_off_nikon">アプリ終了</string>
+    <string name="pref_exit_power_off_theta">アプリ終了</string>
 
     <string name="pref_exit_power_off_fujix">アプリ終了</string>
     <string name="pref_fujix_display_camera_view">LVをカメラでも表示</string>
index ee91104..d04afdb 100644 (file)
@@ -31,6 +31,7 @@
     <string name="pref_exit_power_off_olympuspen">Exit Application(and Camera OFF)</string>
     <string name="pref_exit_power_off_canon">Exit Application</string>
     <string name="pref_exit_power_off_nikon">Exit Application</string>
+    <string name="pref_exit_power_off_theta">Exit Application</string>
 
     <string name="pref_exit_power_off_fujix">Exit Application</string>
     <string name="pref_fujix_display_camera_view">Use Camera Display</string>
diff --git a/app/src/main/res/xml/preferences_theta.xml b/app/src/main/res/xml/preferences_theta.xml
new file mode 100644 (file)
index 0000000..0b9c86e
--- /dev/null
@@ -0,0 +1,70 @@
+<?xml version="1.0" encoding="utf-8"?>
+<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android" >
+    <PreferenceCategory
+        android:title="@string/pref_cat_application_control">
+
+        <PreferenceScreen
+            android:key="exit_application"
+            android:icon="@drawable/ic_power_settings_new_black_24dp"
+            android:title="@string/pref_exit_power_off_theta" />
+
+        <ListPreference
+            android:title="@string/pref_connection_method"
+            android:entryValues="@array/connection_method_value"
+            android:entries="@array/connection_method"
+            android:key="connection_method"
+            android:defaultValue="OPC"/>
+
+        <PreferenceScreen
+            android:key="wifi_settings"
+            android:title="@string/pref_wifi_settings"
+            android:summary="@string/pref_summary_wifi_settings" />
+
+    </PreferenceCategory>
+
+    <PreferenceCategory
+        android:title="@string/pref_cat_camera">
+
+        <CheckBoxPreference
+            android:key="capture_both_camera_and_live_view"
+            android:title="@string/pref_capture_both_camera_and_live_view" />
+
+    </PreferenceCategory>
+
+    <PreferenceCategory
+        android:title="@string/pref_cat_initialize">
+
+        <CheckBoxPreference
+        android:key="auto_connect_to_camera"
+        android:title="@string/pref_auto_connect_camera"
+        android:summary="@string/pref_summary_auto_connect_camera" />
+    </PreferenceCategory>
+
+    <PreferenceCategory
+        android:title="@string/pref_cat_gokigen">
+
+        <Preference
+            android:key="instruction_link"
+            android:title="@string/pref_instruction_manual"
+            android:summary="https://osdn.net/projects/gokigen/wiki/A01d"
+            android:selectable="true">
+            <intent android:action="android.intent.action.VIEW"
+                android:data="https://osdn.net/projects/gokigen/wiki/A01d" />
+        </Preference>
+
+        <Preference
+            android:key="privacy_policy"
+            android:title="@string/pref_privacy_policy"
+            android:summary="https://osdn.net/projects/gokigen/wiki/PrivacyPolicy"
+            android:selectable="true">
+            <intent android:action="android.intent.action.VIEW"
+                android:data="https://osdn.net/projects/gokigen/wiki/PrivacyPolicy" />
+        </Preference>
+
+        <PreferenceScreen
+            android:key="debug_info"
+            android:title="@string/pref_degug_info"
+            android:summary="@string/pref_summary_debug_info" />
+
+    </PreferenceCategory>
+</PreferenceScreen>