Example usage for android.widget TableRow setOnClickListener

List of usage examples for android.widget TableRow setOnClickListener

Introduction

In this page you can find the example usage for android.widget TableRow setOnClickListener.

Prototype

public void setOnClickListener(@Nullable OnClickListener l) 

Source Link

Document

Register a callback to be invoked when this view is clicked.

Usage

From source file:com.uoit.freeroomfinder.Results.java

/**
 * SetupUpTableView Set all the default values for the table view and instantiate handles to the
 * interface elements./* ww w  . j a  v a  2s.  c  om*/
 * 
 * @param inflater The inflater for the layout.
 * @param container The ViewGroup container for the view.
 * @param index The index for the table view.
 * 
 * @return Returns a handle to the first table row.
 */
public TableRow SetupUpTableView(LayoutInflater inflater, ViewGroup container, final int index) {
    View newView = inflater.inflate(R.layout.room_item, container, false);

    TextView room = (TextView) newView.findViewById(R.id.room);
    TextView start = (TextView) newView.findViewById(R.id.stime);
    TextView end = (TextView) newView.findViewById(R.id.etime);
    RadioButton ch = (RadioButton) newView.findViewById(R.id.radio_button);

    // Provides the logic for the selectable table rows.
    ch.setOnClickListener(new OnClickListener() {
        /*
         * (non-Javadoc)
         * 
         * @see android.view.View.OnClickListener#onClick(android.view.View)
         */
        @Override
        public void onClick(View v) {
            RadioButton rb = (RadioButton) v;

            // A different row has been selected.
            if (checked != rb) {
                // Check if it's been checked the first time.
                if (checked != null) {
                    checked.setChecked(false);
                }
                checked = rb;
                rb.setChecked(true);
                isNotChecked = false;
            }
            // The same row has been selected.
            else if (checked == rb) {
                rb.setChecked(isNotChecked);
                checked = rb;
                v = (View) rb;
                isNotChecked = !isNotChecked;
            }

            // Prepare the button if a row is selected, otherwise disable it.
            if (isNotChecked) {
                book.setEnabled(false);
                indexOfChecked = -1;
            } else {
                indexOfChecked = index;
                book.setEnabled(true);
            }

            rb.refreshDrawableState();
        }
    });

    // Grab the results and format the dates according to the values therein.
    Rooms first = results.get(index);

    room.setText(first.getRoom());
    start.setText(DateTimeUtility.formatTime(new Date(first.getStartTime())));
    end.setText(DateTimeUtility.formatTime(new Date(first.getEndTime())));

    TableRow tr = (TableRow) newView.findViewById(R.id.room_row);

    // Provide the logic for selecting a table row.
    tr.setOnClickListener(new OnClickListener() {
        /*
         * (non-Javadoc)
         * 
         * @see android.view.View.OnClickListener#onClick(android.view.View)
         */
        @Override
        public void onClick(View v) {
            TableRow d = (TableRow) v;

            // Note the location of the relative layout is hard coded here as the last element in the table row.
            // Also, the radio button is hard coded here as the first (and only) element in the  relative layout.
            ((RelativeLayout) d.getChildAt(d.getChildCount() - 1)).getChildAt(0).performClick();
        }
    });

    return tr;
}

From source file:com.bonsai.btcreceive.AccountFragment.java

private void addAddressRow(int tableId, int index, TableLayout table, String path, String addr, String ntrans,
        String btcstr, String fiatstr) {
    TableRow row = (TableRow) LayoutInflater.from(getActivity()).inflate(R.layout.address_table_row, table,
            false);//w  w  w  . jav a 2s  .c  o m

    row.setTag(tableId);
    row.setId(index);

    row.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View view) {
            int tableId = (Integer) view.getTag();
            int index = view.getId();
            viewAddress(tableId, index);
        }
    });

    {
        TextView tv = (TextView) row.findViewById(R.id.row_path);
        tv.setText(path);
    }

    {
        TextView tv = (TextView) row.findViewById(R.id.row_addr);
        tv.setText(addr);
    }

    {
        TextView tv = (TextView) row.findViewById(R.id.row_ntrans);
        tv.setText(ntrans);
    }

    {
        TextView tv = (TextView) row.findViewById(R.id.row_btc);
        tv.setText(btcstr);
    }

    {
        TextView tv = (TextView) row.findViewById(R.id.row_fiat);
        tv.setText(fiatstr);
    }

    table.addView(row);
}

From source file:com.bonsai.btcreceive.TransactionsFragment.java

