Search in sources :

Example 66 with OnCheckedChangeListener

use of android.widget.CompoundButton.OnCheckedChangeListener in project SharedPreferenceInspector by PrashamTrivedi.

the class SharedPreferencesItem method onItemClick.

/**
 * Callback method to be invoked when an item in this AdapterView has been clicked.
 * <p/>
 * Implementers can call getItemAtPosition(position) if they need to access the data associated with the selected item.
 *
 * @param parent
 * 		The AdapterView where the click happened.
 * @param view
 * 		The view within the AdapterView that was clicked (this will be a view provided by the adapter)
 * @param position
 * 		The position of the view in the adapter.
 * @param id
 * 		The row id of the item that was clicked.
 */
@Override
public void onItemClick(final AdapterView<?> parent, final View view, final int position, final long id) {
    String cancel = "Cancel";
    /**
     * Checks if entered in test mode. If not, clicking on preferences will prompt user to enter test mode first. If already entered in
     * test mode,
     * it will present the UI to change the value. Once it's changed, it will store original value
     */
    if (preferenceUtils.getBoolean(testModeOpened, false)) {
        final Pair<String, Object> keyValue = (Pair<String, Object>) parent.getItemAtPosition(position);
        Object second = keyValue.second;
        final String valueType = second.getClass().getSimpleName();
        AlertDialog.Builder builder = new Builder(getActivity());
        View editView = LayoutInflater.from(getActivity()).inflate(R.layout.edit_mode, null);
        final EditText et_value = (EditText) editView.findViewById(R.id.value);
        final SwitchCompat booleanSwitch = (SwitchCompat) editView.findViewById(R.id.switchBoolean);
        Spinner type = (Spinner) editView.findViewById(R.id.type);
        final String value = second.toString();
        et_value.setText(value);
        OnItemSelectedListener listener = new OnItemSelectedListener() {

            @Override
            public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
                if (typePosition != position) {
                    et_value.setText("");
                    typePosition = position;
                }
                booleanSwitch.setVisibility(View.GONE);
                et_value.setVisibility(View.VISIBLE);
                if (typePosition == SharedPreferenceUtils.SPINNER_STRING) {
                    et_value.setInputType(InputType.TYPE_CLASS_TEXT);
                } else if (typePosition == SharedPreferenceUtils.SPINNER_INT || typePosition == SharedPreferenceUtils.SPINNER_LONG) {
                    et_value.setInputType(InputType.TYPE_CLASS_NUMBER);
                } else if (typePosition == SharedPreferenceUtils.SPINNER_FLOAT) {
                    et_value.setInputType(InputType.TYPE_NUMBER_FLAG_DECIMAL);
                } else if (typePosition == SharedPreferenceUtils.SPINNER_BOOLEAN) {
                    et_value.setVisibility(View.GONE);
                    booleanSwitch.setVisibility(View.VISIBLE);
                    boolean isPreferenceTrue = !ConstantMethods.isEmptyString(value) && value.equalsIgnoreCase("true");
                    booleanSwitch.setText(isPreferenceTrue ? "true" : "false");
                    booleanSwitch.setChecked(isPreferenceTrue);
                    booleanSwitch.setOnCheckedChangeListener(new OnCheckedChangeListener() {

                        @Override
                        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                            buttonView.setText(isChecked ? "true" : "false");
                        }
                    });
                }
            }

            @Override
            public void onNothingSelected(AdapterView<?> parent) {
                typePosition = 0;
            }
        };
        type.setOnItemSelectedListener(listener);
        OnClickListener listener2 = new OnClickListener() {

            @Override
            public void onClick(DialogInterface dialog, int which) {
            // TODO: Hell nothing right now.
            }
        };
        OnClickListener clearListener = new OnClickListener() {

            @Override
            public void onClick(DialogInterface dialog, int which) {
                storeOriginal(keyValue);
                preferenceUtils.clear(keyValue.first);
                refreshKeyValues();
            }
        };
        if (valueType.equalsIgnoreCase(SharedPreferenceUtils.INT)) {
            typePosition = SharedPreferenceUtils.SPINNER_INT;
            type.setSelection(SharedPreferenceUtils.SPINNER_INT);
        } else if (valueType.equalsIgnoreCase(SharedPreferenceUtils.LONG)) {
            typePosition = SharedPreferenceUtils.SPINNER_LONG;
            type.setSelection(SharedPreferenceUtils.SPINNER_LONG);
        } else if (valueType.equalsIgnoreCase(SharedPreferenceUtils.FLOAT)) {
            typePosition = SharedPreferenceUtils.SPINNER_FLOAT;
            type.setSelection(SharedPreferenceUtils.SPINNER_FLOAT);
        } else if (valueType.equalsIgnoreCase(SharedPreferenceUtils.BOOLEAN)) {
            typePosition = SharedPreferenceUtils.SPINNER_BOOLEAN;
            type.setSelection(SharedPreferenceUtils.SPINNER_BOOLEAN);
        } else if (valueType.equalsIgnoreCase(SharedPreferenceUtils.STRING)) {
            typePosition = SharedPreferenceUtils.SPINNER_STRING;
            type.setSelection(SharedPreferenceUtils.SPINNER_STRING);
        }
        final AlertDialog dialog = builder.setTitle("Change Value").setView(editView).setPositiveButton("Set", null).setNegativeButton(cancel, listener2).setNeutralButton("Clear", clearListener).create();
        dialog.setOnShowListener(new DialogInterface.OnShowListener() {

            @Override
            public void onShow(DialogInterface dialog1) {
                Button b = dialog.getButton(AlertDialog.BUTTON_POSITIVE);
                b.setOnClickListener(new View.OnClickListener() {

                    @Override
                    public void onClick(View view) {
                        storeOriginal(keyValue);
                        Editable text = et_value.getText();
                        switch(typePosition) {
                            case SharedPreferenceUtils.SPINNER_STRING:
                                preferenceUtils.putString(keyValue.first, String.valueOf(text));
                                dialog.dismiss();
                                break;
                            case SharedPreferenceUtils.SPINNER_INT:
                                int number = SharedPreferenceUtils.getNumber(text);
                                preferenceUtils.putInt(keyValue.first, number);
                                dialog.dismiss();
                                break;
                            case SharedPreferenceUtils.SPINNER_LONG:
                                long numberLong = SharedPreferenceUtils.getNumberLong(text);
                                preferenceUtils.putLong(keyValue.first, numberLong);
                                dialog.dismiss();
                                break;
                            case SharedPreferenceUtils.SPINNER_BOOLEAN:
                                boolean value = booleanSwitch.isChecked();
                                preferenceUtils.putBoolean(keyValue.first, value);
                                dialog.dismiss();
                                break;
                            case SharedPreferenceUtils.SPINNER_FLOAT:
                                float numberFloat = SharedPreferenceUtils.getNumberFloat(text);
                                preferenceUtils.putFloat(keyValue.first, numberFloat);
                                dialog.dismiss();
                                break;
                        }
                        refreshKeyValues();
                    }
                });
            }
        });
        dialog.show();
    } else {
        AlertDialog.Builder builder = new Builder(getActivity());
        builder.setTitle("Test mode not enabled").setMessage("If you want to edit value for testing, testing mode should be enabled. It's available in options menu").setPositiveButton("Enable test mode", new OnClickListener() {

            @Override
            public void onClick(DialogInterface dialog, int which) {
                getActivity().supportInvalidateOptionsMenu();
                changeTestMode();
                onItemClick(parent, view, position, id);
            }
        }).setNegativeButton(cancel, new OnClickListener() {

            @Override
            public void onClick(DialogInterface dialog, int which) {
                dialog.dismiss();
                dialog.cancel();
            }
        }).show();
    }
}
Also used : AlertDialog(android.support.v7.app.AlertDialog) DialogInterface(android.content.DialogInterface) Spinner(android.widget.Spinner) Builder(android.support.v7.app.AlertDialog.Builder) Builder(android.support.v7.app.AlertDialog.Builder) Button(android.widget.Button) CompoundButton(android.widget.CompoundButton) Editable(android.text.Editable) Pair(android.support.v4.util.Pair) EditText(android.widget.EditText) OnCheckedChangeListener(android.widget.CompoundButton.OnCheckedChangeListener) SearchView(android.support.v7.widget.SearchView) View(android.view.View) AdapterView(android.widget.AdapterView) ListView(android.widget.ListView) OnItemSelectedListener(android.widget.AdapterView.OnItemSelectedListener) OnClickListener(android.content.DialogInterface.OnClickListener) AdapterView(android.widget.AdapterView) CompoundButton(android.widget.CompoundButton) SwitchCompat(android.support.v7.widget.SwitchCompat)

