private void refreshLoginState() {
   User userLoggedin = TavernaAndroid.getMyEUserLoggedin();
   String userName = null;
   if (userLoggedin != null) {
     userName = userLoggedin.getName();
     Bitmap avatarBitmap =
         TavernaAndroid.getmMemoryCache().get(userLoggedin.getAvatar().getResource());
     if (avatarBitmap != null) {
       // TODO : fixed scaled to 80 x 80
       Drawable avatarDrawable =
           new BitmapDrawable(
               getResources(), Bitmap.createScaledBitmap(avatarBitmap, 80, 80, false));
       /*Rect outRect = new Rect();
       myExperimentLoginText.getDrawingRect(outRect);
       // resize the Rect
       //outRect.inset(-10, 10);
       avatarDrawable.setBounds(outRect);
       myExperimentLoginText.setCompoundDrawables(avatarDrawable, null, null, null);*/
       myExperimentLoginText.setCompoundDrawablesWithIntrinsicBounds(
           avatarDrawable, null, null, null);
     }
     myExperimentLoginText.setText("Logged in as:\n" + userName);
   } else {
     Drawable defaultDrawable = getResources().getDrawable(R.drawable.myexperiment_logo_small);
     myExperimentLoginText.setCompoundDrawablesWithIntrinsicBounds(
         defaultDrawable, null, null, null);
     myExperimentLoginText.setText("Log in to myExperiment");
     myExperimentLoginText.setTextSize(15);
   }
 }
  public void onActivityCreated(Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);
    parentActivity = this.getActivity();
    layoutInflater =
        ((LayoutInflater) parentActivity.getSystemService(Context.LAYOUT_INFLATER_SERVICE));
    font = Typeface.createFromAsset(parentActivity.getAssets(), "Roboto-Light.ttf");
    myExperimentLoginText.setTypeface(font);
    myExperimentLoginText.setTextSize(20);
    myExperimentLoginText.setOnClickListener(
        new android.view.View.OnClickListener() {
          @Override
          public void onClick(View v) {
            User user = TavernaAndroid.getMyEUserLoggedin();
            if (user != null) {
              MessageHelper.showOptionsDialog(
                  parentActivity,
                  "Do you wish to log out ?",
                  "Attention",
                  new CallbackTask() {
                    @Override
                    public Object onTaskInProgress(Object... param) {
                      // Clear user logged-in and cookie
                      TavernaAndroid.setMyEUserLoggedin(null);
                      TavernaAndroid.setMyExperimentSessionCookies(null);
                      TavernaAndroid.setMyWorkflows(null);
                      TavernaAndroid.setFavouriteWorkflows(null);
                      clearLoginPreference();
                      parentActivity.recreate();
                      // refreshLoginState();
                      return null;
                    }

                    @Override
                    public Object onTaskComplete(Object... result) {
                      return null;
                    }
                  },
                  null);
            } else {
              ((MainPanelActivity) parentActivity).getMenu().toggle();
              Intent gotoMyexperimentLogin = new Intent(parentActivity, MyExperimentLogin.class);
              parentActivity.startActivity(gotoMyexperimentLogin);
            }
          }
        });

    // create a new AuthSession so that we can use the Dropbox API.
    AndroidAuthSession session = buildSession();
    mApi = new DropboxAPI<AndroidAuthSession>(session);
    TavernaAndroid.setmApi(mApi);
    if (dropboxLoggedIn()) {
      getDropboxAccountInfo();
    }
    authenticating = false;
  }
  private void refreshMenus() {
    listRoot.removeAllViews();
    // Navigation Menu
    final User userloggedIn = TavernaAndroid.getMyEUserLoggedin();
    ListView navigationMenuList = null;
    String[] navigationMenuNames = null;
    int[] navigationMenuIcons = null;
    if (userloggedIn != null) {
      navigationMenuNames =
          new String[] {"Workflow Run Control", "Explore Workflows", "My Workflows"};
      navigationMenuIcons =
          new int[] {
            R.drawable.gear_icon, R.drawable.myexperiment_logo_small, R.drawable.bookmark_icon
          };
    } else {
      navigationMenuNames = new String[] {"Workflow Run Control", "Explore Workflows"};
      navigationMenuIcons = new int[] {R.drawable.gear_icon, R.drawable.myexperiment_logo_small};
    }
    navigationMenuList = setupList("Navigation", navigationMenuNames, navigationMenuIcons);

    // DataSourc Menu
    if (dataSourceNames == null) {
      dataSourceNames = new String[] {"Dropbox", "Google Drive"};
    }
    int[] dataSourceIcons = new int[] {R.drawable.dropbox_icon, R.drawable.google_drive_icon};
    ListView dataSourceList = setupList("Data Source", dataSourceNames, dataSourceIcons);

    // Other Menu
    String[] otherMenuNames = null;
    int[] otherMenuIcons = null;
    if (userloggedIn == null) {
      otherMenuNames = new String[] {"Settings"};
      otherMenuIcons = new int[] {R.drawable.settings_icon_dark};
    } else {
      otherMenuNames = new String[] {"Settings", "Sign Out"};
      otherMenuIcons = new int[] {R.drawable.settings_icon_dark, R.drawable.sign_out_icon};
    }
    ListView settingList = setupList("Others", otherMenuNames, otherMenuIcons);

    // list item click event setting
    if (navigationMenuList != null) {
      navigationMenuList.setOnItemClickListener(
          new OnItemClickListener() {
            @Override
            public void onItemClick(
                AdapterView<?> theListView, View parentView, int itemIndex, long arg3) {
              if (previouslySelectedFragIndex == itemIndex) {
                ((MainPanelActivity) parentActivity).getMenu().toggle();
              } else {
                previouslySelectedFragIndex = itemIndex;
                if (itemIndex == 1) {
                  beginFragmentTransaction(new int[] {2, 3}, "RunsControlFragment");
                } else if (itemIndex == 2) {
                  beginFragmentTransaction(new int[] {0, 1}, "WorkflowsFragment");
                } else if (itemIndex == 3) {
                  beginFragmentTransaction(new int[] {4, 5}, "MyWorkflowsFragment");
                }
              }
            }
          });
    }

    dataSourceList.setOnItemClickListener(
        new OnItemClickListener() {
          @Override
          public void onItemClick(
              AdapterView<?> theListView, View parentView, int itemIndex, long arg3) {
            // TODO: setup dropbox and google drive
            if (itemIndex == 1) {
              // log out if logged in, or vice versa
              if (dropboxLoggedIn()) {
                MessageHelper.showOptionsDialog(
                    parentActivity,
                    "Do you wish to unlink with current dropbox account ?",
                    "Attention",
                    new CallbackTask() {
                      @Override
                      public Object onTaskInProgress(Object... param) {
                        logOutDropbox();
                        return null;
                      }

                      @Override
                      public Object onTaskComplete(Object... result) {
                        return null;
                      }
                    },
                    null);
              } else {
                // Start the remote authentication
                authenticating = true;
                mApi.getSession().startAuthentication(parentActivity);
              } // end of else
            } else if (itemIndex == 2) {
            }
          }
        });

    settingList.setOnItemClickListener(
        new OnItemClickListener() {
          @Override
          public void onItemClick(
              AdapterView<?> theListView, View parentView, int itemIndex, long arg3) {
            if (itemIndex == 1) {
              ((MainPanelActivity) parentActivity).getMenu().toggle();
              Intent goToSetting = new Intent(parentActivity, SettingsActivity.class);
              parentActivity.startActivity(goToSetting);
            } else if (itemIndex == 2) {
              MessageHelper.showOptionsDialog(
                  parentActivity,
                  "Do you wish to log out ?",
                  "Attention",
                  new CallbackTask() {
                    @Override
                    public Object onTaskInProgress(Object... param) {
                      // Clear user logged-in and cookie
                      TavernaAndroid.setMyEUserLoggedin(null);
                      TavernaAndroid.setMyExperimentSessionCookies(null);
                      TavernaAndroid.setMyWorkflows(null);
                      TavernaAndroid.setFavouriteWorkflows(null);
                      parentActivity.recreate();
                      // refreshLoginState();
                      // clearLoginPreference();
                      // refreshMenus();
                      return null;
                    }

                    @Override
                    public Object onTaskComplete(Object... result) {
                      return null;
                    }
                  },
                  null);
            } // end of else if
          }
        });
  }