initHomeHttp
package com.example.smartcity.http;
import android.content.Context;
import android.os.Handler;
import android.os.Message;
import android.util.Log;
import com.example.smartcity.info.GetPersonInfo;
import com.example.smartcity.info.HomeRotationMain;
import com.example.smartcity.info.HomeServices;
import com.example.smartcity.info.NewsInfo;
import com.example.smartcity.info.NewsType;
import com.example.smartcity.utils.CacheUtils;
import com.example.smartcity.utils.ConstantsUtils;
import com.google.gson.Gson;
import java.io.IOException;
import okhttp3.Call;
import okhttp3.Callback;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.Response;
import static com.example.smartcity.utils.CacheUtils.homeRotationMain;
import static com.example.smartcity.utils.CacheUtils.homeServices;
import static com.example.smartcity.utils.CacheUtils.newsInfo;
import static com.example.smartcity.utils.CacheUtils.newsType;
import static com.example.smartcity.utils.ConstantsUtils.GET_INFO;
import static com.example.smartcity.utils.ConstantsUtils.GET_INFO_WHAT;
import static com.example.smartcity.utils.ConstantsUtils.HOME_ROTATION;
import static com.example.smartcity.utils.ConstantsUtils.HOME_ROTATION_WHAT;
import static com.example.smartcity.utils.ConstantsUtils.HOT_NEWS;
import static com.example.smartcity.utils.ConstantsUtils.HOT_NEWS_WHAT;
import static com.example.smartcity.utils.ConstantsUtils.IP;
import static com.example.smartcity.utils.ConstantsUtils.NEWS_TYPE;
import static com.example.smartcity.utils.ConstantsUtils.NEWS_TYPE_WHAT;
import static com.example.smartcity.utils.ConstantsUtils.SERVICE_ICON;
import static com.example.smartcity.utils.ConstantsUtils.SERVICE_ICON_WHAT;
import static com.example.smartcity.utils.KeyUtils.TOKEN;
import static com.example.smartcity.utils.KeyUtils.USER_INFO;
public class initHomeHttp {
OkHttpClient client = new OkHttpClient();
private Handler mHandler;
public initHomeHttp(Handler mHandler) {
this.mHandler = mHandler;
}
public void getInfoData(Context context,String token) {
Request request = new Request.Builder()
.url(IP + GET_INFO)
.get()
.addHeader("authorization", token)
.addHeader("cache-control", "no-cache")
.addHeader("postman-token", "961dba7a-47cf-7cae-1507-e1820380ded8")
.build();
new OkHttpClient().newCall(request).enqueue(new Callback() {
@Override
public void onFailure(Call call, IOException e) {
}
@Override
public void onResponse(Call call, Response response) throws IOException {
String getInfoDataStr = response.body().string();
GetPersonInfo getPersonInfo = new Gson().fromJson(getInfoDataStr, GetPersonInfo.class);
if (getPersonInfo.getCode()==200){
CacheUtils.putString(context, USER_INFO,getInfoDataStr);
Message message = new Message();
message.what = GET_INFO_WHAT;
message.obj = getPersonInfo;
mHandler.sendMessage(message);
}
else {
CacheUtils.clearString(context,TOKEN);
}
}
});
}
public void newsTypeData(){
Request request = new Request.Builder()
.url(IP + NEWS_TYPE)
.get()
.addHeader("cache-control", "no-cache")
.addHeader("postman-token", "86ad35f7-784c-003d-2a4d-cf2cd25175ad")
.build();
client.newCall(request).enqueue(new Callback() {
@Override
public void onFailure(Call call, IOException e) {
Log.e("TAG", "我没获取到新闻分类 " );
}
@Override
public void onResponse(Call call, Response response) throws IOException {
String newsTypeDataStr = response.body().string();
newsType = new Gson().fromJson(newsTypeDataStr, NewsType.class);
Message message = new Message();
message.what = NEWS_TYPE_WHAT;
message.obj = newsType;
mHandler.sendMessage(message);
}
});
}
public void newsData(){
Request request = new Request.Builder()
.url(IP + HOT_NEWS)
.get()
.addHeader("cache-control", "no-cache")
.addHeader("postman-token", "d06b5e3f-9310-b5e9-80bf-f1418bb1386a")
.build();
client.newCall(request).enqueue(new Callback() {
@Override
public void onFailure(Call call, IOException e) {
}
@Override
public void onResponse(Call call, Response response) throws IOException {
String newsDataStr = response.body().string();
newsInfo = new Gson().fromJson(newsDataStr, NewsInfo.class);
Message message = new Message();
message.what = HOT_NEWS_WHAT;
mHandler.sendMessage(message);
}
});
}
public void servicesData(){
Request request = new Request.Builder()
.url(IP + SERVICE_ICON)
.get()
.addHeader("cache-control", "no-cache")
.addHeader("postman-token", "e56ceb6d-74ec-899b-3090-80599b2c7d8e")
.build();
client.newCall(request).enqueue(new Callback() {
@Override
public void onFailure(Call call, IOException e) {
}
@Override
public void onResponse(Call call, Response response) throws IOException {
String servicesDataStr = response.body().string();
homeServices = new Gson().fromJson(servicesDataStr, HomeServices.class);
Message message = new Message();
message.what = SERVICE_ICON_WHAT;
mHandler.sendMessage(message);
}
});
}
public void homeRotationData() {
Request request = new Request.Builder()
.url(IP + HOME_ROTATION)
.get()
.addHeader("cache-control", "no-cache")
.addHeader("postman-token", "38559bc1-23e9-a79a-d876-b32406ef46bd")
.build();
client.newCall(request).enqueue(new Callback() {
@Override
public void onFailure(Call call, IOException e) {
}
@Override
public void onResponse(Call call, Response response) throws IOException {
String homeRotationDataStr = response.body().string();
Log.e("TAG", "首页 "+homeRotationDataStr );
homeRotationMain = new Gson().fromJson(homeRotationDataStr, HomeRotationMain.class);
Message message = new Message();
message.what = HOME_ROTATION_WHAT;
message.obj = homeRotationMain;
mHandler.sendMessage(message);
}
});
}
}
initLiveHttp(生活)
package com.example.smartcity.http;
import android.os.Handler;
import android.os.Message;
import com.example.smartcity.info.life.LiveIcon;
import com.example.smartcity.info.life.LiveNews;
import com.example.smartcity.info.life.LiveNewsType;
import com.example.smartcity.info.life.LiveRotation;
import com.example.smartcity.info.life.LiveWeather;
import com.example.smartcity.utils.CacheUtils;
import com.example.smartcity.utils.ConstantsUtils;
import com.google.gson.Gson;
import java.io.IOException;
import okhttp3.Call;
import okhttp3.Callback;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.Response;
import static com.example.smartcity.utils.CacheUtils.liveIcon;
import static com.example.smartcity.utils.CacheUtils.liveNews;
import static com.example.smartcity.utils.CacheUtils.liveNewsType;
import static com.example.smartcity.utils.CacheUtils.liveRotation;
import static com.example.smartcity.utils.CacheUtils.liveWeather;
import static com.example.smartcity.utils.ConstantsUtils.IP;
import static com.example.smartcity.utils.ConstantsUtils.LIVE_IMG;
import static com.example.smartcity.utils.ConstantsUtils.LIVE_IMG_WHAT;
import static com.example.smartcity.utils.ConstantsUtils.LIVE_NEWS;
import static com.example.smartcity.utils.ConstantsUtils.LIVE_NEWS_TYPE;
import static com.example.smartcity.utils.ConstantsUtils.LIVE_NEWS_TYPE_WHAT;
import static com.example.smartcity.utils.ConstantsUtils.LIVE_NEWS_WHAT;
import static com.example.smartcity.utils.ConstantsUtils.LIVE_PAY_ICON;
import static com.example.smartcity.utils.ConstantsUtils.LIVE_PAY_ICON_WHAT;
import static com.example.smartcity.utils.ConstantsUtils.LIVE_WEATHER;
import static com.example.smartcity.utils.ConstantsUtils.LIVE_WEATHER_WHAT;
public class initLiveHttp {
OkHttpClient client = new OkHttpClient();
private Handler mHandler;
public initLiveHttp(Handler mHandler) {
this.mHandler = mHandler;
}
public void liveNewsData(){
Request request = new Request.Builder()
.url(IP + LIVE_NEWS)
.get()
.addHeader("cache-control", "no-cache")
.addHeader("postman-token", "0604464f-5907-4f44-a93f-8ed2218aaf4b")
.build();
client.newCall(request).enqueue(new Callback() {
@Override
public void onFailure(Call call, IOException e) {
}
@Override
public void onResponse(Call call, Response response) throws IOException {
String liveNewsDataStr = response.body().string();
liveNews = new Gson().fromJson(liveNewsDataStr, LiveNews.class);
Message message = new Message();
message.what = LIVE_NEWS_WHAT;
message.obj = liveNews;
mHandler.sendMessage(message);
}
});
}
public void liveNewsTypeData(){
Request request = new Request.Builder()
.url(IP + LIVE_NEWS_TYPE)
.get()
.addHeader("cache-control", "no-cache")
.addHeader("postman-token", "c4fde2f3-7297-b94e-d17a-5ac8d91c198e")
.build();
client.newCall(request).enqueue(new Callback() {
@Override
public void onFailure(Call call, IOException e) {
}
@Override
public void onResponse(Call call, Response response) throws IOException {
String liveNewsTypeDataStr = response.body().string();
liveNewsType = new Gson().fromJson(liveNewsTypeDataStr, LiveNewsType.class);
Message message = new Message();
message.what = LIVE_NEWS_TYPE_WHAT;
message.obj = liveNewsType;
mHandler.sendMessage(message);
}
});
}
public void liveWeatherData(){
Request request = new Request.Builder()
.url(IP + LIVE_WEATHER)
.get()
.addHeader("cache-control", "no-cache")
.addHeader("postman-token", "568143e3-23d0-cf30-346a-31f5607ee5f2")
.build();
client.newCall(request).enqueue(new Callback() {
@Override
public void onFailure(Call call, IOException e) {
}
@Override
public void onResponse(Call call, Response response) throws IOException {
String liveIconDataStr = response.body().string();
liveWeather = new Gson().fromJson(liveIconDataStr, LiveWeather.class);
Message message = new Message();
message.what = LIVE_WEATHER_WHAT;
message.obj = liveWeather;
mHandler.sendMessage(message);
}
});
}
public void liveIconData(){
Request request = new Request.Builder()
.url(IP + LIVE_PAY_ICON)
.get()
.addHeader("cache-control", "no-cache")
.addHeader("postman-token", "a6367e9c-4ccd-aad8-3cf4-2dfdf732a419")
.build();
client.newCall(request).enqueue(new Callback() {
@Override
public void onFailure(Call call, IOException e) {
}
@Override
public void onResponse(Call call, Response response) throws IOException {
String liveIconDataStr = response.body().string();
liveIcon = new Gson().fromJson(liveIconDataStr, LiveIcon.class);
Message message = new Message();
message.what = LIVE_PAY_ICON_WHAT;
message.obj = liveIcon;
mHandler.sendMessage(message);
}
});
}
public void liveRotationData(){
Request request = new Request.Builder()
.url(IP + LIVE_IMG)
.get()
.addHeader("cache-control", "no-cache")
.addHeader("postman-token", "a2724702-81e6-479d-9eae-52cc43c39b91")
.build();
client.newCall(request).enqueue(new Callback() {
@Override
public void onFailure(Call call, IOException e) {
}
@Override
public void onResponse(Call call, Response response) throws IOException {
String liveRotationDataStr = response.body().string();
liveRotation = new Gson().fromJson(liveRotationDataStr, LiveRotation.class);
Message message = new Message();
message.what = LIVE_IMG_WHAT;
message.obj = liveRotation;
mHandler.sendMessage(message);
}
});
}
}
initMovieHttp(电影)
package com.example.smartcity.http;
import android.os.Handler;
import android.os.Message;
import android.util.Log;
import com.example.smartcity.info.movie.CinemaInfo;
import com.example.smartcity.info.movie.FilmNumInfo;
import com.example.smartcity.info.movie.HomeRotation;
import com.example.smartcity.info.movie.HotFilmInfo;
import com.example.smartcity.info.movie.RecommendInfo;
import com.example.smartcity.info.movie.StarNews;
import com.example.smartcity.info.movie.StarNewsComment;
import com.example.smartcity.info.movie.Weather;
import com.google.gson.Gson;
import java.io.IOException;
import okhttp3.Call;
import okhttp3.Callback;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.Response;
import static com.example.smartcity.utils.CacheUtils.cinemaInfo;
import static com.example.smartcity.utils.CacheUtils.filmNumInfo;
import static com.example.smartcity.utils.CacheUtils.homeRotation;
import static com.example.smartcity.utils.CacheUtils.hotFilmInfo;
import static com.example.smartcity.utils.CacheUtils.recommendInfo;
import static com.example.smartcity.utils.CacheUtils.starNews;
import static com.example.smartcity.utils.CacheUtils.starNewsComment;
import static com.example.smartcity.utils.CacheUtils.weather;
import static com.example.smartcity.utils.ConstantsUtils.CINEMA;
import static com.example.smartcity.utils.ConstantsUtils.CINEMA_WHAT;
import static com.example.smartcity.utils.ConstantsUtils.FILM_NUM;
import static com.example.smartcity.utils.ConstantsUtils.FILM_NUM_WHAT;
import static com.example.smartcity.utils.ConstantsUtils.HOME_IMG;
import static com.example.smartcity.utils.ConstantsUtils.HOME_IMG_WHAT;
import static com.example.smartcity.utils.ConstantsUtils.HOT_FILM;
import static com.example.smartcity.utils.ConstantsUtils.HOT_FILM_WHAT;
import static com.example.smartcity.utils.ConstantsUtils.IP;
import static com.example.smartcity.utils.ConstantsUtils.RECOMMEND;
import static com.example.smartcity.utils.ConstantsUtils.RECOMMEND_WHAT;
import static com.example.smartcity.utils.ConstantsUtils.STAR_NEWS;
import static com.example.smartcity.utils.ConstantsUtils.STAR_NEWS_COMMENT;
import static com.example.smartcity.utils.ConstantsUtils.STAR_NEWS_COMMENT_WHAT;
import static com.example.smartcity.utils.ConstantsUtils.STAR_NEWS_WHAT;
import static com.example.smartcity.utils.ConstantsUtils.WEATHER;
import static com.example.smartcity.utils.ConstantsUtils.WEATHER_WHAT;
public class initMovieHttp {
OkHttpClient client = new OkHttpClient();
private Handler mHandler;
public initMovieHttp(Handler mHandler) {
this.mHandler = mHandler;
}
public void starNewsCommentData(){
Request request = new Request.Builder()
.url(IP + STAR_NEWS_COMMENT)
.get()
.addHeader("cache-control", "no-cache")
.addHeader("postman-token", "82664d2a-d688-f201-92e1-c7cb23b1afe1")
.build();
client.newCall(request).enqueue(new Callback() {
@Override
public void onFailure(Call call, IOException e) {
}
@Override
public void onResponse(Call call, Response response) throws IOException {
String starNewsCommentDataStr = response.body().string();
starNewsComment = new Gson().fromJson(starNewsCommentDataStr, StarNewsComment.class);
Message message = new Message();
message.what = STAR_NEWS_COMMENT_WHAT;
mHandler.sendMessage(message);
}
});
}
public void starNewsData(){
Request request = new Request.Builder()
.url(IP + STAR_NEWS)
.get()
.addHeader("cache-control", "no-cache")
.addHeader("postman-token", "28fe5cff-b0b2-557e-16ce-57fdacea99b6")
.build();
client.newCall(request).enqueue(new Callback() {
@Override
public void onFailure(Call call, IOException e) {
}
@Override
public void onResponse(Call call, Response response) throws IOException {
String starNewsDataStr = response.body().string();
starNews = new Gson().fromJson(starNewsDataStr, StarNews.class);
Message message = new Message();
message.what = STAR_NEWS_WHAT;
mHandler.sendMessage(message);
}
});
}
public void filmNumData(int filmID,String filmDate){
Request request = new Request.Builder()
.url(IP + FILM_NUM + "?movieId=" +filmID+"&playDate="+filmDate)
.get()
.addHeader("cache-control", "no-cache")
.addHeader("postman-token", "62cd9f9c-3682-0f2c-151f-42e2faf8da81")
.build();
client.newCall(request).enqueue(new Callback() {
@Override
public void onFailure(Call call, IOException e) {
}
@Override
public void onResponse(Call call, Response response) throws IOException {
String filmNumData = response.body().string();
filmNumInfo = new Gson().fromJson(filmNumData, FilmNumInfo.class);
Message message = new Message();
message.what = FILM_NUM_WHAT;
mHandler.sendMessage(message);
}
});
}
public void cinemaData(){
Request request = new Request.Builder()
.url(IP + CINEMA)
.build();
client.newCall(request).enqueue(new Callback() {
@Override
public void onFailure(Call call, IOException e) {
}
@Override
public void onResponse(Call call, Response response) throws IOException {
String cinemaDataStr = response.body().string();
cinemaInfo = new Gson().fromJson(cinemaDataStr, CinemaInfo.class);
Message message = new Message();
message.what = CINEMA_WHAT;
mHandler.sendMessage(message);
}
});
}
public void recommendFilmData(){
Request request = new Request.Builder()
.url(IP + RECOMMEND)
.build();
client.newCall(request).enqueue(new Callback() {
@Override
public void onFailure(Call call, IOException e) {
}
@Override
public void onResponse(Call call, Response response) throws IOException {
String recommendFilmDataStr = response.body().string();
recommendInfo = new Gson().fromJson(recommendFilmDataStr, RecommendInfo.class);
Message message = new Message();
message.what = RECOMMEND_WHAT;
mHandler.sendMessage(message);
}
});
}
public void hotFilmData() {
Request request = new Request.Builder()
.url(IP + HOT_FILM)
.build();
client.newCall(request).enqueue(new Callback() {
@Override
public void onFailure(Call call, IOException e) {
}
@Override
public void onResponse(Call call, Response response) throws IOException {
String hotFilmDataStr = response.body().string();
hotFilmInfo = new Gson().fromJson(hotFilmDataStr, HotFilmInfo.class);
Message message = new Message();
message.what = HOT_FILM_WHAT;
mHandler.sendMessage(message);
}
});
}
public void weatherData() {
Request request = new Request.Builder()
.url(IP + WEATHER)
.build();
client.newCall(request).enqueue(new Callback() {
@Override
public void onFailure(Call call, IOException e) {
}
@Override
public void onResponse(Call call, Response response) throws IOException {
String weatherDataStr = response.body().string();
weather = new Gson().fromJson(weatherDataStr, Weather.class);
Message message = new Message();
message.what = WEATHER_WHAT;
message.obj = weather;
mHandler.sendMessage(message);
}
});
}
public void rotationData() {
Request request = new Request.Builder()
.url(IP + HOME_IMG)
.build();
client.newCall(request).enqueue(new Callback() {
@Override
public void onFailure(Call call, IOException e) {
Log.e("TAG", "我没获取到首页数据");
}
@Override
public void onResponse(Call call, Response response) throws IOException {
String rotationDataStr = response.body().string();
homeRotation = new Gson().fromJson(rotationDataStr, HomeRotation.class);
Message message = new Message();
message.what = HOME_IMG_WHAT;
message.obj = homeRotation;
mHandler.sendMessage(message);
}
});
}
}
initSubwayHttp(地铁)
package com.example.smartcity.http;
import android.os.Handler;
import android.os.Message;
import com.example.smartcity.info.subway.Statement;
import com.example.smartcity.info.subway.LinesImg;
import com.example.smartcity.info.subway.LocCity;
import com.example.smartcity.info.subway.LocProvince;
import com.example.smartcity.info.subway.LostFound;
import com.example.smartcity.info.subway.Operation;
import com.example.smartcity.info.subway.SubwayLines;
import com.example.smartcity.info.subway.SubwayRotation;
import com.google.gson.Gson;
import java.io.IOException;
import okhttp3.Call;
import okhttp3.Callback;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.Response;
import static com.example.smartcity.utils.CacheUtils.statement;
import static com.example.smartcity.utils.CacheUtils.linesImg;
import static com.example.smartcity.utils.CacheUtils.locCity;
import static com.example.smartcity.utils.CacheUtils.locProvince;
import static com.example.smartcity.utils.CacheUtils.lostFound;
import static com.example.smartcity.utils.CacheUtils.statement;
import static com.example.smartcity.utils.CacheUtils.operation;
import static com.example.smartcity.utils.CacheUtils.subwayLines;
import static com.example.smartcity.utils.CacheUtils.subwayRotation;
import static com.example.smartcity.utils.ConstantsUtils.CITY;
import static com.example.smartcity.utils.ConstantsUtils.CITY_WHAT;
import static com.example.smartcity.utils.ConstantsUtils.CLAUSE;
import static com.example.smartcity.utils.ConstantsUtils.CLAUSE_WHAT;
import static com.example.smartcity.utils.ConstantsUtils.EXEMPTION;
import static com.example.smartcity.utils.ConstantsUtils.EXEMPTION_WHAT;
import static com.example.smartcity.utils.ConstantsUtils.IP;
import static com.example.smartcity.utils.ConstantsUtils.LINES;
import static com.example.smartcity.utils.ConstantsUtils.LINES_IMG;
import static com.example.smartcity.utils.ConstantsUtils.LINES_IMG_WHAT;
import static com.example.smartcity.utils.ConstantsUtils.LINES_WHAT;
import static com.example.smartcity.utils.ConstantsUtils.LOST_FOUND;
import static com.example.smartcity.utils.ConstantsUtils.LOST_FOUND_WHAT;
import static com.example.smartcity.utils.ConstantsUtils.NOTICE;
import static com.example.smartcity.utils.ConstantsUtils.NOTICE_WHAT;
import static com.example.smartcity.utils.ConstantsUtils.OPERATION;
import static com.example.smartcity.utils.ConstantsUtils.OPERATION_WHAT;
import static com.example.smartcity.utils.ConstantsUtils.PROVINCE;
import static com.example.smartcity.utils.ConstantsUtils.PROVINCE_WHAT;
import static com.example.smartcity.utils.ConstantsUtils.SUBWAY_IMG;
import static com.example.smartcity.utils.ConstantsUtils.SUBWAY_IMG_WHAT;
public class initSubwayHttp {
OkHttpClient client = new OkHttpClient();
private Handler mHandler;
public initSubwayHttp(Handler mHandler) {
this.mHandler = mHandler;
}
public void exemptionData(){
Request request = new Request.Builder()
.url(IP + EXEMPTION)
.get()
.addHeader("cache-control", "no-cache")
.addHeader("postman-token", "612dd34b-5316-67d8-5c0c-0b706a82c271")
.build();
client.newCall(request).enqueue(new Callback() {
@Override
public void onFailure(Call call, IOException e) {
}
@Override
public void onResponse(Call call, Response response) throws IOException {
String loadExemptionDataStr = response.body().string();
statement = new Gson().fromJson(loadExemptionDataStr, Statement.class);
Message message = new Message();
message.what = EXEMPTION_WHAT;
message.obj = statement;
mHandler.sendMessage(message);
}
});
}
public void lostFoundData() {
Request request = new Request.Builder()
.url(IP + LOST_FOUND)
.get()
.addHeader("cache-control", "no-cache")
.addHeader("postman-token", "169088e6-653c-1b4b-b5a8-92f13234e732")
.build();
client.newCall(request).enqueue(new Callback() {
@Override
public void onFailure(Call call, IOException e) {
}
@Override
public void onResponse(Call call, Response response) throws IOException {
String lostFoundDataStr = response.body().string();
lostFound = new Gson().fromJson(lostFoundDataStr, LostFound.class);
Message message = new Message();
message.what = LOST_FOUND_WHAT;
message.obj = lostFound;
mHandler.sendMessage(message);
}
});
}
public void clauseData() {
Request request = new Request.Builder()
.url(IP + CLAUSE)
.get()
.addHeader("cache-control", "no-cache")
.addHeader("postman-token", "397f934f-5d45-13f9-ecfb-cc1b9f6d9c7f")
.build();
client.newCall(request).enqueue(new Callback() {
@Override
public void onFailure(Call call, IOException e) {
}
@Override
public void onResponse(Call call, Response response) throws IOException {
String clauseDataStr = response.body().string();
statement = new Gson().fromJson(clauseDataStr, Statement.class);
Message message = new Message();
message.what = CLAUSE_WHAT;
message.obj = statement;
mHandler.sendMessage(message);
}
});
}
public void operationData() {
Request request = new Request.Builder()
.url(IP + OPERATION)
.get()
.addHeader("cache-control", "no-cache")
.addHeader("postman-token", "5ae0f164-5e5b-fbb5-438d-d1639c707a50")
.build();
client.newCall(request).enqueue(new Callback() {
@Override
public void onFailure(Call call, IOException e) {
}
@Override
public void onResponse(Call call, Response response) throws IOException {
String operationDataStr = response.body().string();
operation = new Gson().fromJson(operationDataStr, Operation.class);
Message message = new Message();
message.what = OPERATION_WHAT;
message.obj = operation;
mHandler.sendMessage(message);
}
});
}
public void noticeData() {
Request request = new Request.Builder()
.url(IP + NOTICE)
.get()
.addHeader("cache-control", "no-cache")
.addHeader("postman-token", "e558a786-96a0-6410-1ecb-711a197652ec")
.build();
client.newCall(request).enqueue(new Callback() {
@Override
public void onFailure(Call call, IOException e) {
}
@Override
public void onResponse(Call call, Response response) throws IOException {
String noticeDataStr = response.body().string();
statement = new Gson().fromJson(noticeDataStr, Statement.class);
Message message = new Message();
message.what = NOTICE_WHAT;
message.obj = statement;
mHandler.sendMessage(message);
}
});
}
public void linesImgData() {
Request request = new Request.Builder()
.url(IP + LINES_IMG)
.get()
.addHeader("cache-control", "no-cache")
.addHeader("postman-token", "34282518-53df-233d-a54a-da21bbf82af4")
.build();
new OkHttpClient().newCall(request).enqueue(new Callback() {
@Override
public void onFailure(Call call, IOException e) {
}
@Override
public void onResponse(Call call, Response response) throws IOException {
String linesImgData = response.body().string();
linesImg = new Gson().fromJson(linesImgData, LinesImg.class);
Message message = new Message();
message.what = LINES_IMG_WHAT;
message.obj = linesImg;
mHandler.sendMessage(message);
}
});
}
public void linesData() {
Request request = new Request.Builder()
.url(IP + LINES)
.get()
.addHeader("cache-control", "no-cache")
.addHeader("postman-token", "4382fe1c-b61c-c735-0ec7-d315acd5e521")
.build();
client.newCall(request).enqueue(new Callback() {
@Override
public void onFailure(Call call, IOException e) {
}
@Override
public void onResponse(Call call, Response response) throws IOException {
String linesDataStr = response.body().string();
subwayLines = new Gson().fromJson(linesDataStr, SubwayLines.class);
Message message = new Message();
message.what = LINES_WHAT;
message.obj = subwayLines;
mHandler.sendMessage(message);
}
});
}
public void cityData() {
Request request = new Request.Builder()
.url(IP + CITY)
.get()
.addHeader("cache-control", "no-cache")
.addHeader("postman-token", "b8d7f045-b9dd-12dc-2d8b-e6d9cb06e558")
.build();
client.newCall(request).enqueue(new Callback() {
@Override
public void onFailure(Call call, IOException e) {
}
@Override
public void onResponse(Call call, Response response) throws IOException {
String cityDataStr = response.body().string();
locCity = new Gson().fromJson(cityDataStr, LocCity.class);
Message message = new Message();
message.what = CITY_WHAT;
message.obj = locCity;
mHandler.sendMessage(message);
}
});
}
public void provinceData() {
Request request = new Request.Builder()
.url(IP + PROVINCE)
.get()
.addHeader("cache-control", "no-cache")
.addHeader("postman-token", "f585e93d-4b88-7f88-be4e-0cdd5910cded")
.build();
client.newCall(request).enqueue(new Callback() {
@Override
public void onFailure(Call call, IOException e) {
}
@Override
public void onResponse(Call call, Response response) throws IOException {
String provinceDataStr = response.body().string();
locProvince = new Gson().fromJson(provinceDataStr, LocProvince.class);
Message message = new Message();
message.what = PROVINCE_WHAT;
mHandler.sendMessage(message);
}
});
}
public void subwayRotationData() {
Request request = new Request.Builder()
.url(IP + SUBWAY_IMG)
.get()
.addHeader("cache-control", "no-cache")
.addHeader("postman-token", "be229379-61df-c84b-46b7-52c54ed785a1")
.build();
client.newCall(request).enqueue(new Callback() {
@Override
public void onFailure(Call call, IOException e) {
}
@Override
public void onResponse(Call call, Response response) throws IOException {
String subwayRotationDataStr = response.body().string();
subwayRotation = new Gson().fromJson(subwayRotationDataStr, SubwayRotation.class);
Message message = new Message();
message.what = SUBWAY_IMG_WHAT;
mHandler.sendMessage(message);
}
});
}
}