Xamarin Cross-Platform Solution Creating the Views Directory (AdMobView-NotesPage)

Xamarin Cross-Platform Solution Creating the Views Directory (AdMobView-NotesPage)

C#, MySQL, Xamarin Forms
In this post, we will take a look at the AdMobView.cs and NotesPage used in our WetYourWhistle mobile app. Why do we have a routine called AdMobView and why have you seen references to AdMob so far? Because everyone deserves to make a dollar or two from all of their programming efforts. AdMob is one of the ways to monetize your mobile app, creating income from ads placed in inconspicuous places. The code shown below is included in our AdMobView.cs class. What is it doing? I am glad that you were wondering that. This public class inherits main functionality from, or is built upon, the standard View class. As illustrated, it is only creating two properties - AdUnitIdProperty and AdUnitId which allow posting of ad revenue to our AdMob account.…
Read More
Xamarin Cross-Platform Solution Creating the Views Directory (AboutPage)

Xamarin Cross-Platform Solution Creating the Views Directory (AboutPage)

C#, Programming, Xamarin Forms
Now we get to create the individual Views used in our Xamarin cross-platform mobile app. Because many of these are quite similar, we will be excluding much of the code in XAML page documents below the first. As I am sure you already know, proper app design means separation of the Model-View-Controller into their own sections of code. Today we will be covering the View designs of our Wet Your Whistle mobile app. We will start below with the xaml contained in the About page. <?xml version="1.0" encoding="utf-8" ?> <ContentPage xmlns="http://xamarin.com/schemas/2014/forms" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" xmlns:local="clr-namespace:NYWineryHopper.Views" xmlns:controls="clr-namespace:MarcTron.Plugin.Controls;assembly=Plugin.MtAdmob" x:Class="NYWineryHopper.Views.AboutPage" Title="About"> <ContentPage.ToolbarItems > <ToolbarItem Text="Vid Walkthru" Clicked="Loadvid" /> <ToolbarItem Text="Settings" Clicked="LoadSettings" /> </ContentPage.ToolbarItems> <ContentPage.Content> <Grid> <Grid.RowDefinitions> <RowDefinition Height="*" /> <RowDefinition Height="50" /> </Grid.RowDefinitions> <StackLayout Grid.Row="0"> <Label Text="About NY Wine Hopper" FontSize="Large" VerticalOptions="CenterAndExpand" HorizontalOptions="CenterAndExpand" /> <Image…
Read More
Xamarin Cross-Platform Solution Creating the Data Directory

Xamarin Cross-Platform Solution Creating the Data Directory

C#, Programming, Xamarin Forms
Now we will be able to make the connection between the MySQL database designed previously and the individual models. This connection is enabled using the interface, service and Item Manager files shown at the left. Let's begin by explaining the interface and service together. public interface IRestService { Task<List<WineryItem>> ReadWineries(string typ, string val, int wrs, int distanceFrom); Task<List<string>> GetLTDNames(); Task<List<string>> GetCounties(); Task<string> GetName(int id); Task<double> GetLat(int id); Task<double> GetLong(int id); } As with the other interface we have seen, this class file defines the individual procedures declared inside of RestService. After the task declaration we define what will be returned by the individual process (List of WineryItem, list of strings, string, double). Inside the parentheses of each procedure you will notice the type and name of parameters being fed into…
Read More
Xamarin Cross-Platform Solution Creating the Models Directory

Xamarin Cross-Platform Solution Creating the Models Directory

C#, Programming, Xamarin Forms
We will begin with our Models directory. This is not necessarily created by the template chosen in the beginning, so you may need to right-click on the Portable Class Library (PCL) project and Add-New Folder. As you can see, most of these are created as pairs with Item and Records files. As we discover the C# code behind each of these classes, the reason for this design will become quite obvious As shown above, each of these files is a cs class file. These are created with a right-click on the Models directory, Add – Class. CountyRecords.cs, one of the single-file classes, contains the code shown below. using System.Collections.Generic; namespace NYWineryHopper.Models { public class CountyRecords { public List<string> records { get; set; } } } Why is this a “single-file”…
Read More
Creating the Visual Studio 2019 Xamarin Solution

Creating the Visual Studio 2019 Xamarin Solution

C#, Featured, Programming, Xamarin Forms
We have a single Xamarin solution with a main project along with an individual project for each of the platforms being targeted. In this case, we are looking at the individual app designed for New York, called NYWineryHopper. We also see the Android and iOS projects. If desired, we could have included a UWP (Universal Windows) project in order to target windows with our mobile app. We will start by creating a blank Xamarin Forms project. After opening Visual Studio 2019 (version 16.9.2), click on File-New-Project. Since our development will be using the C# language, that is selected in the first dropdown available and Mobile is chosen on the right-side dropdown. We happen to have the desired selection right at the top. Click Mobile App (Xamarin.Forms) and Next to proceed.…
Read More
Building Your PHP Rest Service-Database Design

