Ejemplo n.º 1
0
        void OnProductPurchased(int response, Purchase purchase, string purchaseData, string purchaseSignature)
        {
            DeviceDebugAndroid.LogToFileMethodStatic("appstore response: " + response + " // purchase: " + purchase + " // purchaseData: " + purchaseData + " // purchaseSignature: " + purchaseSignature);

            LoadPurchases();
            NotifyListener(PurchaseStatus.Purchased);
        }
Ejemplo n.º 2
0
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);

#if DEBUG
            Config.EnableDebugBuild();
#else
            if (Config.IsConfigForReleaseBuildValid() == false)
            {
                DeviceCrashReportAndroid.sendMail(new Throwable("Release build: Config check not passed"),
                                                  ApplicationContext.Resources.GetString(Resource.String.applicationName),
                                                  ApplicationContext.Resources.GetString(Resource.String.contactMail));
            }
#endif

            DeviceDebugAndroid.LogToFileMethodStatic();

            // init xamarin.forms framework in a new backgound task, splash stays on screen
            Task task = new Task
                        (
                delegate
            {
                Forms.Init(this, savedInstanceState);
                OxyPlot.Xamarin.Forms.Platform.Android.Forms.Init();
            }
                        );

            task.Start();
        }
Ejemplo n.º 3
0
        void InitSensor()
        {
            locationManager = Application.Context.GetSystemService(Context.LocationService) as LocationManager;
            DeviceDebugAndroid.LogToFileStatic("gps sensor requested");

            if (locationManager != null)
            {
                if (locationManager.IsProviderEnabled(LocationManager.GpsProvider))
                {
                    locationManager.RequestLocationUpdates(LocationManager.GpsProvider, 0, 0, this);
                    locationManager.AddGpsStatusListener(this);
                    location = locationManager.GetLastKnownLocation(LocationManager.GpsProvider);

                    status = IDeviceGpsStatus.Requested;
                    DeviceDebugAndroid.LogToFileStatic("gps sensor init ok");
                }
                else
                {
                    status = IDeviceGpsStatus.Disabled;
                    DeviceDebugAndroid.LogToFileStatic("ERROR: gps sensor not enabled");
                }
            }
            else
            {
                status = IDeviceGpsStatus.Disabled;
                DeviceDebugAndroid.LogToFileStatic("ERROR: gps locationManager is null");
            }
        }
Ejemplo n.º 4
0
        void OnPurchaseConsumed(string token)
        {
            DeviceDebugAndroid.LogToFileMethodStatic("appstore token: " + token);

            LoadPurchases();
            NotifyListener(PurchaseStatus.Consumed);
        }
Ejemplo n.º 5
0
        void OnDisconnected()
        {
            DeviceDebugAndroid.LogToFileMethodStatic();

            if (inAppBillingServiceConnection != null)
            {
                if (inAppBillingServiceConnection.BillingHandler != null)
                {
                    inAppBillingServiceConnection.BillingHandler.OnUserCanceled                    -= OnUserCanceled;
                    inAppBillingServiceConnection.BillingHandler.OnGetProductsError                -= OnGetProductsError;
                    inAppBillingServiceConnection.BillingHandler.OnProductPurchased                -= OnProductPurchased;
                    inAppBillingServiceConnection.BillingHandler.OnPurchaseConsumed                -= OnPurchaseConsumed;
                    inAppBillingServiceConnection.BillingHandler.OnProductPurchasedError           -= OnProductPurchasedError;
                    inAppBillingServiceConnection.BillingHandler.OnPurchaseConsumedError           -= OnPurchaseConsumedError;
                    inAppBillingServiceConnection.BillingHandler.OnPurchaseFailedValidation        -= OnPurchaseFailedValidation;
                    inAppBillingServiceConnection.BillingHandler.OnInvalidOwnedItemsBundleReturned -= OnInvalidOwnedItemsBundleReturned;
                    inAppBillingServiceConnection.BillingHandler.QueryInventoryError               -= OnQueryInventoryError;
                    inAppBillingServiceConnection.BillingHandler.InAppBillingProcesingError        -= OnInAppBillingProcessingError;
                    inAppBillingServiceConnection.BillingHandler.BuyProductError                   -= OnBuyProductError;
                }

                inAppBillingServiceConnection.OnConnected         -= OnConnected;
                inAppBillingServiceConnection.OnInAppBillingError -= OnInAppBillingError;
                inAppBillingServiceConnection.OnDisconnected      -= OnDisconnected;

                NotifyListener(PurchaseStatus.Disconnected);
            }
        }
