下面列出了怎么用android.support.v7.widget.GridLayout的API类实例代码及写法,或者点击链接到github查看源代码。
private void initViews() {
title = findViewById(R.id.title);
image = findViewById(R.id.image);
layoutImage = findViewById(R.id.layout_image);
name = findViewById(R.id.name);
desc = findViewById(R.id.description);
id = findViewById(R.id.id);
generation = findViewById(R.id.generation);
cooldown = findViewById(R.id.cooldown);
openExternal = findViewById(R.id.open_external);
labelAttributes = findViewById(R.id.label_attributes);
grid = findViewById(R.id.grid);
grid.setAlignmentMode(GridLayout.ALIGN_BOUNDS);
grid.setUseDefaultMargins(false);
functionBar = findViewById(R.id.layoutButtons);
if (functionBar != null)
{
List<BigInteger> selection = new ArrayList<>();
selection.add(new BigInteger(asset.getTokenId(16), 16));
functionBar.setupFunctions(this, viewModel.getAssetDefinitionService(), token, null, selection);
functionBar.revealButtons();
}
}
private void setTraits(Asset asset) {
if (asset.getTraits() != null && !asset.getTraits().isEmpty()) {
if (asset.getAssetContract().getName().equals("CryptoKitties")) {
labelAttributes.setText(R.string.label_cattributes);
} else {
labelAttributes.setText(R.string.label_attributes);
}
for (Trait trait : asset.getTraits()) {
View attributeView = View.inflate(this, R.layout.item_attribute, null);
TextView traitType = attributeView.findViewById(R.id.trait);
TextView traitValue = attributeView.findViewById(R.id.value);
GridLayout.LayoutParams params = new GridLayout.LayoutParams(
GridLayout.spec(GridLayout.UNDEFINED, 1f),
GridLayout.spec(GridLayout.UNDEFINED, 1f));
attributeView.setLayoutParams(params);
traitType.setText(trait.getTraitType());
traitValue.setText(trait.getValue());
grid.addView(attributeView);
}
} else {
labelAttributes.setVisibility(View.GONE);
}
}
/**
* 根据屏幕方向创建按钮
*/
public void createActionButton() {
if (!actionBtnArray.isEmpty()) actionBtnArray.clear();
for (int rowIndex = 0; rowIndex < currentPageRow; rowIndex++)
for (int colIndex = 0; colIndex < currentPageCol; colIndex++) {
View view = LayoutInflater.from(getContext()).inflate(R.layout.layout_action_button, null);
ViewGroup actionBtn = view.findViewById(R.id.actionBtn);
actionBtn.setTag(getButtonIndex(rowIndex, colIndex));
actionBtn.setOnClickListener(this);
GridLayout.LayoutParams gridLayoutParam = new GridLayout.LayoutParams(
GridLayout.spec(rowIndex, 1f),
GridLayout.spec(colIndex, 1f)
);
gridLayoutParam.setMargins(1, 1, 1, 1);
gridLayoutParam.height = 0;
gridLayoutParam.width = 0;
addView(view, gridLayoutParam);
UiButtonItem item = new UiButtonItem();
item.button = actionBtn;
item.imageView = view.findViewById(R.id.actionBtnBg);
item.textView = view.findViewById(R.id.actionBtnText);
actionBtnArray.put(getButtonIndex(rowIndex, colIndex), item);
}
}
@Override
public void run() {
switch (mBackspaceLocation) {
case LOCATION_HEADER:
break;
case LOCATION_FOOTER:
((ViewGroup) mHeader).removeView(mBackspace);
// The row of the cell in which the backspace key should go.
// This specifies the row index, which spans one increment,
// and indicates the cell should be filled along the row
// (horizontal) axis.
final GridLayout.Spec rowSpec = GridLayout.spec(
mNumberPad.getRowCount() - 1, GridLayout.FILL);
// The column of the cell in which the backspace key should go.
// This specifies the column index, which spans one increment,
// and indicates the cell should be filled along the column
// (vertical) axis.
final GridLayout.Spec columnSpec = GridLayout.spec(
mNumberPad.getColumnCount() - 1, GridLayout.FILL);
mNumberPad.addView(mBackspace, new GridLayout.LayoutParams(
rowSpec, columnSpec));
break;
}
}
@Override
public void run() {
switch (mBackspaceLocation) {
case LOCATION_HEADER:
break;
case LOCATION_FOOTER:
((ViewGroup) mHeader).removeView(mBackspace);
// The row of the cell in which the backspace key should go.
// This specifies the row index, which spans one increment,
// and indicates the cell should be filled along the row
// (horizontal) axis.
final GridLayout.Spec rowSpec = GridLayout.spec(
mNumberPad.getRowCount() - 1, GridLayout.FILL);
// The column of the cell in which the backspace key should go.
// This specifies the column index, which spans one increment,
// and indicates the cell should be filled along the column
// (vertical) axis.
final GridLayout.Spec columnSpec = GridLayout.spec(
mNumberPad.getColumnCount() - 1, GridLayout.FILL);
mNumberPad.addView(mBackspace, new GridLayout.LayoutParams(
rowSpec, columnSpec));
break;
}
}
/**
* 将倒影布局添加到GridLayout容器中
*/
private void addReflectionImageView() {
mReflectionImageView = new ImageView(mContext);
GridLayout.LayoutParams layoutParams = new GridLayout.LayoutParams();
layoutParams.width = mColumnCount * mBaseWidth
+ ((mColumnCount > 1 ? mHorizontalMargin * (mColumnCount - 1) : 0));
layoutParams.height = mBaseHeight;
layoutParams.rowSpec = GridLayout.spec(mRowCount - 1, 1);
layoutParams.columnSpec = GridLayout.spec(0, mColumnCount);
mReflectionImageView.setLayoutParams(layoutParams);
mReflectionImageView.setScaleType(ImageView.ScaleType.FIT_XY);
this.refreshReflection(0);
mGridLayout.addView(mReflectionImageView);
mReflectionImageView.setVisibility(mVisibility);
}
@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;
}
@Override
protected void createMainSectionContent(LinearLayout mainSectionLayout) {
Context context = mainSectionLayout.getContext();
// Add a label that will be used to indicate that the total cart price has been updated.
addUpdateText(mainSectionLayout);
// The breakdown is represented by an end-aligned GridLayout that takes up only as much
// space as it needs. The GridLayout ensures a consistent margin between the columns.
mBreakdownLayout = new GridLayout(context);
mBreakdownLayout.setColumnCount(2);
LayoutParams breakdownParams =
new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
breakdownParams.gravity = Gravity.END;
mainSectionLayout.addView(mBreakdownLayout, breakdownParams);
// Sets the summary right text view takes the same available space as the summary left
// text view.
LinearLayout.LayoutParams rightTextViewLayoutParams =
(LinearLayout.LayoutParams) getSummaryRightTextView().getLayoutParams();
rightTextViewLayoutParams.width = 0;
rightTextViewLayoutParams.weight = 1f;
}
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;
}
@Override
protected void onCreate(Bundle savedInstanceState) {
Log.i(getClass().getName(), "onCreate");
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_student_selection);
LiteracyApplication literacyApplication = (LiteracyApplication) getApplication();
studentDao = literacyApplication.getDaoSession().getStudentDao();
studentSelectionGridLayout = (GridLayout) findViewById(R.id.studentSelectionGridLayout);
}
private GridLayout.LayoutParams getLayoutParams() {
GridLayout.LayoutParams layoutParams;
layoutParams = new GridLayout.LayoutParams(
GridLayout.spec(GridLayout.UNDEFINED, 1f),
GridLayout.spec(GridLayout.UNDEFINED, 1f));
layoutParams.width = 0;
return layoutParams;
}
private GridBuilder(Context context, GridLayout gridLayout) {
this.mContext = context;
this.mGridLayout = gridLayout;
this.mLayoutInflater = LayoutInflater.from(context);
// 不使用默认margin
this.mGridLayout.setUseDefaultMargins(false);
this.mGridLayout.setAlignmentMode(GridLayout.ALIGN_BOUNDS);
this.mGridLayout.setClipChildren(false);
this.mGridLayout.setClipToPadding(false);
}
public GridViewHolder(GridLayout gridLayout) {
mGridLayout = gridLayout;
mAddedView = new LinkedBlockingQueue<>();
mRemovedView = new LinkedBlockingQueue<>();
init();
}
private View getColorItemView(final Context context, int position, boolean isSelect) {
int color = mColors[position];
int widthImageCheckView = Utils.convertDensityPix(context, 24);
int widthColorView = Utils.convertDensityPix(context, 56);
int widthMargin = Utils.convertDensityPix(context, 4);
ImageView imageView = new ImageView(context);
imageView.setImageResource(R.drawable.ic_done_white_24dp);
FrameLayout.LayoutParams ivParams = new FrameLayout.LayoutParams(widthImageCheckView, widthImageCheckView);
ivParams.gravity = Gravity.CENTER;
imageView.setLayoutParams(ivParams);
imageView.setVisibility(isSelect ? View.VISIBLE : View.INVISIBLE);
FrameLayout frameLayout = new FrameLayout(context);
GridLayout.LayoutParams params = new GridLayout.LayoutParams(new FrameLayout.LayoutParams(widthColorView, widthColorView));
params.setGravity(Gravity.CENTER);
params.setMargins(widthMargin, widthMargin, widthMargin, widthMargin);
frameLayout.setLayoutParams(params);
setBackgroundSelector(frameLayout, color);
frameLayout.addView(imageView);
frameLayout.setOnClickListener(this);
frameLayout.setTag(position);
return frameLayout;
}
public OptionRow(GridLayout parent, int rowIndex, int rowType,
@Nullable PaymentOption item, boolean isSelected) {
assert item != null || rowType != OPTION_ROW_TYPE_OPTION;
boolean optionIconExists = item != null && item.getDrawableIcon() != null;
boolean editIconExists = item != null && item.isEditable() && isSelected;
boolean isEnabled = item != null && item.isValid();
mRowType = rowType;
mOption = item;
mButton = createButton(parent, rowIndex, isSelected, isEnabled);
mLabel = createLabel(parent, rowIndex, optionIconExists, editIconExists, isEnabled);
mOptionIcon = optionIconExists
? createOptionIcon(parent, rowIndex, editIconExists) : null;
mEditIcon = editIconExists ? createEditIcon(parent, rowIndex) : null;
}
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;
}
@Override
protected void createMainSectionContent(LinearLayout mainSectionLayout) {
Context context = mainSectionLayout.getContext();
mCheckingProgress = createLoadingSpinner();
mOptionLayout = new GridLayout(context);
mOptionLayout.setColumnCount(4);
mainSectionLayout.addView(mOptionLayout, new LinearLayout.LayoutParams(
LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT));
}
@Override
protected void onCreate(Bundle savedInstanceState) {
Log.i(getClass().getName(), "onCreate");
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_student_selection);
LiteracyApplication literacyApplication = (LiteracyApplication) getApplication();
studentDao = literacyApplication.getDaoSession().getStudentDao();
studentSelectionGridLayout = (GridLayout) findViewById(R.id.studentSelectionGridLayout);
}
@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);
}
}
@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);
}
}
private void initView() {
mGridLayout = (GridLayout) findViewById(R.id.grid_test);
}
/**
* 创建实例
*/
public static GridBuilder newInstance(Context context, GridLayout gridLayout) {
return new GridBuilder(context, gridLayout);
}
/**
* 向GridLayout容器中添加Grid元素
*
* @param gridItem Grid元素
*/
private GridBuilder addItem(GridItem gridItem) {
View itemLayout = null;
if (null != mOnViewCreateCallBack) {
itemLayout = mOnViewCreateCallBack.onViewCreate(mLayoutInflater, null == mGridViewHolder
? null : mGridViewHolder.getConvertView(), gridItem);
}
if (null == itemLayout) {
return this;
}
GridLayout.LayoutParams layoutParams = new GridLayout.LayoutParams();
// 优先根据预先取得的width/height设置,但不影响跨列/行数
layoutParams.width = (gridItem.getWidth() > 0 ? gridItem.getWidth() : gridItem.getColumnSpec() * mBaseWidth)
+ ((gridItem.getColumnSpec() > 1 && gridItem.getWidth() <= 0 ? mHorizontalMargin * (gridItem.getColumnSpec() - 1) : 0));
layoutParams.height = (gridItem.getHeight() > 0 ? gridItem.getHeight() : gridItem.getRowSpec() * mBaseHeight)
+ ((gridItem.getRowSpec() > 1 && gridItem.getWidth() <= 0 ? mVerticalMargin * (gridItem.getRowSpec() - 1) : 0));
if (gridItem.getWidth() <= 0) {
gridItem.setWidth(layoutParams.width);
}
if (gridItem.getHeight() <= 0) {
gridItem.setHeight(layoutParams.height);
}
layoutParams.rowSpec = GridLayout.spec(gridItem.getRow(), gridItem.getRowSpec());
layoutParams.columnSpec = GridLayout.spec(gridItem.getColumn(), gridItem.getColumnSpec());
// 设置每个item间距,最外层间距也需要设置(因为需要体现边缘item的scale效果)
if (gridItem.getRow() > 0) {
layoutParams.topMargin = mVerticalMargin;
}
if (gridItem.getColumn() > 0) {
layoutParams.leftMargin = mHorizontalMargin;
}
itemLayout.setLayoutParams(layoutParams);
itemLayout.setFocusable(true);
itemLayout.setClickable(true);
itemLayout.setOnFocusChangeListener(this);
itemLayout.setOnClickListener(this);
itemLayout.setOnKeyListener(mOnKeyListener);
itemLayout.setSoundEffectsEnabled(false);
if (mGridLayout.getChildCount() == 0 && gridItem == mGridItemList.get(0)) {
itemLayout.setTag(GridItem.TAG_FIRST_ITEM);
}
this.mGridLayout.addView(itemLayout);
return this;
}
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);
}
}
}
/**
* Updates the total and how it's broken down.
*
* @param cart The shopping cart contents and the total.
*/
public void update(ShoppingCart cart) {
Context context = mBreakdownLayout.getContext();
CharSequence totalPrice = createValueString(
cart.getTotal().getCurrency(), cart.getTotal().getPrice(), true);
// Show the updated text view if the total changed.
showUpdateIfTextChanged(totalPrice);
// Update the summary to display information about the total.
setSummaryText(cart.getTotal().getLabel(), totalPrice);
mBreakdownLayout.removeAllViews();
if (cart.getContents() == null) return;
int maximumDescriptionWidthPx =
((View) mBreakdownLayout.getParent()).getWidth() * 2 / 3;
// Update the breakdown, using one row per {@link LineItem}.
int numItems = cart.getContents().size();
mBreakdownLayout.setRowCount(numItems);
for (int i = 0; i < numItems; i++) {
LineItem item = cart.getContents().get(i);
TextView description = new TextView(context);
ApiCompatibilityUtils.setTextAppearance(description, item.getIsPending()
? R.style.PaymentsUiSectionPendingTextEndAligned
: R.style.PaymentsUiSectionDescriptiveTextEndAligned);
description.setText(item.getLabel());
description.setEllipsize(TruncateAt.END);
description.setMaxLines(2);
if (maximumDescriptionWidthPx > 0) {
description.setMaxWidth(maximumDescriptionWidthPx);
}
TextView amount = new TextView(context);
ApiCompatibilityUtils.setTextAppearance(amount, item.getIsPending()
? R.style.PaymentsUiSectionPendingTextEndAligned
: R.style.PaymentsUiSectionDescriptiveTextEndAligned);
amount.setText(createValueString(item.getCurrency(), item.getPrice(), false));
// Each item is represented by a row in the GridLayout.
GridLayout.LayoutParams descriptionParams = new GridLayout.LayoutParams(
GridLayout.spec(i, 1, GridLayout.END),
GridLayout.spec(0, 1, GridLayout.END));
GridLayout.LayoutParams amountParams = new GridLayout.LayoutParams(
GridLayout.spec(i, 1, GridLayout.END),
GridLayout.spec(1, 1, GridLayout.END));
ApiCompatibilityUtils.setMarginStart(amountParams,
context.getResources().getDimensionPixelSize(
R.dimen.payments_section_descriptive_item_spacing));
mBreakdownLayout.addView(description, descriptionParams);
mBreakdownLayout.addView(amount, amountParams);
}
}
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;
}
@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);
}
}
@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);
}
}
public static BaseDSL.ViewClassResult gridLayout() {
return BaseDSL.v(GridLayout.class);
}
public static Void gridLayout(Anvil.Renderable r) {
return BaseDSL.v(GridLayout.class, r);
}