android.widget.Checkable Java Examples

The following examples show how to use android.widget.Checkable. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: SettingsUserFragment.java    From NGA-CLIENT-VER-OPEN-SOURCE with GNU General Public License v2.0 6 votes vote down vote up
@Override
public void onClick(View v) {

    int position = (int) v.getTag();

    if (v instanceof Checkable) {
        if (((Checkable) v).isChecked()) {
            setActiveUser(position);
        } else {
            ((Checkable) v).setChecked(true);
        }
    } else {
        showUserProfile(position);
    }

}
 
Example #2
Source File: ToggleButtonGroup.java    From ToggleButtonGroup with Apache License 2.0 6 votes vote down vote up
public void onChildViewAdded(View parent, View child) {
    if (parent == ToggleButtonGroup.this && child instanceof Checkable) {
        if (child.getId() == View.NO_ID) {
            child.setId(generateIdForView(child));
        }
        if (child instanceof ToggleButton) {
            setStateTracker((ToggleButton) child);
        } else if (child instanceof CompoundButton) {
            setStateTracker((CompoundButton) child);
        }
    }

    if (mOnHierarchyChangeListener != null) {
        mOnHierarchyChangeListener.onChildViewAdded(parent, child);
    }
}
 
Example #3
Source File: RadioGroup.java    From Carbon with Apache License 2.0 6 votes vote down vote up
@Override
public void addView(View child, int index, ViewGroup.LayoutParams params) {
    if (child instanceof Checkable) {
        final Checkable button = (Checkable) child;
        if (button.isChecked()) {
            mProtectFromCheckedChange = true;
            if (mCheckedId != -1) {
                setCheckedStateForView(mCheckedId, false);
            }
            mProtectFromCheckedChange = false;
            setCheckedId(child.getId());
        }
    }

    super.addView(child, index, params);
}
 
Example #4
Source File: AbsHListView.java    From Klyph with MIT License 6 votes vote down vote up
/**
 * Perform a quick, in-place update of the checked or activated state on all visible item views. This should only be called when
 * a valid choice mode is active.
 */
private void updateOnScreenCheckedViews() {
	final int firstPos = mFirstPosition;
	final int count = getChildCount();
	final boolean useActivated = android.os.Build.VERSION.SDK_INT >= 11;
	for ( int i = 0; i < count; i++ ) {
		final View child = getChildAt( i );
		final int position = firstPos + i;

		if ( child instanceof Checkable ) {
			( (Checkable) child ).setChecked( mCheckStates.get( position ) );
		} else if ( useActivated ) {
			child.setActivated( mCheckStates.get( position ) );
		}
	}
}
 
Example #5
Source File: NotificationSettingsFragment.java    From United4 with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
    View res = getView();
    if (res == null) return;
    boolean enabled = ((Checkable) res.findViewById(R.id.notifications_enabled)).isChecked();
    P.set("notifications", enabled ? "true" : "false");
    res.findViewById(R.id.notify_all).setEnabled(enabled);
    res.findViewById(R.id.notify_direct).setEnabled(enabled);
    res.findViewById(R.id.notify_direct_and_created).setEnabled(enabled);
    res.findViewById(R.id.hour).setEnabled(enabled);
    res.findViewById(R.id.half_day).setEnabled(enabled);
    res.findViewById(R.id.day).setEnabled(enabled);
    if (enabled && b) {
        notify_which_listener.onCheckedChanged(null, true);
        notify_duration_listener.onCheckedChanged(null, true);
    }
}
 
Example #6
Source File: DeleteView.java    From budget-envelopes with GNU General Public License v3.0 6 votes vote down vote up
public void setInnerView(View innerView) {
    if (mInnerView != null) {
        removeView(innerView);
    }
    mInnerView = innerView;
    addView(innerView);
    if (mInnerView instanceof Checkable) {
        ((Checkable)mInnerView).setChecked(mChecked);
    }
    if (mSwipeState == STATE_PRESSED) {
        cancelPressed();
        mSwipeState = STATE_READY;
    } else if (mSwipeState != STATE_READY) {
        cancelSwipe();
    }
}
 
Example #7
Source File: SingleSelectToggleGroup.java    From ToggleButtonGroup with Apache License 2.0 6 votes vote down vote up
@Override
public void addView(View child, int index, LayoutParams params) {
    if (child instanceof Checkable) {
        final Checkable checkable = (Checkable) child;
        if (checkable.isChecked()) {
            if (mCheckedId != -1) {
                setCheckedStateForView(mCheckedId, false);
            }
            if (child.getId() == View.NO_ID) {
                child.setId(generateIdForView(child));
            }
            setCheckedId(child.getId());
        }
        if (child instanceof MarkerButton) {
            ((MarkerButton) child).setRadioStyle(true);
        }
    }

    super.addView(child, index, params);
}
 
