Friday, November 30, 2018

Expandable row with section header in segment

Create  segment:
function Dynseg2(){
  var objsec1 = {"flxSection":{skin:"sknlblhdr"},"lblshirtbrand":{isVisible:true,text:"Fruits"},"imgplus":{isVisible:true,src:"vision.png"},"btnplus":{isVisible:true}};
   var objsec2 = {"flxSection":{skin:"sknlblhdr"},"lblshirtbrand":{isVisible:true,text:"Chocolates"},"imgplus":{isVisible:true,src:"vision.png"},"btnplus":{isVisible:true}};
  var segarray =[];
   var segarray1 =[];
  var segarray2 =[];
  var obj;
  for(var i = 0;i <5 ; i++){
  if(i === 0 || i === "0"){
    obj = {"flxR2":{isVisible:false,skin:"sknflxr"},"lbltype1":{isVisible:true,text:"Orange",skin:"sknlblr"}};
  }else if(i === 1 || i === "1"){
    obj = {"flxR2":{isVisible:false,skin:"sknflxr"},"lbltype1":{isVisible:true,text:"Apple",skin:"sknlblr"}};
  }else if(i === 2 || i === "2"){
    obj = {"flxR2":{isVisible:false,skin:"sknflxr"},"lbltype1":{isVisible:true,text:"Mango",skin:"sknlblr"}};
  }else if(i === 3 || i === "3"){
    obj = {"flxR2":{isVisible:false,skin:"sknflxr"},"lbltype1":{isVisible:true,text:"Banana",skin:"sknlblr"}};
  }else if(i === 4 || i === "4"){
    obj = {"flxR2":{isVisible:false,skin:"sknflxr"},"lbltype1":{isVisible:true,text:"Grabes",skin:"sknlblr"}};
  }
    segarray.push(obj);
  }
  for(var k = 0;k <5 ; k++){
  if(k === 0 || k === "0"){
    obj = {"flxR2":{isVisible:false,skin:"sknflxr"},"lbltype1":{isVisible:true,text:"Munch",skin:"sknlblr"}};
  }else if(k === 1 || k === "1"){
    obj = {"flxR2":{isVisible:false,skin:"sknflxr"},"lbltype1":{isVisible:true,text:"Berk",skin:"sknlblr"}};
  }else if(k === 2 || k === "2"){
    obj = {"flxR2":{isVisible:false,skin:"sknflxr"},"lbltype1":{isVisible:true,text:"Bolo",skin:"sknlblr"}};
  }else if(k === 3 || k === "3"){
    obj = {"flxR2":{isVisible:false,skin:"sknflxr"},"lbltype1":{isVisible:true,text:"Kitkat",skin:"sknlblr"}};
  }else if(k === 4 || k === "4"){
    obj = {"flxR2":{isVisible:false,skin:"sknflxr"},"lbltype1":{isVisible:true,text:"Lays",skin:"sknlblr"}};
  }
    segarray1.push(obj);
  }
 
  for(var j = 0;j <2 ; j++){
     if(j === 0 || j === "0"){
    segarray2.push([objsec1,segarray]);
     }else if(j === 1 || j === "1"){
        segarray2.push([objsec2,segarray1]);
     }
     }
  frmQAsecRow.Seg.setData(segarray2);
}



function onrowclicofsegsection(event){
  var segarray2 =[];
  var selectedIndex= event.sectionIndex;

  var datoseg = frmQAsecRow.Seg.data;
  var selectsedata = datoseg[selectedIndex][0];
  var rowdata = frmQAsecRow.Seg.data[selectedIndex][1];
  for (var i = 0; i < rowdata.length; i++) {
    if(rowdata[i].flxR2.isVisible === false){
    rowdata[i].flxR2 = {isVisible:true,skin:"sknflxr"};
    }else if(rowdata[i].flxR2.isVisible === true){
    rowdata[i].flxR2 = {isVisible:false,skin:"sknflxr"};
    }
 }
  segarray2  = [selectsedata,rowdata];
  frmQAsecRow.Seg.setSectionAt(segarray2, selectedIndex);
}

OUTPUT:


Thursday, November 29, 2018

Question & answer like segment row expandable view

function onrowclickofseg(){
  var cisshow;
  var selectedIndex= frmQA.Seg.selectedRowIndex[1];
  if(frmQA.Seg.selectedRowItems[0].flxQA2.isVisible === true){
    cisshow = false;
  }else{
    cisshow = true;
  }
     var obj = {"flxQA1":{isVisible:true},"lblQ":{isVisible:true,text:"Explain the difference between a class and an object",skin:"sknlbltmp"},"flxQA2":{isVisible:cisshow},"flxA":{isVisible:true},"lblA":{isVisible:true,text:"Is answer",skin:"sknlbltmpans"},"imgArrow":{isVisible:true,src:"forward.png"}};
     frmQA.Seg.setDataAt(obj,selectedIndex,0);
}

//Dynamic segment
function Dynseg(){
  var segarray =[];
for(var i = 0;i <5 ; i++){
  var obj = {"flxQA1":{isVisible:true},"lblQ":{isVisible:true,text:"Explain the difference between a class and an object",skin:"sknlbltmp"},"flxQA2":{isVisible:false},"flxA":{isVisible:true},"lblA":{isVisible:true,text:"Is answer",skin:"sknlbltmpans"},"imgArrow":{isVisible:true,src:"forward.png"}};
  segarray.push(obj);
}
frmQA.Seg.setData(segarray);
}


OUTPUT:

Tuesday, November 27, 2018

Add list data in dynamically

var Receiverdetail = {};

function addMngrlist(){
  var SessionId =  kony.store.getItem("usersessionid");
  var serviceName = "Listoutbyusertype";
  var serviceType = "online";
  var objSvc = kony.sdk.getCurrentInstance().getObjectService(serviceName, {"access": serviceType});
  var objectName = "";
  var dataObject = "";
  if(kony.store.getItem("sessionuserLogin").usertype === 1 || kony.store.getItem("sessionuserLogin").usertype === "1"){
    objectName = "listoutforemployee";
    dataObject = new kony.sdk.dto.DataObject(objectName);
    dataObject.odataUrl = "$filter=emptype ne 1";
  }
  if(kony.store.getItem("sessionuserLogin").usertype === 2 || kony.store.getItem("sessionuserLogin").usertype === "2"){
    objectName = "listoutforManager";
    dataObject = new kony.sdk.dto.DataObject(objectName);
    dataObject.odataUrl = "$filter=emptype eq 3";
  }
  var options = {"dataObject":dataObject};
  objSvc.fetch(options, OSListManagerandceo, ONFailureListManagerandceo);
}


function OSListManagerandceo(res){
  var i = 0;
  Arrayoflist = [];

  if(((res.records).length) >0){
    for(i = 0;i < (res.records).length;i++){
      if(((res.records)[i]).emptype === "2" || ((res.records)[i]).emptype === 2){
        Arrayoflist.push([parseInt(((res.records)[i]).id),((res.records)[i]).empname + "(Manager)"]);

      }
      if(((res.records)[i]).emptype === "3" || ((res.records)[i]).emptype === 3){
        Arrayoflist.push([parseInt(((res.records)[i]).id),((res.records)[i]).empname + "(CEO)"]);
      }
    }

  }else{
    if(kony.store.getItem("sessionuserLogin").usertype === 1 || kony.store.getItem("sessionuserLogin").usertype === "1"){
      Arrayoflist.push(["","Select Manager/CEO"]);
    }else if(kony.store.getItem("sessionuserLogin").usertype === 2 || kony.store.getItem("sessionuserLogin").usertype === "2"){
      Arrayoflist.push(["","Select CEO"]);
    }
  }
  if(kony.application.getCurrentForm().id === "frmRequest"){
    frmRequest.lstmanager.masterData = Arrayoflist;
  }else if(kony.application.getCurrentForm().id === "frmMedical"){
    frmMedical.lstmanager.masterData = Arrayoflist;
  }else if(kony.application.getCurrentForm().id === "frmTravel"){
    frmTravel.lstmanager.masterData = Arrayoflist;
  }
}
function ONFailureListManagerandceo(res){
  alert("failuer in listoutforemployee" + JSON.stringify(res));

}

