Advertisement
Guest User

Untitled

a guest
Jan 23rd, 2017
127
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.88 KB | None | 0 0
  1. package com.mindfire.quickapiintegration;
  2.  
  3. import android.os.Bundle;
  4. import android.support.v7.app.AppCompatActivity;
  5. import android.util.Log;
  6.  
  7. import com.magnet.android.mms.MagnetMobileClient;
  8. import com.magnet.android.mms.async.Call;
  9. import com.magnet.android.mms.exception.SchemaException;
  10. import com.mindfire.quickapiintegration.controller.api.WeatherData;
  11. import com.mindfire.quickapiintegration.controller.api.WeatherDataFactory;
  12. import com.mindfire.quickapiintegration.model.beans.WeatherResult;
  13.  
  14. import java.util.concurrent.ExecutionException;
  15.  
  16. public class MainActivity extends AppCompatActivity {
  17.  
  18. private static final String TAG = MainActivity.class.getName();
  19. private WeatherData mWeatherData;
  20.  
  21. @Override
  22. protected void onCreate(Bundle savedInstanceState) {
  23. super.onCreate(savedInstanceState);
  24. setContentView(R.layout.activity_main);
  25. initWeatherAPI();
  26. WeatherResult weather = null;
  27. try {
  28. weather = fetchWeather();
  29. } catch (ExecutionException | InterruptedException e) {
  30. e.printStackTrace();
  31. }
  32. Log.d(TAG, "onCreate: " + weather.getSys().getMessage() + " " + weather.getMain().getTemp_max());
  33. }
  34.  
  35. private WeatherResult fetchWeather() throws ExecutionException, InterruptedException {
  36. Call<WeatherResult> weatherCall = mWeatherData.getWeather("201301", "ec2d7002083aec3884e9ad313c30df8d", null);
  37. return weatherCall.get();
  38. }
  39.  
  40. /**
  41. * Instantiate a controller
  42. *
  43. * @return Weather Result object
  44. */
  45. private void initWeatherAPI() {
  46.  
  47. MagnetMobileClient magnetClient = MagnetMobileClient.getInstance(this);
  48. WeatherDataFactory controllerFactory = new WeatherDataFactory(magnetClient);
  49. try {
  50. mWeatherData = controllerFactory.obtainInstance();
  51. } catch (SchemaException e) {
  52. e.printStackTrace();
  53. }
  54. }
  55.  
  56. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement