How do I load a custom Font in Xamarin using UrhoSharp? - xamarin.forms

I am trying to follow the example posted by Adam Pedley at
Introduction to UrhoSharp in Xamarin Forms but have run into a problem. In the following code block, he is loading a custom font:
private void CreateText()
{
// Create Text Element
var text = new Text()
{
Value = "Hello World!",
HorizontalAlignment = HorizontalAlignment.Center,
VerticalAlignment = VerticalAlignment.Center
};
text.SetColor(Color.Cyan);
text.SetFont(font: ResourceCache.GetFont("Fonts/Anonymous Pro.ttf"), size: 30);
// Add to UI Root
UI.Root.AddChild(text);
}
The problem I have is that I don't have this font, and it isn't included anywhere in any kind of Assets folder or anything in his GitHub repository of his demo project at adamped/UrhoSharp.Demo. In fact, in spite of the allusion to a "Fonts" folder in the function call, no Fonts folder exists in his demo solution in any of the projects.
Trying to run the application results in a mono runtime error " [ERROR] FATAL UNHANDLED EXCEPTION: System.Exception: Could not find resource...".
In addition, there doesn't seem to be any means of contacting the author to ask (which I find doubly frustrating), so I am having to ask the Stack Overflow community: Where and how do I place custom font assets in my solution (his solution) so that a custom font may be used?
I am currently able to use a custom font in a standard Label with the font file being located in the /Assets folder of both my Sample.Android and Sample.UWP projects, but no combination of path or file name I have tried in the call to GetFont(...) works.

After hours of searching, I finally came across a screen shot showing the proper setup for anyone else who may run into this issue;

Related

Provide WebView with Url to Asset

