Example usage for android.widget TableLayout setLayoutParams

List of usage examples for android.widget TableLayout setLayoutParams

Introduction

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

Prototype

public void setLayoutParams(ViewGroup.LayoutParams params) 

Source Link

Document

Set the layout parameters associated with this view.

Usage

From source file:com.ehret.mixit.fragment.SessionDetailFragment.java

private void addSpeakerInfo(Talk conference) {
    //On vide les lments
    sessionPersonList.removeAllViews();/*from  w  w  w  .  ja v a2 s  .c  o  m*/

    List<Member> speakers = new ArrayList<>();
    for (Speaker member : conference.getSpeakers()) {
        Member membre = MembreFacade.getInstance().getMembre(getActivity(), TypeFile.speaker.name(),
                member.getIdMember());

        if (membre != null) {
            speakers.add(membre);
        }
    }

    //On affiche les liens que si on a recuperer des choses
    if (!speakers.isEmpty()) {
        //On utilisait auparavant une liste pour afficher ces lments dans la page mais cette liste
        //empche d'avoir un ScrollView englobant pour toute la page. Nous utilisons donc un tableau

        //On ajoute un table layout
        TableLayout.LayoutParams tableParams = new TableLayout.LayoutParams(
                TableLayout.LayoutParams.MATCH_PARENT, TableLayout.LayoutParams.WRAP_CONTENT);
        TableLayout tableLayout = new TableLayout(getActivity().getBaseContext());
        tableLayout.setLayoutParams(tableParams);

        if (mInflater != null) {
            for (final Member membre : speakers) {
                LinearLayout row = (LinearLayout) mInflater.inflate(R.layout.item_person, tableLayout, false);
                row.setBackgroundResource(R.drawable.row_transparent_background);

                //Dans lequel nous allons ajouter le contenu que nous faisons mapp dans
                TextView userName = (TextView) row.findViewById(R.id.person_user_name);
                TextView descriptif = (TextView) row.findViewById(R.id.person_shortdesciptif);
                TextView level = (TextView) row.findViewById(R.id.person_level);
                ImageView profileImage = (ImageView) row.findViewById(R.id.person_user_image);

                userName.setText(membre.getCompleteName());

                if (membre.getShortDescription() != null) {
                    descriptif.setText(membre.getShortDescription().trim());
                }

                //Recuperation de l'mage liee au profil
                Bitmap image = FileUtils.getImageProfile(getActivity(), membre);
                if (image == null) {
                    profileImage.setImageDrawable(getResources().getDrawable(R.drawable.person_image_empty));
                } else {
                    //On regarde dans les images embarquees
                    profileImage.setImageBitmap(image);
                }

                row.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        ((HomeActivity) getActivity()).changeCurrentFragment(PeopleDetailFragment
                                .newInstance(TypeFile.speaker.toString(), membre.getLogin(), 7),
                                TypeFile.speaker.toString());
                    }
                });

                tableLayout.addView(row);
            }
        }
        sessionPersonList.addView(tableLayout);
    }
}

From source file:com.ehret.mixit.fragment.PeopleDetailFragment.java

private void addPeopleLink(Member membre) {
    //On vide les lments
    linkLayout.removeAllViews();/*from  ww  w.j ava2 s .c o  m*/

    //On affiche les liens que si on a recuperer des choses
    if (membre != null && membre.getSharedLinks() != null && !membre.getSharedLinks().isEmpty()) {

        //On ajoute un table layout
        TableLayout.LayoutParams tableParams = new TableLayout.LayoutParams(
                TableLayout.LayoutParams.MATCH_PARENT, TableLayout.LayoutParams.WRAP_CONTENT);
        TableLayout tableLayout = new TableLayout(getActivity().getBaseContext());
        tableLayout.setLayoutParams(tableParams);

        if (mInflater != null && membre.getSharedLinks().size() > 0) {
            for (final Link link : membre.getSharedLinks()) {
                RelativeLayout row = (RelativeLayout) mInflater.inflate(R.layout.item_link, tableLayout, false);
                row.setBackgroundResource(R.drawable.row_transparent_background);
                //Dans lequel nous allons ajouter le contenu que nous faisons mapp dans
                TextView link_text = (TextView) row.findViewById(R.id.link_text);
                link_text.setText(Html.fromHtml(String.format("%s : <a href=\"%s\">%s</a>", link.getRel(),
                        link.getHref(), link.getHref())));
                link_text.setBackgroundColor(Color.TRANSPARENT);
                link_text.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        Intent in = new Intent(Intent.ACTION_VIEW, Uri.parse(link.getHref()));
                        getActivity().startActivity(in);
                    }

                });
                tableLayout.addView(row);
            }
        } else {
            RelativeLayout row = (RelativeLayout) mInflater.inflate(R.layout.item_link, tableLayout, false);
            row.setBackgroundResource(R.drawable.row_transparent_background);
            //Dans lequel nous allons ajouter le contenu que nous faisons mapp dans
            TextView link_text = (TextView) row.findViewById(R.id.link_text);
            link_text.setText("Aucun lien");
            link_text.setBackgroundColor(Color.TRANSPARENT);
            tableLayout.addView(row);
        }
        linkLayout.addView(tableLayout);
    } else {
        titleLinks.getLayoutParams().height = 0;
    }
}

From source file:com.ehret.mixit.fragment.PeopleDetailFragment.java