Example 67 with OnCheckedChangeListener

use of android.widget.CompoundButton.OnCheckedChangeListener in project platform_frameworks_base by android.

the class VectorDrawable01 method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    GridLayout container = new GridLayout(this);
    container.setColumnCount(5);
    container.setBackgroundColor(0xFF888888);
    final Button[] bArray = new Button[icon.length];
    CheckBox toggle = new CheckBox(this);
    toggle.setText("Toggle");
    toggle.setChecked(true);
    toggle.setOnCheckedChangeListener(new OnCheckedChangeListener() {

        @Override
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            ViewGroup vg = (ViewGroup) buttonView.getParent();
            for (int i = 0, count = vg.getChildCount(); i < count; i++) {
                View child = vg.getChildAt(i);
                if (child != buttonView) {
                    child.setEnabled(isChecked);
                }
            }
        }
    });
    container.addView(toggle);
    for (int i = 0; i < icon.length; i++) {
        Button button = new Button(this);
        bArray[i] = button;
        button.setWidth(200);
        button.setBackgroundResource(icon[i]);
        container.addView(button);
        VectorDrawable vd = (VectorDrawable) button.getBackground();
        vd.setAlpha((i + 1) * (0xFF / (icon.length + 1)));
    }
    setContentView(container);
}
Also used : GridLayout(android.widget.GridLayout) OnCheckedChangeListener(android.widget.CompoundButton.OnCheckedChangeListener) CompoundButton(android.widget.CompoundButton) Button(android.widget.Button) CheckBox(android.widget.CheckBox) ViewGroup(android.view.ViewGroup) View(android.view.View) CompoundButton(android.widget.CompoundButton) VectorDrawable(android.graphics.drawable.VectorDrawable)

