Пример #1
0
  @Override
  public boolean onContextItemSelected(MenuItem item) {
    // TODO Auto-generated method stub
    AdapterView.AdapterContextMenuInfo info =
        (AdapterView.AdapterContextMenuInfo) item.getMenuInfo();
    selectedSofor =
        soforDao
            .queryBuilder()
            .where(Properties.SoforID.eq(adapter.getItemId(info.position - 1)))
            .list()
            .get(0);
    selectedSofor.setSoforIsActive(false);
    soforDao.update(selectedSofor);
    adapter.remove(selectedSofor);
    adapter.notifyDataSetChanged();

    if (NetworkUtil.checkInternetIsActive(context) == true) {
      new AsyncTask<Void, Void, Boolean>() {

        @Override
        protected Boolean doInBackground(Void... params) {
          // TODO Auto-generated method stub
          JSONBuilder builder = new JSONBuilder();
          JSONSender sender = new JSONSender();
          JSONObject obj = builder.updateSofor(selectedSofor);
          sender.sendJSON(sender.getFlottaUrl(), obj);
          return true;
        }
      }.execute();
    }

    return super.onContextItemSelected(item);
  }
Пример #2
0
  @Override
  public boolean onOptionsItemSelected(MenuItem item) {
    // TODO Auto-generated method stub
    switch (item.getItemId()) {
      case R.id.menu_sendCSV:
        if (NetworkUtil.checkInternetIsActive(context) == true) {
          CSVUtil util = new CSVUtil();
          ArrayList<Sofor> sofors = new ArrayList<Sofor>(soforDao.loadAll());
          Uri u = util.createSoforCSVFile(sofors);

          Intent sendIntent = new Intent(Intent.ACTION_SEND);
          sendIntent.putExtra(Intent.EXTRA_SUBJECT, R.string.drivers);
          sendIntent.putExtra(Intent.EXTRA_STREAM, u);
          sendIntent.setType("text/html");
          startActivity(sendIntent);
        }

        break;
      case R.id.menu_Sort:
        AlertDialog.Builder builder = new AlertDialog.Builder(context);
        builder.setTitle(R.string.sort);
        // final CharSequence[] choiceList = {"Név", "Cím", "Telefonszám" };
        String[] choiceList = {
          getString(R.string.name), getString(R.string.cim), getString(R.string.telefon)
        };
        int selected = -1; // does not select anything

        builder.setSingleChoiceItems(
            choiceList,
            selected,
            new OnClickListener() {

              @Override
              public void onClick(DialogInterface dialog, int which) {
                // TODO Auto-generated method stub

                switch (which) {
                  case 0:
                    try {
                      Collator huCollator = new RuleBasedCollator(hungarianRules);
                      sortSoforNev(huCollator, soforok);
                      adapter.clear();
                      adapter.addAll(soforok);
                      adapter.notifyDataSetChanged();
                    } catch (ParseException e) {
                      // TODO Auto-generated catch block
                      e.printStackTrace();
                    }
                    break;
                  case 1:
                    try {
                      Collator huCollator = new RuleBasedCollator(hungarianRules);
                      sortSoforCim(huCollator, soforok);
                      adapter.clear();
                      adapter.addAll(soforok);
                      adapter.notifyDataSetChanged();
                    } catch (ParseException e) {
                      // TODO Auto-generated catch block
                      e.printStackTrace();
                    }
                    break;
                  case 2:
                    try {
                      Collator huCollator = new RuleBasedCollator(hungarianRules);
                      sortSoforTelefonSzam(huCollator, soforok);
                      adapter.clear();
                      adapter.addAll(soforok);
                      adapter.notifyDataSetChanged();
                    } catch (ParseException e) {
                      // TODO Auto-generated catch block
                      e.printStackTrace();
                    }
                    break;
                }

                dialog.dismiss();
              }
            });

        AlertDialog alert = builder.create();
        alert.show();
        break;
      case R.id.menu_refresh:
        if (NetworkUtil.checkInternetIsActive(context) == true) {
          new AsyncTask<Void, Void, Boolean>() {
            @Override
            protected void onPreExecute() {
              startRefreshAnimation();
            };

            @Override
            protected void onPostExecute(Boolean result) {
              // TODO Auto-generated method stub
              if (result == true) {
                Toast.makeText(context, R.string.refreshed, Toast.LENGTH_SHORT).show();

              } else {
                Toast.makeText(context, R.string.errorRefresh, Toast.LENGTH_SHORT).show();
              }

              try {
                // Play notification sound when refresn finished
                Uri notification = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
                Ringtone r = RingtoneManager.getRingtone(context, notification);
                r.play();
              } catch (Exception e) {
                e.printStackTrace();
              }

              adapter.clear();

              soforok =
                  new ArrayList<Sofor>(
                      soforDao.queryBuilder().where(Properties.SoforIsActive.eq(true)).list());
              adapter.addAll(soforok);
              adapter.notifyDataSetChanged();

              if (refreshItem != null && refreshItem.getActionView() != null) {
                refreshItem.getActionView().clearAnimation();
                refreshItem.setActionView(null);
              }

              stopRefreshAnimation();
            }

            @Override
            protected Boolean doInBackground(Void... params) {
              // TODO Auto-generated method stub
              return saveSoforTable();
            }
          }.execute();

        } else {
          Toast.makeText(context, R.string.no_internet, Toast.LENGTH_SHORT).show();
        }

        break;
    }

    return true;
  }