private void addTransactionRow(String hash, TableLayout table, String datestr, String timestr, String confstr,
        String btcstr, String btcbalstr, String fiatstr, String fiatbalstr, boolean tintrow) {
    TableRow row = (TableRow) LayoutInflater.from(getActivity()).inflate(R.layout.transaction_table_row, table,
            false);//from   w w w . ja  v a2 s  .com

    row.setTag(hash);

    row.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View view) {
            // Dispatch to the transaction viewer.
            String hash = (String) view.getTag();
            Intent intent = new Intent(getActivity(), ViewTransactionActivity.class);
            intent.putExtra("hash", hash);
            startActivity(intent);
        }
    });

    {
        TextView tv = (TextView) row.findViewById(R.id.row_date);
        tv.setText(datestr);
    }
    {
        TextView tv = (TextView) row.findViewById(R.id.row_time);
        tv.setText(timestr);
    }

    {
        TextView tv = (TextView) row.findViewById(R.id.row_confidence);
        tv.setText(confstr);
    }

    {
        TextView tv = (TextView) row.findViewById(R.id.row_btc_balance);
        tv.setText(btcbalstr);
    }
    {
        TextView tv = (TextView) row.findViewById(R.id.row_btc);
        tv.setText(btcstr);
    }

    {
        TextView tv = (TextView) row.findViewById(R.id.row_fiat_balance);
        tv.setText(fiatbalstr);
    }
    {
        TextView tv = (TextView) row.findViewById(R.id.row_fiat);
        tv.setText(fiatstr);
    }

    if (tintrow)
        row.setBackgroundColor(Color.parseColor("#ccffcc"));

    table.addView(row);
}

From source file:com.vanisty.ui.MenuActivity.java

/** Called when the activity is first created. */
@Override//w  w w. j  a v a  2 s  . c  o m
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    // Initialize socialize
    //Socialize.onCreate(this, savedInstanceState);
    Socialize.initAsync(this);
    connectSocialize();
    //ConfigUtils.getConfig(this).setProperty(SocializeConfig.SOCIALIZE_EVENTS_AUTH_ENABLED, "false");
    //ConfigUtils.getConfig(this).setProperty(SocializeConfig.SOCIALIZE_EVENTS_SHARE_ENABLED, "false");

    //Request Progress Spinner for ActionBar must be done first
    requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);

    setContentView(R.layout.menu_activity);

    //Sidebar stuff
    mLayout = (AnimationLayout) findViewById(R.id.root);
    mLayout.setListener(this);
    mLayout.closeSidebar();
    TableRow settings = (TableRow) findViewById(R.id.settings);
    settings.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            user.showUserSettings(MenuActivity.this);
        }

    });

    TableRow userEvents = (TableRow) findViewById(R.id.sideEvents);
    userEvents.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            showUserActivity("events");
        }
    });

    TableRow userLocations = (TableRow) findViewById(R.id.sideLocations);
    userLocations.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            showUserActivity("locations");
        }
    });

    TableRow userAddress = (TableRow) findViewById(R.id.sideCity);
    userAddress.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            showAdressChangeDialog();
        }
    });

    //Temporary set current location to home location. overwritten when Location listener gets result
    try {
        user.getCurrentLocation().setCity(user.getHomeLocation().getCity());
        user.getCurrentLocation().setCountry(user.getHomeLocation().getCountry());
    } catch (Exception ex) {
        ex.printStackTrace();
    }

    //Get Location Data Async. There may be no result
    Navigation.getGpsData(this);

    //Navigation.getGpsData(this);

    //Apply roboto font to all view children
    FontUtils.setRobotoFont(this.getApplicationContext(), findViewById(R.id.root));

    //initialize image loader
    initializeImageLoader();

    ab = getSupportActionBar();

    BitmapDrawable background = new BitmapDrawable(
            BitmapFactory.decodeResource(getResources(), R.drawable.ab_solid_vanisty));
    ab.setBackgroundDrawable(background);

    //Set Progress Spinner visibility false after ActionBar was created
    showProgress(false);

    // set defaults for logo & home up
    ab.setDisplayHomeAsUpEnabled(showHomeUp);
    ab.setLogo(R.drawable.logo_white);
    ab.setDisplayUseLogoEnabled(useLogo);

    //set up tabs
    tab1 = ab.newTab().setTabListener(this);
    tab1.setIcon(R.drawable.list);
    ab.addTab(tab1);
    tab5 = ab.newTab().setTabListener(this);
    tab5.setIcon(R.drawable.friends);
    ab.addTab(tab5);
    tab2 = ab.newTab().setTabListener(this);
    tab2.setIcon(R.drawable.discover);
    ab.addTab(tab2);
    tab3 = ab.newTab().setTabListener(this);
    tab3.setIcon(R.drawable.compass);
    ab.addTab(tab3);

    tab4 = ab.newTab().setTabListener(this);
    tab4.setIcon(R.drawable.users);
    ab.addTab(tab4);

    // default to tab navigation
    showTabsNav();

    em = getEventManager();
    showEventlistContainerFragment();
    //showGridFragment();

}

From source file:com.woofer.activity.personHomeActivity.java

