private LinearLayout GetView(Context con) { //mainLayout LinearLayout mainLayout = new LinearLayout(con); mainLayout.LayoutParameters = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.WrapContent, ViewGroup.LayoutParams.WrapContent); mainLayout.SetGravity(GravityFlags.FillVertical); mainLayout.Orientation = Orientation.Vertical; mainLayout.AddView(simpleInterestCalculatorLabel); mainLayout.AddView(sILabelSpacing); mainLayout.AddView(findingSILabel); mainLayout.FocusableInTouchMode = true; mainLayout.AddView(formulaLabel); mainLayout.AddView(formulaLabelSpacing); LinearLayout principalStack = new LinearLayout(con); principalStack.Orientation = Orientation.Horizontal; principalStack.AddView(principalLabel); principalStack.AddView(principalAmountNumericTextBox); mainLayout.AddView(principalStack); mainLayout.AddView(principalStackSpacing); LinearLayout InterestcalStack = new LinearLayout(con); InterestcalStack.Orientation = Orientation.Horizontal; InterestcalStack.AddView(interestLabel); InterestcalStack.AddView(interestNumericTextBox); mainLayout.AddView(InterestcalStack); mainLayout.AddView(InterestcalStackSpacing); LinearLayout periodStack = new LinearLayout(con); periodStack.Orientation = Orientation.Horizontal; periodStack.AddView(period); periodStack.AddView(periodValueNumericTextBox); mainLayout.AddView(periodStack); LinearLayout outputStack = new LinearLayout(con); outputStack.Orientation = Orientation.Horizontal; outputStack.AddView(outputLabel); if (con.Resources.DisplayMetrics.Density > 1.5) { outputStack.SetY(60); } outputStack.AddView(outputNumberTextBox); mainLayout.AddView(outputStack); mainLayout.SetPadding(20, 20, 10, 20); mainLayout.AddView(outputStackSpacing); mainLayout.Touch += (object sender, View.TouchEventArgs e) => { if (outputNumberTextBox.IsFocused || interestNumericTextBox.IsFocused || periodValueNumericTextBox.IsFocused || principalAmountNumericTextBox.IsFocused) { Rect outRect = new Rect(); outputNumberTextBox.GetGlobalVisibleRect(outRect); interestNumericTextBox.GetGlobalVisibleRect(outRect); periodValueNumericTextBox.GetGlobalVisibleRect(outRect); principalAmountNumericTextBox.GetGlobalVisibleRect(outRect); if (!outRect.Contains((int)e.Event.RawX, (int)e.Event.RawY)) { outputNumberTextBox.ClearFocus(); interestNumericTextBox.ClearFocus(); periodValueNumericTextBox.ClearFocus(); principalAmountNumericTextBox.ClearFocus(); } hideSoftKeyboard((Activity)con); } }; return(mainLayout); }
//Java.Lang.Object.Locale localinfo; public override View GetSampleContent(Context con) { Context localcontext = con; int width = con.Resources.DisplayMetrics.WidthPixels - 40; FrameLayout frameLayout = new FrameLayout(con); FrameLayout.LayoutParams layoutParams = new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MatchParent, ViewGroup.LayoutParams.MatchParent, GravityFlags.FillVertical); frameLayout.LayoutParameters = layoutParams; LinearLayout layout = new LinearLayout(con); layout.LayoutParameters = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.WrapContent, ViewGroup.LayoutParams.WrapContent); layout.SetGravity(GravityFlags.FillVertical); layout.Orientation = Orientation.Vertical; TextView dummy0 = new TextView(con); dummy0.Text = "Simple Interest Calculator"; dummy0.Gravity = GravityFlags.Center; dummy0.TextSize = 24; layout.AddView(dummy0); TextView dummy7 = new TextView(con); layout.AddView(dummy7); TextView dummy = new TextView(con); dummy.Text = "The formula for finding simple interest is:"; dummy.TextSize = 18; layout.AddView(dummy); layout.FocusableInTouchMode = true; SpannableStringBuilder builder = new SpannableStringBuilder(); TextView dummy1 = new TextView(con); String str = "Interest"; SpannableString strSpannable = new SpannableString(str); strSpannable.SetSpan(new ForegroundColorSpan(Color.ParseColor("#66BB6A")), 0, str.Length, 0); builder.Append(strSpannable); builder.Append(" = Principal * Rate * Time"); dummy1.SetText(builder, TextView.BufferType.Spannable); dummy1.TextSize = 18; layout.AddView(dummy1); TextView dummy8 = new TextView(con); layout.AddView(dummy8); /* * Principal amount Stack */ LinearLayout principalStack = new LinearLayout(con); TextView txtPricipal = new TextView(con); txtPricipal.LayoutParameters = new ViewGroup.LayoutParams(width / 2, 100); txtPricipal.Text = "Principal"; principalamount = new SfNumericTextBox(con); principalamount.FormatString = "C"; principalamount.LayoutParameters = new ViewGroup.LayoutParams(width / 2, 100); principalamount.Value = 1000; principalamount.AllowNull = true; principalamount.Watermark = "Principal Amount"; principalamount.MaximumNumberDecimalDigits = 2; var culture = new Java.Util.Locale("en", "US"); principalamount.CultureInfo = culture; principalamount.ValueChangeMode = ValueChangeMode.OnKeyFocus; principalStack.Orientation = Orientation.Horizontal; principalStack.AddView(txtPricipal); principalStack.AddView(principalamount); layout.AddView(principalStack); TextView dummy3 = new TextView(con); layout.AddView(dummy3); /* * Interest Input Box */ LinearLayout InterestcalStack = new LinearLayout(con); TextView txtInterest = new TextView(con); txtInterest.LayoutParameters = new ViewGroup.LayoutParams(width / 2, 100); txtInterest.Text = "Interest Rate"; Interestvalue = new SfNumericTextBox(con); Interestvalue.FormatString = "P"; Interestvalue.PercentDisplayMode = PercentDisplayMode.Compute; Interestvalue.MaximumNumberDecimalDigits = 2; Interestvalue.ValueChangeMode = ValueChangeMode.OnKeyFocus; Interestvalue.LayoutParameters = new ViewGroup.LayoutParams(width / 2, 100); Interestvalue.Value = 0.1f; Interestvalue.Watermark = "Rate of Interest"; Interestvalue.AllowNull = true; Interestvalue.CultureInfo = culture; InterestcalStack.Orientation = Orientation.Horizontal; InterestcalStack.AddView(txtInterest); InterestcalStack.AddView(Interestvalue); layout.AddView(InterestcalStack); TextView dummy2 = new TextView(con); layout.AddView(dummy2); /* * Period Input TextBox */ LinearLayout periodStack = new LinearLayout(con); TextView period = new TextView(con); period.LayoutParameters = new ViewGroup.LayoutParams(width / 2, 100); period.Text = "Term"; periodValue = new SfNumericTextBox(con); periodValue.FormatString = " years"; periodValue.MaximumNumberDecimalDigits = 0; periodValue.LayoutParameters = new ViewGroup.LayoutParams(width / 2, 100); periodValue.Value = 20; periodValue.Watermark = "Period (in years)"; periodValue.ValueChangeMode = ValueChangeMode.OnKeyFocus; periodValue.CultureInfo = culture; periodValue.AllowNull = true; periodStack.Orientation = Orientation.Horizontal; periodStack.AddView(period); periodStack.AddView(periodValue); layout.AddView(periodStack); /* * OutPut values */ LinearLayout outputStack = new LinearLayout(con); TextView outputtxt = new TextView(con); outputtxt.LayoutParameters = new ViewGroup.LayoutParams(width / 2, 100); outputtxt.Text = "Interest"; outputtxt.SetTextColor(Color.ParseColor("#66BB6A")); OutputNumbertxtBox = new SfNumericTextBox(con); OutputNumbertxtBox.FormatString = "c"; OutputNumbertxtBox.MaximumNumberDecimalDigits = 0; OutputNumbertxtBox.AllowNull = true; OutputNumbertxtBox.CultureInfo = culture; OutputNumbertxtBox.Watermark = "Enter Values"; OutputNumbertxtBox.Clickable = false; OutputNumbertxtBox.Value = (float)(1000 * 0.1 * 20); OutputNumbertxtBox.Enabled = false; OutputNumbertxtBox.LayoutParameters = new ViewGroup.LayoutParams(width / 2, 100); OutputNumbertxtBox.ValueChangeMode = ValueChangeMode.OnLostFocus; outputStack.Orientation = Orientation.Horizontal; outputStack.AddView(outputtxt); outputStack.AddView(OutputNumbertxtBox); layout.AddView(outputStack); TextView dummy4 = new TextView(con); layout.SetPadding(20, 20, 10, 20); layout.AddView(dummy4); principalamount.ValueChanged += (object sender, SfNumericTextBox.ValueChangedEventArgs e) => { if (!e.P1.ToString().Equals("") && !periodValue.Value.ToString().Equals("") && !Interestvalue.Value.ToString().Equals("")) { OutputNumbertxtBox.Value = e.P1 * periodValue.Value * Interestvalue.Value; } }; periodValue.ValueChanged += (object sender, SfNumericTextBox.ValueChangedEventArgs e) => { if (!e.P1.ToString().Equals("") && !principalamount.Value.ToString().Equals("") && !Interestvalue.Value.ToString().Equals("")) { OutputNumbertxtBox.Value = e.P1 * principalamount.Value * Interestvalue.Value; } }; Interestvalue.ValueChanged += (object sender, SfNumericTextBox.ValueChangedEventArgs e) => { if (!e.P1.ToString().Equals("") && !principalamount.Value.ToString().Equals("") && !periodValue.Value.ToString().Equals("")) { OutputNumbertxtBox.Value = e.P1 * principalamount.Value * periodValue.Value; } }; layout.Touch += (object sender, View.TouchEventArgs e) => { if (OutputNumbertxtBox.IsFocused || Interestvalue.IsFocused || periodValue.IsFocused || principalamount.IsFocused) { Rect outRect = new Rect(); OutputNumbertxtBox.GetGlobalVisibleRect(outRect); Interestvalue.GetGlobalVisibleRect(outRect); periodValue.GetGlobalVisibleRect(outRect); principalamount.GetGlobalVisibleRect(outRect); if (!outRect.Contains((int)e.Event.RawX, (int)e.Event.RawY)) { if (!OutputNumbertxtBox.Value.ToString().Equals("")) { OutputNumbertxtBox.ClearFocus(); } if (!Interestvalue.Value.ToString().Equals("")) { Interestvalue.ClearFocus(); } if (!periodValue.Value.ToString().Equals("")) { periodValue.ClearFocus(); } if (!principalamount.Value.ToString().Equals("")) { principalamount.ClearFocus(); } } hideSoftKeyboard((Activity)localcontext); } }; frameLayout.AddView(layout); ScrollView scrollView = new ScrollView(con); scrollView.AddView(frameLayout); return(scrollView); }
private void ValueChangeListener() { //numerictextbox Value Changed Listener principalAmountNumericTextBox.ValueChanged += (object sender, ValueChangedEventArgs e) => { if (e.Value != null && periodValueNumericTextBox.Value != null && interestNumericTextBox.Value != null) { outputNumberTextBox.Value = Double.Parse(e.Value.ToString()) * Double.Parse(periodValueNumericTextBox.Value.ToString()) * Double.Parse(interestNumericTextBox.Value.ToString()); } }; periodValueNumericTextBox.ValueChanged += (object sender, ValueChangedEventArgs e) => { if (e.Value != null && principalAmountNumericTextBox.Value != null && interestNumericTextBox.Value != null) { outputNumberTextBox.Value = Double.Parse(e.Value.ToString()) * Double.Parse(principalAmountNumericTextBox.Value.ToString()) * Double.Parse(interestNumericTextBox.Value.ToString()); } }; interestNumericTextBox.ValueChanged += (object sender, ValueChangedEventArgs e) => { if (e.Value != null && principalAmountNumericTextBox.Value != null && periodValueNumericTextBox.Value != null) { outputNumberTextBox.Value = Double.Parse(e.Value.ToString()) * Double.Parse(principalAmountNumericTextBox.Value.ToString()) * Double.Parse(periodValueNumericTextBox.Value.ToString()); } }; mainLayout.Touch += (object sender, View.TouchEventArgs e) => { if (outputNumberTextBox.IsFocused || interestNumericTextBox.IsFocused || periodValueNumericTextBox.IsFocused || principalAmountNumericTextBox.IsFocused) { Rect outRect = new Rect(); outputNumberTextBox.GetGlobalVisibleRect(outRect); interestNumericTextBox.GetGlobalVisibleRect(outRect); periodValueNumericTextBox.GetGlobalVisibleRect(outRect); principalAmountNumericTextBox.GetGlobalVisibleRect(outRect); if (!outRect.Contains((int)e.Event.RawX, (int)e.Event.RawY)) { outputNumberTextBox.ClearFocus(); interestNumericTextBox.ClearFocus(); periodValueNumericTextBox.ClearFocus(); principalAmountNumericTextBox.ClearFocus(); } hideSoftKeyboard((Activity)con); } }; //frame frame.LayoutParameters = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MatchParent, ViewGroup.LayoutParams.MatchParent); frame.SetBackgroundColor(Color.White); //scrollView1 ScrollView scrollView1 = new ScrollView(con); scrollView1.LayoutParameters = new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MatchParent, (int)(totalHeight * 0.6), GravityFlags.Top | GravityFlags.CenterHorizontal); scrollView1.AddView(mainLayout); frame.AddView(scrollView1); //buttomButtonLayout buttomButtonLayout = new FrameLayout(con); buttomButtonLayout.SetBackgroundColor(Color.Transparent); buttomButtonLayout.LayoutParameters = new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MatchParent, (int)(totalHeight * 0.1), GravityFlags.Bottom | GravityFlags.CenterHorizontal); //propertyButton propertyButton = new Button(con); propertyButton.LayoutParameters = new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MatchParent, ViewGroup.LayoutParams.WrapContent, GravityFlags.Bottom | GravityFlags.CenterHorizontal); propertyButton.Text = "OPTIONS"; propertyButton.Gravity = GravityFlags.Start; propertyFrameLayout = new FrameLayout(con); propertyFrameLayout.LayoutParameters = new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MatchParent, (int)(totalHeight * 0.36), GravityFlags.CenterHorizontal); propertyFrameLayout.AddView(GetPropertyLayout(con)); propertyButton.Click += (object sender, EventArgs e) => { buttomButtonLayout.RemoveAllViews(); propertyFrameLayout.RemoveAllViews(); outputNumberTextBox.ClearFocus(); interestNumericTextBox.ClearFocus(); periodValueNumericTextBox.ClearFocus(); principalAmountNumericTextBox.ClearFocus(); propertyFrameLayout.AddView(GetPropertyLayout(con)); }; //scrollView ScrollView scrollView = new ScrollView(con); scrollView.LayoutParameters = new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MatchParent, (int)(totalHeight * 0.36), GravityFlags.Bottom | GravityFlags.CenterHorizontal); scrollView.AddView(propertyFrameLayout); //frame frame.AddView(scrollView); frame.AddView(buttomButtonLayout); frame.FocusableInTouchMode = true; }
//Java.Lang.Object.Locale localinfo; public override View GetSampleContent (Context con) { Context localcontext = con; int width = con.Resources.DisplayMetrics.WidthPixels -40; FrameLayout frameLayout = new FrameLayout(con); FrameLayout.LayoutParams layoutParams = new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MatchParent, ViewGroup.LayoutParams.MatchParent, GravityFlags.FillVertical); frameLayout.LayoutParameters = layoutParams; LinearLayout layout=new LinearLayout(con); layout.LayoutParameters=new ViewGroup.LayoutParams(ViewGroup.LayoutParams.WrapContent, ViewGroup.LayoutParams.WrapContent); layout.SetGravity(GravityFlags.FillVertical); layout.Orientation=Orientation.Vertical; TextView dummy0 = new TextView(con); dummy0.Text="Simple Interest Calculator"; dummy0.Gravity=GravityFlags.Center; dummy0.TextSize=24; layout.AddView(dummy0); TextView dummy7 = new TextView(con); layout.AddView(dummy7); TextView dummy = new TextView(con); dummy.Text="The formula for finding simple interest is:"; dummy.TextSize=18; layout.AddView(dummy); layout.FocusableInTouchMode=true; SpannableStringBuilder builder = new SpannableStringBuilder(); TextView dummy1 = new TextView(con); String str= "Interest"; SpannableString strSpannable= new SpannableString(str); strSpannable.SetSpan(new ForegroundColorSpan(Color.ParseColor("#66BB6A")), 0, str.Length, 0); builder.Append(strSpannable); builder.Append(" = Principal * Rate * Time"); dummy1.SetText(builder, TextView.BufferType.Spannable); dummy1.TextSize=18; layout.AddView(dummy1); TextView dummy8 = new TextView(con); layout.AddView(dummy8); /* Principal amount Stack */ LinearLayout principalStack = new LinearLayout(con); TextView txtPricipal = new TextView(con); txtPricipal.LayoutParameters=new ViewGroup.LayoutParams(width / 2, 100); txtPricipal.Text="Principal"; principalamount =new SfNumericTextBox(con); principalamount.FormatString="C"; principalamount.LayoutParameters=new ViewGroup.LayoutParams(width / 2, 100); principalamount.Value=1000; principalamount.AllowNull = true; principalamount.Watermark = "Principal Amount"; principalamount.MaximumNumberDecimalDigits=2; var culture = new Java.Util.Locale("en","US"); principalamount.CultureInfo = culture; principalamount.ValueChangeMode=ValueChangeMode.OnKeyFocus; principalStack.Orientation = Orientation.Horizontal; principalStack.AddView(txtPricipal); principalStack.AddView(principalamount); layout.AddView(principalStack); TextView dummy3 = new TextView(con); layout.AddView(dummy3); /* Interest Input Box */ LinearLayout InterestcalStack = new LinearLayout(con); TextView txtInterest = new TextView(con); txtInterest.LayoutParameters=new ViewGroup.LayoutParams(width / 2, 100); txtInterest.Text="Interest Rate"; Interestvalue =new SfNumericTextBox(con); Interestvalue.FormatString="P"; Interestvalue.PercentDisplayMode=PercentDisplayMode.Compute; Interestvalue.MaximumNumberDecimalDigits=2; Interestvalue.ValueChangeMode=ValueChangeMode.OnKeyFocus; Interestvalue.LayoutParameters=new ViewGroup.LayoutParams(width / 2, 100); Interestvalue.Value=0.1f; Interestvalue.Watermark = "Rate of Interest"; Interestvalue.AllowNull = true; Interestvalue.CultureInfo = culture; InterestcalStack.Orientation=Orientation.Horizontal; InterestcalStack.AddView(txtInterest); InterestcalStack.AddView(Interestvalue); layout.AddView(InterestcalStack); TextView dummy2 = new TextView(con); layout.AddView(dummy2); /* Period Input TextBox */ LinearLayout periodStack = new LinearLayout(con); TextView period = new TextView(con); period.LayoutParameters=new ViewGroup.LayoutParams(width / 2, 100); period.Text="Term"; periodValue =new SfNumericTextBox(con); periodValue.FormatString=" years"; periodValue.MaximumNumberDecimalDigits=0; periodValue.LayoutParameters=new ViewGroup.LayoutParams(width / 2, 100); periodValue.Value=20; periodValue.Watermark = "Period (in years)"; periodValue.ValueChangeMode=ValueChangeMode.OnKeyFocus; periodValue.CultureInfo = culture; periodValue.AllowNull = true; periodStack.Orientation=Orientation.Horizontal; periodStack.AddView(period); periodStack.AddView(periodValue); layout.AddView(periodStack); /* OutPut values */ LinearLayout outputStack = new LinearLayout(con); TextView outputtxt = new TextView(con); outputtxt.LayoutParameters=new ViewGroup.LayoutParams(width / 2, 100); outputtxt.Text="Interest"; outputtxt.SetTextColor(Color.ParseColor("#66BB6A")); OutputNumbertxtBox =new SfNumericTextBox(con); OutputNumbertxtBox.FormatString="c"; OutputNumbertxtBox.MaximumNumberDecimalDigits=0; OutputNumbertxtBox.AllowNull=true; OutputNumbertxtBox.CultureInfo = culture; OutputNumbertxtBox.Watermark="Enter Values"; OutputNumbertxtBox.Clickable=false; OutputNumbertxtBox.Value = (float)(1000 * 0.1 * 20); OutputNumbertxtBox.Enabled=false; OutputNumbertxtBox.LayoutParameters=new ViewGroup.LayoutParams(width / 2, 100); OutputNumbertxtBox.ValueChangeMode=ValueChangeMode.OnLostFocus; outputStack.Orientation=Orientation.Horizontal; outputStack.AddView(outputtxt); outputStack.AddView(OutputNumbertxtBox); layout.AddView(outputStack); TextView dummy4 = new TextView(con); layout.SetPadding(20, 20, 10, 20); layout.AddView(dummy4); principalamount.ValueChanged+= (object sender, SfNumericTextBox.ValueChangedEventArgs e) => { if(!e.P1.ToString().Equals("")&&!periodValue.Value.ToString().Equals("")&&!Interestvalue.Value.ToString().Equals("")) OutputNumbertxtBox.Value=e.P1 * periodValue.Value * Interestvalue.Value; }; periodValue.ValueChanged+= (object sender, SfNumericTextBox.ValueChangedEventArgs e) => { if(!e.P1.ToString().Equals("")&&!principalamount.Value.ToString().Equals("")&&!Interestvalue.Value.ToString().Equals("")) OutputNumbertxtBox.Value=e.P1* principalamount.Value*Interestvalue.Value; }; Interestvalue.ValueChanged+= (object sender, SfNumericTextBox.ValueChangedEventArgs e) => { if(!e.P1.ToString().Equals("")&&!principalamount.Value.ToString().Equals("")&&!periodValue.Value.ToString().Equals("")) OutputNumbertxtBox.Value=e.P1 * principalamount.Value * periodValue.Value; }; layout.Touch+= (object sender, View.TouchEventArgs e) => { if(OutputNumbertxtBox.IsFocused || Interestvalue.IsFocused ||periodValue.IsFocused || principalamount.IsFocused){ Rect outRect = new Rect(); OutputNumbertxtBox.GetGlobalVisibleRect(outRect); Interestvalue.GetGlobalVisibleRect(outRect); periodValue.GetGlobalVisibleRect(outRect); principalamount.GetGlobalVisibleRect(outRect); if (!outRect.Contains((int)e.Event.RawX, (int)e.Event.RawY)) { if(!OutputNumbertxtBox.Value.ToString().Equals("")) OutputNumbertxtBox.ClearFocus(); if(!Interestvalue.Value.ToString().Equals("")) Interestvalue.ClearFocus(); if(!periodValue.Value.ToString().Equals("")) periodValue.ClearFocus(); if(!principalamount.Value.ToString().Equals("")) principalamount.ClearFocus(); } hideSoftKeyboard((Activity)localcontext); } }; frameLayout.AddView(layout); ScrollView scrollView = new ScrollView(con); scrollView.AddView(frameLayout); return scrollView; }