Ejemplo n.º 6
0
        void InitSensor()
        {
            sensorManager = Application.Context.GetSystemService(Context.SensorService) as SensorManager;
            stopwatch     = new Stopwatch();
            stopwatch.Restart();
            isFirstRun           = true;
            sensorIsAccelerating = true; // moving forward, not backward

            if (sensorManager != null)
            {
                sensor = sensorManager.GetDefaultSensor(SensorType.Accelerometer);
                DeviceDebugAndroid.LogToFileStatic("accelerometer sensor requested");

                if (sensor != null)
                {
                    // SensorDelay.Ui   = approx 15 Hz = every 66 milliseconds
                    // SensorDelay.Game = approx 50 Hz = every 20 milliseconds
                    sensorManager.RegisterListener(this, sensor, SensorDelay.Game);
                    status = "sensor init";
                    DeviceDebugAndroid.LogToFileStatic("accelerometer sensor init ok");
                }
                else
                {
                    status = "sensor not enabled";
                    DeviceDebugAndroid.LogToFileStatic("ERROR: accelerometer sensor is null");
                }
            }
            else
            {
                status = "sensor manager not enabled";
                DeviceDebugAndroid.LogToFileStatic("ERROR: accelerometer sensorManager is null");
            }
        }
Ejemplo n.º 7
0
        public void OnLocationChanged(Location location) // ILocationListener
        {
            this.location = location;
            if (listener != null)
            {
                listener.OnGpsLocationUpdate();
            }

            DeviceDebugAndroid.LogToFileSensorGpsSpeedStatic((location != null) ? location.Speed : 0);
        }
Ejemplo n.º 8
0
        // activity is visible
        protected override void OnStart()
        {
            DeviceDebugAndroid.LogToFileMethodStatic();

            base.OnStart();

            devicePurchseAndroid.SetActivity(this);

            // connect to google play store
            devicePurchseAndroid.Connect();
        }
Ejemplo n.º 9
0
        public void OnActivityResult(int requestCode, Result resultCode, Intent data)
        {
            DeviceDebugAndroid.LogToFileMethodStatic("appstore result [requestCode, resultCode]: " + requestCode + ", " + resultCode);

            if (inAppBillingServiceConnection != null)
            {
                if (inAppBillingServiceConnection.BillingHandler != null)
                {
                    inAppBillingServiceConnection.BillingHandler.HandleActivityResult(requestCode, resultCode, data);
                }
            }
        }
Ejemplo n.º 10
0
        public void Disconnect()
        {
            DeviceDebugAndroid.LogToFileMethodStatic();

            if (inAppBillingServiceConnection != null)
            {
                if (inAppBillingServiceConnection.Connected)
                {
                    inAppBillingServiceConnection.Disconnect();
                }
            }
        }
Ejemplo n.º 11
0
        protected override void OnStart()
        {
            base.OnStart();
            DeviceDebugAndroid.LogToFileMethodStatic();

            // switch to the main app in a new backgound task
            Task task = new Task
                        (
                () => StartActivity(typeof(ActivityMain))
                        );

            task.Start();
        }
