| Index: chrome/android/java/src/org/chromium/chrome/browser/payments/ui/EditorIconsField.java
|
| diff --git a/chrome/android/java/src/org/chromium/chrome/browser/payments/ui/EditorIconsField.java b/chrome/android/java/src/org/chromium/chrome/browser/payments/ui/EditorIconsField.java
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..6d75042a92cfca8b956b9428a64ef05f0dbc006b
|
| --- /dev/null
|
| +++ b/chrome/android/java/src/org/chromium/chrome/browser/payments/ui/EditorIconsField.java
|
| @@ -0,0 +1,58 @@
|
| +// Copyright 2016 The Chromium Authors. All rights reserved.
|
| +// Use of this source code is governed by a BSD-style license that can be
|
| +// found in the LICENSE file.
|
| +
|
| +package org.chromium.chrome.browser.payments.ui;
|
| +
|
| +import android.content.Context;
|
| +import android.view.LayoutInflater;
|
| +import android.view.View;
|
| +import android.view.ViewGroup.LayoutParams;
|
| +import android.widget.ImageView;
|
| +import android.widget.LinearLayout;
|
| +import android.widget.TextView;
|
| +
|
| +import org.chromium.chrome.R;
|
| +
|
| +/**
|
| + * Helper class for creating a horizontal list of icons with a title.
|
| + */
|
| +class EditorIconsField {
|
| + /** The size for each icon in density-independent pixels. */
|
| + private static final int LIST_ICON_SIZE_DP = 38;
|
| +
|
| + private final View mLayout;
|
| +
|
| + /**
|
| + * Builds a horizontal list of icons.
|
| + *
|
| + * @param context The application context to use when creating widgets.
|
| + * @param fieldModel The data model of the icon list.
|
| + */
|
| + public EditorIconsField(Context context, EditorFieldModel fieldModel) {
|
| + assert fieldModel.getInputTypeHint() == EditorFieldModel.INPUT_TYPE_HINT_ICONS;
|
| +
|
| + mLayout = LayoutInflater.from(context).inflate(
|
| + R.layout.payment_request_editor_icons, null, false);
|
| +
|
| + ((TextView) mLayout.findViewById(R.id.label)).setText(fieldModel.getLabel());
|
| +
|
| + LinearLayout container = (LinearLayout) mLayout.findViewById(R.id.icons_container);
|
| + float scale = context.getResources().getDisplayMetrics().density;
|
| + for (int i = 0; i < fieldModel.getIconResourceIds().size(); i++) {
|
| + ImageView icon = new ImageView(context);
|
| + icon.setImageResource(fieldModel.getIconResourceIds().get(i));
|
| + icon.setContentDescription(context.getString(
|
| + fieldModel.getIconDescriptionsForAccessibility().get(i)));
|
| + icon.setAdjustViewBounds(true);
|
| + icon.setMaxWidth((int) (LIST_ICON_SIZE_DP * scale + 0.5f));
|
| + icon.setMaxHeight((int) (LIST_ICON_SIZE_DP * scale + 0.5f));
|
| + container.addView(icon, LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
|
| + }
|
| + }
|
| +
|
| + /** @return The View containing everything. */
|
| + public View getLayout() {
|
| + return mLayout;
|
| + }
|
| +}
|
|
|