Example usage for twitter4j TwitterAdapter TwitterAdapter

List of usage examples for twitter4j TwitterAdapter TwitterAdapter

Introduction

In this page you can find the example usage for twitter4j TwitterAdapter TwitterAdapter.

Prototype

TwitterAdapter

Source Link

Usage

From source file:com.borqs.qiupu.ui.bpc.BeamDataByNFCActivity.java

License:Apache License

private void getUserInfo(final long userid) {
    if (!AccountServiceUtils.isAccountReady()) {
        return;// w  ww. j  a  v a 2 s.  c o m
    }

    synchronized (mInfoLock) {
        if (inInfoProcess == true) {
            Log.d(TAG, "in loading info data");
            return;
        }
    }

    if (isUiLoading() == false) {
        begin();
    }

    synchronized (mInfoLock) {
        inInfoProcess = true;
    }
    asyncQiupu.getUserInfo(userid, getSavedTicket(), new TwitterAdapter() {
        public void getUserInfo(QiupuUser user) {
            Log.d(TAG, "finish getUserInfo=" + user);
            mUser = user;

            synchronized (mInfoLock) {
                inInfoProcess = false;
            }

            // update database
            if ((user.circleId != null && user.circleId.length() > 0)
                    || userid == AccountServiceUtils.getBorqsAccountID()) {
                orm.insertUserinfo(user);
                // create share source data, need it is my friends.
                if (mUser.circleId != null && mUser.circleId.length() > 0) {
                    orm.updateShareSourceDB(userid, user.sharedResource);
                }
            }

            Message msg = mHandler.obtainMessage(GET_USER_FROM_SERVER_END);
            msg.getData().putBoolean(RESULT, true);
            msg.sendToTarget();
        }

        public void onException(TwitterException ex, TwitterMethod method) {

            synchronized (mInfoLock) {
                inInfoProcess = false;
            }
            TwitterExceptionUtils.printException(TAG, "getUserInfo, server exception:", ex, method);
            Log.d(TAG, "fail to load user info=" + ex.getMessage());

            Message msg = mHandler.obtainMessage(GET_USER_FROM_SERVER_END);
            msg.getData().putString(ERROR_MSG, ex.getMessage());
            msg.getData().putBoolean(RESULT, false);
            msg.sendToTarget();
        }
    });
}

From source file:com.marpies.ane.twitter.data.TwitterAPI.java

License:Apache License

public static void getAccessTokensForPIN(String PIN) {
    final AsyncTwitter twitter = getAsyncInstance();
    twitter.addListener(new TwitterAdapter() {
        @Override/*from   ww w .  j a  va 2s  .  c om*/
        public void gotOAuthAccessToken(AccessToken token) {
            AIR.log("Retrieved access tokens");
            /* Store access tokens */
            TwitterAPI.storeAccessTokens(token);
            AIR.dispatchEvent(AIRTwitterEvent.LOGIN_SUCCESS);
        }

        @Override
        public void onException(TwitterException te, TwitterMethod method) {
            if (method == TwitterMethod.OAUTH_ACCESS_TOKEN) {
                AIR.dispatchEvent(AIRTwitterEvent.LOGIN_ERROR, StringUtils.removeLineBreaks(te.getMessage()));
            }
        }
    });
    twitter.getOAuthAccessTokenAsync(mRequestToken, PIN);
}

From source file:com.marpies.ane.twitter.LoginActivity.java

License:Apache License

/**
 *
 *
 * Private API//from w w  w .java  2s . com
 *
 *
 */

private TwitterAdapter getOAuthRequestTokenListener(final boolean forceLogin) {
    return new TwitterAdapter() {
        @Override
        public void gotOAuthRequestToken(RequestToken token) {
            TwitterAPI.setRequestToken(token);
            StringBuilder urlBuilder = new StringBuilder(token.getAuthenticationURL());
            if (forceLogin) {
                urlBuilder.append("&force_login=true");
            }
            /* Launch browser */
            LoginActivity.this.startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(urlBuilder.toString())));
        }

        @Override
        public void onException(TwitterException te, TwitterMethod method) {
            if (method == TwitterMethod.OAUTH_REQUEST_TOKEN) {
                AIR.log("Request token exception " + te.getMessage());
                AIR.dispatchEvent(AIRTwitterEvent.LOGIN_ERROR, StringUtils.removeLineBreaks(te.getMessage()));
            }
            finish();
        }
    };
}

