Custom plugin in MVVMCross - mvvmcross

I'm working on MVVMCross v3 and I want to create my own plugin, I followed this tutorial (which is for the vNext)
http://slodge.blogspot.fr/2012/10/build-new-plugin-for-mvvmcrosss.html
To be compatible for the v3 I changed IMvxServiceConsumer and GetService to Mvx.Resolve.
But on the tutorial there are :
Then, for WinRT, WindowsPhone and MonoTouch clients, you also need to provide a Loader accessor in setup.cs - like:
protected override void AddPluginsLoaders(Cirrious.MvvmCross.Platform.MvxLoaderPluginRegistry loaders)
{
loaders.AddConventionalPlugin<MyCompany.MvvmCross.Plugins.Mega.WindowsPhone.Plugin>();
base.AddPluginsLoaders(loaders);
}
How can I do that in v3?
Thanks

If you want to write a new plugin, then :
the up-to-date sample is https://github.com/slodge/MvvmCross-Tutorials/tree/master/GoodVibrations
there are some notes on this sample in https://speakerdeck.com/cirrious/plugins-in-mvvmcross
For plugin initialisation, the nuget packages now do this via bootstrap files - e.g. see the files added for Location at:
(WinRT, WinPhone, Droid) - https://github.com/slodge/NPlus1DaysOfMvvmCross/blob/master/N-08-Location/Location.Droid/Bootstrap/LocationPluginBootstrap.cs
(Touch) - https://github.com/slodge/NPlus1DaysOfMvvmCross/blob/master/N-08-Location/Location.Touch/Bootstrap/LocationPluginBootstrap.cs
The bootstrap way is the normal way to do initialisation now.
If you did want to use a non-bootstrap technique then you can do this:
In WinRT, WinPhone, and Droid, you don't need to use a loader, but you do need to call MyPlugin.PluginManager.Instance.EnsureLoaded before the plugin can be used.
In Touch, you would need to provide a loader during protected override void AddPluginsLoaders(MvxLoaderPluginRegistry loaders) - and you'd then still need to call EnsureLoaded() before the plugin can be used.
For examples of this 'old way' of working, see Setup.cs in the UI projects in https://github.com/slodge/MvvmCross-Tutorials/tree/master/Sample%20-%20TwitterSearch

Related

Adding API's to chromium build in Electron framework

I would like to write custom functions in Window API in chromium source code. So how do we do it?
In case of doubts about window API here's a link to what I mean click here. I would like to have custom property functions analogus to those shown in the link.
It's for a github electron project.
Well after a week of searching I finally found the solution. Thanks to a pull request by magicae#github.
You need to look create your custom function in
electron/atom/browser/api/lib/atom_api_web_contents.cc
as say
bool WebContents::GetOkOk() {
return true;
}
And define the same in it'h header file
electron/atom/browser/api/lib/atom_api_web_contents.h
as
bool GetOkOk();
Lastly you need to export the function through the webContents method located in
electron/atom/renderer/lib/web-view/web-view.js
as
/* Public-facing API methods. - modified by Akshay Thakare */
methods = ['getOk','getURL', ... ];
And you are good to go.
Finally after you compile your electron app,
in the main.js file add,
console.log(mainWindow.webContents.getOk());
and your done.
As JS is prototype oriented, you could simply extend the BrowserWindow API
var BrowserWindow = require('electron').BrowserWindow; // main process
var BrowserWindow = require('electron').remote.BrowserWindow; // renderer process
BrowserWindow.foo = function() {
console.log('foo');
}
Not sure if you're looking for someting more specific, but I'm not sure you can extend it with heavy impacts on the system, could you explain exactly what you are trying to do ?

mvvmcross Custom binding supressed by Linking optimisation to device

In the Touch version of my app, I've defined a custom binding for the 'selected' property on a UIButton and use that to mimic the ToggleButton behaviour which is available in Android (to have the same UX in both platforms). This additional binding works perfectly fine in the simulator, but not when deploying to device. I've figured out already that this is again the famous linking optimisation problem as the binding does work when I change the Linker behaviour to 'don't link'.
Question, what do I need to include in the LinkerPleaseInclude to preserve my custom binding when deploying to device ? The UIButton in included there but only using the TouchUpInside event which therefore works fine on device - just my custom binding doesn't.
Thx
It's pretty simple. Without any code example I can only suggest you search for UIButton in the LinkerPleaseInclude file and make sure you have something like:
var button = new UIButton();
button.Select += (s,a) => {}
Just need to reference the event so the compiler knows about it...

Creating custom visibility converter

