content: package b4a.example;
  
  
  import anywheresoftware.b4a.B4AMenuItem;
  import android.app.Activity;
  import android.os.Bundle;
  import anywheresoftware.b4a.BA;
  import anywheresoftware.b4a.BALayout;
  import anywheresoftware.b4a.B4AActivity;
  import anywheresoftware.b4a.ObjectWrapper;
  import anywheresoftware.b4a.objects.ActivityWrapper;
  import java.lang.reflect.InvocationTargetException;
  import anywheresoftware.b4a.B4AUncaughtException;
  import anywheresoftware.b4a.debug.*;
  import java.lang.ref.WeakReference;
  
  public class main extends Activity implements B4AActivity{
  	public static main mostCurrent;
  	static boolean afterFirstLayout;
  	static boolean isFirst = true;
      private static boolean processGlobalsRun = false;
  	BALayout layout;
  	public static BA processBA;
  	BA activityBA;
      ActivityWrapper _activity;
      java.util.ArrayList<B4AMenuItem> menuItems;
  	public static final boolean fullScreen = false;
  	public static final boolean includeTitle = true;
      public static WeakReference<Activity> previousOne;
      public static boolean dontPause;
  
  	@Override
  	public void onCreate(Bundle savedInstanceState) {
  		super.onCreate(savedInstanceState);
          mostCurrent = this;
  		if (processBA == null) {
  			processBA = new BA(this.getApplicationContext(), null, null, "b4a.example", "b4a.example.main");
  			processBA.loadHtSubs(this.getClass());
  	        float deviceScale = getApplicationContext().getResources().getDisplayMetrics().density;
  	        BALayout.setDeviceScale(deviceScale);
              
  		}
  		else if (previousOne != null) {
  			Activity p = previousOne.get();
  			if (p != null && p != this) {
                  BA.LogInfo("Killing previous instance (main).");
  				p.finish();
  			}
  		}
          processBA.setActivityPaused(true);
          processBA.runHook("oncreate", this, null);
  		if (!includeTitle) {
          	this.getWindow().requestFeature(android.view.Window.FEATURE_NO_TITLE);
          }
          if (fullScreen) {
          	getWindow().setFlags(android.view.WindowManager.LayoutParams.FLAG_FULLSCREEN,   
          			android.view.WindowManager.LayoutParams.FLAG_FULLSCREEN);
          }
  		
          processBA.sharedProcessBA.activityBA = null;
  		layout = new BALayout(this);
  		setContentView(layout);
  		afterFirstLayout = false;
          WaitForLayout wl = new WaitForLayout();
          if (anywheresoftware.b4a.objects.ServiceHelper.StarterHelper.startFromActivity(this, processBA, wl, false))
  		    BA.handler.postDelayed(wl, 5);
  
  	}
  	static class WaitForLayout implements Runnable {
  		public void run() {
  			if (afterFirstLayout)
  				return;
  			if (mostCurrent == null)
  				return;
              
  			if (mostCurrent.layout.getWidth() == 0) {
  				BA.handler.postDelayed(this, 5);
  				return;
  			}
  			mostCurrent.layout.getLayoutParams().height = mostCurrent.layout.getHeight();
  			mostCurrent.layout.getLayoutParams().width = mostCurrent.layout.getWidth();
  			afterFirstLayout = true;
  			mostCurrent.afterFirstLayout();
  		}
  	}
  	private void afterFirstLayout() {
          if (this != mostCurrent)
  			return;
  		activityBA = new BA(this, layout, processBA, "b4a.example", "b4a.example.main");
          
          processBA.sharedProcessBA.activityBA = new java.lang.ref.WeakReference<BA>(activityBA);
          anywheresoftware.b4a.objects.ViewWrapper.lastId = 0;
          _activity = new ActivityWrapper(activityBA, "activity");
          anywheresoftware.b4a.Msgbox.isDismissing = false;
          if (BA.isShellModeRuntimeCheck(processBA)) {
  			if (isFirst)
  				processBA.raiseEvent2(null, true, "SHELL", false);
  			processBA.raiseEvent2(null, true, "CREATE", true, "b4a.example.main", processBA, activityBA, _activity, anywheresoftware.b4a.keywords.Common.Density, mostCurrent);
  			_activity.reinitializeForShell(activityBA, "activity");
  		}
          initializeProcessGlobals();		
          initializeGlobals();
          
          BA.LogInfo("** Activity (main) Create " + (isFirst ? "(first time)" : "") + " **");
          processBA.raiseEvent2(null, true, "activity_create", false, isFirst);
  		isFirst = false;
  		if (this != mostCurrent)
  			return;
          processBA.setActivityPaused(false);
          BA.LogInfo("** Activity (main) Resume **");
          processBA.raiseEvent(null, "activity_resume");
          if (android.os.Build.VERSION.SDK_INT >= 11) {
  			try {
  				android.app.Activity.class.getMethod("invalidateOptionsMenu").invoke(this,(Object[]) null);
  			} catch (Exception e) {
  				e.printStackTrace();
  			}
  		}
  
  	}
  	public void addMenuItem(B4AMenuItem item) {
  		if (menuItems == null)
  			menuItems = new java.util.ArrayList<B4AMenuItem>();
  		menuItems.add(item);
  	}
  	@Override
  	public boolean onCreateOptionsMenu(android.view.Menu menu) {
  		super.onCreateOptionsMenu(menu);
          try {
              if (processBA.subExists("activity_actionbarhomeclick")) {
                  Class.forName("android.app.ActionBar").getMethod("setHomeButtonEnabled", boolean.class).invoke(
                      getClass().getMethod("getActionBar").invoke(this), true);
              }
          } catch (Exception e) {
              e.printStackTrace();
          }
          if (processBA.runHook("oncreateoptionsmenu", this, new Object[] {menu}))
              return true;
  		if (menuItems == null)
  			return false;
  		for (B4AMenuItem bmi : menuItems) {
  			android.view.MenuItem mi = menu.add(bmi.title);
  			if (bmi.drawable != null)
  				mi.setIcon(bmi.drawable);
              if (android.os.Build.VERSION.SDK_INT >= 11) {
  				try {
                      if (bmi.addToBar) {
  				        android.view.MenuItem.class.getMethod("setShowAsAction", int.class).invoke(mi, 1);
                      }
  				} catch (Exception e) {
  					e.printStackTrace();
  				}
  			}
  			mi.setOnMenuItemClickListener(new B4AMenuItemsClickListener(bmi.eventName.toLowerCase(BA.cul)));
  		}
          
  		return true;
  	}   
   @Override
   public boolean onOptionsItemSelected(android.view.MenuItem item) {
      if (item.getItemId() == 16908332) {
          processBA.raiseEvent(null, "activity_actionbarhomeclick");
          return true;
      }
      else
          return super.onOptionsItemSelected(item); 
  }
  @Override
   public boolean onPrepareOptionsMenu(android.view.Menu menu) {
      super.onPrepareOptionsMenu(menu);
      processBA.runHook("onprepareoptionsmenu", this, new Object[] {menu});
      return true;
      
   }
   protected void onStart() {
      super.onStart();
      processBA.runHook("onstart", this, null);
  }
   protected void onStop() {
      super.onStop();
      processBA.runHook("onstop", this, null);
  }
      public void onWindowFocusChanged(boolean hasFocus) {
         super.onWindowFocusChanged(hasFocus);
         if (processBA.subExists("activity_windowfocuschanged"))
             processBA.raiseEvent2(null, true, "activity_windowfocuschanged", false, hasFocus);
      }
  	private class B4AMenuItemsClickListener implements android.view.MenuItem.OnMenuItemClickListener {
  		private final String eventName;
  		public B4AMenuItemsClickListener(String eventName) {
  			this.eventName = eventName;
  		}
  		public boolean onMenuItemClick(android.view.MenuItem item) {
  			processBA.raiseEventFromUI(item.getTitle(), eventName + "_click");
  			return true;
  		}
  	}
      public static Class<?> getObject() {
  		return main.class;
  	}
      private Boolean onKeySubExist = null;
      private Boolean onKeyUpSubExist = null;
  	@Override
  	public boolean onKeyDown(int keyCode, android.view.KeyEvent event) {
          if (processBA.runHook("onkeydown", this, new Object[] {keyCode, event}))
              return true;
  		if (onKeySubExist == null)
  			onKeySubExist = processBA.subExists("activity_keypress");
  		if (onKeySubExist) {
  			if (keyCode == anywheresoftware.b4a.keywords.constants.KeyCodes.KEYCODE_BACK &&
  					android.os.Build.VERSION.SDK_INT >= 18) {
  				HandleKeyDelayed hk = new HandleKeyDelayed();
  				hk.kc = keyCode;
  				BA.handler.post(hk);
  				return true;
  			}
  			else {
  				boolean res = new HandleKeyDelayed().runDirectly(keyCode);
  				if (res)
  					return true;
  			}
  		}
  		return super.onKeyDown(keyCode, event);
  	}
  	private class HandleKeyDelayed implements Runnable {
  		int kc;
  		public void run() {
  			runDirectly(kc);
  		}
  		public boolean runDirectly(int keyCode) {
  			Boolean res =  (Boolean)processBA.raiseEvent2(_activity, false, "activity_keypress", false, keyCode);
  			if (res == null || res == true) {
                  return true;
              }
              else if (keyCode == anywheresoftware.b4a.keywords.constants.KeyCodes.KEYCODE_BACK) {
  				finish();
  				return true;
  			}
              return false;
  		}
  		
  	}
      @Override
  	public boolean onKeyUp(int keyCode, android.view.KeyEvent event) {
          if (processBA.runHook("onkeyup", this, new Object[] {keyCode, event}))
              return true;
  		if (onKeyUpSubExist == null)
  			onKeyUpSubExist = processBA.subExists("activity_keyup");
  		if (onKeyUpSubExist) {
  			Boolean res =  (Boolean)processBA.raiseEvent2(_activity, false, "activity_keyup", false, keyCode);
  			if (res == null || res == true)
  				return true;
  		}
  		return super.onKeyUp(keyCode, event);
  	}
  	@Override
  	public void onNewIntent(android.content.Intent intent) {
          super.onNewIntent(intent);
  		this.setIntent(intent);
          processBA.runHook("onnewintent", this, new Object[] {intent});
  	}
      @Override 
  	public void onPause() {
  		super.onPause();
          if (_activity == null)
              return;
          if (this != mostCurrent)
  			return;
  		anywheresoftware.b4a.Msgbox.dismiss(true);
          if (!dontPause)
              BA.LogInfo("** Activity (main) Pause, UserClosed = " + activityBA.activity.isFinishing() + " **");
          else
              BA.LogInfo("** Activity (main) Pause event (activity is not paused). **");
          if (mostCurrent != null)
              processBA.raiseEvent2(_activity, true, "activity_pause", false, activityBA.activity.isFinishing());		
          if (!dontPause) {
              processBA.setActivityPaused(true);
              mostCurrent = null;
          }
  
          if (!activityBA.activity.isFinishing())
  			previousOne = new WeakReference<Activity>(this);
          anywheresoftware.b4a.Msgbox.isDismissing = false;
          processBA.runHook("onpause", this, null);
  	}
  
  	@Override
  	public void onDestroy() {
          super.onDestroy();
  		previousOne = null;
          processBA.runHook("ondestroy", this, null);
  	}
      @Override 
  	public void onResume() {
  		super.onResume();
          mostCurrent = this;
          anywheresoftware.b4a.Msgbox.isDismissing = false;
          if (activityBA != null) { //will be null during activity create (which waits for AfterLayout).
          	ResumeMessage rm = new ResumeMessage(mostCurrent);
          	BA.handler.post(rm);
          }
          processBA.runHook("onresume", this, null);
  	}
      private static class ResumeMessage implements Runnable {
      	private final WeakReference<Activity> activity;
      	public ResumeMessage(Activity activity) {
      		this.activity = new WeakReference<Activity>(activity);
      	}
  		public void run() {
              main mc = mostCurrent;
  			if (mc == null || mc != activity.get())
  				return;
  			processBA.setActivityPaused(false);
              BA.LogInfo("** Activity (main) Resume **");
              if (mc != mostCurrent)
                  return;
  		    processBA.raiseEvent(mc._activity, "activity_resume", (Object[])null);
  		}
      }
  	@Override
  	protected void onActivityResult(int requestCode, int resultCode,
  	      android.content.Intent data) {
  		processBA.onActivityResult(requestCode, resultCode, data);
          processBA.runHook("onactivityresult", this, new Object[] {requestCode, resultCode});
  	}
  	private static void initializeGlobals() {
  		processBA.raiseEvent2(null, true, "globals", false, (Object[])null);
  	}
      public void onRequestPermissionsResult(int requestCode,
          String permissions[], int[] grantResults) {
          for (int i = 0;i < permissions.length;i++) {
              Object[] o = new Object[] {permissions[i], grantResults[i] == 0};
              processBA.raiseEventFromDifferentThread(null,null, 0, "activity_permissionresult", true, o);
          }
              
      }
  
  public anywheresoftware.b4a.keywords.Common __c = null;
  public static anywheresoftware.b4a.objects.B4XViewWrapper.XUI _xui = null;
  public b4a.example.starter _starter = null;
  
  public static boolean isAnyActivityVisible() {
      boolean vis = false;
  vis = vis | (main.mostCurrent != null);
  return vis;}
  public static String  _activity_create(boolean _firsttime) throws Exception{
   //BA.debugLineNum = 25;BA.debugLine="Sub Activity_Create(FirstTime As Boolean)";
   //BA.debugLineNum = 26;BA.debugLine="Activity.LoadLayout(\"Layout\")";
  mostCurrent._activity.LoadLayout("Layout",mostCurrent.activityBA);
   //BA.debugLineNum = 27;BA.debugLine="ToastMessageShow ( DateToShamsi(DateTime.Now) , F";
  anywheresoftware.b4a.keywords.Common.ToastMessageShow(BA.ObjectToCharSequence(_datetoshamsi(anywheresoftware.b4a.keywords.Common.DateTime.getNow())),anywheresoftware.b4a.keywords.Common.False);
   //BA.debugLineNum = 28;BA.debugLine="End Sub";
  return "";
  }
  public static String  _activity_pause(boolean _userclosed) throws Exception{
   //BA.debugLineNum = 34;BA.debugLine="Sub Activity_Pause (UserClosed As Boolean)";
   //BA.debugLineNum = 36;BA.debugLine="End Sub";
  return "";
  }
  public static String  _activity_resume() throws Exception{
   //BA.debugLineNum = 30;BA.debugLine="Sub Activity_Resume";
   //BA.debugLineNum = 32;BA.debugLine="End Sub";
  return "";
  }
  public static String  _datetoshamsi(long _time) throws Exception{
  long _msperday = 0L;
  int[] _m = null;
  String[] _n = null;
   //BA.debugLineNum = 38;BA.debugLine="Sub DateToShamsi ( time As Long ) As String";
   //BA.debugLineNum = 39;BA.debugLine="Dim msPerDay As Long = 1000*60*60*24";
  _msperday = (long) (1000*60*60*24);
   //BA.debugLineNum = 40;BA.debugLine="time = time / msPerDay";
  _time = (long) (_time/(double)_msperday);
   //BA.debugLineNum = 41;BA.debugLine="Dim m(3) As Int";
  _m = new int[(int) (3)];
  ;
   //BA.debugLineNum = 42;BA.debugLine="m(0) = 11";
  _m[(int) (0)] = (int) (11);
   //BA.debugLineNum = 43;BA.debugLine="m(1) = 10";
  _m[(int) (1)] = (int) (10);
   //BA.debugLineNum = 44;BA.debugLine="m(2) = 1348";
  _m[(int) (2)] = (int) (1348);
   //BA.debugLineNum = 45;BA.debugLine="Do While time >= 1";
  while (_time>=1) {
   //BA.debugLineNum = 47;BA.debugLine="If (m(0) = 30) And (m(1) > 6 ) And (m(1) < 12) T";
  if ((_m[(int) (0)]==30) && (_m[(int) (1)]>6) && (_m[(int) (1)]<12)) { 
   //BA.debugLineNum = 48;BA.debugLine="m(0) = 1";
  _m[(int) (0)] = (int) (1);
   //BA.debugLineNum = 49;BA.debugLine="m(1) = m(1) + 1";
  _m[(int) (1)] = (int) (_m[(int) (1)]+1);
   }else if((_m[(int) (0)]==31) && (_m[(int) (1)]>0) && (_m[(int) (1)]<7)) { 
   //BA.debugLineNum = 51;BA.debugLine="m(0) = 1";
  _m[(int) (0)] = (int) (1);
   //BA.debugLineNum = 52;BA.debugLine="m(1) = m(1) + 1";
  _m[(int) (1)] = (int) (_m[(int) (1)]+1);
   }else if((_m[(int) (0)]==29) && (_m[(int) (1)]==12) && (_isleapyear(_m[(int) (2)])==anywheresoftware.b4a.keywords.Common.False)) { 
   //BA.debugLineNum = 54;BA.debugLine="m(0) = 1";
  _m[(int) (0)] = (int) (1);
   //BA.debugLineNum = 55;BA.debugLine="m(1) = 1";
  _m[(int) (1)] = (int) (1);
   //BA.debugLineNum = 56;BA.debugLine="m(2) = m(2) + 1";
  _m[(int) (2)] = (int) (_m[(int) (2)]+1);
   }else if((_m[(int) (0)]==30) && (_m[(int) (1)]==12) && (_isleapyear(_m[(int) (2)])==anywheresoftware.b4a.keywords.Common.True)) { 
   //BA.debugLineNum = 58;BA.debugLine="m(0) = 1";
  _m[(int) (0)] = (int) (1);
   //BA.debugLineNum = 59;BA.debugLine="m(1) = 1";
  _m[(int) (1)] = (int) (1);
   //BA.debugLineNum = 60;BA.debugLine="m(2) = m(2) + 1";
  _m[(int) (2)] = (int) (_m[(int) (2)]+1);
   }else {
   //BA.debugLineNum = 62;BA.debugLine="m(0) = m(0) + 1";
  _m[(int) (0)] = (int) (_m[(int) (0)]+1);
   };
   //BA.debugLineNum = 65;BA.debugLine="time = time-1";
  _time = (long) (_time-1);
   }
  ;
   //BA.debugLineNum = 67;BA.debugLine="Dim n(12) As String";
  _n = new String[(int) (12)];
  java.util.Arrays.fill(_n,"");
   //BA.debugLineNum = 68;BA.debugLine="n(0) = \"فروردین\"";
  _n[(int) (0)] = "فروردین";
   //BA.debugLineNum = 69;BA.debugLine="n(1) = \"اردیبهشت\"";
  _n[(int) (1)] = "اردیبهشت";
   //BA.debugLineNum = 70;BA.debugLine="n(2) = \"خرداد\"";
  _n[(int) (2)] = "خرداد";
   //BA.debugLineNum = 71;BA.debugLine="n(3) = \"تیر\"";
  _n[(int) (3)] = "تیر";
   //BA.debugLineNum = 72;BA.debugLine="n(4) = \"مرداد\"";
  _n[(int) (4)] = "مرداد";
   //BA.debugLineNum = 73;BA.debugLine="n(5) = \"شهریور\"";
  _n[(int) (5)] = "شهریور";
   //BA.debugLineNum = 74;BA.debugLine="n(6) = \"مهر\"";
  _n[(int) (6)] = "مهر";
   //BA.debugLineNum = 75;BA.debugLine="n(7) = \"آبان\"";
  _n[(int) (7)] = "آبان";
   //BA.debugLineNum = 76;BA.debugLine="n(8) = \"آذر\"";
  _n[(int) (8)] = "آذر";
   //BA.debugLineNum = 77;BA.debugLine="n(9) = \"دی\"";
  _n[(int) (9)] = "دی";
   //BA.debugLineNum = 78;BA.debugLine="n(10) = \"بهمن\"";
  _n[(int) (10)] = "بهمن";
   //BA.debugLineNum = 79;BA.debugLine="n(11) = \"اسفند\"";
  _n[(int) (11)] = "اسفند";
   //BA.debugLineNum = 80;BA.debugLine="Return ( m(0) & \"  \" & n (m(1)-1) & \"  \" & m(2) )";
  if (true) return (BA.NumberToString(_m[(int) (0)])+"  "+_n[(int) (_m[(int) (1)]-1)]+"  "+BA.NumberToString(_m[(int) (2)]));
   //BA.debugLineNum = 82;BA.debugLine="End Sub";
  return "";
  }
  public static String  _globals() throws Exception{
   //BA.debugLineNum = 21;BA.debugLine="Sub Globals";
   //BA.debugLineNum = 23;BA.debugLine="End Sub";
  return "";
  }
  public static boolean  _isleapyear(int _sal) throws Exception{
   //BA.debugLineNum = 84;BA.debugLine="Sub IsLeapYear ( sal As Int ) As Boolean";
   //BA.debugLineNum = 85;BA.debugLine="If (sal Mod 33=1)Or(sal Mod 33=5)Or(sal Mod 33=9)";
  if ((_sal%33==1) || (_sal%33==5) || (_sal%33==9) || (_sal%33==13) || (_sal%33==17) || (_sal%33==22) || (_sal%33==26) || (_sal%33==30)) { 
   //BA.debugLineNum = 86;BA.debugLine="Return True";
  if (true) return anywheresoftware.b4a.keywords.Common.True;
   }else {
   //BA.debugLineNum = 88;BA.debugLine="Return False";
  if (true) return anywheresoftware.b4a.keywords.Common.False;
   };
   //BA.debugLineNum = 90;BA.debugLine="End Sub";
  return false;
  }
  
  public static void initializeProcessGlobals() {
      
      if (main.processGlobalsRun == false) {
  	    main.processGlobalsRun = true;
  		try {
  		        main._process_globals();
  starter._process_globals();
  		
          } catch (Exception e) {
  			throw new RuntimeException(e);
  		}
      }
  }public static String  _process_globals() throws Exception{
   //BA.debugLineNum = 15;BA.debugLine="Sub Process_Globals";
   //BA.debugLineNum = 18;BA.debugLine="Private xui As XUI";
  _xui = new anywheresoftware.b4a.objects.B4XViewWrapper.XUI();
   //BA.debugLineNum = 19;BA.debugLine="End Sub";
  return "";
  }
  }
  