/*
 *  protected override void EntryRemoved(bool evicted, Java.Lang.Object key, Java.Lang.Object oldValue, Java.Lang.Object newValue) {
 *    base.EntryRemoved(evicted, key, oldValue, newValue);
 *
 *    var bitmap = oldValue as Bitmap;
 *    if (bitmap != null) {
 *      bitmap.Recycle();
 *    }
 *  }
 */

        /// <summary>
        /// Queries the given drawable from the bitmap cache. If the drawable is not
        /// currently in the cache, it will be infated and added.
        /// </summary>
        /// <param name="drawableRes"></param>
        /// <returns></returns>
        public Bitmap GetBitmap(int drawableRes, bool tryAgain = false)
        {
            try {
                Java.Lang.Integer id  = new Java.Lang.Integer(drawableRes);
                Bitmap            ret = (Bitmap)Get(id);

                if (ret == null)
                {
                    ret = BitmapFactory.DecodeResource(res, drawableRes);
                    Put(id, ret);
                }

                return(ret);
            } catch (OutOfMemoryException e) {
                Log.E(this, "Cache caught an OutOfMemoryException while attempting to acquire bitmap.", e);
                Clear();
                if (tryAgain)
                {
                    return(GetBitmap(drawableRes, true));
                }
                else
                {
                    return(BitmapFactory.DecodeResource(res, drawableRes));
                }
            } catch (Exception e) {
                Log.E(this, "Failed to get bitmap for an unknown reason", e);
                Clear();
                return(BitmapFactory.DecodeResource(res, drawableRes));
            }
        }
Exemplo n.º 2
0
        private DateTime dateTimeAdapter(DateTime originalDateTime, Java.Lang.Integer hour, Java.Lang.Integer minute, int offset = 0)
        {
            string dateTimeString = originalDateTime.ToString().Remove(originalDateTime.ToString().Length - 8);

            minute = new Java.Lang.Integer(minute.IntValue() + offset);
            string timeString = hour.ToString() + ":" + minute.ToString() + ":00";

            return(Convert.ToDateTime(dateTimeString + timeString));
        }
Exemplo n.º 3
0
        // Fills in a PDF form and saves the result
        public void fillForm(object sender, EventArgs e)
        {
            try
            {
                // Load the document and get the AcroForm
                using (var document = PDDocument.Load(assetManager.Open("FormTest.pdf")))
                    using (var docCatalog = document.DocumentCatalog)
                        using (var acroForm = docCatalog.AcroForm)
                        {
                            // Fill the text field
                            using (var field = (PDTextField)acroForm.GetField("TextField"))
                            {
                                field.Value = "Filled Text Field";
                                // Optional: don't allow this field to be edited
                                field.ReadOnly = true;
                            }

                            using (var checkbox = acroForm.GetField("Checkbox"))
                            {
                                ((PDCheckbox)checkbox).Check();
                            }

                            using (var radio = acroForm.GetField("Radio"))
                            {
                                ((PDRadioButton)radio).Value = "Second";
                            }

                            // TODO: Use List<int>
                            using (var listbox = acroForm.GetField("ListBox"))
                            {
                                List <Integer> listValues = new List <Integer>();
                                listValues.Add(Integer.ValueOf(1.ToString()));
                                listValues.Add(Integer.ValueOf(2.ToString()));
                                ((PDListBox)listbox).SelectedOptionsIndex = listValues;
                            }

                            /*
                             * // TODO: Fix Exception
                             * using (var dropdown = acroForm.GetField("Dropdown"))
                             * {
                             *      IList<string> list = new List<string>();
                             *      list.Add("Hello");
                             *      ((PDComboBox)dropdown).Value = list;
                             * }
                             */

                            string path = root.AbsolutePath + "/FilledForm.pdf";
                            tv.Text = "Saved filled form to " + path;
                            document.Save(path);
                            document.Close();
                        }
            }
            catch (IOException ex)
            {
                Log.Error("PdfBox-Android-Sample", "Exception thrown while filling form fields", ex);
            }
        }
            void jni_start(int tun, bool fwd53, int rcode, string proxyIp, int proxyPort)
            {
                var tun_       = new Java.Lang.Integer(tun);
                var fwd53_     = new Java.Lang.Boolean(fwd53);
                var rcode_     = new Java.Lang.Integer(rcode);
                var proxyIp_   = new Java.Lang.String(proxyIp);
                var proxyPort_ = new Java.Lang.Integer(proxyPort);

                jni_start(JNIEnv.Handle, Handle, tun_.Handle, fwd53_.Handle, rcode_.Handle, proxyIp_.Handle, proxyPort_.Handle);
            }