public void showTable() {
    TableRow.LayoutParams layoutParams = new TableRow.LayoutParams(TableRow.LayoutParams.MATCH_PARENT,
            TableRow.LayoutParams.WRAP_CONTENT);
    layoutParams.gravity = Gravity.LEFT;
    layoutParams.leftMargin = 30;/*ww w .  j a  v  a 2  s  .co m*/
    layoutParams.bottomMargin = 10;
    layoutParams.topMargin = 10;

    for (int i = 0; i < 30; i++) {

        TableRow tableRow = new TableRow(this);
        TextView textView7 = new TextView(this);
        textView7.setText("" + i);
        textView7.setTextSize(18);
        textView7.setTextColor(Color.rgb(0, 0, 0));

        textView7.setPadding(15, 0, 15, 0);
        tableRow.addView(textView7, layoutParams);
        tableRow.setBackgroundColor(Color.WHITE);

        final int n = i;
        tableRow.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Toast.makeText(personHomeActivity.this, "Click item " + n, Toast.LENGTH_SHORT).show();
            }
        });

        mMainLayout.addView(tableRow);

        TableRow tableRow1 = new TableRow(this);
        TextView textView1 = new TextView(this);
        textView1.setText("Test pull down scrollvsfadasdsadsasadsadsadsadsadasdsadasdasdsadsaddasdiew " + i);
        textView1.setTextSize(16);
        textView1.setPadding(15, 0, 15, 15);
        tableRow1.addView(textView1, layoutParams);
        tableRow1.setBackgroundColor(Color.WHITE);

        tableRow.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Toast.makeText(personHomeActivity.this, "Click item " + n, Toast.LENGTH_SHORT).show();
            }
        });
        mMainLayout.addView(tableRow1);

        //            TableRow tableRow2 = new TableRow(this);
        //            //tableRow2.addView(textView2, layoutParams);
        //            ImageView imageView = new ImageView(this);
        //            imageView.setImageResource(R.drawable.icon_reply_t);
        //            imageView.setScaleX((float) a);
        //            imageView.setScaleY((float) a);
        //            imageView.setPadding(0, 0, 0, 0);
        //
        //            ImageView imageView1 = new ImageView(this);
        //            imageView1.setImageResource(R.drawable.icon_thumb_t);
        //            imageView1.setScaleX((float) a);
        //            imageView1.setScaleY((float) a);
        //            imageView1.setPadding(0, 0, 0, 0);
        //
        //
        //            //tableRow2.addView(imageView);
        //            tableRow2.addView(imageView1);
        //            mMainLayout.addView(tableRow2);
        TableLayout mytable = (TableLayout) findViewById(R.id.degital_textTL);
        int numberOfRow = 1;
        int numberOfColumn = 12;
        int cellDimension = 24;
        int cellPadding = 200;
        for (int row = 0; row < numberOfRow; row++) {
            tableRow = new TableRow(this);
            //tableRow.setLayoutParams(new TableLayout.LayoutParams(TableRow.LayoutParams.MATCH_PARENT,TableRow.LayoutParams.MATCH_PARENT));
            tableRow.setLayoutParams(new TableLayout.LayoutParams(
                    (cellDimension + 2 * cellPadding) * numberOfColumn, cellDimension + 2 * cellPadding));

            for (int column = 0; column < numberOfColumn; column++) {
                if (column % 3 == 0) {
                    TextView textView = new TextView(this);
                    textView.setTextSize(20);
                    textView.setText("   ");
                    tableRow.addView(textView);
                }
                if (column % 3 == 1) {
                    if (column == 1) {
                        ImageView imageView = new ImageView(this);
                        imageView.setScaleX((float) 0.5);
                        imageView.setScaleY((float) 0.5);
                        imageView.setImageResource(R.drawable.icon_eye_t);
                        tableRow.addView(imageView);
                    }
                    if (column == 4) {
                        ImageView imageView = new ImageView(this);
                        imageView.setScaleX((float) 0.5);
                        imageView.setScaleY((float) 0.5);
                        imageView.setImageResource(R.drawable.icon_thumb_t);
                        tableRow.addView(imageView);
                    }
                    if (column == 7) {
                        ImageView imageView = new ImageView(this);
                        imageView.setScaleX((float) 0.5);
                        imageView.setScaleY((float) 0.5);
                        imageView.setImageResource(R.drawable.icon_reply_t);
                        tableRow.addView(imageView);
                    }
                    if (column == 10) {
                        ImageView imageView = new ImageView(this);
                        imageView.setScaleX((float) 0.5);
                        imageView.setScaleY((float) 0.5);
                        imageView.setImageResource(R.drawable.icon_pencil_t);
                        tableRow.addView(imageView);
                    }
                }
                if (column % 3 == 2) {
                    if (column == 2) {
                        TextView textView = new TextView(this);
                        textView.setText("8");
                        tableRow.addView(textView);
                    }
                    if (column == 5) {
                        TextView textView = new TextView(this);
                        textView.setText("8");
                        tableRow.addView(textView);
                    }
                    if (column == 8) {
                        TextView textView = new TextView(this);
                        textView.setText("8");
                        tableRow.addView(textView);
                    }
                    if (column == 11) {
                        TextView textView = new TextView(this);
                        textView.setText("8");
                        tableRow.addView(textView);
                    }
                }

            }
            mytable.addView(tableRow, new TableLayout.LayoutParams(
                    (cellDimension + 2 * cellPadding) * numberOfColumn, cellDimension + 2 * cellPadding));
            //mytable.addView(tableRow,new TableLayout.LayoutParams(TableRow.LayoutParams.MATCH_PARENT,TableRow.LayoutParams.MATCH_PARENT));
        }

    }
}

