示例#1
0
  private void displayAmount() {

    double amount =
        ExpenseTable.getSumOfExpenses(
            dbCon, dateRange, typeSelector, categorySelector, descriptionSelector, dateSelector);
    setHeaderTextRight(Util.formatAmountForView(amount));
  }
示例#2
0
 public static int deleteById(SQLiteDatabase db, Refuel rf) {
   /*
   We can just delete the parent expense row.
   The ON DELETE CASCADE clause, will make sure the
   refuel row is also deleted.
    */
   return ExpenseTable.deleteById(db, rf.getExpense());
 }
示例#3
0
  public static long save(SQLiteDatabase db, Refuel rf) {
    ContentValues cv = new ContentValues();
    cv.put(ODOMETER, rf.getOdometer());
    cv.put(LITRE, rf.getLitre());
    cv.put(RATE, rf.getRate());
    cv.put(PUMP_NAME, rf.getPumpName());
    cv.put(FULL_TANK, rf.isFullTank());
    rf.getExpense().setDesc("Refuel at " + rf.getPumpName());
    rf.getExpense().setType("refuel");
    cv.put(EXP_ID, ExpenseTable.save(db, rf.getExpense()));

    return db.insert(TABLE_NAME, null, cv);
  }
示例#4
0
  @Override
  protected void onClickItemDelete(long id) {

    if (getListView().getCount() == 1) {
      // delete one item = delete all items = delete list
      onClickItemDeleteAll();
      return;
    }

    ExpenseTable.deleteExpense(dbCon, id);
    displayDateInterval();
    displayAmount();
    displayItems();

    super.onClickItemDelete(id);
  }
示例#5
0
  @Override
  protected void onClickItemDeleteAll() {

    ExpenseTable.deleteExpense(
        dbCon, dateRange, typeSelector, categorySelector, descriptionSelector, dateSelector);

    typeSelector = null;
    categorySelector = null;
    descriptionSelector = null;
    dateSelector = null;

    displayDateInterval();
    displayAmount();
    displayItems();

    super.onClickItemDeleteAll();
  }
示例#6
0
  @Override
  protected void displayItems() {

    // always re-query data; records might have been added or deleted
    if (cursor != null) {
      cursor.close();
      cursor = null;
    }

    cursor =
        ExpenseTable.getExpenseCursor(
            dbCon, dateRange, typeSelector, categorySelector, descriptionSelector, dateSelector);

    SimpleCursorAdapter adapter =
        new ExpenseCursorAdapter(
            this,
            R.layout.list_item_expense,
            cursor,
            new String[] { // column names
              ExpenseTable.Column.TYPE,
              ExpenseTable.Column.CATEGORY,
              ExpenseTable.Column.AMOUNT,
              ExpenseTable.Column.DATE,
              ExpenseTable.Column.DESCRIPTION,
            },
            new int[] { // corresponding text views
              R.id.standardListItem4_image,
              R.id.standardListItem4_textUpperLeft,
              R.id.standardListItem4_textUpperRight,
              R.id.standardListItem4_textLowerLeft,
              R.id.standardListItem4_textLowerRight
            },
            !(typeSelector == null
                && categorySelector == null
                && descriptionSelector == null
                && dateSelector == null) // filtered
            );

    setListAdapter(adapter);

    super.displayItems();
  }
示例#7
0
  public static int update(SQLiteDatabase db, Refuel rf) {
    try {
      rf.getExpense().setDesc("Refuel at " + rf.getPumpName());
      rf.getExpense().setType("refuel");
      ExpenseTable.update(db, rf.getExpense());

      ContentValues cv = new ContentValues();
      cv.put(ODOMETER, rf.getOdometer());
      cv.put(LITRE, rf.getLitre());
      cv.put(RATE, rf.getRate());
      cv.put(PUMP_NAME, rf.getPumpName());
      cv.put(FULL_TANK, rf.isFullTank());
      cv.put(EXP_ID, rf.getExpense().getId());

      return db.update(TABLE_NAME, cv, ID + "=" + rf.getId(), null);
    } catch (NullPointerException e) {
      e.printStackTrace();
      return 0;
    }
  }
