Search in sources :

Example 31 with OnCheckedChangeListener

use of android.widget.CompoundButton.OnCheckedChangeListener in project android-app by spark.

the class SmartConfigFragment method setUpCustomKeyCheckbox.

private void setUpCustomKeyCheckbox() {
    final ImageView aesCbImage = Ui.findView(this, R.id.custom_aes_key_checkbox_image);
    customKeyCheckbox.setOnCheckedChangeListener(new OnCheckedChangeListener() {

        @Override
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            customKeyEntry.setVisibility((isChecked) ? View.VISIBLE : View.GONE);
            aesCbImage.setImageResource((isChecked) ? R.drawable.aes_checkbox_checked_temp : R.drawable.aes_checkbox_unchecked_temp);
            validateForm(buttonView.getId());
        }
    });
    View aesBoxParent = Ui.findView(this, R.id.aes_parent);
    aesBoxParent.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            customKeyCheckbox.toggle();
        }
    });
}
Also used : OnCheckedChangeListener(android.widget.CompoundButton.OnCheckedChangeListener) OnClickListener(android.view.View.OnClickListener) ImageView(android.widget.ImageView) ImageView(android.widget.ImageView) View(android.view.View) TextView(android.widget.TextView) CompoundButton(android.widget.CompoundButton)

Example 32 with OnCheckedChangeListener

use of android.widget.CompoundButton.OnCheckedChangeListener in project android_frameworks_base by crdroidandroid.

the class ZenModePanel method bind.

private void bind(final Condition condition, final View row, final int rowId) {
    if (condition == null)
        throw new IllegalArgumentException("condition must not be null");
    final boolean enabled = condition.state == Condition.STATE_TRUE;
    final ConditionTag tag = row.getTag() != null ? (ConditionTag) row.getTag() : new ConditionTag();
    row.setTag(tag);
    final boolean first = tag.rb == null;
    if (tag.rb == null) {
        tag.rb = (RadioButton) mZenRadioGroup.getChildAt(rowId);
    }
    tag.condition = condition;
    final Uri conditionId = getConditionId(tag.condition);
    if (DEBUG)
        Log.d(mTag, "bind i=" + mZenRadioGroupContent.indexOfChild(row) + " first=" + first + " condition=" + conditionId);
    tag.rb.setEnabled(enabled);
    tag.rb.setOnCheckedChangeListener(new OnCheckedChangeListener() {

        @Override
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            if (mExpanded && isChecked) {
                tag.rb.setChecked(true);
                if (DEBUG)
                    Log.d(mTag, "onCheckedChanged " + conditionId);
                MetricsLogger.action(mContext, MetricsEvent.QS_DND_CONDITION_SELECT);
                select(tag.condition);
                announceConditionSelection(tag);
            }
        }
    });
    if (tag.lines == null) {
        tag.lines = row.findViewById(android.R.id.content);
    }
    if (tag.line1 == null) {
        tag.line1 = (TextView) row.findViewById(android.R.id.text1);
        mSpTexts.add(tag.line1);
    }
    if (tag.line2 == null) {
        tag.line2 = (TextView) row.findViewById(android.R.id.text2);
        mSpTexts.add(tag.line2);
    }
    final String line1 = !TextUtils.isEmpty(condition.line1) ? condition.line1 : condition.summary;
    final String line2 = condition.line2;
    tag.line1.setText(line1);
    if (TextUtils.isEmpty(line2)) {
        tag.line2.setVisibility(GONE);
    } else {
        tag.line2.setVisibility(VISIBLE);
        tag.line2.setText(line2);
    }
    tag.lines.setEnabled(enabled);
    tag.lines.setAlpha(enabled ? 1 : .4f);
    final ImageView button1 = (ImageView) row.findViewById(android.R.id.button1);
    button1.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            onClickTimeButton(row, tag, false, /*down*/
            rowId);
        }
    });
    final ImageView button2 = (ImageView) row.findViewById(android.R.id.button2);
    button2.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            onClickTimeButton(row, tag, true, /*up*/
            rowId);
        }
    });
    tag.lines.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            tag.rb.setChecked(true);
        }
    });
    final long time = ZenModeConfig.tryParseCountdownConditionId(conditionId);
    if (rowId != COUNTDOWN_ALARM_CONDITION_INDEX && time > 0) {
        button1.setVisibility(VISIBLE);
        button2.setVisibility(VISIBLE);
        if (mBucketIndex > -1) {
            button1.setEnabled(mBucketIndex > 0);
            button2.setEnabled(mBucketIndex < MINUTE_BUCKETS.length - 1);
        } else {
            final long span = time - System.currentTimeMillis();
            button1.setEnabled(span > MIN_BUCKET_MINUTES * MINUTES_MS);
            final Condition maxCondition = ZenModeConfig.toTimeCondition(mContext, MAX_BUCKET_MINUTES, ActivityManager.getCurrentUser());
            button2.setEnabled(!Objects.equals(condition.summary, maxCondition.summary));
        }
        button1.setAlpha(button1.isEnabled() ? 1f : .5f);
        button2.setAlpha(button2.isEnabled() ? 1f : .5f);
    } else {
        button1.setVisibility(GONE);
        button2.setVisibility(GONE);
    }
    // wire up interaction callbacks for newly-added condition rows
    if (first) {
        Interaction.register(tag.rb, mInteractionCallback);
        Interaction.register(tag.lines, mInteractionCallback);
        Interaction.register(button1, mInteractionCallback);
        Interaction.register(button2, mInteractionCallback);
    }
    row.setVisibility(VISIBLE);
}
Also used : Condition(android.service.notification.Condition) OnCheckedChangeListener(android.widget.CompoundButton.OnCheckedChangeListener) Uri(android.net.Uri) ImageView(android.widget.ImageView) View(android.view.View) TextView(android.widget.TextView) ImageView(android.widget.ImageView) CompoundButton(android.widget.CompoundButton)