From source file:com.twitt4droid.activity.WebLoginActivity.java

License:Apache License

/** Sets up Twitter async listeners. */
private void setUpTwitter() {
    twitter = Twitt4droid.getAsyncTwitter(this);
    twitter.addListener(new TwitterAdapter() {
        @Override/*from  w  w w  . j a  va 2 s  . co  m*/
        public void verifiedCredentials(final User user) {
            runOnUiThread(new Runnable() {

                @Override
                public void run() {
                    handleUserValidation(user);
                }
            });
        }

        @Override
        public void gotOAuthRequestToken(final RequestToken token) {
            runOnUiThread(new Runnable() {

                @Override
                public void run() {
                    String url = token.getAuthenticationURL();
                    urlTextView.setText(url);
                    webView.loadUrl(url);
                }
            });
        }

        @Override
        public void gotOAuthAccessToken(final AccessToken token) {
            runOnUiThread(new Runnable() {

                @Override
                public void run() {
                    Twitt4droid.saveAuthenticationInfo(getApplicationContext(), token);
                }
            });
        }

        @Override
        public void onException(TwitterException te, TwitterMethod method) {
            Log.e(TAG, "Twitter error in " + method, te);
            runOnUiThread(new Runnable() {

                @Override
                public void run() {
                    showErrorAlertDialog();
                }
            });
        }
    });
}

From source file:com.twitt4droid.app.fragment.ListsFragment.java

License:Apache License

private void setUpTwitter() {
    twitter = Twitt4droid.getAsyncTwitter(getActivity());
    twitter.addListener(new TwitterAdapter() {

        @Override// ww  w .j a  v  a  2  s  .co m
        public void gotUserLists(final ResponseList<UserList> userLists) {
            if (getActivity() != null) {
                getActivity().runOnUiThread(new Runnable() {

                    @Override
                    public void run() {
                        if (userLists != null && !userLists.isEmpty()) {
                            for (UserList userList : userLists) {
                                ListTimelineFragment fragment = ListTimelineFragment.newInstance(userList,
                                        isDarkThemeSelected());
                                adapter.addFragment(fragment);
                            }
                        }
                    }
                });
            }
        }

        @Override
        public void onException(TwitterException te, TwitterMethod method) {
            if (getActivity() != null) {
                getActivity().runOnUiThread(new Runnable() {

                    @Override
                    public void run() {
                        Toast.makeText(getActivity().getApplicationContext(),
                                R.string.twitt4droid_error_message, Toast.LENGTH_SHORT).show();
                    }
                });
            }
        }
    });
}

From source file:com.twitt4droid.fragment.UserTimelineFragment.java

License:Apache License

/** Sets up twitter callbacks. */
private void setUpTwitter() {
    twitter.addListener(new TwitterAdapter() {

        @Override//from  ww  w. j  a v  a  2 s  .c  om
        public void gotUserDetail(final User user) {
            if (getActivity() != null) {
                getActivity().runOnUiThread(new Runnable() {

                    @Override
                    public void run() {
                        if (user != null)
                            setUpUser(user);
                    }
                });
            }
        }

        @Override
        public void onException(TwitterException te, TwitterMethod method) {
            Log.e(TAG, "Twitter error in" + method, te);
            if (getActivity() != null) {
                getActivity().runOnUiThread(new Runnable() {

                    @Override
                    public void run() {
                        Toast.makeText(getActivity().getApplicationContext(),
                                R.string.twitt4droid_error_message, Toast.LENGTH_LONG).show();
                    }
                });
            }
        }
    });
}

From source file:com.twitt4droid.widget.TweetAdapter.java

License:Apache License

