本文整理汇总了Java中com.twitter.sdk.android.core.Twitter类的典型用法代码示例。如果您正苦于以下问题:Java Twitter类的具体用法?Java Twitter怎么用?Java Twitter使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Twitter类属于com.twitter.sdk.android.core包,在下文中一共展示了Twitter类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: initFabric
import com.twitter.sdk.android.core.Twitter; //导入依赖的package包/类
public void initFabric(Context reactContext) {
if (consumerKey == null || consumerSecret == null) {
return;
}
TwitterAuthConfig authConfig
= new TwitterAuthConfig(consumerKey, consumerSecret);
final TwitterConfig config = new TwitterConfig.Builder(reactContext)
.twitterAuthConfig(authConfig)
.debug(true)
.build();
Twitter.initialize(config);
new Thread(new Runnable() {
@Override
public void run() {
TweetUi.getInstance();
Log.i("ReactTwitterKit", "TweetUi instance initialized");
}
}).start();
}
示例2: initializeTwitterLogin
import com.twitter.sdk.android.core.Twitter; //导入依赖的package包/类
void initializeTwitterLogin() {
Twitter.initialize(LoginActivity.this);
mLoginButton = (TwitterLoginButton) findViewById(R.id.login_button);
mLoginButton.setCallback(new Callback<TwitterSession>() {
@Override
public void success(Result<TwitterSession> result) {
// Do something with result, which provides a TwitterSession for making API calls
Log.d(TAG, "twitterLogin:success" + result);
handleTwitterSession(result.data);
}
@Override
public void failure(TwitterException exception) {
Log.w(TAG, "twitterLogin:failure", exception);
}
});
}
示例3: TwitterHelper
import com.twitter.sdk.android.core.Twitter; //导入依赖的package包/类
/**
* Public constructor. This will initialize twitter sdk.
*
* @param twitterApiKey twitter api key
* @param twitterSecreteKey twitter secrete key
* @param response {@link TwitterResponse} response listener.
* @param context instance of the caller.
*/
public TwitterHelper(@StringRes final int twitterApiKey,
@StringRes final int twitterSecreteKey,
@NonNull TwitterResponse response,
@NonNull Activity context) {
//noinspection ConstantConditions
if (response == null) throw new IllegalArgumentException("TwitterResponse cannot be null.");
mActivity = context;
mListener = response;
//initialize sdk
TwitterConfig authConfig = new TwitterConfig.Builder(context)
.logger(new DefaultLogger(Log.DEBUG))
.twitterAuthConfig(new TwitterAuthConfig(context.getResources().getString(twitterApiKey),
context.getResources().getString(twitterSecreteKey)))
.debug(true)
.build();
Twitter.initialize(authConfig);
mAuthClient = new TwitterAuthClient();
}
示例4: prepare
import com.twitter.sdk.android.core.Twitter; //导入依赖的package包/类
void prepare(PlayerActivity.PlayerItem item) {
try {
setUpCallToAction(item);
setUpMediaControl(item.looping, item.showVideoControls);
final View.OnTouchListener listener = SwipeToDismissTouchListener
.createFromView(videoView, callback);
videoView.setOnTouchListener(listener);
videoView.setOnPreparedListener(mediaPlayer -> videoProgressView.setVisibility(View.GONE));
videoView.setOnInfoListener((mediaPlayer, what, extra) -> {
if (what == MediaPlayer.MEDIA_INFO_BUFFERING_END) {
videoProgressView.setVisibility(View.GONE);
return true;
} else if (what == MediaPlayer.MEDIA_INFO_BUFFERING_START) {
videoProgressView.setVisibility(View.VISIBLE);
return true;
}
return false;
});
final Uri uri = Uri.parse(item.url);
videoView.setVideoURI(uri, item.looping);
videoView.requestFocus();
} catch (Exception e) {
Twitter.getLogger().e(TAG, "Error occurred during video playback", e);
}
}
示例5: loadTweet
import com.twitter.sdk.android.core.Twitter; //导入依赖的package包/类
/**
* LoadTweet will trigger a request to the Twitter API and hydrate the view with the result.
* In the event of an error it will call the listener that was provided to setOnTwitterApiError.
*/
private void loadTweet() {
final long tweetId = getTweetId();
// create a callback to setTweet on the view or log a failure to load the Tweet
final Callback<Tweet> repoCb = new Callback<Tweet>() {
@Override
public void success(Result<Tweet> result) {
setTweet(result.data);
}
@Override
public void failure(TwitterException exception) {
Twitter.getLogger().d(TAG,
String.format(Locale.ENGLISH, TweetUtils.LOAD_TWEET_DEBUG, tweetId));
}
};
dependencyProvider.getTweetUi().getTweetRepository().loadTweet(getTweetId(), repoCb);
}
示例6: getLinkClickListener
import com.twitter.sdk.android.core.Twitter; //导入依赖的package包/类
protected LinkClickListener getLinkClickListener() {
if (linkClickListener == null) {
linkClickListener = url -> {
if (TextUtils.isEmpty(url)) return;
if (tweetLinkClickListener != null) {
tweetLinkClickListener.onLinkClick(tweet, url);
} else {
final Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
if (!IntentUtils.safeStartActivity(getContext(), intent)) {
Twitter.getLogger().e(TweetUi.LOGTAG,
"Activity cannot be found to open URL");
}
}
};
}
return linkClickListener;
}
示例7: loadTweet
import com.twitter.sdk.android.core.Twitter; //导入依赖的package包/类
/**
* Loads a single Tweet by id.
* @param tweetId Tweet id
* @param cb callback
*/
public static void loadTweet(final long tweetId, final Callback<Tweet> cb) {
TweetUi.getInstance().getTweetRepository().loadTweet(tweetId,
new LoggingCallback<Tweet>(cb, Twitter.getLogger()) {
@Override
public void success(Result<Tweet> result) {
if (cb != null) {
cb.success(result);
}
}
});
}
示例8: loadTweets
import com.twitter.sdk.android.core.Twitter; //导入依赖的package包/类
/**
* Loads a List of Tweets by id. Returns Tweets in the order requested.
* @param tweetIds List of Tweet ids
* @param cb callback
*/
public static void loadTweets(final List<Long> tweetIds, final Callback<List<Tweet>> cb) {
TweetUi.getInstance().getTweetRepository().loadTweets(tweetIds,
new LoggingCallback<List<Tweet>>(cb, Twitter.getLogger()) {
@Override
public void success(Result<List<Tweet>> result) {
if (cb != null) {
cb.success(result);
}
}
});
}
示例9: setUp
import com.twitter.sdk.android.core.Twitter; //导入依赖的package包/类
@Override
protected void setUp() throws Exception {
super.setUp();
createMocks();
// Initialize Fabric with mock executor so that kit#doInBackground() will not be called
// during kit initialization.
final TwitterConfig config = new TwitterConfig.Builder(getContext())
.logger(new DefaultLogger(Log.DEBUG))
.executorService(mock(ThreadPoolExecutor.class))
.build();
Twitter.initialize(config);
final TwitterCore twitterCore = TwitterCoreTestUtils.createTwitterCore(
new TwitterAuthConfig("", ""), clients, apiClient);
tweetUi = TweetUi.getInstance();
final TweetRepository tweetRepository = new TweetRepository(mainHandler,
mock(SessionManager.class), twitterCore);
tweetUi.setTweetRepository(tweetRepository);
tweetUi.setImageLoader(picasso);
}
示例10: addDelayedShutdownHook
import com.twitter.sdk.android.core.Twitter; //导入依赖的package包/类
static void addDelayedShutdownHook(final String serviceName,
final ExecutorService service, final long terminationTimeout, final TimeUnit timeUnit) {
Runtime.getRuntime().addShutdownHook(new Thread(() -> {
try {
service.shutdown();
if (!service.awaitTermination(terminationTimeout, timeUnit)) {
Twitter.getLogger().d(Twitter.TAG, serviceName + " did not shutdown in the"
+ " allocated time. Requesting immediate shutdown.");
service.shutdownNow();
}
} catch (InterruptedException e) {
Twitter.getLogger().d(Twitter.TAG, String.format(Locale.US,
"Interrupted while waiting for %s to shut down." +
" Requesting immediate shutdown.",
serviceName));
service.shutdownNow();
}
}, "Twitter Shutdown Hook for " + serviceName));
}
示例11: rollFileOver
import com.twitter.sdk.android.core.Twitter; //导入依赖的package包/类
/**
* Trigger a file roll over. Returns <code>true</code> if events existed and a roll-over file was created.
* Returns <code>false</code> if no events existed and a roll-over file was not created.
*/
public boolean rollFileOver() throws IOException {
boolean fileRolledOver = false;
String targetFileName = null;
// if the current active file is empty, don't roll it over, however
// still trigger listeners as they may be interested in the fact that an event were fired
if (!eventStorage.isWorkingFileEmpty()){
targetFileName = generateUniqueRollOverFileName();
eventStorage.rollOver(targetFileName);
CommonUtils.logControlled(context,
Log.INFO, Twitter.TAG,
String.format(Locale.US,
"generated new file %s", targetFileName)
);
lastRollOverTime = currentTimeProvider.getCurrentTimeMillis();
fileRolledOver = true;
}
triggerRollOverOnListeners(targetFileName);
return fileRolledOver;
}
示例12: IdManager
import com.twitter.sdk.android.core.Twitter; //导入依赖的package包/类
IdManager(Context appContext, PreferenceStore preferenceStore,
AdvertisingInfoProvider advertisingInfoProvider) {
if (appContext == null) {
throw new IllegalArgumentException("appContext must not be null");
}
this.appIdentifier = appContext.getPackageName();
this.advertisingInfoProvider = advertisingInfoProvider;
this.preferenceStore = preferenceStore;
collectHardwareIds = CommonUtils.getBooleanResourceValue(appContext,
COLLECT_IDENTIFIERS_ENABLED, true);
if (!collectHardwareIds) {
Twitter.getLogger().d(Twitter.TAG, "Device ID collection disabled for "
+ appContext.getPackageName());
}
}
示例13: authorize
import com.twitter.sdk.android.core.Twitter; //导入依赖的package包/类
/**
* Requests authorization.
*
* @param activity The {@link android.app.Activity} context to use for the authorization flow.
* @param callback The callback interface to invoke when authorization completes.
* @throws java.lang.IllegalArgumentException if activity or callback is null.
*/
public void authorize(Activity activity, Callback<TwitterSession> callback) {
if (activity == null) {
throw new IllegalArgumentException("Activity must not be null.");
}
if (callback == null) {
throw new IllegalArgumentException("Callback must not be null.");
}
if (activity.isFinishing()) {
Twitter.getLogger()
.e(TwitterCore.TAG, "Cannot authorize, activity is finishing.", null);
} else {
handleAuthorize(activity, callback);
}
}
示例14: newRequestTempTokenCallback
import com.twitter.sdk.android.core.Twitter; //导入依赖的package包/类
/**
* Package private for testing.
*/
Callback<OAuthResponse> newRequestTempTokenCallback() {
return new Callback<OAuthResponse>() {
@Override
public void success(Result<OAuthResponse> result) {
requestToken = result.data.authToken;
final String authorizeUrl = oAuth1aService.getAuthorizeUrl(requestToken);
// Step 2. Redirect user to web view to complete authorization flow.
Twitter.getLogger().d(TwitterCore.TAG,
"Redirecting user to web view to complete authorization flow");
setUpWebView(webView,
new OAuthWebViewClient(oAuth1aService.buildCallbackUrl(authConfig),
OAuthController.this), authorizeUrl, new OAuthWebChromeClient());
}
@Override
public void failure(TwitterException error) {
Twitter.getLogger().e(TwitterCore.TAG,
"Failed to get request token", error);
// Create new exception that can be safely serialized since Retrofit errors may
// throw a NotSerializableException.
handleAuthError(AuthHandler.RESULT_CODE_ERROR,
new TwitterAuthException("Failed to get request token"));
}
};
}
示例15: handleWebViewSuccess
import com.twitter.sdk.android.core.Twitter; //导入依赖的package包/类
private void handleWebViewSuccess(Bundle bundle) {
Twitter.getLogger().d(TwitterCore.TAG, "OAuth web view completed successfully");
if (bundle != null) {
final String verifier = bundle.getString(OAuthConstants.PARAM_VERIFIER);
if (verifier != null) {
// Step 3. Convert the request token to an access token.
Twitter.getLogger().d(TwitterCore.TAG,
"Converting the request token to an access token.");
oAuth1aService.requestAccessToken(newRequestAccessTokenCallback(),
requestToken, verifier);
return;
}
}
// If we get here, we failed to complete authorization.
Twitter.getLogger().e(TwitterCore.TAG,
"Failed to get authorization, bundle incomplete " + bundle, null);
handleAuthError(AuthHandler.RESULT_CODE_ERROR,
new TwitterAuthException("Failed to get authorization, bundle incomplete"));
}