Java Code Examples for android.support.v7.widget.GridLayout#addView()

The following examples show how to use android.support.v7.widget.GridLayout#addView() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ColorChooseDialog.java    From AppPlus with MIT License 6 votes vote down vote up
@NonNull
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
    int preselect = getArguments().getInt("preselect");
    View view = View.inflate(getActivity(), R.layout.dialog_color_chooser, null);
    mColors = initColors();

    GridLayout gridLayout = (GridLayout) view.findViewById(R.id.grid);

    for (int i = 0; i < mColors.length; i++) {
        gridLayout.addView(getColorItemView(getActivity(), i, i == preselect));
    }
    AlertDialog dialog = new AlertDialog.Builder(getActivity())
            .setTitle(R.string.color_chooser)
            .setView(view)
            .show();
    return dialog;
}
 
Example 2
Source File: PaymentRequestSection.java    From 365browser with Apache License 2.0 6 votes vote down vote up
private View createOptionIcon(GridLayout parent, int rowIndex, boolean editIconExists) {
    // The icon has a pre-defined width.
    ImageView optionIcon = new ImageView(parent.getContext());
    optionIcon.setImportantForAccessibility(IMPORTANT_FOR_ACCESSIBILITY_NO);
    if (mOption.isEditable()) {
        optionIcon.setMaxWidth(mEditableOptionIconMaxWidth);
    } else {
        optionIcon.setMaxWidth(mNonEditableOptionIconMaxWidth);
    }
    optionIcon.setAdjustViewBounds(true);
    optionIcon.setImageDrawable(mOption.getDrawableIcon());

    // Place option icon at column three if no edit icon.
    int columnStart = editIconExists ? 2 : 3;
    GridLayout.LayoutParams iconParams =
            new GridLayout.LayoutParams(GridLayout.spec(rowIndex, 1, GridLayout.CENTER),
                    GridLayout.spec(columnStart, 1, GridLayout.CENTER));
    iconParams.topMargin = mVerticalMargin;
    parent.addView(optionIcon, iconParams);

    optionIcon.setOnClickListener(OptionSection.this);
    return optionIcon;
}
 
Example 3
Source File: PaymentRequestSection.java    From 365browser with Apache License 2.0 5 votes vote down vote up
private View createEditIcon(GridLayout parent, int rowIndex) {
    View editorIcon = LayoutInflater.from(parent.getContext())
                              .inflate(R.layout.payment_option_edit_icon, null);

    // The icon floats to the right of everything.
    GridLayout.LayoutParams iconParams =
            new GridLayout.LayoutParams(GridLayout.spec(rowIndex, 1, GridLayout.CENTER),
                    GridLayout.spec(3, 1, GridLayout.CENTER));
    iconParams.topMargin = mVerticalMargin;
    parent.addView(editorIcon, iconParams);

    editorIcon.setOnClickListener(OptionSection.this);
    return editorIcon;
}
 
Example 4
Source File: NumbersActivity.java    From ml-authentication with Apache License 2.0 4 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    Log.i(getClass().getName(), "onCreate");
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_numbers);

    getWindow().setStatusBarColor(Color.parseColor("#1C80CF"));

    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    getSupportActionBar().setDisplayShowTitleEnabled(false);
    getSupportActionBar().setBackgroundDrawable(getDrawable(R.color.blue));

    LiteracyApplication literacyApplication = (LiteracyApplication) getApplicationContext();
    numberDao = literacyApplication.getDaoSession().getNumberDao();
    audioDao = literacyApplication.getDaoSession().getAudioDao();

    numberGridLayout = (GridLayout) findViewById(R.id.numberGridLayout);


    List<Number> numbers = new CurriculumHelper(getApplication()).getAvailableNumbers(null);
    Log.i(getClass().getName(), "numbers.size(): " + numbers.size());
    for (final Number number : numbers) {
        View numberView = LayoutInflater.from(this).inflate(R.layout.content_numbers_number_view, numberGridLayout, false);
        TextView numberTextView = (TextView) numberView.findViewById(R.id.numberTextView);
        if (!TextUtils.isEmpty(number.getSymbol())) {
            numberTextView.setText(number.getSymbol());
        } else {
            numberTextView.setText(number.getValue().toString());
        }

        numberView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Log.i(getClass().getName(), "onClick");

                Log.i(getClass().getName(), "number.getValue(): " + number.getValue());
                Log.i(getClass().getName(), "number.getSymbol(): " + number.getSymbol());
                Log.i(getClass().getName(), "number.getAllWords(): " + number.getWords());
                if (!number.getWords().isEmpty()) {
                    for (Word numberWord : number.getWords()) {
                        Log.i(getClass().getName(), "numberWord.getText(): " + numberWord.getText());
                    }
                }

                playNumberSound(number);

                EventTracker.reportNumberLearningEvent(getApplicationContext(), number.getValue());

                Intent numberIntent = new Intent(getApplicationContext(), NumberActivity.class);
                numberIntent.putExtra("number", number.getValue());
                startActivity(numberIntent);
            }
        });

        numberGridLayout.addView(numberView);
    }
}
 