From source file:com.example.parkhere.seeker.SeekerProfileVehicleFragment.java

public void addVehicle(final Vehicle vehicle) {
    Retrofit retrofit = new Retrofit.Builder().baseUrl(Constants.BASE_URL)
            .addConverterFactory(GsonConverterFactory.create()).build();

    RequestInterface requestInterface = retrofit.create(RequestInterface.class);

    ServerRequest request = new ServerRequest();
    request.setOperation(Constants.ADD_VEHICLE_OPERATION);
    request.setUser(user);/*from www . j ava 2s.  c o m*/
    request.setVehicle(vehicle);
    Call<ServerResponse> response = requestInterface.operation(request);

    response.enqueue(new Callback<ServerResponse>() {
        @Override
        public void onResponse(Call<ServerResponse> call, retrofit2.Response<ServerResponse> response) {
            ServerResponse resp = response.body();

            if (resp.getResult().equals(Constants.SUCCESS)) {
                TableRow tr = new TableRow(myContext);
                tr.setLayoutParams(new TableRow.LayoutParams(TableRow.LayoutParams.FILL_PARENT,
                        TableRow.LayoutParams.WRAP_CONTENT));
                tr.setTag(tag);
                tag++;
                tr.setClickable(true);
                tr.setOnClickListener(clickListener);

                TextView v_make = new TextView(myContext);
                v_make.setText(vehicle.getMake());
                v_make.setLayoutParams(new TableRow.LayoutParams(300, 150));
                tr.addView(v_make);

                TextView v_model = new TextView(myContext);
                v_model.setText(vehicle.getModel());
                v_model.setLayoutParams(new TableRow.LayoutParams(TableRow.LayoutParams.WRAP_CONTENT,
                        TableRow.LayoutParams.WRAP_CONTENT));
                tr.addView(v_model);

                TextView v_license = new TextView(myContext);
                v_license.setText(vehicle.getLicensePlate());
                v_license.setLayoutParams(new TableRow.LayoutParams(TableRow.LayoutParams.WRAP_CONTENT,
                        TableRow.LayoutParams.WRAP_CONTENT));
                tr.addView(v_license);

                tl.addView(tr, new TableLayout.LayoutParams(TableLayout.LayoutParams.FILL_PARENT,
                        TableLayout.LayoutParams.WRAP_CONTENT));

                Vehicle[] arr = new Vehicle[vehicles.length + 1];
                for (int i = 0; i < vehicles.length; i++) {
                    arr[i] = vehicles[i];
                }
                arr[vehicles.length] = vehicle;
                vehicles = arr;
            }
            Snackbar.make(rootView, resp.getMessage(), Snackbar.LENGTH_LONG).show();
        }

        @Override
        public void onFailure(Call<ServerResponse> call, Throwable t) {
            Snackbar.make(rootView, t.getLocalizedMessage(), Snackbar.LENGTH_LONG).show();
        }
    });
}

From source file:com.example.parkhere.seeker.SeekerProfileVehicleFragment.java

