Page tree
Skip to end of metadata
Go to start of metadata

This guide explains how to use Application library in your project.

What is Application Library ?

Application is a set of collection for application based properties and methods.

Methods

Application library has these methods below :

NAMEDESCRIPTION
call
Launches another application and passes data to it.
callFinish
Calls the caller app of this app.
exit
Exits the app.
maximize
Maximizes this app.
minimize
Minimizes this app.

Let's make an example about some of the methods. Create two buttons, one for minimize and one for exit.

var btnMinimize = new SMF.UI.TextButton({
		left : "12%",
		top : "25%",
		width : "75%",
		height : "10%",

		text : "minimize",
		onPressed : function () {
			Application.minimize();
		}
	});
var btnExit = new SMF.UI.TextButton({
		left : "12%",
		top : "50%",
		width : "75%",
		height : "10%",
		text : "exit",
		onPressed : function () {
			Application.exit();
		}
	});
page1.add(btnMinimize);
page1.add(btnExit);
 
})();

After you add these two buttons to your page, and run the application, it will look like :

        

Minimize and exit seems very similar but they are actually not. When you run minimize method, your application will be minimized and when you open it, the application continues from where you left. But when you run the exit method and then try to open your application again, it starts from the beginning.

Properties

The properties of Application are :

NAMEDESCRIPTION
appID
Shows ID of the application.
applicationState
Gets the state of the application.
byteReceived
Shows the received bytes from the application.
byteSent
Shows the sent bytes from the application.
inAppProductKey
Shows product key of the application for InAppPurchase API.
language
Shows language of the application.
mapProvider
Shows the mapProvider of the device.
orientationsSupported
Shows supported orientation by the application.
smartfaceAppName
Shows name of the application.
version
Shows the version of the application.

Let's show some examples of properties below.

At first, create some labels, and these labels will show the result of properties.

var myLabel1 = new SMF.UI.Label({
		left : "50%",
		top : "10%",
		width : "45%",
		height : "10%",
		text : "",
		backgroundTransparent : false
	});
page1.add(myLabel1);
var myLabel2 = new SMF.UI.Label({
		left : "50%",
		top : "25%",
		width : "45%",
		height : "10%",
		text : "",
		backgroundTransparent : false
	});
page1.add(myLabel2);
var myLabel3 = new SMF.UI.Label({
		left : "50%",
		top : "40%",
		width : "45%",
		height : "10%",
		text : "",
		backgroundTransparent : false
	});
page1.add(myLabel3);
var myLabel4 = new SMF.UI.Label({
		left : "50%",
		top : "55%",
		width : "45%",
		height : "10%",
		text : "",
		backgroundTransparent : false
	});
page1.add(myLabel4);
var myLabel5 = new SMF.UI.Label({
		left : "50%",
		top : "70%",
		width : "45%",
		height : "10%",
		text : "",
		backgroundTransparent : false
	});
page1.add(myLabel5);
var myLabel6 = new SMF.UI.Label({
		left : "50%",
		top : "85%",
		width : "45%",
		height : "10%",
		text : "",
		backgroundTransparent : false
	});
page1.add(myLabel6);

Add these labels to your page.

Now let's create buttons and these buttons will trigger some properties of Application when they are pressed.

var myButton1 = new SMF.UI.TextButton({
		left : "5%",
		top : "10%",
		width : "40%",
		height : "10%",
		text : "app ID",
		onPressed : function () {
			myLabel1.text = Application.appID;
		}
	});
page1.add(myButton1);
var myButton2 = new SMF.UI.TextButton({
		left : "5%",
		top : "25%",
		width : "40%",
		height : "10%",
		text : "state",
		onPressed : function () {
			myLabel2.text = Application.applicationState;
		}
	});
page1.add(myButton2);
var myButton3 = new SMF.UI.TextButton({
		left : "5%",
		top : "40%",
		width : "40%",
		height : "10%",
		text : "byte sent",
		onPressed : function () {
			myLabel3.text = Application.byteSent;
		}
	});
page1.add(myButton3);
var myButton4 = new SMF.UI.TextButton({
		left : "5%",
		top : "55%",
		width : "40%",
		height : "10%",
		text : "language",
		onPressed : function () {
			myLabel4.text = Application.language;
		}
	});
page1.add(myButton4);
var myButton5 = new SMF.UI.TextButton({
		left : "5%",
		top : "70%",
		width : "40%",
		height : "10%",
		text : "app name",
		onPressed : function () {
			myLabel5.text = Application.smartfaceAppName;
		}
	});
page1.add(myButton5);
var myButton6 = new SMF.UI.TextButton({
		left : "5%",
		top : "85%",
		width : "40%",
		height : "10%",
		text : "version",
		onPressed : function () {
			myLabel6.text = Application.version;
		}
	});
page1.add(myButton6);

Also, add these buttons to your page. Application will look like

After you press the buttons, application will look like :

      

Events

The events of Application are :

NAMEDESCRIPTION
onApplicationCallReceived
Triggered when application is called by another application.
onDeviceShaked
Triggered when device is shaked.
onExit
Triggered before exiting application.
onFirstStart
Triggered after application is started first time.
onMaximize
Triggered after application is maximized.
onMinimize
Triggered after application is minimized.
onReceivedNotification
Triggered after a push or local notification recieved.
onSMSReceived
Triggered after an SMS recieved.
onStart
Triggered when application is started.

Now, let's simply see how events can be used. In order to see if onStart event runs or not, simply write the code block below in app.js :

function generatePIN() {
	var generatedPIN = Math.floor((Math.random() * 10000) + 1);
	return generatedPIN;
}

Application.onDeviceShaked = function (e) {
	var newPIN = generatePIN();
	alert("onDeviceShaked event" + "\n " + "Your new PIN = " + newPIN);
}