Esempio n. 1
0
        private void SetBatchNumber(bool regenerate)
        {
            Context        AppContext             = Application.Context;
            AppPreferences applicationPreferences = new AppPreferences(AppContext);

            if (string.IsNullOrEmpty(applicationPreferences.GetAccessKey("batchnumber")) || regenerate)
            {
                Guid batch = Guid.NewGuid();
                applicationPreferences.SaveAccessKey("batchnumber", batch.ToString());
            }

            string batchnumber = applicationPreferences.GetAccessKey("batchnumber");
        }
Esempio n. 2
0
        public void OnLocationChanged(Location location)
        {
            currentLocation = location;
            Context        mContext = Application.Context;
            AppPreferences applicationPreferences = new AppPreferences(mContext);

            if (currentLocation == null)
            {
                TrackingScan.SetBackgroundColor(Android.Graphics.Color.LightPink);
                coordinates.Text = "No GPS fix yet ";
                //Error Message
            }
            else
            {
                applicationPreferences.SaveAccessKey("lastKnownLongitude", currentLocation.Longitude.ToString());
                applicationPreferences.SaveAccessKey("lastKnownLatitude", currentLocation.Latitude.ToString());
                coordinates.Text = "Lat:" + currentLocation.Latitude.ToString(("#.00000")) + " / Long:" + currentLocation.Longitude.ToString(("#.00000"));
            }
        }
        public override bool OnOptionsItemSelected(IMenuItem item)
        {
            int id = item.ItemId;

            switch (item.ItemId)
            {
            case Resource.Id.menu_settings:
                StartActivity(typeof(SettingsActivity));
                break;

            case Resource.Id.menu_signature:
                Context        mContext = Application.Context;
                AppPreferences applicationPreferences = new AppPreferences(mContext);
                applicationPreferences.SaveAccessKey("lastKnownLongitude", currentLocation.Longitude.ToString());
                applicationPreferences.SaveAccessKey("lastKnownLatitude", currentLocation.Latitude.ToString());
                StartActivity(typeof(SignaturPadActivity));
                break;

            case Resource.Id.menu_sqldata:
                StartActivity(typeof(SqliteActivity));
                break;

            case Resource.Id.menu_about:
                StartActivity(typeof(AboutActivity));
                break;

            case Resource.Id.menu_exportdata:
                ExportScanData();
                break;

            case Resource.Id.menu_exit:
                // This should exit the app
                this.FinishAffinity();
                break;
                ;
            }

            return(base.OnOptionsItemSelected(item));
        }
Esempio n. 4
0
        private void PushDataToEndPoint(string SignatureImage, string SignatureText)
        {
            Context        AppContext         = Application.Context;
            AppPreferences ap                 = new AppPreferences(AppContext);
            string         httpEndPoint       = ap.GetAccessKey("submitDataUrl");
            string         loadConfigUrl      = ap.GetAccessKey("loadConfigUrl");
            string         applicationKey     = ap.GetAccessKey("applicationKey");
            string         lastKnownLongitude = ap.GetAccessKey("lastKnownLongitude");
            string         lastKnownLatitude  = ap.GetAccessKey("lastKnownLatitude");
            string         retentionPeriod    = ap.GetAccessKey("retentionPeriod");
            string         databasePath       = System.IO.Path.Combine(
                System.Environment.GetFolderPath(System.Environment.SpecialFolder.Personal),
                GetString(Resource.String.database_name));
            // Create a Dictionary for the parameters
            Dictionary <string, string> Parameters = new Dictionary <string, string>
            {
                { "httpEndPoint", httpEndPoint },
                { "userAgent", "@string/user_agent" },
                { "token", applicationKey },
                { "retentionPeriod", retentionPeriod },
                { "SignatureImage", SignatureImage },
                { "SignatureText", SignatureText }
            };

            try
            {
                Parameters.Add("serialNumber", ap.GetAccessKey("serial" +
                                                               "Number"));
            }
            catch
            {
                Parameters.Add("serialNumber", "");
            }
            try
            {
                Parameters.Add("lontitude", lastKnownLongitude);
                Parameters.Add("latitude", lastKnownLatitude);
            }
            catch
            {
                Parameters.Add("lontitude", "");
                Parameters.Add("latitude", "");
            }
            Parameters.Add("databasePath", databasePath);

            bool status = false;

            try
            {
                // Run the SubmitCollectionData as a Async Task
                System.Threading.Tasks.Task taskA = System.Threading.Tasks.Task.Factory.StartNew(() => status = SubmitCollectionData(Parameters));
            }
            catch (Exception ex)
            {
                Log.Info("SubmitCollectionData", ex.Message);
            }



            // Create a new Batch number;
            SetBatchNumber(true);
            StartActivity(typeof(MainActivity));
        }