private void addPeopleSession(Member membre) {
    //On recupere aussi la liste des sessions de l'utilisateur
    List<Talk> conferences = ConferenceFacade.getInstance().getSessionMembre(membre, getActivity());

    //On vide les lments
    sessionLayout.removeAllViews();//from   w  w w  .ja v a2  s .  c o  m

    //On affiche les liens que si on a recuperer des choses
    if (conferences != null && !conferences.isEmpty()) {
        //On ajoute un table layout
        TableLayout.LayoutParams tableParams = new TableLayout.LayoutParams(
                TableLayout.LayoutParams.MATCH_PARENT, TableLayout.LayoutParams.WRAP_CONTENT);
        TableLayout tableLayout = new TableLayout(getActivity().getBaseContext());
        tableLayout.setLayoutParams(tableParams);

        if (mInflater != null) {

            for (final Talk conf : conferences) {
                LinearLayout row = (LinearLayout) mInflater.inflate(R.layout.item_talk, tableLayout, false);
                row.setBackgroundResource(R.drawable.row_transparent_background);
                //Dans lequel nous allons ajouter le contenu que nous faisons mapp dans
                TextView horaire = (TextView) row.findViewById(R.id.talk_horaire);
                TextView talkImageText = (TextView) row.findViewById(R.id.talkImageText);
                TextView talkSalle = (TextView) row.findViewById(R.id.talk_salle);
                ImageView imageFavorite = (ImageView) row.findViewById(R.id.talk_image_favorite);
                ImageView langImage = (ImageView) row.findViewById(R.id.talk_image_language);

                ((TextView) row.findViewById(R.id.talk_name)).setText(conf.getTitle());
                ((TextView) row.findViewById(R.id.talk_shortdesciptif)).setText(conf.getSummary().trim());

                SimpleDateFormat sdf = new SimpleDateFormat("EEE");
                if (conf.getStart() != null && conf.getEnd() != null) {
                    horaire.setText(String.format(getResources().getString(R.string.periode),
                            sdf.format(conf.getStart()),
                            DateFormat.getTimeInstance(DateFormat.SHORT).format(conf.getStart()),
                            DateFormat.getTimeInstance(DateFormat.SHORT).format(conf.getEnd())));
                } else {
                    horaire.setText(getResources().getString(R.string.pasdate));

                }
                if (conf.getLang() != null && "ENGLISH".equals(conf.getLang())) {
                    langImage.setImageDrawable(getResources().getDrawable(R.drawable.en));
                } else {
                    langImage.setImageDrawable(getResources().getDrawable(R.drawable.fr));
                }
                Salle salle = Salle.INCONNU;
                if (conf instanceof Talk && Salle.INCONNU != Salle.getSalle(conf.getRoom())) {
                    salle = Salle.getSalle(conf.getRoom());
                }
                talkSalle.setText(String.format(getResources().getString(R.string.Salle), salle.getNom()));
                talkSalle.setBackgroundColor(getResources().getColor(salle.getColor()));

                if (conf instanceof Talk) {
                    if ("Workshop".equals(((Talk) conf).getFormat())) {
                        talkImageText.setText("Atelier");
                    } else {
                        talkImageText.setText("Talk");
                    }
                } else {
                    talkImageText.setText("L.Talk");
                }

                row.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        TypeFile typeFile;
                        int page = 6;
                        if (conf instanceof Talk) {
                            if ("Workshop".equals(((Talk) conf).getFormat())) {
                                typeFile = TypeFile.workshops;
                                page = 4;
                            } else {
                                typeFile = TypeFile.talks;
                                page = 3;
                            }
                        } else {
                            typeFile = TypeFile.lightningtalks;
                        }
                        ((HomeActivity) getActivity()).changeCurrentFragment(SessionDetailFragment.newInstance(
                                typeFile.toString(), conf.getIdSession(), page), typeFile.toString());
                    }
                });

                //On regarde si la conf fait partie des favoris
                SharedPreferences settings = getActivity().getSharedPreferences(UIUtils.PREFS_FAVORITES_NAME,
                        0);
                boolean trouve = false;
                for (String key : settings.getAll().keySet()) {
                    if (key.equals(String.valueOf(conf.getIdSession()))) {
                        trouve = true;
                        imageFavorite.setImageDrawable(
                                getActivity().getResources().getDrawable(R.drawable.ic_action_important));
                        break;
                    }
                }
                if (!trouve) {
                    imageFavorite.setImageDrawable(
                            getActivity().getResources().getDrawable(R.drawable.ic_action_not_important));
                }
                tableLayout.addView(row);
            }
        }
        sessionLayout.addView(tableLayout);
    } else {
        titleSessions.getLayoutParams().height = 0;
    }
}

