Example usage for android.widget TableLayout setBackgroundColor

List of usage examples for android.widget TableLayout setBackgroundColor

Introduction

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

Prototype

@RemotableViewMethod
public void setBackgroundColor(@ColorInt int color) 

Source Link

Document

Sets the background color for this view.

Usage

From source file:com.google.adsensequickstart.DisplayInventoryFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

    ScrollView sv = new ScrollView(getActivity());
    TableLayout tl = new TableLayout(getActivity());
    tl.setBackgroundColor(Color.rgb(242, 239, 233));
    sv.addView(tl);//from w ww . j  a v  a  2s  . co  m

    if (displayInventoryController == null) {
        return sv;
    }
    Inventory inventory = displayInventoryController.getInventory();

    TableLayout.LayoutParams tableRowParams = new TableLayout.LayoutParams(LayoutParams.MATCH_PARENT,
            LayoutParams.WRAP_CONTENT);
    tableRowParams.setMargins(1, 1, 1, 1);

    TableRow.LayoutParams accountLayoutParams = new TableRow.LayoutParams(LayoutParams.MATCH_PARENT,
            LayoutParams.WRAP_CONTENT);
    accountLayoutParams.setMargins(2, 1, 2, 1);

    TableRow.LayoutParams adCLientLayoutParams = new TableRow.LayoutParams(LayoutParams.MATCH_PARENT,
            LayoutParams.WRAP_CONTENT);
    adCLientLayoutParams.setMargins(12, 1, 2, 1);

    TableRow.LayoutParams adUnitChannelLayoutParams = new TableRow.LayoutParams(LayoutParams.MATCH_PARENT,
            LayoutParams.WRAP_CONTENT);
    adUnitChannelLayoutParams.setMargins(24, 1, 2, 1);

    for (String accountId : inventory.getAccounts()) {
        TableRow trow = new TableRow(getActivity());
        tl.addView(trow);
        TextView tv = new TextView(getActivity());
        tv.setText(accountId);
        trow.addView(tv);
        tv.setLayoutParams(accountLayoutParams);

        for (String adClient : inventory.getAdClients(accountId)) {
            TableRow trow2 = new TableRow(getActivity());
            trow2.setBackgroundColor(Color.rgb(214, 204, 181));
            tl.addView(trow2);
            TextView tv2 = new TextView(getActivity());
            tv2.setText(adClient);
            trow2.addView(tv2);
            tv2.setLayoutParams(adCLientLayoutParams);
            for (String adUnit : inventory.getAdUnits(adClient)) {
                TableRow trow3 = new TableRow(getActivity());
                trow3.setBackgroundColor(Color.rgb(251, 145, 57));
                tl.addView(trow3);
                TextView tv3 = new TextView(getActivity());
                tv3.setText(adUnit);
                trow3.addView(tv3);
                tv3.setLayoutParams(adUnitChannelLayoutParams);
            }
            for (String customChannel : inventory.getCustomChannels(adClient)) {
                TableRow trow3 = new TableRow(getActivity());
                trow3.setBackgroundColor(Color.rgb(255, 195, 69));
                tl.addView(trow3);
                TextView tv3 = new TextView(getActivity());
                tv3.setText(customChannel);
                trow3.addView(tv3);
                tv3.setLayoutParams(adUnitChannelLayoutParams);
            }
        }
    }
    return sv;
}

From source file:com.example.jesse.barscan.BarcodeCaptureActivity.java

/**
 * onTap returns the tapped barcode result to the calling Activity.
 *///from  w  w  w  .j a v a  2  s.co m
public boolean onTap(float rawX, float rawY) {
    // Find tap point in preview frame coordinates.
    int[] location = new int[2];
    mGraphicOverlay.getLocationOnScreen(location);
    float x = (rawX - location[0]) / mGraphicOverlay.getWidthScaleFactor();
    float y = (rawY - location[1]) / mGraphicOverlay.getHeightScaleFactor();

    // Find the barcode whose center is closest to the tapped point.
    Barcode best = null;
    float bestDistance = Float.MAX_VALUE;
    for (BarcodeGraphic graphic : mGraphicOverlay.getGraphics()) {
        Barcode barcode = graphic.getBarcode();
        if (barcode.getBoundingBox().contains((int) x, (int) y)) {
            // Exact hit, no need to keep looking.
            best = barcode;
            break;
        }
        float dx = x - barcode.getBoundingBox().centerX();
        float dy = y - barcode.getBoundingBox().centerY();
        float distance = (dx * dx) + (dy * dy); // actually squared distance
        if (distance < bestDistance) {
            best = barcode;
            bestDistance = distance;
        }
    }

    if (best != null) {
        Intent data = new Intent();
        data.putExtra(BarcodeObject, best);
        setResult(CommonStatusCodes.SUCCESS, data);

        LayoutInflater inflater = getLayoutInflater();
        View layout = inflater.inflate(R.layout.barcode_toast,
                (ViewGroup) findViewById(R.id.custom_toast_container));

        Barcode barcode = data.getParcelableExtra(BarcodeCaptureActivity.BarcodeObject);
        //Barcode.DriverLicense dlBarcode = barcode.driverLicense;

        Barcode.DriverLicense sample = barcode.driverLicense;

        TextView name = (TextView) layout.findViewById(R.id.name);
        TextView address = (TextView) layout.findViewById(R.id.address);
        TextView cityStateZip = (TextView) layout.findViewById(R.id.cityStateZip);
        TextView gender = (TextView) layout.findViewById(R.id.gender);
        TextView dob = (TextView) layout.findViewById(R.id.dob);
        TableLayout tbl = (TableLayout) layout.findViewById(R.id.tableLayout);

        try {
            int age = DateDifference.generateAge(sample.birthDate);
            if (age < minAge)
                tbl.setBackgroundColor(Color.parseColor("#980517"));
            else
                tbl.setBackgroundColor(Color.parseColor("#617C17"));

        } catch (ParseException e) {
            e.printStackTrace();
        }

        String cityContent = new String(
                sample.addressCity + ", " + sample.addressState + " " + (sample.addressZip).substring(0, 5));

        address.setText(sample.addressStreet);
        cityStateZip.setText(cityContent);

        String genderString;
        if ((sample.gender).equals("1"))
            genderString = "Male";
        else if ((sample.gender).equals("2"))
            genderString = "Female";
        else
            genderString = "Other";

        gender.setText(genderString);

        dob.setText((sample.birthDate).substring(0, 2) + "/" + (sample.birthDate).substring(2, 4) + "/"
                + (sample.birthDate).substring(4, 8));

        String nameString = new String(sample.firstName + " " + sample.middleName + " " + sample.lastName);

        name.setText(nameString);

        Toast toast = new Toast(getApplicationContext());
        toast.setGravity(Gravity.CENTER_VERTICAL, 0, 0);
        toast.setDuration(Toast.LENGTH_LONG);
        toast.setView(layout);
        toast.show();

        Date today = Calendar.getInstance().getTime();
        String reportDate = df.format(today);
        SQLiteDatabase db = helper.getWritableDatabase();
        ContentValues row = new ContentValues();
        row.put("dateVar", reportDate);
        row.put("dobVar", sample.birthDate);
        row.put("zipVar", sample.addressZip);
        row.put("genderVar", genderString);
        db.insert("test", null, row);
        db.close();

        return true;
    }
    return false;
}