Ejemplo n.º 12
0
        public void Connect()
        {
            DeviceDebugAndroid.LogToFileMethodStatic();

            if (activity != null)
            {
                inAppBillingServiceConnection = new InAppBillingServiceConnection(activity, GetPublicKey());

                // below events are unregistered in OnDisconnect()
                inAppBillingServiceConnection.OnConnected         += OnConnected;
                inAppBillingServiceConnection.OnInAppBillingError += OnInAppBillingError;
                inAppBillingServiceConnection.OnDisconnected      += OnDisconnected;

                inAppBillingServiceConnection.Connect();
            }
        }
        void Log(string s = "",
                 [System.Runtime.CompilerServices.CallerMemberName] string methodName     = "",
                 [System.Runtime.CompilerServices.CallerFilePath]   string sourceFilePath = "")
        {
            if (s != null)
            {
                if (Config.Purchase.ListenerLogEnabled)
                {
                    if (listener != null)
                    {
                        listener.OnPurchaseLog(s);
                    }
                }

                DeviceDebugAndroid.LogToFileMethodStatic("appstore " + s, methodName, sourceFilePath);
            }
        }
Ejemplo n.º 14
0
        // activity is not visible or being distroyed by the system
        protected override void OnStop()
        {
            DeviceDebugAndroid.LogToFileMethodStatic();

            if (Config.Purchase.ConsumeOnExitEnabled)
            {
                base.OnStop();
                // disconnect from google play store
                devicePurchseAndroid.Disconnect();
            }
            else
            {
                // disconnect from google play store
                devicePurchseAndroid.Disconnect();
                base.OnStop();
            }
        }
Ejemplo n.º 15
0
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);
            DeviceDebugAndroid.LogToFileMethodStatic();

            // setup handler for uncaught exceptions
            Thread.DefaultUncaughtExceptionHandler = this;

            // request screen is always on
            Window.AddFlags(WindowManagerFlags.KeepScreenOn);

            //UncaughtException(null, new Exception());

            // our google play store
            devicePurchseAndroid = new DevicePurchaseAndroid();

            // start xamarin.forms app
            LoadApplication(new App());
        }
Ejemplo n.º 16
0
        void LoadPurchases()
        {
            DeviceDebugAndroid.LogToFileMethodStatic();

            if (purchases != null)
            {
                purchases.Clear();
            }
            else
            {
                purchases = new List <Purchase>();
            }

            if (inAppBillingServiceConnection != null)
            {
                if (inAppBillingServiceConnection.BillingHandler != null)
                {
                    purchases = inAppBillingServiceConnection.BillingHandler.GetPurchases(ItemType.Product);
                }
            }
        }
Ejemplo n.º 17
0
 void OnInvalidOwnedItemsBundleReturned(Bundle ownedItems)
 {
     DeviceDebugAndroid.LogToFileMethodStatic("appstore ownedItems: " + ownedItems);
 }
Ejemplo n.º 18
0
 void OnProductPurchasedError(int responseCode, string sku)
 {
     DeviceDebugAndroid.LogToFileMethodStatic("appstore responseCode: " + responseCode + " // sku: " + sku);
 }
Ejemplo n.º 19
0
 void OnGetProductsError(int responseCode, Bundle ownedItems)
 {
     DeviceDebugAndroid.LogToFileMethodStatic("appstore responseCode: " + responseCode + " // ownedItems: " + ownedItems);
 }
Ejemplo n.º 20
0
 void OnInAppBillingError(InAppBillingErrorType error, string message)
 {
     DeviceDebugAndroid.LogToFileMethodStatic("appstore *** error *** " + error + " // message: " + message);
 }
Ejemplo n.º 21
0
 public void OnProviderEnabled(string provider) // ILocationListener
 {
     status = IDeviceGpsStatus.Enabled;
     DeviceDebugAndroid.LogToFileMethodStatic(status.ToString());
 }
Ejemplo n.º 22
0
 void OnInAppBillingProcessingError(string message)
 {
     DeviceDebugAndroid.LogToFileMethodStatic("appstore message: " + message);
 }
