Android Open Source - saostar Login Activity






From Project

Back to project page saostar.

License

The source code is released under:

Apache License

If you think the Android project saostar listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package net.azyobuzi.azyotter.saostar.activities;
/*from   w ww.j  a  v  a  2 s .  c  o  m*/
import twitter4j.Twitter;
import twitter4j.auth.AccessToken;
import twitter4j.auth.RequestToken;
import net.azyobuzi.azyotter.saostar.R;
import net.azyobuzi.azyotter.saostar.Twitter4JFactories;
import net.azyobuzi.azyotter.saostar.StringUtil;
import net.azyobuzi.azyotter.saostar.configuration.Account;
import net.azyobuzi.azyotter.saostar.configuration.Accounts;
import net.azyobuzi.azyotter.saostar.configuration.Setting;
import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.os.Handler;
import android.view.Menu;
import android.view.MenuItem;
import android.view.Window;
import android.widget.TextView;

public class LoginActivity extends Activity {
  private Handler h = new Handler();
  private RequestToken reqToken;

  private TextView status;

  private boolean canceled = false;

  @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    setTheme(Setting.getTheme());
        requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);
        setContentView(R.layout.login_waiting_page);

        getActionBar().setDisplayHomeAsUpEnabled(true);

        status = (TextView)findViewById(R.id.tv_login_waiting_status);

        setProgressBarIndeterminateVisibility(true);

        new Thread(new Runnable() {
      @Override
      public void run() {
        try {
          Twitter tw = Twitter4JFactories.twitterFactory.getInstance();
          reqToken = tw.getOAuthRequestToken();
        } catch (Exception ex) {
          h.post(new Runnable() {
            @Override
            public void run() {
              status.setText(R.string.get_token_failed);
              setProgressBarIndeterminateVisibility(false);
            }
          });
          return;
        }

        if (canceled) return;

        h.post(new Runnable() {
          @Override
          public void run() {
            startActivity(new Intent(Intent.ACTION_VIEW)
              .setData(Uri.parse(reqToken.getAuthorizationURL())));
            status.setText(R.string.waiting_for_you_to_authorize);
            setProgressBarIndeterminateVisibility(false);
          }
        });
      }
        }).start();
  }

  @Override
    public boolean onCreateOptionsMenu(Menu menu) {
    getMenuInflater().inflate(R.menu.login_waiting_menu, menu);
    return true;
  }

  @Override
  public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
      case android.R.id.home:
      case R.id.menu_login_waiting_cancel:
        canceled = true;
        finish();
        return true;
      default:
        return super.onOptionsItemSelected(item);
    }
  }

  @Override
  protected void onNewIntent(Intent intent) {
    if (canceled) return;

    if (intent.getData() != null) {
      String verifier = intent.getData().getQueryParameter("oauth_verifier");

      if (!StringUtil.isNullOrEmpty(verifier)) {
        status.setText(R.string.getting_token);
        setProgressBarIndeterminateVisibility(true);

        new Thread(new Runnable() {
          @Override
          public void run() {
            try {
              Twitter tw = Twitter4JFactories.twitterFactory.getInstance();
              AccessToken token = tw.getOAuthAccessToken(reqToken);

              if (canceled) return;

              if (Accounts.get(token.getUserId()) == null) {
                final Account a = new Account(token.getUserId());
                a.setScreenName(token.getScreenName());
                a.setOAuthToken(token.getToken());
                a.setOAuthTokenSecret(token.getTokenSecret());
                h.post(new Runnable() {
                  @Override
                  public void run() {
                    Accounts.add(a);
                    startActivity(new Intent(LoginActivity.this, AccountsActivity.class)
                      .putExtra(AccountPreferenceFragment.ACCOUNT_ID, a.getId())
                      .putExtra(MainActivity.CALLED_FROM_AZYOTTER, true));
                    finish();
                  }
                });
              }
            } catch (Exception ex) {
              h.post(new Runnable() {
                @Override
                public void run() {
                  status.setText(R.string.get_token_failed);
                  setProgressBarIndeterminateVisibility(false);
                }
              });
            }
          }
        }).start();
      }
    }
  }
}




