MoSync native UI and deployment - mobile

Does anybody know if it's possible to use MoSync to create apps with a native UI?
From what I can tell all the UI/graphics is done with their own UI library and don't the the native ui elements.
Also, now that I'm creating a question anyway. Why does MoSync target specific telephones? Is it not possible to just create a generic install package for whatever platform you're targeting? (like .apk files for android). If it's possible it should make distribution easier.

The standard way up til now has been to create a custom non-native UI through the MAUI library. As of 2011-02-03 there is an experimental native UI framework for Android and iPhone. The user documentation is however rather non-existent, so you will have to check the source code for more information. I'll point you in the right direction, for accessing native widgets you use the maWidget* system calls defined in: maapi.idl. For a list of available widgets and properties see: Types.java. Note that this API is likely to change and be expanded.
A simple native UI example:
#include <MAUtil/Moblet.h>
#include <IX_WIDGET.h>
class NativeUIMoblet : public MAUtil::Moblet
{
public:
NativeUIMoblet()
{
// Create a screen
MAHandle mainScreen = maWidgetCreate( "Screen" );
// Create a 'Hello World' label
MAHandle helloLabel = maWidgetCreate( "Label" );
maWidgetSetProperty( helloLabel, "text", "Hello World!" );
// Add the label to the screen
maWidgetAddChild( mainScreen, helloLabel );
// Show the screen
maWidgetScreenShow( mainScreen );
}
void keyPressEvent(int keyCode, int nativeCode)
{
}
void keyReleaseEvent(int keyCode, int nativeCode)
{
}
};
extern "C" int MAMain()
{
MAUtil::Moblet::run( new NativeUIMoblet( ) );
return 0;
};
Presently, there is no emulator support available, so you will have to run it on a device or in a specific SDKs emulator.
The reason for targeting a specific phone is that there exists bugs specific to a certain device. But in the recent nightly builds of MoSync you can build for generic platforms like Android 2.1.

http://www.mosync.com/blog/2011/03/using-nativeeditbox

Related

Using Shiny with UNO Platform

Looking for a way to use shinyorg/shiny nuget packages in cross-platform projects built on the UNO platform.
Facing some challenges beyond my (limited) skills for iOS development, I'm specifically looking for how to integrate Shiny.Core into the solution iOS project.
More precisely, I'm looking for where to put this initialization override:
public override void PerformFetch(UIApplication application, Action<UIBackgroundFetchResult> completionHandler)
=> this.ShinyPerformFetch(completionHandler);
Since when I try adding this in the Main.cs (Application class) of the iOS project, I can't find where to start...
The Main.cs class from the iOS project contains a static Main method (which is the main entry point of the app) in which a call to UIApplication.Main(args, null, typeof(App)); is made.
UIApplication being in fact UIKit.UIApplication
Following this guide https://github.com/shinyorg/shiny/tree/master/src/Shiny.Core where it's said:
* Add the following as the first line in your AppDelegate.cs - FinishedLaunching method
using Shiny;
this.ShinyFinishedLaunching(new YourStartup());
** IOS JOBS **
If you plan to use jobs in iOS, please do the following:
1. Add this to your AppDelegate.cs
public override void PerformFetch(UIApplication application, Action<UIBackgroundFetchResult> completionHandler)
=> this.ShinyPerformFetch(completionHandler);
On iOS, the AppDelegate is actually the App class in your app, created from the default Uno Platform templates.
Windows.UI.Xaml.Application inherits from UIApplicationDelegate and provides a way declare this:
#if __IOS__
public override void PerformFetch(UIApplication application, Action<UIBackgroundFetchResult> completionHandler)
=> this.ShinyPerformFetch(completionHandler);
#endif
in order for the code for the other platforms to ignore this iOS-specific code

From iOS Objective-C code and Android Java code to a Codename One PeerComponent

