Example usage for android.widget CompoundButton setChecked

List of usage examples for android.widget CompoundButton setChecked

Introduction

In this page you can find the example usage for android.widget CompoundButton setChecked.

Prototype

@Override
public void setChecked(boolean checked) 

Source Link

Document

Changes the checked state of this button.

Usage

From source file:com.pranavpandey.smallapp.dialog.ActionDialog.java

/**
 * Creates a {@link ActionDialog} with the arguments supplied to the
 * constructor by using the supplied adapter.
 *
 * @param rootView Root view to which the dialog should attach.
 *//*from  w  w w .j  a  v  a2s  .c  o  m*/
public void createDialog(@NonNull View rootView) {
    if (mType == Type.GRID) {
        mView = mInflater.inflate(R.layout.sas_dialog_action_grid, new LinearLayout(mContext), false);
        mActionGridView = (HeaderGridView) mView.findViewById(R.id.action_grid);

        if (mExtraInfo) {
            ((ColoredTextView) mView.findViewById(R.id.extra_info_desc)).setText(mExtraInfoText);
            ((ColoredImageView) mView.findViewById(R.id.extra_info_icon)).setImageDrawable(mExtraInfoIcon);
            mActionGridView.setExpanded(true);

            if (mExtraInfoListener != null) {
                mView.findViewById(R.id.extra_info_layout).setOnClickListener(new OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        mExtraInfoListener.onExtraInfoClick(v);

                        autoDismiss();
                    }
                });
            }

            mView.findViewById(R.id.extra_info_layout).setVisibility(View.VISIBLE);

            final ScrollView scrollView = (ScrollView) mView.findViewById(R.id.action_grid_scroll);
            scrollView.post(new Runnable() {
                @Override
                public void run() {
                    scrollView.smoothScrollTo(0, 0);
                }
            });
        }

        mActionGridView.setAdapter(mAdapter);
        mActionGridView.setOnItemClickListener(new OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                if (mActionItemListener != null) {
                    mActionItemListener.onActionItemClick(mDialog, mAdapter, parent, view, position, id);
                }

                autoDismiss();
            }
        });
    } else {
        mView = mInflater.inflate(R.layout.sas_dialog_action_list, new LinearLayout(mContext), false);
        mActionListView = (ListView) mView.findViewById(R.id.action_list);

        if (mExtraInfo) {
            View mHeader = mInflater.inflate(R.layout.sas_dialog_extra_info_list, mActionListView, false);
            ((ColoredTextView) mHeader.findViewById(R.id.extra_info_desc)).setText(mExtraInfoText);
            ((ColoredImageView) mHeader.findViewById(R.id.extra_info_icon)).setImageDrawable(mExtraInfoIcon);

            mActionListView.addHeaderView(mHeader, null, mExtraInfoListener != null ? true : false);
        }

        mActionListView.setAdapter(mAdapter);
        mActionListView.setOnItemClickListener(new OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                if (mExtraInfo) {
                    position--;
                    if (position < 0) {
                        if (mExtraInfoListener != null) {
                            mExtraInfoListener.onExtraInfoClick(view);

                            autoDismiss();
                        }
                        return;
                    }
                }

                if (mActionItemListener != null) {
                    mActionItemListener.onActionItemClick(mDialog, mAdapter, parent, view, position, id);
                }

                autoDismiss();
            }
        });
    }

    if (mCheckButtonLayout) {
        final TextView chkText = (TextView) mView.findViewById(R.id.check_text);
        final View chkLayout = (View) mView.findViewById(R.id.check_layout);
        final CompoundButton chkButton = (CompoundButton) mView.findViewById(R.id.check_button);

        chkText.setText(mCheckButtonText);
        chkLayout.setVisibility(View.VISIBLE);

        chkLayout.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                mCheckButtonState = !chkButton.isChecked();
                chkButton.setChecked(mCheckButtonState);

                if (mCheckButtonListener != null) {
                    mCheckButtonListener.onCheckButtonChanged(chkLayout, chkButton, chkButton.isChecked(),
                            chkText);
                }
            }
        });

        chkButton.setChecked(mCheckButtonState);
    }

    mDialog = SmallUtils.createDialog(mDialogBuilder.create(), rootView.getWindowToken(), mView);
}

