Example usage for android.widget ToggleButton isChecked

List of usage examples for android.widget ToggleButton isChecked

Introduction

In this page you can find the example usage for android.widget ToggleButton isChecked.

Prototype

@ViewDebug.ExportedProperty
    @Override
    public boolean isChecked() 

Source Link

Usage

From source file:de.ub0r.android.websms.WebSMS.java

/**
 * Send text after the real connector is chosen.
 *
 * @param connector    which connector should be used.
 * @param subconnector which subconnector should be used
 * @param tos          recipients/*from w  ww  . j  av  a2 s .c o  m*/
 * @param text         message text
 * @return true if message was sent
 */
private boolean sendReal(final ConnectorSpec connector, final SubConnectorSpec subconnector, final String[] tos,
        final String text) {

    Log.d(TAG, "sendReal(" + connector + "," + subconnector + ")");
    final SharedPreferences p = PreferenceManager.getDefaultSharedPreferences(this);

    if (!p.getBoolean(PREFS_TRY_SEND_INVALID, false)
            && connector.hasCapabilities(ConnectorSpec.CAPABILITIES_CHARACTER_CHECK)) {
        final String valid = connector.getValidCharacters();
        if (valid == null) {
            Log.i(TAG, "valid: null");
            Toast.makeText(this, R.string.log_error_char_nonvalid, Toast.LENGTH_LONG).show();
            return false;
        }
        final Pattern checkPattern = Pattern.compile("[^" + Pattern.quote(valid) + "]+");
        Log.d(TAG, "pattern: " + checkPattern.pattern());
        final Matcher m = checkPattern.matcher(text);
        if (m.find()) {
            final String illigal = m.group();
            Log.i(TAG, "invalid character: " + illigal);
            Toast.makeText(this, this.getString(R.string.log_error_char_notsendable) + ": " + illigal,
                    Toast.LENGTH_LONG).show();
            return false;
        }
    }

    ToggleButton v = (ToggleButton) this.findViewById(R.id.flashsms);
    final boolean flashSMS = (v.getVisibility() == View.VISIBLE) && v.isEnabled() && v.isChecked();
    final String defPrefix = p.getString(PREFS_DEFPREFIX, "+49");
    final String defSender = p.getString(PREFS_SENDER, "");

    final ConnectorCommand command = ConnectorCommand.send(nextMsgId(this), subconnector.getID(), defPrefix,
            defSender, tos, text, flashSMS);
    command.setCustomSender(lastCustomSender);
    command.setSendLater(lastSendLater);

    boolean sent = false;
    try {
        if (subconnector.hasFeatures(SubConnectorSpec.FEATURE_MULTIRECIPIENTS) || tos.length == 1) {
            Log.d(TAG, "text: " + text);
            Log.d(TAG, "to: ", tos);
            runCommand(this, connector, command);
        } else {
            ConnectorCommand cc;
            for (String t : tos) {
                if (t.trim().length() < 1) {
                    continue;
                }
                cc = (ConnectorCommand) command.clone();
                cc.setRecipients(t);
                Log.d(TAG, "text: " + text);
                Log.d(TAG, "to: ", tos);
                runCommand(this, connector, cc);
            }
        }
        sent = true;
    } catch (Exception e) {
        Log.e(TAG, "error running command", e);
        Toast.makeText(this, R.string.error, Toast.LENGTH_LONG).show();
    }
    if (sent) {
        this.reset(false);
        try {
            Thread.sleep(SLEEP_BEFORE_EXIT);
        } catch (InterruptedException e) {
            Log.e(TAG, null, e);
        }
        this.finish();
        return true;
    }
    return false;
}

From source file:ru.valle.btc.MainActivity.java

