Example usage for android.widget TableLayout addView

List of usage examples for android.widget TableLayout addView

Introduction

In this page you can find the example usage for android.widget TableLayout addView.

Prototype

@Override
public void addView(View child) 

Source Link

Usage

From source file:li.klass.fhem.adapter.devices.genericui.AvailableTargetStatesDialogUtil.java

public static <D extends FhemDevice<D>> TypeHandler<D> handlerForSelectedOption(D device, Context context,
        final String option, final TargetStateSelectedCallback callback) {

    SetList setList = device.getSetList();
    final SetListValue setListValue = setList.get(option);

    final DeviceStateRequiringAdditionalInformation specialDeviceState = DeviceStateRequiringAdditionalInformation
            .deviceStateForFHEM(option);

    if (setListValue instanceof SetListSliderValue) {
        final SetListSliderValue sliderValue = (SetListSliderValue) setListValue;
        return new TypeHandler<D>() {
            private int dimProgress = 0;

            @Override/*from  w  w w  .  java2s .  c  o  m*/
            public View getContentViewFor(Context context, D device) {
                TableLayout tableLayout = new TableLayout(context);
                int initialProgress = 0;
                if (device instanceof DimmableDevice) {
                    initialProgress = ((DimmableDevice) device).getDimPosition();
                }

                tableLayout.addView(new DeviceDimActionRowFullWidth<D>(initialProgress, sliderValue.getStart(),
                        sliderValue.getStep(), sliderValue.getStop(), null,
                        R.layout.device_detail_seekbarrow_full_width) {

                    @Override
                    public void onStopDim(Context context, D device, int progress) {
                        dimProgress = progress;
                    }

                    @Override
                    public String toDimUpdateText(D device, int progress) {
                        return null;
                    }
                }.createRow(LayoutInflater.from(context), device));
                return tableLayout;
            }

            @Override
            public boolean onPositiveButtonClick(View view, Context context, D device) {
                callback.onTargetStateSelected(option, "" + dimProgress, device, context);
                return true;
            }
        };
    } else if (setListValue instanceof SetListGroupValue) {
        final SetListGroupValue groupValue = (SetListGroupValue) setListValue;
        final List<String> groupStates = groupValue.getGroupStates();
        return new TypeHandler<D>() {

            @Override
            public View getContentViewFor(final Context context, final D device) {
                ListView listView = new ListView(context);
                listView.setAdapter(
                        new ArrayAdapter<>(context, android.R.layout.simple_list_item_1, groupStates));
                listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
                    @Override
                    public void onItemClick(AdapterView<?> adapterView, View view, int position, long id) {
                        String selection = groupStates.get(position);
                        callback.onTargetStateSelected(option, selection, device, context);
                        dialog.dismiss();
                    }
                });

                return listView;
            }

            @Override
            boolean requiresPositiveButton() {
                return false;
            }
        };
    } else if (specialDeviceState != null) {
        return new TypeHandler<D>() {

            private EditText editText;

            @Override
            public View getContentViewFor(Context context, D device) {
                editText = new EditText(context);
                return editText;
            }

            @Override
            public boolean onPositiveButtonClick(View view, Context context, D device) {
                Editable value = editText.getText();
                String text = value == null ? "" : value.toString();

                if (isValidAdditionalInformationValue(text, specialDeviceState)) {
                    callback.onTargetStateSelected(option, text, device, context);
                    return true;
                } else {
                    DialogUtil.showAlertDialog(context, R.string.error, R.string.invalidInput);
                    return false;
                }
            }
        };
    } else {
        callback.onTargetStateSelected(option, null, device, context);
        return null;
    }
}

From source file:Main.java

/**
 * Add button to the layout as the left one on a row.
 *
 * @param act     The running activity./*from   www .  j  a  va 2s  .co  m*/
 * @param table   The table of buttons.
 * @param lastRow The previous row of buttons.
 * @param actName Name of the activity.
 * @return The Button object that is constructed.
 */
private static Button addButtonAsFirst(Activity act, TableLayout table, TableRow lastRow, String actName) {

    /**
     * Create new row for the table.
     */
    TableRow newRow = new TableRow(act);
    newRow.setLayoutParams(lastRow.getLayoutParams());

    /**
     * Create both buttons. Set the second invisible.
     */
    Button old = (Button) lastRow.getChildAt(0);

    Button left = new Button(act);
    left.setText(actName);
    left.setLayoutParams(old.getLayoutParams());

    Button right = new Button(act);
    right.setText("TempButton");
    right.setLayoutParams(old.getLayoutParams());

    right.setVisibility(View.INVISIBLE);

    /**
     * Add them on.
     */
    newRow.addView(left);
    newRow.addView(right);

    table.addView(newRow);

    return left;
}

