Exemple #1
0
    /**
     * Waits until the OSC controller signal that the photo is ready
     * Then retrieve the data, save them and go to display screen with automatic rotation
     **/
    private void ManageWaitingScreen()
    {
        if (mIsOSCReady)
        {
            mTimeout.Reset();
            mFullResolutionImage = mOSCController.GetLatestData();
            //mWatermarker.CreateWatermark(mFullResolutionImage);
            //mWatermarker.AddWatermark();
            //mFullResolutionImage = mWatermarker.GetBytes();
            mCamera.AutomaticRotation(mTimeout);

            //		    // Save image with watermark
            //		    var bytes = watermark.GetTexture().EncodeToPNG();
            //		    File.WriteAllBytes(Application.dataPath + "/final_picture.png", bytes);

            mSkyboxMng.DefineNewSkybox(mFullResolutionImage /*mWatermarker.GetTexture()*/);

            if (mPingTester.CheckServer())
            {
                mCurrentState = ScreensStates.DISPLAY_PHOTO;
            }
            else
            {
                mCurrentState = ScreensStates.DISPLAY_PHOTO_WITHOUT_INTERNET;
            }
            UpdateScreen();
        }
    }
Exemple #2
0
    /**
     * If user touch the welcome screen stop automatic rotation
     * and go to take a photo screen
     **/
    private void ManageWelcomeScreen()
    {
        if (authentification_state == 3)
        {
            mCamera.AutomaticRotation(mTimeout);
            if (Input.touchCount > 0 || Input.GetMouseButton(0))
            {
                try
                {
                    mOSCController.StartLivePreview();
                    mCamera.AutomaticRotation(mTimeout);
                    mTimeoutCoroutine = StartCoroutine(mTimeout.StartTimer());

                    // For logs (new log)
                    mErrorCount = 0;
                    Logger.Instance.WriteStart();

                    mCurrentState = ScreensStates.READY_TAKE_PHOTO;
                    UpdateScreen();
                }
                catch (Exception e)
                {
                    Debug.Log(e.Message);
                }
            }
        }
        else
        {
            mCurrentState = ScreensStates.REGISTRATION;
            UpdateScreen();
        }
    }
Exemple #3
0
 public void TriggerFBShareTerminated(bool success)
 {
     mTimeout.Reset();
     if (success)
     {
         Logger.Instance.WriteFacebookSuccess();
         mCurrentState = ScreensStates.GOODBYE;
         UpdateScreen();
     }
 }
Exemple #4
0
 /**
  * Use this for initialization
  **/
 private void Start()
 {
     mWifi = new WifiManager();
     if (!mWifi.WaitForWifi())        //ensure that wifi is ON when app starts or quit
     {
         Application.Quit();
     }
     mFB                 = new FacebookConnector();
     mAndroidSID         = new AndroidSecureID();
     mTimeout            = new Timeout(mTimeoutValue, TimeoutGoToWelcome);
     Screen.sleepTimeout = SleepTimeout.NeverSleep;    //device screen should never turn off
     mCurrentState       = ScreensStates.REGISTRATION; //start application on registration screen
     mCamera.AutomaticRotation(mTimeout);              //use automatic rotation of welcome photo
     UpdateScreen();
 }