basic coding standard


Widget Prefix
HBox hbx
VBox vbx
TabPane tbp
Tab tab
Label lbl
Button btn
Browser brws
TextBox txt
TextArea txa
Calendar cal
ComboBox cmb
ListBox lst
CheckBoxGroup chk
RadioButtonGroup rbt
Link lnk
Line lin
Image img
MenuItem mnu
Segment seg
ImageGallery igl
HorizontalImageStrip his
Phone phn
Camera cam
Switch swt
PickerView pkv

Using finger touch with this function

function isAuthUsingTouchSupported()
{
var status = kony.localAuthentication.getStatusForAuthenticationMode(constants.LOCAL_AUTHENTICATION_MODE_TOUCH_ID);
if(status == 5000)
{
   
        alert("Touch ID for FingerPrint Sample ");
authUsingTouchID();
}

  else
{
var msg = "Touch ID is not configured on this device.Authentication returned a status ::"+status;
kony.ui.Alert({message: msg+" "+status,
alertType: constants.ALERT_TYPE_INFO,
yesLabel:"Close"},
{});
}
}




function statusCB(status,message)
{

if(status == 5000)
{
   
      frmAddAccount.show();
   
}

  else if(status == 5001)
      {
   
       alert("try again");
      }
  else
{
var messg = status+": "+message;
kony.ui.Alert({message: messg,
alertType: constants.ALERT_TYPE_INFO,
yesLabel:"Close"},
{});
}
}



function authUsingTouchID()
{
 
  var config = {"promptMessage" : "PLEASE AUTHENTICATE USING YOUR TOUCH ID"};
kony.localAuthentication.authenticate(
constants.LOCAL_AUTHENTICATION_MODE_TOUCH_ID,statusCB,config);
}






Monday, November 26, 2018

common alert syntax with sample

function validated(){
if(frmTest.text1.text === null || frmTest.text1.text === "" || frmTest.text1.text === undefined || frmTest.text1.text === " "){
CommonAlrt("Please Enter text");
}
}
function CommonAlrt(response)
{
var basicConf = {message: response,alertType: constants.ALERT_TYPE_CONFIRMATION,alertTitle: "Sample Alert",yesLabel:"yes",
noLabel: "no", alertHandler: alertres};
var pspConf = {};
var infoAlert = kony.ui.Alert(basicConf,pspConf);
 
}

function alertres(response){
  if(response){
  alert("its working yes");
  }else{
    return false;
  }
}

Over basic widget from get value and doreset it


var arrlist =[];
var OnSelecteddate = false;
function validte(rsponse){

  if(rsponse === null || rsponse === "" || rsponse ===" "|| rsponse === undefined){
    return true;
  }else{
    return false;
  }
}
function OnValidateDetail(){
  if(kony.store.getItem("AUDetails") !== null){
    arrlist = kony.store.getItem("AUDetails");
  }
  if(validte(frmRegistor.txtName.text)){
    alert("Please enter username");
    frmRegistor.txtName.setFocus(true);
    return false;
  }
  if(validte(frmRegistor.txtPW.text)){
    alert("Please enter password");
    frmRegistor.txtPW.setFocus(true);
    return false;
  }
  if(validte(frmRegistor.txtCPW.text)){
    alert("Please enter confirm password");
    frmRegistor.txtCPW.setFocus(true);
    return false;
  }
  if(frmRegistor.txtPW.text !== frmRegistor.txtCPW.text){
    alert("Please check confirm password");
    frmRegistor.txtCPW.setFocus(true);
    return false;
  }

  if(validte(frmRegistor.rbtGender.selectedKeyValue)){
    alert("Please select gender");
    frmRegistor.rbtGender.setFocus(true);
    return false;
  }

  if(OnSelecteddate === false){
    var currentdate = new Date();
   
    //OnSelecteddate = true;
  }
  if(validte(frmRegistor.txABOX.text)){
    alert("Please select address");
    frmRegistor.txABOX.setFocus(true);
    return false;
  }

  var a = "";
  if(frmRegistor.CHKBox.selectedKeyValues !== null){
    for(var i = 0; i< frmRegistor.CHKBox.selectedKeyValues.length; i++){
      if(a.length >0){
        a += "/"; 
      }
      a += frmRegistor.CHKBox.selectedKeyValues[i][1];
    }
  }else if(frmRegistor.CHKBox.selectedKeyValues === null){
    alert("Please select Skill");
    return false;
  }
  if(validte(frmRegistor.rchtxtBox.text)){
    alert("Please enter richtext");
    frmRegistor.rchtxtBox.setFocus(true);
    return false;
  }
  if(frmRegistor.lstBox.selectedKey === "Wish0"){
    alert("Please select option");
    frmRegistor.lstBox.setFocus(true);
    return false;
  }
  if(frmRegistor.sldbox.selectedValue === "0"){
    alert("Please give rating 0 above");
    frmRegistor.sldbox.setFocus(true);
    return false;
  }
  if(validte(frmRegistor.pckrDate.selectedKeyValues[2][1])){
    alert("Please select rating above of zero");
    frmRegistor.pckrDate.setFocus(true);
    return false;
  }
  if(validte(frmRegistor.imageshow.base64)){
    alert("Please Update profile picture");
    return false;
  }
  frmDetailofRegistor.lblNAME.text = frmRegistor.txtName.text; 
  frmDetailofRegistor.lblgender.text = frmRegistor.rbtGender.selectedKeyValue[1];
  frmDetailofRegistor.lbladr.text = frmRegistor.txABOX.text;
  frmDetailofRegistor.lblSkills.text = a;
  frmDetailofRegistor.txtrichConvert.text =frmRegistor.rchtxtBox.text;
  frmDetailofRegistor.lblOption.text = frmRegistor.lstBox.selectedKeyValue[1];
  frmDetailofRegistor.lblrating.text = frmRegistor.sldbox.selectedValue;
  if(frmRegistor.btnswitch.selectedIndex === 0.0){
    frmDetailofRegistor.lblWilling.text = "Willing";

  }else{
    frmDetailofRegistor.lblWilling.text = "Not Willing";
  }
  frmDetailofRegistor.lblEntryDate.text = frmRegistor.pckrDate.selectedKeyValues[2][1] +"/"+ frmRegistor.pckrDate.selectedKeyValues[1][1] +"/"+ frmRegistor.pckrDate.selectedKeyValues[0][1];

  var obj ={ "Uimg":frmRegistor.imageshow.base64,"Uname":frmRegistor.txtName.text,"Upw":frmRegistor.txtPW.text,
            "Ucpw":frmRegistor.txtCPW.text,"Ugender":frmRegistor.rbtGender.selectedKeyValue[1],"Udob":frmDetailofRegistor.lblADOB.text,
            "Uaddress":frmRegistor.txABOX.text,"Uskills":a,"Urichtext":frmRegistor.rchtxtBox.text,
            "Uoption":  frmRegistor.lstBox.selectedKeyValue[1],"Urating":frmRegistor.sldbox.selectedValue,"Uwilling":frmDetailofRegistor.lblWilling.text,
            "Uentrydate":frmRegistor.pckrDate.selectedKeyValues[2][1] +"/"+ frmRegistor.pckrDate.selectedKeyValues[1][1] +"/"+ frmRegistor.pckrDate.selectedKeyValues[0][1],
            "IsActive":false};
  arrlist.push(obj);
  kony.store.setItem("AUDetails", arrlist);
  frmLogin.show();
  return false;
}


function onSelection(evenobj){
  frmDetailofRegistor.lblADOB.text = evenobj.day + "/" + evenobj.month + "/" +evenobj.year;
  OnSelecteddate = true;
}

function imgFetchMedia(){
  var querycontext = {mimetype:"image/*"};
  var Status = kony.phone.openMediaGallery(onselectioncallback, querycontext);

  function onselectioncallback(rawBytes)
  {


    if (rawBytes === null){
      alert("please select images");
    }else{
      var base64Str = kony.convertToBase64(rawBytes);
      frmRegistor.imageshow.base64 = base64Str;

      frmDetailofRegistor.imageofuser.base64 = base64Str; 
    }

  }
}
function img(){
  var rawbytes = frmRegistor.cameraid.rawBytes;
  var base64Str = kony.convertToBase64(rawbytes);
  frmRegistor.imageshow.base64 = base64Str;
  frmDetailofRegistor.imageofuser.base64 = base64Str; 
}