I'm trying to create a custom converter for my MvvmCross project. I'm inheriting from MvxBaseVisibilityValueConverter and just implementing the Convert method.
Do I need to implement platform specific projects as well or is there a way to reuse the platform specific visibility plugins?
I've been documenting ValueConverters in the last few days - see https://github.com/slodge/MvvmCross/wiki/Value-Converters
I've just added this example custom visibility ValueConverter to the article:
If you need to create your own Visibility ValueConverter's then the MvxBaseVisibilityValueConverter<T> and MvxBaseVisibilityValueConverter base classes can assist with this - e.g.:
public class SayPleaseVisibilityValueConverter : MvxBaseVisibilityValueConverter<string>
{
protected override MvxVisibility Convert(string value, object parameter, CultureInfo culture)
{
return (value == "Please) ? MvxVisibility.Visible : MvxVisibility.Collapsed;
}
}
Using this approach, then the plugin base class will convert the MvxVisibility to a suitable native value at runtime - so you only need to add this type of class to your core PCL project - you don't need to add native versions of the class - instead the base class from the plugin will take care of the MvxVisibility -> native Visibility conversion.
Aside> in addition to the Visibility enum support from the Plugin, recent 'Tibet' binding changes have also added custom Visible binding properties to all platforms - these are just bools so much easier to use - they should 'just work' on iOS and Android, but on Windows platforms they will only work if you switch to the "Tibet' mvx:Bi.nd style of binding (so not everyone's preferred approach!)

ChartboostX not loading more apps

I am using this wrapper someone recommended for my iOS cocos2dx game link. It works when I call the showInterstitial() method, but when I try to use the showMoreApps the dialog appears for a split second and then disappears.
In my AppDelegate::applicationDidFinishLaunching() I do this
ChartboostX::sharedChartboostX()->setAppId("REDACTED");
ChartboostX::sharedChartboostX()->setAppSignature("REDACTED");
ChartboostX::sharedChartboostX()->startSession();
ChartboostX::sharedChartboostX()->cacheMoreApps();
And then when I want to call the showMoreApps I do this
ChartboostX::sharedChartboostX()->showMoreApps();
Have a look at my wrapper for Chartboost. It has been updated to use the latest version of the Chartboost SDK and works perfectly in my cocos2D-x game. I have not finished the android documentation yet but you can probably work it out yourself if you need to. The documentation for iOS is almost finished and quite easy to follow.(FYI the class ADELLE is the chartboost delegate and is an objective C++ class so you can use C++ in it as you normally would mixed in with the objective C. This is the same for AdWrapper.mm)
Check it out and see if it works for you.
https://github.com/Lochlanna/Chartboost-Cocos2D-x

StageWebView Lack on URLs with target="_blank"

is there any solution on StageWebView.loadURL(), how I can handle URLs in HTML Pages which have target="_blank"?
It's a mobile Android App. (TabbedViewApplication)
Hope someone can help.
Thx
One option is StageWebViewBridge.
StageWebViewBridge is an extended version of flash.media.StageWebView.
Extends loadString method with AS3 - JS communication.
-Extends Bitmap class, you can modify his x,y,alpha,rotation,visible, etc ( Version 1 Beta )
-Communicates Actionscript with Javascript.
-Communicates Javascript with Actionscript.
-Load local files and resources in a easy way.
-Extends loadString method with AS3 - JS communication.
-Extends loadString method to load local resources.
-Lets you take an SnapShot to use as the bitmapData of the bitmap.
StageWebViewBridge source: https://code.google.com/p/stagewebviewbridge/
I never worked with the StageWebView but I know it's really limited. When using an HTMLLoader, you can set a custom HTMLHost instance that specifies to use current HTMLLoader when opening to _blank. However, I don't think it's possible with StageWebView.
public class MyHTMLHost extends HTMLHost
{
public function MyHTMLHost(defaultBehaviors:Boolean=false)
{
super(defaultBehaviors);
}
override public function createWindow(windowCreateOptions:HTMLWindowCreateOptions):HTMLLoader
{
// all JS calls and HREFs to open a new window should use the existing window
return htmlLoader;
}
}
OK, so the only solution for this problem i could found is to load the page (containing the links) as String with the URLLoader and replace its specified parts. Finally loading it via StageWebView.loadString() method.
Problems occur when the Site is dynamic and contains JavaScript. I had also replace some relative links with absolute pathes.
That's it... but I really hope that adobe makes it possible to load those "_blank" links with the StageWebView.loadURL() method.
If you want to capture when a user clicks on a link inside your StageWebView add an an event listener for location changing event (LocationChangeEvent).
This LocationChangeEvent will include the URL they are going to and target. Then you can prevent the URL from loading, let it continue (by doing nothing) or handle it any other way including loading another URL.
If you want to load another URL first stop the loading with stageWebView.stop(). You should also call event.preventDefault(). You can then attempt to
Note: There is another event called locationChange that may be helpful.
As it was declared as an official bug, adobe QA Owner Sanjay C. added a comment: "Able to reproduce the issue with the attached project. Sending to IRB."
So, hope the next Build will come up with the fix wit it.
Best regards