Exemple #5
0
    /**
     * On the share screen go back to welcome screen if user presses the ABORT button
     * Share on Facebook or display the QRcode
     * And disconnect the user from Facebook when living
     **/
    private void ManageShareScreen()
    {
        if (IsButtonDown(InterfaceButtons.SHARE_FB))
        {
            mTimeout.Reset();

            // For logs
            Logger.Instance.WriteShareFacebook();

            mFB.StartConnection(mFullResolutionImage, TriggerFBShareTerminated);
        }
        else if (IsButtonDown(InterfaceButtons.ABORT))
        {
            mTimeout.Reset();
            StopCoroutine(mTimeoutCoroutine);

            // For logs
            Logger.Instance.WriteShareAbandon();

            mSkyboxMng.ResetSkybox();
            mCurrentState = ScreensStates.WELCOME;
            UpdateScreen();
        }
        else if (IsButtonDown(InterfaceButtons.SHARE_CODE))
        {
            mTimeout.Reset();

            // For logs
            Logger.Instance.WriteShareCode();

            Destroy(mQRcode.sprite);
            string token_img = mSharingServer.GetTokenImg();
            if (token_img == null)
            {
                mCurrentState = ScreensStates.SHARE_PHOTO;
            }
            else
            {
                Texture2D tex = GenerateQRcode("https://server.instant-sphere.com/" + token_img);
                mQRcode.sprite = Sprite.Create(tex, new Rect(0.0f, 0.0f, tex.width, tex.height), new Vector2(0.5f, 0.5f));
                code.text      = token_img;

                mCurrentState = ScreensStates.PHOTO_CODE;
            }
            UpdateScreen();
        }
    }
Exemple #6
0
    /**
     * Method to be used as callback when "no action" timeout
     **/
    public void TimeoutGoToWelcome()
    {
        mOSCController.StopLivePreview();
        if (mTimeout != null)
        {
            StopCoroutine(mTimeoutCoroutine);
        }

        if (mCurrentState == ScreensStates.ERROR)
        {
            return;
        }

        mSkyboxMng.ResetSkybox();
        mTimeout = new Timeout(mTimeoutValue, TimeoutGoToWelcome);
        mCamera.AutomaticRotation(mTimeout);
        mCurrentState = ScreensStates.WELCOME;
        UpdateScreen();
    }
Exemple #7
0
    /**
     * If the user presses the back button go back to the share screen
     * else if user presses the OK button next to the email field, send his mail to the server and go to the goodbye screen
     **/
    private void ManageShareCodeScreen()
    {
        if (IsButtonDown(InterfaceButtons.BACK))
        {
            mTimeout.Reset();
            mCurrentState = ScreensStates.SHARE_PHOTO;
            UpdateScreen();
        }
        else if (IsButtonDown(InterfaceButtons.SHARE_EMAIL_OK))
        {
            mTimeout.Reset();

            string mail_s = mail.text;
            mSharingServer.SendToServerMail(mail_s);
            mail.text = "";

            mCurrentState = ScreensStates.GOODBYE;
            UpdateScreen();
        }
    }
Exemple #8
0
    /**
     * If user pushes the Take a Photo button go to screen taking photo
     **/
    private void ManageReadyTakePhotoScreen()
    {
        byte[] data = mOSCController.GetLatestData();
        Logger.Instance.ChangeToRT();
        if (data != null)
        {
            mSkyboxMng.DefineNewSkybox(data);
        }

        if (IsButtonDown(InterfaceButtons.TAKE_PHOTO))
        {
            mTimeout.Reset();

            // For logs
            Logger.Instance.WriteCapture();

            mCurrentState = ScreensStates.TAKING_PHOTO;
            UpdateScreen();
        }
    }
Exemple #9
0
 /**
  * Update is called once per frame
  **/
 private void Update()
 {
     if (!mOSCController.IsCameraOK())   //go to error state and stay inside
     {
         // For logs
         if (mErrorCount < 1)
         {
             Logger.Instance.WriteError(mCurrentState);
             mErrorCount++;
         }
         mCamera.StopRotation();
         mCurrentState = ScreensStates.ERROR;
         UpdateScreen();
     }
     else
     {
         //handle user interactions
         ManageStates();
         ResetButtons();
     }
 }