Exemplo n.º 5
0
 public void NewObjectArray_UsesOnlyTypeParameter()
 {
     using (var s = new Java.Lang.String("foo"))
         using (var i = new Java.Lang.Integer(42)) {
             var array = JNIEnv.NewObjectArray <Java.Lang.Object> (s, i);
             Assert.AreNotEqual(IntPtr.Zero, array, "#1");
             Assert.AreEqual("[Ljava/lang/Object;", JNIEnv.GetClassNameFromInstance(array), "#2");
             Assert.AreEqual(2, JNIEnv.GetArrayLength(array));
             JNIEnv.DeleteLocalRef(array);
         }
 }
Exemplo n.º 6
0
        public void JavaConvert_FromJavaObject_ShouldNotBreakExistingReferences()
        {
            Func <IJavaObject, int> toInt = GetIJavaObjectToInt32();

            using (var instance = new Java.Lang.Integer(42)) {
                Assert.AreSame(instance, Java.Lang.Object.GetObject <Java.Lang.Integer>(instance.Handle, JniHandleOwnership.DoNotTransfer));
                Assert.IsTrue(Java.Interop.Runtime.GetSurfacedObjects()
                              .Any(o => object.ReferenceEquals(o.Target, instance)));
                int e = toInt(instance);
                Assert.AreEqual(42, e);
                Assert.AreSame(instance, Java.Lang.Object.GetObject <Java.Lang.Integer>(instance.Handle, JniHandleOwnership.DoNotTransfer));
            }
        }
Exemplo n.º 7
0
        private void SendDeepLink()
        {
            int amount = 100;

            Java.Lang.Integer installmentCount = (Java.Lang.Integer)null;
            String            returnScheme     = "xamarindeeplink";

            Java.Lang.Integer orderId        = null;
            Java.Lang.Boolean editableAmount = Java.Lang.Boolean.False;

            PaymentInfo paymentInfo = new PaymentInfo(amount, TransactionType.Credit, installmentCount, orderId, editableAmount, returnScheme, InstallmentType.Merchant);

            payment.SendDeepLink(paymentInfo);
        }
        public void JavaCast_InterfaceCast()
        {
            IntPtr g;

            using (var n = new Java.Lang.Integer(42)) {
                g = JNIEnv.NewGlobalRef(n.Handle);
            }
            // We want a Java.Lang.Object so that we create an IComparableInvoker
            // instead of just getting back the original instance.
            using (var o = Java.Lang.Object.GetObject <Java.Lang.Object> (g, JniHandleOwnership.TransferGlobalRef)) {
                var c = JavaObjectExtensions.JavaCast <Java.Lang.IComparable> (o);
                c.Dispose();
            }
        }
Exemplo n.º 9
0
        private void setNumericAttr(object sender, EventArgs e)
        {
            EditText numericKey   = FindViewById <EditText>(Resource.Id.numeric_key);
            EditText numericValue = FindViewById <EditText>(Resource.Id.numeric_value);

            if (numericKey.Text.Length > 0 && numericValue.Text.Length > 0)
            {
                int v = Convert.ToInt32(Convert.ToDecimal(numericValue.Text));

                Java.Lang.Integer intObj = new Java.Lang.Integer(v);
                Java.Lang.Number  numObj = (Java.Lang.Number)intObj;
                appoxeeInstance.SetAttribute(numericKey.Text, numObj);
            }
        }
Exemplo n.º 10
0
        public void Put(string key, int value)
        {
            if (id_put_Ljava_lang_String_Ljava_lang_Integer_ == IntPtr.Zero)
            {
                id_put_Ljava_lang_String_Ljava_lang_Integer_ = JNIEnv.GetMethodID(class_ref, "put", "(Ljava/lang/String;Ljava/lang/Integer;)V");
            }
            IntPtr jkey = JNIEnv.NewString(key);

            try {
                using (var val = new Java.Lang.Integer(value))
                    JNIEnv.CallVoidMethod(Handle, id_put_Ljava_lang_String_Ljava_lang_Integer_, new JValue(jkey), new JValue(val));
            } finally {
                JNIEnv.DeleteLocalRef(jkey);
            }
        }
