use of android.widget.TableLayout in project chefly_android by chef-ly.
the class RecipeDetailActivity method setRecipeInfo.
private void setRecipeInfo() {
final Context c = getApplicationContext();
TextView author = (TextView) findViewById(R.id.recipeAuthor);
// TextView description = (TextView) findViewById(R.id.recipeDescription);
TextView serves = (TextView) findViewById(R.id.recipeServings);
TextView time = (TextView) findViewById(R.id.recipeTime);
String recipeName;
Step[] directions;
if (recipeDetail == null) {
recipeTitle.setText(R.string.recipeNotFound);
} else {
recipeName = recipeDetail.getTitle();
recipeTitle.setText(recipeName);
author.setText(recipeDetail.getCreditText());
int servings = recipeDetail.getServings();
Log.d(TAG, "Serves -> " + servings);
if (servings <= 0) {
serves.setText(R.string.unknown);
} else {
serves.setText(String.valueOf(servings));
}
int cookTime = recipeDetail.getReadyInMinutes();
int hour = 0;
while (cookTime >= 60) {
hour++;
cookTime = cookTime - 60;
}
String newTime;
if (hour < 2) {
newTime = (hour != 0) ? hour + " hr " : "";
} else {
newTime = (hour != 0) ? hour + " hrs " : "";
}
newTime += ((cookTime > 0) ? cookTime + " min" : "");
if (newTime.isEmpty()) {
time.setText(R.string.unknown);
} else {
time.setText(newTime);
}
new AsyncTask<RequestMethod, Integer, Long>() {
Bitmap image = null;
@Override
protected Long doInBackground(RequestMethod... params) {
try {
URL url = new URL(recipeDetail.getImage());
image = BitmapFactory.decodeStream(url.openConnection().getInputStream());
} catch (IOException e) {
Log.d(TAG, "IOException on load image");
Log.d(TAG, e.getMessage());
}
return 1L;
}
@Override
protected void onPostExecute(Long aLong) {
if (image != null) {
imageView.setImageBitmap(image);
}
}
}.execute();
ingredients = recipeDetail.getExtendedIngredients();
if (recipeDetail.getAnalyzedInstructions().length > 0) {
directions = recipeDetail.getAnalyzedInstructions()[0].getSteps();
} else {
directions = new Step[] { new Step(recipeDetail.getInstructions()) };
}
// checkBoxes = new CheckBox[ingredients.length];
// int states[][] = {{android.R.attr.state_checked}, {}};
TableLayout table = (TableLayout) findViewById(R.id.ingredientGroup);
TableLayout.LayoutParams tableRowParams = new TableLayout.LayoutParams(TableLayout.LayoutParams.MATCH_PARENT, TableLayout.LayoutParams.WRAP_CONTENT);
int leftMargin = 30;
int topMargin = 1;
int rightMargin = 30;
int bottomMargin = 1;
tableRowParams.setMargins(leftMargin, topMargin, rightMargin, bottomMargin);
int color1 = getColor(c, R.color.table_color1);
int color2 = getColor(c, R.color.table_color2);
int count = 0;
for (ExtendedIngredient s : ingredients) {
final TableRow row = new TableRow(c);
row.setLayoutParams(tableRowParams);
row.setBackgroundColor(count % 2 == 0 ? color1 : color2);
row.setPadding(10, 5, 10, 5);
TextView text = new TextView(c);
text.setText(s.getOriginalString());
text.setTextColor(ContextCompat.getColor(getApplicationContext(), R.color.black));
text.setTextSize((getResources().getDimension(R.dimen.text_small) / getResources().getDisplayMetrics().density));
text.setLayoutParams(new TableRow.LayoutParams(TableRow.LayoutParams.WRAP_CONTENT, TableRow.LayoutParams.WRAP_CONTENT, 1f));
text.setPadding(10, 5, 10, 5);
text.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
ImageView image = (ImageView) row.getChildAt(1);
String text = String.valueOf(((TextView) row.getChildAt(0)).getText());
if (row.getChildAt(1).getVisibility() == View.GONE) {
image.setVisibility(View.VISIBLE);
shoppingList.add(new ShoppingListItem(text, false));
Toast.makeText(c, text + " added to shopping list", Toast.LENGTH_SHORT).show();
} else {
image.setVisibility(View.GONE);
shoppingList.remove(new ShoppingListItem(text, false));
Toast.makeText(c, text + " removed from shopping list", Toast.LENGTH_SHORT).show();
}
}
});
row.addView(text);
ImageView check = new ImageView(c);
check.setImageResource(R.drawable.shoppinglist);
check.setLayoutParams(new TableRow.LayoutParams(60, 60, 0.1f));
if (shoppingList.contains(new ShoppingListItem(s.getOriginalString(), false))) {
check.setVisibility(View.VISIBLE);
} else {
check.setVisibility(View.GONE);
}
row.addView(check);
table.addView(row);
count++;
}
//
final TableLayout tableDirec = (TableLayout) findViewById(R.id.directionGroup);
tableDirec.setColumnShrinkable(0, true);
tableDirec.setVisibility(View.GONE);
directionsForCooking = new String[directions.length];
count = 1;
for (Step s : directions) {
String step = count + ") " + s.getStep();
TableRow row = new TableRow(c);
row.setLayoutParams(tableRowParams);
row.setBackgroundColor(count % 2 == 0 ? color1 : color2);
TextView text = new TextView(c);
text.setText(step);
text.setTextColor(ContextCompat.getColor(getApplicationContext(), R.color.black));
text.setTextSize((getResources().getDimension(R.dimen.text_small) / getResources().getDisplayMetrics().density));
text.setPadding(15, 1, 15, 1);
text.setLayoutParams(new TableRow.LayoutParams(TableRow.LayoutParams.WRAP_CONTENT, TableRow.LayoutParams.WRAP_CONTENT, 1f));
row.addView(text);
tableDirec.addView(row);
directionsForCooking[count - 1] = s.getStep();
count++;
}
final ScrollView sv = (ScrollView) findViewById(R.id.scrollView);
final ImageButton dropdown = (ImageButton) findViewById(R.id.directionsDropdown);
final RotateAnimation rotatedown = new RotateAnimation(0, 180, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
rotatedown.setDuration(250);
rotatedown.setFillAfter(true);
final RotateAnimation rotateup = new RotateAnimation(180, 0, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
rotateup.setDuration(250);
rotateup.setFillAfter(true);
dropdown.setOnClickListener(new View.OnClickListener() {
private boolean isClicked = false;
@Override
public void onClick(View v) {
if (!isClicked) {
tableDirec.setVisibility(View.VISIBLE);
dropdown.startAnimation(rotatedown);
isClicked = true;
sv.post(new Runnable() {
@Override
public void run() {
// sv.fullScroll(ScrollView.FOCUS_DOWN);
sv.smoothScrollBy(0, 500);
}
});
} else {
dropdown.startAnimation(rotateup);
tableDirec.setVisibility(View.GONE);
isClicked = false;
// sv.fullScroll(ScrollView.FOCUS_DOWN);
}
}
});
}
}
use of android.widget.TableLayout in project drmips by brunonova.
the class DlgComponentDescription method setContents.
private void setContents(Dialog dialog, View rootView) {
String title;
Bundle args = getArguments();
if (!args.containsKey("id"))
return;
DrMIPSActivity activity = (DrMIPSActivity) getActivity();
Component component = activity.getCPU().getComponent(args.getString("id"));
boolean performanceMode = args.getBoolean("performanceMode", false);
int datapathFormat = args.getInt("datapathFormat", DrMIPS.DEFAULT_DATAPATH_DATA_FORMAT);
// Title
int nameId = activity.getResources().getIdentifier(component.getNameKey(), "string", activity.getPackageName());
if (nameId != 0)
title = activity.getString(nameId);
else
title = component.getDefaultName();
title += " (" + component.getId() + ")";
if (component instanceof Synchronous)
title += " - " + activity.getString(R.string.synchronous);
dialog.setTitle(title);
// Description
TextView lblComponentDescription = (TextView) rootView.findViewById(R.id.lblComponentDescription);
String desc = component.getCustomDescription(getResources().getConfiguration().locale.toString());
if (desc == null) {
int descId = activity.getResources().getIdentifier(component.getDescriptionKey(), "string", activity.getPackageName());
if (descId != 0)
desc = activity.getString(descId);
else
desc = component.getDefaultDescription();
}
// ALU operation if ALU
if (!performanceMode && component instanceof ALU) {
ALU alu = (ALU) component;
desc += "\n" + getResources().getString(R.string.operation) + ": " + alu.getOperationName();
// HI and LO registers if extended ALU
if (!performanceMode && component instanceof ExtendedALU) {
ExtendedALU ext_alu = (ExtendedALU) alu;
desc += "\nHI: " + Util.formatDataAccordingToFormat(ext_alu.getHI(), datapathFormat);
desc += "\nLO: " + Util.formatDataAccordingToFormat(ext_alu.getLO(), datapathFormat);
}
}
lblComponentDescription.setText(desc);
// Latency
TextView lblLatency = (TextView) rootView.findViewById(R.id.lblComponentLatency);
if (performanceMode) {
lblLatency.setVisibility(View.VISIBLE);
lblLatency.setText(getResources().getString(R.string.latency) + ": " + component.getLatency() + " " + CPU.LATENCY_UNIT + " (" + getResources().getString(R.string.long_press_to_change) + ")");
} else
lblLatency.setVisibility(View.GONE);
// Inputs
TableLayout tblInputs = (TableLayout) rootView.findViewById(R.id.tblComponentInputs);
tblInputs.removeAllViews();
TableRow row;
TextView lblId, lblValue;
for (Input in : component.getInputs()) {
if (in.isConnected()) {
row = new TableRow(activity);
lblId = new TextView(activity);
lblValue = new TextView(activity);
lblId.setText(in.getId() + ":");
lblValue.setGravity(Gravity.RIGHT);
if (performanceMode) {
lblValue.setText(in.getAccumulatedLatency() + " " + CPU.LATENCY_UNIT);
} else
lblValue.setText(Util.formatDataAccordingToFormat(in.getData(), datapathFormat));
row.addView(lblId);
row.addView(lblValue);
if (performanceMode && in.isInCriticalPath()) {
lblId.setTextColor(getResources().getColor(R.color.red));
lblValue.setTextColor(getResources().getColor(R.color.red));
} else if (in.isInControlPath()) {
lblId.setTextColor(getResources().getColor(R.color.control));
lblValue.setTextColor(getResources().getColor(R.color.control));
}
tblInputs.addView(row);
}
}
// Outputs
TableLayout tblOutputs = (TableLayout) rootView.findViewById(R.id.tblComponentOutputs);
tblOutputs.removeAllViews();
for (Output out : component.getOutputs()) {
if (out.isConnected()) {
row = new TableRow(activity);
lblId = new TextView(activity);
lblValue = new TextView(activity);
lblId.setText(out.getId() + ":");
lblValue.setGravity(Gravity.RIGHT);
if (performanceMode)
lblValue.setText(component.getAccumulatedLatency() + " " + CPU.LATENCY_UNIT);
else
lblValue.setText(Util.formatDataAccordingToFormat(out.getData(), datapathFormat));
row.addView(lblId);
row.addView(lblValue);
if (performanceMode && out.isInCriticalPath()) {
lblId.setTextColor(getResources().getColor(R.color.red));
lblValue.setTextColor(getResources().getColor(R.color.red));
} else if (out.isInControlPath()) {
lblId.setTextColor(getResources().getColor(R.color.control));
lblValue.setTextColor(getResources().getColor(R.color.control));
}
tblOutputs.addView(row);
}
}
}
use of android.widget.TableLayout in project Gadgetbridge by Freeyourgadget.
the class ActivitySummaryDetail method makeSummaryContent.
private void makeSummaryContent(BaseActivitySummary item) {
// make view of data from summaryData of item
String units = GBApplication.getPrefs().getString(SettingsActivity.PREF_MEASUREMENT_SYSTEM, GBApplication.getContext().getString(R.string.p_unit_metric));
String UNIT_IMPERIAL = GBApplication.getContext().getString(R.string.p_unit_imperial);
TableLayout fieldLayout = findViewById(R.id.summaryDetails);
// remove old widgets
fieldLayout.removeAllViews();
ActivitySummaryJsonSummary activitySummaryJsonSummary = new ActivitySummaryJsonSummary(item);
// get list, grouped by groups
JSONObject data = activitySummaryJsonSummary.getSummaryGroupedList();
if (data == null)
return;
Iterator<String> keys = data.keys();
DecimalFormat df = new DecimalFormat("#.##");
while (keys.hasNext()) {
String key = keys.next();
try {
JSONArray innerList = (JSONArray) data.get(key);
TableRow label_row = new TableRow(ActivitySummaryDetail.this);
TextView label_field = new TextView(ActivitySummaryDetail.this);
label_field.setTextSize(16);
label_field.setPadding(0, 10, 0, 0);
label_field.setTypeface(null, Typeface.BOLD);
label_field.setText(String.format("%s", getStringResourceByName(key)));
label_row.addView(label_field);
fieldLayout.addView(label_row);
for (int i = 0; i < innerList.length(); i++) {
TextView name_field = new TextView(ActivitySummaryDetail.this);
TextView value_field = new TextView(ActivitySummaryDetail.this);
name_field.setGravity(Gravity.START);
value_field.setGravity(Gravity.END);
JSONObject innerData = innerList.getJSONObject(i);
String unit = innerData.getString("unit");
String name = innerData.getString("name");
if (!unit.equals("string")) {
double value = innerData.getDouble("value");
if (!show_raw_data) {
// special casing here + imperial units handling
switch(unit) {
case "cm":
if (units.equals(UNIT_IMPERIAL)) {
value = value * 0.0328084;
unit = "ft";
}
break;
case "meters_second":
if (units.equals(UNIT_IMPERIAL)) {
value = value * 2.236936D;
unit = "mi_h";
} else {
// metric
value = value * 3.6;
unit = "km_h";
}
break;
case "seconds_m":
if (units.equals(UNIT_IMPERIAL)) {
value = value * (1609.344 / 60D);
unit = "minutes_mi";
} else {
// metric
value = value * (1000 / 60D);
unit = "minutes_km";
}
break;
case "seconds_km":
if (units.equals(UNIT_IMPERIAL)) {
value = value / 60D * 1.609344;
unit = "minutes_mi";
} else {
// metric
value = value / 60D;
unit = "minutes_km";
}
break;
case "meters":
if (units.equals(UNIT_IMPERIAL)) {
value = value * 3.28084D;
unit = "ft";
if (value > 6000) {
value = value * 0.0001893939D;
unit = "mi";
}
} else {
// metric
if (value > 2000) {
value = value / 1000;
unit = "km";
}
}
break;
}
}
if (unit.equals("seconds") && !show_raw_data) {
// rather then plain seconds, show formatted duration
value_field.setText(DateTimeUtils.formatDurationHoursMinutes((long) value, TimeUnit.SECONDS));
} else {
value_field.setText(String.format("%s %s", df.format(value), getStringResourceByName(unit)));
}
} else {
// we could optimize here a bit and only do this for particular activities (swim at the moment...)
value_field.setText(getStringResourceByName(innerData.getString("value")));
}
TableRow field_row = new TableRow(ActivitySummaryDetail.this);
if (i % 2 == 0)
field_row.setBackgroundColor(alternateColor);
name_field.setText(getStringResourceByName(name));
TableRow.LayoutParams params = new TableRow.LayoutParams(0, TableRow.LayoutParams.WRAP_CONTENT, 1f);
value_field.setLayoutParams(params);
field_row.addView(name_field);
field_row.addView(value_field);
fieldLayout.addView(field_row);
}
} catch (JSONException e) {
LOG.error("SportsActivity", e);
}
}
}
use of android.widget.TableLayout in project glimmr by brk3.
the class ExifInfoFragment method addKeyValueRow.
/**
* Creates a TableRow with two columns containing TextViews, and adds it to
* the main TableView.
*/
@SuppressWarnings("deprecation")
private void addKeyValueRow(String key, String value) {
TableLayout tl = (TableLayout) mLayout.findViewById(R.id.extraExifInfo);
/* Create the TableRow */
TableRow tr = new TableRow(mActivity);
/* Create the left column for the key */
TextView textViewKey = new TextView(mActivity);
textViewKey.setText(key);
TableRow.LayoutParams leftColParams = new TableRow.LayoutParams(0, TableLayout.LayoutParams.WRAP_CONTENT, 1f);
textViewKey.setLayoutParams(leftColParams);
tr.addView(textViewKey);
/* Create the right column for the value */
TextView textViewValue = new TextView(mActivity);
textViewValue.setText(value);
textViewValue.setTextColor(mActivity.getResources().getColor(R.color.flickr_pink));
textViewValue.setMaxLines(1);
textViewValue.setEllipsize(TextUtils.TruncateAt.END);
TableRow.LayoutParams lp = new TableRow.LayoutParams(0, TableLayout.LayoutParams.WRAP_CONTENT, 1f);
/* left, top, right, bottom */
lp.setMargins(8, 0, 0, 0);
textViewValue.setLayoutParams(lp);
tr.addView(textViewValue);
/* Add the row to the table */
tl.addView(tr);
}
use of android.widget.TableLayout in project android-nfc-paycardreader by rayyan.
the class ECCardInfosActivity method addAIDRow.
private void addAIDRow(CharSequence left, CharSequence right) {
TextView t1 = new TextView(this);
t1.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
t1.setPadding(0, 0, (int) (getResources().getDisplayMetrics().density * 10 + 0.5f), 0);
t1.setTextAppearance(this, android.R.attr.textAppearanceMedium);
t1.setText(left);
TextView t2 = new TextView(this);
t2.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
t2.setText(right);
TableRow tr = new TableRow(this);
tr.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
tr.addView(t1);
tr.addView(t2);
TableLayout t = (TableLayout) findViewById(R.id.table_features);
t.addView(tr, new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
}
Aggregations