List of usage examples for android.widget GridLayout setLayoutParams
public void setLayoutParams(ViewGroup.LayoutParams params)
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();// w w w . j a v a 2s . com 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.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);//w w w . j a v a2s.com 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);/*from w w w . ja va 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: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 w w w.j ava 2s . c o m*/ 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(); } }); } }