function doresetR(){

  frmRegistor.imageshow.src="";
  frmRegistor.txtName.text ="";
  frmRegistor.txtPW.text ="";
  frmRegistor.txtCPW.text ="";
  frmRegistor.txABOX.text="";
  frmRegistor.lstBox.selectedKey = "Wish0";
  frmRegistor.rbtGender.selectedKey ="rbg1";
  frmRegistor.sldbox.selectedValue ="0";
  frmRegistor.CHKBox.selectedKeys = [""];
   var currentdate = new Date();
  frmRegistor.calBox.dateComponents = currentdate.getDate() +"/"+ currentdate.getMonth() +"/"+ currentdate.getFullYear();
  frmRegistor.btnswitch.selectedIndex = 0.0;
  frmRegistor.txtName.setFocus(true);
  return false;
}

Gesture swipe using method and functions

function myTap(myWidget,gestureInfo)
{
     
  alert(" single finger double tap Gesture detected");
}

function myTapp(myWidget,gestureInfo)
{
  alert("double finger single Tap Gesture detected");
}

function mySwip(myWidget,gestureInfo)
{
 
 if(gestureInfo.swipeDirection === 1){
    alert("Swiped left");
  }
  else if(gestureInfo.swipeDirection === 2){
    alert("Swiped right");
  }
 
}
function mySwipp(myWidget,gestureInfo)
{
  alert(" 2 finger swipe  Gesture detected");
}
function myLong(myWidget,gestureInfo)
{
  alert("long press Gesture detected");
}
function myLongg(myWidget,gestureInfo)
{
  alert(" 8 second long press Gesture detected");
}
function myPinch(myWidget,gestureInfo)
{
  alert(" Pinch detect");
}

function myPAN(myWidget,gestureInfo)
{
  alert(" Rotation detect");
}
var setupTblTap = {fingers:1,taps:2};
var setupTblTapp = {fingers:2,taps:1};
var setupTblSwip = {fingers: 1, swipeDirection: 1};
var setupTblSwipp = {fingers: 2};
var setupTblLong = {pressDuration:4};
var setupTblLongg = {pressDuration:8};
var setuppinch = {fingers:2, continuousEvents:true};
//var setrotation ={fingers:2, continuousEvents :true};
var setPan ={fingers:1, continuousEvents :true};
function loadonpostshow(){
frmGesture.flxMain.addGestureRecognizer(1,setupTblTap,myTap);
frmGesture.flxMain.addGestureRecognizer(1,setupTblTapp,myTapp);
frmGesture.flxMain.addGestureRecognizer(2,setupTblSwip,mySwip);
frmGesture.flxMain.addGestureRecognizer(2,setupTblSwipp,mySwipp);
frmGesture.flxMain.addGestureRecognizer(3,setupTblLong,myLong);
frmGesture.flxMain.addGestureRecognizer(3,setupTblLong,myLongg);
frmGesture.flxMain.addGestureRecognizer(6,setuppinch,myPinch);
frmGesture.flxMain.img.addGestureRecognizer(4,setPan,myPAN);
}
 
call above function loadonpostshow() which page you want to use

App basic API with function sample

//Type your code here
function getcurfrm(){
  alert(kony.application.getCurrentForm().id);
  return false;
}
function getprefrm(){ 
  alert(kony.application.getPreviousForm().id);
  return false;
}
function getshowload(){
  kony.application.showLoadingScreen("sknloading","Loading...",constants.
LOADING_SCREEN_POSITION_ONLY_CENTER, false,true,{enableMenuKey:true,
enableBackKey:true, progressIndicatorColor : "ffffff77"});
 
}
function gethideload(){
  kony.application.dismissLoadingScreen();
}
function openURLshow()
{
  //Accessing an external web page : http://www.google.com
  kony.application.openURL("http://hitechkd.blogspot.com/");
}
function exitappli()
{
   try{
         kony.application.exit();
      }
   catch(Error)
      {
         alert("Exception While getting exiting the application  : "+Error);
      }
}

function OSfreeM()
{
   var freememory = kony.os.freeMemory();
alert(freememory);
}
function OSDinfo()
{
   var deviceInfo = kony.os.deviceInfo();
for (var key in deviceInfo)
{
              if(key === "version"){
                 DeviceinfoPopup.LlblVersion.text =deviceInfo[key];
                 }
              if(key === "deviceHeight"){
                 DeviceinfoPopup.LlblDeviceHieght.text =deviceInfo[key];
                 }
              if(key === "deviceWidth"){
                 DeviceinfoPopup.LlblDeviceWidth.text =deviceInfo[key];
                 }
              if(key === "name"){
                 DeviceinfoPopup.LlblName.text =deviceInfo[key];
                 }
              if(key === "model"){
                 DeviceinfoPopup.LlblModel.text =deviceInfo[key];
                 }
       
}
  DeviceinfoPopup.show();
}
function popupdismis(){
  DeviceinfoPopup.dismiss();
}
function OSDGPS()
{
   alert(kony.os.hasGPSSupport());
}
function OSCAMRA()
{
   alert(kony.os.hasCameraSupport());
}
function OSTOUCH()
{
   alert(kony.os.hasTouchSupport());
}
 var i = 0;
function timerFuncstart() //nested function
{
 timercallbackcancel();
i = i+1;
frmtimer.lbltimer.text = i+" secs ";
}
function strat(){
kony.timer.schedule("mytimer12",timerFuncstart, 5, true);
}

//nested function
function setcall1(){
  i = 0;
  frmtimer.lbltimer.text = i+" secs";
}
function timerFuncCallBack()
{
  alert("innovike");
kony.timer.setCallBack("mytimer12",setcall1);
}


function timercallbackcancel()
{

try
{
kony.timer.cancel("mytimer12");
}
catch(err)
{
alert("error in second button onclick and err is:: "+err);
}
}

NFI deep link sample

function NFIfunctiondeep()
{
  try{
    var intent = java.import("android.content.Intent");
    var KonyMain = java.import("com.konylabs.android.KonyMain");

    intent = KonyMain.getAppContext().getPackageManager().getLaunchIntentForPackage("com.orgname.NadikaKart");
    KonyMain.getAppContext().startActivity(intent);

  }catch(error)
  {
    alert(error);
  }

}

Search by WIDGET in segment

function getSearchResult(mData, searchValue) {

  if(ArrayofRequestlistseg !== null){
    var arr3 =[];
    arr3 = ArrayofRequestlistseg;
    var length = arr3.length;
    var sData = [];

    for ( i = 0; i < length; i++) {

      if (arr3[i].lblToMangerEmpId !== null || arr3[i].lblToMangerEmpId !== undefined) {

        var txt1 = "";
        if (arr3[i].lblToMangerEmpId !== null && arr3[i].lblToMangerEmpId !== undefined) {

          txt1 = arr3[i].lblToMangerEmpId;

        }
        var pattern = searchValue.text.trim().toUpperCase();

        if (txt1.toUpperCase().search(pattern) !== -1) {
          sData.push(arr3[i]);
        }
      }
    }
    if(sData.length > 0){
      frmDashboard.segmentmain.setData(sData);
    }else{
      sData = [];
      frmDashboard.segmentmain.setData(sData);
    }
  }else{
    return false;
  }
}

function refreshseg(){

  frmDashboard.txtSearchEmpID.text ="";
  if(ArrayofRequestlistseg !== null){
    var arr2 =[];
    arr2 = ArrayofRequestlistseg;
    frmDashboard.segmentmain.setData(arr2);

  }

}

Map function

function getPosition(){
  try{
    var positionoptions = {timeout: 15000};
    frmMap.mapaddress.zoomLevel=15;
    kony.location.getCurrentPosition(successcallback, errorcallback, positionoptions);
  }catch(error)
    {
      alert("error"+error);
    }
}