Example #8
Source File: AbsHListView.java    From letv with Apache License 2.0 6 votes vote down vote up
private void updateOnScreenCheckedViews() {
    boolean useActivated;
    int firstPos = this.mFirstPosition;
    int count = getChildCount();
    if (VERSION.SDK_INT >= 11) {
        useActivated = true;
    } else {
        useActivated = false;
    }
    for (int i = 0; i < count; i++) {
        View child = getChildAt(i);
        int position = firstPos + i;
        if (child instanceof Checkable) {
            ((Checkable) child).setChecked(((Boolean) this.mCheckStates.get(position, Boolean.valueOf(false))).booleanValue());
        } else if (useActivated) {
            child.setActivated(((Boolean) this.mCheckStates.get(position, Boolean.valueOf(false))).booleanValue());
        }
    }
}
 
Example #9
Source File: AdapterWrapper.java    From StickyListHeadersWithRefreshAndLoadMore with Apache License 2.0 6 votes vote down vote up
@Override
public WrapperView getView(int position, View convertView, ViewGroup parent) {
	WrapperView wv = (convertView == null) ? new WrapperView(mContext) : (WrapperView) convertView;
	View item = mDelegate.getView(position, wv.mItem, parent);
	View header = null;
	if (previousPositionHasSameHeader(position)) {
		recycleHeaderIfExists(wv);
	} else {
		header = configureHeader(wv, position);
	}
	if((item instanceof Checkable) && !(wv instanceof CheckableWrapperView)) {
		// Need to create Checkable subclass of WrapperView for ListView to work correctly
		wv = new CheckableWrapperView(mContext);
	} else if(!(item instanceof Checkable) && (wv instanceof CheckableWrapperView)) {
		wv = new WrapperView(mContext);
	}
	wv.update(item, header, mDivider, mDividerHeight);
	return wv;
}
 
Example #10
Source File: MediaStoreRecyclerAdapter.java    From libcommon with Apache License 2.0 5 votes vote down vote up
@Override
public void onClick(final View v) {
	if (DEBUG) Log.v(TAG, "onClick:" + v);
	if ((mRecycleView != null) && mRecycleView.isEnabled()) {
		if (v instanceof Checkable) {
			((Checkable)v).setChecked(true);
			mUIHandler.postDelayed(new Runnable() {
				@Override
				public void run() {
					((Checkable)v).setChecked(false);
				}
			}, 100);
		}
		if (mListener != null) {
			final MediaInfo info = (MediaInfo) v.getTag(R.id.info);
			if (DEBUG) Log.v(TAG, "onClick:info=" + info);
			if (info != null) {
				try {
					mListener.onItemClick(
						MediaStoreRecyclerAdapter.this, v, info);
				} catch (final Exception e) {
					Log.w(TAG, e);
				}
			} else if (DEBUG) {
				// ここにくるのはおかしい
				Log.d(TAG, "MediaInfo not attached!");
			}
		}
	} else {
		Log.w(TAG, "onClick:mRecycleView=" + mRecycleView);
	}
}
 
Example #11
Source File: CheckableRelativeLayout.java    From Android-Multiple-file-Selector-Dialog with MIT License 5 votes vote down vote up
/**
 * Add to our checkable list all the children of the view that implement the
 * interface Checkable
 */
private void findCheckableChildren(View v) {
    if (v instanceof Checkable) {
        this.checkableViews.add((Checkable) v);
    }

    if (v instanceof ViewGroup) {
        final ViewGroup vg = (ViewGroup) v;
        final int childCount = vg.getChildCount();
        for (int i = 0; i < childCount; ++i) {
            findCheckableChildren(vg.getChildAt(i));
        }
    }
}
 
Example #12
Source File: ReflectionNoValuesExtractor.java    From AndroidRipper with GNU Affero General Public License v3.0 5 votes vote down vote up
/**
 * Set Value of the Widget
 * 
 * @param v
 *            Widget
 * @param wd
 *            WidgetDescription instance
 */
protected void setValue(View v, WidgetDescription wd) {

	// Checkboxes, radio buttons and toggle buttons -> the value is the
	// checked state (true or false)
	if (v instanceof Checkable) {
		wd.setValue(String.valueOf(((Checkable) v).isChecked()));
	}

	// Textview, Editview et al. -> the value is the displayed text
	if (v instanceof TextView) {
		wd.setValue(((TextView) v).getText().toString());
		// wd.setValue("");
		return;
	}

	// Progress bars, seek bars and rating bars -> the value is the current
	// progress
	if (v instanceof ProgressBar) {
		//wd.setValue(String.valueOf(((ProgressBar) v).getProgress()));
		wd.setValue("");
	}

	if (v instanceof ImageView) {
		ImageView imgView = (ImageView) v;
		// TODO:
	}

}
 
