Example #1
0
 @SuppressWarnings("unchecked")
 @Override
 public boolean onMenuItemSelected(int featureId, MenuItem item) {
   super.onMenuItemSelected(featureId, item);
   ParserType type = ParserType.values()[item.getItemId()];
   ArrayAdapter<String> adapter = (ArrayAdapter<String>) this.getListAdapter();
   if (adapter.getCount() > 0) {
     adapter.clear();
   }
   this.loadFeed(type);
   return true;
 }
Example #2
0
  @Override
  public boolean onMenuItemSelected(int featureId, MenuItem item) {
    AdapterView.AdapterContextMenuInfo info;
    info = (AdapterView.AdapterContextMenuInfo) item.getMenuInfo();

    super.onMenuItemSelected(featureId, item);
    switch (item.getItemId()) {
      case ACTIVITY_INSERT:
        createFeed();
        break;
      case FEATURE_LIST:
        Intent i = new Intent(this, FeatureList.class);
        startActivity(i);
        break;
      case ACTIVITY_DELETE:
        setListAdapter(null);

        Feed f = feeds.get(info.position);
        Utils.droidDB.deleteFeed(f.feedId);
        fillData();
        Toast.makeText(FeedsList.this, "Feed : " + f.title + "  deleted!", Toast.LENGTH_LONG)
            .show();
        break;
      case ACTIVITY_SYNC_ALL:
        if (Utils.CheckInternetConnection(this)) {
          progressDialog = ProgressDialog.show(FeedsList.this, "Sync In progress", "Syncing all!");
          new Thread() {
            public void run() {
              try {
                for (Feed f : feeds) {
                  // Utils.droidDB.deleteAricles(f.feedId);
                  RSSHandler rh = new RSSHandler();
                  rh.updateArticles(FeedsList.this, f);
                }

              } catch (Exception e) {

              }
              progressDialog.dismiss();
            }
          }.start();
        } else {
          Toast.makeText(this, "No internet connection!", Toast.LENGTH_SHORT).show();
        }
        break;
      case ACTIVITY_SYNC:
        if (Utils.CheckInternetConnection(this)) {
          info = (AdapterView.AdapterContextMenuInfo) item.getMenuInfo();
          final Feed fs = feeds.get(info.position);
          progressDialog =
              ProgressDialog.show(FeedsList.this, "Sync In progress", "Syncing : " + fs.title);
          new Thread() {
            public void run() {
              try {

                // Utils.droidDB.deleteAricles(fs.feedId);
                RSSHandler rh = new RSSHandler();
                rh.updateArticles(FeedsList.this, fs);
                Toast.makeText(
                        FeedsList.this, "Feed : " + fs.title + "  deleted!", Toast.LENGTH_LONG)
                    .show();

              } catch (Exception e) {

              }
              progressDialog.dismiss();
            }
          }.start();
        } else {
          Toast.makeText(this, "No internet connection!", Toast.LENGTH_SHORT).show();
        }
        break;
      case ACTIVITY_STOP_SERVICE:
        if (mBound) {
          unbindService(mConnection);
          mBound = false;
        }

        break;
      case ACTIVITY_ABOUT:
        Toast.makeText(this, this.getString(R.string.about_text), Toast.LENGTH_LONG).show();

        break;
    }
    return true;
  }