Example 5
Source File: LettersActivity.java    From ml-authentication with Apache License 2.0 4 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    Log.i(getClass().getName(), "onCreate");
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_letters);

    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    getSupportActionBar().setDisplayShowTitleEnabled(false);

    LiteracyApplication literacyApplication = (LiteracyApplication) getApplicationContext();
    letterDao = literacyApplication.getDaoSession().getLetterDao();
    audioDao = literacyApplication.getDaoSession().getAudioDao();

    letterGridLayout = (GridLayout) findViewById(R.id.letterGridLayout);


    ContentProvider.initializeDb(this);
    List<Allophone> allophones = ContentProvider.getAllAllophones();
    Log.i(getClass().getName(), "allophones: " + allophones);
    Log.i(getClass().getName(), "allophones.size(): " + allophones.size());

    List<Letter> letters = new CurriculumHelper(getApplication()).getAvailableLetters(null);
    Log.i(getClass().getName(), "letters.size(): " + letters.size());
    for (final Letter letter : letters) {
        View letterView = LayoutInflater.from(this).inflate(R.layout.content_letters_letter_view, letterGridLayout, false);
        TextView letterTextView = (TextView) letterView.findViewById(R.id.letterTextView);
        letterTextView.setText(letter.getText());

        letterView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Log.i(getClass().getName(), "onClick");

                playLetterSound(letter);

                EventTracker.reportLetterLearningEvent(getApplicationContext(), letter.getText());

                Intent scrollingLetterIntent = new Intent(getApplicationContext(), ScrollingLetterActivity.class);
                scrollingLetterIntent.putExtra("letter", letter.getText());
                startActivity(scrollingLetterIntent);
            }
        });

        letterGridLayout.addView(letterView);
    }
}
 
Example 6
Source File: Exchanger.java    From GreenBits with GNU General Public License v3.0 4 votes vote down vote up
Exchanger(final Context context, final GaService service, final View mView, final boolean isBuyPage, final OnCalculateCommissionFinishListener listener) {
    mContext = context;
    mService = service;
    mIsBuyPage = isBuyPage;
    mOnCalculateCommissionFinishListener = listener;

    mAmountFiatWithCommission = UI.find(mView, R.id.amountFiatWithCommission);
    mAmountBtcWithCommission = UI.find(mView, R.id.amountBtcWithCommission);

    final FontAwesomeTextView bitcoinUnitText = UI.find(mView, R.id.sendBitcoinUnitText2);
    UI.setCoinText(mService, bitcoinUnitText, null, null);

    final String currency = mService.getFiatCurrency();

    final FontAwesomeTextView fiatView = UI.find(mView, R.id.commissionFiatIcon);
    AmountFields.changeFiatIcon(fiatView, currency);

    if (mService.isElements()) {
        bitcoinUnitText.setText(String.format("%s ", mService.getAssetSymbol()));
        UI.hide(UI.find(mView, R.id.commissionFiatColumn));
    }

    mAmountFiatEdit = UI.find(mView, R.id.sendAmountFiatEditText);
    mAmountBtcEdit = UI.find(mView, R.id.sendAmountEditText);
    final String btnsValue = service.cfg().getString("exchanger_fiat_btns", "");
    if (!btnsValue.isEmpty()) {
        final String[] btnsValueArray = btnsValue.split(" ");
        final GridLayout gridLayout = UI.find(mView, R.id.gridLayout);
        for (final String value : btnsValueArray) {
            final Button btn = new Button(mContext);
            btn.setText(String.format("%s %s", value, currency));
            final GridLayout.Spec spec = GridLayout.spec(GridLayout.UNDEFINED, 1f);
            final GridLayout.LayoutParams param = new GridLayout.LayoutParams(spec, spec);
            btn.setLayoutParams(param);
            btn.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(final View view) {
                    mAmountFiatEdit.setText(value);
                    if (mService.isElements())
                        mAmountBtcEdit.setText(value);
                }
            });
            gridLayout.addView(btn);
        }
    }
}
 
