IllegalArgumentException when using Android native component in LWUIT - android

I am trying to use native components in a LWUIT app on Android platform.
private Component createNativeTextEdit() {
final Object[] result = new Object[1];
AndroidImplementation.runOnAndroidUIThreadAndWait(LWUITActivity.currentActivity, new Runnable() {
#Override
public void run() {
EditText nativeView = new EditText(LWUITActivity.currentActivity);
nativeView.setText("Type here..");
result[0] = PeerComponent.create(nativeView);
}
});
return (Component)result[0];
}
I then place a component inside a form:
mMainForm = new Form();
mMainForm.setLayout(new BoxLayout(BoxLayout.Y_AXIS));
mMainForm.addComponent(createNativeTextEdit());
mMainForm.show();
Then I get an "IllegalArgumentException: width and height must be > 0" when the system tries to draw the new form.
I traced the problem down to the call to AndroidImplementation.PeerWrapper.getBuffer() and the values returned by getWidth() and getHeight() are width=474 and height=0.
How is height supposed to be set? What am I missing?
Do you know of a working sample program that uses PeerComponent on Android? I searched the web but could only find some snippets where it is not clear where the code is called from, which thread it is executed on etc.
Thanks.

I figured out the issue.
I am using LWUIT 1.5 thorsten_s port for Android.
The issue is that LWUIT computes components preferred size before the native view is added so both width and height are set to 0.
The way to fix it is to call View.measure() on the PeerWrapper at creation time to initialize it to preferred size.
Inside AndroidImplementation.java at the end of the constructor for PeerWrapper class add the line:
measure(MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED),
MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED));
This completely fixes the problem. I can now use components like AnalogClock, DatePicker, and native EditText in LWUIT forms.

This sort of thing works for us in the Codename One implementation. I'm not exactly sure what is happening in Thorsten's port since we are pretty much forked by now. We intend to release Codename One with a native access demo that will demonstrate access to native widgets.

Related

Android: Changing Unity Scene from UI components outside the scene

I am trying to build an Android app that uses Unity for UI rendering where the user can perform some actions from outside the scene.
What this means is that say I have an activity where I have a unity scene as a subview. The rest of the screen is composed of native android views (buttons etc). I want to use these views to make changes to the unity scene such as to show a text field, add text, hide text, add text effects etc.
So far I have added the unity scene as a subview by following this answer and it works fine. I am new to Unity and I am not sure how I can manage and change the scene from views outside the scene. Is this even possible? I know if I add buttons to the scene itself when I create the scene in Unity then I can use those buttons to alter the scene.
But is this possible by UI components that are not a part of the scene? If yes how can I do this? I have tried to find info on this but couldn't find much. Thanks for reading.
Make communicator between Unity side and Android.
It's possible to do that technically, if you make following function in unity. I've just wrote here how unity and android communicate so
before use this code you need to see brief of integration between Unity and Android to use native plugin from Unity so see this link to do that.
https://docs.unity3d.com/Manual/PluginsForAndroid.html
After you understand that how to make plugin for android, then see codes. It will help you.
GameObject Name: LoadGameSceneObject, loadScene.cs
public class loadScene : MonoBehaviour
{
public static void LoadScene(string sceneName)
{
SceneManager.LoadScene(sceneName);
}
}
SceneLoadActivie.java
public static void SendMessageToUnity(String gameObjectName, String methodName, String message) throws Exception
{
Log.d("unity", gameObjectName + " " + methodName + " " + message);
final Class<?> player = Class.forName("com.unity3d.player.UnityPlayer");
player.getMethod("UnitySendMessage", String.class, String.class,
String.class).invoke(null, gameObjectName, methodName, message);
}
...
// call this function.
public void LoadScene()
{
SceneLoadActivie.SendMessageToUnity("LoadGameSceneObject", "LoadScene", "SomeScene");
}

Xamarin Forms Custom Renderer for Android not displaying

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...)

Show image in TImage dynamically (at run time) without opendialog in c++ builder xe8

I want to show image (png,jpg etc) in dynamically created (as per requirement and fully through coding) TImage component, at runtime in C++ builder xe8 (not delphi). But I dont want to use opendialogbox (suggested in many web sites). I want to run this app on my android device. I tried to use LoadFromFile(), it crashes the app on android, but when I run this on windows, its running smoothly. I am just a beginner to c++ builder. So guys pls help. Thanx in advance for any kind of help.Here is what I did.
void __fastcall TForm1::TForm1(TComponent* Owner)
{
TImage* img = new TImage(this);
img->Parent = this;
img->Bitmap->LoadFromFile("D:\\res\\profile.png");
}
Did you see what is the error?
If you run the program with the provided by you code I assume the error would be that the file is not found, because there is no such directory "D:\" in android.
One way to set the path is to write a static path which points to your image. For example : "/storage/sdcard0/DCIM/Camera/MyImage.jpg";
The second way is to include the <System.IOUtils.hpp> header and to use some built-in functions like:
System::Ioutils::TPath::GetPicturesPath();
System::Ioutils::TPath::GetAlarmsPath();
You can check them out, they might be useful.