Esempio n. 5
0
        protected override void OnCreate(Bundle bundle)
        {
            base.OnCreate(bundle);


            SetContentView(Resource.Layout.activity_signature_pad);

            SignaturePadView signatureView = FindViewById <SignaturePadView>(Resource.Id.signatureView);

            Button btnCancel = FindViewById <Button>(Resource.Id.btnCancel);

            Button btnComplete = FindViewById <Button>(Resource.Id.btnComplete);

            EditText SignatureText = FindViewById <EditText>(Resource.Id.txtSignature);

            /*
             * SignatureText.TextChanged += delegate {
             *
             *      if (SignatureText.Length() > 0)
             *      {
             *          btnComplete.Enabled = true;
             *      }
             *      else
             *      {
             *          btnComplete.Enabled = true;
             *      }
             *  };
             */

            btnCancel.Click += delegate
            {
                StartActivity(typeof(MainActivity));
            };


            btnComplete.Click += async delegate
            {
                string path = Environment.GetExternalStoragePublicDirectory(Environment.DirectoryPictures).AbsolutePath;
                if (ContextCompat.CheckSelfPermission(this, Manifest.Permission.WriteExternalStorage) == (int)Permission.Granted ||
                    ContextCompat.CheckSelfPermission(this, Manifest.Permission.ReadExternalStorage) == (int)Permission.Granted)
                {
                    Context        mContext = Application.Context;
                    AppPreferences applicationPreferences = new AppPreferences(mContext);
                    string         batch  = applicationPreferences.GetAccessKey("batchnumber");
                    string         file   = System.IO.Path.Combine(path, batch + ".jpg");
                    string         result = "";
                    try
                    {
                        using (var bitmap = await signatureView.GetImageStreamAsync(SignatureImageFormat.Jpeg, Color.Black, Color.White, 1f))
                            using (var dest = File.OpenWrite(file))
                            {
                                await bitmap.CopyToAsync(dest);
                            }



                        byte[] data = File.ReadAllBytes(file);
                        // ... Convert byte array to Base64 string.
                        result = Convert.ToBase64String(data);
                        // ... Write Base64 string.
                        Console.WriteLine("ENCODED: " + result);
                    }
                    catch { }
                    PushDataToEndPoint(result, SignatureText.Text);
                }
            };
        }
