@Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.login_screen);

    Crittercism.initialize(getApplicationContext(), "53fbdb9283fb796ab8000001"); // line 22

    initializeViews();
    bindListenersToVies();
  }
  @Override
  protected List<PlayersPitchersViewModel.Pitcher> doInBackground(Void... params) {

    List<PlayersPitchersViewModel.Pitcher> list = null;

    try {
      // http://clutchwin.com/api/v1/opponents/pitchers.json?
      final String baseUrl = Config.OpponentsForBatter;
      StringBuilder finalUrl;
      finalUrl = new StringBuilder(baseUrl);
      finalUrl
          .append(Config.AccessTokenKey)
          .append(Config.AccessTokenValue)
          .append(Config.BatterIdKey)
          .append(ClutchWinApplication.getPlayersContextViewModel().getBatterId())
          .append(Config.SeasonIdKey)
          .append(ClutchWinApplication.getPlayersContextViewModel().getYearId())
          .append(Config.FieldSetBasicKeyValue);

      RestTemplate restTemplate = new RestTemplate();
      restTemplate.getMessageConverters().add(new MappingJackson2HttpMessageConverter());
      list =
          Arrays.asList(
              restTemplate.getForObject(
                  finalUrl.toString(), PlayersPitchersViewModel.Pitcher[].class));

      /*
      try {
          if(list != null && list.size() > 0) {
              Helpers.writeListToInternalStorage(list, Config.PP_CacheFileKey);
          } else {
              Helpers.deleteCacheFile(Config.PP_CacheFileKey);
          }
      } catch (IOException e) {
          Log.e("PlayersPitchersAsyncTask::writeListToInternalStorage", e.getMessage(), e);
      }
      */

    } catch (Exception e) {
      Log.e("PlayersPitchersCache", e.getMessage(), e);
      if (onCompleteListener != null) {
        onCompleteListener.onPlayersPitcherServiceFailure(e);
      }

      Crittercism.logHandledException(e);
    }
    return list;
  }
Пример #3
0
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    if (Log.STRICT_MODE) {
      StrictMode.enableDefaults();
    }

    if (Log.CRITTERCISM) {
      Crittercism.initialize(getApplicationContext(), "522a584297c8f23137000001");
    }

    sharedPreferences = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());

    try {
      int versionCode = getPackageManager().getPackageInfo(getPackageName(), 0).versionCode;
      int lastVersionCode = sharedPreferences.getInt(Keys.PREF_LAST_UPDATED_VERSION, 0);

      if (versionCode >= lastVersionCode && lastVersionCode > 0) {
        SQLiteDatabase db = new DBHelper(getApplicationContext()).getReadableDatabase();

        if (db != null) {
          db.close();
          sharedPreferences.edit().putInt(Keys.PREF_LAST_UPDATED_VERSION, versionCode).apply();
        }
      }
    } catch (PackageManager.NameNotFoundException e) {
      Log.e(e, e.getMessage());
    }

    pagerAdapter = new PagerAdapter(getSupportFragmentManager());
    pagerAdapter.addFragment(mainFragment = new MainFragment());

    viewPager = (ViewPager) findViewById(R.id.viewPager);
    viewPager.setAdapter(pagerAdapter);

    viewPager.setOnPageChangeListener(
        new ViewPager.OnPageChangeListener() {
          @Override
          public void onPageScrolled(int i, float v, int i2) {}

          @Override
          public void onPageSelected(int i) {
            if (i == 0) {
              drawerLayout.setDrawerLockMode(DrawerLayout.LOCK_MODE_UNLOCKED);
            } else {
              drawerLayout.setDrawerLockMode(DrawerLayout.LOCK_MODE_LOCKED_CLOSED);
            }
          }

          @Override
          public void onPageScrollStateChanged(int i) {}
        });

    ActionBar actionBar = getActionBar();
    actionBar.setIcon(null);
    actionBar.setDisplayOptions(
        ActionBar.DISPLAY_SHOW_TITLE | ActionBar.DISPLAY_SHOW_HOME | ActionBar.DISPLAY_HOME_AS_UP);

    drawerLayout = (DrawerLayout) findViewById(R.id.drawerLayout);
    drawerAbToggle =
        new ActionBarDrawerToggle(
            this, drawerLayout, R.drawable.ic_drawer, R.string.drawer_open, R.string.drawer_close) {
          float prevOffset;

          @Override
          public void onDrawerSlide(View drawerView, float slideOffset) {
            super.onDrawerSlide(drawerView, slideOffset);

            isSliderOpen = prevOffset <= slideOffset;
            prevOffset = slideOffset;

            invalidateOptionsMenu();
          }
        };
    drawerLayout.setDrawerListener(drawerAbToggle);

    accountsList = (ListView) findViewById(R.id.drawerList);
    accountsAdapter = new AccountsAdapter(getApplicationContext(), accounts);
    accountsList.setAdapter(accountsAdapter);

    accountsList.setOnItemLongClickListener(
        new AdapterView.OnItemLongClickListener() {
          @Override
          public boolean onItemLongClick(
              AdapterView<?> parent, View view, final int position, long id) {
            if (position == 0) {
              return false;
            }

            Account account = accountsAdapter.getItem(position);
            AlertDialog.Builder builder =
                new AlertDialog.Builder(
                    new ContextThemeWrapper(MainActivity.this, R.style.DroidHub_AlertDialog));

            builder.setTitle("Delete account");
            builder.setMessage("Do you really want to remove " + account.type.accName + "?");

            builder.setPositiveButton(
                "Yes",
                new DialogInterface.OnClickListener() {
                  @Override
                  public void onClick(DialogInterface dialog, int which) {
                    removeAccount(position);
                  }
                });

            builder.setNegativeButton(
                "No",
                new DialogInterface.OnClickListener() {
                  @Override
                  public void onClick(DialogInterface dialog, int which) {}
                });

            builder.show();
            return true;
          }
        });

    accountsList.setOnItemClickListener(
        new AdapterView.OnItemClickListener() {
          @Override
          public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            mainFragment.adapter.reloadType(accountsAdapter.getItem(position).type);
            drawerLayout.closeDrawer(accountsList);
          }
        });

    new BackgroundTasks().execute();
  }