Search in sources :

Example 21 with TableLayout

use of android.widget.TableLayout in project sexytopo by richsmith.

the class ScrollingTable method onLayout2.

@SuppressLint("WrongCall")
protected void onLayout2(boolean changed, int l, int t, int r, int b) throws Exception {
    super.onLayout(changed, l, t, r, b);
    List<Integer> colWidths = new ArrayList<>();
    TableLayout header = findViewById(R.id.HeaderTable);
    TableLayout body = findViewById(R.id.BodyTable);
    if (header.getChildCount() == 0) {
        return;
    }
    for (int rownum = 0; rownum < body.getChildCount(); rownum++) {
        TableRow row = (TableRow) body.getChildAt(rownum);
        for (int cellnum = 0; cellnum < row.getChildCount(); cellnum++) {
            View cell = row.getChildAt(cellnum);
            Integer cellWidth = cell.getWidth();
            if (colWidths.size() <= cellnum) {
                colWidths.add(cellWidth);
            } else {
                Integer current = colWidths.get(cellnum);
                if (cellWidth > current) {
                    colWidths.remove(cellnum);
                    colWidths.add(cellnum, cellWidth);
                }
            }
        }
    }
    for (int rownum = 0; rownum < header.getChildCount(); rownum++) {
        TableRow row = (TableRow) header.getChildAt(rownum);
        for (int cellnum = 0; cellnum < row.getChildCount(); cellnum++) {
            View cell = row.getChildAt(cellnum);
            TableRow.LayoutParams params = (TableRow.LayoutParams) cell.getLayoutParams();
            params.width = colWidths.get(cellnum);
        }
    }
}
Also used : TableRow(android.widget.TableRow) ArrayList(java.util.ArrayList) TableLayout(android.widget.TableLayout) View(android.view.View) SuppressLint(android.annotation.SuppressLint) SuppressLint(android.annotation.SuppressLint)

Example 22 with TableLayout

use of android.widget.TableLayout in project smoke by textbrowser.

the class FireChannel method createSchedulers.

