import android.widget.LinearLayout; //导入方法依赖的package包/类
/**
* 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;
}