protected override void OnElementChanged(ElementChangedEventArgs <Slider> e) { base.OnElementChanged(e); if (Control != null) { var customSlider = (CustomSlider)Element; if (customSlider.ThumbColor != Xamarin.Forms.Color.Transparent) { Control.Thumb.SetColorFilter(customSlider.ThumbColor.ToAndroid(), PorterDuff.Mode.SrcIn); } BuildVersionCodes androidVersion = Build.VERSION.SdkInt; if (androidVersion >= BuildVersionCodes.M) { var trackCornerRadius = DpToPixels(customSlider.TrackCornerRadius); var trackHeight = DpToPixels(customSlider.TrackHeight); var progressGradientDrawable = new GradientDrawable(GradientDrawable.Orientation.LeftRight, new int[] { customSlider.ActiveTrackColor.ToAndroid(), customSlider.ActiveTrackColor.ToAndroid() }); progressGradientDrawable.SetCornerRadius(trackCornerRadius); var progress = new ClipDrawable(progressGradientDrawable, GravityFlags.Left, ClipDrawableOrientation.Horizontal); var background = new GradientDrawable(); background.SetColor(customSlider.InactiveTrackColor.ToAndroid()); background.SetCornerRadius(trackCornerRadius); var progressDrawable = new LayerDrawable(new Drawable[] { background, progress }); progressDrawable.SetLayerHeight(0, (int)trackHeight); progressDrawable.SetLayerHeight(1, (int)trackHeight); progressDrawable.SetLayerGravity(0, GravityFlags.CenterVertical); progressDrawable.SetLayerGravity(1, GravityFlags.CenterVertical); Control.ProgressDrawable = progressDrawable; } else { Element.MinimumTrackColor = customSlider.ActiveTrackColor; Control.SecondaryProgressTintList = ColorStateList.ValueOf(customSlider.InactiveTrackColor.ToAndroid()); Control.SecondaryProgressTintMode = PorterDuff.Mode.SrcIn; Control.SecondaryProgress = int.MaxValue; } Control.SetPadding(52, Control.PaddingTop, 52, Control.PaddingBottom); if (customSlider.UserInteractionEnabled) { Control.SplitTrack = true; Control.Thumb.Mutate().SetAlpha(255); } else { Control.SplitTrack = false; Control.Thumb.Mutate().SetAlpha(0); Control.Enabled = false; } } }
public static AbstractNotificationBuilder CreateNotification( Context context, BuildVersionCodes sdkInt, PushMessage pushMessage) { return(sdkInt >= 26 ? (AbstractNotificationBuilder) new OreoNotificationBuilder(context, pushMessage) : (AbstractNotificationBuilder) new NotificationBuilder(context, pushMessage)); }
protected override void OnLayout(bool changed, int l, int t, int r, int b) { base.OnLayout(changed, l, t, r, b); BuildVersionCodes androidVersion = Build.VERSION.SdkInt; if (androidVersion < BuildVersionCodes.JellyBean) { return; } // Thumb only supported JellyBean and higher if (Control == null) { return; } SeekBar seekbar = Control; Drawable thumb = seekbar.Thumb; int thumbTop = seekbar.Height / 2 - thumb.IntrinsicHeight / 2; thumb.SetBounds(thumb.Bounds.Left, thumbTop, thumb.Bounds.Left + thumb.IntrinsicWidth, thumbTop + thumb.IntrinsicHeight); }
protected override void OnElementChanged(ElementChangedEventArgs <SearchBar> e) { base.OnElementChanged(e); HandleKeyboardOnFocus = true; SearchView searchView = Control; if (searchView == null) { searchView = CreateNativeControl(); searchView.SetIconifiedByDefault(false); searchView.Iconified = false; SetNativeControl(searchView); _editText = _editText ?? Control.GetChildrenOfType <EditText>().FirstOrDefault(); if (_editText != null) { var useLegacyColorManagement = e.NewElement.UseLegacyColorManagement(); _textColorSwitcher = new TextColorSwitcher(_editText.TextColors, useLegacyColorManagement); _hintColorSwitcher = new TextColorSwitcher(_editText.HintTextColors, useLegacyColorManagement); } } BuildVersionCodes androidVersion = Build.VERSION.SdkInt; if (androidVersion >= BuildVersionCodes.JellyBean) { _inputType = searchView.InputType; } else { // < API 16, Cannot get the default InputType for a SearchView _inputType = InputTypes.ClassText | InputTypes.TextFlagAutoComplete | InputTypes.TextFlagNoSuggestions; } ClearFocus(searchView); UpdatePlaceholder(); UpdateText(); UpdateEnabled(); UpdateCancelButtonColor(); UpdateFont(); UpdateAlignment(); UpdateTextColor(); UpdatePlaceholderColor(); if (e.OldElement == null) { searchView.SetOnQueryTextListener(this); searchView.SetOnQueryTextFocusChangeListener(this); } }
public static int GetColor(Context context, int id) { BuildVersionCodes version = Build.VERSION.SdkInt; if ((int)version >= 23) { return(Android.Support.V4.Content.ContextCompat.GetColor(context, id)); } else { return(context.Resources.GetColor(id)); } }
protected override void OnLayout(bool changed, int l, int t, int r, int b) { base.OnLayout(changed, l, t, r, b); BuildVersionCodes androidVersion = Build.VERSION.SdkInt; if (androidVersion < BuildVersionCodes.JellyBean) { return; } // Thumb only supported JellyBean and higher if (Control == null) { return; } SeekBar seekbar = Control; // seekbar.Background = new ColorDrawable(Color.AliceBlue); // seekbar.ProgressDrawable = new ColorDrawable(Color.Violet); // seekbar.Background.SetColorFilter(Color.Black, PorterDuff.Mode.SrcIn); //seekbar.ProgressBackgroundTintList = new ColorStateList(); // seekbar.IndeterminateDrawable.SetColorFilter(Color.Black, PorterDuff.Mode.SrcIn); seekbar.ProgressDrawable.SetColorFilter(Color.ParseColor("#697780"), PorterDuff.Mode.SrcIn); seekbar.Thumb.SetColorFilter(Color.ParseColor("#8DB0EA"), PorterDuff.Mode.SrcIn); //Drawable thumb = seekbar.Thumb; //int thumbTop = seekbar.Height / 2 - thumb.IntrinsicHeight / 2; //thumb.SetBounds(thumb.Bounds.Left, thumbTop, thumb.Bounds.Left + thumb.IntrinsicWidth, thumbTop + thumb.IntrinsicHeight); //seekbar.ProgressDrawable.SetTint(); = new ShapeDrawable(); // var path = new Path(); //path.AddRect(Width / 2, Height / 2, radius, Path.Direction.Ccw); //seekbar.SetThumb(); // Drawable thumb = new Rectangle(0,0,5,10); // seekbar.SetThumb(Resources.GetDrawable(Resource.Drawable.audioPause)); //seekbar.SetMinimumHeight(20); //Drawable thumb = seekbar.Thumb; //int thumbTop = seekbar.Height / 2 - thumb.IntrinsicHeight / 2; //thumb.SetBounds(thumb.Bounds.Left, thumbTop, thumb.Bounds.Left + thumb.IntrinsicWidth, thumbTop + thumb.IntrinsicHeight); }
protected override void OnElementChanged(ElementChangedEventArgs <SearchBar> e) { base.OnElementChanged(e); HandleKeyboardOnFocus = true; SearchView searchView = Control; if (searchView == null) { searchView = CreateNativeControl(); searchView.SetIconifiedByDefault(false); searchView.Iconified = false; SetNativeControl(searchView); } BuildVersionCodes androidVersion = Build.VERSION.SdkInt; if (androidVersion >= BuildVersionCodes.JellyBean) { _inputType = searchView.InputType; } else { // < API 16, Cannot get the default InputType for a SearchView _inputType = InputTypes.ClassText | InputTypes.TextFlagAutoComplete | InputTypes.TextFlagNoSuggestions; } ClearFocus(searchView); UpdatePlaceholder(); UpdateText(); UpdateEnabled(); UpdateCancelButtonColor(); UpdateFont(); UpdateAlignment(); UpdateTextColor(); UpdatePlaceholderColor(); if (e.OldElement == null) { searchView.SetOnQueryTextListener(this); searchView.SetOnQueryTextFocusChangeListener(this); } }
public iBeaconEventTriggerService() { OS_VER = Build.VERSION.SdkInt; _btManager = (BluetoothManager)Android.App.Application.Context.GetSystemService("bluetooth"); _btAdapter = _btManager.Adapter; if (OS_VER < BuildVersionCodes.Lollipop) { // 4.4參和はこちら _scanCallbackOld = new LeScanCallback(); } else { // 5.0參貧はこちら _scanCallbackNew = new BleScanCallback(); _bleScanner = _btAdapter?.BluetoothLeScanner; } }
private bool HasPermission(string permission) { PackageInfo info = _Activity.PackageManager.GetPackageInfo(_Activity.PackageName, 0); BuildVersionCodes targetSdkVersion = info.ApplicationInfo.TargetSdkVersion; if (Build.VERSION.SdkInt >= Android.OS.BuildVersionCodes.M) { if (targetSdkVersion >= Android.OS.BuildVersionCodes.M) { return(_Activity.CheckSelfPermission(permission) == PermissionChecker.PermissionGranted); } else { return(PermissionChecker.CheckSelfPermission(_Activity, permission) == PermissionChecker.PermissionGranted); } } return(true); }
/// <summary> /// Obtem o IMEI do aparelho Android /// </summary> /// <returns>Lista de IMEIs do Android</returns> public string[] ObtemImei() { var telephonyManager = (TelephonyManager)Forms.Context.GetSystemService(Context.TelephonyService); List <string> imeis = new List <string>(); BuildVersionCodes version = Build.VERSION.SdkInt; //Na versão 22 pra cima, possuem o metodo getDeviceId, que possibilita pegar mais de um IMEI. if (version >= BuildVersionCodes.LollipopMr1) { Class telephonyManagerClass = Class.ForName(telephonyManager.Class.Name); Class[] parameter = new Class[1]; parameter[0] = Integer.Type; Method DeviceId = telephonyManagerClass.GetMethod("getDeviceId", parameter); Java.Lang.Object[] parametro = new Java.Lang.Object[1]; for (int i = 0; i < 4; i++) { parametro[0] = i; var imei = DeviceId.Invoke(telephonyManager, parametro); if (!imeis.Contains(imei.ToString())) { imeis.Add(imei.ToString()); } } } else { //Obtem ID imeis.Add(telephonyManager.DeviceId); } return(imeis.ToArray()); }
public static bool IsAtLeast(BuildVersionCodes buildVersionCode) => OperatingSystem.IsAndroidVersionAtLeast((int)buildVersionCode);
public static bool IsAtLeast(BuildVersionCodes buildVersionCode) { return(buildVersionCode >= BuildVersion); }
internal static bool HasApiLevel(BuildVersionCodes versionCode) => (int)Build.VERSION.SdkInt >= (int)versionCode;
/// <summary> /// Append rows to the table grid /// @param table The layout to add the rows to /// </summary> /// <param name="aTable">if set to <c>true</c> it is [a table] and false if it is a view</param> private void newAppendRows(bool aTable) { _aTable.RemoveAllViews(); if (_data == null) { return; } int rowSize = _data.Length; if (rowSize == 0) { return; } int colSize = _data[0].getFields().Length; //Go through all the rows of data for (int i = 0; i < rowSize; i++) { int rowNo = i; TableRow row = new TableRow(this); //Make every second row dark gray if (i % 2 == 1) { row.SetBackgroundColor(Color.DarkGray); } //Go through all the columns for (int j = 0; j < colSize; j++) { if (!aTable || j > 0) { TextView c = new TextView(this); c.TextSize = _fontSize; if (_maxWidth > 0) { c.SetMaxWidth(_maxWidth); } if (aTable) { c.Text = _data[i].getFields()[j].getFieldData(); } else { c.Text = _data[i].getFields()[j].getFieldData(); } c.SetBackgroundColor(getBackgroundColor(_data[i].getFields()[j].getFieldType(), (i % 2 == 1))); c.SetPadding(5, 5, 5, 5); // Adding a onClickListener to copy cell value to clip board //ToDo: if the field is a BLOB field make it possible to retrieve / change it c.Click += (sender, e) => { // if the field is not a BLOB field copy it to the clip board string text = c.Text; BuildVersionCodes currentapiVersion = Android.OS.Build.VERSION.SdkInt; try { if (currentapiVersion >= BuildVersionCodes.Honeycomb) { // HONEYCOMB Android.Content.ClipboardManager clipboard = (Android.Content.ClipboardManager)GetSystemService(ClipboardService); ClipData clip = ClipData.NewPlainText("simple text", text); clipboard.PrimaryClip = clip; } else { Android.Text.ClipboardManager clipboard = (Android.Text.ClipboardManager)GetSystemService(ClipboardService); clipboard.Text = text; } ExceptionHandler.toastMsg(_cont, GetText(Resource.String.CopiedToClipboard)); } catch (Exception ex) { ExceptionHandler.toastMsg(this, ex.Message); ExceptionHandler.logDActivity(ex.ToString(), _logging, TAG); } }; row.AddView(c); } // Add a cell with "Select" if (j == colSize - 1 && (aTable || (_canInsertInView || _canUpdateView || _canDeleteView))) { TextView c = addSelectField(rowNo, aTable); row.AddView(c); } } _trLastRow = row; _aTable.AddView(row, new TableLayout.LayoutParams()); } }
public Demo(string title, string className, BuildVersionCodes minVersion) { this.className = className; this.title = title; this.minVersion = minVersion; }
internal static bool HasApiLevel(BuildVersionCodes versionCode) => SdkInt >= (int)versionCode;
private bool HasApiLevel(BuildVersionCodes versionCode) => (int)Build.VERSION.SdkInt >= (int)versionCode;