コード例 #1
0
ファイル: MainActivity.java プロジェクト: hwsyy/AisenWeiBo
  @Override
  protected void onNewIntent(Intent intent) {
    super.onNewIntent(intent);

    if (intent == null) return;

    String action = intent.getAction();

    MenuBean menuBean = MenuGenerator.generateMenu(getActionType(intent, action));

    lastSelectedMenu = menuBean;

    onMenuSelected(menuBean, true, null);

    if ("1".equals(menuBean.getType())) {
      menuFragment.setAccountItem();
      menuFragment.setSelectedMenu(menuBean);
    }

    if (isDrawerOpened()) closeDrawer();
  }
コード例 #2
0
ファイル: MainActivity.java プロジェクト: hwsyy/AisenWeiBo
  public boolean onMenuSelected(MenuBean menu, boolean replace, View view) {
    if (!replace && lastSelectedMenu != null && lastSelectedMenu.getType().equals(menu.getType())) {
      closeDrawer();
      return true;
    }

    int type = Integer.parseInt(menu.getType());

    ABaseFragment fragment = null;
    if (mStripView != null) mStripView.clearAnimation();
    mStripView = null;
    if (animatorSet != null) {
      animatorSet.removeAllListeners();
      animatorSet.end();
      animatorSet = null;
    }
    mToolbar.setTranslationY(0);

    switch (type) {
        // 微博首页
      case 1:
        fragment = TimelineTabsFragment.newInstance();
        break;
        // 提及
      case 2:
        fragment = MentionTabsFragment.newInstance();
        break;
        // 评论
      case 3:
        fragment = CommentTabsFragment.newInstance();
        break;
        // 朋友关系
      case 4:
        fragment = FriendshipTabsFragment.newInstance();
        break;
        // 设置
      case 5:
        closeDrawer();

        SettingsPagerFragment.launch(this);
        return true;
        // 草稿箱
      case 6:
        fragment = DraftFragment.newInstance();
        break;
        // 私信
      case 10:
        new DMAction(this).run();
        return true;
        // 热门微博
      case 11:
        WeiboClientActivity.launchHotStatuses(this);

        closeDrawer();
        return true;
    }

    if (fragment == null) return true;

    getSupportActionBar().setSubtitle(null);
    getSupportActionBar().setTitle(menu.getTitleRes());

    FragmentTransaction ft = getFragmentManager().beginTransaction();
    //		ft.setCustomAnimations(android.R.animator.fade_in, android.R.animator.fade_out,
    //									android.R.animator.fade_in, android.R.animator.fade_out);
    ft.replace(R.id.content_frame, fragment, FRAGMENT_TAG).commit();

    lastSelectedMenu = menu;
    menuFragment.setSelectedMenu(menu);

    setFabType();

    return false;
  }
コード例 #3
0
ファイル: MainActivity.java プロジェクト: hwsyy/AisenWeiBo
  @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);
  }