Ejemplo n.º 23
0
        void OnBuyProductError(int responseCode, string sku)
        {
            DeviceDebugAndroid.LogToFileMethodStatic("appstore responseCode: " + responseCode + " // sku: " + sku);

            NotifyListener(PurchaseStatus.Cancelled);
        }
Ejemplo n.º 24
0
 void OnQueryInventoryError(int responseCode, Bundle skuDetails)
 {
     DeviceDebugAndroid.LogToFileMethodStatic("appstore responseCode: " + responseCode + " // skuDetails: " + skuDetails);
 }
Ejemplo n.º 25
0
        public void OnGpsStatusChanged(GpsEvent e) // GpsStatus.IListener
        {
            if (locationManager != null)
            {
                gpsStatus = locationManager.GetGpsStatus(gpsStatus);

                switch (e)
                {
                case GpsEvent.FirstFix:
                    status = IDeviceGpsStatus.FirstFix;
                    DeviceDebugAndroid.LogToFileMethodStatic("gps: " + status.ToString());
                    break;

                case GpsEvent.SatelliteStatus:
                    if (gpsStatus != null)
                    {
                        gpsSatellitesVisible       = 0;
                        gpsSatellitesUsedInFix     = 0;
                        gpsSatellitesWithEphemeris = 0;
                        gpsSatellitesWithAlmanac   = 0;

                        var satellites = gpsStatus.Satellites;
                        if (satellites != null)
                        {
                            Java.Util.IIterator iterator = satellites.Iterator();
                            {
                                while (iterator.HasNext)
                                {
                                    gpsSatellitesVisible++;

                                    var s = (GpsSatellite)iterator.Next();
                                    if (s.UsedInFix())
                                    {
                                        gpsSatellitesUsedInFix++;
                                    }
                                    if (s.HasEphemeris)
                                    {
                                        gpsSatellitesWithEphemeris++;
                                    }
                                    if (s.HasAlmanac)
                                    {
                                        gpsSatellitesWithAlmanac++;
                                    }
                                }
                            }

                            if (gpsSatellitesUsedInFix > 3)
                            {
                                status = IDeviceGpsStatus.Connected;
                            }
                        }
                    }
                    break;

                case GpsEvent.Started:
                    status = IDeviceGpsStatus.Started;
                    DeviceDebugAndroid.LogToFileMethodStatic("gps: " + status.ToString());
                    break;

                case GpsEvent.Stopped:
                    status = IDeviceGpsStatus.Stopped;
                    DeviceDebugAndroid.LogToFileMethodStatic("gps: " + status.ToString());
                    break;
                }

                if (listener != null)
                {
                    listener.OnGpsStatusUpdate();
                }
            }
        }
Ejemplo n.º 26
0
 void OnPurchaseConsumedError(int responseCode, string token)
 {
     DeviceDebugAndroid.LogToFileMethodStatic("appstore responseCode: " + responseCode + " // token: " + token);
 }
Ejemplo n.º 27
0
 void OnUserCanceled()
 {
     DeviceDebugAndroid.LogToFileMethodStatic("appstore user cancaled");
     NotifyListener(PurchaseStatus.Cancelled);
 }
Ejemplo n.º 28
0
 public void OnAccuracyChanged(Sensor sensor, SensorStatus accuracy) // ISensorEventListener
 {
     status = "sensor accuracy changed to " + accuracy;
     DeviceDebugAndroid.LogToFileMethodStatic(status);
 }
