manifest
<uses-permission android:name="android.permission.INTERNET"/>
build.gradle (Module:app)
compile "com.squareup.retrofit2:retrofit:2.0.0" compile "com.squareup.retrofit2:converter-gson:2.0.0"
Make RestService class.
public interface RestService { String ENDPOINT = "Url path"; @GET("경로") Call<Map<Object, Object>> 메소드명(@Path("lat") String lat, @Path("lon") String lon); @POST("경로") Call<Map<Object, Object>> login(@Body Map<Object, Object> body); class Creator{ public static RestService newRestService(){ Gson gson = new GsonBuilder() .setDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'") .create(); Retrofit retrofit = new Retrofit.Builder() .baseUrl(RestService.ENDPOINT_) .addConverterFactory(GsonConverterFactory.create(gson)) .client(SSLConnect.getInstance().createSSLClient()) // ssl(https) 사용시 주석해제할것 .build(); return retrofit.create(RestService.class); } } }
RestService를 사용해서 http 통신
RestService restService = new RestService.Creator().newRestService(); final Call<Map<Object,Object>> call = restService.getUserInfo(~~~); call.enqueue(new Callback<Map<Object, Object>>() { @Override public void onResponse(Call<Map<Object, Object>> call, Response<Map<Object, Object>> response) { if (!response.isSuccessful()) { Toast.makeText(activity, "Sorry, failed..", Toast.LENGTH_SHORT).show(); return; } Map<Object, Object> body = response.body(); Map<Object, Object> one = (Map<Object, Object>) body.get("body"); Map<Object, Object> data = (Map<Object, Object>) one.get("data"); String name = (String)data.get("name"); String email = (String)data.get("email"); String profileUrl = (String)data.get("profileUrl"); } @Override public void onFailure(Call<Map<Object, Object>> call, Throwable t) { Toast.makeText(activity, "Network Error : " + t.getMessage(), } });
manifest
<uses-permission android:name="android.permission.INTERNET"/>
build.gradle(Module:app)
compile 'com.github.bumptech.glide:glide:3.6.0' compile 'jp.wasabeef:glide-transformations:1.0.6@aar' // 이미지 변형 ( 원형 )
이미지뷰과 url로 이미지 삽입
Glide.with(context) .load({id}) .bitmapTransform(new CropCircleTransformation(bitmapPool)) .override(130,130) .into({view});주의 : bitmapPool은 새로 생성해야 한다. (default로 생성 가능)