Search in sources :

Example 46 with Checkable

use of android.widget.Checkable in project android_frameworks_base by crdroidandroid.

the class AdapterHelper method fillView.

private static void fillView(BridgeContext context, View view, AdapterItem item, AdapterItem parentItem, LayoutlibCallback callback, ResourceReference adapterRef) {
    if (view instanceof ViewGroup) {
        ViewGroup group = (ViewGroup) view;
        final int count = group.getChildCount();
        for (int i = 0; i < count; i++) {
            fillView(context, group.getChildAt(i), item, parentItem, callback, adapterRef);
        }
    } else {
        int id = view.getId();
        if (id != 0) {
            ResourceReference resolvedRef = context.resolveId(id);
            if (resolvedRef != null) {
                int fullPosition = item.getFullPosition();
                int positionPerType = item.getPositionPerType();
                int fullParentPosition = parentItem != null ? parentItem.getFullPosition() : 0;
                int parentPositionPerType = parentItem != null ? parentItem.getPositionPerType() : 0;
                if (view instanceof TextView) {
                    TextView tv = (TextView) view;
                    Object value = callback.getAdapterItemValue(adapterRef, context.getViewKey(view), item.getDataBindingItem().getViewReference(), fullPosition, positionPerType, fullParentPosition, parentPositionPerType, resolvedRef, ViewAttribute.TEXT, tv.getText().toString());
                    if (value != null) {
                        if (value.getClass() != ViewAttribute.TEXT.getAttributeClass()) {
                            Bridge.getLog().error(LayoutLog.TAG_BROKEN, String.format("Wrong Adapter Item value class for TEXT. Expected String, got %s", value.getClass().getName()), null);
                        } else {
                            tv.setText((String) value);
                        }
                    }
                }
                if (view instanceof Checkable) {
                    Checkable cb = (Checkable) view;
                    Object value = callback.getAdapterItemValue(adapterRef, context.getViewKey(view), item.getDataBindingItem().getViewReference(), fullPosition, positionPerType, fullParentPosition, parentPositionPerType, resolvedRef, ViewAttribute.IS_CHECKED, cb.isChecked());
                    if (value != null) {
                        if (value.getClass() != ViewAttribute.IS_CHECKED.getAttributeClass()) {
                            Bridge.getLog().error(LayoutLog.TAG_BROKEN, String.format("Wrong Adapter Item value class for IS_CHECKED. Expected Boolean, got %s", value.getClass().getName()), null);
                        } else {
                            cb.setChecked((Boolean) value);
                        }
                    }
                }
                if (view instanceof ImageView) {
                    ImageView iv = (ImageView) view;
                    Object value = callback.getAdapterItemValue(adapterRef, context.getViewKey(view), item.getDataBindingItem().getViewReference(), fullPosition, positionPerType, fullParentPosition, parentPositionPerType, resolvedRef, ViewAttribute.SRC, iv.getDrawable());
                    if (value != null) {
                        if (value.getClass() != ViewAttribute.SRC.getAttributeClass()) {
                            Bridge.getLog().error(LayoutLog.TAG_BROKEN, String.format("Wrong Adapter Item value class for SRC. Expected Boolean, got %s", value.getClass().getName()), null);
                        } else {
                        // FIXME
                        }
                    }
                }
            }
        }
    }
}
Also used : ViewGroup(android.view.ViewGroup) TextView(android.widget.TextView) ResourceReference(com.android.ide.common.rendering.api.ResourceReference) Checkable(android.widget.Checkable) ImageView(android.widget.ImageView)

Example 47 with Checkable

use of android.widget.Checkable in project android_packages_apps_Settings by LineageOS.

the class CellDataPreference method onBindViewHolder.

@Override
public void onBindViewHolder(PreferenceViewHolder holder) {
    super.onBindViewHolder(holder);
    View switchView = holder.findViewById(android.R.id.switch_widget);
    switchView.setClickable(false);
    ((Checkable) switchView).setChecked(mChecked);
}
Also used : Checkable(android.widget.Checkable) View(android.view.View)

Example 48 with Checkable

use of android.widget.Checkable in project android_packages_apps_Settings by LineageOS.

the class UsbModeChooserActivity method inflateOption.