Ejemplo n.º 29
0
        public void OnSensorChanged(SensorEvent e) // ISensorEventListener
        {
            if (e != null)
            {
                if ((e.Sensor.Type == SensorType.LinearAcceleration) || (e.Sensor.Type == SensorType.Accelerometer))
                {
                    long launchTimeNow = stopwatch.ElapsedMilliseconds;

                    sensorX = e.Values[0];
                    sensorY = e.Values[1];
                    sensorZ = e.Values[2];

                    sensorTimestamp = e.Timestamp;

                    // e.Timestamp = nanoseconds since 01. januar 1970
                    // e.Timestamp / 1 000 000 000 = seconds

                    if (isFirstRun)
                    {
                        isFirstRun              = false;
                        launchTimeLastUpdate    = launchTimeNow;
                        launchTimeDetectedStart = 0;
                        sensorTimestampFirst    = sensorTimestamp;
                        sensorAcceleration      = 0;
                        sensorSpeed             = 0;
                        DeviceDebugAndroid.LogToFileMethodStatic("first values received");
                        DeviceDebugAndroid.LogToFileMethodStatic("accelerometer info: " + GetInfo());
                    }
                    else
                    {
                        sensorXDelta = sensorX - sensorXLast;
                        sensorYDelta = sensorY - sensorYLast;
                        sensorZDelta = sensorZ - sensorZLast;

                        sensorTimestampDelta = sensorTimestampLast - sensorTimestamp;

                        var dt           = sensorTimestampDelta / 1000000000.0f; // from nanoseconds to seconds
                        var sensorSpeedX = sensorXDelta * dt;                    // from acceleration to velocity (x component)
                        var sensorSpeedY = sensorYDelta * dt;                    // from acceleration to velocity (y component)
                        var sensorSpeedZ = sensorZDelta * dt;                    // from acceleration to velocity (z component)

                        // speed magnitude of all components
                        var magnitude = (float)Math.Sqrt(sensorSpeedX * sensorSpeedX + sensorSpeedY * sensorSpeedY + sensorSpeedZ * sensorSpeedZ);

                        // integrate the magnitude onto previous speed
                        // take the direction into account
                        if (sensorIsAccelerating)
                        {
                            sensorSpeed += magnitude;
                        }
                        else
                        {
                            sensorSpeed -= magnitude;
                        }

                        // acceleration calculation
                        var sensorXCompensated = sensorX - sensorAxisOffsetX;
                        var sensorYCompensated = sensorY - sensorAxisOffsetY;
                        var sensorZCompensated = sensorZ - sensorAxisOffsetZ;

                        // acceleration magnitude of all components
                        sensorAcceleration = (float)Math.Sqrt(sensorXCompensated * sensorXCompensated +
                                                              sensorYCompensated * sensorYCompensated +
                                                              sensorZCompensated * sensorZCompensated);

                        if (isRawDataLoggingEnabled)
                        {
                            DeviceDebugAndroid.LogToFileSensorStatic(GetTimeStamp(), sensorX, sensorY, sensorZ, sensorAcceleration);
                        }

                        long launchTimeDiff = launchTimeNow - launchTimeLastUpdate;

                        if (launchTimeDiff > launchTimeUpdateInterval)
                        {
                            launchTimeLastUpdate = launchTimeNow;
                            var launchForce = Math.Abs(sensorXDelta + sensorYDelta + sensorZDelta);

                            if (launchForce * 10 > launchForceDetectLimit)
                            {
                                if (launchTimeDetectedStart == 0)
                                {
                                    launchTimeDetectedStart = launchTimeNow;
                                }

                                if (launchTimeNow - launchTimeDetectedStart > launchTimeDetectLimit)
                                {
                                    if (listener != null)
                                    {
                                        listener.OnAcceleromterLaunchDetected();
                                        launchTimeDetectedStart = 0;
                                    }
                                }
                            }
                        }
                    }

                    sensorXLast         = sensorX;
                    sensorYLast         = sensorY;
                    sensorZLast         = sensorZ;
                    sensorTimestampLast = sensorTimestamp;

                    if (listener != null)
                    {
                        listener.OnAcceleromterUpdate();
                    }
                }
            }
        }
Ejemplo n.º 30
0
 void OnPurchaseFailedValidation(Purchase purchase, string purchaseData, string purchaseSignature)
 {
     DeviceDebugAndroid.LogToFileMethodStatic("appstore purchase: " + purchase + " // purchaseData: " + purchaseData + " // purchaseSignature: " + purchaseSignature);
 }