function successcallback(position){
  try{
  var lat = position.coords.latitude;
  var long = position.coords.longitude; 
  var locationData = [{
           lat: lat,
       lon : long,
       image : "dest.png",
           desc: "your location",
           name: "location"
        }];
  frmMap.mapaddress.locationData = locationData;
    }catch(error)
    {
      alert("error"+error);
    }
}

function errorcallback(positionerror){
   try{
    var errorMesg = "Error code: " + positionerror.code;
    errorMesg = errorMesg  + " message: " + positionerror.message;
    alert(errorMesg);
     }catch(error)
    {
      alert("error"+error);
    }
}

Kony call function

function call()
{
  try{
var Intent = java.import("android.content.Intent");
var KonyMain = java.import("com.konylabs.android.KonyMain");
var uri = java.import("android.net.Uri");

// var launchIntent = getPackageManager().getLaunchIntentForPackage("com.orgname.firstLogin");
var intent = new Intent(Intent.ACTION_CALL);
intent.setData(uri.parse("tel:" + ___________));//change the number
KonyMain.getAppContext().startActivity(intent);

}catch(err){
  alert("Error "+JSON.stringify(err));

}
}

show in pic Image tag

function img(){
  var rawbytes = frmRegistor.cameraid.rawBytes;
  var base64Str = kony.convertToBase64(rawbytes);
  frmRegistor.imageshow.base64 = base64Str;
  frmDetailofRegistor.imageofuser.base64 = base64Str;
}

Kony Store using for array store


Set value in kony store setitem:


var obj ={ "Uimg":frmRegistor.imageshow.base64,"Uname":frmRegistor.txtName.text,"Upw":frmRegistor.txtPW.text,
            "Ucpw":frmRegistor.txtCPW.text,"Ugender":frmRegistor.rbtGender.selectedKeyValue[1],"Udob":frmDetailofRegistor.lblADOB.text,
            "Uaddress":frmRegistor.txABOX.text,"Uskills":a,"Urichtext":frmRegistor.rchtxtBox.text,
            "Uoption":  frmRegistor.lstBox.selectedKeyValue[1],"Urating":frmRegistor.sldbox.selectedValue,"Uwilling":frmDetailofRegistor.lblWilling.text,
            "Uentrydate":frmRegistor.pckrDate.selectedKeyValues[2][1] +"/"+ frmRegistor.pckrDate.selectedKeyValues[1][1] +"/"+ frmRegistor.pckrDate.selectedKeyValues[0][1],
            "IsActive":false};
  arrlist.push(obj);
  kony.store.setItem("AUDetails", arrlist);

Get value in kony store getitem:

kony.store.getItem("AUDetails");

Kony loader Operation

Show:
function getshowload(){
  kony.application.showLoadingScreen("sknloading","Loading...",constants.
LOADING_SCREEN_POSITION_ONLY_CENTER, false,true,{enableMenuKey:true,
enableBackKey:true, progressIndicatorColor : "ffffff77"});

}

Dismiss:
function gethideload(){
  kony.application.dismissLoadingScreen();
}

Kony Popup Operation for device show

Show Popup:
function OSDinfo()
{
   var deviceInfo = kony.os.deviceInfo();
for (var key in deviceInfo)
{
              if(key === "version"){
                 DeviceinfoPopup.LlblVersion.text =deviceInfo[key];
                 }
              if(key === "deviceHeight"){
                 DeviceinfoPopup.LlblDeviceHieght.text =deviceInfo[key];
                 }
              if(key === "deviceWidth"){
                 DeviceinfoPopup.LlblDeviceWidth.text =deviceInfo[key];
                 }
              if(key === "name"){
                 DeviceinfoPopup.LlblName.text =deviceInfo[key];
                 }
              if(key === "model"){
                 DeviceinfoPopup.LlblModel.text =deviceInfo[key];
                 }
       
}
  DeviceinfoPopup.show();
}
Dismiss Popup:
function popupdismis(){
  DeviceinfoPopup.dismiss();
}

Kony Timer

Set Function:
//nested function
function setcall1(){
  i = 0;
  frmtimer.lbltimer.text = i+" secs";
}
Call back Function:
function timerFuncCallBack()
{
  alert("innovike");
kony.timer.setCallBack("mytimer12",setcall1);
}

Callback Cancel Function:
function timercallbackcancel()
{

try
{
kony.timer.cancel("mytimer12");
}
catch(err)
{
alert("error in second button onclick and err is:: "+err);
}
}

Fetch data from basic widget and show it on Segment

Call it while Submit form button:
function OnValidateDetail(){
  if(kony.store.getItem("AUDetails") !== null){
    arrlist = kony.store.getItem("AUDetails");
  }
  if(validte(frmRegistor.txtName.text)){
    alert("Please enter username");
    frmRegistor.txtName.setFocus(true);
    return false;
  }
  if(validte(frmRegistor.txtPW.text)){
    alert("Please enter password");
    frmRegistor.txtPW.setFocus(true);
    return false;
  }
  if(validte(frmRegistor.txtCPW.text)){
    alert("Please enter confirm password");
    frmRegistor.txtCPW.setFocus(true);
    return false;
  }
  if(frmRegistor.txtPW.text !== frmRegistor.txtCPW.text){
    alert("Please check confirm password");
    frmRegistor.txtCPW.setFocus(true);
    return false;
  }

  if(validte(frmRegistor.rbtGender.selectedKeyValue)){
    alert("Please select gender");
    frmRegistor.rbtGender.setFocus(true);
    return false;
  }

  if(OnSelecteddate === false){
    var currentdate = new Date();
    frmDetailofRegistor.lblADOB.text = currentdate.getDate() +"/"+ currentdate.getMonth() +"/"+ currentdate.getFullYear();
    //OnSelecteddate = true;
  }
  if(validte(frmRegistor.txABOX.text)){
    alert("Please select address");
    frmRegistor.txABOX.setFocus(true);
    return false;
  }

  var a = "";
  if(frmRegistor.CHKBox.selectedKeyValues !== null){
    for(var i = 0; i< frmRegistor.CHKBox.selectedKeyValues.length; i++){
      if(a.length >0){
        a += "/";
      }
      a += frmRegistor.CHKBox.selectedKeyValues[i][1];
    }
  }else if(frmRegistor.CHKBox.selectedKeyValues === null){
    alert("Please select Skill");
    return false;
  }
  if(validte(frmRegistor.rchtxtBox.text)){
    alert("Please enter richtext");
    frmRegistor.rchtxtBox.setFocus(true);
    return false;
  }
  if(frmRegistor.lstBox.selectedKey === "Wish0"){
    alert("Please select option");
    frmRegistor.lstBox.setFocus(true);
    return false;
  }
  if(frmRegistor.sldbox.selectedValue === "0"){
    alert("Please give rating 0 above");
    frmRegistor.sldbox.setFocus(true);
    return false;
  }
  if(validte(frmRegistor.pckrDate.selectedKeyValues[2][1])){
    alert("Please select rating above of zero");
    frmRegistor.pckrDate.setFocus(true);
    return false;
  }
  if(validte(frmRegistor.imageshow.base64)){
    alert("Please Update profile picture");
    return false;
  }
  frmDetailofRegistor.lblNAME.text = frmRegistor.txtName.text;
  frmDetailofRegistor.lblgender.text = frmRegistor.rbtGender.selectedKeyValue[1];
  frmDetailofRegistor.lbladr.text = frmRegistor.txABOX.text;
  frmDetailofRegistor.lblSkills.text = a;
  frmDetailofRegistor.txtrichConvert.text =frmRegistor.rchtxtBox.text;
  frmDetailofRegistor.lblOption.text = frmRegistor.lstBox.selectedKeyValue[1];
  frmDetailofRegistor.lblrating.text = frmRegistor.sldbox.selectedValue;
  if(frmRegistor.btnswitch.selectedIndex === 0.0){
    frmDetailofRegistor.lblWilling.text = "Willing";

  }else{
    frmDetailofRegistor.lblWilling.text = "Not Willing";
  }
  frmDetailofRegistor.lblEntryDate.text = frmRegistor.pckrDate.selectedKeyValues[2][1] +"/"+ frmRegistor.pckrDate.selectedKeyValues[1][1] +"/"+ frmRegistor.pckrDate.selectedKeyValues[0][1];

  var obj ={ "Uimg":frmRegistor.imageshow.base64,"Uname":frmRegistor.txtName.text,"Upw":frmRegistor.txtPW.text,
            "Ucpw":frmRegistor.txtCPW.text,"Ugender":frmRegistor.rbtGender.selectedKeyValue[1],"Udob":frmDetailofRegistor.lblADOB.text,
            "Uaddress":frmRegistor.txABOX.text,"Uskills":a,"Urichtext":frmRegistor.rchtxtBox.text,
            "Uoption":  frmRegistor.lstBox.selectedKeyValue[1],"Urating":frmRegistor.sldbox.selectedValue,"Uwilling":frmDetailofRegistor.lblWilling.text,
            "Uentrydate":frmRegistor.pckrDate.selectedKeyValues[2][1] +"/"+ frmRegistor.pckrDate.selectedKeyValues[1][1] +"/"+ frmRegistor.pckrDate.selectedKeyValues[0][1],
            "IsActive":false};
  arrlist.push(obj);
  kony.store.setItem("AUDetails", arrlist);
  frmLogin.show();
  return false;
}