Example 68 with OnCheckedChangeListener

use of android.widget.CompoundButton.OnCheckedChangeListener in project KISS by Neamar.

the class TogglesResult method display.

@SuppressWarnings({ "ResourceType", "deprecation" })
@Override
public View display(Context context, int position, View v) {
    // On first run, initialize handler
    if (togglesHandler == null)
        togglesHandler = new TogglesHandler(context);
    if (v == null)
        v = inflateFromId(context, R.layout.item_toggle);
    String togglePrefix = "<small><small>" + context.getString(R.string.toggles_prefix) + "</small></small>";
    TextView toggleName = (TextView) v.findViewById(R.id.item_toggle_name);
    toggleName.setText(TextUtils.concat(Html.fromHtml(togglePrefix), enrichText(togglePojo.displayName, context)));
    ImageView toggleIcon = (ImageView) v.findViewById(R.id.item_toggle_icon);
    toggleIcon.setImageDrawable(context.getResources().getDrawable(togglePojo.icon));
    toggleIcon.setColorFilter(getThemeFillColor(context), Mode.SRC_IN);
    // Use the handler to check or un-check button
    final CompoundButton toggleButton = (CompoundButton) v.findViewById(R.id.item_toggle_action_toggle);
    //set listener to null to avoid calling the listener of the older toggle item
    //(due to recycling)
    toggleButton.setOnCheckedChangeListener(null);
    Boolean state = togglesHandler.getState(togglePojo);
    if (state != null)
        toggleButton.setChecked(togglesHandler.getState(togglePojo));
    else
        toggleButton.setEnabled(false);
    toggleButton.setOnCheckedChangeListener(new OnCheckedChangeListener() {

        @Override
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            if (!togglesHandler.getState(togglePojo).equals(toggleButton.isChecked())) {
                // record launch manually
                recordLaunch(buttonView.getContext());
                togglesHandler.setState(togglePojo, toggleButton.isChecked());
                toggleButton.setEnabled(false);
                new AsyncTask<Void, Void, Void>() {

                    @Override
                    protected Void doInBackground(Void... params) {
                        try {
                            Thread.sleep(1500);
                        } catch (InterruptedException e) {
                            e.printStackTrace();
                        }
                        return null;
                    }

                    @Override
                    protected void onPostExecute(Void result) {
                        super.onPostExecute(result);
                        toggleButton.setEnabled(true);
                    }
                }.execute();
            }
        }
    });
    return v;
}
Also used : TogglesHandler(fr.neamar.kiss.toggles.TogglesHandler) OnCheckedChangeListener(android.widget.CompoundButton.OnCheckedChangeListener) AsyncTask(android.os.AsyncTask) TextView(android.widget.TextView) ImageView(android.widget.ImageView) CompoundButton(android.widget.CompoundButton)