private void showQRCodePopupForPrivateKey(final String label, final String address, final String[] data,
        final String[] dataTypes) {
    DisplayMetrics dm = getResources().getDisplayMetrics();
    final int screenSize = Math.min(dm.widthPixels, dm.heightPixels);
    new AsyncTask<Void, Void, Bitmap[]>() {

        @Override/*  ww  w  .jav  a 2 s. c  om*/
        protected Bitmap[] doInBackground(Void... params) {
            Bitmap[] result = new Bitmap[data.length];
            for (int i = 0; i < data.length; i++) {
                if (data[i] != null) {
                    QRCode qr = QRCode.getMinimumQRCode(data[i], ErrorCorrectLevel.M);
                    result[i] = qr.createImage(screenSize / 2);
                }
            }
            return result;
        }

        @Override
        protected void onPostExecute(final Bitmap[] bitmap) {
            if (bitmap != null) {
                View view = getLayoutInflater().inflate(R.layout.private_key_qr, mainLayout, false);
                if (view != null) {
                    final ToggleButton toggle1 = (ToggleButton) view.findViewById(R.id.toggle_1);
                    final ToggleButton toggle2 = (ToggleButton) view.findViewById(R.id.toggle_2);
                    final ToggleButton toggle3 = (ToggleButton) view.findViewById(R.id.toggle_3);
                    final ImageView qrView = (ImageView) view.findViewById(R.id.qr_code_image);
                    final TextView dataView = (TextView) view.findViewById(R.id.qr_code_data);

                    if (data[0] == null) {
                        toggle1.setVisibility(View.GONE);
                    } else {
                        toggle1.setTextOff(dataTypes[0]);
                        toggle1.setTextOn(dataTypes[0]);
                        toggle1.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
                            @Override
                            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                                if (isChecked) {
                                    toggle2.setChecked(false);
                                    toggle3.setChecked(false);
                                    qrView.setImageBitmap(bitmap[0]);
                                    dataView.setText(data[0]);
                                } else if (!toggle2.isChecked() && !toggle3.isChecked()) {
                                    buttonView.setChecked(true);
                                }
                            }
                        });
                    }
                    if (data[1] == null) {
                        toggle2.setVisibility(View.GONE);
                    } else {
                        toggle2.setTextOff(dataTypes[1]);
                        toggle2.setTextOn(dataTypes[1]);
                        toggle2.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
                            @Override
                            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                                if (isChecked) {
                                    toggle1.setChecked(false);
                                    toggle3.setChecked(false);
                                    qrView.setImageBitmap(bitmap[1]);
                                    dataView.setText(data[1]);
                                } else if (!toggle1.isChecked() && !toggle3.isChecked()) {
                                    buttonView.setChecked(true);
                                }
                            }
                        });
                    }
                    if (data[2] == null) {
                        toggle3.setVisibility(View.GONE);
                    } else {
                        toggle3.setTextOff(dataTypes[2]);
                        toggle3.setTextOn(dataTypes[2]);
                        toggle3.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
                            @Override
                            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                                if (isChecked) {
                                    toggle1.setChecked(false);
                                    toggle2.setChecked(false);
                                    qrView.setImageBitmap(bitmap[2]);
                                    dataView.setText(data[2]);
                                } else if (!toggle1.isChecked() && !toggle2.isChecked()) {
                                    buttonView.setChecked(true);
                                }
                            }
                        });
                    }
                    if (data[2] != null) {
                        toggle3.setChecked(true);
                    } else if (data[0] != null) {
                        toggle1.setChecked(true);
                    } else {
                        toggle2.setChecked(true);
                    }

                    AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this);
                    builder.setTitle(label);
                    builder.setView(view);
                    DialogInterface.OnClickListener shareClickListener = new DialogInterface.OnClickListener() {

                        @Override
                        public void onClick(DialogInterface dialog, int which) {
                            int selectedIndex;
                            if (toggle1.isChecked()) {
                                selectedIndex = 0;
                            } else if (toggle2.isChecked()) {
                                selectedIndex = 1;
                            } else {
                                selectedIndex = 2;
                            }
                            Intent intent = new Intent(Intent.ACTION_SEND);
                            intent.setType("text/plain");
                            intent.putExtra(Intent.EXTRA_SUBJECT, label);
                            intent.putExtra(Intent.EXTRA_TEXT, data[selectedIndex]);
                            startActivity(
                                    Intent.createChooser(intent, getString(R.string.share_chooser_title)));
                        }
                    };
                    if (systemSupportsPrint()) {
                        builder.setPositiveButton(R.string.print, new DialogInterface.OnClickListener() {
                            @Override
                            public void onClick(DialogInterface dialog, int which) {
                                int selectedIndex;
                                if (toggle1.isChecked()) {
                                    selectedIndex = 0;
                                } else if (toggle2.isChecked()) {
                                    selectedIndex = 1;
                                } else {
                                    selectedIndex = 2;
                                }
                                Renderer.printWallet(MainActivity.this, label, SCHEME_BITCOIN + address,
                                        data[selectedIndex]);
                            }
                        });
                        builder.setNeutralButton(R.string.share, shareClickListener);
                    } else {
                        builder.setPositiveButton(R.string.share, shareClickListener);
                    }
                    builder.setNegativeButton(android.R.string.cancel, null);
                    builder.show();
                }
            }
        }
    }.execute();
}