How to specific row add in segment for section

var Arr =[];
var OBJarr =[];

var i = 0;
var Dumarr =[];

function subdat(){
  if(validate(frmAdmin.txtPname.text)){
    alert("Please enter product");
    frmAdmin.txtPname.setFocus(true);
    return false;
  }
  if(validate(frmAdmin.txttype1.text)){
    alert("Please enter size option");
    frmAdmin.txttype1.setFocus(true);
    return false;
  }
  if(validate(frmAdmin.txttype2.text)){
    alert("Please enter size option");
    frmAdmin.txttype2.setFocus(true);
    return false;
  }
  if(validate(frmAdmin.txttype3.text)){
    alert("Please enter size option");
    frmAdmin.txttype3.setFocus(true);
    return false;
  }
  var isexist = false;
  var dummyi = 0;
  if(Arr.length >0){
    for(i =0; i < Arr.length;i++){
      if(frmAdmin.txtPname.text === Arr[i][0].lblhdr1.text){
        isexist = true;
        dummyi = i;
        break;
      }
    }
    if(isexist === true){
      Arr[dummyi][1].push({"LBL1": frmAdmin.txttype1.text ,"LBL2": frmAdmin.txttype3.text, "LBL3": frmAdmin.txttype3.text});
      isexist =false;
      dummyi = 0;
    }else{
      OBJarr.push({"lblhdr1":{text:frmAdmin.txtPname.text,isVisible:true}},[{"LBL1": frmAdmin.txttype1.text ,"LBL2": frmAdmin.txttype3.text, "LBL3": frmAdmin.txttype3.text}]);
      Arr.push(OBJarr);
    }

  }else{
    OBJarr.push({"lblhdr1":{text:frmAdmin.txtPname.text,isVisible:true}},[{"LBL1": frmAdmin.txttype1.text ,"LBL2": frmAdmin.txttype3.text, "LBL3": frmAdmin.txttype3.text}]);
    Arr.push(OBJarr);
  }
  OBJarr =[];
  frmsec.seg.setData(Arr);
  frmAdmin.destroy();
  frmsec.show();
}//

function setseg(){

  Arr.push([{"lblhdr1":"KAREEM"},[{"LBL1":"FIRST","LBL2":"SECOND"}]]);
  frmsec2.seg.setData(Arr);
  alert(frmsec2.seg.data);
}

function for Arithmedic calculator

function ArithCalc(){
  var CtxtArea = frmCalc.txtOutput.text;
  var arrplus = CtxtArea.split('+');
    var arrminus = CtxtArea.split('-');
    var arrDivide = CtxtArea.split('/');
   var arrPercent = CtxtArea.split('%');
     var arrMul = CtxtArea.split('*');
 //alert(parseInt(arrminus[0]) - parseInt(arrminus[1]));

  if(arrplus.length >0){
      frmCalc.txtOutput.text = (parseInt(arrplus[0]) + parseInt(arrplus[1]));
  }else if(arrminus.length >0){
    frmCalc.txtOutput.text = ""+parseInt(arrminus[0]) - parseInt(arrminus[1]);
  }else if(arrDivide.length >0){
    frmCalc.txtOutput.text = (parseInt(arrDivide[0]) / parseInt(arrDivide[1]));
  }else if(arrPercent.length >0){
    frmCalc.txtOutput.text = (parseInt(arrPercent[0]) % parseInt(arrPercent[1]));
  } else if(arrMul.length >0){
    frmCalc.txtOutput.text = (parseInt(arrMul[0]) * parseInt(arrMul[1]));
  }
}

Call Multiple button in Button click

var index = 0;
function onClickCallBack()
{
    //Write your logic here.
  //Defining the button with onClick:onClickCallBck.
index +=1;
var btnBasic ={id:"Onbutton", isVisible:true, skin:"sknbtn1", focusSkin:"btnCancel", text:"New Button" + index};
var btnLayout ={containerWeight:100, padding:[5,5,5,5], margin:[10,5,5,5], hExpand:true, vExpand:false, displayText:true};
var btnPSP ={glowEffect:true };

//Creating the button.
var Onbutton1 = new kony.ui.Button(btnBasic, btnLayout, btnPSP);
  frmTest.flxMain.add(Onbutton1);
}

Chart create by Code

function chartview()
{
  var chartObj = kdv_createColumnChartJSObject();

  var chartWidget = new kony.ui.Chart2D3D({
    "id": "chartid",
    "isVisible": true
  }, {
    "widgetAlignment": constants.WIDGET_ALIGN_CENTER,
    "contentAlignment": constants.CONTENT_ALIGN_MIDDLE_LEFT,
    "containerWeight": 100
  },
                                          chartObj);
  frmChart.flxMain.add(chartWidget);
}

//creating chart object with chart properties and chart data...
function kdv_createColumnChartJSObject()
{

  var setofdat =  kony.store.getItem("usersessionid");
  var setdata = kony.store.getItem("LSArrayDetails")[setofdat].MarkDetailofUser;

  //var setofdat =  kony.store.getItem("usersessionid");
  //kony.store.getItem("LSArrayDetails")[setofdat].MarkDetailofUser;
  var chartJSObj ={
    "chartProperties":{
      "chartHeight": 50,
      "drawEntities":["axis","grid","columnChart"],         
      "columnChart":{
        "columnId": [0],
        /////// animations
        "animations": {
          "onInitAnimation": true
        },
        "graphType": "normal",
        "dataAlignToAxis": ["primaryYAxis"],
        "plotMissingValues": "assumeZero",
        /////// bar config
        "bar": {
          "width": [400],
          "fillType": ["color"],
          "transparency": [0],
          "gradientType": ["linearTopToBottom"],
          "gradientRatios": [
            [0, 20, 50, 100]
          ],
          "color": ["0x169EECFF", "0xBE0056ff", "0xFCC40EFF", "0xff0000ff", "0x00ff00ff", "0x0000ffff"],
        },
        "border": {
          "visible": false,
          "line": {
            "color": ["0xaaaaaaff"],
            "width": [1],
            "transparency": [0]
          }
        },
        /////// chart datalabels
        "dataLabels": {
          "visible": true,
          "indicators": ["numberValue"],
          "separator": "space",
          "placement": "inside",
          "orientationAngle": 0,
          "font": {
            "size": [14],
            "family": ["Verdana"],
            "style": ["Bold"],
            "color": ["0xaaaaaaff"],
            "transparency": [0]
          },
        }
      }
    },
    "chartData":{
      "columnNames":{
        "values":["col1"]
      },
      "rowNames":{
        "values":["10th","12","UG"]
      },
      "data":{
        "col1":setdata
      }
    }
  };
  return chartJSObj;
}

Create Timer on button click

function timerFunc(){
  var da = new Date();
  frmProfile.lblDatetimeshow.text = da.toLocaleTimeString();
}

var INtrue = false;