Example 7
Source File: PaymentRequestSection.java    From 365browser with Apache License 2.0 4 votes vote down vote up
private TextView createLabel(GridLayout parent, int rowIndex, boolean optionIconExists,
        boolean editIconExists, boolean isEnabled) {
    Context context = parent.getContext();
    Resources resources = context.getResources();

    // By default, the label appears to the right of the "button" in the second column.
    // + If there is no button, no option and edit icon, the label spans the whole row.
    // + If there is no option and edit icon, the label spans three columns.
    // + If there is no edit icon or option icon, the label spans two columns.
    // + Otherwise, the label occupies only its own column.
    int columnStart = 1;
    int columnSpan = 1;
    if (!optionIconExists) columnSpan++;
    if (!editIconExists) columnSpan++;

    TextView labelView = new TextView(context);
    if (mRowType == OPTION_ROW_TYPE_OPTION) {
        // Show the string representing the PaymentOption.
        ApiCompatibilityUtils.setTextAppearance(labelView, isEnabled
                ? R.style.PaymentsUiSectionDefaultText
                : R.style.PaymentsUiSectionDisabledText);
        labelView.setText(convertOptionToString(mOption,
                mDelegate.isBoldLabelNeeded(OptionSection.this),
                false /* singleLine */));
        labelView.setEnabled(isEnabled);
    } else if (mRowType == OPTION_ROW_TYPE_ADD) {
        // Shows string saying that the user can add a new option, e.g. credit card no.
        String typeface = resources.getString(R.string.roboto_medium_typeface);
        int textStyle = resources.getInteger(R.integer.roboto_medium_textstyle);
        int buttonHeight = resources.getDimensionPixelSize(
                R.dimen.payments_section_add_button_height);

        ApiCompatibilityUtils.setTextAppearance(
                labelView, R.style.PaymentsUiSectionAddButtonLabel);
        labelView.setMinimumHeight(buttonHeight);
        labelView.setGravity(Gravity.CENTER_VERTICAL);
        labelView.setTypeface(Typeface.create(typeface, textStyle));
    } else if (mRowType == OPTION_ROW_TYPE_DESCRIPTION) {
        // The description spans all the columns.
        columnStart = 0;
        columnSpan = 4;

        ApiCompatibilityUtils.setTextAppearance(
                labelView, R.style.PaymentsUiSectionDescriptiveText);
    } else if (mRowType == OPTION_ROW_TYPE_WARNING) {
        // Warnings use three columns.
        columnSpan = 3;
        ApiCompatibilityUtils.setTextAppearance(
                labelView, R.style.PaymentsUiSectionWarningText);
    }

    // The label spans two columns if no option or edit icon, or spans three columns if
    // no option and edit icons. Setting the view width to 0 forces it to stretch.
    GridLayout.LayoutParams labelParams =
            new GridLayout.LayoutParams(GridLayout.spec(rowIndex, 1, GridLayout.CENTER),
                    GridLayout.spec(columnStart, columnSpan, GridLayout.FILL, 1f));
    labelParams.topMargin = mVerticalMargin;
    labelParams.width = 0;
    if (optionIconExists) {
        // Margin at the end of the label instead of the start of the option icon to
        // allow option icon in the the next row align with the end of label (include
        // end margin) when edit icon exits in that row, like below:
        // ---Label---------------------[label margin]|---option icon---|
        // ---Label---[label margin]|---option icon---|----edit icon----|
        ApiCompatibilityUtils.setMarginEnd(labelParams, mLargeSpacing);
    }
    parent.addView(labelView, labelParams);

    labelView.setOnClickListener(OptionSection.this);
    return labelView;
}
 