public void getCurrInfo() {
    tag = 1;//  w ww .ja v a 2  s  . com

    Retrofit retrofit = new Retrofit.Builder().baseUrl(Constants.BASE_URL)
            .addConverterFactory(GsonConverterFactory.create()).build();

    RequestInterface requestInterface = retrofit.create(RequestInterface.class);

    ServerRequest request = new ServerRequest();
    request.setOperation(Constants.GET_SEEKER_PROFILE_OPERATION);
    request.setUser(user);
    Call<ServerResponse> response = requestInterface.operation(request);

    response.enqueue(new Callback<ServerResponse>() {
        @Override
        public void onResponse(Call<ServerResponse> call, retrofit2.Response<ServerResponse> response) {
            ServerResponse resp = response.body();

            if (resp.getResult().equals(Constants.SUCCESS)) {
                vehicles = resp.getVehicles();

                TableRow tr_head = new TableRow(myContext);
                tr_head.setBackgroundColor(Color.GRAY);
                tr_head.setLayoutParams(new TableRow.LayoutParams(TableRow.LayoutParams.FILL_PARENT,
                        TableRow.LayoutParams.WRAP_CONTENT));

                TextView make = new TextView(myContext);
                make.setText("MAKE");
                make.setTextColor(Color.WHITE);
                make.setPadding(5, 5, 5, 5);
                tr_head.addView(make);

                TextView model = new TextView(myContext);
                model.setText("MODEL");
                model.setTextColor(Color.WHITE);
                model.setPadding(5, 5, 5, 5);
                tr_head.addView(model);

                final TextView license = new TextView(myContext);
                license.setText("LICENSE PLATE");
                license.setTextColor(Color.WHITE);
                license.setPadding(5, 5, 5, 5);
                tr_head.addView(license);

                tl.addView(tr_head, new TableLayout.LayoutParams(TableLayout.LayoutParams.FILL_PARENT,
                        TableLayout.LayoutParams.WRAP_CONTENT));

                for (int i = 0; i < vehicles.length; i++) {
                    if (vehicles[i].getDeletedWithHistory() == 1) {
                        continue;
                    }

                    TableRow tr = new TableRow(myContext);
                    tr.setLayoutParams(new TableRow.LayoutParams(TableRow.LayoutParams.FILL_PARENT,
                            TableRow.LayoutParams.WRAP_CONTENT));
                    tr.setTag(tag);
                    tag++;
                    tr.setClickable(true);
                    tr.setOnClickListener(clickListener);

                    TextView v_make = new TextView(myContext);
                    v_make.setText(vehicles[i].getMake());
                    v_make.setLayoutParams(new TableRow.LayoutParams(300, 150));
                    tr.addView(v_make);

                    TextView v_model = new TextView(myContext);
                    v_model.setText(vehicles[i].getModel());
                    v_model.setLayoutParams(new TableRow.LayoutParams(TableRow.LayoutParams.WRAP_CONTENT,
                            TableRow.LayoutParams.WRAP_CONTENT));
                    tr.addView(v_model);

                    TextView v_license = new TextView(myContext);
                    v_license.setText(vehicles[i].getLicensePlate());
                    v_license.setLayoutParams(new TableRow.LayoutParams(TableRow.LayoutParams.WRAP_CONTENT,
                            TableRow.LayoutParams.WRAP_CONTENT));
                    tr.addView(v_license);

                    tl.addView(tr, new TableLayout.LayoutParams(TableLayout.LayoutParams.FILL_PARENT,
                            TableLayout.LayoutParams.WRAP_CONTENT));
                }
            }
        }

        @Override
        public void onFailure(Call<ServerResponse> call, Throwable t) {
            Snackbar.make(rootView, t.getLocalizedMessage(), Snackbar.LENGTH_LONG).show();
        }
    });
}

From source file:se.frikod.payday.DailyBudgetFragment.java

private void updateBudgetItems() {

    TableLayout itemsTable = (TableLayout) V.findViewById(R.id.budgetItems);
    itemsTable.removeAllViews();//www.j  av a 2 s . c o  m

    for (int i = 0; i < budget.budgetItems.size(); i++) {
        BudgetItem bi = budget.budgetItems.get(i);
        final int currentIndex = i;
        LayoutInflater inflater = activity.getLayoutInflater();
        TableRow budgetItemView = (TableRow) inflater.inflate(R.layout.daily_budget_budget_item, itemsTable,
                false);

        TextView amount = (TextView) budgetItemView.findViewById(R.id.budgetItemAmount);
        TextView title = (TextView) budgetItemView.findViewById(R.id.budgetItemLabel);

        amount.setText(budget.formatter.format(bi.amount));

        title.setText(bi.title);

        if (bi.exclude) {
            amount.setTextColor(0xffCCCCCC);
            amount.setPaintFlags(amount.getPaintFlags() | Paint.STRIKE_THRU_TEXT_FLAG);

            title.setTextColor(0xffCCCCCC);
            title.setPaintFlags(title.getPaintFlags() | Paint.STRIKE_THRU_TEXT_FLAG);
        }

        budgetItemView.setClickable(true);
        budgetItemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Vibrator vibrator = (Vibrator) activity.getSystemService(Context.VIBRATOR_SERVICE);
                vibrator.vibrate(10);

                BudgetItem bi = budget.budgetItems.get(currentIndex);
                bi.exclude = !bi.exclude;
                budget.saveBudgetItems();
                updateBudgetItems();
            }
        });

        budgetItemView.setLongClickable(true);
        budgetItemView.setOnLongClickListener(new View.OnLongClickListener() {
            @Override
            public boolean onLongClick(View v) {
                editBudgetItem(v, currentIndex);
                return true;
            }
        });
        itemsTable.addView(budgetItemView);
    }

    FontUtils.setRobotoFont(activity, itemsTable);
    updateBudget();
}

From source file:com.landenlabs.all_devtool.TextFragment.java