function itimerStart() //nested function
{
  var d = new Date();
  if(INtrue === false){
    frmProfile.LblDateIn.text ="";
    frmProfile.LblDateIn.text = d.toDateString();
    frmProfile.lblStatusshow.text ="IN";
    frmProfile.LblIntime.text ="IN:";
    frmProfile.LblIntime.text = "IN:" + d.toLocaleTimeString();
    frmProfile.LblOuttime.text ="OUT:";
    INtrue = true;
    frmProfile.imgProgressstatus.setVisibility(true);
  }else if (INtrue === true) {
    frmProfile.LblDateIn.text ="";
    frmProfile.LblDateIn.text = d.toDateString();
    frmProfile.LblOuttime.text ="OUT:";
    frmProfile.LblOuttime.text = "OUT:" + d.toLocaleTimeString();
    frmProfile.imgProgressstatus.setVisibility(false);
    frmProfile.lblStatusshow.text ="OUT";
    INtrue = false;
  }
}
kony.timer.schedule("",timerFunc, 1, true);

Flex Menu Creation form App

var Ibool = true;
function showsidebaritem(eventobject) {
  function SCALE_ACTION____e241c9bdb7514fbea4bcbd4a7b0e59a6_Callback() {}
  if(Ibool === true){
    kony.application.getCurrentForm().FlxMainMenu.animate(
      kony.ui.createAnimation({
        "100": {
          "stepConfig": {
            "timingFunction": kony.anim.EASE
          },
          "width": "40%",
          "height": "100%"
        }
      }), {
        "delay": 0,
        "iterationCount": 1,
        "fillMode": kony.anim.FILL_MODE_FORWARDS,
        "duration": 0.25
      }, {
        "animationEnd": SCALE_ACTION____e241c9bdb7514fbea4bcbd4a7b0e59a6_Callback
      });
    Ibool = false;
    return false;
  }
  if(Ibool ===false){
    kony.application.getCurrentForm().FlxMainMenu.animate(
      kony.ui.createAnimation({
        "100": {
          "stepConfig": {
            "timingFunction": kony.anim.EASE
          },
          "width": "0%",
          "height": "0%"
        }
      }), {
        "delay": 0,
        "iterationCount": 1,
        "fillMode": kony.anim.FILL_MODE_FORWARDS,
        "duration": 0.25
      }, {
        "animationEnd": SCALE_ACTION____e241c9bdb7514fbea4bcbd4a7b0e59a6_Callback
      });
    Ibool = true;
    return false;
  }
}

Validation using regular expression in Javascript

Validation is an essential process in any mobile or web applications where we use forms. So I am sharing some ideas on how to do some basic validations ion Javascript using regular expressions. As this is for Javascript, there won't be much changes in other languages also.


Some regular expressions for basic validations.

"/\d/g"             : For matching any digits if present in the string.
            "/\s/g"             : For matching any whitespace character if present in the string.

            "/[a-zA-Z]/g"    : For matching any letters if present in the string.
            "/[0-9]/g"         : For matching any numbers from 0-9 if present in the string.

            "/[abc]/g"         : will check for letters inside the square bracket if present throughout the string.
            "/[a-b]/g"         : will check for items between the range given inside square bracket if present throughout the string.

            "/[a|b]/g"         : will check for any of the items given inside square bracket if present throughout the string.


Test Method

We can use mainly Javascript test() method for pattern checking.

            var pattern = new RegExp("[a-zA-Z]+");
            var str = "Hello World";
            var res = pattern.test(str);
             alert(res);

this will print true as letters are present inside the string str;

like this for checking digits present inside string, we can perform

            var pattern = new RegExp("/\d/g"); OR var pattern = new RegExp("/[0-9]/g");
            var str = "Hello World";
            var res = pattern.test(str);
             alert(res);

for checking whitespace present inside string, we can perform

            var pattern = new RegExp("/\s/g");
            var str = "Hello World";
            var res = pattern.test(str);
             alert(res);



Replace method


If we want to find a pattern in a string and change it with something else, we can use the Javascript replace() method.

If we want to remove all the whitespace characters from the string, we can perform it by

            var pattern = new RegExp("/\s/g");
            var str = "Hello World";
            var res = str.replace(pattern, "");

This will remove all the whitespace characters with empty, like this we can remove any pattern found inside a string, or replace the pattern with some other patterns

Sample code from Chandy


var DetailsofU = [];
//Type your code here
/*********************
Module name : UserLogin
Function name :validate
Description :Common validation
Author :Abdulkareem
Date :16-10-2018
***************************/
function validate(response){
  if(response === null || response === "" || response === undefined || response === " "){
    return true;
  }else{
    return false;
  }
}

// /*********************
// Module name : UserLogin
// Function name :UserloginIn
// Description :userlogin Service call in here
// Author :Abdulkareem
// Date :16-10-2018
// ***************************/


// function UserloginIn(){
//   if(validate(frmLogin2.txtUsername.text)){
//       alert("Please enter valid Username");
//       frmLogin2.txtUsername.setFocus(true);
//       return false;
//     }
//   if(validate(frmLogin2.txtPw.text)){
//   alert("Please enter password");
//     frmLogin2.txtPw.setFocus(true);
//    return false;
//   }
//   var cName = frmLogin2.txtUsername.text;
//   var cPw = frmLogin2.txtPw.text;
// var serviceName = "devUserLogin";
// var integrationObj = KNYMobileFabric.getIntegrationService(serviceName);
// var operationName =  "UserLogin";
// var data= {"username": cName,"password": cPw};
// var headers= {};
// //integrationObj.invokeOperation(operationName, headers, data, operationSuccess, operationFailure);
// integrationObj.invokeOperation(operationName, headers, data, operationSuccesslogin, operationFailurelogin);

// }


// /*********************
// Module name : UserLogin
// Function name :operationSuccesslogin
// Description :operation name of userlogin success
// Author :Abdulkareem
// Date :16-10-2018
// ***************************/
// function operationSuccesslogin(res){
//    try{
//     alert("response" + JSON.stringify(res));
//      if(res.opstatus === 0){
//        if(res.status === "Success"){
//        frmUserD.lbl1.text =res.response[0].address;
//         frmUserD.lbl2.text =res.response[0].name;
//         frmUserD.lbl3.text =res.response[0].id;
//         frmUserD.lbl4.text =res.response[0].phoneno;
//         frmUserD.lbl5.text =res.response[0].username;
//        } else{
//      alert(res.Message); 
//        }
     
//     }
//       // }
//      frmLogin2.destroy();
//      frmUserD.show();
//   }catch(error){
//     alert("Exception succussful of operationSuccess" + error);
//   }
// //code for success call back
// }


// /*********************
// Module name : UserLogin
// Function name :operationFailurelogin
// Description :operation name of userlogin failure
// Author :Abdulkareem
// Date :16-10-2018
// ***************************/

// function operationFailurelogin(res){
//   try{
//    alert("response" + JSON.stringify(res));
//   }catch(error){
//     alert("Exception succussful of operationFailure" + error);
//   }
// //code for failure call back
// }




/*********************
Module name : shoWinfo
Function name :GetUserdetailService
Description :Userdetail Service call in here
Author :Abdulkareem
Date :16-10-2018
***************************/
function GetUserdetailService(){
  loader();
  var  serviceName = "devUserLogin";
var integrationObj = KNYMobileFabric.getIntegrationService(serviceName);
var operationName =  "getDetails";
var data= {};
var headers= {};
integrationObj.invokeOperation(operationName, headers, data, operationSuccessUDetail, operationFailureUDetail);
}

/*********************
Module name : shoWinfo
Function name :operationSuccessUDetail
Description :Operation name of GetUserdetail Success
Author :Abdulkareem
Date :16-10-2018
***************************/

function operationSuccessUDetail(res){

   try{
       kony.application.dismissLoadingScreen();
    var Userlist =[];
    Userlist = res.response;
    var DataU =[];
    if(Userlist !== null){
    for(var i=0; i < Userlist.length;i++){
  var Obj={"flximagseg":{isVisible:true},"lbl1": Userlist[i].name,"lbl2": Userlist[i].phoneno,"lbl3": Userlist[i].address,"lbl4": Userlist[i].id};
    DataU.push(Obj);
    }
}
    frmActionarea.segD.setData(DataU);
    //frmLogin2.destroy();
   frmActionarea.show();
   
  }catch(error){
    alert("Exception succussful of operationFailure" + error);
  }
  //return false;
//code for failure call back
}
/*********************
Module name : shoWinfo
Function name :operationFailure
Description :Operation name of GetUserdetail Failure
Author :Abdulkareem
Date :16-10-2018
***************************/