From source file:loonyb.in.posmachine.InvoiceFragment.java

public void updateInvoiceView(int position) {
    Context c = getActivity();//from  w  ww.j ava 2 s.  co m

    TableLayout table = (TableLayout) getActivity().findViewById(R.id.items);
    table.addView(itemsHeader());

    // TODO: load invoice from database
    Invoice invoice = Ipsum.Invoices[position];
    for (int i = 0; i < invoice.items.length; i++) {
        table.addView(invoice.items[i].buildRow(c, i));
    }
    mCurrentPosition = position;
}

From source file:com.jeffreyawest.weblogic.monitor.activity.display.DisplayClusterActivity.java

private View getServerTable(ClusterServer server) {

    TableLayout instanceTable = new TableLayout(DisplayClusterActivity.this);

    instanceTable.addView(getRow(R.string.server_name, server.getName()));
    instanceTable.addView(getRow(R.string.cluster_master, server.getClusterMaster()));
    instanceTable.addView(getRow(R.string.server_health,
            server.getHealth() == null ? getResources().getString(R.string.fragments_received)
                    : server.getHealth().toString()));
    instanceTable.addView(getRow(R.string.dropout_frequency, server.getDropOutFrequency()));
    instanceTable.addView(getRow(R.string.fragments_sent, server.getFragmentsSentCount()));
    instanceTable.addView(getRow(R.string.fragments_received, server.getFragmentsReceivedCount()));

    return instanceTable;
}

From source file:com.jeffreyawest.weblogic.monitor.activity.display.DisplayClusterActivity.java

@Override
public void updateDisplay(Cluster result) {
    setTitle(result.getName());//from  w  w w .ja va2  s .co m

    super.updateDisplay(result);
    FragmentManager fm = getSupportFragmentManager();

    ClusterServerHealthPieChart healthPieChart = (ClusterServerHealthPieChart) fm
            .findFragmentById(R.id.server_health_chart_fragment);

    if (healthPieChart != null)
        healthPieChart.update(result);

    ClusterServerStatePieChart statePieChart = (ClusterServerStatePieChart) fm
            .findFragmentById(R.id.server_state_chart_fragment);

    if (statePieChart != null)
        statePieChart.update(result);

    LinearLayout tableContainer = (LinearLayout) DisplayClusterActivity.this.findViewById(R.id.data_container);

    TableLayout summaryTable = new TableLayout(DisplayClusterActivity.this);
    tableContainer.addView(summaryTable);

    summaryTable.addView(getRow(R.string.cluster_name, result.getName()));

    for (ClusterServer server : result.getServers()) {
        tableContainer.addView(getSeparatorRow());
        tableContainer.addView(getServerTable(server));
    }
}

From source file:com.jeffreyawest.weblogic.monitor.activity.display.DisplayServerActivity.java

@Override
public void updateDisplay(Server server) {

    super.updateDisplay(server);

    StringBuilder sb = new StringBuilder();

    if (server.getClusterName() != null && !server.getClusterName().isEmpty()
            && !server.getClusterName().equals("null")) {

        sb.append(server.getClusterName()).append(".");
    }/* w w w  .  ja  va 2 s  .  co m*/

    sb.append(server.getName());
    sb.append(" (").append(server.getState()).append(")");

    setTitle(sb.toString());

    String clusterName = server.getClusterName();

    if (clusterName == null || clusterName.isEmpty() || "null".equals(clusterName)) {
        clusterName = getResources().getString(R.string.n_a);
    }

    String currentMachine = server.getCurrentMachine();

    if (currentMachine == null || currentMachine.isEmpty() || "null".equals(currentMachine)) {
        currentMachine = getResources().getString(R.string.n_a);
    }

    int heapMaxMB = server.getHeapSizeMax() / Constants.ONE_MB;
    int heapFreeMB = heapMaxMB - (server.getHeapSizeCurrent() / Constants.ONE_MB);

    int heapCurrentMB = server.getHeapSizeCurrent() / Constants.ONE_MB;
    int heapCurrentUsedMB = (server.getHeapSizeCurrent() - server.getHeapFreeCurrent()) / Constants.ONE_MB;
    int heapCurrentFreeMB = server.getHeapFreeCurrent() / Constants.ONE_MB;

    TableLayout summaryTable = (TableLayout) this.findViewById(R.id.display_entity_detail_table);

    summaryTable.addView(getRow(R.string.server_name, server.getName()));
    summaryTable.addView(getRow(R.string.server_state, String.valueOf(server.getState())));
    summaryTable.addView(getRow(R.string.server_health, String.valueOf(server.getHealth())));
    summaryTable.addView(getRow(R.string.cluster_name, clusterName));
    summaryTable.addView(getRow(R.string.current_machine, currentMachine));
    summaryTable.addView(getRow(R.string.wls_version, server.getWeblogicVersion()));
    summaryTable.addView(getRow(R.string.operating_system, server.getoSName() + " " + server.getoSVersion()));
    summaryTable.addView(getRow(R.string.os_version, server.getoSVersion()));
    summaryTable.addView(getRow(R.string.jvm_version, server.getJavaVersion()));
    summaryTable.addView(getRow(R.string.open_sockets, String.valueOf(server.getOpenSocketsCurrentCount())));

    summaryTable.addView(getRow(R.string.heap_max, String.valueOf(heapMaxMB) + " MB"));
    summaryTable.addView(getRow(R.string.heap_free, String.valueOf(heapFreeMB) + " MB"));

    summaryTable.addView(getRow(R.string.heap_current, String.valueOf(heapCurrentMB) + " MB"));
    summaryTable.addView(getRow(R.string.heap_allocated_used, String.valueOf(heapCurrentUsedMB) + " MB"));
    summaryTable.addView(getRow(R.string.heap_allocated_free, String.valueOf(heapCurrentFreeMB) + " MB"));

    FragmentManager fm = getSupportFragmentManager();

    JVMCPUPieChart cpuChart = (JVMCPUPieChart) fm.findFragmentById(R.id.cpu_chart_fragment);
    cpuChart.update(server);

    JVMHeapPieChart heapChart = (JVMHeapPieChart) fm.findFragmentById(R.id.heap_chart_fragment);
    heapChart.update(server);
}

