示例#1
0
  /* *
   * Called when invalidateOptionsMenu() is triggered
   */
  @Override
  public boolean onPrepareOptionsMenu(Menu menu) {
    // if nav drawer is opened, hide the action items
    boolean drawerOpen = mDrawerLayout.isDrawerOpen(mDrawerList);
    // if user not loggin, hide the action profile and logout
    boolean checkloggin = (session.isLoggedIn() && session != null);
    boolean checklogginFB = (sessionFacebook != null && sessionFacebook.isOpened());
    boolean check =
        (session != null && session.isLoggedIn())
            || (sessionFacebook != null && sessionFacebook.isOpened());
    menu.findItem(R.id.action_search).setVisible(!drawerOpen);
    menu.findItem(R.id.action_location_found).setVisible(!drawerOpen);
    menu.findItem(R.id.action_login).setVisible(!drawerOpen);
    menu.findItem(R.id.action_profile).setVisible(!drawerOpen);
    menu.findItem(R.id.action_logOut).setVisible(!drawerOpen);

    /*menu.findItem(R.id.action_profile).setVisible(checkloggin);
    menu.findItem(R.id.action_logOut).setVisible(checkloggin);
    menu.findItem(R.id.action_login).setVisible(!checkloggin);

    menu.findItem(R.id.action_logOut).setVisible(!checklogginFB);
    menu.findItem(R.id.action_profile).setVisible(!checklogginFB);
    menu.findItem(R.id.action_login).setVisible(checklogginFB);
      */
    // menu.findItem(R.id.action_profile).setVisible(check);
    menu.findItem(R.id.action_profile).setVisible(!checklogginFB);
    menu.findItem(R.id.action_profile).setVisible(checkloggin);
    menu.findItem(R.id.action_logOut).setVisible(check);
    menu.findItem(R.id.action_login).setVisible(!check);

    return super.onPrepareOptionsMenu(menu);
  }
示例#2
0
  /** Diplaying fragment view for selected nav drawer list item */
  private void displayView(int position) {
    // update the main content by replacing fragments
    Fragment fragment = null;
    switch (position) {
      case 0:
        fragment = new PlanFragment();
        break;
      case 1:
        fragment = new FilterPlanFragment();
        break;
      case 2:
        if ((session != null && session.isLoggedIn())
            || (sessionFacebook != null && sessionFacebook.isOpened())) {
          fragment = new HistoryFragment();
        }
        // if(sessionFacebook.isClosed()){
        else {
          session.checkLogin();
        }
        break;
      case 3:
        if ((session != null && session.isLoggedIn())
            || (sessionFacebook != null && sessionFacebook.isOpened())) {
          fragment = new SettingFragment();
        }
        // if(sessionFacebook.isClosed()){
        else {
          session.checkLogin();
        }
        break;
      default:
        break;
    }

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

      // update selected item and title, then close the drawer
      mDrawerList.setItemChecked(position, true);
      mDrawerList.setSelection(position);
      setTitle(navMenuTitles[position]);
      mDrawerLayout.closeDrawer(mDrawerList);
    } else {
      // error in creating fragment
      Log.e("MainActivity", "Error in creating fragment");
    }
  }
示例#3
0
  private void login() {
    // TODO Auto-generated method stub
    if (session.isLoggedIn()) {
      AlertDialog.Builder builder = new AlertDialog.Builder(this);
      builder.setTitle("Login");
      builder.setIcon(android.R.drawable.ic_dialog_alert);
      builder.setMessage("You are already connected!");
      builder.setPositiveButton(
          "ok",
          new DialogInterface.OnClickListener() {

            @Override
            public void onClick(DialogInterface dialog, int which) {
              Intent i = new Intent(MainActivity.this, MainActivity.class);
              i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
              startActivity(i);
            }
          });
      AlertDialog alert = builder.create();
      alert.show();

    } else {
      Intent i = new Intent(MainActivity.this, LoginActivity.class);
      i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
      startActivity(i);
    }
  }
示例#4
0
  // event handler del boton like
  public void like(View v) {
    // aqui el codigo que se ejucuta cuando se pulsa al buton "i like this plan" porque
    // en fragment_activity.xml he hecho android:onClick="like"

    if ((session != null && session.isLoggedIn())
        || (sessionFacebook != null && sessionFacebook.isOpened())) {
      // Intent i = new Intent(MainActivity.this, Profile.class);
      // i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
      // startActivity(i);
      Toast.makeText(getApplicationContext(), "UNDER CONSTRUCTION", Toast.LENGTH_SHORT).show();

    } else {
      session.checkLogin();
    }
  }
示例#5
0
 private void profile() {
   /*Bundle extras = getIntent().getExtras();
   if (extras != null) {
    Intent i = new Intent(MainActivity.this, Profile.class);
    i.putExtras(extras);
       startActivity(i);
      }else{
    	  Intent i = new Intent(MainActivity.this, Profile.class);
       startActivity(i);
      }*/
   // session.checkLogin();
   if (session.isLoggedIn() || sessionFacebook.isOpened()) {
     Intent i = new Intent(MainActivity.this, Profile.class);
     i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
     startActivity(i);
   }
   if (sessionFacebook.isClosed()) {
     session.checkLogin();
   }
 }