function operationFailureUDetail(res){
  try{
    alert("response" + res);
  }catch(error){
    alert("Exception succussful of operationFailure" + error);
  }

//code for failure call back
}


/*********************
Module name : shoWinfo
Function name :loaddataB
Description :Load user details in segment
Author :Abdulkareem
Date :16-10-2018
***************************/


function loaddataB(){
  if(DetailsofU !== null){
    frmshoWinfo.segD.setData(DetailsofU);
  }
}




/*********************
Module name : shoWinfo
Function name :GetUserdetailGET
Description :Userdetail Service call in here
Author :Abdulkareem
Date :16-10-2018
***************************/
// function GetUserdetailGET(){
//   var  serviceName = "DbUserdetails";
// var integrationObj = KNYMobileFabric.getIntegrationService(serviceName);
// var operationName =  "mflearn_tbl_register_get";
// var data= {};
// var headers= {};
// integrationObj.invokeOperation(operationName, headers, data, operationSuccessUserdetailGET, operationFailureUserdetailGET);
// }
function GetUserdetailGET(){
  loader();
var serviceName = "NewuserDetailOBJ";
var serviceType = "online";
var objSvc = kony.sdk.getCurrentInstance().getObjectService(serviceName, {"access": serviceType});
var objectName = "UserDetailDMobj";
var dataObject = new kony.sdk.dto.DataObject(objectName);
  var options = {"dataObject":dataObject};
  objSvc.fetch(options, operationSuccessUserdetailGET, operationFailureUserdetailGET);
}
  /*********************
Module name : shoWinfo
Function name :operationSuccessUDetail
Description :Operation name of GetUserdetail Success
Author :Abdulkareem
Date :16-10-2018
***************************/

function operationSuccessUserdetailGET(res){
  try{
   kony.application.dismissLoadingScreen();
    var Userlist =[];
    Userlist = res.records;
    var DataU =[];
    if(Userlist !== null){
    for(var i=0; i < Userlist.length;i++){
  var Obj={"flximagseg":{isVisible:true}, "lbl1": Userlist[i].iname,"lbl2": Userlist[i].iphone,"lbl3": Userlist[i].iaddress,"lbl4": Userlist[i].ids};
    DataU.push(Obj);
    }
}
    frmshoWinfo.segD.setData(DataU);
    frmLogin2.destroy();
   frmshoWinfo.show();
  }catch(error){
    alert("Exception succussful of operationFailure" + error);
  }
//code for failure call back
}
/*********************
Module name : shoWinfo
Function name :operationFailure
Description :Operation name of GetUserdetail Failure
Author :Abdulkareem
Date :16-10-2018
***************************/

function operationFailureUserdetailGET(res){
  try{
    alert("response" + res);
  }catch(error){
    alert("Exception succussful of operationFailure" + error);
  }
//code for failure call back
}

/*********************
Module name : shoWinfo
Function name :operationFailure
Description :Operation name of GetUserdetail Failure
Author :Abdulkareem
Date :16-10-2018
***************************/

function DBobjGetuserD(){
// var serviceName = "DBNanAccess";
// var serviceType = "online";
// var objSvc = kony.sdk.getCurrentInstance().getObjectService(serviceName, {"access": serviceType});

// //Code to invoke parent object service should be present to use below code.
// var objectName = "newDetailsObj";
// var dataObject = new kony.sdk.dto.DataObject(objectName);
// //ex: dataObject.odataUrl = "$filter=ORDER_NUM eq 10001,$expand=ORDER_ITEM";
// //dataObject.odataUrl = "$select=<place-holder>,$filter=<place-holder>,$orderby=<place-holder>,$top=<place-holder>,$skip=<place-holder>,$expand=<place-holder>";
// var options = {"dataObject":dataObject};
// //'objSvc' is the instance of the parent object service.
// objSvc.fetch(options, onSuccessGetuserD, onFailureGetuserD);

}
function onSuccessGetuserD(res) {
  try{
   
    var Urget =[]; 
  if(res.opstatus === 0 || res.opstatus === "0"){
    var Userlist = [];
    Userlist = res.newDetailsObj;
    var DataU =[];
    if(Userlist !== null){
    for(var i=0; i < Userlist.length;i++){
  var Obj={"lbl1": Userlist[i].namess,"lbl2": Userlist[i].PhoneNumber,"lbl3": Userlist[i].Addressss,"lbl4": Userlist[i].id};
   DataU.push(Obj);
    }
    }
 
    frmActionarea.segD.setData(DataU);
     }
    frmActionarea.show();
  }catch(error){
  alert("error-->" + error);
  }
//Success handler
}
function onFailureGetuserD(res) {

  alert("error failure obj-->" + error);

//Failure handler
}







/*********************
Module name : UserLogin
Function name :UserloginIn
Description :userlogin Service call in here
Author :Abdulkareem
Date :16-10-2018
***************************/


function UserloginInPost(){
  if(validate(frmEntryform.txtName.text)){
      alert("Please enter Name");
      frmEntryform.txtName.setFocus(true);
      return false;
    }
  if(validate(frmEntryform.txtUsername.text)){
      alert("Please enter UserName");
      frmEntryform.txtUsername.setFocus(true);
      return false;
    }
  if(validate(frmEntryform.txtPasswords.text)){
      alert("Please enter Password");
      frmEntryform.txtPasswords.setFocus(true);
      return false;
    }
  if(validate(frmEntryform.txtAddress.text)){
      alert("Please enter Address");
      frmEntryform.txtAddress.setFocus(true);
      return false;
    }
  if(validate(frmEntryform.txtPhone.text)){
      alert("Please enter Phone");
      frmEntryform.txtPhone.setFocus(true);
      return false;
    }
  var cName = frmEntryform.txtName.text;
  var cUserName = frmEntryform.txtUsername.text;
  var cPasswords = frmEntryform.txtPasswords.text;
  var cAddress = frmEntryform.txtAddress.text;
  var cPhone= frmEntryform.txtPhone.text;
  loader();
  var serviceName = "NewuserDetailOBJ";
var serviceType = "online";
var objSvc = kony.sdk.getCurrentInstance().getObjectService(serviceName, {"access": serviceType});

 var objectName = "UserDetailDMobj";
  var dataObject = new kony.sdk.dto.DataObject(objectName);
 dataObject.addField("iname", cName);
  dataObject.addField("iusername", cUserName);
  dataObject.addField("ipassword", cPasswords);
  dataObject.addField("iaddress", cAddress);
  dataObject.addField("iphone", cPhone);
  var options = {"dataObject":dataObject};
  //'objSvc' is the instance of the parent object service.
objSvc.create(options, onSuccessUsr, onFailureUsr);


}

function onSuccessUsr(res) {
  try{
      kony.application.dismissLoadingScreen();
  alert("Register successfully");
 
  frmEntryform.destroy();
  frmLogin2.destroy();
  frmLogin2.show();
  }catch(err){
    alert("error"+  err);
  }
 
  //Success handler
}
function onFailureUsr(res) {
//Failure handler
  alert("error Registor-->" + res);
}











/*********************
Module name : UserLogin2
Function name :UserloginIn
Description :userlogin Service call in here
Author :Abdulkareem
Date :16-10-2018
***************************/


function UserloginIn2(){
  if(validate(frmLogin2.txtUsername.text)){
      alert("Please enter valid Username");
      frmLogin2.txtUsername.setFocus(true);
      return false;
    }
  if(validate(frmLogin2.txtPW.text)){
  alert("Please enter password");
    frmLogin2.txtPW.setFocus(true);
   return false;
  }
  var cName = frmLogin2.txtUsername.text;
  var cPw = frmLogin2.txtPW.text;
  loader();
 var serviceName = "devUserLogin";
var integrationObj = KNYMobileFabric.getIntegrationService(serviceName);

var operationName =  "UserLogin";
var data= {"username": cName,"password": cPw};
var headers= {};
//integrationObj.invokeOperation(operationName, headers, data, operationSuccess, operationFailure);
integrationObj.invokeOperation(operationName, headers, data, operationSuccesslogin2, operationFailurelogin2);

}