Example 33 with OnCheckedChangeListener

use of android.widget.CompoundButton.OnCheckedChangeListener in project android_frameworks_base by AOSPA.

the class InputMethodManagerService method showInputMethodMenu.

private void showInputMethodMenu(boolean showAuxSubtypes) {
    if (DEBUG)
        Slog.v(TAG, "Show switching menu. showAuxSubtypes=" + showAuxSubtypes);
    final Context context = mContext;
    final boolean isScreenLocked = isScreenLocked();
    final String lastInputMethodId = mSettings.getSelectedInputMethod();
    int lastInputMethodSubtypeId = mSettings.getSelectedInputMethodSubtypeId(lastInputMethodId);
    if (DEBUG)
        Slog.v(TAG, "Current IME: " + lastInputMethodId);
    synchronized (mMethodMap) {
        final HashMap<InputMethodInfo, List<InputMethodSubtype>> immis = mSettings.getExplicitlyOrImplicitlyEnabledInputMethodsAndSubtypeListLocked(mContext);
        if (immis == null || immis.size() == 0) {
            return;
        }
        hideInputMethodMenuLocked();
        final List<ImeSubtypeListItem> imList = mSwitchingController.getSortedInputMethodAndSubtypeListLocked(showAuxSubtypes, isScreenLocked);
        if (lastInputMethodSubtypeId == NOT_A_SUBTYPE_ID) {
            final InputMethodSubtype currentSubtype = getCurrentInputMethodSubtypeLocked();
            if (currentSubtype != null) {
                final InputMethodInfo currentImi = mMethodMap.get(mCurMethodId);
                lastInputMethodSubtypeId = InputMethodUtils.getSubtypeIdFromHashCode(currentImi, currentSubtype.hashCode());
            }
        }
        final int N = imList.size();
        mIms = new InputMethodInfo[N];
        mSubtypeIds = new int[N];
        int checkedItem = 0;
        for (int i = 0; i < N; ++i) {
            final ImeSubtypeListItem item = imList.get(i);
            mIms[i] = item.mImi;
            mSubtypeIds[i] = item.mSubtypeId;
            if (mIms[i].getId().equals(lastInputMethodId)) {
                int subtypeId = mSubtypeIds[i];
                if ((subtypeId == NOT_A_SUBTYPE_ID) || (lastInputMethodSubtypeId == NOT_A_SUBTYPE_ID && subtypeId == 0) || (subtypeId == lastInputMethodSubtypeId)) {
                    checkedItem = i;
                }
            }
        }
        final Context settingsContext = new ContextThemeWrapper(context, com.android.internal.R.style.Theme_DeviceDefault_Settings);
        mDialogBuilder = new AlertDialog.Builder(settingsContext);
        mDialogBuilder.setOnCancelListener(new OnCancelListener() {

            @Override
            public void onCancel(DialogInterface dialog) {
                hideInputMethodMenu();
            }
        });
        final Context dialogContext = mDialogBuilder.getContext();
        final TypedArray a = dialogContext.obtainStyledAttributes(null, com.android.internal.R.styleable.DialogPreference, com.android.internal.R.attr.alertDialogStyle, 0);
        final Drawable dialogIcon = a.getDrawable(com.android.internal.R.styleable.DialogPreference_dialogIcon);
        a.recycle();
        mDialogBuilder.setIcon(dialogIcon);
        final LayoutInflater inflater = dialogContext.getSystemService(LayoutInflater.class);
        final View tv = inflater.inflate(com.android.internal.R.layout.input_method_switch_dialog_title, null);
        mDialogBuilder.setCustomTitle(tv);
        // Setup layout for a toggle switch of the hardware keyboard
        mSwitchingDialogTitleView = tv;
        mSwitchingDialogTitleView.findViewById(com.android.internal.R.id.hard_keyboard_section).setVisibility(mWindowManagerInternal.isHardKeyboardAvailable() ? View.VISIBLE : View.GONE);
        final Switch hardKeySwitch = (Switch) mSwitchingDialogTitleView.findViewById(com.android.internal.R.id.hard_keyboard_switch);
        hardKeySwitch.setChecked(mShowImeWithHardKeyboard);
        hardKeySwitch.setOnCheckedChangeListener(new OnCheckedChangeListener() {

            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                mSettings.setShowImeWithHardKeyboard(isChecked);
                // Ensure that the input method dialog is dismissed when changing
                // the hardware keyboard state.
                hideInputMethodMenu();
            }
        });
        final ImeSubtypeListAdapter adapter = new ImeSubtypeListAdapter(dialogContext, com.android.internal.R.layout.input_method_switch_item, imList, checkedItem);
        final OnClickListener choiceListener = new OnClickListener() {

            @Override
            public void onClick(final DialogInterface dialog, final int which) {
                synchronized (mMethodMap) {
                    if (mIms == null || mIms.length <= which || mSubtypeIds == null || mSubtypeIds.length <= which) {
                        return;
                    }
                    final InputMethodInfo im = mIms[which];
                    int subtypeId = mSubtypeIds[which];
                    adapter.mCheckedItem = which;
                    adapter.notifyDataSetChanged();
                    hideInputMethodMenu();
                    if (im != null) {
                        if (subtypeId < 0 || subtypeId >= im.getSubtypeCount()) {
                            subtypeId = NOT_A_SUBTYPE_ID;
                        }
                        setInputMethodLocked(im.getId(), subtypeId);
                    }
                }
            }
        };
        mDialogBuilder.setSingleChoiceItems(adapter, checkedItem, choiceListener);
        mSwitchingDialog = mDialogBuilder.create();
        mSwitchingDialog.setCanceledOnTouchOutside(true);
        mSwitchingDialog.getWindow().setType(WindowManager.LayoutParams.TYPE_INPUT_METHOD_DIALOG);
        mSwitchingDialog.getWindow().getAttributes().privateFlags |= WindowManager.LayoutParams.PRIVATE_FLAG_SHOW_FOR_ALL_USERS;
        mSwitchingDialog.getWindow().getAttributes().setTitle("Select input method");
        updateSystemUi(mCurToken, mImeWindowVis, mBackDisposition);
        mSwitchingDialog.show();
    }
}
Also used : AlertDialog(android.app.AlertDialog) DialogInterface(android.content.DialogInterface) InputMethodInfo(android.view.inputmethod.InputMethodInfo) TypedArray(android.content.res.TypedArray) ArrayList(java.util.ArrayList) List(java.util.List) LocaleList(android.os.LocaleList) OnCancelListener(android.content.DialogInterface.OnCancelListener) IInputContext(com.android.internal.view.IInputContext) Context(android.content.Context) InputMethodSubtype(android.view.inputmethod.InputMethodSubtype) OnCheckedChangeListener(android.widget.CompoundButton.OnCheckedChangeListener) Drawable(android.graphics.drawable.Drawable) View(android.view.View) TextView(android.widget.TextView) ImeSubtypeListItem(com.android.internal.inputmethod.InputMethodSubtypeSwitchingController.ImeSubtypeListItem) ContextThemeWrapper(android.view.ContextThemeWrapper) Switch(android.widget.Switch) LayoutInflater(android.view.LayoutInflater) OnClickListener(android.content.DialogInterface.OnClickListener) CompoundButton(android.widget.CompoundButton)