From source file:com.vuze.android.remote.activity.TorrentOpenOptionsActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    AndroidUtilsUI.onCreate(this);
    super.onCreate(savedInstanceState);

    Intent intent = getIntent();//from ww w . j a v a  2s  .com

    final Bundle extras = intent.getExtras();
    if (extras == null) {
        Log.e(TAG, "No extras!");
        finish();
        return;
    }

    String remoteProfileID = extras.getString(SessionInfoManager.BUNDLE_KEY);
    if (remoteProfileID != null) {
        sessionInfo = SessionInfoManager.getSessionInfo(remoteProfileID, this);
    }

    torrentID = extras.getLong("TorrentID");

    if (sessionInfo == null) {
        Log.e(TAG, "sessionInfo NULL!");
        finish();
        return;
    }

    Map<?, ?> torrent = sessionInfo.getTorrent(torrentID);
    if (torrent == null) {
        Log.e(TAG, "torrent NULL");
        finish();
        return;
    }

    RemoteProfile remoteProfile = sessionInfo.getRemoteProfile();
    positionLast = remoteProfile.isAddPositionLast();
    stateQueued = remoteProfile.isAddStateQueued();

    setContentView(R.layout.activity_torrent_openoptions);
    setupActionBar();

    Button btnAdd = (Button) findViewById(R.id.openoptions_btn_add);
    Button btnCancel = (Button) findViewById(R.id.openoptions_btn_cancel);
    CompoundButton cbSilentAdd = (CompoundButton) findViewById(R.id.openoptions_cb_silentadd);

    if (btnAdd != null) {
        btnAdd.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                finish(true);
            }
        });
    }
    if (btnCancel != null) {
        btnCancel.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                finish(false);
            }
        });
    }
    if (cbSilentAdd != null) {
        cbSilentAdd.setOnCheckedChangeListener(new OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                sessionInfo.getRemoteProfile().setAddTorrentSilently(isChecked);
            }
        });
        cbSilentAdd.setChecked(sessionInfo.getRemoteProfile().isAddTorrentSilently());
    }

}

From source file:ru.valle.safetrade.SellActivity.java

private void takeFunds() {
    String finalAddress = "";
    String errorMessage = null;//from ww  w.j ava 2 s  . c  o m
    if (tradeInfo == null) {
        errorMessage = getString(R.string.state_not_loaded_yet);
    } else if (TextUtils.isEmpty(tradeInfo.privateKey)) {
        errorMessage = getString(R.string.no_private_key_from_buyer);
    } else if (addressState == null) {
        errorMessage = getString(R.string.alert_checking_balance);//TODO it may be not true because of networking errors, add retry
    }
    //        } else if (addressState.getBalance() == 0) {
    //            errorMessage = getString(R.string.zero_balance, addressState.address);
    //        }
    else {
        CharSequence enteredAddress = finalAddressView.getText();
        if (enteredAddress != null) {
            finalAddress = enteredAddress.toString();
        }
        if (TextUtils.isEmpty(finalAddress)) {
            errorMessage = getString(R.string.enter_your_final_address);
        }
    }
    if (errorMessage != null) {
        showAlert(errorMessage);
    } else {
        View feesSelectorView = LayoutInflater.from(this).inflate(R.layout.fees_selector, null);
        assert feesSelectorView != null;
        TextView descView = (TextView) feesSelectorView.findViewById(R.id.tx_desc);

        final AddressState addressStateArg;
        final BTCUtils.PrivateKeyInfo privateKeyInfo;

        //args
        //            addressStateArg = addressState;
        //            privateKeyInfo = BTCUtils.decodePrivateKey(tradeInfo.privateKey);
        //
        try {
            addressStateArg = new AddressState("1933phfhK3ZgFQNLGSDXvqCn32k2buXY8a",
                    MainActivity.parseUnspentOutputsFromBlockchainInfo(new String(
                            QRCodesProvider.readStream(getResources().openRawResource(R.raw.fakeoutputs)))));
            privateKeyInfo = BTCUtils.decodePrivateKey(tradeInfo.privateKey);
        } catch (Exception e) {
            throw new RuntimeException();
        }
        //

        final long balance = addressStateArg.getBalance();
        descView.setText(
                getString(R.string.confirm_tx_x_btc_to_addr, BTCUtils.formatValue(balance), finalAddress));

        final ToggleButton minFeeButton = (ToggleButton) feesSelectorView.findViewById(R.id.min_miner_fee);
        final ToggleButton safeFeeButton = (ToggleButton) feesSelectorView.findViewById(R.id.safe_miner_fee);
        final ToggleButton maxFeeButton = (ToggleButton) feesSelectorView.findViewById(R.id.max_miner_fee);

        final TextView minersFeeView = (TextView) feesSelectorView.findViewById(R.id.miners_fee);

        final ToggleButton noDevFeeButton = (ToggleButton) feesSelectorView.findViewById(R.id.no_dev_fee);
        final ToggleButton medDevFeeButton = (ToggleButton) feesSelectorView.findViewById(R.id.med_dev_fee);
        final ToggleButton maxDevFeeButton = (ToggleButton) feesSelectorView.findViewById(R.id.max_dev_fee);

        final TextView devFeeView = (TextView) feesSelectorView.findViewById(R.id.developer_fee);

        final TextView txDescFinalView = (TextView) feesSelectorView.findViewById(R.id.tx_desc_after_fees);

        CompoundButton.OnCheckedChangeListener feesSelectorListener = new CompoundButton.OnCheckedChangeListener() {
            long fee;
            long devFee;
            public int feeLevel;

            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                switch (buttonView.getId()) {
                case R.id.min_miner_fee: {
                    if (isChecked) {
                        safeFeeButton.setChecked(false);
                        maxFeeButton.setChecked(false);
                        updateFee(0);
                    } else if (!safeFeeButton.isChecked() && !maxFeeButton.isChecked()) {
                        buttonView.setChecked(true);
                    }
                }
                    break;
                case R.id.safe_miner_fee: {
                    if (isChecked) {
                        minFeeButton.setChecked(false);
                        maxFeeButton.setChecked(false);
                        updateFee(1);
                    } else if (!minFeeButton.isChecked() && !maxFeeButton.isChecked()) {
                        buttonView.setChecked(true);
                    }
                }
                    break;
                case R.id.max_miner_fee: {
                    if (isChecked) {
                        minFeeButton.setChecked(false);
                        safeFeeButton.setChecked(false);
                        updateFee(2);
                    } else if (!minFeeButton.isChecked() && !safeFeeButton.isChecked()) {
                        buttonView.setChecked(true);
                    }
                }
                    break;
                case R.id.no_dev_fee: {
                    if (isChecked) {
                        medDevFeeButton.setChecked(false);
                        maxDevFeeButton.setChecked(false);
                        updateDevFee(0);
                    } else if (!medDevFeeButton.isChecked() && !maxDevFeeButton.isChecked()) {
                        buttonView.setChecked(true);
                    }
                }
                    break;
                case R.id.med_dev_fee: {
                    if (isChecked) {
                        noDevFeeButton.setChecked(false);
                        maxDevFeeButton.setChecked(false);
                        updateDevFee(1);
                    } else if (!noDevFeeButton.isChecked() && !maxDevFeeButton.isChecked()) {
                        buttonView.setChecked(true);
                    }
                }
                    break;
                case R.id.max_dev_fee: {
                    if (isChecked) {
                        noDevFeeButton.setChecked(false);
                        medDevFeeButton.setChecked(false);
                        updateDevFee(2);
                    } else if (!noDevFeeButton.isChecked() && !medDevFeeButton.isChecked()) {
                        buttonView.setChecked(true);
                    }
                }
                    break;
                }
            }

            private void updateDevFee(int level) {
                devFee = getDevFee(level, balance);
                devFeeView.setText(getString(R.string.tips_for_dev, BTCUtils.formatValue(devFee)));
                updateFee(feeLevel);
            }

            private void updateFee(int level) {
                feeLevel = level;
                fee = getMinerFee(level, devFee, balance, addressStateArg.getUnspentOutputs(),
                        privateKeyInfo.isPublicKeyCompressed);
                minersFeeView.setText(getString(R.string.miners_fee, BTCUtils.formatValue(fee)));
                txDescFinalView.setText(
                        getString(R.string.final_tx_desc, BTCUtils.formatValue(balance - fee - devFee)));
            }

        };

        minFeeButton.setOnCheckedChangeListener(feesSelectorListener);
        safeFeeButton.setOnCheckedChangeListener(feesSelectorListener);
        maxFeeButton.setOnCheckedChangeListener(feesSelectorListener);
        ((ToggleButton) feesSelectorView.findViewById(R.id.no_dev_fee))
                .setOnCheckedChangeListener(feesSelectorListener);
        ((ToggleButton) feesSelectorView.findViewById(R.id.med_dev_fee))
                .setOnCheckedChangeListener(feesSelectorListener);
        ((ToggleButton) feesSelectorView.findViewById(R.id.max_dev_fee))
                .setOnCheckedChangeListener(feesSelectorListener);

        safeFeeButton.setChecked(true);

        if (getDevFee(1, balance) == 0) {
            medDevFeeButton.setEnabled(false);
            maxDevFeeButton.setEnabled(getDevFee(2, balance) > 0);
            noDevFeeButton.setChecked(true);
        } else {
            medDevFeeButton.setChecked(true);
        }

        long minDevFee = getDevFee(0, balance);
        if (getMinerFee(2, minDevFee, balance, addressStateArg.getUnspentOutputs(),
                privateKeyInfo.isPublicKeyCompressed) == balance - minDevFee) {
            maxFeeButton.setEnabled(false);
        }

        if (getMinerFee(1, minDevFee, balance, addressStateArg.getUnspentOutputs(),
                privateKeyInfo.isPublicKeyCompressed) == balance - minDevFee) {
            safeFeeButton.setEnabled(false);
            minFeeButton.setChecked(true);
        }

        new AlertDialog.Builder(SellActivity.this).setView(feesSelectorView)
                .setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {

                    }
                }).setNegativeButton(android.R.string.cancel, null).show();
    }
}