At the page https://www.wowza.com/docs/how-to-build-a-basic-app-with-gocoder-sdk-for-ios there are the following examples:
if (self.goCoder != nil) {
// Associate the U/I view with the SDK camera preview
self.goCoder.cameraView = self.view;
// Start the camera preview
[self.goCoder.cameraPreview startPreview];
}
// Start streaming
[self.goCoder startStreaming:self];
// Stop the broadcast that is currently running
[self.goCoder endStreaming:self];
The equivalent Java code for Android is reported at the page https://www.wowza.com/docs/how-to-build-a-basic-app-with-gocoder-sdk-for-android#start-the-camera-preview, it is:
// Associate the WOWZCameraView defined in the U/I layout with the corresponding class member
goCoderCameraView = (WOWZCameraView) findViewById(R.id.camera_preview);
// Start the camera preview display
if (mPermissionsGranted && goCoderCameraView != null) {
if (goCoderCameraView.isPreviewPaused())
goCoderCameraView.onResume();
else
goCoderCameraView.startPreview();
}
// Start streaming
goCoderBroadcaster.startBroadcast(goCoderBroadcastConfig, this);
// Stop the broadcast that is currently running
goCoderBroadcaster.endBroadcast(this);
The code is self-explaining: the first blocks start a camera preview, the second blocks start a streaming and the third blocks stop it. I want the preview and the streaming inside a Codename One PeerComponent, but I didn't remember / understand how I have to modify both these native code examples to return a PeerComponent to the native interface.
(I tried to read again the developer guide but I'm a bit confused on this point).
Thank you
This is the key line in the iOS instructions:
self.goCoder.cameraView = self.view;
Here you define the view that you need to return to the peer and that we can place. You need to change it from self.view to a view object you create. I think you can just allocate a UIView and assign/return that.
For the Android code instead of using the XML code they use there you can use the WOWZCameraView directly and return that as far as I can tell.

Native interface for IOS is OK, how do I handle Android functionality?

For IOS I have a native interface function and it works well.
For Android I may use the standard codenameone function.
How do I handle the Android function?
I saw, using Display.getInstance().getPlatformName() is not a good idea
to change functions between IOS and Android!
Also in this case?
The only way is to check the platform name.
Return false for isSupported() in your Android native implementation code. After that, in your callback class check if isSupported() is true, if not, then check if the platform is Android.
MyNative native = NativeLookup.create(MyNative.class);
if(native != null && native.isSupported()) {
//call your native interface method here
} else if("and".equalsIgnoreCase(CN.getPlatformName())) {
//call Codename One method here for android
} else {
//perform any default action here for other platforms
}

Possible ways for Finding Window coordinate using C++ Windows Form Application

I want to write an application that will automatically detect and fill the text field in the window shown below:
(assuming the data to be entered is in a file).
The question is how does my application find this text field?
I can do this job if I am able to find the location of the text field on the desktop through program.
Can someone help me understand possible ways for finding this text field?
I am using Windows Form application in C++.
Update:
I played with spy++.
I used spy++, to find the window handle. I did it by putting finder on the window I am interested in. Its giving handle in hex values: 00080086 (actually just for testing purpose I put the finder tool on Visual Studio new project page ). How do I interpret this Hex value into meaningful window name ?
See the below figure.
What is the next step to get to the text field " Enter name" under "name" field.
****Any sample code will be highly appreciated.**
I am open to any solution not necessarily how I am doing this.
One solution is to use the Microsoft UI Automation technology. It's shipped out-of-the-box with Windows since Vista. It's usable from .NET but also from C++ using COM.
Here is a short C++ console application example that displays the class name of the UI Automation Element currently at the middle of the desktop window, each second (you can have it run and see what it displays):
int _tmain(int argc, _TCHAR* argv[])
{
CoInitialize(NULL);
IUIAutomation *pAutomation; // requires Uiautomation.h
HRESULT hr = CoCreateInstance(__uuidof(CUIAutomation), NULL, CLSCTX_INPROC_SERVER, __uuidof(IUIAutomation), (LPVOID *)&pAutomation);
if (SUCCEEDED(hr))
{
RECT rc;
GetWindowRect(GetDesktopWindow(), &rc);
POINT center;
center.x = (rc.right - rc.left) / 2;
center.y = (rc.bottom - rc.top) / 2;
printf("center x:%i y:%i'\n", center.x, center.y);
do
{
IUIAutomationElement *pElement;
hr = pAutomation->ElementFromPoint(center, &pElement);
if (SUCCEEDED(hr))
{
BSTR str;
hr = pElement->get_CurrentClassName(&str);
if (SUCCEEDED(hr))
{
printf("element name:'%S'\n", str);
::SysFreeString(str);
}
pElement->Release();
}
Sleep(1000);
}
while(TRUE);
pAutomation->Release();
}
CoUninitialize();
return 0;
}
From this sample, what you can do is launch the application you want to automate and see if the sample detects it (it should).
You could also use the UISpy tool to display the full tree of what can be automated in your target app. You should see the windows and other elements (text field) of this target app and you should see the element displayed by the console application example.
From the pElement discovered in the sample, you can call FindFirst with the proper condition (class name, name, control type, etc...) to get to the text field. From this text field, you would use one of the UI Automation Patterns that should be available (probably TextPattern or ValuePattern) to get or set the text itself.
The cool thing is you can use the UISpy tool to check all this is possible before actually coding it.
You could enumerate windows and then find it.
For exploring application on your screenshot you could you Spy++ (spyxx.exe) that is distributed with visual studio. In you code, you clould use EnumWindows and EnumChildWindows to enumerates all window or all child windows to find one you need.
Although the answer given by Simon is accepted and is the best one, but still for future visitors I am providing this link which has more description for UI automation of windows applications. .
Also for automating a web application one may want to go to this link

Embedding word 2010 editor in a wpf application

How do I use the word editor in a WPF application? Is it possible using windows forms hosting in WPF only? Is there another way to accomplish that?
I found AvalonEdit but it does not have features that I need. So using this way, my problem may not be solved.
Also there is some stuffs out there to host a windows forms control in WPF, but it could not be my answer.
I want to understand that is there a way to use word editor in a native way in a wpf app?
Will all APIs be available in that solution?
Thanks in advance.
You can host MS Word (2007/2010 and probably other versions) from within a WebBrowser control, this works in WinForms and should work in WPF too. A .NET API is provided for automating Word, documented here. The required interop assemblies ship with Office 2010, so deployment is a lot simpler than previous Office versions.
See this Microsoft Support article for more details on hosting Word within a WebBrowser control. The Screenshot below shows Word embedded within a host Winforms application.
Note that this only works reliably for a single hosted instance of Word, so you can't show 2 Word documents side by side in the same application. Also, the Ribbon can sometimes go missing - but Word hasn't ever caused the application to crash.
Administrative rights are required to make the required registry updates as there are potential security issues. One easy method to make the registry updates is to write a script, but the following (revised/untested) code shows how this can be done in c# for Word, Excel and PowerPoint:
using System.Security.AccessControl;
private Dictionary<string,uint> OfficeBrowserRegKeys()
{
string[] officeRegKeyArray = new string[]
{
#"SOFTWARE\Classes\Word.Document.12",
#"SOFTWARE\Classes\Word.DocumentMacroEnabled.12",
#"SOFTWARE\Classes\Excel.Sheet.12",
#"SOFTWARE\Classes\Excel.SheetMacroEnabled.12",
#"SOFTWARE\Classes\Excel.SheetBinaryMacroEnabled.12",
#"SOFTWARE\Classes\PowerPoint.Show.12",
#"SOFTWARE\Classes\PowerPoint.ShowMacroEnabled.12",
#"SOFTWARE\Classes\PowerPoint.SlideShow.12",
#"SOFTWARE\Classes\PowerPoint.SlideShowMacroEnabled.12"
};
Dictionary<string,uint> officeRegKeys = new Dictionary<string, uint>();
uint wrdVal = 0x80000024;
uint excelVal = 0x80000A00;
uint powerPtVal = 0x800000A0;
foreach(string keyName in officeRegKeyArray)
{
if (keyName.Contains("Word"))
{
officeRegKeys.Add(keyName, wrdVal);
}
else if (keyName.Contains("Excel"))
{
officeRegKeys.Add(keyName, excelVal);
}
else
{
officeRegKeys.Add(keyName, powerPtVal);
}
}
return officeRegKeys;
}
private void setNewOfficeKeys()
{
uint editFlag = 0x00010000;
Dictionary<string,uint> officeRegKeys = OfficeBrowserRegKeys();
foreach (KeyValuePair<string, uint> kvp in officeRegKeys)
{
try
{
RegistryKey rKey = Registry.LocalMachine.OpenSubKey(kvp.Key,
RegistryKeyPermissionCheck.ReadWriteSubTree,
System.Security.AccessControl.RegistryRights.SetValue);
rKey.SetValue("BrowserFlags", unchecked((int)kvp.Value),
RegistryValueKind.DWord);
rKey.SetValue("EditFlags", unchecked((int)editFlag),
RegistryValueKind.DWord);
}
catch (Exception e) { string msg = e.Message; }
}
}
Well, Word proper isn't technically designed to be hosted by another app, whether it's WPF, WINFORMS or anything else.
You CAN use api tricks (like SetParent) to move the Main Word window into a WPF hosted window. I've done it before, but it's pretty tricky business and it's very easy to miss things that cause GPFs (both in Word and your app).
Is there any reason why it needs to be "Word in your app"? Why not write a little word addin and then launch Word from your app when necessary. then the Addin can communicate with your app, or your DB or whatever as necessary from within Word.
Users may find that to be a more usable approach in any case.

Resources