Android Open Source - androidcodes New Account Activity






From Project

Back to project page androidcodes.

License

The source code is released under:

GNU General Public License

If you think the Android project androidcodes 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 com.app.twitterclient.view;
/*from  w w  w  . j  a v  a2s.  co m*/
import twitter4j.Twitter;
import twitter4j.TwitterException;
import twitter4j.TwitterFactory;
import twitter4j.auth.RequestToken;
import twitter4j.conf.Configuration;
import twitter4j.conf.ConfigurationBuilder;
import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import android.os.AsyncTask;
import android.os.Bundle;
import android.widget.Toast;

import com.app.twitterclient.R;
import com.app.twitterclient.model.TwitterBackend;
import com.app.twitterclient.utils.ConnectionDetector;
import com.app.twitterclient.utils.ConsumerKeyConstants;

public class NewAccountActivity extends Activity {

  private static final int OAUTH_REQUEST = 1;
  private RequestToken mRequestToken;

  // Twitter
  private static Twitter mTwitter;

  private TwitterBackend mTwitterBackend;

  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    mTwitterBackend = new TwitterBackend(
        ConsumerKeyConstants.TWITTER_CONSUMER_KEY,
        ConsumerKeyConstants.TWITTER_CONSUMER_SECRET, this);
    ConnectionDetector connectionDetector = new ConnectionDetector(this);
    if (connectionDetector.isConnectingToInternet()) {
      loginToTwitter();

    } else {
      Toast.makeText(this, getString(R.string.no_internet_connection),
          Toast.LENGTH_LONG).show();
    }

  }

  private void loginToTwitter() {

    ConfigurationBuilder builder = new ConfigurationBuilder();
    builder.setOAuthConsumerKey(ConsumerKeyConstants.TWITTER_CONSUMER_KEY);
    builder.setOAuthConsumerSecret(ConsumerKeyConstants.TWITTER_CONSUMER_SECRET);
    Configuration configuration = builder.build();

    TwitterFactory factory = new TwitterFactory(configuration);
    mTwitter = factory.getInstance();

    try {
      mTwitterLogin.execute();

    } catch (Exception ex) {
      ex.printStackTrace();
    }

  }

  @Override
  protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (requestCode == OAUTH_REQUEST && resultCode == RESULT_OK) {
      Uri url = Uri.parse(data.getExtras().getString("url"));
      String verifier = url.getQueryParameter("oauth_verifier");
      mTwitterBackend.setAccessToken(verifier);
      mTwitterBackend.twitterInit();
      mTwitterBackend.saveToken();
      finish();
      startActivity(new Intent(getApplicationContext(),
          HomeActivity.class));
    } else if (resultCode == RESULT_CANCELED) {
      Toast.makeText(this, getString(R.string.cannot_connect_to_twitter),
          Toast.LENGTH_SHORT).show();
    }
  }

  private AsyncTask<Void, Void, RequestToken> mTwitterLogin = new AsyncTask<Void, Void, RequestToken>() {

    @Override
    protected RequestToken doInBackground(Void... params) {

      try {
        mRequestToken = mTwitter
            .getOAuthRequestToken(ConsumerKeyConstants.TWITTER_CALLBACK_URL);
      } catch (TwitterException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
      }
      return mRequestToken;
    }

    @Override
    protected void onPostExecute(RequestToken requestToken) {
      // TODO Auto-generated method stub
      super.onPostExecute(requestToken);
      String url = mTwitterBackend.getAuthorizationURL();
      Intent intent = new Intent(getApplicationContext(),
          TwitterAuthActivity.class);
      intent.putExtra("url", url);
      overridePendingTransition(0, 0);
      intent.setFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);
      intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
      startActivityForResult(intent, OAUTH_REQUEST);
      

    }

  };

}




Java Source Code List

com.app.citypediav2.Constants.java
com.app.citypediav2.CustomButton.java
com.app.citypediav2.CustomEditText.java
com.app.citypediav2.CustomText.java
com.app.citypediav2.DetailsActivity.java
com.app.citypediav2.ItemListActivity.java
com.app.citypediav2.ItemListAdapter.java
com.app.citypediav2.ListAdapterOptions.java
com.app.citypediav2.MainActivity.java
com.app.citypediav2.MainApplication.java
com.app.citypediav2.Options.java
com.app.citypediav2.receivers.BootCompletedBroadcastReceiver.java
com.app.citypediav2.receivers.ConnectionChangeReceiver.java
com.app.citypediav2.services.DataLoggingService.java
com.app.citypediav2.utils.AppUtils.java
com.app.citypediav2.utils.ArticleTextExtractor.java
com.app.citypediav2.utils.Constants.java
com.app.citypediav2.utils.LogUtils.java
com.app.citypediav2.utils.PrefUtils.java
com.app.twitterclient.model.TwitterBackend.java
com.app.twitterclient.utils.AppUtils.java
com.app.twitterclient.utils.ConnectionDetector.java
com.app.twitterclient.utils.ConsumerKeyConstants.java
com.app.twitterclient.utils.LogUtils.java
com.app.twitterclient.view.BootActivity.java
com.app.twitterclient.view.HomeActivity.java
com.app.twitterclient.view.NewAccountActivity.java
com.app.twitterclient.view.TwitterAuthActivity.java
com.binarysearch.BinarySearch.java
com.citypedia.app.enities.Atms.java
com.citypedia.app.enities.Cabs.java
com.citypedia.app.enities.Gyms.java
com.citypedia.app.enities.PetrolPumps.java
com.citypedia.app.enities.PlacesToVisit.java
com.citypedia.app.enities.Restaurants.java
com.citypedia.app.providers.CityDB.java
com.citypedia.app.providers.CityPediaProvider.java
com.citypedia.app.providers.ContentDescriptor.java
com.info.magazine.MainActivity.java
com.java.thread.ConditionExample.java
com.java.thread.DeadLock.java
com.java.thread.Main.java
com.java.thread.ProdConsumerProb.java
com.java.thread.SampleThread.java
com.java.thread.package-info.java
com.lists.LinkedListImpl.java
com.pract.threadpool.CustomQueue.java
com.pract.threadpool.MyQueue.java
com.pract.threadpool.TestThreadPoolManager.java
com.pract.threadpool.ThreadPoolManager.java
com.pract.threadpool.Worker.java
com.queues.QueuesImpl.java
com.rjil.logcollector.DeviceBroadcastReceiver.java
com.rjil.logcollector.LogCollectorService.java
com.rjil.logcollector.LogDumper.java
com.sorting.InsertionSort.java
com.sorting.package-info.java
com.stacks.BracketChecker.java
com.stacks.StackImpl.java
com.stacks.StockSpan.java