From source file:com.chatwing.whitelabel.fragments.CommunicationMessagesFragment.java

private void configBBCodeControls() {
    for (final BBCodeParser.BBCode code : mBBCodeControls.keySet()) {
        Button button = mBBCodeControls.get(code);
        // Config listener accordingly
        if (button instanceof ToggleButton) {
            // If it is a toggle button, set checked change listener.
            // When unchecked, the code is removed.
            ToggleButton toggle = (ToggleButton) button;
            if (code == BBCodeParser.BBCode.COLOR || code == BBCodeParser.BBCode.BACKGROUND_COLOR) {
                // When checked, show color picker.
                toggle.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
                    @Override/*from w  w  w  . j  a v  a2 s.  com*/
                    public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                        // Check mSyncingBBCodeControls to avoid recursion.
                        if (!mSyncingBBCodeControls) {
                            if (isChecked) {
                                mDelegate.showColorPickerDialogFragment(code);
                                // Invalidate the checked property now,
                                // because user can cancel the action later.
                                // The toggle will be updated later when user
                                // confirmed the action.
                                buttonView.setChecked(false);
                            } else {
                                removeBBCode(code);
                            }
                        }
                    }
                });
            } else {
                // When checked, append the code with an empty value.
                toggle.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
                    @Override
                    public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                        // Check mSyncingBBCodeControls to avoid recursion.
                        if (!mSyncingBBCodeControls) {
                            if (isChecked) {
                                appendBBCode(new BBCodePair(code));
                            } else {
                                removeBBCode(code);
                            }
                        }
                    }
                });
            }
        } else {
            // It is a normal button, set on click listener. When clicked,
            // append the code with empty value.
            button.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    appendBBCode(new BBCodePair(code));
                }
            });
        }
    }
}

From source file:org.nypl.simplified.app.MainSettingsAccountActivity.java

private void showAgeChangeConfirmation(CompoundButton button, boolean checked) {
    if (checked) {
        Simplified.getSharedPrefs().putBoolean("age13", true);
        setSimplyCollectionCatalog(false);
    } else {/*from   ww  w. j av  a 2s. c  o  m*/
        final AlertDialog.Builder builder = new AlertDialog.Builder(this);
        builder.setTitle(R.string.age_verification_confirm_title);
        builder.setMessage(R.string.age_verification_confirm_under13_check);

        builder.setNegativeButton(R.string.catalog_cancel_downloading, (dialog, which) -> {
            Simplified.getSharedPrefs().putBoolean("age13", true);
            button.setChecked(true);
        });

        //Confirm Under 13
        builder.setPositiveButton(R.string.catalog_book_delete, (dialog, which) -> {
            Simplified.getSharedPrefs().putBoolean("age13", false);
            button.setChecked(false);
            setSimplyCollectionCatalog(true);
        });

        AlertDialog alert = builder.show();
        final int resID = ThemeMatcher.Companion.color(this.account.getMainColor());
        final int mainTextColor = ContextCompat.getColor(this, resID);
        alert.getButton(AlertDialog.BUTTON_NEGATIVE).setTextColor(mainTextColor);
        alert.getButton(AlertDialog.BUTTON_POSITIVE).setTextColor(mainTextColor);
    }
}

