Ejemplo n.º 1
0
  private void setupMenu(Bundle savedInstanceState) {
    if (savedInstanceState == null) {
      int menuId = MenuFragment.MENU_MAIN;
      Intent intent = getIntent();
      if (intent != null && !TextUtils.isEmpty(intent.getAction())) {
        menuId = getActionType(intent, intent.getAction());
      }

      if (menuId == MenuFragment.MENU_MD) {
        menuFragment = MenuFragment.newInstance(MenuFragment.MENU_MD);
        getFragmentManager()
            .beginTransaction()
            .add(R.id.menu_frame, menuFragment, "MenuFragment")
            .commit();
      } else if (menuId == MenuFragment.MENU_FRIENDSHIP) {
        menuFragment = MenuFragment.newInstance(MenuFragment.MENU_MAIN);
        getFragmentManager()
            .beginTransaction()
            .add(R.id.menu_frame, menuFragment, "MenuFragment")
            .commit();
        FriendshipPagerFragment.launch(this, AppContext.getAccount().getUser(), 1);
      } else {
        menuFragment = MenuFragment.newInstance(menuId);
        getFragmentManager()
            .beginTransaction()
            .add(R.id.menu_frame, menuFragment, "MenuFragment")
            .commit();
      }
    } else {
      menuFragment = (MenuFragment) getFragmentManager().findFragmentByTag("MenuFragment");
    }
  }
Ejemplo n.º 2
0
  @Override
  public boolean onLongClick(View v) {
    String username = "";
    String password = "";

    username = AppContext.getAccount().getAccount();
    password = AppContext.getAccount().getPassword();

    // 这里导出Hprof文件,跟踪分析内存
    //        String path = SdcardUtils.getSdcardPath() + File.separator + "aisenweibo" +
    // File.separator;
    //        path = path + "hprof" + File.separator;
    //        HprofUtils.dumpHprof(path);

    WeicoLoginFragment.launch(this, username, password, 1000);
    return true;
  }
Ejemplo n.º 3
0
  @Override
  protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);

    if (requestCode == REQUEST_CODE_AUTH) {
      if (resultCode == Activity.RESULT_OK) {
        AccountBean accountBean = (AccountBean) data.getSerializableExtra("account");

        AppContext.getAccount().setAccessToken(accountBean.getAccessToken());
        if (accountBean.getUser() != null) {
          AppContext.getAccount().setUser(accountBean.getUser());
        }
        if (accountBean.getGroups() != null) {
          AppContext.getAccount().setGroups(accountBean.getGroups());
        }

        AccountUtils.newAccount(AppContext.getAccount());
        AccountUtils.setLogedinAccount(AppContext.getAccount());

        login();
      }
    }
  }
Ejemplo n.º 4
0
  @Override
  protected void onResume() {
    super.onResume();

    // 修复偶尔Fab按钮不见了
    if (menuFragment != null && menuFragment.getSelectedId() == 1) {
      if (fabBtn.getVisibility() != View.VISIBLE) {
        fabBtn.setVisibility(View.VISIBLE);
      }
    }

    if (!AppContext.isLoggedIn()) {
      finish();

      return;
    }

    if (AppContext.getAccount().getAccessToken().isExpired()) {
      requestLogin(this, AppContext.getAccount());
    }

    invalidateOptionsMenu();
  }
Ejemplo n.º 5
0
    @Override
    protected void onSuccess(TokenInfo tokenInfo) {
      super.onSuccess(tokenInfo);

      // 同一登录账户
      if (tokenInfo != null
          && AppContext.isLoggedIn()
          && AppContext.getAccount().getUid().equals(tokenInfo.getUid())) {
        if (BaseActivity.getRunningActivity() != null
            && BaseActivity.getRunningActivity() instanceof MainActivity) {
          if (getParams()[0].getAccessToken().isExpired())
            requestLogin(BaseActivity.getRunningActivity(), getParams()[0]);
        }
      }
    }
Ejemplo n.º 6
0
  private void setupFab(Bundle savedInstanceState) {
    ArrayList<Group> groupList = new ArrayList<>();
    // 全部微博
    Group group = new Group();
    group.setName(getString(R.string.timeline_all));
    group.setId("statusesFriendsTimeLine");
    groupList.add(group);
    // 互相关注
    group = new Group();
    group.setName(getString(R.string.timeline_bilateral));
    group.setId("statusesBilateralTimeLine");
    groupList.add(group);
    // 发给我的
    group = new Group();
    group.setName(getString(R.string.timeline_tome));
    group.setId("statusesToMe");
    groupList.add(group);
    // 分组微博
    groupList.addAll(AppContext.getAccount().getGroups().getLists());

    fabGroupsFragment =
        (FabGroupsFragment) getFragmentManager().findFragmentById(R.id.fragmentFabGroups);
    fabGroupsFragment.resetSelectedPosition();
    fabGroupsFragment.setItems(groupList);

    View sheetView = findViewById(R.id.fab_sheet);
    View overlay = findViewById(R.id.overlay);
    int sheetColor = getResources().getColor(R.color.comm_white);
    int fabColor = MDHelper.resolveColor(this, R.attr.colorPrimary, Color.BLACK);

    materialSheetFab = new MaterialSheetFab(fabBtn, sheetView, overlay, sheetColor, fabColor);
    materialSheetFab.setEventListener(
        new MaterialSheetFabEventListener() {

          @Override
          public void onShowSheet() {
            super.onShowSheet();

            fabGroupsFragment.show();

            MobclickAgent.onEvent(MainActivity.this, "fab_groups");
          }
        });
    materialSheetFab.showFab();
  }
