public override void OnAttachedToWindow() { base.OnAttachedToWindow(); Java.Lang.Class classForId = Java.Lang.Class.ForName("com.android.internal.R$id"); Java.Lang.Reflect.Field timePickerField = classForId.GetField("timePicker"); timePicker = FindViewById <TimePicker> (timePickerField.GetInt(null)); Java.Lang.Reflect.Field field = classForId.GetField("minute"); NumberPicker mMinuteSpinner = timePicker.FindViewById <NumberPicker> (field.GetInt(null)); if (mMinuteSpinner != null) { mMinuteSpinner.MinValue = 0; mMinuteSpinner.MaxValue = (60 / interval) - 1; List <string> displayedValues = new List <string> (); for (int i = 0; i < 60; i += interval) { displayedValues.Add(i.ToString("00")); } mMinuteSpinner.SetDisplayedValues(displayedValues.ToArray()); } OnTimeChanged(timePicker, hourOfDay, minute / interval); }
public void StartPeriodicBackgroundWorkUsingJobScheduler() { Java.Lang.Class javaClass = Java.Lang.Class.FromType(typeof(GetBitcoinPriceJob)); ComponentName component = new ComponentName(Application.Context, javaClass); int jobId = 2300; JobInfo.Builder builder = new JobInfo.Builder(jobId, component) .SetPeriodic(1000 * 10) // start after every 10 seconds .SetPersisted(true) // job will work after device reboot .SetRequiredNetworkType(NetworkType.Any); // and require internet connection of any type JobInfo jobInfo = builder.Build(); JobScheduler jobScheduler = (JobScheduler)Application.Context.GetSystemService(Context.JobSchedulerService); int result = jobScheduler.Schedule(jobInfo); using (var handler = new Handler(Looper.MainLooper)) { if (result == JobScheduler.ResultSuccess) { Toast.MakeText(Application.Context, "job succesfully scheduled", ToastLength.Short); // The job was scheduled. } else { Toast.MakeText(Application.Context, "job failed to schedule", ToastLength.Short); } } }
public static void Emit(ReactApplicationContext context, string name, Java.Lang.Object data) { Java.Lang.Class emitterClass = Java.Lang.Class.FromType(typeof(IRCTNativeAppEventEmitter)); Java.Lang.Object module = context.GetJSModule(emitterClass); IRCTNativeAppEventEmitter emitter = Android.Runtime.Extensions.JavaCast <IRCTNativeAppEventEmitter>(module); emitter.Emit(name, data); }
protected virtual IMarkSpan GetLastMarkSpan(IEditable text) { var markSpanType = CreateStartMarkSpan().GetType(); var markSpans = text.GetSpans(0, text.Length(), JClass.FromType(markSpanType)).ToList(); var lastMarkSpan = markSpans.LastOrDefault(); return(lastMarkSpan as IMarkSpan); }
private void ClearSpanType(IEditable e, Java.Lang.Class spanType) { CharacterStyle[] spans = (CharacterStyle[])e.GetSpans(0, e.Length(), spanType); for (int n = spans.Length; n-- > 0;) { e.RemoveSpan(spans[n]); } }
public static void EnqueueWork(Context context, Intent work) { Java.Lang.Class cls = Java.Lang.Class.FromType(typeof(AppService)); try { EnqueueWork(context, cls, MY_JOB_ID, work); } catch (Exception ex) { throw ex; } }
public static void EnqueueWork(Context context, Intent work) { Java.Lang.Class cls = Java.Lang.Class.FromType(typeof(LongRunningTaskService)); try { EnqueueWork(context, cls, JOB_ID, work); } catch (Exception ex) { Console.WriteLine("Exception: {0}", ex.Message); } }
private bool IsMyServiceRunning(Java.Lang.Class serviceClass) { ActivityManager manager = (ActivityManager)GetSystemService(Context.ActivityService); foreach (var item in manager.GetRunningServices(int.MaxValue)) { if (serviceClass.Name.Equals(item.Service.ClassName)) { return(true); } } return(false); }
public Java.Lang.Object Create(Java.Lang.Class classType) { //Type fred = typeof(DownloadViewModel); Logger.Debug(() => $"ViewModelFactory:Create {classType.CanonicalName}"); // instead of a generic call like this // var obj = IocContainer.Resolve<DownloadViewModel>(); // we do this - because we do not know the type (DownloadViewModel in this example) at compile time MethodInfo method = typeof(IIocContainer).GetMethod(nameof(IIocContainer.Resolve)); MethodInfo generic = method.MakeGenericMethod(ModelMap[classType.CanonicalName].netType); var obj = generic.Invoke(IocContainer, null); Logger.Debug(() => $"ViewModelFactory:Create null == {obj == null}"); return((Java.Lang.Object)obj); }
/// <summary> /// Gets the last instance of a given Spanned Object /// </summary> /// <returns>The instance of a Spanned Object</returns> /// <param name="text">The text contained within the span</param> /// <param name="kind">Object type</param> static Java.Lang.Object getLast(ISpanned text, Java.Lang.Class kind) { /* * This knows that the last returned object from getSpans() * will be the most recently added. */ Java.Lang.Object [] objs = text.GetSpans(0, text.Length(), kind); if (objs.Length == 0) { return(null); } else { return(objs [objs.Length - 1]); } }
// public ActionBarViewWrapper(IViewParent actionBarView) public ActionBarViewWrapper(View actionBarView) { if (!actionBarView.Class.Name.Contains("ActionBarView")) { String previousP = actionBarView.Class.Name; actionBarView = (View)actionBarView.Parent; String throwP = actionBarView.Class.Name; if (!actionBarView.Class.Name.Contains("ActionBarView")) { throw new Java.Lang.IllegalStateException("Cannot find ActionBarView for " + "Activity, instead found " + previousP + " and " + throwP); } } mActionBarView = (IViewParent)actionBarView; mActionBarViewClass = actionBarView.Class; mAbsActionBarViewClass = actionBarView.Class.Superclass; }
public bool IsMobileDateOn() { var cm = (ConnectivityManager)Android.App.Application.Context.GetSystemService(Context.ConnectivityService); bool mobileDataEnabled = false; // Assume disabled try { Java.Lang.Class cmClass = Java.Lang.Class.ForName(cm.Class.Name); Java.Lang.Reflect.Method method = cmClass.GetDeclaredMethod("getMobileDataEnabled"); method.Accessible = (true); // Make the method callable // get the setting for "mobile data" mobileDataEnabled = (bool)method.Invoke(cm); } catch (Java.Lang.Exception ex) { } return(mobileDataEnabled); }
public bool Connect() { //Iniciamos la conexion con el arduino Errores.Text = "Conexion en curso...S"; //Indicamos al adaptador que ya no sea visible try { BluetoothDevice device = BlueAdapter.GetRemoteDevice(address); BlueAdapter.CancelDiscovery(); //Inicamos el socket de comunicacion con el arduino Java.Lang.Class[] clase = new Java.Lang.Class[] { Java.Lang.Integer.Type }; btSocket = (BluetoothSocket)device.Class.GetMethod("createRfcommSocket", clase).Invoke(device, 1); //Conectamos el socket btSocket.Connect(); Errores.Text += "\nConexion Correcta"; } catch (Java.Lang.IllegalArgumentException) { Errores.Text = "dispositivo no encontrado intente conectar nuevamente el dipositivo"; return(false); } catch (IOException e) { } catch (Exception e) { //en caso de generarnos error cerramos el socket try { btSocket.Close(); } catch (Exception) { Errores.Text += "Imposible Conectar"; } //System.Console.WriteLine("Socket Creado"); return(false); } return(true); }
/// <summary> /// Ends the span of an object /// </summary> /// <param name="text">String Builder instance</param> /// <param name="kind">Type of Object to use for the span</param> /// <param name="repl">Type of Object to replace for the span.</param> void end(SpannableStringBuilder text, Java.Lang.Class kind, Java.Lang.Object repl) { int len = text.Length(); Java.Lang.Object obj = getLast(text, kind); int start = text.GetSpanStart(obj); text.RemoveSpan(obj); if (start != len) { // Apply any text transforms here if (_defaultStyle.TextTransform != CssTextTransform.None) { TransformTextRange(_spannableStringBuilder, _defaultStyle, start, len); } text.SetSpan(repl, start, len, SpanTypes.ExclusiveExclusive); } }
internal override void SetCount(int badgeCount) { try { CurrentCount = badgeCount; Java.Lang.Class miuiNotificationClass = Java.Lang.Class.ForName("android.app.MiuiNotification"); Java.Lang.Object miuiNotification = miuiNotificationClass.NewInstance(); Java.Lang.Reflect.Field field = miuiNotification.Class.GetDeclaredField("messageCount"); field.Accessible = true; field.Set(miuiNotification, badgeCount == 0 ? "" : badgeCount.ToString()); } catch (Exception e) { Intent localIntent = new Intent( INTENT_ACTION); localIntent.PutExtra(EXTRA_UPDATE_APP_COMPONENT_NAME, GetContextPackageName() + "/" + GetEntryActivityName()); localIntent.PutExtra(EXTRA_UPDATE_APP_MSG_TEXT, badgeCount == 0 ? "" : badgeCount.ToString()); mContext.SendBroadcast(localIntent); } }
private bool CheckSmallIconInMIUI(Notification notification) { try { Java.Lang.Class miuiNotificationClass = Java.Lang.Class.ForName("android.app.MiuiNotification"); Java.Lang.Object miuiNotification = miuiNotificationClass.NewInstance(); Java.Lang.Reflect.Field field = miuiNotification.Class.GetDeclaredField("customizedIcon"); field.Accessible = true; field.Set(miuiNotification, true); field = notification.Class.GetField("extraNotification"); field.Accessible = true; field.Set(notification, miuiNotification); return(true); } catch (Java.Lang.Exception e) { return(false); } }
/* * 设置Tablayout元素的外边距 */ // 具体方法(通过反射的方式) public void SetIndicator(TabLayout tabs, int leftDip, int rightDip) { Java.Lang.Class tabLayout = tabs.Class; Field tabStrip = null; try { tabStrip = tabLayout.GetDeclaredField("mTabStrip"); } catch (Java.Lang.NoSuchFieldException e) { //e.printStackTrace(); } tabStrip.Accessible = true; LinearLayout llTab = null; try { llTab = (LinearLayout)tabStrip.Get(tabs); } catch (Java.Lang.IllegalAccessException e) { //e.printStackTrace(); } int left = (int)TypedValue.ApplyDimension(ComplexUnitType.Dip, leftDip, Resources.DisplayMetrics); int right = (int)TypedValue.ApplyDimension(ComplexUnitType.Dip, rightDip, Resources.DisplayMetrics); for (int i = 0; i < llTab.ChildCount; i++) { View child = llTab.GetChildAt(i); //child.GetPadding(0, 0, 0, 0); var p = new LinearLayout.LayoutParams(0, ViewGroup.LayoutParams.MatchParent, 1); p.LeftMargin = left; p.RightMargin = right; child.LayoutParameters = p; child.Invalidate(); } }
public static string GetProperty(string propertyName) { string result = string.Empty; try { Java.Lang.Class buildClass = Java.Lang.Class.ForName("android.os.Build"); Java.Lang.Reflect.Method getString = buildClass.GetDeclaredMethod("getString", Java.Lang.Class.FromType(typeof(Java.Lang.String))); getString.Accessible = true; //result = getString.Invoke(null, "net.hostname").ToString(); result = getString.Invoke(null, propertyName).ToString(); } catch (Exception ex) { throw ex; //result = string.Empty; } return(result); }
private void SetPrivateFactoryInternal() { if (this._setPrivateFactory) { return; } if (Build.VERSION.SdkInt < BuildVersionCodes.Honeycomb) { return; } if (!(this.Context is IFactory2)) { this._setPrivateFactory = true; return; } Java.Lang.Class layoutInflaterClass = Java.Lang.Class.FromType(typeof(LayoutInflater)); Method setPrivateFactoryMethod = layoutInflaterClass.GetMethod("setPrivateFactory", Java.Lang.Class.FromType(typeof(IFactory2))); if (setPrivateFactoryMethod != null) { try { setPrivateFactoryMethod.Accessible = true; setPrivateFactoryMethod.Invoke(this, new PrivateFactoryWrapper2((IFactory2)this.Context, this, this._bindingVisitor)); } catch (Java.Lang.Exception ex) { Mvx.Warning("Cannot invoke LayoutInflater.setPrivateFactory :\n{0}", ex.StackTrace); } } this._setPrivateFactory = true; }
public ServiceEventArgs(Java.Lang.Class type, IBinder service) { Type = type; Service = service; }
// This is a workaround addition for missing default interface method support in C#. // (And yes, this is the only class that didn't exist before 26) // FIXME: remove this once we got DIM support in Roslyn/mcs. public bool IsAnnotationPresent(Java.Lang.Class annotationClass) { // http://tools.oesf.biz/android-7.1.1_r1.0/xref/libcore/ojluni/src/main/java/java/lang/reflect/AnnotatedElement.java return(GetAnnotation(annotationClass) != null); }
/// <summary> /// 将 <see cref="Type"/> 转换为 <see cref="Java.Lang.Class"/> 对象。 /// </summary> /// <param name="type"></param> /// <returns></returns> public static JClass GetJClass(this Type type) => JClass.FromType(type);
/// <summary> /// Nasty method to inflate custom layouts that haven't been handled else where. If this fails it /// will fall back through to the PhoneLayoutInflater method of inflating custom views where /// Calligraphy will NOT have a hook into. /// </summary> /// <returns>view or the View we inflate in here.</returns> /// <param name="parent">Parent view.</param> /// <param name="view">view if it has been inflated by this point, if this is not null this method just returns this value.</param> /// <param name="name">name of the thing to inflate.</param> /// <param name="viewContext">Context to inflate by if parent is null</param> /// <param name="attrs">Attr for this view which we can steal fontPath from too.</param> internal View CreateCustomViewInternal(View parent, View view, string name, Context viewContext, IAttributeSet attrs) { // I by no means advise anyone to do this normally, but Google have locked down access to // the createView() method, so we never get a callback with attributes at the end of the // createViewFromTag chain (which would solve all this unnecessary rubbish). // We at the very least try to optimise this as much as possible. // We only call for customViews (As they are the ones that never go through onCreateView(...)). // We also maintain the Field reference and make it accessible which will make a pretty // significant difference to performance on Android 4.0+. // If CustomViewCreation is off skip this. if (!CalligraphyConfig.Get().CustomViewCreation) { return(view); } if (view == null && name.IndexOf('.') > -1) { Java.Lang.Object[] constructorArgsArr = null; Java.Lang.Object lastContext = null; if (Build.VERSION.SdkInt <= BuildVersionCodes.P) { if (constructorArgs == null) { Java.Lang.Class layoutInflaterClass = Java.Lang.Class.FromType(typeof(LayoutInflater)); constructorArgs = layoutInflaterClass.GetDeclaredField("mConstructorArgs"); constructorArgs.Accessible = true; } constructorArgsArr = (Java.Lang.Object[])constructorArgs.Get(this); lastContext = constructorArgsArr[0]; // The LayoutInflater actually finds out the correct context to use. We just need to set // it on the mConstructor for the internal method. // Set the constructor args up for the createView, not sure why we can't pass these in. constructorArgsArr[0] = viewContext; constructorArgs.Set(this, constructorArgsArr); } try { #if __ANDROID_29__ if (Build.VERSION.SdkInt > BuildVersionCodes.P) { view = CreateView(viewContext, name, null, attrs); } else #endif view = CreateView(name, null, attrs); } catch (Java.Lang.ClassNotFoundException) { } finally { if (Build.VERSION.SdkInt <= BuildVersionCodes.P) { constructorArgsArr[0] = lastContext; constructorArgs.Set(this, constructorArgsArr); } } } return(view); }
/// <summary> /// Show a local notification at a specified time /// </summary> /// <param name="title">Title of the notification</param> /// <param name="body">Body or description of the notification</param> /// <param name="id">Id of the notification</param> /// <param name="notifyTime">Time to show notification</param> public void Show(string title, string body, int id, DateTime notifyTime) { var intent = CreateIntent(id); var localNotification = new LocalNotification(); localNotification.Title = title; localNotification.Body = body; localNotification.Id = id; localNotification.NotifyTime = notifyTime; if (NotificationIconId != 0) { localNotification.IconId = NotificationIconId; } else { localNotification.IconId = Resource.Drawable.plugin_lc_smallicon; } var serializedNotification = SerializeNotification(localNotification); if (Build.VERSION.SdkInt >= BuildVersionCodes.Lollipop) { Java.Lang.Class javaClass = Java.Lang.Class.FromType(typeof(ScheduledJobHandler)); ComponentName component = new ComponentName(Application.Context, javaClass); // Bundle up parameters var extras = new PersistableBundle(); extras.PutString(ScheduledAlarmHandler.LocalNotificationKey, serializedNotification); extras.PutInt(ScheduledJobHandler.LocalNotificationIconId, NotificationIconId); var triggerTime = NotifyTimeInMilliseconds(localNotification.NotifyTime) - NotifyTimeInMilliseconds(DateTime.Now); JobInfo.Builder builder = new JobInfo.Builder(id, component) .SetMinimumLatency(triggerTime) // Fire at TriggerTime .SetOverrideDeadline(triggerTime + 5000) // Or at least 5 Seconds Later .SetExtras(extras) .SetPersisted(CheckBootPermission()); //Job will be recreated after Reboot if Permissions are granted JobInfo jobInfo = builder.Build(); JobScheduler jobScheduler = GetJobScheduler(); int result = jobScheduler.Schedule(jobInfo); if (result == JobScheduler.ResultSuccess) { // The job was scheduled. So nothing more to do } else { // The job wasn´t scheduled. So just use the old implementation? triggerTime = NotifyTimeInMilliseconds(localNotification.NotifyTime); intent.PutExtra(ScheduledAlarmHandler.LocalNotificationKey, serializedNotification); var pendingIntent = PendingIntent.GetBroadcast(Application.Context, 0, intent, PendingIntentFlags.CancelCurrent); var alarmManager = GetAlarmManager(); alarmManager.Set(AlarmType.RtcWakeup, triggerTime, pendingIntent); } } else { intent.PutExtra(ScheduledAlarmHandler.LocalNotificationKey, serializedNotification); var pendingIntent = PendingIntent.GetBroadcast(Application.Context, 0, intent, PendingIntentFlags.CancelCurrent); var alarmManager = GetAlarmManager(); var triggerTime = NotifyTimeInMilliseconds(localNotification.NotifyTime); alarmManager.Set(AlarmType.RtcWakeup, triggerTime, pendingIntent); } }
public FragmentReplaceInfo(Java.Lang.Class fragmentClass, String fragmentTag, int containerId) { mFragmentClass = fragmentClass; mFragmentTag = fragmentTag; mContainerId = containerId; }
protected override bool SupportsType(Java.Lang.Class type) { // Defining which types this editor supports is required. return type.Equals(Java.Lang.Class.FromType(typeof(EmployeeType))); }
public FragmentReplaceInfo (Java.Lang.Class fragmentClass, String fragmentTag, int containerId) { mFragmentClass = fragmentClass; mFragmentTag = fragmentTag; mContainerId = containerId; }