use of android.widget.TableRow in project pictureapp by EyeSeeTea.
the class DynamicTabAdapter method renderQuestion.
public void renderQuestion(View rowView, int tabType, Question screenQuestion) {
TableRow tableRow;
IQuestionViewFactory questionViewFactory;
questionViewFactory = (Tab.isMultiQuestionTab(tabType) || Tab.isDynamicTreatmentTab(tabType)) ? new MultiQuestionViewFactory() : new SingleQuestionViewFactory();
// Se get the value from Session
int visibility = View.GONE;
Survey survey = (screenQuestion.isStockQuestion() || screenQuestion.isDynamicStockQuestion()) ? Session.getStockSurvey() : getMalariaSurvey();
if (!screenQuestion.isHiddenBySurveyAndHeader(survey) || !Tab.isMultiQuestionTab(tabType)) {
visibility = View.VISIBLE;
}
Value value = screenQuestion.getValueBySession();
tableRow = new TableRow(context);
IQuestionView questionView = questionViewFactory.getView(context, screenQuestion.getOutput());
if (questionView != null) {
if (questionView instanceof IMultiQuestionView) {
mMultiQuestionViews.add((IMultiQuestionView) questionView);
((IMultiQuestionView) questionView).setHeader(Utils.getInternationalizedString(screenQuestion.getForm_name()));
}
addTagQuestion(screenQuestion, (View) questionView);
configureLayoutParams(tabType, tableRow, (LinearLayout) questionView);
questionView.setHelpText(Utils.getInternationalizedString(screenQuestion.getHelp_text()));
questionView.setEnabled(!readOnly);
if (questionView instanceof IImageQuestionView) {
((IImageQuestionView) questionView).setImage(screenQuestion.getInternationalizedPath());
}
if (screenQuestion.isDynamicStockQuestion()) {
Treatment treatment = new Treatment(getMalariaSurvey(), Session.getStockSurvey());
if (treatment.hasTreatment()) {
org.eyeseetea.malariacare.data.database.model.Treatment dbTreatment = treatment.getTreatment();
Question actAnsweredNo = treatment.getACTQuestionAnsweredNo();
screenQuestion.setAnswer(treatment.getACTOptions(dbTreatment));
((DynamicStockImageRadioButtonSingleQuestionView) questionView).setOptionDose(treatment.getOptionDose(dbTreatment));
}
((DynamicStockImageRadioButtonSingleQuestionView) questionView).setQuestion(screenQuestion);
((DynamicStockImageRadioButtonSingleQuestionView) questionView).setOptions(screenQuestion.getAnswer().getOptions());
//Getting the question to put the correct values on it
ArrayList<Question> questions = new ArrayList<>();
for (Option option : screenQuestion.getAnswer().getOptions()) {
Question question = Question.findByID(option.getId_option());
if (question != null) {
questions.add(question);
}
}
survey.getValuesFromDB();
for (Question question : questions) {
Value valueStock = question.getValueBySession();
questionView.setValue(valueStock);
}
}
if (questionView instanceof AOptionQuestionView) {
((AOptionQuestionView) questionView).setQuestion(screenQuestion);
List<Option> options = screenQuestion.getAnswer().getOptions();
((AOptionQuestionView) questionView).setOptions(options);
}
if (questionView instanceof NumberRadioButtonMultiquestionView) {
if (doseByQuestion != null) {
((NumberRadioButtonMultiquestionView) questionView).setDose(doseByQuestion.get(screenQuestion.getId_question()));
}
((NumberRadioButtonMultiquestionView) questionView).setQuestion(screenQuestion);
((NumberRadioButtonMultiquestionView) questionView).setOptions(screenQuestion.getAnswer().getOptions());
}
if (!readOnly) {
configureAnswerChangedListener(questionView);
}
if (reloadingQuestionFromInvalidOption) {
reloadingQuestionFromInvalidOption = false;
} else {
questionView.setValue(value);
}
setupNavigationByQuestionView(rowView.getRootView(), questionView);
tableRow.addView((View) questionView);
swipeTouchListener.addClickableView(tableRow);
setVisibilityAndAddRow(tableRow, screenQuestion, visibility);
}
}
use of android.widget.TableRow 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.TableRow in project drmips by brunonova.
the class DrMIPSActivity method refreshRegistersTable.
/**
* Refreshes both the rows and values of the registers table.
*/
private void refreshRegistersTable() {
while (// remove all rows except header
tblRegisters.getChildCount() > 1) tblRegisters.removeViewAt(1);
// Add registers
CPU cpu = getCPU();
int numRegs = cpu.getRegBank().getNumberOfRegisters();
TableRow row;
TextView register, value;
String reg;
for (int i = 0; i < numRegs; i++) {
row = new TableRow(this);
row.setOnLongClickListener(registersRowOnLongClickListener);
register = new TextView(this);
reg = i + ": " + cpu.getRegisterName(i);
if (i < 10)
reg = " " + reg;
register.setText(reg);
register.setTextAppearance(this, android.R.style.TextAppearance_Medium);
register.setTypeface(Typeface.MONOSPACE);
value = new TextView(this);
value.setTextAppearance(this, android.R.style.TextAppearance_Medium);
value.setTypeface(Typeface.MONOSPACE);
value.setGravity(Gravity.RIGHT);
row.addView(register);
row.addView(value);
tblRegisters.addView(row);
}
// Add special "registers" (PC,...)
row = new TableRow(this);
row.setOnLongClickListener(registersRowOnLongClickListener);
register = new TextView(this);
register.setText("PC");
register.setTextAppearance(this, android.R.style.TextAppearance_Medium);
register.setTypeface(Typeface.MONOSPACE);
value = new TextView(this);
value.setTextAppearance(this, android.R.style.TextAppearance_Medium);
value.setTypeface(Typeface.MONOSPACE);
value.setGravity(Gravity.RIGHT);
row.addView(register);
row.addView(value);
tblRegisters.addView(row);
// refresh values
refreshRegistersTableValues();
}
use of android.widget.TableRow in project drmips by brunonova.
the class DrMIPSActivity method refreshRegistersTableValues.
/**
* Refreshes the values of the registers table.
*/
public void refreshRegistersTableValues() {
CPU cpu = getCPU();
int numRegs = cpu.getRegBank().getNumberOfRegisters();
TextView value;
TableRow row;
int reg1 = cpu.getRegBank().getReadReg1().getValue();
int reg2 = cpu.getRegBank().getReadReg2().getValue();
int regW = cpu.getRegBank().getWriteReg().getValue();
boolean write = cpu.getRegBank().getRegWrite().getValue() == 1;
for (int i = 0; i < numRegs; i++) {
// registers
row = (TableRow) tblRegisters.getChildAt(i + 1);
value = (TextView) row.getChildAt(1);
value.setText(Util.formatDataAccordingToFormat(cpu.getRegBank().getRegister(i), cmbRegistersFormat.getSelectedItemPosition()));
// Highlight registers being accessed
if (write && i == regW && !cpu.getRegBank().isRegisterConstant(regW)) {
if (i == reg1 || i == reg2)
row.setBackgroundColor(Util.getThemeColor(this, R.attr.rwColor));
else
row.setBackgroundColor(Util.getThemeColor(this, R.attr.writeColor));
} else if (i == reg1 || i == reg2)
row.setBackgroundColor(Util.getThemeColor(this, R.attr.readColor));
else
// remove background color
row.setBackgroundResource(0);
}
// Special "registers"
value = (TextView) ((TableRow) tblRegisters.getChildAt(numRegs + 1)).getChildAt(1);
value.setText(Util.formatDataAccordingToFormat(cpu.getPC().getAddress(), cmbRegistersFormat.getSelectedItemPosition()));
tblRegisters.requestLayout();
}
use of android.widget.TableRow 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);
}
}
});
}
}
Aggregations