Exemplo n.º 11
0
        public void OnClick(View view)
        {
            string     queryText   = queryInput.Text;
            string     language    = languageInput.Text;
            string     countryCode = countryCodeInput.Text;
            double     lat         = double.Parse(latitudeInput.Text, CultureInfo.InvariantCulture);
            double     lon         = double.Parse(longitudeInput.Text, CultureInfo.InvariantCulture);
            Coordinate location    = new Coordinate(lat, lon);

            Java.Lang.Integer radius    = Java.Lang.Integer.ValueOf(radiusInput.Text);
            Java.Lang.Integer pageIndex = Java.Lang.Integer.ValueOf(pageIndexInput.Text);
            Java.Lang.Integer pageSize  = Java.Lang.Integer.ValueOf(pageSizeInput.Text);

            switch (view.Id)
            {
            case Resource.Id.btn_search_place:
                TextSearchRequest textSearchRequest = new TextSearchRequest();
                textSearchRequest.Query       = queryText;
                textSearchRequest.Language    = language;
                textSearchRequest.CountryCode = countryCode;
                textSearchRequest.Location    = location;
                textSearchRequest.Radius      = radius;
                textSearchRequest.PageIndex   = pageIndex;
                textSearchRequest.PageSize    = pageSize;

                TextSearchResultListener textSearchResultListener = new TextSearchResultListener();
                searchService.TextSearch(textSearchRequest, textSearchResultListener);

                break;

            case Resource.Id.btn_search_nearby_place:
                NearbySearchRequest nearbySearchRequest = new NearbySearchRequest();
                nearbySearchRequest.Query     = queryText;
                nearbySearchRequest.Language  = language;
                nearbySearchRequest.Location  = location;
                nearbySearchRequest.Radius    = radius;
                nearbySearchRequest.PageIndex = pageIndex;
                nearbySearchRequest.PageSize  = pageSize;

                NearbySearchResultListener nearbySearchResultListener = new NearbySearchResultListener();
                searchService.NearbySearch(nearbySearchRequest, nearbySearchResultListener);

                break;

            default:
                break;
            }
        }
Exemplo n.º 12
0
        public int GetAsInteger(string key)
        {
            if (id_getAsInteger_Ljava_lang_String_ == IntPtr.Zero)
            {
                id_getAsInteger_Ljava_lang_String_ = JNIEnv.GetMethodID(class_ref, "getAsInteger", "(Ljava/lang/String;)Ljava/lang/Integer;");
            }
            IntPtr jkey = JNIEnv.NewString(key);

            try {
                using (var ret = new Java.Lang.Integer(JNIEnv.CallObjectMethod(Handle, id_getAsInteger_Ljava_lang_String_, new JValue(jkey)),
                                                       JniHandleOwnership.TransferLocalRef | JniHandleOwnership.DoNotRegister))
                    return((int)ret);
            } finally {
                JNIEnv.DeleteLocalRef(jkey);
            }
        }
Exemplo n.º 13
0
 /// <summary>
 /// 初始化摄像头
 /// </summary>
 private void InitCamera()
 {
     try
     {
         CameraManager = (CameraManager)Context.GetSystemService(Context.CameraService);
         var cameraId = ((int)choseCameraFacing).ToString();
         this.CameraCharacteristics = CameraManager.GetCameraCharacteristics(cameraId);
         var jk  = new Java.Lang.Integer((int)CameraCharacteristics.Get(CameraCharacteristics.InfoSupportedHardwareLevel));
         var map = (StreamConfigurationMap)CameraCharacteristics.Get(CameraCharacteristics.ScalerStreamConfigurationMap);
         previewSize = map.GetOutputSizes(Java.Lang.Class.FromType(typeof(SurfaceTexture)))[0];
         CameraManager.OpenCamera(cameraId, GetCameraStateCallBack(), null);
     }
     catch (Exception ex)
     {
     }
 }
Exemplo n.º 14
0
        public static Dictionary <string, Java.Lang.Object> Convert(this IIdentifiable item)
        {
            var dict = new Dictionary <string, Java.Lang.Object>();

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

            foreach (var key in propertyDict.Keys)
            {
                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);
                }

                if (javaVal != null)
                {
                    dict.Add(key, javaVal);
                }
            }

            return(dict);
        }
Exemplo n.º 15
0
 public static int intValue(this Java.Lang.Integer integer)
 {
     return(integer.IntValue());
 }