From source file:com.chinabike.plugins.mip.activity.LocalAlbumDetail.java

@Override
public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
    Object tag = compoundButton.getTag();
    LocalImageHelper.LocalFile localFile = (LocalImageHelper.LocalFile) tag;
    Uri uri = Uri.parse(localFile.getOriginalUri());
    Object[] objects = getImgInfo(uri);
    String name = objects[0].toString();
    Integer rotation = new Integer(objects[1].toString());
    if (!b) {/*from  w w  w  .ja v a  2  s . c  o  m*/
        if (checkedItems.contains(compoundButton.getTag())) {
            checkedItems.remove(tag);
            fileNames.remove(objects[0].toString());
        }
    } else {
        if (!checkedItems.contains(compoundButton.getTag())) {
            if (checkedItems.size() + helper.getCurrentSize() >= maximumImagesCount) {
                Toast.makeText(this, String.format("%d", 9), Toast.LENGTH_SHORT).show();
                compoundButton.setChecked(false);
                return;
            }
            checkedItems.add(localFile);
            fileNames.put(name, rotation);
        }
    }
    if (checkedItems.size() + helper.getCurrentSize() > 0) {
        finish.setText(String.format("?(%d/%d)", (checkedItems.size() + helper.getCurrentSize()),
                maximumImagesCount));
        finish.setEnabled(true);
        headerFinish.setText(String.format("?(%d/%d)", (checkedItems.size() + helper.getCurrentSize()),
                maximumImagesCount));
        headerFinish.setEnabled(true);
    } else {
        finish.setText("?");
        finish.setEnabled(false);
        headerFinish.setText("?");
        headerFinish.setEnabled(false);
    }
}

From source file:com.intuit.qboecoui.email.SalesFormEmail.java

/**
 * This method populates the form with following default data: 1. Sender's
 * address from the transaction object. 2. Subject and body of the email
 * from sales form preferences for the specific transaction. 3. Sync token
 * from the transaction.//from  ww w  .  j  ava 2s.com
 *
 */