Example #13
Source File: BookmarkRecyclerView.java    From AndroidChromium with Apache License 2.0 5 votes vote down vote up
@Override
public void onSelectionStateChange(List<BookmarkId> selectedBookmarks) {
    if (!mDelegate.getSelectionDelegate().isSelectionEnabled()) {
        for (int i = 0; i < getLayoutManager().getChildCount(); ++i) {
            View child = getLayoutManager().getChildAt(i);
            if (child instanceof Checkable) ((Checkable) child).setChecked(false);
        }
    }
}
 
Example #14
Source File: CheckableLinearLayout.java    From libcommon with Apache License 2.0 5 votes vote down vote up
@Override
	public void setChecked(final boolean checked) {
//		if (DEBUG) Log.v(TAG, "setChecked:" + checked);
		if (mChecked != checked) {
			mChecked = checked;
            final int n = this.getChildCount();
            View v;
            for (int i = 0; i < n; i++) {
            	v = this.getChildAt(i);
            	if (v instanceof Checkable)
            		((Checkable)v).setChecked(checked);
            }
            refreshDrawableState();
        }
	}
 
Example #15
Source File: CheckableRelativeLayout.java    From budget-envelopes with GNU General Public License v3.0 5 votes vote down vote up
public void setChecked(boolean checked) {
    if (mChecked != checked) {
        mChecked = checked;
        int s = getChildCount();
        for (int i = 0; i != s; ++i) {
            View v = getChildAt(i);
            if (v instanceof Checkable) {
                Checkable c = (Checkable)v;
                c.setChecked(mChecked);
            }
        }
        refreshDrawableState();
    }
}
 
Example #16
Source File: SwitchPreferenceEx.java    From document-viewer with GNU General Public License v3.0 5 votes vote down vote up
protected Checkable getCheckableView(final View view) {
    if (view instanceof Checkable) {
        return (Checkable) view;
    } else if (view instanceof ViewGroup) {
        final ViewGroup group = (ViewGroup) view;
        for (int i = 0; i < group.getChildCount(); i++) {
            final View v = group.getChildAt(i);
            if (v instanceof Checkable) {
                return (Checkable) v;
            }
        }
    }
    return null;
}
 
Example #17
Source File: DragSortItemViewCheckable.java    From onpc with GNU General Public License v3.0 5 votes vote down vote up
@Override
public boolean isChecked()
{
    View child = getChildAt(0);
    if (child instanceof Checkable)
        return ((Checkable) child).isChecked();
    else
        return false;
}
 
Example #18
Source File: JsonSwitchPreferenceEx.java    From document-viewer with GNU General Public License v3.0 5 votes vote down vote up
@Override
protected void onBindView(final View view) {

    final Checkable cview = getCheckableView(view);
    if (cview instanceof CompoundButton) {
        final CompoundButton btn = (CompoundButton) cview;
        btn.setOnCheckedChangeListener(mListener);
    }
    super.onBindView(view);
}
 
Example #19
Source File: MultiChoiceAdapterHelperBase.java    From MultiChoiceAdapter with Apache License 2.0 5 votes vote down vote up
public View getView(int position, View viewWithoutSelection) {
    if (viewWithoutSelection instanceof Checkable) {
        long handle = positionToSelectionHandle(position);
        boolean selected = isChecked(handle);
        ignoreCheckedListener = true;
        ((Checkable) viewWithoutSelection).setChecked(selected);
        ignoreCheckedListener = false;
    }
    if (itemIncludesCheckBox(viewWithoutSelection)) {
        initItemCheckbox(position, (ViewGroup) viewWithoutSelection);
    }
    return viewWithoutSelection;
}
 
Example #20
Source File: SwitchPreference.java    From MDPreference with Apache License 2.0 5 votes vote down vote up
@Override
protected void onBindView(View view) {
    super.onBindView(view);
    Checkable checkable = (Checkable) view.findViewById(R.id.checkable);
    checkable.setChecked(isChecked());
    syncSummaryView();
}
 
Example #21
Source File: RcvHolder.java    From FamilyChat with Apache License 2.0 5 votes vote down vote up
/**
 * 设置View是否可选
 */
public RcvHolder setChecked(int viewId, boolean checked)
{
    Checkable view = (Checkable) findView(viewId);
    view.setChecked(checked);
    return this;
}
 
Example #22
Source File: CheckableRelativeLayout.java    From AndrOBD with GNU General Public License v3.0 5 votes vote down vote up
public void setChecked(boolean isChecked)
{
	this.isChecked = isChecked;
	for (Checkable c : checkableViews)
	{
		c.setChecked(isChecked);
	}
}
 
