Java Code Examples for android.widget.TableLayout#getChildAt()

The following examples show how to use android.widget.TableLayout#getChildAt() . 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: TableEntry.java    From Markwon with Apache License 2.0 6 votes vote down vote up
@NonNull
private TableRow ensureRow(@NonNull TableLayout layout, int row) {

    final int count = layout.getChildCount();

    // fill the requested views until we have added the `row` one
    if (row >= count) {

        final Context context = layout.getContext();

        int diff = row - count + 1;
        while (diff > 0) {
            layout.addView(new TableRow(context));
            diff -= 1;
        }
    }

    // return requested child (here it always should be the last one)
    return (TableRow) layout.getChildAt(row);
}
 
Example 2
Source File: ListItemExtensions.java    From Android-WYSIWYG-Editor with Apache License 2.0 6 votes vote down vote up
@Override
public Node getContent(View view) {
    Node node = getNodeInstance(view);
    node.childs = new ArrayList<>();
    TableLayout table = (TableLayout) view;
    int _rowCount = table.getChildCount();
    for (int j = 0; j < _rowCount; j++) {
        View row = table.getChildAt(j);
        Node node1 = getNodeInstance(row);
        EditText li = row.findViewById(R.id.txtText);
        EditorControl liTag = (EditorControl) li.getTag();
        node1.contentStyles = liTag.editorTextStyles;
        node1.content.add(Html.toHtml(li.getText()));
        node1.textSettings = liTag.textSettings;
        node1.content.add(Html.toHtml(li.getText()));
        node.childs.add(node1);
    }
    return node;
}
 
Example 3
Source File: ListItemExtensions.java    From Android-WYSIWYG-Editor with Apache License 2.0 6 votes vote down vote up
public void convertListToNormalText(TableLayout _table, int startIndex) {
    int tableChildCount = _table.getChildCount();
    for (int i = startIndex; i < tableChildCount; i++) {
        View _childRow = _table.getChildAt(i);
        _table.removeView(_childRow);
        String text = getTextFromListItem(_childRow);
        int Index = editorCore.getParentView().indexOfChild(_table);
        componentsWrapper.getInputExtensions().insertEditText(Index + 1, "", text);
        i -= 1;
        tableChildCount -= 1;
    }
    //if item is the last in the table, remove the table from parent

    if (_table.getChildCount() == 0) {
        editorCore.getParentView().removeView(_table);
    }
}
 
Example 4
Source File: ListItemExtensions.java    From Android-WYSIWYG-Editor with Apache License 2.0 6 votes vote down vote up
public CustomEditText setFocusToSpecific(CustomEditText customEditText) {
    TableRow tableRow = (TableRow) customEditText.getParent();
    TableLayout tableLayout = (TableLayout) tableRow.getParent();
    int indexOnTable = tableLayout.indexOfChild(tableRow);
    if (indexOnTable == 0) {
        //what if index is 0, get the previous on edittext
    }
    TableRow prevRow = (TableRow) tableLayout.getChildAt(indexOnTable - 1);
    if (prevRow != null) {
        CustomEditText editText = (CustomEditText) tableRow.findViewById(R.id.txtText);
        if (editText.requestFocus()) {
            editText.setSelection(editText.getText().length());
        }
        return editText;
    }
    return null;
}
 
Example 5
Source File: DisplayMnemonicActivity.java    From green_android with GNU General Public License v3.0 5 votes vote down vote up
private void setUpTable(final int id, final int startWordNum) {
    int wordNum = startWordNum;
    final TableLayout table = UI.find(this, id);

    for (int y = 0; y < table.getChildCount(); ++y) {
        final TableRow row = (TableRow) table.getChildAt(y);

        for (int x = 0; x < row.getChildCount() / 2; ++x) {
            ((TextView) row.getChildAt(x * 2)).setText(String.valueOf(wordNum));

            TextView me = (TextView) row.getChildAt(x * 2 + 1);
            me.setInputType(0);
            me.addTextChangedListener(new UI.TextWatcher() {
                @Override
                public void afterTextChanged(final Editable s) {
                    super.afterTextChanged(s);
                    final String original = s.toString();
                    final String trimmed = original.trim();
                    if (!trimmed.isEmpty() && !trimmed.equals(original)) {
                        me.setText(trimmed);
                    }
                }
            });
            registerForContextMenu(me);

            mTextViews[wordNum - 1] = me;
            ++wordNum;
        }
    }
}
 