Exemplo n.º 16
0
 public void Put(string key, int value)
 {
     if (id_put_Ljava_lang_String_Ljava_lang_Integer_ == IntPtr.Zero)
         id_put_Ljava_lang_String_Ljava_lang_Integer_ = JNIEnv.GetMethodID (class_ref, "put", "(Ljava/lang/String;Ljava/lang/Integer;)V");
     IntPtr jkey = JNIEnv.NewString (key);
     try {
         using (var val = new Java.Lang.Integer (value))
             JNIEnv.CallVoidMethod (Handle, id_put_Ljava_lang_String_Ljava_lang_Integer_, new JValue (jkey), new JValue (val));
     } finally {
         JNIEnv.DeleteLocalRef (jkey);
     }
 }
Exemplo n.º 17
0
 public int GetAsInteger(string key)
 {
     if (id_getAsInteger_Ljava_lang_String_ == IntPtr.Zero)
         id_getAsInteger_Ljava_lang_String_ = JNIEnv.GetMethodID (class_ref, "getAsInteger", "(Ljava/lang/String;)Ljava/lang/Integer;");
     IntPtr jkey = JNIEnv.NewString (key);
     try {
         using (var ret = new Java.Lang.Integer (JNIEnv.CallObjectMethod (Handle, id_getAsInteger_Ljava_lang_String_, new JValue (jkey)),
                 JniHandleOwnership.TransferLocalRef | JniHandleOwnership.DoNotRegister))
             return (int) ret;
     } finally {
         JNIEnv.DeleteLocalRef (jkey);
     }
 }
            void jni_stop(int tun)
            {
                var tun_ = new Java.Lang.Integer(tun);

                jni_stop(JNIEnv.Handle, Handle, tun_.Handle);
            }
Exemplo n.º 19
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);
        }
        internal static Notification ToNotification(this Huawei.Hms.Push.RemoteMessage.Notification notification)
        {
            Notification result = new Notification();

            PropertyInfo[] properties = typeof(Notification).GetProperties();
            foreach (PropertyInfo property in properties)
            {
                PropertyInfo notificationProperty = notification.GetType().GetProperty(property.Name);
                if (notificationProperty != null)
                {
                    if (property.PropertyType == notificationProperty.PropertyType)
                    {
                        property.SetValue(result, notificationProperty.GetValue(notification, null));
                    }
                    else if (notificationProperty.PropertyType == typeof(Java.Lang.Integer) && property.PropertyType == typeof(int?))//Java.Lang.Integer to int?
                    {
                        object            valueToSet = notificationProperty.GetValue(notification, null);
                        Java.Lang.Integer javaInt    = valueToSet as Java.Lang.Integer;
                        if (javaInt != null)
                        {
                            property.SetValue(result, javaInt.IntValue());
                        }
                        else
                        {
                            Log.Error("ToNotification", $"({property.PropertyType.FullName}){property.Name} is null");
                        }
                    }
                    else if (notificationProperty.PropertyType == typeof(Java.Lang.Long) && property.PropertyType == typeof(long?))//Java.Lang.Long to long?
                    {
                        object         valueToSet = notificationProperty.GetValue(notification, null);
                        Java.Lang.Long javaLong   = valueToSet as Java.Lang.Long;
                        if (javaLong != null)
                        {
                            property.SetValue(result, javaLong.IntValue());
                        }
                        else
                        {
                            Log.Error("ToNotification", $"({property.PropertyType.FullName}){property.Name} is null");
                        }
                    }
                    else if (notificationProperty.PropertyType == typeof(Android.Net.Uri) && property.PropertyType == typeof(System.Uri))//Android.Net to System.Uri
                    {
                        object          valueToSet = notificationProperty.GetValue(notification, null);
                        Android.Net.Uri androidUri = valueToSet as Android.Net.Uri;
                        if (androidUri != null)
                        {
                            property.SetValue(result, new System.Uri(androidUri.ToString()));
                        }
                        else
                        {
                            Log.Error("ToNotification", $"({property.PropertyType.FullName}){property.Name} is null");
                        }
                    }
                    else
                    {
                        Log.Error("ToNotification", $"[{property.Name}]{property.PropertyType} is not equal to {notificationProperty.PropertyType}");
                    }
                }
                else
                {
                    Log.Error("ToNotification", $"{property.Name} is null");
                }
            }

            return(result);
        }