Esempio n. 6
0
        protected override void OnCreate(Bundle savedInstanceState)
        {
            RequestedOrientation = ScreenOrientation.Portrait;
            Context        AppContext             = Application.Context;
            AppPreferences applicationPreferences = new AppPreferences(AppContext);

            base.OnCreate(savedInstanceState);

            SetContentView(Resource.Layout.activity_settings);
            Android.Support.V7.Widget.Toolbar toolbar = FindViewById <Android.Support.V7.Widget.Toolbar>(Resource.Id.toolbar);
            SetSupportActionBar(toolbar);

            // Load up any stored applicationPreferences
            TextView submitDataUrl = FindViewById <TextView>(Resource.Id.submit_data_url);

            submitDataUrl.Text = applicationPreferences.GetAccessKey("submitDataUrl");
            submitDataUrl.Text = submitDataUrl.Text.TrimEnd('\r', '\n');

            TextView loadConfigUrl = FindViewById <TextView>(Resource.Id.load_config_url);

            loadConfigUrl.Text = applicationPreferences.GetAccessKey("loadConfigUrl");
            loadConfigUrl.Text = loadConfigUrl.Text.TrimEnd('\r', '\n');

            TextView applicationKey = FindViewById <TextView>(Resource.Id.application_key);

            applicationKey.Text = applicationPreferences.GetAccessKey("applicationKey");
            applicationKey.Text = applicationKey.Text.TrimEnd('\r', '\n');

            TextView retentionPeriod = FindViewById <TextView>(Resource.Id.retention_period);

            retentionPeriod.Text = applicationPreferences.GetAccessKey("retentionPeriod");
            retentionPeriod.Text = retentionPeriod.Text.TrimEnd('\r', '\n');

            string databasePath = System.IO.Path.Combine(
                System.Environment.GetFolderPath(System.Environment.SpecialFolder.Personal),
                GetString(Resource.String.database_name));
            SQLiteConnection databaseConnection = new SQLiteConnection(databasePath);

            databaseConnection.CreateTable <ScanSKUDataBase.TrackingNumberPatterns>();

            PopulateRegExView();
            TrackingScan = FindViewById <EditText>(Resource.Id.txtentry);


            TrackingScan.Text = "";
            TrackingScan.RequestFocus();

            TrackingScan.KeyPress += (object sender, View.KeyEventArgs e) =>
            {
                if ((e.Event.Action == KeyEventActions.Down) && (e.KeyCode == Keycode.Enter))
                {
                    if (e.Event.RepeatCount == 0)
                    {
                        string jsonstring = TrackingScan.Text;
                        //jsonstring = Regex.Replace(jsonstring, @"\s+", "");
                        Configuration configuration = new Configuration();
                        try
                        {
                            configuration = JsonConvert.DeserializeObject <Configuration>(jsonstring);
                            if (configuration.UpdateConfiguration.Count == 1)
                            {
                                foreach (UpdateConfiguration configItem in configuration.UpdateConfiguration)
                                {
                                    submitDataUrl.Text   = configItem.UploadEndPoint.ToString();
                                    loadConfigUrl.Text   = configItem.RegexEndPoint.ToString();
                                    applicationKey.Text  = configItem.ApplicationKey.ToString();
                                    retentionPeriod.Text = configItem.RetentionPeriod.ToString();
                                }
                                // Save some application preferences
                                applicationPreferences.SaveAccessKey("submitDataUrl", submitDataUrl.Text, true);
                                applicationPreferences.SaveAccessKey("loadConfigUrl", loadConfigUrl.Text, true);
                                applicationPreferences.SaveAccessKey("applicationKey", applicationKey.Text, true);
                                applicationPreferences.SaveAccessKey("retentionPeriod", retentionPeriod.Text, true);
                                try
                                {
                                    applicationPreferences.SaveAccessKey("serialNumber", Android.OS.Build.Serial.ToString(), true);
                                }
                                catch
                                {
                                    applicationPreferences.SaveAccessKey("serialNumber", "", true);
                                }
                                Log.Info("TAG-SETTINGS", "Settings - Call FetchTrackingRegExData");
                                System.Threading.Tasks.Task taskA = System.Threading.Tasks.Task.Factory.StartNew(() => FetchTrackingRegExData(loadConfigUrl.Text));
                                taskA.Wait();
                                Toast.MakeText(this, "Config QR code read successful", ToastLength.Long).Show();
                            }
                        }
                        catch (Exception ex)
                        {
                            // Any Error in the above block will cause this catch to fire - Even if the json keys don't exist
                            Toast.MakeText(this, "Config QR code not recognised", ToastLength.Long).Show();
                        }
                        PopulateRegExView();
                        TrackingScan.Text = "";
                    }
                }
            };
        }