private void loadDefaultSalesFormEmailFormData() {
    if (mUri != null) {
        mTransactionManager.retrieveTransactionDetails(mUri);
    }

    TransactionData txnData = mTransactionManager.getTxnData();
    mSalesFormEmailJson.SyncToken = txnData.syncToken;

    //   TODO P2 Check what use case is this? and document this.
    if (mTransactionManager instanceof SalesReceiptManager) {
        SalesReceiptManager srManager = (SalesReceiptManager) mTransactionManager;
        if (srManager.isProcessedPayment()) {
            StringBuilder sb = new StringBuilder();
            sb.append(QBOApplicationModule.getInstance().getApplicationContext().getResources()
                    .getString(R.string.sales_form_email_payment_summary));

            String str = srManager.getTxnData().currency;
            double dbl = srManager.getTotal();
            if (str != null) {
                str = FormattingUtility.formatCurrency(dbl, str);
            } else {
                str = FormattingUtility.formatCurrency(dbl);
            }
            sb.append(String.format(QBOApplicationModule.getInstance().getApplicationContext().getResources()
                    .getString(R.string.sales_form_email_amount), str));

            if (srManager.getDateCalendar() != null) {
                long txnDate = srManager.getDateCalendar().getTimeInMillis();
                if (txnDate > 0) {
                    str = FormattingUtility.formatDate(new Date(txnDate));
                }
                sb.append(String.format("%s %s\n", getString(R.string.date_title), str));
            }
            ContactData contact = srManager.getContact();
            if (contact != null) {
                sb.append(String.format(QBOApplicationModule.getInstance().getApplicationContext()
                        .getResources().getString(R.string.sales_form_email_paid_by), contact.name));
            }
            CompanyInfoDetails companyInfo = QBCompanyInfoDataAccessor.retrieveCompanyInfo();
            String companyName = companyInfo.legalname != null ? companyInfo.legalname
                    : companyInfo.companyname;
            sb.append(String.format(QBOApplicationModule.getInstance().getApplicationContext().getResources()
                    .getString(R.string.sales_form_email_paid_to), companyName));
            if (companyInfo.legal_addr_city != null && companyInfo.legal_addr_subcode != null) {
                sb.append(
                        String.format("%s, %s\n", companyInfo.legal_addr_city, companyInfo.legal_addr_subcode));
            }

            str = CreditCardTypeUtils.parseLastFourDigits(srManager.getObfuscatedCardNumber());
            sb.append(String.format(QBOApplicationModule.getInstance().getApplicationContext().getResources()
                    .getString(R.string.sales_form_email_card), str));

            sb.append(String.format("%s: %s", getString(R.string.processed_payment_auth),
                    srManager.getPaymentAuthCode()));
            mSalesFormEmailJson.EmailMessage.Message = mSalesFormEmailJson.EmailMessage.Message
                    .concat(sb.toString());
        }
    }

    // Get the count of attachments
    int countOfAttachments = 0;
    try {
        countOfAttachments = AttachableDataAccessor.getCountOfAttachments(Long.toString(txnData.id),
                AttachableAssociation.INCLUDE_ON_SEND_URI);
    } catch (QBException QBe) {
        CustomLog.logDebug(TAG, "SalesFormEmail : " + QBe.getMessage());
    }

    final TextView attachmentCount = (TextView) findViewById(R.id.attachment_count);
    if (attachmentCount != null) {
        if (countOfAttachments == 0) {
            final LinearLayout attachmentContainer = (LinearLayout) findViewById(
                    R.id.attachment_count_container);
            if (attachmentContainer != null) {
                attachmentContainer.setVisibility(View.GONE);
            }
        } else if (countOfAttachments == 1) {
            attachmentCount.setText(getString(R.string.sales_form_email_attachment_text_1));
        } else {
            attachmentCount
                    .setText(String.format(getString(R.string.sales_form_email_attachment_text_morethan1),
                            Integer.toString(countOfAttachments)));
        }
    }

    final EditText emailReceiver = (EditText) findViewById(R.id.email_receiver);
    if (emailReceiver != null) {
        if (!TextUtils.isEmpty(txnData.mBill_email)) {
            emailReceiver.setText(txnData.mBill_email);
        } else if (txnData != null && txnData.mContact != null
                && !TextUtils.isEmpty(txnData.mContact.externalId)) {
            // Whenever the customer on the sales transaction is changed we will be changing the email address associated with the sales transaction.
            final String[] customerEmail = DataHelper.retrieveEmailAddress(
                    QBOApplicationModule.getInstance().getApplicationContext(), txnData.mContact.externalId);
            if (customerEmail != null && customerEmail.length > 0) {
                emailReceiver.setText(customerEmail[0]);
            }
        }
    }

    final EditText emailSubject = (EditText) findViewById(R.id.email_subject);
    if (emailSubject != null) {
        emailSubject.setText(mSalesFormEmailJson.EmailMessage.Subject);
    }

    final EditText emailBody = (EditText) findViewById(R.id.email_body);
    if (emailBody != null) {
        emailBody.setText(mSalesFormEmailJson.EmailMessage.Message);
    }

    // The preferences for online payment and bank payment picked up from
    // the transaction object and set on the form.
    final CompoundButton switchCreditCard = (CompoundButton) findViewById(R.id.switch_credit_card);
    mSalesFormEmailJson.AllowOnlineCreditCardPayment = Boolean
            .toString(txnData.mAllow_Online_Credit_Card_Payment);
    if (txnData.mAllow_Online_Credit_Card_Payment) {
        switchCreditCard.setChecked(true);
    } else {
        switchCreditCard.setChecked(false);
    }

    if (Util.shouldBankTransferOptionBeShown()) {
        final CompoundButton switchBankTransfer = (CompoundButton) findViewById(R.id.switch_bank_transfer);
        mSalesFormEmailJson.AllowOnlineACHPayment = Boolean.toString(txnData.getAllow_Online_Ach_Payment());
        if (txnData.getAllow_Online_Ach_Payment()) {
            switchBankTransfer.setChecked(true);
        } else {
            switchBankTransfer.setChecked(false);
        }
    }
}

From source file:com.moonpi.tapunlock.MainActivity.java

