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

The following examples show how to use android.widget.TableLayout#getChildCount() . 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: QuestionFragment.java    From android-galaxyzoo with GNU General Public License v3.0 6 votes vote down vote up
private static TableRow addRowToTable(final Activity activity, final TableLayout layoutAnswers) {
    final TableRow row = new TableRow(activity);

    final TableLayout.LayoutParams params =
            new TableLayout.LayoutParams(TableLayout.LayoutParams.MATCH_PARENT,
                    TableLayout.LayoutParams.MATCH_PARENT);

    //Add a top margin between this row and any row above it:
    if (layoutAnswers.getChildCount() > 0) {
        final int margin = UiUtils.getPxForDpResource(activity, R.dimen.tiny_gap);
        params.setMargins(0, margin, 0, 0);
    }

    layoutAnswers.addView(row, params);
    return row;
}
 
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 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 10
Source File: TDDStatsActivity.java    From AndroidAPS with GNU Affero General Public License v3.0 5 votes vote down vote up
private void cleanTable(TableLayout table) {
    int childCount = table.getChildCount();
    // Remove all rows except the first one
    if (childCount > 1) {
        table.removeViews(1, childCount - 1);
    }
}
 
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: InstallerFragment.java    From BusyBox with Apache License 2.0 4 votes vote down vote up
private void setProperties(ArrayList<FileMeta> properties) {
  this.properties = properties;

  if (properties == null) {
    propertiesCard.setVisibility(View.GONE);
    return;
  }
  if (propertiesCard.getVisibility() != View.VISIBLE) {
    propertiesCard.setVisibility(View.VISIBLE);
  }

  Analytics.EventBuilder analytics = Analytics.newEvent("busybox properties");
  for (FileMeta property : properties) {
    analytics.put(property.label, property.value);
  }
  analytics.log();

  TableLayout tableLayout = getViewById(R.id.table_properties);

  if (tableLayout.getChildCount() > 0) {
    tableLayout.removeAllViews();
  }

  int width = ResUtils.dpToPx(128);
  int left = ResUtils.dpToPx(16);
  int top = ResUtils.dpToPx(6);
  int bottom = ResUtils.dpToPx(6);

  int i = 0;
  for (FileMeta meta : properties) {
    TableRow tableRow = new TableRow(getActivity());
    TextView nameText = new TextView(getActivity());
    TextView valueText = new TextView(getActivity());

    if (i % 2 == 0) {
      tableRow.setBackgroundColor(0x0D000000);
    } else {
      tableRow.setBackgroundColor(Color.TRANSPARENT);
    }

    nameText.setLayoutParams(new TableRow.LayoutParams(width, ViewGroup.LayoutParams.WRAP_CONTENT));
    nameText.setPadding(left, top, 0, bottom);
    nameText.setAllCaps(true);
    nameText.setTypeface(Typeface.DEFAULT_BOLD);
    nameText.setText(meta.name);

    valueText.setPadding(left, top, 0, bottom);
    valueText.setText(meta.value);

    tableRow.addView(nameText);
    tableRow.addView(valueText);
    tableLayout.addView(tableRow);

    i++;
  }
}
 
Example 14
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;
}