use of com.linroid.weather.data.WeatherService in project steps by linroid.
the class MainActivity method onAddCity.
@Override
public void onAddCity(String cityName) {
final ProgressDialog dialog = new ProgressDialog(this);
dialog.setMessage("添加中....");
dialog.show();
WeatherApp app = (WeatherApp) getApplication();
WeatherService service = app.getWeatherService();
service.getDataAsync(cityName, new Callback<Data>() {
@Override
public void success(Data data, Response response) {
Result result = data.getResults().get(0);
getContentResolver().insert(DataContract.Weather.CONTENT_URI, result.toContentValues());
// triggerSync();
Toast.makeText(MainActivity.this, R.string.add_city_success, Toast.LENGTH_SHORT).show();
dialog.dismiss();
}
@Override
public void failure(RetrofitError retrofitError) {
Toast.makeText(MainActivity.this, R.string.add_city_fail, Toast.LENGTH_SHORT).show();
}
});
}
use of com.linroid.weather.data.WeatherService in project steps by linroid.
the class WeatherApp method initWeatherService.
private void initWeatherService() {
RestAdapter restAdapter = new RestAdapter.Builder().setEndpoint(Config.ENDPOINT).setClient(new OkClient(new OkHttpClient())).setLogLevel(RestAdapter.LogLevel.BASIC).setErrorHandler(new ErrorHandler() {
@Override
public Throwable handleError(RetrofitError retrofitError) {
Timber.e(retrofitError, "访问 %s 出错", retrofitError.getUrl());
return retrofitError;
}
}).setRequestInterceptor(new RequestInterceptor() {
@Override
public void intercept(RequestFacade requestFacade) {
requestFacade.addQueryParam("ak", Config.BAIDU_AK);
requestFacade.addEncodedQueryParam("mcode", Config.M_CODE);
requestFacade.addQueryParam("output", "json");
}
}).build();
weatherService = restAdapter.create(WeatherService.class);
}
Aggregations