/** Sets up twitter callbacks. */
private void setUpTwitter() {
    twitter.addListener(new TwitterAdapter() {

        @Override/* w ww .  j  a v a2s.  co  m*/
        public void createdFavorite(Status status) {
            ((Activity) context).runOnUiThread(new Runnable() {

                @Override
                public void run() {
                    Toast.makeText(context.getApplicationContext(), R.string.twitt4droid_tweet_favorited,
                            Toast.LENGTH_SHORT).show();
                }
            });
        }

        @Override
        public void retweetedStatus(Status retweetedStatus) {
            ((Activity) context).runOnUiThread(new Runnable() {

                @Override
                public void run() {
                    Toast.makeText(context.getApplicationContext(), R.string.twitt4droid_tweet_retweeted,
                            Toast.LENGTH_SHORT).show();
                }
            });
        }

        @Override
        public void onException(TwitterException te, TwitterMethod method) {
            Log.e(TAG, "Twitter error in" + method, te);
            ((Activity) context).runOnUiThread(new Runnable() {

                @Override
                public void run() {
                    Toast.makeText(context.getApplicationContext(), R.string.twitt4droid_error_message,
                            Toast.LENGTH_SHORT).show();
                }
            });
        }
    });
}

From source file:com.twitt4droid.widget.TweetDialog.java

License:Apache License

/** Initializes components. */
private void init() {
    if (!Twitt4droid.isUserLoggedIn(getContext()))
        throw new IllegalStateException("User must be logged in in order to use TweetDialog");
    twitter = Twitt4droid.getAsyncTwitter(getContext());
    twitter.addListener(new TwitterAdapter() {
        @Override/*www  .j  ava 2  s .co m*/
        public void gotUserDetail(final User user) {
            ((Activity) getContext()).runOnUiThread(new Runnable() {

                @Override
                public void run() {
                    setUpUser(user);
                }
            });
        }

        @Override
        public void updatedStatus(Status status) {
            ((Activity) getContext()).runOnUiThread(new Runnable() {

                @Override
                public void run() {
                    Toast.makeText(getContext().getApplicationContext(), R.string.twitt4droid_tweet_sent,
                            Toast.LENGTH_SHORT).show();
                }
            });
        }

        @Override
        public void onException(TwitterException te, TwitterMethod method) {
            Log.e(TAG, "Twitter error in " + method, te);
            ((Activity) getContext()).runOnUiThread(new Runnable() {

                @Override
                public void run() {
                    Toast.makeText(getContext().getApplicationContext(), R.string.twitt4droid_error_message,
                            Toast.LENGTH_LONG).show();
                }
            });
        }
    });
    requestWindowFeature(Window.FEATURE_NO_TITLE);
    setContentView(R.layout.twitt4droid_new_tweet);
    inputMethodManager = (InputMethodManager) getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
    findViews();
    initConsts();
    setUpTweetEditText();
    setUpTweetButton();
    setUpUser(Twitt4droid.getCurrentUser(getContext()));
    if (Resources.isConnectedToInternet(getContext()))
        twitter.showUser(Twitt4droid.getCurrentUser(getContext()).getScreenName());
}

From source file:net.nokok.twitduke.pluginsupport.TwitterAPI.java

License:Open Source License

@Override
public void onException(ThrowableReceivable receiver) {
    asyncTwitter.addListener(new TwitterAdapter() {

        @Override/*from   ww w  .j av a 2 s.  c o  m*/
        public void onException(TwitterException te, TwitterMethod method) {
            receiver.onError(te);
        }

    });
}

From source file:org.primefaces.examples.service.TwitterAPIService.java

License:Apache License

public List<Status> asyncSearch(String query) {

    TwitterListener listener = new TwitterAdapter() {
        @Override/*from  w w w .  ja v  a2  s  .  c  o m*/
        public void searched(QueryResult queryResult) {
            asyncTweets = queryResult.getTweets();
        }

        @Override
        public void onException(TwitterException e, TwitterMethod method) {
            logger.severe(e.getMessage());
        }
    };

    AsyncTwitter twitter = new AsyncTwitterFactory().getInstance();
    twitter.setOAuthConsumer(twitter_consumer_key, twitter_consumer_secret);
    twitter.setOAuthAccessToken(new AccessToken(access_token, access_token_secret));
    twitter.addListener(listener);
    Query q = new Query(query);
    twitter.search(q);
    return asyncTweets;
}