Unable to print string (Xamarin Android) - xamarin.android

//Beacon MAC Address
string B1 = "E9:32:C6:D9:91:A6";
string B2 = "FA:46:4D:77:C9:9B";
string B3 = "E7:6D:97:D4:83:14";
//Testing
string MAC1;
string Telemetry;
string test;
protected override void OnCreate(Bundle savedInstanceState)
{
base.OnCreate(savedInstanceState);
//Create beacon manager
beaconManager = new BeaconManager(this);
//Connect to beacon manager to start scanning
beaconManager.Connect(this);
// Set our view from the "main" layout resource
SetContentView(Resource.Layout.Main);
Button Scan = FindViewById<Button>(Resource.Id.Scan);
TextView B_Name = FindViewById<TextView>(Resource.Id.B_Name);
TextView B_Rssi = FindViewById<TextView>(Resource.Id.B_Rssi);
TextView B_MacAddress = FindViewById<TextView>(Resource.Id.B_MacAddress);
TextView Check = FindViewById<TextView>(Resource.Id.Check);
Scan.Click += Scan_Click;
int num1 = 0;
eddystone = new Eddystone[3];
//Create an ArrayList
ArrayList arrayList = new ArrayList();
// Wearables will be triggered when nearables are found
beaconManager.Eddystone += (sender, e) =>
{
ActionBar.Subtitle = string.Format("Found {0} eddystones.", e.Eddystones.Count);
B_MacAddress.Text = "MAC Address " + e.Eddystones[0].MacAddress;
B_Rssi.Text = "Rssi " + e.Eddystones[0].Rssi;
e.Eddystones.CopyTo(eddystone, num1);
arrayList.Add(e.Eddystones[0].MacAddress);
MAC1 = "Lol";
};
Check.Text = MAC1 + " jasdh";
}
I need some help with my code.
Currently, I have defined a string called MAC1. However, I defined it inside beaconManager.Eddystone then tried to display it out. It did not work. It only displays jasdh.
I do not understand why. Can anyone tell me the reason?

You're not seeing the text in the variable MAC1 because you set the textview Check to "jasdh". In the code provided you aren't actually updating the Check textview in the beaconManager.Eddystone block. Set the Check text to what ever you want in that code block the same way you do below with Check.Text =

Related

Exception in Application start method java.lang.reflect.InvocationTargetException when using parse Double

