Пример #1
0
        public void WaitUntilDeviceVibrate(int timeoutMs)
        {
            int threadSleepTimeMs = 100;
            int threadLoopCount   = timeoutMs / threadSleepTimeMs + 1;
            VibrationEventListener eventListener = new VibrationEventListener();

            try
            {
                if (mDevice.RegisterHardwareEvent(GameDevice.HW_EVENT_VIBRATOR, eventListener) < 0)
                {
                    Log.E(TAG, "could not register vibrator event.");
                    return;
                }

                while (threadLoopCount-- > 0)
                {
                    if (eventListener.GetVibrated())
                    {
                        Log.D(TAG, "detect vibration, end event pulling looping");
                        return;
                    }
                    Thread.Sleep(threadSleepTimeMs);
                }
            }
            finally
            { // note that the exception will be rethrown
                mDevice.DeregisterHardwareEvent(GameDevice.HW_EVENT_VIBRATOR, eventListener);
            }
        }
Пример #2
0
        public ScreenColor GetColorOnScreen(int index, ScreenCoord src, bool refresh)
        {
            FileStream dumpFile;
            int        offset, ret = 0;

            byte[] colorInfo = new byte[4];

            offset = CalculateOffset(src);
            ScreenColor dest = new ScreenColor();

            try
            {
                if (refresh)
                {
                    ret = RequestRefresh();
                }

                dumpFile = mDevice.ScreenshotOpen(index);
                if (dumpFile == null)
                {
                    throw new Exception();
                }
                dumpFile.Seek(offset, SeekOrigin.Begin);
                dumpFile.Read(colorInfo, 0, 4);
                dest.r = colorInfo[0];
                dest.g = colorInfo[1];
                dest.b = colorInfo[2];
                dest.t = colorInfo[3];
            }
            catch (IOException e)
            {
                Log.E(TAG, "File operation failed: " + e.ToString());
                throw new JoshGameLibrary20.ScreenshotErrorException("screenshot error", ret);
            }
            catch (ThreadInterruptedException e)
            {
                Log.E(TAG, "File operation aborted by interrupt: " + e.ToString());
                throw e;
            }

            return(dest);
        }