// Path: apps/android/ONIRecorder/src/org/pointclouds/onirec/grab/RecordingContextFactory.java
// public class RecordingContextFactory implements ContextFactory {
//     private final File recording;
// 
//     public RecordingContextFactory(File recording) {
//         this.recording = recording;
//     }
// 
//     @Override
//     public Context createContext() throws GeneralException {
//         return new OpenNIContext() {
//             private Player player;
// 
//             {
//                 try {
//                     player = getRealContext().openFileRecordingEx(recording.getAbsolutePath());
//                 } catch (GeneralException e) {
//                     dispose();
//                     throw e;
//                 }
//             }
// 
//             @Override
//             public ColorGenerator createColorGenerator() throws GeneralException {
//                 return new OpenNIColorGenerator(
//                         (ImageGenerator) getRealContext().findExistingNode(NodeType.IMAGE));
//             }
// 
//             @Override
//             public DepthGenerator createDepthGenerator() throws GeneralException {
//                 return new OpenNIDepthGenerator(
//                         (org.OpenNI.DepthGenerator) getRealContext().findExistingNode(NodeType.DEPTH));
//             }
// 
//             @Override
//             public void dispose() {
//                 if (player != null) player.dispose();
//             }
//         };
//     }
// }


import android.app.Activity;
import android.app.PendingIntent;
import android.content.*;
import android.hardware.usb.UsbDevice;
import android.hardware.usb.UsbManager;
import android.os.Bundle;
import android.os.Environment;
import android.preference.PreferenceManager;
import android.util.Log;
import android.view.*;
import android.widget.*;
import org.pointclouds.onirec.grab.DummyContextFactory;
import org.pointclouds.onirec.grab.LiveContextFactory;
import org.pointclouds.onirec.grab.RecordingContextFactory;
import org.OpenNI.MapOutputMode;
import org.libusb.UsbHelper;
import java.io.File;
import java.io.FilenameFilter;
import java.util.*;
            public void reportCaptureStarted(MapOutputMode[] colorModes, MapOutputMode currentColorMode,
                                             MapOutputMode[] depthModes, MapOutputMode currentDepthMode) {
                configureModeSpinner(currentColorMode, spinnerColorMode, spinnerAdapterColor);
                configureModeSpinner(currentDepthMode, spinnerDepthMode, spinnerAdapterDepth);
            }

            private void configureModeSpinner(MapOutputMode mode, Spinner spinner, ArrayAdapter<MapModeWrapper> adapter) {
                adapter.clear();
                adapter.add(new MapModeWrapper(MainActivity.this, mode));
                spinner.setVisibility(View.VISIBLE);
                spinner.setEnabled(false);
            }
        };

        public StateReplaying(File recording) {
            this.recording = recording;
        }

        @Override
        public void enter() {
            getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
            textFps.setVisibility(View.VISIBLE);
            textFps.setText(getResources().getString(R.string.x_fps, 0.));
            textStatus.setText(getResources().getString(R.string.status_replaying, recording.getName()));

            SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(MainActivity.this);
            boolean enable_vis = prefs.getBoolean(PreferencesActivity.KEY_PREF_ENABLE_VISUALIZATION, true);
            boolean fake_grabber = prefs.getBoolean(PreferencesActivity.KEY_PREF_USE_DUMMY_GRABBER, false);

            manager = new CaptureThreadManager(surfaceColor.getHolder(), surfaceDepth.getHolder(), feedback,
// Path: apps/android/ONIRecorder/src/org/pointclouds/onirec/grab/RecordingContextFactory.java
// public class RecordingContextFactory implements ContextFactory {
//     private final File recording;
// 
//     public RecordingContextFactory(File recording) {
//         this.recording = recording;
//     }
// 
//     @Override
//     public Context createContext() throws GeneralException {
//         return new OpenNIContext() {
//             private Player player;
// 
//             {
//                 try {
//                     player = getRealContext().openFileRecordingEx(recording.getAbsolutePath());
//                 } catch (GeneralException e) {
//                     dispose();
//                     throw e;
//                 }
//             }
// 
//             @Override
//             public ColorGenerator createColorGenerator() throws GeneralException {
//                 return new OpenNIColorGenerator(
//                         (ImageGenerator) getRealContext().findExistingNode(NodeType.IMAGE));
//             }
// 
//             @Override
//             public DepthGenerator createDepthGenerator() throws GeneralException {
//                 return new OpenNIDepthGenerator(
//                         (org.OpenNI.DepthGenerator) getRealContext().findExistingNode(NodeType.DEPTH));
//             }
// 
//             @Override
//             public void dispose() {
//                 if (player != null) player.dispose();
//             }
//         };
//     }
// }


// Path: apps/android/ONIRecorder/src/org/pointclouds/onirec/MainActivity.java
import android.app.Activity;
import android.app.PendingIntent;
import android.content.*;
import android.hardware.usb.UsbDevice;
import android.hardware.usb.UsbManager;
import android.os.Bundle;
import android.os.Environment;
import android.preference.PreferenceManager;
import android.util.Log;
import android.view.*;
import android.widget.*;
import org.pointclouds.onirec.grab.DummyContextFactory;
import org.pointclouds.onirec.grab.LiveContextFactory;
import org.pointclouds.onirec.grab.RecordingContextFactory;
import org.OpenNI.MapOutputMode;
import org.libusb.UsbHelper;
import java.io.File;
import java.io.FilenameFilter;
import java.util.*;

            public void reportCaptureStarted(MapOutputMode[] colorModes, MapOutputMode currentColorMode,
                                             MapOutputMode[] depthModes, MapOutputMode currentDepthMode) {
                configureModeSpinner(currentColorMode, spinnerColorMode, spinnerAdapterColor);
                configureModeSpinner(currentDepthMode, spinnerDepthMode, spinnerAdapterDepth);
            }

            private void configureModeSpinner(MapOutputMode mode, Spinner spinner, ArrayAdapter<MapModeWrapper> adapter) {
                adapter.clear();
                adapter.add(new MapModeWrapper(MainActivity.this, mode));
                spinner.setVisibility(View.VISIBLE);
                spinner.setEnabled(false);
            }
        };

        public StateReplaying(File recording) {
            this.recording = recording;
        }

        @Override
        public void enter() {
            getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
            textFps.setVisibility(View.VISIBLE);
            textFps.setText(getResources().getString(R.string.x_fps, 0.));
            textStatus.setText(getResources().getString(R.string.status_replaying, recording.getName()));

            SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(MainActivity.this);
            boolean enable_vis = prefs.getBoolean(PreferencesActivity.KEY_PREF_ENABLE_VISUALIZATION, true);
            boolean fake_grabber = prefs.getBoolean(PreferencesActivity.KEY_PREF_USE_DUMMY_GRABBER, false);

            manager = new CaptureThreadManager(surfaceColor.getHolder(), surfaceDepth.getHolder(), feedback,
                    fake_grabber ? new DummyContextFactory() : new RecordingContextFactory(recording), enable_vis);