protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);
            SetContentView(Resource.Layout.Main);

            // Fill the Adapter with the available activity names/classes
            ListView listMainActivities   = (ListView)FindViewById(Resource.Id.listMainActivities);
            ArrayAdapter <string> adapter = new ArrayAdapter <string>(this,
                                                                      Android.Resource.Layout.SimpleListItem1, ACT_NAMES);

            listMainActivities.Adapter    = adapter;
            listMainActivities.ItemClick += delegate(object sender, ListView.ItemClickEventArgs e)
            {
                JoyaTouchCradleApplication application = (JoyaTouchCradleApplication)ApplicationContext;
                ICradleJoyaTouch           jtCradle    = application.CradleJoyaTouch;
                if (jtCradle.IsDeviceInCradle)
                {
                    // Execute the reset without calling any activity
                    if (ACT_NAMES[e.Position].Equals("Reset"))
                    {
                        jtCradle.Reset();
                    }
                    else
                    {
                        Intent intent = new Intent(this, ACT_CLASSES[e.Position]);
                        StartActivity(intent);
                    }
                }
                else
                {
                    Toast.MakeText(this, "Device is not in Cradle. Retry after insertion.",
                                   ToastLength.Long).Show();
                }
            };


            if (savedInstanceState == null)
            {
                // Get the JoyaTouchCradle instance
                ICradle cradle = CradleManager.Cradle;

                if (cradle != null && cradle.Type == CradleType.JoyaTouchCradle)
                {
                    JoyaTouchCradleApplication application = (JoyaTouchCradleApplication)ApplicationContext;
                    application.CradleJoyaTouch = (ICradleJoyaTouch)cradle;
                }
                else
                {
                    Toast.MakeText(this, "JoyaTouchCradle not found. Cannot execute samples.",
                                   ToastLength.Long).Show();
                    Finish();
                }
            }
        }
Exemple #2
0
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);
            SetContentView(Resource.Layout.activity_cradle_state_info);

            JoyaTouchCradleApplication application = (JoyaTouchCradleApplication)ApplicationContext;

            jtCradle = application.CradleJoyaTouch;

            textDeviceInCradle = (TextView)FindViewById(Resource.Id.textDeviceInCradle);
            textState          = (TextView)FindViewById(Resource.Id.textState);

            if (savedInstanceState == null)
            {
                // Change displayed text.
                updateContent();
            }
        }
Exemple #3
0
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);
            SetContentView(Resource.Layout.activity_cradle_lock);

            JoyaTouchCradleApplication application = (JoyaTouchCradleApplication)ApplicationContext;

            jtCradle = application.CradleJoyaTouch;

            // Fill the Adapter with the available LED names/actions
            ListView listMainActivities   = (ListView)FindViewById(Resource.Id.listLockActions);
            ArrayAdapter <String> adapter = new ArrayAdapter <String>(this,
                                                                      Android.Resource.Layout.SimpleListItem1, NAMES);

            listMainActivities.Adapter    = adapter;
            listMainActivities.ItemClick += delegate(object sender, ListView.ItemClickEventArgs e)
            {
                SetLock(ACTIONS[e.Position]);
            };
        }
Exemple #4
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();
                }
            };
        }
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);
            SetContentView(Resource.Layout.activity_cradle_config_area);

            JoyaTouchCradleApplication application = (JoyaTouchCradleApplication)ApplicationContext;

            jtCradle = application.CradleJoyaTouch;

            if (savedInstanceState == null)
            {
                ConfigArea config = new ConfigArea();
                if (jtCradle.ReadConfigArea(config))
                {
                    configValues = config.GetContent();
                }
                else
                {
                    Toast.MakeText(this, "Failure reading config area. Retry.", ToastLength.Long).Show();
                }
            }
            else
            {
                configValues = savedInstanceState.GetByteArray("configValues");
            }

            ConfigAreaAdapter adapter = new ConfigAreaAdapter(this, configValues);

            grid         = (GridView)FindViewById(Resource.Id.configValuesGrid);
            grid.Adapter = adapter;

            // handle read button
            Button readButton = FindViewById <Button>(Resource.Id.buttonReadConfig);

            readButton.Click += delegate
            {
                ConfigArea config = new ConfigArea();
                if (jtCradle.ReadConfigArea(config))
                {
                    configValues = config.GetContent();
                    ConfigAreaAdapter aTemp = new ConfigAreaAdapter(this, configValues);
                    grid.Adapter = aTemp;
                    grid.Invalidate();
                }
                else
                {
                    Toast.MakeText(this, "Failure reading config area. Retry.", ToastLength.Long).Show();
                }
            };

            // handle write button
            Button writeButton = FindViewById <Button>(Resource.Id.buttonWriteConfig);

            writeButton.Click += delegate
            {
                ConfigArea config = new ConfigArea(configValues);
                if (jtCradle.WriteConfigArea(config))
                {
                    Toast.MakeText(this, "Config data written successfully.", ToastLength.Long).Show();
                }
                else
                {
                    Toast.MakeText(this, "Failure writing config area. Retry.", ToastLength.Long).Show();
                }
            };
        }