From source file:com.example.diplimadoapp.SuperAwesomeCardFragment.java

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

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

    FrameLayout fl = new FrameLayout(getActivity());
    fl.setLayoutParams(params);/*from   w  w w .j  av a  2s.  com*/

    final int margin = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 8,
            getResources().getDisplayMetrics());

    switch (position) {
    case 0:

        LinearLayout ll = new LinearLayout(getActivity());
        ll.setLayoutParams(new FrameLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
        ll.setOrientation(LinearLayout.VERTICAL);

        ImageView iv = new ImageView(getActivity());
        iv.setLayoutParams(new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, 1020));
        //iv.setLayoutParams(new  LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT,LayoutParams.MATCH_PARENT));
        iv.setMaxHeight(520);
        iv.setImageResource(R.drawable.contact);
        ll.addView(iv);

        TableLayout tl = new TableLayout(getActivity());
        tl.setLayoutParams(new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));

        TableRow tr = new TableRow(getActivity());
        tr.setLayoutParams(new TableLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
        tr.setGravity(Gravity.FILL_HORIZONTAL);
        tr.setPadding(5, 5, 5, 5);

        List<RssItem> lecturaitems = null;
        try {
            // Create RSS reader
            RssReader rssReader = new RssReader(
                    "http://www.senalradionica.gov.co/index.php/home/articulos/itemlist?format=feed");
            // Get a ListView from main view
            //ListView itcItems = (ListView) findViewById(R.id.listMainView);

            lecturaitems = rssReader.getItems();

        } catch (Exception e) {
            Log.e("Diplomado App Reader", e.getMessage());
        }

        TextView v1 = new TextView(getActivity());
        params.setMargins(margin, margin, margin, margin);
        v1.setLayoutParams(new TableRow.LayoutParams(0, LayoutParams.WRAP_CONTENT, 2));
        v1.setGravity(Gravity.CENTER);
        v1.setBackgroundResource(R.drawable.background_card);
        if (lecturaitems != null) {
            v1.setText(lecturaitems.get(0).getTitle());
            String urlnoticia = lecturaitems.get(0).getLink();
            v1.setOnClickListener(new NoticiaDestacadaOnClickListener(urlnoticia));
        } else {
            v1.setText("No Registra nuevas noticias");
        }

        tr.addView(v1);

        ImageButton ib = new ImageButton(getActivity());
        ib.setLayoutParams(new TableRow.LayoutParams(0, LayoutParams.WRAP_CONTENT, 1));
        ib.setImageResource(R.drawable.facebook);

        ib.setOnClickListener(new OnClickListener() {
            public void onClick(View v) {
                Intent myWebLink = new Intent(android.content.Intent.ACTION_VIEW);
                myWebLink.setData(Uri.parse("http://www.facebook.com"));
                startActivity(myWebLink);
            }
        });

        tr.addView(ib);

        ImageButton ib2 = new ImageButton(getActivity());
        ib2.setLayoutParams(new TableRow.LayoutParams(0, LayoutParams.WRAP_CONTENT, 1));
        ib2.setImageResource(R.drawable.twitter);

        ib2.setOnClickListener(new OnClickListener() {
            public void onClick(View v) {
                Intent myWebLink = new Intent(android.content.Intent.ACTION_VIEW);
                myWebLink.setData(Uri.parse("http://www.twitter.com"));
                startActivity(myWebLink);
            }
        });

        tr.addView(ib2);

        ImageButton ib3 = new ImageButton(getActivity());
        ib3.setLayoutParams(new TableRow.LayoutParams(0, LayoutParams.WRAP_CONTENT, 1));
        ib3.setImageResource(R.drawable.youtube);

        ib3.setOnClickListener(new OnClickListener() {
            public void onClick(View v) {
                Intent myWebLink = new Intent(android.content.Intent.ACTION_VIEW);
                myWebLink.setData(Uri.parse("http://www.youtube.com"));
                startActivity(myWebLink);
            }
        });

        tr.addView(ib3);

        tl.addView(tr);

        ll.addView(tl);

        fl.addView(ll);

        break;

    case 1:

        LinearLayout ll2 = new LinearLayout(getActivity());
        ll2.setLayoutParams(new FrameLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
        ll2.setOrientation(LinearLayout.VERTICAL);

        TableLayout tl2 = new TableLayout(getActivity());
        tl2.setLayoutParams(
                new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));

        TableRow tr2 = new TableRow(getActivity());
        tr2.setLayoutParams(new TableLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
        tr2.setGravity(Gravity.FILL_HORIZONTAL);
        tr2.setPadding(5, 5, 5, 5);

        TextView v0 = new TextView(getActivity());
        params.setMargins(margin, margin, margin, margin);
        v0.setLayoutParams(new TableRow.LayoutParams(0, LayoutParams.WRAP_CONTENT, 2));
        v0.setGravity(Gravity.CENTER);
        v0.setText("Acusticos Radionoca. Lunes a Viernes 8:00 a.m. - 9:00 a.m.");
        tr2.addView(v0);

        ImageButton ib20 = new ImageButton(getActivity());
        ib20.setLayoutParams(new TableRow.LayoutParams(0, LayoutParams.WRAP_CONTENT, 1));
        ib20.setImageResource(R.drawable.pacusticos);
        ib20.setBackgroundDrawable(null);

        tr2.addView(ib20);

        tl2.addView(tr2);

        TableRow tr3 = new TableRow(getActivity());
        tr3.setLayoutParams(new TableLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
        tr3.setGravity(Gravity.FILL_HORIZONTAL);
        tr3.setPadding(5, 5, 5, 5);

        TextView v03 = new TextView(getActivity());
        params.setMargins(margin, margin, margin, margin);
        v03.setLayoutParams(new TableRow.LayoutParams(0, LayoutParams.WRAP_CONTENT, 2));
        v03.setGravity(Gravity.CENTER);
        v03.setText("Acusticos Radionoca. Lunes a Viernes 8:00 a.m. - 9:00 a.m.");
        tr3.addView(v03);

        ImageButton ib30 = new ImageButton(getActivity());
        ib30.setLayoutParams(new TableRow.LayoutParams(0, LayoutParams.WRAP_CONTENT, 1));
        ib30.setImageResource(R.drawable.pradionica_lacarta);
        ib30.setBackgroundDrawable(null);

        tr3.addView(ib30);

        tl2.addView(tr3);

        TableRow tr4 = new TableRow(getActivity());
        tr4.setLayoutParams(new TableLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
        tr4.setGravity(Gravity.FILL_HORIZONTAL);
        tr4.setPadding(5, 5, 5, 5);

        TextView v04 = new TextView(getActivity());
        params.setMargins(margin, margin, margin, margin);
        v04.setLayoutParams(new TableRow.LayoutParams(0, LayoutParams.WRAP_CONTENT, 2));
        v04.setGravity(Gravity.CENTER);
        v04.setText("Acusticos Radionoca. Lunes a Viernes 8:00 a.m. - 9:00 a.m.");
        tr4.addView(v04);

        tl2.addView(tr4);

        ImageButton ib40 = new ImageButton(getActivity());
        ib40.setLayoutParams(new TableRow.LayoutParams(0, LayoutParams.WRAP_CONTENT, 1));
        ib40.setImageResource(R.drawable.prockeros);
        ib40.setBackgroundDrawable(null);

        tr4.addView(ib40);

        ll2.addView(tl2);

        /*
        VideoView videoView = new VideoView(getActivity());
                
        Uri path = Uri.parse("rtmp://cdns840stu0010.multistream.net:80/rtvcRadionicalive/?pass=|radionica|");
                
        videoView.setVideoURI(path);
        videoView.start(); 
                
        TableRow tr5 =new TableRow(getActivity());
        tr5.setLayoutParams(new TableLayout.LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT));
        tr5.setGravity(Gravity.FILL_HORIZONTAL);
        tr5.setPadding(5,5,5,5);
        tr5.addView(videoView);
                
        ll2.addView(tr5);*/

        fl.addView(ll2);
        break;
    case 2:
        ListView lv = new ListView(getActivity());
        params.setMargins(margin, margin, margin, margin);
        lv.setLayoutParams(params);
        lv.setLayoutParams(params);
        lv.setBackgroundResource(R.drawable.background_card);
        try {
            // Create RSS reader
            RssReader rssReader = new RssReader(
                    "http://www.senalradionica.gov.co/index.php/home/articulos/itemlist?format=feed");
            // Get a ListView from main view
            //ListView itcItems = (ListView) findViewById(R.id.listMainView);

            List<RssItem> lecturaitems2 = rssReader.getItems();
            // Create a list adapter
            ArrayAdapter<RssItem> adapter = new ArrayAdapter<RssItem>(getActivity(),
                    android.R.layout.simple_list_item_1, lecturaitems2);
            // Set list adapter for the ListView
            lv.setAdapter(adapter);

            // Set list view item click listener
            lv.setOnItemClickListener(new ListListener(lecturaitems2, getActivity()));

        } catch (Exception e) {
            Log.e("Diplomado App Reader", e.getMessage());
        }
        fl.addView(lv);
        break;
    }

    return fl;
}

From source file:com.vonglasow.michael.satstat.ui.RadioSectionFragment.java

private final void addWifiResult(ScanResult result) {
    // needed to pass a persistent reference to the OnClickListener
    final ScanResult r = result;
    android.view.View.OnClickListener clis = new android.view.View.OnClickListener() {

        @Override/*from w  w  w  .j  a  va2s.  co  m*/
        public void onClick(View v) {
            onWifiEntryClick(r.BSSID);
        }
    };

    LinearLayout wifiLayout = new LinearLayout(wifiAps.getContext());
    wifiLayout.setLayoutParams(
            new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT));
    wifiLayout.setOrientation(LinearLayout.HORIZONTAL);
    wifiLayout.setWeightSum(22);
    wifiLayout.setMeasureWithLargestChildEnabled(false);

    ImageView wifiType = new ImageView(wifiAps.getContext());
    wifiType.setLayoutParams(new TableRow.LayoutParams(0, LayoutParams.MATCH_PARENT, 3));
    if (WifiCapabilities.isAdhoc(result)) {
        wifiType.setImageResource(R.drawable.ic_content_wifi_adhoc);
    } else if ((WifiCapabilities.isEnterprise(result))
            || (WifiCapabilities.getScanResultSecurity(result) == WifiCapabilities.EAP)) {
        wifiType.setImageResource(R.drawable.ic_content_wifi_eap);
    } else if (WifiCapabilities.getScanResultSecurity(result) == WifiCapabilities.PSK) {
        wifiType.setImageResource(R.drawable.ic_content_wifi_psk);
    } else if (WifiCapabilities.getScanResultSecurity(result) == WifiCapabilities.WEP) {
        wifiType.setImageResource(R.drawable.ic_content_wifi_wep);
    } else if (WifiCapabilities.getScanResultSecurity(result) == WifiCapabilities.OPEN) {
        wifiType.setImageResource(R.drawable.ic_content_wifi_open);
    } else {
        wifiType.setImageResource(R.drawable.ic_content_wifi_unknown);
    }

    wifiType.setScaleType(ScaleType.CENTER);
    wifiLayout.addView(wifiType);

    TableLayout wifiDetails = new TableLayout(wifiAps.getContext());
    wifiDetails.setLayoutParams(new TableRow.LayoutParams(0, LayoutParams.WRAP_CONTENT, 19));
    TableRow innerRow1 = new TableRow(wifiAps.getContext());
    TextView newMac = new TextView(wifiAps.getContext());
    newMac.setLayoutParams(new TableRow.LayoutParams(0, LayoutParams.WRAP_CONTENT, 14));
    newMac.setTextAppearance(wifiAps.getContext(), android.R.style.TextAppearance_Medium);
    newMac.setText(result.BSSID);
    innerRow1.addView(newMac);
    TextView newCh = new TextView(wifiAps.getContext());
    newCh.setLayoutParams(new TableRow.LayoutParams(0, LayoutParams.WRAP_CONTENT, 2));
    newCh.setTextAppearance(wifiAps.getContext(), android.R.style.TextAppearance_Medium);
    newCh.setText(getChannelFromFrequency(result.frequency));
    innerRow1.addView(newCh);
    TextView newLevel = new TextView(wifiAps.getContext());
    newLevel.setLayoutParams(new TableRow.LayoutParams(0, LayoutParams.WRAP_CONTENT, 3));
    newLevel.setTextAppearance(wifiAps.getContext(), android.R.style.TextAppearance_Medium);
    newLevel.setText(String.valueOf(result.level));
    innerRow1.addView(newLevel);
    innerRow1.setOnClickListener(clis);
    wifiDetails.addView(innerRow1,
            new TableLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));

    TableRow innerRow2 = new TableRow(wifiAps.getContext());
    TextView newSSID = new TextView(wifiAps.getContext());
    newSSID.setLayoutParams(new TableRow.LayoutParams(0, LayoutParams.WRAP_CONTENT, 19));
    newSSID.setTextAppearance(wifiAps.getContext(), android.R.style.TextAppearance_Small);
    newSSID.setText(result.SSID);
    innerRow2.addView(newSSID);
    innerRow2.setOnClickListener(clis);
    wifiDetails.addView(innerRow2,
            new TableLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));

    wifiLayout.addView(wifiDetails);
    wifiLayout.setOnClickListener(clis);
    wifiAps.addView(wifiLayout);
}

