How do I implemement MVVMCross in a "Blank Android App"
Is it possible to do this without a Portable Class Library (PCL)?
Do I have to create an App.cs class (The project doesn't come with one included) and is that even possible?
If I do have to then how do I do it?
A good example for startes is the TipCalc-Tutorial which you will find on the official github page (https://github.com/MvvmCross/MvvmCross/wiki), just be careful since most tutorials are for 4.0 so there might some changes. As a example:
When asked to choose platforms, select .NET Framework 4.5, Windows 8,
Windows Phone Silverlight 8, Windows Phone 8.1, Xamarin.Android and
Xamarin.iOS - this will ensure that the PCL is in Profile259.
Is outdated since Silverlight isnt supported anymore from MVVMCross 4.2.2 onwards. So you should use Profile 7 as a Example. More informations for PCL Profiles here: http://danrigby.com/2014/05/14/supported-pcl-profiles-xamarin-for-visual-studio-2/
But yeah you basically should have a Portable Class Library, even if it would work without it. It just gives many advantages without requiring much effort.
And you dont need a "App.cs", but you need a class which inherits from MvxApplication. So it might be easier to stick with that name, since everyone knows then what it is for.
But just check out the tutorials first, everything in there should be explained.
After doing some research I found that you can create an App.cs file (ie a class that extends the Android.App.Application class) in a 'Blank Android App' and hence don't need a PCL to use MVVMCross.
You must ensure that you have an implementation of the public App(IntPtr javaReference, JniHandleOwnership transfer) constructor and some people state that you also need to override the OnCreate method (as i have done).
Also make sure that in your AssemblyInfo.cs file you DONT have a any [Application] lines ie. None of this: [assembly: Application(Debuggable = true)]
See code below.
using Android.App;
using Android.Runtime;
using System;
namespace YOUR.NAMESPACE
{
#if DEBUG
[Application(Debuggable = true)]
#else
[Application(Debuggable = false)]
#endif
public class App : Application
{
public App(IntPtr javaReference, JniHandleOwnership transfer) : base(javaReference, transfer)
{
//Do MVVMCross setup Here
//Mvx.RegisterType<ICalculation,Calculation>();
//Mvx.RegisterSingleton<IMvxAppStart>(new MvxAppStart<TipViewModel>());
}
public override void OnCreate()
{
base.OnCreate();
}
}
}
Related
I want to implement a custom entry in xamarin, followed some youtube tutorials step by step and it works on them but mine crashes when launching it via a live player.
Here is the code in the shared project
using Xamarin.Forms;
namespace QuickTest.CustomControls
{
public class PlainEntry : Entry
{
}
}
And here is the android specific version
using Android.Content;
using QuickTest.CustomControls;
using QuickTest.Droid.CustomAndroidControls;
using Xamarin.Forms;
using Xamarin.Forms.Platform.Android;
[assembly: ExportRenderer(typeof(PlainEntry), typeof(PlainEntryAndroid))]
namespace QuickTest.Droid.CustomAndroidControls
{
public class PlainEntryAndroid : EntryRenderer
{
public PlainEntryAndroid() : base(null) { }
public PlainEntryAndroid(Context context) : base(context) { }
}
}
Its a basic implementation i commented out the OnElementChanged function just so i could get it to run first, is there something am doing wrong, any help would be highly appreciated because i have already wasted enough time on this, thanks.
Btw I have also tried it without either of the constructors and it failed.
Xamarin crashes on Android when creating custom renderer. it didn't give out any error, just xamarin player was crashing
Please refer to the documentation: Limitations of Xamarin Live Player
For Xamarin.Forms:
Custom Renderers are not supported.
Effects are not supported.
Custom Controls with Custom Bindable Properties are not supported.
Embedded resources are not supported (ie. embedding images or other resources in a PCL).
Third party MVVM frameworks are not supported (ie. Prism, Mvvm Cross, Mvvm Light, etc.).
That's why the issue happened. So, it is suggested that deploy your project to an android emulator or a real device.
I'm currently building a weather app using the forecast.io api.
They provide custom font for Forecast.io, as well as for other apis such as Yahoo. I'm not sure about how to proceed to use their API mapping.
For instance, I receive "partly-cloudy-night" and this should render the icon.
I would welcome advices or clues on how to proceed.
Thanks a lot,
You have to use the ttf file il your android project, and convert the css to xml string ressource.
I did it for Web Hosting hub glyph (a bit like font awesome but many more icons).
See https://github.com/neoteknic/whhg-to-android
I can reuse my convertion script an make a repo with these icons.
Edit :
This is for you :
https://github.com/neoteknic/weather-icons-to-android
To use it (I prefer load only once the typeface and make it available globally) :
public class YourAppName extends Application {
public static Typeface weatherIcons;
#Override
public void onCreate(){
YourAppName.weatherIcons= Typeface.createFromAsset(getApplicationContext().getResources().getAssets(), "fonts/weathericons-regular-webfont.ttf");
super.onCreate();
}
}
Then when you wanna use it :
TextView myicon=(TextView) findViewById(R.id.myicon);
myicon.setTypeface(YourAppName.weatherIcons);
myicon.setText(R.string.wi_day_snow_wind);
I am trying to render a checkbox in a Xamarin Forms app. There is nothing rendered at runtime, as far as I can tell the renderer is not even getting called.
Does anyone understand what I am missing or doing incorrectly?
Here is my class in Forms:
public class LegalCheckbox : View
{
public LegalCheckbox ()
{
}
}
And my custom renderer class in Droid:
public class CheckBoxRenderer : ViewRenderer<LegalCheckbox, CheckBox>
{
protected override void OnElementChanged (ElementChangedEventArgs<LegalCheckbox> e)
{
base.OnElementChanged (e);
CheckBox control = new Android.Widget.CheckBox(this.Context);
control.Checked = false;
control.Text = "I agree to terms";
control.SetTextColor (Android.Graphics.Color.Rgb (60, 60, 60));
this.SetNativeControl(control);
}
}
Along with the Assembly Directive:
[assembly: ExportRenderer(typeof(demo.LegalCheckbox), typeof(demo.Droid.CheckBoxRenderer))]
Took your code and fired up a new project with it. The code appears to function fine.
Only thin I can think that might be causing you an issue is the location of you assembly attribute. I typically place them just above the namespace declaration in the same file as my renderer.
I threw what I created up on my github maybe you can spot the difference.
https://github.com/DavidStrickland0/Xamarin-Forms-Samples/tree/master/RendererDemo
#Thibault D.
Xlabs isn't a bad project but its basically just all the code the opensource community came up with during the first year or so of Xamarin.Forms life. Its not really "Their Labs projects" and considering how much of it is marked up with Alpha Beta and the number of bugs in their issues page it's probably best not to imply that the Xamarin company has anything to do with it.
I am not sure if that is the issue but it would make more sense to me if your LegalCheckbox would inherit from a InputView rather than View.
Also, even if Xamarin.Forms does not have a Checkbox control you can still have a look at their "Labs" project here:
https://github.com/XLabs/Xamarin-Forms-Labs/wiki/Checkbox-Control
(And I can actually see that they inherit from View...)
We have heard about the possibility to develop in C# on iOS and Android platforms using MonoTouch and Mono for Android
http://xamarin.com/monoforandroid
I have an iOS MonoTouch application that I would like to convert into a Mono for Android version.
How would a simple example, like the piece of code below, translate into Mono for Android?
using System;
using System.Collections.Generic;
using System.Linq;
using MonoTouch.Foundation;
using MonoTouch.UIKit;
namespace HelloWorld_iPhone
{
public class Application
{
static void Main (string[] args)
{
UIApplication.Main (args, null, "AppDelegate");
}
}
}
There is no use of a static void Main() method in Mono for Android. You basically have a "Main" activity that starts your app.
Here is an example of this:
[Activity (Label="My App", MainLauncher=true)]
public class MyActivity : Activity
{
}
This then generates the appropriate Android manifest file to launch the app. See here.
I would just use File->New Project->Mono for Android App and use what the template generates.
I saw a demo of simulateKeyInput,
some codes as following:
final IWindowManager windowManager=IWindowManager.Stub.
asInterface(ServiceManager.getService("window"));
But I can't find ServiceManager in package android.os,
maybe it's not in android SDK, does anyone know where it is?
Looks like a custom implementation of ServiceManager within your project or your projects included .jar files.
Else there is a ServiceManager in javax.jnlp => (Java Network Launching Protocol).. not sure if this is related to you & Android.
android.os.ServiceManager in frameworks/base/core/java/