Java Source Code List

jp.ne.hatena.d.shogo0809.widget.SortableListView.java
net.azyobuzi.azyotter.saostar.ActivityUtil.java
net.azyobuzi.azyotter.saostar.ContextAccess.java
net.azyobuzi.azyotter.saostar.NotificationCenter.java
net.azyobuzi.azyotter.saostar.SaostarApplication.java
net.azyobuzi.azyotter.saostar.StringUtil.java
net.azyobuzi.azyotter.saostar.Twitter4JFactories.java
net.azyobuzi.azyotter.saostar.TwitterUriGenerator.java
net.azyobuzi.azyotter.saostar.activities.AccountPreferenceActivity.java
net.azyobuzi.azyotter.saostar.activities.AccountPreferenceFragment.java
net.azyobuzi.azyotter.saostar.activities.AccountsActivity.java
net.azyobuzi.azyotter.saostar.activities.AccountsFragment.java
net.azyobuzi.azyotter.saostar.activities.ExpandLinkActivity.java
net.azyobuzi.azyotter.saostar.activities.LoginActivity.java
net.azyobuzi.azyotter.saostar.activities.MainActivity.java
net.azyobuzi.azyotter.saostar.activities.RetryActivity.java
net.azyobuzi.azyotter.saostar.activities.SettingActivity.java
net.azyobuzi.azyotter.saostar.activities.SettingFragment.java
net.azyobuzi.azyotter.saostar.activities.TabFilterSettingFragment.java
net.azyobuzi.azyotter.saostar.activities.TabGeneralSettingFragment.java
net.azyobuzi.azyotter.saostar.activities.TabPreferenceActivity.java
net.azyobuzi.azyotter.saostar.activities.TabsActivity.java
net.azyobuzi.azyotter.saostar.activities.TabsFragment.java
net.azyobuzi.azyotter.saostar.activities.TimelineTabFragment.java
net.azyobuzi.azyotter.saostar.activities.TweetDetailActivity.java
net.azyobuzi.azyotter.saostar.activities.TwitterUriHookActivity.java
net.azyobuzi.azyotter.saostar.activities.UpdateStatusActivity.java
net.azyobuzi.azyotter.saostar.configuration.Account.java
net.azyobuzi.azyotter.saostar.configuration.Accounts.java
net.azyobuzi.azyotter.saostar.configuration.Command.java
net.azyobuzi.azyotter.saostar.configuration.Setting.java
net.azyobuzi.azyotter.saostar.configuration.Tab.java
net.azyobuzi.azyotter.saostar.configuration.Tabs.java
net.azyobuzi.azyotter.saostar.d_aqa.Constant.java
net.azyobuzi.azyotter.saostar.d_aqa.FunctionFactory.java
net.azyobuzi.azyotter.saostar.d_aqa.Function.java
net.azyobuzi.azyotter.saostar.d_aqa.Invokable.java
net.azyobuzi.azyotter.saostar.d_aqa.OperatorFactory.java
net.azyobuzi.azyotter.saostar.d_aqa.Operator.java
net.azyobuzi.azyotter.saostar.d_aqa.PropertyFactory.java
net.azyobuzi.azyotter.saostar.d_aqa.Property.java
net.azyobuzi.azyotter.saostar.d_aqa.Reader.java
net.azyobuzi.azyotter.saostar.d_aqa.operators.EqualityOperator.java
net.azyobuzi.azyotter.saostar.d_aqa.operators.GreaterThanOperator.java
net.azyobuzi.azyotter.saostar.d_aqa.operators.GreaterThanOrEqualOperator.java
net.azyobuzi.azyotter.saostar.d_aqa.operators.InequalityOperator.java
net.azyobuzi.azyotter.saostar.d_aqa.operators.LessThanOperator.java
net.azyobuzi.azyotter.saostar.d_aqa.operators.LessThanOrEqualOperator.java
net.azyobuzi.azyotter.saostar.d_aqa.properties.CreatedAtProperty.java
net.azyobuzi.azyotter.saostar.d_aqa.properties.FromCreatedAtProperty.java
net.azyobuzi.azyotter.saostar.d_aqa.properties.FromIdProperty.java
net.azyobuzi.azyotter.saostar.d_aqa.properties.FromNameProperty.java
net.azyobuzi.azyotter.saostar.d_aqa.properties.FromProtectedProperty.java
net.azyobuzi.azyotter.saostar.d_aqa.properties.FromScreenNameProperty.java
net.azyobuzi.azyotter.saostar.d_aqa.properties.FromVerifiedProperty.java
net.azyobuzi.azyotter.saostar.d_aqa.properties.IdProperty.java
net.azyobuzi.azyotter.saostar.d_aqa.properties.InReplyToProperty.java
net.azyobuzi.azyotter.saostar.d_aqa.properties.IsHomeTweetProperty.java
net.azyobuzi.azyotter.saostar.d_aqa.properties.OriginalTextProperty.java
net.azyobuzi.azyotter.saostar.d_aqa.properties.RetweetedCreatedAtProperty.java
net.azyobuzi.azyotter.saostar.d_aqa.properties.RetweetedIdProperty.java
net.azyobuzi.azyotter.saostar.d_aqa.properties.RetweetedProperty.java
net.azyobuzi.azyotter.saostar.d_aqa.properties.RetweetedSourceProperty.java
net.azyobuzi.azyotter.saostar.d_aqa.properties.RetweetedUserCreatedAtProperty.java
net.azyobuzi.azyotter.saostar.d_aqa.properties.RetweetedUserIdProperty.java
net.azyobuzi.azyotter.saostar.d_aqa.properties.RetweetedUserNameProperty.java
net.azyobuzi.azyotter.saostar.d_aqa.properties.RetweetedUserScreenNameProperty.java
net.azyobuzi.azyotter.saostar.d_aqa.properties.RetweetedUserVerifiedProperty.java
net.azyobuzi.azyotter.saostar.d_aqa.properties.SourceProperty.java
net.azyobuzi.azyotter.saostar.d_aqa.properties.TextProperty.java
net.azyobuzi.azyotter.saostar.linq.Enumerable.java
net.azyobuzi.azyotter.saostar.linq.Enumerator.java
net.azyobuzi.azyotter.saostar.services.FavoriteService.java
net.azyobuzi.azyotter.saostar.services.RetweetService.java
net.azyobuzi.azyotter.saostar.services.TimelineReceiveService.java
net.azyobuzi.azyotter.saostar.services.UpdateStatusService.java
net.azyobuzi.azyotter.saostar.system.Action1.java
net.azyobuzi.azyotter.saostar.system.Action2.java
net.azyobuzi.azyotter.saostar.system.Action3.java
net.azyobuzi.azyotter.saostar.system.Action.java
net.azyobuzi.azyotter.saostar.system.Func1.java
net.azyobuzi.azyotter.saostar.system.Func2.java
net.azyobuzi.azyotter.saostar.system.Func.java
net.azyobuzi.azyotter.saostar.timeline_data.TimelineItemCollection.java
net.azyobuzi.azyotter.saostar.timeline_data.TimelineItemId.java
net.azyobuzi.azyotter.saostar.timeline_data.TimelineItem.java
net.azyobuzi.azyotter.saostar.timeline_data.TweetEntities.java
net.azyobuzi.azyotter.saostar.timeline_data.UserCollection.java
net.azyobuzi.azyotter.saostar.timeline_data.UserInfo.java
net.azyobuzi.azyotter.saostar.widget.AccountSelector.java
net.azyobuzi.azyotter.saostar.widget.CustomizedUrlImageView.java