Example 6
Source File: ListItemExtensions.java    From Android-WYSIWYG-Editor with Apache License 2.0 5 votes vote down vote up
public void convertListToOrdered(TableLayout _table) {
    EditorControl type = editorCore.createTag(EditorType.ol);
    _table.setTag(type);
    for (int i = 0; i < _table.getChildCount(); i++) {
        View _childRow = _table.getChildAt(i);
        CustomEditText editText = (CustomEditText) _childRow.findViewById(R.id.txtText);
        editText.setTag(editorCore.createTag(EditorType.OL_LI));
        _childRow.setTag(editorCore.createTag(EditorType.OL_LI));
        TextView _bullet = (TextView) _childRow.findViewById(R.id.lblOrder);
        _bullet.setText(String.valueOf(i + 1) + ".");
    }
}
 
Example 7
Source File: ListItemExtensions.java    From Android-WYSIWYG-Editor with Apache License 2.0 5 votes vote down vote up
public void convertListToUnordered(TableLayout _table) {
    EditorControl type = editorCore.createTag(EditorType.ul);
    _table.setTag(type);
    for (int i = 0; i < _table.getChildCount(); i++) {
        View _childRow = _table.getChildAt(i);
        CustomEditText _EditText = (CustomEditText) _childRow.findViewById(R.id.txtText);
        _EditText.setTag(editorCore.createTag(EditorType.UL_LI));
        _childRow.setTag(editorCore.createTag(EditorType.UL_LI));
        TextView _bullet = (TextView) _childRow.findViewById(R.id.lblOrder);
        _bullet.setText("•");
    }
}
 
Example 8
Source File: ListItemExtensions.java    From Android-WYSIWYG-Editor with Apache License 2.0 5 votes vote down vote up
private void rearrangeColumns(TableLayout _table) {
    //TODO, make sure that if OL, all the items are ordered numerically
    for (int i = 0; i < _table.getChildCount(); i++) {
        TableRow tableRow = (TableRow) _table.getChildAt(i);
        TextView _bullet = (TextView) tableRow.findViewById(R.id.lblOrder);
        _bullet.setText(String.valueOf(i + 1) + ".");
    }
}
 
Example 9
Source File: ListItemExtensions.java    From Android-WYSIWYG-Editor with Apache License 2.0 5 votes vote down vote up
public void validateAndRemoveLisNode(View view, EditorControl contentType) {
    /*
     *
     * If the person was on an active ul|li, move him to the previous node
     *
     */
    TableRow _row = (TableRow) view.getParent();
    TableLayout _table = (TableLayout) _row.getParent();
    int indexOnList = _table.indexOfChild(_row);
    _table.removeView(_row);
    if (indexOnList > 0) {
        /**
         * check if the index of the deleted row is <0, if so, move the focus to the previous li
         */
        TableRow focusrow = (TableRow) _table.getChildAt(indexOnList - 1);
        EditText text = (EditText) focusrow.findViewById(R.id.txtText);
        /**
         * Rearrange the nodes
         */
        if (contentType.Type == EditorType.OL_LI) {
            rearrangeColumns(_table);
        }
        if (text.requestFocus()) {
            text.setSelection(text.getText().length());
        }
    } else {
        /**
         * The removed row was first on the list. delete the list, and set the focus to previous element on the editor
         */
        editorCore.removeParent(_table);
    }
}
 
Example 10
Source File: ListItemExtensions.java    From Android-WYSIWYG-Editor with Apache License 2.0 5 votes vote down vote up
public void setFocusToList(View view, int position) {
    TableLayout tableLayout = (TableLayout) view;
    int count = tableLayout.getChildCount();
    if (tableLayout.getChildCount() > 0) {
        TableRow tableRow = (TableRow) tableLayout.getChildAt(position == POSITION_START ? 0 : count - 1);
        if (tableRow != null) {
            EditText editText = (EditText) tableRow.findViewById(R.id.txtText);
            if (editText.requestFocus()) {
                editText.setSelection(editText.getText().length());
            }
        }
    }
}
 
Example 11
Source File: KanjiSearchRadicalActivity.java    From aedict with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Computes currently selected radicals.
 */
private String getRadicals() {
	final StringBuilder sb = new StringBuilder();
	final TableLayout v = (TableLayout) findViewById(R.id.kanjisearchRadicals);
	for (int i = 0; i < v.getChildCount(); i++) {
		final TableRow tr = (TableRow) v.getChildAt(i);
		for (int j = 0; j < tr.getChildCount(); j++) {
			final PushButtonListener pbl = (PushButtonListener) tr.getChildAt(j).getTag();
			if (pbl != null && pbl.isPushed()) {
				sb.append(pbl.radical);
			}
		}
	}
	return sb.toString();
}
 
