List of usage examples for android.widget GridLayout spec
public static Spec spec(int start)
To leave the start index undefined, use the value #UNDEFINED .
From source file:io.palaima.debugdrawer.DebugWidgetsFrame.java
@NonNull private GridLayout.LayoutParams getSpanColParams(GridLayout gl) { // http://bbs.csdn.net/topics/391853628 // ?????/*from ww w . j a v a 2 s . co m*/ GridLayout.Spec row = GridLayout.spec(GridLayout.UNDEFINED); // ????? GridLayout.Spec col = GridLayout.spec(GridLayout.UNDEFINED, gl.getColumnCount()); GridLayout.LayoutParams params = new GridLayout.LayoutParams(row, col); params.width = GridLayout.LayoutParams.MATCH_PARENT; return params; }
From source file:org.odk.collect.android.widgets.SelectMultiWidgetGridLayout.java
@SuppressWarnings("unchecked") public SelectMultiWidgetGridLayout(Context context, FormEntryPrompt prompt) { super(context, prompt); mPrompt = prompt;/*from ww w . j av a2s. c o m*/ mCheckboxes = new ArrayList<CheckBox>(); // SurveyCTO-added support for dynamic select content (from .csv files) XPathFuncExpr xPathFuncExpr = ExternalDataUtil.getSearchXPathExpression(prompt.getAppearanceHint()); if (xPathFuncExpr != null) { mItems = ExternalDataUtil.populateExternalChoices(prompt, xPathFuncExpr); } else { mItems = prompt.getSelectChoices(); } setOrientation(LinearLayout.VERTICAL); Vector<Selection> ve = new Vector<Selection>(); if (prompt.getAnswerValue() != null) { ve = (Vector<Selection>) prompt.getAnswerValue().getValue(); } WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE); Display display = wm.getDefaultDisplay(); Point size = new Point(); display.getSize(size); int screenWidth = size.x; int height = size.y; int halfScreenWidth = (int) (screenWidth * 0.5); int quarterScreenWidth = (int) (halfScreenWidth * 0.5); glayout = new GridLayout(getContext()); glayout.setOrientation(0); glayout.setColumnCount(2); //glayout.setRowCount(2); int row_index = 0; int col_index = 0; if (mItems != null) { for (int i = 0; i < mItems.size(); i++) { // no checkbox group so id by answer + offset CheckBox c = new CheckBox(getContext()); c.setTag(Integer.valueOf(i)); c.setId(QuestionWidget.newUniqueId()); c.setText(prompt.getSelectChoiceText(mItems.get(i))); c.setTextSize(TypedValue.COMPLEX_UNIT_DIP, mAnswerFontsize); c.setFocusable(!prompt.isReadOnly()); c.setEnabled(!prompt.isReadOnly()); for (int vi = 0; vi < ve.size(); vi++) { // match based on value, not key if (mItems.get(i).getValue().equals(ve.elementAt(vi).getValue())) { c.setChecked(true); break; } } mCheckboxes.add(c); // when clicked, check for readonly before toggling c.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { if (!mCheckboxInit && mPrompt.isReadOnly()) { if (buttonView.isChecked()) { buttonView.setChecked(false); Collect.getInstance().getActivityLogger().logInstanceAction(this, "onItemClick.deselect", mItems.get((Integer) buttonView.getTag()).getValue(), mPrompt.getIndex()); } else { buttonView.setChecked(true); Collect.getInstance().getActivityLogger().logInstanceAction(this, "onItemClick.select", mItems.get((Integer) buttonView.getTag()).getValue(), mPrompt.getIndex()); } } } }); String audioURI = null; audioURI = prompt.getSpecialFormSelectChoiceText(mItems.get(i), FormEntryCaption.TEXT_FORM_AUDIO); String imageURI; if (mItems.get(i) instanceof ExternalSelectChoice) { imageURI = ((ExternalSelectChoice) mItems.get(i)).getImage(); } else { imageURI = prompt.getSpecialFormSelectChoiceText(mItems.get(i), FormEntryCaption.TEXT_FORM_IMAGE); } String videoURI = null; videoURI = prompt.getSpecialFormSelectChoiceText(mItems.get(i), "video"); String bigImageURI = null; bigImageURI = prompt.getSpecialFormSelectChoiceText(mItems.get(i), "big-image"); MediaLayout mediaLayout = new MediaLayout(getContext()); mediaLayout.setAVT(prompt.getIndex(), "." + Integer.toString(i), c, audioURI, imageURI, videoURI, bigImageURI); // mediaLayout.setAVT(index, selectionDesignator, text, audioURI, imageURI, videoURI, bigImageURI); // addView(mediaLayout); row_index = i / 2 + 1; col_index = i % 2; int orientation = display.getOrientation(); if (orientation == 1) { halfScreenWidth = height / 2; } else { halfScreenWidth = screenWidth / 2; } Spec row = GridLayout.spec(row_index); Spec col = GridLayout.spec(col_index); GridLayout.LayoutParams first = new GridLayout.LayoutParams(row, col); first.width = halfScreenWidth; // first.height = quarterScreenWidth * 2; glayout.addView(mediaLayout, first); // Last, add the dividing line between elements (except for the last element) ImageView divider = new ImageView(getContext()); divider.setBackgroundResource(android.R.drawable.divider_horizontal_bright); if (i != mItems.size() - 1) { if (col_index == 0) glayout.addView(divider); } } } addView(glayout); mCheckboxInit = false; }
From source file:com.affectiva.affdexme.MetricSelectionFragment.java
void addGridItems(IntRef currentRow, int numColumns, LayoutInflater inflater, Resources res, int size, MetricsManager.Metrics[] metricsToAdd) { //keeps track of the column we are adding to int col = -1; //start col at -1 so it becomes 0 during first iteration of for loop for (MetricsManager.Metrics metric : metricsToAdd) { col += 1;/*www . j a va 2 s .com*/ if (col >= numColumns) { col = 0; currentRow.value += 1; } MetricSelector item = metricSelectors.get(metric); if (item != null) { GridLayout.LayoutParams params = new GridLayout.LayoutParams(); params.width = size; params.height = size; params.columnSpec = GridLayout.spec(col); params.rowSpec = GridLayout.spec(currentRow.value); item.setLayoutParams(params); item.setOnClickListener(this); gridLayout.addView(item); } else { Log.e(LOG_TAG, "Unknown MetricSelector item for Metric: " + metric.toString()); } } currentRow.value += 1; //point currentRow to row where next views should be added }
From source file:com.sonymobile.androidapp.gridcomputing.fragments.ReportChartFragment.java
private void setLegends() { if (mChart.getData().getDataSets().size() > 1) { final Resources resources = ApplicationData.getAppContext().getResources(); final float density = getResources().getDisplayMetrics().density; final float legendWidth = resources.getDimension(R.dimen.chart_legend_width) / density; final float legendHeight = resources.getDimension(R.dimen.chart_legend_height) / density; final float legendMargin = resources.getDimension(R.dimen.chart_legend_margin) / density; final float legendCorner = resources.getDimension(R.dimen.chart_legend_corner) / density; for (ILineDataSet lineDataSet : mChart.getData().getDataSets()) { final CheckBox checkBox = new CheckBox(mLegendLayout.getContext()); checkBox.setChecked(true);/* ww w. j a v a2 s .c o m*/ checkBox.setText(lineDataSet.getLabel()); checkBox.setTag(lineDataSet); checkBox.setOnCheckedChangeListener(mLegendCheckedChangeListener); GradientDrawable drawable = new GradientDrawable(); drawable.setShape(GradientDrawable.RECTANGLE); drawable.setColor(lineDataSet.getColor()); drawable.setSize((int) legendWidth, (int) legendHeight); drawable.setCornerRadius(legendCorner); checkBox.setCompoundDrawablesWithIntrinsicBounds(null, null, drawable, null); checkBox.setCompoundDrawablePadding((int) legendMargin); final GridLayout.Spec titleTxtSpecColumn = GridLayout.spec(GridLayout.UNDEFINED); final GridLayout.Spec titleRowSpec = GridLayout.spec(GridLayout.UNDEFINED); final GridLayout.LayoutParams layoutParams = new GridLayout.LayoutParams(titleRowSpec, titleTxtSpecColumn); layoutParams.setMargins((int) legendWidth, 0, (int) legendWidth, 0); mLegendLayout.addView(checkBox, layoutParams); } } }