Building Your PHP Rest Service-Database Design

PHP, REST
You may be thinking – “I am a web designer, I don’t know how to use MS SQL and SQL Studio.” The good news is that in most cases you don’t need these to design a database for your RESTful site. When logging into your web host, they should provide a Control Panel for your management and installation of much of the components used on the site. The most popular control panels are cPanel and Plesk, today we will be starting in cPanel to move into phpMyAdmin and work on our database. Your first step will be to create the new database using the tools available in cPanel. In the Databases section, click on MySQL Databases and Create New Database. It will fill in the name prefix for you, type…
Read More
Building Your PHP Rest Service (step 6)

Building Your PHP Rest Service (step 6)

PHP, REST
In the article for step 5, we began to get into the main functions of this read-only REST service. We now know how to gather unique counties and regions from our database, and will now retrieve the data based on region/county selections or partial name entered, We are still working in the wineries folder and will show complete code for wineries_by_region.php and then review the slight code modifications made to wineries_by_county.php and wineries_by_name.php <?php // required headers header("Access-Control-Allow-Origin: *"); header("Access-Control-Allow-Headers: access"); header("Access-Control-Allow-Methods: GET"); header("Access-Control-Allow-Credentials: true"); header('Content-Type: application/json'); // include database and object files include_once '../config/database.php'; include_once '../objects/wineries.php'; $cred = 0; $user = $_SERVER['PHP_AUTH_USER']; $pwd = $_SERVER['PHP_AUTH_PW']; if(sha1('* user *') == $user and sha1('* pwd *') == $pwd) $cred = 1; if($cred == 0) { // set response code - 403 Not…
Read More
Building Your PHP Rest Service (step 5)

Building Your PHP Rest Service (step 5)

PHP, REST
In the article for step 4, we looked at the contents of the trivia folder and the PHP code designed to retrieve the question/hint/answer for the id being fed in as a parameter. Over the next two steps we will be getting into the main functionality of this REST service – looking up details for wineries, distilleries and meaderies. Let’s jump right in … We will be looking at the files and procedures created to read counties and regions. The main SQL clause used in the two functions called by these procedures is DISTINCT. The code shown below is for read_counties.php <?php // required headers header("Access-Control-Allow-Origin: *"); header("Access-Control-Allow-Headers: access"); header("Access-Control-Allow-Methods: GET"); header("Access-Control-Allow-Credentials: true"); header('Content-Type: application/json'); // include database and object files include_once '../config/database.php'; include_once '../objects/wineries.php'; $cred = 0; $user =…
Read More
Building Your PHP Rest Service (step 4)

Building Your PHP Rest Service (step 4)

PHP, REST
In the article for step 3, we looked at the shared directory and the getPaging function. Although these are not used in our final solution – Wet Ur Whis(tel), we have gained the experience of creating shared functions. Next we will cover the trivia folder and the PHP code used to load a trivia question, hint and answer using ID as the parameter. In the trivia folder we have one file called questions_by_id.php. The code which loads question data is shown below. <?php // required headers header("Access-Control-Allow-Origin: *"); header("Access-Control-Allow-Headers: access"); header("Access-Control-Allow-Methods: GET"); header("Access-Control-Allow-Credentials: true"); header('Content-Type: application/json'); // include database and object files include_once '../config/database.php'; include_once '../objects/trivia.php'; $cred = 0; $user = $_SERVER['PHP_AUTH_USER']; $pwd = $_SERVER['PHP_AUTH_PW']; if(sha1('* encrypted user name goes here *') == $user and sha1('* encrypted password goes here…
Read More
Building Your PHP Rest Service (step 3)

Building Your PHP Rest Service (step 3)

PHP, REST
In the article for step 2, we continued building building our Representational State Transfer (REST) service by looking at files located in the objects directory. Next, we will look at the shared directory. Our final project, located at https://winehopper.app does not use this directory. Shared will contain a file such as utilities.php which contains a getPaging function which is shared among all WordPress PHP theme pages. That function is shown below. <?php class Utilities{ public function getPaging($page, $total_rows, $records_per_page, $page_url){ // paging array $paging_arr=array(); // button for first page $paging_arr["first"] = $page>1 ? "{$page_url}page=1" : ""; // count all products in the database to calculate total pages $total_pages = ceil($total_rows / $records_per_page); // range of links to show $range = 2; // display links to 'range of pages' around 'current…
Read More