protected virtual View CreateFooterView() { if (Element is StructuredItemsView structuredItemsView) { if (structuredItemsView.Footer != null) { View footer = null; if (structuredItemsView.Footer is View view) { footer = view; } else if (structuredItemsView.FooterTemplate != null) { footer = structuredItemsView.FooterTemplate.CreateContent() as View; footer.BindingContext = structuredItemsView.Footer; } else if (structuredItemsView.Footer is String str) { footer = new XLabel { Text = str, }; } return(footer); } } return(null); }
protected override void OnCreate(Bundle savedInstanceState) { TabLayoutResource = Resource.Layout.Tabbar; ToolbarResource = Resource.Layout.Toolbar; base.OnCreate(savedInstanceState); global::Xamarin.Forms.Forms.Init(this, savedInstanceState); var app = new App(); LoadApplication(app); //Assign controls and add handlers labelInfo = (Xamarin.Forms.Label)app.MainPage.FindByName("labelInfo"); labelMotorP = (Xamarin.Forms.Label)app.MainPage.FindByName("labelMotorP"); labelESPP = (Xamarin.Forms.Label)app.MainPage.FindByName("labelESPP"); ButtonConnect = (Xamarin.Forms.Button)app.MainPage.FindByName("ButtonConnect"); ButtonLF = (Xamarin.Forms.Button)app.MainPage.FindByName("ButtonLF"); ButtonLS = (Xamarin.Forms.Button)app.MainPage.FindByName("ButtonLS"); ButtonLB = (Xamarin.Forms.Button)app.MainPage.FindByName("ButtonLB"); ButtonRF = (Xamarin.Forms.Button)app.MainPage.FindByName("ButtonRF"); ButtonRS = (Xamarin.Forms.Button)app.MainPage.FindByName("ButtonRS"); ButtonRB = (Xamarin.Forms.Button)app.MainPage.FindByName("ButtonRB"); ButtonConnect.Clicked += ButtonConnect_CLicked; ButtonLF.Clicked += ButtonLF_CLicked; ButtonLS.Clicked += ButtonLS_CLicked; ButtonLB.Clicked += ButtonLB_CLicked; ButtonRF.Clicked += ButtonRF_CLicked; ButtonRS.Clicked += ButtonRS_CLicked; ButtonRB.Clicked += ButtonRB_CLicked; CheckBt(); }
protected override void OnAttached() { TypefaceEffect typefaceEffect = (TypefaceEffect)Element.Effects.First(e => e is TypefaceEffect); string fontFamily; switch (typefaceEffect.Name) { case TypefaceEffect.InstalledTypeface.MonospaceTypewriter: fontFamily = "MonospaceTypewriter"; break; case TypefaceEffect.InstalledTypeface.Immortal: fontFamily = "Immortal"; break; default: fontFamily = null; break; } try { switch (Control) { case UILabel lbl: Xamarin.Forms.Label lblElem = Element as Xamarin.Forms.Label; if (lblElem != null) { prevUIFont = lbl.Font; lbl.Font = UIFont.FromName(fontFamily, new System.nfloat(lblElem.FontSize)); lblElem.FontFamily = lbl.Font.FamilyName; } break; case UITextField tf: Xamarin.Forms.Picker tfElem = Element as Xamarin.Forms.Picker; if (tfElem != null) { prevUIFont = tf.Font; tf.Font = UIFont.FromName(fontFamily, new System.nfloat(12f)); } break; case UIButton b: Xamarin.Forms.Button bElem = Element as Xamarin.Forms.Button; if (bElem != null) { prevUIFont = b.Font; b.Font = UIFont.FromName(fontFamily, new System.nfloat(bElem.FontSize)); bElem.FontFamily = b.Font.FamilyName; } break; } } catch (Exception ex) { Debug.WriteLine("Cannot set property on attached control. Error: ", ex.Message); } }
protected virtual View CreateHeaderView() { if (_itemsView is StructuredItemsView structuredItemsView) { if (structuredItemsView.Header != null) { View header = null; if (structuredItemsView.Header is View view) { header = view; } else if (structuredItemsView.HeaderTemplate != null) { header = structuredItemsView.HeaderTemplate.CreateContent() as View; header.BindingContext = structuredItemsView.Header; } else if (structuredItemsView.Header is String str) { header = new XLabel { Text = str, }; } return(header); } } return(null); }
private static void AddMessageView(DateTime Timestamp, DataType Type, Byte[] Data, bool IsMyMessage) { Xamarin.Forms.Device.BeginInvokeOnMainThread(delegate { var MessageLocalTime = Timestamp.ToLocalTime(); var PaddingLeft = 5; var PaddingRight = 5; Xamarin.Forms.Color Background; if (IsMyMessage) { PaddingLeft = 20; Background = Settings.Graphics.BackgroundMyMessage; } else { Background = Settings.Graphics.BackgroundMessage; PaddingRight = 20; } var Frame = new Xamarin.Forms.Frame() { CornerRadius = 10, BackgroundColor = Background, Padding = 0 }; var Box = new Xamarin.Forms.StackLayout() { Padding = new Xamarin.Forms.Thickness(PaddingLeft, 5, PaddingRight, 5) }; Frame.Content = Box; Container.Children.Insert(0, Frame); var TimeLabel = new Xamarin.Forms.Label(); TimeSpan Difference = DateTime.Now - MessageLocalTime; if (Difference.TotalDays < 1) { TimeLabel.Text = MessageLocalTime.ToLongTimeString(); } else { TimeLabel.Text = MessageLocalTime.ToLongDateString() + " - " + MessageLocalTime.ToLongTimeString(); } TimeLabel.FontSize = 8; Box.Children.Add(TimeLabel); switch (Type) { case DataType.Text: var Label = new Xamarin.Forms.Label(); Label.Text = Encoding.Unicode.GetString(Data); Box.Children.Add(Label); break; case DataType.Image: break; case DataType.Audio: break; default: break; } }); }
public static bool UpdateProperty(this Xamarin.Forms.Label fView, string property, object value) { switch (property) { case nameof(Text.Value): fView.Text = (string)value; return(true); } return(fView.UpdateBaseProperty(property, value)); }
public void TranslateViewFormY(double yValue) { //arrange var label = new Xamarin.Forms.Label(); var beforeLocation = WhiteMvvm.Animations.Animation.GetTranslate(label); var translateParameters = new TranslateParameters(0, yValue, 100); //act WhiteMvvm.Animations.Animation.SetTranslate(label, translateParameters); var afterLocation = WhiteMvvm.Animations.Animation.GetTranslate(label); var diff = afterLocation.Y - beforeLocation.Y; //assert Assert.IsTrue(Math.Abs(diff - yValue) < 0.001); }
private static void AddMessageView(DataType Type, Byte[] Data, bool IsMyMessage) { var Container = cryptogram.Views.ItemDetailPage.Messages; var PaddingLeft = 5; var PaddingRight = 5; Xamarin.Forms.Color Background; if (IsMyMessage) { PaddingLeft = 20; Background = Settings.Graphics.BackgroundMyMessage; } else { Background = Settings.Graphics.BackgroundMessage; PaddingRight = 20; } var Frame = new Xamarin.Forms.Frame() { CornerRadius = 10, BackgroundColor = Background, Padding = 0 }; var Box = new Xamarin.Forms.StackLayout() { Padding = new Xamarin.Forms.Thickness(PaddingLeft, 5, PaddingRight, 5) }; Frame.Content = Box; Container.Children.Insert(0, Frame); switch (Type) { case DataType.Text: var Label = new Xamarin.Forms.Label(); Label.Text = Encoding.Unicode.GetString(Data); Box.Children.Add(Label); break; case DataType.Image: break; case DataType.Audio: break; default: break; } }
//CONSTRUCTOR public Vector(String p_name, int p_dvd, int p_laser, int p_usb, int p_bluray, int p_inkjet, int p_printer3d, Xamarin.Forms.Label p_label) { this.name = p_name; this.dvd = p_dvd; this.laser = p_laser; this.usb = p_usb; this.bluray = p_bluray; this.inkjet = p_inkjet; this.printer3d = p_printer3d; this.label = p_label; vectorsDict.Add(this.name, this); }
public ItemDefaultTemplateAdaptor(ItemsView itemsView) : base(itemsView) { ItemTemplate = new DataTemplate(() => { var label = new XLabel { TextColor = Color.Black, }; label.SetBinding(XLabel.TextProperty, new Binding(".", converter: new ToTextConverter())); return(new StackLayout { BackgroundColor = Color.White, Padding = 30, Children = { label } }); }); }
protected override void Init() { var span = new Span { Text = " Mi augue molestie ligula lobortis enim Velit, in. \n Imperdiet eu dignissim odio. Massa erat Hac inceptos facilisis nibh " + " Interdum massa Consectetuer risus sociis molestie facilisi enim. Class gravida. \n Gravida sociosqu cras Quam velit, suspendisse" + " leo auctor odio integer primis dui potenti dolor faucibus augue justo morbi ornare sem. " }; var formattedString = new FormattedString(); formattedString.Spans.Add(span); var label = new Xamarin.Forms.Label { LineBreakMode = LineBreakMode.TailTruncation, VerticalOptions = LayoutOptions.Start, FormattedText = formattedString, MaxLines = 3 //max line is less than the text reproduce and textViewExtensions couldn't identify when //it's already pass the MaxLines range because of the paragraph('\n' character). }; var labelDescription = new Label { Text = "If you opened this page, the app didn't crash and you can read three lines in the label above, this test has passed", VerticalOptions = LayoutOptions.StartAndExpand }; var layout = new Xamarin.Forms.StackLayout(); layout.Children.Add(label); layout.Children.Add(labelDescription); Content = layout; }
public EmbeddingControls() { PlayImage = new ImageButton { Source = ImageSource.FromResource(PlayImagePath, typeof(EmbeddingControls).Assembly), IsVisible = false }; PlayImage.Clicked += OnImageButtonClicked; AbsoluteLayout.SetLayoutFlags(PlayImage, AbsoluteLayoutFlags.All); AbsoluteLayout.SetLayoutBounds(PlayImage, new Rectangle(0.5, 0.5, 0.25, 0.25)); PauseImage = new ImageButton { Source = ImageSource.FromResource(PauseImagePath, typeof(EmbeddingControls).Assembly), IsVisible = false }; PauseImage.Clicked += OnImageButtonClicked; AbsoluteLayout.SetLayoutFlags(PauseImage, AbsoluteLayoutFlags.All); AbsoluteLayout.SetLayoutBounds(PauseImage, new Rectangle(0.5, 0.5, 0.25, 0.25)); var bufferingLabel = new XLabel { FontSize = Device.GetNamedSize(NamedSize.Large, typeof(Label), false), HorizontalTextAlignment = XTextAlignment.Center, TextColor = Color.FromHex("#eeeeeeee") }; bufferingLabel.SetBinding(XLabel.TextProperty, new Binding { Path = "BufferingProgress", StringFormat = "{0:0%}" }); bufferingLabel.SetBinding(IsVisibleProperty, new Binding { Path = "IsBuffering", }); AbsoluteLayout.SetLayoutFlags(bufferingLabel, AbsoluteLayoutFlags.All); AbsoluteLayout.SetLayoutBounds(bufferingLabel, new Rectangle(0.5, 0.5, 0.25, 0.25)); var progressBoxView = new BoxView { Color = Color.FromHex($"#4286f4") }; progressBoxView.SetBinding(AbsoluteLayout.LayoutBoundsProperty, new Binding { Path = "Progress", Converter = new ProgressToBoundTextConverter() }); AbsoluteLayout.SetLayoutFlags(progressBoxView, AbsoluteLayoutFlags.All); var posLabel = new XLabel { Margin = new Thickness(10, 0, 0, 0), FontSize = Device.GetNamedSize(NamedSize.Micro, typeof(XLabel)), HorizontalTextAlignment = XTextAlignment.Start }; posLabel.SetBinding(XLabel.TextProperty, new Binding { Path = "Position", Converter = new MillisecondToTextConverter() }); AbsoluteLayout.SetLayoutFlags(posLabel, AbsoluteLayoutFlags.All); AbsoluteLayout.SetLayoutBounds(posLabel, new Rectangle(0, 0, 1, 1)); var durationLabel = new XLabel { Margin = new Thickness(0, 0, 10, 0), FontSize = Device.GetNamedSize(NamedSize.Micro, typeof(XLabel)), HorizontalTextAlignment = XTextAlignment.End }; durationLabel.SetBinding(XLabel.TextProperty, new Binding { Path = "Duration", Converter = new MillisecondToTextConverter() }); AbsoluteLayout.SetLayoutFlags(durationLabel, AbsoluteLayoutFlags.All); AbsoluteLayout.SetLayoutBounds(durationLabel, new Rectangle(0, 0, 1, 1)); var progressInnerLayout = new AbsoluteLayout { HorizontalOptions = LayoutOptions.FillAndExpand, HeightRequest = 23, BackgroundColor = Color.FromHex("#80000000"), Children = { progressBoxView, posLabel, durationLabel } }; var progressLayout = new StackLayout { Children = { new StackLayout { VerticalOptions = LayoutOptions.FillAndExpand }, new StackLayout { Margin = Device.Idiom == TargetIdiom.Watch ? new Thickness(80, 0, 80, 0) : 20, VerticalOptions = LayoutOptions.End, HorizontalOptions = LayoutOptions.FillAndExpand, BackgroundColor = Color.FromHex("#50000000"), Children = { progressInnerLayout } } } }; AbsoluteLayout.SetLayoutFlags(progressLayout, AbsoluteLayoutFlags.All); AbsoluteLayout.SetLayoutBounds(progressLayout, new Rectangle(0, 0, 1, 1)); Content = new AbsoluteLayout { HorizontalOptions = LayoutOptions.FillAndExpand, VerticalOptions = LayoutOptions.FillAndExpand, Children = { progressLayout, PlayImage, PauseImage, bufferingLabel } }; }
public static void UpdateProperties(this Xamarin.Forms.Label fView, Text text) { fView.UpdateBaseProperties(text); fView.Text = text.Value; }
public async void Downlaod_mp3_Url(string url, string audioFileName, Xamarin.Forms.ActivityIndicator LoadingDownloadProgress, Xamarin.Forms.Label DownloadingLabel) { _audioFileName = audioFileName; LoadingDownloadProgress.IsRunning = true; DownloadingLabel.IsVisible = true; // Android.Widget.Toast.MakeText(Android.App.Application.Context, _audioFileName + " Downloading..", Android.Widget.ToastLength.Long).Show(); var webClient = new System.Net.WebClient(); //var url = new Uri("http://www.maninblack.org/demos/SitDownShutUp.mp3"); // string local = "/sdcard/Download/abc.mp3"; byte[] bytes = null; webClient.DownloadProgressChanged += WebClient_DownloadProgressChanged; try { bytes = await webClient.DownloadDataTaskAsync(url); } catch (System.Threading.Tasks.TaskCanceledException) { // Android.Widget.Toast.MakeText(Android.App.Application.Context, "Task Canceled!", Android.Widget.ToastLength.Long).Show(); return; } catch (Exception a) { //Android.Widget.Toast.MakeText(Android.App.Application.Context,a.InnerException.Message, Android.Widget.ToastLength.Long); Download_Completed = false; return; } Java.IO.File documentsPath = new Java.IO.File(Android.OS.Environment.GetExternalStoragePublicDirectory(Android.OS.Environment.DirectoryDownloads), ""); string localFilename = documentsPath + "/" + audioFileName; //Save the Mp3 using writeAsync System.IO.FileStream fs = new System.IO.FileStream(localFilename, System.IO.FileMode.OpenOrCreate); await fs.WriteAsync(bytes, 0, bytes.Length); fs.Close(); LoadingDownloadProgress.IsRunning = false; DownloadingLabel.IsVisible = false; Download_Completed = false; }
public void Downlaod_mp3_Url(string url, string audioFileName, Xamarin.Forms.ActivityIndicator LoadingDownloadProgress, Xamarin.Forms.Label DownloadingLabel) { LoadingDownloadProgress.IsRunning = true; DownloadingLabel.IsVisible = true; // LongAlert(audioFileName + " Downloading.."); var webClient = new System.Net.WebClient(); webClient.DownloadDataCompleted += (s, e) => { var text = e.Result; // get the downloaded text string documentsPath = Environment.GetFolderPath(Environment.SpecialFolder.Personal); string localPath = System.IO.Path.Combine(documentsPath, audioFileName); Console.WriteLine(localPath); File.WriteAllBytes(localPath, text); // writes to local storage LongAlert(audioFileName + " Downloaded to path"); LoadingDownloadProgress.IsRunning = false; DownloadingLabel.IsVisible = false; }; try { var urla = new Uri(url); // give this an actual URI to an MP3 webClient.DownloadDataAsync(urla); } catch (System.Threading.Tasks.TaskCanceledException) { // LongAlert("Task Canceled!"); LoadingDownloadProgress.IsRunning = false; DownloadingLabel.IsVisible = false; return; } catch (Exception a) { //LongAlert(a.InnerException.Message); LoadingDownloadProgress.IsRunning = false; DownloadingLabel.IsVisible = false; Download_Completed = false; return; } Download_Completed = false; webClient.DownloadProgressChanged += WebClient_DownloadProgressChanged; }