Example usage for android.widget GridLayout addView

List of usage examples for android.widget GridLayout addView

Introduction

In this page you can find the example usage for android.widget GridLayout addView.

Prototype

public void addView(View child, int index) 

Source Link

Document

Adds a child view.

Usage

From source file:io.palaima.debugdrawer.DebugWidgetsFrame.java

private void inflateModules(BaseDebugModule module, GridLayout gl) {
    module.setActivity(activity);//from  w  w w  .  j  av a2  s  .  c  o  m
    View titleV = LayoutInflater.from(activity).inflate(R.layout.dd_module_title, null, false);
    ((TextView) titleV.findViewById(R.id.title_tv)).setText(module.getName());
    GridLayout.LayoutParams params = getSpanColParams(gl);
    params.setMargins(0, 20, 0, 3);
    gl.addView(titleV, params);

    DebugWidgetStore widgets = module.createWidgetStore(new DebugWidgetStore.Builder(activity));
    if (widgets == null) {
        gl.removeView(titleV);
        return;
    }

    for (DebugWidget widget : widgets.getWidgets()) {
        if (widget.title != null) {
            // add title widget
            TextView tv = new TextView(
                    new ContextThemeWrapper(activity, R.style.Widget_DebugDrawer_Base_RowTitle));
            tv.setText(widget.title);
            gl.addView(tv);

            // add summary widget
            gl.addView(widget.view);
        } else {
            gl.addView(widget.view, getSpanColParams(gl));
        }
    }
}

From source file:com.retroteam.studio.retrostudio.EditorLandscape.java

/**
 * Create all the views associated with a measure.
 * @param v// w ww.j  av  a2  s. c  o m
 * @param projectLoad
 */

private void addMeasure(View v, boolean projectLoad) {
    int whichtrack = (int) v.getTag(R.id.TAG_ROW);
    int whichmeasure = (int) v.getTag(R.id.TAG_COLUMN);

    if (!projectLoad) {
        theproject.track(whichtrack).addMeasure();
    }
    GridLayout myparent = (GridLayout) v.getParent();

    ImageView measure = new ImageView(getApplicationContext());
    measure.setImageResource(R.drawable.measure_new_empty);
    measure.setLayoutParams(new LinearLayout.LayoutParams((int) (displaysize.x / 3.32),
            LinearLayout.LayoutParams.MATCH_PARENT));
    measure.setTag(R.id.TAG_ROW, whichtrack);
    measure.setTag(R.id.TAG_COLUMN, whichmeasure);
    measure.setTag(R.bool.TAG_HASNOTES, false);
    measure.setTag(R.id.TAG_GUISNAP, 0);
    measure.setTag(R.id.TAG_FILLED_NOTES, new ArrayList<int[]>());
    measure.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            ///
            int whichtrack = (int) v.getTag(R.id.TAG_ROW);
            int whichmeasure = (int) v.getTag(R.id.TAG_COLUMN);
            editMeasure(v);
        }
    });
    myparent.addView(measure, whichmeasure + 1);

    v.setTag(R.id.TAG_COLUMN, whichmeasure + 1);
}

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);//from w  w  w.  j  ava2 s  .  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 ww  .j  a v  a2  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)/*  ww  w . ja  va2 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();
            }
        });
    }

}