private void createSchedulers() {
    if (m_statusScheduler == null) {
        m_statusScheduler = Executors.newSingleThreadScheduledExecutor();
        m_statusScheduler.scheduleAtFixedRate(new Runnable() {

            @Override
            public void run() {
                try {
                    if (Kernel.getInstance().isConnected())
                        Kernel.getInstance().enqueueFireStatus(m_id, m_name);
                    if (m_context == null || m_context.get() == null)
                        return;
                    ((Activity) m_context.get()).runOnUiThread(new Runnable() {

                        @Override
                        public void run() {
                            if (m_view == null)
                                return;
                            TableLayout tableLayout = (TableLayout) m_view.findViewById(R.id.participants);
                            for (int i = tableLayout.getChildCount() - 1; i >= 0; i--) {
                                TableRow row = (TableRow) tableLayout.getChildAt(i);
                                if (row == null)
                                    continue;
                                TextView textView1 = (TextView) row.getChildAt(0);
                                if (textView1 == null) {
                                    tableLayout.removeView(row);
                                    continue;
                                }
                                if (textView1.getId() == -1)
                                    continue;
                                Participant participant = null;
                                try {
                                    participant = m_participants.get(textView1.getTag(R.id.participants).toString());
                                } catch (Exception exception) {
                                    participant = null;
                                }
                                if (participant == null || Math.abs(System.currentTimeMillis() - participant.m_timestamp) >= 2L * STATUS_INTERVAL) {
                                    try {
                                        m_participants.remove(textView1.getTag(R.id.participants).toString());
                                    } catch (Exception exception) {
                                    }
                                    tableLayout.removeView(row);
                                    StringBuilder stringBuilder = new StringBuilder();
                                    stringBuilder.append(textView1.getText().toString());
                                    stringBuilder.append(" has left ");
                                    stringBuilder.append(m_name);
                                    stringBuilder.append(".\n\n");
                                    SpannableStringBuilder spannable = new SpannableStringBuilder(stringBuilder);
                                    spannable.setSpan(new StyleSpan(android.graphics.Typeface.ITALIC), 0, spannable.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
                                    TextView textView2 = (TextView) m_view.findViewById(R.id.chat_messages);
                                    textView2.append("[");
                                    textView2.append(m_simpleDateFormat.format(new Date()));
                                    textView2.append("] ");
                                    textView2.append(spannable);
                                    scrollMessagesView();
                                }
                            }
                        }
                    });
                } catch (Exception exception) {
                }
            }
        }, 1500L, STATUS_INTERVAL, TimeUnit.MILLISECONDS);
    }
}
Also used : SpannableStringBuilder(android.text.SpannableStringBuilder) TableRow(android.widget.TableRow) StyleSpan(android.text.style.StyleSpan) TextView(android.widget.TextView) TableLayout(android.widget.TableLayout) SpannableStringBuilder(android.text.SpannableStringBuilder) Date(java.util.Date)

Example 23 with TableLayout

use of android.widget.TableLayout in project smoke by textbrowser.

the class FireChannel method populateParticipants.

private void populateParticipants() {
    if (m_view == null)
        return;
    final TableLayout tableLayout = (TableLayout) m_view.findViewById(R.id.participants);
    if (m_participants.isEmpty()) {
        tableLayout.removeAllViews();
        return;
    } else
        tableLayout.removeAllViews();
    ArrayList<Participant> arrayList = new ArrayList<>(m_participants.values());
    int i = 0;
    Collections.sort(arrayList, s_participantComparator);
    for (Participant participant : arrayList) {
        if (m_context == null || m_context.get() == null || participant == null)
            continue;
        TextView textView = new TextView(m_context.get());
        textView.setTag(R.id.participants, participant.m_id);
        textView.setText(participant.m_name.trim());
        TableRow row = new TableRow(m_context.get());
        row.addView(textView);
        tableLayout.addView(row, i);
        i += 1;
        if (m_id.equals(participant.m_id)) {
            textView.setBackgroundColor(Color.rgb(255, 183, 77));
            textView.setId(-1);
        } else
            textView.setId(0);
    }
    arrayList.clear();
}
Also used : TableRow(android.widget.TableRow) ArrayList(java.util.ArrayList) TextView(android.widget.TextView) TableLayout(android.widget.TableLayout)

Example 24 with TableLayout

use of android.widget.TableLayout in project Slide by ccrama.

the class CommentOverflow method formatTable.

private TableLayout formatTable(String text, String subreddit, OnClickListener click, OnLongClickListener longClick) {
    TableRow.LayoutParams rowParams = new TableRow.LayoutParams(TableRow.LayoutParams.WRAP_CONTENT, TableRow.LayoutParams.WRAP_CONTENT);
    Context context = getContext();
    TableLayout table = new TableLayout(context);
    TableLayout.LayoutParams params = new TableLayout.LayoutParams(TableLayout.LayoutParams.WRAP_CONTENT, TableLayout.LayoutParams.WRAP_CONTENT);
    table.setLayoutParams(params);
    final String tableStart = "<table>";
    final String tableEnd = "</table>";
    final String tableHeadStart = "<thead>";
    final String tableHeadEnd = "</thead>";
    final String tableRowStart = "<tr>";
    final String tableRowEnd = "</tr>";
    final String tableColumnStart = "<td>";
    final String tableColumnEnd = "</td>";
    final String tableColumnStartLeft = "<td align=\"left\">";
    final String tableColumnStartRight = "<td align=\"right\">";
    final String tableColumnStartCenter = "<td align=\"center\">";
    final String tableHeaderStart = "<th>";
    final String tableHeaderStartLeft = "<th align=\"left\">";
    final String tableHeaderStartRight = "<th align=\"right\">";
    final String tableHeaderStartCenter = "<th align=\"center\">";
    final String tableHeaderEnd = "</th>";
    int i = 0;
    int columnStart = 0;
    int columnEnd;
    int gravity = Gravity.START;
    boolean columnStarted = false;
    TableRow row = null;
    while (i < text.length()) {
        if (text.charAt(i) != '<') {
            // quick check otherwise it falls through to else
            i += 1;
        } else if (text.subSequence(i, i + tableStart.length()).toString().equals(tableStart)) {
            i += tableStart.length();
        } else if (text.subSequence(i, i + tableHeadStart.length()).toString().equals(tableHeadStart)) {
            i += tableHeadStart.length();
        } else if (text.subSequence(i, i + tableRowStart.length()).toString().equals(tableRowStart)) {
            row = new TableRow(context);
            row.setLayoutParams(rowParams);
            i += tableRowStart.length();
        } else if (text.subSequence(i, i + tableRowEnd.length()).toString().equals(tableRowEnd)) {
            table.addView(row);
            i += tableRowEnd.length();
        } else if (text.subSequence(i, i + tableEnd.length()).toString().equals(tableEnd)) {
            i += tableEnd.length();
        } else if (text.subSequence(i, i + tableHeadEnd.length()).toString().equals(tableHeadEnd)) {
            i += tableHeadEnd.length();
        } else if (!columnStarted && i + tableColumnStart.length() < text.length() && (text.subSequence(i, i + tableColumnStart.length()).toString().equals(tableColumnStart) || text.subSequence(i, i + tableHeaderStart.length()).toString().equals(tableHeaderStart))) {
            columnStarted = true;
            gravity = Gravity.START;
            i += tableColumnStart.length();
            columnStart = i;
        } else if (!columnStarted && i + tableColumnStartRight.length() < text.length() && (text.subSequence(i, i + tableColumnStartRight.length()).toString().equals(tableColumnStartRight) || text.subSequence(i, i + tableHeaderStartRight.length()).toString().equals(tableHeaderStartRight))) {
            columnStarted = true;
            gravity = Gravity.END;
            i += tableColumnStartRight.length();
            columnStart = i;
        } else if (!columnStarted && i + tableColumnStartCenter.length() < text.length() && (text.subSequence(i, i + tableColumnStartCenter.length()).toString().equals(tableColumnStartCenter) || text.subSequence(i, i + tableHeaderStartCenter.length()).toString().equals(tableHeaderStartCenter))) {
            columnStarted = true;
            gravity = Gravity.CENTER;
            i += tableColumnStartCenter.length();
            columnStart = i;
        } else if (!columnStarted && i + tableColumnStartLeft.length() < text.length() && (text.subSequence(i, i + tableColumnStartLeft.length()).toString().equals(tableColumnStartLeft) || text.subSequence(i, i + tableHeaderStartLeft.length()).toString().equals(tableHeaderStartLeft))) {
            columnStarted = true;
            gravity = Gravity.START;
            i += tableColumnStartLeft.length();
            columnStart = i;
        } else if (text.substring(i).startsWith("<td")) {
            // case for <td colspan="2"  align="left">
            // See last table in https://www.reddit.com/r/GlobalOffensive/comments/51s3r8/virtuspro_vs_vgcyberzen_sl_ileague_s2_finals/
            columnStarted = true;
            i += text.substring(i).indexOf(">") + 1;
            columnStart = i;
        } else if (text.subSequence(i, i + tableColumnEnd.length()).toString().equals(tableColumnEnd) || text.subSequence(i, i + tableHeaderEnd.length()).toString().equals(tableHeaderEnd)) {
            columnEnd = i;
            SpoilerRobotoTextView textView = new SpoilerRobotoTextView(context);
            textView.setTextHtml(text.subSequence(columnStart, columnEnd), subreddit);
            setStyle(textView, subreddit);
            textView.setLayoutParams(COLUMN_PARAMS);
            textView.setGravity(gravity);
            if (click != null)
                textView.setOnClickListener(click);
            if (longClick != null)
                textView.setOnLongClickListener(longClick);
            if (text.subSequence(i, i + tableHeaderEnd.length()).toString().equals(tableHeaderEnd)) {
                textView.setTypeface(null, Typeface.BOLD);
            }
            if (row != null) {
                row.addView(textView);
            }
            columnStart = 0;
            columnStarted = false;
            i += tableColumnEnd.length();
        } else {
            i += 1;
        }
    }
    return table;
}
Also used : Context(android.content.Context) SpoilerRobotoTextView(me.ccrama.redditslide.SpoilerRobotoTextView) TableRow(android.widget.TableRow) TableLayout(android.widget.TableLayout)

Example 25 with TableLayout

use of android.widget.TableLayout in project smoke by textbrowser.

the class Chat method populateParticipants.

private void populateParticipants() {
    ArrayList<ParticipantElement> arrayList = State.getInstance().participants();
    TableLayout tableLayout = (TableLayout) findViewById(R.id.participants);
    if (arrayList == null || arrayList.isEmpty()) {
        tableLayout.removeAllViews();
        return;
    }
    tableLayout.removeAllViews();
    StringBuilder stringBuilder = new StringBuilder();
    boolean showDetails = m_databaseHelper.readSetting(null, "show_chat_details").equals("true");
    boolean showIcons = m_databaseHelper.readSetting(null, "show_chat_icons").equals("true");
    boolean state = Kernel.getInstance().isConnected();
    int i = 0;
    for (ParticipantElement participantElement : arrayList) {
        if (participantElement == null)
            continue;
        Switch switch1 = new Switch(Chat.this);
        final int oid = participantElement.m_oid;
        if (showIcons) {
            if (participantElement.m_keyStream == null || participantElement.m_keyStream.length != Cryptography.CIPHER_HASH_KEYS_LENGTH)
                switch1.setCompoundDrawablesWithIntrinsicBounds(R.drawable.chat_faulty_session, 0, 0, 0);
            else if (Math.abs(System.currentTimeMillis() - participantElement.m_lastStatusTimestamp) > STATUS_WINDOW || !state)
                switch1.setCompoundDrawablesWithIntrinsicBounds(R.drawable.chat_status_offline, 0, 0, 0);
            else
                switch1.setCompoundDrawablesWithIntrinsicBounds(R.drawable.chat_status_online, 0, 0, 0);
            switch1.setCompoundDrawablePadding(SWITCH_ICON_PADDING);
        }
        registerForContextMenu(switch1);
        switch1.setChecked(State.getInstance().chatCheckBoxIsSelected(oid));
        switch1.setId(participantElement.m_oid);
        switch1.setLayoutDirection(LayoutDirection.LTR);
        switch1.setLayoutParams(new TableRow.LayoutParams(0, LayoutParams.WRAP_CONTENT, 1));
        switch1.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {

            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                State.getInstance().setChatCheckBoxSelected(buttonView.getId(), isChecked);
                Button button1 = (Button) findViewById(R.id.call);
                Button button2 = (Button) findViewById(R.id.send_chat_message);
                if (Kernel.getInstance().availableNeighbors() > 0 && State.getInstance().chatCheckedParticipants() > 0) {
                    button1.setEnabled(Kernel.getInstance().isConnected());
                    button2.setBackgroundResource(R.drawable.send);
                    button2.setEnabled(true);
                } else {
                    button1.setEnabled(false);
                    button2.setBackgroundResource(R.drawable.warning);
                    button2.setEnabled(false);
                }
            }
        });
        stringBuilder.delete(0, stringBuilder.length());
        stringBuilder.append(participantElement.m_name.trim());
        if (showDetails) {
            stringBuilder.append("\n");
            stringBuilder.append(Miscellaneous.prepareSipHashId(participantElement.m_sipHashId));
            stringBuilder.append("\n");
            if (participantElement.m_keyStream == null || participantElement.m_keyStream.length == 0)
                stringBuilder.append("Session Closed");
            else if (participantElement.m_keyStream.length < Cryptography.CIPHER_HASH_KEYS_LENGTH)
                stringBuilder.append("Session Incomplete");
            else if (participantElement.m_keyStream.length == Cryptography.CIPHER_HASH_KEYS_LENGTH)
                stringBuilder.append("Session Ready");
            else
                stringBuilder.append("Session Faulty");
            if (participantElement.m_keyStream != null && participantElement.m_keyStream.length == Cryptography.CIPHER_HASH_KEYS_LENGTH) {
                stringBuilder.append("\n");
                long[] value = s_siphash.hmac(participantElement.m_keyStream, Cryptography.SIPHASH_OUTPUT_LENGTH);
                stringBuilder.append(Miscellaneous.byteArrayAsHexStringDelimited(Miscellaneous.longArrayToByteArray(value), '-', 4).toUpperCase());
            }
        }
        switch1.setTag(participantElement.m_sipHashId);
        switch1.setText(stringBuilder);
        switch1.setTextSize(CHECKBOX_TEXT_SIZE);
        TableRow row = new TableRow(Chat.this);
        row.addView(switch1);
        tableLayout.addView(row, i);
        i += 1;
    }