Example 34 with OnCheckedChangeListener

use of android.widget.CompoundButton.OnCheckedChangeListener in project android_frameworks_base by DirtyUnicorns.

the class ZenModePanel method bind.

private void bind(final Condition condition, final View row, final int rowId) {
    if (condition == null)
        throw new IllegalArgumentException("condition must not be null");
    final boolean enabled = condition.state == Condition.STATE_TRUE;
    final ConditionTag tag = row.getTag() != null ? (ConditionTag) row.getTag() : new ConditionTag();
    row.setTag(tag);
    final boolean first = tag.rb == null;
    if (tag.rb == null) {
        tag.rb = (RadioButton) mZenRadioGroup.getChildAt(rowId);
    }
    tag.condition = condition;
    final Uri conditionId = getConditionId(tag.condition);
    if (DEBUG)
        Log.d(mTag, "bind i=" + mZenRadioGroupContent.indexOfChild(row) + " first=" + first + " condition=" + conditionId);
    tag.rb.setEnabled(enabled);
    tag.rb.setOnCheckedChangeListener(new OnCheckedChangeListener() {

        @Override
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            if (mExpanded && isChecked) {
                tag.rb.setChecked(true);
                if (DEBUG)
                    Log.d(mTag, "onCheckedChanged " + conditionId);
                MetricsLogger.action(mContext, MetricsEvent.QS_DND_CONDITION_SELECT);
                select(tag.condition);
                announceConditionSelection(tag);
            }
        }
    });
    if (tag.lines == null) {
        tag.lines = row.findViewById(android.R.id.content);
    }
    if (tag.line1 == null) {
        tag.line1 = (TextView) row.findViewById(android.R.id.text1);
        mSpTexts.add(tag.line1);
    }
    if (tag.line2 == null) {
        tag.line2 = (TextView) row.findViewById(android.R.id.text2);
        mSpTexts.add(tag.line2);
    }
    final String line1 = !TextUtils.isEmpty(condition.line1) ? condition.line1 : condition.summary;
    final String line2 = condition.line2;
    tag.line1.setText(line1);
    if (TextUtils.isEmpty(line2)) {
        tag.line2.setVisibility(GONE);
    } else {
        tag.line2.setVisibility(VISIBLE);
        tag.line2.setText(line2);
    }
    tag.lines.setEnabled(enabled);
    tag.lines.setAlpha(enabled ? 1 : .4f);
    final ImageView button1 = (ImageView) row.findViewById(android.R.id.button1);
    button1.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            onClickTimeButton(row, tag, false, /*down*/
            rowId);
        }
    });
    final ImageView button2 = (ImageView) row.findViewById(android.R.id.button2);
    button2.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            onClickTimeButton(row, tag, true, /*up*/
            rowId);
        }
    });
    tag.lines.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            tag.rb.setChecked(true);
        }
    });
    final long time = ZenModeConfig.tryParseCountdownConditionId(conditionId);
    if (rowId != COUNTDOWN_ALARM_CONDITION_INDEX && time > 0) {
        button1.setVisibility(VISIBLE);
        button2.setVisibility(VISIBLE);
        if (mBucketIndex > -1) {
            button1.setEnabled(mBucketIndex > 0);
            button2.setEnabled(mBucketIndex < MINUTE_BUCKETS.length - 1);
        } else {
            final long span = time - System.currentTimeMillis();
            button1.setEnabled(span > MIN_BUCKET_MINUTES * MINUTES_MS);
            final Condition maxCondition = ZenModeConfig.toTimeCondition(mContext, MAX_BUCKET_MINUTES, ActivityManager.getCurrentUser());
            button2.setEnabled(!Objects.equals(condition.summary, maxCondition.summary));
        }
        button1.setAlpha(button1.isEnabled() ? 1f : .5f);
        button2.setAlpha(button2.isEnabled() ? 1f : .5f);
    } else {
        button1.setVisibility(GONE);
        button2.setVisibility(GONE);
    }
    // wire up interaction callbacks for newly-added condition rows
    if (first) {
        Interaction.register(tag.rb, mInteractionCallback);
        Interaction.register(tag.lines, mInteractionCallback);
        Interaction.register(button1, mInteractionCallback);
        Interaction.register(button2, mInteractionCallback);
    }
    row.setVisibility(VISIBLE);
}
Also used : Condition(android.service.notification.Condition) OnCheckedChangeListener(android.widget.CompoundButton.OnCheckedChangeListener) Uri(android.net.Uri) ImageView(android.widget.ImageView) View(android.view.View) TextView(android.widget.TextView) ImageView(android.widget.ImageView) CompoundButton(android.widget.CompoundButton)

