List of usage examples for android.widget TableRow addView
public void addView(View child)
Adds a child view.
From source file:com.vonglasow.michael.satstat.MainActivity.java
protected static void showCellLte(CellTowerLte cell) { TableRow row = new TableRow(rilLteCells.getContext()); row.setWeightSum(29);/* w w w. java2 s. c o m*/ TextView newType = new TextView(rilLteCells.getContext()); newType.setLayoutParams(new TableRow.LayoutParams(0, LayoutParams.WRAP_CONTENT, 2)); newType.setTextAppearance(rilLteCells.getContext(), android.R.style.TextAppearance_Medium); newType.setTextColor( rilLteCells.getContext().getResources().getColor(getColorFromGeneration(cell.getGeneration()))); newType.setText(rilLteCells.getContext().getResources().getString(R.string.smallDot)); row.addView(newType); TextView newMcc = new TextView(rilLteCells.getContext()); newMcc.setLayoutParams(new TableRow.LayoutParams(0, LayoutParams.WRAP_CONTENT, 3)); newMcc.setTextAppearance(rilLteCells.getContext(), android.R.style.TextAppearance_Medium); newMcc.setText(formatCellData(rilLteCells.getContext(), "%03d", cell.getMcc())); row.addView(newMcc); TextView newMnc = new TextView(rilLteCells.getContext()); newMnc.setLayoutParams(new TableRow.LayoutParams(0, LayoutParams.WRAP_CONTENT, 3)); newMnc.setTextAppearance(rilLteCells.getContext(), android.R.style.TextAppearance_Medium); newMnc.setText(formatCellData(rilLteCells.getContext(), "%02d", cell.getMnc())); row.addView(newMnc); TextView newTac = new TextView(rilLteCells.getContext()); newTac.setLayoutParams(new TableRow.LayoutParams(0, LayoutParams.WRAP_CONTENT, 5)); newTac.setTextAppearance(rilLteCells.getContext(), android.R.style.TextAppearance_Medium); newTac.setText(formatCellData(rilLteCells.getContext(), null, cell.getTac())); row.addView(newTac); TextView newCi = new TextView(rilLteCells.getContext()); newCi.setLayoutParams(new TableRow.LayoutParams(0, LayoutParams.WRAP_CONTENT, 9)); newCi.setTextAppearance(rilLteCells.getContext(), android.R.style.TextAppearance_Medium); newCi.setText(formatCellData(rilLteCells.getContext(), null, cell.getCi())); row.addView(newCi); TextView newPci = new TextView(rilLteCells.getContext()); newPci.setLayoutParams(new TableRow.LayoutParams(0, LayoutParams.WRAP_CONTENT, 3)); newPci.setTextAppearance(rilLteCells.getContext(), android.R.style.TextAppearance_Medium); newPci.setText(formatCellData(rilLteCells.getContext(), null, cell.getPci())); row.addView(newPci); TextView newDbm = new TextView(rilLteCells.getContext()); newDbm.setLayoutParams(new TableRow.LayoutParams(0, LayoutParams.WRAP_CONTENT, 4)); newDbm.setTextAppearance(rilLteCells.getContext(), android.R.style.TextAppearance_Medium); newDbm.setText(formatCellDbm(rilLteCells.getContext(), null, cell.getDbm())); row.addView(newDbm); rilLteCells.addView(row, new TableLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT)); }
From source file:hongik.android.project.best.HistoryActivity.java
public void drawHistory() { int rowCnt = historyTable.getChildCount(); Log.i("ROWCOUNT", rowCnt + ""); String query = "func=history&cid=" + cid; DBConnector conn = new DBConnector(query); conn.start();//from w w w. j a v a2s .c o m try { conn.join(); JSONObject jsonResult = conn.getResult(); boolean result = (boolean) jsonResult.get("result"); if (!result) return; TableRow motive = (TableRow) historyTable.getChildAt(1); JSONArray jsonArray = jsonResult.getJSONArray("values"); for (int i = 0; i < jsonArray.length(); i++) { TableRow tbRow = new TableRow(this); final TextViewPlus[] tbCols = new TextViewPlus[4]; JSONObject json = jsonArray.getJSONObject(i); String[] elements = new String[4]; elements[0] = json.getString("SNAME"); elements[1] = Double.parseDouble(json.getString("GRADE")) + ""; elements[2] = json.getString("NOTE"); elements[3] = json.getString("DAY"); final String license = json.getString("LICENSE#"); if (elements[2].length() > 14) elements[2] = elements[2].substring(0, 14) + "..."; for (int j = 0; j < 4; j++) { tbCols[j] = new TextViewPlus(this); tbCols[j].setText(elements[j]); tbCols[j].setLayoutParams(motive.getChildAt(j).getLayoutParams()); tbCols[j].setGravity(Gravity.CENTER); tbCols[j].setTypeface(Typeface.createFromAsset(tbCols[j].getContext().getAssets(), "InterparkGothicBold.ttf")); final HistoryActivity originActivity = this; tbCols[j].setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Intent reviewIntent = new Intent(originActivity, ReviewDetailActivity.class); reviewIntent.putExtra("ACCESS", "HISTORY"); reviewIntent.putExtra("CID", cid); reviewIntent.putExtra("LICENSE", license); startActivity(reviewIntent); } }); Log.i("History", "COL" + j + ":" + elements[j]); tbRow.addView(tbCols[j]); } historyTable.addView(tbRow); } for (int i = 1; i < rowCnt; i++) { historyTable.removeViewAt(1); } } catch (Exception e) { e.printStackTrace(); } }
From source file:de.ribeiro.android.gso.dataclasses.Pager.java
/** * Erstellt eine Stundeplan Seite des ViewPagers, inkl Header und Footer * <p/>// www . j a v a2s . c o m * Hier wird die Wochenansicht generiert * * @param weekData * @param ctxt * @return * @author Tobias Janssen */ private View createWeekPage(WeekData weekData) { // in die Page kommen alle Elemente dieser Ansicht View page = inflater.inflate(R.layout.weeklayout, null); TableLayout tl = (TableLayout) page.findViewById(R.id.weekTimetable); LinearLayoutBordered ll = new LinearLayoutBordered(context); // Tagesberschrift erstellen: TableRow tr = new TableRow(context); for (int x = Calendar.SUNDAY; x < Calendar.SATURDAY; x++) { // einen neuen Rahmen fr das Tabellenfeld vorbereiten ll = new LinearLayoutBordered(context); ll.setBorderRight(true); ll.setBorderBottom(true); ll.setBorderTop(true); ll.setBorderSize(1); ll.setBackgroundColor(Color.WHITE); View textview = inflater.inflate(R.layout.textview, null); TextView tv = (TextView) textview.findViewById(R.id.textview); // berschriftentextgre einstellen tv.setTextSize(textSize); if (x == Calendar.SUNDAY) { tv.setText(timeslots[0]); tv.setTextColor(Color.parseColor("#3A599A")); } else { tv.setText(ResolveWeekDay(x)); } ll.addView(tv); tr.addView(ll); } tl.addView(tr); // den Stundenplan zusammensetzten // fr jeden tag List<Lesson> stunden = GetSchulstunden(); for (int y = 0; y < stunden.size(); y++) { tr = new TableRow(context); for (int x = Calendar.SUNDAY; x <= Calendar.FRIDAY; x++) { if (x == Calendar.SUNDAY) { addColumn(timeslots[y + 1], "#3A599A", tr); } else { // alle events dieses Tages durchgehen ob die zu dieser // schulstunde passen boolean lessonAdded = false; TextView lastTextView = null; for (ICalEvent ev : weekData.events) { // ist event an diesem tag? if (ev.DTSTART.get(Calendar.DAY_OF_WEEK) == x) { // ja // ist event zu dieser schulstunde? Time st = new Time(); st.set(ev.DTSTART.getTimeInMillis()); int start = GetSchulstundeOfDateTime(st); Time et = new Time(); et.set(ev.DTEND.getTimeInMillis() - 60000); int end = GetSchulstundeOfDateTime(et); // ende der schulstunde herausfinden if (((start != end) && y >= start && y <= end) || start == y || end == y) { // ja event ist in dieser stunde // ist eine Doopelbelegung fr diese Stunde? if (lessonAdded && lastTextView != null) { // ja, doppelbelegung String newText = ""; if (weekData.typeId.equalsIgnoreCase("4")) { newText = lastTextView.getText() + "\r\n" + ev.DESCRIPTION + " " + ev.SUMMARY; } else { newText = lastTextView.getText() + "\r\n" + ev.DESCRIPTION.replace(weekData.elementId, "") + " " + ev.SUMMARY + " " + ev.LOCATION; } lastTextView.setText(newText); } else { // prfen, ob dieses event eine gelschte // stunde ist if (ev.UID.equalsIgnoreCase("deleted")) { // gelschtes event lastTextView = addColumn(" --- " + " " + " --- " + " " + " --- ", "#FF0000", tr); } else { String color = "#3A599A"; if (ev.UID.equalsIgnoreCase("diff")) color = "#FF0000"; if (weekData.typeId.equalsIgnoreCase("4")) { lastTextView = addColumn(ev.DESCRIPTION + " " + ev.SUMMARY, color, tr); } else { lastTextView = addColumn(ev.DESCRIPTION.replace(weekData.elementId, "") + " " + ev.SUMMARY + " " + ev.LOCATION, color, tr); } } } lessonAdded = true; } } } if (!lessonAdded) { // ja event ist in dieser stunde addColumn("", "#3A599A", tr); } } } tl.addView(tr); } TextView syncTime = (TextView) page.findViewById(R.id.syncTime); Calendar sync = new GregorianCalendar(); sync.setTimeInMillis(weekData.syncTime); String minute = String.valueOf(sync.get(Calendar.MINUTE)); if (minute.length() == 1) minute = "0" + minute; syncTime.setText(weekData.elementId + " | Stand vom " + sync.get(Calendar.DAY_OF_MONTH) + "." + (sync.get(Calendar.MONTH) + 1) + "." + sync.get(Calendar.YEAR) + " " + sync.get(Calendar.HOUR_OF_DAY) + ":" + minute + " Uhr"); return page; }
From source file:com.adarshahd.indianrailinfo.donate.PNRStat.java
private void createTableLayoutPsnDtls() { if (mPageResult.contains("FLUSHED PNR / ") || mPageResult.contains("Invalid PNR")) { mTextViewPNRSts.setText("The PNR entered is either invalid or expired! Please check."); mFrameLayout.removeAllViews();/*from www .j a va2 s . co m*/ mFrameLayout.addView(mTextViewPNRSts); mStrPassengerDetails = null; return; } if (mPageResult.contains("Connectivity Failure") || mPageResult.contains("try again")) { mTextViewPNRSts.setText("Looks like server is busy or currently unavailable. Please try again later!"); mFrameLayout.removeAllViews(); mFrameLayout.addView(mTextViewPNRSts); mStrPassengerDetails = null; return; } List<List<String>> passengersList; if (mPassengerDetails == null || mPassengerDetails.getPNR() != mPNRNumber) { Elements elements = Jsoup.parse(mPageResult).select("table tr td:containsOwn(S. No.)"); Iterator iterator = null; try { iterator = elements.first().parent().parent().getElementsByTag("tr").iterator(); } catch (Exception e) { Log.i("PNRStat", mPageResult); return; } passengersList = new ArrayList<List<String>>(); List<String> list; Element tmp; while (iterator.hasNext()) { tmp = (Element) iterator.next(); if (tmp.toString().contains("Passenger")) { list = new ArrayList<String>(); list.add(tmp.select("td").get(0).text()); list.add(tmp.select("td").get(1).text()); list.add(tmp.select("td").get(2).text()); if (!tmp.select("td").get(2).text().toUpperCase().contains("CNF") && !tmp.select("td").get(2).text().toUpperCase().contains("CAN")) { isWaitingList = true; } passengersList.add(list); } } mPassengerDetails = new PassengerDetails(passengersList, mPNRNumber); } else { passengersList = mPassengerDetails.getPassengerList(); } mTableLayoutPsn = new TableLayout(mActivity); TableRow row; TextView tv1, tv2, tv3, tv4; mStrPassengerDetails = new ArrayList<String>(); int current; mTableLayoutPsn.setLayoutParams(new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT)); for (int i = 0; i < passengersList.size(); ++i) { current = i + 1; row = new TableRow(mActivity); row.setLayoutParams(new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT)); tv1 = new TextView(mActivity); tv2 = new TextView(mActivity); tv3 = new TextView(mActivity); tv4 = new TextView(mActivity); tv1.setText("" + (i + 1) + "."); tv2.setText(" " + passengersList.get(i).get(0)); tv3.setText(" " + passengersList.get(i).get(1)); tv4.setText(" " + passengersList.get(i).get(2)); tv1.setTextAppearance(mActivity, android.R.style.TextAppearance_DeviceDefault_Medium); tv2.setTextAppearance(mActivity, android.R.style.TextAppearance_DeviceDefault_Medium); tv3.setTextAppearance(mActivity, android.R.style.TextAppearance_DeviceDefault_Medium); tv4.setTextAppearance(mActivity, android.R.style.TextAppearance_DeviceDefault_Medium); tv1.setPadding(10, 10, 10, 10); tv2.setPadding(10, 10, 10, 10); tv3.setPadding(10, 10, 10, 10); tv4.setPadding(10, 10, 10, 10); row.addView(tv1); row.addView(tv2); row.addView(tv3); row.addView(tv4); row.setBackgroundResource(R.drawable.card_background); row.setGravity(Gravity.CENTER_HORIZONTAL | Gravity.CENTER_VERTICAL); mTableLayoutPsn.addView(row); String strPsn = "" + current + ". " + passengersList.get(i).get(0) + " " + passengersList.get(i).get(1) + " " + passengersList.get(i).get(2); mStrPassengerDetails.add(strPsn); } }
From source file:com.mobicage.rogerthat.plugins.messaging.ServiceMessageDetailActivity.java
private void addButton(final String senderName, String myEmail, boolean somebodyAnswered, boolean canEdit, TableLayout tableLayout, final ButtonTO button) { TableRow row = new TableRow(this); tableLayout.addView(row);// w ww .j a v a 2 s . c o m row.setLayoutParams(new TableLayout.LayoutParams(TableLayout.LayoutParams.WRAP_CONTENT, TableLayout.LayoutParams.WRAP_CONTENT, 1)); // XXX: inconsistent margin between 2 rows final Button buttonView = new Button(this); buttonView.setMinWidth(UIUtils.convertDipToPixels(this, 100)); buttonView.setText(button.caption); buttonView.setTextColor(getResources().getColor(android.R.color.primary_text_dark)); if (somebodyAnswered) buttonView.setGravity(Gravity.RIGHT | Gravity.CENTER_VERTICAL); else { buttonView.setWidth(mDisplayWidth - UIUtils.convertDipToPixels(this, 12)); } buttonView.setTextSize(19); row.addView(buttonView); final LinearLayout container = (LinearLayout) getLayoutInflater().inflate(R.layout.message_button_detail, null); container.setGravity(Gravity.LEFT | Gravity.CENTER_VERTICAL); boolean buttonSelectedByMe = false; for (MemberStatusTO status : mCurrentMessage.members) { if ((status.status & MessagingPlugin.STATUS_ACKED) == MessagingPlugin.STATUS_ACKED && ((button.id == null && status.button_id == null) || (button.id != null && button.id.equals(status.button_id)))) { getLayoutInflater().inflate(R.layout.avatar, container); ImageView avatar = (ImageView) container.getChildAt(container.getChildCount() - 1); setAvatar(avatar, status.member); if (status.member.equals(myEmail)) buttonSelectedByMe = true; int dp42 = UIUtils.convertDipToPixels(this, 42); int dp2 = UIUtils.convertDipToPixels(this, 1); LinearLayout.LayoutParams lp = (LinearLayout.LayoutParams) avatar.getLayoutParams(); lp.setMargins(0, dp2, 0, 0); lp.width = dp42; lp.height = dp42; } } row.addView(container); boolean hasAction = button.action != null && !"".equals(button.action); final boolean buttonIsEnabled = canEdit && (mCurrentMessage.form != null || !buttonSelectedByMe || hasAction); buttonView.setEnabled(buttonIsEnabled); int color; if (button.id == null || mCurrentMessage.form != null && Message.POSITIVE.equals(button.id)) { color = buttonIsEnabled ? Message.GREEN_BUTTON_COLOR : Message.GREENGRAY_BUTTON_COLOR; } else if (mCurrentMessage.form != null && Message.NEGATIVE.equals(button.id)) { color = buttonIsEnabled ? Message.RED_BUTTON_COLOR : Message.REDGRAY_BUTTON_COLOR; } else { color = buttonIsEnabled ? Message.BLUE_BUTTON_COLOR : Message.BLUEGRAY_BUTTON_COLOR; } buttonView.getBackground().setColorFilter(color, PorterDuff.Mode.MULTIPLY); buttonView.setOnClickListener(new SafeViewOnClickListener() { @Override public void safeOnClick(View v) { T.UI(); executeButtonClick(button, container, true); } }); final HorizontalScrollView scroller = (HorizontalScrollView) findViewById(R.id.button_scroller); scroller.post(new SafeRunnable() { @Override protected void safeRun() throws Exception { scroller.fullScroll(ScrollView.FOCUS_RIGHT); } }); }
From source file:com.adarshahd.indianrailinfo.donate.TrainDetails.java
private void createTableLayoutTrainAvailability() { if (mPage.contains("SORRY")) { TextView textViewTrnDtls = new TextView(mActivity); textViewTrnDtls.setText("Not a valid class, Please select a different class and try again."); textViewTrnDtls.setTextAppearance(mActivity, android.R.style.TextAppearance_DeviceDefault_Large); textViewTrnDtls.setPadding(10, 10, 10, 10); textViewTrnDtls.setTextColor(Color.RED); mFrameLayout.removeAllViews();//w w w .j a v a 2s . c o m mFrameLayout.addView(textViewTrnDtls); if (mDialog.isShowing()) { mDialog.cancel(); } return; } if (mPage.contains("ISL Of")) { TextView textViewTrnDtls = new TextView(mActivity); textViewTrnDtls.setText("Station is not in ISL Of the Train. \nPlease modify the source/destination!"); textViewTrnDtls.setTextAppearance(mActivity, android.R.style.TextAppearance_DeviceDefault_Large); textViewTrnDtls.setPadding(10, 10, 10, 10); textViewTrnDtls.setTextColor(Color.RED); mFrameLayout.removeAllViews(); mFrameLayout.addView(textViewTrnDtls); if (mDialog.isShowing()) { mDialog.cancel(); } return; } if (mPage.contains("ERROR")) { TextView textViewTrnDtls = new TextView(mActivity); textViewTrnDtls.setText("Your request resulted in an error.\nPlease check!"); textViewTrnDtls.setTextAppearance(mActivity, android.R.style.TextAppearance_DeviceDefault_Large); textViewTrnDtls.setPadding(10, 10, 10, 10); textViewTrnDtls.setTextColor(Color.RED); mFrameLayout.removeAllViews(); mFrameLayout.addView(textViewTrnDtls); if (mDialog.isShowing()) { mDialog.cancel(); } return; } if (mPage.contains("Network Connectivity")) { TextView textViewTrnDtls = new TextView(mActivity); textViewTrnDtls.setText("Looks like the server is busy.\nPlease try later!"); textViewTrnDtls.setTextAppearance(mActivity, android.R.style.TextAppearance_DeviceDefault_Large); textViewTrnDtls.setPadding(10, 10, 10, 10); textViewTrnDtls.setTextColor(Color.RED); mFrameLayout.removeAllViews(); mFrameLayout.addView(textViewTrnDtls); if (mDialog.isShowing()) { mDialog.cancel(); } return; } if (mPage.contains("unavailable")) { TextView textViewTrnDtls = new TextView(mActivity); textViewTrnDtls.setText( "Response from server:\n\nYour request could not be processed now.\nPlease try again later!"); textViewTrnDtls.setTextAppearance(mActivity, android.R.style.TextAppearance_DeviceDefault_Large); textViewTrnDtls.setPadding(10, 10, 10, 10); textViewTrnDtls.setTextColor(Color.RED); mFrameLayout.removeAllViews(); mFrameLayout.addView(textViewTrnDtls); if (mDialog.isShowing()) { mDialog.cancel(); } return; } if (mDetails == null || !mDetails.getTrainNumber().equals(mTrainNumber)) { Iterator iterator = null; try { iterator = mElements.first().parent().parent().parent().getElementsByTag("tr").iterator(); } catch (Exception e) { Log.i("TrainDetails", mPage); e.printStackTrace(); return; } mListAv = new ArrayList<List<String>>(); List<String> list; Element tmp; tmp = (Element) iterator.next(); list = new ArrayList<String>(); list.add(tmp.select("th").get(0).text()); list.add("Date"); list.add(tmp.select("th").get(2).text()); //list.add(tmp.select("th").get(3).text()); mListAv.add(list); while (iterator.hasNext()) { tmp = (Element) iterator.next(); if (!tmp.hasText()) { continue; } list = new ArrayList<String>(); list.add(tmp.select("td").get(0).text()); list.add(tmp.select("td").get(1).text()); list.add(tmp.select("td").get(2).text()); //list.add(tmp.select("td").get(3).text()); mListAv.add(list); } mDetails = new Details(mListAv, TrainEnquiry.AVAILABILITY, mTrainNumber); } else { mListAv = mDetails.getList(); } mTblLayoutAv = new TableLayout(mActivity); TableRow row; TextView tv1, tv2, tv3; mTblLayoutAv.setLayoutParams(new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT)); for (int i = 0; i < mListAv.size(); i++) { row = new TableRow(mActivity); tv1 = new TextView(mActivity); tv2 = new TextView(mActivity); tv3 = new TextView(mActivity); //tv4 = new TextView(mActivity); tv1.setText(" " + mListAv.get(i).get(0)); tv2.setText(" " + mListAv.get(i).get(1)); tv3.setText(" " + mListAv.get(i).get(2)); //tv4.setText(" " + mListAv.get(i).get(3)); tv1.setTextAppearance(mActivity, android.R.style.TextAppearance_DeviceDefault_Medium); tv2.setTextAppearance(mActivity, android.R.style.TextAppearance_DeviceDefault_Medium); tv3.setTextAppearance(mActivity, android.R.style.TextAppearance_DeviceDefault_Medium); //tv4.setTextAppearance(mActivity,android.R.style.TextAppearance_DeviceDefault_Medium); tv1.setPadding(5, 5, 5, 5); tv2.setPadding(5, 5, 5, 5); tv3.setPadding(5, 5, 5, 5); //tv4.setPadding(5,5,5,5); /*tv2.setBackgroundResource(R.drawable.card_divider); tv3.setBackgroundResource(R.drawable.card_divider); tv4.setBackgroundResource(R.drawable.card_divider);*/ row.addView(tv1); row.addView(tv2); row.addView(tv3); //row.addView(tv4); row.setBackgroundResource(R.drawable.button_selector); row.setGravity(Gravity.CENTER_HORIZONTAL | Gravity.CENTER_VERTICAL); row.setOnClickListener(this); mTblLayoutAv.addView(row); } LinearLayout ll = new LinearLayout(mActivity); ScrollView scrollView = new ScrollView(mActivity); TextView textViewTrnDtls = new TextView(mActivity); textViewTrnDtls.setText("Availability details:"); textViewTrnDtls.setTextAppearance(mActivity, android.R.style.TextAppearance_DeviceDefault_Large); textViewTrnDtls.setPadding(10, 10, 10, 10); ll.setLayoutParams(new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT)); ll.setOrientation(LinearLayout.VERTICAL); ll.addView(textViewTrnDtls); ll.addView(mTblLayoutAv); scrollView.addView(ll); mFrameLayout.removeAllViews(); mFrameLayout.addView(scrollView); if (mDialog.isShowing()) { mDialog.cancel(); } }
From source file:de.tobiasbielefeld.solitaire.ui.Statistics.java
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activty_statistics); int padding = (int) getResources().getDimension(R.dimen.statistics_table_padding); int textSize = getResources().getInteger(R.integer.statistics_text_size); boolean addedEntries = false; TableRow row; if (getSupportActionBar() != null) getSupportActionBar().setDisplayHomeAsUpEnabled(true); tableLayout = (TableLayout) findViewById(R.id.statisticsTableHighScores); textWonGames = (TextView) findViewById(R.id.statisticsTextViewGamesWon); textWinPercentage = (TextView) findViewById(R.id.statisticsTextViewWinPercentage); loadData();// w w w . j a va 2 s . co m for (int i = 0; i < Scores.MAX_SAVED_SCORES; i++) { //for each entry in highScores, add a new view with it if (scores.get(i, 0) == 0) //if the score is zero, don't show it continue; if (!addedEntries) addedEntries = true; row = new TableRow(this); TextView textView1 = new TextView(this); TextView textView2 = new TextView(this); TextView textView3 = new TextView(this); TextView textView4 = new TextView(this); textView1.setText(String.format(Locale.getDefault(), "%s", scores.get(i, 0))); textView2.setText(String.format(Locale.getDefault(), "%02d:%02d:%02d", //add it to the view scores.get(i, 1) / 3600, (scores.get(i, 1) % 3600) / 60, (scores.get(i, 1) % 60))); textView3.setText(DateFormat.getDateInstance(DateFormat.SHORT).format(scores.get(i, 2))); //textView4.setText(DateFormat.getTimeInstance(DateFormat.SHORT).format(scores.get(i,2))); textView4.setText(new SimpleDateFormat("HH:mm", Locale.getDefault()).format(scores.get(i, 2))); textView1.setPadding(padding, 0, padding, 0); textView2.setPadding(padding, 0, padding, 0); textView3.setPadding(padding, 0, padding, 0); textView4.setPadding(padding, 0, padding, 0); textView1.setTextSize(textSize); textView2.setTextSize(textSize); textView3.setTextSize(textSize); textView4.setTextSize(textSize); textView1.setGravity(Gravity.CENTER); textView2.setGravity(Gravity.CENTER); textView3.setGravity(Gravity.CENTER); textView4.setGravity(Gravity.CENTER); row.addView(textView1); row.addView(textView2); row.addView(textView3); row.addView(textView4); row.setGravity(Gravity.CENTER); tableLayout.addView(row); } }
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);/*ww w . ja v a2 s. c o m*/ table.setShrinkAllColumns(true); 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 a v a 2s .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); }
From source file:eu.power_switch.gui.adapter.RoomRecyclerViewAdapter.java
private void updateReceiverViews(final RoomRecyclerViewAdapter.ViewHolder holder, final Room room) { String inflaterString = Context.LAYOUT_INFLATER_SERVICE; LayoutInflater inflater = (LayoutInflater) fragmentActivity.getSystemService(inflaterString); // clear previous items holder.linearLayoutOfReceivers.removeAllViews(); // add items/*from w w w . j a v a 2s . c o m*/ for (final Receiver receiver : room.getReceivers()) { // create a new receiverRow for our current receiver and add it to // our table of all devices of our current room // the row will contain the device name and all buttons LinearLayout receiverLayout = (LinearLayout) inflater.inflate(R.layout.list_item_receiver, holder.linearLayoutOfReceivers, false); receiverLayout.setOrientation(LinearLayout.HORIZONTAL); holder.linearLayoutOfReceivers.addView(receiverLayout); // setup TextView to display device name TextView receiverName = (TextView) receiverLayout.findViewById(R.id.txt_name); receiverName.setText(receiver.getName()); receiverName.setTextSize(18); TableLayout buttonLayout = (TableLayout) receiverLayout.findViewById(R.id.buttonLayout); int buttonsPerRow; if (receiver.getButtons().size() % 3 == 0) { buttonsPerRow = 3; } else { buttonsPerRow = 2; } int i = 0; final ArrayList<android.widget.Button> buttonViews = new ArrayList<>(); long lastActivatedButtonId = receiver.getLastActivatedButtonId(); TableRow buttonRow = null; for (final Button button : receiver.getButtons()) { final android.widget.Button buttonView = (android.widget.Button) inflater .inflate(R.layout.simple_button, buttonRow, false); final ColorStateList defaultTextColor = buttonView.getTextColors(); //save original colors buttonViews.add(buttonView); buttonView.setText(button.getName()); final int accentColor = ThemeHelper.getThemeAttrColor(fragmentActivity, R.attr.colorAccent); if (SmartphonePreferencesHandler.getHighlightLastActivatedButton() && lastActivatedButtonId != -1 && button.getId() == lastActivatedButtonId) { buttonView.setTextColor(accentColor); } buttonView.setOnClickListener(new android.widget.Button.OnClickListener() { @Override public void onClick(final View v) { if (SmartphonePreferencesHandler.getVibrateOnButtonPress()) { VibrationHandler.vibrate(fragmentActivity, SmartphonePreferencesHandler.getVibrationDuration()); } new AsyncTask<Void, Void, Void>() { @Override protected Void doInBackground(Void... params) { // send signal ActionHandler.execute(fragmentActivity, receiver, button); return null; } @Override protected void onPostExecute(Void aVoid) { if (SmartphonePreferencesHandler.getHighlightLastActivatedButton()) { for (android.widget.Button button : buttonViews) { if (button != v) { button.setTextColor(defaultTextColor); } else { button.setTextColor(accentColor); } } } } }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); } }); if (i == 0 || i % buttonsPerRow == 0) { buttonRow = new TableRow(fragmentActivity); buttonRow.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.MATCH_PARENT)); buttonRow.addView(buttonView); buttonLayout.addView(buttonRow); } else { buttonRow.addView(buttonView); } i++; } receiverLayout.setOnLongClickListener(new View.OnLongClickListener() { @Override public boolean onLongClick(View v) { ConfigureReceiverDialog configureReceiverDialog = ConfigureReceiverDialog .newInstance(receiver.getId()); configureReceiverDialog.setTargetFragment(recyclerViewFragment, 0); configureReceiverDialog.show(fragmentActivity.getSupportFragmentManager(), null); return true; } }); } }