So, I am attempting to get a GUI working for a programming project. This involved changing it from a simple scanning function to converting the userinput from the text field using parse Double. The program was able to function, but once I made the change it throws the exception in the title and terminates the program every time I run it. Yes, I do have a main method.
Here is the relevant code:
public class TaxProject extends Application implements
EventHandler<ActionEvent>
{
private Stage primaryStage;
private Button button;
public void start(Stage primaryStage)
{
Scanner input = new Scanner(System.in);
TaxInput t1 = new TaxInput();
StateTax s1 = new StateTax(); //Declaring Classes
FedTax f1 = new FedTax();
GridPane pane = new GridPane();
pane.setPadding(new Insets(10, 10, 10, 10));
pane.setVgap(8);
pane.setHgap(10);
TextField tfHrlyWage = new TextField();
TextField tfHrsPerWeek = new TextField();
TextField tfMaritalStatus = new TextField();
TextField tfIncome = new TextField();
Button btCalculate = new Button("Calculate");
pane.add(new Label("Hourly Wage: "), 0, 0);
pane.add(new Label("Hours Per Week: "), 0, 1);
pane.add(new Label("Married or Single? "), 0, 2);
pane.add(btCalculate, 0, 3);
pane.add(tfHrlyWage, 1, 0);
pane.add(tfHrsPerWeek, 1, 1);
pane.add(tfMaritalStatus, 1, 2);
pane.add(tfIncome, 1, 0);
tfHrlyWage.setPrefColumnCount(4);
tfHrsPerWeek.setPrefColumnCount(3);
tfMaritalStatus.setPrefColumnCount(7);
tfIncome.setPrefColumnCount(7);
Scene scene = new Scene(pane, 250,150);
primaryStage.setTitle("Tax Calculator");
primaryStage.setScene(scene);
primaryStage.show();
String MaritalStatus; //Used for deciding federal income tax brackets
//System.out.println("Please Enter your Hourly Wage:");
t1.HrlyWage = Double.parseDouble(tfHrlyWage.getText()); //HourlyWage Input
//System.out.println("Please Enter the hours you work per week:");
t1.HrsPerWeek = Double.parseDouble(tfHrsPerWeek.getText());
MaritalStatus = tfMaritalStatus.getText();
btCalculate.setOnAction(e -> System.out.println("Your Yearly Income After Federal and State Income Taxes is $" + f1.YearlyTakeHome));
The start method is simply setting up the GUI. Nothing makes the code wait for user input the way a console program with a scanner would.
JavaFX is event based and you should find some event/property to add a event handler/listener to and react on events/changes.
This could be a listener to the text property of the TextFields, if you want to automatically update the result on a change of the text field content
//t1.HrlyWage = Double.parseDouble(tfHrlyWage.getText());
//t1.HrsPerWeek = Double.parseDouble(tfHrsPerWeek.getText());
InvalidationListener listener = o -> {
try {
t1.HrlyWage = Double.parseDouble(tfHrlyWage.getText());
t1.HrsPerWeek = Double.parseDouble(tfHrsPerWeek.getText());
// TODO: some output???
} catch (NumberFormatException ex) {
// TODO: output error message???
}
};
tfHrlyWage.textProperty().addListener(listener);
tfHrsPerWeek.textProperty().addListener(listener);
or from the listener to the button event handler:
//t1.HrlyWage = Double.parseDouble(tfHrlyWage.getText());
//t1.HrsPerWeek = Double.parseDouble(tfHrsPerWeek.getText());
btCalculate.setOnAction(e -> {
try {
t1.HrlyWage = Double.parseDouble(tfHrlyWage.getText());
t1.HrsPerWeek = Double.parseDouble(tfHrsPerWeek.getText());
// TODO: use properties for some calculations???
} catch (NumberFormatException ex) {
// TODO: display error message???
}
System.out.println("Your Yearly Income After Federal and State Income Taxes is $" + f1.YearlyTakeHome);
});

Xamarin.Android doesn't create SQLite database

I'm trying to create a database with Xamarin.Android but both on the emulator and on the tablet I do not receive an error but nothing is created, where am I wrong?
protected override void OnCreate(Bundle bundle)
{
base.OnCreate(bundle);
// Set our view from the "main" layout resource
SetContentView(Resource.Layout.Main);
// create variables for our onscreen widgets
var btnCreate = FindViewById<Button>(Resource.Id.btnCreateDB);
// create DB path
var docsFolder = System.Environment.GetFolderPath(System.Environment.SpecialFolder.MyDocuments);
var pathToDatabase = System.IO.Path.Combine(docsFolder, "db_sqlnet.db");
// disable the single and list buttons until the database has been created
btnSingle.Enabled = btnList.Enabled = false;
// create events for buttons
btnCreate.Click += delegate
{
var result = createDatabase(pathToDatabase);
txtResult.Text = result + "\n";
// if the database was created ok, then enable the list and single buttons
if (result == "Database created")
btnList.Enabled = btnSingle.Enabled = true;
};
private string createDatabase(string path)
{
try
{
var connection = new SQLiteConnection(path);
connection.CreateTable< Entity.Person>();
return "Database created";
}
catch (SQLiteException ex)
{
return ex.Message;
}
}
In you I would use the folder System.Environment.SpecialFolder.Personal instead of System.Environment.SpecialFolder.MyDocuments.
End when you open the connection with new SQLiteConnection(path) try to add SQLiteOpenFlags.ReadWrite | SQLiteOpenFlags.Create as second parameter.

HiQPdf Evaluation tag added when printing

I have a c# dll that uses HiQPdf to print a PDF from file. The issue is the printed PDF has a string added to the top left saying "HiQPdf Evaluation". The marigins are also greatly increased making the image smaller.
When I open the pdf and print from there it is fine. I couldn't find anything on the string being added so hoping someone here might have some insight :)
code:
public void PrintFromFile(string fileName, System.Drawing.Printing.PrinterSettings printerSettings)
{
var imagePrinter = new PdfPrinter();
imagePrinter.PrinterSettings.Copies = printerSettings.Copies;
imagePrinter.PrinterSettings.Duplex = printerSettings.Duplex;
imagePrinter.PrinterSettings.FromPage = printerSettings.FromPage;
imagePrinter.PrinterSettings.MaximumPage = printerSettings.MaximumPage;
imagePrinter.PrinterSettings.MinimumPage = printerSettings.MinimumPage;
imagePrinter.PrinterSettings.PrinterName = printerSettings.PrinterName;
imagePrinter.PrinterSettings.PrintFileName = printerSettings.PrintFileName;
imagePrinter.PrinterSettings.PrintRange = printerSettings.PrintRange;
imagePrinter.PrinterSettings.PrintToFile = printerSettings.PrintToFile;
imagePrinter.PrinterSettings.ToPage = printerSettings.ToPage;
imagePrinter.PrinterSettings.Collate = printerSettings.Collate;
var pdf = new MemoryStream(System.IO.File.ReadAllBytes("V:\\AccW2\\" + fileName));
pdf.Position = 0;
imagePrinter.PrintPdf(pdf);
}
If you have an HtmlToPdf element in you PrintPdf function you should set your SerialNumber
private void PrintPdf(string htmlbody, string pdfname)
{
HtmlToPdf htmlToPdfConverter = new HtmlToPdf();
// set a demo serial number
htmlToPdfConverter.SerialNumber = "-- HiQPdf Serial Number --";
}

Xamarin.iOS ZXing.Net.Mobile barcode scanner

I'm trying to add barcode scanner feature to my xamarin.ios app. I'm developing from visual studio and I've added the Zxing.Net.Mobile component from xamarin components store.
I've implemented it as shown in the samples:
ScanButton.TouchUpInside += async (sender, e) => {
//var options = new ZXing.Mobile.MobileBarcodeScanningOptions();
//options.AutoRotate = false;
//options.PossibleFormats = new List<ZXing.BarcodeFormat>() {
// ZXing.BarcodeFormat.EAN_8, ZXing.BarcodeFormat.EAN_13
//};
var scanner = new ZXing.Mobile.MobileBarcodeScanner(this);
//scanner.TopText = "Hold camera up to barcode to scan";
//scanner.BottomText = "Barcode will automatically scan";
//scanner.UseCustomOverlay = false;
scanner.FlashButtonText = "Flash";
scanner.CancelButtonText = "Cancel";
scanner.Torch(true);
scanner.AutoFocus();
var result = await scanner.Scan(true);
HandleScanResult(result);
};
void HandleScanResult(ZXing.Result result)
{
if (result != null && !string.IsNullOrEmpty(result.Text))
TextField.Text = result.Text;
}
The problem is that when I tap the scan button, the capture view is shown correctly but if I try to capture a barcode nothing happens and it seems the scanner doesn't recognize any barcode.
Someone has experienced this issue? How can I made it work?
Thanks in advance for your help!
I answered a similar question here. I couldn't get barcodes to scan because the default camera resolution was set too low. The specific implementation for this case would be:
ScanButton.TouchUpInside += async (sender, e) => {
var options = new ZXing.Mobile.MobileBarcodeScanningOptions {
CameraResolutionSelector = HandleCameraResolutionSelectorDelegate
};
var scanner = new ZXing.Mobile.MobileBarcodeScanner(this);
.
.
.
scanner.AutoFocus();
//call scan with options created above
var result = await scanner.Scan(options, true);
HandleScanResult(result);
};
And then the definition for HandleCameraResolutionSelectorDelegate:
CameraResolution HandleCameraResolutionSelectorDelegate(List<CameraResolution> availableResolutions)
{
//Don't know if this will ever be null or empty
if (availableResolutions == null || availableResolutions.Count < 1)
return new CameraResolution () { Width = 800, Height = 600 };
//Debugging revealed that the last element in the list
//expresses the highest resolution. This could probably be more thorough.
return availableResolutions [availableResolutions.Count - 1];
}

How we can show "No Data Available" message in RDLC Reports via Resources files

How we can show "No Data Available" message in RDLC Reports via Resources files if no data is found. Currently we are reflecting message from NoRowsMessage property for a table, matrix, or list
(https://technet.microsoft.com/en-us/library/cc645968.aspx).
But we want to show it via Resource files and C# code rather then setting it from Properties of Table. Can anyone please assist. The code (Page_Load) of our control page (.ascx)is mentioned below:
private void Page_Load(object sender, EventArgs e)
{
var presenter = (ReportPresenter)Model;
reportViewer.ProcessingMode = ProcessingMode.Local;
reportViewer.Visible = true;
var rdlcPath = "~/ReportsRDLC/EmployeeData.rdlc";
if(presenter.ReportFilter.GroupOption == Resources.Date)
{
rdlcPath = "~/ReportsRDLC/EmployeeDatebyDate.rdlc";
}
groupOption.SelectedValue = presenter.ReportFilter.GroupOption;
const string DataSetName = "EmployeeDataSet";
reportViewer.LocalReport.ReportPath = HttpContext.Current.Server.MapPath(rdlcPath);
var dataSource = new ReportDataSource(DataSetName, presenter.EmployeeDetails);
reportViewer.AsyncRendering = false;
reportViewer.SizeToReportContent = true;
reportViewer.ShowPrintButton = false;
reportViewer.ShowRefreshButton = false;
reportViewer.ShowToolBar = true;
reportViewer.Height = 600;
reportViewer.Width = 400;
reportViewer.ShowPageNavigationControls = false;
reportViewer.ShowFindControls = false;
reportViewer.ShowZoomControl = false;
reportViewer.LocalReport.DataSources.Add(dataSource);
}
Perhaps you could send the message as a parameter.
You can tell if the report will be empty depending if presenter.EmployeeDetails is empty.
ReportParameter[] myParameters = new ReportParameter[1];
myParameters[0] = new ReportParameter("pEmptyMessage", presenter.EmployeeDetails.Any() ? "No Data Available" : string.Empty);
reportViewer.LocalReport.SetParameters(myParameters);
On your report you can then display this message as you please, using the parameter. You can even place it in a textbox and decide whether to display it based on the value.
I hope this is of use to you.
Edit: I forgot to mention that you should add the report parameter with the correct name to your reporter:
In the reporter you can then use the parameter as followed : [#pEmptyMessage]
=Parameters!pEmptyMessage.Value

Resources