public void myVouchers() {
    if (NetworkUtils.isNetworkAvailable(this)) {

      // Updated offline vouchers
      if (isUserLogIn() && isSyncOn) {
        try {
          new VoucherListViewTask().execute();
        } catch (Exception e) {
        }
      }

      Intent ia = new Intent(DealsMagazineActivity.this, DealsWebView.class);
      ia.putExtra(DealsWebView.KEY_PAGE_CONTROLLER, Globals.INT_MY_VOUCHERS);
      ia.putExtra(DealsWebView.KEY_FROM_ACTIVITY, Globals.DEALS_MAGAZINE_ACTIVITY);
      startActivityForResult(ia, Globals.DEALS_WEB_VIEW);
      finish();
    } else {
      if (isUserLogIn()) {
        Intent ia = new Intent(DealsMagazineActivity.this, VoucherListView.class);
        startActivityForResult(ia, Globals.VOUCHER_LIST_VIEW);
        finish();
      } else {
        Intent i = new Intent(DealsMagazineActivity.this, NetworkConnectionView.class);
        startActivityForResult(i, Globals.LOGIN_VIEW);
        finish();
      }
    }
  }
 public String doInBackground(Void... params) {
   String loginResult = "";
   String username = ((User) getApplication()).loadusernameFrompreferences();
   String password = ((User) getApplication()).loadpasswordFrompreferences();
   try {
     loginResult = NetworkUtils.validateLogin(username, password);
   } catch (Exception e) {
   }
   return loginResult;
 }
 public byte[] doInBackground(Void... params) {
   byte[] buffer = null;
   String username = ((User) getApplication()).loadusernameFrompreferences();
   String password = ((User) getApplication()).loadpasswordFrompreferences();
   String userid = ((User) getApplication()).loaduserIdFromPreferences();
   try {
     buffer = NetworkUtils.getVoucherFromServer(username, password, userid);
   } catch (Exception e) {
   }
   return buffer;
 }
  @Override
  public void onCreate(Bundle savedInstanceState) {
    Eula.show(this);
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    // Get settings
    SharedPreferences sprefs = PreferenceManager.getDefaultSharedPreferences(appContext);
    String sync_key = appContext.getString(R.string.prefs_autosync_key);
    String dele_key = appContext.getString(R.string.prefs_autodelete_key);
    try {
      isSyncOn = sprefs.getBoolean(sync_key, true);
    } catch (ClassCastException e) {
      isSyncOn = false;
    }

    try {
      isDelete = sprefs.getBoolean(dele_key, false);
    } catch (ClassCastException e) {
      isDelete = false;
    }

    // Get sync tag
    Bundle extras = getIntent().getExtras();
    try {
      syncTag = extras.getInt(KEY_SYNC);
    } catch (Exception e) {
      syncTag = 0;
    }

    try {
      lastcheck = ((User) getApplication()).loadLastCheckFromPreferences();
    } catch (Exception e) {
    }

    tv_mainmenu = (TextView) this.findViewById(R.id.text_mainmenu);
    tv_mainmenu.setVisibility(View.INVISIBLE);

    imgbtn_viewdeals = (ImageButton) this.findViewById(R.id.imgbtn_mydeals);
    imgbtn_myvouchers = (ImageButton) this.findViewById(R.id.imgbtn_myvouchers);

    // If the network is unavailable, change to off line mode
    if (!NetworkUtils.isNetworkAvailable(this)) {
      imgbtn_viewdeals.setVisibility(View.GONE);
      tv_mainmenu.setText(this.getString(R.string.offline));
      tv_mainmenu.setVisibility(View.VISIBLE);
    }

    // Set the listener for view deals
    imgbtn_viewdeals.setOnClickListener(
        new OnClickListener() {
          public void onClick(View v) {
            viewDeals();
          }
        });

    // Set the listener for my voucher
    imgbtn_myvouchers.setOnClickListener(
        new OnClickListener() {
          public void onClick(View v) {
            myVouchers();
          }
        });

    // Delete expired files
    if (isDelete) {
      systemFilesMgt();
    }

    // Background sync task
    if (isUserLogIn()
        && NetworkUtils.isNetworkAvailable(this)
        && syncTag == 1
        && TimerUtils.isCheckTimeAvailable(lastcheck)) {
      syncTag = 0;

      long dateMillis = System.currentTimeMillis();
      Time yourDate = new Time();
      yourDate.set(dateMillis);
      lastcheck = yourDate.format("%Y-%m-%d %H:%M");
      ((User) getApplication()).setLastCheck(lastcheck);
      ((User) getApplication()).saveLastCheckToPreferences();

      try {
        backgroundTask();
      } catch (Exception e) {
      }
    }
  }