From source file:com.near.chimerarevo.fragments.PostFragment.java

private void parseTables(Elements tbls) {
    TableLayout tl = new TableLayout(getActivity());
    LayoutParams tl_prms = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
    tl_prms.gravity = Gravity.CENTER_HORIZONTAL;
    tl_prms.setMargins(10, 10, 10, 0);// w  w w. j  av  a2s .c o  m
    tl.setLayoutParams(tl_prms);

    for (Element tbl : tbls) {
        Elements rws = tbl.getElementsByTag("td");
        TableRow row = new TableRow(getActivity());
        for (Element rw : rws) {
            TextView txt = new TextView(getActivity());
            txt.setLayoutParams(new TableRow.LayoutParams(TableRow.LayoutParams.WRAP_CONTENT,
                    TableRow.LayoutParams.WRAP_CONTENT));
            txt.setText(rw.text());
            row.addView(txt);
        }
        tl.addView(row);
    }
    lay.addView(tl);
}

From source file:edu.ksu.cs.a4vm.bse.MorphologyCount.java

@Override
public void onResume() {
    super.onResume();
    test = "Resume called...";
    final MediaPlayer btnChangeSound = MediaPlayer.create(getApplicationContext(), R.raw.button_changed);
    final MediaPlayer limitRchdSound = MediaPlayer.create(getApplicationContext(), R.raw.limit_reached);
    initVals = (HashSet<String>) SharedPrefUtil.getValue(getApplicationContext(),
            Constant.PREFS_BULL_MORPHOLOGY_INFO, morphKey);
    /*morphologyLabels = (HashSet<String>) SharedPrefUtil.getValue(getApplicationContext(),
        Constant.PREFS_FILE_MORPH_INFO,Constant.KEY_MORPHOLOGY);*/
    morphologyLabels = (HashSet<String>) SharedPrefUtil.getValue(getApplicationContext(),
            Constant.PREFS_GRP_MORPH_CONFIG, grpKey);
    TableLayout table = new TableLayout(this);
    FrameLayout.LayoutParams lp = new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.MATCH_PARENT);
    table.setLayoutParams(lp);
    table.setShrinkAllColumns(true);//from w  w  w .j a va  2 s.c  o m
    table.setStretchAllColumns(true);

    TableLayout.LayoutParams rowLp = new TableLayout.LayoutParams(0, ViewGroup.LayoutParams.MATCH_PARENT, 0.5f);
    TableRow.LayoutParams cellLp = new TableRow.LayoutParams(0, ViewGroup.LayoutParams.MATCH_PARENT, 1.0f);

    TableRow.LayoutParams cell1Lp = new TableRow.LayoutParams(60, 120, 1.0f);

    if (initVals != null) {
        for (String Val : initVals) {
            String[] values = Val.split("=");
            if (values != null && values.length == 2 && values[0].equalsIgnoreCase("Normal")) {
                NormalCount = Integer.valueOf(values[1].trim().substring(0, values[1].trim().indexOf("(")));
                NormalProp = Double.valueOf(values[1].trim().substring(values[1].trim().indexOf("(") + 1,
                        values[1].trim().indexOf("%")));
            } else if (morphologyLabels != null) {
                for (String label : morphologyLabels) {
                    String[] lbls = label.split("=");
                    if (lbls != null && lbls.length == 2 && lbls[1].equalsIgnoreCase(values[0])) {
                        if (lbls[0].equalsIgnoreCase("Morphology Field 2")) {
                            Lb2Count = Integer
                                    .valueOf(values[1].trim().substring(0, values[1].trim().indexOf("(")));
                            Lb2Prop = Double.valueOf(values[1].trim().substring(
                                    values[1].trim().indexOf("(") + 1, values[1].trim().indexOf("%")));
                        } else if (lbls[0].equalsIgnoreCase("Morphology Field 3")) {
                            Lb3Count = Integer
                                    .valueOf(values[1].trim().substring(0, values[1].trim().indexOf("(")));
                            Lb3Prop = Double.valueOf(values[1].trim().substring(
                                    values[1].trim().indexOf("(") + 1, values[1].trim().indexOf("%")));
                        } else if (lbls[0].equalsIgnoreCase("Morphology Field 4")) {
                            Lb4Count = Integer
                                    .valueOf(values[1].trim().substring(0, values[1].trim().indexOf("(")));
                            Lb4Prop = Double.valueOf(values[1].trim().substring(
                                    values[1].trim().indexOf("(") + 1, values[1].trim().indexOf("%")));
                        } else if (lbls[0].equalsIgnoreCase("Morphology Field 5")) {
                            Lb5Count = Integer
                                    .valueOf(values[1].trim().substring(0, values[1].trim().indexOf("(")));
                            Lb5Prop = Double.valueOf(values[1].trim().substring(
                                    values[1].trim().indexOf("(") + 1, values[1].trim().indexOf("%")));
                        } else if (lbls[0].equalsIgnoreCase("Morphology Field 6")) {
                            Lb6Count = Integer
                                    .valueOf(values[1].trim().substring(0, values[1].trim().indexOf("(")));
                            Lb6Prop = Double.valueOf(values[1].trim().substring(
                                    values[1].trim().indexOf("(") + 1, values[1].trim().indexOf("%")));
                        } else if (lbls[0].equalsIgnoreCase("Morphology Field 7")) {
                            Lb7Count = Integer
                                    .valueOf(values[1].trim().substring(0, values[1].trim().indexOf("(")));
                            Lb7Prop = Double.valueOf(values[1].trim().substring(
                                    values[1].trim().indexOf("(") + 1, values[1].trim().indexOf("%")));
                        } else if (lbls[0].equalsIgnoreCase("Morphology Field 8")) {
                            Lb8Count = Integer
                                    .valueOf(values[1].trim().substring(0, values[1].trim().indexOf("(")));
                            Lb8Prop = Double.valueOf(values[1].trim().substring(
                                    values[1].trim().indexOf("(") + 1, values[1].trim().indexOf("%")));
                        }
                    }
                }
            }
        }
    }

    Constant.sum = NormalCount + Lb2Count + Lb3Count + Lb4Count + Lb5Count + Lb6Count + Lb7Count + Lb8Count;

    row = new TableRow(this);
    btn1 = new Button(this);
    btn1.setId(R.id.button1);
    btn1.setText("Normal:" + NormalCount + "(" + String.format("%.2f", NormalProp) + "%)");
    btn1.setBackground(ContextCompat.getDrawable(getApplicationContext(), R.drawable.button));
    btn1.setTextColor(ContextCompat.getColor(getApplicationContext(), R.color.white));
    row.addView(btn1, cellLp);
    table.addView(row, rowLp);
    setContentView(table);
    if (morphologyLabels != null) {
        Iterator<String> it;

        TableRow row2 = new TableRow(this);
        TableRow row3 = new TableRow(this);
        TableRow row4 = new TableRow(this);
        TableRow row5 = new TableRow(this);

        it = morphologyLabels.iterator();
        while (it.hasNext()) {
            String label = it.next();
            String text[] = label.split("=");
            if (label.contains("Morphology Field 2")) {
                btn2 = new Button(this);
                btn2.setId(R.id.button2);
                if (text != null && text.length == 2) {
                    btn2.setText(text[1] + ":" + Lb2Count + "(" + String.format("%.2f", Lb2Prop) + "%)");
                }
                btn2.setBackground(ContextCompat.getDrawable(getApplicationContext(), R.drawable.button2));
                btn2.setTextColor(ContextCompat.getColor(getApplicationContext(), R.color.white));
                btn2.setHeight(300);
                row2.addView(btn2);
            } else if (label.contains("Morphology Field 4")) {
                btn4 = new Button(this);
                btn4.setId(R.id.button4);
                if (text != null && text.length == 2) {
                    btn4.setText(text[1] + ":" + Lb4Count + "(" + String.format("%.2f", Lb4Prop) + "%)");
                }
                btn4.setBackground(ContextCompat.getDrawable(getApplicationContext(), R.drawable.button4));
                btn4.setTextColor(ContextCompat.getColor(getApplicationContext(), R.color.white));
                btn4.setHeight(300);
                row3.addView(btn4);
            } else if (label.contains("Morphology Field 6")) {
                btn6 = new Button(this);
                btn6.setId(R.id.button6);
                if (text != null && text.length == 2) {
                    btn6.setText(text[1] + ":" + Lb6Count + "(" + String.format("%.2f", Lb6Prop) + "%)");
                }
                btn6.setBackground(ContextCompat.getDrawable(getApplicationContext(), R.drawable.button6));
                btn6.setTextColor(ContextCompat.getColor(getApplicationContext(), R.color.white));
                btn6.setHeight(300);
                row4.addView(btn6);
            } else if (label.contains("Morphology Field 8")) {
                btn8 = new Button(this);
                btn8.setId(R.id.button8);
                if (text != null && text.length == 2) {
                    btn8.setText(text[1] + ":" + Lb8Count + "(" + String.format("%.2f", Lb8Prop) + "%)");
                }
                btn8.setBackground(ContextCompat.getDrawable(getApplicationContext(), R.drawable.button8));
                btn8.setTextColor(ContextCompat.getColor(getApplicationContext(), R.color.white));
                //btn = new Button(this);
                btn8.setHeight(300);
                row5.addView(btn8);
                //row5.addView(btn);
            }
        }

        it = morphologyLabels.iterator();
        while (it.hasNext()) {
            String label = it.next();
            String text[] = label.split("=");
            if (label.contains("Limit")) {
                if (text != null && text.length == 2) {
                    limit = Integer.valueOf(text[1]);
                }
            } else if (label.contains("Morphology Field 3")) {
                btn3 = new Button(this);
                btn3.setId(R.id.button3);
                if (text != null && text.length == 2) {
                    btn3.setText(text[1] + ":" + Lb3Count + "(" + String.format("%.2f", Lb3Prop) + "%)");
                }
                btn3.setBackground(ContextCompat.getDrawable(getApplicationContext(), R.drawable.button3));
                btn3.setTextColor(ContextCompat.getColor(getApplicationContext(), R.color.white));
                btn3.setHeight(300);
                row2.addView(btn3);
            } else if (label.contains("Morphology Field 5")) {
                btn5 = new Button(this);
                btn5.setId(R.id.button5);
                if (text != null && text.length == 2) {
                    btn5.setText(text[1] + ":" + Lb5Count + "(" + String.format("%.2f", Lb5Prop) + "%)");
                }
                btn5.setBackground(ContextCompat.getDrawable(getApplicationContext(), R.drawable.button5));
                btn5.setTextColor(ContextCompat.getColor(getApplicationContext(), R.color.white));
                btn5.setHeight(300);
                row3.addView(btn5);
            } else if (label.contains("Morphology Field 7")) {
                btn7 = new Button(this);
                btn7.setId(R.id.button7);
                if (text != null && text.length == 2) {
                    btn7.setText(text[1] + ":" + Lb7Count + "(" + String.format("%.2f", Lb7Prop) + "%)");
                }
                btn7.setBackground(ContextCompat.getDrawable(getApplicationContext(), R.drawable.button7));
                btn7.setTextColor(ContextCompat.getColor(getApplicationContext(), R.color.white));
                btn7.setHeight(300);
                row4.addView(btn7);
            }

        }

        table.addView(row2, rowLp);
        table.addView(row3, rowLp);
        table.addView(row4, rowLp);
        table.addView(row5, rowLp);

    }

    row = new TableRow(this);

    btn = new Button(this);
    btn.setId(R.id.button);
    btn.setText("Edit Morphology Counts");
    btn.setGravity(Gravity.CENTER);
    row.addView(btn, cell1Lp);

    tv = new TextView(this);
    tv.setId(R.id.totals);
    tv.setText("Total Count:" + Constant.sum);
    tv.setGravity(Gravity.CENTER);
    row.addView(tv, cell1Lp);
    //table.addView(row, rowLp);
    //setContentView(table);

    //row = new TableRow(this);

    table.addView(row, rowLp);
    setContentView(table);

    //initializing morphology counts
    if (initVals == null) {
        morphologyCounts = new HashSet<String>();
        if (btn1 != null) {
            String initEntry = btn1.getText().toString().trim().replace(":", "=");
            morphologyCounts.add(initEntry);
        }
        if (btn2 != null) {
            String initEntry = btn2.getText().toString().trim().replace(":", "=");
            morphologyCounts.add(initEntry);
        }
        if (btn3 != null) {
            String initEntry = btn3.getText().toString().trim().replace(":", "=");
            morphologyCounts.add(initEntry);
        }
        if (btn4 != null) {
            String initEntry = btn4.getText().toString().trim().replace(":", "=");
            morphologyCounts.add(initEntry);
        }
        if (btn5 != null) {
            String initEntry = btn5.getText().toString().trim().replace(":", "=");
            morphologyCounts.add(initEntry);
        }
        if (btn6 != null) {
            String initEntry = btn6.getText().toString().trim().replace(":", "=");
            morphologyCounts.add(initEntry);
        }
        if (btn7 != null) {
            String initEntry = btn7.getText().toString().trim().replace(":", "=");
            morphologyCounts.add(initEntry);
        }
        if (btn8 != null) {
            String initEntry = btn8.getText().toString().trim().replace(":", "=");
            morphologyCounts.add(initEntry);
        }
    } else {
        morphologyCounts = new HashSet<String>();
        for (String initVal : initVals) {
            morphologyCounts.add(initVal);
        }
    }

    if (btn != null) {
        btn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                //SharedPrefUtil.saveGroup(getApplicationContext(),Constant.PREFS_BULL_MORPHOLOGY_INFO,morphKey,morphologyCounts);
                Intent gotoEditCount = new Intent(getApplicationContext(), EditMorphologyCounts.class);
                gotoEditCount.putExtra("morphKey", morphKey);
                startActivity(gotoEditCount);
            }
        });
    }
    if (btn1 != null) {
        btn1.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                //final MediaPlayer btnChangeSound = MediaPlayer.create(getApplicationContext(),R.raw.button_changed);
                if (currentButton == null)
                    currentButton = "btn1";
                else {
                    if (!"btn1".equalsIgnoreCase(currentButton)) {
                        //make sound
                        btnChangeSound.start();
                        currentButton = "btn1";
                    }
                }
                try {
                    String[] btnStrings = btn1.getText().toString().trim().split(":");
                    String btnLbl = btnStrings[0].trim();
                    String btnCount = btnStrings[1].trim().substring(0, btnStrings[1].trim().indexOf("("));
                    String btnprop = btnStrings[1].trim().substring(btnStrings[1].trim().indexOf("(") + 1,
                            btnStrings[1].trim().indexOf("%"));

                    NormalCount = Integer.valueOf(btnCount);
                    NormalProp = Double.valueOf(btnprop);
                    if (Constant.sum < limit) {
                        String oldTxt = btnLbl + "=" + NormalCount + "(" + String.format("%.2f", NormalProp)
                                + "%" + ")";
                        morphologyCounts.remove(oldTxt);
                        NormalCount = NormalCount + 1;
                        Constant.sum = Constant.sum + 1;
                        NormalProp = (NormalCount * 100.0) / Constant.sum;
                        String newTxt = btnLbl + ":" + NormalCount + "(" + String.format("%.2f", NormalProp)
                                + "%" + ")";
                        btn1.setText(newTxt);
                        newTxt = btnLbl + "=" + NormalCount + "(" + String.format("%.2f", NormalProp) + "%"
                                + ")";
                        morphologyCounts.add(newTxt);
                    } else if (Constant.sum == limit) {
                        limitRchdSound.start();
                        Constant.sum++;
                    }

                    if (Constant.sum < limit)
                        tv.setText("Total Count:" + Constant.sum);
                    else
                        tv.setText("Total Count:" + limit);
                } catch (Exception e) {
                    e.printStackTrace();
                    Toast.makeText(getApplicationContext(), "Error occured. Restart and try again",
                            Toast.LENGTH_SHORT).show();
                }

            }
        });
    }

    if (btn2 != null) {
        tv.setText("Total Count:" + Constant.sum);
        btn2.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                //final MediaPlayer btnChangeSound = MediaPlayer.create(getApplicationContext(),R.raw.button_changed);
                if (currentButton == null)
                    currentButton = "btn2";
                else {
                    if (!"btn2".equalsIgnoreCase(currentButton)) {
                        //make sound
                        btnChangeSound.start();
                        currentButton = "btn2";
                    }
                }

                try {
                    String[] btnStrings = btn2.getText().toString().trim().split(":");
                    String btnLbl = btnStrings[0].trim();
                    String btnCount = btnStrings[1].trim().substring(0, btnStrings[1].trim().indexOf("("));
                    String btnprop = btnStrings[1].trim().substring(btnStrings[1].trim().indexOf("(") + 1,
                            btnStrings[1].trim().indexOf("%"));

                    Lb2Count = Integer.valueOf(btnCount);
                    Lb2Prop = Double.valueOf(btnprop);
                    if (Constant.sum < limit) {
                        String oldTxt = btnLbl + "=" + Lb2Count + "(" + String.format("%.2f", Lb2Prop) + "%"
                                + ")";
                        morphologyCounts.remove(oldTxt);
                        Lb2Count = Lb2Count + 1;
                        Constant.sum = Constant.sum + 1;
                        Lb2Prop = (Lb2Count * 100.0) / Constant.sum;
                        String newTxt = btnLbl + ":" + Lb2Count + "(" + String.format("%.2f", Lb2Prop) + "%"
                                + ")";
                        btn2.setText(newTxt);
                        newTxt = btnLbl + "=" + Lb2Count + "(" + String.format("%.2f", Lb2Prop) + "%" + ")";
                        morphologyCounts.add(newTxt);
                    } else if (Constant.sum == limit) {
                        limitRchdSound.start();
                        Constant.sum++;
                    }

                    if (Constant.sum < limit)
                        tv.setText("Total Count:" + Constant.sum);
                    else
                        tv.setText("Total Count:" + limit);
                } catch (Exception e) {
                    e.printStackTrace();
                    Toast.makeText(getApplicationContext(), "Error occured. Restart and try again",
                            Toast.LENGTH_SHORT).show();
                }
            }
        });
    }
    if (btn3 != null) {
        btn3.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (currentButton == null)
                    currentButton = "btn3";
                else {
                    if (!"btn3".equalsIgnoreCase(currentButton)) {
                        //make sound
                        btnChangeSound.start();
                        currentButton = "btn3";
                    }
                }

                try {
                    String[] btnStrings = btn3.getText().toString().trim().split(":");
                    String btnLbl = btnStrings[0].trim();
                    String btnCount = btnStrings[1].trim().substring(0, btnStrings[1].trim().indexOf("("));
                    String btnprop = btnStrings[1].trim().substring(btnStrings[1].trim().indexOf("(") + 1,
                            btnStrings[1].trim().indexOf("%"));

                    Lb3Count = Integer.valueOf(btnCount);
                    Lb3Prop = Double.valueOf(btnprop);
                    if (Constant.sum < limit) {
                        String oldTxt = btnLbl + "=" + Lb3Count + "(" + String.format("%.2f", Lb3Prop) + "%"
                                + ")";
                        morphologyCounts.remove(oldTxt);
                        Lb3Count = Lb3Count + 1;
                        Constant.sum = Constant.sum + 1;
                        Lb3Prop = (Lb3Count * 100.0) / Constant.sum;
                        String newTxt = btnLbl + ":" + Lb3Count + "(" + String.format("%.2f", Lb3Prop) + "%"
                                + ")";
                        btn3.setText(newTxt);
                        newTxt = btnLbl + "=" + Lb3Count + "(" + String.format("%.2f", Lb3Prop) + "%" + ")";
                        morphologyCounts.add(newTxt);
                    } else if (Constant.sum == limit) {
                        limitRchdSound.start();
                        Constant.sum++;
                    }

                    if (Constant.sum < limit)
                        tv.setText("Total Count:" + Constant.sum);
                    else
                        tv.setText("Total Count:" + limit);
                } catch (Exception e) {
                    e.printStackTrace();
                    Toast.makeText(getApplicationContext(), "Error occured. Restart and try again",
                            Toast.LENGTH_SHORT).show();
                }
            }
        });
    }
    if (btn4 != null) {
        btn4.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (currentButton == null)
                    currentButton = "btn4";
                else {
                    if (!"btn4".equalsIgnoreCase(currentButton)) {
                        //make sound
                        btnChangeSound.start();
                        currentButton = "btn4";
                    }
                }

                try {
                    String[] btnStrings = btn4.getText().toString().trim().split(":");
                    String btnLbl = btnStrings[0].trim();
                    String btnCount = btnStrings[1].trim().substring(0, btnStrings[1].trim().indexOf("("));
                    String btnprop = btnStrings[1].trim().substring(btnStrings[1].trim().indexOf("(") + 1,
                            btnStrings[1].trim().indexOf("%"));

                    Lb4Count = Integer.valueOf(btnCount);
                    Lb4Prop = Double.valueOf(btnprop);
                    if (Constant.sum < limit) {
                        String oldTxt = btnLbl + "=" + Lb4Count + "(" + String.format("%.2f", Lb4Prop) + "%"
                                + ")";
                        morphologyCounts.remove(oldTxt);
                        Lb4Count = Lb4Count + 1;
                        Constant.sum = Constant.sum + 1;
                        Lb4Prop = (Lb4Count * 100.0) / Constant.sum;
                        String newTxt = btnLbl + ":" + Lb4Count + "(" + String.format("%.2f", Lb4Prop) + "%"
                                + ")";
                        btn4.setText(newTxt);
                        newTxt = btnLbl + "=" + Lb4Count + "(" + String.format("%.2f", Lb4Prop) + "%" + ")";
                        morphologyCounts.add(newTxt);
                    } else if (Constant.sum == limit) {
                        limitRchdSound.start();
                        Constant.sum++;
                    }

                    if (Constant.sum < limit)
                        tv.setText("Total Count:" + Constant.sum);
                    else
                        tv.setText("Total Count:" + limit);
                } catch (Exception e) {
                    e.printStackTrace();
                    Toast.makeText(getApplicationContext(), "Error occured. Restart and try again",
                            Toast.LENGTH_SHORT).show();
                }
            }
        });
    }
    if (btn5 != null) {
        btn5.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (currentButton == null)
                    currentButton = "btn5";
                else {
                    if (!"btn5".equalsIgnoreCase(currentButton)) {
                        //make sound
                        btnChangeSound.start();
                        currentButton = "btn5";
                    }
                }

                try {
                    String[] btnStrings = btn5.getText().toString().trim().split(":");
                    String btnLbl = btnStrings[0].trim();
                    String btnCount = btnStrings[1].trim().substring(0, btnStrings[1].trim().indexOf("("));
                    String btnprop = btnStrings[1].trim().substring(btnStrings[1].trim().indexOf("(") + 1,
                            btnStrings[1].trim().indexOf("%"));

                    Lb5Count = Integer.valueOf(btnCount);
                    Lb5Prop = Double.valueOf(btnprop);
                    if (Constant.sum < limit) {
                        String oldTxt = btnLbl + "=" + Lb5Count + "(" + String.format("%.2f", Lb5Prop) + "%"
                                + ")";
                        morphologyCounts.remove(oldTxt);
                        Lb5Count = Lb5Count + 1;
                        Constant.sum = Constant.sum + 1;
                        Lb5Prop = (Lb5Count * 100.0) / Constant.sum;
                        String newTxt = btnLbl + ":" + Lb5Count + "(" + String.format("%.2f", Lb5Prop) + "%"
                                + ")";
                        btn5.setText(newTxt);
                        newTxt = btnLbl + "=" + Lb5Count + "(" + String.format("%.2f", Lb5Prop) + "%" + ")";
                        morphologyCounts.add(newTxt);
                    } else if (Constant.sum == limit) {
                        limitRchdSound.start();
                        Constant.sum++;
                    }

                    if (Constant.sum < limit)
                        tv.setText("Total Count:" + Constant.sum);
                    else
                        tv.setText("Total Count:" + limit);
                } catch (Exception e) {
                    e.printStackTrace();
                    Toast.makeText(getApplicationContext(), "Error occured. Restart and try again",
                            Toast.LENGTH_SHORT).show();
                }
            }
        });
    }
    if (btn6 != null) {
        btn6.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (currentButton == null)
                    currentButton = "btn6";
                else {
                    if (!"btn6".equalsIgnoreCase(currentButton)) {
                        //make sound
                        btnChangeSound.start();
                        currentButton = "btn6";
                    }
                }

                try {
                    String[] btnStrings = btn6.getText().toString().trim().split(":");
                    String btnLbl = btnStrings[0].trim();
                    String btnCount = btnStrings[1].trim().substring(0, btnStrings[1].trim().indexOf("("));
                    String btnprop = btnStrings[1].trim().substring(btnStrings[1].trim().indexOf("(") + 1,
                            btnStrings[1].trim().indexOf("%"));

                    Lb6Count = Integer.valueOf(btnCount);
                    Lb6Prop = Double.valueOf(btnprop);
                    if (Constant.sum < limit) {
                        String oldTxt = btnLbl + "=" + Lb6Count + "(" + String.format("%.2f", Lb6Prop) + "%"
                                + ")";
                        morphologyCounts.remove(oldTxt);
                        Lb6Count = Lb6Count + 1;
                        Constant.sum = Constant.sum + 1;
                        Lb6Prop = (Lb6Count * 100.0) / Constant.sum;
                        String newTxt = btnLbl + ":" + Lb6Count + "(" + String.format("%.2f", Lb6Prop) + "%"
                                + ")";
                        btn6.setText(newTxt);
                        newTxt = btnLbl + "=" + Lb6Count + "(" + String.format("%.2f", Lb6Prop) + "%" + ")";
                        morphologyCounts.add(newTxt);
                    } else if (Constant.sum == limit) {
                        limitRchdSound.start();
                        Constant.sum++;
                    }

                    if (Constant.sum < limit)
                        tv.setText("Total Count:" + Constant.sum);
                    else
                        tv.setText("Total Count:" + limit);
                } catch (Exception e) {
                    e.printStackTrace();
                    Toast.makeText(getApplicationContext(), "Error occured. Restart and try again",
                            Toast.LENGTH_SHORT).show();
                }
            }
        });
    }
    if (btn7 != null) {
        btn7.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (currentButton == null)
                    currentButton = "btn7";
                else {
                    if (!"btn7".equalsIgnoreCase(currentButton)) {
                        //make sound
                        btnChangeSound.start();
                        currentButton = "btn7";
                    }
                }

                try {
                    String[] btnStrings = btn7.getText().toString().trim().split(":");
                    String btnLbl = btnStrings[0].trim();
                    String btnCount = btnStrings[1].trim().substring(0, btnStrings[1].trim().indexOf("("));
                    String btnprop = btnStrings[1].trim().substring(btnStrings[1].trim().indexOf("(") + 1,
                            btnStrings[1].trim().indexOf("%"));

                    Lb7Count = Integer.valueOf(btnCount);
                    Lb7Prop = Double.valueOf(btnprop);
                    if (Constant.sum < limit) {
                        String oldTxt = btnLbl + "=" + Lb7Count + "(" + String.format("%.2f", Lb7Prop) + "%"
                                + ")";
                        morphologyCounts.remove(oldTxt);
                        Lb7Count = Lb7Count + 1;
                        Constant.sum = Constant.sum + 1;
                        Lb7Prop = (Lb7Count * 100.0) / Constant.sum;
                        String newTxt = btnLbl + ":" + Lb7Count + "(" + String.format("%.2f", Lb7Prop) + "%"
                                + ")";
                        btn7.setText(newTxt);
                        newTxt = btnLbl + "=" + Lb7Count + "(" + String.format("%.2f", Lb7Prop) + "%" + ")";
                        morphologyCounts.add(newTxt);
                    } else if (Constant.sum == limit) {
                        limitRchdSound.start();
                        Constant.sum++;
                    }

                    if (Constant.sum < limit)
                        tv.setText("Total Count:" + Constant.sum);
                    else
                        tv.setText("Total Count:" + limit);
                } catch (Exception e) {
                    e.printStackTrace();
                    Toast.makeText(getApplicationContext(), "Error occured. Restart and try again",
                            Toast.LENGTH_SHORT).show();
                }
            }
        });
    }
    if (btn8 != null) {
        btn8.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (currentButton == null)
                    currentButton = "btn8";
                else {
                    if (!"btn8".equalsIgnoreCase(currentButton)) {
                        //make sound
                        btnChangeSound.start();
                        currentButton = "btn8";
                    }
                }

                try {
                    String[] btnStrings = btn8.getText().toString().trim().split(":");
                    String btnLbl = btnStrings[0].trim();
                    String btnCount = btnStrings[1].trim().substring(0, btnStrings[1].trim().indexOf("("));
                    String btnprop = btnStrings[1].trim().substring(btnStrings[1].trim().indexOf("(") + 1,
                            btnStrings[1].trim().indexOf("%"));

                    Lb8Count = Integer.valueOf(btnCount);
                    Lb8Prop = Double.valueOf(btnprop);
                    if (Constant.sum < limit) {
                        String oldTxt = btnLbl + "=" + Lb8Count + "(" + String.format("%.2f", Lb8Prop) + "%"
                                + ")";
                        morphologyCounts.remove(oldTxt);
                        Lb8Count = Lb8Count + 1;
                        Constant.sum = Constant.sum + 1;
                        Lb8Prop = (Lb8Count * 100.0) / Constant.sum;
                        String newTxt = btnLbl + ":" + Lb8Count + "(" + String.format("%.2f", Lb8Prop) + "%"
                                + ")";
                        btn8.setText(newTxt);
                        newTxt = btnLbl + "=" + Lb8Count + "(" + String.format("%.2f", Lb8Prop) + "%" + ")";
                        morphologyCounts.add(newTxt);
                    } else if (Constant.sum == limit) {
                        limitRchdSound.start();
                        Constant.sum++;
                    }

                    if (Constant.sum < limit)
                        tv.setText("Total Count:" + Constant.sum);
                    else
                        tv.setText("Total Count:" + limit);
                } catch (Exception e) {
                    e.printStackTrace();
                    Toast.makeText(getApplicationContext(), "Error occured. Restart and try again",
                            Toast.LENGTH_SHORT).show();
                }
            }
        });
    }

}

