Beispiel #1
0
        private static void TryImplicitlyInteroperate()
        {
            Console.WriteLine("Part3: Call by real-interop");

            var item = new Java.Lang.Object();

            Console.WriteLine(item.ToString());

            var item2 = new Java.Lang.String("Hello java!");

            Console.WriteLine(((Java.Lang.Object)item2).ToString());

            var item3 = new Java.Util.HashMap();

            Console.WriteLine(item3.ToString());

            var map = new Java.Util.HashMap <Java.Lang.String, Java.Lang.Integer>();

            map.Add((String)"One hundred", 100);
            map.Add((String)"Two hundred", 200);
            map.Add((String)"Hello", -100000);

            foreach (var kvp in map)
            {
                var key   = (string)kvp.Key;
                var value = (int)kvp.Value;
                Console.WriteLine($"{key} : {value}");
            }

            Console.WriteLine(map.ToString());
        }
Beispiel #2
0
        public static Java.Util.HashMap HashUser(string Email, string Phone, string Username)
        {
            var UserMap = new Java.Util.HashMap();

            UserMap.Put(nameof(Email), Email);
            UserMap.Put(nameof(Phone), Phone);
            UserMap.Put(nameof(Username), Username);
            return(UserMap);
        }
Beispiel #3
0
        public override Java.Lang.Object GetItem(int position)
        {
            Java.Util.HashMap map = new Java.Util.HashMap();

            foreach (var item in data[position])
            {
                map.Put(item.Key, item.Value.ToString());
            }

            return(map);
        }
Beispiel #4
0
        public static Java.Util.HashMap HashModel(Message t)
        {
            var properties = t.GetType().GetProperties();

            Java.Util.HashMap hashset            = new Java.Util.HashMap();
            System.Collections.IDictionary hDict = new Dictionary <string, object>();
            foreach (var item in properties)
            {
                hDict.Add(item.Name, item.GetValue(t, null));
            }
            hashset.PutAll(hDict);
            return(hashset);
        }
        async void InitGarmin()
        {
            var commStrategy = IQ.IQConnectType.Wireless;

            _iq = IQ.GetInstance(this, commStrategy);
            var initStatus = await _iq.InitializeAsync(this, autoUI : true);

            if (initStatus.HasError)
            {
                Log.Error("BindingTest", $"Received garmin SDK error {initStatus.ErrorStatus}");
                return;
            }

            var knownDevices = _iq.KnownDevices;

            _device = knownDevices.First(dev => dev.FriendlyName == "vivoactive HR");
            IQDevice.IQDeviceStatus status = _iq.GetDeviceStatus(_device);
            if (status != IQDevice.IQDeviceStatus.Connected)
            {
                return;
            }

            var appInfo = await _iq.GetApplicationInfoAsync("fc4cdb94-9339-44e4-ad86-2d235312f0e7", _device);

            if (!appInfo.Installed)
            {
                Log.Error("BindingTest", "Application not installed");
                return;
            }

            _app = appInfo.App;
            var javaMap = new Java.Util.HashMap();

            javaMap.Put(1, 6);
            var messageStatus = await _iq.SendMessageAsync(_device, _app, javaMap);

            Log.Info("BindingTest", $"Message status {messageStatus.MessageStatus}");
        }
Beispiel #6
0
        //Dictionary<string, Java.Lang.Object>
        public static Java.Util.HashMap Convert(this IIdentifiable item)
        {
            var dict = new Dictionary <string, Java.Lang.Object>();

            //var dict = new Java.Util.HashMap(dictionary);

            System.Diagnostics.Debug.WriteLine("\n\nConverting item\n\n"); //МУСОР

            var jsonStr = Newtonsoft.Json.JsonConvert.SerializeObject(item);

            System.Diagnostics.Debug.WriteLine("\n\nNewtonsoft.SerializeObject result -> " + jsonStr + "\n\n"); //МУСОР

            var propertyDict = Newtonsoft.Json.JsonConvert.DeserializeObject <Dictionary <string, object> >(jsonStr);

            System.Diagnostics.Debug.WriteLine("\n\nNewtonsoft.DeserializeObject result -> " + propertyDict + "\n\n"); //МУСОР



            foreach (var key in propertyDict.Keys)
            {
                System.Diagnostics.Debug.WriteLine("\n\nKey value -> " + key); //МУСОР

                if (key.Equals("Id"))
                {
                    continue;
                }
                var val = propertyDict[key];
                Java.Lang.Object javaVal = null;
                if (val is string str)
                {
                    javaVal = new Java.Lang.String(str);
                }
                else if (val is double dbl)
                {
                    javaVal = new Java.Lang.Double(dbl);
                }
                else if (val is int intVal)
                {
                    javaVal = new Java.Lang.Integer(intVal);
                }
                else if (val is DateTime dt)
                {
                    javaVal = dt.ToString();
                }
                else if (val is bool boolVal)
                {
                    javaVal = new Java.Lang.Boolean(boolVal);
                }
                else if (val is Stream stream)
                {
                    continue;
                }

                if (javaVal != null)
                {
                    System.Diagnostics.Debug.WriteLine("Java object value -> " + javaVal); //МУСОР
                    dict.Add(key, javaVal);
                    //dict.Put(key, javaVal);
                }
            }

            var javaDict = new Java.Util.HashMap(dict);

            return(javaDict);
        }