Java Code Examples for android.widget.LinearLayout.removeViews()

The following are Jave code examples for showing how to use removeViews() of the android.widget.LinearLayout class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: TextView_CustomEdit_CustomColor   File: ColorPickerPreference.java   View Source Code Vote up 7 votes
private void setPreviewColor() {
	if (mView == null) return;
	ImageView iView = new ImageView(getContext());
	LinearLayout widgetFrameView = ((LinearLayout)mView.findViewById(android.R.id.widget_frame));
	if (widgetFrameView == null) return;
	widgetFrameView.setVisibility(View.VISIBLE);
	widgetFrameView.setPadding(
		widgetFrameView.getPaddingLeft(),
		widgetFrameView.getPaddingTop(),
		(int)(mDensity * 8),
		widgetFrameView.getPaddingBottom()
	);
	// remove already create preview image
	int count = widgetFrameView.getChildCount();
	if (count > 0) {
		widgetFrameView.removeViews(0, count);
	}
	widgetFrameView.addView(iView);
	widgetFrameView.setMinimumWidth(0);
	iView.setBackgroundDrawable(new AlphaPatternDrawable((int)(5 * mDensity)));
	iView.setImageBitmap(getPreviewBitmap());
}
 
Example 2
Project: GravityBox   File: ColorPickerPreference.java   View Source Code Vote up 7 votes
private void setPreviewColor() {
	if (mView == null) return;
	ImageView iView = new ImageView(getContext());
	LinearLayout widgetFrameView = ((LinearLayout)mView.findViewById(android.R.id.widget_frame));
	if (widgetFrameView == null) return;
	widgetFrameView.setVisibility(View.VISIBLE);
	widgetFrameView.setPadding(
		widgetFrameView.getPaddingLeft(),
		widgetFrameView.getPaddingTop(),
		(int)(mDensity * 8),
		widgetFrameView.getPaddingBottom()
	);
	// remove already create preview image
	int count = widgetFrameView.getChildCount();
	if (count > 0) {
		widgetFrameView.removeViews(0, count);
	}
	widgetFrameView.addView(iView);
	widgetFrameView.setMinimumWidth(0);
	iView.setBackground(new AlphaPatternDrawable((int)(5 * mDensity)));
	iView.setImageBitmap(getPreviewBitmap());
}
 
Example 3
Project: buildAPKsApps   File: ListSettingsLayout.java   View Source Code Vote up 4 votes
public void updateLayout(Activity activity) {
	
	final LayoutInflater inflater = activity.getLayoutInflater();
	final ArrayList<Setting> settings = mApp.getSettings();
	final int settingCount = getSettingsCount(settings);
	final LinearLayout layout = mList;

	// Go through all settings and ensure they have corresponding 
	// views in the layout. Then remove not used views in such.
	
	for (int settingIndex = 0; settingIndex < settingCount; settingIndex++) {

		int layoutIndex = settingIndex << 1;
		View layoutView = layout.getChildCount() < layoutIndex ? null : layout.getChildAt(layoutIndex);

		Setting setting = settings.get(settingIndex + 1);
		View settingView = setting.getAssignedRenderer().getView(inflater, setting, null, activity);
		
		if (layoutView == null) {
			// we just need to append setting view

			safelyRemoveViewFromParent(layout, layoutIndex, settingView);

    		// add setting view
    		layout.addView(settingView);
    		
			// add delimiter if it is not the last setting
			ImageView delimiter = new ImageView(activity);
			delimiter.setImageResource(android.R.drawable.divider_horizontal_dim_dark);
			layout.addView(delimiter);
			settingView.setTag(delimiter);
			
		} else if (layoutView != settingView) {
			
			// we just need to remove current view and put setting view instead
			// replace view
			layout.removeView(layoutView);

    		// detach it from a parent if there is a parent
			safelyRemoveViewFromParent(layout, layoutIndex, settingView);
			
			layout.addView(settingView, layoutIndex); // add setting view
			settingView.setTag(layout.getChildAt(layoutIndex + 1)); // reuse delimiter
		} 
		// else - do nothing, this is same view
		
	}
	
	// if we have more views then settings, we have to remove redundant views
	final int layoutCount = layout.getChildCount();
	final int expectedCount = settingCount << 1;
	if (layoutCount > expectedCount) {
		layout.removeViews(expectedCount, layoutCount - expectedCount);
	}
}
 
Example 4
Project: microMathematics   File: FormulaTerm.java   View Source Code Vote up 4 votes
/**
 * Procedure deletes argument layout for given term and returns the previous term
 */
protected TermField deleteArgument(TermField owner, String sep, boolean storeUndoState)
{
    // target layout where terms will be deleted
    View expandable = owner.getLayout();
    if (expandable == null)
    {
        return null;
    }
    LinearLayout expandableLayout = (LinearLayout) expandable;

    // view index of the field within the parent layout
    int startIndex = ViewUtils.getViewIndex(expandableLayout, owner.getEditText());
    if (startIndex < 0)
    {
        return null;
    }

    // how much views shall be deleted:
    int count = 1;
    {
        final String termKey = getContext().getResources().getString(R.string.formula_arg_term_key);
        final boolean firstTerm = owner.getTermKey().equals(termKey + String.valueOf(1));
        if (firstTerm && startIndex + 1 < expandableLayout.getChildCount()
                && expandableLayout.getChildAt(startIndex + 1) instanceof CustomTextView)
        {
            final CustomTextView next = ((CustomTextView) expandableLayout.getChildAt(startIndex + 1));
            if (next.getText().toString().equals(sep))
            {
                count++;
            }
        }
        else if (!firstTerm && startIndex >= 1
                && expandableLayout.getChildAt(startIndex - 1) instanceof CustomTextView)
        {
            final CustomTextView prev = ((CustomTextView) expandableLayout.getChildAt(startIndex - 1));
            if (prev.getText().toString().equals(sep))
            {
                startIndex--;
                count++;
            }
        }
    }

    if (storeUndoState && parentField != null)
    {
        getFormulaList().getUndoState().addEntry(parentField.getState());
    }
    int prevIndex = terms.indexOf(owner);
    prevIndex--;
    terms.remove(owner);
    expandableLayout.removeViews(startIndex, count);
    reIndexTerms();

    return (prevIndex >= 0) ? terms.get(prevIndex) : null;
}