Example usage for android.widget AdapterView INVALID_POSITION

List of usage examples for android.widget AdapterView INVALID_POSITION

Introduction

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

Prototype

int INVALID_POSITION

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

Click Source Link

Document

Represents an invalid position.

Usage

From source file:com.grottworkshop.gwsswipelayout.SwipeLayout.java

private void performAdapterViewItemClick(MotionEvent e) {
    ViewParent t = getParent();/*  www  .jav  a  2  s  .  c  o  m*/
    while (t != null) {
        if (t instanceof AdapterView) {
            AdapterView view = (AdapterView) t;
            int p = view.getPositionForView(SwipeLayout.this);
            if (p != AdapterView.INVALID_POSITION
                    && view.performItemClick(view.getChildAt(p), p, view.getAdapter().getItemId(p)))
                return;
        } else {
            if (t instanceof View && ((View) t).performClick())
                return;
        }
        t = t.getParent();
    }
}

From source file:biz.bokhorst.xprivacy.ActivityMain.java

@SuppressLint("InflateParams")
private void optionTemplate() {
    final int userId = Util.getUserId(Process.myUid());

    // Build view
    LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    View view = inflater.inflate(R.layout.template, null);
    final Spinner spTemplate = (Spinner) view.findViewById(R.id.spTemplate);
    Button btnRename = (Button) view.findViewById(R.id.btnRename);
    ExpandableListView elvTemplate = (ExpandableListView) view.findViewById(R.id.elvTemplate);

    // Template selector
    final SpinnerAdapter spAdapter = new SpinnerAdapter(this, android.R.layout.simple_spinner_item);
    spAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    String defaultName = PrivacyManager.getSetting(userId, Meta.cTypeTemplateName, "0",
            getString(R.string.title_default));
    spAdapter.add(defaultName);//from   w  ww  .j a va  2 s  .c o m
    for (int i = 1; i <= 4; i++) {
        String alternateName = PrivacyManager.getSetting(userId, Meta.cTypeTemplateName, Integer.toString(i),
                getString(R.string.title_alternate) + " " + i);
        spAdapter.add(alternateName);
    }
    spTemplate.setAdapter(spAdapter);

    // Template definition
    final TemplateListAdapter templateAdapter = new TemplateListAdapter(this, view, R.layout.templateentry);
    elvTemplate.setAdapter(templateAdapter);
    elvTemplate.setGroupIndicator(null);

    spTemplate.setOnItemSelectedListener(new OnItemSelectedListener() {
        @Override
        public void onItemSelected(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
            templateAdapter.notifyDataSetChanged();
        }

        @Override
        public void onNothingSelected(AdapterView<?> arg0) {
            templateAdapter.notifyDataSetChanged();
        }
    });

    btnRename.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            if (Util.hasProLicense(ActivityMain.this) == null) {
                // Redirect to pro page
                Util.viewUri(ActivityMain.this, cProUri);
                return;
            }

            final int templateId = spTemplate.getSelectedItemPosition();
            if (templateId == AdapterView.INVALID_POSITION)
                return;

            AlertDialog.Builder dlgRename = new AlertDialog.Builder(spTemplate.getContext());
            dlgRename.setTitle(R.string.title_rename);

            final String original = (templateId == 0 ? getString(R.string.title_default)
                    : getString(R.string.title_alternate) + " " + templateId);
            dlgRename.setMessage(original);

            final EditText input = new EditText(spTemplate.getContext());
            dlgRename.setView(input);

            dlgRename.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int whichButton) {
                    String name = input.getText().toString();
                    if (TextUtils.isEmpty(name)) {
                        PrivacyManager.setSetting(userId, Meta.cTypeTemplateName, Integer.toString(templateId),
                                null);
                        name = original;
                    } else {
                        PrivacyManager.setSetting(userId, Meta.cTypeTemplateName, Integer.toString(templateId),
                                name);
                    }
                    spAdapter.remove(spAdapter.getItem(templateId));
                    spAdapter.insert(name, templateId);
                    spAdapter.notifyDataSetChanged();
                }
            });

            dlgRename.setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int whichButton) {
                    // Do nothing
                }
            });

            dlgRename.create().show();
        }
    });

    // Build dialog
    AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(this);
    alertDialogBuilder.setTitle(R.string.menu_template);
    alertDialogBuilder.setIcon(getThemed(R.attr.icon_launcher));
    alertDialogBuilder.setView(view);
    alertDialogBuilder.setPositiveButton(getString(R.string.msg_done), new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            // Do nothing
        }
    });

    // Show dialog
    AlertDialog alertDialog = alertDialogBuilder.create();
    alertDialog.show();
}

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

public Account getCurrentAccount() {
    if (mAccounts == null) {
        return null;
    }//from   w w w  . j a v a 2s .c o m
    int selected = mAccountSpinner.getSelectedItemPosition();
    if (selected == android.widget.AdapterView.INVALID_POSITION || selected >= mAccounts.length) {
        return null;
    }
    return mAccounts[selected];
}

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