示例#8
0
  @Override
  protected Dialog onCreateDialog(int id, final Bundle b) {

    // dialog might need to be re-created - e.g. when screen is turned
    // from portrait to landscape - then db and dbCon can be null and
    // need to be initialized

    if (db == null) {
      db = new Database(this);
    }

    if (dbCon == null) {
      dbCon = db.getReadableDatabase();
    }

    Dialog d = null;

    switch (id) {
      case DIALOG_ID_FILTER_SELECTION:
        final Expense expense = ExpenseTable.getExpense(dbCon, b.getLong(ITEM_ID));

        String categoryFilter = expense.category;
        String descriptionFilter = expense.description;
        String typeFilter = Util.formatTypeForView(getListView().getContext(), expense.type);
        String dateFilter = Util.formatDateForView(expense.date);

        ArrayList<String> filterDialogItems_list = new ArrayList<String>();
        ArrayList<Boolean> filterDialogCheckmarks_list = new ArrayList<Boolean>();

        final int[] position = new int[] {-1, -1, -1, -1};
        int pos = -1;

        if (typeFilter != null && typeFilter.length() != 0) {
          filterDialogItems_list.add(typeFilter);
          filterDialogCheckmarks_list.add(typeSelector != null);
          position[0] = ++pos;
        }
        if (dateFilter != null && dateFilter.length() != 0) {
          filterDialogItems_list.add(dateFilter);
          filterDialogCheckmarks_list.add(dateSelector != null);
          position[1] = ++pos;
        }
        if (categoryFilter != null && categoryFilter.length() != 0) {
          filterDialogItems_list.add(categoryFilter);
          filterDialogCheckmarks_list.add(categorySelector != null);
          position[2] = ++pos;
        }
        if (descriptionFilter != null && descriptionFilter.length() != 0) {
          filterDialogItems_list.add(descriptionFilter);
          filterDialogCheckmarks_list.add(descriptionSelector != null);
          position[3] = ++pos;
        }

        final String[] filterDialogItems = filterDialogItems_list.toArray(new String[] {});
        final boolean[] filterDialogCheckmarks = new boolean[filterDialogCheckmarks_list.size()];

        for (int i = 0; i < filterDialogCheckmarks_list.size(); i++) {
          filterDialogCheckmarks[i] = filterDialogCheckmarks_list.get(i).booleanValue();
        }

        d =
            new AlertDialog.Builder(this)
                .setTitle(R.string.expense_filterDialog_title)
                .setOnCancelListener(
                    new DialogInterface.OnCancelListener() {
                      public void onCancel(DialogInterface dialog) {
                        removeDialog(DIALOG_ID_FILTER_SELECTION);
                      }
                    })
                .setMultiChoiceItems(
                    filterDialogItems,
                    filterDialogCheckmarks,
                    new DialogInterface.OnMultiChoiceClickListener() {
                      public void onClick(
                          DialogInterface dialog, int whichButton, boolean isChecked) {
                        if (whichButton == position[2]) { // category
                          if (isChecked) {
                            categorySelector = expense.category;
                          } else {
                            categorySelector = null;
                          }
                        } else if (whichButton == position[0]) { // type
                          if (isChecked) {
                            typeSelector = expense.type;
                          } else {
                            typeSelector = null;
                          }
                        } else if (whichButton == position[3]) { // description
                          if (isChecked) {
                            descriptionSelector = expense.description;
                          } else {
                            descriptionSelector = null;
                          }
                        } else if (whichButton == position[1]) { // date
                          if (isChecked) {
                            dateSelector = expense.date;
                          } else {
                            dateSelector = null;
                          }
                        }
                      }
                    })
                .setPositiveButton(
                    R.string.button_ok,
                    new DialogInterface.OnClickListener() {
                      public void onClick(DialogInterface dialog, int whichButton) {
                        refresh();
                        removeDialog(DIALOG_ID_FILTER_SELECTION);
                      }
                    })
                .create();

        break;

      case DIALOG_ID_DATE_INTERVAL_SELECTION:
        final DateIntervals dateIntervals = DateIntervalTable.getDateIntervals(dbCon);
        d =
            new AlertDialog.Builder(this)
                .setTitle(R.string.dateInterval_filterDialog_title)
                .setOnCancelListener(
                    new DialogInterface.OnCancelListener() {
                      public void onCancel(DialogInterface dialog) {
                        removeDialog(DIALOG_ID_DATE_INTERVAL_SELECTION);
                      }
                    })
                .setItems(
                    dateIntervals.names,
                    new DialogInterface.OnClickListener() {
                      public void onClick(DialogInterface dialog, int whichPosition) {
                        dateRange.id = dateIntervals.ids[whichPosition];
                        // date range was set - so reset dateSelector (if set)
                        dateSelector = null;
                        refresh();
                        removeDialog(DIALOG_ID_DATE_INTERVAL_SELECTION);
                      }
                    })
                .setPositiveButton(
                    R.string.button_add,
                    new DialogInterface.OnClickListener() {
                      public void onClick(DialogInterface dialog, int whichButton) {
                        // prepare data for hand-over to update-activity
                        Intent intent = new Intent(ExpenseListUI.this, DateIntervalUI.class);
                        intent.putExtra(DateIntervalUI.PARAM_MODE, DateIntervalUI.MODE_ADD);
                        // start update-activity
                        startActivityForResult(intent, REQUEST_CODE_ADD_DATE_INTERVAL);
                        removeDialog(DIALOG_ID_DATE_INTERVAL_SELECTION);
                      }
                    })
                .create();
        break;

      case DIALOG_ID_SEND_MAIL:
        LayoutInflater factory = LayoutInflater.from(this);
        final View textEntryView = factory.inflate(R.layout.dialog_send_list, null);

        d =
            new AlertDialog.Builder(this)
                //					.setIcon(R.drawable.alert_dialog_icon)
                .setTitle(R.string.sendList_dialog_title)
                .setOnCancelListener(
                    new DialogInterface.OnCancelListener() {
                      public void onCancel(DialogInterface dialog) {
                        removeDialog(DIALOG_ID_SEND_MAIL);
                      }
                    })
                .setView(textEntryView)
                .setPositiveButton(
                    R.string.sendList_dialog_button_send,
                    new DialogInterface.OnClickListener() {
                      public void onClick(DialogInterface dialog, int whichButton) {

                        // get mail address from UI
                        EditText adr = (EditText) textEntryView.findViewById(R.id.username_edit);
                        RadioButton qifRadioButton =
                            (RadioButton) textEntryView.findViewById(R.id.mail_format_qif);
                        RadioButton htmlRadioButton =
                            (RadioButton) textEntryView.findViewById(R.id.mail_format_html);
                        RadioButton xmlRadioButton =
                            (RadioButton) textEntryView.findViewById(R.id.mail_format_xml);
                        RadioButton csvRadioButton =
                            (RadioButton) textEntryView.findViewById(R.id.mail_format_csv);

                        String mailAddress = adr.getEditableText().toString();

                        String mailFormat = null;
                        if (qifRadioButton.isChecked()) {
                          mailFormat = QIF;
                        } else if (htmlRadioButton.isChecked()) {
                          mailFormat = HTML;
                        } else if (xmlRadioButton.isChecked()) {
                          mailFormat = XML;
                        } else if (csvRadioButton.isChecked()) {
                          mailFormat = CSV;
                        }

                        // store address (private mode) for later re-use
                        SharedPreferences settings = getPreferences(MODE_PRIVATE);
                        SharedPreferences.Editor prefEditor = settings.edit();
                        prefEditor.putString(PREF_MAIL_ADDRESS, mailAddress);
                        prefEditor.putString(PREF_MAIL_FORMAT, mailFormat);
                        prefEditor.commit();

                        String mimeType = "";

                        if (qifRadioButton.isChecked()) {
                          convertedList = Util.convertListToQifFile(getListView());
                          mimeType = "text/plain; charset=ISO-8859-1";
                        } else if (htmlRadioButton.isChecked()) {
                          convertedList = Util.convertListToHtmlFile(getListView());
                          mimeType = "text/html; charset=UTF-8";
                        } else if (xmlRadioButton.isChecked()) {
                          convertedList = Util.convertListToXmlFile(getListView());
                          mimeType = "text/xml; charset=UTF-8";
                        } else if (csvRadioButton.isChecked()) {
                          convertedList = Util.convertListToCsvFile(getListView());
                          mimeType = "text/plain; charset=UTF-8";
                        } else {
                          // should not happen
                          convertedList = null;
                        }

                        if (convertedList != null) {

                          Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);
                          emailIntent.setType(mimeType);
                          emailIntent.putExtra(Intent.EXTRA_EMAIL, new String[] {mailAddress});
                          emailIntent.putExtra(
                              Intent.EXTRA_SUBJECT, getResources().getString(R.string.app_name));
                          emailIntent.putExtra(
                              Intent.EXTRA_TEXT,
                              getResources().getString(R.string.sendList_eMail_subject));
                          emailIntent.putExtra(
                              Intent.EXTRA_STREAM,
                              Uri.parse("file://" + convertedList.getAbsolutePath()));

                          startActivityForResult(
                              Intent.createChooser(
                                  emailIntent,
                                  getResources().getString(R.string.sendList_dialog_title)),
                              REQUEST_CODE_SEND_MAIL);
                        } else {
                          // present toast: file conversion failed
                        }

                        removeDialog(DIALOG_ID_SEND_MAIL);
                      }
                    })
                .setNegativeButton(
                    R.string.button_cancel,
                    new DialogInterface.OnClickListener() {
                      public void onClick(DialogInterface dialog, int whichButton) {
                        removeDialog(DIALOG_ID_SEND_MAIL);
                      }
                    })
                .create();

        EditText adr = (EditText) textEntryView.findViewById(R.id.username_edit);
        RadioButton qifRadioButton = (RadioButton) textEntryView.findViewById(R.id.mail_format_qif);
        RadioButton htmlRadioButton =
            (RadioButton) textEntryView.findViewById(R.id.mail_format_html);
        RadioButton csvRadioButton = (RadioButton) textEntryView.findViewById(R.id.mail_format_csv);
        RadioButton xmlRadioButton = (RadioButton) textEntryView.findViewById(R.id.mail_format_xml);

        SharedPreferences settings = getPreferences(MODE_PRIVATE);

        // check if mail address already had been entered before
        // if yes, re-use the known address
        String mailAddress = settings.getString(PREF_MAIL_ADDRESS, "");
        adr.setText(mailAddress);

        // check if mail format already had been entered before
        // if yes, re-use the known format
        String mailFormat = settings.getString(PREF_MAIL_FORMAT, HTML);
        if (HTML.equals(mailFormat)) {
          htmlRadioButton.setChecked(true);
        } else if (XML.equals(mailFormat)) {
          xmlRadioButton.setChecked(true);
        } else if (CSV.equals(mailFormat)) {
          csvRadioButton.setChecked(true);
        } else if (QIF.equals(mailFormat)) {
          qifRadioButton.setChecked(true);
        }

        break;

      default:
        d = super.onCreateDialog(id, b);
        break;
    }
    return d;
  }