Appcelerator - Different xml for the same controller - appcelerator

Is possible to have one xml for iOS and one xml for Android for the same controller?
For example:
I have que controller: UIPhoto.js
and I want to have 2 different xml and tss files: UIPhoto-iOS.xml and UIPhoto-Android.xml
and charge each when the device is iOS or Android.
Thank you.

Yes it is possible and is quite simple!
You just need to have a different folder for the specific platform you want to target.
Imagine that you have the index.xml file inside Views folder, right?
You can code your xml as you're used to and if you want a different file for Android (let's say), you just need to create a folder inside "Views" folder called Android. Check this image with a folder structure:
Notice the Android folder in 'controllers' and the iOS in 'views' ;)

You may use platform specific folder in your views
controllers
--- UIPhoto.js
views
--- android
------ UIPhoto.xml
--- iOS
------ UIPhoto.xml
but i recommend you to use tss rather than use 2 xml and 2 tss.
for example in your tss:
"Window[platform=ios]":{
fullscreen : true
}
"View[platform=android]" :{
elevation : 8
}
"View[formFactor=tablet]" :{
elevation : 8
}
"View[platform=android formFactor=handheld]" :{
elevation : 8
}
and for your controller :
if(OS_IOS){
}
if(OS_ANDROID){
}

I don't think you can switch xml file or tss file when device is iOS or Android.
But maybe this is helpful:
First of all you can detect OS with Ti.Platform.osname; in your index.js and valorize a global varibale like this Alloy.Globals.OS.
Now you can switch your code with a simple if statements also in js file with:
if(Alloy.Globals.OS == "android"){...}
In your tss file you can distingue platform like this:
"#title[platform=android]" : {
font : { textStyle : Ti.UI.TEXT_STYLE_HEADLINE }
}

Related

Xamarin Forms creating a Folder in Local

Creating folder by following code
var documents=Environment.GetFolderPath(Environment.SpecialFolder.MyPictures);
var directoryname = Path.Combine(documents, "XX");
Directory.CreateDirectory(directoryname);
but the folder does not exists in the specific path..May i know whats the reason.
regards..
if you need the main picture folder on the android then your code should look like this
string AndroidDcimFolder = Android.OS.Environment.GetExternalStoragePublicDirectory(Android.OS.Environment.DirectoryDcim).AbsolutePath;
From Xamarin Official Site:
Not all directories in this enumeration will be available on all
platforms for all users. When running on the Windows operating system,
the operating system determines the paths to these directories.
Enumeration means Environment.SpecialFolder.
You need to implement a DependencyService and need to call System.Environment.GetFolderPath from within the platform-specific implementation.
Check this sample.
As per my knowledge, it (your code) will not work in Xamarin.Form PCL project.
You can do another thing is, In your Android and iOS Project you can put this code to get the platform specific path:
using Xamarin Forms;
//Get current Path.
Config.PathApp = System.Environment.GetFolderPath (System.Environment.SpecialFolder.Personal);

Nativescript - platform specific code

I've got an iOS specific code (class definition) and would like to include in a separate ios specific file.
So I created two files
utils2.ios.ts <-- added my code here
utils2.android.ts
And then from another file, I did:
import utils2 = require("./utils2");
But I'm getting an error message that the module is not found.
I had to go this route because I've got a class definition in
the code and if I have just one file, I get a run-time error on Android.
Does typescript support platform specific files?
Or another option - is something like this possible in ts file
if ios
do this
end
Similar to C preprocesser
You can get by with just a utils.ts file and inside it you can do platform specific logic that you mention. Your issue about the module not found is likely just a path issue to that module, not that the module isn't actually there. Also note that Typescript doesn't really "support" platform specific files. Nativescript takes those .android.ts and .ios.ts files and at runtime loads the file you need on the platform running. So just FYI that's not really TS related :)
Nativescript provides a platform module in the tns-core-modules. Import the { isAndroid } or { isIOS } from the platform module in your code and use it as the
if (isAndroid) {
// do android only here
} else {
// ios
}

Separate package names for iOS and Android

