List of usage examples for android.widget GridLayout GridLayout
public GridLayout(Context context)
From source file:com.softminds.matrixcalculator.base_fragments.ViewMatrixFragment.java
@Override public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { int index = getArguments().getInt("INDEX"); View v = inflater.inflate(R.layout.view_matrix_frag, container, false); CardView cardView = v.findViewById(R.id.DynamicCardView); SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(getContext()); String string = sharedPreferences.getString("ELEVATE_AMOUNT", "4"); String string2 = sharedPreferences.getString("CARD_CHANGE_KEY", "#bdbdbd"); cardView.setCardElevation(Integer.parseInt(string)); final int border = getResources().getDimensionPixelOffset(R.dimen.border_width); CardView.LayoutParams params1 = new CardView.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT); cardView.setUseCompatPadding(true);/* www . j av a 2 s . co m*/ GridLayout gridLayout = new GridLayout(getContext()); int rows = ((GlobalValues) getActivity().getApplication()).GetCompleteList().get(index).getNumberOfRows(); int cols = ((GlobalValues) getActivity().getApplication()).GetCompleteList().get(index).getNumberOfCols(); gridLayout.setRowCount(rows); gridLayout.setColumnCount(cols); for (int i = 0; i < rows; i++) { for (int j = 0; j < cols; j++) { TextView textView = new TextView(getContext()); textView.setGravity(Gravity.CENTER); textView.setBackgroundColor(Color.parseColor(string2)); textView.setText(SafeSubString(GetText(((GlobalValues) getActivity().getApplication()) .GetCompleteList().get(index).getElementOf(i, j)), getLength())); textView.setWidth(CalculatedWidth(cols)); textView.setTextSize(SizeReturner(rows, cols, PreferenceManager .getDefaultSharedPreferences(getContext()).getBoolean("EXTRA_SMALL_FONT", false))); textView.setHeight(CalculatedHeight(rows)); GridLayout.Spec Row = GridLayout.spec(i, 1); GridLayout.Spec Col = GridLayout.spec(j, 1); GridLayout.LayoutParams params = new GridLayout.LayoutParams(Row, Col); params.leftMargin = params.topMargin = params.bottomMargin = params.rightMargin = border; gridLayout.addView(textView, params); } } gridLayout.setLayoutParams(params1); cardView.addView(gridLayout); // Inflate the layout for this fragment return v; }
From source file:com.softminds.matrixcalculator.base_fragments.EditFragment.java
@Override public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View V = inflater.inflate(R.layout.fragment_edit, container, false); CardView cardView = V.findViewById(R.id.EditMatrixCard); SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(getContext()); String string = sharedPreferences.getString("ELEVATE_AMOUNT", "4"); String string2 = sharedPreferences.getString("CARD_CHANGE_KEY", "#bdbdbd"); cardView.setCardElevation(Integer.parseInt(string)); CardView.LayoutParams params1 = new CardView.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT); //noinspection ConstantConditions int index = getArguments().getInt("INDEX"); //noinspection ConstantConditions MatrixV2 m = ((GlobalValues) getActivity().getApplication()).GetCompleteList().get(index); GridLayout gridLayout = new GridLayout(getContext()); gridLayout.setRowCount(m.getNumberOfRows()); gridLayout.setColumnCount(m.getNumberOfCols()); for (int i = 0; i < m.getNumberOfRows(); i++) { for (int j = 0; j < m.getNumberOfCols(); j++) { EditText editText = new EditText(getContext()); editText.setId(i * 10 + j);/* w w w . java 2 s . c o m*/ editText.setBackgroundColor(Color.parseColor(string2)); editText.setGravity(Gravity.CENTER); if (!PreferenceManager.getDefaultSharedPreferences(getContext()).getBoolean("DECIMAL_USE", true)) { editText.setInputType(InputType.TYPE_CLASS_NUMBER | InputType.TYPE_NUMBER_FLAG_SIGNED); } else { editText.setInputType(InputType.TYPE_CLASS_NUMBER | InputType.TYPE_NUMBER_FLAG_DECIMAL | InputType.TYPE_NUMBER_FLAG_SIGNED); } editText.setFilters(new InputFilter[] { new InputFilter.LengthFilter(getLength()) }); if (!PreferenceManager.getDefaultSharedPreferences(getContext()).getBoolean("SMART_FIT_KEY", false)) { editText.setWidth(ConvertTopx(62)); editText.setTextSize(SizeReturner(3, 3, PreferenceManager .getDefaultSharedPreferences(getContext()).getBoolean("EXTRA_SMALL_FONT", false))); } else { editText.setWidth(ConvertTopx(CalculatedWidth(m.getNumberOfCols()))); editText.setTextSize(SizeReturner(m.getNumberOfRows(), m.getNumberOfCols(), PreferenceManager .getDefaultSharedPreferences(getContext()).getBoolean("EXTRA_SMALL_FONT", false))); } editText.setText(SafeSubString(GetText(m.getElementOf(i, j)), getLength())); editText.setSingleLine(); GridLayout.Spec Row = GridLayout.spec(i, 1); GridLayout.Spec Col = GridLayout.spec(j, 1); GridLayout.LayoutParams params = new GridLayout.LayoutParams(Row, Col); params.leftMargin = params.topMargin = params.bottomMargin = params.rightMargin = getResources() .getDimensionPixelOffset(R.dimen.border_width); gridLayout.addView(editText, params); } } gridLayout.setLayoutParams(params1); cardView.addView(gridLayout); RootView = V; return V; }
From source file:org.odk.collect.android.widgets.SelectMultiWidgetGridLayout.java
@SuppressWarnings("unchecked") public SelectMultiWidgetGridLayout(Context context, FormEntryPrompt prompt) { super(context, prompt); mPrompt = prompt;/* ww w. java 2 s . c om*/ 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.softminds.matrixcalculator.base_activities.FillingMatrix.java
@Override protected void onCreate(Bundle savedInstanceState) { SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this); boolean isDark = preferences.getBoolean("DARK_THEME_KEY", false); boolean SmartFit = preferences.getBoolean("SMART_FIT_KEY", false); if (isDark)//from ww w . j a v a 2 s . c om setTheme(R.style.AppThemeDark_NoActionBar); else setTheme(R.style.AppTheme_NoActionBar); super.onCreate(savedInstanceState); Bundle bundle = getIntent().getExtras(); if (bundle == null) { Log.wtf("FillingMatrix", "How the heck, it got called ??"); Toast.makeText(getApplication(), R.string.unexpected_error, Toast.LENGTH_SHORT).show(); finish(); } else { col = bundle.getInt("COL"); row = bundle.getInt("ROW"); } setContentView(R.layout.filler); adCard = findViewById(R.id.AddCardFiller); if (!((GlobalValues) getApplication()).DonationKeyFound()) { AdView adView = findViewById(R.id.adViewFiller); AdRequest adRequest = new AdRequest.Builder().build(); adView.setAdListener(new AdLoadListener(adCard)); adView.loadAd(adRequest); if (getResources() .getConfiguration().orientation == android.content.res.Configuration.ORIENTATION_LANDSCAPE) adCard.setVisibility(View.INVISIBLE); else adCard.setVisibility(View.VISIBLE); } else ((ViewGroup) adCard.getParent()).removeView(adCard); Toolbar toolbar = findViewById(R.id.toolbarFill); setSupportActionBar(toolbar); CardView cardView = findViewById(R.id.DynamicCard); SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this); String string = sharedPreferences.getString("ELEVATE_AMOUNT", "4"); String string2 = sharedPreferences.getString("CARD_CHANGE_KEY", "#bdbdbd"); cardView.setCardElevation(Integer.parseInt(string)); CardView.LayoutParams params1 = new CardView.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT); GridLayout gridLayout = new GridLayout(getApplicationContext()); gridLayout.setRowCount(row); gridLayout.setColumnCount(col); for (int i = 0; i < row; i++) { for (int j = 0; j < col; j++) { EditText editText = new EditText(getApplication()); editText.setBackgroundColor(Color.parseColor(string2)); editText.setId(i * 10 + j); if (isDark) editText.setTextColor(ContextCompat.getColor(this, R.color.white)); editText.setGravity(Gravity.CENTER); SpannableStringBuilder stringBuilder = new SpannableStringBuilder( "a" + String.valueOf(i + 1) + String.valueOf(j + 1)); stringBuilder.setSpan(new SubscriptSpan(), 1, 3, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); stringBuilder.setSpan(new RelativeSizeSpan(0.75f), 1, 3, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); editText.setHint(stringBuilder); if (!PreferenceManager.getDefaultSharedPreferences(this).getBoolean("DECIMAL_USE", true)) { editText.setInputType(InputType.TYPE_CLASS_NUMBER | InputType.TYPE_NUMBER_FLAG_SIGNED); } else { editText.setInputType(InputType.TYPE_CLASS_NUMBER | InputType.TYPE_NUMBER_FLAG_DECIMAL | InputType.TYPE_NUMBER_FLAG_SIGNED); } editText.setFilters(new InputFilter[] { new InputFilter.LengthFilter(getLength()) }); if (SmartFit) { editText.setWidth(ConvertTopx(CalculatedWidth(col))); editText.setTextSize(SizeReturner(row, col, PreferenceManager.getDefaultSharedPreferences(getApplicationContext()) .getBoolean("EXTRA_SMALL_FONT", false))); } else { editText.setWidth(ConvertTopx(62)); editText.setTextSize(SizeReturner(3, 3, PreferenceManager.getDefaultSharedPreferences(getApplicationContext()) .getBoolean("EXTRA_SMALL_FONT", false))); } editText.setSingleLine(); GridLayout.Spec Row = GridLayout.spec(i, 1); GridLayout.Spec Col = GridLayout.spec(j, 1); GridLayout.LayoutParams params = new GridLayout.LayoutParams(Row, Col); params.leftMargin = params.topMargin = params.bottomMargin = params.rightMargin = getResources() .getDimensionPixelOffset(R.dimen.border_width); gridLayout.addView(editText, params); } } gridLayout.setLayoutParams(params1); cardView.addView(gridLayout); MakeType((Type) (getIntent().getExtras().getSerializable("TYPE"))); if (GetMaximum() < GetMinimum()) { final Snackbar snackbar; snackbar = Snackbar.make(findViewById(R.id.filling_matrix), R.string.Warning3, Snackbar.LENGTH_INDEFINITE); snackbar.show(); snackbar.setAction(getString(R.string.action_settings), new View.OnClickListener() { @Override public void onClick(View view) { snackbar.dismiss(); Intent intent = new Intent(getApplicationContext(), SettingsTab.class); startActivity(intent); finish(); } }); } }
From source file:nz.ac.otago.psyanlab.common.designer.program.stage.EditPropPropertiesFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { Bundle args = getArguments();//from ww w . j a v a2 s. c o m if (args.containsKey(ARG_PROP)) { mProp = args.getParcelable(ARG_PROP); } else { mProp = mCallbacks.getProp(args.getInt(ARG_PROP_ID)).getProp(); } mFieldMap = new HashMap<String, Field>(); mViewMap = new HashMap<String, View>(); // Run through the fields of the prop and build groups and mappings for // the fields and views to allow the user to change the property values. Field[] fields = mProp.getClass().getFields(); for (int i = 0; i < fields.length; i++) { Field field = fields[i]; PALEPropProperty annotation = field.getAnnotation(PALEPropProperty.class); if (annotation != null) { String fieldName = annotation.value(); View view; if (field.getType().isAssignableFrom(Integer.TYPE)) { try { view = newIntegerInputView(annotation.isSigned(), field.getInt(mProp)); } catch (IllegalArgumentException e) { throw new RuntimeException("Should never get here.", e); } catch (IllegalAccessException e) { throw new RuntimeException("Should never get here.", e); } } else if (field.getType().isAssignableFrom(Float.TYPE)) { try { view = newFloatInputView(annotation.isSigned(), field.getFloat(mProp)); } catch (IllegalArgumentException e) { throw new RuntimeException("Should never get here.", e); } catch (IllegalAccessException e) { throw new RuntimeException("Should never get here.", e); } } else if (field.getType().isAssignableFrom(String.class)) { try { view = newStringInputView((String) field.get(mProp)); } catch (IllegalArgumentException e) { throw new RuntimeException("Should never get here.", e); } catch (IllegalAccessException e) { throw new RuntimeException("Should never get here.", e); } } else { continue; } mFieldMap.put(fieldName, field); mViewMap.put(fieldName, view); if (mGroupings.containsKey(annotation.group())) { mGroupings.get(annotation.group()).add(fieldName); } else { ArrayList<String> list = new ArrayList<String>(); list.add(fieldName); mGroupings.put(annotation.group(), list); } } } // Initialise grid layout. GridLayout grid = new GridLayout(getActivity()); grid.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT)); grid.setAlignmentMode(GridLayout.ALIGN_BOUNDS); grid.setColumnCount(2); grid.setUseDefaultMargins(true); // Run through groupings of properties adding the created views to the // GridLayout in sections. for (String group : mGroupings.keySet()) { if (!TextUtils.isEmpty(group) && !TextUtils.equals(group, "")) { TextView sectionBreak = (TextView) inflater.inflate(R.layout.prop_property_section_break, grid, false); sectionBreak.setText(group); GridLayout.LayoutParams sectionBreakParams = new GridLayout.LayoutParams(); sectionBreakParams.columnSpec = GridLayout.spec(0, 2); sectionBreak.setLayoutParams(sectionBreakParams); grid.addView(sectionBreak); } for (String name : mGroupings.get(group)) { TextView propertyLabel = (TextView) inflater.inflate(R.layout.prop_property_label, grid, false); GridLayout.LayoutParams params = new GridLayout.LayoutParams(); propertyLabel.setLayoutParams(params); propertyLabel.setText(getResources().getString(R.string.format_property_label, name)); View propertyView = mViewMap.get(name); params = new GridLayout.LayoutParams(); params.setGravity(Gravity.FILL_HORIZONTAL); propertyView.setLayoutParams(params); grid.addView(propertyLabel); grid.addView(propertyView); } } return grid; }
From source file:com.retroteam.studio.retrostudio.EditorLandscape.java
/** * Create all the views associated with a track. * @param waveDrawableID//from w ww.ja v a 2 s . c o m * @param projectLoad * @return */ private ImageView addTrack(int waveDrawableID, boolean projectLoad) { //add the track with the measure adder to the view //get layout LinearLayout track_layout = (LinearLayout) findViewById(R.id.track_layout); //create track container HorizontalScrollView track_container = new HorizontalScrollView(getApplicationContext()); track_container.setLayoutParams(new HorizontalScrollView.LayoutParams( HorizontalScrollView.LayoutParams.MATCH_PARENT, displaysize.y / 4)); track_container.setBackground(getResources().getDrawable(R.color.track_container_bg)); //create grid layout GridLayout track_grid = new GridLayout(getApplicationContext()); track_grid.setColumnCount(100); track_grid.setRowCount(1); track_grid.setOrientation(GridLayout.HORIZONTAL); track_grid.setId(R.id.track_grid); //create linear layout for track id and wave LinearLayout track_identifier = new LinearLayout(getApplicationContext()); track_identifier.setLayoutParams(new LinearLayout.LayoutParams(displaysize.x / 14, displaysize.y / 4)); track_identifier.setOrientation(LinearLayout.VERTICAL); track_identifier.setBackgroundColor(getResources().getColor(R.color.black_overlay)); //create textview for linear layout TextView track_num = new TextView(getApplicationContext()); track_num.setText("1"); track_num.setTextSize(45); track_num.setGravity(Gravity.CENTER | Gravity.CENTER_VERTICAL); //create imageview for linear layout ImageView track_type = new ImageView(getApplicationContext()); track_type.setImageResource(waveDrawableID); track_type.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.MATCH_PARENT)); //create "add measure" for grid layout ImageView add_measure = new ImageView(getApplicationContext()); add_measure.setImageResource(R.drawable.measure_new); add_measure.setLayoutParams(new LinearLayout.LayoutParams((int) (displaysize.x / 3.32), LinearLayout.LayoutParams.MATCH_PARENT)); if (projectLoad) { add_measure.setTag(R.id.TAG_ROW, trackReloadCounter); add_measure.setId(trackReloadCounter + 4200); } else { add_measure.setTag(R.id.TAG_ROW, theproject.size() - 1); add_measure.setId(theproject.size() - 1 + 4200); } add_measure.setTag(R.id.TAG_COLUMN, 0); add_measure.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { addMeasure(v, false); } }); track_identifier.addView(track_num); if (projectLoad) { track_num.setText(Integer.toString(trackReloadCounter + 1)); trackReloadCounter += 1; } else { track_num.setText(Integer.toString(theproject.size())); } track_num.setTextSize(45); track_identifier.addView(track_type); track_grid.addView(track_identifier); track_grid.addView(add_measure); track_container.addView(track_grid); track_layout.addView(track_container); return add_measure; }