Example 35 with OnCheckedChangeListener

use of android.widget.CompoundButton.OnCheckedChangeListener in project gene-rate by Pixplicity.

the class Rate method showRatingSnackbar.

private void showRatingSnackbar() {
    // Wie is hier nou de snackbar?
    final Snackbar snackbar = Snackbar.make(mParentView, mMessage, mSnackBarSwipeToDismiss ? Snackbar.LENGTH_INDEFINITE : Snackbar.LENGTH_LONG);
    Snackbar.SnackbarLayout layout = (Snackbar.SnackbarLayout) snackbar.getView();
    // Hide default text
    TextView textView = layout.findViewById(android.support.design.R.id.snackbar_text);
    textView.setVisibility(View.INVISIBLE);
    // Inflate our custom view
    final LayoutInflater inflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    assert inflater != null;
    @SuppressLint("InflateParams") View snackView = inflater.inflate(R.layout.in_snackbar, null);
    // Configure the view
    TextView tvMessage = snackView.findViewById(R.id.text);
    tvMessage.setText(mMessage);
    final CheckBox cbNever = snackView.findViewById(R.id.cb_never);
    cbNever.setText(mTextNever);
    cbNever.setChecked(DEFAULT_CHECKED);
    final Button btFeedback = snackView.findViewById(R.id.bt_negative);
    btFeedback.setPaintFlags(btFeedback.getPaintFlags() | Paint.UNDERLINE_TEXT_FLAG);
    final Button btRate = snackView.findViewById(R.id.bt_positive);
    snackView.findViewById(R.id.tv_swipe).setVisibility(mSnackBarSwipeToDismiss ? View.VISIBLE : View.GONE);
    // Remember to not ask again if user swiped it
    snackbar.addCallback(new Snackbar.Callback() {

        @Override
        public void onDismissed(Snackbar transientBottomBar, @DismissEvent int event) {
            super.onDismissed(transientBottomBar, event);
            if (event == Snackbar.Callback.DISMISS_EVENT_SWIPE && cbNever.isChecked()) {
                saveAsked();
            }
            mFeedbackAction.onRequestDismissed(cbNever.isChecked());
        }
    });
    // Rate listener
    btRate.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            snackbar.dismiss();
            openPlayStore();
            saveAsked();
            mFeedbackAction.onRateTapped();
        }
    });
    // Feedback listener
    if (mFeedbackAction != null) {
        btFeedback.setText(mTextNegative);
        btFeedback.setVisibility(View.VISIBLE);
        btFeedback.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                if (cbNever.isChecked()) {
                    saveAsked();
                }
                snackbar.dismiss();
                mFeedbackAction.onFeedbackTapped();
            }
        });
    }
    // Checkbox listener
    cbNever.setOnCheckedChangeListener(new OnCheckedChangeListener() {

        @Override
        public void onCheckedChanged(CompoundButton button, boolean checked) {
            mPrefs.edit().putBoolean(KEY_BOOL_ASKED, checked).apply();
        }
    });
    // Add the view to the Snackbar's layout
    layout.addView(snackView, 0);
    // Show the Snackbar
    snackbar.show();
}
Also used : OnCheckedChangeListener(android.widget.CompoundButton.OnCheckedChangeListener) View(android.view.View) TextView(android.widget.TextView) SuppressLint(android.annotation.SuppressLint) Paint(android.graphics.Paint) Button(android.widget.Button) CompoundButton(android.widget.CompoundButton) CheckBox(android.widget.CheckBox) LayoutInflater(android.view.LayoutInflater) SuppressLint(android.annotation.SuppressLint) TextView(android.widget.TextView) CompoundButton(android.widget.CompoundButton) Snackbar(android.support.design.widget.Snackbar)

Aggregations

OnCheckedChangeListener (android.widget.CompoundButton.OnCheckedChangeListener)63 CompoundButton (android.widget.CompoundButton)62 View (android.view.View)47 TextView (android.widget.TextView)40 ImageView (android.widget.ImageView)25 OnClickListener (android.view.View.OnClickListener)17 DialogInterface (android.content.DialogInterface)13 AlertDialog (android.app.AlertDialog)12 Button (android.widget.Button)12 OnClickListener (android.content.DialogInterface.OnClickListener)11 Cursor (android.database.Cursor)9 CheckBox (android.widget.CheckBox)9 LayoutInflater (android.view.LayoutInflater)8 Context (android.content.Context)7 Intent (android.content.Intent)7 Paint (android.graphics.Paint)7 AdapterView (android.widget.AdapterView)7 OnCancelListener (android.content.DialogInterface.OnCancelListener)6 TypedArray (android.content.res.TypedArray)6 Drawable (android.graphics.drawable.Drawable)5