Example 69 with OnCheckedChangeListener

use of android.widget.CompoundButton.OnCheckedChangeListener in project bitcoin-wallet by bitcoin-wallet.

the class RequestCoinsFragment method onCreateView.

@Override
public View onCreateView(final LayoutInflater inflater, final ViewGroup container, final Bundle savedInstanceState) {
    final View view = inflater.inflate(R.layout.request_coins_fragment, container, false);
    qrView = (ImageView) view.findViewById(R.id.request_coins_qr);
    final CardView qrCardView = (CardView) view.findViewById(R.id.request_coins_qr_card);
    qrCardView.setCardBackgroundColor(Color.WHITE);
    qrCardView.setPreventCornerOverlap(false);
    qrCardView.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(final View v) {
            BitmapFragment.show(getFragmentManager(), qrCodeBitmap.getBitmap());
        }
    });
    final CurrencyAmountView btcAmountView = (CurrencyAmountView) view.findViewById(R.id.request_coins_amount_btc);
    btcAmountView.setCurrencySymbol(config.getFormat().code());
    btcAmountView.setInputFormat(config.getMaxPrecisionFormat());
    btcAmountView.setHintFormat(config.getFormat());
    final CurrencyAmountView localAmountView = (CurrencyAmountView) view.findViewById(R.id.request_coins_amount_local);
    localAmountView.setInputFormat(Constants.LOCAL_FORMAT);
    localAmountView.setHintFormat(Constants.LOCAL_FORMAT);
    amountCalculatorLink = new CurrencyCalculatorLink(btcAmountView, localAmountView);
    acceptBluetoothPaymentView = (CheckBox) view.findViewById(R.id.request_coins_accept_bluetooth_payment);
    acceptBluetoothPaymentView.setVisibility(bluetoothAdapter != null ? View.VISIBLE : View.GONE);
    acceptBluetoothPaymentView.setChecked(bluetoothAdapter != null && bluetoothAdapter.isEnabled());
    acceptBluetoothPaymentView.setOnCheckedChangeListener(new OnCheckedChangeListener() {

        @Override
        public void onCheckedChanged(final CompoundButton buttonView, final boolean isChecked) {
            if (bluetoothAdapter != null && isChecked) {
                if (bluetoothAdapter.isEnabled()) {
                    maybeStartBluetoothListening();
                } else {
                    // ask for permission to enable bluetooth
                    startActivityForResult(new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE), REQUEST_CODE_ENABLE_BLUETOOTH);
                }
            } else {
                stopBluetoothListening();
            }
            updateView();
        }
    });
    initiateRequestView = (TextView) view.findViewById(R.id.request_coins_fragment_initiate_request);
    return view;
}
Also used : OnCheckedChangeListener(android.widget.CompoundButton.OnCheckedChangeListener) CardView(android.support.v7.widget.CardView) OnClickListener(android.view.View.OnClickListener) Intent(android.content.Intent) ImageView(android.widget.ImageView) View(android.view.View) CardView(android.support.v7.widget.CardView) TextView(android.widget.TextView) CompoundButton(android.widget.CompoundButton)

Example 70 with OnCheckedChangeListener

use of android.widget.CompoundButton.OnCheckedChangeListener in project vlc-android by videolan.

the class EqualizerFragment method fillViews.

