@Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_home);
    ((ReadingChallengeApplication) getApplication()).inject(this);

    gridView = (GridView) findViewById(R.id.gridview);

    ((ReadingChallengeApplication) this.getApplication())
        .setDisplay(readSharedPreferences(getString(R.string.display)));

    // listen refresh event
    layout = (PullRefreshLayout) findViewById(R.id.swipeRefreshLayout);
    layout.setOnRefreshListener(
        new PullRefreshLayout.OnRefreshListener() {
          @Override
          public void onRefresh() {
            getCategories();
          }
        });
    getCategories();

    // admobs
    AdView mAdView = (AdView) findViewById(R.id.adView);
    AdRequest adRequest = new AdRequest.Builder().build();
    mAdView.loadAd(adRequest);

    // analytics
    ReadingChallengeApplication application = (ReadingChallengeApplication) getApplication();
    Tracker mTracker = application.getDefaultTracker();
    mTracker.setScreenName("HomeActivity");
    mTracker.send(new HitBuilders.ScreenViewBuilder().build());
  }
  public void getCategories() {
    layout.setRefreshing(true);
    level = String.valueOf(((ReadingChallengeApplication) this.getApplication()).getLevel());
    // get categories from api
    apiService.listCategoriesByLevel(
        level,
        new Callback<List<Category>>() {
          @Override
          public void success(List<Category> categories, Response response) {
            displayCategories(categories);
            layout.setRefreshing(false);
          }

          @Override
          public void failure(RetrofitError error) {
            displayAlertDialog(getString(R.string.error), getString(R.string.activity_home_error));
            layout.setRefreshing(false);
            Timber.e("Error get categories : " + error.getMessage());
          }
        });
  }
 public Context getContext() {
   return mRefreshLayout != null ? mRefreshLayout.getContext() : null;
 }