From source file:com.jeffreyawest.weblogic.monitor.activity.display.DisplayApplicationActivity.java

@Override
public void updateDisplay(Application app) {

    super.updateDisplay(app);

    setTitle(app.getName() + " (" + app.getType() + ")");
    //app_target_state_chart_fragment

    FragmentManager fm = getSupportFragmentManager();

    ApplicationTargetStatePieChart targetStatePieChart = (ApplicationTargetStatePieChart) fm
            .findFragmentById(R.id.app_target_state_chart_fragment);
    targetStatePieChart.update(app);//from   ww w  . j  a  va2s. com

    LinearLayout tableContainer = (LinearLayout) DisplayApplicationActivity.this
            .findViewById(R.id.data_container);

    TextView header = new TextView(DisplayApplicationActivity.this);
    header.setTextSize(this.getResources().getDimension(R.dimen.entity_details_table_text_size));
    header.setText("Application Target States");

    TableLayout stateTable = new TableLayout(DisplayApplicationActivity.this);
    tableContainer.addView(stateTable);

    for (ApplicationTargetState state : app.getTargetStates()) {
        stateTable.addView(getRow(state.getTarget(), state.getState().toString()));
    }
}

From source file:com.jeffreyawest.weblogic.monitor.charting.DefaultPieChart.java

protected final void updateLegend(final String[] pNAME_list, final Integer[] pCOLORS, int pID) {
    TableLayout tl = (TableLayout) getActivity().findViewById(pID);

    if (tl != null) {
        tl.removeAllViews();//from   ww w . j a va 2s .  c  om
        for (int x = 0; x < pNAME_list.length; x++) {
            tl.addView(getRow(getActivity(), pCOLORS[x], pNAME_list[x]));
        }
    }
}

From source file:mx.udlap.is522.tedroid.activity.ScoresActivity.java

/**
 * Setea los valores de los objetos Score proporcionados o manda un mensaje si no hay datos.
 * // w  w w .j av  a2  s.c o m
 * @param scores objetos Score.
 */
private void setUpScores(List<Score> scores, TableLayout table) {
    if (scores != null && !scores.isEmpty()) {
        table.removeAllViews();
        table.addView(createHeaderRow());
        for (Score score : scores)
            table.addView(toTableRow(score));
    } else {
        table.removeAllViews();
        table.addView(emptyScoresRow());
    }
}

From source file:org.brandroid.openmanager.fragments.DialogHandler.java

private static void fillShortcutsTable(TableLayout table) {
    final Context context = table.getContext();
    for (int sc : MenuUtils.getMenuShortcuts(context)) {
        TableRow tr = new TableRow(context);
        TextView tv1 = new TextView(context);
        tv1.setGravity(Gravity.RIGHT);/*from w  w  w  . j  a  v  a  2 s . co  m*/
        tv1.setPadding(20, 0, 20, 0);
        char scc = (char) (sc + ('a' - KeyEvent.KEYCODE_A));
        tv1.setText("" + scc);
        TextView tv2 = new TextView(context);
        MenuItem item = MenuUtils.getMenuShortcut(sc);
        tv2.setText(item.getTitle());
        tr.addView(tv1);
        tr.addView(tv2);
        table.addView(tr);
    }
}