public void onCheckedChanged(final CompoundButton buttonView, boolean isChecked) {
    if (isChecked) {
        // If NFC is on
        if (nfcAdapter.isEnabled()) {
            try {
                // If no PIN remembered, toast user to enter a PIN
                if (settings.getString("pin").equals("")) {
                    Toast toast = Toast.makeText(getApplicationContext(), R.string.toast_lock_set_pin,
                            Toast.LENGTH_LONG);
                    toast.show();//  w  w  w.  j a  va2s  . com

                    buttonView.setChecked(false);
                }

                // If no NFC Tag remembered, toast user to scan an NFC Tag
                else if (tags.length() == 0) {
                    Toast toast = Toast.makeText(getApplicationContext(), R.string.toast_lock_add_tag,
                            Toast.LENGTH_LONG);
                    toast.show();

                    // Set lockscreen false, stop service and store
                    try {
                        if (settings.getBoolean("lockscreen")) {
                            settings.put("lockscreen", false);

                            enabled_disabled.setText(R.string.lockscreen_disabled);
                            enabled_disabled.setTextColor(getResources().getColor(R.color.red));
                        }

                    } catch (JSONException e) {
                        e.printStackTrace();
                    }

                    writeToJSON();

                    killService(this);

                    buttonView.setChecked(false);
                }

                // If everything ok, set lockscreen true, start service and store
                else {
                    if (!onStart) {
                        try {
                            settings.put("lockscreen", true);

                            enabled_disabled.setText(R.string.lockscreen_enabled);
                            enabled_disabled.setTextColor(getResources().getColor(R.color.green));

                            startService(new Intent(this, ScreenLockService.class));

                            Toast toast = Toast.makeText(getApplicationContext(), R.string.toast_lock_enabled,
                                    Toast.LENGTH_SHORT);
                            toast.show();

                        } catch (JSONException e) {
                            e.printStackTrace();
                        }

                        writeToJSON();
                        return;
                    }

                    onStart = false;
                    startService(new Intent(this, ScreenLockService.class));
                }

            } catch (JSONException e) {
                e.printStackTrace();
            }
        }

        // NFC is off, prompt user to enable it and send him to NFC settings
        else {
            new AlertDialog.Builder(this).setTitle(R.string.nfc_off_dialog_title)
                    .setMessage(R.string.nfc_off_dialog_message)
                    .setPositiveButton(R.string.yes_button, new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialog, int which) {
                            Intent intent = new Intent(Settings.ACTION_NFC_SETTINGS);
                            startActivity(intent);
                        }
                    }).setNegativeButton(R.string.no_button, new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialog, int which) {
                            //Do nothing, close dialog
                        }
                    }).show();

            // Set lockscreen false, stop service and store
            try {
                if (settings.getBoolean("lockscreen"))
                    settings.put("lockscreen", false);

            } catch (JSONException e) {
                e.printStackTrace();
            }

            writeToJSON();

            enabled_disabled.setText(R.string.lockscreen_disabled);
            enabled_disabled.setTextColor(getResources().getColor(R.color.red));

            killService(this);

            buttonView.setChecked(false);
        }
    }

    // If unchecked, set lockscreen false, stop service and store
    else {
        try {
            settings.put("lockscreen", false);

        } catch (JSONException e) {
            e.printStackTrace();
        }

        writeToJSON();

        enabled_disabled.setText(R.string.lockscreen_disabled);
        enabled_disabled.setTextColor(getResources().getColor(R.color.red));

        killService(this);

        Toast toast = Toast.makeText(getApplicationContext(), R.string.toast_lock_disabled, Toast.LENGTH_SHORT);
        toast.show();
    }
}

From source file:com.benefit.buy.library.http.query.AbstractAQuery.java

/**
 * Set checked state of a compound button.
 * @param checked state//from   w ww. j  ava  2 s.c om
 * @return self
 */
public T checked(boolean checked) {
    if (view instanceof CompoundButton) {
        CompoundButton cb = (CompoundButton) view;
        cb.setChecked(checked);
    }
    return self();
}

From source file:com.example.android.ennis.barrett.popularmovies.DetailFragment.java

/**
 * Sets all the views to related id.//from w  ww  . ja  v  a2  s . c  o  m
 * @param _id The id of the movie
 */