Example #23
Source File: BasisViewHelper.java    From FastLib with Apache License 2.0 5 votes vote down vote up
public T setChecked(int viewId, boolean checked) {
    View view = getView(viewId);
    if (view instanceof Checkable) {
        ((Checkable) view).setChecked(checked);
    }
    return back();
}
 
Example #24
Source File: ItemSelectionSupport.java    From MultiView with Apache License 2.0 5 votes vote down vote up
@TargetApi(HONEYCOMB)
public void setViewChecked(View view, boolean checked) {
    if (view instanceof Checkable) {
        ((Checkable) view).setChecked(checked);
    } else if (Build.VERSION.SDK_INT >= HONEYCOMB) {
        view.setActivated(checked);
    }
}
 
Example #25
Source File: AdvancedAdapter.java    From SimpleDialogFragments with Apache License 2.0 5 votes vote down vote up
@Override
public View getView(int position, View convertView, ViewGroup parent) {

    // apply checked state
    if (convertView instanceof Checkable){
        ((Checkable) convertView).setChecked(isItemChecked(position));
        if (mNoAnimations){ // suppresses the check animation when filtering
            convertView.jumpDrawablesToCurrentState();
        }
    }

    return convertView;
}
 
Example #26
Source File: DragSortListView.java    From UltimateAndroid with Apache License 2.0 5 votes vote down vote up
@Override
public View getView(int position, View convertView, ViewGroup parent) {

    DragSortItemView v;
    View child;
    // Log.d("mobeta",
    // "getView: position="+position+" convertView="+convertView);
    if (convertView != null) {
        v = (DragSortItemView) convertView;
        View oldChild = v.getChildAt(0);

        child = mAdapter.getView(position, oldChild, DragSortListView.this);
        if (child != oldChild) {
            // shouldn't get here if user is reusing convertViews
            // properly
            if (oldChild != null) {
                v.removeViewAt(0);
            }
            v.addView(child);
        }
    } else {
        child = mAdapter.getView(position, null, DragSortListView.this);
        if (child instanceof Checkable) {
            v = new DragSortItemViewCheckable(getContext());
        } else {
            v = new DragSortItemView(getContext());
        }
        v.setLayoutParams(new LayoutParams(
                ViewGroup.LayoutParams.FILL_PARENT,
                ViewGroup.LayoutParams.WRAP_CONTENT));
        v.addView(child);
    }

    // Set the correct item height given drag state; passed
    // View needs to be measured if measurement is required.
    adjustItem(position + getHeaderViewsCount(), v, true);

    return v;
}
 
Example #27
Source File: SelectAnimatorDuration.java    From AnimatorDurationTile with Apache License 2.0 5 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.select_scale_dialog);
    float scale = AnimatorDurationScaler.getAnimatorScale(getContentResolver());
    ((Checkable) findViewById(getScaleItemId(scale))).setChecked(true);
}
 
Example #28
Source File: BoardSubListFragment.java    From NGA-CLIENT-VER-OPEN-SOURCE with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void onClick(final View v) {
    final SubBoard board = (SubBoard) v.getTag();
    if (v.getId() == R.id.check) {
        OnHttpCallBack<String> callBack = new OnHttpCallBack<String>() {
            @Override
            public void onError(String text) {
                showToast(text);
                ((Checkable) v).setChecked(board.isChecked());
            }

            @Override
            public void onSuccess(String data) {
                showToast(data);
                board.setChecked(v.isClickable());
                setResult(Activity.RESULT_OK);
            }
        };
        if (board.isChecked()) {
            mSubscribeTask.unsubscribe(board, callBack);
        } else {
            mSubscribeTask.subscribe(board, callBack);
        }
    } else {
        ARouter.getInstance()
                .build(ARouterConstants.ACTIVITY_TOPIC_LIST)
                .withString(ParamKey.KEY_TITLE, board.getName())
                .withInt(ParamKey.KEY_FID, board.getFid())
                .withInt(ParamKey.KEY_STID, board.getStid())
                .navigation(getContext());
    }
}
 
Example #29
Source File: MaterialButtonToggleGroupTest.java    From material-components-android with Apache License 2.0 5 votes vote down vote up
@Test
public void singleSelection_withSelectionRequired_doesNotUnSelect() {
  toggleGroup.setSelectionRequired(true);
  toggleGroup.setSingleSelection(true);

  View button = toggleGroup.getChildAt(0);
  button.performClick();
  button.performClick();

  assertThat(((Checkable) button).isChecked()).isTrue();
}
 
Example #30
Source File: RcvHolder.java    From RecyclerViewAdapter with Apache License 2.0 5 votes vote down vote up
/**
 * 设置View是否可选
 */
public RcvHolder setChecked(int viewId, boolean checked)
{
    Checkable view = (Checkable) findView(viewId);
    view.setChecked(checked);
    return this;
}