Try to add candlestickseries to shinobiCharts in Xamarin.Android

I'm novice at Xamarin and I'm trying to use ShinobiCharts in Xamarin.Android to show candlestick data on it.
Code from .axml:
<fragment
class="com.shinobicontrols.charts.ChartFragment"
android:id="#+id/chart"
android:layout_width="match_parent"
android:layout_height="match_parent" />
This is fragment where should be shown chart.
var chartFragment = (ChartFragment)FragmentManager.FindFragmentById(Resource.Id.chart);
var chart = chartFragment.ShinobiChart;
chart.SetLicenseKey("license_key");
chart.AddXAxis(new DateTimeAxis
{
GesturePanningEnabled = true,
GestureZoomingEnabled = true
});
chart.AddYAxis(new NumberAxis
{
GesturePanningEnabled = true,
GestureZoomingEnabled = true
});
var dataPoints =
quotes.Select(
quoteCandle =>
new MultiValueDataPoint(DateUtils.ConvertToJavaDate(TimeStamp.UnixToDate(quoteCandle.Timestamp)),
(double) quoteCandle.Low, (double) quoteCandle.High,
(double) quoteCandle.Open, (double) quoteCandle.Close)).ToList();
var series = new OHLCSeries { DataAdapter = new SimpleDataAdapter() };
series.DataAdapter.AddAll(dataPoints);
chart.AddSeries(series);
chart.XAxis.Style.GridlineStyle.GridlinesShown = true;
chart.YAxis.Style.GridlineStyle.GridlinesShown = true;
chart.RedrawChart();
This is code of creating ShinobiCharts.
The problem is that added series are not shown in chart. Style changed, but there are no series. What do I do wrong? I hope anyone can help.
Sorry for question, Candlestickes are not available for trial version of ShinobiControls, only for premium version.
As sammyd said, CandlestickSeries are available in the trial version of ShinobiCharts for Android (as are all the other premium features). Have you managed to get the CandlestickChart sample running? The sample is included in the download bundle.
On the face of it your code looks fine (without seeing the rest of it) but there are a couple of things I'd recommend checking:
Have you replaced the string license_key with the trial license key we would have emailed you when you downloaded the bundle? The trial license key is a a really long string of characters and digits.
Is your data coming in as expected and does it make sense (e.g. are your low values less than your open values etc.)?
I'm not sure it'll make much difference, as they're pretty much interchangeable, but you're actually creating an OHLCSeries in code but mention a CandlestickSeries
Have you set the series' style object in a way that would stop it from showing i.e. have you set it to be transparent in colour?
Are you getting an actual error, and if so what message is being logged?
Hopefully the above will help you get your candlestick chart up and running!
Edit:
If you're using the Android Emulator, your AVD needs to have GPU emulation turned on (as we use OpenGL ES 2.0 for rendering the charts). There's more information on using the emulator with OpenGL on the Android developer site.
Disclaimer: I work for ShinobiControls

How to import a SpriteFont into MonoGame

I'm porting a simple tetris-like XNA app to Android, using Mono For Android and MonoGame; I have followed the suggested steps in this link and so far, everything compiles well, and no relevant warnings fire up. However, upon loading the contents, a null parameter exception breaks the program at the point below in my program:
protected override void LoadContent() {
// ...
_font = Content.Load<Microsoft.Xna.Framework.Graphics.SpriteFont>("SpriteFont1");
// ...
}
The content root directory is set in the game constructor class:
public Game2 (){
Content.RootDirectory = "Content";
Content.RootDirectory = "Assets/Content"; // TEST.
//...}
And I have tried several combinations, all to no avail.
I have also tried setting the xnb files as Content as well as Android Assets in the Build Action property; having the linked, copied always, copied only if newer... etc.
Either way, my problem is that I don't really understand WHY and HOW should I do this. I'm rather new to the platform and to XNA as well, so this may very well be a newbie question, but the truth is after several hours banging my head and fists against the monitor/keyboard I feel stuck and need your help.
I have a library that supports variable-width fonts (generated by BMFont) on MonoGame. Unfortunately it is a renderer and so has other code around it. However, the basic idea is very simple. You can take a look at the loader here and the mesh builder (given a string) here. This builder supports fonts that spread characters across multiple pages, too.
Hope this helps!
MonoGame (2.5.1) throws NotImplementedException in ContentManager.Load for SpriteFont type. Have the same not resolved problem. I'm trying not to use DrawString.
For loading textures in Win32 application I use:
Content.RootDirectory = #"../../Content";
var sampleTexture = Content.Load<Texture2D>("Sample.png");
You even must not add it to solution.
For Andoind (MonoDroid) application you must add "Content" folder to your solution and set "Andtoid Asset" in "Sample.png" properties.
Content.RootDirectory = "Content";
var sampleTexture = Content.Load<Texture2D>("Sample.png");
See also:
http://monogame.codeplex.com/discussions/360468
http://monogame.codeplex.com/discussions/267900

Categories

Resources