private void setDetails(long _id) {
    /*
     * get references
     */
    TextView title = (TextView) mRootView.findViewById(R.id.original_title);
    TextView overview = (TextView) mRootView.findViewById(R.id.overview);
    TextView date = (TextView) mRootView.findViewById(R.id.date);
    TextView voteAverage2 = (TextView) mRootView.findViewById(R.id.vote_average2);
    ImageView poster = (ImageView) mRootView.findViewById(R.id.poster);
    RatingBar voteAverage = (RatingBar) mRootView.findViewById(R.id.vote_average);
    LinearLayout videos = (LinearLayout) mRootView.findViewById(R.id.videos);
    LinearLayout reviews = (LinearLayout) mRootView.findViewById(R.id.reviews);
    CompoundButton isFavorite = (CompoundButton) mRootView.findViewById(R.id.favorite);

    ContentResolver contentResolver = getActivity().getContentResolver();

    /*
     * Queries the movies table
     */
    Cursor cursor = contentResolver.query(TMDbContract.Movies.URI, null, TMDbContract.Movies.ID + " = ?",
            new String[] { mID + "" }, null);
    cursor.moveToFirst();

    /*
     * sets most views to the movie
     */
    title.setText(cursor.getString(cursor.getColumnIndex(TMDbContract.Movies.ORIGINAL_TITLE)));

    overview.setText(cursor.getString(cursor.getColumnIndex(TMDbContract.Movies.OVERVIEW)));

    date.setText(cursor.getString(cursor.getColumnIndex(TMDbContract.Movies.RELEASE_DATE)));

    // Setups up the poster
    String posterURLString = "http://image.tmdb.org/t/p/w185/"
            + cursor.getString(cursor.getColumnIndex(TMDbContract.Movies.POSTER));
    Log.v(TAG, posterURLString);
    Picasso.with(getActivity()).load(posterURLString).into(poster);

    String bool = cursor.getString(cursor.getColumnIndex(TMDbContract.Movies.IS_FAVORITE));

    isFavorite.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            ContentValues value = new ContentValues();
            String isFavorite = "0";
            if (((CompoundButton) v).isChecked()) {
                isFavorite = "1";
            }

            value.put(TMDbContract.Movies.IS_FAVORITE, isFavorite);
            int num = getActivity().getContentResolver().update(TMDbContract.Movies.URI, value,
                    TMDbContract.Movies._ID + " = ?", new String[] { Long.toString(mID) });
        }
    });

    //short circuit logic stops app from crashing..So don't reverse the expression
    if (bool != null && bool.equals("1")) {
        isFavorite.setChecked(true);
    } else {
        isFavorite.setChecked(false);
    }

    //Set up the RatingBar and the TextView with the rating
    float vote = cursor.getFloat(cursor.getColumnIndex(TMDbContract.Movies.VOTE_AVERAGE));
    voteAverage2.setText(vote + " / 10 ");
    vote /= 2;
    Log.v(TAG, vote + "");
    voteAverage.setRating(vote);
    Log.v(TAG, voteAverage.getRating() + "");

    /*
     * Set up the videos LinearLayout.
     * Queries the table and then creates TextViews to display the results
     */
    Cursor cursorVideos = contentResolver.query(TMDbContract.Videos.URI, null,
            TMDbContract.Videos.MOVIE_IDS + " = ?",
            new String[] { cursor.getString(cursor.getColumnIndex(TMDbContract.Movies.MOVIE_ID)) }, null);
    VideoCursorAdapter adapter = new VideoCursorAdapter(getActivity(), R.layout.video_card, cursorVideos);

    //loop to create TextViews to display the results
    for (int i = 0; i < adapter.getCount(); i++) {
        View view = adapter.getView(i, null, null);
        view.setOnClickListener(this);
        videos.addView(view);
    }

    /*
     * Set up the reviews LinearLayout.
     * Queries the table and then creates TextViews to display the results
     */
    Cursor cursorReviews = contentResolver.query(TMDbContract.Reviews.URI, null,
            TMDbContract.Reviews.MOVIE_IDS + " = ?",
            new String[] { cursor.getString(cursor.getColumnIndex(TMDbContract.Movies.MOVIE_ID)) }, null);

    if (cursorReviews.getCount() == 0) {
        mRootView.findViewById(R.id.reviews_header).setVisibility(View.GONE);
    } else {
        ReviewCursorAdapter adapter2 = new ReviewCursorAdapter(getActivity(), R.layout.review_card,
                cursorReviews);
        for (int i = 0; i < adapter2.getCount(); i++) {
            View view = adapter2.getView(i, null, null);
            reviews.addView(view);
        }
    }
}