From source file:com.updetector.MainActivity.java

/**
* Handle Setting click//  w  w  w .ja  v a2s . c  om
*/
private void handleSettings() {
    final Dialog dialog = new Dialog(this);
    dialog.setTitle(R.string.menu_item_settings);
    dialog.setContentView(R.layout.settings);

    final SharedPreferences mPrefs = getSharedPreferences(Constants.SHARED_PREFERENCES, Context.MODE_PRIVATE);
    final Editor editor = mPrefs.edit();

    final ToggleButton logOnButton = (ToggleButton) dialog.findViewById(R.id.log_on);
    logOnButton.setChecked(mPrefs.getBoolean(Constants.LOGGING_ON, false));

    final Button btDeviceSelectButton = (Button) dialog.findViewById(R.id.bt_device_button);
    btDeviceSelectButton.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(final View v) {
            if (mBluetoothAdapter.isEnabled()) {
                selectBluetoothDevice();
            } else {
                Toast.makeText(getApplicationContext(), "Please enable your Bluetooth first.",
                        Toast.LENGTH_SHORT).show();
            }

        }
    });

    final Button applyButton = (Button) dialog.findViewById(R.id.apply_button);
    final Button cancelButton = (Button) dialog.findViewById(R.id.cancel_button);
    applyButton.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(final View v) {
            if (logOnButton.isChecked())
                editor.putBoolean(Constants.LOGGING_ON, true);
            else
                editor.putBoolean(Constants.LOGGING_ON, false);
            editor.commit();
            dialog.cancel();
        }
    });

    cancelButton.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(final View v) {
            dialog.cancel();
        }
    });
    dialog.show();
}

From source file:cm.aptoide.pt.MainActivity.java

private void displayOptionsDialog() {

    final SharedPreferences sPref = PreferenceManager.getDefaultSharedPreferences(this);
    final Editor editor = sPref.edit();

    View view = LayoutInflater.from(mContext).inflate(R.layout.dialog_order_popup, null);
    AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(mContext).setView(view);
    final AlertDialog orderDialog = dialogBuilder.create();
    orderDialog.setIcon(android.R.drawable.ic_menu_sort_by_size);
    orderDialog.setTitle(getString(R.string.menu_display_options));
    orderDialog.setCancelable(true);//from  ww  w  .j  a  v  a 2 s  .c  o  m

    final RadioButton ord_rct = (RadioButton) view.findViewById(R.id.org_rct);
    final RadioButton ord_abc = (RadioButton) view.findViewById(R.id.org_abc);
    final RadioButton ord_rat = (RadioButton) view.findViewById(R.id.org_rat);
    final RadioButton ord_dwn = (RadioButton) view.findViewById(R.id.org_dwn);
    final RadioButton ord_price = (RadioButton) view.findViewById(R.id.org_price);
    final RadioButton btn1 = (RadioButton) view.findViewById(R.id.shw_ct);
    final RadioButton btn2 = (RadioButton) view.findViewById(R.id.shw_all);

    final ToggleButton adult = (ToggleButton) view.findViewById(R.id.adultcontent_toggle);

    orderDialog.setButton(Dialog.BUTTON_NEUTRAL, "Ok", new Dialog.OnClickListener() {
        boolean pop_change = false;
        private boolean pop_change_category = false;

        public void onClick(DialogInterface dialog, int which) {
            if (ord_rct.isChecked()) {
                pop_change = true;
                order = Order.DATE;
            } else if (ord_abc.isChecked()) {
                pop_change = true;
                order = Order.NAME;
            } else if (ord_rat.isChecked()) {
                pop_change = true;
                order = Order.RATING;
            } else if (ord_dwn.isChecked()) {
                pop_change = true;
                order = Order.DOWNLOADS;
            } else if (ord_price.isChecked()) {
                pop_change = true;
                order = Order.PRICE;
            }

            if (btn1.isChecked()) {
                pop_change = true;
                pop_change_category = true;
                editor.putBoolean("orderByCategory", true);
            } else if (btn2.isChecked()) {
                pop_change = true;
                pop_change_category = true;
                editor.putBoolean("orderByCategory", false);
            }
            if (adult.isChecked()) {
                pop_change = true;
                editor.putBoolean("matureChkBox", false);
            } else {
                editor.putBoolean("matureChkBox", true);
            }
            if (pop_change) {
                editor.putInt("order_list", order.ordinal());
                editor.commit();
                if (pop_change_category) {

                    if (!depth.equals(ListDepth.CATEGORY1) && !depth.equals(ListDepth.STORES)) {
                        if (depth.equals(ListDepth.APPLICATIONS)) {
                            removeLastBreadCrumb();
                        }
                        removeLastBreadCrumb();
                        depth = ListDepth.CATEGORY1;
                    }

                }
                redrawAll();
                refreshAvailableList(true);
            }
        }
    });

    if (sPref.getBoolean("orderByCategory", false)) {
        btn1.setChecked(true);
    } else {
        btn2.setChecked(true);
    }
    if (!ApplicationAptoide.MATURECONTENTSWITCH) {
        adult.setVisibility(View.GONE);
        view.findViewById(R.id.dialog_adult_content_label).setVisibility(View.GONE);
    }
    adult.setChecked(!sPref.getBoolean("matureChkBox", false));
    // adult.setOnCheckedChangeListener(adultCheckedListener);
    switch (order) {
    case DATE:
        ord_rct.setChecked(true);
        break;
    case DOWNLOADS:
        ord_dwn.setChecked(true);
        break;
    case NAME:
        ord_abc.setChecked(true);
        break;
    case RATING:
        ord_rat.setChecked(true);
        break;
    case PRICE:
        ord_price.setChecked(true);
        break;

    default:
        break;
    }

    orderDialog.show();

}