In my Uno UWP project, I can view an html Asset file (w/ Content BuildAction), stored in my shared project, using the following:
var myAssetUri = new Uri("ms-appx-web:///Assets/Html/index.html");
myWebView.Navigate(myAssetUri);
However, this does not work with Android or WASM (not yet tried on other platforms). On WASM, I get a blank page. On Android, I get a page with the message:
The webpage at ms-appx-web:///Assets/Html/index.html could not be loaded because:
net::ERR_UNKNOWN_URL_SCHEME
When I look at the package folders for both platforms, I do find my html file:
WASM: bin/Debug/netstardard2.0/dist/package_.../Assets/Html/index.html
Android: (unziping my app's apk) assets/Html/index.html
so, I am guessing I'm not doing something right ... but I don't know what that might be.
The cause is simple: WebView not implemented yet on Wasm nor Skia.
This is the solution after hours investing!!
For you proyect write this line:
var myAssetUri = new Uri("file:///android_asset/Assets/Assets/Html/index.html");
This work 100%

Alfresco Aikau debugging

In Alfresco Share the Search page is implemented with Aikau.
I'm interested in the more general question, is it possible to Debug Aikau widgets?
I have founds some links on this matter, but they talk more about logging and not actual javascript debugging:
http://docs.alfresco.com/5.1/tasks/dev-extensions-share-tutorials-debugging.html
https://github.com/Alfresco/Aikau/blob/master/tutorial/chapters/Tutorial4.md
Suppose I have the following Aikau widget alfresco/search/AlfSearchResult and the following method inside it:
/**
* This function is called to create a
* [SearchResultPropertyLink]{#link module:alfresco/renderers/SearchResultPropertyLink} widget
* to render the displayName of the result. It can be overridden to replace the default widget
* with a reconfigured version.
*
* #instance
*/
createDisplayNameRenderer: function alfresco_search_AlfSearchResult__createDisplayNameRenderer() {
// jshint nonew:false
var config = {
id: this.id + "_DISPLAY_NAME",
currentItem: this.currentItem,
pubSubScope: this.pubSubScope,
propertyToRender: "displayName",
renderSize: "large",
newTabOnMiddleOrCtrlClick: this.newTabOnMiddleOrCtrlClick,
defaultNavigationTarget: this.navigationTarget
};
if (this.navigationTarget)
{
config.navigationTarget = this.navigationTarget;
}
new SearchResultPropertyLink(config, this.nameNode);
}
Is there any way I could insert a breakpoint and stop execution at the line where this.currentItem is used in order for me to evaluate it's properties?
Yes, there are several ways in which you can debug Aikau... the first thing to do is to make sure that you're running with "client-debug" mode enabled (either in Share or in your custom Aikau client).
For example, in Share you'd want to update the /WEB-INF/classes/alfresco/share-config.xml file to change:
<config>
<flags>
<client-debug>false</client-debug>
...to be...
<config>
<flags>
<client-debug>true</client-debug>
You'll need to restart Share for the changes to take effect. You'll see then that you have a "Debug Menu" item in the main header menu bar. If you open this you can enable logging by toggling "Debug Logging" and "Show All Logs" to be true.
This will result in logging output appearing in your browser developer tools console. You can also fine tune the logging output to only show errors or warning and to provide a RegEx expression to match certain logging output.
With client debug enabled the JavaScript source being loaded by the browser will be uncompressed. This will make it easier for you to add break points.
Because Surf aggregates all of the required module source code into a single resource (for performance and caching reasons) you will want to find the Aikau source file - the easiest way to do this is to use "CTRL-P" (in Chrome) to open a resource and type "surf" into the box that appears - this will always find the Aikau source code first.
Firebug for Firefox handles finding across resources better, so you can just used "CTRL-F" and then paste in the line you want to break on.
You can add breakpoints in this resource as you normally would and the browser will break on them.
As well as setting break points you can also use the DebugLog widget. This can be toggled from the "Debug Menu" and shows all the publications and subscriptions that are being made.
It is also possible to directly include and configure the alfresco/services/LoggingService and the alfresco/logging/DebugLog widgets in your page as you are developing. We take this approach for all our unit test pages. This can be a handy approach during development and they can be removed when you're finished developing.
This presentation although quite old, also contains some useful debugging tips (see slide 56 onwards).

Orchard ResourceManifest.cs - Searching in wrong location

I have some problems with the ResourceManifest.cs of an Orchard custom module (let's call it 'testmodule'). In the manifest inside this testmodule I defined the following Style:
manifest.DefineStyle("Identifier123").SetUrl("dashboard.min.css");
that is located in the testmodule's Styles folder.
Now in the View (that is also located in the testmodule) I call:
Style.Require("Identifier123");
Unfortunately I get the following dashboard.min.css file added, instead of my file:
/Modules/Amba.ImagePowerTools/Styles/dashboard.min.css
When I rename my dashboard.min.css to dashboard2.min.css (and also in the manifest) it is working fine. Is this a normal behavior or some priority problem caused by Amba.ImagePowerTools? Can someone help me with this?

Phonegap: InAppBrowser insertCSS file

I'm trying to create an app that loads a website and then adds some custom CSS to adjust it to a mobile device.
I'm using window.open to load the page successfully, and I have a callback on loadstop where I'm calling browser.insertCSS, this is where the problem is.
If I do something like this:
browser.insertCSS({code:"body{background-color:red;}");
The style is applied correctly. However if I do this:
browser.insertCSS({file:"mobile-style.css");
And add the same CSS to the file, it doesn't get loaded
I have tried different paths (putting the file in the www folder, in the css folder, in the same folder as the JS file, and referencing it with "./mobile-style.css", "mobile-style.css", "/www/mobile-style.css", "/mobile-style.css" but none of them seem to load the file correctly.
I saw another post What should file paths fed to insertCSS() be relative to? where this same question was asked, but there is no accepted answer (I have tried the suggestion there and it doesn't work).
Any help would be greatly appreciated.
Thanks
Will
you have to wait until your inAppBrowser page loading finishes.
You must add an event listener:
var inApp = window.open('mypage.html', '_blank', 'location=no');
inApp.addEventListener('loadstop', function(){
inApp.insertCSS({
file: 'inAppStyle.css'
},onSuccess);
});
EDITED
Use this path for your android projects file:///android_asset/{your folder}
INFO: https://github.com/apache/cordova-plugin-file/blob/master/doc/index.md#android-file-system-layout
I couldn't find the right local path. Instead, I just uploaded the css file to the web and provided a regular URL
file: 'http://mywebsite.com/path-if-needed/my.css'
Not ideal to have an external dependency, but not a big deal since InAppBrowser itself requires internet access.
I probably know why it won't work, it is because your path isn't right, this css file should not put in www folder, neither the cordova project folder, u should put it into the server, for example, if ur browser is to visit http://192.168.1.1/admin, then the cordova only fetch this file when the browser is under the 192.168.1.1/admin, it fetch the file under the server directory.I don't know if u use any debug tool , if u use one, it's easy to find out what went wrong, ur console will log the error which path it fetch the css file and didn't get it.
If you want to add an external CSS file stored locally in the APP's sandbox and not around in the Internet, this is the only way, that is, you get the external file, you store it into a string variable, and then you insert such code into the Browser.
var inAppBrowserRef = cordova.InAppBrowser.open(url, "_blank", "location=no");
//when load stops call loadedCallbackFunction
inAppBrowserRef.addEventListener('loadstop', loadedCallbackFunction);
function loadedCallbackFunction() {
console.log("InAppBrowser Window loaded");
$.ajax({
type: "GET",
url: cordova.file.applicationDirectory + "www/css/myExternalCSS.css",
dataType: "text",
success: function (CSScode) {
inAppBrowserRef.insertCSS(
{ code: JScode},
function(){
console.log("CSS code Inserted Succesfully into inApp Browser Window");
});
},
error: function () {
console.error("Ajax Error");
}
});
}
You need the cordova-plugin-inappbrowser

After exporting a flex project, the images are broken

After completing building a flex project in Flash Builder 4.5, the project was exported using the
File -> Export Flash Builder Project.
After which some of the images stopped working (get the broken image icon). This has left me clueless and even search on the internet did not give me good answers...
I get the same problem time to time. Probably compiler / Flash Builder bug. But to be sure, you might want to check some basic things. First off: check that you have correct image urls. Secondly, ensure you are not using absolute source paths (e.g. C:\workspace\project\src\assets\images\image.png). Instead use relative path (i.e. assets\images\image.png).
If these are correct, check your build directory (default build directory for release builds in FB is bin-release) and see if the images are compiled there correctly. As I said, for some reason my FB does not always compile all the assets correctly, so sometimes I have to move them in manually. That is, you can simply drag and drop them from the source directory to the bin-release directory (although if you are using svn, you should be careful with this as it might copy also the svn metadata).
Other solutions you might want to try:
restart eclipse / FB (maybe it's simply out of memory)
delete the project from your workspace and import it again with no project information
change workspace and import the project there
I finally found the answer... made all the images bindable and just used the class to tag the images.
for example... instead of
if (draggedImage.id == "Chris" )
{
newImage.source = "assets/Chris.png";
}
changed it to
if (draggedImage.id == "Chris" )
{
newImage.source = pic3_icon;
}

Resources