Permalink
Cannot retrieve contributors at this time
Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.
Sign up
Fetching contributors…
| /* | |
| * Copyright (C) 2015 Twitter, Inc. | |
| * | |
| * Licensed under the Apache License, Version 2.0 (the "License"); | |
| * you may not use this file except in compliance with the License. | |
| * You may obtain a copy of the License at | |
| * | |
| * http://www.apache.org/licenses/LICENSE-2.0 | |
| * | |
| * Unless required by applicable law or agreed to in writing, software | |
| * distributed under the License is distributed on an "AS IS" BASIS, | |
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
| * See the License for the specific language governing permissions and | |
| * limitations under the License. | |
| * | |
| */ | |
| package com.example.app; | |
| import android.app.Application; | |
| import android.os.StrictMode; | |
| import android.util.Log; | |
| import com.squareup.leakcanary.LeakCanary; | |
| import com.twitter.sdk.android.core.Twitter; | |
| import com.twitter.sdk.android.core.TwitterApiClient; | |
| import com.twitter.sdk.android.core.TwitterCore; | |
| import com.twitter.sdk.android.core.TwitterSession; | |
| import okhttp3.OkHttpClient; | |
| import okhttp3.logging.HttpLoggingInterceptor; | |
| public class SampleApplication extends Application { | |
| private static final String TAG = SampleApplication.class.getSimpleName(); | |
| @Override | |
| public void onCreate() { | |
| super.onCreate(); | |
| LeakCanary.install(this); | |
| Log.d(TAG, "Setting up StrictMode policy checking."); | |
| StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder() | |
| .detectAll() | |
| .penaltyLog() | |
| .build()); | |
| StrictMode.setVmPolicy(new StrictMode.VmPolicy.Builder() | |
| .detectAll() | |
| .penaltyLog() | |
| .build()); | |
| Twitter.initialize(this); | |
| final HttpLoggingInterceptor loggingInterceptor = new HttpLoggingInterceptor(); | |
| loggingInterceptor.setLevel(HttpLoggingInterceptor.Level.BASIC); | |
| final OkHttpClient customClient = new OkHttpClient.Builder() | |
| .addInterceptor(loggingInterceptor).build(); | |
| final TwitterSession activeSession = TwitterCore.getInstance() | |
| .getSessionManager().getActiveSession(); | |
| final TwitterApiClient customApiClient; | |
| if (activeSession != null) { | |
| customApiClient = new TwitterApiClient(activeSession, customClient); | |
| TwitterCore.getInstance().addApiClient(activeSession, customApiClient); | |
| } else { | |
| customApiClient = new TwitterApiClient(customClient); | |
| TwitterCore.getInstance().addGuestApiClient(customApiClient); | |
| } | |
| } | |
| } |