Ejemplo n.º 1
0
        protected override void OnCreate(Bundle bundle)
        {
            base.OnCreate(bundle);
            var folderPath = Android.OS.Environment.ExternalStorageDirectory.AbsolutePath;
            folderPath = Path.Combine(folderPath, "_signatureRecognition");
            CurSignature = new Signature();

            SetContentView(Resource.Layout.Main);

            FloatingActionButton floatingButton = FindViewById<FloatingActionButton>(Resource.Id.flBtn);
            floatingButton.Click += (sender, args) =>
            {
                _flag = false;
                var name = FindViewById<EditText>(Resource.Id.edittext);
                if (!Directory.Exists(folderPath))
                {
                    Directory.CreateDirectory(folderPath);
                }

                string path;
                if (string.IsNullOrEmpty(name.Text))
                {
                    path = Path.Combine(folderPath, "cur_signature.xml");
                }
                else
                {
                    path = Path.Combine(folderPath, name.Text + ".xml");
                }
                var state = FindViewById<TextView>(Resource.Id.state);
                    state.SetText("stopsave",TextView.BufferType.Normal);

                var curSignatures = new Signatures();

                if (CurSignature.Points.Count != 0)
                {
                    if (File.Exists(path))
                    {
                        using (var fileStream = new FileStream(path, FileMode.OpenOrCreate, FileAccess.Read))
                        {
                            using (var streamReader = new StreamReader(fileStream))
                            {
                                XmlSerializer serializer =
                                    new XmlSerializer(typeof(Signatures));
                                curSignatures = (Signatures)serializer.Deserialize(streamReader);
                            }
                        }
                    }

                    using (var fileStream = new FileStream(path, FileMode.OpenOrCreate, FileAccess.Write))
                    {
                        CurSignature.Name = FindViewById<EditText>(Resource.Id.edittext).Text;
                        curSignatures.SList.Add(CurSignature);

                        var encoding = Encoding.UTF8;
                        using (var streamWriter = new StreamWriter(fileStream, encoding))
                        {
                            XmlSerializer serializer =
                                new XmlSerializer(typeof(Signatures));
                            serializer.Serialize(streamWriter, curSignatures);
                        }
                    }
                }
                //});
            };

            FloatingActionButton floatingButtonClear = FindViewById<FloatingActionButton>(Resource.Id.flBtnClearAndStop);
            floatingButtonClear.Click += (sender, args) =>
            {
                _flag = false;
                CurSignature = new Signature();
                FindViewById<DrawingView>(Resource.Id.drawing).Clear();

                var state = FindViewById<TextView>(Resource.Id.state);
                state.SetText("stopclear",TextView.BufferType.Normal);
            };

            var drawerView = FindViewById<DrawingView>(Resource.Id.drawing);
            drawerView.OnCoordinatesChange += CoordinatesChangedHandler;
        }
Ejemplo n.º 2
0
        private void открытьToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Stream myStream = null;
            openFileDialog.Filter = "xML files (*.xml)|*.xml";
            openFileDialog.FilterIndex = 1;

            if (openFileDialog.ShowDialog() == DialogResult.OK)
            {
                try
                {
                    if ((myStream = openFileDialog.OpenFile()) != null)
                    {
                        using (myStream)
                        {
                            XmlSerializer serializer = new XmlSerializer(typeof(Signatures));
                            XmlReader reader = XmlReader.Create(myStream);

                            Signatures = (Signatures)serializer.Deserialize(reader);
                            myStream.Close();
                            UpdateData();
                        }
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show("Error: Could not read file from disk. Original error: " + ex.Message);
                }
            }
        }