示例#1
0
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);
            SetContentView(Resource.Layout.activity_cradle_custom_area);

            text = (EditText)FindViewById(Resource.Id.customValuesText);

            JoyaTouchCradleApplication application = (JoyaTouchCradleApplication)ApplicationContext;

            jtCradle = application.CradleJoyaTouch;

            if (savedInstanceState == null)
            {
                CustomArea custom = new CustomArea();
                if (jtCradle.ReadCustomArea(custom, custom.Size))
                {
                    customValues = custom.GetContent();
                    setTextUTF();
                }
                else
                {
                    Toast.MakeText(this, "Failure reading custom area. Retry.", ToastLength.Long).Show();
                }
            }

            // Handle READ button press
            Button readButton = FindViewById <Button>(Resource.Id.buttonReadCustom);

            readButton.Click += delegate
            {
                CustomArea custom = new CustomArea();
                if (jtCradle.ReadCustomArea(custom, custom.Size))
                {
                    customValues = custom.GetContent();
                    setTextUTF();
                }
                else
                {
                    Toast.MakeText(this, "Failure reading custom area. Retry.", ToastLength.Long).Show();
                }
            };

            // Handle CLEAR button press
            Button clearButton = FindViewById <Button>(Resource.Id.buttonClearCustom);

            clearButton.Click += delegate
            {
                CustomArea custom = new CustomArea();
                customValues = custom.GetContent();
                for (int i = 0; i < customValues.Length; i++)
                {
                    customValues[i] = 0;
                }
                if (jtCradle.WriteCustomArea(custom, custom.Size))
                {
                    text.Text = "";
                }
                else
                {
                    Toast.MakeText(this, "Failure clearing custom area. Retry.", ToastLength.Long).Show();
                }
            };

            // Handle WRITE button press
            Button writeButton = FindViewById <Button>(Resource.Id.buttonWriteCustom);

            writeButton.Click += delegate
            {
                try
                {
                    customValues = System.Text.Encoding.UTF8.GetBytes(text.Text);
                }
                catch (UnsupportedEncodingException)
                {
                    Toast.MakeText(this, "Wrong conversion of the UTF-8 string into custom area bytes.",
                                   ToastLength.Long).Show();
                    return;
                }

                CustomArea custom = new CustomArea((byte[])(Array)customValues);

                if (customValues == null || customValues.Length == 0 || customValues.Length > custom.Size)
                {
                    Toast.MakeText(this, "Invalid custom area bytes size.", ToastLength.Long).Show();
                    return;
                }

                if (jtCradle.WriteCustomArea(custom, custom.Size))
                {
                    Toast.MakeText(this, "Custom data written successfully.", ToastLength.Long).Show();
                }
                else
                {
                    Toast.MakeText(this, "Failure writing custom area. Retry.", ToastLength.Long).Show();
                }
            };
        }
示例#2
0
 public override void OnInspectorGUI()
 {
     m_target = (CustomArea)target;
     DrawGenerateButton();
     DrawDefaultInspector();
 }