Search in sources :

Example 1 with WeatherService

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();
        }
    });
}
Also used : Response(retrofit.client.Response) WeatherService(com.linroid.weather.data.WeatherService) Data(com.linroid.weather.model.Data) ProgressDialog(android.app.ProgressDialog) Result(com.linroid.weather.model.Result) RetrofitError(retrofit.RetrofitError)

Example 2 with WeatherService

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);
}
Also used : ErrorHandler(retrofit.ErrorHandler) OkHttpClient(com.squareup.okhttp.OkHttpClient) OkClient(retrofit.client.OkClient) WeatherService(com.linroid.weather.data.WeatherService) RequestInterceptor(retrofit.RequestInterceptor) RestAdapter(retrofit.RestAdapter) RetrofitError(retrofit.RetrofitError)

Aggregations

WeatherService (com.linroid.weather.data.WeatherService)2 RetrofitError (retrofit.RetrofitError)2 ProgressDialog (android.app.ProgressDialog)1 Data (com.linroid.weather.model.Data)1 Result (com.linroid.weather.model.Result)1 OkHttpClient (com.squareup.okhttp.OkHttpClient)1 ErrorHandler (retrofit.ErrorHandler)1 RequestInterceptor (retrofit.RequestInterceptor)1 RestAdapter (retrofit.RestAdapter)1 OkClient (retrofit.client.OkClient)1 Response (retrofit.client.Response)1