package  leo.findyourfate.com;   
 
import android.app.Activity; 
import android.app.AlertDialog;
import android.content.Context; 
import android.content.DialogInterface;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.AsyncTask;
import android.os.Bundle; 
import android.text.Html;
import android.util.Log;  
import android.webkit.WebView; 
import android.widget.ImageView;  
 
public class MainActivityfirst extends Activity {
	
     ShareExternalServer appUtil;
     String regId;
     AsyncTask<Void, Void, String> shareRegidTask;
     WebView content,addimagetop;  
	 ImageView img;
	 String statlink;
	 int w;
 	 public static final String MyPREFERENCES = "my" ;
	 public static final String name = "";
	 
    @Override
    public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.firsthome); 
    appUtil = new ShareExternalServer();
    getActionBar().setTitle(
			   Html.fromHtml("<font color=\"#ffffff\" size=\"25px\"><b>"+"Leo"+"</b></font>"));
	
    regId = getIntent().getStringExtra("regId");
    
    SharedPreferences prefs =  getSharedPreferences(MyPREFERENCES,Context.MODE_PRIVATE);
    //statlink = prefs.getString(key , "");
    statlink= prefs.getString("key", name);
    
    if((statlink.equals("")) || (statlink.equals("yes")))
    {
      statlink ="yes";
    }
     Log.d("MainActivity", "regId: " + regId);
    Log.d("MainActivity", "status: " + statlink);
    
    final Context context = this;
          shareRegidTask = new AsyncTask<Void, Void, String>() {
      @Override
      protected String doInBackground(Void... params) {
        String result = appUtil.shareRegIdWithAppServer(context, regId,statlink);
        return result;
      }
      @Override
      protected void onPostExecute(String result) {
       shareRegidTask = null;
      }
      };
      
    shareRegidTask.execute(null, null, null);
    final ImageView  img = (ImageView) findViewById(R.id.imageView1);
     Runnable swapImage = new Runnable() { 
		@Override
	    public void run() {
			Intent int_dr1 = new Intent(MainActivityfirst.this,home.class);
			int_dr1.putExtra("REGID", regId);
			int_dr1.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
			startActivity(int_dr1);
	    }  
     };
    img.postDelayed(swapImage,2000); 
    }
   
  @Override
 	public void onBackPressed() {
 	AlertDialog.Builder builder = new AlertDialog.Builder(this);
 	builder.setTitle("Exit!");
 	builder.setMessage("Are you sure you want to exit from leo app?")
 	       .setCancelable(false)
 	       .setIcon(R.drawable.alert)
 	       .setPositiveButton("Yes", new DialogInterface.OnClickListener() {
 	           public void onClick(DialogInterface dialog, int id) {
 	         	Intent intent = new Intent(Intent.ACTION_MAIN);
 			    	intent.addCategory(Intent.CATEGORY_HOME);
 			    	intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
 			    	startActivity(intent);
 	               }
 	       })
 	       .setNegativeButton("No", new DialogInterface.OnClickListener() {
 	        public void onClick(DialogInterface dialog, int id) {
 	         dialog.cancel();
 	           }
 	       });
 	AlertDialog alert = builder.create();
 	alert.show();
 }
  }

   