Example usage for android.widget AdapterView INVALID_ROW_ID

List of usage examples for android.widget AdapterView INVALID_ROW_ID

Introduction

In this page you can find the example usage for android.widget AdapterView INVALID_ROW_ID.

Prototype

long INVALID_ROW_ID

To view the source code for android.widget AdapterView INVALID_ROW_ID.

Click Source Link

Document

Represents an empty or invalid row id

Usage

From source file:Main.java

public static <T> T selectedValue(T[] values, long index) {
    T result = null;//from   w ww. j  ava 2s.com
    if (index != AdapterView.INVALID_ROW_ID) {
        result = values[(int) index];
    }
    return result;
}

From source file:Main.java

public static Integer selectedValue(int[] values, long index) {
    Integer result = null;//w w  w.j  av  a  2s .  c  o  m
    if (index != AdapterView.INVALID_ROW_ID) {
        result = values[(int) index];
    }
    return result;
}

From source file:com.google.android.feeds.ContentDecorator.java

/** {@inheritDoc} */
public long getItemId(int position) {
    if (isItem(position)) {
        return mAdapter.getItemId(position);
    } else {//from w  w  w  .j a  v  a  2s  .  c om
        return AdapterView.INVALID_ROW_ID;
    }
}

From source file:org.totschnig.myexpenses.activity.ExpenseEdit.java

/**
 * sets the state of the UI on mTransaction
 *
 * @return false if any data is not valid, also informs user through toast
 *///from  w  ww .j ava2  s.c  om
protected boolean syncStateAndValidate(boolean forSave) {
    boolean validP = true;
    String title;

    Account account = getCurrentAccount();
    if (account == null)
        return false;

    BigDecimal amount = validateAmountInput(forSave);

    if (amount == null) {
        //Toast is shown in validateAmountInput
        validP = false;
    } else {
        if (mType == EXPENSE) {
            amount = amount.negate();
        }
        mTransaction.getAmount().setCurrency(account.currency);
        mTransaction.getAmount().setAmountMajor(amount);//TODO refactor to better respect encapsulation
    }
    mTransaction.accountId = account.getId();

    mTransaction.comment = mCommentText.getText().toString();

    if (!(mTransaction instanceof SplitPartCategory || mTransaction instanceof SplitPartTransfer)) {
        mTransaction.setDate(mCalendar.getTime());
    }

    if (mOperationType == MyExpenses.TYPE_TRANSACTION) {
        mTransaction.setCatId(mCatId);
    }
    if (mIsMainTransactionOrTemplate) {
        mTransaction.setPayee(mPayeeText.getText().toString());
        long selected = mMethodSpinner.getSelectedItemId();
        mTransaction.methodId = (selected != AdapterView.INVALID_ROW_ID && selected > 0) ? selected : null;
    }
    if (mOperationType == MyExpenses.TYPE_TRANSFER) {
        mTransaction.transfer_account = mTransferAccountSpinner.getSelectedItemId();
        final Account transferAccount = Account.getInstanceFromDb(mTransferAccountSpinner.getSelectedItemId());
        boolean isSame = account.currency.equals(transferAccount.currency);
        if (mTransaction instanceof Template) {
            if (!isSame && amount == null) {
                BigDecimal transferAmount = validateAmountInput(mTransferAmountText, forSave);
                if (transferAmount != null) {
                    mTransaction.accountId = transferAccount.getId();
                    mTransaction.transfer_account = account.getId();
                    if (mType == INCOME) {
                        transferAmount = transferAmount.negate();
                    }
                    mTransaction.setAmount(new Money(transferAccount.currency, transferAmount));
                    mAmountText.setError(null);
                    validP = true; //we only need either amount or transfer amount
                }
            }
        } else {
            mTransaction.getTransferAmount().setCurrency(transferAccount.currency);
            if (isSame) {
                if (amount != null)
                    mTransaction.getTransferAmount().setAmountMajor(amount.negate());
            } else {
                BigDecimal transferAmount = validateAmountInput(mTransferAmountText, forSave);

                if (transferAmount == null) {
                    //Toast is shown in validateAmountInput
                    validP = false;
                } else {
                    if (mType == INCOME) {
                        transferAmount = transferAmount.negate();
                    }
                    mTransaction.getTransferAmount().setAmountMajor(transferAmount);
                }
            }
        }
    }
    if (mTransaction instanceof Template) {
        title = mTitleText.getText().toString();
        if (title.equals("")) {
            mTitleText.setError(getString(R.string.no_title_given));
            validP = false;
        }
        ((Template) mTransaction).setTitle(title);
        if (mPlan == null) {
            if (mReccurenceSpinner.getSelectedItemPosition() > 0) {
                String description = ((Template) mTransaction).compileDescription(ExpenseEdit.this);
                mPlan = new Plan(mCalendar,
                        ((Plan.Recurrence) mReccurenceSpinner.getSelectedItem()).toRrule(mCalendar),
                        ((Template) mTransaction).getTitle(), description);
                ((Template) mTransaction).setPlan(mPlan);
            }
        } else {
            mPlan.description = ((Template) mTransaction).compileDescription(ExpenseEdit.this);
            mPlan.title = title;
            ((Template) mTransaction).setPlan(mPlan);
        }
    } else {
        mTransaction.referenceNumber = mReferenceNumberText.getText().toString();
        if (forSave
                && !(mTransaction instanceof SplitPartCategory || mTransaction instanceof SplitPartTransfer)) {
            if (mReccurenceSpinner.getSelectedItemPosition() > 0) {
                title = TextUtils.isEmpty(mTransaction.payee) ? (TextUtils.isEmpty(mLabel)
                        ? (TextUtils.isEmpty(mTransaction.comment) ? getString(R.string.menu_create_template)
                                : mTransaction.comment)
                        : mLabel) : mTransaction.payee;
                mTransaction.originTemplate = new Template(mTransaction, title);
                mTransaction.originTemplate.setPlanExecutionAutomatic(true);
                String description = mTransaction.originTemplate.compileDescription(ExpenseEdit.this);
                mTransaction.originTemplate.setPlan(new Plan(mCalendar,
                        ((Plan.Recurrence) mReccurenceSpinner.getSelectedItem()).toRrule(mCalendar),
                        mTransaction.originTemplate.getTitle(), description));
            }
        }
    }

    mTransaction.crStatus = (Transaction.CrStatus) mStatusSpinner.getSelectedItem();

    mTransaction.setPictureUri(mPictureUri);
    return validP;
}