private void fillViews() {
    context = getActivity();
    if (context == null)
        return;
    allSets.clear();
    allSets = new ArrayList<>();
    allSets.addAll(Arrays.asList(getEqualizerPresets()));
    presetCount = allSets.size();
    for (Map.Entry<String, ?> entry : PreferenceManager.getDefaultSharedPreferences(context).getAll().entrySet()) {
        if (entry.getKey().startsWith("custom_equalizer_")) {
            allSets.add(entry.getKey().replace("custom_equalizer_", "").replace("_", " "));
            customCount++;
        }
    }
    allSets.add(newPresetName);
    mEqualizer = VLCOptions.getEqualizerSetFromSettings(context, true);
    // on/off
    binding.equalizerButton.setChecked(VLCOptions.getEqualizerEnabledState(context));
    binding.equalizerButton.setOnCheckedChangeListener(new OnCheckedChangeListener() {

        @Override
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            if (mService != null)
                if (isChecked)
                    mService.setEqualizer(mEqualizer);
                else
                    mService.setEqualizer(null);
        }
    });
    binding.equalizerSave.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            createSaveCustomSetDialog(binding.equalizerPresets.getSelectedItemPosition(), true, false);
        }
    });
    binding.equalizerDelete.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            createDeleteCustomSetSnacker();
        }
    });
    binding.equalizerRevert.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            revertCustomSetChanges();
        }
    });
    // presets
    adapter = new ArrayAdapter<>(context, android.R.layout.simple_spinner_dropdown_item, allSets);
    binding.equalizerPresets.setAdapter(adapter);
    // Set the default selection asynchronously to prevent a layout initialization bug.
    binding.equalizerPresets.post(new Runnable() {

        @Override
        public void run() {
            binding.equalizerPresets.setOnItemSelectedListener(mSetListener);
            final int pos = allSets.indexOf(VLCOptions.getEqualizerNameFromSettings(context));
            mState.update(pos, VLCOptions.getEqualizerSavedState(context));
            updateAlreadyHandled = true;
            if (binding.equalizerButton.isChecked() || !mState.saved) {
                savePos = pos;
                revertPos = getEqualizerType(pos) == TYPE_CUSTOM ? pos : 0;
                binding.equalizerPresets.setSelection(pos);
            } else {
                updateEqualizer(0);
            }
        }
    });
    // preamp
    binding.equalizerPreamp.setMax(40);
    binding.equalizerPreamp.setProgress((int) mEqualizer.getPreAmp() + 20);
    binding.equalizerPreamp.setOnSeekBarChangeListener(mPreampListener);
    // bands
    for (int i = 0; i < BAND_COUNT; i++) {
        float band = MediaPlayer.Equalizer.getBandFrequency(i);
        EqualizerBar bar = new EqualizerBar(context, band);
        bar.setValue(mEqualizer.getAmp(i));
        bar.setListener(new BandListener(i));
        binding.equalizerBands.addView(bar);
        LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.MATCH_PARENT, 1);
        bar.setLayoutParams(params);
    }
}
Also used : OnCheckedChangeListener(android.widget.CompoundButton.OnCheckedChangeListener) LayoutParams(android.view.ViewGroup.LayoutParams) View(android.view.View) AdapterView(android.widget.AdapterView) EqualizerBar(org.videolan.vlc.gui.view.EqualizerBar) Map(java.util.Map) CompoundButton(android.widget.CompoundButton) LinearLayout(android.widget.LinearLayout)

Aggregations

OnCheckedChangeListener (android.widget.CompoundButton.OnCheckedChangeListener)101 CompoundButton (android.widget.CompoundButton)98 View (android.view.View)78 TextView (android.widget.TextView)66 ImageView (android.widget.ImageView)40 OnClickListener (android.view.View.OnClickListener)31 CheckBox (android.widget.CheckBox)30 DialogInterface (android.content.DialogInterface)27 AdapterView (android.widget.AdapterView)24 AlertDialog (android.app.AlertDialog)23 ListView (android.widget.ListView)20 Button (android.widget.Button)19 LayoutInflater (android.view.LayoutInflater)17 ArrayList (java.util.ArrayList)17 List (java.util.List)15 OnClickListener (android.content.DialogInterface.OnClickListener)12 SuppressLint (android.annotation.SuppressLint)11 Intent (android.content.Intent)11 ViewGroup (android.view.ViewGroup)10 Cursor (android.database.Cursor)9