Esempio n. 7
0
        protected override void OnCreate(Bundle savedInstanceState)
        {
            RequestedOrientation = ScreenOrientation.Portrait;
            Context        AppContext             = Application.Context;
            AppPreferences applicationPreferences = new AppPreferences(AppContext);

            // Check application Preferences have been saved previously if not open Settings Activity and wait there.
            if (
                string.IsNullOrEmpty(applicationPreferences.GetAccessKey("submitDataUrl")) ||
                string.IsNullOrEmpty(applicationPreferences.GetAccessKey("loadConfigUrl")) ||
                string.IsNullOrEmpty(applicationPreferences.GetAccessKey("applicationKey")) ||
                string.IsNullOrEmpty(applicationPreferences.GetAccessKey("retentionPeriod"))
                )
            {
                // No, well start the setting activity
                StartActivity(typeof(SettingsActivity));
            }
            base.OnCreate(savedInstanceState);
            SetContentView(Resource.Layout.activity_main);

            Android.Support.V7.Widget.Toolbar toolbar = FindViewById <Android.Support.V7.Widget.Toolbar>(Resource.Id.toolbar);
            SetSupportActionBar(toolbar);
            // We only want to create a batch number here once when the app first starts and not everytime the activity loads
            if (batch == Guid.Empty)
            {
                SetBatchNumber(false);
            }
            FloatingActionButton fab = FindViewById <FloatingActionButton>(Resource.Id.fab);

            fab.Click += FabOnClick;

            databasePath = System.IO.Path.Combine(
                System.Environment.GetFolderPath(System.Environment.SpecialFolder.Personal),
                GetString(Resource.String.database_name));
            databaseConnection = new SQLiteConnection(databasePath);
            // Create the ParcelScans table
            databaseConnection.CreateTable <ScanSKUDataBase.ParcelScans>();
            if (ContextCompat.CheckSelfPermission(this, Manifest.Permission.AccessFineLocation) == (int)Permission.Granted)
            {
                mediaPlayer = MediaPlayer.Create(this, Resource.Raw.beep_07);
                TrackingNumberDataProvider();

                // We have permission, go ahead and use the GPS.
                Log.Debug("GPS", "We have permission, go ahead and use the GPS.");
                InitializeLocationManager();

                coordinates = FindViewById <TextView>(Resource.Id.footer_text);


                TrackingScan = FindViewById <EditText>(Resource.Id.txtentry);

                TrackingScan.Text = "";
                TrackingScan.RequestFocus();

                TrackingScan.KeyPress += (object sender, View.KeyEventArgs e) =>
                {
                    if ((e.Event.Action == KeyEventActions.Down) && (e.KeyCode == Keycode.Enter))
                    {
                        if (e.Event.RepeatCount == 0)
                        {
                            /// need to regex the scan against the Tracking Patterns
                            ///
                            TableQuery <TrackingNumberPatterns> trackingPatterns = databaseConnection.Table <TrackingNumberPatterns>();

                            bool patternFound = false;
                            try
                            {
                                foreach (var trackingPattern in trackingPatterns)
                                {
                                    Match m = Regex.Match(@TrackingScan.Text, @trackingPattern.Pattern, RegexOptions.IgnoreCase);
                                    if (m.Success)
                                    {
                                        patternFound = true;
                                    }
                                }
                            }
                            catch { }

                            if (patternFound)
                            {
                                ParcelScans newScan = new ScanSKUDataBase.ParcelScans
                                {
                                    TrackingNumber = TrackingScan.Text.ToUpper(),
                                    ScanTime       = DateTime.Now.ToString("yyyy-MM-ddTHH:mm:ss"),
                                    Batch          = batchnumber,
                                    Sent           = null
                                };
                                try
                                {
                                    newScan.Longitude = currentLocation.Longitude;
                                }
                                catch
                                {
                                    newScan.Longitude = null;
                                }
                                try
                                {
                                    newScan.Latitude = currentLocation.Latitude;
                                }
                                catch
                                {
                                    newScan.Latitude = null;
                                }
                                try
                                {
                                    databaseConnection.Insert(newScan);
                                    TextView TrackingListView = FindViewById <TextView>(Resource.Id.tracking_list);
                                    TrackingListView.Text = TrackingScan.Text.ToUpper() + System.Environment.NewLine + TrackingListView.Text;


                                    //mBarcodeScannerList.FetchUnCollected();

                                    //mAdapter.NotifyDataSetChanged();
                                    //mRecyclerView.RefreshDrawableState();
                                    mediaPlayer.Start();
                                }
                                catch (SQLiteException ex)
                                {
                                    Toast.MakeText(this, "Scan Error : Duplicated Barcode Scan", ToastLength.Long).Show();
                                    Log.Info("SCANNER", "Scan Error : " + ex.Message);
                                }
                            }
                            else
                            {
                                Toast.MakeText(this, "Barcode format not recognised", ToastLength.Short).Show();
                            }

                            TrackingScan.RequestFocus();
                            TrackingScan.Text = "";
                        }
                    }
                };
            }
            else
            {
                // GPS permission is not granted. If necessary display rationale & request.
                Log.Debug("GPS", "GPS permission is not granted");

                if (ActivityCompat.ShouldShowRequestPermissionRationale(this, Manifest.Permission.AccessFineLocation))
                {
                    // Provide an additional rationale to the user if the permission was not granted
                    // and the user would benefit from additional context for the use of the permission.
                    // For example if the user has previously denied the permission.
                    Log.Info("GPS", "Displaying GPS permission rationale to provide additional context.");
                    CoordinatorLayout rootView = FindViewById <CoordinatorLayout>(Resource.Id.root_view);


                    String[] requiredPermissions = new String[] { Manifest.Permission.AccessFineLocation };
                    ActivityCompat.RequestPermissions(this, requiredPermissions, REQUEST_LOCATION);
                }
                else
                {
                    ActivityCompat.RequestPermissions(this, new String[] { Manifest.Permission.AccessFineLocation }, REQUEST_LOCATION);
                }
            }
        }