/*********************
Module name : UserLogin2
Function name :operationSuccesslogin
Description :operation name of userlogin success
Author :Abdulkareem
Date :16-10-2018
***************************/
function operationSuccesslogin2(res){
 try{
     kony.application.dismissLoadingScreen();
     if(res.opstatus === 0){
       if(res.status === "Success"){
       frmUserD.lbl1.text =res.response[0].address;
        frmUserD.lbl2.text =res.response[0].name;
        frmUserD.lbl3.text =res.response[0].id;
        frmUserD.lbl4.text =res.response[0].phoneno;
        frmUserD.lbl5.text =res.response[0].username;
          frmLogin2.destroy();
         frmHome.show();
       } else{
     alert(res.Message); 
       }
     
    }

   //  frmUserD.show();
      }
   
  catch(error){
    alert("Exception succussful of operationSuccess" + error);
  }
}
//code for success call back



/*********************
Module name : UserLogin2
Function name :operationFailurelogin
Description :operation name of userlogin failure
Author :Abdulkareem
Date :16-10-2018
***************************/

function operationFailurelogin2(res){
  try{
   alert("response" + JSON.stringify(res));
  }catch(error){
    alert("Exception succussful of operationFailure" + error);
  }
//code for failure call back
}
/*********************
Module name : Gatewayscreen
Function name :BtnLoginOnclick
Description :userlogin form call with destroy
Author :Abdulkareem
Date :23-10-2018
***************************/

function BtnLoginOnclick(){
  try{
   frmLogin2.destroy(true);
    frmLogin2.show();
  }catch(error){
    alert("Exception succussful of operationFailure" + error);
  }
//code for failure call back
}


/*********************
Module name : Gatewayscreen
Function name :BtnLoginBackOnclick
Description :userlogin form call with destroy
Author :Abdulkareem
Date :23-10-2018
***************************/

function BtnLoginBackOnclick(){
  try{
   frmLogin2.destroy(true);
    frmGateway.show();
  }catch(error){
    alert("Exception succussful of operationFailure" + error);
  }
//code for failure call back
}


/*********************
Module name : Register
Function name :BtnBackGWOnclick
Description :call back Gateway screen
Author :Abdulkareem
Date :23-10-2018
***************************/

function BtnBackGWOnclick(){
  try{
   frmEntryform.destroy(true);
   frmGateway.show();
  }catch(error){
    alert("Exception succussful of operationFailure" + error);
  }
//code for failure call back
}

/*********************
Module name : Gatewayscreen
Function name :BtnRegistorOnclick
Description :Registor form call with destroy
Author :Abdulkareem
Date :23-10-2018
***************************/

function BtnRegistorOnclick(){
  try{
   frmEntryform.destroy(true);
    frmEntryform.show();
  }catch(error){
    alert("Exception succussful of operationFailure" + error);
  }
//code for failure call back
}


/*********************
Module name : Register
Function name :BtnRegistorDoROnclick
Description :Registor form reset
Author :Abdulkareem
Date :23-10-2018
***************************/

function BtnRegistorDoROnclick(){
  try{
    frmEntryform.txtName.text ="";
    frmEntryform.txtUsername.text ="";
    frmEntryform.txtPasswords.text ="";
    frmEntryform.txtAddress.text ="";
    frmEntryform.txtPhone.text ="";
    frmEntryform.txtName.setFocus(true);
  }catch(error){
    alert("Register Doreset" + error);
  }
//code for failure call back
}







/*********************
Module name : NFIscreen
Function name :NFIfunctionCall
Description :call option
Author :Abdulkareem
Date :24-10-2018
***************************/


function NFIfunctionCall(){
try{
var Intent = java.import("android.content.Intent");
var KonyMain = java.import("com.konylabs.android.KonyMain");
var uri = java.import("android.net.Uri");

// var launchIntent = getPackageManager().getLaunchIntentForPackage("com.orgname.firstLogin");
var intent = new Intent(Intent.ACTION_CALL);
intent.setData(uri.parse("tel:" + 9677403105));//change the number
KonyMain.getAppContext().startActivity(intent);

}catch(err){

}
}

/*********************
Module name : NFIscreen
Function name :GetCurrentmillisecond
Description :get Currentmillisecond
Author :Abdulkareem
Date :24-10-2018
***************************/
function GetCurrentmillisecond(){
  var System = java.import("java.lang.System");
  var CurrentTime = System.currentTimeMillis();
  return CurrentTime;
}


/*********************
Module name : NFIscreen
Function name :Callbacktap
Description :Call back func
Author :Abdulkareem
Date :24-10-2018
***************************/

// function Callbacktap(restap){

//  alert(JSON.stringify(restap));


// }




/*********************
Module name : NFIscreen
Function name :NFIFunctionInt
Description :get start activity
Author :Abdulkareem
Date :24-10-2018
***************************/

function NFIFunctionInt(){
try{

var intent = java.import("android.content.Intent");
var KonyMain = java.import("com.konylabs.android.KonyMain");

intent = KonyMain.getAppContext().getPackageManager().getLaunchIntentForPackage("com.truetech.nativeffi");
KonyMain.getAppContext().startActivity(intent);

}catch(err){
alert("Error "+JSON.stringify(err));
}

}








/*********************
Module name : NFIscreen
Function name :NFIFunctionIntSmsOpt
Description :send sms
Author :Abdulkareem
Date :24-10-2018
***************************/


function NFIFunctionIntSmsOpt(){
try{

var Intent = java.import("android.content.Intent");
var KonyMain = java.import("com.konylabs.android.KonyMain");
var uri = java.import("android.net.Uri");

var intents = new Intent(Intent.ACTION_VIEW);
intents.setData(uri.parse("sms:" + 9659675924));
KonyMain.getAppContext().startActivity(intents);


}catch(err){
alert("Error "+JSON.stringify(err));
}

}


/*********************
Module name : NFIscreen
Function name :NFIFunctionAutoSMS
Description :send sms
Author :Abdulkareem
Date :24-10-2018
***************************/

function autoSMSSending(){
  try{
    var SmsManager = java.import("android.telephony.SmsManager");
    smsManager = SmsManager.getDefault();
    smsManager.sendTextMessage("9677089975", null, "welcome chandru", null, null);
  }catch(err){
    alert(JSON.stringify(err));
  }
}

/*********************
Module name : FFIscreen
Function name :additionOne
Description :Add number by ffi java package
Author :Abdulkareem
Date :24-10-2018
***************************/

function additionOne(){
  try{
  var AddVal = additionExample.iaddition(200, 100);
   alert("Value of addtion" + AddVal);
  }catch(error){
   
    alert("error of addval javapackage " + JSON.stringify(error));
  }

}


/*********************
Module name : FFIscreen
Function name :additionToast
Description :Add number by ffi java package with Toast
Author :Abdulkareem
Date :24-10-2018
***************************/

function additionToast(){
   additionExample.iaddtionT();
}

function additionWithoutStatic(){
  try{
    var AdditionNonStaticObject = new additionExample.WithoutStatic();
    var returnedValue = AdditionNonStaticObject.NonStaticAdd(16, 30, 10);
    alert("Non Static Addition value "+ returnedValue);
  }catch(err){
    alert("Error :" + err);
  }
}

function additionCallback(){
  try{
    var AdditionNonStaticObject = new additionExample.WithoutStatic();
    AdditionNonStaticObject.NonStaticCallBack( 18, 18, callBack);
  }catch(err){
    alert("Error :" + err);
  }
}

function callBack(res){
  alert(JSON.stringify(res));
}




function loader() {
    kony.application.showLoadingScreen("sknlblload", "Loading...", constants.LOADING_SCREEN_POSITION_ONLY_CENTER, false, true, {
        enableMenuKey: true,
        enableBackKey: true,
        progressIndicatorColor: "White"
    });
}