I'm trying also to generate from a database list the Shell Flyout elements. But I am not sure that implementing directly in AppShell.xaml.cs is a good idea. Is it possible to do the same thing but in
xaml?
I saw something similarly in Define FlyoutItem appearance. But I still can't figure it out.
Also, is it a good idea to implement code directly into AppShell.xaml.cs or App.xaml.cs?
LocationLevelViewModel diudu = new LocationLevelViewModel();
var lists = diudu.Items;
foreach (var list in lists)
{
ShellSection shell_section = new ShellSection();
shell_section.Title = list.LocationName;
shell_section.Icon = "icon_feed.png";
shell_section.Items.Add(new ShellContent() { Content = new LocationLevelPage() });
this.Items.Add(shell_section);
}
The code you provided, you could create a new class named AppShellCS and use teh code in a new AppShellCS.cs file like below. It works well. I made a simple example to test instead of database.
public class AppShellCS : Shell
{
public AppShellCS()
{
LocationLevelViewModel diudu = new LocationLevelViewModel();
//var lists = diudu.Items;
var lists = new List<LocationLevelViewModel>
{
new LocationLevelViewModel() { LocationName="A"},
new LocationLevelViewModel() { LocationName="B"},
new LocationLevelViewModel() { LocationName="C"}
};
foreach (var list in lists)
{
ShellSection shell_section = new ShellSection();
shell_section.Title = list.LocationName;
shell_section.Icon = "tab_feed.png";
shell_section.Items.Add(new ShellContent() { Content = new LocationLevelPage() });
this.Items.Add(shell_section);
}
}
}
public class LocationLevelViewModel
{
public string LocationName { get; set; }
}
App.xaml.cs
public App()
{
InitializeComponent();
DependencyService.Register<MockDataStore>();
MainPage = new AppShellCS();
}
OutPut:
If you want to add this in a exist Shell project, you could try the code below.
AppShell.xaml.cs
public partial class AppShell : Xamarin.Forms.Shell
{
public AppShell()
{
InitializeComponent();
//Routing.RegisterRoute("step", typeof(Page2));
LocationLevelViewModel diudu = new LocationLevelViewModel();
//var lists = diudu.Items;
var lists = new List<LocationLevelViewModel>
{
new LocationLevelViewModel() { LocationName="A"},
new LocationLevelViewModel() { LocationName="B"},
new LocationLevelViewModel() { LocationName="C"}
};
foreach (var list in lists)
{
ShellSection shell_section = new ShellSection();
shell_section.Title = list.LocationName;
shell_section.Icon = "tab_feed.png";
shell_section.Items.Add(new ShellContent() { Content = new LocationLevelPage() });
this.Items.Add(shell_section);
}
}
}
Output:
Related
I am fairly new at working with the Android code in Visual Studio 2019. The ultimate result desired here was to be able to display the various wifi Access Points near the phone. I have gotten the wifi scan to work and I can see the results of the scan in the "WifiScans" collection but the listWifiScan ListView does not show the results on the display. I can see lines on the display for the number of items that should be displayed. If I touch one of the items I can see it turn to a solid color (Orange) but the information is not displayed. Can anyone tell me what I am doing wrong? Thanks for any help you can give.
using Android;
using Android.Content.PM;
using Android.Support.V4.App;
using Android.Support.V4.Content;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Runtime.CompilerServices;
using System.Text;
using Xamarin.Forms;
namespace MobileWifi
{
public partial class MainPage : ContentPage
{
ObservableCollection<WifiScan> WifiScans { get; set; }
Label lblTitle;
ListView listWifiScan;
readonly Button btnWifiScan;
public static bool response = false;
public MainPage()
{
// add code to handle the components here
WifiScans = new ObservableCollection<WifiScan>();
this.Padding = new Thickness(20,20,20,20); // wall padding for page
// Listview data template
var scanDataTemplate = new DataTemplate(() =>
{
var grid = new Grid();
var bssidLabel = new Label { FontAttributes = FontAttributes.Bold };
var ssidLabel = new Label();
var levelLabel = new Label { HorizontalTextAlignment = TextAlignment.End };
bssidLabel.SetBinding(Label.TextProperty, "BSSID");
ssidLabel.SetBinding(Label.TextProperty, "SSID");
levelLabel.SetBinding(Label.TextProperty, "Level");
grid.Children.Add(bssidLabel);
grid.Children.Add(ssidLabel, 1, 0);
grid.Children.Add(levelLabel, 2, 0);
return new ViewCell { View = grid };
});
// setup StackLayout for controls and set spacing of controls within the layout
StackLayout panel = new StackLayout
{
Spacing = 15,
Margin = new Thickness(20),
};
panel.Children.Add(lblTitle = new Label
{
Text = "Mobile Wifi Scanner",
HorizontalTextAlignment = TextAlignment.Center,
FontSize = Device.GetNamedSize(NamedSize.Large, typeof(Label)),
FontAttributes = FontAttributes.Bold,
});
panel.Children.Add(btnWifiScan = new Button
{
Text = "Start Scan"
});
panel.Children.Add(listWifiScan = new ListView
{
ItemsSource = WifiScans,
HasUnevenRows = true,
ItemTemplate = scanDataTemplate,
Margin = new Thickness(0, 20, 0, 0),
});
btnWifiScan.Clicked += OnBtnWifiScanClicked;
this.Content = panel;
}
private void OnBtnWifiScanClicked(object sender, EventArgs e)
{
btnWifiScan.Text = "Scanning...";
WifiScans.Clear(); // clear out results from previous scan
try
{
IWifiScan service = DependencyService.Get<IWifiScan>().GetObj();
service.Start();
service.Finished += WifiScanDone;
}
catch (Exception ex)
{
btnWifiScan.Text = "Start Scan";
DisplayAlert("Alert", ex.Message, "OK");
}
}
public void WifiScanDone(object sender,EventArgs e)
{
IWifiScan service = DependencyService.Get<IWifiScan>();
List<string> WifiBSSID = service.GetBSSID();
List<string> WifiSSID = service.GetSSID();
List<int> WifiLevel = service.GetLevel();
int count = WifiBSSID.Count;
// add logic here to display the data from the scan
// add results of the scan
if(count > 0)
{
for (int i = 0; i < count; i++)
{
WifiScans.Add(new WifiScan { WifiBSSID = WifiBSSID[i], WifiSSID = WifiSSID[i], WifiLevel = WifiLevel[i].ToString()});
}
}else
{
WifiScans.Add(new WifiScan { WifiBSSID = "None Found", WifiSSID = "", WifiLevel = "0"});
}
btnWifiScan.Text = "Start Scan";
// finalize the scan, etc.
service.Done();
}
}
}
I finally found the problem. It turns out I did not specify the correct property in the binding. The correct code for the binding in the data template should have been:
bssidLabel.SetBinding(Label.TextProperty, "WifiBSSID");
ssidLabel.SetBinding(Label.TextProperty, "WifiSSID");
levelLabel.SetBinding(Label.TextProperty, "WifiLevel");
I'm not sure where I got the original values but after studying the data binding properties I realized they were wrong. Also I did not include the source in the original question that would have helped identify the problem so I am adding it here in case it is helpful to someone else that may have a similar problem.
public class WifiScan
{
public string WifiSSID { get; set; }
public string WifiBSSID { get; set; }
public string WifiLevel { get; set; }
}
I am writing a library for Android and wanted it to use the constants in the BuildConfig exclusively - so the lib's client, so to speak, won't see them easily.
So, what I would like to achieve is instead of the public constant like this:
package my.lib;
public final class BuildConfig {
public static final boolean FOO = false;
}
it would rather generate a constant with no access modifier that would make the stuff visible in the package of my lib rather:
package my.lib;
public final class BuildConfig {
static final boolean FOO = false;
}
Is it possible to achieve somehow?
Thanks!
This is the generate() method from BuildConfigGenerator class:
/**
* Generates the BuildConfig class.
*/
public void generate() throws IOException {
File pkgFolder = getFolderPath();
if (!pkgFolder.isDirectory()) {
if (!pkgFolder.mkdirs()) {
throw new RuntimeException("Failed to create " + pkgFolder.getAbsolutePath());
}
}
File buildConfigJava = new File(pkgFolder, BUILD_CONFIG_NAME);
FileWriter out = new FileWriter(buildConfigJava);
JavaWriter writer = new JavaWriter(out);
Set<Modifier> publicFinal = EnumSet.of(Modifier.PUBLIC, Modifier.FINAL);
Set<Modifier> publicFinalStatic = EnumSet.of(Modifier.PUBLIC, Modifier.FINAL, Modifier.STATIC);
writer.emitJavadoc("Automatically generated file. DO NOT MODIFY")
.emitPackage(mBuildConfigPackageName)
.beginType("BuildConfig", "class", publicFinal);
for (ClassField field : mFields) {
writer.emitField(
field.getType(),
field.getName(),
publicFinalStatic,
field.getValue());
}
for (Object item : mItems) {
if (item instanceof ClassField) {
ClassField field = (ClassField)item;
writer.emitField(
field.getType(),
field.getName(),
publicFinalStatic,
field.getValue());
} else if (item instanceof String) {
writer.emitSingleLineComment((String) item);
}
}
writer.endType();
out.close();
}
}
So this is impossible because BuildConfigGenerator creates only public final modifiers
Set<Modifier> publicFinal = EnumSet.of(Modifier.PUBLIC, Modifier.FINAL);
writer.emitJavadoc("Automatically generated file. DO NOT MODIFY")
.emitPackage(mBuildConfigPackageName)
.beginType("BuildConfig", "class", publicFinal);
and does not give you the option to choose)
I just tried to Inserting a data to azure platform. But that problem occurred.
No 'id' member found on type 'app4.MainActivity' I used a break points for examination the problem and it goes to the catch line at " JObject jo = new JObject(); or the next line (now break points doesnt work) "
using Android.App;
using Android.Widget;
using Android.OS;
using Microsoft.WindowsAzure.MobileServices;
using Android.Views;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System;
namespace App4
{
[Activity(Label = "App4", MainLauncher = true, Icon = "#drawable/icon")]
public class MainActivity : Activity
{
public TextView txtShow;
public EditText txtEnter;
public Button btnSave;
// string id;
[JsonProperty(PropertyName = "id")]
public string Id
{
get { return Id; }
set { Id = value; }
}
[JsonProperty(PropertyName = "Questions")]
public string Questions { get; set; }
/* [JsonProperty(PropertyName = "complete")]
public bool Complete { get; set; }*/
protected override void OnCreate(Bundle bundle)
{
base.OnCreate(bundle);
SetContentView(Resource.Layout.Main);
Button btnSave = FindViewById<Button>(Resource.Id.btnSave);
TextView txtShow = FindViewById<TextView>(Resource.Id.txtSoru);
EditText txtEnter = FindViewById<EditText>(Resource.Id.txtSoruGir);
Microsoft.WindowsAzure.MobileServices.CurrentPlatform.Init();
SQLitePCL.Batteries.Init();
// IMobileServiceTable<MainActivity> SurveyTable = client.GetTable<MainActivity>();
// Initialization for Azure Mobile Apps
Microsoft.WindowsAzure.MobileServices.CurrentPlatform.Init();
// This MobileServiceClient has been configured to communicate with the Azure Mobile App and
// Azure Gateway using the application url. You're all set to start working with your Mobile App!
Microsoft.WindowsAzure.MobileServices.MobileServiceClient TrendDemoClient = new Microsoft.WindowsAzure.MobileServices.MobileServiceClient(
"http://xxxx.azurewebsites.net");
// Set our view from the "main" layout resource
// SetContentView (Resource.Layout.Main);
}
// It is save button. ( or insert button)using on xml
// using via android:onClick="AddItem"
[Java.Interop.Export()]
public async void AddItem(View view)
{
var client = new MobileServiceClient("http://*****.azurewebsites.net/");
IMobileServiceTable SurveyTable = client.GetTable("Survey");
var table = client.GetSyncTable<MainActivity>();
txtEnter.Text = txtShow.Text;
string txt;
txt = txtShow.Text;
var item = new MainActivity
{
Questions = txtShow.Text,
};
Questions = txt;
try
{
////the problem occur over here and goes to catch
JObject jo = new JObject();
jo.Add("id", "myemail#emaildomain.com");
jo.Add("Questions", "Hello World");
// jo.Add("Complete", false);
//// It does't come so far
var inserted = await table.InsertAsync(jo);
// var inserted = await table.InsertAsync(Questions);
}
catch (Exception e)
{
CreateAndShowDialog(e, "Amk Necosu");
}
}
private void CreateAndShowDialog(Exception exception, String title)
{
CreateAndShowDialog(exception.Message, title);
}
private void CreateAndShowDialog(string message, string title)
{
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.SetMessage(message);
builder.SetTitle(title);
builder.Create().Show();
}
}
}
Backend Part is here
Controller.cs
using System.Linq;
using System.Threading.Tasks;
using System.Web.Http;
using System.Web.Http.Controllers;
using System.Web.Http.OData;
using Microsoft.Azure.Mobile.Server;
using TrendDemoService.DataObjects;
using TrendDemoService.Models;
using Microsoft.Azure.Mobile.Server.Config;
namespace TrendDemoService.Controllers
{
[MobileAppController]
public class Controller : TableController<MyFirstDbTableModel>
{
protected override void Initialize(HttpControllerContext controllerContext)
{
base.Initialize(controllerContext);
Context context = new Context();
DomainManager = new EntityDomainManager<MyFirstDbTableModel>(context, Request);
}
// GET tables/TodoItem
public IQueryable<MyFirstDbTableModel> GetAllMyFirstDbTableModels()
{
return Query();
}
// GET tables/TodoItem/48D68C86-6EA6-4C25-AA33-223FC9A27959
public SingleResult<MyFirstDbTableModel> GetMyFirstDbTableModel(string id)
{
return Lookup(id);
}
// PATCH tables/TodoItem/48D68C86-6EA6-4C25-AA33-223FC9A27959
public Task<MyFirstDbTableModel> PatchMyFirstDbTableModel(string id, Delta<MyFirstDbTableModel> patch)
{
return UpdateAsync(id, patch);
}
// POST tables/TodoItem
public async Task<IHttpActionResult> PostMyFirstDbTableModel(MyFirstDbTableModel item)
{
MyFirstDbTableModel current = await InsertAsync(item);
return CreatedAtRoute("Tables", new { id = current.Id }, current);
}
// DELETE tables/TodoItem/48D68C86-6EA6-4C25-AA33-223FC9A27959
public Task DeleteTodoItem(string id)
{
return DeleteAsync(id);
}
}
}
Context.cs
using System.Data.Entity;
using System.Data.Entity.ModelConfiguration.Conventions;
using System.Linq;
using Microsoft.Azure.Mobile.Server;
using Microsoft.Azure.Mobile.Server.Tables;
using TrendDemoService.DataObjects;
namespace TrendDemoService.Models
{
public class Context : DbContext
{
// You can add custom code to this file. Changes will not be overwritten.
//
// If you want Entity Framework to alter your database
// automatically whenever you change your model schema, please use data migrations.
// For more information refer to the documentation:
// http://msdn.microsoft.com/en-us/data/jj591621.aspx
private const string connectionStringName = "Name=MS_TableConnectionString";
public Context() : base(connectionStringName)
{
}
public DbSet<MyFirstDbTableModel> MyFirstDbTableModel { get; set; }
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
modelBuilder.Conventions.Add(
new AttributeToColumnAnnotationConvention<TableColumnAttribute, string>(
"ServiceTableColumn", (property, attributes) => attributes.Single().ColumnType.ToString()));
}
}
}
MyFirstDbTableModel
using Microsoft.Azure.Mobile.Server;
namespace TrendDemoService.DataObjects
{
public class MyFirstDbTableModel : EntityData
{
public string Questions { get; set; }
public bool Complete { get; set; }
}
}
AFTER EDIT
Startup.MobileApp
Backend Part
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data.Entity;
using System.Web.Http;
using Microsoft.Azure.Mobile.Server;
using Microsoft.Azure.Mobile.Server.Authentication;
using Microsoft.Azure.Mobile.Server.Config;
using TrendDemoService.DataObjects;
using TrendDemoService.Models;
using Owin;
namespace TrendDemoService
{
public partial class Startup
{
public static void ConfigureMobileApp(IAppBuilder app)
{
HttpConfiguration config = new HttpConfiguration();
//For more information on Web API tracing, see http://go.microsoft.com/fwlink/?LinkId=620686
config.EnableSystemDiagnosticsTracing();
new MobileAppConfiguration()
.UseDefaultConfiguration()
.ApplyTo(config);
// Use Entity Framework Code First to create database tables based on your DbContext
Database.SetInitializer(new TrendDemoInitializer());
// To prevent Entity Framework from modifying your database schema, use a null database initializer
// Database.SetInitializer<TrendDemoContext>(null);
MobileAppSettingsDictionary settings = config.GetMobileAppSettingsProvider().GetMobileAppSettings();
if (string.IsNullOrEmpty(settings.HostName))
{
// This middleware is intended to be used locally for debugging. By default, HostName will
// only have a value when running in an App Service application.
app.UseAppServiceAuthentication(new AppServiceAuthenticationOptions
{
SigningKey = ConfigurationManager.AppSettings["SigningKey"],
ValidAudiences = new[] { ConfigurationManager.AppSettings["ValidAudience"] },
ValidIssuers = new[] { ConfigurationManager.AppSettings["ValidIssuer"] },
TokenHandler = config.GetAppServiceTokenHandler()
});
}
app.UseWebApi(config);
}
}
public class TrendDemoInitializer : CreateDatabaseIfNotExists<Context>
{
protected override void Seed(Context context)
{
List<MyFirstDbTableModel> todoItems = new List<MyFirstDbTableModel>
{
new MyFirstDbTableModel { Id = Guid.NewGuid().ToString(), Questions = "First item", Complete = false },
new MyFirstDbTableModel { Id = Guid.NewGuid().ToString(), Questions = "Second item", Complete = false },
};
foreach (MyFirstDbTableModel todoItem in todoItems)
{
context.Set<MyFirstDbTableModel>().Add(todoItem);
}
base.Seed(context);
}
}
}
Frontend
MainActivity
using Android.App;
using Android.Widget;
using Android.OS;
using Microsoft.WindowsAzure.MobileServices;
using Android.Views;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System;
using System.Runtime.Serialization;
namespace App4
{
[Activity(Label = "App4", MainLauncher = true, Icon = "#drawable/icon")]
public class MainActivity : Activity
{
public TextView txtShow;
public EditText txtEnter;
public Button btnSave;
protected override void OnCreate(Bundle bundle)
{
base.OnCreate(bundle);
SetContentView(Resource.Layout.Main);
Button btnSave = FindViewById<Button>(Resource.Id.btnSave);
TextView txtShow = FindViewById<TextView>(Resource.Id.txtSoru);
EditText txtEnter = FindViewById<EditText>(Resource.Id.txtSoruGir);
Microsoft.WindowsAzure.MobileServices.CurrentPlatform.Init();
SQLitePCL.Batteries.Init();
// IMobileServiceTable<MainActivity> SurveyTable = client.GetTable<MainActivity>();
// Initialization for Azure Mobile Apps
Microsoft.WindowsAzure.MobileServices.CurrentPlatform.Init();
// This MobileServiceClient has been configured to communicate with the Azure Mobile App and
// Azure Gateway using the application url. You're all set to start working with your Mobile App!
Microsoft.WindowsAzure.MobileServices.MobileServiceClient TrendDemoClient = new Microsoft.WindowsAzure.MobileServices.MobileServiceClient(
"http://******.azurewebsites.net");
// Set our view from the "main" layout resource
// SetContentView (Resource.Layout.Main);
}
);
[Java.Interop.Export()]
public async void AddItem(View view)
{
var client = new MobileServiceClient("http://xx.azurewebsites.net/");
// IMobileServiceTable SurveyTable = client.GetTable("Survey");
var table = client.GetSyncTable<MyFirstDbTableModel>();
var myFirstModelInstance = new MyFirstDbTableModel();
myFirstModelInstance.Id = Guid.NewGuid().ToString();
myFirstModelInstance.Questions = "Could I help you with this answer?";
myFirstModelInstance.Complete = false;
try
{
await table.InsertAsync(myFirstModelInstance);
}
catch (Exception e)
{
CreateAndShowDialog(e, "Error");
}
}
private void CreateAndShowDialog(Exception exception, String title)
{
CreateAndShowDialog(exception.Message, title);
}
private void CreateAndShowDialog(string message, string title)
{
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.SetMessage(message);
builder.SetTitle(title);
builder.Create().Show();
}
}
}
MyFirstDbTableModel Class
using Newtonsoft.Json;
namespace App4
{
public class MyFirstDbTableModel
{
// string id;
public string Id { get; set; }
public string Questions { get; set; }
public bool Complete { get; set; }
}
}
The Error Message has changed.
Error
-Synccontext is not yet initialized
Output (when I press the Button )
06-28 14:20:48.971 D/ViewRootImpl#16dc384[MainActivity]( 4390): ViewPostImeInputStage processPointer 0
06-28 14:20:49.025 D/ViewRootImpl#16dc384[MainActivity]( 4390): ViewPostImeInputStage processPointer 1
06-28 14:20:49.075 D/ViewRootImpl#5067e47[MainActivity]( 4390): ThreadedRenderer.create() translucent=true
06-28 14:20:49.079 D/InputTransport( 4390): Input channel constructed: fd=74
06-28 14:20:49.079 D/ViewRootImpl#5067e47[MainActivity]( 4390): setView = DecorView#279674[MainActivity] touchMode=true
06-28 14:20:49.081 D/ViewRootImpl#5067e47[MainActivity]( 4390): dispatchAttachedToWindow
06-28 14:20:49.093 D/ViewRootImpl#5067e47[MainActivity]( 4390): Relayout returned: oldFrame=[0,0][0,0] newFrame=[36,1062][1404,1593] result=0x27 surface={isValid=true 504091385344} surfaceGenerationChanged=true
06-28 14:20:49.094 D/ViewRootImpl#5067e47[MainActivity]( 4390): mHardwareRenderer.initialize() mSurface={isValid=true 504091385344} hwInitialized=true
06-28 14:20:49.099 D/mali_winsys( 4390): EGLint new_window_surface(egl_winsys_display*, void*, EGLSurface, EGLConfig, egl_winsys_surface**, egl_color_buffer_format*, EGLBoolean) returns 0x3000, [1624x787]-format:1
06-28 14:20:49.099 D/ScrollView( 4390): onsize change changed
06-28 14:20:49.110 D/ViewRootImpl#5067e47[MainActivity]( 4390): MSG_WINDOW_FOCUS_CHANGED 1
06-28 14:20:49.110 D/ViewRootImpl#5067e47[MainActivity]( 4390): mHardwareRenderer.initializeIfNeeded()#2 mSurface={isValid=true 504091385344}
06-28 14:20:49.124 D/ViewRootImpl#5067e47[MainActivity]( 4390): MSG_RESIZED_REPORT: ci=Rect(0, 0 - 0, 0) vi=Rect(0, 0 - 0, 0) or=1
06-28 14:20:49.141 D/ViewRootImpl#16dc384[MainActivity]( 4390): MSG_WINDOW_FOCUS_CHANGED 0
06-28 14:20:49.142 D/SEM_CLIP_SemClipboardManager( 4390): isCocktailBarDisplayed : false
You use your MainActivity as database model. You shouldn't do that.
What you should do:
Create a database table model:
public class MyFirstDbTableModel
{
// string id;
public string Id { get; set; }
public string Questions { get; set; }
public bool Complete { get; set; }
}
Get the table like this:
var table = client.GetTable<MyFirstDbTableModel>();
Create an instance of your database table model and add values:
var myFirstModelInstance = new MyFirstDbTableModel();
myFirstModelInstance.Id = Guid.NewGuid().ToString();
myFirstModelInstance.Questions = "Could I help you with this answer?";
myFirstModelInstance.Complete = false;
Put the instance to the database in Azure:
var inserted = await table.InsertAsync(myFirstModelInstance);
Notice: It is necessary, that you have created the database table from the backend or directly in the database. You can use the "MyFirstDbTableModel" model directly in the backend, but it must inherit from
public class MyFirstDbTableModel : EntityData {...}
and you have to do some more stuff, like to create a controller, which is described in the Azure documentation or you can see it in the Azure Mobile Apps Quickstart example.
Update based on the edit of the question:
You should change the class name from "Controller" to "MyFirstDbTableModelController". The name of the controller is reflected in the request link.
You should connect to your database with SSMS (SQL Server Management Studio). With this program you can see, whether the table is already created. Note: The table will only created, after you has send a request to the backend.
You don't use attributes in your model, with this, I have removed the attributes in step 3.
Have you changed the Initializer in the Startup.MobileApp.cs?
If you use the code in my answer, it should work with the changes from my update.
If you getting an exception, please post the stacktrace. Additionally you can debug the backend, as well, to get an stacktrace.
Notice: If you change the model, for example the MyFirstDbTableModel, the database will not create the table again. You have to drop all tables in the db.
This part is wrong:
[JsonProperty(PropertyName = "id")]
public string Id
{
get { return Id; }
set { Id = value; }
}
You are returning Id which in turns return Id, so it is a recursive call. It can't work.
I also agree with Sean that this isn't the best practice to add the data to Azure.
I have an app setup and I have been testing it with Android pretty successfully but now I am trying to add in iOS and it doesn't seem to work at all.
I have a MasterDetailPage that I mostly copied from the mobileCRM project which works fine for me on Adroid and my buildhost but not in my ported over version.
public class RootPage : MasterDetailPage
{
OptionItem _previousItem;
public RootPage()
{
var optionsPage = new MenuPage { Icon = "Icon.png", Title = "menu" };
optionsPage.Menu.ItemSelected += (sender, e) => NavigateTo(e.SelectedItem as OptionItem);
Master = optionsPage;
NavigateTo(optionsPage.Menu.ItemsSource.Cast<OptionItem>().First());
}
void NavigateTo(OptionItem option)
{
if (_previousItem != null)
_previousItem.Selected = false;
option.Selected = true;
_previousItem = option;
var displayPage = PageForOption(option);
Detail = new NavigationPage(displayPage)
{
BarBackgroundColor = Helpers.Color.Orange.ToFormsColor()
};
Detail.SetValue(TitleProperty, option.Title);
Detail.SetValue(IconProperty, option.Icon);
IsPresented = false;
}
static Page PageForOption(OptionItem option)
{
switch (option.Title)
{
case "Home":
return new HomePage();
case "Circles":
return new CirclesPage();
case "Settings":
return new SettingsPage ();
default:
throw new NotImplementedException("Unknown menu option: " + option.Title);
}
}
}
This looks like a bug in Xamarin.Forms, and I've reported it.
I was able to reproduce your issue, but also able to workaround it by replacing the ListView in OptionPage by a StackLayout of Buttons :
public MenuPage (MasterDetailPage mdpage)
{
Content = new StackLayout {
Children = {
new Button { Text = "Home", Command = new Command (() => {mdpage.Detail = new HomePage ();mdpage.IsPresented = false;}) },
new Button { Text = "Circles", Command = new Command (() => {mdpage.Detail = new CirclesPage ();mdpage.IsPresented = false;}) },
new Button { Text = "Settings", Command = new Command (() => {mdpage.Detail = new SettingsPage ();mdpage.IsPresented = false;}) },
}
};
}
In one of my projects, I'm using a TableView in the Master, but just like the ListView here, it triggers the issue.
I have a doubt
I created an application that takes pictures, sends it to a database and then print on some page.
When I go to put the application to function, the camera appears correctly. But it only on the desktop. When I turn the fla in an apk and try running on android, facing the camera appears in the horizontal.
How can I solve this problem?
The code is here:
import com.adobe.images.JPEGEncoder;
var video:Video;
var camera:Camera;
var imgBA:ByteArray;
var imgBD:BitmapData;
var imgBitmap:Bitmap;
var phpPath:String;
var jpgEncoder:JPEGEncoder;
var sendHeader:URLRequestHeader;
var sendReq:URLRequest;
var sendLoader:URLLoader;
var imagePath:String;
setupCamera(430,500);
var inicializado:Boolean=false;
status_txt.text="esperando coordenadas";
var geolocationmarcelinho:MarcelinhoGeolocation=new MarcelinhoGeolocation(geoUpdate);
function geoUpdate(lat:Number,lon:Number)
{
if(inicializado)
{
lat_txt.text=lat+"";
lon_txt.text=lon+"";
}
else
{
setupApplication();
lat_txt.text=lat+"";
lon_txt.text=lon+"";
if(lat==-1)
{
status_txt.text="sem geolocation";
}
else
{
status_txt.text="pode usar!";
}
inicializado=true;
}
}
//setupApplication();
function setupCamera(w:int,h:int):void {
try {
camera = Camera.getCamera();
} catch(e:Error) {
status_txt.text="camera não conectada!";
trace("No Camera detected!");
}
camera.addEventListener(StatusEvent.STATUS, camStatusHandler);
camera.setMode(w,h,stage.frameRate);
video = new Video(w,h);
video.attachCamera(camera);
addChild(video);
}
function camStatusHandler(event:StatusEvent):void {
// Camera.Muted or Camera.Unmuted -> User's security
trace(event.code);
}
function setupApplication():void {
shotBtn.addEventListener(MouseEvent.CLICK, createSnapshot);
removeBtn.addEventListener(MouseEvent.CLICK, removeSnapshot);
sendBtn.addEventListener(MouseEvent.CLICK, sendImage);
jpgEncoder = new JPEGEncoder(90);
}
function createSnapshot(event:MouseEvent):void {
imgBD = new BitmapData(video.width,video.height);
imgBD.draw(video);
imgBitmap = new Bitmap(imgBD);
addChild(imgBitmap);
shotBtn.removeEventListener(MouseEvent.CLICK, createSnapshot);
}
function removeSnapshot(event:MouseEvent):void {
removeChild(imgBitmap);
comentario_txt.text="";
status_txt.text="pode usar!";
shotBtn.addEventListener(MouseEvent.CLICK, createSnapshot);
}
function sendImage(event:MouseEvent):void {
phpPath = "http://celoweb.com.br/app/img_aplicativo/upload.php?comentario=qualquercoisa&latitude=34&longitude=-45"
+comentario_txt.text+"&latitude="+lat_txt.text+"&longitude="+lon_txt.text;
sendHeader = new URLRequestHeader("Content-type","application/octet-stream");
sendReq = new URLRequest(phpPath);
sendReq.requestHeaders.push(sendHeader);
sendReq.method = URLRequestMethod.POST;
sendLoader = new URLLoader();
sendLoader.addEventListener(Event.COMPLETE,imageSentHandler);
imgBA = jpgEncoder.encode(imgBD);
sendReq.data = imgBA;
sendLoader.load(sendReq);
}
function imageSentHandler(event:Event):void {
var dataStr:String = event.currentTarget.data.toString();
var resultVars:URLVariables = new URLVariables();
resultVars.decode(dataStr);
imagePath = "http://" + resultVars.base + "/" + resultVars.filename;
status_txt.text="Uploaded to: " + imagePath;
trace("Uploaded to: " + imagePath);
sendLoader.removeEventListener(Event.COMPLETE,imageSentHandler);
}
Agreed your question is a little unclear but at a guess...
To rotate your image you would use: imgBitmap.rotation = 90;
or to flip:
imgBitmap.scaleX = -1;