Skip to content

Instantly share code, notes, and snippets.

View leeyc09's full-sized avatar

Youngchan leeyc09

  • jiransoft
  • S.korea
View GitHub Profile
Call<JsonObject> jsonObjectCall = sample_RestfulAdapter.getInstance().Project();
jsonObjectCall.enqueue(new Callback<JsonObject>() {
@Override
public void onResponse(Response<JsonObject> response) {
//통신성공 시
JsonObject jsonObject = response.body();
//Json 파싱 후 사용
}
import java.io.IOException;
import java.util.HashSet;
import okhttp3.Interceptor;
import okhttp3.Request;
import okhttp3.Response;
public class AddCookiesInterceptor implements Interceptor {
@Override
import java.io.IOException;
import java.util.HashSet;
import okhttp3.Interceptor;
import okhttp3.Request;
import okhttp3.Response;
public class ReceivedCookiesInterceptor implements Interceptor {
@Override
public Response intercept(Chain chain) {
import java.io.IOException;
import java.util.HashSet;
import okhttp3.Interceptor;
import okhttp3.Request;
import okhttp3.Response;
public class ReceivedCookiesInterceptor implements Interceptor {
@Override
public Response intercept(Chain chain) {
public class RestfulAdapter {
public static final int CONNECT_TIMEOUT = 15;
public static final int WRITE_TIMEOUT = 15;
public static final int READ_TIMEOUT = 15;
private static final String SERVER_URL = "https://api.server.net/"; //2부터 url뒤에 /를 입력해야 합니다.
private static OkHttpClient client;
private static sample_Interface Interface;
public synchronized static sample_Interface getInstance() {
if (Interface == null) {
public class AuthModel implements Parcelable {
public static final String TAG = LoginActivity.class.getSimpleName();
public static final String PARCELABLE_KEY = TAG + ":" + "ParcelableKey";
String email; //json의 name 과 동일해야 함.
String nick_name;
String profile_modified;
String profile_thumb;
long storage_limit;
long storage_used;
public interface sample_Interface {
//URL encoding하여 보냅니다.
//POST 방식, 파라메터는 @Field("파라메터명") 으로 보낼 수 있습니다.
//Json형식에 맞게 Bean객체를 만들어 두면 설정항 Parser가 자동으로 컨버팅해 돌려 줍니다.
@FormUrlEncoded
@POST("auth")
Call<AuthModel> Auth(@Field("email") String email, @Field("password") String password);
// Get방식, 파라메터는 @Query("파라메터명")으로 보낼 수 있습니다.
@leeyc09
leeyc09 / OkHttp3ImagePipelineConfigFactory.java
Created January 15, 2016 09:35
fresco OkHttpImagePipelineConfigFactory use Okhttp3
package Your.package
import com.facebook.imagepipeline.core.ImagePipelineConfig;
import android.content.Context;
import okhttp3.OkHttpClient;
/**
* Created by user on 2016-01-15.
*/
@leeyc09
leeyc09 / OkHttp3NetworkFetcher.java
Created January 15, 2016 09:34
Fresco Network fetcher that uses OkHttp3 as a backend.
package your.package
import android.net.Uri;
import android.os.Looper;
import android.os.SystemClock;
import com.facebook.common.logging.FLog;
import com.facebook.imagepipeline.image.EncodedImage;
import com.facebook.imagepipeline.producers.BaseNetworkFetcher;
import com.facebook.imagepipeline.producers.BaseProducerContextCallbacks;
import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.Canvas;
import android.graphics.Rect;
import android.graphics.drawable.Drawable;
import android.graphics.drawable.NinePatchDrawable;
import android.util.AttributeSet;
import android.widget.RelativeLayout;
public class FRelativeLayout extends RelativeLayout {