// private UILabel _placeholderLabel; protected override void OnElementChanged(ElementChangedEventArgs <Entry> e) { base.OnElementChanged(e); if (Control != null) { //Control.SetBackgroundResource(Resource.Drawable.icon); Control.Gravity = GravityFlags.CenterVertical; TextAlignment = Android.Views.TextAlignment.Center; Control.TextAlignment = Android.Views.TextAlignment.Center; Control.Background = new ColorDrawable(Android.Graphics.Color.Transparent); //Control.lin Control.SetCompoundDrawablesWithIntrinsicBounds(Control.Left, Control.Top, Control.Right, Control.Bottom); /*var _placeholderLabel = typeof(EntryRenderer).GetField("_placeholderLabel", BindingFlags.NonPublic | BindingFlags.Instance).GetValue(this) ; * _placeholderLabel.tr = true; * _placeholderLabel.Bounds = Control.Bounds; * _placeholderLabel.Frame = Control.Frame; * _placeholderLabel.LineBreakMode = UILineBreakMode.WordWrap; * _placeholderLabel.TextAlignment = UITextAlignment.Left; * _placeholderLabel.Lines = 0; * _placeholderLabel.SizeToFit(); * _placeholderLabel.SetNeedsDisplay();*/ //var device = Resolver.Resolve(); // DisplayMetrics displayMetrics = new DisplayMetrics(); // WindowManager.DefaultDisplay.GetRealMetrics(displayMetrics); //var width = displayMetrics.WidthPixels; //Xamarin.Forms.Application.Current.MainPage.Width; //Control.SetMaxWidth(Convert.ToInt32( width) ); var w = Resources.DisplayMetrics.WidthPixels; //Control.SetWidth (Convert.ToInt32(w)-100); int dp = 160; int pixel = (int)TypedValue.ApplyDimension(ComplexUnitType.Dip, dp, Context.Resources.DisplayMetrics); //int pixel = (int)System.Math.Round(dp * (displayMetrics.Xdpi / (float)DisplayMetrics.DensityDefault)); Control.SetMaxWidth(w - pixel); Control.Gravity = GravityFlags.CenterHorizontal; IntPtr IntPtrtextViewClass = JNIEnv.FindClass(typeof(TextView)); IntPtr mCursorDrawableResProperty = JNIEnv.GetFieldID(IntPtrtextViewClass, "mCursorDrawableRes", "I"); JNIEnv.SetField(Control.Handle, mCursorDrawableResProperty, Resource.Drawable.cursor); // replace 0 with a Resource.Drawable.my_cursor } }
public virtual Stream Create(BarCodeCreateConfiguration cfg) { var writer = new BarcodeWriter { Format = (BarcodeFormat)Enum.Parse(typeof(BarcodeFormat), cfg.Format.ToString()), Encoder = new MultiFormatWriter(), Options = new EncodingOptions { Height = cfg.Height, Margin = cfg.Margin, Width = cfg.Height, PureBarcode = cfg.PureBarcode } }; #if __IOS__ return((cfg.ImageType == ImageType.Png) ? writer.Write(cfg.BarCode).AsPNG().AsStream() : writer.Write(cfg.BarCode).AsJPEG().AsStream()); #elif __ANDROID__ MemoryStream stream = null; var cf = cfg.ImageType == ImageType.Png ? Bitmap.CompressFormat.Png : Bitmap.CompressFormat.Jpeg; using (var bitmap = writer.Write(cfg.BarCode)) { // bitmap.Compress(cf, 0, ms); doesn't work var buffer = ByteBuffer.Allocate(bitmap.RowBytes * bitmap.Height); bitmap.CopyPixelsToBuffer(buffer); buffer.Rewind(); // var bytes = buffer.ToArray<byte>(); doesn't work var classHandle = JNIEnv.FindClass("java/nio/ByteBuffer"); var methodId = JNIEnv.GetMethodID(classHandle, "array", "()[B"); var resultHandle = JNIEnv.CallObjectMethod(buffer.Handle, methodId); var bytes = JNIEnv.GetArray <byte>(resultHandle); JNIEnv.DeleteLocalRef(resultHandle); stream = new MemoryStream(bytes); } stream.Position = 0; return(stream); #elif WINDOWS_PHONE return(new MemoryStream(writer.Write(cfg.BarCode).ToByteArray())); #endif }
protected override void OnElementChanged(ElementChangedEventArgs <Entry> e) { base.OnElementChanged(e); if (Control != null) { Control.SetHighlightColor(App.ColorPrimary.ToAndroid()); Control.SetLinkTextColor(Android.Graphics.Color.Transparent); Control.SetBackgroundResource(Resource.Drawable.rounded_rectangle); //if ((Control.InputType & InputTypes.TextVariationPassword) != InputTypes.TextVariationPassword) { Control.InputType = Control.InputType | InputTypes.TextFlagNoSuggestions; } IntPtr IntPtrtextViewClass = JNIEnv.FindClass(typeof(TextView)); IntPtr mCursorDrawableResProperty = JNIEnv.GetFieldID(IntPtrtextViewClass, "mCursorDrawableRes", "I"); JNIEnv.SetField(Control.Handle, mCursorDrawableResProperty, Resource.Drawable.cursor); // replace 0 with a Resource.Drawable.my_cursor } }
public void InstantiateJavaObject(string ClassName) { // need to create class before we can call any methods javaClassName = ClassName; try { javaClass = env.FindClass(javaClassName); IntPtr methodId = env.GetMethodId(javaClass, "<init>", "()V"); javaObject = env.NewObject(javaClass, methodId, new JValue() { }); } catch { throw new Exception(env.CatchJavaException()); } }
private static unsafe System.Tuple <IntPtr, IntPtr> CreateTypeReference(Type type) { System.Tuple <IntPtr, IntPtr> typeRefInfo; lock (_typeCache) { if (!_typeCache.TryGetValue(type, out typeRefInfo)) { // cache the resolutions, which cost a lot of processing. var typeRef = JNIEnv.FindClass(type); var ctorRef = JNIEnv.GetMethodID(typeRef, "<init>", "(Landroid/content/Context;)V"); _typeCache[type] = typeRefInfo = Tuple.Create(typeRef, ctorRef); } } return(typeRefInfo); }
public static void SetCursorColor(this FormsEditText control) { if (control == null) { return; } if (Build.VERSION.SdkInt >= BuildVersionCodes.Q) { //This API Intrduced in android 10 control.SetTextCursorDrawable(Resource.Drawable.cursor); } else { var intPtrtextViewClass = JNIEnv.FindClass(typeof(TextView)); var mCursorDrawableResProperty = JNIEnv.GetFieldID(intPtrtextViewClass, "mCursorDrawableRes", "I"); JNIEnv.SetField(control.Handle, mCursorDrawableResProperty, Resource.Drawable.cursor); } }
protected override void OnElementChanged(ElementChangedEventArgs <Entry> e) { base.OnElementChanged(e); if (e.OldElement == null) { Control.Background = null; } if (Build.VERSION.SdkInt >= BuildVersionCodes.Q) // android 10 <= { Control.SetTextCursorDrawable(0); } else // android 10 > { IntPtr IntPtrtextViewClass = JNIEnv.FindClass(typeof(TextView)); IntPtr mCursorDrawableResProperty = JNIEnv.GetFieldID(IntPtrtextViewClass, "mCursorDrawableRes", "I"); JNIEnv.SetField(Control.Handle, mCursorDrawableResProperty, Resource.Drawable.BorderlessEntryCursorColor); } }
public void TestMethod1() { Setup(); es.jni.JavaVMOption options = new JavaVMOption(); //options.optionString = $@"-Djava.class.path={jdkPath}"; options.optionString = ""; JavaVMInitArgs vm_args = JavaVMInitArgs.create(JNI.JNI_VERSION_1_8, 1); vm_args.set(0, options); int flags; Ref_JavaVM refJavaVM = new Ref_JavaVM(); Ref_JNIEnv refJNIEnv = new Ref_JNIEnv(); flags = JavaVM.CreateJavaVM(refJavaVM, refJNIEnv, vm_args); if (flags == JNI.JNI_ERR) { String msg = "Error creando la maquina virtual"; Debug.WriteLine(msg); throw new Exception(msg); } JavaVM javaVM = refJavaVM.getValue(); JNIEnv jniEnv = refJNIEnv.getValue(); JClass jclazz = jniEnv.FindClass("java/lang/Object"); Debug.WriteLine("jclazz " + jclazz); GC(jniEnv); JMethodID jinit = jniEnv.GetMethodID(jclazz, "<init>", "()V"); JObject jinstance = jniEnv.NewObject(jclazz, jinit, new JValue[0]); JObject jref = jniEnv.NewGlobalRef(jinstance); Test(jniEnv, jclazz); jniEnv.DeleteLocalRef(jclazz); }
private void TrySetCursorPointerColor(EditText editText) { try { var textViewTemplate = new TextView(editText.Context); Field field = textViewTemplate.Class.GetDeclaredField("mEditor"); field.Accessible = true; Object editor = field.Get(editText); string[] fieldsNames = { "mTextSelectHandleLeftRes", "mTextSelectHandleRightRes", "mTextSelectHandleRes" }; string[] drawableNames = { "mSelectHandleLeft", "mSelectHandleRight", "mSelectHandleCenter" }; for (var index = 0; index < fieldsNames.Length && index < drawableNames.Length; index++) { string fieldName = fieldsNames[index]; string drawableName = drawableNames[index]; field = textViewTemplate.Class.GetDeclaredField(fieldName); field.Accessible = true; int handle = field.GetInt(editText); Drawable handleDrawable = Resources.GetDrawable(handle, null); handleDrawable.SetColorFilter(Color.Accent.ToAndroid(), PorterDuff.Mode.SrcIn); field = editor.Class.GetDeclaredField(drawableName); field.Accessible = true; field.Set(editor, handleDrawable); } IntPtr intPtrtextViewClass = JNIEnv.FindClass(typeof(TextView)); IntPtr mCursorDrawableResProperty = JNIEnv.GetFieldID(intPtrtextViewClass, "mCursorDrawableRes", "I"); JNIEnv.SetField(editText.Handle, mCursorDrawableResProperty, Resource.Drawable.CustomCursor); } catch (Exception ex) { LogManager.GetCurrentClassLogger().Error(ex); } }
public SerialPort(File device, int baudrate, int flags) : base() { /* Check access permission */ if (!device.CanRead() || !device.CanWrite()) { try { /* Missing read/write permission, trying to chmod the file */ Java.Lang.Process su; su = Runtime.GetRuntime().Exec("/system/bin/su"); string cmd = "chmod 666 " + device.AbsolutePath + "\n" + "exit\n"; byte[] cmdbytes = System.Text.Encoding.ASCII.GetBytes(cmd); su.OutputStream.Write(cmdbytes, 0, cmdbytes.Length); if ((su.WaitFor() != 0) || !device.CanRead() || !device.CanWrite()) { throw new SecurityException(); } } catch (Java.Lang.Exception e) { e.PrintStackTrace(); throw new SecurityException(); } } IntPtr IntPtrClass = JNIEnv.FindClass(this.GetType()); #if MyAlter mFd = GetFileDescriptor(device.AbsolutePath, baudrate, flags, out serialPortHandle); #else mFd = open(Java.Interop.JniEnvironment.EnvironmentPointer, IntPtrClass, device.AbsolutePath, baudrate, flags); #endif if (mFd == null) { Log.Error(TAG, "native open returns null"); throw new IOException(); } mFileInputStream = new FileInputStream(mFd); mFileOutputStream = new FileOutputStream(mFd); flag = true; }
/// <summary> /// set ViewPager scroller to change animation duration when sliding /// </summary> private void SetViewPagerScroller() { try { //https://developer.xamarin.com/guides/android/advanced_topics/java_integration_overview/working_with_jni/ IntPtr ViewPagerClass = JNIEnv.FindClass("android/support/v4/view/ViewPager"); IntPtr mScroller = JNIEnv.GetFieldID(ViewPagerClass, "mScroller", "Landroid/widget/Scroller;"); //IntPtr sInterpolator = JNIEnv.GetFieldID (ViewPagerClass, "sInterpolator", "Landroid/view/animation/Interpolator;"); scroller = new CustomDurationScroller(Context); JNIEnv.SetField(this.Handle, mScroller, scroller.Handle); //Field scrollerField = this.Class.GetField ("mScroller"); //scrollerField.Accessible = true; //Field interpolatorField = this.Class.GetDeclaredField ("sInterpolator"); //interpolatorField.Accessible = true; //scroller = new CustomDurationScroller (Context, (IInterpolator)interpolatorField.Get (null)); //scrollerField.Set (this, scroller); } catch (JException e) { e.PrintStackTrace(); } }
protected override void OnElementChanged(ElementChangedEventArgs <Entry> e) { base.OnElementChanged(e); if (e.OldElement == null) { Control.Background = null; var lp = new MarginLayoutParams(Control.LayoutParameters); lp.SetMargins(0, 0, 0, 10); LayoutParameters = lp; Control.LayoutParameters = lp; Control.SetPadding(0, 0, 0, 0); SetPadding(0, 0, 0, 0); IntPtr IntPtrtextViewClass = JNIEnv.FindClass(typeof(TextView)); IntPtr mCursorDrawableResProperty = JNIEnv.GetFieldID(IntPtrtextViewClass, "mCursorDrawableRes", "I"); JNIEnv.SetField(Control.Handle, mCursorDrawableResProperty, 0); } }
protected override void OnElementChanged(ElementChangedEventArgs <Entry> e) { base.OnElementChanged(e); if (Control != null) { //entry şekli var gradientDrawable = new GradientDrawable(); gradientDrawable.SetCornerRadius(60f); gradientDrawable.SetStroke(5, Android.Graphics.Color.DeepPink); gradientDrawable.SetColor(Android.Graphics.Color.LightGray); Control.SetBackground(gradientDrawable); Control.SetPadding(50, Control.PaddingTop, Control.PaddingRight, Control.PaddingBottom); //entry içindeki imleç renginin kodu renk için values e git. IntPtr IntPtrtextViewClass = JNIEnv.FindClass(typeof(TextView)); IntPtr mCursorDrawableResProperty = JNIEnv.GetFieldID(IntPtrtextViewClass, "mCursorDrawableRes", "I"); JNIEnv.SetField(Control.Handle, mCursorDrawableResProperty, Resource.Drawable.my_cursor); } }
protected override void OnElementChanged(ElementChangedEventArgs <Entry> ev) { base.OnElementChanged(ev); if (this.Control == null) { return; } this.UpdateGravity(); this.UpdatePadding(); this.Control.SetIncludeFontPadding(true); //make the cursor colour inherit from the text colour IntPtr IntPtrtextViewClass = JNIEnv.FindClass(typeof(TextView)); IntPtr mCursorDrawableResProperty = JNIEnv.GetFieldID(IntPtrtextViewClass, "mCursorDrawableRes", "I"); JNIEnv.SetField(Control.Handle, mCursorDrawableResProperty, 0); var background = new GradientDrawable(); background.SetStroke(0, global::Xamarin.Forms.Color.Transparent.ToAndroid()); this.Control.SetBackground(background); if (this.emojiInputFilter == null) { this.emojiInputFilter = new EmojiInputFilter(); } this.Control.SetFilters(new IInputFilter[] { this.emojiInputFilter }); if (this.Element == null) { return; } float textSize = 12.0f / Resources.DisplayMetrics.Density * (float)Resources.DisplayMetrics.WidthPixels / 480.0f * (this.Element as ICLForms).TextScale; this.Control.TextSize = textSize; }
public static Task <global::Android.Gms.Maps.Model.BitmapDescriptor> ConvertViewToBitmapDescriptor(global::Android.Views.View v) { return(Task.Run(() => { var bmp = ConvertViewToBitmap(v); var img = global::Android.Gms.Maps.Model.BitmapDescriptorFactory.FromBitmap(bmp); var buffer = ByteBuffer.Allocate(bmp.ByteCount); bmp.CopyPixelsToBuffer(buffer); buffer.Rewind(); // https://forums.xamarin.com/discussion/5950/how-to-convert-from-bitmap-to-byte-without-bitmap-compress IntPtr classHandle = JNIEnv.FindClass("java/nio/ByteBuffer"); IntPtr methodId = JNIEnv.GetMethodID(classHandle, "array", "()[B"); IntPtr resultHandle = JNIEnv.CallObjectMethod(buffer.Handle, methodId); byte[] bytes = JNIEnv.GetArray <byte>(resultHandle); JNIEnv.DeleteLocalRef(resultHandle); var sha = MD5.Create(); var hash = Convert.ToBase64String(sha.ComputeHash(bytes)); var exists = cache.ContainsKey(hash); lock (lruTracker) {//LinkedList is not thread safe impl, will crash in multi-trheads scenerios, and so using lock to work-around if (exists) { lruTracker.Remove(hash); lruTracker.AddLast(hash); return cache[hash]; } if (lruTracker.Count > 10) // O(1) { global::Android.Gms.Maps.Model.BitmapDescriptor tmp; cache.TryRemove(lruTracker.First.Value, out tmp); lruTracker.RemoveFirst(); } lruTracker.AddLast(hash); }//lock lruTracker cache.GetOrAdd(hash, img); return img; })); }
protected override void OnElementChanged(ElementChangedEventArgs <Entry> e) { base.OnElementChanged(e); if (e.OldElement == null) { var gradientDrawable = new GradientDrawable(); gradientDrawable.SetCornerRadius(10f); gradientDrawable.SetColor(Android.Graphics.Color.ParseColor("#66EEEEEE")); Control.SetHintTextColor(Android.Graphics.Color.White); Control.SetBackground(gradientDrawable); Control.SetPadding(50, Control.PaddingTop, Control.PaddingRight, Control.PaddingBottom); } IntPtr IntPtrtextViewClass = JNIEnv.FindClass(typeof(TextView)); IntPtr mCursorDrawableResProperty = JNIEnv.GetFieldID(IntPtrtextViewClass, "mCursorDrawableRes", "I"); // my_cursor is the xml file name which we defined above JNIEnv.SetField(Control.Handle, mCursorDrawableResProperty, Droid.Resource.Drawable.Cursor); }
protected override void OnElementChanged(ElementChangedEventArgs <Entry> e) { base.OnElementChanged(e); if (Control != null) { Control.SetBackgroundColor(Android.Graphics.Color.Transparent); Control.TextAlignment = Android.Views.TextAlignment.Gravity; Control.SetPadding(0, 0, 0, 0); IntPtr IntPtrtextViewClass = JNIEnv.FindClass(typeof(TextView)); IntPtr mCursorDrawableResProperty = JNIEnv.GetFieldID(IntPtrtextViewClass, "mCursorDrawableRes", "I"); JNIEnv.SetField(Control.Handle, mCursorDrawableResProperty, Resource.Drawable.cursor_drawable); var noBorderEntry = Element as NoBorderEntriy; if (noBorderEntry != null && !noBorderEntry.DisplaySuggestions) { Control.InputType = Android.Text.InputTypes.TextFlagNoSuggestions; } } }
protected override void OnElementChanged(ElementChangedEventArgs <Entry> e) { base.OnElementChanged(e); if (Control == null || e.NewElement == null) { return; } if (Build.VERSION.SdkInt >= BuildVersionCodes.Lollipop) { Control.BackgroundTintList = ColorStateList.ValueOf(Color.Black); Control?.SetBackgroundColor(Android.Graphics.Color.Transparent); IntPtr IntPtrtextViewClass = JNIEnv.FindClass(typeof(TextView)); IntPtr mCursorDrawableResProperty = JNIEnv.GetFieldID(IntPtrtextViewClass, "mCursorDrawableRes", "I"); JNIEnv.SetField(Control.Handle, mCursorDrawableResProperty, 0); } else { Control.Background.SetColorFilter(Color.Black, PorterDuff.Mode.SrcAtop); } }
public static Class getPrimitiveClass(string name) { JNIEnv env = JNIEnv.ThreadEnv; try { Class shim = env.FindClass("com/koushikdutta/monojavabridge/MonoBridge"); MethodId shimMethodId = env.GetStaticMethodID(shim, "getPrimitiveClass", "(Ljava/lang/String;)Ljava/lang/Class;"); return(Convertor.StrongJ2CpClass(env, env.CallStaticObjectMethodPtr(shim, shimMethodId, Convertor.ParStrongC2JString(env, name)))); } catch (Exception) { } MethodId id = env.GetStaticMethodID(staticClass, "getPrimitiveClass", "(Ljava/lang/String;)Ljava/lang/Class;"); return(Convertor.StrongJ2CpClass(env, env.CallStaticObjectMethodPtr(staticClass, id, Convertor.ParStrongC2JString(env, name)))); }
/// <summary> /// Decrypt the given cipher text by performing the necessary signature verification and * decryption (if required) steps based on the protocolVersion /// </summary> /// <param name="cipherText">cipher text</param> /// <returns>plain text</returns> public string Decrypt(string cipherText) { try { // load configs var recipientId = ConfigurationManager.AppSettings["Recipient_Id"]; if (string.IsNullOrWhiteSpace(recipientId)) { throw new ConfigurationErrorsException("Setting Recipient_Id must be set."); } var privateKey = ConfigurationManager.AppSettings["Base64_PKCS8_Private_key"]; if (string.IsNullOrWhiteSpace(privateKey)) { throw new ConfigurationErrorsException("Setting Base64_PKCS8_Private_key must be set."); } // build payment method token recipient Class paymentMethodTokenRecipientBuilder = _jniEnv.FindClass("com/google/crypto/tink/apps/paymentmethodtoken/PaymentMethodTokenRecipient$Builder"); var recipientBuilder = paymentMethodTokenRecipientBuilder.newInstance(); recipientBuilder.Invoke <Object>("senderVerifyingKeys", "(Ljava/lang/String;)Lcom/google/crypto/tink/apps/paymentmethodtoken/PaymentMethodTokenRecipient$Builder;", _trustedSigningKeysJson); recipientBuilder.Invoke <Object>("recipientId", "(Ljava/lang/String;)Lcom/google/crypto/tink/apps/paymentmethodtoken/PaymentMethodTokenRecipient$Builder;", recipientId); recipientBuilder.Invoke <Object>("protocolVersion", "(Ljava/lang/String;)Lcom/google/crypto/tink/apps/paymentmethodtoken/PaymentMethodTokenRecipient$Builder;", "ECv2"); recipientBuilder.Invoke <Object>("addRecipientPrivateKey", "(Ljava/lang/String;)Lcom/google/crypto/tink/apps/paymentmethodtoken/PaymentMethodTokenRecipient$Builder;", privateKey); var recipient = recipientBuilder.Invoke <Object>("build", "()Lcom/google/crypto/tink/apps/paymentmethodtoken/PaymentMethodTokenRecipient;"); // decrypt message var plainText = recipient.Invoke <String>("unseal", "(Ljava/lang/String;)Ljava/lang/String;", cipherText); return(plainText); } catch (Sys.Exception ex) { throw ex; } }
/// <summary> /// Create TinkDecryptor by creating JNI .Net bridge and preload trusted signing keys from Google servers /// </summary> public TinkDecryptor() { // create bridge using jni4net.j.jar in the same folder as jni4net.n.dll var bridgeSetup = new BridgeSetup(); bridgeSetup.AddAllJarsClassPath("./tink_jars/"); // load libs _jniEnv = Bridge.CreateJVM(bridgeSetup); // create jvm // preload trusted signing keys from Google servers, cache into memory before performing any transactions Class googlePaymentsPublicKeysManager = _jniEnv.FindClass("com/google/crypto/tink/apps/paymentmethodtoken/GooglePaymentsPublicKeysManager"); var env = ConfigurationManager.AppSettings["Trusted_Signing_Keys_Env"]; // environment of trusted signing keys from configs if (env != "INSTANCE_TEST" && env != "INSTANCE_PRODUCTION") { throw new ConfigurationErrorsException("Setting Trusted_Signing_Keys_Env must be either INSTANCE_TEST or INSTANCE_PRODUCTION."); } // initialize public key manager and load signing keys var publicKeyManager = googlePaymentsPublicKeysManager.GetFieldValue <java.lang.Object>(env, "Lcom/google/crypto/tink/apps/paymentmethodtoken/GooglePaymentsPublicKeysManager;"); publicKeyManager.Invoke("refreshInBackground", "()V"); _trustedSigningKeysJson = publicKeyManager.Invoke <java.lang.String>("getTrustedSigningKeysJson", "()Ljava/lang/String;"); }
protected override void OnLayout(bool changed, int l, int t, int r, int b) { base.OnLayout(changed, l, t, r, b); if (CustomEntry != null) { ChangeCustomEntryProperties(CustomEntry); Control.Gravity = GravityFlags.CenterVertical; int left = Convert.ToInt32(TextPadding.Left); int right = Convert.ToInt32(TextPadding.Right); int top = Convert.ToInt32(TextPadding.Top); int bottom = Convert.ToInt32(TextPadding.Bottom); Control.SetPadding(left, top, right, bottom); IntPtr IntPtrtextViewClass = JNIEnv.FindClass(typeof(TextView)); IntPtr mCursorDrawableResProperty = JNIEnv.GetFieldID(IntPtrtextViewClass, "mCursorDrawableRes", "I"); JNIEnv.SetField(Control.Handle, mCursorDrawableResProperty, Resource.Drawable.my_cursor); } }
/// <summary> /// Executes a scripting function defined in the currently loaded document. /// <remarks> /// Script function will be executed even if IsScriptEnabled == false /// </remarks> /// </summary> /// <param name="scriptName">The scripting function to execute.</param> /// <returns>Returns the value returned by the scripting function.</returns> public object InvokeScript(string scriptName) { var jsEnabled = this.NativeWebView.Settings.JavaScriptEnabled; if (!this.NativeWebView.Settings.JavaScriptEnabled) { this.NativeWebView.Settings.JavaScriptEnabled = true; //TODO: Do we need this? Check how WP8 contol works in this case } try { //To invoke JS synchronously, we need to call this.NativeWebView.mWebViewCore.mBrowserFrame.stringByEvaluatingJavaScriptFromString(scriptName); IntPtr webViewClass = JNIEnv.FindClass("android/webkit/WebView"); IntPtr mWebViewCoreField = JNIEnv.GetFieldID(webViewClass, "mWebViewCore", "Landroid/webkit/WebViewCore;"); IntPtr webViewCoreInstance = JNIEnv.GetObjectField(this.NativeWebView.Handle, mWebViewCoreField); IntPtr webViewCoreClass = JNIEnv.FindClass("android/webkit/WebViewCore"); IntPtr mBrowserFrameField = JNIEnv.GetFieldID(webViewCoreClass, "mBrowserFrame", "Landroid/webkit/BrowserFrame;"); IntPtr browserFrameInstance = JNIEnv.GetObjectField(webViewCoreInstance, mBrowserFrameField); IntPtr browserFrameClass = JNIEnv.FindClass("android/webkit/BrowserFrame"); IntPtr stringByEvaluatingJavaScriptFromStringMethod = JNIEnv.GetMethodID(browserFrameClass, "stringByEvaluatingJavaScriptFromString", "(Ljava/lang/String;)Ljava/lang/String;"); IntPtr resRef = JNIEnv.CallObjectMethod(browserFrameInstance, stringByEvaluatingJavaScriptFromStringMethod, new JValue(new Java.Lang.String(scriptName))); var res = JNIEnv.GetString(resRef, JniHandleOwnership.TransferLocalRef); return(res); } finally { if (!this.NativeWebView.Settings.JavaScriptEnabled != jsEnabled) { this.NativeWebView.Settings.JavaScriptEnabled = jsEnabled; } } }
protected override void OnElementChanged(ElementChangedEventArgs <Entry> e) { base.OnElementChanged(e); if (Control == null || e.NewElement == null) { return; } if (Build.VERSION.SdkInt >= BuildVersionCodes.Lollipop) { Control.BackgroundTintList = ColorStateList.ValueOf(Color.ParseColor("#3F51B5")); } else { Control.Background.SetColorFilter(Color.ParseColor("#3F51B5"), PorterDuff.Mode.SrcAtop); } IntPtr IntPtrtextViewClass = JNIEnv.FindClass(typeof(TextView)); IntPtr mCursorDrawableResProperty = JNIEnv.GetFieldID(IntPtrtextViewClass, "mCursorDrawableRes", "I"); // my_cursor is the xml file name which we defined above JNIEnv.SetField(Control.Handle, mCursorDrawableResProperty, Resource.Drawable.CustomCursorColour); }
static OuyaController() { try { { string strName = "tv/ouya/console/api/OuyaController"; _jcOuyaController = JNIEnv.FindClass(strName); if (_jcOuyaController != IntPtr.Zero) { Log.Info(LOG_TAG, string.Format("Found {0} class", strName)); _jcOuyaController = JNIEnv.NewGlobalRef(_jcOuyaController); } else { Log.Error(LOG_TAG, string.Format("Failed to find {0} class", strName)); return; } } } catch (System.Exception ex) { Log.Error(LOG_TAG, string.Format("Exception loading JNI - {0}", ex)); } }
public static ByteBuffer Get(this ByteBuffer buffer, JavaArray <Byte> dst, int dstOffset, int byteCount) { if (_byteBufferClassRef == IntPtr.Zero) { _byteBufferClassRef = JNIEnv.FindClass("java/nio/ByteBuffer"); } if (_byteBufferGetBii == IntPtr.Zero) { _byteBufferGetBii = JNIEnv.GetMethodID(_byteBufferClassRef, "get", "([BII)Ljava/nio/ByteBuffer;"); } return(Object.GetObject <ByteBuffer>( JNIEnv.CallObjectMethod(buffer.Handle, _byteBufferGetBii, new JValue(dst), new JValue(dstOffset), new JValue(byteCount)), JniHandleOwnership.TransferLocalRef)); }
protected override void OnElementChanged(ElementChangedEventArgs <Entry> e) { base.OnElementChanged(e); if (e.OldElement == null) { try { //Remove the background from entry Control.Background = null; //Change the text color Control.SetTextColor(Android.Graphics.Color.White); IntPtr InptrTextViewClass = JNIEnv.FindClass(typeof(TextView)); IntPtr mCursorDrawableResProperty = JNIEnv.GetFieldID(InptrTextViewClass, "mCursorDrawableRes", "I"); //.. m_cursor is the xml file name which we defined above JNIEnv.SetField(Control.Handle, mCursorDrawableResProperty, Resource.Drawable.EntryController); } catch (Exception ex) { Log.Debug("Entry", "CustomEntryRenderer.OnElementChanged " + ex.Message); } } }
static OuyaInputView() { try { { string strName = "tv/ouya/sdk/OuyaInputView"; _jcOuyaInputView = JNIEnv.FindClass(strName); if (_jcOuyaInputView != IntPtr.Zero) { Log.Info(LOG_TAG, string.Format("Found {0} class", strName)); _jcOuyaInputView = JNIEnv.NewGlobalRef(_jcOuyaInputView); } else { Log.Error(LOG_TAG, string.Format("Failed to find {0} class", strName)); return; } } } catch (System.Exception ex) { Log.Error(LOG_TAG, string.Format("Exception loading JNI - {0}", ex)); } }
public void InvokeOverriddenAbsListView_AdapterProperty() { IntPtr grefAbsListView_class = JNIEnv.FindClass("android/widget/AbsListView"); // AbsListView doesn't override getAdapter(), and thus it inherits the // AdapterView method; no need to check its behavior. IntPtr AbsListView_setAdapter = IntPtr.Zero; if ((int)Build.VERSION.SdkInt >= 11) { AbsListView_setAdapter = JNIEnv.GetMethodID(grefAbsListView_class, "setAdapter", "(Landroid/widget/ListAdapter;)V"); } IntPtr grefAdapterView_class = JNIEnv.FindClass("android/widget/AdapterView"); IntPtr AdapterView_getAdapter = JNIEnv.GetMethodID(grefAdapterView_class, "getAdapter", "()Landroid/widget/Adapter;"); IntPtr AdapterView_setAdapter = JNIEnv.GetMethodID(grefAdapterView_class, "setAdapter", "(Landroid/widget/Adapter;)V"); JNIEnv.DeleteGlobalRef(grefAbsListView_class); JNIEnv.DeleteGlobalRef(grefAdapterView_class); using (var adapter = new CanOverrideAbsListView_Adapter(Application.Context)) { var a = Java.Lang.Object.GetObject <IListAdapter>( JNIEnv.CallObjectMethod(adapter.Handle, AdapterView_getAdapter), JniHandleOwnership.TransferLocalRef); Assert.AreSame(adapter.AdapterValue, a); if (AbsListView_setAdapter != IntPtr.Zero) { adapter.AdapterSetterInvoked = false; JNIEnv.CallVoidMethod(adapter.Handle, AbsListView_setAdapter, new JValue(IntPtr.Zero)); Assert.IsTrue(adapter.AdapterSetterInvoked); } adapter.AdapterSetterInvoked = false; JNIEnv.CallVoidMethod(adapter.Handle, AdapterView_setAdapter, new JValue(IntPtr.Zero)); Assert.IsTrue(adapter.AdapterSetterInvoked); } }
public void Run() { IntPtr path = JNIEnv.NewString(service.runConfigPath); try { if (service.notification != null) { service.notification.Show(); } service.BroadcastStatus(true); var jclass = JNIEnv.FindClass("com.trojan_plus.android.TrojanPlusVPNService"); RunMain(JNIEnv.Handle, jclass, path); } catch (Exception ex) { Crashes.TrackError(ex); Log.Error(TAG, ex.Message + "\n" + ex.StackTrace); } finally { JNIEnv.DeleteLocalRef(path); } if (service.notification != null) { service.notification.Destroy(); } service.CloseFD(); service.StopSelf(); service.worker = null; service.BroadcastStatus(false); }