private void inflateOption(final int mode, boolean selected, LinearLayout container, final boolean disallowedByAdmin) {
    View v = mLayoutInflater.inflate(R.layout.restricted_radio_with_summary, container, false);
    TextView titleView = (TextView) v.findViewById(android.R.id.title);
    titleView.setText(getTitle(mode));
    TextView summaryView = (TextView) v.findViewById(android.R.id.summary);
    updateSummary(summaryView, mode);
    if (disallowedByAdmin) {
        if (mEnforcedAdmin != null) {
            setDisabledByAdmin(v, titleView, summaryView);
        } else {
            return;
        }
    }
    v.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            if (disallowedByAdmin && mEnforcedAdmin != null) {
                RestrictedLockUtils.sendShowAdminSupportDetailsIntent(UsbModeChooserActivity.this, mEnforcedAdmin);
                return;
            }
            if (!ActivityManager.isUserAMonkey()) {
                mBackend.setMode(mode);
            }
            mDialog.dismiss();
            finish();
        }
    });
    ((Checkable) v).setChecked(selected);
    container.addView(v);
}
Also used : OnClickListener(android.view.View.OnClickListener) TextView(android.widget.TextView) Checkable(android.widget.Checkable) View(android.view.View) TextView(android.widget.TextView)

Example 49 with Checkable

use of android.widget.Checkable in project EhViewer by seven332.

the class SwitchPreference method onBindView.

@SuppressWarnings("TryWithIdenticalCatches")
@Override
protected void onBindView(View view) {
    super.onBindView(view);
    View checkableView = view.findViewById(R.id.switchWidget);
    if (checkableView != null && checkableView instanceof Checkable) {
        if (checkableView instanceof SwitchCompat) {
            final SwitchCompat switchView = (SwitchCompat) checkableView;
            switchView.setOnCheckedChangeListener(null);
        }
        ((Checkable) checkableView).setChecked(isChecked());
        if (checkableView instanceof SwitchCompat) {
            final SwitchCompat switchView = (SwitchCompat) checkableView;
            switchView.setTextOn(mSwitchOn);
            switchView.setTextOff(mSwitchOff);
            switchView.setOnCheckedChangeListener(mListener);
        }
    }
    if (sSyncSummaryViewMethod != null) {
        try {
            sSyncSummaryViewMethod.invoke(this, view);
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        } catch (InvocationTargetException e) {
            e.printStackTrace();
        }
    }
}
Also used : Checkable(android.widget.Checkable) View(android.view.View) InvocationTargetException(java.lang.reflect.InvocationTargetException) SwitchCompat(android.support.v7.widget.SwitchCompat)

Example 50 with Checkable

use of android.widget.Checkable in project frostwire by frostwire.

the class AbstractListAdapter method initCheckBox.

/**
 * Sets up the behavior of a possible checkbox to check this item.
 * <p/>
 * Takes in consideration:
 * - Only so many views are created and reused by the ListView
 * - Setting the correct checked/unchecked value without triggering the onCheckedChanged event.
 *
 * @see #getChecked()
 */
protected void initCheckBox(View view, T item) {
    CheckBox checkbox = findView(view, R.id.view_selectable_list_item_checkbox);
    if (checkbox != null) {
        checkbox.setVisibility((checkboxesVisibility) ? View.VISIBLE : View.GONE);
        if (checkbox.getVisibility() == View.VISIBLE) {
            checkbox.setOnCheckedChangeListener(null);
            checkbox.setChecked(checked.contains(item));
            checkbox.setTag(item);
            checkbox.setOnCheckedChangeListener(checkboxOnCheckedChangeListener);
        }
    }
    if (view instanceof Checkable) {
        ((Checkable) view).setChecked(checked.contains(item));
    }
}
Also used : CheckBox(android.widget.CheckBox) Checkable(android.widget.Checkable)

Aggregations

Checkable (android.widget.Checkable)79 View (android.view.View)47 TextView (android.widget.TextView)18 ViewGroup (android.view.ViewGroup)9 OnClickListener (android.view.View.OnClickListener)7 ImageView (android.widget.ImageView)7 Switch (android.widget.Switch)7 ResourceReference (com.android.ide.common.rendering.api.ResourceReference)6 Resources (android.content.res.Resources)5 Paint (android.graphics.Paint)5 Point (android.graphics.Point)4 SuppressLint (android.annotation.SuppressLint)3 AdapterView (android.widget.AdapterView)3 CheckBox (android.widget.CheckBox)3 ListView (android.widget.ListView)3 Spinner (android.widget.Spinner)3 Map (java.util.Map)3 Switch (org.holoeverywhere.widget.Switch)3 SimpleArrayMap (android.support.v4.util.SimpleArrayMap)2 AlertDialog (android.support.v7.app.AlertDialog)2