From source file:com.updetector.MainActivity.java

/**
* Handle Performance Tuning Click//from   w  w  w .ja va2s  . c  o m
*/
private void handleAdvancedSetting() {
    final Dialog dialog = new Dialog(this);
    dialog.setTitle(R.string.menu_item_advanced_settings);
    dialog.setContentView(R.layout.advanced_setting);

    final SharedPreferences mPrefs = getSharedPreferences(Constants.SHARED_PREFERENCES, Context.MODE_PRIVATE);
    final Editor editor = mPrefs.edit();

    final ToggleButton classifierForCIVOnButton = (ToggleButton) dialog.findViewById(R.id.civ_classifier_on);
    classifierForCIVOnButton.setChecked(mPrefs.getBoolean(Constants.PREFERENCE_KEY_CIV_CLASSIFIER_ON, false));

    final ToggleButton isOutdoorButton = (ToggleButton) dialog.findViewById(R.id.is_outdoor);
    isOutdoorButton.setChecked(mPrefs.getBoolean(Constants.PREFERENCE_KEY_IS_OUTDOOR, false));

    final EditText notificationTresholdText = (EditText) dialog.findViewById(R.id.notification_threshold);
    notificationTresholdText
            .setText(String.format("%.2f", mPrefs.getFloat(Constants.PREFERENCE_KEY_NOTIFICATION_THRESHOLD,
                    (float) Constants.DEFAULT_DETECTION_THRESHOLD)));

    //final EditText detectionIntervalText=(EditText)dialog.findViewById(R.id.detection_interval);
    //detectionIntervalText.setText(String.valueOf(mPrefs.getInt(Constants.PREFERENCE_KEY_DETECTION_INTERVAL, Constants.DETECTION_INTERVAL_DEFAULT_VALUE) ));

    final EditText googleActivityUpdateIntervalText = (EditText) dialog
            .findViewById(R.id.google_activity_update_interval);
    googleActivityUpdateIntervalText
            .setText(String.valueOf(mPrefs.getInt(Constants.PREFERENCE_KEY_GOOGLE_ACTIVITY_UPDATE_INTERVAL,
                    Constants.GOOGLE_ACTIVITY_UPDATE_INTERVAL_DEFAULT_VALUE)));

    //final ToggleButton useGoogleActivityInFusion=(ToggleButton)dialog.findViewById(R.id.use_google_for_motion_state_in_fusion);
    //useGoogleActivityInFusion.setChecked(mPrefs.getBoolean(Constants.PREFERENCE_KEY_USE_GOOGLE_ACTIVITY_IN_FUSION, false));

    final ToggleButton logAcclRawButton = (ToggleButton) dialog.findViewById(R.id.log_raw_switch);
    logAcclRawButton.setChecked(mPrefs.getBoolean(Constants.LOGGING_ACCL_RAW_SWITCH, false));

    final ToggleButton logGoogleActUpdatesButton = (ToggleButton) dialog
            .findViewById(R.id.log_google_updates_switch);
    logGoogleActUpdatesButton.setChecked(mPrefs.getBoolean(Constants.LOGGING_GOOGLE_ACTIVITY_UPDATE, false));

    final ToggleButton logDetectionButton = (ToggleButton) dialog.findViewById(R.id.log_report_switch);
    logDetectionButton.setChecked(mPrefs.getBoolean(Constants.LOGGING_DETECTION_SWITCH, false));

    final ToggleButton logErrorButton = (ToggleButton) dialog.findViewById(R.id.log_error_switch);
    logErrorButton.setChecked(mPrefs.getBoolean(Constants.LOGGING_ERROR_SWITCH, true));

    //final EditText deltaForConditionalProb=(EditText)dialog.findViewById(R.id.normal_dist_delta);
    //deltaForConditionalProb.setText(String.valueOf(mPrefs.getFloat(Constants.CIV_DELTA_CONDITIONAL_PROBABILITY, 2)) );      

    final Button applyButton = (Button) dialog.findViewById(R.id.performance_apply_button);
    final Button cancelButton = (Button) dialog.findViewById(R.id.peformance_cancel_button);
    applyButton.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(final View v) {
            if (classifierForCIVOnButton.isChecked())
                editor.putBoolean(Constants.PREFERENCE_KEY_CIV_CLASSIFIER_ON, true);
            else
                editor.putBoolean(Constants.PREFERENCE_KEY_CIV_CLASSIFIER_ON, false);

            if (isOutdoorButton.isChecked())
                editor.putBoolean(Constants.PREFERENCE_KEY_IS_OUTDOOR, true);
            else
                editor.putBoolean(Constants.PREFERENCE_KEY_IS_OUTDOOR, false);

            if (logAcclRawButton.isChecked())
                editor.putBoolean(Constants.LOGGING_ACCL_RAW_SWITCH, true);
            else
                editor.putBoolean(Constants.LOGGING_ACCL_RAW_SWITCH, false);

            if (logGoogleActUpdatesButton.isChecked())
                editor.putBoolean(Constants.LOGGING_GOOGLE_ACTIVITY_UPDATE, true);
            else
                editor.putBoolean(Constants.LOGGING_GOOGLE_ACTIVITY_UPDATE, false);

            if (logDetectionButton.isChecked())
                editor.putBoolean(Constants.LOGGING_DETECTION_SWITCH, true);
            else
                editor.putBoolean(Constants.LOGGING_DETECTION_SWITCH, false);

            if (logErrorButton.isChecked())
                editor.putBoolean(Constants.LOGGING_ERROR_SWITCH, true);
            else
                editor.putBoolean(Constants.LOGGING_ERROR_SWITCH, false);

            float notificationTreshold;
            try {
                notificationTreshold = Float.parseFloat(notificationTresholdText.getText().toString());
            } catch (Exception ex) {
                notificationTreshold = (float) Constants.DEFAULT_DETECTION_THRESHOLD;
            }
            editor.putFloat(Constants.PREFERENCE_KEY_NOTIFICATION_THRESHOLD, notificationTreshold);

            /*int detectionInterval;
            try{
               detectionInterval=Integer.parseInt(
             detectionIntervalText.getText().toString());
            }catch(Exception ex){
               detectionInterval=Constants.DETECTION_INTERVAL_DEFAULT_VALUE;
            }
            editor.putInt(Constants.PREFERENCE_KEY_DETECTION_INTERVAL, detectionInterval);*/

            /*if (useGoogleActivityInFusion.isChecked())
               editor.putBoolean(Constants.PREFERENCE_KEY_USE_GOOGLE_ACTIVITY_IN_FUSION, true);
            else
               editor.putBoolean(Constants.PREFERENCE_KEY_USE_GOOGLE_ACTIVITY_IN_FUSION, false);*/

            int googleActivityUpdateInterval;
            try {
                googleActivityUpdateInterval = Integer
                        .parseInt(googleActivityUpdateIntervalText.getText().toString());
            } catch (Exception ex) {
                googleActivityUpdateInterval = Constants.GOOGLE_ACTIVITY_UPDATE_INTERVAL_DEFAULT_VALUE;
            }
            editor.putInt(Constants.PREFERENCE_KEY_GOOGLE_ACTIVITY_UPDATE_INTERVAL,
                    googleActivityUpdateInterval);

            /*try{
               Float delta=Float.parseFloat(deltaForConditionalProb.getText().toString());
               editor.putFloat(Constants.CIV_DELTA_CONDITIONAL_PROBABILITY, delta);
            }catch(Exception ex){
               Toast.makeText(getApplicationContext(), "Input must be a float number", Toast.LENGTH_SHORT).show();
            }*/

            editor.commit();
            dialog.cancel();
        }
    });

    cancelButton.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(final View v) {
            dialog.cancel();
        }
    });
    dialog.show();
}