Search in sources :

Example 6 with TableLayout

use of android.widget.TableLayout in project android_frameworks_base by DirtyUnicorns.

the class AddColumn method onCreate.

@Override
protected void onCreate(Bundle icicle) {
    super.onCreate(icicle);
    setContentView(R.layout.add_column_in_table);
    final Button addRowButton = (Button) findViewById(R.id.add_row_button);
    addRowButton.setOnClickListener(new View.OnClickListener() {

        public void onClick(View v) {
            final TableLayout table = (TableLayout) findViewById(R.id.table);
            final TableRow newRow = new TableRow(AddColumn.this);
            for (int i = 0; i < 4; i++) {
                final TextView view = new TextView(AddColumn.this);
                view.setText("Column " + (i + 1));
                view.setPadding(3, 3, 3, 3);
                newRow.addView(view, new TableRow.LayoutParams());
            }
            table.addView(newRow, new TableLayout.LayoutParams());
            newRow.requestLayout();
        }
    });
}
Also used : Button(android.widget.Button) TableRow(android.widget.TableRow) TextView(android.widget.TextView) TextView(android.widget.TextView) View(android.view.View) TableLayout(android.widget.TableLayout)

Example 7 with TableLayout

use of android.widget.TableLayout in project android_frameworks_base by ResurrectionRemix.

the class AddColumn method onCreate.

@Override
protected void onCreate(Bundle icicle) {
    super.onCreate(icicle);
    setContentView(R.layout.add_column_in_table);
    final Button addRowButton = (Button) findViewById(R.id.add_row_button);
    addRowButton.setOnClickListener(new View.OnClickListener() {

        public void onClick(View v) {
            final TableLayout table = (TableLayout) findViewById(R.id.table);
            final TableRow newRow = new TableRow(AddColumn.this);
            for (int i = 0; i < 4; i++) {
                final TextView view = new TextView(AddColumn.this);
                view.setText("Column " + (i + 1));
                view.setPadding(3, 3, 3, 3);
                newRow.addView(view, new TableRow.LayoutParams());
            }
            table.addView(newRow, new TableLayout.LayoutParams());
            newRow.requestLayout();
        }
    });
}
Also used : Button(android.widget.Button) TableRow(android.widget.TableRow) TextView(android.widget.TextView) TextView(android.widget.TextView) View(android.view.View) TableLayout(android.widget.TableLayout)

Example 8 with TableLayout

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);
        }
    }
}
Also used : Bundle(android.os.Bundle) ALU(brunonova.drmips.simulator.components.ALU) ExtendedALU(brunonova.drmips.simulator.components.ExtendedALU) ExtendedALU(brunonova.drmips.simulator.components.ExtendedALU) DrMIPSActivity(brunonova.drmips.android.DrMIPSActivity) SuppressLint(android.annotation.SuppressLint) TableRow(android.widget.TableRow) TextView(android.widget.TextView) TableLayout(android.widget.TableLayout)

Example 9 with TableLayout

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);
                }
            }
        });
    }
}
Also used : RequestMethod(com.se491.chef_ly.http.RequestMethod) Step(com.se491.chef_ly.model.Step) ExtendedIngredient(com.se491.chef_ly.model.ExtendedIngredient) URL(java.net.URL) RotateAnimation(android.view.animation.RotateAnimation) Bitmap(android.graphics.Bitmap) ImageButton(android.widget.ImageButton) TextView(android.widget.TextView) ImageView(android.widget.ImageView) TableLayout(android.widget.TableLayout) Context(android.content.Context) IOException(java.io.IOException) ShoppingListItem(com.se491.chef_ly.model.ShoppingListItem) ImageView(android.widget.ImageView) View(android.view.View) TextView(android.widget.TextView) ScrollView(android.widget.ScrollView) ScrollView(android.widget.ScrollView) TableRow(android.widget.TableRow)

Example 10 with TableLayout

use of android.widget.TableLayout in project chefly_android by chef-ly.

the class DialogPopUp method onViewCreated.

@Override
public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
    super.onViewCreated(view, savedInstanceState);
    //Remove title bar from dialog
    Window w = getDialog().getWindow();
    if (w != null) {
        w.requestFeature(Window.FEATURE_NO_TITLE);
    }
    if (showTitle) {
        TextView title = (TextView) view.findViewById(R.id.title);
        title.setText(getArguments().getString("title"));
        title.setVisibility(View.VISIBLE);
    }
    Button exit = (Button) view.findViewById(R.id.exit);
    exit.bringToFront();
    exit.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            getDialog().dismiss();
        }
    });
    TableLayout table = (TableLayout) view.findViewById(R.id.table);
    ArrayList<String> data = getArguments().getStringArrayList("data");
    Context c = getContext();
    TableLayout.LayoutParams tableRowParams = new TableLayout.LayoutParams(TableLayout.LayoutParams.MATCH_PARENT, TableLayout.LayoutParams.WRAP_CONTENT);
    int leftMargin = 30;
    int topMargin = 1;
    int rightMargin = 55;
    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;
    if (data != null) {
        for (String s : data) {
            TableRow row = new TableRow(getContext());
            row.setLayoutParams(tableRowParams);
            row.setBackgroundColor(count % 2 == 0 ? color1 : color2);
            row.setPadding(10, 5, 10, 5);
            TextView text = new TextView(c);
            text.setText(s);
            text.setTextColor(getColor(c, 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);
            row.addView(text);
            table.addView(row);
            count++;
        }
    } else {
        TableRow row = new TableRow(getContext());
        row.setLayoutParams(tableRowParams);
        row.setBackgroundColor(count % 2 == 0 ? color1 : color2);
        row.setPadding(10, 5, 10, 5);
        TextView text = new TextView(c);
        text.setText("No data available");
        text.setTextColor(getColor(c, R.color.black));
        text.setTextSize((getResources().getDimension(R.dimen.text_medium) / getResources().getDisplayMetrics().density));
        text.setLayoutParams(new TableRow.LayoutParams(TableRow.LayoutParams.WRAP_CONTENT, TableRow.LayoutParams.WRAP_CONTENT, 1f));
        text.setPadding(10, 5, 10, 5);
        row.addView(text);
        table.addView(row);
    }
}
Also used : Window(android.view.Window) Context(android.content.Context) TextView(android.widget.TextView) View(android.view.View) Button(android.widget.Button) TableRow(android.widget.TableRow) TextView(android.widget.TextView) TableLayout(android.widget.TableLayout)

Aggregations

TableLayout (android.widget.TableLayout)13 TableRow (android.widget.TableRow)13 TextView (android.widget.TextView)13 View (android.view.View)9 Button (android.widget.Button)7 Context (android.content.Context)2 DrMIPSActivity (brunonova.drmips.android.DrMIPSActivity)2 SuppressLint (android.annotation.SuppressLint)1 Bitmap (android.graphics.Bitmap)1 Bundle (android.os.Bundle)1 ViewGroup (android.view.ViewGroup)1 Window (android.view.Window)1 RotateAnimation (android.view.animation.RotateAnimation)1 ImageButton (android.widget.ImageButton)1 ImageView (android.widget.ImageView)1 ScrollView (android.widget.ScrollView)1 LayoutParams (android.widget.TableRow.LayoutParams)1 CPU (brunonova.drmips.simulator.CPU)1 Instruction (brunonova.drmips.simulator.Instruction)1 PseudoInstruction (brunonova.drmips.simulator.PseudoInstruction)1