From source file:com.vonglasow.michael.satstat.MainActivity.java

private final void addWifiResult(ScanResult result) {
    final ScanResult r = result;
    android.view.View.OnClickListener clis = new android.view.View.OnClickListener() {

        @Override/*from   w  ww.  j  av  a 2  s  .  c  o  m*/
        public void onClick(View v) {
            onWifiEntryClick(r.BSSID);
        }
    };

    View divider = new View(wifiAps.getContext());
    divider.setLayoutParams(new TableRow.LayoutParams(LayoutParams.MATCH_PARENT, 1));
    divider.setBackgroundColor(getResources().getColor(android.R.color.tertiary_text_dark));
    divider.setOnClickListener(clis);
    wifiAps.addView(divider);

    LinearLayout wifiLayout = new LinearLayout(wifiAps.getContext());
    wifiLayout.setLayoutParams(
            new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT));
    wifiLayout.setOrientation(LinearLayout.HORIZONTAL);
    wifiLayout.setWeightSum(22);
    wifiLayout.setMeasureWithLargestChildEnabled(false);

    ImageView wifiType = new ImageView(wifiAps.getContext());
    wifiType.setLayoutParams(new TableRow.LayoutParams(0, LayoutParams.MATCH_PARENT, 3));
    if (WifiCapabilities.isAdhoc(result)) {
        wifiType.setImageResource(R.drawable.ic_content_wifi_adhoc);
    } else if ((WifiCapabilities.isEnterprise(result))
            || (WifiCapabilities.getScanResultSecurity(result) == WifiCapabilities.EAP)) {
        wifiType.setImageResource(R.drawable.ic_content_wifi_eap);
    } else if (WifiCapabilities.getScanResultSecurity(result) == WifiCapabilities.PSK) {
        wifiType.setImageResource(R.drawable.ic_content_wifi_psk);
    } else if (WifiCapabilities.getScanResultSecurity(result) == WifiCapabilities.WEP) {
        wifiType.setImageResource(R.drawable.ic_content_wifi_wep);
    } else if (WifiCapabilities.getScanResultSecurity(result) == WifiCapabilities.OPEN) {
        wifiType.setImageResource(R.drawable.ic_content_wifi_open);
    } else {
        wifiType.setImageResource(R.drawable.ic_content_wifi_unknown);
    }

    wifiType.setScaleType(ScaleType.CENTER);
    wifiLayout.addView(wifiType);

    TableLayout wifiDetails = new TableLayout(wifiAps.getContext());
    wifiDetails.setLayoutParams(new TableRow.LayoutParams(0, LayoutParams.WRAP_CONTENT, 19));
    TableRow innerRow1 = new TableRow(wifiAps.getContext());
    TextView newMac = new TextView(wifiAps.getContext());
    newMac.setLayoutParams(new TableRow.LayoutParams(0, LayoutParams.WRAP_CONTENT, 14));
    newMac.setTextAppearance(wifiAps.getContext(), android.R.style.TextAppearance_Medium);
    newMac.setText(result.BSSID);
    innerRow1.addView(newMac);
    TextView newCh = new TextView(wifiAps.getContext());
    newCh.setLayoutParams(new TableRow.LayoutParams(0, LayoutParams.WRAP_CONTENT, 2));
    newCh.setTextAppearance(wifiAps.getContext(), android.R.style.TextAppearance_Medium);
    newCh.setText(getChannelFromFrequency(result.frequency));
    innerRow1.addView(newCh);
    TextView newLevel = new TextView(wifiAps.getContext());
    newLevel.setLayoutParams(new TableRow.LayoutParams(0, LayoutParams.WRAP_CONTENT, 3));
    newLevel.setTextAppearance(wifiAps.getContext(), android.R.style.TextAppearance_Medium);
    newLevel.setText(String.valueOf(result.level));
    innerRow1.addView(newLevel);
    innerRow1.setOnClickListener(clis);
    wifiDetails.addView(innerRow1,
            new TableLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));

    TableRow innerRow2 = new TableRow(wifiAps.getContext());
    TextView newSSID = new TextView(wifiAps.getContext());
    newSSID.setLayoutParams(new TableRow.LayoutParams(0, LayoutParams.WRAP_CONTENT, 19));
    newSSID.setTextAppearance(wifiAps.getContext(), android.R.style.TextAppearance_Small);
    newSSID.setText(result.SSID);
    innerRow2.addView(newSSID);
    innerRow2.setOnClickListener(clis);
    wifiDetails.addView(innerRow2,
            new TableLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));

    wifiLayout.addView(wifiDetails);
    wifiLayout.setOnClickListener(clis);
    wifiAps.addView(wifiLayout);
}