Exemple #10
0
    /**
     * On the display screen go to the share screen when user presses the OK button
     * Go to back to take a photo if user presses the RETRY button
     * Go to welcome screen if user presses the ABORT button
     **/
    private void ManageDisplayScreen()
    {
        if (IsButtonDown(InterfaceButtons.ABORT))
        {
            mTimeout.Reset();
            StopCoroutine(mTimeoutCoroutine);

            // For logs
            Logger.Instance.WriteVisualizeAbandon();

            mSkyboxMng.ResetSkybox();
            mCurrentState = ScreensStates.WELCOME;
            mCamera.AutomaticRotation(mTimeout);
        }
        else if (IsButtonDown(InterfaceButtons.RETRY))
        {
            mTimeout.Reset();

            // For logs
            Logger.Instance.WriteVisualizeRestart();
            mOSCController.StartLivePreview();
            mCurrentState = ScreensStates.READY_TAKE_PHOTO;
        }
        else if (IsButtonDown(InterfaceButtons.SHARE))
        {
            mTimeout.Reset();

            // For logs
            Logger.Instance.WriteVisualizeShare();
            mCurrentState = ScreensStates.SHARE_PHOTO;
            Debug.Log("Sending photo to server");
            mSharingServer.SendToServer(mFullResolutionImage);
        }
        else
        {
            return;
        }
        UpdateScreen();
    }
Exemple #11
0
    /**
     * Starts the countdown if it's not
     * If the countdown is finished, ask camera to capture a photo and go to waiting screen
     **/
    private void ManageTakingPhotoScreen()
    {
        byte[] data = mOSCController.GetLatestData();
        Logger.Instance.ChangeToHQ();

        if (data != null)
        {
            mSkyboxMng.DefineNewSkybox(data);
        }

        if (!mCounter.IsCounting())
        {
            mCounterCoroutine = StartCoroutine(mCounter.Count(3, UpdateCountDownText));
        }
        else if (mCounter.IsCounterFinished())
        {
            try
            {
                mTimeout.Reset();

                mIsOSCReady = false;
                mOSCController.StopLivePreview();
                mOSCController.StartCapture(TriggerOSCReady);
                mCurrentState = ScreensStates.WAITING;
                UpdateScreen();
            }
            catch (Exception e)
            {
                Debug.Log(e.Message);
            }
            finally
            {
                StopCoroutine(mCounterCoroutine);
                mCounter = new CounterDown();   //new countdown for next time
            }
        }
    }
Exemple #12
0
    /**
     * Checks if auth file exists, if not creates it
     * If auth file is empty ask for our token to the server
     * Else go to welcome screen
     **/
    private void ManageRegistrationScreen()
    {
        mTimeout.Reset();
        if (!System.IO.File.Exists(Application.persistentDataPath + "/auth_file.txt"))
        {
            Debug.Log("creating auth.txt");
            System.IO.File.Create(Application.persistentDataPath + "/auth_file.txt");
        }
        else
        {
            if (new System.IO.FileInfo(Application.persistentDataPath + "/auth_file.txt").Length == 0 && timeStart.AddSeconds(10) < DateTime.Now)
            {
                string androidID = mAndroidSID.GetSID();
                Debug.Log("SID is " + androidID);
                timeStart = DateTime.Now;
                if (authentification_state == 0)
                {
                    try
                    {
                        bool auth = mSharingServer.GetAuth();

                        if (auth == true)
                        {
                            authentification_state = 1;
                        }
                        else
                        {
                            mSharingServer.SendToServerAuthentication(androidID);
                        }
                    }
                    catch (Exception e)
                    {
                        Debug.Log(e.Message);
                    }
                }
                else
                {
                    string token = mSharingServer.GetToken();
                    if (token != null)
                    {
                        using (System.IO.StreamWriter outputFile = new System.IO.StreamWriter(Application.persistentDataPath + "/auth_file.txt"))
                        {
                            outputFile.WriteLine(token);
                        }
                        authentification_state = 2;
                    }
                    else
                    {
                        mSharingServer.SendToServerAskToken(androidID);
                    }
                }
            }
            else if (new System.IO.FileInfo(Application.persistentDataPath + "/auth_file.txt").Length != 0)
            {
                System.IO.StreamReader file = new System.IO.StreamReader(Application.persistentDataPath + "/auth_file.txt");
                string line = file.ReadLine();
                Debug.Log("Token :" + line);
                mSharingServer.SetToken(line);
                authentification_state = 3;
                mCurrentState          = ScreensStates.WELCOME;
                UpdateScreen();
            }
        }
    }