private void fillLayout() {
    m_tableLayout.removeAllViews();/*from  www .j  a va 2  s  .  c  o  m*/
    m_textInfoList.clear();

    int minSP = 8;
    int maxSP = 20;
    int stepSP = 2;

    int[] colors = new int[] { 0xffe0e0e0, 0xffffe0e0, 0xffe0ffe0, 0xffe0e0ff };

    TableLayout.LayoutParams tableLP = new TableLayout.LayoutParams(TableLayout.LayoutParams.MATCH_PARENT,
            TableLayout.LayoutParams.WRAP_CONTENT);
    TableRow.LayoutParams rowLP = new TableRow.LayoutParams(TableRow.LayoutParams.WRAP_CONTENT,
            TableRow.LayoutParams.MATCH_PARENT);

    TextView textView;
    TableRow tableRow;
    int textColor = 0xff000000;

    for (int tfIdx = 0; tfIdx < TextInfo.getCount(); tfIdx++) {
        Typeface typeface = TextInfo.getTypeface(tfIdx);
        String typefaceStr = TextInfo.getTypefaceStr(tfIdx);

        textView = new TextView(m_context);
        textView.setBackgroundColor(Utils.blend(colors[tfIdx], 0x20000000));
        textView.setText(typefaceStr);
        textView.setGravity(Gravity.CENTER);
        textView.setTextColor(textColor);
        m_tableLayout.addView(textView, tableLP);

        for (int sizeSP = minSP; sizeSP <= maxSP; sizeSP += stepSP) {
            tableRow = new TableRow(m_context);
            tableRow.setBackgroundColor(colors[tfIdx]);

            tableRow.setTag(Integer.valueOf(m_textInfoList.size()));
            m_textInfoList.add(new TextInfo(sizeSP, tfIdx));

            tableRow.setClickable(true);
            tableRow.setOnClickListener(new OnClickListener() {

                @Override
                public void onClick(View v) {
                    int idx = (Integer) v.getTag();
                    showTextDialog(m_textInfoList, idx);
                }
            });

            textView = new TextView(m_context);
            textView.setText(String.valueOf(sizeSP) + "sp ");
            textView.setBackgroundColor(0x20000000);
            textView.setPadding(8, 0, 8, 0);
            textView.setGravity(Gravity.CENTER);
            textView.setTextColor(textColor);
            tableRow.addView(textView, rowLP);

            textView = new TextView(m_context);
            textView.setText("Normal");
            textView.setTextSize(TypedValue.COMPLEX_UNIT_SP, sizeSP);
            textView.setTypeface(typeface, Typeface.NORMAL);
            textView.setGravity(Gravity.CENTER);
            textView.setTextColor(textColor);
            tableRow.addView(textView, rowLP);

            textView = new TextView(m_context);
            textView.setText("Bold");
            textView.setTextSize(TypedValue.COMPLEX_UNIT_SP, sizeSP);
            textView.setTypeface(typeface, Typeface.BOLD);
            textView.setPadding(8, 0, 8, 0);
            textView.setGravity(Gravity.CENTER);
            textView.setTextColor(textColor);
            tableRow.addView(textView, rowLP);

            textView = new TextView(m_context);
            textView.setText("Italic");
            textView.setTextSize(TypedValue.COMPLEX_UNIT_SP, sizeSP);
            textView.setTypeface(typeface, Typeface.ITALIC);
            textView.setGravity(Gravity.CENTER);
            textView.setTextColor(textColor);
            tableRow.addView(textView, rowLP);

            m_tableLayout.addView(tableRow, tableLP);
        }
    }
}

From source file:org.nypl.simplified.app.MainSettingsAccountActivity.java