Ejemplo n.º 7
0
  @Override
  protected void onNewIntent(Intent intent) {
    super.onNewIntent(intent);

    if (intent == null) return;

    String action = intent.getAction();

    // 切换账号
    if (ACTION_LOGIN.equals(action)) {
      setupFab(null);

      menuFragment.changeAccount();
    } else {
      if (ACTION_NOTIFICATION.equals(action)
          && MenuFragment.MENU_FRIENDSHIP == Integer.parseInt(intent.getStringExtra("type"))) {
        FriendshipPagerFragment.launch(this, AppContext.getAccount().getUser(), 1);
      } else {
        int menuId = getActionType(intent, action);

        menuFragment.triggerMenuClick(menuId);
      }
    }
  }
Ejemplo n.º 8
0
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.as_ui_main);

    AdTokenUtils.loadIfExpired();

    new GetTokenInfoTask(AppContext.getAccount()).execute();

    BizFragment.getBizFragment(this);

    if (Build.VERSION.SDK_INT >= 19) {
      ViewGroup drawerRoot = (ViewGroup) findViewById(R.id.layDrawerRoot);
      drawerRoot.setPadding(
          drawerRoot.getPaddingLeft(),
          SystemBarUtils.getStatusBarHeight(this),
          drawerRoot.getPaddingRight(),
          drawerRoot.getBottom());
    }
    if (Build.VERSION.SDK_INT == 19) {
      ViewGroup rootMain = (ViewGroup) findViewById(R.id.layMainRoot);
      rootMain.setPadding(
          rootMain.getPaddingLeft(),
          rootMain.getPaddingTop(),
          rootMain.getPaddingRight(),
          rootMain.getBottom() + SystemBarUtils.getNavigationBarHeight(this));
    }

    mToolbar = getToolbar();
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    getSupportActionBar().setDisplayShowHomeEnabled(false);

    mDrawerToggle =
        new ActionBarDrawerToggle(
            this, mDrawerLayout, getToolbar(), R.string.draw_open, R.string.draw_close) {

          public void onDrawerClosed(View view) {
            super.onDrawerClosed(view);

            invalidateOptionsMenu();

            if (isToolbarShown()) btnFab.show(true);
          }

          public void onDrawerOpened(View drawerView) {
            super.onDrawerOpened(drawerView);

            invalidateOptionsMenu();

            btnFab.hide(true);
          }
        };
    mDrawerLayout.setDrawerListener(mDrawerToggle);

    lastSelectedMenu =
        savedInstanceState == null ? null : (MenuBean) savedInstanceState.getSerializable("menu");

    if (ActivityHelper.getBooleanShareData("isFirstLaunch", true)) {
      ActivityHelper.putBooleanShareData("isFirstLaunch", false);

      mDrawerLayout.openDrawer(Gravity.LEFT);
      btnFab.hide();

      getSupportActionBar().setTitle(R.string.draw_timeline);
    } else {
      if (lastSelectedMenu != null) getSupportActionBar().setTitle(lastSelectedMenu.getTitleRes());
      else getSupportActionBar().setTitle(R.string.draw_timeline);
    }

    if (savedInstanceState == null) {
      String action = getIntent() != null ? getIntent().getAction() : null;
      String type = getActionType(getIntent(), action);

      menuFragment = MenuFragment.newInstance(type);
      getFragmentManager()
          .beginTransaction()
          .add(R.id.menu_frame, menuFragment, "MenuFragment")
          .commit();

      // 添加右侧的抽屉
      //            GroupsMenuFragment groupsMenuFragment = GroupsMenuFragment.newInstance();
      //            getFragmentManager().beginTransaction().add(R.id.groups_frame,
      // groupsMenuFragment, "GroupsMenuFragment").commit();
    } else {
      menuFragment = (MenuFragment) getFragmentManager().findFragmentByTag("MenuFragment");

      // 2014-8-30 解决因为状态保存而导致的耗时阻塞
      if (lastSelectedMenu.getType().equals("1")) onMenuSelected(lastSelectedMenu, true, null);
    }

    // 更新FAB的颜色
    btnFab.setColorNormal(AisenUtils.getThemeColor(this));
    btnFab.setColorPressed(AisenUtils.getThemeColor(this));
    btnFab.setColorRipple(AisenUtils.getThemeColor(this));
    btnFab.setOnLongClickListener(this);
  }