I currently have a native app published to the App Store and Google Play and both have different package names. I was wanting to know if there is there a way to tell NativeScript to use a one package name for iOS and a different one for Android? Thank you.
Yep, you can absolutely do that. For iOS, include a CFBundleIdentifier flag in your app/App_Resources/iOS/Info.plist file.
<key>CFBundleIdentifier</key>
<string>com.mycompany.myapp</string>
And for Android, update the android.defaultConfig.applicationId in your app/App_Resources/Android/app.gradle file. See https://github.com/NativeScript/template-hello-world/blob/90b81bcb772ab21a06f06bd502be2043e6afc9ee/App_Resources/Android/app.gradle#L11.
For those looking for a solution in 2021, there is an easy way to set it up.
Open your nativescript.config.ts and add different id properties inside android and ios:
import { NativeScriptConfig } from '#nativescript/core';
export default {
appPath: 'src',
appResourcesPath: 'App_Resources',
android: {
v8Flags: '--expose_gc',
markingMode: 'none',
id: 'com.yourapp.android'
},
ios: {
id: 'com.yourapp.ios'
}
} as NativeScriptConfig;

How to add Windows Phone project with resx localization to Xamarin PCL solution?

I have a working PCL project for iOS and I'm trying to create the Windows Phone 8.1 version.
I'm following this tutorial: https://developer.xamarin.com/guides/xamarin-forms/advanced/localization/
And checking the app at: https://github.com/xamarin/xamarin-forms-samples/tree/master/UsingResxLocalization
But it is too deprecated. Even the git project is different from the tutorial, and none of them works.
The ILocalize interface for Windows should look like:
[assembly: Dependency(typeof(UsingResxLocalization.WinPhone.Localize))]
namespace UsingResxLocalization.WinPhone
{
public class Localize : UsingResxLocalization.ILocalize
{
public System.Globalization.CultureInfo GetCurrentCultureInfo ()
{
return System.Threading.Thread.CurrentThread.CurrentUICulture;
}
}
}
But System.Threading.Thread.CurrentThread.CurrentUICulture simply doesn't exist. I found out that I can use Windows.System.UserProfile.GlobalizationPreferences.Languages[0].ToString() instead.
It works for the localized language resources but the default Resource is not working either for the default language "en" or any other non localized language like "ru". I get another error:
In the TranslateExtention class ProvideValue() method I get:
Key 'Start' was not found in resources 'AppNameSpace.AppResources' for
culture 'en'
Being "Start" the first key it tries to get from the resource. It happens for all the other keys on the project.
AppNameSpace.AppResources would be the right file, and "en" is the region I set, so it should work. But it's not.
I'm also getting the following warning when compiling:
The assembly "MyApp.dll"
does not have a NeutralResourcesLanguageAttribute on it. To be used in
an app package, portable libraries must define a
NeutralResourcesLanguageAttribute on their main assembly (ie, the one
containing code, not a satellite assembly). 4>C:\Program Files
(x86)\MSBuild\Microsoft\VisualStudio\v14.0\AppxPackage\Microsoft.AppXPackage.Targets(1216,5):
warning APPX2002: Cannot find the neutral resource language for the
resources for portable library 'MyApp'. Verify that
the portable library defines a NeutralResourcesLanguageAttribute. The
build is continuing assuming the project's default culture of 'en-US'
correctly identifies the portable library's neutral resources.
4>MakePRI : warning 0xdef00522: Resources found for language(s) 'de,
es, fr, pt' but no resources found for default language(s): 'en-US'.
Change the default language or qualify resources with the default
language. http://go.microsoft.com/fwlink/?LinkId=231899
But I have no idea how to fix it.
On the tutorial it also says:
Windows Phone projects must be properly configured for localized text
to be displayed. Supported languages must be selected in the Project
Options and the WMAppManifest.xml files. If these settings are not
updated the localized RESX resources will not be loaded.
Fine, but those options doesn't exist anymore. At least where they should be. I even found a Package.appxmanifest file in my project, but it doesn't have those regional options.
So, I need help with an updated way to do it.
Thanks
So I found out that when you add a Windows Phone project to a solution with no Windows Phone projects, it doesn't add everything it needs.
Also the tutorials don't show everything that is necessary (no big news there).
All my project was missing was [assembly: NeutralResourcesLanguage("en-US")] in my PCL AssemblyInfo.cs file.
The RESX tutorial also says that you should use:
if (Device.OS == TargetPlatform.iOS || Device.OS == TargetPlatform.Android)
{
ci = DependencyService.Get<ILocalize>().GetCurrentCultureInfo();
}
In the TranslateExtention.cs file because Windows Phones don't need it. Well, that's false. At least for the emulator to get the right language, it needs to use the DependencyService and get the CultureInfo this way:
System.Globalization.CultureInfo ci = null;
ci = new System.Globalization.CultureInfo(Windows.System.UserProfile.GlobalizationPreferences.Languages[0].ToString());
return ci;