// Do not clear arrayList!
}
Also used : SpannableStringBuilder(android.text.SpannableStringBuilder) Switch(android.widget.Switch) Button(android.widget.Button) CompoundButton(android.widget.CompoundButton) TableRow(android.widget.TableRow) TableLayout(android.widget.TableLayout) CompoundButton(android.widget.CompoundButton)

Aggregations

TableLayout (android.widget.TableLayout)43 TextView (android.widget.TextView)36 TableRow (android.widget.TableRow)35 View (android.view.View)22 Button (android.widget.Button)10 SuppressLint (android.annotation.SuppressLint)6 SpannableStringBuilder (android.text.SpannableStringBuilder)5 LinearLayout (android.widget.LinearLayout)5 ScrollView (android.widget.ScrollView)5 Switch (android.widget.Switch)5 ArrayList (java.util.ArrayList)5 Context (android.content.Context)4 AdapterView (android.widget.AdapterView)4 CompoundButton (android.widget.CompoundButton)4 DialogInterface (android.content.DialogInterface)3 ImageView (android.widget.ImageView)3 NavigationView (android.support.design.widget.NavigationView)2 AlertDialog (android.support.v7.app.AlertDialog)2 StyleSpan (android.text.style.StyleSpan)2 LayoutInflater (android.view.LayoutInflater)2