@Override
protected void onCreate(final @Nullable Bundle state) {
    super.onCreate(state);

    final Bundle extras = getIntent().getExtras();
    if (extras != null) {
        this.account = new AccountsRegistry(this).getAccount(extras.getInt("selected_account"));
    } else {//from  ww  w  .jav a 2 s.  c  o  m
        this.account = Simplified.getCurrentAccount();
    }

    final ActionBar bar = this.getActionBar();
    if (android.os.Build.VERSION.SDK_INT < 21) {
        bar.setDisplayHomeAsUpEnabled(false);
        bar.setHomeButtonEnabled(true);
        bar.setIcon(R.drawable.ic_arrow_back);
    } else {
        bar.setHomeAsUpIndicator(R.drawable.ic_arrow_back);
        bar.setDisplayHomeAsUpEnabled(true);
        bar.setHomeButtonEnabled(false);
    }

    final DocumentStoreType docs = Simplified.getDocumentStore(this.account, getResources());

    final LayoutInflater inflater = NullCheck.notNull(this.getLayoutInflater());

    final FrameLayout content_area = this.getContentFrame();
    final ViewGroup layout = NullCheck
            .notNull((ViewGroup) inflater.inflate(R.layout.settings_account, content_area, false));
    content_area.addView(layout);
    content_area.requestLayout();

    final TextView in_barcode_label = NullCheck.notNull(this.findViewById(R.id.settings_barcode_label));
    final TextView in_barcode_text = NullCheck.notNull(this.findViewById(R.id.settings_barcode_text));
    final TextView in_pin_label = NullCheck.notNull(this.findViewById(R.id.settings_pin_label));
    final ImageView in_barcode_image = NullCheck.notNull(this.findViewById(R.id.settings_barcode_image));
    final TextView in_barcode_image_toggle = NullCheck
            .notNull(this.findViewById(R.id.settings_barcode_toggle_barcode));
    final TextView in_pin_text = NullCheck.notNull(this.findViewById(R.id.settings_pin_text));
    final CheckBox in_pin_reveal = NullCheck.notNull(this.findViewById(R.id.settings_reveal_password));

    if (!this.account.pinRequired()) {
        in_pin_label.setVisibility(View.INVISIBLE);
        in_pin_text.setVisibility(View.INVISIBLE);
        in_pin_reveal.setVisibility(View.INVISIBLE);
    }

    final Button in_login = NullCheck.notNull(this.findViewById(R.id.settings_login));
    final Button in_signup = NullCheck.notNull(this.findViewById(R.id.settings_signup));

    this.sync_switch = findViewById(R.id.sync_switch);
    this.sync_table_row = findViewById(R.id.sync_table_row);
    this.sync_table_row.setVisibility(View.GONE);
    this.advanced_table_row = findViewById(R.id.link_advanced);
    this.advanced_table_row.setVisibility(View.GONE);

    this.advanced_table_row.setOnClickListener(view -> {
        final FragmentManager mgr = getFragmentManager();
        final FragmentTransaction transaction = mgr.beginTransaction();
        final SettingsAccountAdvancedFragment fragment = new SettingsAccountAdvancedFragment();
        transaction.add(R.id.settings_account_container, fragment).addToBackStack("advanced").commit();
    });

    final TableRow in_privacy = findViewById(R.id.link_privacy);
    final TableRow in_license = findViewById(R.id.link_license);

    final TextView account_name = NullCheck.notNull(this.findViewById(android.R.id.text1));
    final TextView account_subtitle = NullCheck.notNull(this.findViewById(android.R.id.text2));

    final ImageView in_account_icon = NullCheck.notNull(this.findViewById(R.id.account_icon));

    in_pin_text.setTransformationMethod(PasswordTransformationMethod.getInstance());
    if (android.os.Build.VERSION.SDK_INT >= 21) {
        this.handle_pin_reveal(in_pin_text, in_pin_reveal);
    } else {
        in_pin_reveal.setVisibility(View.GONE);
    }

    final TableRow in_report_issue = findViewById(R.id.report_issue);

    if (this.account.getSupportEmail() == null) {
        in_report_issue.setVisibility(View.GONE);
    } else {
        in_report_issue.setVisibility(View.VISIBLE);
        in_report_issue.setOnClickListener(view -> {
            final Intent intent = new Intent(this, ReportIssueActivity.class);
            final Bundle b = new Bundle();
            b.putInt("selected_account", this.account.getId());
            intent.putExtras(b);
            startActivity(intent);
        });
    }

    final TableRow in_support_center = findViewById(R.id.support_center);
    if (this.account.supportsHelpCenter()) {
        in_support_center.setVisibility(View.VISIBLE);
        in_support_center.setOnClickListener(view -> {
            final HSHelpStack stack = HSHelpStack.getInstance(this);
            final HSDeskGear gear = new HSDeskGear("https://nypl.desk.com/", "4GBRmMv8ZKG8fGehhA", null);
            stack.setGear(gear);
            stack.showHelp(this);
        });
    } else {
        in_support_center.setVisibility(View.GONE);
    }

    //Get labels from the current authentication document.
    final AuthenticationDocumentType auth_doc = docs.getAuthenticationDocument();
    in_barcode_label.setText(auth_doc.getLabelLoginUserID());
    in_pin_label.setText(auth_doc.getLabelLoginPassword());

    final TableLayout in_table_with_code = NullCheck
            .notNull(this.findViewById(R.id.settings_login_table_with_code));
    in_table_with_code.setVisibility(View.GONE);
    final TableLayout in_table_signup = NullCheck.notNull(this.findViewById(R.id.settings_signup_table));

    //    boolean locationpermission = false;
    //    if (ContextCompat.checkSelfPermission(getApplicationContext(), android.Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED) {
    //      locationpermission = true;
    //    }
    //    else
    //    {
    //      ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.ACCESS_FINE_LOCATION}, 1);
    //    }

    if (this.account.supportsCardCreator() || this.account.getCardCreatorUrl() != null) {
        in_table_signup.setVisibility(View.VISIBLE);
    } else {
        in_table_signup.setVisibility(View.GONE);
    }

    in_login.setOnClickListener(v -> this.onLoginWithBarcode());

    final CheckBox in_age13_checkbox = NullCheck.notNull(this.findViewById(R.id.age13_checkbox));

    if (Simplified.getSharedPrefs().contains("age13")) {
        in_age13_checkbox.setChecked(Simplified.getSharedPrefs().getBoolean("age13"));
    } else if (account.getId() == 2) {
        showAgeGateOptionsDialog(in_age13_checkbox);
    }

    in_age13_checkbox.setOnCheckedChangeListener(this::showAgeChangeConfirmation);

    if (this.account.needsAuth()) {
        in_login.setVisibility(View.VISIBLE);
        in_age13_checkbox.setVisibility(View.GONE);
    } else {
        in_login.setVisibility(View.GONE);
        in_age13_checkbox.setVisibility(View.VISIBLE);
    }

    if (this.account.supportsCardCreator()) {
        in_signup.setOnClickListener(v -> {
            final Intent cardcreator = new Intent(this, CardCreatorActivity.class);
            startActivity(cardcreator);
        });
        in_signup.setText(R.string.need_card_button);

    } else if (this.account.getCardCreatorUrl() != null) {
        in_signup.setOnClickListener(v -> {
            final Intent e_card = new Intent(Intent.ACTION_VIEW);
            e_card.setData(Uri.parse(this.account.getCardCreatorUrl()));
            startActivity(e_card);
        });
        in_signup.setText(R.string.need_card_button);
    }

    final boolean permission = Simplified.getSharedPrefs().getBoolean("syncPermissionGranted",
            this.account.getId());
    this.sync_switch.setChecked(permission);

    /*
    If switching on, disable user interaction until server has responded.
    If switching off, disable applicable network requests by updating shared prefs flags.
     */
    this.sync_switch.setOnCheckedChangeListener((buttonView, isChecked) -> {
        if (isChecked) {
            buttonView.setEnabled(false);
            annotationsManager.updateServerSyncPermissionStatus(true, (success) -> {
                if (success) {
                    Simplified.getSharedPrefs().putBoolean("syncPermissionGranted", this.account.getId(), true);
                    this.sync_switch.setChecked(true);
                } else {
                    Simplified.getSharedPrefs().putBoolean("syncPermissionGranted", this.account.getId(),
                            false);
                    this.sync_switch.setChecked(false);
                }
                this.sync_switch.setEnabled(true);
                return kotlin.Unit.INSTANCE;
            });
        } else {
            Simplified.getSharedPrefs().putBoolean("syncPermissionGranted", this.account.getId(), false);
            this.sync_switch.setChecked(false);
        }
    });

    if (this.account.getPrivacyPolicy() != null) {
        in_privacy.setVisibility(View.VISIBLE);
    } else {
        in_privacy.setVisibility(View.GONE);
    }
    if (this.account.getContentLicense() != null) {
        in_license.setVisibility(View.VISIBLE);
    } else {
        in_license.setVisibility(View.GONE);
    }

    in_license.setOnClickListener(view -> {
        final Intent intent = new Intent(this, WebViewActivity.class);
        final Bundle b = new Bundle();
        WebViewActivity.setActivityArguments(b, this.account.getContentLicense(), "Content Licenses",
                SimplifiedPart.PART_SETTINGS);
        intent.putExtras(b);
        intent.setFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);
        startActivity(intent);
    });

    in_privacy.setOnClickListener(view -> {
        final Intent intent = new Intent(this, WebViewActivity.class);
        final Bundle b = new Bundle();
        WebViewActivity.setActivityArguments(b, this.account.getPrivacyPolicy(), "Privacy Policy",
                SimplifiedPart.PART_SETTINGS);
        intent.putExtras(b);
        intent.setFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);
        startActivity(intent);
    });

    this.navigationDrawerSetActionBarTitle();

    this.account_name_text = account_name;
    this.account_subtitle_text = account_subtitle;
    this.account_icon = in_account_icon;
    this.barcode_text = in_barcode_text;
    this.pin_text = in_pin_text;
    this.barcode_image_toggle = in_barcode_image_toggle;
    this.barcode_image = in_barcode_image;
    this.login = in_login;
    this.table_with_code = in_table_with_code;
    this.table_signup = in_table_signup;

    final CheckBox in_eula_checkbox = NullCheck.notNull(this.findViewById(R.id.eula_checkbox));

    final OptionType<EULAType> eula_opt = docs.getEULA();

    if (eula_opt.isSome()) {
        final Some<EULAType> some_eula = (Some<EULAType>) eula_opt;
        final EULAType eula = some_eula.get();

        in_eula_checkbox.setChecked(eula.eulaHasAgreed());
        in_eula_checkbox.setEnabled(true);
        in_eula_checkbox.setOnCheckedChangeListener((button, checked) -> eula.eulaSetHasAgreed(checked));

        if (eula.eulaHasAgreed()) {
            LOG.debug("EULA: agreed");
        } else {
            LOG.debug("EULA: not agreed");
        }
    } else {
        LOG.debug("EULA: unavailable");
    }

    this.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
}