Qooxdoo - how do i create a new theme and use it in the application?

I am quite new to qooxdoo and I need help in creating a custom theme for my application.
I copied the native Modern theme and modified some of its features, now my question is how do I add it as new theme to qooxdoo and how can I use it in my application?
any help or guidance would be greatly appreciated.
You don't need to copy it over, simply extending the theme would be good. If you created your app with the qooxdoo desktop skeleton using the create-application.py helper, you should already have a custom theme in place running and extending the modern theme. If not, you simply have to edit the config.json file which should be in your root project folder and search for a key named QXTHEME. The value of that key is a classname which specifies your theme. Change that to your custom theme class and rebuild the app to see the result.
Here are some further resources on how to work with themes: http://manual.qooxdoo.org/current/pages/desktop/ui_custom_themes.html
To add a bit to Martin's answer: You don't copy and modify theme code, you extend and override, much as with class code.
If you create an application skeleton with create-application.py, the default code structure under source/class already contains custom theme classes (under source/class//theme/*). The thing is those theme classes extend from the Modern theme without actually overriding anything, so you effectively get the Modern look and feel.
But you can then go ahead and flesh out those custom theme classes, with properties that suite your taste, thereby creating your own theme.
i found it very difficult to create a custom theme by extending one of the existing native themes (classic, modern... etc) without looking at the source code, also i don't want to mess up the original API's files by modifying them, so i did the following:
1- replaced files in my application's directory: myapplication/source/class/myapplication/theme/ with the files in /qooxdoo-directory/framework/source/class/qx/theme/modern/. replaced four files in total (Appearance.js, Decoration.js, Color.js and Font.js).
2- copied decoration directory from /qooxdoo-directory/framework/source/resource/qx/decoration/Modern to my application's directory: myapplication/source/recourse/myapplication/decoration.
3- copied icons directory from qooxdoo-directory/framework/source/resource/qx/icon/Tango to my application's directory myapplication/source/resource/myapplication/icon.
4- copied Tango.js from qooxdoo-directory/framework/source/class/qx/theme/icon/Tango.js to my application's directory myapplication/source/class/myapplication/theme/icon/Icon.js.
5- edited the meta file Themes.js and changed it to:
qx.Theme.define("myapplication.theme.Theme",
{
meta :
{
color : myapplication.theme.Color,
decoration : myapplication.theme.Decoration,
font : myapplication.theme.Font,
icon : myapplication.theme.icon.Icon,
appearance : myapplication.theme.Appearance
}
});
6- edited Icon.js file (which i copied from Tango.js in step 4) and changed it to:
qx.Theme.define("myapplication.theme.icon.Icon",
{
title : "myIcons",
aliases : {
"icon" : "myapplication/icon"
}
});
7- edited Decoration.js, Appearance.js, Color.js and Font.js in my application's theme directory and changed the classes' namespaces from:
qx.Theme.define("qx.theme.modern.<file's name>",
to
qx.Theme.define("myapplication.theme.<file's name>",
8- corrected assets paths in Decoration.js and Appearance.js from the original path qx/decoration/Modern or qx/icon/Tango to the one relevant to my appliaction myapplication/decoration and myapplication/icon, for example:
#asset(qx/decoration/Modern/toolbar/toolbar-part.gif)
changed to
#asset(myapplication/decoration/toolbar/toolbar-part.gif)
ps: the relative path in an application is application-name/source/resource, so you can refer to any directory in this folder by application-name/folder-name.
9- likewise in step 8 i changed aliases in decoration.js to:
aliases : {
decoration : "myapplication/decoration"
},
10 - ran generate.py file in myapplication/source.
and done, now i can change anything i want without crashing the API :)

Resources