@Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);
    DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
    ActionBarDrawerToggle toggle =
        new ActionBarDrawerToggle(
            this,
            drawer,
            toolbar,
            R.string.navigation_drawer_open,
            R.string.navigation_drawer_close);
    drawer.setDrawerListener(toggle);
    toggle.syncState();

    NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
    navigationView.setNavigationItemSelectedListener(this);
    navigationView.setCheckedItem(R.id.nav_new);

    // viewpager & tabs
    ViewPager pager = (ViewPager) findViewById(R.id.pager);
    final MyFragmentPagerAdapter adapter = new MyFragmentPagerAdapter(getSupportFragmentManager());
    adapter.addFragment(SwitchesFragment.newInstance(0), "swiches");
    adapter.addFragment(ButtonFragment.newInstance(1), "botton");
    adapter.addFragment(ProgressFragment.newInstance(2), "progress");
    adapter.addFragment(TextfieldFragment.newInstance(3), "textfield");
    adapter.addFragment(SliderFragment.newInstance(4), "slider");
    adapter.addFragment(SpinnerFragment.newInstance(5), "spinner");
    adapter.addFragment(DialogsFragment.newInstance(6), "dialogs");
    pager.setAdapter(adapter);

    TabLayout tabLayout = (TabLayout) findViewById(R.id.tabs);
    tabLayout.setupWithViewPager(pager);
  }
 @Override
 protected void onPreExecute() {
   progress = ProgressFragment.newInstance();
   progress.show(getFragmentManager(), "progressFragment");
 }
예제 #3
0
  class OAuthTask extends MyAsyncTask<String, UserBean, DBResult> {

    WeiboException e;

    ProgressFragment progressFragment = ProgressFragment.newInstance();

    @Override
    protected void onPreExecute() {
      progressFragment.setAsyncTask(this);
      progressFragment.show(getSupportFragmentManager(), "");
    }

    @Override
    protected DBResult doInBackground(String... params) {

      String token = params[0];
      long expiresInSeconds = Long.valueOf(params[1]);

      try {
        UserBean user = new OAuthDao(token).getOAuthUserInfo();
        AccountBean account = new AccountBean();
        account.setAccess_token(token);
        account.setExpires_time(System.currentTimeMillis() + expiresInSeconds * 1000);
        account.setInfo(user);
        AppLogger.e("token expires in " + Utility.calcTokenExpiresInDays(account) + " days");
        return AccountDBTask.addOrUpdateAccount(account, false);
      } catch (WeiboException e) {
        AppLogger.e(e.getError());
        this.e = e;
        cancel(true);
        return null;
      }
    }

    @Override
    protected void onCancelled(DBResult dbResult) {
      super.onCancelled(dbResult);
      if (progressFragment != null) {
        progressFragment.dismissAllowingStateLoss();
      }
      if (e != null) Toast.makeText(OAuthActivity.this, e.getError(), Toast.LENGTH_SHORT).show();
      webView.loadUrl(getWeiboOAuthUrl());
    }

    @Override
    protected void onPostExecute(DBResult dbResult) {
      if (progressFragment.isVisible()) {
        progressFragment.dismissAllowingStateLoss();
      }
      switch (dbResult) {
        case add_successfuly:
          Toast.makeText(OAuthActivity.this, getString(R.string.login_success), Toast.LENGTH_SHORT)
              .show();
          break;
        case update_successfully:
          Toast.makeText(
                  OAuthActivity.this,
                  getString(R.string.update_account_success),
                  Toast.LENGTH_SHORT)
              .show();
          break;
      }
      finish();
    }
  }