I have just started to learn the basics of Blackberry....
So, I am facing one issue in Bitmap UI API of Blackberry..
I have a class called UiFunApplication which have main method :
public class UiFunApplication extends UiApplication {
public UiFunApplication() {
UiFunMainScreen mainScreen = new UiFunMainScreen();
pushScreen(mainScreen);
}
public static void main(String[] args) {
UiFunApplication app = new UiFunApplication();
app.enterEventDispatcher();
}
}
Now my UiMainScreen Class have following code :
public class UiFunMainScreen extends MainScreen {
BitmapField bitmapField;
public UiFunMainScreen() {
Bitmap logoBitmap = Bitmap.getBitmapResource("res/image.png");
bitmapField = new BitmapField(logoBitmap,Field.FIELD_HCENTER);
add(bitmapField);
LabelField labelField = new LabelField("Hello World");
add(labelField);
}
}
I have also included image.png in the res folder which is in the same directory structure as src.
Still in the simulator I am just getting the label called "Hello World", but not the image at the top.
Thanks in advance....
The latest BlackBerry plugin in Eclipse uses the res folder convention from J2ME: everything in the res folder ends up top-level in your jar file.
So changing the line
Bitmap logoBitmap = Bitmap.getBitmapResource("res/image.png");
to
Bitmap logoBitmap = Bitmap.getBitmapResource("image.png");
should fix the problem.
To confirm that this is the issue, look in the deliverables folder in your project directory for the jar generated by Eclipse. Open it up (just rename the extension to .zip) and verify that the image is right there at the top level of the jar.
If you want the res to be there, add another res folder under the res folder and put all your images in there.
Related
I want to let user to download a file from server.
I looked up for the solution and when trying to make an example - ended up with this:
#Route("test-download")
public class Download extends VerticalLayout {
public Download() {
Anchor downloadLink = new Anchor(createResource(), "Download");
downloadLink.getElement().setAttribute("download", true);
add(downloadLink);
}
private AbstractStreamResource createResource() {
return new StreamResource("/home/johny/my/important-file.log", this::createExportr);
}
private InputStream createExportr(){
return null;
}
}
Which is giving java.lang.IllegalArgumentException: Resource file name parameter contains '/' when I go to the page in browser.
How do I make a download button (or anchor) knowing file location on disk?
Have a look at the documentation, paragraph "Using StreamResource". The first parameter is just a file name that will be used by the browser to propose that file name to the user when downloading. So you could pass it like "important-file.log". The content of the download is provided by the InputStream parameter. For instance, you could read from your file, see here:
File initialFile = new File("src/main/resources/sample.txt");
InputStream targetStream = new FileInputStream(initialFile);
I followed the direction here for adding a new extension so that I can trigger an event whenever a new image is uploaded to Ektron. I created this new file in the App_Code folder of my project:
using System;
using System.Collections.Generic;
using System.Text;
using Ektron.Cms;
using Ektron.Cms.Common;
using Ektron.Cms.Extensibility;
using Ektron.Cms.Extensibility.Content;
namespace Cms.Extensions.Samples
{
public class UploadExtension : LibraryStrategy
{
public override void OnAfterAdd(LibraryData taxonomyData, CmsEventArgs eventArgs)
{
string[] lines = { "Written on Ektron upload event!" };
System.IO.File.WriteAllLines(#"C:\Users\Public\TestFolder\WORKING.txt", lines);
var x = taxonomyData;
}
public override void OnAfterUpdate(LibraryData taxonomyData, CmsEventArgs eventArgs)
{
var x = taxonomyData;
}
public override void OnBeforeDelete(long id, CmsEventArgs eventArgs)
{
var x = id;
}
}
}
I just put in one test line for each method so that I could add a breakpoint to see if it's getting hit. I registered the new extension in objectfactory:
<objectFactory>
<objectStrategies>
<add name="Library">
<strategies>
<add name="EktronUploadExtension" type="Cms.Extensions.Samples.UploadExtension"/>
<add name="GoogleGeoCoder" type="Cms.Extensions.GoogleGeoCoder.LibraryStrategy, Cms.Extensions.GoogleGeoCoder"/>
</strategies>
</add>
</objectStrategies>
</objectFactory>
It looks like I set everything up correctly, but I attached to process and opened up my Ektron work area and uploaded a new image to the library, but none of my breakpoints (specifically the breakpoint in OnAfterAdd) got hit. I'm not sure how to debug or figure out what's wrong with my extension.
EDIT: I fixed the objectfactory.config file, but it's still not working. The breakpoints in UploadExtension.cs aren't working, and the test file that I put in the function isn't getting written when I add new library item in Ektron.
Your objectfactory.config file is incorrect. You have created a LibraryStrategy but placed it into the Content Strategy section of the objectfactory.config.
You should add a section called "Library" to the config file like so:
<add name="Library">
<strategies>
<add name="MyFirstExample"
type="Cms.Extensions.Samples.UploadExtension"/>
</strategies>
</add>
I just created a new MVC 5 app on VS 2013 RTM.
For some reason background image url in my CSS files were not being transformed.
So, to debug the issue, I created my custom CssRewriteUrlTransform wrapper.
And I found that my breakpoint is not being called.
This is what I have in my BundleConfig.cs
using System.Web.Optimization;
namespace Utilities.Web
{
public class BundleConfig
{
private const string JQUERY_CDN_URL = "//code.jquery.com/jquery-1.10.1.min.js";
public static void RegisterBundles(BundleCollection bundles)
{
bundles.UseCdn = true;
BundleTable.EnableOptimizations = true;
bundles.Add(new StyleBundle("~/css/coming-soon")
.Include("~/Content/Site/coming-soon.css",
new CssRewriteUrlTransformWrapper()));
bundles.Add(new ScriptBundle("~/js/coming-soon")
.Include("~/Scripts/jquery.placeholder.js")
.Include("~/Scripts/Site/coming-soon.js"));
bundles.Add(new ScriptBundle("~/js/jquery", JQUERY_CDN_URL)
{
CdnFallbackExpression = "window.jQuery"
}.Include("~/Scripts/jquery-{version}.js"));
}
}
public class CssRewriteUrlTransformWrapper : IItemTransform
{
public string Process(string includedVirtualPath, string input)
{
return new CssRewriteUrlTransform().Process(includedVirtualPath, input);
}
}
}
It appears the transform does not run if you have the minified version of the CSS. Remove the .min.css file and it should start working.
I have the same problem. Сlass CssRewriteUrlTransform does not work as I need. I looked at the source code AspNetWebOptimization and found that when Bundle finds a file with ".min", it creates a new BundleFile without transforms from the original BundleFile. The best solution is to turn off the FileExtensionReplacement for these bundles:
var bundle = new StyleBundle("~/bundles/css/font-awesome")
.Include("~/Content/font-awesome.css", new CssRewriteUrlTransform());
bundle.EnableFileExtensionReplacements = false;
bundles.Add(bundle);
I would have liked to put this as a comment under the marked answer. But I do not have the right to do so. The answer helped me. I also found another solution for it. In the Bundle-configuration method add this:
BundleTable.Bundles.FileExtensionReplacementList.Clear();
This will avoid the *.min.css file to be included automatically. And the transform will be called.
Regards Hans
My app is localized using the standard .NET RESX methods (ie. String.fr.resx, Strings.de.resx etc.) works great under Windows Phone.
I am porting to Android using MonoDroid and I do not see the localized UI when I switch locales on the phone. If I rename the APK file to ZIP and open it I see that it has not packaged up the locale DLLs produced during the build (ie. the intermediate \.Resources.dll files are under the bin directory but are not packaged into the APK).
What am I missing? I have tried changing the build action on the RESX files from "Embedded Resource" to "Android Resource" and even "Android Asset" but to no avail.
Thanks in advance for any help!
Cheers
Warren
I asked about this on the monodroid irc channel and the official answer was "not supported yet but we do have plans to do it".
You need to convert the resx files to android xml format (see below) and add them to your project as shown here: http://docs.xamarin.com/android/tutorials/Android_Resources/Part_5_-_Application_Localization_and_String_Resources
In my app (game) I needed to look up the localised strings by name. The code to do this was simple but not immediately obvious. Instead of using ResourceManager I swapped in this for android:
class AndroidResourcesProxy : Arands.Core.IResourcesProxy
{
Context _context;
public AndroidResourcesProxy(Context context)
{
_context = context;
}
public string GetString(string key)
{
int resId = _context.Resources.GetIdentifier(key, "string", _context.PackageName);
return _context.Resources.GetString(resId);
}
}
Since I'm not a XSLT guru I made a command line program for converting resx to Android string XML files:
/// <summary>
/// Conerts localisation resx string files into the android xml format
/// </summary>
class Program
{
static void Main(string[] args)
{
string inFile = args[0];
XmlDocument inDoc = new XmlDocument();
using (XmlTextReader reader = new XmlTextReader(inFile))
{
inDoc.Load(reader);
}
string outFile = Path.Combine(Path.GetDirectoryName(inFile), Path.GetFileNameWithoutExtension(inFile)) + ".xml";
XmlDocument outDoc = new XmlDocument();
outDoc.AppendChild(outDoc.CreateXmlDeclaration("1.0", "utf-8", null));
XmlElement resElem = outDoc.CreateElement("resources");
outDoc.AppendChild(resElem);
XmlNodeList stringNodes = inDoc.SelectNodes("root/data");
foreach (XmlNode n in stringNodes)
{
string key = n.Attributes["name"].Value;
string val = n.SelectSingleNode("value").InnerText;
XmlElement stringElem = outDoc.CreateElement("string");
XmlAttribute nameAttrib = outDoc.CreateAttribute("name");
nameAttrib.Value = key;
stringElem.Attributes.Append(nameAttrib);
stringElem.InnerText = val;
resElem.AppendChild(stringElem);
}
XmlWriterSettings xws = new XmlWriterSettings();
xws.Encoding = Encoding.UTF8;
xws.Indent = true;
xws.NewLineChars = "\n";
using (StreamWriter sr = new StreamWriter(outFile))
{
using (XmlWriter writer = XmlWriter.Create(sr, xws))
{
outDoc.Save(writer);
}
}
}
}
I have the following problem with a blackberry demo class:
MenuItem locatorItem = new MenuItem(new StringProvider("Location Search"), 0x230020, 0);
locatorItem.setCommand(new Command(new CommandHandler()
(...)
I am using Eclipse and a BlackBerry simulator to get this demo running and I get the 'Cannot instantiate the type MenuItem' error. I don't know why and there's no suggestion to solve it.
I imported 'net.rim.device.api.ui.MenuItem;'.
I think you're using the wrong type of MenuItem. net.rim.device.api.ui.MenuItem you are using is specific to the Blackberry.
If this is a J2ME Application/Midlet, just create a javax.microedition.lcdui.Command. They are turned into menu items on the blackberry.
If you're also usingnet.rim.device.api.ui.Screen or any other net.rim classes in the application, this is the way menu items are usually created:
function doSomething() {
// Your Code Here
}
// In the function building your screen
MenuItem somethingMi = new MenuItem() {
private MenuItem() { super("Do Something",100001, 5); }
public void run() { doSomething() };
}
addMenuItem(somethingMI);