Example 8
Source File: NumbersActivity.java    From ml-authentication with Apache License 2.0 4 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    Log.i(getClass().getName(), "onCreate");
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_numbers);

    getWindow().setStatusBarColor(Color.parseColor("#1C80CF"));

    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    getSupportActionBar().setDisplayShowTitleEnabled(false);
    getSupportActionBar().setBackgroundDrawable(getDrawable(R.color.blue));

    LiteracyApplication literacyApplication = (LiteracyApplication) getApplicationContext();
    numberDao = literacyApplication.getDaoSession().getNumberDao();
    audioDao = literacyApplication.getDaoSession().getAudioDao();

    numberGridLayout = (GridLayout) findViewById(R.id.numberGridLayout);


    List<Number> numbers = new CurriculumHelper(getApplication()).getAvailableNumbers(null);
    Log.i(getClass().getName(), "numbers.size(): " + numbers.size());
    for (final Number number : numbers) {
        View numberView = LayoutInflater.from(this).inflate(R.layout.content_numbers_number_view, numberGridLayout, false);
        TextView numberTextView = (TextView) numberView.findViewById(R.id.numberTextView);
        if (!TextUtils.isEmpty(number.getSymbol())) {
            numberTextView.setText(number.getSymbol());
        } else {
            numberTextView.setText(number.getValue().toString());
        }

        numberView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Log.i(getClass().getName(), "onClick");

                Log.i(getClass().getName(), "number.getValue(): " + number.getValue());
                Log.i(getClass().getName(), "number.getSymbol(): " + number.getSymbol());
                Log.i(getClass().getName(), "number.getAllWords(): " + number.getWords());
                if (!number.getWords().isEmpty()) {
                    for (Word numberWord : number.getWords()) {
                        Log.i(getClass().getName(), "numberWord.getText(): " + numberWord.getText());
                    }
                }

                playNumberSound(number);

                EventTracker.reportNumberLearningEvent(getApplicationContext(), number.getValue());

                Intent numberIntent = new Intent(getApplicationContext(), NumberActivity.class);
                numberIntent.putExtra("number", number.getValue());
                startActivity(numberIntent);
            }
        });

        numberGridLayout.addView(numberView);
    }
}
 
Example 9
Source File: LettersActivity.java    From ml-authentication with Apache License 2.0 4 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    Log.i(getClass().getName(), "onCreate");
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_letters);

    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    getSupportActionBar().setDisplayShowTitleEnabled(false);

    LiteracyApplication literacyApplication = (LiteracyApplication) getApplicationContext();
    letterDao = literacyApplication.getDaoSession().getLetterDao();
    audioDao = literacyApplication.getDaoSession().getAudioDao();

    letterGridLayout = (GridLayout) findViewById(R.id.letterGridLayout);


    ContentProvider.initializeDb(this);
    List<Allophone> allophones = ContentProvider.getAllAllophones();
    Log.i(getClass().getName(), "allophones: " + allophones);
    Log.i(getClass().getName(), "allophones.size(): " + allophones.size());

    List<Letter> letters = new CurriculumHelper(getApplication()).getAvailableLetters(null);
    Log.i(getClass().getName(), "letters.size(): " + letters.size());
    for (final Letter letter : letters) {
        View letterView = LayoutInflater.from(this).inflate(R.layout.content_letters_letter_view, letterGridLayout, false);
        TextView letterTextView = (TextView) letterView.findViewById(R.id.letterTextView);
        letterTextView.setText(letter.getText());

        letterView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Log.i(getClass().getName(), "onClick");

                playLetterSound(letter);

                EventTracker.reportLetterLearningEvent(getApplicationContext(), letter.getText());

                Intent scrollingLetterIntent = new Intent(getApplicationContext(), ScrollingLetterActivity.class);
                scrollingLetterIntent.putExtra("letter", letter.getText());
                startActivity(scrollingLetterIntent);
            }
        });

        letterGridLayout.addView(letterView);
    }
}