@Override
public void onLoadFinished(Loader<Cursor> loader, Cursor data) {
    if (data == null) {
        return;//from w w  w  . jav a  2 s. c  o m
    }
    int id = loader.getId();
    switch (id) {
    case METHODS_CURSOR:
        mMethodsCursor = data;
        View methodContainer = findViewById(R.id.MethodRow);
        if (mMethodsAdapter == null || !data.moveToFirst()) {
            methodContainer.setVisibility(View.GONE);
        } else {
            methodContainer.setVisibility(View.VISIBLE);
            MatrixCursor extras = new MatrixCursor(new String[] { KEY_ROWID, KEY_LABEL, KEY_IS_NUMBERED });
            extras.addRow(new String[] { "0", "- - - -", "0" });
            mMethodsAdapter.swapCursor(new MergeCursor(new Cursor[] { extras, data }));
            if (mSavedInstance) {
                mTransaction.methodId = mMethodId;
            }
            if (mTransaction.methodId != null) {
                while (data.isAfterLast() == false) {
                    if (data.getLong(data.getColumnIndex(KEY_ROWID)) == mTransaction.methodId) {
                        mMethodSpinner.setSelection(data.getPosition() + 1);
                        break;
                    }
                    data.moveToNext();
                }
            } else {
                mMethodSpinner.setSelection(0);
            }
        }
        break;
    case ACCOUNTS_CURSOR:
        mAccountsAdapter.swapCursor(data);
        mAccounts = new Account[data.getCount()];
        if (mSavedInstance) {
            mTransaction.accountId = mAccountId;
            mTransaction.transfer_account = mTransferAccountId;
        }
        data.moveToFirst();
        boolean selectionSet = false;
        String currencyExtra = getIntent().getStringExtra(KEY_CURRENCY);
        while (data.isAfterLast() == false) {
            int position = data.getPosition();
            Account a = Account.fromCacheOrFromCursor(data);
            mAccounts[position] = a;
            if (!selectionSet && (a.currency.getCurrencyCode().equals(currencyExtra)
                    || (currencyExtra == null && a.getId().equals(mTransaction.accountId)))) {
                mAccountSpinner.setSelection(position);
                setAccountLabel(a);
                selectionSet = true;
            }
            data.moveToNext();
        }
        //if the accountId we have been passed does not exist, we select the first entry
        if (mAccountSpinner.getSelectedItemPosition() == android.widget.AdapterView.INVALID_POSITION) {
            mAccountSpinner.setSelection(0);
            mTransaction.accountId = mAccounts[0].getId();
            setAccountLabel(mAccounts[0]);
        }
        if (mOperationType == MyExpenses.TYPE_TRANSFER) {
            mTransferAccountCursor = new FilterCursorWrapper(data);
            int selectedPosition = setTransferAccountFilterMap();
            mTransferAccountsAdapter.swapCursor(mTransferAccountCursor);
            mTransferAccountSpinner.setSelection(selectedPosition);
            mTransaction.transfer_account = mTransferAccountSpinner.getSelectedItemId();
            configureTransferInput();
            if (!mNewInstance && !(mTransaction instanceof Template)) {
                isProcessingLinkedAmountInputs = true;
                mTransferAmountText.setAmount(mTransaction.getTransferAmount().getAmountMajor().abs());
                updateExchangeRates();
                isProcessingLinkedAmountInputs = false;
            }
        } else {
            //the methods cursor is based on the current account,
            //hence it is loaded only after the accounts cursor is loaded
            if (!(mTransaction instanceof SplitPartCategory)) {
                mManager.initLoader(METHODS_CURSOR, null, this);
            }
        }
        mTypeButton.setEnabled(true);
        configureType();
        configureStatusSpinner();
        if (mIsResumed)
            setupListeners();
        break;
    case LAST_EXCHANGE_CURSOR:
        if (data.moveToFirst()) {
            final Currency currency1 = getCurrentAccount().currency;
            final Currency currency2 = Account
                    .getInstanceFromDb(mTransferAccountSpinner.getSelectedItemId()).currency;
            if (currency1.getCurrencyCode().equals(data.getString(0))
                    && currency2.getCurrencyCode().equals(data.getString(1))) {
                BigDecimal amount = new Money(currency1, data.getLong(2)).getAmountMajor();
                BigDecimal transferAmount = new Money(currency2, data.getLong(3)).getAmountMajor();
                BigDecimal exchangeRate = amount.compareTo(nullValue) != 0
                        ? transferAmount.divide(amount, EXCHANGE_RATE_FRACTION_DIGITS, RoundingMode.DOWN)
                        : nullValue;
                if (exchangeRate.compareTo(nullValue) != 0) {
                    mExchangeRate1Text.setAmount(exchangeRate);
                }
            }
        }
    }
}