Example 12
Source File: MnemonicActivity.java    From green_android with GNU General Public License v3.0 4 votes vote down vote up
private void setUpTable(final int id, final int startWordNum) {
    int wordNum = startWordNum;
    final TableLayout table = UI.find(this, id);

    for (int y = 0; y < table.getChildCount(); ++y) {
        final TableRow row = (TableRow) table.getChildAt(y);

        for (int x = 0; x < row.getChildCount() / 2; ++x) {
            ((TextView) row.getChildAt(x * 2)).setText(String.valueOf(wordNum));

            MultiAutoCompleteTextView me = (MultiAutoCompleteTextView) row.getChildAt(x * 2 + 1);
            me.setAdapter(mWordsAdapter);
            me.setThreshold(3);
            me.setTokenizer(mTokenizer);
            me.setOnEditorActionListener(this);
            me.setOnKeyListener(this);
            me.addTextChangedListener(new UI.TextWatcher() {
                @Override
                public void afterTextChanged(final Editable s) {
                    super.afterTextChanged(s);
                    final String original = s.toString();
                    final String trimmed = original.trim();
                    if (!trimmed.isEmpty() && !trimmed.equals(original)) {
                        me.setText(trimmed);
                        return;
                    }
                    final boolean isInvalid = markInvalidWord(s);
                    if (!isInvalid && (s.length() > 3)) {
                        if (!enableLogin())
                            nextFocus();
                    }
                    enableLogin();
                }
            });
            me.setOnFocusChangeListener((View v, boolean hasFocus) -> {
                if (!hasFocus && v instanceof EditText) {
                    final Editable e = ((EditText)v).getEditableText();
                    final String word = e.toString();
                    if (!MnemonicHelper.mWords.contains(word)) {
                        e.setSpan(new StrikethroughSpan(), 0, word.length(), 0);
                    }
                }
            });
            registerForContextMenu(me);

            mWordEditTexts[wordNum - 1] = me;
            ++wordNum;
        }
    }
}
 
Example 13
Source File: MyDialog.java    From ExpandableRecyclerView with Apache License 2.0 4 votes vote down vote up
private ArrayList<String> checkInput(View table) {
    if (!(table instanceof TableLayout)) return null;
    ArrayList<String> result = new ArrayList<>();
    TableLayout tableLayout = (TableLayout) table;
    final int childCount = tableLayout.getChildCount();
    for (int i = 0; i < childCount; i++) {
        View tableChild = tableLayout.getChildAt(i);
        if (tableChild instanceof TableRow) {
            TableRow tableRow = (TableRow) tableChild;
            final int count = tableRow.getChildCount();
            for (int j = 0; j < count; j++) {
                View childView = tableRow.getChildAt(j);
                if (!(childView instanceof EditText)) continue;
                EditText editText = (EditText) childView;
                String type = editText.getHint().toString();
                String method = (String) editText.getTag();
                String input = editText.getText().toString().trim();
                if (TextUtils.isEmpty(input)) continue;
                String[] methods = input.split("\n");
                for (String m : methods) {
                    String methodType = "";
                    String[] args = m.split(",");
                    if (type.equals(PARENT_TYPE)) {
                        if (args.length == 1) {
                            methodType = ITEM_OPERATE_TYPE;
                        } else if (args.length == 2) {
                            methodType = ITEM_RANGE_OPERATE_TYPE;
                        }
                    } else if (type.equals(CHILD_TYPE)) {
                        if (args.length == 2) {
                            methodType = ITEM_OPERATE_TYPE;
                        } else if (args.length == 3) {
                            methodType = ITEM_RANGE_OPERATE_TYPE;
                        }
                    } else if (type.equals(MOVE_PARENT_TYPE)) {
                        if (args.length == 2) {
                            methodType = ITEM_OPERATE_TYPE;
                        }
                    } else if (type.equals(MOVE_CHILD_TYPE)) {
                        if (args.length == 4) {
                            methodType = ITEM_OPERATE_TYPE;
                        }
                    }
                    String methodName = String.format(method, methodType);
                    String ma = String.format(getString(R.string.methodAndArgs), methodName, m);
                    result.add(ma);
                }
            }
        }
    }
    Logger.e(TAG, "requestList=" + result.toString());
    return result;
}