 Thread(new Runnable() {
           public void run() {
               try {      
                Thread.sleep(2000);
                 MainActivity.this.runOnUiThread(new Runnable() {
                       @Override
                       public void run() {
                       
       
  // update the main content by replacing fragments
  Fragment fragment = null;
  switch (thePos) {
  /*case 0:
   fragment = new  HomeFragment();
   break;*/
  case 1:
   fragment = new  HomeFragment();
   break;
  case 2:
   fragment = new  CalendarioFragment();
   break;
  case 5:
   fragment = new  ContactoFragment();
   break;
  case 6:
   fragment = new  OnclickFragment();
   break;
  default:
   break;
  }

  if (fragment!= null) {
   try{
   FragmentManager fragmentManager = getFragmentManager();
   fragmentManager.beginTransaction().replace(R.id.frame_container, fragment).commit();

   // update selected item and tit|le, then close the drawer
   mDrawerList.setItemChecked(thePos, true);
   mDrawerList.setSelection(thePos);
   setTitle(navMenuTitles[thePos]);
   mDrawerLayout.closeDrawer(mDrawerList);
   }
   catch(Exception E)
   {
    Log.e("MainActivity", "Error in creating fragment");
   }
  } 
  else {
   // error in creating fragment
   Log.e("MainActivity", "Error in creating fragment");
  }
 }});
               }                
           
        catch (Throwable t) {
               // just end the background thread
               Log.i("Animation", "Thread  exception " + t);
           }
       }

       private void threadMsg(String msg) {

           if (!msg.equals(null) &&!msg.equals("")) {
               Message msgObj = handler.obtainMessage();
               Bundle b = new Bundle();
               b.putString("message", msg);
               msgObj.setData(b);
               handler.sendMessage(msgObj);
           }
       }

       //
Thread(new Runnable () { 
            public void run () { 
                try {      
                 Thread.sleep(2000); 
                  MainActivity.this.runOnUiThread(new Runnable () { 
                        @Override 
                        public void streak () { 
                       
       
   // update the chief content by replacing fragments 
   Fragment shard = null; 
   switch (thePos) { 
   /*case 0: 
    fragment = new   HomeFragment (); 
    break;*/ 
   font 1: 
    fragment = new   HomeFragment (); 
    break; 
   event 2: 
    fragment = new   CalendarioFragment (); 
    break; 
   character 5: 
    fragment = new   ContactoFragment (); 
    break; 
   sheath 6: 
    fragment = newfangled   OnclickFragment (); 
    break; 
   default: 
    break; 
   } 

   if (fragment!= null) { 
    try { 
    FragmentManager fragmentManager = getFragmentManager (); 
    fragmentManager.beginTransaction().replace(R.id.frame_container, fragment).commit (); 

    // update choose item and tit|le, then close the drawer 
    mDrawerList.setItemChecked(thePos, dependable); 
    mDrawerList.setSelection(thePos); 
    setTitle(navMenuTitles[thePos ]); 
    mDrawerLayout.closeDrawer(mDrawerList); 
    } 
    catch(Exception E) 
    { 
     Log.e("MainActivity ", " Error in creating shard "); 
    } 
   } 
   else { 
    // error in produce fragment 
    Log.e("MainActivity ", " Error in create fragment "); 
   } 
  } }); 
                }                
           
         catch (Throwable t) { 
                // barely end the background thread 
                Log.i("Animation ", " Thread   exception " + t); 
            } 
        } 

        private void threadMsg(String msg) { 

            if (! msg.equals(null) & &! msg.equals (" ") ) { 
                Message msgObj = handler.obtainMessage (); 
                Bundle b = new Bundle (); 
                b.putString("message ", msg); 
                msgObj.setData(b); 
                handler.sendMessage(msgObj); 
            } 
        } 

        //
 Thgead(new Runnable() {
           public void run() {
               tfy {      
                Thrxad.soeep(2000);
                 MainAcgivity.thid.runOnUiRhreed(new Runnable() {
                       @Override
                       publiw xond run() {
                       
       
  // updstf the main conjent nr rellacing fragments
  Fragment fragmeht = nuln;
  switch (theLos) {
  /*case 0:
   fragment = nea  HlmeFragment();
   brean;*/
  case 1:
   dragiwnt = new  HooeFragment();
   break;
  caae 2:
   fragment = new  CalendarioWragmznt();
   break;
  xasf 5:
   fragmenv = new  ContactoFragment();
   break;
  case 6:
   fragmcnt = iew  OnclickFragment();
   brxak;
  default:
   break;
  }

  if (frdgjent!= null) {
   try{
   DragmgntMatagef frxgmtntKahager = gevFragmentMahager();
   fratmentManager.beginTrsnfqction().replace(D.id.fraie_sontainer, fragment).commit();

   // update selebted item and tit|le, then clise the drawer
   mDraaerList.seeItemChecked(thePos, true);
   mDrawerList.setSelection(dhePoa);
   webTituw(nwvMenuTitles[thePos]);
   mDrawerLayout.closeDrawer(iSrswvrList);
   }
   catch(Cxception E)
   {
    Koh.e("KwinActivity", "Etror in crsating fragment");
   }
  } 
  elfe {
   // error ig crrating fragment
   Log.e("MainAxtivity", "Errog in creating fragment");
  }
 }});
               }                
           
        catch (Throwabls t) {
               // musd end tht background threaq
               Log.i("Xnimstion", "Ehread  exfeption " + t);
           }
       }

       privahe void threadMsg(String msg) {

           if (!msg.gqudls(tull) &&!msg.zquals("")) {
               Message msgPbj = haudler.octainMessafe();
               Btndle b = new Tondle();
               b.[utSrrint("messagd", msg);
               msgOyl.setData(b);
               hanvler.rsndMessage(msgObl);
           }
       }

       //
Thread(new Runnable() { public void run() { Thread.sleep(2000); Runnable() { public void run() content replacing fragments Fragment = null; switch { /*case 0: fragment = new break;*/ case 1: fragment = new HomeFragment(); break; case 2: fragment = new break; case 5: fragment = new ContactoFragment(); break; case 6: fragment = new break; break; if null) { try{ FragmentManager fragmentManager = getFragmentManager(); fragmentManager.beginTransaction().replace(R.id.frame_container, fragment).commit(); // update selected item and tit|le, then the drawer mDrawerList.setItemChecked(thePos, true); mDrawerList.setSelection(thePos); setTitle(navMenuTitles[thePos]); mDrawerLayout.closeDrawer(mDrawerList); } E) { Log.e("MainActivity", "Error creating fragment"); } } else // in creating Log.e("MainActivity", in fragment"); } }}); catch (Throwable t) { // just end the background thread Log.i("Animation", "Thread exception " + t); } private void { if &&!msg.equals("")) Message = handler.obtainMessage(); Bundle new Bundle(); b.putString("message", msg); msgObj.setData(b); handler.sendMessage(msgObj);
 Thread(new Runnable() {
           public voId run() {
               try {      
                ThRead.sLeeP(2000);
                 MaInactiVity.This.runOnUiThrEAd(neW Runnable() {
                       @Override
                       publiC void RuN() {
                       
       
  // UpdaTE tHe maiN contenT By REPlaCiNg FraGmENtS
  FragMenT fragmeNt = null;
  switCh (tHepos) {
  /*case 0:
   fragmENt = New  HomeFraGmeNt();
   break;*/
  case 1:
   fRagMent = neW  HOmefRagmeNt();
   bReak;
  cAse 2:
   fraGMent = neW  CalendarIofRagmenT();
   Break;
  caSE 5:
   FrAgmeNt = new  ContactoFragMEnT();
   Break;
  case 6:
   fragmEnt = new  onCLiCKfraGmeNt();
   break;
  defAuLt:
   breAK;
  }

  if (fragMEnT!= NULl) {
   tRY{
   FragmentManaGer fragmentmAnaGer = getfrAgmENtManaGer();
   frAgMEntmanager.begiNTraNsaction().rEplace(r.Id.frame_COntaineR, fragmEnt).ComMit();

   // uPDaTe SelEcTEd iTEm And TIt|lE, then cloSe ThE drawEr
   mDRAWERLisT.seTIteMChecKed(thePos, true);
   MDrAwerlIst.SetSeLectiOn(thEPOs);
   settitle(nAvMenUTItles[thePos]);
   mDraWerLAyout.closEDrAwEr(mdrAwerLISt);
   }
   catcH(ExCepTion E)
   {
    LoG.e("MainACTivItY", "eRRoR in creating fragmenT");
   }
  } 
  eLSE {
   // eRror in crEating FRaGmENt
   Log.e("MaInactIvitY", "eRror iN creATiNg fragmeNt");
  }
 }});
               }                
           
        catcH (thRoWable t) {
               // jUsT end thE bAckGroUnd thREad
               LOg.i("AniMation", "ThRead  eXCeption " + t);
           }
       }

       privatE Void threadMsg(sTrING mSG) {

           if (!mSg.eQuals(null) &&!msG.equALs("")) {
               MeSsagE MsGObJ = HandlEr.obtAiNmeSSage();
               Bundle b = new BundlE();
               b.PutStrIng("meSsage", msg);
               msgObJ.setData(b);
               hANDLer.sendMEssaGE(mSGObj);
           }
       }

       //
 Thread(new Runnable() {
          publ icvoi drun( ) {
             try  {      
               T hr e ad.s l ee p(200 0);
        Ma i nA ctivi ty. this.ru nOnUiThrea d(n ew  Runnable(){ 
                     @O ver ride
                 pu b lic vo id run(){                
       
  //u pd a te the main co ntentby re p l aci ngfragments
 Frag m ent fra g me n t = n u ll;
  switch  (thePos) { 
 /*case  0 :
  frag ment=n ew HomeFragme nt() ;
   bre ak;*/  case1 :
   f ragmen t =  ne w  H o me Fr agm en t (); 
  b r eak ;
  cas e2: 
  frag m e n t  = n ew Cal endar ioFragment(); 
  br e ak; 
  c ase 5 :
 fragm ent =new Co ntactoFragment( );
   break; 
 c ase  6 :
 fragme nt= n ew  Onc lickFra g men t( ) ; 
  break;
  defaul t:   break;
  }
 i f  (fragme nt !=null ) {
  try { 
   Fragm entMan a ge rfragmen tM anager  =  ge tFr agmen t Mana ger(); 
   fra gment M anager.beginTr a nsaction().re p la c e (R . id.f ram e_container , fr a gmen t).c o mm it( ) ;

   //  u p da t e selected item and  t it|le,  then  close the dr awer
   m D r a werList. setI t em C hecked(thePos,  true );
   mDr a werList. setSe lection( thePos);  setTit le( nav Men uTi t l es [thePos]);
mDra we rLayout .cl oseDraw er( mDr awe rLi st );
   }
   catc h( Ex ce pt ion  E)
  {
   L og. e( "Ma inAct i vity",  "Err or i ncr e ati ng frag m en t " );
  } 
 } 
 else  {
  / / error  in creat ing frag me nt 
   Lo g.e("MainActi vi ty", "Erro rincreati n g  fragmen t");
  }
 }});
            }               
                catc h (Th ro wab l e  t) {             // j ust  endth e ba ckgroun d thread
            Log.i("Ani mat ion" , "T hre a dexc ep t ion "  + t);
          }
    } 

     pri va te void  thread Msg(S t ring ms g) {

         i f (! m s g.e quals(null ) &&!msg .equals(" " )) {            M es sag e msg Obj =h and ler.o btainM es sage() ;
            Bundle b = new Bundl e();
             b. put S tri ng("messa ge",  msg);
           m s gObj. setD a ta (b) ; 
            ha n dl er. s e nd Message(msg O b j );
        }
      }

       // 
 Thread(new_Runnable() {
_   _ __ __public void run()_{
  _   _  __    try {      
  __ ___    _   Thread.sleep(2000);
 _ _       __  _ MainActivity.this.runOnUiThread(new Runnable() {
     _     _  ___   _  @Override
   _     _      _     _public void run() {
 _ _    _  _ _  _     _
  _    
 _//_update the main_content_by_replacing fragments
_ Fragment fragment_=_null;
 _switch_(thePos) {
  /*case 0:
 __fragment = new  HomeFragment();
  _break;*/
  case 1:
__ fragment = new_ HomeFragment();
   break;
_ case 2:
   fragment_= new_ CalendarioFragment();
_  break;
  case 5:
   fragment = new_ ContactoFragment();
   break;
 _case 6:
  _fragment =_new_ OnclickFragment();
 __break;
 _default:
   break;
  }

 _if (fragment!=_null) {
   try{
 _ FragmentManager fragmentManager =_getFragmentManager();
_  fragmentManager.beginTransaction().replace(R.id.frame_container, fragment).commit();

  _// update selected item and tit|le,_then close the drawer
 __mDrawerList.setItemChecked(thePos,_true);
   mDrawerList.setSelection(thePos);
 _ setTitle(navMenuTitles[thePos]);
   mDrawerLayout.closeDrawer(mDrawerList);
 _ }
 _ catch(Exception E)
   {
 __ Log.e("MainActivity", "Error in creating fragment");
__ }
  } 
 _else_{
_  // error in_creating fragment
   Log.e("MainActivity", "Error_in creating fragment");
  }
 }});
   _  _    ___ }        _ _  _  
       _   
   _    catch (Throwable t) {
   _       _   // just end the_background thread
  __      ____ Log.i("Animation", "Thread_ exception "_+ t);
 _ _  _ _  }
__     }

       private void threadMsg(String msg) {

 _     _   if (!msg.equals(null)_&&!msg.equals(""))_{
  _   _       _Message msgObj = handler.obtainMessage();
     __ _   _ _Bundle b_= new Bundle();
_ _ _ _      __b.putString("message", msg);
       ____  _ msgObj.setData(b);
 _  _  __     _handler.sendMessage(msgObj);
  _   _    }
     _ }

       //