From source file:org.totschnig.myexpenses.activity.ExpenseEdit.java

@Override
protected void onSaveInstanceState(Bundle outState) {
    super.onSaveInstanceState(outState);
    outState.putSerializable(KEY_CALENDAR, mCalendar);
    //restored in onCreate
    if (mRowId != 0) {
        outState.putLong(KEY_ROWID, mRowId);
    }//from   w  w w.ja va2  s .c  o m
    if (mCatId != null) {
        outState.putLong(KEY_CATID, mCatId);
    }
    outState.putString(KEY_LABEL, mLabel);
    if (mPictureUri != null) {
        outState.putParcelable(KEY_PICTURE_URI, mPictureUri);
    }
    if (mPictureUriTemp != null) {
        outState.putParcelable(KEY_PICTURE_URI_TMP, mPictureUriTemp);
    }
    long methodId = mMethodSpinner.getSelectedItemId();
    if (methodId == android.widget.AdapterView.INVALID_ROW_ID && mMethodId != null) {
        methodId = mMethodId;
    }
    if (methodId != android.widget.AdapterView.INVALID_ROW_ID) {
        outState.putLong(KEY_METHODID, methodId);
    }
    long accountId = mAccountSpinner.getSelectedItemId();
    if (accountId == android.widget.AdapterView.INVALID_ROW_ID && mAccountId != null) {
        accountId = mAccountId;
    }
    if (accountId != android.widget.AdapterView.INVALID_ROW_ID) {
        outState.putLong(KEY_ACCOUNTID, accountId);
    }
    if (mOperationType == MyExpenses.TYPE_TRANSFER) {
        outState.putLong(KEY_TRANSFER_ACCOUNT, mTransferAccountSpinner.getSelectedItemId());
    }
}